added possibility to edit command flags (cmd_modcmd)
authorpk910 <philipp@zoelle1.de>
Sun, 25 Dec 2011 20:49:18 +0000 (21:49 +0100)
committerpk910 <philipp@zoelle1.de>
Sun, 25 Dec 2011 20:54:33 +0000 (21:54 +0100)
src/bot_DummyServ.c
src/bot_NeonHelp.c
src/bot_NeonServ.c
src/bot_NeonSpam.c
src/bots.c
src/cmd_global_modcmd.c
src/modcmd.c
src/modcmd.h

index f6fc7aca827d2d437243f7e15c7c9cee3ce99df2..dc957393e02fa9ca40ff64c94c0cdf55b542950b 100644 (file)
@@ -82,7 +82,7 @@ static void start_bots() {
         connect_socket(client);
     }
     
-    printf_mysql_query("SELECT `command`, `function`, `parameters`, `global_access`, `chan_access` FROM `bot_binds` WHERE `botclass` = '%d'", BOTID);
+    printf_mysql_query("SELECT `command`, `function`, `parameters`, `global_access`, `chan_access`, `flags` FROM `bot_binds` WHERE `botclass` = '%d'", BOTID);
     res2 = mysql_use();
     while ((row = mysql_fetch_row(res2)) != NULL) {
         if(bind_cmd_to_command(BOTID, row[0], row[1])) {
@@ -95,6 +95,8 @@ static void start_bots() {
             if(row[4]) {
                 bind_set_channel_access(BOTID, row[0], row[4]);
             }
+            if(strcmp(row[5], "0"))
+                bind_set_bind_flags(BOTID, row[0], atoi(row[5]));
         }
     }
     bind_unbound_required_functions(BOTID);
index 3473d3c09f536c2b57ea8477d7c31ce2af4c3ee0..ee8525f87337cdb6822f09b3d10b638ca219ebca 100644 (file)
@@ -84,7 +84,7 @@ static void start_bots() {
         connect_socket(client);
     }
     
-    printf_mysql_query("SELECT `command`, `function`, `parameters`, `global_access`, `chan_access` FROM `bot_binds` WHERE `botclass` = '%d'", BOTID);
+    printf_mysql_query("SELECT `command`, `function`, `parameters`, `global_access`, `chan_access`, `flags` FROM `bot_binds` WHERE `botclass` = '%d'", BOTID);
     res2 = mysql_use();
     while ((row = mysql_fetch_row(res2)) != NULL) {
         if(bind_cmd_to_command(BOTID, row[0], row[1])) {
@@ -97,6 +97,8 @@ static void start_bots() {
             if(row[4]) {
                 bind_set_channel_access(BOTID, row[0], row[4]);
             }
+            if(strcmp(row[5], "0"))
+                bind_set_bind_flags(BOTID, row[0], atoi(row[5]));
         }
     }
     bind_unbound_required_functions(BOTID);
index 9ec41e4445c9acab73606ca377c60e881fdd2a5a..32de3d6d4fe8d367b2c8c15567c2f7df5f1fada5 100644 (file)
@@ -364,6 +364,7 @@ static const struct default_language_entry msgtab[] = {
     {"NS_MODCMD_SETTING", "$b%s$b is an unknown modcmd setting."}, /* {ARGS: "strangeSetting"} */
     {"NS_MODCMD_HEADER", "$bSettings for command %s:$b"}, /* {ARGS: "access"} */
     {"NS_MODCMD_OUTRANKED", "$b%s$b outranks you. (required access: %d)"}, /* {ARGS: "die", 1000} */
+    {"NS_MODCMD_STATIC_FLAG", "This Flag is added statically. It can't be modified manually."},
     {NULL, NULL}
 };
 
@@ -449,7 +450,7 @@ static void start_bots() {
         connect_socket(client);
     }
     
-    printf_mysql_query("SELECT `command`, `function`, `parameters`, `global_access`, `chan_access` FROM `bot_binds` WHERE `botclass` = '%d'", BOTID);
+    printf_mysql_query("SELECT `command`, `function`, `parameters`, `global_access`, `chan_access`, `flags` FROM `bot_binds` WHERE `botclass` = '%d'", BOTID);
     res2 = mysql_use();
     while ((row = mysql_fetch_row(res2)) != NULL) {
         if(bind_cmd_to_command(BOTID, row[0], row[1])) {
@@ -462,6 +463,8 @@ static void start_bots() {
             if(row[4]) {
                 bind_set_channel_access(BOTID, row[0], row[4]);
             }
+            if(strcmp(row[5], "0"))
+                bind_set_bind_flags(BOTID, row[0], atoi(row[5]));
         }
     }
     bind_unbound_required_functions(BOTID);
index 0ba375471c89636e32289115e84a670026d17c66..61116414742a88f014d5c4ea2de113a4a80617a1 100644 (file)
@@ -167,7 +167,7 @@ static void start_bots() {
         connect_socket(client);
     }
     
-    printf_mysql_query("SELECT `command`, `function`, `parameters`, `global_access`, `chan_access` FROM `bot_binds` WHERE `botclass` = '%d'", BOTID);
+    printf_mysql_query("SELECT `command`, `function`, `parameters`, `global_access`, `chan_access`, `flags` FROM `bot_binds` WHERE `botclass` = '%d'", BOTID);
     res2 = mysql_use();
     while ((row = mysql_fetch_row(res2)) != NULL) {
         if(bind_cmd_to_command(BOTID, row[0], row[1])) {
@@ -180,6 +180,8 @@ static void start_bots() {
             if(row[4]) {
                 bind_set_channel_access(BOTID, row[0], row[4]);
             }
+            if(strcmp(row[5], "0"))
+                bind_set_bind_flags(BOTID, row[0], atoi(row[5]));
         }
     }
     bind_unbound_required_functions(BOTID);
index 9cc84d259f430fd881fde5f126220ccd2bbf45be..d239dffaeced9ff4bc0dd4489825fe8b8b469829 100644 (file)
@@ -56,7 +56,7 @@ static void start_zero_bots() {
         client->clientid = atoi(row[7]);
         connect_socket(client);
         
-        printf_mysql_query("SELECT `command`, `function`, `parameters`, `global_access`, `chan_access` FROM `bot_binds` WHERE `botclass` = '0' AND `botid` = '%d'", client->clientid);
+        printf_mysql_query("SELECT `command`, `function`, `parameters`, `global_access`, `chan_access`, `flags` FROM `bot_binds` WHERE `botclass` = '0' AND `botid` = '%d'", client->clientid);
         res2 = mysql_use();
         while ((row = mysql_fetch_row(res2)) != NULL) {
             if(bind_botwise_cmd_to_command(0, client->clientid, row[0], row[1])) {
@@ -69,6 +69,8 @@ static void start_zero_bots() {
                 if(row[4]) {
                     bind_botwise_set_channel_access(0, client->clientid, row[0], row[4]);
                 }
+                if(strcmp(row[5], "0"))
+                    bind_botwise_set_bind_flags(0, client->clientid, row[0], atoi(row[5]));
             }
         }
         bind_botwise_unbound_required_functions(0, client->clientid);
index 7a3b80bcc7f222f6e94d7d9a921a657af2047b53..a5f36ad98760c1a813ed2b74fddce90206fc224c 100644 (file)
@@ -24,6 +24,7 @@
 */
 
 static int global_cmd_modcmd_params(struct UserNode *user, struct cmd_binding *cbind, char *value);
+static int global_cmd_modcmd_flags(struct UserNode *user, struct cmd_binding *cbind, char *value);
 static int global_cmd_modcmd_caccess(struct UserNode *user, struct cmd_binding *cbind, char *value);
 static int global_cmd_modcmd_oaccess(struct UserNode *user, struct cmd_binding *cbind, char *value);
 
@@ -56,6 +57,7 @@ CMD_BIND(global_cmd_modcmd) {
         if(!stricmp(argv[1], "caccess")) log_event = global_cmd_modcmd_caccess(user, cbind, value);
         else if(!stricmp(argv[1], "oaccess")) log_event = global_cmd_modcmd_oaccess(user, cbind, value);
         else if(!stricmp(argv[1], "parameters")) log_event = global_cmd_modcmd_params(user, cbind, value);
+        else if(!stricmp(argv[1], "flags")) log_event = global_cmd_modcmd_flags(user, cbind, value);
         else {
             reply(getTextBot(), user, "NS_MODCMD_SETTING", argv[1]);
         }
@@ -67,6 +69,7 @@ CMD_BIND(global_cmd_modcmd) {
         global_cmd_modcmd_params(user, cbind, NULL);
         global_cmd_modcmd_caccess(user, cbind, NULL);
         global_cmd_modcmd_oaccess(user, cbind, NULL);
+        global_cmd_modcmd_flags(user, cbind, NULL);
     }
 }
 
@@ -95,6 +98,81 @@ static int global_cmd_modcmd_params(struct UserNode *user, struct cmd_binding *c
     return ret;
 }
 
+static const struct {
+    const char *name;
+    unsigned int flag;
+} global_cmd_modcmd_show_flags[] = {
+    {"REQUIRE_CHAN",        CMDFLAG_REQUIRE_CHAN},      //The command requires a valid channel (at least one bot in it)
+    {"REQUIRE_AUTH",        CMDFLAG_REQUIRE_AUTH},      //The command requires the user to be authenticated
+    {"REQUIRE_GOD",         CMDFLAG_REQUIRE_GOD},       //The command requires the user to have security override enabled
+    {"REQUIRE_REGISTERED",  CMDFLAG_REGISTERED_CHAN},   //The command requires the channel to be registered (database entry)
+    {"CHECK_AUTH",          CMDFLAG_CHECK_AUTH},        //WHO the user if no auth is known, yet
+    {"CHANNEL_ARGS",        CMDFLAG_CHAN_PARAM},        //don't interpret channel arguments as channel - just pass them as a string
+    {"LOG",                 CMDFLAG_LOG},
+    {"OPLOG",               CMDFLAG_OPLOG},
+    {"FUNCMD",              CMDFLAG_FUNCMD},
+    {"ESCAPED_ARGS",        CMDFLAG_ESCAPE_ARGS},       //allows arguments to be escaped ("a\ b" = "a b" as one argument)
+    {NULL, 0}
+};
+
+static int global_cmd_modcmd_flags(struct UserNode *user, struct cmd_binding *cbind, char *value) {
+    char flags[MAXLEN];
+    int flagpos = 0;
+    int ret = 0;
+    int i = 0;
+    while(global_cmd_modcmd_show_flags[i].name) {
+        if(cbind->func->flags & global_cmd_modcmd_show_flags[i].flag) {
+            flagpos += sprintf(flags + flagpos, (flagpos ? " %s" : "\00314%s"), global_cmd_modcmd_show_flags[i].name);
+        }
+        i++;
+    }
+    if(flagpos) 
+        flags[flagpos++] = '\003';
+    if(value) {
+        int add = 1;
+        unsigned int current_flag = 0;
+        if(value[0] == '+') {
+            value++;
+        } else if(value[0] == '-') {
+            add = 0;
+            value++;
+        }
+        if(*value) {
+            i = 0;
+            while(global_cmd_modcmd_show_flags[i].name) {
+                if(!stricmp(global_cmd_modcmd_show_flags[i].name, value)) {
+                    current_flag = global_cmd_modcmd_show_flags[i].flag;
+                    break;
+                }
+                i++;
+            }
+        }
+        if(cbind->func->flags & current_flag) {
+            reply(getTextBot(), user, "NS_MODCMD_STATIC_FLAG");
+            return 0;
+        }
+        if(add)
+            cbind->flags |= current_flag;
+        else
+            cbind->flags &= ~current_flag;
+        if(cbind->botid == 0)
+            printf_mysql_query("UPDATE `bot_binds` SET `flags` = '%u' WHERE `botclass` = '0' AND `botid` = '%d' AND `command` = '%s'", cbind->flags, cbind->clientid, escape_string(cbind->cmd));
+        else
+            printf_mysql_query("UPDATE `bot_binds` SET `flags` = '%u' WHERE `botclass` = '%d' AND `command` = '%s'", cbind->flags, cbind->botid, escape_string(cbind->cmd));
+        ret = 1;
+    }
+    i = 0;
+    while(global_cmd_modcmd_show_flags[i].name) {
+        if(cbind->flags & global_cmd_modcmd_show_flags[i].flag) {
+            flagpos += sprintf(flags + flagpos, (flagpos ? " %s" : "%s"), global_cmd_modcmd_show_flags[i].name);
+        }
+        i++;
+    }
+    flags[flagpos] = '\0';
+    reply(getTextBot(), user, "\002FLAGS      \002 %s", flags);
+    return ret;
+}
+
 static int global_cmd_modcmd_caccess(struct UserNode *user, struct cmd_binding *cbind, char *value) {
     char caccess[MAXLEN];
     int ret = 0;
index 9af13218fc32a47f7a12efe713d5b83fadce5763..03b24d8351b984f6a9b53df311e9c79ce1ee0292 100644 (file)
@@ -204,7 +204,7 @@ static void handle_command(struct ClientSocket *client, struct UserNode *user, s
                 statistics_commands++;
             total_triggered++;
             cbind->triggered++;
-            if((cbind->func->flags & CMDFLAG_FUNCMD)) {
+            if((BIND_FLAGS(cbind) & CMDFLAG_FUNCMD)) {
                 if(!sent_chan)
                     break;
                 chan = sent_chan;
@@ -224,7 +224,7 @@ static void handle_command(struct ClientSocket *client, struct UserNode *user, s
                     if (argc >= MAXNUMPARAMS)
                         break;
                     while ((escape || *args != ' ') && *args) {
-                        if((cbind->func->flags & CMDFLAG_ESCAPE_ARGS) && *args == '\\') {
+                        if((BIND_FLAGS(cbind) & CMDFLAG_ESCAPE_ARGS) && *args == '\\') {
                             escape = 1;
                             offset++;
                         } else if(escape)
@@ -242,7 +242,7 @@ static void handle_command(struct ClientSocket *client, struct UserNode *user, s
                 }
             }
             argv = arga;
-            if(argc != 0 && argv[0][0] == '#' && !(cbind->func->flags & CMDFLAG_CHAN_PARAM)) {
+            if(argc != 0 && argv[0][0] == '#' && !(BIND_FLAGS(cbind) & CMDFLAG_CHAN_PARAM)) {
                 struct ChanNode *chan2 = getChanByName(argv[0]);
                 if(chan2) {
                     argv += 1;
@@ -307,7 +307,7 @@ static void handle_command(struct ClientSocket *client, struct UserNode *user, s
                                     }
                                     args_pos++;
                                 }
-                            } else if((cbind->func->flags & CMDFLAG_EMPTY_ARGS)) {
+                            } else if((BIND_FLAGS(cbind) & CMDFLAG_EMPTY_ARGS)) {
                                 uargs[uargc++] = args_buffer + args_pos;
                                 args_buffer[args_pos++] = '\0';
                             } else if(c) {
@@ -334,11 +334,11 @@ static void handle_command(struct ClientSocket *client, struct UserNode *user, s
                 reply(tmp_text_client, user, "MODCMD_LESS_PARAM_COUNT");
                 break;
             }
-            if((cbind->func->flags & CMDFLAG_REQUIRE_CHAN) && !chan) {
+            if((BIND_FLAGS(cbind) & CMDFLAG_REQUIRE_CHAN) && !chan) {
                 reply(tmp_text_client, user, "MODCMD_CHAN_REQUIRED");
                 break;
             }
-            if(((cbind->func->flags & CMDFLAG_CHECK_AUTH) || (chan && chan != sent_chan && !isUserOnChan(user, chan))) && !(user->flags & USERFLAG_ISAUTHED)) {
+            if(((BIND_FLAGS(cbind) & CMDFLAG_CHECK_AUTH) || (chan && chan != sent_chan && !isUserOnChan(user, chan))) && !(user->flags & USERFLAG_ISAUTHED)) {
                 //check auth...
                 struct command_check_user_cache *data = malloc(sizeof(*data));
                 char **temp_argv = malloc(argc*sizeof(*temp_argv));
@@ -376,8 +376,8 @@ static void handle_command_async(struct ClientSocket *client, struct UserNode *u
     MYSQL_ROW row;
     int uaccess;
     char requested_uaccess = 0;
-    int eventflags = (cbind->func->flags & (CMDFLAG_LOG | CMDFLAG_OPLOG));
-    if((cbind->func->flags & CMDFLAG_REQUIRE_AUTH) && !(user->flags & USERFLAG_ISAUTHED)) {
+    int eventflags = (BIND_FLAGS(cbind) & (CMDFLAG_LOG | CMDFLAG_OPLOG));
+    if((BIND_FLAGS(cbind) & CMDFLAG_REQUIRE_AUTH) && !(user->flags & USERFLAG_ISAUTHED)) {
         reply(tmp_text_client, user, "MODCMD_AUTH_REQUIRED");
         return;
     }
@@ -431,7 +431,7 @@ static void handle_command_async(struct ClientSocket *client, struct UserNode *u
             return;
         }
     }
-    if((cbind->func->flags & CMDFLAG_REGISTERED_CHAN)) {
+    if((BIND_FLAGS(cbind) & CMDFLAG_REGISTERED_CHAN)) {
         MYSQL_ROW defaults = NULL;
         char access_list[256];
         int access_pos = 0;
@@ -522,7 +522,7 @@ static void handle_command_async(struct ClientSocket *client, struct UserNode *u
             return;
         }
     }
-    if((cbind->func->flags & CMDFLAG_REQUIRE_GOD) && !isGodMode(user)) {
+    if((BIND_FLAGS(cbind) & CMDFLAG_REQUIRE_GOD) && !isGodMode(user)) {
         reply(tmp_text_client, user, "MODCMD_PRIVILEGED", cbind->cmd);
         return;
     }
@@ -905,6 +905,17 @@ void bind_botwise_set_channel_access(int botid, int clientid, char *cmd, char *c
     }
 }
 
+void bind_botwise_set_bind_flags(int botid, int clientid, char *cmd, unsigned int flags) {
+    int bind_index = get_binds_index(cmd[0]);
+    struct cmd_binding *cbind;
+    for(cbind = cmd_binds[bind_index]; cbind; cbind = cbind->next) {
+        if(cbind->botid == botid && (botid || clientid == cbind->clientid) && strcmp(cbind->cmd, cmd) == 0) {
+            cbind->flags |= flags;
+            return;
+        }
+    }
+}
+
 struct cmd_binding *find_botwise_cmd_binding(int botid, int clientid, char *cmd) {
     int bind_index = get_binds_index(cmd[0]);
     struct cmd_binding *cbind;
index 2be6f3d5e42a6d9ff80e3d27625228b9e858e916..9bb799cc1a3194158da7a5f7fceff811a32c7ca8 100644 (file)
@@ -72,6 +72,8 @@ struct cmd_binding {
     struct cmd_binding *next;
 };
 
+#define BIND_FLAGS(BIND) (BIND->flags | BIND->func->flags)
+
 struct trigger_cache {
     int botid;
     int clientid;
@@ -116,6 +118,9 @@ void bind_botwise_set_global_access(int botid, int clientid, char *cmd, int gacc
 #define bind_set_channel_access(BOTID,CMD,CACCESS) bind_botwise_set_channel_access(BOTID, 0, CMD, CACCESS)
 void bind_botwise_set_channel_access(int botid, int clientid, char *cmd, char *chanaccess);
 
+#define bind_set_bind_flags(BOTID,CMD,FLAGS) bind_botwise_set_bind_flags(BOTID, 0, CMD, FLAGS)
+void bind_botwise_set_bind_flags(int botid, int clientid, char *cmd, unsigned int flags);
+
 #define find_cmd_binding(BOTID,CMD) find_botwise_cmd_binding(BOTID, 0, CMD)
 struct cmd_binding *find_botwise_cmd_binding(int botid, int clientid, char *cmd);