added recover function to NeonBackup (used to recover Bot privileges when NeonBackup...
[NeonServV5.git] / src / modules / NeonBackup.mod / bot_NeonBackup.c
index 9738afbdcb80cd5747dc24fdcd15c003cb4f3e9a..19cffbde99cd6caafcbe9e4e2c6c05f9bcd44939 100644 (file)
@@ -96,7 +96,7 @@ static void start_bots(int type) {
             client->flags |= (strcmp(row[6], "0") ? SOCKET_FLAG_PREFERRED : 0);
             client->flags |= (strcmp(row[8], "0") ? SOCKET_FLAG_USE_QUEUE : 0);
             client->flags |= (strcmp(row[9], "0") ? SOCKET_FLAG_SSL : 0);
-            client->flags |= SOCKET_FLAG_REQUEST_INVITE;
+            client->flags |= SOCKET_FLAG_REQUEST_INVITE | SOCKET_FLAG_REQUEST_OP;
             client->botid = BOTID;
             client->clientid = atoi(row[7]);
             connect_socket(client);
@@ -124,7 +124,23 @@ static void start_bots(int type) {
 }
 
 void neonbackup_recover_chan(struct ChanNode *chan) {
-    
+    struct ClientSocket *bot = getChannelBot(chan, BOTID); // prefer backup bot ;)
+    struct ChanUser *chanuser = (bot ? getChanUser(bot->user, chan) : NULL);
+    if(!chanuser || !(chanuser->flags & CHANUSERFLAG_OPPED)) {
+        //search an opped bot
+        for(bot = getBots(SOCKET_FLAG_READY, NULL); bot; bot = getBots(SOCKET_FLAG_READY, bot)) {
+            if((chanuser = getChanUser(bot->user, chan)) && (chanuser->flags & CHANUSERFLAG_OPPED))
+                break;
+        }
+    }
+    if(!bot) //no opped bots present... channel can't be recovered
+        return;
+    struct ClientSocket *target;
+    for(target = getBots(SOCKET_FLAG_READY, NULL); target; target = getBots(SOCKET_FLAG_READY, target)) {
+        if((target->flags & SOCKET_FLAG_REQUEST_OP) && (chanuser = getChanUser(target->user, chan)) && !(chanuser->flags & CHANUSERFLAG_OPPED)) {
+            putsock(bot, "MODE %s +o %s", chan->name, target->user->nick);
+        }
+    }
 }
 
 static void neonbackup_event_join(struct ChanUser *chanuser) {