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
]);
1181 if (!hchannels_on_queue(husr) && !hchannels_on_desk(husr))
1183 helpmod_reply(sender, returntype, "Can not correct the luser: User %s is not in any queue", argv[i]);
1187 hchannels_dnmo(husr
);
1189 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");
1190 helpmod_reply(sender
, returntype
, "User %s has been informed of his mistake", argv
[i
]);
1192 { /* fix the autoqueue for the channel(s) */
1194 for (hchan
= hchannels
;hchan
;hchan
= hchan
->next
)
1195 hqueue_handle_queue(hchan
, sender
);
1199 static void helpmod_cmd_ban (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
1203 helpmod_reply(sender
, returntype
, "Can not global handle bans: Operation not defined");
1207 else if (!ci_strcmp(argv
[0], "list"))
1218 helpmod_reply(sender
, returntype
, "Global bans matching pattern %s", pattern
);
1220 for (;ptr
;ptr
= ptr
->next
)
1221 if (strregexp(bantostring(ptr
->real_ban
), pattern
))
1223 helpmod_reply(sender
, returntype
, "%-64s %-15s %s", bantostring(ptr
->real_ban
), helpmod_strtime(ptr
->expiration
- time(NULL
)), ptr
->reason
?ptr
->reason
->content
:"");
1227 helpmod_reply(sender
, returntype
, "%d Global bans match pattern %s", count
, pattern
);
1230 else if (!ci_strcmp(argv
[0], "add"))
1232 int duration
= 4 * HDEF_h
;
1233 char *reason
= "Banned";
1234 char *target
= argv
[1];
1238 helpmod_reply(sender
, returntype
, "Can not add global ban: Target hostmask not defined");
1243 if ((duration
= helpmod_read_strtime(argv
[2])) < 0)
1245 helpmod_reply(sender
, returntype
, "Can not add global ban: Invalid time %s", argv
[2]);
1257 hban_add(target
, reason
, time(NULL
) + duration
, 0);
1258 helpmod_reply(sender
, returntype
, "Added ban for %s (%s), expires in %s", target
, reason
, helpmod_strtime(duration
));
1260 else if (!ci_strcmp(argv
[0], "del"))
1265 helpmod_reply(sender
, returntype
, "Can not remove global ban: Target hostmask not defined");
1268 if (argc
> H_CMD_MAX_ARGS
)
1269 argc
= H_CMD_MAX_ARGS
;
1270 for (i
=1;i
<argc
;i
++)
1272 hban
*ptr
= hban_get(argv
[i
]);
1275 helpmod_reply(sender
, returntype
, "Can not remove global ban: Hostmask %s is not banned", argv
[i
]);
1278 helpmod_reply(sender
, returntype
, "Global ban for hostmask %s removed", argv
[i
]);
1284 helpmod_reply(sender
, returntype
, "Can not handle global bans: Unknown operation %s", argv
[0]);
1289 static void helpmod_cmd_chanban (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
1298 helpmod_reply(sender
, returntype
, "Can not handle channel bans: Channel not defined or not found");
1302 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
1306 helpmod_reply(sender
, returntype
, "Can not handle channel bans: Operation not defined");
1310 if (!ci_strcmp(argv
[0], "list"))
1312 char *pattern
, *cban
;
1313 chanban
*ptr
= hchan
->real_channel
->bans
;
1321 helpmod_reply(sender
, returntype
, "Bans matching pattern %s for channel %s", pattern
, hchannel_get_name(hchan
));
1322 for (;ptr
;ptr
= ptr
->next
)
1323 if (strregexp((cban
= bantostring(ptr
)), pattern
))
1326 if (hchanban_get(hchan
,cban
))
1327 helpmod_reply(sender
, returntype
, "%s Expires in %s", bantostring(ptr
), helpmod_strtime(hchanban_get(hchan
, cban
)->expiration
- time(NULL
)));
1329 helpmod_reply(sender
, returntype
, "%s", bantostring(ptr
));
1331 helpmod_reply(sender
, returntype
, "%d bans match pattern %s on channel %s", count
, pattern
, hchannel_get_name(hchan
));
1333 else if (!ci_strcmp(argv
[0], "add"))
1337 helpmod_reply(sender
, returntype
, "Can not add channel bans: Pattern not defined");
1340 if (argc
> H_CMD_MAX_ARGS
)
1341 argc
= H_CMD_MAX_ARGS
;
1342 for (i
=1;i
<argc
;i
++)
1344 /* POSSIBLE BUG ? */
1345 helpmod_setban(hchan
, argv
[i
], H_ETERNITY
, MCB_ADD
, HLAZY
);
1346 helpmod_reply(sender
, returntype
, "Added ban %s to channel %s", argv
[i
], hchannel_get_name(hchan
));
1349 else if (!ci_strcmp(argv
[0], "del"))
1353 helpmod_reply(sender
, returntype
, "Can not remove channel bans: Pattern not defined");
1356 if (argc
> H_CMD_MAX_ARGS
)
1357 argc
= H_CMD_MAX_ARGS
;
1358 for (i
=1;i
<argc
;i
++)
1360 chanban
*ptr
= hchan
->real_channel
->bans
;
1361 for (;ptr
;ptr
= ptr
->next
)
1362 if (strregexp(bantostring(ptr
), argv
[i
]))
1364 helpmod_setban(hchan
, argv
[i
], 0, MCB_DEL
, HLAZY
);
1365 helpmod_reply(sender
, returntype
, "Channel ban %s removed from channel %s", argv
[i
], hchannel_get_name(hchan
));
1369 helpmod_reply(sender
, returntype
, "Can not remove channel ban: Pattern %s not banned on channel %s", argv
[i
], hchannel_get_name(hchan
));
1374 helpmod_reply(sender
, returntype
, "Can not handle channel bans: Unknown operation %s", argv
[0]);
1379 static void helpmod_cmd_idlekick (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
1386 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
1390 helpmod_reply(sender
, returntype
, "Can not handle the idlekick: Channel not defined or not found");
1393 if (argc
== 0) /* view */
1395 helpmod_reply(sender
, returntype
, "Idlekick for channel %s is set to %s", hchannel_get_name(hchan
), helpmod_strtime(hchan
->max_idle
));
1398 else if ((tmp
= helpmod_read_strtime(argv
[0])) < 0 || tmp
< HDEF_m
|| tmp
> HDEF_w
)
1400 helpmod_reply(sender
, returntype
, "Can not set the idlekick: Invalid time given '%s'", argv
[0]);
1405 hchan
->max_idle
= tmp
;
1406 helpmod_reply(sender
, returntype
, "Idlekick for channel %s set to %s succesfully", hchannel_get_name(hchan
), helpmod_strtime(hchan
->max_idle
));
1410 static void helpmod_cmd_topic (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
1415 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
1419 helpmod_reply(sender
, returntype
, "Can not handle the topic: Channel not defined or not found");
1422 if (!(hchan
-> flags
& H_HANDLE_TOPIC
))
1423 helpmod_reply(sender
, returntype
, "Note: I'm not set to handle the topic on channel %s", hchannel_get_name(hchan
));
1425 if (argc
== 0) /* check the topic */
1427 helpmod_reply(sender
, returntype
, "Topic of channel %s is currently: %s", hchannel_get_name(hchan
), htopic_construct(hchan
->topic
));
1430 if (!ci_strcmp(argv
[0], "erase"))
1432 htopic_del_all(&hchan
->topic
);
1433 hchannel_set_topic(hchan
);
1434 helpmod_reply(sender
, returntype
, "Topic of channel %s erased", hchannel_get_name(hchan
));
1436 else if (!ci_strcmp(argv
[0], "refresh"))
1438 hchannel_set_topic(hchan
);
1439 helpmod_reply(sender
, returntype
, "Topic of channel %s refreshed", hchannel_get_name(hchan
));
1441 else if (!ci_strcmp(argv
[0], "add"))
1447 helpmod_reply(sender
, returntype
, "Cannot handle the topic of channel %s: Additional arguments required", hchannel_get_name(hchan
));
1450 if (sscanf(argv
[0], "%d", &pos
) && pos
>= 0)
1456 if (argc
== 0) /* lame repeat :( */
1458 helpmod_reply(sender
, returntype
, "Cannot handle the topic of channel %s: Additional arguments required", hchannel_get_name(hchan
));
1461 if (htopic_len(hchan
->topic
) + strlen(ostr
) + 3 > TOPICLEN
)
1463 helpmod_reply(sender
, returntype
, "Cannot add to the topic of channel %s: Maximum topic length exceeded", hchannel_get_name(hchan
));
1467 htopic_add(&hchan
->topic
, ostr
, pos
);
1468 hchannel_set_topic(hchan
);
1469 helpmod_reply(sender
, returntype
, "Added '%s' to the topic of channel %s", ostr
, hchannel_get_name(hchan
));
1471 else if (!ci_strcmp(argv
[0], "del"))
1476 helpmod_reply(sender
, returntype
, "Cannot handle the topic of channel %s: Additional arguments required", hchannel_get_name(hchan
));
1480 if (!sscanf(argv
[0], "%d", &pos
) || pos
< 0)
1482 helpmod_reply(sender
, returntype
, "Cannot handle the topic of channel %s: Expected positive integer", hchannel_get_name(hchan
));
1485 if (htopic_count(hchan
->topic
) < pos
)
1487 helpmod_reply(sender
, returntype
, "Cannot delete from the topic of channel %s: No such topic element %d", hchannel_get_name(hchan
), pos
);
1490 htopic_del(&hchan
->topic
, htopic_get(hchan
->topic
, pos
));
1491 hchannel_set_topic(hchan
);
1493 else if (!ci_strcmp(argv
[0], "set"))
1497 helpmod_reply(sender
, returntype
, "Cannot handle the topic of channel %s: Additional arguments required", hchannel_get_name(hchan
));
1501 htopic_del_all(&hchan
->topic
);
1502 htopic_add(&hchan
->topic
, ostr
, 0);
1503 hchannel_set_topic(hchan
);
1506 helpmod_reply(sender
, returntype
, "Can not handle the topic of channel %s: Unknown operation %s", hchannel_get_name(hchan
), argv
[0]);
1509 static void helpmod_cmd_out (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
1513 char *reason
= "Banned";
1514 huser
*targets
[H_CMD_MAX_ARGS
];
1519 helpmod_reply(sender
, returntype
, "Can not get rid of the user: User not specified");
1523 if (argc
> H_CMD_MAX_ARGS
)
1524 argc
= H_CMD_MAX_ARGS
;
1525 for (i
=0;i
<argc
;i
++)
1527 if (argv
[i
][0] == ':')
1531 helpmod_reply(sender
, returntype
, "Can not get rid of users: No users specified");
1542 husr
= huser_get(getnickbynick(argv
[i
]));
1545 helpmod_reply(sender
, returntype
, "Can not get rid of the user: User %s not found", argv
[i
]);
1548 if (huser_get_level(husr
) > H_PEON
)
1550 helpmod_reply(sender
, returntype
, "Can not get rid of the user: User %s is not a peon", husr
->real_user
->nick
);
1553 targets
[ntargets
++] = husr
;
1556 for (i
=0;i
<ntargets
;i
++)
1558 const char *banmask
= hban_ban_string(targets
[i
]->real_user
, HBAN_HOST
);
1560 hban_add(banmask
, reason
, time(NULL
) + HCMD_OUT_DEFAULT
, 0);
1562 helpmod_reply(sender
, returntype
, "User %s is now gone", targets
[i
]->real_user
->nick
);
1566 static void helpmod_cmd_everyoneout (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
1569 hchannel_user
**hchanuser
;
1570 char *reason
= "clearing channel";
1571 int autoqueue_tmp
= -1;
1575 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
1579 helpmod_reply(sender
, returntype
, "Can not clear channel: Channel not defined or not found");
1586 hchan
->flags
|= H_MAINTAIN_I
;
1587 hchannel_mode_check(hchan
);
1589 hchanuser
= &hchan
->channel_users
;
1591 if ((hchan
->flags
& H_QUEUE
) && (hchan
->flags
& H_QUEUE_MAINTAIN
))
1593 autoqueue_tmp
= hchan
->autoqueue
;
1594 hchan
->autoqueue
= 0;
1599 if (huser_get_level((*hchanuser
)->husr
) < H_TRIAL
)
1600 helpmod_kick(hchan
, (*hchanuser
)->husr
, reason
);
1602 hchanuser
= &(*hchanuser
)->next
;
1605 if (autoqueue_tmp
> 0)
1606 hchan
->autoqueue
= autoqueue_tmp
;
1608 helpmod_reply(sender
, returntype
, "Channel %s has been cleared of normal users", hchannel_get_name(hchan
));
1611 static void helpmod_cmd_kick (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
1615 huser
*husr
, *targets
[H_CMD_MAX_ARGS
];
1617 char *reason
= "out";
1620 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
1624 helpmod_reply(sender
, returntype
, "Can not kick the user: Channel not defined or not found");
1630 helpmod_reply(sender
, returntype
, "Can not kick users: No users specified");
1634 if (argc
> H_CMD_MAX_ARGS
)
1635 argc
= H_CMD_MAX_ARGS
;
1636 for (i
=0;i
<argc
;i
++)
1638 if (*argv
[i
] == ':')
1642 helpmod_reply(sender
, returntype
, "Can not kick the user: No users defined");
1652 husr
= huser_get(getnickbynick(argv
[i
]));
1655 helpmod_reply(sender
, returntype
, "Can not kick the user: User %s not found", argv
[i
]);
1658 if (huser_on_channel(husr
, hchan
) == NULL
)
1660 helpmod_reply(sender
, returntype
, "Can not kick the user: User %s is not on channel %s", husr
->real_user
->nick
, hchannel_get_name(hchan
));
1663 if (huser_get_level(husr
) > H_PEON
)
1665 helpmod_reply(sender
, returntype
, "Can not kick the user: User %s is not a peon", husr
->real_user
->nick
);
1668 targets
[ntargets
++] = husr
;
1671 for (i
=0;i
<ntargets
;i
++)
1672 helpmod_kick(hchan
, targets
[i
], reason
);
1675 static void helpmod_cmd_stats (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
1678 haccount
*target
= sender
->account
;
1680 hstat_account_entry
*stat_entry
;
1681 int days
= 1, weeks
= 0;
1682 int type
= HSTAT_ACCOUNT_SHORT
;
1684 time_t timer
= time(NULL
);
1685 struct tm
*tstruct
= localtime(&timer
);
1691 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
1695 helpmod_reply(sender
, returntype
, "Can not show user statistics: Channel not defined or not found");
1699 if (argc
> 0 && huser_get_level(sender
) == H_ADMIN
)
1700 { /* not very elegant */
1701 if (argv
[0][0] == '#') /* account */
1703 target
= haccount_get_by_name(argv
[0]+1);
1706 helpmod_reply(sender
, returntype
, "Can not show user statistics: Account %s not found", argv
[0]);
1715 helpmod_reply(sender
, returntype
, "Can not show user statistics: You do not have an account");
1721 if (!ci_strcmp(argv
[0], "short") || !ci_strcmp(argv
[0], "s"))
1723 type
= HSTAT_ACCOUNT_SHORT
;
1726 else if (!ci_strcmp(argv
[0], "long") || !ci_strcmp(argv
[0], "l"))
1728 type
= HSTAT_ACCOUNT_LONG
;
1734 if (sscanf(argv
[0], "%d", &days
))
1736 if (days
< 0 || days
> 7)
1738 helpmod_reply(sender
, returntype
, "Can not show user statistics: Expected integer between [0, 7]");
1748 if (sscanf(argv
[0], "%d", &weeks
))
1750 if (weeks
< 0 || weeks
> 10)
1752 helpmod_reply(sender
, returntype
, "Can not show user statistics: Expected integer between [0, 10]");
1761 for (ptr
= target
->stats
;ptr
;ptr
= ptr
->next
)
1762 if (ptr
->hchan
== hchan
)
1767 helpmod_reply(sender
, returntype
, "Can not show user statistics: User %s has no statistics for channel %s", target
->name
->content
, hchannel_get_name(hchan
));
1771 if (!days
&& !weeks
)
1774 helpmod_reply(sender
, returntype
, "Statistics for user %s on channel %s", target
->name
->content
, hchannel_get_name(hchan
));
1778 helpmod_reply(sender
, returntype
, "Last %d day%s", days
, (days
==1)?"":"s");
1779 helpmod_reply(sender
, returntype
, "%s", hstat_header(type
));
1780 for (i
=0;i
<days
;i
++)
1782 stat_entry
= &ptr
->week
[(tstruct
->tm_wday
- i
+ 7) % 7];
1783 helpmod_reply(sender
, returntype
, "%s", hstat_account_print(stat_entry
, type
));
1789 helpmod_reply(sender
, returntype
, "Last %d week%s", weeks
, (weeks
==1)?"":"s");
1790 helpmod_reply(sender
, returntype
, "%s", hstat_header(type
));
1791 for (i
=0;i
<weeks
;i
++)
1793 stat_entry
= &ptr
->longterm
[(hstat_week() - i
+ 10) % 10];
1794 helpmod_reply(sender
, returntype
, "%s", hstat_account_print(stat_entry
, type
));
1799 static void helpmod_cmd_chanstats (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
1802 hstat_channel
*channel_stats
;
1803 hstat_channel_entry
*stat_entry
;
1805 time_t timer
= time(NULL
);
1806 struct tm
*tstruct
= localtime(&timer
);
1809 int type
= HSTAT_CHANNEL_SHORT
;
1816 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
1820 helpmod_reply(sender
, returntype
, "Can not show channel statistics: Channel not defined or not found");
1826 if (!ci_strcmp(argv
[0], "short") || !ci_strcmp(argv
[0], "s"))
1828 type
= HSTAT_CHANNEL_SHORT
;
1831 else if (!ci_strcmp(argv
[0], "long") || !ci_strcmp(argv
[0], "l"))
1833 type
= HSTAT_CHANNEL_LONG
;
1839 if (sscanf(argv
[0], "%d", &days
))
1841 if (days
< 0 || days
> 7)
1843 helpmod_reply(sender
, returntype
, "Can not show channel statistics: Expected integer between [0, 7]");
1853 if (sscanf(argv
[0], "%d", &weeks
))
1855 if (weeks
< 0 || weeks
> 10)
1857 helpmod_reply(sender
, returntype
, "Can not show channel statistics: Expected integer between [0, 10]");
1867 channel_stats
= hchan
->stats
;
1869 if (!days
&& !weeks
)
1872 helpmod_reply(sender
, returntype
, "Statistics for channel %s", hchannel_get_name(hchan
));
1876 helpmod_reply(sender
, returntype
, "Last %d day%s", days
, (days
==1)?"":"s");
1877 helpmod_reply(sender
, returntype
, "%s", hstat_header(type
));
1878 for (i
=0;i
<days
;i
++) /* latest week */
1880 stat_entry
= &hchan
->stats
->week
[(tstruct
->tm_wday
- i
+ 7) % 7];
1881 helpmod_reply(sender
, returntype
, "%s", hstat_channel_print(stat_entry
, type
));
1887 helpmod_reply(sender
, returntype
, "Last %d week%s", weeks
, (weeks
==1)?"":"s");
1888 helpmod_reply(sender
, returntype
, "%s", hstat_header(type
));
1889 for (i
=0;i
<weeks
;i
++) /* latest weeks */
1891 stat_entry
= &hchan
->stats
->longterm
[(hstat_week() - i
+ 10) % 10];
1892 helpmod_reply(sender
, returntype
, "%s", hstat_channel_print(stat_entry
, type
));
1897 static void helpmod_cmd_activestaff (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
1900 hstat_accounts_array arr
;
1901 hlevel lvl
= H_OPER
;
1909 helpmod_reply(sender
, returntype
, "Can not list active staff: Channel not specified or not found");
1915 if (!ci_strcmp(argv
[0], "opers") || !ci_strcmp(argv
[0], "o"))
1920 else if (!ci_strcmp(argv
[0], "staff") || !ci_strcmp(argv
[0], "s"))
1929 if (!ci_strcmp(argv
[0], "active") || !ci_strcmp(argv
[0], "a"))
1934 else if (!ci_strcmp(argv
[0], "inactive") || !ci_strcmp(argv
[0], "i"))
1941 arr
= create_hstat_account_array(hchan
, lvl
);
1943 helpmod_reply(sender
, returntype
, "%s %ss for channel %s", listtype
?"Inactive":"Active", hlevel_name(lvl
), hchannel_get_name(hchan
));
1947 for (i
=0;i
< arr
.arrlen
&& arr
.array
[i
].prime_time_spent
> H_ACTIVE_LIMIT
;i
++)
1948 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
));
1951 for (i
=arr
.arrlen
-1;i
>= 0 && arr
.array
[i
].prime_time_spent
< H_ACTIVE_LIMIT
;i
--)
1952 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
));
1959 static void helpmod_cmd_top10 (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
1962 hstat_accounts_array arr
;
1963 hlevel lvl
= H_OPER
;
1968 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
1972 helpmod_reply(sender
, returntype
, "Can not list channel Top10: Channel not specified or not found");
1978 if (!ci_strcmp(argv
[0], "opers") || !ci_strcmp(argv
[0], "o"))
1980 else if (!ci_strcmp(argv
[0], "staff") || !ci_strcmp(argv
[0], "s"))
1986 if (sscanf(argv
[1], "%d", &tmp
) && (tmp
>= 10) && (tmp
<= 50))
1990 arr
= create_hstat_account_array(hchan
, lvl
);
1992 helpmod_reply(sender
, returntype
, "Top%d most active %ss of channel %s", top_n
, hlevel_name(lvl
), hchannel_get_name(hchan
));
1993 for (i
=0;i
< arr
.arrlen
&& i
< top_n
;i
++)
1994 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
));
1999 static void helpmod_cmd_report (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
2001 hchannel
*hchan
, *target
;
2004 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
2006 if (hchan
!= NULL
&& (argc
== 2))
2008 hchan
= hchannel_get_by_name(argv
[0]);
2014 helpmod_reply(sender
, returntype
, "Can not view or set channel reporting: Channel not defined or not found");
2019 if (hchan
->report_to
== NULL
|| !hchannel_is_valid(hchan
->report_to
))
2020 helpmod_reply(sender
, returntype
, "Channel %s is not reported anywhere (%s)", hchannel_get_name(hchan
), hchannel_get_state(hchan
, H_REPORT
));
2022 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
));
2025 if ((target
= hchannel_get_by_name(argv
[0])) == NULL
)
2027 helpmod_reply(sender
, returntype
, "Can not set channel reporting: Channel %s not found", argv
[0]);
2030 hchan
->report_to
= target
;
2031 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
));
2034 static void helpmod_cmd_mode(huser
*sender
, channel
* returntype
, int change
, char* ostr
, int argc
, char *argv
[])
2037 huser_channel
*huserchan
;
2043 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
2047 helpmod_reply(sender
, returntype
, "Can not change mode: Channel not specified or not found");
2051 if (argc
==0) /* for a simple opme */
2054 argv
[0] = sender
->real_user
->nick
;
2057 if (argc
> H_CMD_MAX_ARGS
)
2058 argc
= H_CMD_MAX_ARGS
;
2060 for (i
=0;i
<argc
;i
++)
2062 husr
= huser_get(getnickbynick(argv
[i
]));
2065 helpmod_reply(sender
, returntype
, "Can not change mode: User %s not found", argv
[i
], hchannel_get_name(hchan
));
2068 huserchan
= huser_on_channel(husr
, hchan
);
2069 if (huserchan
== NULL
)
2071 helpmod_reply(sender
, returntype
, "Can not change mode: User %s it not on channel %s", husr
->real_user
->nick
, hchannel_get_name(hchan
));
2080 for (j
=0;j
< hchan
->real_channel
->users
->hashsize
;j
++)
2081 if (getnickbynumeric(hchan
->real_channel
->users
->content
[j
]) == husr
->real_user
)
2083 if ((huserchan
->flags
& HCUMODE_OP
) && !(hchan
->real_channel
->users
->content
[j
] & CUMODE_OP
))
2085 huserchan
->flags
&= ~HCUMODE_OP
;
2086 Error("helpmod", ERR_ERROR
, "userchannelmode inconsistency (+o when should be -o)");
2088 if (huserchan
->flags
& HCUMODE_OP
)
2090 helpmod_reply(sender
, returntype
, "Can not change mode: User %s is already +o on channel %s", husr
->real_user
->nick
, hchannel_get_name(hchan
));
2093 if (huser_get_level(husr
) < H_STAFF
)
2095 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
));
2098 helpmod_channick_modes(husr
, hchan
, MC_OP
, HLAZY
);
2104 for (j
=0;j
< hchan
->real_channel
->users
->hashsize
;j
++)
2105 if (getnickbynumeric(hchan
->real_channel
->users
->content
[j
]) == husr
->real_user
)
2107 if (!(huserchan
->flags
& HCUMODE_OP
) && (hchan
->real_channel
->users
->content
[j
] & CUMODE_OP
))
2109 huserchan
->flags
|= HCUMODE_OP
;
2110 Error("helpmod", ERR_ERROR
, "userchannelmode inconsistency (-o when should be +o)");
2112 if (!(huserchan
->flags
& HCUMODE_OP
))
2114 helpmod_reply(sender
, returntype
, "Can not change mode: User %s is already -o on channel %s", husr
->real_user
->nick
, hchannel_get_name(hchan
));
2117 if (huser_get_level(husr
) > huser_get_level(sender
))
2119 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
));
2122 helpmod_channick_modes(husr
, hchan
, MC_DEOP
, HLAZY
);
2128 for (j
=0;j
< hchan
->real_channel
->users
->hashsize
;j
++)
2129 if (getnickbynumeric(hchan
->real_channel
->users
->content
[j
]) == husr
->real_user
)
2131 if ((huserchan
->flags
& HCUMODE_VOICE
) && !(hchan
->real_channel
->users
->content
[j
] & CUMODE_VOICE
))
2133 huserchan
->flags
&= ~HCUMODE_VOICE
;
2134 Error("helpmod", ERR_ERROR
, "userchannelmode inconsistency (+v when should be -v)");
2136 if (huserchan
->flags
& HCUMODE_VOICE
)
2138 helpmod_reply(sender
, returntype
, "Can not change mode: User %s is already -v on channel %s", husr
->real_user
->nick
, hchannel_get_name(hchan
));
2141 helpmod_channick_modes(husr
, hchan
, MC_VOICE
, HLAZY
);
2147 for (j
=0;j
< hchan
->real_channel
->users
->hashsize
;j
++)
2148 if (getnickbynumeric(hchan
->real_channel
->users
->content
[j
]) == husr
->real_user
)
2150 if (!(huserchan
->flags
& HCUMODE_VOICE
) && (hchan
->real_channel
->users
->content
[j
] & CUMODE_VOICE
))
2152 huserchan
->flags
|= HCUMODE_VOICE
;
2153 Error("helpmod", ERR_ERROR
, "userchannelmode inconsistency (-v when should be +v)");
2155 if (!(huserchan
->flags
& HCUMODE_VOICE
))
2157 helpmod_reply(sender
, returntype
, "Can not change mode: User %s is already -v on channel %s", husr
->real_user
->nick
, hchannel_get_name(hchan
));
2160 helpmod_channick_modes(husr
, hchan
, MC_DEVOICE
, HLAZY
);
2167 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
); }
2168 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
); }
2169 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
); }
2170 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
); }
2172 static void helpmod_cmd_invite (huser
*sender
, channel
*returntype
, char* arg
, int argc
, char *argv
[])
2179 helpmod_reply(sender
, returntype
, "Can not invite: Channel not defined or not found");
2183 if (huser_get_level(sender
) == H_PEON
)
2186 hchan
= hchannel_get_by_name(argv
[0]);
2189 helpmod_reply(sender
, returntype
, "Can not invite: Unknown channel %s", argv
[0]);
2192 /* if tickets don't work, it's better that the user doesn't know that the channel really exists */
2193 if (!(hchan
->flags
& H_REQUIRE_TICKET
))
2195 helpmod_reply(sender
, returntype
, "Can not invite: Unknown channel %s", argv
[0]);
2198 htick
= hticket_get(sender
->real_user
->authname
, hchan
);
2202 helpmod_reply(sender
, returntype
, "Can not invite: You do not have an invite ticket for channel %s", argv
[0]);
2206 if (nickbanned(sender
->real_user
, hchan
->real_channel
))
2208 helpmod_reply(sender
, returntype
, "Can not invite: You are banned from channel %s", argv
[0]);
2212 helpmod_invite(hchan
, sender
);
2213 helpmod_reply(sender
, returntype
, "Invited you to channel %s", hchannel_get_name(hchan
));
2217 if (argc
> H_CMD_MAX_ARGS
)
2218 argc
= H_CMD_MAX_ARGS
;
2220 for (i
= 0;i
< argc
; i
++)
2222 hchan
= hchannel_get_by_name(argv
[0]);
2225 helpmod_reply(sender
, returntype
, "Can not invite: Unknown channel %s", argv
[i
]);
2228 if (!(hchannel_authority(hchan
, sender
) || hticket_get(sender
->real_user
->authname
, hchan
)))
2230 helpmod_reply(sender
, returntype
, "Sorry, channel %s is oper only", hchannel_get_name(hchan
));
2233 if (huser_on_channel(sender
, hchan
) != NULL
)
2235 helpmod_reply(sender
, returntype
, "Can not invite: You are already on channel %s", hchannel_get_name(hchan
));
2238 helpmod_invite(hchan
, sender
);
2239 helpmod_reply(sender
, returntype
, "Invited you to channel %s", hchannel_get_name(hchan
));
2243 static void helpmod_cmd_ticket (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
2245 int expiration
= HTICKET_EXPIRATION_TIME
;
2252 helpmod_reply(sender
, returntype
, "Can not issue a ticket: Channel not specified");
2256 hchan
= hchannel_get_by_name(argv
[0]);
2259 helpmod_reply(sender
, returntype
, "Can not issue a ticket: Unknown channel %s", argv
[0]);
2262 if (!(hchan
->flags
& H_REQUIRE_TICKET
))
2264 helpmod_reply(sender
, returntype
, "Can not issue a ticket: Tickets are not enabled for channel %s", argv
[0]);
2269 helpmod_reply(sender
, returntype
, "Can not issue a ticket: Target user not specified");
2273 husr
= huser_get(getnickbynick(argv
[1]));
2276 helpmod_reply(sender
, returntype
, "Can not issue a ticket: Unknown user %s", argv
[1]);
2279 if (!IsAccount(husr
->real_user
))
2281 helpmod_reply(sender
, returntype
, "Can not issue a ticket: User %s is not authed", argv
[1]);
2284 if (huser_get_level(husr
) < H_PEON
)
2286 helpmod_reply(sender
, returntype
, "Can not issue a ticket: User %s is considered improper and not worthy of a ticket", argv
[1]);
2292 tmp
= helpmod_read_strtime(argv
[2]);
2293 if (tmp
> HDEF_m
&& tmp
< 2 * HDEF_M
)
2297 htick
= hticket_get(husr
->real_user
->authname
, hchan
);
2300 htick
->time_expiration
= time(NULL
) + expiration
;
2302 hticket_add(husr
->real_user
->authname
, time(NULL
) + expiration
, hchan
);
2304 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
));
2305 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
));
2308 static void helpmod_cmd_resolve (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
2317 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
2319 if (argc
> H_CMD_MAX_ARGS
)
2320 argc
= H_CMD_MAX_ARGS
;
2324 helpmod_reply(sender
, returntype
, "Can not resolve a ticket: The channel is not specified");
2328 for (i
= 0;i
< argc
;i
++)
2330 if (argv
[i
][0] == '#')
2332 htick
= hticket_get(&argv
[i
][1], hchan
);
2335 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
));
2338 hticket_del(htick
, hchan
);
2339 helpmod_reply(sender
, returntype
, "Resolved authname %s's ticket for channel %s", &argv
[i
][1], hchannel_get_name(hchan
));
2343 husr
= huser_get(getnickbynick(argv
[i
]));
2346 helpmod_reply(sender
, returntype
, "Can not resolve a ticket: User %s not found", argv
[i
]);
2349 if (!IsAccount(husr
->real_user
))
2351 helpmod_reply(sender
, returntype
, "Can not resolve a ticket: User %s is not authed", argv
[i
]);
2354 htick
= hticket_get(husr
->real_user
->authname
,hchan
);
2357 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
));
2360 hticket_del(htick
, hchan
);
2361 helpmod_reply(sender
, returntype
, "Resolved user %s's ticket for channel %s", argv
[i
], hchannel_get_name(hchan
));
2366 static void helpmod_cmd_tickets (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
2374 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
2378 helpmod_reply(sender
, returntype
, "Can not list tickets: Channel not defined or not found");
2382 if (!(hchan
->flags
& H_REQUIRE_TICKET
))
2384 helpmod_reply(sender
, returntype
, "Can not list tickets: Channel %s does not use the ticket system", hchannel_get_name(hchan
));
2388 htick
= hchan
->htickets
;
2392 helpmod_reply(sender
, returntype
, "Channel %s has no valid tickets", hchannel_get_name(hchan
));
2396 helpmod_reply(sender
, returntype
, "Valid tickets for channel %s", hchannel_get_name(hchan
));
2398 for (i
= 0;htick
;htick
= htick
->next
, i
++)
2399 helpmod_reply(sender
, returntype
, "%4d %16s %48s", i
, htick
->authname
, helpmod_strtime(time(NULL
) - htick
->time_expiration
));
2401 helpmod_reply(sender
, returntype
, "Done listing tickets. Channel %s had %d valid ticket%s", hchannel_get_name(hchan
), i
, (i
==1)?"":"s");
2404 static void helpmod_cmd_showticket (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
2413 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
2415 if (argc
> H_CMD_MAX_ARGS
)
2416 argc
= H_CMD_MAX_ARGS
;
2420 helpmod_reply(sender
, returntype
, "Can not show the ticket: Channel not defined or not found");
2423 for (i
= 0;i
< argc
;i
++)
2425 husr
= huser_get(getnickbynick(argv
[i
]));
2428 helpmod_reply(sender
, returntype
, "Can not show the ticket: User %s not found", argv
[i
]);
2431 if (!IsAccount(husr
->real_user
))
2433 helpmod_reply(sender
, returntype
, "Can not show the ticket: User %s is not authed", argv
[i
]);
2436 htick
= hticket_get(husr
->real_user
->authname
, hchan
);
2439 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
));
2442 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
)));
2446 static int helpmod_cmd_termstats_sort(const void *left
, const void *right
)
2448 return (*((hterm
**)right
))->usage
- (*((hterm
**)left
))->usage
;
2451 static void helpmod_cmd_termstats(huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
2453 hterm
**arr
, *origin
;
2462 origin
= hchan
->channel_hterms
;
2464 count
= hterm_count(origin
);
2468 helpmod_reply(sender
, returntype
, "Can not list term usage statistics: No terms available");
2472 arr
= malloc(sizeof(hterm
*) * count
);
2473 assert(arr
!= NULL
);
2475 for (i
=0;i
< count
;i
++,origin
= origin
->next
)
2478 qsort(arr
, count
, sizeof(hterm
*), helpmod_cmd_termstats_sort
);
2481 helpmod_reply(sender
, returntype
, "10 Most used global terms");
2483 helpmod_reply(sender
, returntype
, "10 Most used terms for channel %s", hchannel_get_name(hchan
));
2485 for (i
=0;i
< 10 && i
< count
;i
++)
2486 helpmod_reply(sender
, returntype
, "#%02d %32s :%d",i
+1, arr
[i
]->name
->content
,arr
[i
]->usage
);
2491 static int helpmod_cmd_checkchannel_nicksort(const void *left
, const void *right
)
2493 return ci_strcmp(getnickbynumeric(*((unsigned long*)left
))->nick
, getnickbynumeric(*((unsigned long*)right
))->nick
);
2496 static int helpmod_cmd_checkchannel_statussort(const void *left
, const void *right
)
2498 int level1
= 0, level2
= 0;
2500 if (*((unsigned long*)left
) & CUMODE_VOICE
)
2502 if (*((unsigned long*)left
) & CUMODE_OP
)
2505 if (*((unsigned long*)right
) & CUMODE_VOICE
)
2507 if (*((unsigned long*)right
) & CUMODE_OP
)
2510 return level2
- level1
;
2513 static void helpmod_cmd_checkchannel(huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
2517 int i
, j
, nick_count
= 0, authed_count
= 0, o_limit
= 0, v_limit
= 0, summary_only
= 0;
2518 unsigned long *numeric_array
;
2522 helpmod_reply(sender
, returntype
, "Can not check channel: Channel not defined");
2526 chan
= findchannel(argv
[0]);
2529 helpmod_reply(sender
, returntype
, "Can not check channel: Channel %s not found", argv
[0]);
2532 if (argc
> 1 && !ci_strcmp(argv
[1], "summary"))
2535 /* first pass - verify validity and count nicks */
2536 for (i
=0;i
< chan
->users
->hashsize
;i
++)
2538 nck
= getnickbynumeric(chan
->users
->content
[i
]);
2539 if (!nck
) /* it's a hash, not an array */
2547 if (IsOper(nck
) && strlen(nck
->nick
) > 1)
2549 helpmod_reply(sender
, returntype
, "Can not check channel: Permission denied. Channel %s has an oper on it", argv
[0]);
2554 numeric_array
= (unsigned long*)malloc(nick_count
* sizeof(unsigned long));
2556 /* second pass - construct array */
2557 for (i
=0,j
=0;i
< chan
->users
->hashsize
;i
++)
2559 if (getnickbynumeric(chan
->users
->content
[i
]) == NULL
) /* it's a hash, not an array */
2562 numeric_array
[j
++] = chan
->users
->content
[i
];
2565 qsort(numeric_array
, nick_count
, sizeof(unsigned long), helpmod_cmd_checkchannel_statussort
);
2567 /* third pass - find status boundaries */
2569 for (;o_limit
< nick_count
&& numeric_array
[o_limit
] & CUMODE_OP
; o_limit
++);
2571 for(v_limit
= o_limit
; (v_limit
< nick_count
) && numeric_array
[v_limit
] & CUMODE_VOICE
; v_limit
++);
2574 helpmod_reply(sender
, returntype
, "Information on channel %s", argv
[0]);
2575 helpmod_reply(sender
, returntype
, "Channel created %s ago", helpmod_strtime(time(NULL
) - chan
->timestamp
));
2576 if (!IsKey(chan
) && !IsInviteOnly(chan
))
2577 helpmod_reply(sender
, returntype
, "Channel topic: %s", chan
->topic
?chan
->topic
->content
:"Not set");
2578 helpmod_reply(sender
, returntype
, "Channel modes: %s", printflags(chan
->flags
, cmodeflags
));
2581 /* sort the sub arrays */
2584 qsort(numeric_array
, o_limit
, sizeof(unsigned long), helpmod_cmd_checkchannel_nicksort
);
2585 if (v_limit
- o_limit
> 0)
2586 qsort(numeric_array
+ o_limit
, v_limit
- o_limit
, sizeof(unsigned long), helpmod_cmd_checkchannel_nicksort
);
2587 if (nick_count
- v_limit
> 0)
2588 qsort(numeric_array
+ v_limit
, nick_count
- v_limit
, sizeof(unsigned long), helpmod_cmd_checkchannel_nicksort
);
2590 /* fourth pass - print results */
2592 for (i
=0;i
< nick_count
;i
++)
2594 char buf
[256], status
;
2596 if (numeric_array
[i
] & CUMODE_OP
)
2598 else if (numeric_array
[i
] & CUMODE_VOICE
)
2603 visiblehostmask(getnickbynumeric(numeric_array
[i
]), buf
);
2604 if (IsAccount(getnickbynumeric(numeric_array
[i
])))
2605 helpmod_reply(sender
, returntype
, "%c%s (%s)", status
, buf
, getnickbynumeric(numeric_array
[i
])->authname
);//nick_array[i]->authname);
2607 helpmod_reply(sender
, returntype
, "%c%s", status
, buf
);
2610 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);
2612 free(numeric_array
);
2615 static void helpmod_cmd_statsdump (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
2617 haccount
*hacc
= haccounts
;
2621 helpmod_reply(sender
, returntype
, "Account statistics");
2622 for (;hacc
;hacc
= hacc
->next
)
2623 for (ptr
= hacc
->stats
;ptr
;ptr
= ptr
->next
)
2625 helpmod_reply(sender
, returntype
, "Account %s channel %s short-term", hacc
->name
->content
, hchannel_get_name(ptr
->hchan
));
2626 for (i
= 0;i
< 7;i
++)
2627 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
);
2628 helpmod_reply(sender
, returntype
, "Account %s channel %s long-term", hacc
->name
->content
, hchannel_get_name(ptr
->hchan
));
2629 for (i
= 0;i
< 10;i
++)
2630 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
);
2634 static void helpmod_cmd_statsrepair (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
2636 haccount
*hacc
= haccounts
;
2640 helpmod_reply(sender
, returntype
, "Repairing account statistics");
2641 for (;hacc
;hacc
= hacc
->next
)
2642 for (ptr
= hacc
->stats
;ptr
;ptr
= ptr
->next
)
2644 for (i
= 0;i
< 7;i
++)
2646 if (ptr
->week
[i
].time_spent
> HDEF_d
)
2648 ptr
->week
[i
].time_spent
= 0;
2649 helpmod_reply(sender
, returntype
, "repaired short term TimeSpent %s @ %s : Greater than one day",hacc
->name
->content
, hchannel_get_name(ptr
->hchan
));
2651 if (ptr
->week
[i
].time_spent
< 0)
2653 ptr
->week
[i
].time_spent
= 0;
2654 helpmod_reply(sender
, returntype
, "repaired short term TimeSpent %s @ %s : Less than zero",hacc
->name
->content
, hchannel_get_name(ptr
->hchan
));
2657 if (ptr
->week
[i
].prime_time_spent
> HDEF_d
)
2659 ptr
->week
[i
].prime_time_spent
= 0;
2660 helpmod_reply(sender
, returntype
, "repaired short term PrimeTimeSpent %s @ %s : Greater than one day",hacc
->name
->content
, hchannel_get_name(ptr
->hchan
));
2662 if (ptr
->week
[i
].prime_time_spent
< 0)
2664 ptr
->week
[i
].prime_time_spent
= 0;
2665 helpmod_reply(sender
, returntype
, "repaired short term PrimeTimeSpent %s @ %s : Less than zero",hacc
->name
->content
, hchannel_get_name(ptr
->hchan
));
2668 if (ptr
->week
[i
].lines
> 10000)
2670 ptr
->week
[i
].lines
= 0;
2671 helpmod_reply(sender
, returntype
, "repaired short term Lines %s @ %s : Greater than 10000",hacc
->name
->content
, hchannel_get_name(ptr
->hchan
));
2673 if (ptr
->week
[i
].lines
< 0)
2675 ptr
->week
[i
].lines
= 0;
2676 helpmod_reply(sender
, returntype
, "repaired short term Lines %s @ %s : Less than zero",hacc
->name
->content
, hchannel_get_name(ptr
->hchan
));
2679 if (ptr
->week
[i
].words
> 50000)
2681 ptr
->week
[i
].words
= 0;
2682 helpmod_reply(sender
, returntype
, "repaired short term Words %s @ %s : Greater than 50000",hacc
->name
->content
, hchannel_get_name(ptr
->hchan
));
2684 if (ptr
->week
[i
].words
< 0)
2686 ptr
->week
[i
].words
= 0;
2687 helpmod_reply(sender
, returntype
, "repaired short term Words %s @ %s : Less than zero",hacc
->name
->content
, hchannel_get_name(ptr
->hchan
));
2690 for (i
= 0;i
< 10;i
++)
2692 if (ptr
->longterm
[i
].time_spent
> HDEF_w
)
2694 ptr
->longterm
[i
].time_spent
= 0;
2695 helpmod_reply(sender
, returntype
, "repaired long term TimeSpent %s @ %s : Greater than one week",hacc
->name
->content
, hchannel_get_name(ptr
->hchan
));
2697 if (ptr
->longterm
[i
].time_spent
< 0)
2699 ptr
->longterm
[i
].time_spent
= 0;
2700 helpmod_reply(sender
, returntype
, "repaired long term TimeSpent %s @ %s : Less than zero",hacc
->name
->content
, hchannel_get_name(ptr
->hchan
));
2703 if (ptr
->longterm
[i
].prime_time_spent
> HDEF_w
)
2705 ptr
->longterm
[i
].prime_time_spent
= 0;
2706 helpmod_reply(sender
, returntype
, "repaired long term PrimeTimeSpent %s @ %s : Greater than one week",hacc
->name
->content
, hchannel_get_name(ptr
->hchan
));
2708 if (ptr
->longterm
[i
].prime_time_spent
< 0)
2710 ptr
->longterm
[i
].prime_time_spent
= 0;
2711 helpmod_reply(sender
, returntype
, "repaired long term PrimeTimeSpent %s @ %s : Less than zero",hacc
->name
->content
, hchannel_get_name(ptr
->hchan
));
2714 if (ptr
->longterm
[i
].lines
> 50000)
2716 ptr
->longterm
[i
].lines
= 0;
2717 helpmod_reply(sender
, returntype
, "repaired long term Lines %s @ %s : Greater than 50000",hacc
->name
->content
, hchannel_get_name(ptr
->hchan
));
2719 if (ptr
->longterm
[i
].lines
< 0)
2721 ptr
->longterm
[i
].lines
= 0;
2722 helpmod_reply(sender
, returntype
, "repaired long term Lines %s @ %s : Less than zero",hacc
->name
->content
, hchannel_get_name(ptr
->hchan
));
2725 if (ptr
->longterm
[i
].words
> 50000)
2727 ptr
->longterm
[i
].words
= 0;
2728 helpmod_reply(sender
, returntype
, "repaired long term Words %s @ %s : Greater than 50000",hacc
->name
->content
, hchannel_get_name(ptr
->hchan
));
2730 if (ptr
->longterm
[i
].words
< 0)
2732 ptr
->longterm
[i
].words
= 0;
2733 helpmod_reply(sender
, returntype
, "repaired long term Words %s @ %s : Less than zero",hacc
->name
->content
, hchannel_get_name(ptr
->hchan
));
2737 helpmod_reply(sender
, returntype
, "Account statistics repaired");
2741 static void helpmod_cmd_statsreset (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
2743 haccount
*hacc
= haccounts
;
2746 int i
, short_del
, long_del
;
2750 helpmod_reply(sender
, returntype
, "Insufficient parameters");
2754 if (sscanf(argv
[0], "%d", &short_del
) == 0)
2756 helpmod_reply(sender
, returntype
, "Invalid parameter");
2759 if (sscanf(argv
[1], "%d", &long_del
) == 0)
2761 helpmod_reply(sender
, returntype
, "Invalid parameter");
2765 for (;hacc
;hacc
= hacc
->next
)
2766 for (ptr
= hacc
->stats
;ptr
;ptr
= ptr
->next
)
2768 for (i
= 1;i
< short_del
+ 1;i
++)
2769 HSTAT_ACCOUNT_ZERO(ptr
->week
[(hstat_day() + i
) % 7]);
2770 for (i
= 1;i
< long_del
+ 1;i
++)
2771 HSTAT_ACCOUNT_ZERO(ptr
->longterm
[(hstat_week() + i
) % 10]);
2774 for (hchan
= hchannels
;hchan
;hchan
= hchan
->next
)
2776 for (i
= 1;i
< short_del
+ 1;i
++)
2777 HSTAT_CHANNEL_ZERO(hchan
->stats
->week
[(hstat_day() + i
) % 7]);
2778 for (i
= 1;i
< long_del
+ 1;i
++)
2779 HSTAT_CHANNEL_ZERO(hchan
->stats
->longterm
[(hstat_week() + i
) % 10]);
2783 helpmod_reply(sender
, returntype
, "Statistics reset complete");
2786 static void helpmod_cmd_message (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
2792 helpmod_reply(sender
, returntype
, "Can not send a message: Insufficient arguments");
2795 hchan
= hchannel_get_by_name(argv
[0]);
2798 helpmod_reply(sender
, returntype
, "Can not send a message: Invalid channel %s", argv
[0]);
2802 helpmod_message_channel(hchan
, "(%s) %s", sender
->real_user
->nick
, ostr
);
2803 helpmod_reply(sender
, returntype
, "Message sent to %s", hchannel_get_name(hchan
));
2807 void helpmod_cmd_load (huser
*sender
, channel
*returntype
, char* arg
, int argc
, char *argv
[])
2810 char buf
[128] = "helpmod/default";
2813 helpmod_reply(sender
, returntype
, "Warning: No config specified, using default");
2816 if (strlen(arg
) >= 100)
2819 sprintf(buf
, "helpmod/%s", arg
);
2822 if (!(tmp_file
= fopen(buf
, "rt")))
2824 helpmod_reply(sender
, returntype
, "File %s not found", buf
);
2830 helpmod_clear_aliases(&aliases
);
2831 helpmod_clear_all_entries();
2832 helpmod_init_entry(&helpmod_base
);
2833 huser_reset_states();
2834 helpmod_load_entries(buf
);
2835 strcpy(helpmod_db
, buf
);
2836 helpmod_reply(sender
, returntype
, "New config loaded and system reset");
2839 void helpmod_cmd_status (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
2841 helpmod_reply(sender
, returntype
, "HelpMod version %s (built %s, up %s)", HELPMOD_VERSION
, __DATE__
, helpmod_strtime(time(NULL
) - helpmod_startup_time
));
2842 helpmod_reply(sender
, returntype
, "Channels %d", hchannel_count());
2843 helpmod_reply(sender
, returntype
, "Accounts %d", haccount_count(H_ANY
));
2844 helpmod_reply(sender
, returntype
, "Users %d", huser_count());
2845 helpmod_reply(sender
, returntype
, "Help entries %d", helpmod_entry_count(helpmod_base
));
2846 helpmod_reply(sender
, returntype
, "Bans %d", hban_count());
2847 helpmod_reply(sender
, returntype
, "Help provided %d", helpmod_usage
);
2848 helpmod_reply(sender
, returntype
, "Tickets %d", hticket_count());
2851 /* not really a command, but help wants this one */
2852 void helpmod_send_help(huser
* target
)
2856 for (i
=0;i
<target
->state
->text_lines
;i
++)
2857 helpmod_reply(target
, NULL
, "%s", target
->state
->text
[i
]->content
);
2858 for (i
=0;i
<target
->state
->option_count
;i
++)
2859 helpmod_reply(target
, NULL
, "%d) %s", i
+1, target
->state
->options
[i
]->description
->content
);
2860 if (!target
->state
->option_count
)
2862 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");
2866 void helpmod_cmd_command(huser
* sender
, channel
* returntype
, char* arg
, int argc
, char *argv
[])
2869 char buffer
[512], *ptr
= argv
[0];
2874 helpmod_reply(sender
, returntype
, "Usage: command [name of the command] for a list see 'showcommands'");
2878 hcom
= hcommand_get(argv
[0], huser_get_level(sender
));
2882 helpmod_reply(sender
, returntype
, "Unknown command '%s'", argv
[0]);
2888 *ptr
= tolower(*ptr
);
2890 /* ? is handled like this because windows is shit */
2891 if (!ci_strcmp(argv
[0], "?"))
2892 sprintf(buffer
, "./helpmod2/commands/questionmark");
2894 sprintf(buffer
, "./helpmod2/commands/%s", argv
[0]);
2896 if ((in
= fopen(buffer
, "rt")) == NULL
)
2898 helpmod_reply(sender
, returntype
, "No help available for command '%s' (Ask strutsi to write it)", argv
[0]);
2904 fgets(buffer
, 512, in
);
2907 helpmod_reply(sender
, returntype
, "%s", buffer
);
2913 void helpmod_cmd_help (huser
* sender
, channel
* returntype
, char* arg
, int argc
, char *argv
[])
2917 if (helpmod_base
== NULL
|| !helpmod_base
->option_count
)
2919 helpmod_reply(sender
, returntype
, "The help service is not available at this time, please try again later");
2925 sender
->state
= helpmod_base
;
2926 helpmod_send_help(sender
);
2930 if (!sscanf(arg
, "%d", &hlp_target
))
2934 tmp
= helpmod_get_alias(arg
);
2936 helpmod_reply(sender
, returntype
, "Invalid value. Either use 'help' to restart or give an integer as a valid selection");
2939 sender
->state
= tmp
;
2940 helpmod_send_help(sender
);
2946 if (!helpmod_valid_selection(sender
->state
, hlp_target
))
2948 if (!sender
->state
->option_count
)
2949 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");
2950 else if (!sender
->state
->parent
)
2951 helpmod_reply(sender
, returntype
, "Bad selection, please enter your selection as an integer from %d to %d", 1, sender
->state
->option_count
);
2953 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
);
2957 sender
->state
= helpmod_make_selection(sender
->state
, hlp_target
);
2958 helpmod_send_help(sender
);
2962 /* adds all of the abowe to the system */
2963 void hcommands_add(void)
2965 hcommand_add("help", H_PEON
, helpmod_cmd_help
,"Offers the H1 type help");
2966 hcommand_add("status",H_OPER
, helpmod_cmd_status
,"Gives service status");
2967 hcommand_add("load", H_OPER
, helpmod_cmd_load
,"Loads a new help database");
2968 hcommand_add("aliases",H_STAFF
, helpmod_cmd_aliases
,"Lists all aliases currently in use");
2969 hcommand_add("showcommands", H_LAMER
, helpmod_cmd_showcommands
,"Lists all commands available to you");
2971 hcommand_add("improper", H_STAFF
, helpmod_cmd_improper
, "Sets the userlevel of the target to banned (lvl 0). Long term ban.");
2972 hcommand_add("peon", H_STAFF
, helpmod_cmd_peon
, "Sets the userlevel of the target to peon (lvl 1)");
2973 hcommand_add("trial", H_OPER
, helpmod_cmd_trial
, "Sets the userlevel of the target to trial staff (lvl 2)");
2974 hcommand_add("staff", H_OPER
, helpmod_cmd_staff
, "Sets the userlevel of the target to staff (lvl 3)");
2975 hcommand_add("oper", H_OPER
, helpmod_cmd_oper
, "Sets the userlevel of the target to oper (lvl 4)");
2976 hcommand_add("admin", H_ADMIN
, helpmod_cmd_admin
, "Sets the userlevel of the target to admin (lvl 5)");
2977 hcommand_add("deluser", H_OPER
, helpmod_cmd_deluser
, "Removes an account from " HELPMOD_NICK
);
2978 hcommand_add("listuser", H_STAFF
, helpmod_cmd_listuser
, "Lists user accounts of " HELPMOD_NICK
);
2980 hcommand_add("chanconf", H_STAFF
, helpmod_cmd_chanconf
, "Channel configuration");
2981 hcommand_add("acconf", H_TRIAL
, helpmod_cmd_acconf
, "Personalise " HELPMOD_NICK
" behaviour");
2982 hcommand_add("welcome", H_STAFF
, helpmod_cmd_welcome
, "Views or changes the channel welcome message");
2983 hcommand_add("censor", H_STAFF
, helpmod_cmd_censor
, "Handles the censored patterns for a channel");
2985 hcommand_add("queue", H_TRIAL
, helpmod_cmd_queue
, "Handles the channel queue");
2986 hcommand_add("next", H_TRIAL
, helpmod_cmd_next
, "Same as queue next");
2987 hcommand_add("done", H_TRIAL
, helpmod_cmd_done
, "Same as queue done");
2988 hcommand_add("enqueue", H_TRIAL
, helpmod_cmd_enqueue
, "Same as queue on or chanconf +3");
2989 hcommand_add("dequeue", H_TRIAL
, helpmod_cmd_dequeue
, "Same as queue off or chanconf -3");
2990 hcommand_add("autoqueue", H_TRIAL
, helpmod_cmd_autoqueue
, "Same as queue maintain");
2992 hcommand_add("?", H_PEON
, helpmod_cmd_term_find
, "Same as term find with multiple targets");
2993 hcommand_add("?+", H_TRIAL
, helpmod_cmd_term_find_plus
, "Multitarget term find which advances the queue");
2994 hcommand_add("?-", H_TRIAL
, helpmod_cmd_term_find_minus
, "Multitarget term find which removes users from queue");
2995 hcommand_add("term", H_STAFF
, helpmod_cmd_term
, "Term handling");
2997 hcommand_add("klingon", H_OPER
, helpmod_cmd_klingon
, "Phrases in klingon, both targeted and general");
2998 hcommand_add("out", H_STAFF
, helpmod_cmd_out
, "Sets the userlevel of the target to banned (lvl 0) for a short while");
2999 hcommand_add("kick", H_TRIAL
, helpmod_cmd_kick
, "Kicks user(s) from a channel");
3000 hcommand_add("ban", H_STAFF
, helpmod_cmd_ban
, "Handles global bans");
3001 hcommand_add("chanban", H_TRIAL
, helpmod_cmd_chanban
, "Handles channel bans");
3002 hcommand_add("dnmo", H_STAFF
, helpmod_cmd_dnmo
, "DoNotMessageOpers informs the luser of his mistake and sets him to the bottom of the queue");
3003 hcommand_add("lamercontrol", H_OPER
, helpmod_cmd_lamercontrol
, "Views or changes the channel lamercontrol profile");
3004 hcommand_add("topic", H_STAFF
, helpmod_cmd_topic
, "Handles the topic of a channel");
3005 hcommand_add("idlekick", H_OPER
, helpmod_cmd_idlekick
, "Views or sets the idle kick time");
3006 hcommand_add("everyoneout", H_STAFF
, helpmod_cmd_everyoneout
, "Removes all normal users from a channel and enforces +i");
3008 hcommand_add("stats", H_STAFF
, helpmod_cmd_stats
, "Shows staff activity statistics");
3009 hcommand_add("chanstats", H_STAFF
, helpmod_cmd_chanstats
, "Shows channel activity statistics");
3010 hcommand_add("activestaff", H_ADMIN
, helpmod_cmd_activestaff
, "Shows active staff members for a channel");
3011 hcommand_add("top10", H_STAFF
, helpmod_cmd_top10
, "Shows the top 10 most active staff");
3012 hcommand_add("report", H_OPER
, helpmod_cmd_report
, "Sets the channel where to report this channels statistics every 5 minutes");
3014 hcommand_add("whoami", H_LAMER
, helpmod_cmd_whoami
, "Tells who you are to " HELPMOD_NICK
);
3015 hcommand_add("whois", H_STAFF
, helpmod_cmd_whois
, "Tells you who someone is");
3016 hcommand_add("command", H_LAMER
, helpmod_cmd_command
, "Gives detailed information on a command");
3017 hcommand_add("addchan", H_ADMIN
, helpmod_cmd_addchan
, "Joins " HELPMOD_NICK
" to a new channel");
3018 hcommand_add("delchan", H_ADMIN
, helpmod_cmd_delchan
, "Removes " HELPMOD_NICK
" permanently from a channel");
3019 hcommand_add("seen", H_STAFF
, helpmod_cmd_seen
, "Tells when a specific user/account has had activity");
3021 hcommand_add("op", H_STAFF
, helpmod_cmd_op
, "Sets mode +o on channels");
3022 hcommand_add("deop", H_STAFF
, helpmod_cmd_deop
, "Sets mode -o on channels");
3023 hcommand_add("voice", H_STAFF
, helpmod_cmd_voice
, "Sets mode +v on channels");
3024 hcommand_add("devoice", H_STAFF
, helpmod_cmd_devoice
, "Sets mode -v on channels");
3026 hcommand_add("invite", H_PEON
, helpmod_cmd_invite
, "Invites you to a channel");
3027 hcommand_add("ticket", H_TRIAL
, helpmod_cmd_ticket
, "Gives a ticket to be used with invite");
3028 hcommand_add("resolve", H_STAFF
, helpmod_cmd_resolve
, "Resolves (deletes) a ticket");
3029 hcommand_add("tickets", H_STAFF
, helpmod_cmd_tickets
, "Lists all valid tickets for a channel");
3030 hcommand_add("showticket", H_STAFF
, helpmod_cmd_showticket
, "Shows the ticket for the user");
3032 hcommand_add("termstats", H_OPER
, helpmod_cmd_termstats
, "Lists usage statistics for terms");
3033 hcommand_add("checkchannel", H_STAFF
, helpmod_cmd_checkchannel
, "Shows channel information for any channel");
3034 hcommand_add("statsdump", H_ADMIN
, helpmod_cmd_statsdump
, "Statistics dump command");
3035 hcommand_add("statsrepair", H_ADMIN
, helpmod_cmd_statsrepair
, "Statistics repair command");
3036 hcommand_add("statsreset", H_ADMIN
, helpmod_cmd_statsreset
, "Statistics reset command");
3038 hcommand_add("message", H_TRIAL
, helpmod_cmd_message
, "Sends a message to a channel");
3039 /*hcommand_add("megod", H_PEON, helpmod_cmd_megod, "Gives you userlevel 4, if you see this in the final version, please kill strutsi");*/
3040 /*hcommand_add("test", H_PEON, helpmod_cmd_test, "Gives you userlevel 4, if you see this in the final version, please kill strutsi");*/
3043 void helpmod_command(huser
*sender
, channel
* returntype
, char *args
)
3045 int argc
= 0, useless_var
;
3046 char args_copy
[512];
3047 char *parsed_args
[H_CMD_MAX_ARGS
+ 3], *ptr
= args_copy
;
3049 /* only accept commands from valid sources */
3050 if (huser_get_level(sender
) < H_PEON
|| huser_get_level(sender
) > H_ADMIN
)
3053 if (returntype
&& !strncmp(args
, helpmodnick
->nick
, strlen(helpmodnick
->nick
)))
3058 args
+=strlen(helpmodnick
->nick
)+1;
3061 if (*args
== '-' || *args
== '?')
3064 strcpy(args_copy
, args
);
3065 /* FIX stringituki */
3068 while (isspace(*ptr
) && *ptr
)
3074 if (*ptr
== '"' && strchr(ptr
+1, '"'))
3075 { /* string support */
3076 parsed_args
[argc
++] = ptr
+1;
3077 ptr
= strchr(ptr
+1, '"');
3081 while (!isspace(*ptr
) && *ptr
)
3089 parsed_args
[argc
++] = ptr
;
3091 while (!isspace(*ptr
) && *ptr
)
3104 /* old H compatibility */
3105 if (sscanf(parsed_args
[0], "%d", &useless_var
) && returntype
== NULL
)
3107 helpmod_cmd_help(sender
, NULL
, parsed_args
[0], 1, NULL
);
3112 char *ostr
= args
, **argv
= (char**)&parsed_args
; // for SKIP_WORD
3113 hcommand
*hcom
= hcommand_get(parsed_args
[0], huser_get_level(sender
));
3117 if ((sender
->account
== NULL
&& returntype
== NULL
) || (sender
->account
!= NULL
&& !(sender
->account
->flags
& H_NO_CMD_ERROR
)))
3118 helpmod_reply(sender
, returntype
, "Unknown command '%s', please see showcommands for a list of all commands available to you", parsed_args
[0]);
3123 hcom
->function(sender
, returntype
, ostr
, argc
, argv
);
3129 #undef DEFINE_HCHANNEL
3130 #undef HCHANNEL_VERIFY_AUTHORITY