added NeonBackup recover command
authorpk910 <philipp@zoelle1.de>
Thu, 6 Dec 2012 22:28:45 +0000 (23:28 +0100)
committerpk910 <philipp@zoelle1.de>
Thu, 6 Dec 2012 22:36:15 +0000 (23:36 +0100)
Makefile.am
src/modules/NeonBackup.mod/cmd_neonbackup.c
src/modules/NeonBackup.mod/cmd_neonbackup.h
src/modules/NeonBackup.mod/cmd_neonbackup_recover.c [new file with mode: 0644]

index b03b830..679e1f6 100644 (file)
@@ -67,6 +67,7 @@ libNeonHelp_la_LIBADD = $(MYSQL_LIBS)
 
 libNeonBackup_la_SOURCES = src/modules/NeonBackup.mod/bot_NeonBackup.c \
       src/modules/NeonBackup.mod/cmd_neonbackup.c \
+      src/modules/NeonBackup.mod/cmd_neonbackup_recover.c \
       src/modules/NeonBackup.mod/module.c
 libNeonBackup_la_LDFLAGS = -module -rpath /nowhere -avoid-version -no-undefined
 libNeonBackup_la_LIBADD = $(MYSQL_LIBS)
index 9234854..f78bf37 100644 (file)
@@ -23,6 +23,9 @@ void register_commands() {
     //NeonBackup Commands
     register_command_alias(6, "NeonBackup");
     
-    
+    #define OPER_COMMAND(NAME,FUNCTION,PARAMCOUNT,GACCESS,FLAGS) register_command(6, NAME, module_id, FUNCTION, PARAMCOUNT, NULL, GACCESS, FLAGS)
+    //            NAME            FUNCTION              PARAMS  ACCS  FLAGS
+    OPER_COMMAND("recover",      neonbackup_cmd_recover, 0,     900,  CMDFLAG_REQUIRE_AUTH | CMDFLAG_CHECK_AUTH);
+    #undef OPER_COMMAND
     
 }
\ No newline at end of file
index fed816d..d6f1763 100644 (file)
@@ -32,5 +32,6 @@
 
 void register_commands();
 
+CMD_BIND(neonbackup_cmd_recover);
 
 #endif
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);
+}