Merge branch 'development'
[NeonServV5.git] / src / modules / NeonBackup.mod / cmd_neonbackup_recover.c
1 /* cmd_neonbackup_recover.c - NeonServ v5.6
2  * Copyright (C) 2011-2012  Philipp Kreil (pk910)
3  * 
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.
8  * 
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.
13  * 
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/>. 
16  */
17
18 #include "cmd_neonbackup.h"
19
20 /*
21 * no argv
22 */
23 static struct ClientSocket *neonbackup_cmd_recover_get_bot(int clientid) {
24     struct ClientSocket *bot;
25     for(bot = getBots(SOCKET_FLAG_READY, NULL); bot; bot = getBots(SOCKET_FLAG_READY, bot)) {
26         if(bot->clientid == clientid)
27             return bot;
28     }
29     return NULL;
30 }
31
32 CMD_BIND(neonbackup_cmd_recover) {
33     MYSQL_RES *res;
34     MYSQL_ROW row;
35     printf_mysql_query("SELECT `channels`.`channel_name`, `bots`.`id` FROM `bot_channels`, `bots`, `channels` WHERE `bots`.`id` = `botid` AND `channel_id` = `chanid` AND `active` = 1");
36     res = mysql_use();
37     
38     struct ClientSocket *bot;
39     struct ChanUser *chanuser;
40     while ((row = mysql_fetch_row(res)) != NULL) {
41         chan = getChanByName(row[0]);
42         if(!chan)
43             continue;
44         bot = neonbackup_cmd_recover_get_bot(atoi(row[1]));
45         if(!bot)
46             continue;
47         if(!(chanuser = getChanUser(bot->user, chan))) {
48             requestInvite(bot->user, chan);
49             reply(textclient, user, "NS_INVITE_DONE", bot->user->nick, chan->name);
50         } else if(!chanuser->flags & CHANUSERFLAG_OPPED) {
51             requestOp(bot->user, chan);
52             reply(textclient, user, "NS_OP_DONE", chan->name);
53         }
54     }
55     logEvent(event);
56 }