d90ac64ee48299af4540cf0cac2ca70b3b102316
[NeonServV5.git] / cmd_neonserv_csuspend.c
1
2 /*
3 * argv[0] - channel
4 */
5 static CMD_BIND(neonserv_cmd_csuspend) {
6     MYSQL_RES *res;
7     MYSQL_ROW row;
8     char *channel = argv[0];
9     if(!is_valid_chan(channel)) {
10         reply(getTextBot(), user, "NS_INVALID_CHANNEL_NAME", argv[0]);
11         return;
12     }
13     int chanid;
14     printf_mysql_query("SELECT `channel_id` FROM `channels` WHERE `channel_name` = '%s'", escape_string(channel));
15     res = mysql_use();
16     if ((row = mysql_fetch_row(res)) != NULL) {
17         chanid = atoi(row[0]);
18     } else {
19         reply(getTextBot(), user, "NS_UNREGISTER_NOT_REGISTERED", argv[0], client->user->nick);
20         return;
21     }
22     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);
23     res = mysql_use();
24     if ((row = mysql_fetch_row(res)) == NULL) {
25         reply(getTextBot(), user, "NS_UNREGISTER_NOT_REGISTERED", argv[0], client->user->nick);
26         return;
27     }
28     if(!strcmp(row[2], "1")) {
29         reply(getTextBot(), user, "NS_CSUSPEND_ALREADY", channel);
30         return;
31     }
32     int botid = atoi(row[0]);
33     struct ClientSocket *bot;
34     for(bot = getBots(SOCKET_FLAG_READY, NULL); bot; bot = getBots(SOCKET_FLAG_READY, bot)) {
35         if(bot->clientid == botid)
36             break;
37     }
38     if(bot) {
39         putsock(bot, "PART %s :Channel suspended.", channel);
40     }
41     printf_mysql_query("UPDATE `bot_channels` SET `suspended` = '1' WHERE `id` = '%s'", row[1]);
42     reply(getTextBot(), user, "NS_CSUSPEND_DONE", channel);
43     logEvent(event);
44 }