added .gitignore
[NeonServV5.git] / WHOHandler.c
index f2de5a1fd1cee519aa4c0a7527406e34576d11db..38e0ce745b28a37281d953850816aa014318264a 100644 (file)
@@ -2,6 +2,8 @@
 #include "WHOHandler.h"
 #include "ChanNode.h"
 #include "UserNode.h"
+#include "ChanUser.h"
+#include "ClientSocket.h"
 
 #define WHOQUEUETYPE_ISONQUEUE 0x01
 #define WHOQUEUETYPE_USERLIST  0x02
@@ -13,6 +15,7 @@ struct WHOQueueEntry {
     struct UserNode *user;
     struct WHOQueueEntry *next;
     userlist_callback_t *callback;
+    void *data;
 };
 
 static struct WHOQueueEntry *first_entry = NULL, *last_entry = NULL;
@@ -30,6 +33,7 @@ static struct WHOQueueEntry* addWHOQueueEntry(struct ClientSocket *client) {
         last_entry->next = entry;
     if(!first_entry)
         first_entry = entry;
+    return entry;
 }
 
 static struct WHOQueueEntry* getNextWHOQueueEntry(struct ClientSocket *client, int freeEntry) {
@@ -48,7 +52,7 @@ static struct WHOQueueEntry* getNextWHOQueueEntry(struct ClientSocket *client, i
     return entry;
 }
 
-void get_userlist(struct ChanNode *chan, userlist_callback_t callback) {
+void get_userlist(struct ChanNode *chan, userlist_callback_t callback, void *data) {
     struct ClientSocket *bot;
     for(bot = getBots(SOCKET_FLAG_READY, NULL); bot; bot = getBots(SOCKET_FLAG_READY, bot)) {
         if(isUserOnChan(bot->user, chan))
@@ -59,6 +63,7 @@ void get_userlist(struct ChanNode *chan, userlist_callback_t callback) {
     entry->type = WHOQUEUETYPE_ISONQUEUE | WHOQUEUETYPE_USERLIST;
     entry->chan = chan;
     entry->callback = callback;
+    entry->data = data;
     //WHO ".$channel->getName().",".$id." d%tuhnaf,".$id
     putsock(bot, "WHO %s,%d %%tuhnaf,%d", chan->name, entry->type, entry->type);
 }
@@ -123,7 +128,17 @@ void recv_whohandler_315(struct ClientSocket *client, char **argv, unsigned int
     if(type & WHOQUEUETYPE_USERLIST) {
         //:OGN2.OnlineGamesNet.net 315 skynet #pk910,1 :End of /WHO list.
         entry->chan->flags |= CHANFLAG_RECEIVED_USERLIST;
-        entry->callback(client, entry->chan);
+        entry->callback(client, entry->chan, entry->data);
     }
     free(entry);
 }
+
+void free_whoqueue() {
+    struct WHOQueueEntry *entry, *next;
+    for(entry = first_entry; entry; entry = next) {
+        next = entry->next;
+        free(entry);
+    }
+    first_entry = NULL;
+    last_entry = NULL;
+}