Another year is about to end... So we have to update these damn copyright information :P
[NeonServV5.git] / src / cmd_global_register.c
index a0c42587defee4804b438b5b4a046589908ec615..9132484b362a445ad4a1ddcbdda3398f4a11c381 100644 (file)
@@ -1,5 +1,5 @@
-/* cmd_global_register.c - NeonServ v5.2
- * Copyright (C) 2011  Philipp Kreil (pk910)
+/* cmd_global_register.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
@@ -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
@@ -80,7 +80,7 @@ CMD_BIND(global_cmd_register) {
         global_cmd_register_async1(client, getTextBot(), user, chan, event, channel, NULL, multibot, botname);
         return;
     } else if(argc < 2) {
-        reply(getTextBot(), user, "MODCMD_LESS_PARAM_COUNT");
+        global_cmd_register_async1(client, getTextBot(), user, chan, event, channel, user->auth, multibot, botname);
         return;
     }
     //check own access
@@ -209,17 +209,18 @@ 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' AND `active` = '1' ORDER BY `register_priority` DESC", client->botid);
+    if(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);
+    else
+        printf_mysql_query("SELECT `id`, `max_channels`, `defaulttrigger`, `nick` FROM `bots` WHERE `id` = '%d' AND `active` = '1'", client->clientid);
     res = mysql_use();
     int botid = 0;
-    char *bottrigger;
     while ((row = mysql_fetch_row(res)) != NULL) {
         //check channel count
         printf_mysql_query("SELECT COUNT(*) FROM `bot_channels` WHERE `botid` = '%s'", row[0]);
         row2 = mysql_fetch_row(mysql_use());
         if(atoi(row2[0]) < atoi(row[1]) && (!botname || !stricmp(botname, row[3]))) {
             botid = atoi(row[0]);
-            bottrigger = row[2];
             break;
         }
     }
@@ -246,7 +247,7 @@ static void global_cmd_register_async1(struct ClientSocket *client, struct Clien
         putsock(bot, "JOIN %s", channel);
     } else
         reply(textclient, user, "NS_REGISTER_DISCONNECTED", channel);
-    printf_mysql_query("INSERT INTO `bot_channels` (`botid`, `chanid`, `trigger`) VALUES ('%d', '%d', '%s')", botid, chanid, bottrigger);
+    printf_mysql_query("INSERT INTO `bot_channels` (`botid`, `chanid`, `trigger`) VALUES ('%d', '%d', NULL)", botid, chanid);
     if(multibot != 2) {
         if(multibot) {
             printf_mysql_query("UPDATE `chanusers` SET `chanuser_access` = 499 WHERE `chanuser_cid` = '%d' AND `chanuser_access` = '500'", chanid);