added some more ZNC/sBNC support
authorpk910 <philipp@zoelle1.de>
Sat, 17 Dec 2011 19:26:33 +0000 (20:26 +0100)
committerpk910 <philipp@zoelle1.de>
Sat, 17 Dec 2011 21:37:38 +0000 (22:37 +0100)
src/IRCParser.c

index d3c97a4955373692757171e140dcd0d58f998286..8631165e270fcedb7a74f3996804c6caf01ff571 100644 (file)
@@ -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,7 +171,7 @@ 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 && (!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) {
@@ -436,6 +437,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 +624,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);