]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/usermanager.cpp
Initialize more User and LocalUser fields using the init list
[user/henk/code/inspircd.git] / src / usermanager.cpp
index 3e5fee3fcba4729088515b1642a4ec41a447be1f..7b4bbe281cbd3a2396ffa58c668e594f64c10f35 100644 (file)
@@ -49,7 +49,8 @@ namespace
 }
 
 UserManager::UserManager()
-       : unregistered_count(0)
+       : already_sent_id(0)
+       , unregistered_count(0)
 {
 }
 
@@ -67,35 +68,22 @@ void UserManager::AddUser(int socket, ListenSocket* via, irc::sockets::sockaddrs
        /* NOTE: Calling this one parameter constructor for User automatically
         * allocates a new UUID and places it in the hash_map.
         */
-       LocalUser* New = NULL;
-       try
-       {
-               New = new LocalUser(socket, client, server);
-       }
-       catch (...)
-       {
-               ServerInstance->Logs->Log("USERS", LOG_DEFAULT, "*** WTF *** Duplicated UUID! -- Crack smoking monkeys have been unleashed.");
-               ServerInstance->SNO->WriteToSnoMask('a', "WARNING *** Duplicate UUID allocated!");
-               return;
-       }
+       LocalUser* const New = new LocalUser(socket, client, server);
        UserIOHandler* eh = &New->eh;
 
        // If this listener has an IO hook provider set then tell it about the connection
-       if (via->iohookprov)
-               via->iohookprov->OnAccept(eh, client, server);
+       for (ListenSocket::IOHookProvList::iterator i = via->iohookprovs.begin(); i != via->iohookprovs.end(); ++i)
+       {
+               ListenSocket::IOHookProvRef& iohookprovref = *i;
+               if (iohookprovref)
+                       iohookprovref->OnAccept(eh, client, server);
+       }
 
        ServerInstance->Logs->Log("USERS", LOG_DEBUG, "New user fd: %d", socket);
 
        this->unregistered_count++;
 
-       /* The users default nick is their UUID */
-       New->nick = New->uuid;
        this->clientlist[New->nick] = New;
-
-       New->registered = REG_NONE;
-       New->signon = ServerInstance->Time();
-       New->lastping = 1;
-
        this->AddClone(New);
 
        this->local_users.push_front(New);
@@ -136,7 +124,7 @@ void UserManager::AddUser(int socket, ListenSocket* via, irc::sockets::sockaddrs
                        /* user banned */
                        ServerInstance->Logs->Log("BANCACHE", LOG_DEBUG, "BanCache: Positive hit for " + New->GetIPString());
                        if (!ServerInstance->Config->XLineMessage.empty())
-                               New->WriteNumeric(ERR_YOUREBANNEDCREEP, ":" + ServerInstance->Config->XLineMessage);
+                               New->WriteNumeric(ERR_YOUREBANNEDCREEP, ServerInstance->Config->XLineMessage);
                        this->QuitUser(New, b->Reason);
                        return;
                }
@@ -288,17 +276,6 @@ void UserManager::ServerNoticeAll(const char* text, ...)
        }
 }
 
-void UserManager::GarbageCollect()
-{
-       // Reset the already_sent IDs so we don't wrap it around and drop a message
-       LocalUser::already_sent_id = 0;
-       for (LocalList::const_iterator i = local_users.begin(); i != local_users.end(); ++i)
-       {
-               (**i).already_sent = 0;
-               (**i).RemoveExpiredInvites();
-       }
-}
-
 /* this returns true when all modules are satisfied that the user should be allowed onto the irc server
  * (until this returns true, a user will block in the waiting state, waiting to connect up to the
  * registration timeout maximum seconds)
@@ -381,3 +358,18 @@ void UserManager::DoBackgroundUserStuff()
                }
        }
 }
+
+already_sent_t UserManager::NextAlreadySentId()
+{
+       if (++already_sent_id == 0)
+       {
+               // Wrapped around, reset the already_sent ids of all users
+               already_sent_id = 1;
+               for (LocalList::iterator i = local_users.begin(); i != local_users.end(); ++i)
+               {
+                       LocalUser* user = *i;
+                       user->already_sent = 0;
+               }
+       }
+       return already_sent_id;
+}