Another year is about to end... So we have to update these damn copyright information :P
[NeonServV5.git] / src / UserNode.c
index 2ced2eb5b88d3f3129173b9b867a0fbf3823d048..fe68f3e796eb99ca823b70fdfb1fec86a9f723bf 100644 (file)
@@ -1,6 +1,23 @@
+/* UserNode.c - NeonServ v5.3
+ * Copyright (C) 2011-2012  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"
+#include "IRCEvents.h"
 
 static struct UserNode **userList;
 
@@ -143,6 +160,20 @@ struct UserNode* getAllUsers(struct UserNode *last) {
         return last->next;
 }
 
+struct UserNode* getUsersWithAuth(const char *auth, struct UserNode *last) {
+    int cindex = (last ? get_nicklist_entry(last->nick[0]) : 0);
+    struct UserNode *cuser = last;
+    while(cindex <= VALID_NICK_CHARS_FIRST_LEN) {
+        for(cuser = (cuser ? cuser->next : userList[cindex]); cuser; cuser = cuser->next) {
+            if((cuser->flags & USERFLAG_ISAUTHED) && !strcmp(cuser->auth, auth))
+                return cuser;
+        }
+        cindex++;
+        cuser = NULL;
+    }
+    return NULL;
+}
+
 int getUserCount() {
     int i, count = 0;
     struct UserNode *user;
@@ -171,6 +202,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 +257,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 +274,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 +297,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 +313,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;
@@ -289,6 +339,7 @@ int renameUser(struct UserNode* user, const char *new_nick) {
 void delUser(struct UserNode* user, int freeUser) {
     int userListIndex = get_nicklist_entry(user->nick[0]);
     if(userListIndex == -1) return;
+    event_freeuser(user);
     struct UserNode *cuser, *last_user = NULL;
     for(cuser = userList[userListIndex]; cuser; cuser = cuser->next) {
         if(cuser == user) {