*** VERSION 5.4.0 ***
[NeonServV5.git] / src / IRCParser.c
index 17aeef45ed25ecfaf89d056c2b94d39c4214f497..da4f434e4cf19f8b2f1e41147e25d87ff1ae720e 100644 (file)
@@ -1,4 +1,4 @@
-/* IRCParser.c - NeonServ v5.3
+/* IRCParser.c - NeonServ v5.4
  * Copyright (C) 2011-2012  Philipp Kreil (pk910)
  * 
  * This program is free software: you can redistribute it and/or modify
@@ -566,11 +566,17 @@ static IRC_CMD(raw_notice) {
     return 1;
 }
 
+static void client_renamed(struct ClientSocket *client);
+
 static IRC_CMD(raw_nick) {
     if(from == NULL || argc == 0) return 0;
     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
+    if(isBot(user)) {
+        if(client->user != user) return 1;
+        client_renamed(client);
+    }
+    else if(!is_firstBotSeeUser(client, user)) return 1; //we ignore it - but it's not a parse error
     event_nick(user, argv[0]);
     renameUser(user, argv[0]);
     return 1;
@@ -684,8 +690,40 @@ static IRC_CMD(raw_332) {
     return 1;
 }
 
+struct ClientRenamePartedChannel {
+    char channel[CHANNELLEN+1];
+    struct ClientRenamePartedChannel *next;
+};
+
+static IRC_CMD(raw_437) { //can NOT change nick
+    struct ClientRenamePartedChannel *partedchan = malloc(sizeof(*partedchan));
+    strcpy(partedchan->channel, argv[1]);
+    if((client->flags & SOCKET_FLAG_CHANGENICK))
+        partedchan->next = client->changenick_channels;
+    else
+        partedchan->next = NULL;
+    client->changenick_channels = partedchan;
+    client->flags |= SOCKET_FLAG_CHANGENICK;
+    putsock(client, "PART %s", argv[1]);
+    putsock(client, "NICK %s", client->nick);
+    return 1;
+}
+
+static void client_renamed(struct ClientSocket *client) {
+    if((client->flags & SOCKET_FLAG_CHANGENICK)) {
+        struct ClientRenamePartedChannel *partedchan, *nextchan;
+        for(partedchan = client->changenick_channels; partedchan; partedchan = nextchan) {
+            nextchan = partedchan->next;
+            putsock(client, "JOIN %s", partedchan->channel);
+            free(partedchan);
+        }
+        client->flags &= ~SOCKET_FLAG_CHANGENICK;
+    }
+}
+
 void init_parser() {
     //all the raws we receive...
+    register_irc_function("437", raw_437);
     register_irc_function("002", raw_002);
     register_irc_function("251", raw_251);
     register_irc_function("254", raw_254);