6 #include "../nick/nick.h"
7 #include "../channel/channel.h"
8 #include "../lib/irc_string.h"
10 #include "hcommands.h"
15 #include "helpmod_alias.h"
27 #define HCMD_OUT_DEFAULT (10 * HDEF_m)
29 /* following are macros for use ONLY IN HERE
30 they may not look pretty, but work surprisingly well */
34 if (*ostr == '"' && strchr(ostr+1, '"'))\
35 ostr = strchr(ostr+1, '"');\
36 while (!isspace(*ostr) && *ostr)\
38 while (isspace(*ostr) && *ostr)\
44 #define DEFINE_HCHANNEL \
47 hchan = hchannel_get_by_channel(returntype);\
48 else if (*argv[0] == '#')\
50 hchan = hchannel_get_by_name(argv[0]);\
54 hchan = hchannel_get_by_channel(returntype);\
57 #define HCHANNEL_VERIFY_AUTHORITY(c, u)\
59 if ((c) != NULL && !hchannel_authority((c), (u)))\
61 helpmod_reply(u, returntype, "Sorry, channel %s is oper only", hchannel_get_name((c)));\
81 static void helpmod_cmd_addchan (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
85 helpmod_reply(sender
, returntype
, "Can not add channel: Channel not defined");
91 helpmod_reply(sender
, returntype
, "Can not add channel: Channel name must start with '#'");
95 if (hchannel_get_by_name(argv
[0]) != NULL
)
97 helpmod_reply(sender
, returntype
, "Can not add channel: Channel %s already active", argv
[0]);
101 if (hchannel_add(argv
[0]) != NULL
)
103 helpmod_reply(sender
, returntype
, "Channel %s added succesfully", argv
[0]);
108 static void helpmod_cmd_delchan (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
116 helpmod_reply(sender
, returntype
, "Can not delete channel: Channel not defined or not found");
119 strcpy(buffer
, hchan
->real_channel
->index
->name
->content
);
120 if (argc
== 0 || strcmp(argv
[0], "YesImSure"))
122 helpmod_reply(sender
, returntype
, "Can not delete channel: Sanity check. Please add a parameter \"YesImSure\" to confirm channel deletion");
127 helpmod_reply(sender
, returntype
, "Channel %s deleted succesfully", buffer
);
130 static void helpmod_cmd_whoami (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
132 helpmod_reply(sender
, returntype
, "You are %s", sender
->real_user
->nick
);
133 helpmod_reply(sender
, returntype
, "Your userlevel is %s", hlevel_name(huser_get_level(sender
)));
134 if (sender
->account
== NULL
)
135 helpmod_reply(sender
, returntype
, "You do not have an account with me");
137 helpmod_reply(sender
, returntype
, "Your accounts name is %s", sender
->account
->name
->content
);
138 if (huser_get_level(sender
) < H_TRIAL
)
140 if (sender
->lc
[0] || sender
->lc
[1] || sender
->lc
[2])
141 helpmod_reply(sender
, returntype
, "You violated the following rules: Excessive use of capital letters %d, repeating %d and improper use of language %d", sender
->lc
[0], sender
->lc
[1], sender
->lc
[2]);
143 helpmod_reply(sender
, returntype
, "You have not violated any rules");
148 huser_channel
*huserchan
= sender
->hchannels
;
149 for (;huserchan
;huserchan
= huserchan
->next
)
150 if ((pos
= hqueue_get_position(huserchan
->hchan
, sender
)) > -1)
151 helpmod_reply(sender
, returntype
, "You have queue position #%d on channel %s", pos
, hchannel_get_name(huserchan
->hchan
));
154 if (IsAccount(sender
->real_user
))
158 for (hchan
= hchannels
;hchan
;hchan
= hchan
->next
)
159 if (hchan
->flags
& H_REQUIRE_TICKET
)
161 htick
= hticket_get(sender
->real_user
->authname
, hchan
);
163 helpmod_reply(sender
, returntype
, "You have an invite ticket for channel %s that expires in %s", hchannel_get_name(hchan
), helpmod_strtime(time(NULL
) - htick
->time_expiration
));
168 static void helpmod_cmd_whois (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
175 helpmod_reply(sender
, returntype
, "Can not get user information: User not specified");
178 if (argc
> H_CMD_MAX_ARGS
)
179 argc
= H_CMD_MAX_ARGS
;
183 husr
= huser_get(getnickbynick(argv
[i
]));
186 helpmod_reply(sender
, returntype
, "Can not get user information: User %s not found", argv
[i
]);
189 helpmod_reply(sender
, returntype
, "User %s has userlevel %s", husr
->real_user
->nick
,hlevel_name(huser_get_level(husr
)));
190 if (husr
->account
== NULL
)
191 helpmod_reply(sender
, returntype
, "User %s does not have an account with me", husr
->real_user
->nick
);
193 helpmod_reply(sender
, returntype
, "User %s has account named %s", husr
->real_user
->nick
,husr
->account
->name
->content
);
194 if (huser_get_level(husr
) < H_TRIAL
)
196 if (husr
->lc
[0] || husr
->lc
[1] || husr
->lc
[2])
197 helpmod_reply(sender
, returntype
, "User %s has lamercontrol entries: Excessive use of capital letters %d, repeating %d and improper use of language %d", husr
->real_user
->nick
, husr
->lc
[0], husr
->lc
[1], husr
->lc
[2]);
199 helpmod_reply(sender
, returntype
, "User %s has no lamercontrol entries", husr
->real_user
->nick
);
203 huser_channel
*huserchan
= husr
->hchannels
;
204 for (;huserchan
;huserchan
= huserchan
->next
)
206 if ((pos
= hqueue_get_position(huserchan
->hchan
, husr
)) > -1)
207 helpmod_reply(sender
, returntype
, "User %s has queue queue position #%d on channel %s", husr
->real_user
->nick
, pos
, hchannel_get_name(huserchan
->hchan
));
208 if (on_desk(husr
, huserchan
))
209 helpmod_reply(sender
, returntype
, "User %s is receiving support on channel %s", husr
->real_user
->nick
, hchannel_get_name(huserchan
->hchan
));
212 if (IsAccount(husr
->real_user
))
216 for (hchan
= hchannels
;hchan
;hchan
= hchan
->next
)
217 if (hchan
->flags
& H_REQUIRE_TICKET
)
219 htick
= hticket_get(husr
->real_user
->authname
, hchan
);
221 helpmod_reply(sender
, returntype
, "User %s has an invite ticket for channel %s that expires in %s", husr
->real_user
->nick
, hchannel_get_name(hchan
), helpmod_strtime(time(NULL
) - htick
->time_expiration
));
227 void helpmod_cmd_megod (huser *sender, channel* returntype, char* ostr, int argc, char *argv[])
229 if (sender->account == NULL)
230 sender->account = haccount_add(sender->real_user->nick, H_ADMIN);
232 sender->account->level = H_ADMIN;
236 void helpmod_cmd_test (huser *sender, channel* returntype, char* ostr, int argc, char *argv[])
238 //lpmod_config_write("helpmod.db.test");
243 helpmod_channick_modes(huser_get(getnickbynick(argv[0])), hchan, MC_DEVOICE, 1);
247 static void helpmod_cmd_seen (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
250 haccount
*target_haccount
;
255 helpmod_reply(sender
, returntype
, "No targets specified for seen");
258 for (i
=0;i
< argc
;i
++)
262 if (!ci_strcmp(argv
[i
] + 1, HELPMOD_AUTH
))
263 { /* A nice special case */
264 helpmod_reply(sender
, returntype
, "I'm right here");
267 target_haccount
= haccount_get_by_name(argv
[i
]);
268 if (target_haccount
== NULL
)
270 helpmod_reply(sender
, returntype
, "Account %s not found", argv
[i
] + 1);
274 helpmod_reply(sender
, returntype
, "Account %s's last recorded activity was %s ago", target_haccount
->name
->content
, helpmod_strtime(time(NULL
) - target_haccount
->last_activity
));
278 if (getnickbynick(argv
[i
]) == helpmodnick
)
279 { /* A nice special case */
280 helpmod_reply(sender
, returntype
, "I'm right here");
283 target_huser
= huser_get(getnickbynick(argv
[i
]));
284 if (target_huser
== NULL
)
286 helpmod_reply(sender
, returntype
, "User %s not found", argv
[i
]);
289 helpmod_reply(sender
, returntype
, "User %s's last recorded activity was %s ago", target_huser
->real_user
->nick
, helpmod_strtime(time(NULL
) - target_huser
->last_activity
));
294 static void helpmod_cmd_change_userlevel(huser
*sender
, hlevel target_level
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
297 haccount
*target_haccount
;
302 helpmod_reply(sender
, returntype
, "Incorrect syntax: Nick or account required");
306 if (argc
> H_CMD_MAX_ARGS
)
307 argc
= H_CMD_MAX_ARGS
;
309 for (i
= 0;i
< argc
;i
++)
311 if (*argv
[i
] == '#') /* account */
313 target_haccount
= haccount_get_by_name(argv
[i
]);
314 if (target_haccount
== NULL
)
316 helpmod_reply(sender
, returntype
, "Can not change userlevel: Account '%s' not found", argv
[i
]);
319 if (target_haccount
->level
> huser_get_level(sender
))
321 helpmod_reply(sender
, returntype
, "Can not change userlevel: Account '%s' has a userlevel higher than yours", argv
[i
]);
325 if (target_haccount
->level
== target_level
)
327 helpmod_reply(sender
, returntype
, "Can not change userlevel: Account '%s' already has userlevel %s", argv
[i
], hlevel_name(target_level
));
331 target_haccount
->level
= target_level
;
333 helpmod_reply(sender
, returntype
, "Userlevel changed: Account '%s' now has userlevel %s", argv
[i
], hlevel_name(target_level
));
338 target_huser
= huser_get(getnickbynick(argv
[i
]));
339 if (target_huser
== NULL
)
341 helpmod_reply(sender
, returntype
, "Can not change userlevel: User '%s' not found", argv
[i
]);
344 if (huser_get_level(target_huser
) > huser_get_level(sender
))
346 helpmod_reply(sender
, returntype
, "Can not change userlevel: User '%s' has a userlevel higher than yours", argv
[i
]);
349 if (huser_get_level(target_huser
) == H_STAFF
&& huser_get_level(sender
) == H_STAFF
)
351 helpmod_reply(sender
, returntype
, "Can not change userlevel: User '%s' has the same userlevel as you have", argv
[i
]);
355 if (huser_get_level(target_huser
) == target_level
)
357 helpmod_reply(sender
, returntype
, "Can not change userlevel: User '%s' already has userlevel %s", argv
[i
], hlevel_name(target_level
));
360 if (target_huser
== sender
)
362 helpmod_reply(sender
, returntype
, "Can not change userlevel: Sanity check, you're changing your own userlevel, use #account instead of nick if you really wish to do this");
365 if (!IsAccount(target_huser
->real_user
))
367 helpmod_reply(sender
, returntype
, "Can not change userlevel: User '%s' is not authed", argv
[i
]);
371 if (target_huser
->account
== NULL
)
373 if (haccount_get_by_name(target_huser
->real_user
->authname
) != NULL
)
375 helpmod_reply(sender
, returntype
, "Can not change userlevel: Unable to create an account. Account %s already exists", target_huser
->real_user
->authname
);
379 target_huser
->account
= haccount_add(target_huser
->real_user
->authname
, target_level
);
382 target_huser
->account
->level
= target_level
;
384 helpmod_reply(sender
, returntype
, "Userlevel changed: User '%s' now has userlevel %s", argv
[i
], hlevel_name(target_level
));
385 if (huser_get_level(target_huser
) != H_LAMER
)
386 helpmod_reply(target_huser
, NULL
, "Your userlevel has been changed, your current userlevel is %s", hlevel_name(target_level
));
391 /* pseudo commands for the above */
392 static void helpmod_cmd_improper (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[]) { helpmod_cmd_change_userlevel(sender
, H_LAMER
, returntype
, ostr
, argc
, argv
); }
393 static void helpmod_cmd_peon (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[]) { helpmod_cmd_change_userlevel(sender
, H_PEON
, returntype
, ostr
, argc
, argv
); }
394 static void helpmod_cmd_trial (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[]) { helpmod_cmd_change_userlevel(sender
, H_TRIAL
, returntype
, ostr
, argc
, argv
); }
395 static void helpmod_cmd_staff (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[]) { helpmod_cmd_change_userlevel(sender
, H_STAFF
, returntype
, ostr
, argc
, argv
); }
396 static void helpmod_cmd_oper (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[]) { helpmod_cmd_change_userlevel(sender
, H_OPER
, returntype
, ostr
, argc
, argv
); }
397 static void helpmod_cmd_admin (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[]) { helpmod_cmd_change_userlevel(sender
, H_ADMIN
, returntype
, ostr
, argc
, argv
); }
399 static void helpmod_cmd_deluser (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
403 haccount
*target_haccount
;
407 helpmod_reply(sender
, returntype
, "Usage: deluser [nick|#account]");
411 if (argc
> H_CMD_MAX_ARGS
)
412 argc
= H_CMD_MAX_ARGS
;
414 for (i
= 0;i
< argc
;i
++)
418 target_huser
= huser_get(getnickbynick(argv
[i
]));
419 if (target_huser
== NULL
)
421 helpmod_reply(sender
, returntype
, "Cannot delete the account: User %s does not exist", argv
[i
]);
424 if (target_huser
->account
== NULL
)
426 helpmod_reply(sender
, returntype
, "Cannot delete the account: User %s does not have an account", argv
[i
]);
429 target_haccount
= target_huser
->account
;
432 target_haccount
= haccount_get_by_name(argv
[i
]);
434 if (target_haccount
== NULL
)
436 helpmod_reply(sender
, returntype
, "Cannot delete the account: Account %s does not exist", argv
[i
]);
439 if (target_haccount
->level
> huser_get_level(sender
))
441 helpmod_reply(sender
, returntype
, "Cannot delete the account: Account %s has higher userlevel than you", target_haccount
->name
->content
);
444 helpmod_reply(sender
, returntype
, "Account %s deleted", target_haccount
->name
->content
);
445 haccount_del(target_haccount
);
449 static void helpmod_cmd_listuser (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
452 haccount
*hack
= haccounts
;
453 int count
= 0, lvl
= -1;
456 if (argc
> 0 && sscanf(argv
[0], "%d", &lvl
) && lvl
>= H_LAMER
&& lvl
<= H_ADMIN
)
469 helpmod_reply(sender
, returntype
, "%s accounts matching pattern %s: (account name, userlevel, expires in)", hlevel_name(lvl
), pattern
);
471 helpmod_reply(sender
, returntype
, "Accounts matching pattern %s: (account name, userlevel, expires in)", pattern
);
472 for (;hack
;hack
= hack
->next
)
474 if (strregexp(hack
->name
->content
, pattern
))
476 if (lvl
>= 0 && hack
->level
!= lvl
)
478 timer
= hack
->last_activity
+ HELPMOD_ACCOUNT_EXPIRATION
[hack
->level
];
479 helpmod_reply(sender
, returntype
, "%-16s %-32s %s", hack
->name
->content
, hlevel_name(hack
->level
), asctime(localtime(&timer
)));
484 helpmod_reply(sender
, returntype
, "%s accounts matching pattern %d", hlevel_name(lvl
), count
);
486 helpmod_reply(sender
, returntype
, "Accounts matching pattern %d", count
);
489 static void helpmod_cmd_censor (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
497 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
501 helpmod_reply(sender
, returntype
, "Can not handle the censor: Channel not specified or found");
505 if (argc
< 2) /* view */
507 if (hchan
->censor
== NULL
)
508 helpmod_reply(sender
, returntype
, "Nothing is censored on channel %s", hchan
->real_channel
->index
->name
->content
);
511 helpmod_reply(sender
, returntype
, "Censored patterns for channel %s (%s):", hchan
->real_channel
->index
->name
->content
, (hchan
->flags
& H_CENSOR
)?"active":"inactive");
512 for (hcens
= hchan
->censor
;hcens
;hcens
= hcens
->next
)
513 helpmod_reply(sender
, returntype
, "#%d %s%s%s", i
++, hcens
->pattern
->content
, hcens
->reason
?" :: ":"", hcens
->reason
?hcens
->reason
->content
:"");
518 if (!ci_strcmp(argv
[0], "add"))
531 if (hcensor_get_by_pattern(hchan
->censor
, pattern
))
533 helpmod_reply(sender
, returntype
, "Cannot add censor entry: Pattern '%s' already censored", pattern
);
537 if (hcensor_add(&hchan
->censor
, pattern
, reason
))
538 helpmod_reply(sender
, returntype
, "Pattern '%s' (%s) censored succesfully", pattern
, reason
?reason
:"no reason specified");
540 helpmod_reply(sender
, returntype
, "Cannot add censor entry: Pattern '%s' already censored", pattern
);
543 else if (!ci_strcmp(argv
[0], "del"))
549 if (!sscanf(argv
[0], "#%d", &tmp
))
551 helpmod_reply(sender
, returntype
, "Cannot delete censor entry: Bad index, integer expected");
554 hcens
= hcensor_get_by_index(hchan
->censor
, tmp
);
557 hcens
= hcensor_get_by_pattern(hchan
->censor
, argv
[0]);
560 helpmod_reply(sender
, returntype
, "Cannot delete censor entry: Entry not found");
563 hcensor_del(&hchan
->censor
, hcens
);
564 helpmod_reply(sender
, returntype
, "Censor entry deleted succesfully");
568 helpmod_reply(sender
, returntype
, "Unknown censor command %s", argv
[0]);
572 static void helpmod_cmd_chanconf (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
579 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
583 helpmod_reply(sender
, returntype
, "Can not change or view channel configuration: Channel not specified or found");
587 if (argc
== 0) /* view, spammy but with pretty formatting */
590 helpmod_reply(sender
, returntype
, "Channel configuration for %s:", hchan
->real_channel
->index
->name
->content
);
592 for (i
=0;i
<=HCHANNEL_CONF_COUNT
;i
++)
593 helpmod_reply(sender
, returntype
, "(%02d) %-32s : %s", i
, hchannel_get_sname(i
), hchannel_get_state(hchan
, 1 << i
));
598 old_flags
= hchan
->flags
;
600 if (argc
> H_CMD_MAX_ARGS
)
601 argc
= H_CMD_MAX_ARGS
;
610 else if (*argv
[i
] == '-')
618 if (!sscanf(argv
[i
], "%d", &tmp
) || (tmp
< 0) || (tmp
> HCHANNEL_CONF_COUNT
))
620 helpmod_reply(sender
, returntype
, "Can not change channel configuration: Expected integer between [0, %d]", HCHANNEL_CONF_COUNT
);
627 hchan
->flags
&= ~(1 << tmp
);
628 helpmod_reply(sender
, returntype
, "Channel configuration for %s changed: %s set to %s",hchannel_get_name(hchan
), hchannel_get_sname(tmp
), hchannel_get_state(hchan
, 1 << tmp
));
631 helpmod_reply(sender
, returntype
, "(%02d) %-32s : %s", tmp
, hchannel_get_sname(tmp
), hchannel_get_state(hchan
, 1 << tmp
));
634 hchan
->flags
|= (1 << tmp
);
635 helpmod_reply(sender
, returntype
, "Channel configuration for %s changed: %s set to %s", hchannel_get_name(hchan
), hchannel_get_sname(tmp
), hchannel_get_state(hchan
, 1 << tmp
));
639 hchannel_conf_change(hchan
, old_flags
);
643 static void helpmod_cmd_acconf (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
645 haccount
*hacc
= sender
->account
;
649 helpmod_reply(sender
, returntype
, "Account configuration impossible: You do not have an account");
653 if (argc
== 0) /* view, spammy but with pretty formatting */
656 helpmod_reply(sender
, returntype
, "Account configuration for %s:", hacc
->name
->content
);
658 for (i
=0;i
<=HACCOUNT_CONF_COUNT
;i
++)
659 helpmod_reply(sender
, returntype
, "(%02d) %-35s : %s", i
, haccount_get_sname(i
), haccount_get_state(hacc
, 1 << i
));
665 if (argc
> H_CMD_MAX_ARGS
)
666 argc
= H_CMD_MAX_ARGS
;
675 else if (*argv
[i
] == '-')
683 if (!sscanf(argv
[i
], "%d", &tmp
) || (tmp
< 0) || (tmp
> HACCOUNT_CONF_COUNT
))
685 helpmod_reply(sender
, returntype
, "Can not change account configuration: Expected integer between [0, %d]", HACCOUNT_CONF_COUNT
);
692 hacc
->flags
&= ~(1 << tmp
);
693 helpmod_reply(sender
, returntype
, "Account configuration for %s changed: %s set to %s",hacc
->name
->content
, haccount_get_sname(tmp
), haccount_get_state(hacc
, 1 << tmp
));
696 helpmod_reply(sender
, returntype
, "(%02d) %-35s : %s", tmp
, haccount_get_sname(tmp
), haccount_get_state(hacc
, 1 << tmp
));
699 hacc
->flags
|= (1 << tmp
);
700 helpmod_reply(sender
, returntype
, "Account configuration for %s changed: %s set to %s", hacc
->name
->content
, haccount_get_sname(tmp
), haccount_get_state(hacc
, 1 << tmp
));
707 static void helpmod_cmd_welcome (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
713 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
717 helpmod_reply(sender
, returntype
, "Can not change or view chanflags: Channel not specified or found");
721 if (argc
== 0) /* view */
723 helpmod_reply(sender
, returntype
, "Welcome for channel %s (%s): %s", hchan
->real_channel
->index
->name
->content
, hchannel_get_state(hchan
, H_WELCOME
), hchan
->welcome
);
727 strcpy(hchan
->welcome
, ostr
);
728 helpmod_reply(sender
, returntype
, "Welcome for channel %s (%s) is now: %s", hchan
->real_channel
->index
->name
->content
, hchannel_get_state(hchan
, H_WELCOME
), hchan
->welcome
);
732 static void helpmod_cmd_aliases (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
736 void helpmod_list_aliases(alias_tree node
)
740 helpmod_reply(sender
, returntype
, "%s", buf
);
745 sprintf(buf
+i
,"%.200s ",node
->name
->content
);
746 i
+=(1+strlen(node
->name
->content
));
747 helpmod_list_aliases(node
->left
);
748 helpmod_list_aliases(node
->right
);
750 helpmod_list_aliases(aliases
);
752 helpmod_reply(sender
, returntype
, "%s", buf
);
755 static void helpmod_cmd_showcommands (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
760 if (!(argc
&& (sscanf(argv
[0], "%d", &level
)) && (level
>= 0) && (level
<= huser_get_level(sender
))))
761 level
= huser_get_level(sender
);
763 helpmod_reply(sender
, returntype
, "HelpMod %s commands for userlevel %s:", HELPMOD_VERSION
, hlevel_name(level
));
765 hcommand_list(H_NONE
);
767 while ((tmp
= hcommand_list(level
)) != NULL
)
768 helpmod_reply(sender
, returntype
, "%-16s %s", tmp
->name
->content
, tmp
->help
->content
);
773 static void helpmod_cmd_lamercontrol (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
780 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
782 if (hchan
== NULL
) /* list profiles */
784 helpmod_reply(sender
, returntype
, "Following lamercontrol profiles are available:");
785 for (ptr
= hlc_profiles
;ptr
;ptr
= ptr
->next
)
786 helpmod_reply(sender
, returntype
, "%s", ptr
->name
->content
);
791 if (hchan
->lc_profile
== NULL
)
792 helpmod_reply(sender
, returntype
, "Channel %s has no lamercontrol profile set", hchannel_get_name(hchan
));
794 helpmod_reply(sender
, returntype
, "Channel %s is using lamercontrol profile %s (%s)", hchannel_get_name(hchan
), hchan
->lc_profile
->name
->content
, hchannel_get_state(hchan
, H_LAMER_CONTROL
));
797 if (!ci_strcmp(argv
[0], "list"))
799 helpmod_reply(sender
, returntype
, "Following lamercontrol profiles are available:");
800 for (ptr
= hlc_profiles
;ptr
;ptr
= ptr
->next
)
801 helpmod_reply(sender
, returntype
, "%s", ptr
->name
->content
);
804 ptr
= hlc_get(argv
[0]);
807 helpmod_reply(sender
, returntype
, "Can not set the lamercontrol profile: Profile %s does not exist:", argv
[0]);
812 hchan
->lc_profile
= ptr
;
813 helpmod_reply(sender
, returntype
, "Lamercontrol profile %s set to channel %s succesfully",ptr
->name
->content
,hchannel_get_name(hchan
));
818 static void helpmod_cmd_term_find_general (huser
*sender
, channel
* returntype
, int type
, char* ostr
, int argc
, char *argv
[])
831 source
= hchan
->channel_hterms
;
835 if (type
== H_TERM_PLUS
)
836 hqueue_advance(hchan
, sender
, 1);
838 helpmod_reply(sender
, returntype
, "Can not find term: Term not specified");
841 htrm
= hterm_get_and_find(source
, argv
[0]);
844 helpmod_reply(sender
, returntype
, "No term found matching '%s'", argv
[0]);
847 if (returntype
!= NULL
&& huser_get_level(sender
) > H_PEON
)
849 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
854 if (argc
> H_CMD_MAX_ARGS
)
855 argc
= H_CMD_MAX_ARGS
;
858 targets
[ntargets
] = huser_get(getnickbynick(argv
[i
]));
859 if (targets
[ntargets
] == NULL
)
861 helpmod_reply(sender
, returntype
, "Error using ?: User %s not found", argv
[i
]);
870 helpmod_message_channel_long(hchannel_get_by_channel(returntype
), "(%s): %s", htrm
->name
->content
, htrm
->description
->content
);
873 char buffer
[256] = "";
874 for (i
=0;i
<ntargets
;i
++)
877 strcat(buffer
, targets
[i
]->real_user
->nick
);
880 helpmod_message_channel_long(hchannel_get_by_channel(returntype
), "%s: (%s) %s", buffer
, htrm
->name
->content
, htrm
->description
->content
);
881 if (type
!= H_TERM_FIND
)
883 if (hchan
->flags
& H_QUEUE
)
885 for (i
=0;i
<ntargets
;i
++)
887 huser_channel
*huserchan
= huser_on_channel(targets
[i
], hchan
);
888 huserchan
->flags
|= HQUEUE_DONE
;
889 if (huserchan
->flags
& HCUMODE_VOICE
)
890 helpmod_channick_modes(targets
[i
], hchan
, MC_DEVOICE
, HLAZY
);
892 if (type
== H_TERM_PLUS
)
893 hqueue_advance(hchan
, sender
, ntargets
);
899 helpmod_reply(sender
, returntype
, "(%s): %s", htrm
->name
->content
, htrm
->description
->content
);
902 static void helpmod_cmd_term_find (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
904 helpmod_cmd_term_find_general(sender
, returntype
, H_TERM_FIND
, ostr
, argc
, argv
);
907 static void helpmod_cmd_term_find_minus (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
909 helpmod_cmd_term_find_general(sender
, returntype
, H_TERM_MINUS
, ostr
, argc
, argv
);
912 static void helpmod_cmd_term_find_plus (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
914 helpmod_cmd_term_find_general(sender
, returntype
, H_TERM_PLUS
, ostr
, argc
, argv
);
917 static void helpmod_cmd_klingon (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
920 huser
*target
= NULL
;
927 rand_val
= rand() % KLINGON_NTARGETED
;
928 helpmod_reply(sender
, NULL
, "%s: %s", sender
->real_user
->nick
, klingon_targeted
[rand_val
]);
933 target
= huser_get(getnickbynick(argv
[0]));
937 rand_val
= rand() % KLINGON_NTARGETED
;
938 helpmod_message_channel(hchan
, "%s: %s", target
->real_user
->nick
, klingon_targeted
[rand_val
]);
942 rand_val
= rand() % KLINGON_NGENERAL
;
943 helpmod_message_channel(hchan
, "%s", klingon_general
[rand_val
]);
947 static void helpmod_cmd_term (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
955 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
960 source
= &hchan
->channel_hterms
;
964 helpmod_reply(sender
, returntype
, "Can not handle terms: Operation not specified");
967 if (!ci_strcmp(argv
[0], "list"))
981 helpmod_reply(sender
, returntype
, "Terms matching pattern '%s'", pattern
);
982 for (;htrm
;htrm
= htrm
->next
)
984 if (strlen(buffer
) >= 250)
986 helpmod_reply(sender
, returntype
, "%s", buffer
);
989 if (strregexp(htrm
->description
->content
, pattern
) || strregexp(htrm
->name
->content
, pattern
))
991 sprintf(buffer
+strlen(buffer
) /* :) */, "%s(%d) ", htrm
->name
->content
, strlen(htrm
->description
->content
));
996 helpmod_reply(sender
, returntype
, "%s", buffer
);
997 helpmod_reply(sender
, returntype
, "%d term%s match%s pattern '%s'", count
, (count
== 1)?"":"s", (count
== 1)?"es":"", pattern
);
999 else if (!ci_strcmp(argv
[0], "listfull"))
1002 helpmod_reply(sender
, returntype
, "Following terms have been entered:");
1003 for (;htrm
;htrm
= htrm
->next
)
1004 helpmod_reply(sender
, returntype
, "(%s): %s", htrm
->name
->content
, htrm
->description
->content
);
1006 else if (!ci_strcmp(argv
[0], "get"))
1010 helpmod_reply(sender
, returntype
, "Can not get term: Term not specified");
1013 htrm
= hterm_get(*source
, argv
[1]);
1015 helpmod_reply(sender
, returntype
, "Can not get term: Term %s not found", argv
[1]);
1017 helpmod_reply(sender
, returntype
, "(%s): %s", htrm
->name
->content
, htrm
->description
->content
);
1019 else if (!ci_strcmp(argv
[0], "add"))
1022 helpmod_reply(sender
, returntype
, "Can not add term: Term name not specified");
1024 helpmod_reply(sender
, returntype
, "Can not add term: Term description not specified");
1025 else if ((htrm
= hterm_get(*source
, argv
[1])) != NULL
)
1026 helpmod_reply(sender
, returntype
, "Can not add term: Term %s is already added", argv
[1]);
1029 char *name
= argv
[1], *description
;
1030 SKIP_WORD
; SKIP_WORD
;
1032 htrm
= hterm_add(source
, name
, description
);
1033 helpmod_reply(sender
, returntype
, "Term %s added succesfully", name
);
1036 else if (!ci_strcmp(argv
[0], "del"))
1041 helpmod_reply(sender
, returntype
, "Can not delete term: Term name not specified");
1044 if (argc
> H_CMD_MAX_ARGS
)
1045 argc
= H_CMD_MAX_ARGS
;
1046 for (i
=1;i
<argc
;i
++)
1048 htrm
= hterm_get(*source
, argv
[i
]);
1051 helpmod_reply(sender
, returntype
, "Can not delete term: Term %s not found", argv
[i
]);
1054 hterm_del(source
!= NULL
?source
:&hterms
, htrm
);
1055 helpmod_reply(sender
, returntype
, "Term %s deleted succesfully", argv
[i
]);
1058 else if (!ci_strcmp(argv
[0], "find"))
1062 helpmod_reply(sender
, returntype
, "Can not find term: Term name not specified");
1065 htrm
= hterm_get_and_find(*source
, argv
[1]);
1069 helpmod_reply(sender
, returntype
, "No term found matching '%s'", argv
[1]);
1072 if (returntype
!= NULL
&& huser_get_level(sender
) > H_PEON
)
1073 helpmod_message_channel(hchannel_get_by_channel(returntype
), "(%s): %s", htrm
->name
->content
, htrm
->description
->content
);
1075 helpmod_reply(sender
, returntype
, "(%s): %s", htrm
->name
->content
, htrm
->description
->content
);
1079 helpmod_reply(sender
, returntype
, "Can not handle terms: Operation not specified");
1083 static void helpmod_cmd_queue (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
1090 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
1094 helpmod_reply(sender
, returntype
, "Can not handle queue: Operation not specified");
1098 if (!ci_strcmp(argv
[0], "done"))
1099 operation
= HQ_DONE
;
1100 else if (!ci_strcmp(argv
[0], "next"))
1101 operation
= HQ_NEXT
;
1102 else if (!ci_strcmp(argv
[0], "on"))
1104 else if (!ci_strcmp(argv
[0], "off"))
1106 else if (!ci_strcmp(argv
[0], "maintain"))
1107 operation
= HQ_MAINTAIN
;
1108 else if (!ci_strcmp(argv
[0], "list"))
1109 operation
= HQ_LIST
;
1110 else if (!ci_strcmp(argv
[0], "summary"))
1111 operation
= HQ_SUMMARY
;
1112 else if (!ci_strcmp(argv
[0], "reset"))
1113 operation
= HQ_RESET
;
1115 operation
= HQ_NONE
;
1119 helpmod_queue_handler(sender
, returntype
, hchan
, operation
, ostr
, argc
, argv
);
1122 static void helpmod_cmd_done (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
1126 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
1127 helpmod_queue_handler(sender
, returntype
, hchan
, HQ_DONE
, ostr
, argc
, argv
);
1130 static void helpmod_cmd_next (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
1134 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
1135 helpmod_queue_handler(sender
, returntype
, hchan
, HQ_NEXT
, ostr
, argc
, argv
);
1138 static void helpmod_cmd_enqueue (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
1142 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
1143 helpmod_queue_handler(sender
, returntype
, hchan
, HQ_ON
, ostr
, argc
, argv
);
1146 static void helpmod_cmd_dequeue (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
1150 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
1151 helpmod_queue_handler(sender
, returntype
, hchan
, HQ_OFF
, ostr
, argc
, argv
);
1154 static void helpmod_cmd_autoqueue (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
1158 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
1159 helpmod_queue_handler(sender
, returntype
, hchan
, HQ_MAINTAIN
, ostr
, argc
, argv
);
1162 static void helpmod_cmd_dnmo (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
1167 helpmod_reply(sender
, returntype
, "Can not correct the luser: User not defined");
1170 if (argc
> H_CMD_MAX_ARGS
)
1171 argc
= H_CMD_MAX_ARGS
;
1172 for (i
=0;i
<argc
;i
++)
1174 huser
*husr
= huser_get(getnickbynick(argv
[i
]));
1177 helpmod_reply(sender
, returntype
, "Can not correct the luser: User %s not found", argv
[i
]);
1180 if (huser_get_level(husr
) > H_PEON
)
1182 helpmod_reply(sender
, returntype
, "Can not correct the luser: User %s is not a peon", argv
[i
]);
1186 if (!hchannels_on_queue(husr) && !hchannels_on_desk(husr))
1188 helpmod_reply(sender, returntype, "Can not correct the luser: User %s is not in any queue", argv[i]);
1192 hchannels_dnmo(husr
);
1194 helpmod_reply(husr
, NULL
, "You contacted a channel operator without permission. This is a violation of the channel rules. As a result you have been set to the last queue position");
1195 helpmod_reply(sender
, returntype
, "User %s has been informed of his mistake", argv
[i
]);
1197 { /* fix the autoqueue for the channel(s) */
1199 for (hchan
= hchannels
;hchan
;hchan
= hchan
->next
)
1200 hqueue_handle_queue(hchan
, sender
);
1204 static void helpmod_cmd_ban (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
1208 helpmod_reply(sender
, returntype
, "Can not global handle bans: Operation not defined");
1212 else if (!ci_strcmp(argv
[0], "list"))
1223 helpmod_reply(sender
, returntype
, "Global bans matching pattern %s", pattern
);
1225 for (;ptr
;ptr
= ptr
->next
)
1226 if (strregexp(bantostring(ptr
->real_ban
), pattern
))
1228 helpmod_reply(sender
, returntype
, "%-64s %-15s %s", bantostring(ptr
->real_ban
), helpmod_strtime(ptr
->expiration
- time(NULL
)), ptr
->reason
?ptr
->reason
->content
:"");
1232 helpmod_reply(sender
, returntype
, "%d Global bans match pattern %s", count
, pattern
);
1235 else if (!ci_strcmp(argv
[0], "add"))
1237 int duration
= 4 * HDEF_h
;
1238 char *reason
= "Banned";
1239 char *target
= argv
[1];
1243 helpmod_reply(sender
, returntype
, "Can not add global ban: Target hostmask not defined");
1248 if ((duration
= helpmod_read_strtime(argv
[2])) < 0)
1250 helpmod_reply(sender
, returntype
, "Can not add global ban: Invalid time %s", argv
[2]);
1262 hban_add(target
, reason
, time(NULL
) + duration
, 0);
1263 helpmod_reply(sender
, returntype
, "Added ban for %s (%s), expires in %s", target
, reason
, helpmod_strtime(duration
));
1265 else if (!ci_strcmp(argv
[0], "del"))
1270 helpmod_reply(sender
, returntype
, "Can not remove global ban: Target hostmask not defined");
1273 if (argc
> H_CMD_MAX_ARGS
)
1274 argc
= H_CMD_MAX_ARGS
;
1275 for (i
=1;i
<argc
;i
++)
1277 hban
*ptr
= hban_get(argv
[i
]);
1280 helpmod_reply(sender
, returntype
, "Can not remove global ban: Hostmask %s is not banned", argv
[i
]);
1283 helpmod_reply(sender
, returntype
, "Global ban for hostmask %s removed", argv
[i
]);
1289 helpmod_reply(sender
, returntype
, "Can not handle global bans: Unknown operation %s", argv
[0]);
1294 static void helpmod_cmd_chanban (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
1303 helpmod_reply(sender
, returntype
, "Can not handle channel bans: Channel not defined or not found");
1307 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
1311 helpmod_reply(sender
, returntype
, "Can not handle channel bans: Operation not defined");
1315 if (!ci_strcmp(argv
[0], "list"))
1317 char *pattern
, *cban
;
1318 chanban
*ptr
= hchan
->real_channel
->bans
;
1326 helpmod_reply(sender
, returntype
, "Bans matching pattern %s for channel %s", pattern
, hchannel_get_name(hchan
));
1327 for (;ptr
;ptr
= ptr
->next
)
1328 if (strregexp((cban
= bantostring(ptr
)), pattern
))
1331 if (hchanban_get(hchan
,cban
))
1332 helpmod_reply(sender
, returntype
, "%s Expires in %s", bantostring(ptr
), helpmod_strtime(hchanban_get(hchan
, cban
)->expiration
- time(NULL
)));
1334 helpmod_reply(sender
, returntype
, "%s", bantostring(ptr
));
1336 helpmod_reply(sender
, returntype
, "%d bans match pattern %s on channel %s", count
, pattern
, hchannel_get_name(hchan
));
1338 else if (!ci_strcmp(argv
[0], "add"))
1342 helpmod_reply(sender
, returntype
, "Can not add channel bans: Pattern not defined");
1345 if (argc
> H_CMD_MAX_ARGS
)
1346 argc
= H_CMD_MAX_ARGS
;
1347 for (i
=1;i
<argc
;i
++)
1349 /* POSSIBLE BUG ? */
1350 helpmod_setban(hchan
, argv
[i
], H_ETERNITY
, MCB_ADD
, HLAZY
);
1351 helpmod_reply(sender
, returntype
, "Added ban %s to channel %s", argv
[i
], hchannel_get_name(hchan
));
1354 else if (!ci_strcmp(argv
[0], "del"))
1358 helpmod_reply(sender
, returntype
, "Can not remove channel bans: Pattern not defined");
1361 if (argc
> H_CMD_MAX_ARGS
)
1362 argc
= H_CMD_MAX_ARGS
;
1363 for (i
=1;i
<argc
;i
++)
1365 chanban
*ptr
= hchan
->real_channel
->bans
;
1366 for (;ptr
;ptr
= ptr
->next
)
1367 if (strregexp(bantostring(ptr
), argv
[i
]))
1369 helpmod_setban(hchan
, argv
[i
], 0, MCB_DEL
, HLAZY
);
1370 helpmod_reply(sender
, returntype
, "Channel ban %s removed from channel %s", argv
[i
], hchannel_get_name(hchan
));
1374 helpmod_reply(sender
, returntype
, "Can not remove channel ban: Pattern %s not banned on channel %s", argv
[i
], hchannel_get_name(hchan
));
1379 helpmod_reply(sender
, returntype
, "Can not handle channel bans: Unknown operation %s", argv
[0]);
1384 static void helpmod_cmd_idlekick (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
1391 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
1395 helpmod_reply(sender
, returntype
, "Can not handle the idlekick: Channel not defined or not found");
1398 if (argc
== 0) /* view */
1400 helpmod_reply(sender
, returntype
, "Idlekick for channel %s is set to %s", hchannel_get_name(hchan
), helpmod_strtime(hchan
->max_idle
));
1403 else if ((tmp
= helpmod_read_strtime(argv
[0])) < 0 || tmp
< HDEF_m
|| tmp
> HDEF_w
)
1405 helpmod_reply(sender
, returntype
, "Can not set the idlekick: Invalid time given '%s'", argv
[0]);
1410 hchan
->max_idle
= tmp
;
1411 helpmod_reply(sender
, returntype
, "Idlekick for channel %s set to %s succesfully", hchannel_get_name(hchan
), helpmod_strtime(hchan
->max_idle
));
1415 static void helpmod_cmd_topic (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
1420 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
1424 helpmod_reply(sender
, returntype
, "Can not handle the topic: Channel not defined or not found");
1427 if (!(hchan
-> flags
& H_HANDLE_TOPIC
))
1428 helpmod_reply(sender
, returntype
, "Note: I'm not set to handle the topic on channel %s", hchannel_get_name(hchan
));
1430 if (argc
== 0) /* check the topic */
1432 helpmod_reply(sender
, returntype
, "Topic of channel %s is currently: %s", hchannel_get_name(hchan
), htopic_construct(hchan
->topic
));
1435 if (!ci_strcmp(argv
[0], "erase"))
1437 htopic_del_all(&hchan
->topic
);
1438 hchannel_set_topic(hchan
);
1439 helpmod_reply(sender
, returntype
, "Topic of channel %s erased", hchannel_get_name(hchan
));
1441 else if (!ci_strcmp(argv
[0], "refresh"))
1443 hchannel_set_topic(hchan
);
1444 helpmod_reply(sender
, returntype
, "Topic of channel %s refreshed", hchannel_get_name(hchan
));
1446 else if (!ci_strcmp(argv
[0], "add"))
1452 helpmod_reply(sender
, returntype
, "Cannot handle the topic of channel %s: Additional arguments required", hchannel_get_name(hchan
));
1455 if (sscanf(argv
[0], "%d", &pos
) && pos
>= 0)
1461 if (argc
== 0) /* lame repeat :( */
1463 helpmod_reply(sender
, returntype
, "Cannot handle the topic of channel %s: Additional arguments required", hchannel_get_name(hchan
));
1466 if (htopic_len(hchan
->topic
) + strlen(ostr
) + 3 > TOPICLEN
)
1468 helpmod_reply(sender
, returntype
, "Cannot add to the topic of channel %s: Maximum topic length exceeded", hchannel_get_name(hchan
));
1472 htopic_add(&hchan
->topic
, ostr
, pos
);
1473 hchannel_set_topic(hchan
);
1474 helpmod_reply(sender
, returntype
, "Added '%s' to the topic of channel %s", ostr
, hchannel_get_name(hchan
));
1476 else if (!ci_strcmp(argv
[0], "del"))
1481 helpmod_reply(sender
, returntype
, "Cannot handle the topic of channel %s: Additional arguments required", hchannel_get_name(hchan
));
1485 if (!sscanf(argv
[0], "%d", &pos
) || pos
< 0)
1487 helpmod_reply(sender
, returntype
, "Cannot handle the topic of channel %s: Expected positive integer", hchannel_get_name(hchan
));
1490 if (htopic_count(hchan
->topic
) < pos
)
1492 helpmod_reply(sender
, returntype
, "Cannot delete from the topic of channel %s: No such topic element %d", hchannel_get_name(hchan
), pos
);
1495 htopic_del(&hchan
->topic
, htopic_get(hchan
->topic
, pos
));
1496 hchannel_set_topic(hchan
);
1498 else if (!ci_strcmp(argv
[0], "set"))
1502 helpmod_reply(sender
, returntype
, "Cannot handle the topic of channel %s: Additional arguments required", hchannel_get_name(hchan
));
1506 htopic_del_all(&hchan
->topic
);
1507 htopic_add(&hchan
->topic
, ostr
, 0);
1508 hchannel_set_topic(hchan
);
1511 helpmod_reply(sender
, returntype
, "Can not handle the topic of channel %s: Unknown operation %s", hchannel_get_name(hchan
), argv
[0]);
1514 static void helpmod_cmd_out (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
1518 char *reason
= "Banned";
1519 huser
*targets
[H_CMD_MAX_ARGS
];
1524 helpmod_reply(sender
, returntype
, "Can not get rid of the user: User not specified");
1528 if (argc
> H_CMD_MAX_ARGS
)
1529 argc
= H_CMD_MAX_ARGS
;
1530 for (i
=0;i
<argc
;i
++)
1532 if (argv
[i
][0] == ':')
1536 helpmod_reply(sender
, returntype
, "Can not get rid of users: No users specified");
1547 husr
= huser_get(getnickbynick(argv
[i
]));
1550 helpmod_reply(sender
, returntype
, "Can not get rid of the user: User %s not found", argv
[i
]);
1553 if (huser_get_level(husr
) > H_PEON
)
1555 helpmod_reply(sender
, returntype
, "Can not get rid of the user: User %s is not a peon", husr
->real_user
->nick
);
1558 targets
[ntargets
++] = husr
;
1561 for (i
=0;i
<ntargets
;i
++)
1563 const char *banmask
= hban_ban_string(targets
[i
]->real_user
, HBAN_HOST
);
1565 hban_add(banmask
, reason
, time(NULL
) + HCMD_OUT_DEFAULT
, 0);
1567 helpmod_reply(sender
, returntype
, "User %s is now gone", targets
[i
]->real_user
->nick
);
1571 static void helpmod_cmd_everyoneout (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
1574 hchannel_user
**hchanuser
;
1575 char *reason
= "clearing channel";
1576 int autoqueue_tmp
= -1;
1580 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
1584 helpmod_reply(sender
, returntype
, "Can not clear channel: Channel not defined or not found");
1591 hchan
->flags
|= H_MAINTAIN_I
;
1592 hchannel_mode_check(hchan
);
1594 hchanuser
= &hchan
->channel_users
;
1596 if ((hchan
->flags
& H_QUEUE
) && (hchan
->flags
& H_QUEUE_MAINTAIN
))
1598 autoqueue_tmp
= hchan
->autoqueue
;
1599 hchan
->autoqueue
= 0;
1604 if (huser_get_level((*hchanuser
)->husr
) < H_TRIAL
)
1605 helpmod_kick(hchan
, (*hchanuser
)->husr
, reason
);
1607 hchanuser
= &(*hchanuser
)->next
;
1610 if (autoqueue_tmp
> 0)
1611 hchan
->autoqueue
= autoqueue_tmp
;
1613 helpmod_reply(sender
, returntype
, "Channel %s has been cleared of normal users", hchannel_get_name(hchan
));
1616 static void helpmod_cmd_kick (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
1620 huser
*husr
, *targets
[H_CMD_MAX_ARGS
];
1622 char *reason
= "out";
1625 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
1629 helpmod_reply(sender
, returntype
, "Can not kick the user: Channel not defined or not found");
1635 helpmod_reply(sender
, returntype
, "Can not kick users: No users specified");
1639 if (argc
> H_CMD_MAX_ARGS
)
1640 argc
= H_CMD_MAX_ARGS
;
1641 for (i
=0;i
<argc
;i
++)
1643 if (*argv
[i
] == ':')
1647 helpmod_reply(sender
, returntype
, "Can not kick the user: No users defined");
1657 husr
= huser_get(getnickbynick(argv
[i
]));
1660 helpmod_reply(sender
, returntype
, "Can not kick the user: User %s not found", argv
[i
]);
1663 if (huser_on_channel(husr
, hchan
) == NULL
)
1665 helpmod_reply(sender
, returntype
, "Can not kick the user: User %s is not on channel %s", husr
->real_user
->nick
, hchannel_get_name(hchan
));
1668 if (huser_get_level(husr
) > H_PEON
)
1670 helpmod_reply(sender
, returntype
, "Can not kick the user: User %s is not a peon", husr
->real_user
->nick
);
1673 targets
[ntargets
++] = husr
;
1676 for (i
=0;i
<ntargets
;i
++)
1677 helpmod_kick(hchan
, targets
[i
], reason
);
1680 static void helpmod_cmd_stats (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
1683 haccount
*target
= sender
->account
;
1685 hstat_account_entry
*stat_entry
;
1686 int days
= 1, weeks
= 0;
1687 int type
= HSTAT_ACCOUNT_SHORT
;
1689 time_t timer
= time(NULL
);
1690 struct tm
*tstruct
= localtime(&timer
);
1696 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
1700 helpmod_reply(sender
, returntype
, "Can not show user statistics: Channel not defined or not found");
1704 if (argc
> 0 && huser_get_level(sender
) == H_ADMIN
)
1705 { /* not very elegant */
1706 if (argv
[0][0] == '#') /* account */
1708 target
= haccount_get_by_name(argv
[0]+1);
1711 helpmod_reply(sender
, returntype
, "Can not show user statistics: Account %s not found", argv
[0]);
1720 helpmod_reply(sender
, returntype
, "Can not show user statistics: You do not have an account");
1726 if (!ci_strcmp(argv
[0], "short") || !ci_strcmp(argv
[0], "s"))
1728 type
= HSTAT_ACCOUNT_SHORT
;
1731 else if (!ci_strcmp(argv
[0], "long") || !ci_strcmp(argv
[0], "l"))
1733 type
= HSTAT_ACCOUNT_LONG
;
1739 if (sscanf(argv
[0], "%d", &days
))
1741 if (days
< 0 || days
> 7)
1743 helpmod_reply(sender
, returntype
, "Can not show user statistics: Expected integer between [0, 7]");
1753 if (sscanf(argv
[0], "%d", &weeks
))
1755 if (weeks
< 0 || weeks
> 10)
1757 helpmod_reply(sender
, returntype
, "Can not show user statistics: Expected integer between [0, 10]");
1766 for (ptr
= target
->stats
;ptr
;ptr
= ptr
->next
)
1767 if (ptr
->hchan
== hchan
)
1772 helpmod_reply(sender
, returntype
, "Can not show user statistics: User %s has no statistics for channel %s", target
->name
->content
, hchannel_get_name(hchan
));
1776 if (!days
&& !weeks
)
1779 helpmod_reply(sender
, returntype
, "Statistics for user %s on channel %s", target
->name
->content
, hchannel_get_name(hchan
));
1783 helpmod_reply(sender
, returntype
, "Last %d day%s", days
, (days
==1)?"":"s");
1784 helpmod_reply(sender
, returntype
, "%s", hstat_header(type
));
1785 for (i
=0;i
<days
;i
++)
1787 stat_entry
= &ptr
->week
[(tstruct
->tm_wday
- i
+ 7) % 7];
1788 helpmod_reply(sender
, returntype
, "%s", hstat_account_print(stat_entry
, type
));
1794 helpmod_reply(sender
, returntype
, "Last %d week%s", weeks
, (weeks
==1)?"":"s");
1795 helpmod_reply(sender
, returntype
, "%s", hstat_header(type
));
1796 for (i
=0;i
<weeks
;i
++)
1798 stat_entry
= &ptr
->longterm
[(hstat_week() - i
+ 10) % 10];
1799 helpmod_reply(sender
, returntype
, "%s", hstat_account_print(stat_entry
, type
));
1804 static void helpmod_cmd_chanstats (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
1807 hstat_channel
*channel_stats
;
1808 hstat_channel_entry
*stat_entry
;
1810 time_t timer
= time(NULL
);
1811 struct tm
*tstruct
= localtime(&timer
);
1814 int type
= HSTAT_CHANNEL_SHORT
;
1821 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
1825 helpmod_reply(sender
, returntype
, "Can not show channel statistics: Channel not defined or not found");
1831 if (!ci_strcmp(argv
[0], "short") || !ci_strcmp(argv
[0], "s"))
1833 type
= HSTAT_CHANNEL_SHORT
;
1836 else if (!ci_strcmp(argv
[0], "long") || !ci_strcmp(argv
[0], "l"))
1838 type
= HSTAT_CHANNEL_LONG
;
1844 if (sscanf(argv
[0], "%d", &days
))
1846 if (days
< 0 || days
> 7)
1848 helpmod_reply(sender
, returntype
, "Can not show channel statistics: Expected integer between [0, 7]");
1858 if (sscanf(argv
[0], "%d", &weeks
))
1860 if (weeks
< 0 || weeks
> 10)
1862 helpmod_reply(sender
, returntype
, "Can not show channel statistics: Expected integer between [0, 10]");
1872 channel_stats
= hchan
->stats
;
1874 if (!days
&& !weeks
)
1877 helpmod_reply(sender
, returntype
, "Statistics for channel %s", hchannel_get_name(hchan
));
1881 helpmod_reply(sender
, returntype
, "Last %d day%s", days
, (days
==1)?"":"s");
1882 helpmod_reply(sender
, returntype
, "%s", hstat_header(type
));
1883 for (i
=0;i
<days
;i
++) /* latest week */
1885 stat_entry
= &hchan
->stats
->week
[(tstruct
->tm_wday
- i
+ 7) % 7];
1886 helpmod_reply(sender
, returntype
, "%s", hstat_channel_print(stat_entry
, type
));
1892 helpmod_reply(sender
, returntype
, "Last %d week%s", weeks
, (weeks
==1)?"":"s");
1893 helpmod_reply(sender
, returntype
, "%s", hstat_header(type
));
1894 for (i
=0;i
<weeks
;i
++) /* latest weeks */
1896 stat_entry
= &hchan
->stats
->longterm
[(hstat_week() - i
+ 10) % 10];
1897 helpmod_reply(sender
, returntype
, "%s", hstat_channel_print(stat_entry
, type
));
1902 static void helpmod_cmd_activestaff (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
1905 hstat_accounts_array arr
;
1906 hlevel lvl
= H_OPER
;
1914 helpmod_reply(sender
, returntype
, "Can not list active staff: Channel not specified or not found");
1920 if (!ci_strcmp(argv
[0], "opers") || !ci_strcmp(argv
[0], "o"))
1925 else if (!ci_strcmp(argv
[0], "staff") || !ci_strcmp(argv
[0], "s"))
1934 if (!ci_strcmp(argv
[0], "active") || !ci_strcmp(argv
[0], "a"))
1939 else if (!ci_strcmp(argv
[0], "inactive") || !ci_strcmp(argv
[0], "i"))
1946 arr
= create_hstat_account_array(hchan
, lvl
);
1948 helpmod_reply(sender
, returntype
, "%s %ss for channel %s", listtype
?"Inactive":"Active", hlevel_name(lvl
), hchannel_get_name(hchan
));
1952 for (i
=0;i
< arr
.arrlen
&& arr
.array
[i
].prime_time_spent
> H_ACTIVE_LIMIT
;i
++)
1953 helpmod_reply(sender
, returntype
, "#%-2d %-20s %-20s %-20s", i
+1,((haccount
*)(arr
.array
[i
].owner
))->name
->content
, helpmod_strtime(arr
.array
[i
].prime_time_spent
), helpmod_strtime(arr
.array
[i
].time_spent
));
1956 for (i
=arr
.arrlen
-1;i
>= 0 && arr
.array
[i
].prime_time_spent
< H_ACTIVE_LIMIT
;i
--)
1957 helpmod_reply(sender
, returntype
, "#%-2d %-20s %-20s %-20s", (arr
.arrlen
- i
),((haccount
*)(arr
.array
[i
].owner
))->name
->content
, helpmod_strtime(arr
.array
[i
].prime_time_spent
), helpmod_strtime(arr
.array
[i
].time_spent
));
1964 static void helpmod_cmd_top10 (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
1967 hstat_accounts_array arr
;
1968 hlevel lvl
= H_OPER
;
1973 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
1977 helpmod_reply(sender
, returntype
, "Can not list channel Top10: Channel not specified or not found");
1983 if (!ci_strcmp(argv
[0], "opers") || !ci_strcmp(argv
[0], "o"))
1985 else if (!ci_strcmp(argv
[0], "staff") || !ci_strcmp(argv
[0], "s"))
1991 if (sscanf(argv
[1], "%d", &tmp
) && (tmp
>= 10) && (tmp
<= 50))
1995 arr
= create_hstat_account_array(hchan
, lvl
);
1997 helpmod_reply(sender
, returntype
, "Top%d most active %ss of channel %s", top_n
, hlevel_name(lvl
), hchannel_get_name(hchan
));
1998 for (i
=0;i
< arr
.arrlen
&& i
< top_n
;i
++)
1999 helpmod_reply(sender
, returntype
, "#%-2d %-20s %-20s %-20s",i
+1,((haccount
*)(arr
.array
[i
].owner
))->name
->content
, helpmod_strtime(arr
.array
[i
].prime_time_spent
), helpmod_strtime(arr
.array
[i
].time_spent
));
2004 static void helpmod_cmd_report (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
2006 hchannel
*hchan
, *target
;
2009 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
2011 if (hchan
!= NULL
&& (argc
== 2))
2013 hchan
= hchannel_get_by_name(argv
[0]);
2019 helpmod_reply(sender
, returntype
, "Can not view or set channel reporting: Channel not defined or not found");
2024 if (hchan
->report_to
== NULL
|| !hchannel_is_valid(hchan
->report_to
))
2025 helpmod_reply(sender
, returntype
, "Channel %s is not reported anywhere (%s)", hchannel_get_name(hchan
), hchannel_get_state(hchan
, H_REPORT
));
2027 helpmod_reply(sender
, returntype
, "Channel %s is reported to channel %s (%s)", hchannel_get_name(hchan
), hchannel_get_name(hchan
->report_to
), hchannel_get_state(hchan
, H_REPORT
));
2030 if ((target
= hchannel_get_by_name(argv
[0])) == NULL
)
2032 helpmod_reply(sender
, returntype
, "Can not set channel reporting: Channel %s not found", argv
[0]);
2035 hchan
->report_to
= target
;
2036 helpmod_reply(sender
, returntype
, "Channel %s is now reported to channel %s (%s)", hchannel_get_name(hchan
), hchannel_get_name(hchan
->report_to
), hchannel_get_state(hchan
, H_REPORT
));
2039 static void helpmod_cmd_mode(huser
*sender
, channel
* returntype
, int change
, char* ostr
, int argc
, char *argv
[])
2042 huser_channel
*huserchan
;
2048 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
2052 helpmod_reply(sender
, returntype
, "Can not change mode: Channel not specified or not found");
2056 if (argc
==0) /* for a simple opme */
2059 argv
[0] = sender
->real_user
->nick
;
2062 if (argc
> H_CMD_MAX_ARGS
)
2063 argc
= H_CMD_MAX_ARGS
;
2065 for (i
=0;i
<argc
;i
++)
2067 husr
= huser_get(getnickbynick(argv
[i
]));
2070 helpmod_reply(sender
, returntype
, "Can not change mode: User %s not found", argv
[i
], hchannel_get_name(hchan
));
2073 huserchan
= huser_on_channel(husr
, hchan
);
2074 if (huserchan
== NULL
)
2076 helpmod_reply(sender
, returntype
, "Can not change mode: User %s it not on channel %s", husr
->real_user
->nick
, hchannel_get_name(hchan
));
2085 for (j
=0;j
< hchan
->real_channel
->users
->hashsize
;j
++)
2086 if (getnickbynumeric(hchan
->real_channel
->users
->content
[j
]) == husr
->real_user
)
2088 if ((huserchan
->flags
& HCUMODE_OP
) && !(hchan
->real_channel
->users
->content
[j
] & CUMODE_OP
))
2090 huserchan
->flags
&= ~HCUMODE_OP
;
2091 Error("helpmod", ERR_ERROR
, "userchannelmode inconsistency (+o when should be -o)");
2093 if (huserchan
->flags
& HCUMODE_OP
)
2095 helpmod_reply(sender
, returntype
, "Can not change mode: User %s is already +o on channel %s", husr
->real_user
->nick
, hchannel_get_name(hchan
));
2098 if (huser_get_level(husr
) < H_STAFF
)
2100 helpmod_reply(sender
, returntype
, "Can not change mode: User %s is not allowed to have +o on channel %s", husr
->real_user
->nick
, hchannel_get_name(hchan
));
2103 helpmod_channick_modes(husr
, hchan
, MC_OP
, HLAZY
);
2109 for (j
=0;j
< hchan
->real_channel
->users
->hashsize
;j
++)
2110 if (getnickbynumeric(hchan
->real_channel
->users
->content
[j
]) == husr
->real_user
)
2112 if (!(huserchan
->flags
& HCUMODE_OP
) && (hchan
->real_channel
->users
->content
[j
] & CUMODE_OP
))
2114 huserchan
->flags
|= HCUMODE_OP
;
2115 Error("helpmod", ERR_ERROR
, "userchannelmode inconsistency (-o when should be +o)");
2117 if (!(huserchan
->flags
& HCUMODE_OP
))
2119 helpmod_reply(sender
, returntype
, "Can not change mode: User %s is already -o on channel %s", husr
->real_user
->nick
, hchannel_get_name(hchan
));
2122 if (huser_get_level(husr
) > huser_get_level(sender
))
2124 helpmod_reply(sender
, returntype
, "Can not change mode: User %s is meant to have +o on channel %s", husr
->real_user
->nick
, hchannel_get_name(hchan
));
2127 helpmod_channick_modes(husr
, hchan
, MC_DEOP
, HLAZY
);
2133 for (j
=0;j
< hchan
->real_channel
->users
->hashsize
;j
++)
2134 if (getnickbynumeric(hchan
->real_channel
->users
->content
[j
]) == husr
->real_user
)
2136 if ((huserchan
->flags
& HCUMODE_VOICE
) && !(hchan
->real_channel
->users
->content
[j
] & CUMODE_VOICE
))
2138 huserchan
->flags
&= ~HCUMODE_VOICE
;
2139 Error("helpmod", ERR_ERROR
, "userchannelmode inconsistency (+v when should be -v)");
2141 if (huserchan
->flags
& HCUMODE_VOICE
)
2143 helpmod_reply(sender
, returntype
, "Can not change mode: User %s is already +v on channel %s", husr
->real_user
->nick
, hchannel_get_name(hchan
));
2146 helpmod_channick_modes(husr
, hchan
, MC_VOICE
, HLAZY
);
2152 for (j
=0;j
< hchan
->real_channel
->users
->hashsize
;j
++)
2153 if (getnickbynumeric(hchan
->real_channel
->users
->content
[j
]) == husr
->real_user
)
2155 if (!(huserchan
->flags
& HCUMODE_VOICE
) && (hchan
->real_channel
->users
->content
[j
] & CUMODE_VOICE
))
2157 huserchan
->flags
|= HCUMODE_VOICE
;
2158 Error("helpmod", ERR_ERROR
, "userchannelmode inconsistency (-v when should be +v)");
2160 if (!(huserchan
->flags
& HCUMODE_VOICE
))
2162 helpmod_reply(sender
, returntype
, "Can not change mode: User %s is already -v on channel %s", husr
->real_user
->nick
, hchannel_get_name(hchan
));
2165 helpmod_channick_modes(husr
, hchan
, MC_DEVOICE
, HLAZY
);
2172 static void helpmod_cmd_op (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[]) { helpmod_cmd_mode(sender
, returntype
, H_CMD_OP
, ostr
, argc
, argv
); }
2173 static void helpmod_cmd_deop (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[]) { helpmod_cmd_mode(sender
, returntype
, H_CMD_DEOP
, ostr
, argc
, argv
); }
2174 static void helpmod_cmd_voice (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[]) { helpmod_cmd_mode(sender
, returntype
, H_CMD_VOICE
, ostr
, argc
, argv
); }
2175 static void helpmod_cmd_devoice (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[]) { helpmod_cmd_mode(sender
, returntype
, H_CMD_DEVOICE
, ostr
, argc
, argv
); }
2177 static void helpmod_cmd_invite (huser
*sender
, channel
*returntype
, char* arg
, int argc
, char *argv
[])
2184 helpmod_reply(sender
, returntype
, "Can not invite: Channel not defined or not found");
2188 if (huser_get_level(sender
) == H_PEON
)
2191 hchan
= hchannel_get_by_name(argv
[0]);
2194 helpmod_reply(sender
, returntype
, "Can not invite: Unknown channel %s", argv
[0]);
2197 /* if tickets don't work, it's better that the user doesn't know that the channel really exists */
2198 if (!(hchan
->flags
& H_REQUIRE_TICKET
))
2200 helpmod_reply(sender
, returntype
, "Can not invite: Unknown channel %s", argv
[0]);
2203 htick
= hticket_get(sender
->real_user
->authname
, hchan
);
2207 helpmod_reply(sender
, returntype
, "Can not invite: You do not have an invite ticket for channel %s", argv
[0]);
2211 if (nickbanned(sender
->real_user
, hchan
->real_channel
))
2213 helpmod_reply(sender
, returntype
, "Can not invite: You are banned from channel %s", argv
[0]);
2217 helpmod_invite(hchan
, sender
);
2218 helpmod_reply(sender
, returntype
, "Invited you to channel %s", hchannel_get_name(hchan
));
2222 if (argc
> H_CMD_MAX_ARGS
)
2223 argc
= H_CMD_MAX_ARGS
;
2225 for (i
= 0;i
< argc
; i
++)
2227 hchan
= hchannel_get_by_name(argv
[0]);
2230 helpmod_reply(sender
, returntype
, "Can not invite: Unknown channel %s", argv
[i
]);
2233 if (!(hchannel_authority(hchan
, sender
) || hticket_get(sender
->real_user
->authname
, hchan
)))
2235 helpmod_reply(sender
, returntype
, "Sorry, channel %s is oper only", hchannel_get_name(hchan
));
2238 if (huser_on_channel(sender
, hchan
) != NULL
)
2240 helpmod_reply(sender
, returntype
, "Can not invite: You are already on channel %s", hchannel_get_name(hchan
));
2243 helpmod_invite(hchan
, sender
);
2244 helpmod_reply(sender
, returntype
, "Invited you to channel %s", hchannel_get_name(hchan
));
2248 static void helpmod_cmd_ticket (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
2250 int expiration
= HTICKET_EXPIRATION_TIME
;
2257 helpmod_reply(sender
, returntype
, "Can not issue a ticket: Channel not specified");
2261 hchan
= hchannel_get_by_name(argv
[0]);
2264 helpmod_reply(sender
, returntype
, "Can not issue a ticket: Unknown channel %s", argv
[0]);
2267 if (!(hchan
->flags
& H_REQUIRE_TICKET
))
2269 helpmod_reply(sender
, returntype
, "Can not issue a ticket: Tickets are not enabled for channel %s", argv
[0]);
2274 helpmod_reply(sender
, returntype
, "Can not issue a ticket: Target user not specified");
2278 husr
= huser_get(getnickbynick(argv
[1]));
2281 helpmod_reply(sender
, returntype
, "Can not issue a ticket: Unknown user %s", argv
[1]);
2284 if (!IsAccount(husr
->real_user
))
2286 helpmod_reply(sender
, returntype
, "Can not issue a ticket: User %s is not authed", argv
[1]);
2289 if (huser_get_level(husr
) < H_PEON
)
2291 helpmod_reply(sender
, returntype
, "Can not issue a ticket: User %s is considered improper and not worthy of a ticket", argv
[1]);
2297 tmp
= helpmod_read_strtime(argv
[2]);
2298 if (tmp
> HDEF_m
&& tmp
< 2 * HDEF_M
)
2302 htick
= hticket_get(husr
->real_user
->authname
, hchan
);
2305 htick
->time_expiration
= time(NULL
) + expiration
;
2307 hticket_add(husr
->real_user
->authname
, time(NULL
) + expiration
, hchan
);
2309 helpmod_reply(sender
, returntype
, "Issued an invite ticket to user %s for channel %s expiring in %s", husr
->real_user
->nick
, hchannel_get_name(hchan
), helpmod_strtime(expiration
));
2310 helpmod_reply(husr
, NULL
, "You have been issued an invite ticket for channel %s. This ticket is valid for a period of %s. You can use my invite command to get to the channel now. Type /msg %s invite %s",hchannel_get_name(hchan
), helpmod_strtime(HTICKET_EXPIRATION_TIME
), helpmodnick
->nick
, hchannel_get_name(hchan
));
2313 static void helpmod_cmd_resolve (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
2322 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
2324 if (argc
> H_CMD_MAX_ARGS
)
2325 argc
= H_CMD_MAX_ARGS
;
2329 helpmod_reply(sender
, returntype
, "Can not resolve a ticket: The channel is not specified");
2333 for (i
= 0;i
< argc
;i
++)
2335 if (argv
[i
][0] == '#')
2337 htick
= hticket_get(&argv
[i
][1], hchan
);
2340 helpmod_reply(sender
, returntype
, "Can not resolve a ticket: Authname %s does not have a ticket for channel %s", &argv
[i
][1], hchannel_get_name(hchan
));
2343 hticket_del(htick
, hchan
);
2344 helpmod_reply(sender
, returntype
, "Resolved authname %s's ticket for channel %s", &argv
[i
][1], hchannel_get_name(hchan
));
2348 husr
= huser_get(getnickbynick(argv
[i
]));
2351 helpmod_reply(sender
, returntype
, "Can not resolve a ticket: User %s not found", argv
[i
]);
2354 if (!IsAccount(husr
->real_user
))
2356 helpmod_reply(sender
, returntype
, "Can not resolve a ticket: User %s is not authed", argv
[i
]);
2359 htick
= hticket_get(husr
->real_user
->authname
,hchan
);
2362 helpmod_reply(sender
, returntype
, "Can not resolve a ticket: User %s does not have a ticket for channel %s", argv
[i
], hchannel_get_name(hchan
));
2365 hticket_del(htick
, hchan
);
2366 helpmod_reply(sender
, returntype
, "Resolved user %s's ticket for channel %s", argv
[i
], hchannel_get_name(hchan
));
2371 static void helpmod_cmd_tickets (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
2379 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
2383 helpmod_reply(sender
, returntype
, "Can not list tickets: Channel not defined or not found");
2387 if (!(hchan
->flags
& H_REQUIRE_TICKET
))
2389 helpmod_reply(sender
, returntype
, "Can not list tickets: Channel %s does not use the ticket system", hchannel_get_name(hchan
));
2393 htick
= hchan
->htickets
;
2397 helpmod_reply(sender
, returntype
, "Channel %s has no valid tickets", hchannel_get_name(hchan
));
2401 helpmod_reply(sender
, returntype
, "Valid tickets for channel %s", hchannel_get_name(hchan
));
2403 for (i
= 0;htick
;htick
= htick
->next
, i
++)
2404 helpmod_reply(sender
, returntype
, "%4d %16s %48s", i
, htick
->authname
, helpmod_strtime(time(NULL
) - htick
->time_expiration
));
2406 helpmod_reply(sender
, returntype
, "Done listing tickets. Channel %s had %d valid ticket%s", hchannel_get_name(hchan
), i
, (i
==1)?"":"s");
2409 static void helpmod_cmd_showticket (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
2418 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
2420 if (argc
> H_CMD_MAX_ARGS
)
2421 argc
= H_CMD_MAX_ARGS
;
2425 helpmod_reply(sender
, returntype
, "Can not show the ticket: Channel not defined or not found");
2428 for (i
= 0;i
< argc
;i
++)
2430 husr
= huser_get(getnickbynick(argv
[i
]));
2433 helpmod_reply(sender
, returntype
, "Can not show the ticket: User %s not found", argv
[i
]);
2436 if (!IsAccount(husr
->real_user
))
2438 helpmod_reply(sender
, returntype
, "Can not show the ticket: User %s is not authed", argv
[i
]);
2441 htick
= hticket_get(husr
->real_user
->authname
, hchan
);
2444 helpmod_reply(sender
, returntype
, "Can not show the ticket: User %s does not have a valid ticket for channel %s", argv
[i
], hchannel_get_name(hchan
));
2447 helpmod_reply(sender
, returntype
, "User %s has a ticket for channel %s expiring in %s", argv
[i
], hchannel_get_name(hchan
), helpmod_strtime(htick
->time_expiration
- time(NULL
)));
2451 static int helpmod_cmd_termstats_sort(const void *left
, const void *right
)
2453 return (*((hterm
**)right
))->usage
- (*((hterm
**)left
))->usage
;
2456 static void helpmod_cmd_termstats(huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
2458 hterm
**arr
, *origin
;
2467 origin
= hchan
->channel_hterms
;
2469 count
= hterm_count(origin
);
2473 helpmod_reply(sender
, returntype
, "Can not list term usage statistics: No terms available");
2477 arr
= malloc(sizeof(hterm
*) * count
);
2478 assert(arr
!= NULL
);
2480 for (i
=0;i
< count
;i
++,origin
= origin
->next
)
2483 qsort(arr
, count
, sizeof(hterm
*), helpmod_cmd_termstats_sort
);
2486 helpmod_reply(sender
, returntype
, "10 Most used global terms");
2488 helpmod_reply(sender
, returntype
, "10 Most used terms for channel %s", hchannel_get_name(hchan
));
2490 for (i
=0;i
< 10 && i
< count
;i
++)
2491 helpmod_reply(sender
, returntype
, "#%02d %32s :%d",i
+1, arr
[i
]->name
->content
,arr
[i
]->usage
);
2496 static int helpmod_cmd_checkchannel_nicksort(const void *left
, const void *right
)
2498 return ci_strcmp(getnickbynumeric(*((unsigned long*)left
))->nick
, getnickbynumeric(*((unsigned long*)right
))->nick
);
2501 static int helpmod_cmd_checkchannel_statussort(const void *left
, const void *right
)
2503 int level1
= 0, level2
= 0;
2505 if (*((unsigned long*)left
) & CUMODE_VOICE
)
2507 if (*((unsigned long*)left
) & CUMODE_OP
)
2510 if (*((unsigned long*)right
) & CUMODE_VOICE
)
2512 if (*((unsigned long*)right
) & CUMODE_OP
)
2515 return level2
- level1
;
2518 static void helpmod_cmd_checkchannel(huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
2522 int i
, j
, nick_count
= 0, authed_count
= 0, o_limit
= 0, v_limit
= 0, summary_only
= 0;
2523 unsigned long *numeric_array
;
2527 helpmod_reply(sender
, returntype
, "Can not check channel: Channel not defined");
2531 chan
= findchannel(argv
[0]);
2534 helpmod_reply(sender
, returntype
, "Can not check channel: Channel %s not found", argv
[0]);
2537 if (argc
> 1 && !ci_strcmp(argv
[1], "summary"))
2540 /* first pass - verify validity and count nicks */
2541 for (i
=0;i
< chan
->users
->hashsize
;i
++)
2543 nck
= getnickbynumeric(chan
->users
->content
[i
]);
2544 if (!nck
) /* it's a hash, not an array */
2552 if (IsOper(nck
) && strlen(nck
->nick
) > 1)
2554 helpmod_reply(sender
, returntype
, "Can not check channel: Permission denied. Channel %s has an oper on it", argv
[0]);
2559 numeric_array
= (unsigned long*)malloc(nick_count
* sizeof(unsigned long));
2561 /* second pass - construct array */
2562 for (i
=0,j
=0;i
< chan
->users
->hashsize
;i
++)
2564 if (getnickbynumeric(chan
->users
->content
[i
]) == NULL
) /* it's a hash, not an array */
2567 numeric_array
[j
++] = chan
->users
->content
[i
];
2570 qsort(numeric_array
, nick_count
, sizeof(unsigned long), helpmod_cmd_checkchannel_statussort
);
2572 /* third pass - find status boundaries */
2574 for (;o_limit
< nick_count
&& numeric_array
[o_limit
] & CUMODE_OP
; o_limit
++);
2576 for(v_limit
= o_limit
; (v_limit
< nick_count
) && numeric_array
[v_limit
] & CUMODE_VOICE
; v_limit
++);
2579 helpmod_reply(sender
, returntype
, "Information on channel %s", argv
[0]);
2580 helpmod_reply(sender
, returntype
, "Channel created %s ago", helpmod_strtime(time(NULL
) - chan
->timestamp
));
2581 if (!IsKey(chan
) && !IsInviteOnly(chan
))
2582 helpmod_reply(sender
, returntype
, "Channel topic: %s", chan
->topic
?chan
->topic
->content
:"Not set");
2583 helpmod_reply(sender
, returntype
, "Channel modes: %s", printflags(chan
->flags
, cmodeflags
));
2586 /* sort the sub arrays */
2589 qsort(numeric_array
, o_limit
, sizeof(unsigned long), helpmod_cmd_checkchannel_nicksort
);
2590 if (v_limit
- o_limit
> 0)
2591 qsort(numeric_array
+ o_limit
, v_limit
- o_limit
, sizeof(unsigned long), helpmod_cmd_checkchannel_nicksort
);
2592 if (nick_count
- v_limit
> 0)
2593 qsort(numeric_array
+ v_limit
, nick_count
- v_limit
, sizeof(unsigned long), helpmod_cmd_checkchannel_nicksort
);
2595 /* fourth pass - print results */
2597 for (i
=0;i
< nick_count
;i
++)
2599 char buf
[256], status
;
2601 if (numeric_array
[i
] & CUMODE_OP
)
2603 else if (numeric_array
[i
] & CUMODE_VOICE
)
2608 visiblehostmask(getnickbynumeric(numeric_array
[i
]), buf
);
2609 if (IsAccount(getnickbynumeric(numeric_array
[i
])))
2610 helpmod_reply(sender
, returntype
, "%c%s (%s)", status
, buf
, getnickbynumeric(numeric_array
[i
])->authname
);//nick_array[i]->authname);
2612 helpmod_reply(sender
, returntype
, "%c%s", status
, buf
);
2615 helpmod_reply(sender
, returntype
, "Users: %d Clones: %d Opped: %d Voiced: %d Authed: %3.0f%%", nick_count
, nick_count
- countuniquehosts(chan
), o_limit
, v_limit
- o_limit
, ((float)authed_count
/ (float)nick_count
) * 100.0);
2617 free(numeric_array
);
2620 static void helpmod_cmd_statsdump (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
2622 haccount
*hacc
= haccounts
;
2626 helpmod_reply(sender
, returntype
, "Account statistics");
2627 for (;hacc
;hacc
= hacc
->next
)
2628 for (ptr
= hacc
->stats
;ptr
;ptr
= ptr
->next
)
2630 helpmod_reply(sender
, returntype
, "Account %s channel %s short-term", hacc
->name
->content
, hchannel_get_name(ptr
->hchan
));
2631 for (i
= 0;i
< 7;i
++)
2632 helpmod_reply(sender
, returntype
, "%d %d %d %d", ptr
->week
[i
].time_spent
, ptr
->week
[i
].prime_time_spent
, ptr
->week
[i
].lines
, ptr
->week
[i
].words
);
2633 helpmod_reply(sender
, returntype
, "Account %s channel %s long-term", hacc
->name
->content
, hchannel_get_name(ptr
->hchan
));
2634 for (i
= 0;i
< 10;i
++)
2635 helpmod_reply(sender
, returntype
, "%d %d %d %d", ptr
->longterm
[i
].time_spent
, ptr
->longterm
[i
].prime_time_spent
, ptr
->longterm
[i
].lines
, ptr
->longterm
[i
].words
);
2639 static void helpmod_cmd_statsrepair (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
2641 haccount
*hacc
= haccounts
;
2645 helpmod_reply(sender
, returntype
, "Repairing account statistics");
2646 for (;hacc
;hacc
= hacc
->next
)
2647 for (ptr
= hacc
->stats
;ptr
;ptr
= ptr
->next
)
2649 for (i
= 0;i
< 7;i
++)
2651 if (ptr
->week
[i
].time_spent
> HDEF_d
)
2653 ptr
->week
[i
].time_spent
= 0;
2654 helpmod_reply(sender
, returntype
, "repaired short term TimeSpent %s @ %s : Greater than one day",hacc
->name
->content
, hchannel_get_name(ptr
->hchan
));
2656 if (ptr
->week
[i
].time_spent
< 0)
2658 ptr
->week
[i
].time_spent
= 0;
2659 helpmod_reply(sender
, returntype
, "repaired short term TimeSpent %s @ %s : Less than zero",hacc
->name
->content
, hchannel_get_name(ptr
->hchan
));
2662 if (ptr
->week
[i
].prime_time_spent
> HDEF_d
)
2664 ptr
->week
[i
].prime_time_spent
= 0;
2665 helpmod_reply(sender
, returntype
, "repaired short term PrimeTimeSpent %s @ %s : Greater than one day",hacc
->name
->content
, hchannel_get_name(ptr
->hchan
));
2667 if (ptr
->week
[i
].prime_time_spent
< 0)
2669 ptr
->week
[i
].prime_time_spent
= 0;
2670 helpmod_reply(sender
, returntype
, "repaired short term PrimeTimeSpent %s @ %s : Less than zero",hacc
->name
->content
, hchannel_get_name(ptr
->hchan
));
2673 if (ptr
->week
[i
].lines
> 10000)
2675 ptr
->week
[i
].lines
= 0;
2676 helpmod_reply(sender
, returntype
, "repaired short term Lines %s @ %s : Greater than 10000",hacc
->name
->content
, hchannel_get_name(ptr
->hchan
));
2678 if (ptr
->week
[i
].lines
< 0)
2680 ptr
->week
[i
].lines
= 0;
2681 helpmod_reply(sender
, returntype
, "repaired short term Lines %s @ %s : Less than zero",hacc
->name
->content
, hchannel_get_name(ptr
->hchan
));
2684 if (ptr
->week
[i
].words
> 50000)
2686 ptr
->week
[i
].words
= 0;
2687 helpmod_reply(sender
, returntype
, "repaired short term Words %s @ %s : Greater than 50000",hacc
->name
->content
, hchannel_get_name(ptr
->hchan
));
2689 if (ptr
->week
[i
].words
< 0)
2691 ptr
->week
[i
].words
= 0;
2692 helpmod_reply(sender
, returntype
, "repaired short term Words %s @ %s : Less than zero",hacc
->name
->content
, hchannel_get_name(ptr
->hchan
));
2695 for (i
= 0;i
< 10;i
++)
2697 if (ptr
->longterm
[i
].time_spent
> HDEF_w
)
2699 ptr
->longterm
[i
].time_spent
= 0;
2700 helpmod_reply(sender
, returntype
, "repaired long term TimeSpent %s @ %s : Greater than one week",hacc
->name
->content
, hchannel_get_name(ptr
->hchan
));
2702 if (ptr
->longterm
[i
].time_spent
< 0)
2704 ptr
->longterm
[i
].time_spent
= 0;
2705 helpmod_reply(sender
, returntype
, "repaired long term TimeSpent %s @ %s : Less than zero",hacc
->name
->content
, hchannel_get_name(ptr
->hchan
));
2708 if (ptr
->longterm
[i
].prime_time_spent
> HDEF_w
)
2710 ptr
->longterm
[i
].prime_time_spent
= 0;
2711 helpmod_reply(sender
, returntype
, "repaired long term PrimeTimeSpent %s @ %s : Greater than one week",hacc
->name
->content
, hchannel_get_name(ptr
->hchan
));
2713 if (ptr
->longterm
[i
].prime_time_spent
< 0)
2715 ptr
->longterm
[i
].prime_time_spent
= 0;
2716 helpmod_reply(sender
, returntype
, "repaired long term PrimeTimeSpent %s @ %s : Less than zero",hacc
->name
->content
, hchannel_get_name(ptr
->hchan
));
2719 if (ptr
->longterm
[i
].lines
> 50000)
2721 ptr
->longterm
[i
].lines
= 0;
2722 helpmod_reply(sender
, returntype
, "repaired long term Lines %s @ %s : Greater than 50000",hacc
->name
->content
, hchannel_get_name(ptr
->hchan
));
2724 if (ptr
->longterm
[i
].lines
< 0)
2726 ptr
->longterm
[i
].lines
= 0;
2727 helpmod_reply(sender
, returntype
, "repaired long term Lines %s @ %s : Less than zero",hacc
->name
->content
, hchannel_get_name(ptr
->hchan
));
2730 if (ptr
->longterm
[i
].words
> 50000)
2732 ptr
->longterm
[i
].words
= 0;
2733 helpmod_reply(sender
, returntype
, "repaired long term Words %s @ %s : Greater than 50000",hacc
->name
->content
, hchannel_get_name(ptr
->hchan
));
2735 if (ptr
->longterm
[i
].words
< 0)
2737 ptr
->longterm
[i
].words
= 0;
2738 helpmod_reply(sender
, returntype
, "repaired long term Words %s @ %s : Less than zero",hacc
->name
->content
, hchannel_get_name(ptr
->hchan
));
2742 helpmod_reply(sender
, returntype
, "Account statistics repaired");
2746 static void helpmod_cmd_statsreset (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
2748 haccount
*hacc
= haccounts
;
2751 int i
, short_del
, long_del
;
2755 helpmod_reply(sender
, returntype
, "Insufficient parameters");
2759 if (sscanf(argv
[0], "%d", &short_del
) == 0)
2761 helpmod_reply(sender
, returntype
, "Invalid parameter");
2764 if (sscanf(argv
[1], "%d", &long_del
) == 0)
2766 helpmod_reply(sender
, returntype
, "Invalid parameter");
2770 for (;hacc
;hacc
= hacc
->next
)
2771 for (ptr
= hacc
->stats
;ptr
;ptr
= ptr
->next
)
2773 for (i
= 1;i
< short_del
+ 1;i
++)
2774 HSTAT_ACCOUNT_ZERO(ptr
->week
[(hstat_day() + i
) % 7]);
2775 for (i
= 1;i
< long_del
+ 1;i
++)
2776 HSTAT_ACCOUNT_ZERO(ptr
->longterm
[(hstat_week() + i
) % 10]);
2779 for (hchan
= hchannels
;hchan
;hchan
= hchan
->next
)
2781 for (i
= 1;i
< short_del
+ 1;i
++)
2782 HSTAT_CHANNEL_ZERO(hchan
->stats
->week
[(hstat_day() + i
) % 7]);
2783 for (i
= 1;i
< long_del
+ 1;i
++)
2784 HSTAT_CHANNEL_ZERO(hchan
->stats
->longterm
[(hstat_week() + i
) % 10]);
2788 helpmod_reply(sender
, returntype
, "Statistics reset complete");
2791 static void helpmod_cmd_message (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
2797 helpmod_reply(sender
, returntype
, "Can not send a message: Insufficient arguments");
2800 hchan
= hchannel_get_by_name(argv
[0]);
2803 helpmod_reply(sender
, returntype
, "Can not send a message: Invalid channel %s", argv
[0]);
2807 helpmod_message_channel(hchan
, "(%s) %s", sender
->real_user
->nick
, ostr
);
2808 helpmod_reply(sender
, returntype
, "Message sent to %s", hchannel_get_name(hchan
));
2812 void helpmod_cmd_load (huser
*sender
, channel
*returntype
, char* arg
, int argc
, char *argv
[])
2815 char buf
[128] = "helpmod/default";
2818 helpmod_reply(sender
, returntype
, "Warning: No config specified, using default");
2821 if (strlen(arg
) >= 100)
2824 sprintf(buf
, "helpmod/%s", arg
);
2827 if (!(tmp_file
= fopen(buf
, "rt")))
2829 helpmod_reply(sender
, returntype
, "File %s not found", buf
);
2835 helpmod_clear_aliases(&aliases
);
2836 helpmod_clear_all_entries();
2837 helpmod_init_entry(&helpmod_base
);
2838 huser_reset_states();
2839 helpmod_load_entries(buf
);
2840 strcpy(helpmod_db
, buf
);
2841 helpmod_reply(sender
, returntype
, "New config loaded and system reset");
2844 void helpmod_cmd_status (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
2846 helpmod_reply(sender
, returntype
, "HelpMod version %s (built %s, up %s)", HELPMOD_VERSION
, __DATE__
, helpmod_strtime(time(NULL
) - helpmod_startup_time
));
2847 helpmod_reply(sender
, returntype
, "Channels %d", hchannel_count());
2848 helpmod_reply(sender
, returntype
, "Accounts %d", haccount_count(H_ANY
));
2849 helpmod_reply(sender
, returntype
, "Users %d", huser_count());
2850 helpmod_reply(sender
, returntype
, "Help entries %d", helpmod_entry_count(helpmod_base
));
2851 helpmod_reply(sender
, returntype
, "Bans %d", hban_count());
2852 helpmod_reply(sender
, returntype
, "Help provided %d", helpmod_usage
);
2853 helpmod_reply(sender
, returntype
, "Tickets %d", hticket_count());
2856 /* not really a command, but help wants this one */
2857 void helpmod_send_help(huser
* target
)
2861 for (i
=0;i
<target
->state
->text_lines
;i
++)
2862 helpmod_reply(target
, NULL
, "%s", target
->state
->text
[i
]->content
);
2863 for (i
=0;i
<target
->state
->option_count
;i
++)
2864 helpmod_reply(target
, NULL
, "%d) %s", i
+1, target
->state
->options
[i
]->description
->content
);
2865 if (!target
->state
->option_count
)
2867 helpmod_reply(target
, NULL
, "This concludes the help for this topic, if you want to, you can restart the service with the 'help' command, or return to the previous entry by selecting 0");
2871 void helpmod_cmd_command(huser
* sender
, channel
* returntype
, char* arg
, int argc
, char *argv
[])
2874 char buffer
[512], *ptr
= argv
[0];
2879 helpmod_reply(sender
, returntype
, "Usage: command [name of the command] for a list see 'showcommands'");
2883 hcom
= hcommand_get(argv
[0], huser_get_level(sender
));
2887 helpmod_reply(sender
, returntype
, "Unknown command '%s'", argv
[0]);
2893 *ptr
= tolower(*ptr
);
2895 /* ? is handled like this because windows is shit */
2896 if (!ci_strcmp(argv
[0], "?"))
2897 sprintf(buffer
, "./helpmod2/commands/questionmark");
2899 sprintf(buffer
, "./helpmod2/commands/%s", argv
[0]);
2901 if ((in
= fopen(buffer
, "rt")) == NULL
)
2903 helpmod_reply(sender
, returntype
, "No help available for command '%s' (Ask strutsi to write it)", argv
[0]);
2909 fgets(buffer
, 512, in
);
2912 helpmod_reply(sender
, returntype
, "%s", buffer
);
2918 void helpmod_cmd_help (huser
* sender
, channel
* returntype
, char* arg
, int argc
, char *argv
[])
2922 if (helpmod_base
== NULL
|| !helpmod_base
->option_count
)
2924 helpmod_reply(sender
, returntype
, "The help service is not available at this time, please try again later");
2930 sender
->state
= helpmod_base
;
2931 helpmod_send_help(sender
);
2935 if (!sscanf(arg
, "%d", &hlp_target
))
2939 tmp
= helpmod_get_alias(arg
);
2941 helpmod_reply(sender
, returntype
, "Invalid value. Either use 'help' to restart or give an integer as a valid selection");
2944 sender
->state
= tmp
;
2945 helpmod_send_help(sender
);
2951 if (!helpmod_valid_selection(sender
->state
, hlp_target
))
2953 if (!sender
->state
->option_count
)
2954 helpmod_reply(sender
, returntype
, "There are no more options to choose from, you can restart the service by giving the 'help' command or select 0 to return to the previous entry");
2955 else if (!sender
->state
->parent
)
2956 helpmod_reply(sender
, returntype
, "Bad selection, please enter your selection as an integer from %d to %d", 1, sender
->state
->option_count
);
2958 helpmod_reply(sender
, returntype
, "Bad selection, please enter your selection as an integer from %d to %d, selecting 0 will take you to the previous entry", 1, sender
->state
->option_count
);
2962 sender
->state
= helpmod_make_selection(sender
->state
, hlp_target
);
2963 helpmod_send_help(sender
);
2967 /* adds all of the abowe to the system */
2968 void hcommands_add(void)
2970 hcommand_add("help", H_PEON
, helpmod_cmd_help
,"Offers the H1 type help");
2971 hcommand_add("status",H_OPER
, helpmod_cmd_status
,"Gives service status");
2972 hcommand_add("load", H_OPER
, helpmod_cmd_load
,"Loads a new help database");
2973 hcommand_add("aliases",H_STAFF
, helpmod_cmd_aliases
,"Lists all aliases currently in use");
2974 hcommand_add("showcommands", H_LAMER
, helpmod_cmd_showcommands
,"Lists all commands available to you");
2976 hcommand_add("improper", H_STAFF
, helpmod_cmd_improper
, "Sets the userlevel of the target to banned (lvl 0). Long term ban.");
2977 hcommand_add("peon", H_STAFF
, helpmod_cmd_peon
, "Sets the userlevel of the target to peon (lvl 1)");
2978 hcommand_add("trial", H_OPER
, helpmod_cmd_trial
, "Sets the userlevel of the target to trial staff (lvl 2)");
2979 hcommand_add("staff", H_OPER
, helpmod_cmd_staff
, "Sets the userlevel of the target to staff (lvl 3)");
2980 hcommand_add("oper", H_OPER
, helpmod_cmd_oper
, "Sets the userlevel of the target to oper (lvl 4)");
2981 hcommand_add("admin", H_ADMIN
, helpmod_cmd_admin
, "Sets the userlevel of the target to admin (lvl 5)");
2982 hcommand_add("deluser", H_OPER
, helpmod_cmd_deluser
, "Removes an account from " HELPMOD_NICK
);
2983 hcommand_add("listuser", H_STAFF
, helpmod_cmd_listuser
, "Lists user accounts of " HELPMOD_NICK
);
2985 hcommand_add("chanconf", H_STAFF
, helpmod_cmd_chanconf
, "Channel configuration");
2986 hcommand_add("acconf", H_TRIAL
, helpmod_cmd_acconf
, "Personalise " HELPMOD_NICK
" behaviour");
2987 hcommand_add("welcome", H_STAFF
, helpmod_cmd_welcome
, "Views or changes the channel welcome message");
2988 hcommand_add("censor", H_STAFF
, helpmod_cmd_censor
, "Handles the censored patterns for a channel");
2990 hcommand_add("queue", H_TRIAL
, helpmod_cmd_queue
, "Handles the channel queue");
2991 hcommand_add("next", H_TRIAL
, helpmod_cmd_next
, "Same as queue next");
2992 hcommand_add("done", H_TRIAL
, helpmod_cmd_done
, "Same as queue done");
2993 hcommand_add("enqueue", H_TRIAL
, helpmod_cmd_enqueue
, "Same as queue on or chanconf +3");
2994 hcommand_add("dequeue", H_TRIAL
, helpmod_cmd_dequeue
, "Same as queue off or chanconf -3");
2995 hcommand_add("autoqueue", H_TRIAL
, helpmod_cmd_autoqueue
, "Same as queue maintain");
2997 hcommand_add("?", H_PEON
, helpmod_cmd_term_find
, "Same as term find with multiple targets");
2998 hcommand_add("?+", H_TRIAL
, helpmod_cmd_term_find_plus
, "Multitarget term find which advances the queue");
2999 hcommand_add("?-", H_TRIAL
, helpmod_cmd_term_find_minus
, "Multitarget term find which removes users from queue");
3000 hcommand_add("term", H_STAFF
, helpmod_cmd_term
, "Term handling");
3002 hcommand_add("klingon", H_OPER
, helpmod_cmd_klingon
, "Phrases in klingon, both targeted and general");
3003 hcommand_add("out", H_STAFF
, helpmod_cmd_out
, "Sets the userlevel of the target to banned (lvl 0) for a short while");
3004 hcommand_add("kick", H_TRIAL
, helpmod_cmd_kick
, "Kicks user(s) from a channel");
3005 hcommand_add("ban", H_STAFF
, helpmod_cmd_ban
, "Handles global bans");
3006 hcommand_add("chanban", H_TRIAL
, helpmod_cmd_chanban
, "Handles channel bans");
3007 hcommand_add("dnmo", H_STAFF
, helpmod_cmd_dnmo
, "DoNotMessageOpers informs the luser of his mistake and sets him to the bottom of the queue");
3008 hcommand_add("lamercontrol", H_OPER
, helpmod_cmd_lamercontrol
, "Views or changes the channel lamercontrol profile");
3009 hcommand_add("topic", H_STAFF
, helpmod_cmd_topic
, "Handles the topic of a channel");
3010 hcommand_add("idlekick", H_OPER
, helpmod_cmd_idlekick
, "Views or sets the idle kick time");
3011 hcommand_add("everyoneout", H_STAFF
, helpmod_cmd_everyoneout
, "Removes all normal users from a channel and enforces +i");
3013 hcommand_add("stats", H_STAFF
, helpmod_cmd_stats
, "Shows staff activity statistics");
3014 hcommand_add("chanstats", H_STAFF
, helpmod_cmd_chanstats
, "Shows channel activity statistics");
3015 hcommand_add("activestaff", H_ADMIN
, helpmod_cmd_activestaff
, "Shows active staff members for a channel");
3016 hcommand_add("top10", H_STAFF
, helpmod_cmd_top10
, "Shows the top 10 most active staff");
3017 hcommand_add("report", H_OPER
, helpmod_cmd_report
, "Sets the channel where to report this channels statistics every 5 minutes");
3019 hcommand_add("whoami", H_LAMER
, helpmod_cmd_whoami
, "Tells who you are to " HELPMOD_NICK
);
3020 hcommand_add("whois", H_STAFF
, helpmod_cmd_whois
, "Tells you who someone is");
3021 hcommand_add("command", H_LAMER
, helpmod_cmd_command
, "Gives detailed information on a command");
3022 hcommand_add("addchan", H_ADMIN
, helpmod_cmd_addchan
, "Joins " HELPMOD_NICK
" to a new channel");
3023 hcommand_add("delchan", H_ADMIN
, helpmod_cmd_delchan
, "Removes " HELPMOD_NICK
" permanently from a channel");
3024 hcommand_add("seen", H_STAFF
, helpmod_cmd_seen
, "Tells when a specific user/account has had activity");
3026 hcommand_add("op", H_STAFF
, helpmod_cmd_op
, "Sets mode +o on channels");
3027 hcommand_add("deop", H_STAFF
, helpmod_cmd_deop
, "Sets mode -o on channels");
3028 hcommand_add("voice", H_TRIAL
, helpmod_cmd_voice
, "Sets mode +v on channels");
3029 hcommand_add("devoice", H_TRIAL
, helpmod_cmd_devoice
, "Sets mode -v on channels");
3031 hcommand_add("invite", H_PEON
, helpmod_cmd_invite
, "Invites you to a channel");
3032 hcommand_add("ticket", H_TRIAL
, helpmod_cmd_ticket
, "Gives a ticket to be used with invite");
3033 hcommand_add("resolve", H_STAFF
, helpmod_cmd_resolve
, "Resolves (deletes) a ticket");
3034 hcommand_add("tickets", H_STAFF
, helpmod_cmd_tickets
, "Lists all valid tickets for a channel");
3035 hcommand_add("showticket", H_STAFF
, helpmod_cmd_showticket
, "Shows the ticket for the user");
3037 hcommand_add("termstats", H_OPER
, helpmod_cmd_termstats
, "Lists usage statistics for terms");
3038 hcommand_add("checkchannel", H_STAFF
, helpmod_cmd_checkchannel
, "Shows channel information for any channel");
3039 hcommand_add("statsdump", H_ADMIN
, helpmod_cmd_statsdump
, "Statistics dump command");
3040 hcommand_add("statsrepair", H_ADMIN
, helpmod_cmd_statsrepair
, "Statistics repair command");
3041 hcommand_add("statsreset", H_ADMIN
, helpmod_cmd_statsreset
, "Statistics reset command");
3043 hcommand_add("message", H_TRIAL
, helpmod_cmd_message
, "Sends a message to a channel");
3044 /*hcommand_add("megod", H_PEON, helpmod_cmd_megod, "Gives you userlevel 4, if you see this in the final version, please kill strutsi");*/
3045 /*hcommand_add("test", H_PEON, helpmod_cmd_test, "Gives you userlevel 4, if you see this in the final version, please kill strutsi");*/
3048 void helpmod_command(huser
*sender
, channel
* returntype
, char *args
)
3050 int argc
= 0, useless_var
;
3051 char args_copy
[512];
3052 char *parsed_args
[H_CMD_MAX_ARGS
+ 3], *ptr
= args_copy
;
3054 /* only accept commands from valid sources */
3055 if (huser_get_level(sender
) < H_PEON
|| huser_get_level(sender
) > H_ADMIN
)
3058 if (returntype
&& !strncmp(args
, helpmodnick
->nick
, strlen(helpmodnick
->nick
)))
3063 args
+=strlen(helpmodnick
->nick
)+1;
3066 if (*args
== '-' || *args
== '?')
3069 strcpy(args_copy
, args
);
3070 /* FIX stringituki */
3073 while (isspace(*ptr
) && *ptr
)
3079 if (*ptr
== '"' && strchr(ptr
+1, '"'))
3080 { /* string support */
3081 parsed_args
[argc
++] = ptr
+1;
3082 ptr
= strchr(ptr
+1, '"');
3086 while (!isspace(*ptr
) && *ptr
)
3094 parsed_args
[argc
++] = ptr
;
3096 while (!isspace(*ptr
) && *ptr
)
3109 /* old H compatibility */
3110 if (sscanf(parsed_args
[0], "%d", &useless_var
) && returntype
== NULL
)
3112 helpmod_cmd_help(sender
, NULL
, parsed_args
[0], 1, NULL
);
3117 char *ostr
= args
, **argv
= (char**)&parsed_args
; // for SKIP_WORD
3118 hcommand
*hcom
= hcommand_get(parsed_args
[0], huser_get_level(sender
));
3122 if ((sender
->account
== NULL
&& returntype
== NULL
) || (sender
->account
!= NULL
&& !(sender
->account
->flags
& H_NO_CMD_ERROR
)))
3123 helpmod_reply(sender
, returntype
, "Unknown command '%s', please see showcommands for a list of all commands available to you", parsed_args
[0]);
3128 hcom
->function(sender
, returntype
, ostr
, argc
, argv
);
3134 #undef DEFINE_HCHANNEL
3135 #undef HCHANNEL_VERIFY_AUTHORITY