]> jfr.im git - irc/evilnet/x3.git/blobdiff - src/modcmd.c
About time I added myself to the credits
[irc/evilnet/x3.git] / src / modcmd.c
index bc0d365a397868072b2f0fc005207873c1d5d2f7..6800e1afc5d9a53dc169f152928ecf57db720f13 100644 (file)
@@ -1,11 +1,11 @@
 /* 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
+ * 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
+ * the Free Software Foundation; either version 3 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
  */
 
-//#include "arch-version.h"
 #include "chanserv.h"
 #include "conf.h"
+#include "compat.h"
 #include "modcmd.h"
+#include "opserv.h"
 #include "saxdb.h"
+#include "timeq.h"
+#include "version.h"
+
 
 struct pending_template {
     struct svccmd *cmd;
@@ -30,11 +34,12 @@ 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;
 static struct module *modcmd_module;
-static struct modcmd *bind_command, *help_command, *version_command;
+static struct modcmd *bind_command, *help_command, *version_command, *credits_command;
 static const struct message_entry msgtab[] = {
     { "MCMSG_BARE_FLAG", "Flag %.*s must be preceded by a + or -." },
     { "MCMSG_UNKNOWN_FLAG", "Unknown module flag %.*s." },
@@ -56,6 +61,11 @@ static const struct message_entry msgtab[] = {
     { "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." },
@@ -125,6 +135,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);
@@ -139,25 +150,25 @@ struct userData *_GetChannelUser(struct chanData *channel, struct handle_info *h
 static struct modcmd_flag {
     const char *name;
     unsigned int flag;
-} flags[] = {
+} modcmd_flags[] = {
     { "acceptchan", MODCMD_ACCEPT_CHANNEL },
     { "acceptpluschan", MODCMD_ACCEPT_PCHANNEL },
     { "authed", MODCMD_REQUIRE_AUTHED },
     { "channel", MODCMD_REQUIRE_CHANNEL },
     { "chanuser", MODCMD_REQUIRE_CHANUSER },
     { "disabled", MODCMD_DISABLED },
+    { "helping", MODCMD_REQUIRE_HELPING },
     { "ignore_csuspend", MODCMD_IGNORE_CSUSPEND },
     { "joinable", MODCMD_REQUIRE_JOINABLE },
     { "keepbound", MODCMD_KEEP_BOUND },
     { "loghostmask", MODCMD_LOG_HOSTMASK },
-    { "nolog", MODCMD_NO_LOG },
     { "networkhelper", MODCMD_REQUIRE_NETWORK_HELPER },
     { "never_csuspend", MODCMD_NEVER_CSUSPEND },
+    { "nolog", MODCMD_NO_LOG },
     { "oper", MODCMD_REQUIRE_OPER },
     { "qualified", MODCMD_REQUIRE_QUALIFIED },
     { "regchan", MODCMD_REQUIRE_REGCHAN },
     { "supporthelper", MODCMD_REQUIRE_SUPPORT_HELPER },
-    { "helping", MODCMD_REQUIRE_HELPING },
     { "toy", MODCMD_TOY },
     { NULL, 0 }
 };
@@ -175,8 +186,8 @@ flags_qsort(const void *a, const void *b) {
     return irccasecmp(fa->name, fb->name);
 }
 
-DEFINE_LIST(svccmd_list, struct svccmd*);
-DEFINE_LIST(module_list, struct module*);
+DEFINE_LIST(svccmd_list, struct svccmd*)
+DEFINE_LIST(module_list, struct module*)
 
 static void
 free_service_command(void *data) {
@@ -250,7 +261,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];
 
@@ -325,7 +336,7 @@ svccmd_configure(struct svccmd *cmd, struct userNode *user, struct userNode *bot
                 return 0;
             }
             value++;
-            flag = bsearch(value, flags, ArrayLength(flags)-1, sizeof(flags[0]), flags_bsearch);
+            flag = bsearch(value, modcmd_flags, ArrayLength(modcmd_flags)-1, sizeof(modcmd_flags[0]), flags_bsearch);
             if (!flag) {
                 if (user)
                     send_message(user, bot, "MCMSG_UNKNOWN_FLAG", end, value);
@@ -435,6 +446,7 @@ modcmd_register(struct module *module, const char *name, modcmd_func_t func, uns
  */
 int
 svccmd_can_invoke(struct userNode *user, struct userNode *bot, struct svccmd *cmd, struct chanNode *channel, int options) {
+    extern struct userNode *chanserv;
     unsigned int uData_checked = 0;
     struct userData *uData = NULL;
     int rflags = 0, flags = cmd->effective_flags;
@@ -468,15 +480,17 @@ svccmd_can_invoke(struct userNode *user, struct userNode *bot, struct svccmd *cm
             return 0;
         }
         if (flags & MODCMD_REQUIRE_REGCHAN) {
-            if (!channel->channel_info) {
+            if (!chanserv) {
+                /* Just use the inferred MODCMD_REQUIRE_CHANNEL. */
+            } else if (!channel->channel_info) {
                 if (options & SVCCMD_NOISY)
                     send_message(user, bot, "MCMSG_CHAN_NOT_REGISTERED", channel->name);
                 return 0;
             } else if (IsSuspended(channel->channel_info) && !(flags & MODCMD_IGNORE_CSUSPEND)) {
-                /* allow security-override users to always ignore channel suspensions, but flag it as a staff command */
-                if (!user->handle_info
-                    || !HANDLE_FLAGGED(user->handle_info, HELPING)
-                    || (flags & MODCMD_NEVER_CSUSPEND)) {
+                /* Allow security-override users to ignore most channel
+                 * suspensions, but flag that use as a staff command.
+                 */
+                if (!IsHelping(user) || (flags & MODCMD_NEVER_CSUSPEND)) {
                     if (options & SVCCMD_NOISY)
                         send_message(user, bot, "MCMSG_CHAN_SUSPENDED", channel->name, channel->channel_info->suspended->reason);
                     return 0;
@@ -487,7 +501,9 @@ svccmd_can_invoke(struct userNode *user, struct userNode *bot, struct svccmd *cm
         if (flags & MODCMD_REQUIRE_CHANUSER) {
             if (!uData_checked)
                 uData = _GetChannelUser(channel->channel_info, user->handle_info, 1, 0), uData_checked = 1;
-            if (!uData) {
+            if (!chanserv) {
+                /* Assume someone knows what they're doing. */
+            } else if (!uData) {
                 if (options & SVCCMD_NOISY)
                     send_message(user, bot, "MCMSG_NO_CHANNEL_ACCESS", channel->name);
                 return 0;
@@ -546,7 +562,8 @@ svccmd_can_invoke(struct userNode *user, struct userNode *bot, struct svccmd *cm
         rflags |= ACTION_STAFF;
     }
     if (cmd->min_opserv_level > 0) {
-        if (!oper_has_access(user, bot, cmd->min_opserv_level, !(options & SVCCMD_NOISY))) return 0;
+        if (!oper_has_access(user, bot, cmd->min_opserv_level, !(options & SVCCMD_NOISY)))
+          return 0;
         rflags |= ACTION_STAFF;
     }
     if (cmd->req_account_flags || cmd->deny_account_flags) {
@@ -567,7 +584,7 @@ svccmd_can_invoke(struct userNode *user, struct userNode *bot, struct svccmd *cm
     /* If it's an override, return a special value. */
     if ((flags & MODCMD_REQUIRE_CHANUSER)
         && (options & SVCCMD_NOISY)
-        && (uData->access > 500)
+        && (!uData || (uData->access > 500))
         && (!(uData = _GetChannelUser(channel->channel_info, user->handle_info, 0, 0))
             || uData->access < cmd->min_channel_access)
         && !(flags & (MODCMD_REQUIRE_STAFF|MODCMD_REQUIRE_HELPING))) {
@@ -577,11 +594,12 @@ 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;
+    char *arg, *altarg;
 
     for (ii=new_argc=0; ii<cmd->alias.used; ++ii) {
+        altarg = NULL;
         arg = cmd->alias.list[ii];
         if (arg[0] != '$') {
             new_argv[new_argc++] = arg;
@@ -590,12 +608,27 @@ svccmd_expand_alias(struct svccmd *cmd, unsigned int old_argc, char *old_argv[],
         if (arg[1] == '$') {
             new_argv[new_argc++] = arg + 1;
         } else if (isdigit(arg[1])) {
-            unsigned int lbound, ubound, jj;
+            unsigned int lbound = 0;
+            unsigned int ubound = 0;
+            unsigned int jj = 0;
             char *end_num;
 
             lbound = strtoul(arg+1, &end_num, 10);
             switch (end_num[0]) {
             case 0: ubound = lbound; break;
+            case 'a':
+                altarg = (user && user->handle_info) ? user->handle_info->handle : "(account)";
+                break;
+            case 'n':
+                altarg = user ? user->nick : "(nick)";
+                break;
+            case 'm':
+#ifdef WITH_PROTOCOL_P10
+                altarg = user ? user->numeric : "(numnick)";
+#else
+                altarg = "(This ircd protocol has no numnicks!)";
+#endif
+                break;
             case '-':
                 if (end_num[1] == 0) {
                     ubound = old_argc - 1;
@@ -609,14 +642,46 @@ svccmd_expand_alias(struct svccmd *cmd, unsigned int old_argc, char *old_argv[],
                 log_module(MAIN_LOG, LOG_ERROR, "Alias expansion parse error in %s (near %s; %s.%s arg %d).", arg, end_num, cmd->parent->bot->nick, cmd->name, ii);
                 return 0;
             }
+            if (altarg != NULL) {
+                if (end_num[1] != 0) {
+                    if ((end_num[1] == '-') && (end_num[2] == 0))
+                        ubound = old_argc - 1;
+                    else if ((end_num[1] == '-') && (isdigit(end_num[2])))
+                        ubound = strtoul(end_num+2, NULL, 10);
+                    else {
+                        log_module(MAIN_LOG, LOG_ERROR, "Alias expansion parse error in %s (near %s; %s.%s arg %d).", arg, end_num, cmd->parent->bot->nick, cmd->name, ii);
+                        return 0;
+                    }
+                } else {
+                    ubound = lbound;
+                }
+                if (lbound >= old_argc)
+                    new_argv[new_argc++] = altarg;
+            }
             if (ubound >= old_argc)
                 ubound = old_argc - 1;
             if (lbound < old_argc)
                 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;
@@ -626,15 +691,9 @@ int
 svccmd_invoke_argv(struct userNode *user, struct service *service, struct chanNode *channel, unsigned int argc, char *argv[], unsigned int server_qualified) {
     extern struct userNode *chanserv;
     struct svccmd *cmd;
-    unsigned int cmd_arg, perms, flags, options;
+    unsigned int cmd_arg, perms, flags, options, result;
     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;
-    }
+    char *new_argv[MAXNUMPARAMS]; /* for aliases */
 
     options = (server_qualified ? SVCCMD_QUALIFIED : 0) | SVCCMD_DEBIT | SVCCMD_NOISY;
     /* Find the command argument. */
@@ -653,6 +712,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.
@@ -690,12 +757,17 @@ 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);
-        if (!argc) {
-            send_message(service->bot, user, "MCMSG_ALIAS_ERROR", cmd->name);
+        int res;
+
+        res = svccmd_expand_alias(cmd, user, argc, argv, new_argv);
+        if (res < 0) {
+            send_message(user, service->bot, "MSG_MISSING_PARAMS", cmd->name);
+            return 0;
+        } else if (res == 0) {
+            send_message(user, service->bot, "MCMSG_ALIAS_ERROR", cmd->name);
             return 0;
         }
+        argc = res;
         argv = new_argv;
 
         /* Try again to grab a handle to the channel after alias
@@ -720,6 +792,7 @@ svccmd_invoke_argv(struct userNode *user, struct service *service, struct chanNo
     }
     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) {
@@ -737,11 +810,16 @@ svccmd_invoke_argv(struct userNode *user, struct service *service, struct chanNo
         safestrncpy(channel_name, channel->name, sizeof(channel_name));
     else
         channel_name[0] = 0;
-    if (!cmd->command->func(user, channel, argc, argv, cmd))
+
+    /* Call the function here */
+    if (!(result = cmd->command->func(user, channel, argc, argv, cmd))) 
         return 0;
+
     if (!(flags & MODCMD_NO_LOG)) {
         enum log_severity slvl;
-        if (perms & ACTION_STAFF)
+        if (result & CMD_LOG_OVERRIDE)
+            slvl = LOG_OVERRIDE;
+        else if ((perms & ACTION_STAFF) || (result & CMD_LOG_STAFF))
             slvl = LOG_STAFF;
         else if (perms & ACTION_OVERRIDE)
             slvl = LOG_OVERRIDE;
@@ -749,59 +827,127 @@ 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;
 }
 
+/* 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 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 = "<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 (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");
@@ -809,9 +955,10 @@ svccmd_send_help_2(struct userNode *user, struct service *service, const char *t
 }
 
 static int
-svccmd_invoke(struct userNode *user, struct service *service, struct chanNode *channel, char *text, int server_qualified) {
+svccmd_invoke(struct userNode *user, struct service *service, struct chanNode *channel, const char *text, int server_qualified) {
     unsigned int argc;
     char *argv[MAXNUMPARAMS];
+    char tmpline[MAXLEN];
 
     if (!*text)
         return 0;
@@ -829,12 +976,13 @@ svccmd_invoke(struct userNode *user, struct service *service, struct chanNode *c
             return 0;
         }
     }
-    argc = split_line(text, false, ArrayLength(argv), argv);
+    safestrncpy(tmpline, text, sizeof(tmpline));
+    argc = split_line(tmpline, false, ArrayLength(argv), argv);
     return argc ? svccmd_invoke_argv(user, service, channel, argc, argv, server_qualified) : 0;
 }
 
 void
-modcmd_privmsg(struct userNode *user, struct userNode *bot, char *text, int server_qualified) {
+modcmd_privmsg(struct userNode *user, struct userNode *bot, const char *text, int server_qualified) {
     struct service *service;
 
     if (!(service = dict_find(services, bot->nick, NULL))) {
@@ -867,10 +1015,10 @@ modcmd_privmsg(struct userNode *user, struct userNode *bot, char *text, int serv
             irc_notice_user(bot, user, "\001CLIENTINFO CLIENTINFO PING TIME USERINFO VERSION\x01");
         } else if (!irccasecmp(text, "PING")) {
             if (term) {
-                snprintf(response, sizeof(response), "\x01PONG %s\x01", term);
+                snprintf(response, sizeof(response), "\x01PING %s\x01", term);
                 irc_notice_user(bot, user, response);
             } else {
-                irc_notice_user(bot,user, "\x01PONG\x01");
+                irc_notice_user(bot,user, "\x01PING\x01");
             }
         } else if (!irccasecmp(text, "TIME")) {
             struct tm tm;
@@ -881,14 +1029,11 @@ modcmd_privmsg(struct userNode *user, struct userNode *bot, char *text, int serv
             snprintf(response, sizeof(response), "\x01USERINFO %s\x01", bot->info);
             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
-             * remove this command or its accessibility to normal IRC
-             * users, except to add copyright information pertaining
-             * to changes you make to srvx.
-             */
-            snprintf(response, sizeof(response), "\x01VERSION %s (%s) %s\x01", PACKAGE_STRING, CODENAME, "");
+            snprintf(response, sizeof(response), "\x01VERSION %s+[%s]\x01", PACKAGE_STRING, cvs_version);
             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;
     }
@@ -899,10 +1044,12 @@ modcmd_privmsg(struct userNode *user, struct userNode *bot, char *text, int serv
 }
 
 void
-modcmd_chanmsg(struct userNode *user, struct chanNode *chan, char *text, struct userNode *bot) {
+modcmd_chanmsg(struct userNode *user, struct chanNode *chan, const char *text, struct userNode *bot, unsigned int is_notice, UNUSED_ARG(void *extra)) {
     struct service *service;
-    if (!(service = dict_find(services, bot->nick, NULL))) return;
+    if (!(service = dict_find(services, bot->nick, NULL)))
+        return;
     svccmd_invoke(user, service, chan, text, 0);
+    (void)is_notice;
 }
 
 struct service *
@@ -986,11 +1133,21 @@ check_alias_args(char *argv[], unsigned int argc) {
             continue;
         } else if (isdigit(argv[arg][1])) {
             char *end_num;
+            unsigned long tmp;
 
-            strtoul(argv[arg]+1, &end_num, 10);
+            tmp = strtoul(argv[arg]+1, &end_num, 10);
             switch (end_num[0]) {
             case 0:
                 continue;
+            case 'a':
+            case 'n':
+            case 'm':
+                if (end_num[1] == 0)
+                    continue;
+                else if (end_num[1] == '-')
+                    end_num++;
+                else
+                    return arg;
             case '-':
                 if (end_num[1] == 0)
                     continue;
@@ -1000,8 +1157,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;
 }
@@ -1135,20 +1300,24 @@ service_recheck_bindings(struct service *service, struct module *module) {
 }
 
 static svccmd_unbind_func_t *suf_list;
+static void **suf_list_extra;
 unsigned int suf_size, suf_used;
 
 void
-reg_svccmd_unbind_func(svccmd_unbind_func_t handler) {
+reg_svccmd_unbind_func(svccmd_unbind_func_t handler, void *extra) {
     if (suf_used == suf_size) {
         if (suf_size) {
             suf_size <<= 1;
             suf_list = realloc(suf_list, suf_size*sizeof(svccmd_unbind_func_t));
+            suf_list_extra = realloc(suf_list_extra, suf_size*sizeof(void*));
         } else {
             suf_size = 8;
             suf_list = malloc(suf_size*sizeof(svccmd_unbind_func_t));
+            suf_list_extra = malloc(suf_size*sizeof(void*));
         }
     }
-    suf_list[suf_used++] = handler;
+    suf_list[suf_used] = handler;
+    suf_list_extra[suf_used++] = extra;
 }
 
 static MODCMD_FUNC(cmd_unbind) {
@@ -1181,7 +1350,7 @@ static MODCMD_FUNC(cmd_unbind) {
     }
 
     for (ii=0; ii<suf_used; ii++)
-        suf_list[ii](bound);
+        suf_list[ii](bound, suf_list_extra[ii]);
     /* If this command binding is removing itself, we must take care
      * not to dereference it after the dict_remove.
      */
@@ -1223,8 +1392,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;
@@ -1234,7 +1403,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) {
@@ -1248,8 +1417,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;
@@ -1380,18 +1549,19 @@ modcmd_describe_command(struct userNode *user, struct svccmd *cmd, struct svccmd
         snprintf(buf1, sizeof(buf1), "%s.%s", target->command->parent->name, target->command->name);
         reply("MCMSG_COMMAND_BINDING", target->name, buf1);
     }
-    for (ii = buf1_used = buf2_used = 0; flags[ii].name; ++ii) {
-        if (target->flags & flags[ii].flag) {
+    for (ii = buf1_used = buf2_used = 0; modcmd_flags[ii].name; ++ii) {
+        const struct modcmd_flag *flag = &modcmd_flags[ii];
+        if (target->flags & flag->flag) {
             if (buf1_used)
                 buf1[buf1_used++] = ',';
-            len = strlen(flags[ii].name);
-            memcpy(buf1 + buf1_used, flags[ii].name, len);
+            len = strlen(flag->name);
+            memcpy(buf1 + buf1_used, flag->name, len);
             buf1_used += len;
-        } else if (target->effective_flags & flags[ii].flag) {
+        } else if (target->effective_flags & flag->flag) {
             if (buf2_used)
                 buf2[buf2_used++] = ',';
-            len = strlen(flags[ii].name);
-            memcpy(buf2 + buf2_used, flags[ii].name, len);
+            len = strlen(flag->name);
+            memcpy(buf2 + buf2_used, flag->name, len);
             buf2_used += len;
         }
     }
@@ -1443,6 +1613,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;
 
@@ -1452,26 +1634,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");
     }
 
@@ -1479,7 +1663,7 @@ static MODCMD_FUNC(cmd_god) {
 }
 
 static MODCMD_FUNC(cmd_joiner) {
-    char cmdname[80];
+    char cmdname[MAXLEN];
 
     if (argc < 2) {
         int len = sprintf(cmdname, "%s ", cmd->name);
@@ -1680,20 +1864,20 @@ static MODCMD_FUNC(cmd_showcommands) {
         if (show_opserv_level)
             tbl.contents[ii+1][1] = strtab(svccmd->min_opserv_level);
         if (show_channel_access) {
-            const char *access;
+            const char *access_name;
             int flags = svccmd->effective_flags;
             if (flags & MODCMD_REQUIRE_HELPING)
-                access = "helping";
+                access_name = "helping";
             else if (flags & MODCMD_REQUIRE_STAFF) {
-                switch (flags & MODCMD_REQUIRE_STAFF) {
-                case MODCMD_REQUIRE_OPER: access = "oper"; break;
-                case MODCMD_REQUIRE_OPER | MODCMD_REQUIRE_NETWORK_HELPER:
-                case MODCMD_REQUIRE_NETWORK_HELPER: access = "net.helper"; break;
-                default: access = "staff"; break;
-                }
+                if (flags & MODCMD_REQUIRE_OPER)
+                    access_name = "oper";
+                else if (flags & MODCMD_REQUIRE_NETWORK_HELPER)
+                    access_name = "net.helper";
+                else
+                    access_name = "staff";
             } else
-                access = strtab(svccmd->min_channel_access);
-            tbl.contents[ii+1][1+show_opserv_level] = access;
+                access_name = strtab(svccmd->min_channel_access);
+            tbl.contents[ii+1][1+show_opserv_level] = access_name;
         }
     }
     svccmd_list_clean(&commands);
@@ -1745,7 +1929,7 @@ static MODCMD_FUNC(cmd_service_add) {
         reply("MCMSG_ALREADY_SERVICE", bot->nick);
         return 0;
     }
-    bot = AddService(nick, desc, hostname);
+    bot = AddLocalUser(nick, nick, hostname, desc, NULL);
     service_register(bot);
     reply("MCMSG_NEW_SERVICE", bot->nick);
     return 1;
@@ -1779,7 +1963,7 @@ static MODCMD_FUNC(cmd_service_trigger) {
         return 1;
     }
     if (service->trigger)
-        reg_chanmsg_func(service->trigger, NULL, NULL);
+        reg_chanmsg_func(service->trigger, NULL, NULL, NULL);
     if (!irccasecmp(argv[2], "none") || !irccasecmp(argv[2], "remove")) {
         service->trigger = 0;
         reply("MCMSG_REMOVED_TRIGGER", service->bot->nick);
@@ -1788,7 +1972,7 @@ static MODCMD_FUNC(cmd_service_trigger) {
         return 1;
     } else {
         service->trigger = argv[2][0];
-        reg_chanmsg_func(service->trigger, service->bot, modcmd_chanmsg);
+        reg_chanmsg_func(service->trigger, service->bot, modcmd_chanmsg, NULL);
         reply("MCMSG_NEW_TRIGGER", service->bot->nick, service->trigger);
     }
     return 1;
@@ -1843,37 +2027,72 @@ static MODCMD_FUNC(cmd_dump_messages) {
         reply("MSG_INTERNAL_FAILURE");
         return 0;
     }
-    if ((res = setjmp(ctx->jbuf)) != 0) {
-        ctx->complex.used = 0; /* to avoid false assert()s in close */
-        saxdb_close_context(ctx);
-        fclose(pf);
+
+    if ((res = setjmp(*saxdb_jmp_buf(ctx))) != 0) {
+        saxdb_close_context(ctx, 1);
         reply("MCMSG_MESSAGE_DUMP_FAILED", strerror(res));
         return 0;
     } else {
         for (it = dict_first(lang_C->messages); it; it = iter_next(it))
             saxdb_write_string(ctx, iter_key(it), iter_data(it));
-        saxdb_close_context(ctx);
-        fclose(pf);
+        saxdb_close_context(ctx, 1);
         reply("MCMSG_MESSAGES_DUMPED", fname);
         return 1;
     }
 }
 
 static MODCMD_FUNC(cmd_version) {
-    /* This function provides copyright management information to end
-     * users of srvx. 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.
-     */
-    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.");
-    if ((argc > 1) && !irccasecmp(argv[1], "arch"))
-        send_message_type(4, user, cmd->parent->bot, "%s", "");
+    send_message_type(4, user, cmd->parent->bot, "$b"PACKAGE_STRING"+[%s]$b (Based on srvx 1.3.x), Built: "__DATE__", "__TIME__".", cvs_version);
+    send_message_type(4, user, cmd->parent->bot, "See $bCREDITS$b for more information.");
+    return 1;
+}
+
+/* This function provides copyright management information 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 X3.
+ */
+static MODCMD_FUNC(cmd_credits) {
+    send_message_type(4, user, cmd->parent->bot, "$b"PACKAGE"$b is based on srvx");
+    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, Matthew Beeching.");
+    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 files.");
+
     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;
+}
+
+static MODCMD_FUNC(cmd_tell) {
+    struct userNode *target;
+    char *msg;
+
+    target = GetUserH(argv[1]);
+    msg = unsplit_string(argv + 2, argc - 2, NULL);
+    if (!target) {
+        reply("MSG_NOT_TARGET_NAME");
+        return 0;
+    }
+    send_message_type(MSG_TYPE_NOXLATE, target, cmd->parent->bot, "%s", msg);
+    return 1;
+}
 
 void
-modcmd_nick_change(struct userNode *user, const char *old_nick) {
+modcmd_nick_change(struct userNode *user, const char *old_nick, UNUSED_ARG(void *extra)) {
     struct service *svc;
     if (!(svc = dict_find(services, old_nick, NULL)))
         return;
@@ -1882,11 +2101,13 @@ modcmd_nick_change(struct userNode *user, const char *old_nick) {
 }
 
 void
-modcmd_cleanup(void) {
+modcmd_cleanup(UNUSED_ARG(void* extra)) {
     dict_delete(services);
     dict_delete(modules);
     if (suf_list)
         free(suf_list);
+    if (suf_list_extra)
+        free(suf_list_extra);
 }
 
 static void
@@ -1906,11 +2127,12 @@ modcmd_saxdb_write_command(struct saxdb_context *ctx, struct svccmd *cmd) {
         saxdb_write_int(ctx, "channel_access", cmd->min_channel_access);
     if (cmd->flags != template->flags) {
         if (cmd->flags) {
-            for (nn=pos=0; flags[nn].name; ++nn) {
-                if (cmd->flags & flags[nn].flag) {
+            for (nn=pos=0; modcmd_flags[nn].name; ++nn) {
+                const struct modcmd_flag *flag = &modcmd_flags[nn];
+                if (cmd->flags & flag->flag) {
                     buf[pos++] = '+';
-                    len = strlen(flags[nn].name);
-                    memcpy(buf+pos, flags[nn].name, len);
+                    len = strlen(flag->name);
+                    memcpy(buf+pos, flag->name, len);
                     pos += len;
                     buf[pos++] = ',';
                 }
@@ -1952,6 +2174,8 @@ modcmd_saxdb_write(struct saxdb_context *ctx) {
     saxdb_start_record(ctx, "bots", 1);
     for (it = dict_first(services); it; it = iter_next(it)) {
         char buff[16];
+        char modes[32];
+
         service = iter_data(it);
         saxdb_start_record(ctx, service->bot->nick, 1);
         if (service->trigger) {
@@ -1961,6 +2185,10 @@ modcmd_saxdb_write(struct saxdb_context *ctx) {
         }
         saxdb_write_string(ctx, "description", service->bot->info);
         saxdb_write_string(ctx, "hostname", service->bot->hostname);
+        if (service->bot->modes) {
+            irc_user_modes(service->bot, modes, sizeof(modes));
+            saxdb_write_string(ctx, "modes", modes);
+        }
         if (service->privileged)
             saxdb_write_string(ctx, "privileged", "1");
         saxdb_end_record(ctx);
@@ -2013,10 +2241,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")) {
@@ -2045,7 +2273,7 @@ modcmd_load_bots(struct dict *db, int default_nick) {
     for (it = dict_first(db); it; it = iter_next(it)) {
         struct record_data *rd;
         struct service *svc;
-        const char *nick, *desc, *hostname;
+        const char *nick, *desc, *hostname, *modes;
 
         rd = iter_data(it);
         if (rd->type != RECDB_OBJECT) {
@@ -2062,9 +2290,10 @@ modcmd_load_bots(struct dict *db, int default_nick) {
         svc = service_find(nick);
         desc = database_get_data(rd->d.object, "description", RECDB_QSTRING);
         hostname = database_get_data(rd->d.object, "hostname", RECDB_QSTRING);
+        modes = database_get_data(rd->d.object, "modes", RECDB_QSTRING);
         if (desc) {
             if (!svc)
-                svc = service_register(AddService(nick, desc, hostname));
+                svc = service_register(AddLocalUser(nick, nick, hostname, desc, modes));
             else if (hostname)
                 strcpy(svc->bot->hostname, hostname);
             desc = database_get_data(rd->d.object, "trigger", RECDB_QSTRING);
@@ -2084,13 +2313,13 @@ modcmd_conf_read(void) {
 
 void
 modcmd_init(void) {
-    qsort(flags, ArrayLength(flags)-1, sizeof(flags[0]), flags_qsort);
+    qsort(modcmd_flags, ArrayLength(modcmd_flags)-1, sizeof(modcmd_flags[0]), flags_qsort);
     modules = dict_new();
     dict_set_free_data(modules, free_module);
     services = dict_new();
     dict_set_free_data(services, free_service);
-    reg_nick_change_func(modcmd_nick_change);
-    reg_exit_func(modcmd_cleanup);
+    reg_nick_change_func(modcmd_nick_change, NULL);
+    reg_exit_func(modcmd_cleanup, NULL);
     conf_register_reload(modcmd_conf_read);
 
     modcmd_module = module_register("modcmd", MAIN_LOG, "modcmd.help", modcmd_expand);
@@ -2113,8 +2342,12 @@ modcmd_init(void) {
     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, "tell", cmd_tell, 3, 0, "flags", "+oper", 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);
+    credits_command = modcmd_register(modcmd_module, "credits", cmd_credits, 1, 0, NULL);
     message_register_table(msgtab);
+
 }
 
 static void
@@ -2278,7 +2511,7 @@ modcmd_saxdb_read(struct dict *db) {
 }
 
 static void
-create_default_binds(void) {
+create_default_binds(int rebind) {
     /* Which services should import which modules by default? */
     struct {
         const char *svcname;
@@ -2292,6 +2525,7 @@ create_default_binds(void) {
         { "Global", { "Global", NULL } },
         { "NickServ", { "NickServ", NULL } },
         { "OpServ", { "OpServ", "modcmd", "sendmail", "saxdb", "proxycheck", NULL } },
+        { "SpamServ", { "SpamServ", NULL } },
         { NULL, { NULL } }
     };
     unsigned int ii, jj;
@@ -2305,7 +2539,7 @@ create_default_binds(void) {
             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 */
@@ -2318,19 +2552,25 @@ create_default_binds(void) {
         /* Bind the help and version commands to this service */
         service_bind_modcmd(service, help_command, help_command->name);
         service_bind_modcmd(service, version_command, version_command->name);
+        service_bind_modcmd(service, credits_command, credits_command->name);
 
         /* 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, "addmanager", "*chanserv.adduser", "$1", "manager", NULL);
-            service_make_alias(service, "addop", "*chanserv.adduser", "$1", "op", 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, "addpal", "*chanserv.adduser", "$1", "pal", "$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, "delpal", "*chanserv.deluser", "pal", "$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")) {
@@ -2339,6 +2579,8 @@ create_default_binds(void) {
             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;
         }
     }
 }
@@ -2380,7 +2622,7 @@ modcmd_finalize(void) {
 
     /* Check databases. */
     saxdb_register("modcmd", modcmd_saxdb_read, modcmd_saxdb_write);
-    create_default_binds();
+    create_default_binds(0);
     if (!saxdb_present)
         import_aliases_db();
 
@@ -2388,7 +2630,7 @@ modcmd_finalize(void) {
     for (it = dict_first(services); it; it = iter_next(it)) {
         struct service *svc = iter_data(it);
         if (svc->trigger)
-            reg_chanmsg_func(svc->trigger, svc->bot, modcmd_chanmsg);
+            reg_chanmsg_func(svc->trigger, svc->bot, modcmd_chanmsg, NULL);
     }
 
     /* Resolve command rule-templates. */