added "nowho" parameter to debug userlist and fixed memory leak in DBHelper.c
[NeonServV5.git] / src / cmd_global_setbot.c
index c285ffd1b034411af071f3bb92e2980459c1dea0..e823a9e0f8360ec2ccd1cd9947a58ea778360071 100644 (file)
@@ -1,5 +1,5 @@
-/* cmd_global_setbot.c - NeonServ v5.2
- * Copyright (C) 2011  Philipp Kreil (pk910)
+/* cmd_global_setbot.c - NeonServ v5.3
+ * Copyright (C) 2011-2012  Philipp Kreil (pk910)
  * 
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -70,11 +70,17 @@ CMD_BIND(global_cmd_setbot) {
         else if(!stricmp(argv[1], "prefered")) log_event = global_cmd_setbot_prefered(user, row, value);
         else if(!stricmp(argv[1], "maxchan")) log_event = global_cmd_setbot_maxchan(user, row, value);
         else if(!stricmp(argv[1], "priority")) log_event = global_cmd_setbot_priority(user, row, value);
-        else if(!stricmp(argv[1], "trigger")) log_event = global_cmd_setbot_nick(user, row, value);
+        else if(!stricmp(argv[1], "trigger")) log_event = global_cmd_setbot_trigger(user, row, value);
         else {
             reply(getTextBot(), user, "NS_SETBOT_SETTING", argv[1]);
         }
         if(log_event) {
+            if(!stricmp(argv[1], "serverpass") && value) { //censor server password 
+                char cmd_args[MAXLEN];
+                sprintf(cmd_args, "%d SERVERPASS ***", botid);
+                free(event->arguments);
+                event->arguments = strdup(cmd_args);
+            }
             logEvent(event);
         }
     } else {
@@ -120,11 +126,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;
                     }
@@ -325,12 +352,14 @@ static int global_cmd_setbot_serverpass(struct UserNode *user, MYSQL_ROW bot, ch
     char *val = bot[4];
     int ret = 0;
     if(value) {
+        if(!strcmp(value, "*")) 
+            value = "";
         struct ClientSocket *client;
         for(client = getBots(0, NULL); client; client = getBots(0, client)) {
             if(client->clientid == atoi(bot[15])) {
                 if(client->pass)
                     free(client->pass);
-                client->pass = strdup(value);
+                client->pass = (value ? strdup(value) : NULL);
                 if(client->flags & SOCKET_FLAG_READY)
                     reply(getTextBot(), user, "NS_SETBOT_NEED_RESTART");
                 break;
@@ -440,7 +469,7 @@ static int global_cmd_setbot_prefered(struct UserNode *user, MYSQL_ROW bot, char
                 break;
             }
         }
-        printf_mysql_query("UPDATE `bots` SET `queue` = '%d' WHERE `id` = '%s'", val, bot[15]);
+        printf_mysql_query("UPDATE `bots` SET `prefered` = '%d' WHERE `id` = '%s'", val, bot[15]);
         ret = 1;
     }
     reply(getTextBot(), user, "\002PREFERED   \002 %s", get_language_string(user, (val ? "NS_SET_ON" : "NS_SET_OFF")));
@@ -456,7 +485,7 @@ static int global_cmd_setbot_maxchan(struct UserNode *user, MYSQL_ROW bot, char
             reply(getTextBot(), user, "NS_SETBOT_MAXCHAN_INVALID", value);
             return 0;
         }
-        printf_mysql_query("UPDATE `bots` SET `maxchan` = '%d' WHERE `id` = '%s'", val, bot[15]);
+        printf_mysql_query("UPDATE `bots` SET `max_channels` = '%d' WHERE `id` = '%s'", val, bot[15]);
         ret = 1;
     }
     reply(getTextBot(), user, "\002MAXCHAN    \002 %d", val);
@@ -488,6 +517,7 @@ static int global_cmd_setbot_trigger(struct UserNode *user, MYSQL_ROW bot, char
             return 0;
         }
         printf_mysql_query("UPDATE `bots` SET `defaulttrigger` = '%s' WHERE `id` = '%s'", escape_string(value), bot[15]);
+        flush_trigger_cache(atoi(bot[5]), atoi(bot[15]));
         reply(getTextBot(), user, "NS_SETBOT_TRIGGER_NOTE");
         val = value;
         ret = 1;