*** VERSION 5.2.0 ***
[NeonServV5.git] / src / cmd_neonserv_move.c
index 804954faf45ff92be7a1f9798fdd11e200e92da4..d8ae8069fb5487a959a27a30a45f6efb7a2b53d7 100644 (file)
@@ -1,3 +1,19 @@
+/* cmd_neonserv_move.c - NeonServ v5.2
+ * Copyright (C) 2011  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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License 
+ * along with this program. If not, see <http://www.gnu.org/licenses/>. 
+ */
 
 #include "cmd_neonserv.h"
 
@@ -53,18 +69,23 @@ CMD_BIND(neonserv_cmd_move) {
         putsock(bot, "PART %s :Channel moved to %s.", channel, new_channel);
         putsock(bot, "JOIN %s", new_channel);
     }
-    printf_mysql_query("DELETE FROM `channels` WHERE `channel_name` = '%s'", escape_string(new_channel));
-    printf_mysql_query("UPDATE `channels` SET `channel_name` = '%s' WHERE `channel_id` = '%s'", escape_string(new_channel), row[1]);
+    printf_mysql_query("SELECT `channel_id` FROM `channels` WHERE `channel_name` = '%s'", escape_string(new_channel));
+    res = mysql_use();
+    if ((row = mysql_fetch_row(res)) != NULL) {
+        chanid = atoi(row[0]);
+        printf_mysql_query("DELETE FROM `chanusers` WHERE `chanuser_cid` = '%d'", chanid);
+        printf_mysql_query("DELETE FROM `bans` WHERE `ban_channel` = '%d'", chanid);
+        printf_mysql_query("DELETE FROM `events` WHERE `cid` = '%d'", chanid);
+        printf_mysql_query("DELETE FROM `noinvite` WHERE `cid` = '%d'", chanid);
+        printf_mysql_query("DELETE FROM `owner_history` WHERE `owner_history_cid` = '%d'", chanid);
+        printf_mysql_query("DELETE FROM `channels` WHERE `channel_id` = '%d'", chanid);
+    }
+    printf_mysql_query("UPDATE `channels` SET `channel_name` = '%s' WHERE `channel_name` = '%s'", escape_string(new_channel), escape_string(channel));
     struct ChanNode *channode = getChanByName(channel);
     if(channode && channode->flags & CHANFLAG_REQUESTED_CHANINFO) {
         channode->flags &= ~CHANFLAG_CHAN_REGISTERED;
         channode->channel_id = 0;
     }
-    channode = getChanByName(new_channel);
-    if(channode && channode->flags & CHANFLAG_REQUESTED_CHANINFO) {
-        channode->flags |= CHANFLAG_CHAN_REGISTERED;
-        channode->channel_id = atoi(row[1]);
-    }
     reply(getTextBot(), user, "NS_MOVE_DONE", channel, new_channel);
     logEvent(event);
 }