4 * argv[1] - new channel
6 static CMD_BIND(neonserv_cmd_move) {
9 char *channel = argv[0];
10 char *new_channel = argv[1];
11 if(!is_valid_chan(new_channel)) {
12 reply(getTextBot(), user, "NS_INVALID_CHANNEL_NAME", new_channel);
15 if(!stricmp(channel, new_channel)) {
16 reply(getTextBot(), user, "NS_MOVE_SELF");
19 printf_mysql_query("SELECT `channel_id` FROM `bot_channels` LEFT JOIN `channels` ON `channel_id` = `chanid` WHERE `channel_name` = '%s'", escape_string(new_channel));
21 if ((row = mysql_fetch_row(res)) != NULL) {
22 reply(getTextBot(), user, "NS_REGISTER_ALREADY", new_channel, client->user->nick);
26 printf_mysql_query("SELECT `channel_id` FROM `channels` WHERE `channel_name` = '%s'", escape_string(channel));
28 if ((row = mysql_fetch_row(res)) != NULL) {
29 chanid = atoi(row[0]);
31 reply(getTextBot(), user, "NS_UNREGISTER_NOT_REGISTERED", argv[0], client->user->nick);
34 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);
36 if ((row = mysql_fetch_row(res)) == NULL) {
37 reply(getTextBot(), user, "NS_UNREGISTER_NOT_REGISTERED", argv[0], client->user->nick);
40 if(!strcmp(row[2], "1")) {
41 reply(getTextBot(), user, "NS_MOVE_SUSPENDED");
44 int botid = atoi(row[0]);
45 struct ClientSocket *bot;
46 for(bot = getBots(SOCKET_FLAG_READY, NULL); bot; bot = getBots(SOCKET_FLAG_READY, bot)) {
47 if(bot->clientid == botid)
51 putsock(bot, "PART %s :Channel moved to %s.", channel, new_channel);
52 putsock(bot, "JOIN %s", new_channel);
54 printf_mysql_query("DELETE FROM `channels` WHERE `channel_name` = '%s'", escape_string(new_channel));
55 printf_mysql_query("UPDATE `channels` SET `channel_name` = '%s' WHERE `channel_id` = '%s'", escape_string(new_channel), row[1]);
56 struct ChanNode *channode = getChanByName(channel);
57 if(channode && channode->flags & CHANFLAG_REQUESTED_CHANINFO) {
58 channode->flags &= ~CHANFLAG_CHAN_REGISTERED;
59 channode->channel_id = 0;
61 channode = getChanByName(new_channel);
62 if(channode && channode->flags & CHANFLAG_REQUESTED_CHANINFO) {
63 channode->flags |= CHANFLAG_CHAN_REGISTERED;
64 channode->channel_id = atoi(row[1]);
66 reply(getTextBot(), user, "NS_MOVE_DONE", channel, new_channel);