made bind/unbind command bindings "required" (means: there has to be at least 1 comma...
[NeonServV5.git] / src / bot_NeonServ.c
index 34414f02a5167edfbc167972b9e2f6d351f5fdb7..97f4f246f6c7ead35c3c3f1ae84e03dbb649ab66 100644 (file)
@@ -1,4 +1,4 @@
-/* bot_NeonServ.c - NeonServ v5.1
+/* bot_NeonServ.c - NeonServ v5.2
  * Copyright (C) 2011  Philipp Kreil (pk910)
  * 
  * This program is free software: you can redistribute it and/or modify
@@ -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}
 };
 
@@ -383,36 +384,38 @@ static void start_bots() {
     MYSQL_RES *res, *res2;
     MYSQL_ROW row;
     
-    printf_mysql_query("SELECT `nick`, `ident`, `realname`, `server`, `port`, `pass`, `textbot`, `id` FROM `bots` WHERE `botclass` = '%d' AND `active` = '1'", BOTID);
+    printf_mysql_query("SELECT `nick`, `ident`, `realname`, `server`, `port`, `pass`, `textbot`, `id`, `queue` FROM `bots` WHERE `botclass` = '%d' AND `active` = '1'", BOTID);
     res = mysql_use();
     
     while ((row = mysql_fetch_row(res)) != NULL) {
-        
         user = addUser(row[0]);
         strcpy(user->ident, row[1]);
         strcpy(user->realname, row[2]);
         user->flags |= USERFLAG_ISBOT;
         client = create_socket(row[3], atoi(row[4]), row[5], user);
         client->flags |= (strcmp(row[6], "0") ? SOCKET_FLAG_PREFERRED : 0);
+        client->flags |= (strcmp(row[8], "0") ? SOCKET_FLAG_USE_QUEUE : 0);
         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() {
@@ -487,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);