fixed cmd_register and cmd_unregister for "zero-bot" support
[NeonServV5.git] / src / cmd_global_register.c
index ab467d979b87dde8fc24f7fba8b184f696c5960c..b22fc5840f008d0b0ded13be2038756134fc461a 100644 (file)
@@ -50,7 +50,7 @@ CMD_BIND(global_cmd_register) {
     printf_mysql_query("SELECT `botid`, `botclass` FROM `bot_channels` LEFT JOIN `bots` ON `bot_channels`.`botid` = `bots`.`id` LEFT JOIN `channels` ON `bot_channels`.`chanid` = `channels`.`channel_id` WHERE `channel_name` = '%s'", escape_string(channel));
     res = mysql_use();
     while ((row = mysql_fetch_row(res)) != NULL) {
-        if(atoi(row[1]) == client->botid) {
+        if(atoi(row[1]) == client->botid && (client->botid || client->clientid == atoi(row[0]))) {
             reply(getTextBot(), user, "NS_REGISTER_ALREADY", argv[0], client->user->nick);
             return;
         } else
@@ -209,7 +209,7 @@ static void global_cmd_register_async1(struct ClientSocket *client, struct Clien
             userid = (int) mysql_insert_id(mysql_conn);
         }
     }
-    printf_mysql_query("SELECT `id`, `max_channels`, `defaulttrigger`, `nick` FROM `bots` WHERE `botclass` = '%d' ORDER BY `register_priority` DESC", client->botid);
+    printf_mysql_query("SELECT `id`, `max_channels`, `defaulttrigger`, `nick` FROM `bots` WHERE `botclass` = '%d' AND `active` = '1' ORDER BY `register_priority` DESC", client->botid);
     res = mysql_use();
     int botid = 0;
     char *bottrigger;
@@ -245,7 +245,7 @@ static void global_cmd_register_async1(struct ClientSocket *client, struct Clien
     if(bot) {
         putsock(bot, "JOIN %s", channel);
     } else
-        reply(textclient, user, "NS_REGISTER_DISCONNECTED");
+        reply(textclient, user, "NS_REGISTER_DISCONNECTED", channel);
     printf_mysql_query("INSERT INTO `bot_channels` (`botid`, `chanid`, `trigger`) VALUES ('%d', '%d', '%s')", botid, chanid, bottrigger);
     if(multibot != 2) {
         if(multibot) {