/* modcmd.c - Generalized module command support
* Copyright 2002-2004 srvx Development Team
*
- * This file is part of srvx.
+ * This file is part of x3.
*
* srvx is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
+#include "../ChangeLog.X3"
#include "chanserv.h"
#include "conf.h"
#include "modcmd.h"
{ "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", "$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." },
pending_templates = pending;
}
-static struct svccmd *
+struct svccmd *
svccmd_resolve_name(struct svccmd *origin, const char *name) {
char *sep, svcname[MAXLEN];
}
if (argc < cmd->command->min_argc) {
send_message(user, service->bot, "MSG_MISSING_PARAMS", cmd->name);
+ svccmd_send_help_brief(user, service->bot, cmd);
return 0;
}
if (!cmd->command->func) {
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;
}
+/* First line (syntax usually) only help.. used for wrong param counts etc */
int
-svccmd_send_help(struct userNode *user, struct userNode *bot, struct svccmd *cmd) {
- char cmdname[MAXLEN];
- unsigned int nn;
+svccmd_send_help_brief(struct userNode *user, struct userNode *bot, struct svccmd *cmd) {
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 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);
+ 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)
+ {
+ send_message(user, bot, "MCMSG_COMMAND_ALIASES", cmd->name, cmd->command->name);
+ r = send_help_brief(user, bot, cmd->command->parent->helpfile, cmd->command->name);
+ }
}
return r;
}
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 = "<index>";
- /* 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 */
+ if ((cmd = dict_find(service->commands, topic, NULL)))
+ {
+ 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");
irc_notice_user(bot, user, response);
} else if (!irccasecmp(text, "VERSION")) {
/* This function provides copyright management information
- * to end users of srvx. You should not alter, disable or
+ * to end users of X3. You should not alter, disable or
* remove this command or its accessibility to normal IRC
* users, except to add copyright information pertaining
- * to changes you make to srvx.
+ * to changes you make to X3.
*/
- snprintf(response, sizeof(response), "\x01VERSION %s (%s) %s\x01", PACKAGE_STRING, CODENAME, "");
+ 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;
}
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) {
static MODCMD_FUNC(cmd_version) {
/* This function provides copyright management information to end
- * users of srvx. You should not alter, disable or remove this
+ * users of X3. You should not alter, disable or remove this
* command or its accessibility to normal IRC users, except to add
- * copyright information pertaining to changes you make to srvx.
+ * copyright information pertaining to changes you make to X3.
*/
- send_message_type(4, user, cmd->parent->bot, "$b"PACKAGE_STRING"$b ("CODENAME"), Built: "__DATE__", "__TIME__".\nCopyright 2000-2004 srvx Development Team.\nThe srvx Development Team includes Paul Chang, Adrian Dewhurst, Miles Peterson, Michael Poole and others.\nThe srvx Development Team can be reached at http://sf.net/projects/srvx/ or in #srvx on irc.gamesurge.net.");
+ 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.");
+ 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.");
+ return 1;
+}
+
+static void create_default_binds(int rebind);
+
+static MODCMD_FUNC(cmd_rebindall) {
+ send_message_type(4, user, cmd->parent->bot, "$bRe-binding all default commands to respective services..$b");
+ create_default_binds(1);
return 1;
}
modcmd_register(modcmd_module, "service privileged", cmd_service_privileged, 2, 0, "flags", "+oper", NULL);
modcmd_register(modcmd_module, "service remove", cmd_service_remove, 2, 0, "flags", "+oper", NULL);
modcmd_register(modcmd_module, "dumpmessages", cmd_dump_messages, 1, 0, "oper_level", "1000", NULL);
+ modcmd_register(modcmd_module, "rebindall", cmd_rebindall, 0, MODCMD_KEEP_BOUND, "oper_level", "800", NULL);
version_command = modcmd_register(modcmd_module, "version", cmd_version, 1, 0, NULL);
message_register_table(msgtab);
}
}
static void
-create_default_binds(void) {
+create_default_binds(int rebind) {
/* Which services should import which modules by default? */
struct {
const char *svcname;
continue;
if (!(service = service_find(nick)))
continue;
- if (dict_size(service->commands) > 0)
+ if (dict_size(service->commands) > 0 && !rebind)
continue;
/* Bind the default modules for this service to it */
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, "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", 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")) {
/* Check databases. */
saxdb_register("modcmd", modcmd_saxdb_read, modcmd_saxdb_write);
- create_default_binds();
+ create_default_binds(0);
if (!saxdb_present)
import_aliases_db();