Another year is about to end... So we have to update these damn copyright information :P
[NeonServV5.git] / src / IRCParser.c
index e96063e54ff0219aebcf469f8604c4d1f38e31fd..b525a7d95dd3d63652ab176304de80168d8943a2 100644 (file)
@@ -1,5 +1,5 @@
-/* IRCParser.c - NeonServ v5.2
- * Copyright (C) 2011  Philipp Kreil (pk910)
+/* IRCParser.c - NeonServ v5.3
+ * Copyright (C) 2011-2012  Philipp Kreil (pk910)
  * 
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -26,6 +26,7 @@
 #include "DBHelper.h"
 #include "BanNode.h"
 #include "ModeNode.h"
+#include "tools.h"
 
 struct irc_cmd *irc_commands = NULL;
 static struct UserNode *registering_users = NULL;
@@ -115,7 +116,7 @@ static USERLIST_CALLBACK(got_channel_userlist) {
     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]);
@@ -170,8 +171,8 @@ 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(chan && ((!isBot(user) && chan->chanbot != client->user) || (isBot(user) && client->user != 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);
@@ -202,7 +203,7 @@ static IRC_CMD(raw_join) {
         //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) || isBot(user))) {
@@ -331,6 +332,7 @@ static IRC_CMD(raw_quit) {
         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;
             }
@@ -379,6 +381,7 @@ void bot_disconnect(struct ClientSocket *client) {
             }
         }
         client->user = NULL;
+        client->flags &= ~SOCKET_FLAG_READY;
     }
 }
 
@@ -388,7 +391,7 @@ static IRC_CMD(raw_kick) {
     struct UserNode *target = getUserByNick(argv[1]);
     struct ChanNode *chan = getChanByName(argv[0]);
     if(chan == NULL || target == NULL) return 0;
-    if(((!isBot(user) && chan->chanbot != client->user) || (isBot(user) && client->user != 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) {
@@ -436,6 +439,16 @@ static IRC_CMD(raw_privmsg) {
         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) {
@@ -613,7 +626,7 @@ static IRC_CMD(raw_332) {
 
 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);