made bind/unbind command bindings "required" (means: there has to be at least 1 comma...
authorpk910 <philipp@zoelle1.de>
Sun, 30 Oct 2011 23:05:40 +0000 (00:05 +0100)
committerpk910 <philipp@zoelle1.de>
Sun, 30 Oct 2011 23:05:40 +0000 (00:05 +0100)
src/bot_DummyServ.c
src/bot_NeonServ.c
src/bot_NeonSpam.c
src/cmd_neonserv_unbind.c
src/modcmd.c
src/modcmd.h

index 88e8461b39728436f292180bd947d256718e7df7..9e7793598a54ae7b6a06fe1fe527f3590e98ad5b 100644 (file)
@@ -73,7 +73,6 @@ static void start_bots() {
     res = mysql_use();
     
     while ((row = mysql_fetch_row(res)) != NULL) {
-        
         user = addUser(row[0]);
         strcpy(user->ident, row[1]);
         strcpy(user->realname, row[2]);
@@ -84,22 +83,24 @@ static void start_bots() {
         client->botid = BOTID;
         client->clientid = atoi(row[7]);
         connect_socket(client);
-        printf_mysql_query("SELECT `command`, `function`, `parameters`, `global_access`, `chan_access` FROM `bot_binds` WHERE `botclass` = '%d'", client->botid);
-        res2 = mysql_use();
-        while ((row = mysql_fetch_row(res2)) != NULL) {
-            if(bind_cmd_to_command(BOTID, row[0], row[1])) {
-                if(row[2] && strcmp(row[2], "")) {
-                    bind_set_parameters(BOTID, row[0], row[2]);
-                }
-                if(row[3]) {
-                    bind_set_global_access(BOTID, row[0], atoi(row[3]));
-                }
-                if(row[4]) {
-                    bind_set_channel_access(BOTID, row[0], row[4]);
-                }
+    }
+    
+    printf_mysql_query("SELECT `command`, `function`, `parameters`, `global_access`, `chan_access` 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])) {
+            if(row[2] && strcmp(row[2], "")) {
+                bind_set_parameters(BOTID, row[0], row[2]);
+            }
+            if(row[3]) {
+                bind_set_global_access(BOTID, row[0], atoi(row[3]));
+            }
+            if(row[4]) {
+                bind_set_channel_access(BOTID, row[0], row[4]);
             }
         }
     }
+    bind_unbound_required_functions(BOTID);
 }
 
 void init_DummyServ() {
@@ -114,8 +115,8 @@ void init_DummyServ() {
     //            NAME            FUNCTION              PARAMS  ACCS  FLAGS
     OPER_COMMAND("register",     neonserv_cmd_register,  1,     200,  CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_CHAN_PARAM | CMDFLAG_OPLOG);
     OPER_COMMAND("unregister",   neonserv_cmd_unregister,1,     200,  CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_CHAN_PARAM | CMDFLAG_OPLOG);
-    OPER_COMMAND("bind",         neonserv_cmd_bind,      2,     900,  CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_OPLOG);
-    OPER_COMMAND("unbind",       neonserv_cmd_unbind,    1,     900,  CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_OPLOG);
+    OPER_COMMAND("bind",         neonserv_cmd_bind,      2,     900,  CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_OPLOG | CMDFLAG_REQUIRED);
+    OPER_COMMAND("unbind",       neonserv_cmd_unbind,    1,     900,  CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_OPLOG | CMDFLAG_REQUIRED);
     OPER_COMMAND("say",          neonserv_cmd_say,       2,     600,  CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_CHAN_PARAM | CMDFLAG_OPLOG);
     OPER_COMMAND("emote",        neonserv_cmd_emote,     2,     600,  CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_CHAN_PARAM | CMDFLAG_OPLOG);
     OPER_COMMAND("notice",       neonserv_cmd_notice,    2,     600,  CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_CHAN_PARAM | CMDFLAG_OPLOG);
index 53ad3512f03ab090b8531bdad6ba896e616b91be..97f4f246f6c7ead35c3c3f1ae84e03dbb649ab66 100644 (file)
@@ -313,6 +313,7 @@ static const struct default_language_entry msgtab[] = {
     {"NS_RENAME_DONE", "Renamed $b%s$b to $b%s$b."},
     {"NS_RENAME_FAIL", "Failed renaming $b%s$b."},
     {"NS_FUN_DISABLED", "Fun commands are disabled in %s."},
+    {"NS_UNBIND_REQUIRED", "%1$s is a required function and there is no other command bound to %1$s. Bind anothjer command to %1$s first."}, /* {ARGS: bind} */
     {NULL, NULL}
 };
 
@@ -387,7 +388,6 @@ static void start_bots() {
     res = mysql_use();
     
     while ((row = mysql_fetch_row(res)) != NULL) {
-        
         user = addUser(row[0]);
         strcpy(user->ident, row[1]);
         strcpy(user->realname, row[2]);
@@ -398,22 +398,24 @@ static void start_bots() {
         client->botid = BOTID;
         client->clientid = atoi(row[7]);
         connect_socket(client);
-        printf_mysql_query("SELECT `command`, `function`, `parameters`, `global_access`, `chan_access` FROM `bot_binds` WHERE `botclass` = '%d'", client->botid);
-        res2 = mysql_use();
-        while ((row = mysql_fetch_row(res2)) != NULL) {
-            if(bind_cmd_to_command(BOTID, row[0], row[1])) {
-                if(row[2] && strcmp(row[2], "")) {
-                    bind_set_parameters(BOTID, row[0], row[2]);
-                }
-                if(row[3]) {
-                    bind_set_global_access(BOTID, row[0], atoi(row[3]));
-                }
-                if(row[4]) {
-                    bind_set_channel_access(BOTID, row[0], row[4]);
-                }
+    }
+    
+    printf_mysql_query("SELECT `command`, `function`, `parameters`, `global_access`, `chan_access` 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])) {
+            if(row[2] && strcmp(row[2], "")) {
+                bind_set_parameters(BOTID, row[0], row[2]);
+            }
+            if(row[3]) {
+                bind_set_global_access(BOTID, row[0], atoi(row[3]));
+            }
+            if(row[4]) {
+                bind_set_channel_access(BOTID, row[0], row[4]);
             }
         }
     }
+    bind_unbound_required_functions(BOTID);
 }
 
 void init_NeonServ() {
@@ -488,8 +490,8 @@ void init_NeonServ() {
     OPER_COMMAND("csuspend",     neonserv_cmd_csuspend,  1,     100,  CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_CHAN_PARAM | CMDFLAG_OPLOG);
     OPER_COMMAND("cunsuspend",   neonserv_cmd_cunsuspend,1,     100,  CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_CHAN_PARAM | CMDFLAG_OPLOG);
     OPER_COMMAND("move",         neonserv_cmd_move,      2,     300,  CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_CHAN_PARAM | CMDFLAG_OPLOG);
-    OPER_COMMAND("bind",         neonserv_cmd_bind,      2,     900,  CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_OPLOG);
-    OPER_COMMAND("unbind",       neonserv_cmd_unbind,    1,     900,  CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_OPLOG);
+    OPER_COMMAND("bind",         neonserv_cmd_bind,      2,     900,  CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_OPLOG | CMDFLAG_REQUIRED);
+    OPER_COMMAND("unbind",       neonserv_cmd_unbind,    1,     900,  CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_OPLOG | CMDFLAG_REQUIRED);
     OPER_COMMAND("oplog",        neonserv_cmd_oplog,     0,     1,    CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_OPLOG);
     OPER_COMMAND("search",       neonserv_cmd_search,    1,     400,  CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH);
     OPER_COMMAND("setaccess",    neonserv_cmd_setaccess, 2,     1000, CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_OPLOG);
index 8463d430697772f955748d0a1c1215aad54ac0d0..57d9164f5679a0666f8e50899e7dd05ed5e38caa 100644 (file)
@@ -126,7 +126,6 @@ static void start_bots() {
     res = mysql_use();
     
     while ((row = mysql_fetch_row(res)) != NULL) {
-        
         user = addUser(row[0]);
         strcpy(user->ident, row[1]);
         strcpy(user->realname, row[2]);
@@ -137,22 +136,24 @@ static void start_bots() {
         client->botid = BOTID;
         client->clientid = atoi(row[7]);
         connect_socket(client);
-        printf_mysql_query("SELECT `command`, `function`, `parameters`, `global_access`, `chan_access` FROM `bot_binds` WHERE `botclass` = '%d'", client->botid);
-        res2 = mysql_use();
-        while ((row = mysql_fetch_row(res2)) != NULL) {
-            if(bind_cmd_to_command(BOTID, row[0], row[1])) {
-                if(row[2] && strcmp(row[2], "")) {
-                    bind_set_parameters(BOTID, row[0], row[2]);
-                }
-                if(row[3]) {
-                    bind_set_global_access(BOTID, row[0], atoi(row[3]));
-                }
-                if(row[4]) {
-                    bind_set_channel_access(BOTID, row[0], row[4]);
-                }
+    }
+    
+    printf_mysql_query("SELECT `command`, `function`, `parameters`, `global_access`, `chan_access` 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])) {
+            if(row[2] && strcmp(row[2], "")) {
+                bind_set_parameters(BOTID, row[0], row[2]);
+            }
+            if(row[3]) {
+                bind_set_global_access(BOTID, row[0], atoi(row[3]));
+            }
+            if(row[4]) {
+                bind_set_channel_access(BOTID, row[0], row[4]);
             }
         }
     }
+    bind_unbound_required_functions(BOTID);
 }
 
 char* convertNeonSpamSettingsToString(unsigned int flags, char *buffer) {
@@ -301,8 +302,8 @@ void init_NeonSpam() {
     //            NAME            FUNCTION              PARAMS  ACCS  FLAGS
     OPER_COMMAND("register",     neonserv_cmd_register,  1,     200,  CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_CHAN_PARAM | CMDFLAG_OPLOG);
     OPER_COMMAND("unregister",   neonserv_cmd_unregister,1,     200,  CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_CHAN_PARAM | CMDFLAG_OPLOG);
-    OPER_COMMAND("bind",         neonserv_cmd_bind,      2,     900,  CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_OPLOG);
-    OPER_COMMAND("unbind",       neonserv_cmd_unbind,    1,     900,  CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_OPLOG);
+    OPER_COMMAND("bind",         neonserv_cmd_bind,      2,     900,  CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_OPLOG | CMDFLAG_REQUIRED);
+    OPER_COMMAND("unbind",       neonserv_cmd_unbind,    1,     900,  CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_OPLOG | CMDFLAG_REQUIRED);
     OPER_COMMAND("csuspend",     neonserv_cmd_csuspend,  1,     100,  CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_CHAN_PARAM | CMDFLAG_OPLOG);
     OPER_COMMAND("cunsuspend",   neonserv_cmd_cunsuspend,1,     100,  CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_CHAN_PARAM | CMDFLAG_OPLOG);
     OPER_COMMAND("say",          neonserv_cmd_say,       2,     600,  CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH | CMDFLAG_CHAN_PARAM | CMDFLAG_OPLOG);
index a14ea46277eee660187d2ab8e614b93c850b4dbc..67153d036a759e1bfed9249364d184dee4de1ff2 100644 (file)
 CMD_BIND(neonserv_cmd_unbind) {
     MYSQL_RES *res;
     MYSQL_ROW row;
-    printf_mysql_query("SELECT `id` FROM `bot_binds` WHERE `botclass` = '%d' AND `command` = '%s'", client->botid, escape_string(argv[0]));
+    printf_mysql_query("SELECT `function` FROM `bot_binds` WHERE `botclass` = '%d' AND `command` = '%s'", client->botid, escape_string(argv[0]));
     res = mysql_use();
     if ((row = mysql_fetch_row(res)) == NULL) {
         reply(getTextBot(), user, "NS_UNBIND_NOT_FOUND", argv[0]);
         return;
     }
+    struct cmd_function *function = find_cmd_function(client->botid, row[0]);
+    if(function && (function->flags & CMDFLAG_REQUIRED)) {
+        printf_mysql_query("SELECT `id` FROM `bot_binds` WHERE `botclass` = '%d' AND `function` = '%s'", client->botid, escape_string(function->name));
+        res = mysql_use();
+        if (mysql_num_rows(res) <= 1) {
+            reply(getTextBot(), user, "NS_UNBIND_REQUIRED", function->name);
+            return;
+        }
+    }
     unbind_cmd(client->botid, argv[0]);
     printf_mysql_query("DELETE FROM `bot_binds` WHERE `id` = '%s'", row[0]);
     reply(getTextBot(), user, "NS_UNBIND_DONE", argv[0]);
index 301a50256806802ca6f4edd4647a5a360d835da0..90e46e069354775aea37408db06757ebd1e21a29 100644 (file)
@@ -701,3 +701,27 @@ struct cmd_binding *find_cmd_binding(int botid, char *cmd) {
     return NULL;
 }
 
+void bind_unbound_required_functions(int botid) {
+    struct cmd_function *cmdfunc;
+    int i, found;
+    struct cmd_binding *cbind;
+    for(cmdfunc = cmd_functions; cmdfunc; cmdfunc = cmdfunc->next) {
+        if(cmdfunc->botid == botid && (cmdfunc->flags & CMDFLAG_REQUIRED)) {
+            found = 0;
+            for(i = 0; i < 27; i++) {
+                for(cbind = cmd_binds[i]; cbind; cbind = cbind->next) {
+                    if(cbind->botid == botid && cbind->func == cmdfunc) {
+                        found = 1;
+                        break;
+                    }
+                }
+                if(found)
+                    break;
+            }
+            if(!found) {
+                bind_cmd_to_function(botid, cmdfunc->name, cmdfunc);
+            }
+        }
+    }
+}
+
index 6d01cbf3940a1402a746123f5cae837bc673670c..4c8da64da1942b6304bb9ed7a8c97fba6d6bbc5b 100644 (file)
@@ -31,6 +31,7 @@
 #define CMDFLAG_LOG                     0x0100
 #define CMDFLAG_OPLOG                   0x0200
 #define CMDFLAG_EMPTY_ARGS              0x0400
+#define CMDFLAG_REQUIRED                0x0800
 
 struct ClientSocket;
 struct UserNode;
@@ -88,5 +89,6 @@ void bind_set_parameters(int botid, char *cmd, char *parameters);
 void bind_set_global_access(int botid, char *cmd, int gaccess);
 void bind_set_channel_access(int botid, char *cmd, char *chanaccess);
 struct cmd_binding *find_cmd_binding(int botid, char *cmd);
+void bind_unbound_required_functions(int botid);
 
 #endif
\ No newline at end of file