]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Add UserManager::GetUsers()
authorAttila Molnar <attilamolnar@hush.com>
Sat, 15 Mar 2014 14:21:18 +0000 (15:21 +0100)
committerAttila Molnar <attilamolnar@hush.com>
Sat, 15 Mar 2014 14:21:18 +0000 (15:21 +0100)
15 files changed:
include/usermanager.h
src/coremods/core_lusers.cpp
src/coremods/core_stats.cpp
src/coremods/core_who.cpp
src/coremods/core_xline/core_xline.cpp
src/coremods/core_xline/core_xline.h
src/mode.cpp
src/modules.cpp
src/modules/m_check.cpp
src/modules/m_httpd_stats.cpp
src/modules/m_spanningtree/netburst.cpp
src/modules/m_spanningtree/override_map.cpp
src/modules/m_spanningtree/treeserver.cpp
src/modules/m_spanningtree/uid.cpp
src/modules/m_tline.cpp

index b1c3520e9551db9cfcb7f6b9c9d58206bf41e740..15d41e6bc4b6b6a7ebb472338625d13b73adcd17 100644 (file)
@@ -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
index 206d969d19dcdc1fee13eabd25887fc7e824f34f..8cc603eee5138262642d8ba561b2b0cec6aa3fb5 100644 (file)
@@ -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))
index df0c12725c8f381af35bafa51c7e24f993c0e798..4f53f3270f4addc9b99585c18dd2a5b6a4d5939c 100644 (file)
@@ -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()));
 
index dc39e296c95c9e3a996fec5d174f42b80bcffe5e..523d857cedbb3f73c57e4bda3889a6a58eb71b00 100644 (file)
@@ -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()))
                                {
index 94183d829cae9e276c8d57e8f49671655521a517..7daa70b49ec964089145cc5eb7d2b45e019f950b 100644 (file)
@@ -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);
index 6101d79bfd7b3e23204901ba3765bb0e7771ebc6..d4ad498a0a52f8fcb19cd36fcd519760cf8f59ae 100644 (file)
@@ -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))
index ee6b1cae51fe6a6bf3f99b2f3e6e30cb6d11db79..9d24160f65b0bd8a2ba68c33138533aec83301ac 100644 (file)
@@ -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:
                {
index 62c3aa213a38e0a45c959ff305fc87669f4890e8..b6d18b8fd79b2502b82cad3abdc81e36ae1e321c 100644 (file)
@@ -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
index ba20f9445ca039db32e6980f08a98f70e86eee52..d7cfe74bd50bf2ff4505aae97b6e426070c9f3a7 100644 (file)
@@ -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))
                                {
index 75be402becd916a0ed36a0a74976691c6b898559..2dcf1e1cf4be55de4e758255a475bfbafa962126 100644 (file)
@@ -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>"
index 93b4d72f49bec6e427dccf5bb0206979e6d0c33c..a33cf8a134004f22a690ea5344f7d07dfc43acfb 100644 (file)
@@ -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)
index 216fd4d66d53f030babff73c1f274a0483ee0e90..68551e84f5ba22359cdd4e3a0235c181a4ae40ba 100644 (file)
@@ -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",
index b51c21db65dacd3ef80d2e8bae6ad8833222bf25..3d57b1314f15ff15a3be5d3b6b1159b9bbc66339 100644 (file)
@@ -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(); )
        {
index 0d96167b9c2e8850e03a90fc6c5db381982a1493..37c54ae601770debbf38b68172d2e6b20006bff0 100644 (file)
@@ -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)
index 64beb31203c5db6adcd5a7425cf238af80b88b7b..77ec0e26ceb06f6211a5583463d2da70c1665beb 100644 (file)
@@ -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;