13 #include "helpmod_alias.h"
26 /* following are macros for use ONLY IN HERE
27 they may not look pretty, but work surprisingly well */
31 if (*ostr == '"' && strchr(ostr+1, '"'))\
32 ostr = strchr(ostr+1, '"');\
33 while (!isspace(*ostr) && *ostr)\
35 while (isspace(*ostr) && *ostr)\
41 #define DEFINE_HCHANNEL \
44 hchan = hchannel_get_by_channel(returntype);\
45 else if (*argv[0] == '#')\
47 hchan = hchannel_get_by_name(argv[0]);\
51 hchan = hchannel_get_by_channel(returntype);\
54 #define HCHANNEL_VERIFY_AUTHORITY(c, u)\
56 if ((c) != NULL && !hchannel_authority((c), (u)))\
58 helpmod_reply(u, returntype, "Sorry, channel %s is oper only", hchannel_get_name((c)));\
78 static void helpmod_cmd_addchan (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
82 helpmod_reply(sender
, returntype
, "Cannot add channel: Channel not defined");
88 helpmod_reply(sender
, returntype
, "Can not add channel: Channel name must start with '#'");
92 if (hchannel_get_by_name(argv
[0]) != NULL
)
94 helpmod_reply(sender
, returntype
, "Can not add channel: Channel %s already active", argv
[0]);
98 if (hchannel_add(argv
[0]) != NULL
)
100 helpmod_reply(sender
, returntype
, "Channel %s added succesfully", argv
[0]);
105 static void helpmod_cmd_delchan (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
113 helpmod_reply(sender
, returntype
, "Can not delete channel: Channel not defined or not found");
116 strcpy(buffer
, hchan
->real_channel
->index
->name
->content
);
117 if (argc
== 0 || strcmp(argv
[0], "YesImSure"))
119 helpmod_reply(sender
, returntype
, "Can not delete channel: Sanity check. Please add a parameter \"YesImSure\" to confirm channel deletion");
124 helpmod_reply(sender
, returntype
, "Channel %s deleted succesfully", buffer
);
127 static void helpmod_cmd_whoami (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
129 helpmod_reply(sender
, returntype
, "You are %s", huser_get_nick(sender
));
130 helpmod_reply(sender
, returntype
, "Your userlevel is %s", hlevel_name(huser_get_level(sender
)));
131 if (sender
->account
== NULL
)
132 helpmod_reply(sender
, returntype
, "You do not have an account with me");
134 helpmod_reply(sender
, returntype
, "Your accounts name is %s", sender
->account
->name
->content
);
135 if (huser_get_level(sender
) < H_TRIAL
)
137 if (sender
->lc
[0] || sender
->lc
[1] || sender
->lc
[2] || sender
->lc
[3] || sender
->lc
[4])
138 helpmod_reply(sender
, returntype
, "You violated the following rules: Excessive use of capital letters: %d, repeating: %d, improper use of language: %d, flooding: %d and spamming: %d", sender
->lc
[0], sender
->lc
[1], sender
->lc
[2], sender
->lc
[3], sender
->lc
[4]);
140 helpmod_reply(sender
, returntype
, "You have not violated any rules");
145 huser_channel
*huserchan
= sender
->hchannels
;
146 for (;huserchan
;huserchan
= huserchan
->next
)
147 if ((pos
= hqueue_get_position(huserchan
->hchan
, sender
)) > -1)
148 helpmod_reply(sender
, returntype
, "You have queue position #%d on channel %s", pos
, hchannel_get_name(huserchan
->hchan
));
151 if (IsAccount(sender
->real_user
))
155 for (hchan
= hchannels
;hchan
;hchan
= hchan
->next
)
156 if (hchan
->flags
& H_REQUIRE_TICKET
)
158 htick
= hticket_get(huser_get_auth(sender
), hchan
);
160 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
));
165 static void helpmod_cmd_whois (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
172 helpmod_reply(sender
, returntype
, "Cannot get user information: User not specified");
175 if (argc
> H_CMD_MAX_ARGS
)
176 argc
= H_CMD_MAX_ARGS
;
180 husr
= huser_get(getnickbynick(argv
[i
]));
183 if (getnickbynick(argv
[i
]) == NULL
)
184 helpmod_reply(sender
, returntype
, "Cannot get user information: User %s does not exist in the network", argv
[i
]);
186 helpmod_reply(sender
, returntype
, "Cannot get user information: User %s exists but is not known to me", argv
[i
]);
189 helpmod_reply(sender
, returntype
, "User %s has userlevel %s", huser_get_nick(husr
), hlevel_name(huser_get_level(husr
)));
190 if (husr
->account
== NULL
)
191 helpmod_reply(sender
, returntype
, "User %s does not have an account with me", huser_get_nick(husr
));
193 helpmod_reply(sender
, returntype
, "User %s has account named %s", huser_get_nick(husr
),husr
->account
->name
->content
);
194 if (huser_get_level(husr
) < H_TRIAL
)
196 if (husr
->lc
[0] || husr
->lc
[1] || husr
->lc
[2] || husr
->lc
[3] || husr
->lc
[4])
197 helpmod_reply(sender
, returntype
, "User %s has lamercontrol entries: Excessive use of capital letters: %d, repeating: %d, improper use of language: %d, flooding: %d and spamming: %d", huser_get_nick(husr
), husr
->lc
[0], husr
->lc
[1], husr
->lc
[2], husr
->lc
[3], husr
->lc
[4]);
199 helpmod_reply(sender
, returntype
, "User %s has no lamercontrol entries", huser_get_nick(husr
));
203 huser_channel
*huserchan
= husr
->hchannels
;
204 for (;huserchan
;huserchan
= huserchan
->next
)
206 if ((pos
= hqueue_get_position(huserchan
->hchan
, husr
)) > -1)
207 helpmod_reply(sender
, returntype
, "User %s has queue queue position #%d on channel %s", huser_get_nick(husr
), pos
, hchannel_get_name(huserchan
->hchan
));
208 if (on_desk(husr
, huserchan
))
209 helpmod_reply(sender
, returntype
, "User %s is receiving support on channel %s", huser_get_nick(husr
), hchannel_get_name(huserchan
->hchan
));
212 if (IsAccount(husr
->real_user
))
216 for (hchan
= hchannels
;hchan
;hchan
= hchan
->next
)
217 if (hchan
->flags
& H_REQUIRE_TICKET
)
219 htick
= hticket_get(huser_get_auth(husr
), hchan
);
221 helpmod_reply(sender
, returntype
, "User %s has an invite ticket for channel %s that expires in %s", huser_get_nick(husr
), hchannel_get_name(hchan
), helpmod_strtime(time(NULL
) - htick
->time_expiration
));
227 void helpmod_cmd_megod (huser *sender, channel* returntype, char* ostr, int argc, char *argv[])
229 if (sender->account == NULL)
230 sender->account = haccount_add(huser_get_nick(sender), H_ADMIN);
232 sender->account->level = H_ADMIN;
236 static void helpmod_cmd_seen (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
239 haccount
*target_haccount
;
244 helpmod_reply(sender
, returntype
, "No targets specified for seen");
247 for (i
=0;i
< argc
;i
++)
251 if (!ci_strcmp(argv
[i
] + 1, HELPMOD_AUTH
))
252 { /* A nice special case */
253 helpmod_reply(sender
, returntype
, "I'm right here");
256 target_haccount
= haccount_get_by_name(argv
[i
]);
257 if (target_haccount
== NULL
)
259 helpmod_reply(sender
, returntype
, "Account %s not found", argv
[i
] + 1);
263 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
));
267 if (getnickbynick(argv
[i
]) == helpmodnick
)
268 { /* A nice special case */
269 helpmod_reply(sender
, returntype
, "I'm right here");
272 target_huser
= huser_get(getnickbynick(argv
[i
]));
273 if (target_huser
== NULL
)
275 helpmod_reply(sender
, returntype
, "User %s not found", argv
[i
]);
278 helpmod_reply(sender
, returntype
, "User %s's last recorded activity was %s ago", huser_get_nick(target_huser
), helpmod_strtime(time(NULL
) - target_huser
->last_activity
));
283 static void helpmod_cmd_change_userlevel(huser
*sender
, hlevel target_level
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
286 haccount
*target_haccount
;
291 helpmod_reply(sender
, returntype
, "Incorrect syntax: Nick or account required");
295 if (argc
> H_CMD_MAX_ARGS
)
296 argc
= H_CMD_MAX_ARGS
;
298 for (i
= 0;i
< argc
;i
++)
300 if (*argv
[i
] == '#') /* account */
302 target_haccount
= haccount_get_by_name(argv
[i
]);
303 if (target_haccount
== NULL
)
305 helpmod_reply(sender
, returntype
, "Cannot change userlevel: Account '%s' not found", argv
[i
]);
308 if (target_haccount
->level
> huser_get_level(sender
))
310 helpmod_reply(sender
, returntype
, "Cannot change userlevel: Account '%s' has a userlevel higher than yours", argv
[i
]);
314 if (target_haccount
->level
== target_level
)
316 helpmod_reply(sender
, returntype
, "Cannot change userlevel: Account '%s' already has userlevel %s", argv
[i
], hlevel_name(target_level
));
320 target_haccount
->level
= target_level
;
322 helpmod_reply(sender
, returntype
, "Userlevel changed: Account '%s' now has userlevel %s", argv
[i
], hlevel_name(target_level
));
327 target_huser
= huser_get(getnickbynick(argv
[i
]));
328 if (target_huser
== NULL
)
330 helpmod_reply(sender
, returntype
, "Cannot change userlevel: User '%s' not found", argv
[i
]);
333 if (huser_get_level(target_huser
) > huser_get_level(sender
))
335 helpmod_reply(sender
, returntype
, "Cannot change userlevel: User '%s' has a userlevel higher than yours", argv
[i
]);
338 if (huser_get_level(target_huser
) == H_STAFF
&& huser_get_level(sender
) == H_STAFF
)
340 helpmod_reply(sender
, returntype
, "Cannot change userlevel: User '%s' has the same userlevel as you have", argv
[i
]);
344 if (huser_get_level(target_huser
) == target_level
)
346 helpmod_reply(sender
, returntype
, "Cannot change userlevel: User '%s' already has userlevel %s", argv
[i
], hlevel_name(target_level
));
349 if (target_huser
== sender
)
351 helpmod_reply(sender
, returntype
, "Cannot change userlevel: Sanity check, you're changing your own userlevel, use #account instead of nick if you really wish to do this");
355 if (target_level
== H_LAMER
)
357 const char *banmask
= hban_ban_string(target_huser
->real_user
, HBAN_HOST
);
358 hban_add(banmask
, "Improper user", time(NULL
) + HCMD_OUT_DEFAULT
, 1);
359 if (!IsAccount(target_huser
->real_user
))
361 helpmod_reply(sender
, returntype
, "Cannot change userlevel: User '%s' is not authed. Banning user instead.", argv
[i
]);
366 if (!IsAccount(target_huser
->real_user
))
368 helpmod_reply(sender
, returntype
, "Cannot change userlevel: User '%s' is not authed", argv
[i
]);
372 if (target_huser
->account
== NULL
)
374 if (haccount_get_by_name(huser_get_auth(target_huser
)) != NULL
)
376 helpmod_reply(sender
, returntype
, "Cannot change userlevel: Unable to create an account. Account %s already exists", huser_get_auth(target_huser
));
380 target_huser
->account
= haccount_add(huser_get_auth(target_huser
), target_level
);
383 target_huser
->account
->level
= target_level
;
385 helpmod_reply(sender
, returntype
, "Userlevel changed: User '%s' now has userlevel %s", argv
[i
], hlevel_name(target_level
));
387 if (target_level
!= H_LAMER
)
388 helpmod_reply(target_huser
, NULL
, "Your userlevel has been changed, your current userlevel is %s", hlevel_name(target_level
));
393 /* pseudo commands for the above */
394 static void helpmod_cmd_improper (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[]) { helpmod_cmd_change_userlevel(sender
, H_LAMER
, returntype
, ostr
, argc
, argv
); }
395 static void helpmod_cmd_peon (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[]) { helpmod_cmd_change_userlevel(sender
, H_PEON
, returntype
, ostr
, argc
, argv
); }
396 static void helpmod_cmd_friend (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[]) { helpmod_cmd_change_userlevel(sender
, H_FRIEND
, returntype
, ostr
, argc
, argv
); }
397 static void helpmod_cmd_trial (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[]) { helpmod_cmd_change_userlevel(sender
, H_TRIAL
, returntype
, ostr
, argc
, argv
); }
398 static void helpmod_cmd_staff (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[]) { helpmod_cmd_change_userlevel(sender
, H_STAFF
, returntype
, ostr
, argc
, argv
); }
399 static void helpmod_cmd_oper (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[]) { helpmod_cmd_change_userlevel(sender
, H_OPER
, returntype
, ostr
, argc
, argv
); }
400 static void helpmod_cmd_admin (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[]) { helpmod_cmd_change_userlevel(sender
, H_ADMIN
, returntype
, ostr
, argc
, argv
); }
402 static void helpmod_cmd_deluser (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
406 haccount
*target_haccount
;
410 helpmod_reply(sender
, returntype
, "Usage: deluser [nick|#account]");
414 if (argc
> H_CMD_MAX_ARGS
)
415 argc
= H_CMD_MAX_ARGS
;
417 for (i
= 0;i
< argc
;i
++)
421 target_huser
= huser_get(getnickbynick(argv
[i
]));
422 if (target_huser
== NULL
)
424 helpmod_reply(sender
, returntype
, "Cannot delete the account: User %s does not exist", argv
[i
]);
427 if (target_huser
->account
== NULL
)
429 helpmod_reply(sender
, returntype
, "Cannot delete the account: User %s does not have an account", argv
[i
]);
432 target_haccount
= target_huser
->account
;
435 target_haccount
= haccount_get_by_name(argv
[i
]);
437 if (target_haccount
== NULL
)
439 helpmod_reply(sender
, returntype
, "Cannot delete the account: Account %s does not exist", argv
[i
]);
442 if (target_haccount
->level
> huser_get_level(sender
))
444 helpmod_reply(sender
, returntype
, "Cannot delete the account: Account %s has higher userlevel than you", target_haccount
->name
->content
);
447 helpmod_reply(sender
, returntype
, "Account %s deleted", target_haccount
->name
->content
);
448 haccount_del(target_haccount
);
452 static void helpmod_cmd_listuser (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
455 haccount
*hack
= haccounts
;
456 int count
= 0, lvl
= -1;
459 if (argc
> 0 && sscanf(argv
[0], "%d", &lvl
) && lvl
>= H_LAMER
&& lvl
<= H_ADMIN
)
472 helpmod_reply(sender
, returntype
, "%s accounts matching pattern %s: (account name, userlevel, expires in)", hlevel_name(lvl
), pattern
);
474 helpmod_reply(sender
, returntype
, "Accounts matching pattern %s: (account name, userlevel, expires in)", pattern
);
475 for (;hack
;hack
= hack
->next
)
477 if (strregexp(hack
->name
->content
, pattern
))
479 if (lvl
>= 0 && hack
->level
!= lvl
)
481 timer
= hack
->last_activity
+ HELPMOD_ACCOUNT_EXPIRATION
[hack
->level
];
482 helpmod_reply(sender
, returntype
, "%-16s %-32s %s", hack
->name
->content
, hlevel_name(hack
->level
), asctime(localtime(&timer
)));
487 helpmod_reply(sender
, returntype
, "%s accounts matching pattern %d", hlevel_name(lvl
), count
);
489 helpmod_reply(sender
, returntype
, "Accounts matching pattern %d", count
);
492 static void helpmod_cmd_censor (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
500 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
504 helpmod_reply(sender
, returntype
, "Cannot handle the censor: Channel not specified or found");
508 if (argc
< 2 || !ci_strcmp(argv
[0], "list")) /* view */
510 if (hchan
->censor
== NULL
)
511 helpmod_reply(sender
, returntype
, "Nothing is censored on channel %s", hchan
->real_channel
->index
->name
->content
);
514 helpmod_reply(sender
, returntype
, "Censored patterns for channel %s (%s):", hchan
->real_channel
->index
->name
->content
, (hchan
->flags
& H_CENSOR
)?"active":"inactive");
515 for (hcens
= hchan
->censor
;hcens
;hcens
= hcens
->next
)
516 helpmod_reply(sender
, returntype
, "#%-4d %-8s %s%s%s", i
++, hcensor_get_typename(hcens
->type
), hcens
->pattern
->content
, hcens
->reason
?" :: ":"", hcens
->reason
?hcens
->reason
->content
:"");
521 if (!ci_strcmp(argv
[0], "add"))
525 int type
= HCENSOR_KICK
;
529 /* not very elegant but will have to do */
532 if (!ci_strcmp(argv
[0], "warn"))
537 helpmod_reply(sender
, returntype
, "Cannot add censor entry: Entries of type warn require a reason");
542 else if (!ci_strcmp(argv
[0], "kick"))
547 else if (!ci_strcmp(argv
[0], "chanban"))
549 type
= HCENSOR_CHANBAN
;
552 else if (!ci_strcmp(argv
[0], "ban"))
561 if (strlen(pattern
) == 0)
563 helpmod_reply(sender
, returntype
, "Cannot add censor entry: Pattern must be non-empty");
568 if (argc
&& strlen(ostr
) > 0)
573 if (hcensor_get_by_pattern(hchan
->censor
, pattern
))
575 helpmod_reply(sender
, returntype
, "Cannot add censor entry: Pattern '%s' is already censored", pattern
);
579 if (hcensor_add(&hchan
->censor
, pattern
, reason
, type
))
580 helpmod_reply(sender
, returntype
, "Pattern '%s' (%s) with type %s, censored succesfully", pattern
, reason
?reason
:"no reason specified", hcensor_get_typename(type
));
582 helpmod_reply(sender
, returntype
, "Cannot add censor entry: Pattern '%s' is already censored", pattern
);
585 else if (!ci_strcmp(argv
[0], "del"))
591 if (!sscanf(argv
[0], "#%d", &tmp
))
593 helpmod_reply(sender
, returntype
, "Cannot delete censor entry: Bad index, integer expected");
596 hcens
= hcensor_get_by_index(hchan
->censor
, tmp
);
599 hcens
= hcensor_get_by_pattern(hchan
->censor
, argv
[0]);
602 helpmod_reply(sender
, returntype
, "Cannot delete censor entry: Entry not found");
605 hcensor_del(&hchan
->censor
, hcens
);
606 helpmod_reply(sender
, returntype
, "Censor entry deleted succesfully");
610 helpmod_reply(sender
, returntype
, "Unknown censor command %s", argv
[0]);
614 static void helpmod_cmd_chanconf (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
621 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
625 helpmod_reply(sender
, returntype
, "Cannot change or view channel configuration: Channel not specified or found");
629 if (argc
== 0) /* view, spammy but with pretty formatting */
632 helpmod_reply(sender
, returntype
, "Channel configuration for %s:", hchan
->real_channel
->index
->name
->content
);
634 for (i
=0;i
<=HCHANNEL_CONF_COUNT
;i
++)
635 helpmod_reply(sender
, returntype
, "(%02d) %-32s : %s", i
, hchannel_get_sname(i
), hchannel_get_state(hchan
, 1 << i
));
640 old_flags
= hchan
->flags
;
642 if (argc
> H_CMD_MAX_ARGS
)
643 argc
= H_CMD_MAX_ARGS
;
652 else if (*argv
[i
] == '-')
660 if (!sscanf(argv
[i
], "%d", &tmp
) || (tmp
< 0) || (tmp
> HCHANNEL_CONF_COUNT
))
662 helpmod_reply(sender
, returntype
, "Cannot change channel configuration: Expected integer between [0, %d]", HCHANNEL_CONF_COUNT
);
669 hchan
->flags
&= ~(1 << tmp
);
670 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
));
673 helpmod_reply(sender
, returntype
, "(%02d) %-32s : %s", tmp
, hchannel_get_sname(tmp
), hchannel_get_state(hchan
, 1 << tmp
));
676 hchan
->flags
|= (1 << tmp
);
677 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
));
681 hchannel_conf_change(hchan
, old_flags
);
685 static void helpmod_cmd_acconf (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
687 haccount
*hacc
= sender
->account
;
691 helpmod_reply(sender
, returntype
, "Account configuration impossible: You do not have an account");
695 if (argc
== 0) /* view, spammy but with pretty formatting */
698 helpmod_reply(sender
, returntype
, "Account configuration for %s:", hacc
->name
->content
);
700 for (i
=0;i
<=HACCOUNT_CONF_COUNT
;i
++)
701 helpmod_reply(sender
, returntype
, "(%02d) %-35s : %s", i
, haccount_get_sname(i
), haccount_get_state(hacc
, 1 << i
));
707 if (argc
> H_CMD_MAX_ARGS
)
708 argc
= H_CMD_MAX_ARGS
;
717 else if (*argv
[i
] == '-')
725 if (!sscanf(argv
[i
], "%d", &tmp
) || (tmp
< 0) || (tmp
> HACCOUNT_CONF_COUNT
))
727 helpmod_reply(sender
, returntype
, "Cannot change account configuration: Expected integer between [0, %d]", HACCOUNT_CONF_COUNT
);
734 hacc
->flags
&= ~(1 << tmp
);
735 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
));
738 helpmod_reply(sender
, returntype
, "(%02d) %-35s : %s", tmp
, haccount_get_sname(tmp
), haccount_get_state(hacc
, 1 << tmp
));
741 hacc
->flags
|= (1 << tmp
);
742 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
));
749 static void helpmod_cmd_welcome (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
755 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
759 helpmod_reply(sender
, returntype
, "Cannot change or view the welcome message: Channel not specified or found");
763 if (argc
== 0) /* view */
765 helpmod_reply(sender
, returntype
, "Welcome message for channel %s (%s): %s", hchan
->real_channel
->index
->name
->content
, hchannel_get_state(hchan
, H_WELCOME
), hchan
->welcome
);
769 strcpy(hchan
->welcome
, ostr
);
770 helpmod_reply(sender
, returntype
, "Welcome message for channel %s (%s) is now: %s", hchan
->real_channel
->index
->name
->content
, hchannel_get_state(hchan
, H_WELCOME
), hchan
->welcome
);
774 static void helpmod_cmd_aliases (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
778 void helpmod_list_aliases(alias_tree node
)
782 helpmod_reply(sender
, returntype
, "%s", buf
);
787 sprintf(buf
+i
,"%.200s ",node
->name
->content
);
788 i
+=(1+strlen(node
->name
->content
));
789 helpmod_list_aliases(node
->left
);
790 helpmod_list_aliases(node
->right
);
792 helpmod_list_aliases(aliases
);
794 helpmod_reply(sender
, returntype
, "%s", buf
);
797 static void helpmod_cmd_showcommands (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
799 int level
= H_PEON
, previous_level
= H_PEON
;
802 if (!(argc
&& (sscanf(argv
[0], "%d", &level
)) && (level
>= 0) && (level
<= huser_get_level(sender
))))
803 level
= huser_get_level(sender
);
805 helpmod_reply(sender
, returntype
, "HelpMod %s commands for userlevel %s:", HELPMOD_VERSION
, hlevel_name(level
));
807 hcommand_list(H_NONE
);
809 while ((tmp
= hcommand_list(level
)) != NULL
)
811 if (tmp
->level
> previous_level
)
813 helpmod_reply(sender
, returntype
, "--- Additional commands for userlevel %s ---", hlevel_name(tmp
->level
));
814 previous_level
= tmp
->level
;
816 helpmod_reply(sender
, returntype
, "%-16s %s", tmp
->name
->content
, tmp
->help
->content
);
822 static void helpmod_cmd_lamercontrol (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
829 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
831 if (hchan
== NULL
) /* list profiles */
833 helpmod_reply(sender
, returntype
, "Following lamercontrol profiles are available:");
834 for (ptr
= hlc_profiles
;ptr
;ptr
= ptr
->next
)
835 helpmod_reply(sender
, returntype
, "%s", ptr
->name
->content
);
840 if (hchan
->lc_profile
== NULL
)
841 helpmod_reply(sender
, returntype
, "Channel %s has no lamercontrol profile set", hchannel_get_name(hchan
));
843 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
));
846 if (!ci_strcmp(argv
[0], "list"))
848 helpmod_reply(sender
, returntype
, "Following lamercontrol profiles are available:");
849 for (ptr
= hlc_profiles
;ptr
;ptr
= ptr
->next
)
850 helpmod_reply(sender
, returntype
, "%s", ptr
->name
->content
);
853 ptr
= hlc_get(argv
[0]);
856 helpmod_reply(sender
, returntype
, "Cannot set the lamercontrol profile: Profile %s does not exist:", argv
[0]);
861 hchan
->lc_profile
= ptr
;
862 helpmod_reply(sender
, returntype
, "Lamercontrol profile %s set to channel %s succesfully",ptr
->name
->content
,hchannel_get_name(hchan
));
867 static void helpmod_cmd_term_find_general (huser
*sender
, channel
* returntype
, int type
, char* ostr
, int argc
, char *argv
[])
880 source
= hchan
->channel_hterms
;
884 if (type
== H_TERM_PLUS
)
885 hqueue_advance(hchan
, sender
, 1);
887 helpmod_reply(sender
, returntype
, "Cannot find term: Term not specified");
890 htrm
= hterm_get_and_find(source
, argv
[0]);
893 helpmod_reply(sender
, returntype
, "No term found matching '%s'", argv
[0]);
896 if (returntype
!= NULL
&& huser_get_level(sender
) >= H_TRIAL
)
898 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
903 if (argc
> H_CMD_MAX_ARGS
)
904 argc
= H_CMD_MAX_ARGS
;
907 targets
[ntargets
] = huser_get(getnickbynick(argv
[i
]));
908 if (targets
[ntargets
] == NULL
)
910 helpmod_reply(sender
, returntype
, "Error using ?: User %s not found", argv
[i
]);
919 helpmod_message_channel_long(hchannel_get_by_channel(returntype
), "(%s): %s", htrm
->name
->content
, htrm
->description
->content
);
922 char buffer
[256] = "";
923 for (i
=0;i
<ntargets
;i
++)
927 strcat(buffer
, huser_get_nick(targets
[i
]));
930 helpmod_message_channel_long(hchannel_get_by_channel(returntype
), "%s: (%s) %s", buffer
, htrm
->name
->content
, htrm
->description
->content
);
931 if (type
!= H_TERM_FIND
)
933 if (hchan
->flags
& H_QUEUE
)
935 for (i
=0;i
<ntargets
;i
++)
937 huser_channel
*huserchan
= huser_on_channel(targets
[i
], hchan
);
938 huserchan
->flags
|= HQUEUE_DONE
;
939 if (huserchan
->flags
& HCUMODE_VOICE
)
940 helpmod_channick_modes(targets
[i
], hchan
, MC_DEVOICE
, HLAZY
);
942 if (type
== H_TERM_PLUS
)
943 hqueue_advance(hchan
, sender
, ntargets
);
949 helpmod_reply(sender
, returntype
, "(%s): %s", htrm
->name
->content
, htrm
->description
->content
);
952 static void helpmod_cmd_term_find (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
954 helpmod_cmd_term_find_general(sender
, returntype
, H_TERM_FIND
, ostr
, argc
, argv
);
957 static void helpmod_cmd_term_find_minus (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
959 helpmod_cmd_term_find_general(sender
, returntype
, H_TERM_MINUS
, ostr
, argc
, argv
);
962 static void helpmod_cmd_term_find_plus (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
964 helpmod_cmd_term_find_general(sender
, returntype
, H_TERM_PLUS
, ostr
, argc
, argv
);
967 static void helpmod_cmd_klingon (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
970 huser
*target
= NULL
;
977 rand_val
= rand() % KLINGON_NTARGETED
;
978 helpmod_reply(sender
, NULL
, "%s: %s", huser_get_nick(sender
), klingon_targeted
[rand_val
]);
983 target
= huser_get(getnickbynick(argv
[0]));
987 rand_val
= rand() % KLINGON_NTARGETED
;
988 helpmod_message_channel(hchan
, "%s: %s", huser_get_nick(target
), klingon_targeted
[rand_val
]);
992 rand_val
= rand() % KLINGON_NGENERAL
;
993 helpmod_message_channel(hchan
, "%s", klingon_general
[rand_val
]);
997 void helpmod_cmd_term (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
1005 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
1010 source
= &hchan
->channel_hterms
;
1014 helpmod_reply(sender
, returntype
, "Cannot handle terms: Operation not specified");
1017 if (!ci_strcmp(argv
[0], "list"))
1021 char *pattern
= "*";
1031 helpmod_reply(sender
, returntype
, "Terms matching pattern '%s'", pattern
);
1032 for (;htrm
;htrm
= htrm
->next
)
1034 if (strlen(buffer
) >= 250)
1036 helpmod_reply(sender
, returntype
, "%s", buffer
);
1039 if (strregexp(htrm
->description
->content
, pattern
) || strregexp(htrm
->name
->content
, pattern
))
1041 sprintf(buffer
+strlen(buffer
) /* :) */, "%s(%u) ", htrm
->name
->content
, (unsigned int)strlen(htrm
->description
->content
));
1046 helpmod_reply(sender
, returntype
, "%s", buffer
);
1047 helpmod_reply(sender
, returntype
, "%d term%s match%s pattern '%s'", count
, (count
== 1)?"":"s", (count
== 1)?"es":"", pattern
);
1049 else if (!ci_strcmp(argv
[0], "listfull"))
1052 helpmod_reply(sender
, returntype
, "Following terms have been entered:");
1053 for (;htrm
;htrm
= htrm
->next
)
1054 helpmod_reply(sender
, returntype
, "(%s): %s", htrm
->name
->content
, htrm
->description
->content
);
1056 else if (!ci_strcmp(argv
[0], "get"))
1060 helpmod_reply(sender
, returntype
, "Cannot get term: Term not specified");
1063 htrm
= hterm_get(*source
, argv
[1]);
1065 helpmod_reply(sender
, returntype
, "Cannot get term: Term %s not found", argv
[1]);
1067 helpmod_reply(sender
, returntype
, "(%s): %s", htrm
->name
->content
, htrm
->description
->content
);
1069 else if (!ci_strcmp(argv
[0], "add"))
1072 helpmod_reply(sender
, returntype
, "Cannot add term: Term name not specified");
1074 helpmod_reply(sender
, returntype
, "Cannot add term: Term description not specified");
1075 else if ((htrm
= hterm_get(*source
, argv
[1])) != NULL
)
1076 helpmod_reply(sender
, returntype
, "Cannot add term: Term %s is already added", argv
[1]);
1079 char *name
= argv
[1], *description
;
1080 SKIP_WORD
; SKIP_WORD
;
1082 htrm
= hterm_add(source
, name
, description
);
1083 helpmod_reply(sender
, returntype
, "Term %s added succesfully", name
);
1086 else if (!ci_strcmp(argv
[0], "del"))
1091 helpmod_reply(sender
, returntype
, "Cannot delete term: Term name not specified");
1094 if (argc
> H_CMD_MAX_ARGS
)
1095 argc
= H_CMD_MAX_ARGS
;
1096 for (i
=1;i
<argc
;i
++)
1098 htrm
= hterm_get(*source
, argv
[i
]);
1101 helpmod_reply(sender
, returntype
, "Cannot delete term: Term %s not found", argv
[i
]);
1104 hterm_del(source
!= NULL
?source
:&hterms
, htrm
);
1105 helpmod_reply(sender
, returntype
, "Term %s deleted succesfully", argv
[i
]);
1108 else if (!ci_strcmp(argv
[0], "find"))
1112 helpmod_reply(sender
, returntype
, "Cannot find term: Term name not specified");
1115 htrm
= hterm_get_and_find(*source
, argv
[1]);
1119 helpmod_reply(sender
, returntype
, "No term found matching '%s'", argv
[1]);
1122 if (returntype
!= NULL
&& huser_get_level(sender
) >= H_TRIAL
)
1123 helpmod_message_channel(hchannel_get_by_channel(returntype
), "(%s): %s", htrm
->name
->content
, htrm
->description
->content
);
1125 helpmod_reply(sender
, returntype
, "(%s): %s", htrm
->name
->content
, htrm
->description
->content
);
1129 helpmod_reply(sender
, returntype
, "Cannot handle terms: Operation not specified");
1133 static void helpmod_cmd_queue (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
1140 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
1144 helpmod_reply(sender
, returntype
, "Cannot handle queue: Operation not specified");
1148 if (!ci_strcmp(argv
[0], "done"))
1149 operation
= HQ_DONE
;
1150 else if (!ci_strcmp(argv
[0], "next"))
1151 operation
= HQ_NEXT
;
1152 else if (!ci_strcmp(argv
[0], "on"))
1154 else if (!ci_strcmp(argv
[0], "off"))
1156 else if (!ci_strcmp(argv
[0], "maintain"))
1157 operation
= HQ_MAINTAIN
;
1158 else if (!ci_strcmp(argv
[0], "list"))
1159 operation
= HQ_LIST
;
1160 else if (!ci_strcmp(argv
[0], "summary"))
1161 operation
= HQ_SUMMARY
;
1162 else if (!ci_strcmp(argv
[0], "reset"))
1163 operation
= HQ_RESET
;
1165 operation
= HQ_NONE
;
1169 helpmod_queue_handler(sender
, returntype
, hchan
, operation
, ostr
, argc
, argv
);
1172 static void helpmod_cmd_done (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
1176 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
1177 helpmod_queue_handler(sender
, returntype
, hchan
, HQ_DONE
, ostr
, argc
, argv
);
1180 static void helpmod_cmd_next (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
1184 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
1185 helpmod_queue_handler(sender
, returntype
, hchan
, HQ_NEXT
, ostr
, argc
, argv
);
1188 static void helpmod_cmd_enqueue (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
1192 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
1193 helpmod_queue_handler(sender
, returntype
, hchan
, HQ_ON
, ostr
, argc
, argv
);
1196 static void helpmod_cmd_dequeue (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
1200 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
1201 helpmod_queue_handler(sender
, returntype
, hchan
, HQ_OFF
, ostr
, argc
, argv
);
1204 static void helpmod_cmd_autoqueue (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
1208 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
1209 helpmod_queue_handler(sender
, returntype
, hchan
, HQ_MAINTAIN
, ostr
, argc
, argv
);
1212 static void helpmod_cmd_dnmo (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
1217 helpmod_reply(sender
, returntype
, "Cannot correct the luser: User not defined");
1220 if (argc
> H_CMD_MAX_ARGS
)
1221 argc
= H_CMD_MAX_ARGS
;
1222 for (i
=0;i
<argc
;i
++)
1224 huser
*husr
= huser_get(getnickbynick(argv
[i
]));
1227 helpmod_reply(sender
, returntype
, "Cannot correct the luser: User %s not found", argv
[i
]);
1230 if (huser_get_level(husr
) > H_PEON
)
1232 helpmod_reply(sender
, returntype
, "Cannot correct the luser: User %s is not a peon", argv
[i
]);
1236 if (!hchannels_on_queue(husr) && !hchannels_on_desk(husr))
1238 helpmod_reply(sender, returntype, "Cannot correct the luser: User %s is not in any queue", argv[i]);
1242 hchannels_dnmo(husr
);
1244 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");
1245 helpmod_reply(sender
, returntype
, "User %s has been informed of his mistake", argv
[i
]);
1247 { /* fix the autoqueue for the channel(s) */
1249 for (hchan
= hchannels
;hchan
;hchan
= hchan
->next
)
1250 hqueue_handle_queue(hchan
, sender
);
1254 static void helpmod_cmd_ban (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
1256 if (argc
== 0 || !ci_strcmp(argv
[0], "list"))
1267 helpmod_reply(sender
, returntype
, "Global bans matching pattern %s", pattern
);
1269 for (;ptr
;ptr
= ptr
->next
)
1270 if (strregexp(bantostring(ptr
->real_ban
), pattern
))
1272 helpmod_reply(sender
, returntype
, "%-64s %-20s %s", bantostring(ptr
->real_ban
), helpmod_strtime(ptr
->expiration
- time(NULL
)), ptr
->reason
?ptr
->reason
->content
:"");
1276 helpmod_reply(sender
, returntype
, "%d Global bans match pattern %s", count
, pattern
);
1278 else if (!ci_strcmp(argv
[0], "add"))
1280 int duration
= 4 * HDEF_h
;
1281 char *reason
= "Banned";
1282 char *target
= argv
[1];
1286 helpmod_reply(sender
, returntype
, "Cannot add global ban: Target hostmask not defined");
1291 if ((duration
= helpmod_read_strtime(argv
[2])) < 0)
1293 helpmod_reply(sender
, returntype
, "Cannot add global ban: Invalid time %s", argv
[2]);
1305 hban_add(target
, reason
, time(NULL
) + duration
, 0);
1306 helpmod_reply(sender
, returntype
, "Added ban for %s (%s), expires in %s", target
, reason
, helpmod_strtime(duration
));
1308 else if (!ci_strcmp(argv
[0], "del"))
1313 helpmod_reply(sender
, returntype
, "Cannot remove global ban: Target hostmask not defined");
1316 if (argc
> H_CMD_MAX_ARGS
)
1317 argc
= H_CMD_MAX_ARGS
;
1318 for (i
=1;i
<argc
;i
++)
1320 hban
*ptr
= hban_get(argv
[i
]);
1323 helpmod_reply(sender
, returntype
, "Cannot remove global ban: Hostmask %s is not banned", argv
[i
]);
1326 helpmod_reply(sender
, returntype
, "Global ban for hostmask %s removed", argv
[i
]);
1332 helpmod_reply(sender
, returntype
, "Cannot handle global bans: Unknown operation %s", argv
[0]);
1337 static void helpmod_cmd_chanban (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
1346 helpmod_reply(sender
, returntype
, "Cannot handle channel bans: Channel not defined or not found");
1350 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
1354 helpmod_reply(sender, returntype, "Cannot handle channel bans: Operation not defined");
1358 if (argc
== 0 || !ci_strcmp(argv
[0], "list"))
1360 char *pattern
, *cban
;
1361 chanban
*ptr
= hchan
->real_channel
->bans
;
1369 helpmod_reply(sender
, returntype
, "Bans matching pattern %s for channel %s", pattern
, hchannel_get_name(hchan
));
1370 for (;ptr
;ptr
= ptr
->next
)
1371 if (strregexp((cban
= bantostring(ptr
)), pattern
))
1374 if (hchanban_get(hchan
,cban
) != NULL
)
1375 helpmod_reply(sender
, returntype
, "%s Expires in %s", bantostring(ptr
), helpmod_strtime(hchanban_get(hchan
, cban
)->expiration
- time(NULL
)));
1377 helpmod_reply(sender
, returntype
, "%s", bantostring(ptr
));
1379 helpmod_reply(sender
, returntype
, "%d bans match pattern %s on channel %s", count
, pattern
, hchannel_get_name(hchan
));
1381 else if (!ci_strcmp(argv
[0], "add"))
1385 helpmod_reply(sender
, returntype
, "Cannot add channel bans: Pattern not defined");
1388 if (argc
> H_CMD_MAX_ARGS
)
1389 argc
= H_CMD_MAX_ARGS
;
1390 for (i
=1;i
<argc
;i
++)
1392 /* POSSIBLE BUG ? */
1393 helpmod_setban(hchan
, argv
[i
], H_ETERNITY
, MCB_ADD
, HLAZY
);
1394 helpmod_reply(sender
, returntype
, "Added ban %s to channel %s", argv
[i
], hchannel_get_name(hchan
));
1397 else if (!ci_strcmp(argv
[0], "del"))
1401 helpmod_reply(sender
, returntype
, "Cannot remove channel bans: Pattern not defined");
1404 if (argc
> H_CMD_MAX_ARGS
)
1405 argc
= H_CMD_MAX_ARGS
;
1406 for (i
=1;i
<argc
;i
++)
1408 chanban
*ptr
= hchan
->real_channel
->bans
;
1409 for (;ptr
;ptr
= ptr
->next
)
1410 if (strregexp(bantostring(ptr
), argv
[i
]))
1412 helpmod_setban(hchan
, argv
[i
], 0, MCB_DEL
, HLAZY
);
1413 helpmod_reply(sender
, returntype
, "Channel ban %s removed from channel %s", argv
[i
], hchannel_get_name(hchan
));
1417 helpmod_reply(sender
, returntype
, "Cannot remove channel ban: Pattern %s not banned on channel %s", argv
[i
], hchannel_get_name(hchan
));
1422 helpmod_reply(sender
, returntype
, "Cannot handle channel bans: Unknown operation %s", argv
[0]);
1427 static void helpmod_cmd_idlekick (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
1434 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
1438 helpmod_reply(sender
, returntype
, "Cannot handle the idlekick: Channel not defined or not found");
1441 if (argc
== 0) /* view */
1443 helpmod_reply(sender
, returntype
, "Idlekick for channel %s is set to %s", hchannel_get_name(hchan
), helpmod_strtime(hchan
->max_idle
));
1446 else if ((tmp
= helpmod_read_strtime(argv
[0])) < 0 || tmp
< HDEF_m
|| tmp
> HDEF_w
)
1448 helpmod_reply(sender
, returntype
, "Cannot set the idlekick: Invalid time given '%s'", argv
[0]);
1453 hchan
->max_idle
= tmp
;
1454 helpmod_reply(sender
, returntype
, "Idlekick for channel %s set to %s succesfully", hchannel_get_name(hchan
), helpmod_strtime(hchan
->max_idle
));
1458 static void helpmod_cmd_topic (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
1463 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
1467 helpmod_reply(sender
, returntype
, "Cannot handle the topic: Channel not defined or not found");
1470 if (!(hchan
-> flags
& H_HANDLE_TOPIC
))
1471 helpmod_reply(sender
, returntype
, "Note: I'm not set to handle the topic on channel %s", hchannel_get_name(hchan
));
1473 if (argc
== 0) /* check the topic */
1475 helpmod_reply(sender
, returntype
, "Topic of channel %s is currently: %s", hchannel_get_name(hchan
), htopic_construct(hchan
->topic
));
1478 if (!ci_strcmp(argv
[0], "erase"))
1480 htopic_del_all(&hchan
->topic
);
1481 hchannel_set_topic(hchan
);
1482 helpmod_reply(sender
, returntype
, "Topic of channel %s erased", hchannel_get_name(hchan
));
1484 else if (!ci_strcmp(argv
[0], "refresh"))
1486 hchannel_set_topic(hchan
);
1487 helpmod_reply(sender
, returntype
, "Topic of channel %s refreshed", hchannel_get_name(hchan
));
1489 else if (!ci_strcmp(argv
[0], "add"))
1495 helpmod_reply(sender
, returntype
, "Cannot handle the topic of channel %s: Additional arguments required", hchannel_get_name(hchan
));
1498 if (sscanf(argv
[0], "%d", &pos
) && pos
>= 0)
1504 if (argc
== 0) /* lame repeat :( */
1506 helpmod_reply(sender
, returntype
, "Cannot handle the topic of channel %s: Additional arguments required", hchannel_get_name(hchan
));
1509 if (htopic_len(hchan
->topic
) + strlen(ostr
) + 3 > TOPICLEN
)
1511 helpmod_reply(sender
, returntype
, "Cannot add to the topic of channel %s: Maximum topic length exceeded", hchannel_get_name(hchan
));
1515 htopic_add(&hchan
->topic
, ostr
, pos
);
1516 hchannel_set_topic(hchan
);
1517 helpmod_reply(sender
, returntype
, "Added '%s' to the topic of channel %s", ostr
, hchannel_get_name(hchan
));
1519 else if (!ci_strcmp(argv
[0], "del"))
1524 helpmod_reply(sender
, returntype
, "Cannot handle the topic of channel %s: Additional arguments required", hchannel_get_name(hchan
));
1528 if (!sscanf(argv
[0], "%d", &pos
) || pos
< 0)
1530 helpmod_reply(sender
, returntype
, "Cannot handle the topic of channel %s: Expected positive integer", hchannel_get_name(hchan
));
1533 if (htopic_count(hchan
->topic
) < pos
)
1535 helpmod_reply(sender
, returntype
, "Cannot delete from the topic of channel %s: No such topic element %d", hchannel_get_name(hchan
), pos
);
1538 htopic_del(&hchan
->topic
, htopic_get(hchan
->topic
, pos
));
1539 hchannel_set_topic(hchan
);
1541 else if (!ci_strcmp(argv
[0], "set"))
1545 helpmod_reply(sender
, returntype
, "Cannot handle the topic of channel %s: Additional arguments required", hchannel_get_name(hchan
));
1549 htopic_del_all(&hchan
->topic
);
1550 htopic_add(&hchan
->topic
, ostr
, 0);
1551 hchannel_set_topic(hchan
);
1554 helpmod_reply(sender
, returntype
, "Cannot handle the topic of channel %s: Unknown operation %s", hchannel_get_name(hchan
), argv
[0]);
1557 static void helpmod_cmd_out (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
1561 char *reason
= "Banned";
1562 huser
*targets
[H_CMD_MAX_ARGS
];
1567 helpmod_reply(sender
, returntype
, "Cannot get rid of the user: User not specified");
1571 if (argc
> H_CMD_MAX_ARGS
)
1572 argc
= H_CMD_MAX_ARGS
;
1573 for (i
=0;i
<argc
;i
++)
1575 if (argv
[i
][0] == ':')
1579 helpmod_reply(sender
, returntype
, "Cannot get rid of users: No users specified");
1588 if (!strncmp(reason
, "?? ", 3))
1589 { /* obtain reason from hterms */
1590 hchannel
*hchan
= NULL
;
1592 if (returntype
!= NULL
)
1593 { /* if hchan is NULL here then everything is broken already */
1594 hchan
= hchannel_get_by_channel(returntype
);
1595 new_reason
= hterm_get_and_find(hchan
->channel_hterms
, reason
+ 3);
1598 new_reason
= hterm_get_and_find(hterms
, reason
+ 3);
1600 if (new_reason
!= NULL
)
1601 reason
= new_reason
->description
->content
;
1606 husr
= huser_get(getnickbynick(argv
[i
]));
1609 helpmod_reply(sender
, returntype
, "Cannot get rid of the user: User %s not found", argv
[i
]);
1612 if (huser_get_level(husr
) > H_PEON
)
1614 helpmod_reply(sender
, returntype
, "Cannot get rid of the user: User %s is not a peon", huser_get_nick(husr
));
1617 targets
[ntargets
++] = husr
;
1620 for (i
=0;i
<ntargets
;i
++)
1622 const char *banmask
= hban_ban_string(targets
[i
]->real_user
, HBAN_HOST
);
1624 hban_add(banmask
, reason
, time(NULL
) + HCMD_OUT_DEFAULT
, HLAZY
);
1626 helpmod_reply(sender
, returntype
, "User %s is now gone", huser_get_nick(targets
[i
]));
1631 static void helpmod_cmd_everyoneout (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
1634 hchannel_user
**hchanuser
;
1635 char *reason
= "clearing channel";
1636 int autoqueue_tmp
= -1;
1639 HELPMOD_KICKMODE_ALL
,
1640 HELPMOD_KICKMODE_UNAUTHED
1641 } kickmode
= HELPMOD_KICKMODE_ALL
;
1645 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
1649 helpmod_reply(sender
, returntype
, "Cannot clear channel: Channel not defined or not found");
1655 if (!ci_strcmp(argv
[0], "all"))
1657 kickmode
= HELPMOD_KICKMODE_ALL
;
1660 else if (!ci_strcmp(argv
[0], "unauthed"))
1662 kickmode
= HELPMOD_KICKMODE_UNAUTHED
;
1670 hchan
->flags
|= H_MAINTAIN_I
;
1671 hchannel_mode_check(hchan
);
1673 hchanuser
= &hchan
->channel_users
;
1675 if ((hchan
->flags
& H_QUEUE
) && (hchan
->flags
& H_QUEUE_MAINTAIN
))
1677 autoqueue_tmp
= hchan
->autoqueue
;
1678 hchan
->autoqueue
= 0;
1683 if (huser_get_level((*hchanuser
)->husr
) < H_TRIAL
)
1684 if (kickmode
== HELPMOD_KICKMODE_ALL
|| (kickmode
== HELPMOD_KICKMODE_UNAUTHED
&& !IsAccount((*hchanuser
)->husr
->real_user
)))
1686 helpmod_kick(hchan
, (*hchanuser
)->husr
, reason
);
1689 hchanuser
= &(*hchanuser
)->next
;
1692 if (autoqueue_tmp
> 0)
1693 hchan
->autoqueue
= autoqueue_tmp
;
1695 helpmod_reply(sender
, returntype
, "Channel %s has been cleared of normal users", hchannel_get_name(hchan
));
1698 static void helpmod_cmd_kick (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
1702 huser
*husr
, *targets
[H_CMD_MAX_ARGS
];
1704 char *reason
= "out";
1707 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
1711 helpmod_reply(sender
, returntype
, "Cannot kick the user: Channel not defined or not found");
1717 helpmod_reply(sender
, returntype
, "Cannot kick users: No users specified");
1721 if (argc
> H_CMD_MAX_ARGS
)
1722 argc
= H_CMD_MAX_ARGS
;
1723 for (i
=0;i
<argc
;i
++)
1725 if (*argv
[i
] == ':')
1729 helpmod_reply(sender
, returntype
, "Cannot kick the user: No users defined");
1739 husr
= huser_get(getnickbynick(argv
[i
]));
1742 helpmod_reply(sender
, returntype
, "Cannot kick the user: User %s not found", argv
[i
]);
1745 if (huser_on_channel(husr
, hchan
) == NULL
)
1747 helpmod_reply(sender
, returntype
, "Cannot kick the user: User %s is not on channel %s", huser_get_nick(husr
), hchannel_get_name(hchan
));
1750 if (huser_get_level(husr
) > H_PEON
)
1752 helpmod_reply(sender
, returntype
, "Cannot kick the user: User %s is not a peon", huser_get_nick(husr
));
1755 targets
[ntargets
++] = husr
;
1758 for (i
=0;i
<ntargets
;i
++)
1759 helpmod_kick(hchan
, targets
[i
], reason
);
1762 static void helpmod_cmd_stats (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
1765 haccount
*target
= sender
->account
;
1767 hstat_account_entry
*stat_entry
;
1768 int days
= 1, weeks
= 0;
1769 int type
= HSTAT_ACCOUNT_SHORT
;
1771 time_t timer
= time(NULL
);
1772 struct tm
*tstruct
= localtime(&timer
);
1778 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
1782 helpmod_reply(sender
, returntype
, "Cannot show user statistics: Channel not defined or not found");
1786 if (argc
> 0 && huser_get_level(sender
) == H_ADMIN
)
1787 { /* not very elegant */
1788 if (argv
[0][0] == '#') /* account */
1790 target
= haccount_get_by_name(argv
[0]+1);
1793 helpmod_reply(sender
, returntype
, "Cannot show user statistics: Account %s not found", argv
[0]);
1802 helpmod_reply(sender
, returntype
, "Cannot show user statistics: You do not have an account");
1808 if (!ci_strcmp(argv
[0], "short") || !ci_strcmp(argv
[0], "s"))
1810 type
= HSTAT_ACCOUNT_SHORT
;
1813 else if (!ci_strcmp(argv
[0], "long") || !ci_strcmp(argv
[0], "l"))
1815 type
= HSTAT_ACCOUNT_LONG
;
1821 if (sscanf(argv
[0], "%d", &days
))
1823 if (days
< 0 || days
> 7)
1825 helpmod_reply(sender
, returntype
, "Cannot show user statistics: Expected integer between [0, 7]");
1835 if (sscanf(argv
[0], "%d", &weeks
))
1837 if (weeks
< 0 || weeks
> 10)
1839 helpmod_reply(sender
, returntype
, "Cannot show user statistics: Expected integer between [0, 10]");
1848 for (ptr
= target
->stats
;ptr
;ptr
= ptr
->next
)
1849 if (ptr
->hchan
== hchan
)
1854 helpmod_reply(sender
, returntype
, "Cannot show user statistics: User %s has no statistics for channel %s", target
->name
->content
, hchannel_get_name(hchan
));
1858 if (!days
&& !weeks
)
1861 helpmod_reply(sender
, returntype
, "Statistics for user %s on channel %s", target
->name
->content
, hchannel_get_name(hchan
));
1865 helpmod_reply(sender
, returntype
, "Last %d day%s", days
, (days
==1)?"":"s");
1866 helpmod_reply(sender
, returntype
, "%s", hstat_header(type
));
1867 for (i
=0;i
<days
;i
++)
1869 stat_entry
= &ptr
->week
[(tstruct
->tm_wday
- i
+ 7) % 7];
1870 helpmod_reply(sender
, returntype
, "%s", hstat_account_print(stat_entry
, type
));
1876 helpmod_reply(sender
, returntype
, "Last %d week%s", weeks
, (weeks
==1)?"":"s");
1877 helpmod_reply(sender
, returntype
, "%s", hstat_header(type
));
1878 for (i
=0;i
<weeks
;i
++)
1880 stat_entry
= &ptr
->longterm
[(hstat_week() - i
+ 10) % 10];
1881 helpmod_reply(sender
, returntype
, "%s", hstat_account_print(stat_entry
, type
));
1886 static void helpmod_cmd_chanstats (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
1889 hstat_channel
*channel_stats
;
1890 hstat_channel_entry
*stat_entry
;
1892 time_t timer
= time(NULL
);
1893 struct tm
*tstruct
= localtime(&timer
);
1896 int type
= HSTAT_CHANNEL_SHORT
;
1903 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
1907 helpmod_reply(sender
, returntype
, "Cannot show channel statistics: Channel not defined or not found");
1913 if (!ci_strcmp(argv
[0], "short") || !ci_strcmp(argv
[0], "s"))
1915 type
= HSTAT_CHANNEL_SHORT
;
1918 else if (!ci_strcmp(argv
[0], "long") || !ci_strcmp(argv
[0], "l"))
1920 type
= HSTAT_CHANNEL_LONG
;
1926 if (sscanf(argv
[0], "%d", &days
))
1928 if (days
< 0 || days
> 7)
1930 helpmod_reply(sender
, returntype
, "Cannot show channel statistics: Expected integer between [0, 7]");
1940 if (sscanf(argv
[0], "%d", &weeks
))
1942 if (weeks
< 0 || weeks
> 10)
1944 helpmod_reply(sender
, returntype
, "Cannot show channel statistics: Expected integer between [0, 10]");
1953 channel_stats
= hchan
->stats
;
1955 if (!days
&& !weeks
)
1958 helpmod_reply(sender
, returntype
, "Statistics for channel %s", hchannel_get_name(hchan
));
1962 helpmod_reply(sender
, returntype
, "Last %d day%s", days
, (days
==1)?"":"s");
1963 helpmod_reply(sender
, returntype
, "%s", hstat_header(type
));
1964 for (i
=0;i
<days
;i
++) /* latest week */
1966 stat_entry
= &hchan
->stats
->week
[(tstruct
->tm_wday
- i
+ 7) % 7];
1967 helpmod_reply(sender
, returntype
, "%s", hstat_channel_print(stat_entry
, type
));
1973 helpmod_reply(sender
, returntype
, "Last %d week%s", weeks
, (weeks
==1)?"":"s");
1974 helpmod_reply(sender
, returntype
, "%s", hstat_header(type
));
1975 for (i
=0;i
<weeks
;i
++) /* latest weeks */
1977 stat_entry
= &hchan
->stats
->longterm
[(hstat_week() - i
+ 10) % 10];
1978 helpmod_reply(sender
, returntype
, "%s", hstat_channel_print(stat_entry
, type
));
1983 static void helpmod_cmd_activestaff (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
1986 hstat_accounts_array arr
;
1987 hlevel lvl
= H_OPER
;
1995 helpmod_reply(sender
, returntype
, "Cannot list active staff: Channel not specified or not found");
2001 if (!ci_strcmp(argv
[0], "opers") || !ci_strcmp(argv
[0], "o"))
2006 else if (!ci_strcmp(argv
[0], "staff") || !ci_strcmp(argv
[0], "s"))
2011 else if (!ci_strcmp(argv
[0], "staff") || !ci_strcmp(argv
[0], "s"))
2020 if (!ci_strcmp(argv
[0], "active") || !ci_strcmp(argv
[0], "a"))
2025 else if (!ci_strcmp(argv
[0], "inactive") || !ci_strcmp(argv
[0], "i"))
2032 arr
= create_hstat_account_array(hchan
, lvl
, HSTAT_ACCOUNT_ARRAY_TOP10
);
2034 helpmod_reply(sender
, returntype
, "%s %ss for channel %s", listtype
?"Inactive":"Active", hlevel_name(lvl
), hchannel_get_name(hchan
));
2038 for (i
=0;i
< arr
.arrlen
&& arr
.array
[i
].prime_time_spent
> H_ACTIVE_LIMIT
;i
++)
2039 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
));
2042 for (i
=arr
.arrlen
-1;i
>= 0 && arr
.array
[i
].prime_time_spent
< H_ACTIVE_LIMIT
;i
--)
2043 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
));
2050 static void helpmod_cmd_top10 (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
2053 hstat_accounts_array arr
;
2054 hlevel lvl
= H_OPER
;
2059 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
2063 helpmod_reply(sender
, returntype
, "Cannot list channel Top10: Channel not specified or not found");
2069 if (!ci_strcmp(argv
[0], "opers") || !ci_strcmp(argv
[0], "o"))
2071 else if (!ci_strcmp(argv
[0], "staff") || !ci_strcmp(argv
[0], "s"))
2073 else if (!ci_strcmp(argv
[0], "all") || !ci_strcmp(argv
[0], "a"))
2079 if (sscanf(argv
[1], "%d", &tmp
) && (tmp
>= 10) && (tmp
<= 50))
2083 arr
= create_hstat_account_array(hchan
, lvl
, HSTAT_ACCOUNT_ARRAY_TOP10
);
2085 helpmod_reply(sender
, returntype
, "Top%d most active %ss of channel %s", top_n
, hlevel_name(lvl
), hchannel_get_name(hchan
));
2086 for (i
=0;i
< arr
.arrlen
&& i
< top_n
;i
++)
2087 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
));
2092 static void helpmod_cmd_report (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
2094 hchannel
*hchan
, *target
;
2097 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
2099 if (hchan
!= NULL
&& (argc
== 2))
2101 hchan
= hchannel_get_by_name(argv
[0]);
2107 helpmod_reply(sender
, returntype
, "Cannot view or set channel reporting: Channel not defined or not found");
2112 if (hchan
->report_to
== NULL
|| !hchannel_is_valid(hchan
->report_to
))
2113 helpmod_reply(sender
, returntype
, "Channel %s is not reported anywhere (%s)", hchannel_get_name(hchan
), hchannel_get_state(hchan
, H_REPORT
));
2115 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
));
2118 if ((target
= hchannel_get_by_name(argv
[0])) == NULL
)
2120 helpmod_reply(sender
, returntype
, "Cannot set channel reporting: Channel %s not found", argv
[0]);
2123 hchan
->report_to
= target
;
2124 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
));
2127 static void helpmod_cmd_mode(huser
*sender
, channel
* returntype
, int change
, char* ostr
, int argc
, char *argv
[])
2130 huser_channel
*huserchan
;
2136 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
2140 helpmod_reply(sender
, returntype
, "Cannot change mode: Channel not specified or not found");
2144 if (argc
==0) /* for a simple opme */
2147 argv
[0] = (char*)huser_get_nick(sender
);
2150 if (argc
> H_CMD_MAX_ARGS
)
2151 argc
= H_CMD_MAX_ARGS
;
2153 for (i
=0;i
<argc
;i
++)
2155 husr
= huser_get(getnickbynick(argv
[i
]));
2158 helpmod_reply(sender
, returntype
, "Cannot change mode: User %s not found", argv
[i
]);
2161 huserchan
= huser_on_channel(husr
, hchan
);
2162 if (huserchan
== NULL
)
2164 helpmod_reply(sender
, returntype
, "Cannot change mode: User %s it not on channel %s", huser_get_nick(husr
), hchannel_get_name(hchan
));
2173 for (j
=0;j
< hchan
->real_channel
->users
->hashsize
;j
++)
2174 if (getnickbynumeric(hchan
->real_channel
->users
->content
[j
]) == husr
->real_user
)
2176 if ((huserchan
->flags
& HCUMODE_OP
) && !(hchan
->real_channel
->users
->content
[j
] & CUMODE_OP
))
2178 huserchan
->flags
&= ~HCUMODE_OP
;
2179 Error("helpmod", ERR_ERROR
, "userchannelmode inconsistency (+o when should be -o)");
2181 if (huserchan
->flags
& HCUMODE_OP
)
2183 helpmod_reply(sender
, returntype
, "Cannot change mode: User %s is already +o on channel %s", huser_get_nick(husr
), hchannel_get_name(hchan
));
2186 if (huser_get_level(husr
) < H_STAFF
)
2188 helpmod_reply(sender
, returntype
, "Cannot change mode: User %s is not allowed to have +o on channel %s", huser_get_nick(husr
), hchannel_get_name(hchan
));
2191 helpmod_channick_modes(husr
, hchan
, MC_OP
, HLAZY
);
2197 for (j
=0;j
< hchan
->real_channel
->users
->hashsize
;j
++)
2198 if (getnickbynumeric(hchan
->real_channel
->users
->content
[j
]) == husr
->real_user
)
2200 if (!(huserchan
->flags
& HCUMODE_OP
) && (hchan
->real_channel
->users
->content
[j
] & CUMODE_OP
))
2202 huserchan
->flags
|= HCUMODE_OP
;
2203 Error("helpmod", ERR_ERROR
, "userchannelmode inconsistency (-o when should be +o)");
2205 if (!(huserchan
->flags
& HCUMODE_OP
))
2207 helpmod_reply(sender
, returntype
, "Cannot change mode: User %s is already -o on channel %s", huser_get_nick(husr
), hchannel_get_name(hchan
));
2210 if (huser_get_level(husr
) > huser_get_level(sender
))
2212 helpmod_reply(sender
, returntype
, "Cannot change mode: User %s is meant to have +o on channel %s", huser_get_nick(husr
), hchannel_get_name(hchan
));
2215 helpmod_channick_modes(husr
, hchan
, MC_DEOP
, HLAZY
);
2221 for (j
=0;j
< hchan
->real_channel
->users
->hashsize
;j
++)
2222 if (getnickbynumeric(hchan
->real_channel
->users
->content
[j
]) == husr
->real_user
)
2224 if ((huserchan
->flags
& HCUMODE_VOICE
) && !(hchan
->real_channel
->users
->content
[j
] & CUMODE_VOICE
))
2226 huserchan
->flags
&= ~HCUMODE_VOICE
;
2227 Error("helpmod", ERR_ERROR
, "userchannelmode inconsistency (+v when should be -v)");
2229 if (huserchan
->flags
& HCUMODE_VOICE
)
2231 helpmod_reply(sender
, returntype
, "Cannot change mode: User %s is already +v on channel %s", huser_get_nick(husr
), hchannel_get_name(hchan
));
2234 helpmod_channick_modes(husr
, hchan
, MC_VOICE
, HLAZY
);
2240 for (j
=0;j
< hchan
->real_channel
->users
->hashsize
;j
++)
2241 if (getnickbynumeric(hchan
->real_channel
->users
->content
[j
]) == husr
->real_user
)
2243 if (!(huserchan
->flags
& HCUMODE_VOICE
) && (hchan
->real_channel
->users
->content
[j
] & CUMODE_VOICE
))
2245 huserchan
->flags
|= HCUMODE_VOICE
;
2246 Error("helpmod", ERR_ERROR
, "userchannelmode inconsistency (-v when should be +v)");
2248 if (!(huserchan
->flags
& HCUMODE_VOICE
))
2250 helpmod_reply(sender
, returntype
, "Cannot change mode: User %s is already -v on channel %s", huser_get_nick(husr
), hchannel_get_name(hchan
));
2253 helpmod_channick_modes(husr
, hchan
, MC_DEVOICE
, HLAZY
);
2260 static void helpmod_cmd_op (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[]) { helpmod_cmd_mode(sender
, returntype
, H_CMD_OP
, ostr
, argc
, argv
); }
2261 static void helpmod_cmd_deop (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[]) { helpmod_cmd_mode(sender
, returntype
, H_CMD_DEOP
, ostr
, argc
, argv
); }
2262 static void helpmod_cmd_voice (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[]) { helpmod_cmd_mode(sender
, returntype
, H_CMD_VOICE
, ostr
, argc
, argv
); }
2263 static void helpmod_cmd_devoice (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[]) { helpmod_cmd_mode(sender
, returntype
, H_CMD_DEVOICE
, ostr
, argc
, argv
); }
2265 static void helpmod_cmd_invite (huser
*sender
, channel
*returntype
, char* arg
, int argc
, char *argv
[])
2272 helpmod_reply(sender
, returntype
, "Cannot invite: Channel not defined or not found");
2276 if (huser_get_level(sender
) < H_STAFF
)
2279 hchan
= hchannel_get_by_name(argv
[0]);
2282 helpmod_reply(sender
, returntype
, "Cannot invite: Unknown channel %s", argv
[0]);
2285 /* if tickets don't work, it's better that the user doesn't know that the channel really exists */
2286 if (!(hchan
->flags
& H_REQUIRE_TICKET
))
2288 helpmod_reply(sender
, returntype
, "Cannot invite: Unknown channel %s", argv
[0]);
2291 htick
= hticket_get(huser_get_auth(sender
), hchan
);
2295 helpmod_reply(sender
, returntype
, "Cannot invite: You do not have an invite ticket for channel %s", argv
[0]);
2299 if (nickbanned(sender
->real_user
, hchan
->real_channel
))
2301 helpmod_reply(sender
, returntype
, "Cannot invite: You are banned from channel %s", argv
[0]);
2305 helpmod_invite(hchan
, sender
);
2306 helpmod_reply(sender
, returntype
, "Invited you to channel %s", hchannel_get_name(hchan
));
2310 if (argc
> H_CMD_MAX_ARGS
)
2311 argc
= H_CMD_MAX_ARGS
;
2313 for (i
= 0;i
< argc
; i
++)
2315 hchan
= hchannel_get_by_name(argv
[i
]);
2318 helpmod_reply(sender
, returntype
, "Cannot invite: Unknown channel %s", argv
[i
]);
2321 if (huser_on_channel(sender
, hchan
) != NULL
)
2323 helpmod_reply(sender
, returntype
, "Cannot invite: You are already on channel %s", hchannel_get_name(hchan
));
2326 if (!hchannel_authority(hchan
, sender
))
2328 if (huser_get_level(sender
) >= H_STAFF
&& (hchan
->flags
& H_REQUIRE_TICKET
));
2331 helpmod_reply(sender
, returntype
, "Sorry, channel %s is oper only", hchannel_get_name(hchan
));
2335 helpmod_invite(hchan
, sender
);
2336 helpmod_reply(sender
, returntype
, "Invited you to channel %s", hchannel_get_name(hchan
));
2340 static void helpmod_cmd_ticket (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
2342 int expiration
= HTICKET_EXPIRATION_TIME
;
2346 const char *message
= NULL
;
2350 helpmod_reply(sender
, returntype
, "Cannot issue a ticket: Channel not specified");
2354 hchan
= hchannel_get_by_name(argv
[0]);
2357 helpmod_reply(sender
, returntype
, "Cannot issue a ticket: Unknown channel %s", argv
[0]);
2360 if (!(hchan
->flags
& H_REQUIRE_TICKET
))
2362 helpmod_reply(sender
, returntype
, "Cannot issue a ticket: Tickets are not enabled for channel %s", argv
[0]);
2367 helpmod_reply(sender
, returntype
, "Cannot issue a ticket: Target user not specified");
2371 husr
= huser_get(getnickbynick(argv
[1]));
2374 helpmod_reply(sender
, returntype
, "Cannot issue a ticket: Unknown user %s", argv
[1]);
2377 if (!IsAccount(husr
->real_user
))
2379 helpmod_reply(sender
, returntype
, "Cannot issue a ticket: User %s is not authed", argv
[1]);
2382 if (huser_get_level(husr
) < H_PEON
)
2384 helpmod_reply(sender
, returntype
, "Cannot issue a ticket: User %s is considered improper and not worthy of a ticket", argv
[1]);
2387 if (huser_get_level(husr
) > H_PEON
)
2389 helpmod_reply(sender
, returntype
, "Cannot issue a ticket: User %s does not require a ticket", argv
[1]);
2395 tmp
= helpmod_read_strtime(argv
[2]);
2396 if (tmp
> HDEF_m
&& tmp
< 2 * HDEF_M
)
2399 if (argc
>= 4 && strlen(argv
[3]) < 128)
2401 if (argv
[3][0] != '\0')
2405 htick
= hticket_get(huser_get_auth(husr
), hchan
);
2408 htick
->time_expiration
= time(NULL
) + expiration
;
2410 hticket_add(huser_get_auth(husr
), time(NULL
) + expiration
, hchan
, message
);
2412 helpmod_reply(sender
, returntype
, "Issued an invite ticket to user %s for channel %s expiring in %s", huser_get_nick(husr
), hchannel_get_name(hchan
), helpmod_strtime(expiration
));
2413 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
));
2414 if (hchan
->flags
& H_TICKET_MESSAGE
&& hchan
->ticket_message
!= NULL
)
2415 helpmod_reply(husr
, NULL
, "Ticket information for %s: %s", hchannel_get_name(hchan
), hchan
->ticket_message
->content
);
2418 static void helpmod_cmd_resolve (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
2427 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
2429 if (argc
> H_CMD_MAX_ARGS
)
2430 argc
= H_CMD_MAX_ARGS
;
2434 helpmod_reply(sender
, returntype
, "Cannot resolve a ticket: The channel is not specified");
2438 for (i
= 0;i
< argc
;i
++)
2440 if (argv
[i
][0] == '#')
2442 htick
= hticket_get(&argv
[i
][1], hchan
);
2445 helpmod_reply(sender
, returntype
, "Cannot resolve a ticket: Authname %s does not have a ticket for channel %s", &argv
[i
][1], hchannel_get_name(hchan
));
2448 hticket_del(htick
, hchan
);
2449 helpmod_reply(sender
, returntype
, "Resolved authname %s's ticket for channel %s", &argv
[i
][1], hchannel_get_name(hchan
));
2453 husr
= huser_get(getnickbynick(argv
[i
]));
2456 helpmod_reply(sender
, returntype
, "Cannot resolve a ticket: User %s not found", argv
[i
]);
2459 if (!IsAccount(husr
->real_user
))
2461 helpmod_reply(sender
, returntype
, "Cannot resolve a ticket: User %s is not authed", argv
[i
]);
2464 htick
= hticket_get(huser_get_auth(husr
),hchan
);
2467 helpmod_reply(sender
, returntype
, "Cannot resolve a ticket: User %s does not have a ticket for channel %s", argv
[i
], hchannel_get_name(hchan
));
2470 hticket_del(htick
, hchan
);
2471 helpmod_reply(sender
, returntype
, "Resolved user %s's ticket for channel %s", argv
[i
], hchannel_get_name(hchan
));
2476 static void helpmod_cmd_tickets (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
2484 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
2488 helpmod_reply(sender
, returntype
, "Cannot list tickets: Channel not defined or not found");
2492 if (!(hchan
->flags
& H_REQUIRE_TICKET
))
2494 helpmod_reply(sender
, returntype
, "Cannot list tickets: Channel %s does not use the ticket system", hchannel_get_name(hchan
));
2498 htick
= hchan
->htickets
;
2502 helpmod_reply(sender
, returntype
, "Channel %s has no valid tickets", hchannel_get_name(hchan
));
2506 helpmod_reply(sender
, returntype
, "Valid tickets for channel %s", hchannel_get_name(hchan
));
2508 for (i
= 0;htick
;htick
= htick
->next
, i
++)
2509 helpmod_reply(sender
, returntype
, "%4d %16s %48s", i
, htick
->authname
, helpmod_strtime(time(NULL
) - htick
->time_expiration
));
2511 helpmod_reply(sender
, returntype
, "Done listing tickets. Channel %s had %d valid ticket%s", hchannel_get_name(hchan
), i
, (i
==1)?"":"s");
2514 static void helpmod_cmd_showticket (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
2523 if (argc
> H_CMD_MAX_ARGS
)
2524 argc
= H_CMD_MAX_ARGS
;
2528 helpmod_reply(sender
, returntype
, "Cannot show the ticket: Channel not defined or not found");
2531 for (i
= 0;i
< argc
;i
++)
2533 husr
= huser_get(getnickbynick(argv
[i
]));
2536 helpmod_reply(sender
, returntype
, "Cannot show the ticket: User %s not found", argv
[i
]);
2539 if (!IsAccount(husr
->real_user
))
2541 helpmod_reply(sender
, returntype
, "Cannot show the ticket: User %s is not authed", argv
[i
]);
2544 htick
= hticket_get(huser_get_auth(husr
), hchan
);
2547 helpmod_reply(sender
, returntype
, "Cannot show the ticket: User %s does not have a valid ticket for channel %s", argv
[i
], hchannel_get_name(hchan
));
2550 if (htick
->message
== NULL
)
2551 helpmod_reply(sender
, returntype
, "User %s has a ticket for channel %s expiring in %s. No message is attached.", argv
[i
], hchannel_get_name(hchan
), helpmod_strtime(htick
->time_expiration
- time(NULL
)));
2553 helpmod_reply(sender
, returntype
, "User %s has a ticket for channel %s expiring in %s. With message: %s", argv
[i
], hchannel_get_name(hchan
), helpmod_strtime(htick
->time_expiration
- time(NULL
)), htick
->message
->content
);
2557 static int helpmod_cmd_termstats_sort(const void *left
, const void *right
)
2559 return (*((hterm
**)right
))->usage
- (*((hterm
**)left
))->usage
;
2562 static void helpmod_cmd_termstats(huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
2564 hterm
**arr
, *origin
;
2570 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
2575 origin
= hchan
->channel_hterms
;
2577 count
= hterm_count(origin
);
2581 helpmod_reply(sender
, returntype
, "Cannot list term usage statistics: No terms available");
2585 arr
= malloc(sizeof(hterm
*) * count
);
2586 assert(arr
!= NULL
);
2588 for (i
=0;i
< count
;i
++,origin
= origin
->next
)
2591 qsort(arr
, count
, sizeof(hterm
*), helpmod_cmd_termstats_sort
);
2594 helpmod_reply(sender
, returntype
, "10 Most used global terms");
2596 helpmod_reply(sender
, returntype
, "10 Most used terms for channel %s", hchannel_get_name(hchan
));
2598 for (i
=0;i
< 10 && i
< count
;i
++)
2599 helpmod_reply(sender
, returntype
, "#%02d %32s :%d",i
+1, arr
[i
]->name
->content
,arr
[i
]->usage
);
2604 static int helpmod_cmd_checkchannel_nicksort(const void *left
, const void *right
)
2606 return ci_strcmp(getnickbynumeric(*((unsigned long*)left
))->nick
, getnickbynumeric(*((unsigned long*)right
))->nick
);
2609 static int helpmod_cmd_checkchannel_statussort(const void *left
, const void *right
)
2611 int level1
= 0, level2
= 0;
2613 if (*((unsigned long*)left
) & CUMODE_VOICE
)
2615 if (*((unsigned long*)left
) & CUMODE_OP
)
2618 if (*((unsigned long*)right
) & CUMODE_VOICE
)
2620 if (*((unsigned long*)right
) & CUMODE_OP
)
2623 return level2
- level1
;
2626 static void helpmod_cmd_checkchannel(huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
2630 int i
, j
, nick_count
= 0, authed_count
= 0, o_limit
= 0, v_limit
= 0, summary_only
= 0;
2631 unsigned long *numeric_array
;
2635 helpmod_reply(sender
, returntype
, "Cannot check channel: Channel not defined");
2639 chan
= findchannel(argv
[0]);
2642 helpmod_reply(sender
, returntype
, "Cannot check channel: Channel %s not found", argv
[0]);
2645 if (argc
> 1 && !ci_strcmp(argv
[1], "summary"))
2648 /* first pass - verify validity and count nicks */
2649 for (i
=0;i
< chan
->users
->hashsize
;i
++)
2651 nck
= getnickbynumeric(chan
->users
->content
[i
]);
2652 if (!nck
) /* it's a hash, not an array */
2660 if (IsOper(nck
) && strlen(nck
->nick
) > 1 && (IsSecret(chan
) || IsPrivate(chan
) || IsKey(chan
) || IsInviteOnly(chan
)))
2662 helpmod_reply(sender
, returntype
, "Cannot check channel: Permission denied. Channel %s has an oper on it and one or more of +i/+k/+p/+s", argv
[0]);
2667 numeric_array
= (unsigned long*)malloc(nick_count
* sizeof(unsigned long));
2669 /* second pass - construct array */
2670 for (i
=0,j
=0;i
< chan
->users
->hashsize
;i
++)
2672 if (getnickbynumeric(chan
->users
->content
[i
]) == NULL
) /* it's a hash, not an array */
2675 numeric_array
[j
++] = chan
->users
->content
[i
];
2678 qsort(numeric_array
, nick_count
, sizeof(unsigned long), helpmod_cmd_checkchannel_statussort
);
2680 /* third pass - find status boundaries */
2682 for (;o_limit
< nick_count
&& numeric_array
[o_limit
] & CUMODE_OP
; o_limit
++);
2684 for(v_limit
= o_limit
; (v_limit
< nick_count
) && numeric_array
[v_limit
] & CUMODE_VOICE
; v_limit
++);
2687 helpmod_reply(sender
, returntype
, "Information on channel %s", argv
[0]);
2688 helpmod_reply(sender
, returntype
, "Channel created %s ago", helpmod_strtime(time(NULL
) - chan
->timestamp
));
2689 if (!IsKey(chan
) && !IsInviteOnly(chan
))
2690 helpmod_reply(sender
, returntype
, "Channel topic: %s", chan
->topic
?chan
->topic
->content
:"Not set");
2691 helpmod_reply(sender
, returntype
, "Channel modes: %s", printflags(chan
->flags
, cmodeflags
));
2694 /* sort the sub arrays */
2697 qsort(numeric_array
, o_limit
, sizeof(unsigned long), helpmod_cmd_checkchannel_nicksort
);
2698 if (v_limit
- o_limit
> 0)
2699 qsort(numeric_array
+ o_limit
, v_limit
- o_limit
, sizeof(unsigned long), helpmod_cmd_checkchannel_nicksort
);
2700 if (nick_count
- v_limit
> 0)
2701 qsort(numeric_array
+ v_limit
, nick_count
- v_limit
, sizeof(unsigned long), helpmod_cmd_checkchannel_nicksort
);
2703 /* fourth pass - print results */
2705 for (i
=0;i
< nick_count
;i
++)
2707 char buf
[256], status
;
2709 if (numeric_array
[i
] & CUMODE_OP
)
2711 else if (numeric_array
[i
] & CUMODE_VOICE
)
2716 visiblehostmask(getnickbynumeric(numeric_array
[i
]), buf
);
2717 if (IsAccount(getnickbynumeric(numeric_array
[i
])))
2718 helpmod_reply(sender
, returntype
, "%c%s (%s)", status
, buf
, getnickbynumeric(numeric_array
[i
])->authname
);
2720 helpmod_reply(sender
, returntype
, "%c%s", status
, buf
);
2723 helpmod_reply(sender
, returntype
, "Users: %d Clones: %d Opped: %d Voiced: %d Authed: %3.0f%%", nick_count
, nick_count
- countuniquehosts(chan
), o_limit
, v_limit
- o_limit
, ((float)authed_count
/ (float)nick_count
) * 100.0);
2725 free(numeric_array
);
2728 static void helpmod_cmd_statsdump (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
2730 haccount
*hacc
= haccounts
;
2734 helpmod_reply(sender
, returntype
, "Account statistics");
2735 for (;hacc
;hacc
= hacc
->next
)
2736 for (ptr
= hacc
->stats
;ptr
;ptr
= ptr
->next
)
2738 helpmod_reply(sender
, returntype
, "Account %s channel %s short-term", hacc
->name
->content
, hchannel_get_name(ptr
->hchan
));
2739 for (i
= 0;i
< 7;i
++)
2740 helpmod_reply(sender
, returntype
, "%d %d %d %d", ptr
->week
[i
].time_spent
, ptr
->week
[i
].prime_time_spent
, ptr
->week
[i
].lines
, ptr
->week
[i
].words
);
2741 helpmod_reply(sender
, returntype
, "Account %s channel %s long-term", hacc
->name
->content
, hchannel_get_name(ptr
->hchan
));
2742 for (i
= 0;i
< 10;i
++)
2743 helpmod_reply(sender
, returntype
, "%d %d %d %d", ptr
->longterm
[i
].time_spent
, ptr
->longterm
[i
].prime_time_spent
, ptr
->longterm
[i
].lines
, ptr
->longterm
[i
].words
);
2747 static void helpmod_cmd_statsrepair (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
2749 haccount
*hacc
= haccounts
;
2753 helpmod_reply(sender
, returntype
, "Repairing account statistics");
2754 for (;hacc
;hacc
= hacc
->next
)
2755 for (ptr
= hacc
->stats
;ptr
;ptr
= ptr
->next
)
2757 for (i
= 0;i
< 7;i
++)
2759 if (ptr
->week
[i
].time_spent
> HDEF_d
)
2761 ptr
->week
[i
].time_spent
= 0;
2762 helpmod_reply(sender
, returntype
, "repaired short term TimeSpent %s @ %s : Greater than one day",hacc
->name
->content
, hchannel_get_name(ptr
->hchan
));
2764 if (ptr
->week
[i
].time_spent
< 0)
2766 ptr
->week
[i
].time_spent
= 0;
2767 helpmod_reply(sender
, returntype
, "repaired short term TimeSpent %s @ %s : Less than zero",hacc
->name
->content
, hchannel_get_name(ptr
->hchan
));
2770 if (ptr
->week
[i
].prime_time_spent
> HDEF_d
)
2772 ptr
->week
[i
].prime_time_spent
= 0;
2773 helpmod_reply(sender
, returntype
, "repaired short term PrimeTimeSpent %s @ %s : Greater than one day",hacc
->name
->content
, hchannel_get_name(ptr
->hchan
));
2775 if (ptr
->week
[i
].prime_time_spent
< 0)
2777 ptr
->week
[i
].prime_time_spent
= 0;
2778 helpmod_reply(sender
, returntype
, "repaired short term PrimeTimeSpent %s @ %s : Less than zero",hacc
->name
->content
, hchannel_get_name(ptr
->hchan
));
2781 if (ptr
->week
[i
].lines
> 10000)
2783 ptr
->week
[i
].lines
= 0;
2784 helpmod_reply(sender
, returntype
, "repaired short term Lines %s @ %s : Greater than 10000",hacc
->name
->content
, hchannel_get_name(ptr
->hchan
));
2786 if (ptr
->week
[i
].lines
< 0)
2788 ptr
->week
[i
].lines
= 0;
2789 helpmod_reply(sender
, returntype
, "repaired short term Lines %s @ %s : Less than zero",hacc
->name
->content
, hchannel_get_name(ptr
->hchan
));
2792 if (ptr
->week
[i
].words
> 50000)
2794 ptr
->week
[i
].words
= 0;
2795 helpmod_reply(sender
, returntype
, "repaired short term Words %s @ %s : Greater than 50000",hacc
->name
->content
, hchannel_get_name(ptr
->hchan
));
2797 if (ptr
->week
[i
].words
< 0)
2799 ptr
->week
[i
].words
= 0;
2800 helpmod_reply(sender
, returntype
, "repaired short term Words %s @ %s : Less than zero",hacc
->name
->content
, hchannel_get_name(ptr
->hchan
));
2803 for (i
= 0;i
< 10;i
++)
2805 if (ptr
->longterm
[i
].time_spent
> HDEF_w
)
2807 ptr
->longterm
[i
].time_spent
= 0;
2808 helpmod_reply(sender
, returntype
, "repaired long term TimeSpent %s @ %s : Greater than one week",hacc
->name
->content
, hchannel_get_name(ptr
->hchan
));
2810 if (ptr
->longterm
[i
].time_spent
< 0)
2812 ptr
->longterm
[i
].time_spent
= 0;
2813 helpmod_reply(sender
, returntype
, "repaired long term TimeSpent %s @ %s : Less than zero",hacc
->name
->content
, hchannel_get_name(ptr
->hchan
));
2816 if (ptr
->longterm
[i
].prime_time_spent
> HDEF_w
)
2818 ptr
->longterm
[i
].prime_time_spent
= 0;
2819 helpmod_reply(sender
, returntype
, "repaired long term PrimeTimeSpent %s @ %s : Greater than one week",hacc
->name
->content
, hchannel_get_name(ptr
->hchan
));
2821 if (ptr
->longterm
[i
].prime_time_spent
< 0)
2823 ptr
->longterm
[i
].prime_time_spent
= 0;
2824 helpmod_reply(sender
, returntype
, "repaired long term PrimeTimeSpent %s @ %s : Less than zero",hacc
->name
->content
, hchannel_get_name(ptr
->hchan
));
2827 if (ptr
->longterm
[i
].lines
> 50000)
2829 ptr
->longterm
[i
].lines
= 0;
2830 helpmod_reply(sender
, returntype
, "repaired long term Lines %s @ %s : Greater than 50000",hacc
->name
->content
, hchannel_get_name(ptr
->hchan
));
2832 if (ptr
->longterm
[i
].lines
< 0)
2834 ptr
->longterm
[i
].lines
= 0;
2835 helpmod_reply(sender
, returntype
, "repaired long term Lines %s @ %s : Less than zero",hacc
->name
->content
, hchannel_get_name(ptr
->hchan
));
2838 if (ptr
->longterm
[i
].words
> 50000)
2840 ptr
->longterm
[i
].words
= 0;
2841 helpmod_reply(sender
, returntype
, "repaired long term Words %s @ %s : Greater than 50000",hacc
->name
->content
, hchannel_get_name(ptr
->hchan
));
2843 if (ptr
->longterm
[i
].words
< 0)
2845 ptr
->longterm
[i
].words
= 0;
2846 helpmod_reply(sender
, returntype
, "repaired long term Words %s @ %s : Less than zero",hacc
->name
->content
, hchannel_get_name(ptr
->hchan
));
2850 helpmod_reply(sender
, returntype
, "Account statistics repaired");
2854 static void helpmod_cmd_statsreset (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
2856 haccount
*hacc
= haccounts
;
2859 int i
, short_del
, long_del
;
2863 helpmod_reply(sender
, returntype
, "Insufficient parameters");
2867 if (sscanf(argv
[0], "%d", &short_del
) == 0)
2869 helpmod_reply(sender
, returntype
, "Invalid parameter");
2872 if (sscanf(argv
[1], "%d", &long_del
) == 0)
2874 helpmod_reply(sender
, returntype
, "Invalid parameter");
2878 for (;hacc
;hacc
= hacc
->next
)
2879 for (ptr
= hacc
->stats
;ptr
;ptr
= ptr
->next
)
2881 for (i
= 1;i
< short_del
+ 1;i
++)
2882 HSTAT_ACCOUNT_ZERO(ptr
->week
[(hstat_day() + i
) % 7]);
2883 for (i
= 1;i
< long_del
+ 1;i
++)
2884 HSTAT_ACCOUNT_ZERO(ptr
->longterm
[(hstat_week() + i
) % 10]);
2887 for (hchan
= hchannels
;hchan
;hchan
= hchan
->next
)
2889 for (i
= 1;i
< short_del
+ 1;i
++)
2890 HSTAT_CHANNEL_ZERO(hchan
->stats
->week
[(hstat_day() + i
) % 7]);
2891 for (i
= 1;i
< long_del
+ 1;i
++)
2892 HSTAT_CHANNEL_ZERO(hchan
->stats
->longterm
[(hstat_week() + i
) % 10]);
2896 helpmod_reply(sender
, returntype
, "Statistics reset complete");
2899 static void helpmod_cmd_message (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
2905 helpmod_reply(sender
, returntype
, "Cannot send a message: Insufficient arguments");
2908 hchan
= hchannel_get_by_name(argv
[0]);
2911 helpmod_reply(sender
, returntype
, "Cannot send a message: Invalid channel %s", argv
[0]);
2915 helpmod_message_channel(hchan
, "(%s) %s", huser_get_nick(sender
), ostr
);
2916 helpmod_reply(sender
, returntype
, "Message sent to %s", hchannel_get_name(hchan
));
2919 static void helpmod_cmd_version (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
2921 helpmod_reply(sender
, returntype
, "HelpMod version " HELPMOD_VERSION
" by strutsi (strutsi@quakenet.org)");
2924 static void helpmod_cmd_ticketmsg (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
2930 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
2934 helpmod_reply(sender
, returntype
, "Can not view or set ticket message: No channel is specified.");
2940 if (hchan
->ticket_message
== NULL
)
2941 helpmod_reply(sender
, returntype
, "No ticket message is set for channel %s", hchannel_get_name(hchan
));
2943 helpmod_reply(sender
, returntype
, "Ticket message for channel %s is: %s", hchannel_get_name(hchan
), hchan
->ticket_message
->content
);
2948 if (hchan
->ticket_message
!= NULL
)
2949 freesstring(hchan
->ticket_message
);
2951 hchan
->ticket_message
= getsstring(ostr
, strlen(ostr
));
2952 helpmod_reply(sender
, returntype
, "Ticket message for channel %s set to: %s", hchannel_get_name(hchan
), hchan
->ticket_message
->content
);
2955 static void helpmod_cmd_lcedit (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
2957 hlc_profile
*profile
;
2961 helpmod_reply(sender
, returntype
, "Can not handle lamer control profiles: Operation not defined");
2965 if (!ci_strcmp(argv
[0], "list"))
2967 if (hlc_profiles
== NULL
)
2969 helpmod_reply(sender
, returntype
, "Can not list lamer control profiles: No profiles");
2972 helpmod_reply(sender
, returntype
, "Following lamer control profiles are currently available:");
2973 for (profile
= hlc_profiles
;profile
!= NULL
;profile
= profile
->next
)
2974 helpmod_reply(sender
, returntype
, "%s", profile
->name
->content
);
2976 else if (!ci_strcmp(argv
[0], "add"))
2980 helpmod_reply(sender
, returntype
, "Can not add a lamer control profile: Profile name not defined");
2984 profile
= hlc_get(argv
[1]);
2986 if (profile
!= NULL
)
2988 helpmod_reply(sender
, returntype
, "Can not add a lamer control profile: Profile named %s already exists", argv
[1]);
2991 profile
= hlc_add(argv
[1]);
2993 { /* set the default values */
2994 profile
->caps_max_percentage
= 40;
2995 profile
->caps_min_count
= 20;
2997 profile
->repeats_max_count
= 3;
2998 profile
->repeats_min_length
= 7;
3000 profile
->symbol_repeat_max_count
= 6;
3001 profile
->character_repeat_max_count
= 7;
3002 profile
->symbol_max_count
= 9;
3004 profile
->tolerance_flood
= 5;
3006 profile
->tolerance_spam
= 0.008;
3007 profile
->constant_spam
= 10;
3009 profile
->tolerance_warn
= 1;
3010 profile
->tolerance_kick
= 3;
3011 profile
->tolerance_remove
= 5;
3014 helpmod_reply(sender
, returntype
, "Lamer control profile %s added", argv
[1]);
3016 else if (!ci_strcmp(argv
[0], "del"))
3021 helpmod_reply(sender
, returntype
, "Can not delete a lamer control profile: Profile name not defined");
3025 profile
= hlc_get(argv
[1]);
3027 if (profile
== NULL
)
3029 helpmod_reply(sender
, returntype
, "Can not delete a lamer control profile: Profile named %s does not exist", argv
[1]);
3032 for (hchan
= hchannels
;hchan
!= NULL
;hchan
= hchan
->next
)
3033 if (hchan
->lc_profile
== profile
)
3035 helpmod_reply(sender
, returntype
, "Can not delete a lamer control profile: Profile %s is in use", argv
[1]);
3039 helpmod_reply(sender
, returntype
, "Lamer control profile %s deleted", argv
[1]);
3041 else if (!ci_strcmp(argv
[0], "view"))
3045 helpmod_reply(sender
, returntype
, "Can not view a lamer control profile: Profile name not defined");
3049 profile
= hlc_get(argv
[1]);
3051 if (profile
== NULL
)
3053 helpmod_reply(sender
, returntype
, "Can not view a lamer control profile: Profile named %s not found", argv
[1]);
3057 helpmod_reply(sender
, returntype
, "Lamer control profile %s:", profile
->name
->content
);
3058 helpmod_reply(sender
, returntype
, "Maximum caps percentage: %d", profile
->caps_max_percentage
);
3059 helpmod_reply(sender
, returntype
, "Caps minimum count: %d", profile
->caps_min_count
);
3060 helpmod_reply(sender
, returntype
, "Repeat tolerance: %d", profile
->repeats_max_count
);
3061 helpmod_reply(sender
, returntype
, "Repeat minimum length: %d", profile
->repeats_min_length
);
3062 helpmod_reply(sender
, returntype
, "Symbol repeat tolerance: %d", profile
->symbol_repeat_max_count
);
3063 helpmod_reply(sender
, returntype
, "Character repeat tolerance: %d", profile
->character_repeat_max_count
);
3064 helpmod_reply(sender
, returntype
, "Continuous symbol tolerance: %d", profile
->symbol_max_count
);
3065 helpmod_reply(sender
, returntype
, "Flood tolerance: %d", profile
->tolerance_flood
);
3066 helpmod_reply(sender
, returntype
, "Spam tolerance: %d", profile
->tolerance_spam
);
3067 helpmod_reply(sender
, returntype
, "Spam multiplier: %f", profile
->constant_spam
);
3068 helpmod_reply(sender
, returntype
, "Warning limit: %d", profile
->tolerance_warn
);
3069 helpmod_reply(sender
, returntype
, "Kick limit: %d", profile
->tolerance_kick
);
3070 helpmod_reply(sender
, returntype
, "Ban limit: %d", profile
->tolerance_remove
);
3072 else if (!ci_strcmp(argv
[0], "edit"))
3075 double dbl_val
= -1;
3079 helpmod_reply(sender
, returntype
, "Can not edit a lamer control profile: Syntax error");
3083 profile
= hlc_get(argv
[1]);
3085 if (profile
== NULL
)
3087 helpmod_reply(sender
, returntype
, "Can not edit a lamer control profile: Profile %s not found", argv
[1]);
3091 sscanf(argv
[3], "%d", &int_val
);
3092 sscanf(argv
[3], "%lf", &dbl_val
);
3095 { /* All int values are also valid double values */
3096 helpmod_reply(sender
, returntype
, "Can not edit a lamer control profile: Invalid argument");
3100 if (!ci_strcmp(argv
[2], "caps_percentage"))
3101 profile
->caps_max_percentage
= int_val
;
3102 else if (!ci_strcmp(argv
[2], "caps_count"))
3103 profile
->caps_min_count
= int_val
;
3104 else if (!ci_strcmp(argv
[2], "repeat_tolerance"))
3105 profile
->repeats_max_count
= int_val
;
3106 else if (!ci_strcmp(argv
[2], "repeat_length"))
3107 profile
->repeats_min_length
= int_val
;
3108 else if (!ci_strcmp(argv
[2], "symbol_repeat"))
3109 profile
->symbol_repeat_max_count
= int_val
;
3110 else if (!ci_strcmp(argv
[2], "character_repeat"))
3111 profile
->character_repeat_max_count
= int_val
;
3112 else if (!ci_strcmp(argv
[2], "continuous_symbol"))
3113 profile
->symbol_max_count
= int_val
;
3114 else if (!ci_strcmp(argv
[2], "flood_tolerance"))
3115 profile
->tolerance_flood
= int_val
;
3116 else if (!ci_strcmp(argv
[2], "spam_tolerance"))
3117 profile
->tolerance_spam
= int_val
;
3118 else if (!ci_strcmp(argv
[2], "spam_multiplier"))
3119 profile
->constant_spam
= dbl_val
;
3120 else if (!ci_strcmp(argv
[2], "warn_limit"))
3121 profile
->tolerance_warn
= int_val
;
3122 else if (!ci_strcmp(argv
[2], "kick_limit"))
3123 profile
->tolerance_kick
= int_val
;
3124 else if (!ci_strcmp(argv
[2], "ban_limit"))
3125 profile
->tolerance_remove
= int_val
;
3128 helpmod_reply(sender
, returntype
, "Can not edit a lamer control profile: No component named %s", argv
[2]);
3131 helpmod_reply(sender
, returntype
, "Lamer control profile component value changed succesfully.");
3135 static void helpmod_cmd_ged (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
3137 helpmod_editor
*editor
;
3139 if (sender
->editor
== NULL
)
3140 { /* Start a new editor */
3143 helpmod_reply(sender
, returntype
, "Can not use ged: Filename not specified");
3146 editor
= hed_open(sender
, argv
[0]);
3149 helpmod_reply(sender
, returntype
, "Can not use ged: Invalid filename %s", argv
[0]);
3152 if (editor
->user
!= sender
)
3154 helpmod_reply(sender
, returntype
, "Can not use ged: File %s is currently being edited by %s", editor
->filename
, huser_get_nick(editor
->user
));
3157 editor
->user
= sender
;
3158 sender
->editor
= editor
;
3160 helpmod_reply(sender
, returntype
, "Ged: %d", hed_byte_count(editor
));
3164 hed_command(sender
, returntype
, ostr
, argc
, argv
);
3168 static void helpmod_cmd_text (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
3174 if (argc
== 0 || !ci_strcmp(argv
[0], "list"))
3177 struct dirent
*dent
;
3178 char buffer
[384], **lines
, *start
;
3179 int nwritten
, bufpos
= 0, nlines
= 0,i
;
3181 dir
= opendir(HELPMOD_TEXT_DIR
);
3182 assert(dir
!= NULL
);
3184 /* First pass, count */
3185 for (dent
= readdir(dir
);dent
!= NULL
;dent
= readdir(dir
))
3187 /* Skip stuff like . and .. */
3188 if (!strncmp(dent
->d_name
, ".", 1))
3195 helpmod_reply(sender
, returntype
, "No texts are available.");
3199 helpmod_reply(sender
, returntype
, "Following texts are available:");
3202 lines
= (char **)malloc(sizeof(char*) * nlines
);
3203 *lines
= (char *)malloc(sizeof(char) * (HED_FILENAME_LENGTH
+1) * nlines
);
3204 /* We need the start to free this array */
3206 for(i
=0;i
< nlines
;i
++)
3207 lines
[i
] = &lines
[0][(HED_FILENAME_LENGTH
+1) * i
];
3210 /* Second pass, create array */
3212 for (dent
= readdir(dir
), i
= 0;dent
!= NULL
&& i
< nlines
;dent
= readdir(dir
))
3214 /* Skip stuff like . and .. */
3215 if (!strncmp(dent
->d_name
, ".", 1))
3217 strncpy(lines
[i
], dent
->d_name
, 64);
3221 qsort(*lines
, nlines
, sizeof(char)*(HED_FILENAME_LENGTH
+1), (int (*)(const void*, const void*))&strcmp
);
3223 for (i
= 0;i
< nlines
;i
++)
3227 buffer
[bufpos
] = ' ';
3230 sprintf(buffer
+ bufpos
, "%s%n", lines
[i
], &nwritten
);
3233 if (bufpos
> (384 - (HED_FILENAME_LENGTH
+1)))
3235 helpmod_reply(sender
, returntype
, buffer
);
3241 helpmod_reply(sender
, returntype
, buffer
);
3248 else if (!ci_strcmp(argv
[0], "show"))
3250 char fname_buffer
[128], buffer
[512];
3253 helpmod_reply(sender
, returntype
, "Can not show text: Text not specified");
3256 if (!hed_is_valid_filename(argv
[1]))
3258 helpmod_reply(sender
, returntype
, "Can not show text: Invalid filename");
3261 sprintf(fname_buffer
, HELPMOD_TEXT_DIR
"/%s" ,argv
[1]);
3262 in
= fopen(fname_buffer
, "rwt");
3265 helpmod_reply(sender
, returntype
, "Can not show text: Text %s not found", argv
[1]);
3270 if (!fgets(buffer
, 512, in
))
3272 if (returntype
!= NULL
&& huser_get_level(sender
) >= H_TRIAL
)
3273 helpmod_message_channel(hchannel_get_by_channel(returntype
), "%s", buffer
);
3275 helpmod_reply(sender
, returntype
, "%s", buffer
);
3281 if (huser_get_level(sender
) < H_STAFF
)
3283 helpmod_reply(sender
, returntype
, "Can not handle text: Insufficient user level");
3287 if (!ci_strcmp(argv
[0], "add"))
3289 char fname_buffer
[128];
3292 helpmod_reply(sender
, returntype
, "Can not add text: Text not specified");
3295 if (!hed_is_valid_filename(argv
[1]))
3297 helpmod_reply(sender
, returntype
, "Can not add text: Invalid filename");
3300 sprintf(fname_buffer
, HELPMOD_TEXT_DIR
"/%s" ,argv
[1]);
3301 if ((in
= fopen(fname_buffer
, "rt")) != NULL
)
3303 helpmod_reply(sender
, returntype
, "Can not add text: Text %s already exists", argv
[1]);
3308 if ((in
= fopen(fname_buffer
, "wt")) == NULL
)
3310 helpmod_reply(sender
, returntype
, "Can not add text: Unexpected error, please contact strutsi");
3315 helpmod_reply(sender
, returntype
, "Text %s added succesfully", argv
[1]);
3317 else if (!ci_strcmp(argv
[0], "del"))
3319 char fname_buffer
[128];
3322 helpmod_reply(sender
, returntype
, "Can not delete text: Text not specified");
3325 if (!hed_is_valid_filename(argv
[1]))
3327 helpmod_reply(sender
, returntype
, "Can not delete text: Invalid filename");
3330 sprintf(fname_buffer
, HELPMOD_TEXT_DIR
"/%s" ,argv
[1]);
3332 if (!remove(fname_buffer
))
3333 helpmod_reply(sender
, returntype
, "Text %s removed", argv
[1]);
3335 helpmod_reply(sender
, returntype
, "Can not delete text: Text %s does not exist or can not be deleted", argv
[1]);
3339 helpmod_reply(sender
, returntype
, "Can not handle text: Unknown operation %s", argv
[0]);
3344 static void helpmod_cmd_rating (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
3347 hstat_account_entry sum
= {0,0,0,0};
3353 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
3357 helpmod_reply(sender
, returntype
, "Can not show rating: Unknown channel");
3360 if (sender
->account
== NULL
)
3362 helpmod_reply(sender
, returntype
, "Can not show rating: You do not have an account");
3365 for (ptr
= sender
->account
->stats
;ptr
!= NULL
;ptr
= ptr
->next
)
3366 if (ptr
->hchan
== hchan
)
3368 if (hstat_day() == 0)
3369 { /* Sunday screws the indexing */
3370 for (i
= 0;i
< 7;i
++)
3371 HSTAT_ACCOUNT_SUM(sum
, sum
, ptr
->week
[i
]);
3375 for (i
= 1;i
<= hstat_day();i
++)
3376 HSTAT_ACCOUNT_SUM(sum
, sum
, ptr
->week
[i
]);
3379 helpmod_reply(sender
, returntype
, "Your rating for channel %s for this week is: %s", hchannel_get_name(hchan
), helpmod_strtime(sum
.time_spent
));
3382 helpmod_reply(sender
, returntype
, "Can not show rating: You do not have any statistics for channel %s", hchannel_get_name(hchan
));
3385 static void helpmod_cmd_writedb (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
3387 rename(HELPMOD_DEFAULT_DB
, HELPMOD_DEFAULT_DB
".old");
3388 helpmod_config_write(HELPMOD_DEFAULT_DB
);
3390 helpmod_reply(sender
, returntype
, "Database written");
3393 static void helpmod_cmd_evilhack1 (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
3398 helpmod_reply(sender
, returntype
, "hstat_cycle: %d", hstat_cycle
);
3401 if (!sscanf(argv
[0], "%d", &tmp
) || tmp
< 0)
3403 helpmod_reply(sender
, returntype
, "Invalid argument");
3407 helpmod_reply(sender
, returntype
, "hstat_cycle is now: %d", hstat_cycle
);
3411 static void helpmod_cmd_evilhack2 (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
3413 haccount
*hacc
= haccounts
;
3416 hstat_account_entry tmp_account
;
3417 hstat_channel_entry tmp_channel
;
3422 helpmod_reply(sender
, returntype
, "Syntax error: evilhack2 <first> <second>");
3426 if (!sscanf(argv
[0],"%d", &first
) || first
< 0 || first
> 9)
3428 helpmod_reply(sender
, returntype
, "Syntax error: Invalid first");
3432 if (!sscanf(argv
[1],"%d", &second
) || second
< 0 || second
> 9)
3434 helpmod_reply(sender
, returntype
, "Syntax error: Invalid second");
3438 for (;hacc
;hacc
= hacc
->next
)
3439 for (ptr
= hacc
->stats
;ptr
;ptr
= ptr
->next
)
3441 tmp_account
= ptr
->longterm
[first
];
3442 ptr
->longterm
[first
] = ptr
->longterm
[second
];
3443 ptr
->longterm
[second
] = tmp_account
;
3446 for (hchan
= hchannels
;hchan
;hchan
= hchan
->next
)
3448 tmp_channel
= hchan
->stats
->longterm
[first
];
3449 hchan
->stats
->longterm
[first
] = hchan
->stats
->longterm
[second
];
3450 hchan
->stats
->longterm
[second
] = tmp_channel
;
3453 helpmod_reply(sender
, returntype
, "Evilhack2 done: Swapped %d and %d", first
, second
);
3456 static void helpmod_cmd_channel (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
3459 hchannel_user
*hchanuser
;
3465 helpmod_reply(sender
, returntype
, "Can not show channel: Channel not specified");
3469 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
3471 helpmod_reply(sender
, returntype
, "Users for channel %s", hchannel_get_name(hchan
));
3472 helpmod_reply(sender
, returntype
, "Nick Account User level Idle time");
3474 for (hchanuser
= hchan
->channel_users
;hchanuser
;hchanuser
=hchanuser
->next
)
3475 helpmod_reply(sender
, returntype
, "%-16s %-16s %-24s %s",hchanuser
->husr
->real_user
->nick
,hchanuser
->husr
->account
?hchanuser
->husr
->account
->name
->content
:"-",hlevel_name(huser_get_level(hchanuser
->husr
)), helpmod_strtime(time(NULL
)-huser_on_channel(hchanuser
->husr
, hchan
)->last_activity
));
3477 helpmod_reply(sender
, returntype
, "Listed %d users for channel %s", hchannel_count_users(hchan
, H_ANY
), hchannel_get_name(hchan
));
3480 static void helpmod_cmd_weekstats (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
3483 hstat_accounts_array arr
;
3491 helpmod_reply(sender
, returntype
, "Can not list weekly stats: Channel not specified");
3495 HCHANNEL_VERIFY_AUTHORITY(hchan
, sender
);
3499 if (!ci_strcmp(argv
[0], "opers") || !ci_strcmp(argv
[0], "o"))
3501 else if (!ci_strcmp(argv
[0], "staff") || !ci_strcmp(argv
[0], "s"))
3503 else if (!ci_strcmp(argv
[0], "all") || !ci_strcmp(argv
[0], "a"))
3507 arr
= create_hstat_account_array(hchan
, lvl
, HSTAT_ACCOUNT_ARRAY_WEEKSTATS
);
3509 helpmod_reply(sender
, returntype
, "Weekly statistics for %ss on channel %s", hlevel_name(lvl
), hchannel_get_name(hchan
));
3511 for (i
=0;i
< arr
.arrlen
&& arr
.array
[i
].time_spent
> HDEF_m
;i
++)
3512 helpmod_reply(sender
, returntype
, "%-20s %-20s %-20s",((haccount
*)(arr
.array
[i
].owner
))->name
->content
, helpmod_strtime(arr
.array
[i
].prime_time_spent
), helpmod_strtime(arr
.array
[i
].time_spent
));
3518 void helpmod_cmd_load (huser
*sender
, channel
*returntype
, char* arg
, int argc
, char *argv
[])
3521 char buf
[128] = "helpmod/default";
3524 helpmod_reply(sender
, returntype
, "Warning: No config specified, using default");
3527 if (strlen(arg
) >= 100)
3530 sprintf(buf
, "helpmod/%s", arg
);
3533 if (!(tmp_file
= fopen(buf
, "rt")))
3535 helpmod_reply(sender
, returntype
, "File %s not found", buf
);
3541 helpmod_clear_aliases(&aliases
);
3542 helpmod_clear_all_entries();
3543 helpmod_init_entry(&helpmod_base
);
3544 huser_reset_states();
3545 helpmod_load_entries(buf
);
3546 strcpy(helpmod_db
, buf
);
3547 helpmod_reply(sender
, returntype
, "New config loaded and system reset");
3550 void helpmod_cmd_status (huser
*sender
, channel
* returntype
, char* ostr
, int argc
, char *argv
[])
3552 helpmod_reply(sender
, returntype
, "HelpMod version %s (built %s, up %s)", HELPMOD_VERSION
, __DATE__
, helpmod_strtime(time(NULL
) - helpmod_startup_time
));
3553 helpmod_reply(sender
, returntype
, "Channels %d", hchannel_count());
3554 helpmod_reply(sender
, returntype
, "Accounts %d", haccount_count(H_ANY
));
3555 helpmod_reply(sender
, returntype
, "Users %d", huser_count());
3556 helpmod_reply(sender
, returntype
, "Help entries %ld", helpmod_entry_count(helpmod_base
));
3557 helpmod_reply(sender
, returntype
, "Bans %d", hban_count());
3558 helpmod_reply(sender
, returntype
, "Help provided %ld", helpmod_usage
);
3559 helpmod_reply(sender
, returntype
, "Tickets %d", hticket_count());
3562 /* not really a command, but help wants this one */
3563 void helpmod_send_help(huser
* target
)
3567 for (i
=0;i
<target
->state
->text_lines
;i
++)
3568 helpmod_reply(target
, NULL
, "%s", target
->state
->text
[i
]->content
);
3569 for (i
=0;i
<target
->state
->option_count
;i
++)
3570 helpmod_reply(target
, NULL
, "%d) %s", i
+1, target
->state
->options
[i
]->description
->content
);
3571 if (!target
->state
->option_count
)
3573 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");
3577 void helpmod_cmd_command(huser
* sender
, channel
* returntype
, char* arg
, int argc
, char *argv
[])
3580 char buffer
[512], *ptr
= argv
[0];
3585 helpmod_reply(sender
, returntype
, "Usage: command [name of the command] for a list see 'showcommands'");
3589 hcom
= hcommand_get(argv
[0], huser_get_level(sender
));
3593 helpmod_reply(sender
, returntype
, "Unknown command '%s'", argv
[0]);
3599 *ptr
= tolower(*ptr
);
3601 /* ?,?+.?- is handled like this because windows is shit */
3602 if (!ci_strcmp(argv
[0], "?"))
3603 sprintf(buffer
, "./helpmod2/commands/questionmark");
3604 else if (!ci_strcmp(argv
[0], "?+"))
3605 sprintf(buffer
, "./helpmod2/commands/questionmarkplus");
3606 else if (!ci_strcmp(argv
[0], "?-"))
3607 sprintf(buffer
, "./helpmod2/commands/questionmarkminus");
3609 sprintf(buffer
, "./helpmod2/commands/%s", argv
[0]);
3611 if ((in
= fopen(buffer
, "rt")) == NULL
)
3613 helpmod_reply(sender
, returntype
, "No help available for command '%s' (Ask strutsi to write it)", argv
[0]);
3619 fgets(buffer
, 512, in
);
3622 helpmod_reply(sender
, returntype
, "%s", buffer
);
3628 void helpmod_cmd_help (huser
* sender
, channel
* returntype
, char* arg
, int argc
, char *argv
[])
3632 if (helpmod_base
== NULL
|| !helpmod_base
->option_count
)
3634 helpmod_reply(sender
, returntype
, "The help service is not available at this time, please try again later");
3640 sender
->state
= helpmod_base
;
3641 helpmod_send_help(sender
);
3645 if (!sscanf(arg
, "%d", &hlp_target
))
3649 tmp
= helpmod_get_alias(arg
);
3651 helpmod_reply(sender
, returntype
, "Invalid value. Either use 'help' to restart or give an integer as a valid selection");
3654 sender
->state
= tmp
;
3655 helpmod_send_help(sender
);
3661 if (!helpmod_valid_selection(sender
->state
, hlp_target
))
3663 if (!sender
->state
->option_count
)
3664 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");
3665 else if (!sender
->state
->parent
)
3666 helpmod_reply(sender
, returntype
, "Bad selection, please enter your selection as an integer from %d to %d", 1, sender
->state
->option_count
);
3668 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
);
3672 sender
->state
= helpmod_make_selection(sender
->state
, hlp_target
);
3673 helpmod_send_help(sender
);
3677 /* adds all of the abowe to the system */
3678 void hcommands_add(void)
3680 hcommand_add("help", H_PEON
, helpmod_cmd_help
,"Offers the H1 type help");
3681 hcommand_add("status",H_OPER
, helpmod_cmd_status
,"Gives service status");
3682 hcommand_add("load", H_OPER
, helpmod_cmd_load
,"Loads a new help database");
3683 hcommand_add("aliases",H_STAFF
, helpmod_cmd_aliases
,"Lists all aliases currently in use");
3684 hcommand_add("showcommands", H_LAMER
, helpmod_cmd_showcommands
,"Lists all commands available to you");
3686 hcommand_add("improper", H_STAFF
, helpmod_cmd_improper
, "Sets the userlevel of the target to banned (lvl 0). Long term ban.");
3687 hcommand_add("peon", H_STAFF
, helpmod_cmd_peon
, "Sets the userlevel of the target to peon (lvl 1)");
3688 hcommand_add("friend", H_STAFF
, helpmod_cmd_friend
, "Sets the userlevel of the target to friend (lvl 2)");
3689 hcommand_add("trial", H_OPER
, helpmod_cmd_trial
, "Sets the userlevel of the target to trial staff (lvl 3)");
3690 hcommand_add("staff", H_OPER
, helpmod_cmd_staff
, "Sets the userlevel of the target to staff (lvl 4)");
3692 hcommand_add("oper", H_OPER
, helpmod_cmd_oper
, "Sets the userlevel of the target to oper (lvl 5)");
3693 hcommand_add("admin", H_ADMIN
, helpmod_cmd_admin
, "Sets the userlevel of the target to admin (lvl 6)");
3694 hcommand_add("deluser", H_OPER
, helpmod_cmd_deluser
, "Removes an account from " HELPMOD_NICK
);
3695 hcommand_add("listuser", H_STAFF
, helpmod_cmd_listuser
, "Lists user accounts of " HELPMOD_NICK
);
3697 hcommand_add("chanconf", H_STAFF
, helpmod_cmd_chanconf
, "Channel configuration");
3698 hcommand_add("acconf", H_TRIAL
, helpmod_cmd_acconf
, "Personalise " HELPMOD_NICK
" behaviour");
3699 hcommand_add("welcome", H_STAFF
, helpmod_cmd_welcome
, "Views or changes the channel welcome message");
3700 hcommand_add("censor", H_STAFF
, helpmod_cmd_censor
, "Handles the censored patterns for a channel");
3702 hcommand_add("queue", H_TRIAL
, helpmod_cmd_queue
, "Handles the channel queue");
3703 hcommand_add("next", H_TRIAL
, helpmod_cmd_next
, "Same as queue next");
3704 hcommand_add("done", H_TRIAL
, helpmod_cmd_done
, "Same as queue done");
3705 hcommand_add("enqueue", H_TRIAL
, helpmod_cmd_enqueue
, "Same as queue on or chanconf +3");
3706 hcommand_add("dequeue", H_TRIAL
, helpmod_cmd_dequeue
, "Same as queue off or chanconf -3");
3707 hcommand_add("autoqueue", H_TRIAL
, helpmod_cmd_autoqueue
, "Same as queue maintain");
3709 hcommand_add("?", H_PEON
, helpmod_cmd_term_find
, "Same as term find with multiple targets");
3710 hcommand_add("?+", H_TRIAL
, helpmod_cmd_term_find_plus
, "Multitarget term find which advances the queue");
3711 hcommand_add("?-", H_TRIAL
, helpmod_cmd_term_find_minus
, "Multitarget term find which removes users from queue");
3712 hcommand_add("term", H_STAFF
, helpmod_cmd_term
, "Term handling");
3714 hcommand_add("klingon", H_OPER
, helpmod_cmd_klingon
, "Phrases in klingon, both targeted and general");
3715 hcommand_add("out", H_STAFF
, helpmod_cmd_out
, "Sets the userlevel of the target to banned (lvl 0) for a short while");
3716 hcommand_add("kick", H_TRIAL
, helpmod_cmd_kick
, "Kicks user(s) from a channel");
3717 hcommand_add("ban", H_STAFF
, helpmod_cmd_ban
, "Handles global bans");
3718 hcommand_add("chanban", H_TRIAL
, helpmod_cmd_chanban
, "Handles channel bans");
3719 hcommand_add("dnmo", H_STAFF
, helpmod_cmd_dnmo
, "DoNotMessageOpers informs the luser of his mistake and sets him to the bottom of the queue");
3720 hcommand_add("lamercontrol", H_OPER
, helpmod_cmd_lamercontrol
, "Views or changes the channel lamercontrol profile");
3721 hcommand_add("topic", H_STAFF
, helpmod_cmd_topic
, "Handles the topic of a channel");
3722 hcommand_add("idlekick", H_OPER
, helpmod_cmd_idlekick
, "Views or sets the idle kick time");
3723 hcommand_add("everyoneout", H_STAFF
, helpmod_cmd_everyoneout
, "Removes all normal users from a channel and enforces +i");
3725 hcommand_add("stats", H_STAFF
, helpmod_cmd_stats
, "Shows staff activity statistics");
3726 hcommand_add("chanstats", H_STAFF
, helpmod_cmd_chanstats
, "Shows channel activity statistics");
3727 hcommand_add("activestaff", H_ADMIN
, helpmod_cmd_activestaff
, "Shows active staff members for a channel");
3728 hcommand_add("top10", H_STAFF
, helpmod_cmd_top10
, "Shows the top 10 most active staff");
3729 hcommand_add("report", H_OPER
, helpmod_cmd_report
, "Sets the channel where to report this channels statistics every 5 minutes");
3731 hcommand_add("whoami", H_LAMER
, helpmod_cmd_whoami
, "Tells who you are to " HELPMOD_NICK
);
3732 hcommand_add("whois", H_STAFF
, helpmod_cmd_whois
, "Tells you who someone is");
3733 hcommand_add("command", H_LAMER
, helpmod_cmd_command
, "Gives detailed information on a command");
3734 hcommand_add("addchan", H_ADMIN
, helpmod_cmd_addchan
, "Joins " HELPMOD_NICK
" to a new channel");
3735 hcommand_add("delchan", H_ADMIN
, helpmod_cmd_delchan
, "Removes " HELPMOD_NICK
" permanently from a channel");
3737 hcommand_add("seen", H_STAFF
, helpmod_cmd_seen
, "Tells when a specific user/account has had activity");
3738 hcommand_add("op", H_STAFF
, helpmod_cmd_op
, "Sets mode +o on channels");
3739 hcommand_add("deop", H_STAFF
, helpmod_cmd_deop
, "Sets mode -o on channels");
3740 hcommand_add("voice", H_TRIAL
, helpmod_cmd_voice
, "Sets mode +v on channels");
3741 hcommand_add("devoice", H_TRIAL
, helpmod_cmd_devoice
, "Sets mode -v on channels");
3743 hcommand_add("invite", H_PEON
, helpmod_cmd_invite
, "Invites you to a channel");
3744 hcommand_add("ticket", H_TRIAL
, helpmod_cmd_ticket
, "Gives a ticket to be used with invite");
3745 hcommand_add("resolve", H_STAFF
, helpmod_cmd_resolve
, "Resolves (deletes) a ticket");
3746 hcommand_add("tickets", H_STAFF
, helpmod_cmd_tickets
, "Lists all valid tickets for a channel");
3747 hcommand_add("showticket", H_STAFF
, helpmod_cmd_showticket
, "Shows the ticket for the user");
3749 hcommand_add("termstats", H_OPER
, helpmod_cmd_termstats
, "Lists usage statistics for terms");
3750 hcommand_add("checkchannel", H_STAFF
, helpmod_cmd_checkchannel
, "Shows channel information for any channel");
3751 hcommand_add("message", H_TRIAL
, helpmod_cmd_message
, "Sends a message to a channel");
3752 hcommand_add("version", H_PEON
, helpmod_cmd_version
, "G version information");
3753 hcommand_add("ticketmsg", H_STAFF
, helpmod_cmd_ticketmsg
, "Handle the ticket message for a channel");
3755 hcommand_add("lcedit", H_ADMIN
, helpmod_cmd_lcedit
, "Lamer control profile manager");
3756 hcommand_add("ged", H_STAFF
, helpmod_cmd_ged
, "Ged IRC text editor");
3757 hcommand_add("text", H_PEON
, helpmod_cmd_text
, "Lists or shows text files");
3758 hcommand_add("evilhack1", H_ADMIN
, helpmod_cmd_evilhack1
, "An evil hack, don't use");
3759 hcommand_add("evilhack2", H_ADMIN
, helpmod_cmd_evilhack2
, "Another evil hack, don't use");
3761 hcommand_add("statsdump", H_ADMIN
, helpmod_cmd_statsdump
, "Statistics dump command");
3762 hcommand_add("statsrepair", H_ADMIN
, helpmod_cmd_statsrepair
, "Statistics repair command");
3763 hcommand_add("statsreset", H_ADMIN
, helpmod_cmd_statsreset
, "Statistics reset command");
3764 hcommand_add("rating", H_TRIAL
, helpmod_cmd_rating
, "Simple rating for the current week");
3765 hcommand_add("writedb", H_OPER
, helpmod_cmd_writedb
, "Writes the " HELPMOD_NICK
" database to disk");
3767 hcommand_add("channel", H_TRIAL
, helpmod_cmd_channel
, "Gives a list of all channel users");
3768 hcommand_add("weekstats", H_ADMIN
, helpmod_cmd_weekstats
, "Gives weekly stats for a channel");
3769 /*hcommand_add("megod", H_PEON, helpmod_cmd_megod, "Gives you userlevel 4, if you see this in the final version, please kill strutsi");*/
3770 /*hcommand_add("test", H_PEON, helpmod_cmd_test, "Gives you userlevel 4, if you see this in the final version, please kill strutsi");*/
3773 void helpmod_command(huser
*sender
, channel
* returntype
, char *args
)
3775 int argc
= 0, useless_var
;
3776 char args_copy
[512];
3777 char *parsed_args
[H_CMD_MAX_ARGS
+ 4], *ptr
= args_copy
;
3779 /* only accept commands from valid sources */
3780 if (huser_get_level(sender
) > H_ADMIN
)
3783 if (returntype
&& !strncmp(args
, helpmodnick
->nick
, strlen(helpmodnick
->nick
)))
3788 args
+=strlen(helpmodnick
->nick
)+1;
3791 if (*args
== '-' || *args
== '?')
3794 strncpy(args_copy
, args
, (sizeof(args_copy
) - 1));
3795 args_copy
[sizeof(args_copy
) - 1] = '\0';
3797 /* FIX stringituki */
3798 while (argc
< (H_CMD_MAX_ARGS
+ 4))
3800 while (isspace(*ptr
) && *ptr
)
3806 if (*ptr
== '"' && strchr(ptr
+1, '"'))
3807 { /* string support */
3808 parsed_args
[argc
++] = ptr
+1;
3809 ptr
= strchr(ptr
+1, '"');
3813 while (!isspace(*ptr
) && *ptr
)
3821 parsed_args
[argc
++] = ptr
;
3823 while (!isspace(*ptr
) && *ptr
)
3836 /* old H compatibility */
3837 if (sscanf(parsed_args
[0], "%d", &useless_var
) && returntype
== NULL
)
3839 helpmod_cmd_help(sender
, NULL
, parsed_args
[0], 1, NULL
);
3844 char *ostr
= args
, **argv
= (char**)&parsed_args
;
3845 hcommand
*hcom
= hcommand_get(parsed_args
[0], huser_get_level(sender
));
3849 controlwall(NO_DEVELOPER
, NL_ALL_COMMANDS
, "(G) From: %s!%s@%s%s%s: %s",
3850 sender
->real_user
->nick
, sender
->real_user
->ident
,
3851 sender
->real_user
->host
->name
->content
, IsAccount(sender
->real_user
)?"/":"",
3852 IsAccount(sender
->real_user
)?sender
->real_user
->authname
:"", args
);
3853 if ((returntype
== NULL
) ||
3854 (sender
->account
!= NULL
&& !(sender
->account
->flags
& H_NO_CMD_ERROR
)))
3855 helpmod_reply(sender
, returntype
, "Unknown command '%s', please see showcommands for a list of all commands available to you", parsed_args
[0]);
3859 controlwall(NO_DEVELOPER
, NL_ALL_COMMANDS
, "(G) From: %s!%s@%s%s%s: %s", sender
->real_user
->nick
, sender
->real_user
->ident
, sender
->real_user
->host
->name
->content
, IsAccount(sender
->real_user
)?"/":"", IsAccount(sender
->real_user
)?sender
->real_user
->authname
:"", args
);
3861 hcom
->function(sender
, returntype
, ostr
, argc
, argv
);
3867 #undef DEFINE_HCHANNEL
3868 #undef HCHANNEL_VERIFY_AUTHORITY