bind / unbind commands when bot gets marked as active / inactive
authorpk910 <philipp@zoelle1.de>
Thu, 22 Dec 2011 00:22:04 +0000 (01:22 +0100)
committerpk910 <philipp@zoelle1.de>
Thu, 22 Dec 2011 00:22:04 +0000 (01:22 +0100)
src/cmd_global_setbot.c

index c285ffd1b034411af071f3bb92e2980459c1dea0..99587d6f4cd58e5964e00340500d80508f316ac0 100644 (file)
@@ -120,11 +120,32 @@ static int global_cmd_setbot_active(struct UserNode *user, MYSQL_ROW bot, char *
                 client->botid = atoi(bot[5]);
                 client->clientid = atoi(bot[15]);
                 connect_socket(client);
+                if(client->botid == 0) {
+                    MYSQL_RES *res;
+                    MYSQL_ROW row;
+                    printf_mysql_query("SELECT `command`, `function`, `parameters`, `global_access`, `chan_access` FROM `bot_binds` WHERE `botclass` = '0' AND `botid` = '%d'", client->clientid);
+                    res = mysql_use();
+                    while ((row = mysql_fetch_row(res)) != NULL) {
+                        if(bind_botwise_cmd_to_command(0, client->clientid, row[0], row[1])) {
+                            if(row[2] && strcmp(row[2], "")) {
+                                bind_botwise_set_parameters(0, client->clientid, row[0], row[2]);
+                            }
+                            if(row[3]) {
+                                bind_botwise_set_global_access(0, client->clientid, row[0], atoi(row[3]));
+                            }
+                            if(row[4]) {
+                                bind_botwise_set_channel_access(0, client->clientid, row[0], row[4]);
+                            }
+                        }
+                    }
+                    bind_botwise_unbound_required_functions(0, client->clientid);
+                }
             } else {
                 //remove the bot
                 struct ClientSocket *client;
                 for(client = getBots(0, NULL); client; client = getBots(0, client)) {
                     if(client->clientid == atoi(bot[15])) {
+                        unbind_botwise_allcmd(client->clientid);
                         close_socket(client);
                         break;
                     }