#include "ChanUser.h"
#include "IRCEvents.h"
#include "ClientSocket.h"
+#include "WHOHandler.h"
struct irc_cmd *irc_commands = NULL;
}
}
if(!ret) {
- fprintf(stderr,"PARSE ERROR: %s", cmd);
+ //fprintf(stderr,"PARSE ERROR: %s", cmd); commented out right now - we're still developing and this is very spammy
+ }
+}
+
+static USERLIST_CALLBACK(got_channel_userlist) {
+ struct ChanUser *chanuser = data;
+ event_join(chanuser);
+ putsock(client, "PRIVMSG %s :[BOT JOIN] Users on this Channel:", chan->name);
+ for(chanuser = getChannelUsers(chan, NULL); chanuser; chanuser = getChannelUsers(chan, chanuser)) {
+ putsock(client, "PRIVMSG %s : %s!%s@%s [%s] rights: %d", chan->name, chanuser->user->nick, chanuser->user->ident, chanuser->user->host, ((chanuser->user->flags & USERFLAG_ISAUTHED) ? chanuser->user->auth : "*"), chanuser->flags);
}
}
static IRC_CMD(raw_join) {
if(from == NULL || argc < 1) return 0;
struct UserNode *user = getUserByMask(from);
+ struct ChanNode *chan = getChanByName(argv[0]);
+ if(!chan && !(user->flags & USERFLAG_ISBOT)) return 0;
if(user == NULL) {
user = addUserMask(from);
}
- struct ChanNode *chan = getChanByName(argv[0]);
if(chan == NULL) {
chan = addChannel(argv[0]);
-
+ //request member list
+ chan->chanbot = user;
+ struct ChanUser *chanuser = addChanUser(chan, user); //it must be a bot
+ get_userlist(chan, got_channel_userlist, chanuser);
+ } else if(!isUserOnChan(user, chan) && (chan->flags & CHANFLAG_RECEIVED_USERLIST)) {
+ struct ChanUser *chanuser = addChanUser(chan, user);
+ event_join(chanuser);
+ }
+ return 1;
+}
+
+static IRC_CMD(raw_part) {
+ if(from == NULL || argc < 2) return 0;
+ struct UserNode *user = getUserByMask(from);
+ if(user == NULL) return 0;
+ struct ChanNode *chan = getChanByName(argv[0]);
+ if(chan == NULL) return 0;
+ if(isUserOnChan(user, chan) && (chan->flags & CHANFLAG_RECEIVED_USERLIST)) {
+ struct ChanUser *chanuser = getChanUser(user, chan);
+ delChanUser(chanuser, 0); //we need to free the chanuser manually!
+ event_part(chanuser, argv[1]);
+ free(chanuser);
+ if(chan->chanbot == user) {
+ //check if theres another bot in the channel - otherwise free it
+ checkChannelVisibility(chan);
+ }
+ }
+ if(user->channel == NULL && !(user->flags & USERFLAG_ISBOT)) {
+ //remove the user
+ delUser(user, 1);
+ }
+ return 1;
+}
+
+static IRC_CMD(raw_quit) {
+ if(from == NULL || argc < 2) return 0;
+ struct UserNode *user = getUserByMask(from);
+ if(user == NULL) return 0;
+ delUser(user, 0); //a little bit crazy, but we want to delete the user on the channel's userlists - but not the users channel list
+ event_quit(user, argv[1]);
+ if(user->flags & USERFLAG_ISBOT) {
+ //check if there are other bots in the users channel - otherwise free them
+ struct ChanUser *chanuser, *next;
+ for(chanuser = getUserChannels(user, NULL); chanuser; chanuser = next) {
+ next = getUserChannels(user, chanuser);
+ checkChannelVisibility(chanuser->chan);
+ }
+ }
+ delUser(user, 1); //now we fully free the user
+ return 1;
+}
+
+void bot_disconnect(struct ClientSocket *client) {
+ struct UserNode *user = client->user;
+ struct ChanUser *chanuser, *next;
+ delUser(user, 0);
+ event_quit(user, "disconnected");
+ for(chanuser = getUserChannels(user, NULL); chanuser; chanuser = next) {
+ next = getUserChannels(user, chanuser);
+ checkChannelVisibility(chanuser->chan);
+ free(chanuser);
+ }
+ user->channel = NULL;
+}
+
+static IRC_CMD(raw_kick) {
+ if(from == NULL || argc < 3) return 0;
+ struct UserNode *user = getUserByMask(from);
+ struct UserNode *target = getUserByNick(argv[1]);
+ struct ChanNode *chan = getChanByName(argv[0]);
+ if(chan == NULL || target == NULL) return 0;
+ if(isUserOnChan(target, chan) && (chan->flags & CHANFLAG_RECEIVED_USERLIST)) {
+ if(user == NULL) {
+ user = createTempUser(from);
+ user->flags |= USERFLAG_ISTMPUSER;
+ }
+ struct ChanUser *chanuser = getChanUser(target, chan);
+ delChanUser(chanuser, 0); //we need to free the chanuser manually!
+ event_kick(user, chanuser, argv[1]);
+ free(chanuser);
+ if(target->flags & USERFLAG_ISBOT) {
+ //check if theres another bot in the channel - otherwise free it
+ checkChannelVisibility(chan);
+ }
+ }
+ if(target->channel == NULL && !(target->flags & USERFLAG_ISBOT)) {
+ //remove the user
+ delUser(user, 1);
}
- putsock(client, "PRIVMSG #pktest :hi");
-
+ return 1;
+}
+
+static IRC_CMD(raw_topic) {
+ if(from == NULL || argc < 2) return 0;
+ struct UserNode *user = getUserByMask(from);
+ struct ChanNode *chan = getChanByName(argv[0]);
+ if(chan == NULL) return 0;
+ if(chan->chanbot != client->user) return 1; //just ignore it to prevent event duplicates
+ if(user == NULL) {
+ user = createTempUser(from);
+ user->flags |= USERFLAG_ISTMPUSER;
+ }
+ event_topic(user, chan, argv[1]);
+ strcpy(chan->topic, argv[1]);
+ return 1;
+}
+
+static IRC_CMD(raw_privmsg) {
+ if(from == NULL || argc < 2) return 0;
+ struct UserNode *user = getUserByMask(from);
+ if(user == NULL) {
+ user = createTempUser(from);
+ user->flags |= USERFLAG_ISTMPUSER;
+ }
+ if(argv[0][0] == '#') { //Channel message
+ struct ChanNode *chan = getChanByName(argv[0]);
+ if(chan && chan->chanbot == client->user)
+ event_chanmsg(user, chan, argv[1]);
+ } else {
+ struct UserNode *target = getUserByNick(argv[0]);
+ if(target)
+ event_privmsg(user, target, argv[1]);
+ }
+ return 1;
+}
+
+static IRC_CMD(raw_notice) {
+ if(from == NULL || argc < 2) return 0;
+ struct UserNode *user = getUserByMask(from);
+ if(user == NULL) {
+ user = createTempUser(from);
+ user->flags |= USERFLAG_ISTMPUSER;
+ }
+ if(argv[0][0] == '#') { //Channel notice
+ struct ChanNode *chan = getChanByName(argv[0]);
+ if(chan && chan->chanbot == client->user)
+ event_channotice(user, chan, argv[1]);
+ } else {
+ struct UserNode *target = getUserByNick(argv[0]);
+ if(target)
+ event_privnotice(user, target, argv[1]);
+ }
+ return 1;
+}
+
+static IRC_CMD(raw_nick) {
+ if(from == NULL || argc == 0) return 0;
+ struct UserNode *user = getUserByMask(from);
+ event_nick(user, argv[0]);
+ renameUser(user, argv[0]);
return 1;
}
return 1;
}
+static IRC_CMD(raw_354) {
+ recv_whohandler_354(client, argv, argc);
+ return 1;
+}
+
+static IRC_CMD(raw_315) {
+ recv_whohandler_315(client, argv, argc);
+ return 1;
+}
+
void parser_init() {
//all the raws we receive...
register_irc_function("001", raw_001);
+ register_irc_function("NOTICE", raw_notice);
+ register_irc_function("TOPIC", raw_topic);
+ register_irc_function("KICK", raw_kick);
+ register_irc_function("PART", raw_part);
+ register_irc_function("QUIT", raw_quit);
register_irc_function("JOIN", raw_join);
+ register_irc_function("NICK", raw_nick);
+ register_irc_function("354", raw_354);
+ register_irc_function("315", raw_315);
register_irc_function("PING", raw_ping);
+ register_irc_function("PRIVMSG", raw_privmsg);
}