X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fusermanager.cpp;h=f62d28faab3d83c8dad12a88454d5e73590ee5c6;hb=39ddf2fb7a4d030fc29a7d421e09394cd70dc9bf;hp=b6a33d2c48c0f3eae4a1b7cbd11450a1161932d0;hpb=20ea635c9fcd0d559ff6fc2863ab581591bc4ef8;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/usermanager.cpp b/src/usermanager.cpp index b6a33d2c4..f62d28faa 100644 --- a/src/usermanager.cpp +++ b/src/usermanager.cpp @@ -24,6 +24,11 @@ #include "xline.h" #include "bancache.h" +UserManager::UserManager() + : unregistered_count(0), local_count(0) +{ +} + /* add a client connection to the sockets list */ void UserManager::AddUser(int socket, ListenSocket* via, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server) { @@ -63,17 +68,18 @@ void UserManager::AddUser(int socket, ListenSocket* via, irc::sockets::sockaddrs this->unregistered_count++; /* The users default nick is their UUID */ - New->nick.assign(New->uuid, 0, ServerInstance->Config->Limits.NickMax); + New->nick = New->uuid; (*(this->clientlist))[New->nick] = New; New->registered = REG_NONE; - New->signon = ServerInstance->Time() + ServerInstance->Config->dns_timeout; + New->signon = ServerInstance->Time(); New->lastping = 1; ServerInstance->Users->AddLocalClone(New); ServerInstance->Users->AddGlobalClone(New); - this->local_users.push_back(New); + New->localuseriter = this->local_users.insert(local_users.end(), New); + local_count++; if ((this->local_users.size() > ServerInstance->Config->SoftLimit) || (this->local_users.size() >= (unsigned int)ServerInstance->SE->GetMaxFds())) { @@ -111,7 +117,11 @@ void UserManager::AddUser(int socket, ListenSocket* via, irc::sockets::sockaddrs ServerInstance->Logs->Log("BANCACHE", DEBUG, std::string("BanCache: Positive hit for ") + New->GetIPString()); if (!ServerInstance->Config->MoronBanner.empty()) New->WriteServ("NOTICE %s :*** %s", New->nick.c_str(), ServerInstance->Config->MoronBanner.c_str()); - this->QuitUser(New, b->Reason); + + if (ServerInstance->Config->HideBans) + this->QuitUser(New, b->Type + "-Lined", b->Reason.c_str()); + else + this->QuitUser(New, b->Reason); return; } else @@ -137,6 +147,7 @@ void UserManager::AddUser(int socket, ListenSocket* via, irc::sockets::sockaddrs { ServerInstance->Logs->Log("USERS", DEBUG,"Internal error on new connection"); this->QuitUser(New, "Internal error handling connection"); + return; } /* NOTE: even if dns lookups are *off*, we still need to display this. @@ -147,6 +158,9 @@ void UserManager::AddUser(int socket, ListenSocket* via, irc::sockets::sockaddrs New->WriteServ("NOTICE Auth :*** Raw I/O logging is enabled on this server. All messages, passwords, and commands are being recorded."); FOREACH_MOD(I_OnSetUserIP,OnSetUserIP(New)); + if (New->quitting) + return; + FOREACH_MOD(I_OnUserInit,OnUserInit(New)); if (ServerInstance->Config->NoUserDns) @@ -164,13 +178,13 @@ void UserManager::QuitUser(User *user, const std::string &quitreason, const char { if (user->quitting) { - ServerInstance->Logs->Log("CULLLIST",DEBUG, "*** Warning *** - You tried to quit a user (%s) twice. Did your module call QuitUser twice?", user->nick.c_str()); + ServerInstance->Logs->Log("USERS", DEFAULT, "ERROR: Tried to quit quitting user: " + user->nick); return; } if (IS_SERVER(user)) { - ServerInstance->Logs->Log("CULLLIST",DEBUG, "*** Warning *** - You tried to quit a fake user (%s)", user->nick.c_str()); + ServerInstance->Logs->Log("USERS", DEFAULT, "ERROR: Tried to quit server user: " + user->nick); return; } @@ -236,7 +250,7 @@ void UserManager::QuitUser(User *user, const std::string &quitreason, const char if (iter != this->clientlist->end()) this->clientlist->erase(iter); else - ServerInstance->Logs->Log("USERS", DEBUG, "iter == clientlist->end, can't remove them from hash... problematic.."); + ServerInstance->Logs->Log("USERS", DEFAULT, "ERROR: Nick not found in clientlist, cannot remove: " + user->nick); ServerInstance->Users->uuidlist->erase(user->uuid); } @@ -278,6 +292,22 @@ void UserManager::RemoveCloneCounts(User *user) } } +void UserManager::RehashCloneCounts() +{ + local_clones.clear(); + global_clones.clear(); + + const user_hash& hash = *ServerInstance->Users->clientlist; + for (user_hash::const_iterator i = hash.begin(); i != hash.end(); ++i) + { + User* u = i->second; + + if (IS_LOCAL(u)) + AddLocalClone(u); + AddGlobalClone(u); + } +} + unsigned long UserManager::GlobalCloneCount(User *user) { clonemap::iterator x = global_clones.find(user->GetCIDRMask()); @@ -329,7 +359,7 @@ unsigned int UserManager::UnregisteredUserCount() unsigned int UserManager::LocalUserCount() { /* Doesnt count unregistered clients */ - return (this->local_users.size() - this->UnregisteredUserCount()); + return (this->local_count - this->UnregisteredUserCount()); } void UserManager::ServerNoticeAll(const char* text, ...) @@ -346,7 +376,7 @@ void UserManager::ServerNoticeAll(const char* text, ...) snprintf(formatbuffer,MAXBUF,"NOTICE $%s :%s", ServerInstance->Config->ServerName.c_str(), textbuffer); - for (std::vector::const_iterator i = local_users.begin(); i != local_users.end(); i++) + for (LocalUserList::const_iterator i = local_users.begin(); i != local_users.end(); i++) { User* t = *i; t->WriteServ(std::string(formatbuffer)); @@ -367,7 +397,7 @@ void UserManager::ServerPrivmsgAll(const char* text, ...) snprintf(formatbuffer,MAXBUF,"PRIVMSG $%s :%s", ServerInstance->Config->ServerName.c_str(), textbuffer); - for (std::vector::const_iterator i = local_users.begin(); i != local_users.end(); i++) + for (LocalUserList::const_iterator i = local_users.begin(); i != local_users.end(); i++) { User* t = *i; t->WriteServ(std::string(formatbuffer));