#include "WHOHandler.h"
#include "ChanNode.h"
#include "UserNode.h"
+#include "ChanUser.h"
+#include "ClientSocket.h"
#define WHOQUEUETYPE_ISONQUEUE 0x01
#define WHOQUEUETYPE_USERLIST 0x02
struct ChanNode *chan;
struct UserNode *user;
struct WHOQueueEntry *next;
- userlist_callback_t callback;
-}
+ userlist_callback_t *callback;
+ void *data;
+};
static struct WHOQueueEntry *first_entry = NULL, *last_entry = NULL;
last_entry->next = entry;
if(!first_entry)
first_entry = entry;
+ return entry;
}
-static struct WHOQueueEntry* getNextWHOQueueEntry(struct ClientSocket *client, int remove) {
+static struct WHOQueueEntry* getNextWHOQueueEntry(struct ClientSocket *client, int freeEntry) {
if(!first_entry) return NULL;
struct WHOQueueEntry *entry;
for(entry = first_entry; entry; entry = entry->next) {
break;
}
if(entry == NULL) return NULL;
- if(remove) {
+ if(freeEntry) {
first_entry = first_entry->next;
if(last_entry == first_entry)
last_entry = NULL;
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))
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);
+ putsock(bot, "WHO %s,%d %%tuhnaf,%d", chan->name, entry->type, entry->type);
}
void recv_whohandler_354(struct ClientSocket *client, char **argv, unsigned int argc) {
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;
+}