1 /* cmd_global_move.c - NeonServ v5.6
2 * Copyright (C) 2011-2012 Philipp Kreil (pk910)
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include "cmd_global.h"
22 * argv[1] - new channel
24 CMD_BIND(global_cmd_move) {
27 char *channel = argv[0];
28 char *new_channel = argv[1];
29 if(!is_valid_chan(new_channel)) {
30 reply(textclient, user, "NS_INVALID_CHANNEL_NAME", new_channel);
33 if(!stricmp(channel, new_channel)) {
34 reply(textclient, user, "NS_MOVE_SELF");
37 printf_mysql_query("SELECT `channel_id` FROM `bot_channels` LEFT JOIN `channels` ON `channel_id` = `chanid` WHERE `channel_name` = '%s'", escape_string(new_channel));
39 if ((row = mysql_fetch_row(res)) != NULL) {
40 reply(textclient, user, "NS_REGISTER_ALREADY", new_channel, client->user->nick);
44 printf_mysql_query("SELECT `channel_id` FROM `channels` WHERE `channel_name` = '%s'", escape_string(channel));
46 if ((row = mysql_fetch_row(res)) != NULL) {
47 chanid = atoi(row[0]);
49 reply(textclient, user, "NS_UNREGISTER_NOT_REGISTERED", argv[0], client->user->nick);
52 printf_mysql_query("SELECT `botid`, `bot_channels`.`id`, `suspended` FROM `bot_channels` LEFT JOIN `bots` ON `bot_channels`.`botid` = `bots`.`id` WHERE `chanid` = '%d' AND `botclass` = '%d'", chanid, client->botid);
54 if ((row = mysql_fetch_row(res)) == NULL) {
55 reply(textclient, user, "NS_UNREGISTER_NOT_REGISTERED", argv[0], client->user->nick);
58 if(!strcmp(row[2], "1")) {
59 reply(textclient, user, "NS_MOVE_SUSPENDED");
62 int botid = atoi(row[0]);
63 struct ClientSocket *bot;
64 struct ChanNode *channode = getChanByName(channel);
66 for(bot = getBots(SOCKET_FLAG_READY, NULL); bot; bot = getBots(SOCKET_FLAG_READY, bot)) {
67 if(isUserOnChan(bot->user, channode)) {
68 putsock(bot, "PART %s", channel);
69 putsock(bot, "JOIN %s", new_channel);
73 for(bot = getBots(SOCKET_FLAG_READY, NULL); bot; bot = getBots(SOCKET_FLAG_READY, bot)) {
74 if(bot->clientid == botid)
75 putsock(bot, "JOIN %s", new_channel);
78 printf_mysql_query("SELECT `channel_id` FROM `channels` WHERE `channel_name` = '%s'", escape_string(new_channel));
80 if ((row = mysql_fetch_row(res)) != NULL) {
81 chanid = atoi(row[0]);
82 printf_mysql_query("DELETE FROM `chanusers` WHERE `chanuser_cid` = '%d'", chanid);
83 printf_mysql_query("DELETE FROM `bans` WHERE `ban_channel` = '%d'", chanid);
84 printf_mysql_query("DELETE FROM `events` WHERE `cid` = '%d'", chanid);
85 printf_mysql_query("DELETE FROM `noinvite` WHERE `cid` = '%d'", chanid);
86 printf_mysql_query("DELETE FROM `owner_history` WHERE `owner_history_cid` = '%d'", chanid);
87 printf_mysql_query("DELETE FROM `channels` WHERE `channel_id` = '%d'", chanid);
89 printf_mysql_query("UPDATE `channels` SET `channel_name` = '%s' WHERE `channel_name` = '%s'", escape_string(new_channel), escape_string(channel));
91 if(channode && channode->flags & CHANFLAG_REQUESTED_CHANINFO) {
92 channode->flags &= ~CHANFLAG_CHAN_REGISTERED;
93 channode->channel_id = 0;
95 reply(textclient, user, "NS_MOVE_DONE", channel, new_channel);