*** VERSION 5.2.0 ***
[NeonServV5.git] / src / UserNode.c
index 2ced2eb5b88d3f3129173b9b867a0fbf3823d048..7be5ebdac2115a29ec6eeb6df69af88776680901 100644 (file)
@@ -1,3 +1,19 @@
+/* UserNode.c - NeonServ v5.2
+ * 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"
@@ -171,6 +187,7 @@ struct UserNode* addUser(const char *nick) {
     user->realname[0] = 0;
     user->flags = 0;
     user->channel = NULL;
+    user->last_who = 0;
     user->next = userList[userListIndex];
     userList[userListIndex] = user;
     return user;
@@ -225,6 +242,7 @@ struct UserNode* createTempUser(const char *mask) {
             user->realname[0] = 0;
             user->flags = 0;
             user->channel = NULL;
+            user->last_who = 0;
             ii = i+1;
         } else if(cmask[i] == '.' && !user) {
             //it's a server
@@ -241,6 +259,7 @@ struct UserNode* createTempUser(const char *mask) {
             user->realname[0] = 0;
             user->flags = USERFLAG_ISSERVER;
             user->channel = NULL;
+            user->last_who = 0;
             return user;
         } else if(cmask[i] == '@') {
             if(user == NULL) return NULL;
@@ -263,6 +282,7 @@ struct UserNode* createTempUser(const char *mask) {
                 user->realname[0] = 0;
                 user->flags = 0;
                 user->channel = NULL;
+                user->last_who = 0;
                 return user;
             }
             strcpy(user->host, &cmask[ii]);
@@ -278,8 +298,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;