1 /* cmd_neonserv_move.c - NeonServ v5.1
2 * Copyright (C) 2011 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_neonserv.h"
22 * argv[1] - new channel
24 CMD_BIND(neonserv_cmd_move) {
27 char *channel = argv[0];
28 char *new_channel = argv[1];
29 if(!is_valid_chan(new_channel)) {
30 reply(getTextBot(), user, "NS_INVALID_CHANNEL_NAME", new_channel);
33 if(!stricmp(channel, new_channel)) {
34 reply(getTextBot(), 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(getTextBot(), 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(getTextBot(), 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(getTextBot(), user, "NS_UNREGISTER_NOT_REGISTERED", argv[0], client->user->nick);
58 if(!strcmp(row[2], "1")) {
59 reply(getTextBot(), user, "NS_MOVE_SUSPENDED");
62 int botid = atoi(row[0]);
63 struct ClientSocket *bot;
64 for(bot = getBots(SOCKET_FLAG_READY, NULL); bot; bot = getBots(SOCKET_FLAG_READY, bot)) {
65 if(bot->clientid == botid)
69 putsock(bot, "PART %s :Channel moved to %s.", channel, new_channel);
70 putsock(bot, "JOIN %s", new_channel);
72 printf_mysql_query("DELETE FROM `channels` WHERE `channel_name` = '%s'", escape_string(new_channel));
73 printf_mysql_query("UPDATE `channels` SET `channel_name` = '%s' WHERE `channel_id` = '%s'", escape_string(new_channel), row[1]);
74 struct ChanNode *channode = getChanByName(channel);
75 if(channode && channode->flags & CHANFLAG_REQUESTED_CHANINFO) {
76 channode->flags &= ~CHANFLAG_CHAN_REGISTERED;
77 channode->channel_id = 0;
79 channode = getChanByName(new_channel);
80 if(channode && channode->flags & CHANFLAG_REQUESTED_CHANINFO) {
81 channode->flags |= CHANFLAG_CHAN_REGISTERED;
82 channode->channel_id = atoi(row[1]);
84 reply(getTextBot(), user, "NS_MOVE_DONE", channel, new_channel);