fixed auto-rejoin when only bots are in an opless channel
[NeonServV5.git] / src / IRCParser.c
index 2ff95c8ba066b3e2b440d1b6250e4242060e1042..2c30d6992dfe32f89abe3fd6b944d97b3e8652c4 100644 (file)
@@ -27,6 +27,7 @@
 #include "BanNode.h"
 #include "ModeNode.h"
 #include "tools.h"
+#include "bots.h"
 
 struct irc_cmd *irc_commands = NULL;
 static struct UserNode *registering_users = NULL;
@@ -238,11 +239,11 @@ static IRC_CMD(raw_join) {
             free(chan->rejoin_array);
             chan->flags &= ~CHANFLAG_REJOINING;
         }
-    } else if(chan->usercount == 1 && isUserOnChan(user, chan)) {
+    } else if(isUserOnChan(user, chan)) { //user is already in the channel? ^^
         //first bot rejoined
+        chan->flags &= ~CHANFLAG_RECEIVED_USERLIST;
         struct ChanUser *chanuser = getChanUser(user, chan);
-        chanuser->flags &= ~CHANUSERFLAG_VOICED;
-        chanuser->flags |= CHANUSERFLAG_OPPED;
+        get_userlist_with_invisible(chan, 0, got_channel_userlist, chanuser);
     }
     DESYNCHRONIZE(cache_sync);
     return 1;
@@ -328,8 +329,14 @@ static IRC_CMD(raw_part) {
     }
     else if(keep_channel && (chan->flags & CHANFLAG_REJOINING) && chan->usercount == 1) {
         //bot is alone... rejoin!
-        putsock(client, "PART %s :magic hop", chan->name);
-        putsock(client, "JOIN %s", chan->name);
+        struct ClientSocket *bot;
+        //find the last bot in the channel
+        for(bot = getBots(SOCKET_FLAG_READY, NULL); bot; bot = getBots(SOCKET_FLAG_READY, bot)) {
+            if(bot->user == chan->chanbot) {
+                putsock(bot, "PART %s :magic hop", chan->name);
+                putsock(bot, "JOIN %s", chan->name);
+            }
+        }
     }
     DESYNCHRONIZE(cache_sync);
     return 1;
@@ -798,6 +805,15 @@ static IRC_CMD(raw_005) {
     return 1;
 }
 
+static IRC_CMD(raw_nojoin) {
+    if(from == NULL || argc < 3) return 0;
+    struct ChanNode *chan = getChanByName(argv[1]);
+    if(chan == NULL) return 0;
+    if(client->flags & SOCKET_FLAG_REQUEST_INVITE)
+        requestInvite(client->user, chan);
+    return 1;
+}
+
 void init_parser() {
     //all the raws we receive...
     register_irc_function("437", raw_437);
@@ -808,6 +824,10 @@ void init_parser() {
     register_irc_function("324", raw_324);
     register_irc_function("332", raw_332);
     register_irc_function("367", raw_367);
+    register_irc_function("471", raw_nojoin);
+    register_irc_function("473", raw_nojoin);
+    register_irc_function("474", raw_nojoin);
+    register_irc_function("475", raw_nojoin);
     register_irc_function("INVITE", raw_invite);
     register_irc_function("NOTICE", raw_notice);
     register_irc_function("TOPIC", raw_topic);