}
static USERLIST_CALLBACK(got_channel_userlist) {
- chan->flags |= CHANFLAG_RECEIVED_USERLIST;
+ putsock(client, "PRIVMSG %s :[BOT JOIN] Users on this Channel:", chan->name);
+ struct ChanUser *chanuser;
+ for(chanuser = getChannelUsers(chan, NULL); chanuser; chanuser = getChannelUsers(chan, chanuser)) {
+ putsock(client, "PRIVMSG %s : %s!%s@%s [%s] rights: %d", chanuser->user->nick, chanuser->user->ident, chanuser->user->host, ((chanuser->user->flags & USERFLAG_ISAUTHED) ? chanuser->user->auth : "0"), chanuser->flags);
+ }
}
static IRC_CMD(raw_001) {
if(chan == NULL) {
chan = addChannel(argv[0]);
//request member list
+ addChanUser(chan, user); //it must be a bot
get_userlist(chan, got_channel_userlist);
} else if(!isUserOnChan(user, chan) && (chan->flags & CHANFLAG_RECEIVED_USERLIST)) {
struct ChanUser *chanuser = addChanUser(chan, user);
#include "ChanNode.h"
#include "UserNode.h"
+#define WHOQUEUETYPE_ISONQUEUE 0x01
+#define WHOQUEUETYPE_USERLIST 0x02
+
struct WHOQueueEntry {
char type;
+ struct ClientSocket *client;
struct ChanNode *chan;
struct UserNode *user;
struct WHOQueueEntry *next;
+ userlist_callback_t callback;
}
static struct WHOQueueEntry *first_entry = NULL, *last_entry = NULL;
-static struct WHOQueueEntry* addWHOQueueEntry() {
+static struct WHOQueueEntry* addWHOQueueEntry(struct ClientSocket *client) {
struct WHOQueueEntry *entry = malloc(sizeof(*entry));
if (!entry)
{
return NULL;
}
entry->next = NULL;
+ entry->client = client;
if(last_entry)
last_entry->next = entry;
if(!first_entry)
first_entry = entry;
}
-static struct WHOQueueEntry* getNextWHOQueueEntry(int remove) {
+static struct WHOQueueEntry* getNextWHOQueueEntry(struct ClientSocket *client, int remove) {
if(!first_entry) return NULL;
- struct WHOQueueEntry *entry = first_entry;
+ struct WHOQueueEntry *entry;
+ for(entry = first_entry; entry; entry = entry->next) {
+ if(entry->client == client)
+ break;
+ }
+ if(entry == NULL) return NULL;
if(remove) {
first_entry = first_entry->next;
if(last_entry == first_entry)
}
void get_userlist(struct ChanNode *chan, userlist_callback_t callback) {
-
+ struct ClientSocket *bot;
+ for(bot = getBots(SOCKET_FLAG_READY, NULL); bot; bot = getBots(SOCKET_FLAG_READY, bot)) {
+ if(isUserOnChan(bot->user, chan))
+ break;
+ }
+ if(bot == NULL) return;
+ struct WHOQueueEntry* entry = addWHOQueueEntry(bot);
+ entry->type = WHOQUEUETYPE_ISONQUEUE | WHOQUEUETYPE_USERLIST;
+ entry->chan = chan;
+ entry->callback = callback;
+ //WHO ".$channel->getName().",".$id." d%tuhnaf,".$id
+ 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) {
- struct WHOQueueEntry* entry = getNextWHOQueueEntry(0);
-
+ int i;
+ if(argc < 2) return;
+ int type = atoi(argv[1]);
+ if(!(type & WHOQUEUETYPE_ISONQUEUE)) return;
+ struct WHOQueueEntry* entry = getNextWHOQueueEntry(client, 0);
+ if(entry == NULL || entry->type != type) return;
+ if(type & WHOQUEUETYPE_USERLIST) {
+ if(argc < 7) return;
+ //:OGN2.OnlineGamesNet.net 354 skynet 1 pk910 2001:41d0:2:1d3b::babe skynet H@ pk910
+ struct ChanNode *chan = entry->chan;
+ //add the user toe the channel if he isn't added, yet and update its user data
+ struct UserNode *user = getUserByNick(argv[4]);
+ if(user == NULL) {
+ user = addUser(argv[4]);
+ }
+ //parse flags
+ int userflags = 0;
+ int chanuserflags = 0;
+ for(i = 0; i < strlen(argv[5]); i++) {
+ switch (argv[5][i]) {
+ case '@':
+ chanuserflags |= CHANUSERFLAG_OPPED;
+ break;
+ case '+':
+ chanuserflags |= CHANUSERFLAG_VOICED;
+ break;
+ case '*':
+ userflags |= USERFLAG_ISIRCOP;
+ break;
+ default:
+ break;
+ }
+ }
+ user->flags = (user->flags & ~USERFLAG_ISIRCOP) | userflags;
+ if(!isUserOnChan(user, chan)) {
+ struct ChanUser *chanuser = addChanUser(chan, user);
+ chanuser->flags = (chanuser->flags & ~CHANUSERFLAG_OPPED_OR_VOICED) | chanuserflags;
+ }
+ if(!*user->ident)
+ strcpy(user->ident, argv[2]);
+ if(!*user->host)
+ strcpy(user->host, argv[3]);
+ if(!(user->flags & USERFLAG_ISAUTHED) && strcmp(argv[6], "0")) {
+ strcpy(user->auth, argv[6]);
+ user->flags |= USERFLAG_ISAUTHED;
+ }
+ }
}
void recv_whohandler_315(struct ClientSocket *client, char **argv, unsigned int argc) {
- struct WHOQueueEntry* entry = getNextWHOQueueEntry(1);
-
+ if(argc < 2) return;
+ char *typestr = strstr(argv[1], ",") + 1;
+ int type = atoi(typestr);
+ if(!(type & WHOQUEUETYPE_ISONQUEUE)) return;
+ struct WHOQueueEntry* entry = getNextWHOQueueEntry(client, 1);
+ if(entry == NULL || entry->type != type) return;
+ 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);
+ }
free(entry);
}