*** VERSION 5.1.0 ***
[NeonServV5.git] / src / UserNode.c
index 2ced2eb5b88d3f3129173b9b867a0fbf3823d048..60360e82a54b02951fd325d85ea51f78a82f34d8 100644 (file)
@@ -1,3 +1,19 @@
+/* UserNode.c - NeonServ v5.1
+ * Copyright (C) 2011  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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License 
+ * along with this program. If not, see <http://www.gnu.org/licenses/>. 
+ */
 #include "UserNode.h"
 #include "ChanUser.h"
 #include "tools.h"
@@ -278,8 +294,23 @@ int renameUser(struct UserNode* user, const char *new_nick) {
         strcpy(user->nick, new_nick);
         return 1;
     }
-    int userListIndex = get_nicklist_entry(*new_nick);
-    delUser(user, 0);
+    //delUser(user, 0); //EPIC FAIL! This deletes the user from the channel Userlist -.-
+    //manually remove the user from the old userList
+    int userListIndex = get_nicklist_entry(user->nick[0]);
+    if(userListIndex != -1) {
+        struct UserNode *cuser, *last_user = NULL;
+        for(cuser = userList[userListIndex]; cuser; cuser = cuser->next) {
+            if(cuser == user) {
+                if(last_user)
+                    last_user->next = user->next;
+                else
+                    userList[userListIndex] = user->next;
+                break;
+            } else
+                last_user = cuser;
+        }
+    }
+    userListIndex = get_nicklist_entry(*new_nick);
     strcpy(user->nick, new_nick);
     user->next = userList[userListIndex];
     userList[userListIndex] = user;