X-Git-Url: https://jfr.im/git/irc/evilnet/x3.git/blobdiff_plain/c82735893e91d97cbb512a1a0ed68d320aa24ca7..8dc0685213ead3f8896c83cadc130143ccc4d181:/src/modcmd.c diff --git a/src/modcmd.c b/src/modcmd.c index ba282df..9b6576b 100644 --- a/src/modcmd.c +++ b/src/modcmd.c @@ -3,7 +3,7 @@ * * This file is part of x3. * - * srvx is free software; you can redistribute it and/or modify + * x3 is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. @@ -18,11 +18,13 @@ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -#include "../ChangeLog.X3" +#include "../ChangeLog" #include "chanserv.h" #include "conf.h" #include "modcmd.h" +#include "opserv.h" #include "saxdb.h" +#include "timeq.h" struct pending_template { struct svccmd *cmd; @@ -30,6 +32,7 @@ struct pending_template { struct pending_template *next; }; +extern unsigned long god_timeout; static struct dict *modules; static struct dict *services; static struct pending_template *pending_templates; @@ -55,8 +58,12 @@ static const struct message_entry msgtab[] = { { "MCMSG_NO_CHANNEL_BEFORE", "You may not give a channel name before this command." }, { "MCMSG_NO_PLUS_CHANNEL", "You may not use a +channel with this command." }, { "MCMSG_COMMAND_ALIASES", "%s is an alias for: %s" }, -/* { "MCMSG_HELP_COMMAND_ALIAS_FOR", "$bALIAS FOR:$b %s" },*/ { "MCMSG_HELP_COMMAND_ALIAS", "$uAlias for:$u %s" }, + { "MCMSG_HELP_COMMAND_HEADER", "Command help for: $b%s$b" }, + { "MCMSG_HELP_COMMAND_UNKNOWN", "No help available for that command." }, + { "MCMSG_HELP_TOPIC_HEADER", "Help topic: $b%s$b" }, + { "MCMSG_HELP_DIVIDER", "=---------------------------------------=" }, + { "MCMSG_HELP_FOOTER", "=------------- End of Help -------------=" }, { "MCMSG_COMMAND_BINDING", "%s is a binding of: %s" }, { "MCMSG_ALIAS_ERROR", "Error in alias expansion for %s; check the error log for details." }, { "MCMSG_INTERNAL_COMMAND", "$b%s$b is an internal command and cannot be called directly; please check command bindings." }, @@ -126,6 +133,7 @@ static const struct message_entry msgtab[] = { { "MCMSG_COMMAND_ACCOUNT_FLAGS", "Requires account flags +%s, prohibits account flags +%s." }, { "MCMSG_COMMAND_ACCESS_LEVEL", "Requires channel access %d and $O access %d." }, { "MCMSG_COMMAND_USES", "%s has been used %d times." }, + { "MCMSG_GOD_EXPIRED", "Security override expired." }, { NULL, NULL } }; struct userData *_GetChannelUser(struct chanData *channel, struct handle_info *handle, int override, int allow_suspended); @@ -251,7 +259,7 @@ add_pending_template(struct svccmd *cmd, const char *target) { pending_templates = pending; } -static struct svccmd * +struct svccmd * svccmd_resolve_name(struct svccmd *origin, const char *name) { char *sep, svcname[MAXLEN]; @@ -579,7 +587,7 @@ svccmd_can_invoke(struct userNode *user, struct userNode *bot, struct svccmd *cm } static int -svccmd_expand_alias(struct svccmd *cmd, unsigned int old_argc, char *old_argv[], char *new_argv[]) { +svccmd_expand_alias(struct svccmd *cmd, struct userNode *user, unsigned int old_argc, char *old_argv[], char *new_argv[]) { unsigned int ii, new_argc; char *arg; @@ -617,8 +625,24 @@ svccmd_expand_alias(struct svccmd *cmd, unsigned int old_argc, char *old_argv[], for (jj = lbound; jj <= ubound; ) new_argv[new_argc++] = old_argv[jj++]; } else { - log_module(MAIN_LOG, LOG_ERROR, "Alias expansion: I do not know how to handle %s (%s.%s arg %d).", arg, cmd->parent->bot->nick, cmd->name, ii); - return 0; + switch(arg[1]) { + case 'a': + new_argv[new_argc++] = (user && user->handle_info) ? user->handle_info->handle : "(account)"; + break; + case 'n': + new_argv[new_argc++] = user ? user->nick : "(nick)"; + break; + case 'm': +#ifdef WITH_PROTOCOL_P10 + new_argv[new_argc++] = user ? user->numeric : "(numnick)"; +#else + new_argv[new_argc++] = "(This ircd protocol has no numnicks!)"; +#endif + break; + default: + log_module(MAIN_LOG, LOG_ERROR, "Alias expansion: I do not know how to handle %s (%s.%s arg %d).", arg, cmd->parent->bot->nick, cmd->name, ii); + return 0; + } } } return new_argc; @@ -631,13 +655,6 @@ svccmd_invoke_argv(struct userNode *user, struct service *service, struct chanNo unsigned int cmd_arg, perms, flags, options; char channel_name[CHANNELLEN+1]; - /* First check pubcmd for the channel. */ - if (channel && (channel->channel_info) && (service->bot == chanserv) - && !check_user_level(channel, user, lvlPubCmd, 1, 0)) { - send_message(user, service->bot, "MCMSG_PUBLIC_DENY", channel->name); - return 0; - } - options = (server_qualified ? SVCCMD_QUALIFIED : 0) | SVCCMD_DEBIT | SVCCMD_NOISY; /* Find the command argument. */ cmd_arg = IsChannelName(argv[0]) ? 1 : 0; @@ -655,6 +672,14 @@ svccmd_invoke_argv(struct userNode *user, struct service *service, struct chanNo send_message(user, service->bot, "MSG_COMMAND_UNKNOWN", argv[cmd_arg]); return 0; } + + /* Check pubcmd for the channel. */ + if (channel && (channel->channel_info) && (service->bot == chanserv) + && !check_user_level(channel, user, lvlPubCmd, 1, 0)) { + send_message(user, service->bot, "MCMSG_PUBLIC_DENY", channel->name); + return 0; + } + flags = cmd->effective_flags; /* If they put a channel name first, check if the command allows * it. If so, swap it with the command name. @@ -693,9 +718,9 @@ svccmd_invoke_argv(struct userNode *user, struct service *service, struct chanNo /* Expand the alias arguments, if there are any. */ if (cmd->alias.used) { char *new_argv[MAXNUMPARAMS]; - argc = svccmd_expand_alias(cmd, argc, argv, new_argv); + argc = svccmd_expand_alias(cmd, user, argc, argv, new_argv); if (!argc) { - send_message(service->bot, user, "MCMSG_ALIAS_ERROR", cmd->name); + send_message(user, service->bot, "MCMSG_ALIAS_ERROR", cmd->name); return 0; } argv = new_argv; @@ -752,65 +777,23 @@ svccmd_invoke_argv(struct userNode *user, struct service *service, struct chanNo slvl = LOG_COMMAND; /* Unsplit argv after running the function to get the benefit * of any mangling/hiding done by the commands. */ - log_audit(cmd->command->parent->clog, slvl, user, service->bot, channel_name, ((flags & MODCMD_LOG_HOSTMASK) ? AUDIT_HOSTMASK : 0), unsplit_string(argv, argc, NULL)); + log_audit(cmd->command->parent->clog, slvl, user, service->bot, channel_name, AUDIT_HOSTMASK, unsplit_string(argv, argc, NULL)); } return 1; } -int -svccmd_send_help(struct userNode *user, struct userNode *bot, struct svccmd *cmd) { - char cmdname[MAXLEN]; - unsigned int nn; - int r; - /* Show command name (in bold). */ - for (nn=0; cmd->name[nn]; nn++) - cmdname[nn] = toupper(cmd->name[nn]); - cmdname[nn] = 0; - send_message_type(4, user, bot, "=--- $b%s$b ---=", cmdname); - - /* Show the help entry for the underlying command. */ - /* Lets not show help for a parent command, thats not what - * they asked for! - * return send_help(user, bot, cmd->command->parent->helpfile, cmd->command->name); - * TODO: We actually DO want to show the parent IF there is no other help. - */ - r = send_help(user, bot, cmd->command->parent->helpfile, cmd->name); - if(cmd->command->name && strcasecmp(cmd->command->name, cmd->name)) - { - send_message(user, bot, "MCMSG_HELP_COMMAND_ALIAS", cmd->command->name); - } - - /* If it's an alias, show what it's an alias for. */ - if (cmd->alias.used) { - char alias_text[MAXLEN]; - unsplit_string((char**)cmd->alias.list, cmd->alias.used, alias_text); - send_message(user, bot, "MCMSG_HELP_COMMAND_ALIAS", alias_text); - } - return r; -} - +/* First line (syntax usually) only help.. used for wrong param counts etc */ int svccmd_send_help_brief(struct userNode *user, struct userNode *bot, struct svccmd *cmd) { - char cmdname[MAXLEN]; - unsigned int nn; int r; - /* Show command name (in bold). */ - for (nn=0; cmd->name[nn]; nn++) - cmdname[nn] = toupper(cmd->name[nn]); - cmdname[nn] = 0; - /* Show the help entry for the underlying command. */ - /* Lets not show help for a parent command, thats not what - * they asked for! - * return send_help(user, bot, cmd->command->parent->helpfile, cmd->command->name); - * TODO: We actually DO want to show the parent IF there is no other help. - */ /* If it's an alias, show what it's an alias for. */ if (cmd->alias.used) { char alias_text[MAXLEN]; unsplit_string((char**)cmd->alias.list, cmd->alias.used, alias_text); send_message(user, bot, "MCMSG_COMMAND_ALIASES", cmd->name, cmd->command->name); } + /* Send the syntax line of help.. */ r = send_help_brief(user, bot, cmd->command->parent->helpfile, cmd->name); if(!r) { if(cmd->command->name) @@ -819,31 +802,102 @@ svccmd_send_help_brief(struct userNode *user, struct userNode *bot, struct svccm r = send_help_brief(user, bot, cmd->command->parent->helpfile, cmd->command->name); } } - return r; } +int is_joiner(struct svccmd *cmd) +{ + if(cmd->command->name) + { + if(strcasecmp("joiner", cmd->command->name)) + return(0); + else + return(1); + } + return(0); +/* + if(cmd->alias.used) + { + char alias_text[MAXLEN]; + unsplit_string((char**)cmd->alias.list, cmd->alias.used, alias_text); + if(strcasecmp("joiner", alias_text)) + return(0); + else + return(1); + } +*/ +} int -svccmd_send_help_2(struct userNode *user, struct service *service, const char *topic) { +svccmd_send_help(struct userNode *user, struct service *service, const char *topic) { struct module *module; struct svccmd *cmd; - unsigned int ii; - - /* If there is a command, send help for the command */ - if ((cmd = dict_find(service->commands, topic, NULL))) - return svccmd_send_help(user, service->bot, cmd); + char cmdname[MAXLEN]; + unsigned int nn, ii; + int helpsent = 0; /* If there is no topic show the index */ if (!topic) topic = ""; - /* look for the thing in the included help files */ - for (ii = 0; ii < service->modules.used; ++ii) { - module = service->modules.list[ii]; - if (!module->helpfile) - continue; - if (dict_find(module->helpfile->db, topic, NULL)) - return send_help(user, service->bot, module->helpfile, topic); + /* make heading str (uppercase) */ + for (nn=0; topic[nn]; nn++) + cmdname[nn] = toupper(topic[nn]); + cmdname[nn] = 0; + + /* If there is a command 'topic', send command help for the command (unless its bound to JOINER) */ + if ((cmd = dict_find(service->commands, topic, NULL)) && !is_joiner(cmd)) + { + send_message(user, service->bot, "MCMSG_HELP_COMMAND_HEADER", cmdname); + send_message(user, service->bot, "MCMSG_HELP_DIVIDER"); + helpsent = send_help(user, service->bot, cmd->command->parent->helpfile, cmd->name); + + /* Show if its an alias, or a binding of another command */ + if (cmd->alias.used) + { + char alias_text[MAXLEN]; + unsplit_string((char**)cmd->alias.list, cmd->alias.used, alias_text); + send_message(user, service->bot, "MCMSG_HELP_COMMAND_ALIAS", alias_text); + /* If send_help above didnt work, try again with the referenced command.. */ + if(!helpsent) + helpsent = send_help(user, service->bot, cmd->command->parent->helpfile, alias_text); + } + else if(cmd->command->name && strcasecmp(cmd->command->name, cmd->name)) + { + send_message(user, service->bot, "MCMSG_HELP_COMMAND_ALIAS", cmd->command->name); + /* If send_help above didnt work, try again with the referenced command.. */ + if(!helpsent) + helpsent = send_help(user, service->bot, cmd->command->parent->helpfile, cmd->command->name); + } + /* If send_help still couldnt find it, tell them sorry */ + if(!helpsent) + send_message(user, service->bot, "MCMSG_HELP_COMMAND_UNKNOWN"); + send_message(user, service->bot, "MCMSG_HELP_FOOTER"); + return true; + } + else /* look for topic in the help files loaded to this nick/service */ + { + /* Check for non command help in first primary help file, then next and so on */ + /* Note - we need to think about default bindings. see opserv.helpfiles */ + for(ii = 0; ii < service->modules.used; ii++) + { + module = service->modules.list[ii]; + if(!module->helpfile) + continue; + if(dict_find(module->helpfile->db, topic, NULL)) + { + if (module->helpfile && dict_find(module->helpfile->db, topic, NULL)) + { + + send_message(user, service->bot, "MCMSG_HELP_TOPIC_HEADER", cmdname); + send_message(user, service->bot, "MCMSG_HELP_DIVIDER"); + /* This should never fail but maybe if something is odd? */ + if(!send_help(user, service->bot, module->helpfile, topic)) + send_message(user, service->bot, "MSG_TOPIC_UNKNOWN"); + send_message(user, service->bot, "MCMSG_HELP_FOOTER"); + return true; + } + } + } } /* Otherwise say we cant find it */ send_message(user, service->bot, "MSG_TOPIC_UNKNOWN"); @@ -931,6 +985,9 @@ modcmd_privmsg(struct userNode *user, struct userNode *bot, char *text, int serv */ snprintf(response, sizeof(response), "\x01VERSION %s\x01", PACKAGE_STRING); irc_notice_user(bot, user, response); + } else if (!irccasecmp(text, "GENDER")) { + snprintf(response, sizeof(response), "\x01GENDER ummm im still deciding\x01"); + irc_notice_user(bot, user, response); } return; } @@ -1042,8 +1099,16 @@ check_alias_args(char *argv[], unsigned int argc) { default: return arg; } - } else - return arg; + } else { + switch(argv[arg][1]) { + case 'a': + case 'n': + case 'm': + continue; + default: + return arg; + } + } } return arg; } @@ -1265,8 +1330,8 @@ static MODCMD_FUNC(cmd_readhelp) { stop.tv_sec -= start.tv_sec; stop.tv_usec -= start.tv_usec; if (stop.tv_usec < 0) { - stop.tv_sec -= 1; - stop.tv_usec += 1000000; + stop.tv_sec -= 1; + stop.tv_usec += 1000000; } reply("MCMSG_HELPFILE_READ", module->name, stop.tv_sec, stop.tv_usec/1000); return 1; @@ -1276,7 +1341,7 @@ static MODCMD_FUNC(cmd_help) { const char *topic; topic = (argc < 2) ? NULL : unsplit_string(argv+1, argc-1, NULL); - return svccmd_send_help_2(user, cmd->parent, topic); + return svccmd_send_help(user, cmd->parent, topic); } static MODCMD_FUNC(cmd_timecmd) { @@ -1290,8 +1355,8 @@ static MODCMD_FUNC(cmd_timecmd) { stop.tv_sec -= start.tv_sec; stop.tv_usec -= start.tv_usec; if (stop.tv_usec < 0) { - stop.tv_sec -= 1; - stop.tv_usec += 1000000; + stop.tv_sec -= 1; + stop.tv_usec += 1000000; } reply("MCMSG_COMMAND_TIME", cmd_text, stop.tv_sec, stop.tv_usec); return 1; @@ -1485,6 +1550,18 @@ static MODCMD_FUNC(cmd_modcmd) { return changed; } +static void +timeout_god(void *data) +{ + extern struct userNode *chanserv; + struct userNode *user = data; + + if(!user || !IsHelping(user)) return; + + HANDLE_CLEAR_FLAG(user->handle_info, HELPING); + send_message(user, chanserv, "MCMSG_GOD_EXPIRED"); +} + static MODCMD_FUNC(cmd_god) { int helping; @@ -1494,26 +1571,28 @@ static MODCMD_FUNC(cmd_god) { reply("MCMSG_ALREADY_HELPING"); return 0; } - helping = 1; + helping = 1; } else if (disabled_string(argv[1])) { if (!HANDLE_FLAGGED(user->handle_info, HELPING)) { reply("MCMSG_ALREADY_NOT_HELPING"); return 0; } - helping = 0; + helping = 0; } else { reply("MSG_INVALID_BINARY", argv[1]); return 0; - } + } } else { helping = !IsHelping(user); } if (helping) { HANDLE_SET_FLAG(user->handle_info, HELPING); + timeq_add(now + god_timeout, timeout_god, user); reply("MCMSG_NOW_HELPING"); } else { HANDLE_CLEAR_FLAG(user->handle_info, HELPING); + timeq_del(0, timeout_god, user, TIMEQ_IGNORE_WHEN); reply("MCMSG_NOW_NOT_HELPING"); } @@ -1907,13 +1986,34 @@ static MODCMD_FUNC(cmd_version) { * command or its accessibility to normal IRC users, except to add * copyright information pertaining to changes you make to X3. */ - send_message_type(4, user, cmd->parent->bot, "$b"PACKAGE_STRING"$b (Based on srvx 1.3), Built: "__DATE__", "__TIME__"."); - send_message_type(4, user, cmd->parent->bot, "("CVS_VERSION")"); - send_message_type(4, user, cmd->parent->bot, "Copyright 2000-2005 srvx Development Team."); - send_message_type(4, user, cmd->parent->bot, "Copyright 2004-2005 X3 Development Team."); - send_message_type(4, user, cmd->parent->bot, "The srvx 1.3 Development Team includes Paul Chang, Adrian Dewhurst, Miles Peterson, Michael Poole and others."); + + char *svn = NULL, *svnver = NULL, *svndate = NULL, *v = 0, ver[MAXLEN]; + int vc = 0; + + strcpy(ver, CVS_VERSION); + for (svn = x3_strtok(&v, ver, " "); svn; + svn = x3_strtok(&v, 0, " ")) { + if (vc == 2) + svnver = svn; + else if (vc == 3) + svndate = svn; + vc++; + } + + send_message_type(4, user, cmd->parent->bot, "$b"PACKAGE_STRING"+[%s %s]$b (Based on srvx 1.3.x), Built: "__DATE__", "__TIME__".", svnver, svndate); + send_message_type(4, user, cmd->parent->bot, "$b$b"); + send_message_type(4, user, cmd->parent->bot, "Copyright 2000-2007 srvx Development Team."); + send_message_type(4, user, cmd->parent->bot, "Copyright 2004-2007 X3 Development Team."); + send_message_type(4, user, cmd->parent->bot, "This software is OSI Certified Open Source Software."); + send_message_type(4, user, cmd->parent->bot, "OSI Certified is a certification mark of the Open Source Initiative."); + send_message_type(4, user, cmd->parent->bot, "$b$b"); + send_message_type(4, user, cmd->parent->bot, "The srvx 1.3.x Development Team includes Paul Chang, Adrian Dewhurst, Miles Peterson, Michael Poole and others."); send_message_type(4, user, cmd->parent->bot, "The X3 Development Team includes Alex Schumann, Reed Loden, Neil Spierling."); - send_message_type(4, user, cmd->parent->bot, "The X3 Development Team can be reached at http://sf.net/projects/x2serv/ or in #evilnet on irc.afternet.org."); + send_message_type(4, user, cmd->parent->bot, "The X3 Development Team can be reached at http://evilnet.sourceforge.net or in #evilnet on irc.afternet.org."); + send_message_type(4, user, cmd->parent->bot, "$b$b"); + send_message_type(4, user, cmd->parent->bot, "Thanks goes to ThiefMaster, Joe Hansche (joeatrr), Martijn Smit (wasted), and to any other people who have contributed to X3."); + send_message_type(4, user, cmd->parent->bot, "This program is free software; see COPYING in the distribution."); + return 1; } @@ -2067,10 +2167,10 @@ modcmd_expand(const char *variable) { exp.type = HF_TABLE; exp.value.table.length = 1; exp.value.table.width = 1; - exp.value.table.flags = TABLE_REPEAT_ROWS; + exp.value.table.flags = TABLE_REPEAT_ROWS | TABLE_NO_HEADERS; exp.value.table.contents = calloc(dict_size(service->commands)+1, sizeof(char**)); exp.value.table.contents[0] = calloc(1, sizeof(char*)); - exp.value.table.contents[0][0] = "Commands:"; + exp.value.table.contents[0][0] = "Commands"; dict_foreach(service->commands, append_entry, &exp); return exp; } else if (!irccasecmp(variable, "languages")) { @@ -2347,6 +2447,7 @@ create_default_binds(int rebind) { { "Global", { "Global", NULL } }, { "NickServ", { "NickServ", NULL } }, { "OpServ", { "OpServ", "modcmd", "sendmail", "saxdb", "proxycheck", NULL } }, + { "SpamServ", { "SpamServ", NULL } }, { NULL, { NULL } } }; unsigned int ii, jj; @@ -2376,19 +2477,19 @@ create_default_binds(int rebind) { /* Now some silly hax.. (aliases that most people want) */ if (!irccasecmp(def_binds[ii].svcname, "ChanServ")) { - service_make_alias(service, "addowner", "*chanserv.adduser", "$1", "owner", NULL); - service_make_alias(service, "addcoowner", "*chanserv.adduser", "$1", "coowner", NULL); - service_make_alias(service, "addco", "*chanserv.adduser", "$1", "coowner", NULL); - service_make_alias(service, "addmanager", "*chanserv.adduser", "$1", "manager", NULL); - service_make_alias(service, "addop", "*chanserv.adduser", "$1", "op", NULL); - service_make_alias(service, "addhop", "*chanserv.adduser", "$1", "halfop", NULL); - service_make_alias(service, "addpeon", "*chanserv.adduser", "$1", "peon", NULL); + service_make_alias(service, "addowner", "*chanserv.adduser", "$1", "owner", "$2", NULL); + service_make_alias(service, "addcoowner", "*chanserv.adduser", "$1", "coowner", "$2", NULL); + service_make_alias(service, "addco", "*chanserv.adduser", "$1", "coowner", "$2", NULL); + service_make_alias(service, "addmanager", "*chanserv.adduser", "$1", "manager", "$2", NULL); + service_make_alias(service, "addop", "*chanserv.adduser", "$1", "op", "$2", NULL); + service_make_alias(service, "addhop", "*chanserv.adduser", "$1", "halfop", "$2", NULL); + service_make_alias(service, "addpeon", "*chanserv.adduser", "$1", "peon", "$2", NULL); service_make_alias(service, "delowner", "*chanserv.deluser", "owner", "$1", NULL); service_make_alias(service, "delcoowner", "*chanserv.deluser", "coowner", "$1", NULL); service_make_alias(service, "delmanager", "*chanserv.deluser", "manager", "$1", NULL); service_make_alias(service, "delop", "*chanserv.deluser", "op", "$1", NULL); service_make_alias(service, "delpeon", "*chanserv.deluser", "peon", "$1", NULL); - service_make_alias(service, "llist", "*chanserv.lamers", "1", "$1", NULL); + service_make_alias(service, "llist", "*chanserv.lamers", "$1", NULL); service_make_alias(service, "command", "*modcmd.command", NULL); service_make_alias(service, "god", "*modcmd.god", NULL); } else if (!irccasecmp(def_binds[ii].svcname, "OpServ")) { @@ -2397,6 +2498,8 @@ create_default_binds(int rebind) { svccmd->min_opserv_level = 101; svccmd = service_make_alias(service, "service", "*modcmd.joiner", NULL); svccmd->min_opserv_level = 900; + svccmd = service_make_alias(service, "routing", "*modcmd.joiner", NULL); + svccmd->min_opserv_level = 100; } } }