Another year is about to end... So we have to update these damn copyright information :P
[NeonServV5.git] / src / cmd_neonserv_move.c
index 197bd6583a9b676640804bba647cb4ba1e96ad38..211247e8643c15e262aaaa280bd8fc8cc72948c9 100644 (file)
@@ -1,5 +1,5 @@
-/* cmd_neonserv_move.c - NeonServ v5.1
- * Copyright (C) 2011  Philipp Kreil (pk910)
+/* cmd_neonserv_move.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
@@ -69,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);
 }