added NeonBackup recover command
[NeonServV5.git] / src / modules / NeonBackup.mod / cmd_neonbackup_recover.c
diff --git a/src/modules/NeonBackup.mod/cmd_neonbackup_recover.c b/src/modules/NeonBackup.mod/cmd_neonbackup_recover.c
new file mode 100644 (file)
index 0000000..dc71276
--- /dev/null
@@ -0,0 +1,56 @@
+/* cmd_neonbackup_recover.c - NeonServ v5.6
+ * Copyright (C) 2011-2012  Philipp Kreil (pk910)
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License 
+ * along with this program. If not, see <http://www.gnu.org/licenses/>. 
+ */
+
+#include "cmd_neonbackup.h"
+
+/*
+* no argv
+*/
+static struct ClientSocket *neonbackup_cmd_recover_get_bot(int clientid) {
+    struct ClientSocket *bot;
+    for(bot = getBots(SOCKET_FLAG_READY, NULL); bot; bot = getBots(SOCKET_FLAG_READY, bot)) {
+        if(bot->clientid == clientid)
+            return bot;
+    }
+    return NULL;
+}
+
+CMD_BIND(neonbackup_cmd_recover) {
+    MYSQL_RES *res;
+    MYSQL_ROW row;
+    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");
+    res = mysql_use();
+    
+    struct ClientSocket *bot;
+    struct ChanUser *chanuser;
+    while ((row = mysql_fetch_row(res)) != NULL) {
+        chan = getChanByName(row[0]);
+        if(!chan)
+            continue;
+        bot = neonbackup_cmd_recover_get_bot(atoi(row[1]));
+        if(!bot)
+            continue;
+        if(!(chanuser = getChanUser(bot->user, chan))) {
+            requestInvite(bot->user, chan);
+            reply(textclient, user, "NS_INVITE_DONE", bot->user->nick, chan->name);
+        } else if(!chanuser->flags & CHANUSERFLAG_OPPED) {
+            requestOp(bot->user, chan);
+            reply(textclient, user, "NS_OP_DONE", chan->name);
+        }
+    }
+    logEvent(event);
+}