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