diff options
author | Attila Molnar <attilamolnar@hush.com> | 2014-03-15 15:21:18 +0100 |
---|---|---|
committer | Attila Molnar <attilamolnar@hush.com> | 2014-03-15 15:21:18 +0100 |
commit | 66965131f834d14104ad618fd6d89bfd912cd120 (patch) | |
tree | 3090eefce9e5ca824edc376dc11f7f17f0a33be9 | |
parent | adb26a4e882d317de4e4135f414b7002cafe07a4 (diff) |
Add UserManager::GetUsers()
-rw-r--r-- | include/usermanager.h | 5 | ||||
-rw-r--r-- | src/coremods/core_lusers.cpp | 3 | ||||
-rw-r--r-- | src/coremods/core_stats.cpp | 2 | ||||
-rw-r--r-- | src/coremods/core_who.cpp | 3 | ||||
-rw-r--r-- | src/coremods/core_xline/core_xline.cpp | 2 | ||||
-rw-r--r-- | src/coremods/core_xline/core_xline.h | 2 | ||||
-rw-r--r-- | src/mode.cpp | 5 | ||||
-rw-r--r-- | src/modules.cpp | 4 | ||||
-rw-r--r-- | src/modules/m_check.cpp | 3 | ||||
-rw-r--r-- | src/modules/m_httpd_stats.cpp | 7 | ||||
-rw-r--r-- | src/modules/m_spanningtree/netburst.cpp | 4 | ||||
-rw-r--r-- | src/modules/m_spanningtree/override_map.cpp | 7 | ||||
-rw-r--r-- | src/modules/m_spanningtree/treeserver.cpp | 2 | ||||
-rw-r--r-- | src/modules/m_spanningtree/uid.cpp | 7 | ||||
-rw-r--r-- | src/modules/m_tline.cpp | 5 |
15 files changed, 39 insertions, 22 deletions
diff --git a/include/usermanager.h b/include/usermanager.h index b1c3520e9..15d41e6bc 100644 --- a/include/usermanager.h +++ b/include/usermanager.h @@ -157,6 +157,11 @@ class CoreExport UserManager */ unsigned int LocalUserCount() const { return (this->local_users.size() - this->UnregisteredUserCount()); } + /** Get a hash map containing all users, keyed by their nickname + * @return A hash map mapping nicknames to User pointers + */ + user_hash& GetUsers() { return *clientlist; } + /** Send a server notice to all local users * @param text The text format string to send * @param ... The format arguments diff --git a/src/coremods/core_lusers.cpp b/src/coremods/core_lusers.cpp index 206d969d1..8cc603eee 100644 --- a/src/coremods/core_lusers.cpp +++ b/src/coremods/core_lusers.cpp @@ -132,7 +132,8 @@ class ModuleLusers : public Module unsigned int CountInvisible() { unsigned int c = 0; - for (user_hash::iterator i = ServerInstance->Users->clientlist->begin(); i != ServerInstance->Users->clientlist->end(); ++i) + const user_hash& users = ServerInstance->Users->GetUsers(); + for (user_hash::const_iterator i = users.begin(); i != users.end(); ++i) { User* u = i->second; if (u->IsModeSet(invisiblemode)) diff --git a/src/coremods/core_stats.cpp b/src/coremods/core_stats.cpp index df0c12725..4f53f3270 100644 --- a/src/coremods/core_stats.cpp +++ b/src/coremods/core_stats.cpp @@ -201,7 +201,7 @@ void CommandStats::DoStats(char statschar, User* user, string_list &results) /* stats z (debug and memory info) */ case 'z': { - results.push_back("249 "+user->nick+" :Users: "+ConvToStr(ServerInstance->Users->clientlist->size())); + results.push_back("249 "+user->nick+" :Users: "+ConvToStr(ServerInstance->Users->GetUsers().size())); results.push_back("249 "+user->nick+" :Channels: "+ConvToStr(ServerInstance->GetChans().size())); results.push_back("249 "+user->nick+" :Commands: "+ConvToStr(ServerInstance->Parser->cmdlist.size())); diff --git a/src/coremods/core_who.cpp b/src/coremods/core_who.cpp index dc39e296c..523d857ce 100644 --- a/src/coremods/core_who.cpp +++ b/src/coremods/core_who.cpp @@ -365,7 +365,8 @@ CmdResult CommandWho::Handle (const std::vector<std::string>& parameters, User * } else { - for (user_hash::iterator i = ServerInstance->Users->clientlist->begin(); i != ServerInstance->Users->clientlist->end(); i++) + const user_hash& users = ServerInstance->Users->GetUsers(); + for (user_hash::const_iterator i = users.begin(); i != users.end(); ++i) { if (whomatch(user, i->second, matchtext.c_str())) { diff --git a/src/coremods/core_xline/core_xline.cpp b/src/coremods/core_xline/core_xline.cpp index 94183d829..7daa70b49 100644 --- a/src/coremods/core_xline/core_xline.cpp +++ b/src/coremods/core_xline/core_xline.cpp @@ -34,7 +34,7 @@ bool InsaneBan::MatchesEveryone(const std::string& mask, MatcherBase& test, User if (!matches) return false; - float percent = ((float)matches / (float)ServerInstance->Users->clientlist->size()) * 100; + float percent = ((float)matches / (float)ServerInstance->Users->GetUsers().size()) * 100; if (percent > itrigger) { ServerInstance->SNO->WriteToSnoMask('a', "\2WARNING\2: %s tried to set a %s-line mask of %s, which covers %.2f%% of the network!", user->nick.c_str(), bantype, mask.c_str(), percent); diff --git a/src/coremods/core_xline/core_xline.h b/src/coremods/core_xline/core_xline.h index 6101d79bf..d4ad498a0 100644 --- a/src/coremods/core_xline/core_xline.h +++ b/src/coremods/core_xline/core_xline.h @@ -38,7 +38,7 @@ class InsaneBan { long matches = 0; const T* c = static_cast<T*>(this); - const user_hash& users = *ServerInstance->Users->clientlist; + const user_hash& users = ServerInstance->Users->GetUsers(); for (user_hash::const_iterator i = users.begin(); i != users.end(); ++i) { if (c->Check(i->second, mask)) diff --git a/src/mode.cpp b/src/mode.cpp index ee6b1cae5..9d24160f6 100644 --- a/src/mode.cpp +++ b/src/mode.cpp @@ -693,12 +693,15 @@ bool ModeParser::DelMode(ModeHandler* mh) switch (mh->GetModeType()) { case MODETYPE_USER: - for (user_hash::iterator i = ServerInstance->Users->clientlist->begin(); i != ServerInstance->Users->clientlist->end(); ) + { + const user_hash& users = ServerInstance->Users->GetUsers(); + for (user_hash::const_iterator i = users.begin(); i != users.end(); ) { User* user = i->second; ++i; mh->RemoveMode(user); } + } break; case MODETYPE_CHANNEL: { diff --git a/src/modules.cpp b/src/modules.cpp index 62c3aa213..b6d18b8fd 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -401,7 +401,9 @@ void ModuleManager::DoSafeUnload(Module* mod) for(UserMembCIter mi = users->begin(); mi != users->end(); mi++) mi->second->doUnhookExtensions(items); } - for (user_hash::iterator u = ServerInstance->Users->clientlist->begin(); u != ServerInstance->Users->clientlist->end(); ) + + const user_hash& users = ServerInstance->Users->GetUsers(); + for (user_hash::const_iterator u = users.begin(); u != users.end(); ) { User* user = u->second; // The module may quit the user (e.g. SSL mod unloading) and that will remove it from the container diff --git a/src/modules/m_check.cpp b/src/modules/m_check.cpp index ba20f9445..d7cfe74bd 100644 --- a/src/modules/m_check.cpp +++ b/src/modules/m_check.cpp @@ -248,7 +248,8 @@ class CommandCheck : public Command long x = 0; /* hostname or other */ - for (user_hash::const_iterator a = ServerInstance->Users->clientlist->begin(); a != ServerInstance->Users->clientlist->end(); a++) + const user_hash& users = ServerInstance->Users->GetUsers(); + for (user_hash::const_iterator a = users.begin(); a != users.end(); ++a) { if (InspIRCd::Match(a->second->host, parameters[0], ascii_case_insensitive_map) || InspIRCd::Match(a->second->dhost, parameters[0], ascii_case_insensitive_map)) { diff --git a/src/modules/m_httpd_stats.cpp b/src/modules/m_httpd_stats.cpp index 75be402be..2dcf1e1cf 100644 --- a/src/modules/m_httpd_stats.cpp +++ b/src/modules/m_httpd_stats.cpp @@ -104,7 +104,7 @@ class ModuleHttpStats : public Module << Sanitize(ServerInstance->GetVersionString()) << "</version></server>"; data << "<general>"; - data << "<usercount>" << ServerInstance->Users->clientlist->size() << "</usercount>"; + data << "<usercount>" << ServerInstance->Users->GetUsers().size() << "</usercount>"; data << "<channelcount>" << ServerInstance->GetChans().size() << "</channelcount>"; data << "<opercount>" << ServerInstance->Users->all_opers.size() << "</opercount>"; data << "<socketcount>" << (SocketEngine::GetUsedFds()) << "</socketcount><socketmax>" << SocketEngine::GetMaxFds() << "</socketmax><socketengine>" INSPIRCD_SOCKETENGINE_NAME "</socketengine>"; @@ -182,9 +182,10 @@ class ModuleHttpStats : public Module data << "</channellist><userlist>"; - for (user_hash::const_iterator a = ServerInstance->Users->clientlist->begin(); a != ServerInstance->Users->clientlist->end(); ++a) + const user_hash& users = ServerInstance->Users->GetUsers(); + for (user_hash::const_iterator i = users.begin(); i != users.end(); ++i) { - User* u = a->second; + User* u = i->second; data << "<user>"; data << "<nickname>" << u->nick << "</nickname><uuid>" << u->uuid << "</uuid><realhost>" diff --git a/src/modules/m_spanningtree/netburst.cpp b/src/modules/m_spanningtree/netburst.cpp index 93b4d72f4..a33cf8a13 100644 --- a/src/modules/m_spanningtree/netburst.cpp +++ b/src/modules/m_spanningtree/netburst.cpp @@ -271,7 +271,9 @@ void TreeSocket::SyncChannel(Channel* chan) void TreeSocket::SendUsers(BurstState& bs) { ProtocolInterface::Server& piserver = bs.server; - for (user_hash::iterator u = ServerInstance->Users->clientlist->begin(); u != ServerInstance->Users->clientlist->end(); u++) + + const user_hash& users = ServerInstance->Users->GetUsers(); + for (user_hash::const_iterator u = users.begin(); u != users.end(); ++u) { User* user = u->second; if (user->registered != REG_ALL) diff --git a/src/modules/m_spanningtree/override_map.cpp b/src/modules/m_spanningtree/override_map.cpp index 216fd4d66..68551e84f 100644 --- a/src/modules/m_spanningtree/override_map.cpp +++ b/src/modules/m_spanningtree/override_map.cpp @@ -66,10 +66,11 @@ static std::vector<std::string> GetMap(User* user, TreeServer* current, unsigned { float percent = 0; - if (!ServerInstance->Users->clientlist->empty()) + const user_hash& users = ServerInstance->Users->GetUsers(); + if (!users.empty()) { // If there are no users, WHO THE HELL DID THE /MAP?!?!?! - percent = current->UserCount * 100.0 / ServerInstance->Users->clientlist->size(); + percent = current->UserCount * 100.0 / users.size(); } std::string buffer = current->GetName(); @@ -201,7 +202,7 @@ CmdResult CommandMap::Handle(const std::vector<std::string>& parameters, User* u user->SendText(":%s %03d %s :%s", ServerInstance->Config->ServerName.c_str(), RPL_MAP, user->nick.c_str(), i->c_str()); - size_t totusers = ServerInstance->Users->clientlist->size(); + size_t totusers = ServerInstance->Users->GetUsers().size(); float avg_users = (float) totusers / Utils->serverlist.size(); user->SendText(":%s %03d %s :%u server%s and %u user%s, average %.2f users per server", diff --git a/src/modules/m_spanningtree/treeserver.cpp b/src/modules/m_spanningtree/treeserver.cpp index b51c21db6..3d57b1314 100644 --- a/src/modules/m_spanningtree/treeserver.cpp +++ b/src/modules/m_spanningtree/treeserver.cpp @@ -144,7 +144,7 @@ int TreeServer::QuitUsers(const std::string &reason) { std::string publicreason = ServerInstance->Config->HideSplits ? "*.net *.split" : reason; - const user_hash& users = *ServerInstance->Users->clientlist; + const user_hash& users = ServerInstance->Users->GetUsers(); unsigned int original_size = users.size(); for (user_hash::const_iterator i = users.begin(); i != users.end(); ) { diff --git a/src/modules/m_spanningtree/uid.cpp b/src/modules/m_spanningtree/uid.cpp index 0d96167b9..37c54ae60 100644 --- a/src/modules/m_spanningtree/uid.cpp +++ b/src/modules/m_spanningtree/uid.cpp @@ -48,14 +48,13 @@ CmdResult CommandUID::HandleServer(TreeServer* remoteserver, std::vector<std::st return CMD_INVALID; /* check for collision */ - user_hash::iterator iter = ServerInstance->Users->clientlist->find(params[2]); - - if (iter != ServerInstance->Users->clientlist->end()) + User* collideswith = ServerInstance->FindNickOnly(params[2]); + if (collideswith) { /* * Nick collision. */ - int collide = Utils->DoCollision(iter->second, remoteserver, age_t, params[5], params[6], params[0]); + int collide = Utils->DoCollision(collideswith, remoteserver, age_t, params[5], params[6], params[0]); ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "*** Collision on %s, collide=%d", params[2].c_str(), collide); if (collide != 1) diff --git a/src/modules/m_tline.cpp b/src/modules/m_tline.cpp index 64beb3120..77ec0e26c 100644 --- a/src/modules/m_tline.cpp +++ b/src/modules/m_tline.cpp @@ -36,7 +36,8 @@ class CommandTline : public Command unsigned int n_match_host = 0; unsigned int n_match_ip = 0; - for (user_hash::const_iterator u = ServerInstance->Users->clientlist->begin(); u != ServerInstance->Users->clientlist->end(); u++) + const user_hash& users = ServerInstance->Users->GetUsers(); + for (user_hash::const_iterator u = users.begin(); u != users.end(); ++u) { if (InspIRCd::Match(u->second->GetFullRealHost(),parameters[0])) { @@ -54,7 +55,7 @@ class CommandTline : public Command } } - unsigned long n_counted = ServerInstance->Users->clientlist->size(); + unsigned long n_counted = users.size(); if (n_matched) { float p = (n_matched / (float)n_counted) * 100; |