License update
[srvx.git] / src / modcmd.c
index 834efabe31c51a94f201f1efc3bd6c32e526b3aa..f8d02055abfe142f01ca49ddd16b801d23209094 100644 (file)
@@ -1,11 +1,12 @@
 /* modcmd.c - Generalized module command support
  * Copyright 2002-2004 srvx Development Team
  *
- * This program is free software; you can redistribute it and/or modify
+ * This file is part of srvx.
+ *
+ * srvx 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.  Important limitations are
- * listed in the COPYING file that accompanies this software.
+ * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -13,7 +14,8 @@
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with this program; if not, email srvx-maintainers@srvx.net.
+ * along with srvx; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
  */
 
 #include "arch-version.h"
@@ -32,7 +34,7 @@ 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;
+static struct modcmd *bind_command, *help_command, *version_command;
 static const struct message_entry msgtab[] = {
     { "MCMSG_VERSION", "$b"PACKAGE_STRING"$b ("CODENAME"), Built: " __DATE__ ", " __TIME__"." },
     { "MCMSG_BARE_FLAG", "Flag %.*s must be preceeded by a + or -." },
@@ -114,6 +116,7 @@ static const struct message_entry msgtab[] = {
     { "MCMSG_DUPLICATE_TRIGGER", "$b%s$b already uses trigger $b%c$b." },
     { "MCMSG_CURRENT_TRIGGER", "Trigger for $b%s$b is $b%c$b." },
     { "MCMSG_NEW_TRIGGER", "Changed trigger for $b%s$b to $b%c$b." },
+    { "MCMSG_SERVICE_PRIVILEGED", "Service $b%s$b privileged: $b%s$b." },
     { "MCMSG_SERVICE_REMOVED", "Service $b%s$b has been deleted." },
     { "MCMSG_FILE_NOT_OPENED", "Unable to open file $b%s$b for writing." },
     { "MCMSG_MESSAGES_DUMPED", "Messages written to $b%s$b." },
@@ -336,7 +339,7 @@ svccmd_configure(struct svccmd *cmd, struct userNode *user, struct userNode *bot
         return 1;
     } else if (!irccasecmp(param, "channel_level") || !irccasecmp(param, "channel_access") || !irccasecmp(param, "access")) {
         unsigned short ul;
-        if (!irccasecmp(value, "none")) {
+        if (!irccasecmp(value, "none") || !irccasecmp(value, "0")) {
             cmd->min_channel_access = 0;
             return 1;
         } else if ((ul = user_level_from_name(value, UL_OWNER)) > 0) {
@@ -641,7 +644,8 @@ svccmd_invoke_argv(struct userNode *user, struct service *service, struct chanNo
     }
     cmd = dict_find(service->commands, argv[cmd_arg], NULL);
     if (!cmd) {
-        send_message(user, service->bot, "MSG_COMMAND_UNKNOWN", argv[cmd_arg]);
+        if (!channel)
+            send_message(user, service->bot, "MSG_COMMAND_UNKNOWN", argv[cmd_arg]);
         return 0;
     }
     flags = cmd->effective_flags;
@@ -1519,7 +1523,8 @@ static MODCMD_FUNC(cmd_showcommands) {
 
     /* Find the matching commands. */
     svccmd_list_init(&commands);
-    if (cmd->parent->privileged) ignore_flags = MODCMD_REQUIRE_OPER;
+    if (cmd->parent->privileged)
+        ignore_flags = MODCMD_REQUIRE_OPER;
     for (it = dict_first(cmd->parent->commands); it; it = iter_next(it)) {
         svccmd = iter_data(it);
         if (strchr(svccmd->name, ' '))
@@ -1673,6 +1678,21 @@ static MODCMD_FUNC(cmd_service_trigger) {
     return 1;
 }
 
+static MODCMD_FUNC(cmd_service_privileged) {
+    struct service *service;
+    const char *newval;
+
+    if (!(service = service_find(argv[1]))) {
+        reply("MCMSG_UNKNOWN_SERVICE", argv[1]);
+        return 0;
+    }
+    if (argc >= 3)
+        service->privileged = true_string(argv[2]) || enabled_string(argv[2]);
+    newval = user_find_message(user, service->privileged ? "MSG_ON" : "MSG_OFF");
+    reply("MCMSG_SERVICE_PRIVILEGED", service->bot->nick, newval);
+    return 1;
+}
+
 static MODCMD_FUNC(cmd_service_remove) {
     char *name, *reason;
     struct service *service;
@@ -1716,7 +1736,7 @@ static MODCMD_FUNC(cmd_dump_messages) {
 
 static MODCMD_FUNC(cmd_version) {
     reply("MCMSG_VERSION");
-    send_message_type(4, user, cmd->parent->bot, "Copyright 2000-2004 srvx Development Team.\nThe srvx Development Team includes Paul Chang, Adrian Dewhurst, Miles Peterson, Michael Poole and others.");
+    send_message_type(4, user, cmd->parent->bot, "Copyright 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", ARCH_VERSION);
     return 1;
@@ -1811,6 +1831,8 @@ modcmd_saxdb_write(struct saxdb_context *ctx) {
             saxdb_write_string(ctx, "trigger", buff);
         }
         saxdb_write_string(ctx, "description", service->bot->info);
+        if (service->privileged)
+            saxdb_write_string(ctx, "privileged", "1");
         saxdb_end_record(ctx);
     }
     saxdb_end_record(ctx);
@@ -1911,8 +1933,12 @@ modcmd_load_bots(struct dict *db) {
         desc = database_get_data(rd->d.object, "description", RECDB_QSTRING);
         if (desc)
         {
+            struct service *svc;
             bot = AddService(nick, desc);
-            service_register(bot, trigger);
+            svc = service_register(bot, trigger);
+            desc = database_get_data(rd->d.object, "privileged", RECDB_QSTRING);
+            if (desc && (true_string(desc) || enabled_string(desc)))
+                svc->privileged = 1;
         }
     }
 }
@@ -1934,25 +1960,26 @@ modcmd_init(void) {
     conf_register_reload(modcmd_conf_read);
 
     modcmd_module = module_register("modcmd", MAIN_LOG, "modcmd.help", modcmd_expand);
-    bind_command = modcmd_register(modcmd_module, "bind", cmd_bind, 4, MODCMD_KEEP_BOUND, "level", "800", NULL);
+    bind_command = modcmd_register(modcmd_module, "bind", cmd_bind, 4, MODCMD_KEEP_BOUND, "oper_level", "800", NULL);
     help_command = modcmd_register(modcmd_module, "help", cmd_help, 1, 0, "flags", "+nolog", NULL);
     modcmd_register(modcmd_module, "command", cmd_command, 2, 0, "flags", "+nolog", NULL);
     modcmd_register(modcmd_module, "modcmd", cmd_modcmd, 4, MODCMD_KEEP_BOUND, "template", "bind", NULL);
     modcmd_register(modcmd_module, "god", cmd_god, 0, MODCMD_REQUIRE_AUTHED, "flags", "+oper,+networkhelper", NULL);
-    modcmd_register(modcmd_module, "readhelp", cmd_readhelp, 2, 0, "level", "650", NULL);
-    modcmd_register(modcmd_module, "timecmd", cmd_timecmd, 2, 0, "level", "1", NULL);
+    modcmd_register(modcmd_module, "readhelp", cmd_readhelp, 2, 0, "oper_level", "650", NULL);
+    modcmd_register(modcmd_module, "timecmd", cmd_timecmd, 2, 0, "oper_level", "1", NULL);
     modcmd_register(modcmd_module, "unbind", cmd_unbind, 3, 0, "template", "bind", NULL);
     modcmd_register(modcmd_module, "joiner", cmd_joiner, 1, 0, NULL);
-    modcmd_register(modcmd_module, "stats modules", cmd_stats_modules, 1, 0, "level", "0", NULL);
-    modcmd_register(modcmd_module, "stats services", cmd_stats_services, 1, 0, "level", "0", NULL);
+    modcmd_register(modcmd_module, "stats modules", cmd_stats_modules, 1, 0, "flags", "+oper", NULL);
+    modcmd_register(modcmd_module, "stats services", cmd_stats_services, 1, 0, "flags", "+oper", NULL);
     modcmd_register(modcmd_module, "showcommands", cmd_showcommands, 1, 0, "flags", "+acceptchan", NULL);
     modcmd_register(modcmd_module, "helpfiles", cmd_helpfiles, 2, 0, "template", "bind", NULL);
-    modcmd_register(modcmd_module, "service add", cmd_service_add, 3, 0, NULL);
-    modcmd_register(modcmd_module, "service rename", cmd_service_rename, 3, 0, NULL);
-    modcmd_register(modcmd_module, "service trigger", cmd_service_trigger, 2, 0, NULL);
-    modcmd_register(modcmd_module, "service remove", cmd_service_remove, 2, 0, NULL);
+    modcmd_register(modcmd_module, "service add", cmd_service_add, 3, 0, "flags", "+oper", NULL);
+    modcmd_register(modcmd_module, "service rename", cmd_service_rename, 3, 0, "flags", "+oper", NULL);
+    modcmd_register(modcmd_module, "service trigger", cmd_service_trigger, 2, 0, "flags", "+oper", NULL);
+    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, "version", cmd_version, 1, 0, NULL);
+    version_command = modcmd_register(modcmd_module, "version", cmd_version, 1, 0, NULL);
     message_register_table(msgtab);
 }
 
@@ -2146,21 +2173,25 @@ create_default_binds(void) {
             continue;
         if (dict_size(service->commands) > 0)
             continue;
+
         /* Bind the default modules for this service to it */
         for (jj = 0; def_binds[ii].modnames[jj]; ++jj) {
             if (!(module = module_find(def_binds[ii].modnames[jj])))
                 continue;
             service_bind_module(service, module);
         }
-        /* Bind the help command to this service */
+
+        /* 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);
+
         /* Now some silly hax.. (aliases that most people want) */
         if (!irccasecmp(def_binds[ii].svcname, "ChanServ")) {
-            service_make_alias(service, "addowner", "*chanserv.adduser", "owner", "$1", NULL);
-            service_make_alias(service, "addcoowner", "*chanserv.adduser", "coowner", "$1", NULL);
-            service_make_alias(service, "addmaster", "*chanserv.adduser", "master", "$1", NULL);
-            service_make_alias(service, "addop", "*chanserv.adduser", "op", "$1", NULL);
-            service_make_alias(service, "addpeon", "*chanserv.adduser", "peon", "$1", NULL);
+            service_make_alias(service, "addowner", "*chanserv.adduser", "$1", "owner", NULL);
+            service_make_alias(service, "addcoowner", "*chanserv.adduser", "$1", "coowner", NULL);
+            service_make_alias(service, "addmaster", "*chanserv.adduser", "$1", "master", 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, "delowner", "*chanserv.deluser", "owner", "$1", NULL);
             service_make_alias(service, "delcoowner", "*chanserv.deluser", "coowner", "$1", NULL);
             service_make_alias(service, "delmaster", "*chanserv.deluser", "master", "$1", NULL);