multiple fixes
[NeonServV5.git] / src / IRCParser.c
index 97e851aa2eb63b8b4ed0ff7bb2212f5ee99e6244..17aeef45ed25ecfaf89d056c2b94d39c4214f497 100644 (file)
@@ -58,9 +58,9 @@ static void parse_line(struct ClientSocket *client, char *line) {
     int argc = 0;
     char *argv[MAXNUMPARAMS];
     #ifdef HAVE_THREADS
-    printf("[%lu recv %lu] %s\n", syscall(SYS_gettid), (unsigned long) strlen(line), line);
+    putlog(LOGLEVEL_RAW, "[%d recv %lu] %s\n", getCurrentThreadID(), (unsigned long) strlen(line), line);
     #else
-    printf("[recv %lu] %s\n", (unsigned long) strlen(line), line);
+    putlog(LOGLEVEL_RAW, "[recv %lu] %s\n", (unsigned long) strlen(line), line);
     #endif
     if(line[0] == ':')
         line++;
@@ -214,12 +214,12 @@ static IRC_CMD(raw_join) {
         //request member list
         chan->chanbot = user;
         struct ChanUser *chanuser = addChanUser(chan, user); //it must be a bot
-        get_userlist_with_invisible(chan, got_channel_userlist, chanuser);
+        get_userlist_with_invisible(chan, 0, got_channel_userlist, chanuser);
         putsock(client, "MODE %s", chan->name);
         putsock(client, "MODE %s +b", chan->name);
     } else if(!isUserOnChan(user, chan) && ((chan->flags & CHANFLAG_RECEIVED_USERLIST) || isBot(user))) {
         struct ChanUser *chanuser = addChanUser(chan, user);
-        if(isModeSet(chan->modes, 'D'))
+        if(isBot(user) && isModeSet(chan->modes, 'D')) //if the bot joins a channel it could also be invisible
             chanuser->flags |= CHANUSERFLAG_INVISIBLE;
         if(!noEvent) {
             if(wasRegistering)
@@ -482,22 +482,30 @@ static IRC_CMD(raw_topic) {
 
 static IRC_CMD(raw_privmsg) {
     if(from == NULL || argc < 2) return 0;
+    if(!stricmplen(from, "*status", 7) || !stricmplen(from, "-sBNC", 5)) {
+        #ifdef HAVE_THREADS
+        unsigned int tid = (unsigned int) pthread_self_tid();
+        while(!clientsocket_parseorder_top(tid)) {
+            usleep(1000); //1ms
+        }
+        #endif
+        if(!match("Disconnected from IRC.*", argv[1])) {
+            //ZNC DISCONNECT
+            bot_disconnect(client);
+            return 1;
+        }
+        if(!match("* disconnected from the server.", argv[1])) {
+            //sBNC DISCONNECT
+            bot_disconnect(client);
+            return 1;
+        }
+    }
     struct UserNode *user = getUserByMask(from);
     if(user == NULL) {
         user = createTempUserMask(from);
                if(!user) return 0;
         user->flags |= USERFLAG_ISTMPUSER;
     }
-    if(!stricmp(user->nick, "*status") && !match("Disconnected from IRC.*", argv[1])) {
-        //ZNC DISCONNECT
-        bot_disconnect(client);
-        return 1;
-    }
-    if(!stricmp(user->nick, "-sBNC") && !match("* disconnected from the server.", argv[1])) {
-        //sBNC DISCONNECT
-        bot_disconnect(client);
-        return 1;
-    }
     if(argv[0][0] == '#') { //Channel message
         struct ChanNode *chan = getChanByName(argv[0]);
         if(chan && chan->chanbot == client->user) {