added ChanUser.c and basic cache system
[NeonServV5.git] / IRCParser.c
index 30ecfc6c44e5b7ad9edabec1d57ee07904367143..ed71d391ca30f4991c4306f620b715c157e9f777 100644 (file)
@@ -97,13 +97,77 @@ static IRC_CMD(raw_join) {
     struct ChanNode *chan = getChanByName(argv[0]);
     if(chan == NULL) {
         chan = addChannel(argv[0]);
-        
+        //request member list
+        //TODO!
+    } 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(user->flags & USERFLAG_ISBOT) {
+            //check if theres another bot in the channel - otherwise free it
+            
+        }
+    }
+    if(user->channel == NULL && !(user->flags & USERFLAG_ISBOT)) {
+        //remove the user
+        delUser(user, 1);
     }
-    putsock(client, "PRIVMSG #pktest :hi");
     
     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
+        
+    }
+    delUser(user, 1); //now we fully free the user
+    return 1;
+}
+
+static IRC_CMD(raw_kick) {
+    if(from == NULL || argc < 3) return 0;
+    struct UserNode *user = getUserByMask(from);
+    struct UserNode *target = getUserByNick(argv[1]);
+    if(user == NULL || target == NULL) return 0;
+    struct ChanNode *chan = getChanByName(argv[0]);
+    if(chan == NULL) return 0;
+    if(isUserOnChan(target, chan) && (chan->flags & CHANFLAG_RECEIVED_USERLIST)) {
+        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
+            
+        }
+    }
+    if(target->channel == NULL && !(target->flags & USERFLAG_ISBOT)) {
+        //remove the user
+        delUser(user, 1);
+    }
+    return 1;
+}
+
 static IRC_CMD(raw_ping) {
     if(argc == 0) return 0;
     putsock(client, "PONG :%s", argv[0]);
@@ -113,6 +177,9 @@ static IRC_CMD(raw_ping) {
 void parser_init() {
     //all the raws we receive...
     register_irc_function("001", raw_001);
+    register_irc_function("KICK", raw_kick);
     register_irc_function("JOIN", raw_join);
+    register_irc_function("PART", raw_part);
+    register_irc_function("QUIT", raw_quit);
     register_irc_function("PING", raw_ping);
 }