]> jfr.im git - irc/quakenet/newserv.git/blob - helpmod2/hcommands.c
Initial Import
[irc/quakenet/newserv.git] / helpmod2 / hcommands.c
1 #include <string.h>
2 #include <ctype.h>
3 #include <stdio.h>
4
5 #include "../nick/nick.h"
6 #include "../channel/channel.h"
7 #include "../lib/irc_string.h"
8
9 #include "hcommands.h"
10 #include "hcommand.h"
11
12 #include "helpmod.h"
13 #include "klingon.h"
14 #include "helpmod_alias.h"
15
16 #include "haccount.h"
17 #include "hqueue.h"
18 #include "hterm.h"
19
20 #include "hgen.h"
21 #include "hban.h"
22 #include "hchanban.h"
23
24 #include "hticket.h"
25
26 #define HCMD_OUT_DEFAULT (10 * HDEF_m)
27
28 /* following are macros for use ONLY IN HERE
29 they may not look pretty, but work surprisingly well */
30
31 #define SKIP_WORD \
32 {\
33 if (*ostr == '"' && strchr(ostr+1, '"'))\
34 ostr = strchr(ostr+1, '"');\
35 while (!isspace(*ostr) && *ostr)\
36 ostr++;\
37 while (isspace(*ostr) && *ostr)\
38 ostr++;\
39 argc--;\
40 argv++;\
41 }
42
43 #define DEFINE_HCHANNEL \
44 {\
45 if (argc == 0)\
46 hchan = hchannel_get_by_channel(returntype);\
47 else if (*argv[0] == '#')\
48 {\
49 hchan = hchannel_get_by_name(argv[0]);\
50 SKIP_WORD;\
51 }\
52 else\
53 hchan = hchannel_get_by_channel(returntype);\
54 }
55
56 #define HCHANNEL_VERIFY_AUTHORITY(c, u)\
57 {\
58 if ((c) != NULL && !hchannel_authority((c), (u)))\
59 {\
60 helpmod_reply(u, returntype, "Sorry, channel %s is oper only", hchannel_get_name((c)));\
61 return;\
62 }\
63 }
64
65 enum
66 {
67 H_CMD_OP,
68 H_CMD_DEOP,
69 H_CMD_VOICE,
70 H_CMD_DEVOICE
71 };
72
73 enum
74 {
75 H_TERM_FIND,
76 H_TERM_MINUS,
77 H_TERM_PLUS
78 };
79
80 void helpmod_cmd_addchan (huser *sender, channel* returntype, char* ostr, int argc, char *argv[])
81 {
82 if (argc == 0)
83 {
84 helpmod_reply(sender, returntype, "Can not add channel: Channel not defined");
85 return;
86 }
87
88 if (*argv[0] != '#')
89 {
90 helpmod_reply(sender, returntype, "Can not add channel: Channel name must start with '#'");
91 return;
92 }
93
94 if (hchannel_get_by_name(argv[0]) != NULL)
95 {
96 helpmod_reply(sender, returntype, "Can not add channel: Channel %s already active", argv[0]);
97 return;
98 }
99
100 if (hchannel_add(argv[0]) != NULL)
101 {
102 helpmod_reply(sender, returntype, "Channel %s added succesfully", argv[0]);
103 return;
104 }
105 }
106
107 void helpmod_cmd_delchan (huser *sender, channel* returntype, char* ostr, int argc, char *argv[])
108 {
109 hchannel *hchan;
110 char buffer[256];
111 DEFINE_HCHANNEL;
112
113 if (hchan == NULL)
114 {
115 helpmod_reply(sender, returntype, "Can not delete channel: Channel not defined or not found");
116 return;
117 }
118 strcpy(buffer, hchan->real_channel->index->name->content);
119 if (argc == 0 || strcmp(argv[0], "YesImSure"))
120 {
121 helpmod_reply(sender, returntype, "Can not delete channel: Sanity check. Please add a parameter \"YesImSure\" to confirm channel deletion");
122 return;
123 }
124 hchannel_del(hchan);
125
126 helpmod_reply(sender, returntype, "Channel %s deleted succesfully", buffer);
127 }
128
129 void helpmod_cmd_whoami (huser *sender, channel* returntype, char* ostr, int argc, char *argv[])
130 {
131 helpmod_reply(sender, returntype, "You are %s", sender->real_user->nick);
132 helpmod_reply(sender, returntype, "Your userlevel is %s", hlevel_name(huser_get_level(sender)));
133 if (sender->account == NULL)
134 helpmod_reply(sender, returntype, "You do not have an account with me");
135 else
136 helpmod_reply(sender, returntype, "Your accounts name is %s", sender->account->name->content);
137 if (huser_get_level(sender) < H_TRIAL)
138 {
139 if (sender->lc[0] || sender->lc[1] || sender->lc[2])
140 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]);
141 else
142 helpmod_reply(sender, returntype, "You have not violated any rules");
143 }
144
145 {
146 int pos;
147 huser_channel *huserchan = sender->hchannels;
148 for (;huserchan;huserchan = huserchan->next)
149 if ((pos = hqueue_get_position(huserchan->hchan, sender)) > -1)
150 helpmod_reply(sender, returntype, "You have queue position #%d on channel %s", pos, hchannel_get_name(huserchan->hchan));
151 }
152
153 if (IsAccount(sender->real_user))
154 {
155 hchannel *hchan;
156 hticket *htick;
157 for (hchan = hchannels;hchan;hchan = hchan->next)
158 if (hchan->flags & H_REQUIRE_TICKET)
159 {
160 htick = hticket_get(sender->real_user->authname, hchan);
161 if (htick != NULL)
162 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));
163 }
164 }
165 }
166
167 void helpmod_cmd_whois (huser *sender, channel* returntype, char* ostr, int argc, char *argv[])
168 {
169 huser *husr;
170 int i;
171
172 if (argc == 0)
173 {
174 helpmod_reply(sender, returntype, "Can not get user information: User not specified");
175 return;
176 }
177 if (argc > H_CMD_MAX_ARGS)
178 argc = H_CMD_MAX_ARGS;
179
180 for (i=0;i<argc;i++)
181 {
182 husr = huser_get(getnickbynick(argv[i]));
183 if (husr == NULL)
184 {
185 helpmod_reply(sender, returntype, "Can not get user information: User %s not found", argv[i]);
186 continue;
187 }
188 helpmod_reply(sender, returntype, "User %s has userlevel %s", husr->real_user->nick,hlevel_name(huser_get_level(husr)));
189 if (husr->account == NULL)
190 helpmod_reply(sender, returntype, "User %s does not have an account with me", husr->real_user->nick);
191 else
192 helpmod_reply(sender, returntype, "User %s has account named %s", husr->real_user->nick,husr->account->name->content);
193 if (huser_get_level(husr) < H_TRIAL)
194 {
195 if (husr->lc[0] || husr->lc[1] || husr->lc[2])
196 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]);
197 else
198 helpmod_reply(sender, returntype, "User %s has no lamercontrol entries", husr->real_user->nick);
199 }
200 {
201 int pos;
202 huser_channel *huserchan = husr->hchannels;
203 for (;huserchan;huserchan = huserchan->next)
204 {
205 if ((pos = hqueue_get_position(huserchan->hchan, husr)) > -1)
206 helpmod_reply(sender, returntype, "User %s has queue queue position #%d on channel %s", husr->real_user->nick, pos, hchannel_get_name(huserchan->hchan));
207 if (on_desk(husr, huserchan))
208 helpmod_reply(sender, returntype, "User %s is receiving support on channel %s", husr->real_user->nick, hchannel_get_name(huserchan->hchan));
209 }
210 }
211 if (IsAccount(husr->real_user))
212 {
213 hchannel *hchan;
214 hticket *htick;
215 for (hchan = hchannels;hchan;hchan = hchan->next)
216 if (hchan->flags & H_REQUIRE_TICKET)
217 {
218 htick = hticket_get(husr->real_user->authname, hchan);
219 if (htick != NULL)
220 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));
221 }
222 }
223 }
224 }
225 /*
226 void helpmod_cmd_megod (huser *sender, channel* returntype, char* ostr, int argc, char *argv[])
227 {
228 if (sender->account == NULL)
229 sender->account = haccount_add(sender->real_user->nick, H_ADMIN);
230
231 sender->account->level = H_ADMIN;
232 }
233 */
234 /*
235 void helpmod_cmd_test (huser *sender, channel* returntype, char* ostr, int argc, char *argv[])
236 {
237 //lpmod_config_write("helpmod.db.test");
238 hchannel *hchan;
239
240 DEFINE_HCHANNEL;
241
242 helpmod_channick_modes(huser_get(getnickbynick(argv[0])), hchan, MC_DEVOICE, 1);
243 }
244 */
245
246 void helpmod_cmd_seen (huser *sender, channel* returntype, char* ostr, int argc, char *argv[])
247 {
248 huser *target_huser;
249 haccount *target_haccount;
250 int i;
251
252 if (argc == 0)
253 {
254 helpmod_reply(sender, returntype, "No targets specified for seen");
255 return;
256 }
257 for (i=0;i < argc;i++)
258 {
259 if (*argv[i] == '#')
260 { /* account */
261 if (!ci_strcmp(argv[i] + 1, HELPMOD_AUTH))
262 { /* A nice special case */
263 helpmod_reply(sender, returntype, "I'm right here");
264 continue;
265 }
266 target_haccount = haccount_get_by_name(argv[i]);
267 if (target_haccount == NULL)
268 {
269 helpmod_reply(sender, returntype, "Account %s not found", argv[i] + 1);
270 continue;
271 }
272
273 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));
274 }
275 else
276 {
277 if (getnickbynick(argv[i]) == helpmodnick)
278 { /* A nice special case */
279 helpmod_reply(sender, returntype, "I'm right here");
280 continue;
281 }
282 target_huser = huser_get(getnickbynick(argv[i]));
283 if (target_huser == NULL)
284 {
285 helpmod_reply(sender, returntype, "User %s not found", argv[i]);
286 continue;
287 }
288 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));
289 }
290 }
291 }
292
293 void helpmod_cmd_change_userlevel(huser *sender, hlevel target_level, channel* returntype, char* ostr, int argc, char *argv[])
294 {
295 huser *target_huser;
296 haccount *target_haccount;
297 int i;
298
299 if (argc == 0)
300 {
301 helpmod_reply(sender, returntype, "Incorrect syntax, nick or account required");
302 return ;
303 }
304
305 if (argc > H_CMD_MAX_ARGS)
306 argc = H_CMD_MAX_ARGS;
307
308 for (i = 0;i < argc;i++)
309 {
310 if (*argv[i] == '#') /* account */
311 {
312 target_haccount = haccount_get_by_name(argv[i]);
313 if (target_haccount == NULL)
314 {
315 helpmod_reply(sender, returntype, "Can not change userlevel: Account '%s' not found", argv[i]);
316 continue;
317 }
318 if (target_haccount->level > huser_get_level(sender))
319 {
320 helpmod_reply(sender, returntype, "Can not change userlevel: Account '%s' has a userlevel higher than yours", argv[i]);
321 continue;
322 }
323
324 if (target_haccount->level == target_level)
325 {
326 helpmod_reply(sender, returntype, "Can not change userlevel: Account '%s' already has userlevel %s", argv[i], hlevel_name(target_level));
327 continue;
328 }
329
330 target_haccount->level = target_level;
331
332 helpmod_reply(sender, returntype, "Userlevel changed: Account '%s' now has userlevel %s", argv[i], hlevel_name(target_level));
333
334 }
335 else
336 {
337 target_huser = huser_get(getnickbynick(argv[i]));
338 if (target_huser == NULL)
339 {
340 helpmod_reply(sender, returntype, "Can not change userlevel: User '%s' not found", argv[i]);
341 continue;
342 }
343 if (huser_get_level(target_huser) > huser_get_level(sender))
344 {
345 helpmod_reply(sender, returntype, "Can not change userlevel: User '%s' has a userlevel higher than yours", argv[i]);
346 continue;
347 }
348 if (huser_get_level(target_huser) == H_STAFF && huser_get_level(sender) == H_STAFF)
349 {
350 helpmod_reply(sender, returntype, "Can not change userlevel: User '%s' has the same userlevel as you have", argv[i]);
351 continue;
352 }
353
354 if (huser_get_level(target_huser) == target_level)
355 {
356 helpmod_reply(sender, returntype, "Can not change userlevel: User '%s' already has userlevel %s", argv[i], hlevel_name(target_level));
357 continue;
358 }
359 if (target_huser == sender)
360 {
361 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");
362 continue;
363 }
364 if (!IsAccount(target_huser->real_user))
365 {
366 helpmod_reply(sender, returntype, "Can not change userlevel: User '%s' is not authed", argv[i]);
367 continue;
368 }
369
370 if (target_huser->account == NULL)
371 {
372 if (haccount_get_by_name(target_huser->real_user->authname) != NULL)
373 {
374 helpmod_reply(sender, returntype, "Can not change userlevel: Unable to create an account. Account %s already exists", target_huser->real_user->authname);
375 continue;
376 }
377 else
378 target_huser->account = haccount_add(target_huser->real_user->authname, target_level);
379 }
380
381 target_huser->account->level = target_level;
382
383 helpmod_reply(sender, returntype, "Userlevel changed: User '%s' now has userlevel %s", argv[i], hlevel_name(target_level));
384 helpmod_reply(target_huser, NULL, "Your userlevel has been changed, your current userlevel is %s", hlevel_name(target_level));
385 }
386 }
387 }
388
389 /* pseudo commands for the above */
390 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); }
391 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); }
392 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); }
393 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); }
394 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); }
395 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); }
396
397 void helpmod_cmd_deluser (huser *sender, channel* returntype, char* ostr, int argc, char *argv[])
398 {
399 int i;
400 huser *target_huser;
401 haccount *target_haccount;
402
403 if (argc == 0)
404 {
405 helpmod_reply(sender, returntype, "Usage: deluser [nick|#account]");
406 return;
407 }
408
409 if (argc > H_CMD_MAX_ARGS)
410 argc = H_CMD_MAX_ARGS;
411
412 for (i = 0;i < argc;i++)
413 {
414 if (*argv[i] != '#')
415 {
416 target_huser = huser_get(getnickbynick(argv[i]));
417 if (target_huser == NULL)
418 {
419 helpmod_reply(sender, returntype, "Cannot delete the account: User %s does not exist", argv[i]);
420 continue;
421 }
422 if (target_huser->account == NULL)
423 {
424 helpmod_reply(sender, returntype, "Cannot delete the account: User %s does not have an account", argv[i]);
425 continue;
426 }
427 target_haccount = target_huser->account;
428 }
429 else
430 target_haccount = haccount_get_by_name(argv[i]);
431
432 if (target_haccount == NULL)
433 {
434 helpmod_reply(sender, returntype, "Cannot delete the account: Account %s does not exist", argv[i]);
435 continue;
436 }
437 if (target_haccount->level > huser_get_level(sender))
438 {
439 helpmod_reply(sender, returntype, "Cannot delete the account: Account %s has higher userlevel than you", target_haccount->name->content);
440 continue;
441 }
442 helpmod_reply(sender, returntype, "Account %s deleted", target_haccount->name->content);
443 haccount_del(target_haccount);
444 }
445 }
446
447 void helpmod_cmd_listuser (huser *sender, channel* returntype, char* ostr, int argc, char *argv[])
448 {
449 char *pattern;
450 haccount *hack = haccounts;
451 int count = 0, lvl = -1;
452 time_t timer;
453
454 if (argc > 0 && sscanf(argv[0], "%d", &lvl) && lvl >= H_LAMER && lvl <= H_ADMIN)
455 {
456 SKIP_WORD;
457 }
458 else
459 lvl = -1;
460
461 if (argc == 0)
462 pattern = "*";
463 else
464 pattern = argv[0];
465
466 if (lvl > 0)
467 helpmod_reply(sender, returntype, "%s accounts matching pattern %s: (account name, userlevel, expires in)", hlevel_name(lvl), pattern);
468 else
469 helpmod_reply(sender, returntype, "Accounts matching pattern %s: (account name, userlevel, expires in)", pattern);
470 for (;hack;hack = hack->next)
471 {
472 if (strregexp(hack->name->content, pattern))
473 {
474 if (lvl > 0 && hack->level != lvl)
475 continue;
476 timer = hack->last_activity + HELPMOD_ACCOUNT_EXPIRATION[hack->level];
477 helpmod_reply(sender, returntype, "%-16s %-32s %s", hack->name->content, hlevel_name(hack->level), asctime(localtime(&timer)));
478 count++;
479 }
480 }
481 if (lvl > 0)
482 helpmod_reply(sender, returntype, "%s accounts matching pattern %d", hlevel_name(lvl), count);
483 else
484 helpmod_reply(sender, returntype, "Accounts matching pattern %d", count);
485 }
486
487 void helpmod_cmd_censor (huser *sender, channel* returntype, char* ostr, int argc, char *argv[])
488 {
489 hchannel *hchan;
490 hcensor *hcens;
491 int i = 0;
492
493 DEFINE_HCHANNEL;
494
495 HCHANNEL_VERIFY_AUTHORITY(hchan, sender);
496
497 if (hchan == NULL)
498 {
499 helpmod_reply(sender, returntype, "Can not handle the censor: Channel not specified or found");
500 return;
501 }
502
503 if (argc < 2) /* view */
504 {
505 if (hchan->censor == NULL)
506 helpmod_reply(sender, returntype, "Nothing is censored on channel %s", hchan->real_channel->index->name->content);
507 else
508 {
509 helpmod_reply(sender, returntype, "Censored patterns for channel %s (%s):", hchan->real_channel->index->name->content, (hchan->flags & H_CENSOR)?"active":"inactive");
510 for (hcens = hchan->censor;hcens;hcens = hcens->next)
511 helpmod_reply(sender, returntype, "#%d %s%s%s", i++, hcens->pattern->content, hcens->reason?" :: ":"", hcens->reason?hcens->reason->content:"");
512 }
513 }
514 else
515 {
516 if (!ci_strcmp(argv[0], "add"))
517 {
518 char *pattern;
519 char *reason;
520
521 SKIP_WORD;
522 pattern = argv[0];
523 SKIP_WORD;
524 if (argc)
525 reason = ostr;
526 else
527 reason = NULL;
528
529 if (hcensor_get_by_pattern(hchan->censor, pattern))
530 {
531 helpmod_reply(sender, returntype, "Cannot add censor entry: Pattern '%s' already censored", pattern);
532 return;
533 }
534
535 if (hcensor_add(&hchan->censor, pattern, reason))
536 helpmod_reply(sender, returntype, "Pattern '%s' (%s) censored succesfully", pattern, reason?reason:"no reason specified");
537 else
538 helpmod_reply(sender, returntype, "Cannot add censor entry: Pattern '%s' already censored", pattern);
539
540 }
541 else if (!ci_strcmp(argv[0], "del"))
542 {
543 SKIP_WORD;
544 if (*argv[0] == '#')
545 {
546 int tmp;
547 if (!sscanf(argv[0], "#%d", &tmp))
548 {
549 helpmod_reply(sender, returntype, "Cannot delete censor entry: Bad index, integer expected");
550 return;
551 }
552 hcens = hcensor_get_by_index(hchan->censor, tmp);
553 }
554 else
555 hcens = hcensor_get_by_pattern(hchan->censor, argv[0]);
556
557 if (hcens == NULL)
558 helpmod_reply(sender, returntype, "Cannot delete censor entry: Entry not found");
559 else
560 {
561 hcensor_del(&hchan->censor, hcens);
562 helpmod_reply(sender, returntype, "Censor entry deleted succesfully");
563 }
564 }
565 else
566 helpmod_reply(sender, returntype, "Unknown censor command %s", argv[0]);
567 }
568 }
569
570 void helpmod_cmd_chanconf (huser *sender, channel* returntype, char* ostr, int argc, char *argv[])
571 {
572 hchannel *hchan;
573 int old_flags=0;
574
575 DEFINE_HCHANNEL;
576
577 HCHANNEL_VERIFY_AUTHORITY(hchan, sender);
578
579 if (hchan == NULL)
580 {
581 helpmod_reply(sender, returntype, "Can not change or view channel configuration: Channel not specified or found");
582 return;
583 }
584
585 if (argc == 0) /* view, spammy but with pretty formatting */
586 {
587 int i;
588 helpmod_reply(sender, returntype, "Channel configuration for %s:", hchan->real_channel->index->name->content);
589
590 for (i=0;i<=HCHANNEL_CONF_COUNT;i++)
591 helpmod_reply(sender, returntype, "(%02d) %-32s : %s", i, hchannel_get_sname(i), hchannel_get_state(hchan, 1 << i));
592 }
593 else /* change */
594 {
595 int i, tmp, type;
596 old_flags = hchan->flags;
597
598 if (argc > H_CMD_MAX_ARGS)
599 argc = H_CMD_MAX_ARGS;
600
601 for (i=0;i<argc;i++)
602 {
603 if (*argv[i] == '+')
604 {
605 type = 1;
606 argv[i]++;
607 }
608 else if (*argv[i] == '-')
609 {
610 type = -1;
611 argv[i]++;
612 }
613 else
614 type = 0;
615
616 if (!sscanf(argv[i], "%d", &tmp) || (tmp < 0) || (tmp > HCHANNEL_CONF_COUNT))
617 {
618 helpmod_reply(sender, returntype, "Can not change channel configuration: Expected integer between [0, %d]", HCHANNEL_CONF_COUNT);
619 continue;
620 }
621
622 switch (type)
623 {
624 case -1: /* unset */
625 hchan->flags &= ~(1 << tmp);
626 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));
627 break;
628 case 0: /* view */
629 helpmod_reply(sender, returntype, "(%02d) %-32s : %s", tmp, hchannel_get_sname(tmp), hchannel_get_state(hchan, 1 << tmp));
630 break;
631 case 1: /* set */
632 hchan->flags |= (1 << tmp);
633 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));
634 break;
635 }
636 }
637 hchannel_conf_change(hchan, old_flags);
638 }
639 }
640
641 void helpmod_cmd_acconf (huser *sender, channel* returntype, char* ostr, int argc, char *argv[])
642 {
643 haccount *hacc = sender->account;
644
645 if (hacc == NULL)
646 {
647 helpmod_reply(sender, returntype, "Account configuration impossible: You do not have an account");
648 return;
649 }
650
651 if (argc == 0) /* view, spammy but with pretty formatting */
652 {
653 int i;
654 helpmod_reply(sender, returntype, "Account configuration for %s:", hacc->name->content);
655
656 for (i=0;i<=HACCOUNT_CONF_COUNT;i++)
657 helpmod_reply(sender, returntype, "(%02d) %-35s : %s", i, haccount_get_sname(i), haccount_get_state(hacc, 1 << i));
658 }
659 else /* change */
660 {
661 int i, tmp, type;
662
663 if (argc > H_CMD_MAX_ARGS)
664 argc = H_CMD_MAX_ARGS;
665
666 for (i=0;i<argc;i++)
667 {
668 if (*argv[i] == '+')
669 {
670 type = 1;
671 argv[i]++;
672 }
673 else if (*argv[i] == '-')
674 {
675 type = -1;
676 argv[i]++;
677 }
678 else
679 type = 0;
680
681 if (!sscanf(argv[i], "%d", &tmp) || (tmp < 0) || (tmp > HACCOUNT_CONF_COUNT))
682 {
683 helpmod_reply(sender, returntype, "Can not change account configuration: Expected integer between [0, %d]", HACCOUNT_CONF_COUNT);
684 continue;
685 }
686
687 switch (type)
688 {
689 case -1: /* unset */
690 hacc->flags &= ~(1 << tmp);
691 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));
692 break;
693 case 0: /* view */
694 helpmod_reply(sender, returntype, "(%02d) %-35s : %s", tmp, haccount_get_sname(tmp), haccount_get_state(hacc, 1 << tmp));
695 break;
696 case 1: /* set */
697 hacc->flags |= (1 << tmp);
698 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));
699 break;
700 }
701 }
702 }
703 }
704
705 void helpmod_cmd_welcome (huser *sender, channel* returntype, char* ostr, int argc, char *argv[])
706 {
707 hchannel *hchan;
708
709 DEFINE_HCHANNEL;
710
711 HCHANNEL_VERIFY_AUTHORITY(hchan, sender);
712
713 if (hchan == NULL)
714 {
715 helpmod_reply(sender, returntype, "Can not change or view chanflags: Channel not specified or found");
716 return;
717 }
718
719 if (argc == 0) /* view */
720 {
721 helpmod_reply(sender, returntype, "Welcome for channel %s (%s): %s", hchan->real_channel->index->name->content, hchannel_get_state(hchan, H_WELCOME), hchan->welcome);
722 }
723 else
724 {
725 strcpy(hchan->welcome, ostr);
726 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);
727 }
728 }
729
730 void helpmod_cmd_aliases (huser *sender, channel* returntype, char* ostr, int argc, char *argv[])
731 {
732 char buf[512];
733 int i = 0;
734 void helpmod_list_aliases(alias_tree node)
735 {
736 if (i > 256)
737 {
738 helpmod_reply(sender, returntype, buf);
739 i = 0;
740 }
741 if (!node)
742 return;
743 sprintf(buf+i,"%.200s ",node->name->content);
744 i+=(1+strlen(node->name->content));
745 helpmod_list_aliases(node->left);
746 helpmod_list_aliases(node->right);
747 }
748 helpmod_list_aliases(aliases);
749 if (i)
750 helpmod_reply(sender, returntype, buf);
751 }
752
753 void helpmod_cmd_showcommands (huser *sender, channel* returntype, char* ostr, int argc, char *argv[])
754 {
755 int level = H_PEON;
756 hcommand *tmp;
757
758 if (!(argc && (sscanf(argv[0], "%d", &level)) && (level >= 0) && (level <= huser_get_level(sender))))
759 level = huser_get_level(sender);
760
761 helpmod_reply(sender, returntype, "HelpMod %s commands for userlevel %s:", HELPMOD_VERSION, hlevel_name(level));
762
763 hcommand_list(H_NONE);
764
765 while ((tmp = hcommand_list(level)) != NULL)
766 helpmod_reply(sender, returntype, "%-16s %s", tmp->name->content, tmp->help->content);
767
768 return;
769 }
770
771 void helpmod_cmd_lamercontrol (huser *sender, channel* returntype, char* ostr, int argc, char *argv[])
772 {
773 hchannel *hchan;
774 hlc_profile *ptr;
775
776 DEFINE_HCHANNEL;
777
778 HCHANNEL_VERIFY_AUTHORITY(hchan, sender);
779
780 if (hchan == NULL) /* list profiles */
781 {
782 helpmod_reply(sender, returntype, "Following lamercontrol profiles are available:");
783 for (ptr = hlc_profiles;ptr;ptr = ptr->next)
784 helpmod_reply(sender, returntype, "%s", ptr->name->content);
785 return;
786 }
787 if (argc == 0)
788 {
789 if (hchan->lc_profile == NULL)
790 helpmod_reply(sender, returntype, "Channel %s has no lamercontrol profile set", hchannel_get_name(hchan));
791 else
792 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));
793 return;
794 }
795 if (!ci_strcmp(argv[0], "list"))
796 {
797 helpmod_reply(sender, returntype, "Following lamercontrol profiles are available:");
798 for (ptr = hlc_profiles;ptr;ptr = ptr->next)
799 helpmod_reply(sender, returntype, "%s", ptr->name->content);
800 return;
801 }
802 ptr = hlc_get(argv[0]);
803 if (ptr == NULL)
804 {
805 helpmod_reply(sender, returntype, "Can not set the lamercontrol profile: Profile %s does not exist:", argv[0]);
806 return;
807 }
808 else
809 {
810 hchan->lc_profile = ptr;
811 helpmod_reply(sender, returntype, "Lamercontrol profile %s set to channel %s succesfully",ptr->name->content,hchannel_get_name(hchan));
812 }
813
814 }
815
816 void helpmod_cmd_term_find_general (huser *sender, channel* returntype, int type, char* ostr, int argc, char *argv[])
817 {
818 hterm *htrm;
819 hterm *source;
820 hchannel *hchan;
821 huser *targets[6];
822 int i,ntargets = 0;
823
824 DEFINE_HCHANNEL;
825
826 if (hchan == NULL)
827 source = hterms;
828 else
829 source = hchan->channel_hterms;
830
831 if (argc == 0)
832 {
833 if (type == H_TERM_PLUS)
834 hqueue_advance(hchan, sender, 1);
835 else
836 helpmod_reply(sender, returntype, "Can not find term: Term not specified");
837 return;
838 }
839 htrm = hterm_get_and_find(source, argv[0]);
840 if (htrm == NULL)
841 {
842 helpmod_reply(sender, returntype, "No term found matching '%s'", argv[0]);
843 return;
844 }
845 if (returntype != NULL && huser_get_level(sender) > H_PEON)
846 {
847 HCHANNEL_VERIFY_AUTHORITY(hchan, sender);
848
849 if (argc > 1)
850 {
851 SKIP_WORD;
852 if (argc > H_CMD_MAX_ARGS)
853 argc = H_CMD_MAX_ARGS;
854 for (i=0;i<argc;i++)
855 {
856 targets[ntargets] = huser_get(getnickbynick(argv[i]));
857 if (targets[ntargets] == NULL)
858 {
859 helpmod_reply(sender, returntype, "Error using ?: User %s not found", argv[i]);
860 continue;
861 }
862 else
863 ntargets++;
864 }
865 }
866
867 if (ntargets == 0)
868 helpmod_message_channel_long(hchannel_get_by_channel(returntype), "(%s): %s", htrm->name->content, htrm->description->content);
869 else
870 {
871 char buffer[256] = "";
872 for (i=0;i<ntargets;i++)
873 {
874 strcat(buffer, " ");
875 strcat(buffer, targets[i]->real_user->nick);
876 }
877
878 helpmod_message_channel_long(hchannel_get_by_channel(returntype), "%s: (%s) %s", buffer, htrm->name->content, htrm->description->content);
879 if (type != H_TERM_FIND)
880 {
881 if (hchan->flags & H_QUEUE)
882 {
883 for (i=0;i<ntargets;i++)
884 {
885 huser_channel *huserchan = huser_on_channel(targets[i], hchan);
886 huserchan->flags |= HQUEUE_DONE;
887 if (huserchan->flags & HCUMODE_VOICE)
888 helpmod_channick_modes(targets[i], hchan, MC_DEVOICE, HLAZY);
889 }
890 if (type == H_TERM_PLUS)
891 hqueue_advance(hchan, sender, ntargets);
892 }
893 }
894 }
895 }
896 else
897 helpmod_reply(sender, returntype, "(%s): %s", htrm->name->content, htrm->description->content);
898 }
899
900 void helpmod_cmd_term_find (huser *sender, channel* returntype, char* ostr, int argc, char *argv[])
901 {
902 helpmod_cmd_term_find_general(sender, returntype, H_TERM_FIND, ostr, argc, argv);
903 }
904
905 void helpmod_cmd_term_find_minus (huser *sender, channel* returntype, char* ostr, int argc, char *argv[])
906 {
907 helpmod_cmd_term_find_general(sender, returntype, H_TERM_MINUS, ostr, argc, argv);
908 }
909
910 void helpmod_cmd_term_find_plus (huser *sender, channel* returntype, char* ostr, int argc, char *argv[])
911 {
912 helpmod_cmd_term_find_general(sender, returntype, H_TERM_PLUS, ostr, argc, argv);
913 }
914
915 void helpmod_cmd_klingon (huser *sender, channel* returntype, char* ostr, int argc, char *argv[])
916 {
917 hchannel *hchan;
918 huser *target = NULL;
919 int rand_val;
920
921 DEFINE_HCHANNEL;
922
923 if (hchan == NULL)
924 {
925 rand_val = rand() % KLINGON_NTARGETED;
926 helpmod_reply(sender, NULL, "%s: %s", sender->real_user->nick, klingon_targeted[rand_val]);
927 return;
928 }
929
930 if (argc)
931 target = huser_get(getnickbynick(argv[0]));
932
933 if (target)
934 {
935 rand_val = rand() % KLINGON_NTARGETED;
936 helpmod_message_channel(hchan, "%s: %s", target->real_user->nick, klingon_targeted[rand_val]);
937 }
938 else
939 {
940 rand_val = rand() % KLINGON_NGENERAL;
941 helpmod_message_channel(hchan, "%s", klingon_general[rand_val]);
942 }
943 }
944
945 void helpmod_cmd_term (huser *sender, channel* returntype, char* ostr, int argc, char *argv[])
946 {
947 hterm *htrm;
948 hterm **source;
949 hchannel *hchan;
950
951 DEFINE_HCHANNEL;
952
953 HCHANNEL_VERIFY_AUTHORITY(hchan, sender);
954
955 if (hchan == NULL)
956 source = &hterms;
957 else
958 source = &hchan->channel_hterms;
959
960 if (argc == 0)
961 {
962 helpmod_reply(sender, returntype, "Can not handle terms: Operation not specified");
963 return;
964 }
965 if (!ci_strcmp(argv[0], "list"))
966 {
967 char buffer[512];
968 int count = 0;
969 char *pattern = "*";
970
971 buffer[0] = '\0';
972 htrm = *source;
973
974 if (argc > 2)
975 pattern = argv[1];
976 else
977 pattern = "*";
978
979 helpmod_reply(sender, returntype, "Terms matching pattern '%s'", pattern);
980 for (;htrm;htrm = htrm->next)
981 {
982 if (strlen(buffer) >= 250)
983 {
984 helpmod_reply(sender, returntype, buffer);
985 buffer[0] = '\0';
986 }
987 if (strregexp(htrm->description->content, pattern) || strregexp(htrm->name->content, pattern))
988 {
989 sprintf(buffer+strlen(buffer) /* :) */, "%s(%d) ", htrm->name->content, strlen(htrm->description->content));
990 count++;
991 }
992 }
993 if (buffer[0])
994 helpmod_reply(sender, returntype, buffer);
995 helpmod_reply(sender, returntype, "%d term%s match%s pattern '%s'", count, (count == 1)?"":"s", (count == 1)?"es":"", pattern);
996 }
997 else if (!ci_strcmp(argv[0], "listfull"))
998 {
999 htrm = *source;
1000 helpmod_reply(sender, returntype, "Following terms have been entered:");
1001 for (;htrm;htrm = htrm->next)
1002 helpmod_reply(sender, returntype, "(%s): %s", htrm->name->content, htrm->description->content);
1003 }
1004 else if (!ci_strcmp(argv[0], "get"))
1005 {
1006 if (argc < 2)
1007 {
1008 helpmod_reply(sender, returntype, "Can not get term: Term not specified");
1009 return;
1010 }
1011 htrm = hterm_get(*source, argv[1]);
1012 if (htrm == NULL)
1013 helpmod_reply(sender, returntype, "Can not get term: Term %s not found", argv[1]);
1014 else
1015 helpmod_reply(sender, returntype, "(%s): %s", htrm->name->content, htrm->description->content);
1016 }
1017 else if (!ci_strcmp(argv[0], "add"))
1018 {
1019 if (argc < 2)
1020 helpmod_reply(sender, returntype, "Can not add term: Term name not specified");
1021 else if (argc < 3)
1022 helpmod_reply(sender, returntype, "Can not add term: Term description not specified");
1023 else if ((htrm = hterm_get(*source, argv[1])) != NULL)
1024 helpmod_reply(sender, returntype, "Can not add term: Term %s is already added", argv[1]);
1025 else
1026 {
1027 char *name = argv[1], *description;
1028 SKIP_WORD; SKIP_WORD;
1029 description = ostr;
1030 htrm = hterm_add(source, name, description);
1031 helpmod_reply(sender, returntype, "Term %s added succesfully", name);
1032 }
1033 }
1034 else if (!ci_strcmp(argv[0], "del"))
1035 {
1036 int i;
1037 if (argc < 2)
1038 {
1039 helpmod_reply(sender, returntype, "Can not delete term: Term name not specified");
1040 return;
1041 }
1042 if (argc > H_CMD_MAX_ARGS)
1043 argc = H_CMD_MAX_ARGS;
1044 for (i=1;i<argc;i++)
1045 {
1046 htrm = hterm_get(*source, argv[i]);
1047 if (htrm == NULL)
1048 {
1049 helpmod_reply(sender, returntype, "Can not delete term: Term %s not found", argv[i]);
1050 continue;
1051 }
1052 hterm_del(source, htrm);
1053 helpmod_reply(sender, returntype, "Term %s deleted succesfully", argv[i]);
1054 }
1055
1056 }
1057 else if (!ci_strcmp(argv[0], "find"))
1058 {
1059 if (argc < 2)
1060 {
1061 helpmod_reply(sender, returntype, "Can not find term: Term name not specified");
1062 return;
1063 }
1064 htrm = hterm_get_and_find(*source, argv[1]);
1065
1066 if (htrm == NULL)
1067 {
1068 helpmod_reply(sender, returntype, "No term found matching '%s'", argv[0]);
1069 return;
1070 }
1071 if (returntype != NULL && huser_get_level(sender) > H_PEON)
1072 helpmod_message_channel(hchannel_get_by_channel(returntype), "(%s): %s", htrm->name->content, htrm->description->content);
1073 else
1074 helpmod_reply(sender, returntype, "(%s): %s", htrm->name->content, htrm->description->content);
1075 }
1076 else
1077 {
1078 helpmod_reply(sender, returntype, "Can not handle terms: Operation not specified");
1079 }
1080 }
1081
1082 void helpmod_cmd_queue (huser *sender, channel* returntype, char* ostr, int argc, char *argv[])
1083 {
1084 hchannel *hchan;
1085 int operation;
1086
1087 DEFINE_HCHANNEL;
1088
1089 HCHANNEL_VERIFY_AUTHORITY(hchan, sender);
1090
1091 if (argc == 0)
1092 {
1093 helpmod_reply(sender, returntype, "Can not handle queue: Operation not specified");
1094 return;
1095 }
1096
1097 if (!ci_strcmp(argv[0], "done"))
1098 operation = HQ_DONE;
1099 else if (!ci_strcmp(argv[0], "next"))
1100 operation = HQ_NEXT;
1101 else if (!ci_strcmp(argv[0], "on"))
1102 operation = HQ_ON;
1103 else if (!ci_strcmp(argv[0], "off"))
1104 operation = HQ_OFF;
1105 else if (!ci_strcmp(argv[0], "maintain"))
1106 operation = HQ_MAINTAIN;
1107 else if (!ci_strcmp(argv[0], "list"))
1108 operation = HQ_LIST;
1109 else if (!ci_strcmp(argv[0], "summary"))
1110 operation = HQ_SUMMARY;
1111 else if (!ci_strcmp(argv[0], "reset"))
1112 operation = HQ_RESET;
1113 else
1114 operation = HQ_NONE;
1115
1116 SKIP_WORD;
1117
1118 helpmod_queue_handler(sender, returntype, hchan, operation, ostr, argc, argv);
1119 }
1120
1121 void helpmod_cmd_done (huser *sender, channel* returntype, char* ostr, int argc, char *argv[])
1122 {
1123 hchannel *hchan;
1124 DEFINE_HCHANNEL;
1125 HCHANNEL_VERIFY_AUTHORITY(hchan, sender);
1126 helpmod_queue_handler(sender, returntype, hchan, HQ_DONE, ostr, argc, argv);
1127 }
1128
1129 void helpmod_cmd_next (huser *sender, channel* returntype, char* ostr, int argc, char *argv[])
1130 {
1131 hchannel *hchan;
1132 DEFINE_HCHANNEL;
1133 HCHANNEL_VERIFY_AUTHORITY(hchan, sender);
1134 helpmod_queue_handler(sender, returntype, hchan, HQ_NEXT, ostr, argc, argv);
1135 }
1136
1137 void helpmod_cmd_enqueue (huser *sender, channel* returntype, char* ostr, int argc, char *argv[])
1138 {
1139 hchannel *hchan;
1140 DEFINE_HCHANNEL;
1141 HCHANNEL_VERIFY_AUTHORITY(hchan, sender);
1142 helpmod_queue_handler(sender, returntype, hchan, HQ_ON, ostr, argc, argv);
1143 }
1144
1145 void helpmod_cmd_dequeue (huser *sender, channel* returntype, char* ostr, int argc, char *argv[])
1146 {
1147 hchannel *hchan;
1148 DEFINE_HCHANNEL;
1149 HCHANNEL_VERIFY_AUTHORITY(hchan, sender);
1150 helpmod_queue_handler(sender, returntype, hchan, HQ_OFF, ostr, argc, argv);
1151 }
1152
1153 void helpmod_cmd_autoqueue (huser *sender, channel* returntype, char* ostr, int argc, char *argv[])
1154 {
1155 hchannel *hchan;
1156 DEFINE_HCHANNEL;
1157 HCHANNEL_VERIFY_AUTHORITY(hchan, sender);
1158 helpmod_queue_handler(sender, returntype, hchan, HQ_MAINTAIN, ostr, argc, argv);
1159 }
1160
1161 void helpmod_cmd_dnmo (huser *sender, channel* returntype, char* ostr, int argc, char *argv[])
1162 {
1163 int i;
1164 if (argc == 0)
1165 {
1166 helpmod_reply(sender, returntype, "Can not correct the luser: User not defined");
1167 return;
1168 }
1169 if (argc > H_CMD_MAX_ARGS)
1170 argc = H_CMD_MAX_ARGS;
1171 for (i=0;i<argc;i++)
1172 {
1173 huser *husr = huser_get(getnickbynick(argv[i]));
1174 if (husr == NULL)
1175 {
1176 helpmod_reply(sender, returntype, "Can not correct the luser: User %s not found", argv[i]);
1177 continue;
1178 }
1179 /*
1180 if (!hchannels_on_queue(husr) && !hchannels_on_desk(husr))
1181 {
1182 helpmod_reply(sender, returntype, "Can not correct the luser: User %s is not in any queue", argv[i]);
1183 continue;
1184 }
1185 */
1186 hchannels_dnmo(husr);
1187
1188 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");
1189 helpmod_reply(sender, returntype, "User %s has been informed of his mistake", argv[i]);
1190 }
1191 { /* fix the autoqueue for the channel(s) */
1192 hchannel *hchan;
1193 for (hchan = hchannels;hchan;hchan = hchan->next)
1194 hqueue_handle_queue(hchan, sender);
1195 }
1196 }
1197
1198 void helpmod_cmd_ban (huser *sender, channel* returntype, char* ostr, int argc, char *argv[])
1199 {
1200 if (argc == 0)
1201 {
1202 helpmod_reply(sender, returntype, "Can not global handle bans: Operation not defined");
1203 return;
1204 }
1205
1206 else if (!ci_strcmp(argv[0], "list"))
1207 {
1208 hban *ptr = hbans;
1209 char *pattern;
1210 int count = 0;
1211
1212 if (argc == 1)
1213 pattern = "*";
1214 else
1215 pattern = argv[1];
1216
1217 helpmod_reply(sender, returntype, "Global bans matching pattern %s", pattern);
1218
1219 for (;ptr;ptr = ptr->next)
1220 if (strregexp(bantostring(ptr->real_ban), pattern))
1221 {
1222 helpmod_reply(sender, returntype, "%-64s %-15s %s", bantostring(ptr->real_ban), helpmod_strtime(ptr->expiration - time(NULL)), ptr->reason?ptr->reason->content:"");
1223 count++;
1224 }
1225
1226 helpmod_reply(sender, returntype, "%d Global bans match pattern %s", count, pattern);
1227 }
1228
1229 else if (!ci_strcmp(argv[0], "add"))
1230 {
1231 int duration = 4 * HDEF_h;
1232 char *reason = "Banned";
1233 char *target = argv[1];
1234
1235 if (argc == 1)
1236 {
1237 helpmod_reply(sender, returntype, "Can not add global ban: Target hostmask not defined");
1238 return;
1239 }
1240 if (argc >= 3)
1241 {
1242 if ((duration = helpmod_read_strtime(argv[2])) < 0)
1243 {
1244 helpmod_reply(sender, returntype, "Can not add global ban: Invalid time %s", argv[2]);
1245 return;
1246 }
1247 }
1248 if (argc >= 4)
1249 {
1250 SKIP_WORD;
1251 SKIP_WORD;
1252 SKIP_WORD;
1253
1254 reason = ostr;
1255 }
1256 hban_add(target, reason, time(NULL) + duration, 0);
1257 helpmod_reply(sender, returntype, "Added ban for %s (%s), expires in %s", target, reason, helpmod_strtime(duration));
1258 }
1259 else if (!ci_strcmp(argv[0], "del"))
1260 {
1261 int i;
1262 if (argc == 1)
1263 {
1264 helpmod_reply(sender, returntype, "Can not remove global ban: Target hostmask not defined");
1265 return;
1266 }
1267 if (argc > H_CMD_MAX_ARGS)
1268 argc = H_CMD_MAX_ARGS;
1269 for (i=1;i<argc;i++)
1270 {
1271 hban *ptr = hban_get(argv[i]);
1272 if (ptr == NULL)
1273 {
1274 helpmod_reply(sender, returntype, "Can not remove global ban: Hostmask %s is not banned", argv[i]);
1275 continue;
1276 }
1277 helpmod_reply(sender, returntype, "Global ban for hostmask %s removed", argv[i]);
1278 hban_del(ptr,0);
1279 }
1280 }
1281 else
1282 {
1283 helpmod_reply(sender, returntype, "Can not handle global bans: Unknown operation %s", argv[0]);
1284 return;
1285 }
1286 }
1287
1288 void helpmod_cmd_chanban (huser *sender, channel* returntype, char* ostr, int argc, char *argv[])
1289 {
1290 hchannel *hchan;
1291 int i;
1292
1293 DEFINE_HCHANNEL;
1294
1295 if (hchan == NULL)
1296 {
1297 helpmod_reply(sender, returntype, "Can not handle channel bans: Channel not defined or not found");
1298 return;
1299 }
1300
1301 HCHANNEL_VERIFY_AUTHORITY(hchan, sender);
1302
1303 if (argc == 0)
1304 {
1305 helpmod_reply(sender, returntype, "Can not handle channel bans: Operation not defined");
1306 return;
1307 }
1308
1309 if (!ci_strcmp(argv[0], "list"))
1310 {
1311 char *pattern, *cban;
1312 chanban *ptr = hchan->real_channel->bans;
1313 int count = 0;
1314
1315 if (argc == 1)
1316 pattern = "*";
1317 else
1318 pattern = argv[1];
1319
1320 helpmod_reply(sender, returntype, "Bans matching pattern %s for channel %s", pattern, hchannel_get_name(hchan));
1321 for (;ptr;ptr = ptr->next)
1322 if (strregexp((cban = bantostring(ptr)), pattern))
1323 {
1324 count++;
1325 if (hchanban_get(hchan,cban))
1326 helpmod_reply(sender, returntype, "%s Expires in %s", bantostring(ptr), helpmod_strtime(hchanban_get(hchan, cban)->expiration - time(NULL)));
1327 else
1328 helpmod_reply(sender, returntype, "%s", bantostring(ptr));
1329 }
1330 helpmod_reply(sender, returntype, "%d bans match pattern %s on channel %s", count, pattern, hchannel_get_name(hchan));
1331 }
1332 else if (!ci_strcmp(argv[0], "add"))
1333 {
1334 if (argc == 1)
1335 {
1336 helpmod_reply(sender, returntype, "Can not add channel bans: Pattern not defined");
1337 return;
1338 }
1339 if (argc > H_CMD_MAX_ARGS)
1340 argc = H_CMD_MAX_ARGS;
1341 for (i=1;i<argc;i++)
1342 {
1343 /* POSSIBLE BUG ? */
1344 helpmod_setban(hchan, argv[i], H_ETERNITY, MCB_ADD, HLAZY);
1345 helpmod_reply(sender, returntype, "Added ban %s to channel %s", argv[i], hchannel_get_name(hchan));
1346 }
1347 }
1348 else if (!ci_strcmp(argv[0], "del"))
1349 {
1350 if (argc == 1)
1351 {
1352 helpmod_reply(sender, returntype, "Can not remove channel bans: Pattern not defined");
1353 return;
1354 }
1355 if (argc > H_CMD_MAX_ARGS)
1356 argc = H_CMD_MAX_ARGS;
1357 for (i=1;i<argc;i++)
1358 {
1359 chanban *ptr = hchan->real_channel->bans;
1360 for (;ptr;ptr = ptr->next)
1361 if (strregexp(bantostring(ptr), argv[i]))
1362 {
1363 helpmod_setban(hchan, argv[i], 0, MCB_DEL, HLAZY);
1364 helpmod_reply(sender, returntype, "Channel ban %s removed from channel %s", argv[i], hchannel_get_name(hchan));
1365 break;
1366 }
1367 if (ptr == NULL)
1368 helpmod_reply(sender, returntype, "Can not remove channel ban: Pattern %s not banned on channel %s", argv[i], hchannel_get_name(hchan));
1369 }
1370 }
1371 else
1372 {
1373 helpmod_reply(sender, returntype, "Can not handle channel bans: Unknown operation %s", argv[0]);
1374 return;
1375 }
1376 }
1377
1378 void helpmod_cmd_idlekick (huser *sender, channel* returntype, char* ostr, int argc, char *argv[])
1379 {
1380 hchannel *hchan;
1381 int tmp;
1382
1383 DEFINE_HCHANNEL;
1384
1385 HCHANNEL_VERIFY_AUTHORITY(hchan, sender);
1386
1387 if (hchan == NULL)
1388 {
1389 helpmod_reply(sender, returntype, "Can not handle the idlekick: Channel not defined or not found");
1390 return;
1391 }
1392 if (argc == 0) /* view */
1393 {
1394 helpmod_reply(sender, returntype, "Idlekick for channel %s is set to %s", hchannel_get_name(hchan), helpmod_strtime(hchan->max_idle));
1395 return;
1396 }
1397 else if ((tmp = helpmod_read_strtime(argv[0])) < 0 || tmp < HDEF_m || tmp > HDEF_w)
1398 {
1399 helpmod_reply(sender, returntype, "Can not set the idlekick: Invalid time given '%s'", argv[0]);
1400 return;
1401 }
1402 else /* set it ! */
1403 {
1404 hchan->max_idle = tmp;
1405 helpmod_reply(sender, returntype, "Idlekick for channel %s set to %s succesfully", hchannel_get_name(hchan), helpmod_strtime(hchan->max_idle));
1406 }
1407 }
1408
1409 void helpmod_cmd_topic (huser *sender, channel* returntype, char* ostr, int argc, char *argv[])
1410 {
1411 hchannel *hchan;
1412 DEFINE_HCHANNEL;
1413
1414 HCHANNEL_VERIFY_AUTHORITY(hchan, sender);
1415
1416 if (hchan == NULL)
1417 {
1418 helpmod_reply(sender, returntype, "Can not handle the topic: Channel not defined or not found");
1419 return;
1420 }
1421 if (!(hchan -> flags & H_HANDLE_TOPIC))
1422 helpmod_reply(sender, returntype, "Note: I'm not set to handle the topic on channel %s", hchannel_get_name(hchan));
1423
1424 if (argc == 0) /* check the topic */
1425 {
1426 helpmod_reply(sender, returntype, "Topic of channel %s is currently: %s", hchannel_get_name(hchan), htopic_construct(hchan->topic));
1427 return;
1428 }
1429 if (!ci_strcmp(argv[0], "erase"))
1430 {
1431 htopic_del_all(&hchan->topic);
1432 hchannel_set_topic(hchan);
1433 helpmod_reply(sender, returntype, "Topic of channel %s erased", hchannel_get_name(hchan));
1434 }
1435 else if (!ci_strcmp(argv[0], "refresh"))
1436 {
1437 hchannel_set_topic(hchan);
1438 helpmod_reply(sender, returntype, "Topic of channel %s refreshed", hchannel_get_name(hchan));
1439 }
1440 else if (!ci_strcmp(argv[0], "add"))
1441 {
1442 int pos;
1443 SKIP_WORD;
1444 if (argc == 0)
1445 {
1446 helpmod_reply(sender, returntype, "Cannot handle the topic of channel %s: Additional arguments required", hchannel_get_name(hchan));
1447 return;
1448 }
1449 if (sscanf(argv[0], "%d", &pos) && pos >= 0)
1450 {
1451 SKIP_WORD;
1452 }
1453 else
1454 pos = 0;
1455 if (argc == 0) /* lame repeat :( */
1456 {
1457 helpmod_reply(sender, returntype, "Cannot handle the topic of channel %s: Additional arguments required", hchannel_get_name(hchan));
1458 return;
1459 }
1460 if (htopic_len(hchan->topic) + strlen(ostr) + 3 > TOPICLEN)
1461 {
1462 helpmod_reply(sender, returntype, "Cannot add to the topic of channel %s: Maximum topic length exceeded", hchannel_get_name(hchan));
1463 return;
1464 }
1465
1466 htopic_add(&hchan->topic, ostr, pos);
1467 hchannel_set_topic(hchan);
1468 helpmod_reply(sender, returntype, "Added '%s' to the topic of channel %s", ostr, hchannel_get_name(hchan));
1469 }
1470 else if (!ci_strcmp(argv[0], "del"))
1471 {
1472 int pos;
1473 if (argc == 1)
1474 {
1475 helpmod_reply(sender, returntype, "Cannot handle the topic of channel %s: Additional arguments required", hchannel_get_name(hchan));
1476 return;
1477 }
1478 SKIP_WORD;
1479 if (!sscanf(argv[0], "%d", &pos) || pos < 0)
1480 {
1481 helpmod_reply(sender, returntype, "Cannot handle the topic of channel %s: Expected positive integer", hchannel_get_name(hchan));
1482 return;
1483 }
1484 if (htopic_count(hchan->topic) < pos)
1485 {
1486 helpmod_reply(sender, returntype, "Cannot delete from the topic of channel %s: No such topic element %d", hchannel_get_name(hchan), pos);
1487 return;
1488 }
1489 htopic_del(&hchan->topic, htopic_get(hchan->topic, pos));
1490 hchannel_set_topic(hchan);
1491 }
1492 else if (!ci_strcmp(argv[0], "set"))
1493 {
1494 if (argc == 1)
1495 {
1496 helpmod_reply(sender, returntype, "Cannot handle the topic of channel %s: Additional arguments required", hchannel_get_name(hchan));
1497 return;
1498 }
1499 SKIP_WORD;
1500 htopic_del_all(&hchan->topic);
1501 htopic_add(&hchan->topic, ostr, 0);
1502 hchannel_set_topic(hchan);
1503 }
1504 else
1505 helpmod_reply(sender, returntype, "Can not handle the topic of channel %s: Unknown operation %s", hchannel_get_name(hchan), argv[0]);
1506 }
1507
1508 void helpmod_cmd_out (huser *sender, channel* returntype, char* ostr, int argc, char *argv[])
1509 {
1510 huser *husr;
1511 int i;
1512 if (argc == 0)
1513 {
1514 helpmod_reply(sender, returntype, "Can not get rid of the user: User not specified");
1515 return;
1516 }
1517
1518 if (argc > H_CMD_MAX_ARGS)
1519 argc = H_CMD_MAX_ARGS;
1520 for (i=0;i<argc;i++)
1521 {
1522 husr = huser_get(getnickbynick(argv[i]));
1523 if (husr == NULL)
1524 {
1525 helpmod_reply(sender, returntype, "Can not get rid of the user: User %s not found", argv[i]);
1526 continue;
1527 }
1528 if (huser_get_level(husr) > H_PEON)
1529 {
1530 helpmod_reply(sender, returntype, "Can not get rid of the user: User %s is not a peon", husr->real_user->nick);
1531 continue;
1532 }
1533 {
1534 const char *banmask = hban_ban_string(husr->real_user, HBAN_REAL_HOST);
1535
1536 hban_add(banmask, "Banned", time(NULL) + HCMD_OUT_DEFAULT, 0);
1537 }
1538 helpmod_reply(sender, returntype, "User %s is now gone", husr->real_user->nick);
1539 }
1540 }
1541
1542 void helpmod_cmd_everyoneout (huser *sender, channel* returntype, char* ostr, int argc, char *argv[])
1543 {
1544 hchannel *hchan;
1545 hchannel_user **hchanuser;
1546 char *reason = "clearing channel";
1547 int autoqueue_tmp = -1;
1548
1549 DEFINE_HCHANNEL;
1550
1551 HCHANNEL_VERIFY_AUTHORITY(hchan, sender);
1552
1553 if (hchan == NULL)
1554 {
1555 helpmod_reply(sender, returntype, "Can not clear channel: Channel not defined or not found");
1556 return;
1557 }
1558
1559 if (argc)
1560 reason = ostr;
1561
1562 hchan->flags |= H_MAINTAIN_I;
1563 hchannel_mode_check(hchan);
1564
1565 hchanuser = &hchan->channel_users;
1566
1567 if ((hchan->flags & H_QUEUE) && (hchan->flags & H_QUEUE_MAINTAIN))
1568 {
1569 autoqueue_tmp = hchan->autoqueue;
1570 hchan->autoqueue = 0;
1571 }
1572
1573 while (*hchanuser)
1574 {
1575 if (huser_get_level((*hchanuser)->husr) < H_TRIAL)
1576 helpmod_kick(hchan, (*hchanuser)->husr, reason);
1577 else
1578 hchanuser = &(*hchanuser)->next;
1579 }
1580
1581 if (autoqueue_tmp > 0)
1582 hchan->autoqueue = autoqueue_tmp;
1583
1584 helpmod_reply(sender, returntype, "Channel %s has been cleared of normal users", hchannel_get_name(hchan));
1585 }
1586
1587 void helpmod_cmd_kick (huser *sender, channel* returntype, char* ostr, int argc, char *argv[])
1588 {
1589 hchannel *hchan;
1590 int i;
1591 huser *husr, *targets[6];
1592 int ntargets = 0;
1593 char *reason = "out";
1594 DEFINE_HCHANNEL;
1595
1596 HCHANNEL_VERIFY_AUTHORITY(hchan, sender);
1597
1598 if (hchan == NULL)
1599 {
1600 helpmod_reply(sender, returntype, "Can not kick the user: Channel not defined or not found");
1601 return;
1602 }
1603 if (argc > H_CMD_MAX_ARGS)
1604 argc = H_CMD_MAX_ARGS;
1605 for (i=0;i<argc;i++)
1606 {
1607 if (*argv[i] == ':')
1608 {
1609 while (i--)
1610 {
1611 SKIP_WORD;
1612 }
1613 reason = ostr+1;
1614 break;
1615 }
1616 husr = huser_get(getnickbynick(argv[i]));
1617 if (husr == NULL)
1618 {
1619 helpmod_reply(sender, returntype, "Can not kick the user: User %s not found", argv[i]);
1620 continue;
1621 }
1622 if (huser_on_channel(husr, hchan) == NULL)
1623 {
1624 helpmod_reply(sender, returntype, "Can not kick the user: User %s is on channel", husr->real_user->nick, hchannel_get_name(hchan));
1625 continue;
1626 }
1627 if (huser_get_level(husr) > H_PEON)
1628 {
1629 helpmod_reply(sender, returntype, "Can not kick the user: User %s is not a peon", husr->real_user->nick);
1630 continue;
1631 }
1632 targets[ntargets++] = husr;
1633 }
1634 if (!ntargets)
1635 {
1636 helpmod_reply(sender, returntype, "Can not kick the user: No users defined");
1637 return;
1638 }
1639 for (i=0;i<ntargets;i++)
1640 helpmod_kick(hchan, targets[i], reason);
1641 }
1642
1643 void helpmod_cmd_stats (huser *sender, channel* returntype, char* ostr, int argc, char *argv[])
1644 {
1645 hchannel *hchan;
1646 haccount *target = sender->account;
1647 hstat_account *ptr;
1648 hstat_account_entry *stat_entry;
1649 int days = 1, weeks = 0;
1650 int type = HSTAT_ACCOUNT_SHORT;
1651
1652 time_t timer = time(NULL);
1653 struct tm *tstruct = localtime(&timer);
1654
1655 int i = 0;
1656
1657 DEFINE_HCHANNEL;
1658
1659 HCHANNEL_VERIFY_AUTHORITY(hchan, sender);
1660
1661 if (hchan == NULL)
1662 {
1663 helpmod_reply(sender, returntype, "Can not show user statistics: Channel not defined or not found");
1664 return;
1665 }
1666
1667 if (argc > 0 && huser_get_level(sender) == H_ADMIN)
1668 { /* not very elegant */
1669 if (argv[0][0] == '#') /* account */
1670 {
1671 target = haccount_get_by_name(argv[0]+1);
1672 if (target == NULL)
1673 {
1674 helpmod_reply(sender, returntype, "Can not show user statistics: Account %s not found", argv[0]);
1675 return;
1676 }
1677 SKIP_WORD;
1678 }
1679 }
1680
1681 if (target == NULL)
1682 {
1683 helpmod_reply(sender, returntype, "Can not show user statistics: You do not have an account");
1684 return;
1685 }
1686
1687 if (argc > 0)
1688 {
1689 if (!ci_strcmp(argv[0], "short") || !ci_strcmp(argv[0], "s"))
1690 {
1691 type = HSTAT_ACCOUNT_SHORT;
1692 SKIP_WORD;
1693 }
1694 else if (!ci_strcmp(argv[0], "long") || !ci_strcmp(argv[0], "l"))
1695 {
1696 type = HSTAT_ACCOUNT_LONG;
1697 SKIP_WORD;
1698 }
1699 }
1700
1701 if (argc > 0)
1702 if (sscanf(argv[0], "%d", &days))
1703 {
1704 if (days < 0 || days > 7)
1705 {
1706 helpmod_reply(sender, returntype, "Can not show user statistics: Expected integer between [0, 7]");
1707 return;
1708 }
1709 else
1710 {
1711 SKIP_WORD;
1712 }
1713 }
1714
1715 if (argc > 0)
1716 if (sscanf(argv[0], "%d", &weeks))
1717 {
1718 if (weeks < 0 || weeks > 10)
1719 {
1720 helpmod_reply(sender, returntype, "Can not show user statistics: Expected integer between [0, 10]");
1721 return;
1722 }
1723 else
1724 {
1725 SKIP_WORD;
1726 }
1727 }
1728
1729 for (ptr = target->stats;ptr;ptr = ptr->next)
1730 if (ptr->hchan == hchan)
1731 break;
1732
1733 if (ptr == NULL)
1734 {
1735 helpmod_reply(sender, returntype, "Can not show user statistics: User %s has no statistics for channel %s", target->name->content, hchannel_get_name(hchan));
1736 return;
1737 }
1738
1739 if (!days && !weeks)
1740 return;
1741
1742 helpmod_reply(sender, returntype, "Statistics for user %s on channel %s", target->name->content, hchannel_get_name(hchan));
1743
1744 if (days)
1745 {
1746 helpmod_reply(sender, returntype, "Last %d day%s", days, (days==1)?"":"s");
1747 helpmod_reply(sender, returntype, hstat_header(type));
1748 for (i=0;i<days;i++)
1749 {
1750 stat_entry = &ptr->week[(tstruct->tm_wday - i + 7) % 7];
1751 helpmod_reply(sender, returntype, hstat_account_print(stat_entry, type));
1752 }
1753 }
1754
1755 if (weeks)
1756 {
1757 helpmod_reply(sender, returntype, "Last %d week%s", weeks, (weeks==1)?"":"s");
1758 helpmod_reply(sender, returntype, hstat_header(type));
1759 for (i=0;i<weeks;i++)
1760 {
1761 stat_entry = &ptr->longterm[(hstat_week() - i + 10) % 10];
1762 helpmod_reply(sender, returntype, hstat_account_print(stat_entry, type));
1763 }
1764 }
1765 }
1766
1767 void helpmod_cmd_chanstats (huser *sender, channel* returntype, char* ostr, int argc, char *argv[])
1768 {
1769 hchannel *hchan;
1770 hstat_channel *channel_stats;
1771 hstat_channel_entry *stat_entry;
1772
1773 time_t timer = time(NULL);
1774 struct tm *tstruct = localtime(&timer);
1775
1776 int days=1;
1777 int type = HSTAT_CHANNEL_SHORT;
1778 int weeks=0;
1779
1780 int i = 7;
1781
1782 DEFINE_HCHANNEL;
1783
1784 HCHANNEL_VERIFY_AUTHORITY(hchan, sender);
1785
1786 if (hchan == NULL)
1787 {
1788 helpmod_reply(sender, returntype, "Can not show channel statistics: Channel not defined or not found");
1789 return;
1790 }
1791
1792 if (argc > 0)
1793 {
1794 if (!ci_strcmp(argv[0], "short") || !ci_strcmp(argv[0], "s"))
1795 {
1796 type = HSTAT_CHANNEL_SHORT;
1797 SKIP_WORD;
1798 }
1799 else if (!ci_strcmp(argv[0], "long") || !ci_strcmp(argv[0], "l"))
1800 {
1801 type = HSTAT_CHANNEL_LONG;
1802 SKIP_WORD;
1803 }
1804 }
1805
1806 if (argc > 0)
1807 if (sscanf(argv[0], "%d", &days))
1808 {
1809 if (days < 0 || days > 7)
1810 {
1811 helpmod_reply(sender, returntype, "Can not show channel statistics: Expected integer between [0, 7]");
1812 return;
1813 }
1814 else
1815 {
1816 SKIP_WORD;
1817 }
1818 }
1819
1820 if (argc > 0)
1821 if (sscanf(argv[0], "%d", &weeks))
1822 {
1823 if (weeks < 0 || weeks > 10)
1824 {
1825 helpmod_reply(sender, returntype, "Can not show channel statistics: Expected integer between [0, 10]");
1826 return;
1827 }
1828 else
1829 {
1830 SKIP_WORD;
1831 }
1832 }
1833
1834
1835 channel_stats = hchan->stats;
1836
1837 if (!days && !weeks)
1838 return;
1839
1840 helpmod_reply(sender, returntype, "Statistics for channel %s", hchannel_get_name(hchan));
1841
1842 if (days)
1843 {
1844 helpmod_reply(sender, returntype, "Last %d day%s", days, (days==1)?"":"s");
1845 helpmod_reply(sender, returntype, hstat_header(type));
1846 for (i=0;i<days;i++) /* latest week */
1847 {
1848 stat_entry = &hchan->stats->week[(tstruct->tm_wday - i + 7) % 7];
1849 helpmod_reply(sender, returntype, hstat_channel_print(stat_entry, type));
1850 }
1851 }
1852
1853 if (weeks)
1854 {
1855 helpmod_reply(sender, returntype, "Last %d week%s", weeks, (weeks==1)?"":"s");
1856 helpmod_reply(sender, returntype, hstat_header(type));
1857 for (i=0;i<weeks;i++) /* latest weeks */
1858 {
1859 stat_entry = &hchan->stats->longterm[(hstat_week() - i + 10) % 10];
1860 helpmod_reply(sender, returntype, hstat_channel_print(stat_entry, type));
1861 }
1862 }
1863 }
1864
1865 void helpmod_cmd_activestaff (huser *sender, channel* returntype, char* ostr, int argc, char *argv[])
1866 {
1867 hchannel *hchan;
1868 hstat_accounts_array arr;
1869 hlevel lvl = H_OPER;
1870 int listtype = 0;
1871 int i;
1872
1873 DEFINE_HCHANNEL;
1874
1875 if (hchan == NULL)
1876 {
1877 helpmod_reply(sender, returntype, "Can not list active staff: Channel not specified or not found");
1878 return;
1879 }
1880
1881 if (argc == 1)
1882 {
1883 if (!ci_strcmp(argv[0], "opers") || !ci_strcmp(argv[0], "o"))
1884 {
1885 lvl = H_OPER;
1886 SKIP_WORD;
1887 }
1888 else if (!ci_strcmp(argv[0], "staff") || !ci_strcmp(argv[0], "s"))
1889 {
1890 lvl = H_STAFF;
1891 SKIP_WORD;
1892 }
1893 }
1894
1895 if (argc == 1)
1896 {
1897 if (!ci_strcmp(argv[0], "active") || !ci_strcmp(argv[0], "a"))
1898 {
1899 listtype = 0;
1900 SKIP_WORD;
1901 }
1902 else if (!ci_strcmp(argv[0], "inactive") || !ci_strcmp(argv[0], "i"))
1903 {
1904 listtype = 1;
1905 SKIP_WORD;
1906 }
1907 }
1908
1909 arr = create_hstat_account_array(hchan, lvl);
1910
1911 helpmod_reply(sender, returntype, "%s %ss for channel %s", listtype?"Inactive":"Active", hlevel_name(lvl), hchannel_get_name(hchan));
1912 switch (listtype)
1913 {
1914 case 0:
1915 for (i=0;i < arr.arrlen && arr.array[i].prime_time_spent > H_ACTIVE_LIMIT;i++)
1916 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));
1917 break;
1918 case 1:
1919 for (i=arr.arrlen-1;i >= 0 && arr.array[i].prime_time_spent < H_ACTIVE_LIMIT;i--)
1920 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));
1921 break;
1922 }
1923
1924 free(arr.array);
1925 }
1926
1927 void helpmod_cmd_top10 (huser *sender, channel* returntype, char* ostr, int argc, char *argv[])
1928 {
1929 hchannel *hchan;
1930 hstat_accounts_array arr;
1931 hlevel lvl = H_OPER;
1932 int i, top_n = 10;
1933
1934 DEFINE_HCHANNEL;
1935
1936 HCHANNEL_VERIFY_AUTHORITY(hchan, sender);
1937
1938 if (hchan == NULL)
1939 {
1940 helpmod_reply(sender, returntype, "Can not list channel Top10: Channel not specified or not found");
1941 return;
1942 }
1943
1944 if (argc >= 1)
1945 {
1946 if (!ci_strcmp(argv[0], "opers") || !ci_strcmp(argv[0], "o"))
1947 lvl = H_OPER;
1948 else if (!ci_strcmp(argv[0], "staff") || !ci_strcmp(argv[0], "s"))
1949 lvl = H_STAFF;
1950 }
1951 if (argc == 2)
1952 {
1953 int tmp;
1954 if (sscanf(argv[1], "%d", &tmp) && (tmp >= 10) && (tmp <= 50))
1955 top_n = tmp;
1956 }
1957
1958 arr = create_hstat_account_array(hchan, lvl);
1959
1960 helpmod_reply(sender, returntype, "Top%d most active %ss of channel %s", top_n, hlevel_name(lvl), hchannel_get_name(hchan));
1961 for (i=0;i < arr.arrlen && i < top_n;i++)
1962 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));
1963
1964 free(arr.array);
1965 }
1966
1967 void helpmod_cmd_report (huser *sender, channel* returntype, char* ostr, int argc, char *argv[])
1968 {
1969 hchannel *hchan, *target;
1970 DEFINE_HCHANNEL;
1971
1972 HCHANNEL_VERIFY_AUTHORITY(hchan, sender);
1973
1974 if (hchan != NULL && (argc == 2))
1975 {
1976 hchan = hchannel_get_by_name(argv[0]);
1977 SKIP_WORD;
1978 }
1979
1980 if (hchan == NULL)
1981 {
1982 helpmod_reply(sender, returntype, "Can not view or set channel reporting: Channel not defined or not found");
1983 return;
1984 }
1985 if (argc != 1)
1986 {
1987 if (hchan->report_to == NULL || !hchannel_is_valid(hchan->report_to))
1988 helpmod_reply(sender, returntype, "Channel %s is not reported anywhere (%s)", hchannel_get_name(hchan), hchannel_get_state(hchan, H_REPORT));
1989 else
1990 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));
1991 return;
1992 }
1993 if ((target = hchannel_get_by_name(argv[0])) == NULL)
1994 {
1995 helpmod_reply(sender, returntype, "Can not set channel reporting: Channel %s not found", argv[0]);
1996 return;
1997 }
1998 hchan->report_to = target;
1999 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));
2000 }
2001
2002 void helpmod_cmd_mode(huser *sender, channel* returntype, int change, char* ostr, int argc, char *argv[])
2003 {
2004 hchannel *hchan;
2005 huser_channel *huserchan;
2006 huser *husr;
2007 int i;
2008
2009 DEFINE_HCHANNEL;
2010
2011 HCHANNEL_VERIFY_AUTHORITY(hchan, sender);
2012
2013 if (hchan == NULL)
2014 {
2015 helpmod_reply(sender, returntype, "Can not change mode: Channel not specified or not found");
2016 return;
2017 }
2018
2019 if (argc==0) /* for a simple opme */
2020 {
2021 argc = 1;
2022 argv[0] = sender->real_user->nick;
2023 }
2024
2025 if (argc > H_CMD_MAX_ARGS)
2026 argc = H_CMD_MAX_ARGS;
2027
2028 for (i=0;i<argc;i++)
2029 {
2030 husr = huser_get(getnickbynick(argv[i]));
2031 if (husr == NULL)
2032 {
2033 helpmod_reply(sender, returntype, "Can not change mode: User %s not found", argv[i], hchannel_get_name(hchan));
2034 continue;
2035 }
2036 huserchan = huser_on_channel(husr, hchan);
2037 if (huserchan == NULL)
2038 {
2039 helpmod_reply(sender, returntype, "Can not change mode: User %s it not on channel %s", husr->real_user->nick, hchannel_get_name(hchan));
2040 continue;
2041 }
2042
2043 switch (change)
2044 {
2045 case H_CMD_OP:
2046 {
2047 int j;
2048 for (j=0;j < hchan->real_channel->users->hashsize;j++)
2049 if (getnickbynumeric(hchan->real_channel->users->content[j]) == husr->real_user)
2050 break;
2051 if ((huserchan->flags & HCUMODE_OP) && !(hchan->real_channel->users->content[j] & CUMODE_OP))
2052 {
2053 huserchan->flags &= ~HCUMODE_OP;
2054 Error("helpmod", ERR_ERROR, "userchannelmode inconsistency (+o when should be -o)");
2055 }
2056 if (huserchan->flags & HCUMODE_OP)
2057 {
2058 helpmod_reply(sender, returntype, "Can not change mode: User %s is already +o on channel %s", husr->real_user->nick, hchannel_get_name(hchan));
2059 continue;
2060 }
2061 if (huser_get_level(husr) < H_STAFF)
2062 {
2063 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));
2064 continue;
2065 }
2066 helpmod_channick_modes(husr, hchan, MC_OP, HLAZY);
2067 }
2068 break;
2069 case H_CMD_DEOP:
2070 {
2071 int j;
2072 for (j=0;j < hchan->real_channel->users->hashsize;j++)
2073 if (getnickbynumeric(hchan->real_channel->users->content[j]) == husr->real_user)
2074 break;
2075 if (!(huserchan->flags & HCUMODE_OP) && (hchan->real_channel->users->content[j] & CUMODE_OP))
2076 {
2077 huserchan->flags |= HCUMODE_OP;
2078 Error("helpmod", ERR_ERROR, "userchannelmode inconsistency (-o when should be +o)");
2079 }
2080 if (!(huserchan->flags & HCUMODE_OP))
2081 {
2082 helpmod_reply(sender, returntype, "Can not change mode: User %s is already -o on channel %s", husr->real_user->nick, hchannel_get_name(hchan));
2083 continue;
2084 }
2085 if (huser_get_level(husr) > huser_get_level(sender))
2086 {
2087 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));
2088 continue;
2089 }
2090 helpmod_channick_modes(husr, hchan, MC_DEOP, HLAZY);
2091 }
2092 break;
2093 case H_CMD_VOICE:
2094 {
2095 int j;
2096 for (j=0;j < hchan->real_channel->users->hashsize;j++)
2097 if (getnickbynumeric(hchan->real_channel->users->content[j]) == husr->real_user)
2098 break;
2099 if ((huserchan->flags & HCUMODE_VOICE) && !(hchan->real_channel->users->content[j] & CUMODE_VOICE))
2100 {
2101 huserchan->flags &= ~HCUMODE_VOICE;
2102 Error("helpmod", ERR_ERROR, "userchannelmode inconsistency (+v when should be -v)");
2103 }
2104 if (huserchan->flags & HCUMODE_VOICE)
2105 {
2106 helpmod_reply(sender, returntype, "Can not change mode: User %s is already -v on channel %s", husr->real_user->nick, hchannel_get_name(hchan));
2107 continue;
2108 }
2109 helpmod_channick_modes(husr, hchan, MC_VOICE, HLAZY);
2110 }
2111 break;
2112 case H_CMD_DEVOICE:
2113 {
2114 int j;
2115 for (j=0;j < hchan->real_channel->users->hashsize;j++)
2116 if (getnickbynumeric(hchan->real_channel->users->content[j]) == husr->real_user)
2117 break;
2118 if (!(huserchan->flags & HCUMODE_VOICE) && (hchan->real_channel->users->content[j] & CUMODE_VOICE))
2119 {
2120 huserchan->flags |= HCUMODE_VOICE;
2121 Error("helpmod", ERR_ERROR, "userchannelmode inconsistency (-v when should be +v)");
2122 }
2123 if (!(huserchan->flags & HCUMODE_VOICE))
2124 {
2125 helpmod_reply(sender, returntype, "Can not change mode: User %s is already -v on channel %s", husr->real_user->nick, hchannel_get_name(hchan));
2126 continue;
2127 }
2128 helpmod_channick_modes(husr, hchan, MC_DEVOICE, HLAZY);
2129 }
2130 break;
2131 }
2132 }
2133 }
2134
2135 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); }
2136 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); }
2137 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); }
2138 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); }
2139
2140 void helpmod_cmd_invite (huser *sender, channel *returntype, char* arg, int argc, char *argv[])
2141 {
2142 hchannel *hchan;
2143 int i;
2144
2145 if (argc == 0)
2146 {
2147 helpmod_reply(sender, returntype, "Can not invite: Channel not defined or not found");
2148 return;
2149 }
2150
2151 if (huser_get_level(sender) == H_PEON)
2152 {
2153 hticket *htick;
2154 hchan = hchannel_get_by_name(argv[0]);
2155 if (hchan == NULL)
2156 {
2157 helpmod_reply(sender, returntype, "Can not invite: Unknown channel %s", argv[0]);
2158 return;
2159 }
2160 /* if tickets don't work, it's better that the user doesn't know that the channel really exists */
2161 if (!(hchan->flags & H_REQUIRE_TICKET))
2162 {
2163 helpmod_reply(sender, returntype, "Can not invite: Unknown channel %s", argv[0]);
2164 return;
2165 }
2166 htick = hticket_get(sender->real_user->authname ,hchan);
2167 if (htick == NULL)
2168 {
2169 helpmod_reply(sender, returntype, "Can not invite: You do not have an invite ticket for channel %s", argv[0]);
2170 return;
2171 }
2172 else
2173 {
2174 helpmod_invite(hchan, sender);
2175 helpmod_reply(sender, returntype, "Invited you to channel %s", hchannel_get_name(hchan));
2176 }
2177 return;
2178 }
2179
2180 if (argc > H_CMD_MAX_ARGS)
2181 argc = H_CMD_MAX_ARGS;
2182
2183 for (i = 0;i < argc; i++)
2184 {
2185 hchan = hchannel_get_by_name(argv[0]);
2186 if (hchan == NULL)
2187 {
2188 helpmod_reply(sender, returntype, "Can not invite: Unknown channel %s", argv[i]);
2189 continue;
2190 }
2191 if (!hchannel_authority(hchan, sender))
2192 {
2193 helpmod_reply(sender, returntype, "Sorry, channel %s is oper only", hchannel_get_name(hchan));
2194 continue;
2195 }
2196 if (huser_on_channel(sender, hchan) != NULL)
2197 {
2198 helpmod_reply(sender, returntype, "Can not invite: You are already on channel %s", hchannel_get_name(hchan));
2199 continue;
2200 }
2201 helpmod_invite(hchan, sender);
2202 helpmod_reply(sender, returntype, "Invited you to channel %s", hchannel_get_name(hchan));
2203 }
2204 }
2205
2206 void helpmod_cmd_ticket (huser *sender, channel* returntype, char* ostr, int argc, char *argv[])
2207 {
2208 int expiration = HTICKET_EXPIRATION_TIME;
2209 hchannel *hchan;
2210 huser *husr;
2211 hticket *htick;
2212
2213 if (argc < 1)
2214 {
2215 helpmod_reply(sender, returntype, "Can not issue a ticket: Channel not specified");
2216 return;
2217 }
2218
2219 hchan = hchannel_get_by_name(argv[0]);
2220 if (hchan == NULL)
2221 {
2222 helpmod_reply(sender, returntype, "Can not issue a ticket: Unknown channel %s", argv[0]);
2223 return;
2224 }
2225 if (!(hchan->flags & H_REQUIRE_TICKET))
2226 {
2227 helpmod_reply(sender, returntype, "Can not issue a ticket: Tickets are not enabled for channel %s", argv[0]);
2228 return;
2229 }
2230 if (argc < 2)
2231 {
2232 helpmod_reply(sender, returntype, "Can not issue a ticket: Target user not specified");
2233 return;
2234 }
2235
2236 husr = huser_get(getnickbynick(argv[1]));
2237 if (husr == NULL)
2238 {
2239 helpmod_reply(sender, returntype, "Can not issue a ticket: Unknown user %s", argv[1]);
2240 return;
2241 }
2242 if (!IsAccount(husr->real_user))
2243 {
2244 helpmod_reply(sender, returntype, "Can not issue a ticket: User %s is not authed", argv[1]);
2245 return;
2246 }
2247 if (huser_get_level(husr) < H_PEON)
2248 {
2249 helpmod_reply(sender, returntype, "Can not issue a ticket: User %s is considered improper and not worthy of a ticket", argv[1]);
2250 return;
2251 }
2252 if (argc >= 3)
2253 {
2254 int tmp;
2255 tmp = helpmod_read_strtime(argv[2]);
2256 if (tmp > HDEF_m && tmp < 2 * HDEF_M)
2257 expiration = tmp;
2258 }
2259
2260 htick = hticket_get(husr->real_user->authname, hchan);
2261
2262 if (htick != NULL)
2263 htick->time_expiration = time(NULL) + expiration;
2264 else
2265 hticket_add(husr->real_user->authname, time(NULL) + expiration, hchan);
2266
2267 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));
2268 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));
2269 }
2270
2271 void helpmod_cmd_resolve (huser *sender, channel* returntype, char* ostr, int argc, char *argv[])
2272 {
2273 int i;
2274 hchannel *hchan;
2275 hticket *htick;
2276 huser *husr;
2277
2278 DEFINE_HCHANNEL;
2279
2280 HCHANNEL_VERIFY_AUTHORITY(hchan, sender);
2281
2282 if (argc > H_CMD_MAX_ARGS)
2283 argc = H_CMD_MAX_ARGS;
2284
2285 if (hchan == NULL)
2286 {
2287 helpmod_reply(sender, returntype, "Can not resolve a ticket: The channel is not specified");
2288 return;
2289 }
2290
2291 for (i = 0;i< argc;i++)
2292 {
2293 if (argv[i][0] == '#')
2294 {
2295 htick = hticket_get(&argv[i][1], hchan);
2296 if (htick == NULL)
2297 {
2298 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));
2299 continue;
2300 }
2301 hticket_del(htick, hchan);
2302 helpmod_reply(sender, returntype, "Resolved authname %s's ticket for channel %s", &argv[i][1], hchannel_get_name(hchan));
2303 }
2304 else
2305 {
2306 husr = huser_get(getnickbynick(argv[i]));
2307 if (husr == NULL)
2308 {
2309 helpmod_reply(sender, returntype, "Can not resolve a ticket: User %s not found", argv[i]);
2310 continue;
2311 }
2312 if (!IsAccount(husr->real_user))
2313 {
2314 helpmod_reply(sender, returntype, "Can not resolve a ticket: User %s is not authed", argv[i]);
2315 continue;
2316 }
2317 htick = hticket_get(husr->real_user->authname,hchan);
2318 if (htick == NULL)
2319 {
2320 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));
2321 continue;
2322 }
2323 hticket_del(htick, hchan);
2324 helpmod_reply(sender, returntype, "Resolved user %s's ticket for channel %s", argv[i], hchannel_get_name(hchan));
2325 }
2326 }
2327 }
2328
2329 void helpmod_cmd_tickets (huser *sender, channel* returntype, char* ostr, int argc, char *argv[])
2330 {
2331 hchannel *hchan;
2332 hticket *htick;
2333 int i;
2334
2335 DEFINE_HCHANNEL;
2336
2337 HCHANNEL_VERIFY_AUTHORITY(hchan, sender);
2338
2339 if (hchan == NULL)
2340 {
2341 helpmod_reply(sender, returntype, "Can not list tickets: Channel not defined or not found");
2342 return;
2343 }
2344
2345 if (!(hchan->flags & H_REQUIRE_TICKET))
2346 {
2347 helpmod_reply(sender, returntype, "Can not list tickets: Channel %s does not use the ticket system", hchannel_get_name(hchan));
2348 return;
2349 }
2350
2351 htick = hchan->htickets;
2352
2353 if (htick == NULL)
2354 {
2355 helpmod_reply(sender, returntype, "Channel %s has no valid tickets", hchannel_get_name(hchan));
2356 return;
2357 }
2358
2359 helpmod_reply(sender, returntype, "Valid tickets for channel %s", hchannel_get_name(hchan));
2360
2361 for (i = 0;htick;htick = htick->next, i++)
2362 helpmod_reply(sender, returntype, "%4d %16s %48s", i, htick->authname, helpmod_strtime(time(NULL) - htick->time_expiration));
2363
2364 helpmod_reply(sender, returntype, "Done listing tickets. Channel %s had %d valid tickets", hchannel_get_name(hchan), i);
2365 }
2366
2367 void helpmod_cmd_showticket (huser *sender, channel* returntype, char* ostr, int argc, char *argv[])
2368 {
2369 hchannel *hchan;
2370 huser *husr;
2371 hticket *htick;
2372 int i;
2373
2374 DEFINE_HCHANNEL;
2375
2376 HCHANNEL_VERIFY_AUTHORITY(hchan, sender);
2377
2378 if (argc > H_CMD_MAX_ARGS)
2379 argc = H_CMD_MAX_ARGS;
2380
2381 if (hchan == NULL)
2382 {
2383 helpmod_reply(sender, returntype, "Can not show the ticket: Channel not defined or not found");
2384 return;
2385 }
2386 for (i = 0;i < argc;i++)
2387 {
2388 husr = huser_get(getnickbynick(argv[i]));
2389 if (husr == NULL)
2390 {
2391 helpmod_reply(sender, returntype, "Can not show the ticket: User %s not found", argv[i]);
2392 continue;
2393 }
2394 if (!IsAccount(husr->real_user))
2395 {
2396 helpmod_reply(sender, returntype, "Can not show the ticket: User %s is not authed", argv[i]);
2397 continue;
2398 }
2399 htick = hticket_get(husr->real_user->authname, hchan);
2400 if (htick == NULL)
2401 {
2402 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));
2403 continue;
2404 }
2405 helpmod_reply(sender, returntype, "User %s has a ticket for chanenl %s expiring in %s", argv[i], hchannel_get_name(hchan), helpmod_strtime(htick->time_expiration - time(NULL)));
2406 }
2407 }
2408
2409 /* old H stuff */
2410 void helpmod_cmd_load (huser *sender, channel *returntype, char* arg, int argc, char *argv[])
2411 {
2412 FILE *tmp_file;
2413 char buf[128] = "helpmod/default";
2414
2415 if (!arg)
2416 helpmod_reply(sender, returntype, "Warning: No config specified, using default");
2417 else
2418 {
2419 if (strlen(arg) >= 100)
2420 return;
2421 else
2422 sprintf(buf, "helpmod/%s", arg);
2423 }
2424
2425 if (!(tmp_file = fopen(buf, "rt")))
2426 {
2427 helpmod_reply(sender, returntype, "File %s not found", buf);
2428 return;
2429 }
2430 else
2431 fclose(tmp_file);
2432
2433 helpmod_clear_aliases(&aliases);
2434 helpmod_clear_all_entries();
2435 helpmod_init_entry(&helpmod_base);
2436 huser_reset_states();
2437 helpmod_load_entries(buf);
2438 strcpy(helpmod_db, buf);
2439 helpmod_reply(sender, returntype, "New config loaded and system reset");
2440 }
2441
2442 void helpmod_cmd_status (huser *sender, channel* returntype, char* ostr, int argc, char *argv[])
2443 {
2444 helpmod_reply(sender, returntype, "HelpMod version %s (built %s, up %s)", HELPMOD_VERSION, __DATE__, helpmod_strtime(time(NULL) - helpmod_startup_time));
2445 helpmod_reply(sender, returntype, "Channels %d", hchannel_count());
2446 helpmod_reply(sender, returntype, "Accounts %d", haccount_count(H_ANY));
2447 helpmod_reply(sender, returntype, "Users %d", huser_count());
2448 helpmod_reply(sender, returntype, "Help entries %d", helpmod_entry_count(helpmod_base));
2449 helpmod_reply(sender, returntype, "Bans %d", hban_count());
2450 helpmod_reply(sender, returntype, "Help provided %d", helpmod_usage);
2451 helpmod_reply(sender, returntype, "Tickets %d", hticket_count());
2452 }
2453
2454 /* not really a command, but help wants this one */
2455 void helpmod_send_help(huser* target)
2456 {
2457 int i;
2458 helpmod_usage++;
2459 for (i=0;i<target->state->text_lines;i++)
2460 helpmod_reply(target, NULL, "%s", target->state->text[i]->content);
2461 for (i=0;i<target->state->option_count;i++)
2462 helpmod_reply(target, NULL, "%d) %s", i+1, target->state->options[i]->description->content);
2463 if (!target->state->option_count)
2464 {
2465 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");
2466 }
2467 }
2468
2469 void helpmod_cmd_command(huser* sender, channel* returntype, char* arg, int argc, char *argv[])
2470 {
2471 hcommand *hcom;
2472 char buffer[512], *ptr = argv[0];
2473 FILE *in;
2474
2475 if (argc == 0)
2476 {
2477 helpmod_reply(sender, returntype, "Usage: command [name of the command] for a list see 'showcommands'");
2478 return;
2479 }
2480
2481 hcom = hcommand_get(argv[0], huser_get_level(sender));
2482
2483 if (hcom == NULL)
2484 {
2485 helpmod_reply(sender, returntype, "Unknown command '%s'", argv[0]);
2486 return;
2487 }
2488
2489 /* tolower */
2490 while (*(ptr++))
2491 *ptr = tolower(*ptr);
2492
2493 sprintf(buffer, "./helpmod/commands/%s", argv[0]);
2494
2495 if ((in = fopen(buffer, "rt")) == NULL)
2496 {
2497 helpmod_reply(sender, returntype, "No help available for command '%s' (Ask strutsi to write it)", argv[0]);
2498 return;
2499 }
2500
2501 while (!feof(in))
2502 {
2503 fgets(buffer, 512, in);
2504 if (feof(in))
2505 break;
2506 helpmod_reply(sender, returntype, "%s", buffer);
2507 }
2508
2509 fclose(in);
2510 }
2511
2512 void helpmod_cmd_help (huser* sender, channel* returntype, char* arg, int argc, char *argv[])
2513 {
2514 int hlp_target;
2515
2516 if (helpmod_base == NULL || !helpmod_base->option_count)
2517 {
2518 helpmod_reply(sender, returntype, "The help service is not available at this time, please try again later");
2519 return;
2520 }
2521
2522 if (!argc)
2523 {
2524 sender->state = helpmod_base;
2525 helpmod_send_help(sender);
2526 return;
2527 }
2528 else
2529 if (!sscanf(arg, "%d", &hlp_target))
2530 {
2531 helpmod_entry tmp;
2532
2533 tmp = helpmod_get_alias(arg);
2534 if (!tmp)
2535 helpmod_reply(sender, returntype, "Invalid value. Either use 'help' to restart or give an integer as a valid selection");
2536 else
2537 {
2538 sender->state = tmp;
2539 helpmod_send_help(sender);
2540 }
2541 return;
2542 }
2543
2544 hlp_target--;
2545 if (!helpmod_valid_selection(sender->state, hlp_target))
2546 {
2547 if (!sender->state->option_count)
2548 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");
2549 else if (!sender->state->parent)
2550 helpmod_reply(sender, returntype, "Bad selection, please enter your selection as an integer from %d to %d", 1, sender->state->option_count);
2551 else
2552 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);
2553 return;
2554 }
2555
2556 sender->state = helpmod_make_selection(sender->state, hlp_target);
2557 helpmod_send_help(sender);
2558
2559 return;
2560 }
2561 /* adds all of the abowe to the system */
2562 void hcommands_add(void)
2563 {
2564 hcommand_add("help", H_PEON, helpmod_cmd_help,"Offers the H1 type help");
2565 hcommand_add("status",H_OPER, helpmod_cmd_status,"Gives service status");
2566 hcommand_add("load", H_OPER, helpmod_cmd_load,"Loads a new help database");
2567 hcommand_add("aliases",H_STAFF, helpmod_cmd_aliases,"Lists all aliases currently in use");
2568 hcommand_add("showcommands", H_LAMER, helpmod_cmd_showcommands,"Lists all commands available to you");
2569
2570 hcommand_add("improper", H_STAFF, helpmod_cmd_improper, "Sets the userlevel of the target to banned (lvl 0). Long term ban.");
2571 hcommand_add("peon", H_STAFF, helpmod_cmd_peon, "Sets the userlevel of the target to peon (lvl 1)");
2572 hcommand_add("trial", H_OPER, helpmod_cmd_trial, "Sets the userlevel of the target to trial staff (lvl 2)");
2573 hcommand_add("staff", H_OPER, helpmod_cmd_staff, "Sets the userlevel of the target to staff (lvl 3)");
2574 hcommand_add("oper", H_OPER, helpmod_cmd_oper, "Sets the userlevel of the target to oper (lvl 4)");
2575 hcommand_add("admin", H_ADMIN, helpmod_cmd_admin, "Sets the userlevel of the target to admin (lvl 4)");
2576 hcommand_add("deluser", H_OPER, helpmod_cmd_deluser, "Removes an account from H");
2577 hcommand_add("listuser", H_STAFF, helpmod_cmd_listuser, "Lists user accounts of H");
2578
2579 hcommand_add("chanconf", H_STAFF, helpmod_cmd_chanconf, "Channel configuration");
2580 hcommand_add("acconf", H_TRIAL, helpmod_cmd_acconf, "Personalise H behaviour");
2581 hcommand_add("welcome", H_STAFF, helpmod_cmd_welcome, "Views or changes the channel welcome message");
2582 hcommand_add("censor", H_STAFF, helpmod_cmd_censor, "Handles the censored patterns for a channel");
2583
2584 hcommand_add("queue", H_TRIAL, helpmod_cmd_queue, "Handles the channel queue");
2585 hcommand_add("next", H_TRIAL, helpmod_cmd_next, "Same as queue next");
2586 hcommand_add("done", H_TRIAL, helpmod_cmd_done, "Same as queue done");
2587 hcommand_add("enqueue", H_TRIAL, helpmod_cmd_enqueue, "Same as queue on or chanconf +3");
2588 hcommand_add("dequeue", H_TRIAL, helpmod_cmd_dequeue, "Same as queue off or chanconf -3");
2589 hcommand_add("autoqueue", H_TRIAL, helpmod_cmd_autoqueue, "Same as queue maintain");
2590
2591 hcommand_add("?", H_PEON, helpmod_cmd_term_find, "Same as term find with multiple targets");
2592 hcommand_add("?+", H_TRIAL, helpmod_cmd_term_find_plus, "Multitarget term find which advances the queue");
2593 hcommand_add("?-", H_TRIAL, helpmod_cmd_term_find_minus, "Multitarget term find which removes users from queue");
2594 hcommand_add("term", H_STAFF, helpmod_cmd_term, "Term handling");
2595
2596 hcommand_add("klingon", H_OPER, helpmod_cmd_klingon, "Phrases in klingon, both targeted and general");
2597 hcommand_add("out", H_STAFF, helpmod_cmd_out, "Sets the userlevel of the target to banned (lvl 0) for a short while");
2598 hcommand_add("kick", H_TRIAL, helpmod_cmd_kick, "Kicks user(s) from a channel");
2599 hcommand_add("ban", H_STAFF, helpmod_cmd_ban, "Handles global bans");
2600 hcommand_add("chanban", H_TRIAL, helpmod_cmd_chanban, "Handles channel bans");
2601 hcommand_add("dnmo", H_STAFF, helpmod_cmd_dnmo, "DoNotMessageOpers informs the luser of his mistake and sets him to the bottom of the queue");
2602 hcommand_add("lamercontrol", H_OPER, helpmod_cmd_lamercontrol, "Views or changes the channel lamercontrol profile");
2603 hcommand_add("topic", H_STAFF, helpmod_cmd_topic, "Handles the topic of a channel");
2604 hcommand_add("idlekick", H_OPER, helpmod_cmd_idlekick, "Views or sets the idle kick time");
2605 hcommand_add("everyoneout", H_STAFF, helpmod_cmd_everyoneout, "Removes all normal users from a channel and enforces +i");
2606
2607 hcommand_add("stats", H_STAFF, helpmod_cmd_stats, "Shows staff activity statistics");
2608 hcommand_add("chanstats", H_STAFF, helpmod_cmd_chanstats, "Shows channel activity statistics");
2609 hcommand_add("activestaff", H_ADMIN, helpmod_cmd_activestaff, "Shows active staff members for a channel");
2610 hcommand_add("top10", H_STAFF, helpmod_cmd_top10, "Shows the top 10 most active staff");
2611 hcommand_add("report", H_OPER, helpmod_cmd_report, "Sets the channel where to report this channels statistics every 5 minutes");
2612
2613 hcommand_add("whoami", H_LAMER, helpmod_cmd_whoami, "Tells who you are to H");
2614 hcommand_add("whois", H_STAFF, helpmod_cmd_whois, "Tells you who someone is");
2615 hcommand_add("command", H_LAMER, helpmod_cmd_command, "Gives detailed information on a command");
2616 hcommand_add("addchan", H_ADMIN, helpmod_cmd_addchan, "Joins H to a new channel");
2617 hcommand_add("delchan", H_ADMIN, helpmod_cmd_delchan, "Removes H permanently from a channel");
2618 hcommand_add("seen", H_STAFF, helpmod_cmd_seen, "Tells when a specific user/account has had activity");
2619
2620 hcommand_add("op", H_STAFF, helpmod_cmd_op, "Sets mode +o on channels");
2621 hcommand_add("deop", H_STAFF, helpmod_cmd_deop, "Sets mode -o on channels");
2622 hcommand_add("voice", H_STAFF, helpmod_cmd_voice, "Sets mode +v on channels");
2623 hcommand_add("devoice", H_STAFF, helpmod_cmd_devoice, "Sets mode -v on channels");
2624
2625 hcommand_add("invite", H_PEON, helpmod_cmd_invite, "Invites you to a channel");
2626 hcommand_add("ticket", H_TRIAL, helpmod_cmd_ticket, "Gives a ticket to be used with invite");
2627 hcommand_add("resolve", H_STAFF, helpmod_cmd_resolve, "Resolves (deletes) a ticket");
2628 hcommand_add("tickets", H_STAFF, helpmod_cmd_tickets, "Lists all valid tickets for a channel");
2629 hcommand_add("showticket", H_STAFF, helpmod_cmd_showticket, "Shows the ticket for the user");
2630
2631 /*hcommand_add("megod", H_PEON, helpmod_cmd_megod, "Gives you userlevel 4, if you see this in the final version, please kill strutsi");*/
2632 /*hcommand_add("test", H_PEON, helpmod_cmd_test, "Gives you userlevel 4, if you see this in the final version, please kill strutsi");*/
2633 }
2634
2635 void helpmod_command(huser *sender, channel* returntype, char *args)
2636 {
2637 int argc = 0, useless_var;
2638 char args_copy[512];
2639 char *parsed_args[H_CMD_MAX_ARGS + 3], *ptr = args_copy;
2640
2641 /* only accept commands from valid sources */
2642 if (huser_get_level(sender) < H_PEON || huser_get_level(sender) > H_ADMIN)
2643 return;
2644
2645 if (returntype && !strncmp(args, helpmodnick->nick, strlen(helpmodnick->nick)))
2646 {
2647 if (!args[1])
2648 return;
2649 else
2650 args+=strlen(helpmodnick->nick)+1;
2651 }
2652
2653 if (*args == '-' || *args == '?')
2654 args++;
2655
2656 strcpy(args_copy, args);
2657 /* FIX stringituki */
2658 while (argc < 10)
2659 {
2660 while (isspace(*ptr) && *ptr)
2661 ptr++;
2662
2663 if (*ptr == '\0')
2664 break;
2665
2666 if (*ptr == '"' && strchr(ptr+1, '"'))
2667 { /* string support */
2668 parsed_args[argc++] = ptr+1;
2669 ptr = strchr(ptr+1, '"');
2670
2671 *(ptr++) = '\0';
2672
2673 while (!isspace(*ptr) && *ptr)
2674 ptr++;
2675
2676 if (*ptr == '\0')
2677 break;
2678 }
2679 else
2680 {
2681 parsed_args[argc++] = ptr;
2682
2683 while (!isspace(*ptr) && *ptr)
2684 ptr++;
2685
2686 if (*ptr == '\0')
2687 break;
2688
2689 *(ptr++) = '\0';
2690 }
2691
2692 }
2693
2694 if (!argc)
2695 return;
2696
2697 /* old H compatibility */
2698 if (sscanf(parsed_args[0], "%d", &useless_var) && returntype == NULL)
2699 {
2700 helpmod_cmd_help(sender, NULL, parsed_args[0], 1, NULL);
2701 return;
2702 }
2703
2704 {
2705 char *ostr = args, **argv = (char**)&parsed_args; // for SKIP_WORD
2706 hcommand *hcom = hcommand_get(parsed_args[0], huser_get_level(sender));
2707
2708 if (hcom == NULL)
2709 helpmod_reply(sender, returntype, "Unknown command '%s', please see showcommands for a list of all commands available to you", parsed_args[0]);
2710 else
2711 {
2712 SKIP_WORD;
2713 hcom->function(sender, returntype, ostr, argc, argv);
2714 }
2715 }
2716 }
2717
2718 #undef SKIP_WORD
2719 #undef DEFINE_HCHANNEL
2720 #undef HCHANNEL_VERIFY_AUTHORITY