-/* IRCParser.c - NeonServ v5.2
+/* IRCParser.c - NeonServ v5.3
* Copyright (C) 2011 Philipp Kreil (pk910)
*
* This program is free software: you can redistribute it and/or modify
#include "DBHelper.h"
#include "BanNode.h"
#include "ModeNode.h"
+#include "tools.h"
struct irc_cmd *irc_commands = NULL;
static struct UserNode *registering_users = NULL;
event_join(chanuser);
}
-static IRC_CMD(raw_001) {
+static IRC_CMD(raw_002) { //fixed: ZNC fakes a 001 raw even if we're not connected!
struct UserNode *user = getUserByNick(argv[0]);
if(!user)
user = addUser(argv[0]);
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(chan && chan->chanbot != client->user) return 1; //we ignore it - but it's not a parse error
+ if(!chan && (!user || !(user->flags & USERFLAG_ISBOT))) return 0;
+ if(chan && (((!user || !isBot(user)) && chan->chanbot != client->user) || ((user && isBot(user)) && client->user != user))) return 1; //we ignore it - but it's not a parse error
+ //let Bots always add themselves! (maybe they join invisible)
if(user == NULL) {
user = addUserMask(from);
}
//request member list
chan->chanbot = user;
struct ChanUser *chanuser = addChanUser(chan, user); //it must be a bot
- get_userlist(chan, got_channel_userlist, chanuser);
+ get_userlist_with_invisible(chan, got_channel_userlist, chanuser);
putsock(client, "MODE %s", chan->name);
putsock(client, "MODE %s +b", chan->name);
- } else if(!isUserOnChan(user, chan) && (chan->flags & CHANFLAG_RECEIVED_USERLIST)) {
+ } else if(!isUserOnChan(user, chan) && ((chan->flags & CHANFLAG_RECEIVED_USERLIST) || isBot(user))) {
struct ChanUser *chanuser = addChanUser(chan, user);
+ if(isModeSet(chan->modes, 'D'))
+ chanuser->flags |= CHANUSERFLAG_INVISIBLE;
if(!noEvent) {
if(wasRegistering)
user->flags |= USERFLAG_WAS_REGISTRING;
if(user == NULL) return 0;
struct ChanNode *chan = getChanByName(argv[0]);
if(chan == NULL) return 0;
- if(chan->chanbot != client->user) return 1; //we ignore it - but it's not a parse error
+ if((!isBot(user) && chan->chanbot != client->user) || (isBot(user) && client->user != user)) return 1; //we ignore it - but it's not a parse error
int keep_channel = 1;
if(chan->chanbot == user && (chan->flags & CHANFLAG_REJOINING)) {
struct ClientSocket **clients = chan->rejoin_array;
struct UserNode *user = getUserByMask(from);
if(user == NULL) return 0;
if(!is_firstBotSeeUser(client, user)) return 1; //we ignore it - but it's not a parse error
- int keep_channel = 1;
int registering = !stricmp(argv[0], "Registered");
if((registering && (user->flags & USERFLAG_ISBOT))) return 1; //bot is registering - just ignore it
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
for(chanuser = getUserChannels(user, NULL); chanuser; chanuser = next) {
next = getUserChannels(user, chanuser);
if(chanuser->chan->chanbot == user)
- keep_channel = checkChannelVisibility(chanuser->chan);
+ checkChannelVisibility(chanuser->chan);
}
//search the user representing the bot in the world of IRC
struct ClientSocket *bot;
for(bot = getBots(0, NULL); bot; bot = getBots(0, bot)) {
if(bot->user == user) {
+ bot->flags &= ~SOCKET_FLAG_READY;
bot->user = NULL;
break;
}
}
}
client->user = NULL;
+ client->flags &= ~SOCKET_FLAG_READY;
}
}
struct UserNode *target = getUserByNick(argv[1]);
struct ChanNode *chan = getChanByName(argv[0]);
if(chan == NULL || target == NULL) return 0;
- if(chan->chanbot != client->user) return 1; //we ignore it - but it's not a parse error
+ if(((!isBot(target) && chan->chanbot != client->user) || (isBot(target) && client->user != target))) return 1; //we ignore it - but it's not a parse error
int keep_channel = 1;
if(isUserOnChan(target, chan) && (chan->flags & CHANFLAG_RECEIVED_USERLIST)) {
if(user == NULL) {
user = createTempUser(from);
user->flags |= USERFLAG_ISTMPUSER;
}
+ if(!stricmp(user->nick, "*status") && !match("Disconnected from IRC.*", argv[1])) {
+ //ZNC DISCONNECT
+ bot_disconnect(client);
+ return 1;
+ }
+ if(!stricmp(user->nick, "-sBNC") && !match("* disconnected from the server.", argv[1])) {
+ //sBNC DISCONNECT
+ bot_disconnect(client);
+ return 1;
+ }
if(argv[0][0] == '#') { //Channel message
struct ChanNode *chan = getChanByName(argv[0]);
if(chan && chan->chanbot == client->user) {
void init_parser() {
//all the raws we receive...
- register_irc_function("001", raw_001);
+ register_irc_function("002", raw_002);
register_irc_function("251", raw_251);
register_irc_function("254", raw_254);
register_irc_function("324", raw_324);