fixed viscount update when another bot joins a channel
[NeonServV5.git] / src / IRCParser.c
index d13c173b7af02949ccc05011ca7623f8dad39184..1d53ec2aa1ba6c4e82e0d1a53a527ded07a56747 100644 (file)
@@ -35,27 +35,10 @@ int statistics_privmsg = 0;
 int statistics_network_users = 0;
 int statistics_network_channels = 0;
 
-static void parse_line(struct ClientSocket *client, char *line);
 static void register_irc_function(char *command, irc_cmd_t *func);
 static void parse_raw(struct ClientSocket *client, char *from, char *cmd, char **argv, int argc);
 
-int parse_lines(struct ClientSocket *client, char *lines, int len) {
-    int i, used = 0;
-    char *line = lines;
-    for(i = 0; i < len; i++) {
-        if(lines[i] == '\r') //just zero it out :D
-            lines[i] = 0;
-        if(lines[i] == '\n') {
-            lines[i] = 0;
-            parse_line(client, line);
-            line = lines+(i+1);
-            used = i+1;
-        }
-    }
-    return used;
-}
-
-static void parse_line(struct ClientSocket *client, char *line) {
+void parse_line(struct ClientSocket *client, char *line) {
     int argc = 0;
     char *argv[MAXNUMPARAMS];
     #ifdef HAVE_THREADS
@@ -204,7 +187,7 @@ static IRC_CMD(raw_join) {
         //join user to an existing channel
         chanuser = addChanUser(chan, user);
         chanuser->visCount = 1;
-        if(isBot(user)) {
+        if(isBot(user) && client->user == user) {
             if(isModeSet(chan->modes, 'D')) //if the bot joins a channel it could also be invisible
                 chanuser->flags |= CHANUSERFLAG_INVISIBLE;
             increase_viscount_butone(chan, chanuser);
@@ -227,7 +210,7 @@ static IRC_CMD(raw_join) {
         chanuser = getChanUser(user, chan);
         chanuser->visCount++;
         
-        if(isBot(user) && !(chanuser->flags & CHANUSERFLAG_INVISIBLE))
+        if(isBot(user) && client->user == user)
             increase_viscount_butone(chan, chanuser);
         
         //if multiple bots see the user, it can't be invisible
@@ -412,13 +395,16 @@ static IRC_CMD(raw_quit) {
     struct ChanUser *chanuser, *next_chanuser;
     for(chanuser = getUserChannels(user, NULL); chanuser; chanuser = next_chanuser) {
         next_chanuser = getUserChannels(user, chanuser);
-        chanuser->visCount--;
-        if(chanuser->visCount <= 0 && !(user->flags & USERFLAG_WAS_REGISTERING)) {
-            delChanUser(chanuser, 0); //not free, yet!
-            event_part(chanuser, 1, argv[0]);
-            if((chanuser->chan->flags & CHANFLAG_RECEIVED_USERLIST) && !(chanuser->chan->flags & CHANFLAG_REJOINING))
-                check_full_rejoin(chanuser->chan);
-            freeChanUser(chanuser);
+        //decrease visCount counter only if client is in the channel
+        if(isUserOnChan(client->user, chanuser->chan)) {
+            chanuser->visCount--;
+            if(chanuser->visCount <= 0 && !(user->flags & USERFLAG_WAS_REGISTERING)) {
+                delChanUser(chanuser, 0); //not free, yet!
+                event_part(chanuser, 1, argv[0]);
+                if((chanuser->chan->flags & CHANFLAG_RECEIVED_USERLIST) && !(chanuser->chan->flags & CHANFLAG_REJOINING))
+                    check_full_rejoin(chanuser->chan);
+                freeChanUser(chanuser);
+            }
         }
     }