2 #include "WHOHandler.h"
6 #define WHOQUEUETYPE_ISONQUEUE 0x01
7 #define WHOQUEUETYPE_USERLIST 0x02
11 struct ClientSocket *client;
12 struct ChanNode *chan;
13 struct UserNode *user;
14 struct WHOQueueEntry *next;
15 userlist_callback_t *callback;
18 static struct WHOQueueEntry *first_entry = NULL, *last_entry = NULL;
20 static struct WHOQueueEntry* addWHOQueueEntry(struct ClientSocket *client) {
21 struct WHOQueueEntry *entry = malloc(sizeof(*entry));
24 perror("malloc() failed");
28 entry->client = client;
30 last_entry->next = entry;
36 static struct WHOQueueEntry* getNextWHOQueueEntry(struct ClientSocket *client, int freeEntry) {
37 if(!first_entry) return NULL;
38 struct WHOQueueEntry *entry;
39 for(entry = first_entry; entry; entry = entry->next) {
40 if(entry->client == client)
43 if(entry == NULL) return NULL;
45 first_entry = first_entry->next;
46 if(last_entry == first_entry)
52 void get_userlist(struct ChanNode *chan, userlist_callback_t callback) {
53 struct ClientSocket *bot;
54 for(bot = getBots(SOCKET_FLAG_READY, NULL); bot; bot = getBots(SOCKET_FLAG_READY, bot)) {
55 if(isUserOnChan(bot->user, chan))
58 if(bot == NULL) return;
59 struct WHOQueueEntry* entry = addWHOQueueEntry(bot);
60 entry->type = WHOQUEUETYPE_ISONQUEUE | WHOQUEUETYPE_USERLIST;
62 entry->callback = callback;
63 //WHO ".$channel->getName().",".$id." d%tuhnaf,".$id
64 putsock(bot, "WHO %s,%d %%tuhnaf,%d", chan->name, entry->type, entry->type);
67 void recv_whohandler_354(struct ClientSocket *client, char **argv, unsigned int argc) {
70 int type = atoi(argv[1]);
71 if(!(type & WHOQUEUETYPE_ISONQUEUE)) return;
72 struct WHOQueueEntry* entry = getNextWHOQueueEntry(client, 0);
73 if(entry == NULL || entry->type != type) return;
74 if(type & WHOQUEUETYPE_USERLIST) {
76 //:OGN2.OnlineGamesNet.net 354 skynet 1 pk910 2001:41d0:2:1d3b::babe skynet H@ pk910
77 struct ChanNode *chan = entry->chan;
78 //add the user toe the channel if he isn't added, yet and update its user data
79 struct UserNode *user = getUserByNick(argv[4]);
81 user = addUser(argv[4]);
85 int chanuserflags = 0;
86 for(i = 0; i < strlen(argv[5]); i++) {
89 chanuserflags |= CHANUSERFLAG_OPPED;
92 chanuserflags |= CHANUSERFLAG_VOICED;
95 userflags |= USERFLAG_ISIRCOP;
101 user->flags = (user->flags & ~USERFLAG_ISIRCOP) | userflags;
102 if(!isUserOnChan(user, chan)) {
103 struct ChanUser *chanuser = addChanUser(chan, user);
104 chanuser->flags = (chanuser->flags & ~CHANUSERFLAG_OPPED_OR_VOICED) | chanuserflags;
107 strcpy(user->ident, argv[2]);
109 strcpy(user->host, argv[3]);
110 if(!(user->flags & USERFLAG_ISAUTHED) && strcmp(argv[6], "0")) {
111 strcpy(user->auth, argv[6]);
112 user->flags |= USERFLAG_ISAUTHED;
117 void recv_whohandler_315(struct ClientSocket *client, char **argv, unsigned int argc) {
119 char *typestr = strstr(argv[1], ",") + 1;
120 int type = atoi(typestr);
121 if(!(type & WHOQUEUETYPE_ISONQUEUE)) return;
122 struct WHOQueueEntry* entry = getNextWHOQueueEntry(client, 1);
123 if(entry == NULL || entry->type != type) return;
124 if(type & WHOQUEUETYPE_USERLIST) {
125 //:OGN2.OnlineGamesNet.net 315 skynet #pk910,1 :End of /WHO list.
126 entry->chan->flags |= CHANFLAG_RECEIVED_USERLIST;
127 entry->callback(client, entry->chan);