5 #include "../nick/nick.h"
6 #include "../channel/channel.h"
7 #include "../lib/irc_string.h"
14 #include "helpmod_alias.h"
26 #define HCMD_OUT_DEFAULT (10 * HDEF_m)
28 /* following are macros for use ONLY IN HERE
29 they may not look pretty, but work surprisingly well */
33 if (*ostr == '"' && strchr(ostr+1, '"'))\
34 ostr = strchr(ostr+1, '"');\
35 while (!isspace(*ostr) && *ostr)\
37 while (isspace(*ostr) && *ostr)\
43 #define DEFINE_HCHANNEL \
46 hchan = hchannel_get_by_channel(returntype);\
47 else if (*argv[0] == '#')\
49 hchan = hchannel_get_by_name(argv[0]);\
53 hchan = hchannel_get_by_channel(returntype);\
56 #define HCHANNEL_VERIFY_AUTHORITY(c, u)\
58 if ((c) != NULL && !hchannel_authority((c), (u)))\
60 helpmod_reply(u, returntype, "Sorry, channel %s is oper only", hchannel_get_name((c)));\
80 void helpmod_cmd_addchan (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
84 helpmod_reply(sender
, returntype
, "Can not add channel: Channel not defined");
90 helpmod_reply(sender
, returntype
, "Can not add channel: Channel name must start with '#'");
94 if (hchannel_get_by_name(argv
[0]) != NULL
)
96 helpmod_reply(sender
, returntype
, "Can not add channel: Channel %s already active", argv
[0]);
100 if (hchannel_add(argv
[0]) != NULL
)
102 helpmod_reply(sender
, returntype
, "Channel %s added succesfully", argv
[0]);
107 void helpmod_cmd_delchan (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
115 helpmod_reply(sender
, returntype
, "Can not delete channel: Channel not defined or not found");
118 strcpy(buffer
, hchan
->real_channel
->index
->name
->content
);
119 if (argc
== 0 || strcmp(argv
[0], "YesImSure"))
121 helpmod_reply(sender
, returntype
, "Can not delete channel: Sanity check. Please add a parameter \"YesImSure\" to confirm channel deletion");
126 helpmod_reply(sender
, returntype
, "Channel %s deleted succesfully", buffer
);
129 void helpmod_cmd_whoami (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
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");
136 helpmod_reply(sender
, returntype
, "Your accounts name is %s", sender
->account
->name
->content
);
137 if (huser_get_level(sender
) < H_TRIAL
)
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]);
142 helpmod_reply(sender
, returntype
, "You have not violated any rules");
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
));
153 if (IsAccount(sender
->real_user
))
157 for (hchan
= hchannels
;hchan
;hchan
= hchan
->next
)
158 if (hchan
->flags
& H_REQUIRE_TICKET
)
160 htick
= hticket_get(sender
->real_user
->authname
, hchan
);
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
));
167 void helpmod_cmd_whois (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
174 helpmod_reply(sender
, returntype
, "Can not get user information: User not specified");
177 if (argc
> H_CMD_MAX_ARGS
)
178 argc
= H_CMD_MAX_ARGS
;
182 husr
= huser_get(getnickbynick(argv
[i
]));
185 helpmod_reply(sender
, returntype
, "Can not get user information: User %s not found", argv
[i
]);
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
);
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
)
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]);
198 helpmod_reply(sender
, returntype
, "User %s has no lamercontrol entries", husr
->real_user
->nick
);
202 huser_channel
*huserchan
= husr
->hchannels
;
203 for (;huserchan
;huserchan
= huserchan
->next
)
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
));
211 if (IsAccount(husr
->real_user
))
215 for (hchan
= hchannels
;hchan
;hchan
= hchan
->next
)
216 if (hchan
->flags
& H_REQUIRE_TICKET
)
218 htick
= hticket_get(husr
->real_user
->authname
, hchan
);
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
));
226 void helpmod_cmd_megod (huser *sender, channel* returntype, char* ostr, int argc, char *argv[])
228 if (sender->account == NULL)
229 sender->account = haccount_add(sender->real_user->nick, H_ADMIN);
231 sender->account->level = H_ADMIN;
235 void helpmod_cmd_test (huser *sender, channel* returntype, char* ostr, int argc, char *argv[])
237 //lpmod_config_write("helpmod.db.test");
242 helpmod_channick_modes(huser_get(getnickbynick(argv[0])), hchan, MC_DEVOICE, 1);
246 void helpmod_cmd_seen (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
249 haccount
*target_haccount
;
254 helpmod_reply(sender
, returntype
, "No targets specified for seen");
257 for (i
=0;i
< argc
;i
++)
261 if (!ci_strcmp(argv
[i
] + 1, HELPMOD_AUTH
))
262 { /* A nice special case */
263 helpmod_reply(sender
, returntype
, "I'm right here");
266 target_haccount
= haccount_get_by_name(argv
[i
]);
267 if (target_haccount
== NULL
)
269 helpmod_reply(sender
, returntype
, "Account %s not found", argv
[i
] + 1);
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
));
277 if (getnickbynick(argv
[i
]) == helpmodnick
)
278 { /* A nice special case */
279 helpmod_reply(sender
, returntype
, "I'm right here");
282 target_huser
= huser_get(getnickbynick(argv
[i
]));
283 if (target_huser
== NULL
)
285 helpmod_reply(sender
, returntype
, "User %s not found", argv
[i
]);
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
));
293 void helpmod_cmd_change_userlevel(huser
*sender
, hlevel target_level
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
296 haccount
*target_haccount
;
301 helpmod_reply(sender
, returntype
, "Incorrect syntax, nick or account required");
305 if (argc
> H_CMD_MAX_ARGS
)
306 argc
= H_CMD_MAX_ARGS
;
308 for (i
= 0;i
< argc
;i
++)
310 if (*argv
[i
] == '#') /* account */
312 target_haccount
= haccount_get_by_name(argv
[i
]);
313 if (target_haccount
== NULL
)
315 helpmod_reply(sender
, returntype
, "Can not change userlevel: Account '%s' not found", argv
[i
]);
318 if (target_haccount
->level
> huser_get_level(sender
))
320 helpmod_reply(sender
, returntype
, "Can not change userlevel: Account '%s' has a userlevel higher than yours", argv
[i
]);
324 if (target_haccount
->level
== target_level
)
326 helpmod_reply(sender
, returntype
, "Can not change userlevel: Account '%s' already has userlevel %s", argv
[i
], hlevel_name(target_level
));
330 target_haccount
->level
= target_level
;
332 helpmod_reply(sender
, returntype
, "Userlevel changed: Account '%s' now has userlevel %s", argv
[i
], hlevel_name(target_level
));
337 target_huser
= huser_get(getnickbynick(argv
[i
]));
338 if (target_huser
== NULL
)
340 helpmod_reply(sender
, returntype
, "Can not change userlevel: User '%s' not found", argv
[i
]);
343 if (huser_get_level(target_huser
) > huser_get_level(sender
))
345 helpmod_reply(sender
, returntype
, "Can not change userlevel: User '%s' has a userlevel higher than yours", argv
[i
]);
348 if (huser_get_level(target_huser
) == H_STAFF
&& huser_get_level(sender
) == H_STAFF
)
350 helpmod_reply(sender
, returntype
, "Can not change userlevel: User '%s' has the same userlevel as you have", argv
[i
]);
354 if (huser_get_level(target_huser
) == target_level
)
356 helpmod_reply(sender
, returntype
, "Can not change userlevel: User '%s' already has userlevel %s", argv
[i
], hlevel_name(target_level
));
359 if (target_huser
== sender
)
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");
364 if (!IsAccount(target_huser
->real_user
))
366 helpmod_reply(sender
, returntype
, "Can not change userlevel: User '%s' is not authed", argv
[i
]);
370 if (target_huser
->account
== NULL
)
372 if (haccount_get_by_name(target_huser
->real_user
->authname
) != NULL
)
374 helpmod_reply(sender
, returntype
, "Can not change userlevel: Unable to create an account. Account %s already exists", target_huser
->real_user
->authname
);
378 target_huser
->account
= haccount_add(target_huser
->real_user
->authname
, target_level
);
381 target_huser
->account
->level
= target_level
;
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
));
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
); }
397 void helpmod_cmd_deluser (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
401 haccount
*target_haccount
;
405 helpmod_reply(sender
, returntype
, "Usage: deluser [nick|#account]");
409 if (argc
> H_CMD_MAX_ARGS
)
410 argc
= H_CMD_MAX_ARGS
;
412 for (i
= 0;i
< argc
;i
++)
416 target_huser
= huser_get(getnickbynick(argv
[i
]));
417 if (target_huser
== NULL
)
419 helpmod_reply(sender
, returntype
, "Cannot delete the account: User %s does not exist", argv
[i
]);
422 if (target_huser
->account
== NULL
)
424 helpmod_reply(sender
, returntype
, "Cannot delete the account: User %s does not have an account", argv
[i
]);
427 target_haccount
= target_huser
->account
;
430 target_haccount
= haccount_get_by_name(argv
[i
]);
432 if (target_haccount
== NULL
)
434 helpmod_reply(sender
, returntype
, "Cannot delete the account: Account %s does not exist", argv
[i
]);
437 if (target_haccount
->level
> huser_get_level(sender
))
439 helpmod_reply(sender
, returntype
, "Cannot delete the account: Account %s has higher userlevel than you", target_haccount
->name
->content
);
442 helpmod_reply(sender
, returntype
, "Account %s deleted", target_haccount
->name
->content
);
443 haccount_del(target_haccount
);
447 void helpmod_cmd_listuser (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
450 haccount
*hack
= haccounts
;
451 int count
= 0, lvl
= -1;
454 if (argc
> 0 && sscanf(argv
[0], "%d", &lvl
) && lvl
>= H_LAMER
&& lvl
<= H_ADMIN
)
467 helpmod_reply(sender
, returntype
, "%s accounts matching pattern %s: (account name, userlevel, expires in)", hlevel_name(lvl
), pattern
);
469 helpmod_reply(sender
, returntype
, "Accounts matching pattern %s: (account name, userlevel, expires in)", pattern
);
470 for (;hack
;hack
= hack
->next
)
472 if (strregexp(hack
->name
->content
, pattern
))
474 if (lvl
> 0 && hack
->level
!= lvl
)
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
)));
482 helpmod_reply(sender
, returntype
, "%s accounts matching pattern %d", hlevel_name(lvl
), count
);
484 helpmod_reply(sender
, returntype
, "Accounts matching pattern %d", count
);
487 void helpmod_cmd_censor (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
495 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
499 helpmod_reply(sender
, returntype
, "Can not handle the censor: Channel not specified or found");
503 if (argc
< 2) /* view */
505 if (hchan
->censor
== NULL
)
506 helpmod_reply(sender
, returntype
, "Nothing is censored on channel %s", hchan
->real_channel
->index
->name
->content
);
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
:"");
516 if (!ci_strcmp(argv
[0], "add"))
529 if (hcensor_get_by_pattern(hchan
->censor
, pattern
))
531 helpmod_reply(sender
, returntype
, "Cannot add censor entry: Pattern '%s' already censored", pattern
);
535 if (hcensor_add(&hchan
->censor
, pattern
, reason
))
536 helpmod_reply(sender
, returntype
, "Pattern '%s' (%s) censored succesfully", pattern
, reason
?reason
:"no reason specified");
538 helpmod_reply(sender
, returntype
, "Cannot add censor entry: Pattern '%s' already censored", pattern
);
541 else if (!ci_strcmp(argv
[0], "del"))
547 if (!sscanf(argv
[0], "#%d", &tmp
))
549 helpmod_reply(sender
, returntype
, "Cannot delete censor entry: Bad index, integer expected");
552 hcens
= hcensor_get_by_index(hchan
->censor
, tmp
);
555 hcens
= hcensor_get_by_pattern(hchan
->censor
, argv
[0]);
558 helpmod_reply(sender
, returntype
, "Cannot delete censor entry: Entry not found");
561 hcensor_del(&hchan
->censor
, hcens
);
562 helpmod_reply(sender
, returntype
, "Censor entry deleted succesfully");
566 helpmod_reply(sender
, returntype
, "Unknown censor command %s", argv
[0]);
570 void helpmod_cmd_chanconf (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
577 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
581 helpmod_reply(sender
, returntype
, "Can not change or view channel configuration: Channel not specified or found");
585 if (argc
== 0) /* view, spammy but with pretty formatting */
588 helpmod_reply(sender
, returntype
, "Channel configuration for %s:", hchan
->real_channel
->index
->name
->content
);
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
));
596 old_flags
= hchan
->flags
;
598 if (argc
> H_CMD_MAX_ARGS
)
599 argc
= H_CMD_MAX_ARGS
;
608 else if (*argv
[i
] == '-')
616 if (!sscanf(argv
[i
], "%d", &tmp
) || (tmp
< 0) || (tmp
> HCHANNEL_CONF_COUNT
))
618 helpmod_reply(sender
, returntype
, "Can not change channel configuration: Expected integer between [0, %d]", HCHANNEL_CONF_COUNT
);
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
));
629 helpmod_reply(sender
, returntype
, "(%02d) %-32s : %s", tmp
, hchannel_get_sname(tmp
), hchannel_get_state(hchan
, 1 << tmp
));
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
));
637 hchannel_conf_change(hchan
, old_flags
);
641 void helpmod_cmd_acconf (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
643 haccount
*hacc
= sender
->account
;
647 helpmod_reply(sender
, returntype
, "Account configuration impossible: You do not have an account");
651 if (argc
== 0) /* view, spammy but with pretty formatting */
654 helpmod_reply(sender
, returntype
, "Account configuration for %s:", hacc
->name
->content
);
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
));
663 if (argc
> H_CMD_MAX_ARGS
)
664 argc
= H_CMD_MAX_ARGS
;
673 else if (*argv
[i
] == '-')
681 if (!sscanf(argv
[i
], "%d", &tmp
) || (tmp
< 0) || (tmp
> HACCOUNT_CONF_COUNT
))
683 helpmod_reply(sender
, returntype
, "Can not change account configuration: Expected integer between [0, %d]", HACCOUNT_CONF_COUNT
);
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
));
694 helpmod_reply(sender
, returntype
, "(%02d) %-35s : %s", tmp
, haccount_get_sname(tmp
), haccount_get_state(hacc
, 1 << tmp
));
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
));
705 void helpmod_cmd_welcome (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
711 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
715 helpmod_reply(sender
, returntype
, "Can not change or view chanflags: Channel not specified or found");
719 if (argc
== 0) /* view */
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
);
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
);
730 void helpmod_cmd_aliases (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
734 void helpmod_list_aliases(alias_tree node
)
738 helpmod_reply(sender
, returntype
, buf
);
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
);
748 helpmod_list_aliases(aliases
);
750 helpmod_reply(sender
, returntype
, buf
);
753 void helpmod_cmd_showcommands (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
758 if (!(argc
&& (sscanf(argv
[0], "%d", &level
)) && (level
>= 0) && (level
<= huser_get_level(sender
))))
759 level
= huser_get_level(sender
);
761 helpmod_reply(sender
, returntype
, "HelpMod %s commands for userlevel %s:", HELPMOD_VERSION
, hlevel_name(level
));
763 hcommand_list(H_NONE
);
765 while ((tmp
= hcommand_list(level
)) != NULL
)
766 helpmod_reply(sender
, returntype
, "%-16s %s", tmp
->name
->content
, tmp
->help
->content
);
771 void helpmod_cmd_lamercontrol (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
778 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
780 if (hchan
== NULL
) /* list profiles */
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
);
789 if (hchan
->lc_profile
== NULL
)
790 helpmod_reply(sender
, returntype
, "Channel %s has no lamercontrol profile set", hchannel_get_name(hchan
));
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
));
795 if (!ci_strcmp(argv
[0], "list"))
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
);
802 ptr
= hlc_get(argv
[0]);
805 helpmod_reply(sender
, returntype
, "Can not set the lamercontrol profile: Profile %s does not exist:", argv
[0]);
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
));
816 void helpmod_cmd_term_find_general (huser
*sender
, channel
* returntype
, int type
, char* ostr
, int argc
, char *argv
[])
829 source
= hchan
->channel_hterms
;
833 if (type
== H_TERM_PLUS
)
834 hqueue_advance(hchan
, sender
, 1);
836 helpmod_reply(sender
, returntype
, "Can not find term: Term not specified");
839 htrm
= hterm_get_and_find(source
, argv
[0]);
842 helpmod_reply(sender
, returntype
, "No term found matching '%s'", argv
[0]);
845 if (returntype
!= NULL
&& huser_get_level(sender
) > H_PEON
)
847 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
852 if (argc
> H_CMD_MAX_ARGS
)
853 argc
= H_CMD_MAX_ARGS
;
856 targets
[ntargets
] = huser_get(getnickbynick(argv
[i
]));
857 if (targets
[ntargets
] == NULL
)
859 helpmod_reply(sender
, returntype
, "Error using ?: User %s not found", argv
[i
]);
868 helpmod_message_channel_long(hchannel_get_by_channel(returntype
), "(%s): %s", htrm
->name
->content
, htrm
->description
->content
);
871 char buffer
[256] = "";
872 for (i
=0;i
<ntargets
;i
++)
875 strcat(buffer
, targets
[i
]->real_user
->nick
);
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
)
881 if (hchan
->flags
& H_QUEUE
)
883 for (i
=0;i
<ntargets
;i
++)
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
);
890 if (type
== H_TERM_PLUS
)
891 hqueue_advance(hchan
, sender
, ntargets
);
897 helpmod_reply(sender
, returntype
, "(%s): %s", htrm
->name
->content
, htrm
->description
->content
);
900 void helpmod_cmd_term_find (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
902 helpmod_cmd_term_find_general(sender
, returntype
, H_TERM_FIND
, ostr
, argc
, argv
);
905 void helpmod_cmd_term_find_minus (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
907 helpmod_cmd_term_find_general(sender
, returntype
, H_TERM_MINUS
, ostr
, argc
, argv
);
910 void helpmod_cmd_term_find_plus (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
912 helpmod_cmd_term_find_general(sender
, returntype
, H_TERM_PLUS
, ostr
, argc
, argv
);
915 void helpmod_cmd_klingon (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
918 huser
*target
= NULL
;
925 rand_val
= rand() % KLINGON_NTARGETED
;
926 helpmod_reply(sender
, NULL
, "%s: %s", sender
->real_user
->nick
, klingon_targeted
[rand_val
]);
931 target
= huser_get(getnickbynick(argv
[0]));
935 rand_val
= rand() % KLINGON_NTARGETED
;
936 helpmod_message_channel(hchan
, "%s: %s", target
->real_user
->nick
, klingon_targeted
[rand_val
]);
940 rand_val
= rand() % KLINGON_NGENERAL
;
941 helpmod_message_channel(hchan
, "%s", klingon_general
[rand_val
]);
945 void helpmod_cmd_term (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
953 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
958 source
= &hchan
->channel_hterms
;
962 helpmod_reply(sender
, returntype
, "Can not handle terms: Operation not specified");
965 if (!ci_strcmp(argv
[0], "list"))
979 helpmod_reply(sender
, returntype
, "Terms matching pattern '%s'", pattern
);
980 for (;htrm
;htrm
= htrm
->next
)
982 if (strlen(buffer
) >= 250)
984 helpmod_reply(sender
, returntype
, buffer
);
987 if (strregexp(htrm
->description
->content
, pattern
) || strregexp(htrm
->name
->content
, pattern
))
989 sprintf(buffer
+strlen(buffer
) /* :) */, "%s(%d) ", htrm
->name
->content
, strlen(htrm
->description
->content
));
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
);
997 else if (!ci_strcmp(argv
[0], "listfull"))
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
);
1004 else if (!ci_strcmp(argv
[0], "get"))
1008 helpmod_reply(sender
, returntype
, "Can not get term: Term not specified");
1011 htrm
= hterm_get(*source
, argv
[1]);
1013 helpmod_reply(sender
, returntype
, "Can not get term: Term %s not found", argv
[1]);
1015 helpmod_reply(sender
, returntype
, "(%s): %s", htrm
->name
->content
, htrm
->description
->content
);
1017 else if (!ci_strcmp(argv
[0], "add"))
1020 helpmod_reply(sender
, returntype
, "Can not add term: Term name not specified");
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]);
1027 char *name
= argv
[1], *description
;
1028 SKIP_WORD
; SKIP_WORD
;
1030 htrm
= hterm_add(source
, name
, description
);
1031 helpmod_reply(sender
, returntype
, "Term %s added succesfully", name
);
1034 else if (!ci_strcmp(argv
[0], "del"))
1039 helpmod_reply(sender
, returntype
, "Can not delete term: Term name not specified");
1042 if (argc
> H_CMD_MAX_ARGS
)
1043 argc
= H_CMD_MAX_ARGS
;
1044 for (i
=1;i
<argc
;i
++)
1046 htrm
= hterm_get(*source
, argv
[i
]);
1049 helpmod_reply(sender
, returntype
, "Can not delete term: Term %s not found", argv
[i
]);
1052 hterm_del(source
, htrm
);
1053 helpmod_reply(sender
, returntype
, "Term %s deleted succesfully", argv
[i
]);
1057 else if (!ci_strcmp(argv
[0], "find"))
1061 helpmod_reply(sender
, returntype
, "Can not find term: Term name not specified");
1064 htrm
= hterm_get_and_find(*source
, argv
[1]);
1068 helpmod_reply(sender
, returntype
, "No term found matching '%s'", argv
[0]);
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
);
1074 helpmod_reply(sender
, returntype
, "(%s): %s", htrm
->name
->content
, htrm
->description
->content
);
1078 helpmod_reply(sender
, returntype
, "Can not handle terms: Operation not specified");
1082 void helpmod_cmd_queue (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
1089 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
1093 helpmod_reply(sender
, returntype
, "Can not handle queue: Operation not specified");
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"))
1103 else if (!ci_strcmp(argv
[0], "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
;
1114 operation
= HQ_NONE
;
1118 helpmod_queue_handler(sender
, returntype
, hchan
, operation
, ostr
, argc
, argv
);
1121 void helpmod_cmd_done (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
1125 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
1126 helpmod_queue_handler(sender
, returntype
, hchan
, HQ_DONE
, ostr
, argc
, argv
);
1129 void helpmod_cmd_next (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
1133 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
1134 helpmod_queue_handler(sender
, returntype
, hchan
, HQ_NEXT
, ostr
, argc
, argv
);
1137 void helpmod_cmd_enqueue (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
1141 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
1142 helpmod_queue_handler(sender
, returntype
, hchan
, HQ_ON
, ostr
, argc
, argv
);
1145 void helpmod_cmd_dequeue (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
1149 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
1150 helpmod_queue_handler(sender
, returntype
, hchan
, HQ_OFF
, ostr
, argc
, argv
);
1153 void helpmod_cmd_autoqueue (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
1157 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
1158 helpmod_queue_handler(sender
, returntype
, hchan
, HQ_MAINTAIN
, ostr
, argc
, argv
);
1161 void helpmod_cmd_dnmo (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
1166 helpmod_reply(sender
, returntype
, "Can not correct the luser: User not defined");
1169 if (argc
> H_CMD_MAX_ARGS
)
1170 argc
= H_CMD_MAX_ARGS
;
1171 for (i
=0;i
<argc
;i
++)
1173 huser
*husr
= huser_get(getnickbynick(argv
[i
]));
1176 helpmod_reply(sender
, returntype
, "Can not correct the luser: User %s not found", argv
[i
]);
1180 if (!hchannels_on_queue(husr) && !hchannels_on_desk(husr))
1182 helpmod_reply(sender, returntype, "Can not correct the luser: User %s is not in any queue", argv[i]);
1186 hchannels_dnmo(husr
);
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
]);
1191 { /* fix the autoqueue for the channel(s) */
1193 for (hchan
= hchannels
;hchan
;hchan
= hchan
->next
)
1194 hqueue_handle_queue(hchan
, sender
);
1198 void helpmod_cmd_ban (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
1202 helpmod_reply(sender
, returntype
, "Can not global handle bans: Operation not defined");
1206 else if (!ci_strcmp(argv
[0], "list"))
1217 helpmod_reply(sender
, returntype
, "Global bans matching pattern %s", pattern
);
1219 for (;ptr
;ptr
= ptr
->next
)
1220 if (strregexp(bantostring(ptr
->real_ban
), pattern
))
1222 helpmod_reply(sender
, returntype
, "%-64s %-15s %s", bantostring(ptr
->real_ban
), helpmod_strtime(ptr
->expiration
- time(NULL
)), ptr
->reason
?ptr
->reason
->content
:"");
1226 helpmod_reply(sender
, returntype
, "%d Global bans match pattern %s", count
, pattern
);
1229 else if (!ci_strcmp(argv
[0], "add"))
1231 int duration
= 4 * HDEF_h
;
1232 char *reason
= "Banned";
1233 char *target
= argv
[1];
1237 helpmod_reply(sender
, returntype
, "Can not add global ban: Target hostmask not defined");
1242 if ((duration
= helpmod_read_strtime(argv
[2])) < 0)
1244 helpmod_reply(sender
, returntype
, "Can not add global ban: Invalid time %s", argv
[2]);
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
));
1259 else if (!ci_strcmp(argv
[0], "del"))
1264 helpmod_reply(sender
, returntype
, "Can not remove global ban: Target hostmask not defined");
1267 if (argc
> H_CMD_MAX_ARGS
)
1268 argc
= H_CMD_MAX_ARGS
;
1269 for (i
=1;i
<argc
;i
++)
1271 hban
*ptr
= hban_get(argv
[i
]);
1274 helpmod_reply(sender
, returntype
, "Can not remove global ban: Hostmask %s is not banned", argv
[i
]);
1277 helpmod_reply(sender
, returntype
, "Global ban for hostmask %s removed", argv
[i
]);
1283 helpmod_reply(sender
, returntype
, "Can not handle global bans: Unknown operation %s", argv
[0]);
1288 void helpmod_cmd_chanban (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
1297 helpmod_reply(sender
, returntype
, "Can not handle channel bans: Channel not defined or not found");
1301 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
1305 helpmod_reply(sender
, returntype
, "Can not handle channel bans: Operation not defined");
1309 if (!ci_strcmp(argv
[0], "list"))
1311 char *pattern
, *cban
;
1312 chanban
*ptr
= hchan
->real_channel
->bans
;
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
))
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
)));
1328 helpmod_reply(sender
, returntype
, "%s", bantostring(ptr
));
1330 helpmod_reply(sender
, returntype
, "%d bans match pattern %s on channel %s", count
, pattern
, hchannel_get_name(hchan
));
1332 else if (!ci_strcmp(argv
[0], "add"))
1336 helpmod_reply(sender
, returntype
, "Can not add channel bans: Pattern not defined");
1339 if (argc
> H_CMD_MAX_ARGS
)
1340 argc
= H_CMD_MAX_ARGS
;
1341 for (i
=1;i
<argc
;i
++)
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
));
1348 else if (!ci_strcmp(argv
[0], "del"))
1352 helpmod_reply(sender
, returntype
, "Can not remove channel bans: Pattern not defined");
1355 if (argc
> H_CMD_MAX_ARGS
)
1356 argc
= H_CMD_MAX_ARGS
;
1357 for (i
=1;i
<argc
;i
++)
1359 chanban
*ptr
= hchan
->real_channel
->bans
;
1360 for (;ptr
;ptr
= ptr
->next
)
1361 if (strregexp(bantostring(ptr
), argv
[i
]))
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
));
1368 helpmod_reply(sender
, returntype
, "Can not remove channel ban: Pattern %s not banned on channel %s", argv
[i
], hchannel_get_name(hchan
));
1373 helpmod_reply(sender
, returntype
, "Can not handle channel bans: Unknown operation %s", argv
[0]);
1378 void helpmod_cmd_idlekick (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
1385 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
1389 helpmod_reply(sender
, returntype
, "Can not handle the idlekick: Channel not defined or not found");
1392 if (argc
== 0) /* view */
1394 helpmod_reply(sender
, returntype
, "Idlekick for channel %s is set to %s", hchannel_get_name(hchan
), helpmod_strtime(hchan
->max_idle
));
1397 else if ((tmp
= helpmod_read_strtime(argv
[0])) < 0 || tmp
< HDEF_m
|| tmp
> HDEF_w
)
1399 helpmod_reply(sender
, returntype
, "Can not set the idlekick: Invalid time given '%s'", argv
[0]);
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
));
1409 void helpmod_cmd_topic (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
1414 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
1418 helpmod_reply(sender
, returntype
, "Can not handle the topic: Channel not defined or not found");
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
));
1424 if (argc
== 0) /* check the topic */
1426 helpmod_reply(sender
, returntype
, "Topic of channel %s is currently: %s", hchannel_get_name(hchan
), htopic_construct(hchan
->topic
));
1429 if (!ci_strcmp(argv
[0], "erase"))
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
));
1435 else if (!ci_strcmp(argv
[0], "refresh"))
1437 hchannel_set_topic(hchan
);
1438 helpmod_reply(sender
, returntype
, "Topic of channel %s refreshed", hchannel_get_name(hchan
));
1440 else if (!ci_strcmp(argv
[0], "add"))
1446 helpmod_reply(sender
, returntype
, "Cannot handle the topic of channel %s: Additional arguments required", hchannel_get_name(hchan
));
1449 if (sscanf(argv
[0], "%d", &pos
) && pos
>= 0)
1455 if (argc
== 0) /* lame repeat :( */
1457 helpmod_reply(sender
, returntype
, "Cannot handle the topic of channel %s: Additional arguments required", hchannel_get_name(hchan
));
1460 if (htopic_len(hchan
->topic
) + strlen(ostr
) + 3 > TOPICLEN
)
1462 helpmod_reply(sender
, returntype
, "Cannot add to the topic of channel %s: Maximum topic length exceeded", hchannel_get_name(hchan
));
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
));
1470 else if (!ci_strcmp(argv
[0], "del"))
1475 helpmod_reply(sender
, returntype
, "Cannot handle the topic of channel %s: Additional arguments required", hchannel_get_name(hchan
));
1479 if (!sscanf(argv
[0], "%d", &pos
) || pos
< 0)
1481 helpmod_reply(sender
, returntype
, "Cannot handle the topic of channel %s: Expected positive integer", hchannel_get_name(hchan
));
1484 if (htopic_count(hchan
->topic
) < pos
)
1486 helpmod_reply(sender
, returntype
, "Cannot delete from the topic of channel %s: No such topic element %d", hchannel_get_name(hchan
), pos
);
1489 htopic_del(&hchan
->topic
, htopic_get(hchan
->topic
, pos
));
1490 hchannel_set_topic(hchan
);
1492 else if (!ci_strcmp(argv
[0], "set"))
1496 helpmod_reply(sender
, returntype
, "Cannot handle the topic of channel %s: Additional arguments required", hchannel_get_name(hchan
));
1500 htopic_del_all(&hchan
->topic
);
1501 htopic_add(&hchan
->topic
, ostr
, 0);
1502 hchannel_set_topic(hchan
);
1505 helpmod_reply(sender
, returntype
, "Can not handle the topic of channel %s: Unknown operation %s", hchannel_get_name(hchan
), argv
[0]);
1508 void helpmod_cmd_out (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
1514 helpmod_reply(sender
, returntype
, "Can not get rid of the user: User not specified");
1518 if (argc
> H_CMD_MAX_ARGS
)
1519 argc
= H_CMD_MAX_ARGS
;
1520 for (i
=0;i
<argc
;i
++)
1522 husr
= huser_get(getnickbynick(argv
[i
]));
1525 helpmod_reply(sender
, returntype
, "Can not get rid of the user: User %s not found", argv
[i
]);
1528 if (huser_get_level(husr
) > H_PEON
)
1530 helpmod_reply(sender
, returntype
, "Can not get rid of the user: User %s is not a peon", husr
->real_user
->nick
);
1534 const char *banmask
= hban_ban_string(husr
->real_user
, HBAN_REAL_HOST
);
1536 hban_add(banmask
, "Banned", time(NULL
) + HCMD_OUT_DEFAULT
, 0);
1538 helpmod_reply(sender
, returntype
, "User %s is now gone", husr
->real_user
->nick
);
1542 void helpmod_cmd_everyoneout (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
1545 hchannel_user
**hchanuser
;
1546 char *reason
= "clearing channel";
1547 int autoqueue_tmp
= -1;
1551 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
1555 helpmod_reply(sender
, returntype
, "Can not clear channel: Channel not defined or not found");
1562 hchan
->flags
|= H_MAINTAIN_I
;
1563 hchannel_mode_check(hchan
);
1565 hchanuser
= &hchan
->channel_users
;
1567 if ((hchan
->flags
& H_QUEUE
) && (hchan
->flags
& H_QUEUE_MAINTAIN
))
1569 autoqueue_tmp
= hchan
->autoqueue
;
1570 hchan
->autoqueue
= 0;
1575 if (huser_get_level((*hchanuser
)->husr
) < H_TRIAL
)
1576 helpmod_kick(hchan
, (*hchanuser
)->husr
, reason
);
1578 hchanuser
= &(*hchanuser
)->next
;
1581 if (autoqueue_tmp
> 0)
1582 hchan
->autoqueue
= autoqueue_tmp
;
1584 helpmod_reply(sender
, returntype
, "Channel %s has been cleared of normal users", hchannel_get_name(hchan
));
1587 void helpmod_cmd_kick (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
1591 huser
*husr
, *targets
[6];
1593 char *reason
= "out";
1596 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
1600 helpmod_reply(sender
, returntype
, "Can not kick the user: Channel not defined or not found");
1603 if (argc
> H_CMD_MAX_ARGS
)
1604 argc
= H_CMD_MAX_ARGS
;
1605 for (i
=0;i
<argc
;i
++)
1607 if (*argv
[i
] == ':')
1616 husr
= huser_get(getnickbynick(argv
[i
]));
1619 helpmod_reply(sender
, returntype
, "Can not kick the user: User %s not found", argv
[i
]);
1622 if (huser_on_channel(husr
, hchan
) == NULL
)
1624 helpmod_reply(sender
, returntype
, "Can not kick the user: User %s is on channel", husr
->real_user
->nick
, hchannel_get_name(hchan
));
1627 if (huser_get_level(husr
) > H_PEON
)
1629 helpmod_reply(sender
, returntype
, "Can not kick the user: User %s is not a peon", husr
->real_user
->nick
);
1632 targets
[ntargets
++] = husr
;
1636 helpmod_reply(sender
, returntype
, "Can not kick the user: No users defined");
1639 for (i
=0;i
<ntargets
;i
++)
1640 helpmod_kick(hchan
, targets
[i
], reason
);
1643 void helpmod_cmd_stats (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
1646 haccount
*target
= sender
->account
;
1648 hstat_account_entry
*stat_entry
;
1649 int days
= 1, weeks
= 0;
1650 int type
= HSTAT_ACCOUNT_SHORT
;
1652 time_t timer
= time(NULL
);
1653 struct tm
*tstruct
= localtime(&timer
);
1659 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
1663 helpmod_reply(sender
, returntype
, "Can not show user statistics: Channel not defined or not found");
1667 if (argc
> 0 && huser_get_level(sender
) == H_ADMIN
)
1668 { /* not very elegant */
1669 if (argv
[0][0] == '#') /* account */
1671 target
= haccount_get_by_name(argv
[0]+1);
1674 helpmod_reply(sender
, returntype
, "Can not show user statistics: Account %s not found", argv
[0]);
1683 helpmod_reply(sender
, returntype
, "Can not show user statistics: You do not have an account");
1689 if (!ci_strcmp(argv
[0], "short") || !ci_strcmp(argv
[0], "s"))
1691 type
= HSTAT_ACCOUNT_SHORT
;
1694 else if (!ci_strcmp(argv
[0], "long") || !ci_strcmp(argv
[0], "l"))
1696 type
= HSTAT_ACCOUNT_LONG
;
1702 if (sscanf(argv
[0], "%d", &days
))
1704 if (days
< 0 || days
> 7)
1706 helpmod_reply(sender
, returntype
, "Can not show user statistics: Expected integer between [0, 7]");
1716 if (sscanf(argv
[0], "%d", &weeks
))
1718 if (weeks
< 0 || weeks
> 10)
1720 helpmod_reply(sender
, returntype
, "Can not show user statistics: Expected integer between [0, 10]");
1729 for (ptr
= target
->stats
;ptr
;ptr
= ptr
->next
)
1730 if (ptr
->hchan
== hchan
)
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
));
1739 if (!days
&& !weeks
)
1742 helpmod_reply(sender
, returntype
, "Statistics for user %s on channel %s", target
->name
->content
, hchannel_get_name(hchan
));
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
++)
1750 stat_entry
= &ptr
->week
[(tstruct
->tm_wday
- i
+ 7) % 7];
1751 helpmod_reply(sender
, returntype
, hstat_account_print(stat_entry
, type
));
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
++)
1761 stat_entry
= &ptr
->longterm
[(hstat_week() - i
+ 10) % 10];
1762 helpmod_reply(sender
, returntype
, hstat_account_print(stat_entry
, type
));
1767 void helpmod_cmd_chanstats (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
1770 hstat_channel
*channel_stats
;
1771 hstat_channel_entry
*stat_entry
;
1773 time_t timer
= time(NULL
);
1774 struct tm
*tstruct
= localtime(&timer
);
1777 int type
= HSTAT_CHANNEL_SHORT
;
1784 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
1788 helpmod_reply(sender
, returntype
, "Can not show channel statistics: Channel not defined or not found");
1794 if (!ci_strcmp(argv
[0], "short") || !ci_strcmp(argv
[0], "s"))
1796 type
= HSTAT_CHANNEL_SHORT
;
1799 else if (!ci_strcmp(argv
[0], "long") || !ci_strcmp(argv
[0], "l"))
1801 type
= HSTAT_CHANNEL_LONG
;
1807 if (sscanf(argv
[0], "%d", &days
))
1809 if (days
< 0 || days
> 7)
1811 helpmod_reply(sender
, returntype
, "Can not show channel statistics: Expected integer between [0, 7]");
1821 if (sscanf(argv
[0], "%d", &weeks
))
1823 if (weeks
< 0 || weeks
> 10)
1825 helpmod_reply(sender
, returntype
, "Can not show channel statistics: Expected integer between [0, 10]");
1835 channel_stats
= hchan
->stats
;
1837 if (!days
&& !weeks
)
1840 helpmod_reply(sender
, returntype
, "Statistics for channel %s", hchannel_get_name(hchan
));
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 */
1848 stat_entry
= &hchan
->stats
->week
[(tstruct
->tm_wday
- i
+ 7) % 7];
1849 helpmod_reply(sender
, returntype
, hstat_channel_print(stat_entry
, type
));
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 */
1859 stat_entry
= &hchan
->stats
->longterm
[(hstat_week() - i
+ 10) % 10];
1860 helpmod_reply(sender
, returntype
, hstat_channel_print(stat_entry
, type
));
1865 void helpmod_cmd_activestaff (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
1868 hstat_accounts_array arr
;
1869 hlevel lvl
= H_OPER
;
1877 helpmod_reply(sender
, returntype
, "Can not list active staff: Channel not specified or not found");
1883 if (!ci_strcmp(argv
[0], "opers") || !ci_strcmp(argv
[0], "o"))
1888 else if (!ci_strcmp(argv
[0], "staff") || !ci_strcmp(argv
[0], "s"))
1897 if (!ci_strcmp(argv
[0], "active") || !ci_strcmp(argv
[0], "a"))
1902 else if (!ci_strcmp(argv
[0], "inactive") || !ci_strcmp(argv
[0], "i"))
1909 arr
= create_hstat_account_array(hchan
, lvl
);
1911 helpmod_reply(sender
, returntype
, "%s %ss for channel %s", listtype
?"Inactive":"Active", hlevel_name(lvl
), hchannel_get_name(hchan
));
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
));
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
));
1927 void helpmod_cmd_top10 (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
1930 hstat_accounts_array arr
;
1931 hlevel lvl
= H_OPER
;
1936 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
1940 helpmod_reply(sender
, returntype
, "Can not list channel Top10: Channel not specified or not found");
1946 if (!ci_strcmp(argv
[0], "opers") || !ci_strcmp(argv
[0], "o"))
1948 else if (!ci_strcmp(argv
[0], "staff") || !ci_strcmp(argv
[0], "s"))
1954 if (sscanf(argv
[1], "%d", &tmp
) && (tmp
>= 10) && (tmp
<= 50))
1958 arr
= create_hstat_account_array(hchan
, lvl
);
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
));
1967 void helpmod_cmd_report (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
1969 hchannel
*hchan
, *target
;
1972 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
1974 if (hchan
!= NULL
&& (argc
== 2))
1976 hchan
= hchannel_get_by_name(argv
[0]);
1982 helpmod_reply(sender
, returntype
, "Can not view or set channel reporting: Channel not defined or not found");
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
));
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
));
1993 if ((target
= hchannel_get_by_name(argv
[0])) == NULL
)
1995 helpmod_reply(sender
, returntype
, "Can not set channel reporting: Channel %s not found", argv
[0]);
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
));
2002 void helpmod_cmd_mode(huser
*sender
, channel
* returntype
, int change
, char* ostr
, int argc
, char *argv
[])
2005 huser_channel
*huserchan
;
2011 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
2015 helpmod_reply(sender
, returntype
, "Can not change mode: Channel not specified or not found");
2019 if (argc
==0) /* for a simple opme */
2022 argv
[0] = sender
->real_user
->nick
;
2025 if (argc
> H_CMD_MAX_ARGS
)
2026 argc
= H_CMD_MAX_ARGS
;
2028 for (i
=0;i
<argc
;i
++)
2030 husr
= huser_get(getnickbynick(argv
[i
]));
2033 helpmod_reply(sender
, returntype
, "Can not change mode: User %s not found", argv
[i
], hchannel_get_name(hchan
));
2036 huserchan
= huser_on_channel(husr
, hchan
);
2037 if (huserchan
== NULL
)
2039 helpmod_reply(sender
, returntype
, "Can not change mode: User %s it not on channel %s", husr
->real_user
->nick
, hchannel_get_name(hchan
));
2048 for (j
=0;j
< hchan
->real_channel
->users
->hashsize
;j
++)
2049 if (getnickbynumeric(hchan
->real_channel
->users
->content
[j
]) == husr
->real_user
)
2051 if ((huserchan
->flags
& HCUMODE_OP
) && !(hchan
->real_channel
->users
->content
[j
] & CUMODE_OP
))
2053 huserchan
->flags
&= ~HCUMODE_OP
;
2054 Error("helpmod", ERR_ERROR
, "userchannelmode inconsistency (+o when should be -o)");
2056 if (huserchan
->flags
& HCUMODE_OP
)
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
));
2061 if (huser_get_level(husr
) < H_STAFF
)
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
));
2066 helpmod_channick_modes(husr
, hchan
, MC_OP
, HLAZY
);
2072 for (j
=0;j
< hchan
->real_channel
->users
->hashsize
;j
++)
2073 if (getnickbynumeric(hchan
->real_channel
->users
->content
[j
]) == husr
->real_user
)
2075 if (!(huserchan
->flags
& HCUMODE_OP
) && (hchan
->real_channel
->users
->content
[j
] & CUMODE_OP
))
2077 huserchan
->flags
|= HCUMODE_OP
;
2078 Error("helpmod", ERR_ERROR
, "userchannelmode inconsistency (-o when should be +o)");
2080 if (!(huserchan
->flags
& HCUMODE_OP
))
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
));
2085 if (huser_get_level(husr
) > huser_get_level(sender
))
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
));
2090 helpmod_channick_modes(husr
, hchan
, MC_DEOP
, HLAZY
);
2096 for (j
=0;j
< hchan
->real_channel
->users
->hashsize
;j
++)
2097 if (getnickbynumeric(hchan
->real_channel
->users
->content
[j
]) == husr
->real_user
)
2099 if ((huserchan
->flags
& HCUMODE_VOICE
) && !(hchan
->real_channel
->users
->content
[j
] & CUMODE_VOICE
))
2101 huserchan
->flags
&= ~HCUMODE_VOICE
;
2102 Error("helpmod", ERR_ERROR
, "userchannelmode inconsistency (+v when should be -v)");
2104 if (huserchan
->flags
& HCUMODE_VOICE
)
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
));
2109 helpmod_channick_modes(husr
, hchan
, MC_VOICE
, HLAZY
);
2115 for (j
=0;j
< hchan
->real_channel
->users
->hashsize
;j
++)
2116 if (getnickbynumeric(hchan
->real_channel
->users
->content
[j
]) == husr
->real_user
)
2118 if (!(huserchan
->flags
& HCUMODE_VOICE
) && (hchan
->real_channel
->users
->content
[j
] & CUMODE_VOICE
))
2120 huserchan
->flags
|= HCUMODE_VOICE
;
2121 Error("helpmod", ERR_ERROR
, "userchannelmode inconsistency (-v when should be +v)");
2123 if (!(huserchan
->flags
& HCUMODE_VOICE
))
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
));
2128 helpmod_channick_modes(husr
, hchan
, MC_DEVOICE
, HLAZY
);
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
); }
2140 void helpmod_cmd_invite (huser
*sender
, channel
*returntype
, char* arg
, int argc
, char *argv
[])
2147 helpmod_reply(sender
, returntype
, "Can not invite: Channel not defined or not found");
2151 if (huser_get_level(sender
) == H_PEON
)
2154 hchan
= hchannel_get_by_name(argv
[0]);
2157 helpmod_reply(sender
, returntype
, "Can not invite: Unknown channel %s", argv
[0]);
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
))
2163 helpmod_reply(sender
, returntype
, "Can not invite: Unknown channel %s", argv
[0]);
2166 htick
= hticket_get(sender
->real_user
->authname
,hchan
);
2169 helpmod_reply(sender
, returntype
, "Can not invite: You do not have an invite ticket for channel %s", argv
[0]);
2174 helpmod_invite(hchan
, sender
);
2175 helpmod_reply(sender
, returntype
, "Invited you to channel %s", hchannel_get_name(hchan
));
2180 if (argc
> H_CMD_MAX_ARGS
)
2181 argc
= H_CMD_MAX_ARGS
;
2183 for (i
= 0;i
< argc
; i
++)
2185 hchan
= hchannel_get_by_name(argv
[0]);
2188 helpmod_reply(sender
, returntype
, "Can not invite: Unknown channel %s", argv
[i
]);
2191 if (!hchannel_authority(hchan
, sender
))
2193 helpmod_reply(sender
, returntype
, "Sorry, channel %s is oper only", hchannel_get_name(hchan
));
2196 if (huser_on_channel(sender
, hchan
) != NULL
)
2198 helpmod_reply(sender
, returntype
, "Can not invite: You are already on channel %s", hchannel_get_name(hchan
));
2201 helpmod_invite(hchan
, sender
);
2202 helpmod_reply(sender
, returntype
, "Invited you to channel %s", hchannel_get_name(hchan
));
2206 void helpmod_cmd_ticket (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
2208 int expiration
= HTICKET_EXPIRATION_TIME
;
2215 helpmod_reply(sender
, returntype
, "Can not issue a ticket: Channel not specified");
2219 hchan
= hchannel_get_by_name(argv
[0]);
2222 helpmod_reply(sender
, returntype
, "Can not issue a ticket: Unknown channel %s", argv
[0]);
2225 if (!(hchan
->flags
& H_REQUIRE_TICKET
))
2227 helpmod_reply(sender
, returntype
, "Can not issue a ticket: Tickets are not enabled for channel %s", argv
[0]);
2232 helpmod_reply(sender
, returntype
, "Can not issue a ticket: Target user not specified");
2236 husr
= huser_get(getnickbynick(argv
[1]));
2239 helpmod_reply(sender
, returntype
, "Can not issue a ticket: Unknown user %s", argv
[1]);
2242 if (!IsAccount(husr
->real_user
))
2244 helpmod_reply(sender
, returntype
, "Can not issue a ticket: User %s is not authed", argv
[1]);
2247 if (huser_get_level(husr
) < H_PEON
)
2249 helpmod_reply(sender
, returntype
, "Can not issue a ticket: User %s is considered improper and not worthy of a ticket", argv
[1]);
2255 tmp
= helpmod_read_strtime(argv
[2]);
2256 if (tmp
> HDEF_m
&& tmp
< 2 * HDEF_M
)
2260 htick
= hticket_get(husr
->real_user
->authname
, hchan
);
2263 htick
->time_expiration
= time(NULL
) + expiration
;
2265 hticket_add(husr
->real_user
->authname
, time(NULL
) + expiration
, hchan
);
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
));
2271 void helpmod_cmd_resolve (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
2280 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
2282 if (argc
> H_CMD_MAX_ARGS
)
2283 argc
= H_CMD_MAX_ARGS
;
2287 helpmod_reply(sender
, returntype
, "Can not resolve a ticket: The channel is not specified");
2291 for (i
= 0;i
< argc
;i
++)
2293 if (argv
[i
][0] == '#')
2295 htick
= hticket_get(&argv
[i
][1], hchan
);
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
));
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
));
2306 husr
= huser_get(getnickbynick(argv
[i
]));
2309 helpmod_reply(sender
, returntype
, "Can not resolve a ticket: User %s not found", argv
[i
]);
2312 if (!IsAccount(husr
->real_user
))
2314 helpmod_reply(sender
, returntype
, "Can not resolve a ticket: User %s is not authed", argv
[i
]);
2317 htick
= hticket_get(husr
->real_user
->authname
,hchan
);
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
));
2323 hticket_del(htick
, hchan
);
2324 helpmod_reply(sender
, returntype
, "Resolved user %s's ticket for channel %s", argv
[i
], hchannel_get_name(hchan
));
2329 void helpmod_cmd_tickets (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
2337 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
2341 helpmod_reply(sender
, returntype
, "Can not list tickets: Channel not defined or not found");
2345 if (!(hchan
->flags
& H_REQUIRE_TICKET
))
2347 helpmod_reply(sender
, returntype
, "Can not list tickets: Channel %s does not use the ticket system", hchannel_get_name(hchan
));
2351 htick
= hchan
->htickets
;
2355 helpmod_reply(sender
, returntype
, "Channel %s has no valid tickets", hchannel_get_name(hchan
));
2359 helpmod_reply(sender
, returntype
, "Valid tickets for channel %s", hchannel_get_name(hchan
));
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
));
2364 helpmod_reply(sender
, returntype
, "Done listing tickets. Channel %s had %d valid tickets", hchannel_get_name(hchan
), i
);
2367 void helpmod_cmd_showticket (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
2376 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
2378 if (argc
> H_CMD_MAX_ARGS
)
2379 argc
= H_CMD_MAX_ARGS
;
2383 helpmod_reply(sender
, returntype
, "Can not show the ticket: Channel not defined or not found");
2386 for (i
= 0;i
< argc
;i
++)
2388 husr
= huser_get(getnickbynick(argv
[i
]));
2391 helpmod_reply(sender
, returntype
, "Can not show the ticket: User %s not found", argv
[i
]);
2394 if (!IsAccount(husr
->real_user
))
2396 helpmod_reply(sender
, returntype
, "Can not show the ticket: User %s is not authed", argv
[i
]);
2399 htick
= hticket_get(husr
->real_user
->authname
, hchan
);
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
));
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
)));
2410 void helpmod_cmd_load (huser
*sender
, channel
*returntype
, char* arg
, int argc
, char *argv
[])
2413 char buf
[128] = "helpmod/default";
2416 helpmod_reply(sender
, returntype
, "Warning: No config specified, using default");
2419 if (strlen(arg
) >= 100)
2422 sprintf(buf
, "helpmod/%s", arg
);
2425 if (!(tmp_file
= fopen(buf
, "rt")))
2427 helpmod_reply(sender
, returntype
, "File %s not found", buf
);
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");
2442 void helpmod_cmd_status (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
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());
2454 /* not really a command, but help wants this one */
2455 void helpmod_send_help(huser
* target
)
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
)
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");
2469 void helpmod_cmd_command(huser
* sender
, channel
* returntype
, char* arg
, int argc
, char *argv
[])
2472 char buffer
[512], *ptr
= argv
[0];
2477 helpmod_reply(sender
, returntype
, "Usage: command [name of the command] for a list see 'showcommands'");
2481 hcom
= hcommand_get(argv
[0], huser_get_level(sender
));
2485 helpmod_reply(sender
, returntype
, "Unknown command '%s'", argv
[0]);
2491 *ptr
= tolower(*ptr
);
2493 sprintf(buffer
, "./helpmod/commands/%s", argv
[0]);
2495 if ((in
= fopen(buffer
, "rt")) == NULL
)
2497 helpmod_reply(sender
, returntype
, "No help available for command '%s' (Ask strutsi to write it)", argv
[0]);
2503 fgets(buffer
, 512, in
);
2506 helpmod_reply(sender
, returntype
, "%s", buffer
);
2512 void helpmod_cmd_help (huser
* sender
, channel
* returntype
, char* arg
, int argc
, char *argv
[])
2516 if (helpmod_base
== NULL
|| !helpmod_base
->option_count
)
2518 helpmod_reply(sender
, returntype
, "The help service is not available at this time, please try again later");
2524 sender
->state
= helpmod_base
;
2525 helpmod_send_help(sender
);
2529 if (!sscanf(arg
, "%d", &hlp_target
))
2533 tmp
= helpmod_get_alias(arg
);
2535 helpmod_reply(sender
, returntype
, "Invalid value. Either use 'help' to restart or give an integer as a valid selection");
2538 sender
->state
= tmp
;
2539 helpmod_send_help(sender
);
2545 if (!helpmod_valid_selection(sender
->state
, hlp_target
))
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
);
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
);
2556 sender
->state
= helpmod_make_selection(sender
->state
, hlp_target
);
2557 helpmod_send_help(sender
);
2561 /* adds all of the abowe to the system */
2562 void hcommands_add(void)
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");
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");
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");
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");
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");
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");
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");
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");
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");
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");
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");*/
2635 void helpmod_command(huser
*sender
, channel
* returntype
, char *args
)
2637 int argc
= 0, useless_var
;
2638 char args_copy
[512];
2639 char *parsed_args
[H_CMD_MAX_ARGS
+ 3], *ptr
= args_copy
;
2641 /* only accept commands from valid sources */
2642 if (huser_get_level(sender
) < H_PEON
|| huser_get_level(sender
) > H_ADMIN
)
2645 if (returntype
&& !strncmp(args
, helpmodnick
->nick
, strlen(helpmodnick
->nick
)))
2650 args
+=strlen(helpmodnick
->nick
)+1;
2653 if (*args
== '-' || *args
== '?')
2656 strcpy(args_copy
, args
);
2657 /* FIX stringituki */
2660 while (isspace(*ptr
) && *ptr
)
2666 if (*ptr
== '"' && strchr(ptr
+1, '"'))
2667 { /* string support */
2668 parsed_args
[argc
++] = ptr
+1;
2669 ptr
= strchr(ptr
+1, '"');
2673 while (!isspace(*ptr
) && *ptr
)
2681 parsed_args
[argc
++] = ptr
;
2683 while (!isspace(*ptr
) && *ptr
)
2697 /* old H compatibility */
2698 if (sscanf(parsed_args
[0], "%d", &useless_var
) && returntype
== NULL
)
2700 helpmod_cmd_help(sender
, NULL
, parsed_args
[0], 1, NULL
);
2705 char *ostr
= args
, **argv
= (char**)&parsed_args
; // for SKIP_WORD
2706 hcommand
*hcom
= hcommand_get(parsed_args
[0], huser_get_level(sender
));
2709 helpmod_reply(sender
, returntype
, "Unknown command '%s', please see showcommands for a list of all commands available to you", parsed_args
[0]);
2713 hcom
->function(sender
, returntype
, ostr
, argc
, argv
);
2719 #undef DEFINE_HCHANNEL
2720 #undef HCHANNEL_VERIFY_AUTHORITY