added experimental multi thread support
[NeonServV5.git] / src / WHOHandler.c
index eafa62fcfccfd86cba1bfeeeec4fc376fe345b03..a8a55d91c693956cebd57329babecb6ec73fa829 100644 (file)
@@ -21,6 +21,7 @@
 #include "ChanUser.h"
 #include "ModeNode.h"
 #include "ClientSocket.h"
+#include "IPNode.h"
 
 #define WHOQUEUETYPE_ISONQUEUE 0x01
 #define WHOQUEUETYPE_USERLIST  0x02
@@ -45,6 +46,7 @@ static struct WHOQueueEntry* addWHOQueueEntry(struct ClientSocket *client) {
         perror("malloc() failed");
         return NULL;
     }
+    SYNCHRONIZE(cache_sync);
     entry->next = NULL;
     if(client->whoqueue_last) {
         client->whoqueue_last->next = entry;
@@ -52,11 +54,13 @@ static struct WHOQueueEntry* addWHOQueueEntry(struct ClientSocket *client) {
         client->whoqueue_first = entry;
     }
     client->whoqueue_last = entry;
+    DESYNCHRONIZE(cache_sync);
     return entry;
 }
 
 static struct WHOQueueEntry* getNextWHOQueueEntry(struct ClientSocket *client, int freeEntry) {
     if(!client->whoqueue_first) return NULL;
+    SYNCHRONIZE(cache_sync);
     struct WHOQueueEntry *entry = client->whoqueue_first;
     if(freeEntry) {
         client->whoqueue_first = entry->next;
@@ -64,11 +68,13 @@ static struct WHOQueueEntry* getNextWHOQueueEntry(struct ClientSocket *client, i
             client->whoqueue_last = NULL;
         }
     }
+    DESYNCHRONIZE(cache_sync);
     return entry;
 }
 
 void clear_whoqueue(struct ClientSocket *client) {
     if(!client->whoqueue_first) return;
+    SYNCHRONIZE(cache_sync);
     struct WHOQueueEntry *entry, *next;
     for(entry = client->whoqueue_first; entry; entry = next) {
         next = entry->next;
@@ -76,6 +82,7 @@ void clear_whoqueue(struct ClientSocket *client) {
     }
     client->whoqueue_last = NULL;
     client->whoqueue_first = NULL;
+    DESYNCHRONIZE(cache_sync);
 }
 
 void get_userlist(struct ChanNode *chan, userlist_callback_t callback, void *data) {
@@ -107,7 +114,7 @@ void get_userlist(struct ChanNode *chan, userlist_callback_t callback, void *dat
         entry->data[0] = data;
         for(i = 1; i < MAXCALLBACKS; i++)
             entry->data[i] = NULL;
-        putsock(bot, "WHO %s,%d %%tuhnaf,%d", chan->name, entry->type, entry->type);
+        putsock(bot, "WHO %s,%d %%tuihnaf,%d", chan->name, entry->type, entry->type);
     } else
         callback(bot, chan, data);
 }
@@ -142,7 +149,7 @@ void _get_userlist_with_invisible(struct ChanNode *chan, userlist_callback_t cal
         entry->data[0] = data;
         for(i = 1; i < MAXCALLBACKS; i++)
             entry->data[i] = NULL;
-        putsock(bot, "WHO %s,%d d%%tuhnaf,%d", chan->name, entry->type, entry->type);
+        putsock(bot, "WHO %s,%d d%%tuihnaf,%d", chan->name, entry->type, entry->type);
     } else
         callback(bot, chan, data);
 }
@@ -209,8 +216,8 @@ void recv_whohandler_354(struct ClientSocket *client, char **argv, unsigned int
         //parse flags
         int userflags = 0;
         int chanuserflags = 0;
-        for(i = 0; i < strlen(argv[5]); i++) {
-            switch (argv[5][i]) {
+        for(i = 0; i < strlen(argv[6]); i++) {
+            switch (argv[6][i]) {
                 case '@':
                     chanuserflags |= CHANUSERFLAG_OPPED;
                     break;
@@ -231,17 +238,17 @@ void recv_whohandler_354(struct ClientSocket *client, char **argv, unsigned int
             }
         }
         
-        struct UserNode *user = getUserByNick(argv[4]);
+        struct UserNode *user = getUserByNick(argv[5]);
         struct ChanUser *chanuser;
         if((chanuserflags & CHANUSERFLAG_INVISIBLE) && (!user || !isBot(user))) {
-            user = createTempUser(argv[4]);
+            user = createTempUser(argv[5]);
             user->flags |= USERFLAG_ISTMPUSER;
             chan->flags |= CHANFLAG_HAVE_INVISIBLES;
             chanuser = addInvisibleChanUser(chan, user);
             chanuser->flags = (chanuser->flags & ~CHANUSERFLAG_OPPED_OR_VOICED) | chanuserflags;
         } else {
             if(user == NULL) {
-                user = addUser(argv[4]);
+                user = addUser(argv[5]);
             }
             if(!(chanuser = getChanUser(user, chan))) {
                 chanuser = addChanUser(chan, user);
@@ -252,10 +259,12 @@ void recv_whohandler_354(struct ClientSocket *client, char **argv, unsigned int
         user->last_who = time(0);
         if(!*user->ident)
             strcpy(user->ident, argv[2]);
+        if(!user->ip)
+            user->ip = createIPNode(argv[3]);
         if(!*user->host)
-            strcpy(user->host, argv[3]);
-        if(!(user->flags & USERFLAG_ISAUTHED) && strcmp(argv[6], "0")) {
-            strcpy(user->auth, argv[6]);
+            strcpy(user->host, argv[4]);
+        if(!(user->flags & USERFLAG_ISAUTHED) && strcmp(argv[7], "0")) {
+            strcpy(user->auth, argv[7]);
             user->flags |= USERFLAG_ISAUTHED;
         }
     } else if((type & WHOQUEUETYPE_USERAUTH) && !(entry->type & WHOQUEUETYPE_FOUND)) {