diff options
-rw-r--r-- | include/usermanager.h | 47 | ||||
-rw-r--r-- | src/inspircd.cpp | 2 | ||||
-rw-r--r-- | src/usermanager.cpp | 52 |
3 files changed, 36 insertions, 65 deletions
diff --git a/include/usermanager.h b/include/usermanager.h index 86978b3b3..50dac27bf 100644 --- a/include/usermanager.h +++ b/include/usermanager.h @@ -30,19 +30,16 @@ class CoreExport UserManager /** Map of local ip addresses for clone counting */ clonemap local_clones; + public: + /** Constructor, initializes variables and allocates the hashmaps + */ UserManager(); - ~UserManager() - { - for (user_hash::iterator i = clientlist->begin();i != clientlist->end();i++) - { - delete i->second; - } - clientlist->clear(); - delete clientlist; - delete uuidlist; - } + /** Destructor, destroys all users in clientlist and then deallocates + * the hashmaps + */ + ~UserManager(); /** Client list, a hash_map containing all clients, local and remote */ @@ -139,30 +136,30 @@ class CoreExport UserManager */ unsigned long LocalCloneCount(User *user); - /** Return a count of users, unknown and known connections - * @return The number of users + /** Return a count of all global users, unknown and known connections + * @return The number of users on the network, including local unregistered users */ - unsigned int UserCount(); + unsigned int UserCount() const { return this->clientlist->size(); } - /** Return a count of fully registered connections only - * @return The number of registered users + /** Return a count of fully registered connections on the network + * @return The number of registered users on the network */ - unsigned int RegisteredUserCount(); + unsigned int RegisteredUserCount() { return this->clientlist->size() - this->UnregisteredUserCount(); } - /** Return a count of opered (umode +o) users only - * @return The number of opers + /** Return a count of opered (umode +o) users on the network + * @return The number of opers on the network */ - unsigned int OperCount(); + unsigned int OperCount() const { return this->all_opers.size(); } - /** Return a count of unregistered (before NICK/USER) users only - * @return The number of unregistered (unknown) connections + /** Return a count of local unregistered (before NICK/USER) users + * @return The number of local unregistered (unknown) connections */ - unsigned int UnregisteredUserCount(); + unsigned int UnregisteredUserCount() const { return this->unregistered_count; } - /** Return a count of local users on this server only - * @return The number of local users + /** Return a count of local registered users + * @return The number of registered local users */ - unsigned int LocalUserCount(); + unsigned int LocalUserCount() const { return (this->local_count - this->UnregisteredUserCount()); } /** Number of users with a certain mode set on them */ diff --git a/src/inspircd.cpp b/src/inspircd.cpp index c40c5fb00..4e4b3f5e2 100644 --- a/src/inspircd.cpp +++ b/src/inspircd.cpp @@ -322,8 +322,6 @@ InspIRCd::InspIRCd(int argc, char** argv) : // Create base manager classes early, so nothing breaks this->Users = new UserManager; - this->Users->clientlist = new user_hash(); - this->Users->uuidlist = new user_hash(); this->chanlist = new chan_hash(); this->Config = new ServerConfig; diff --git a/src/usermanager.cpp b/src/usermanager.cpp index df1d5f9f1..c7d9a61a1 100644 --- a/src/usermanager.cpp +++ b/src/usermanager.cpp @@ -25,10 +25,23 @@ #include "bancache.h" UserManager::UserManager() - : unregistered_count(0), local_count(0) + : clientlist(new user_hash) + , uuidlist(new user_hash) + , unregistered_count(0), local_count(0) { } +UserManager::~UserManager() +{ + for (user_hash::iterator i = clientlist->begin(); i != clientlist->end(); ++i) + { + delete i->second; + } + + delete clientlist; + delete uuidlist; +} + /* add a client connection to the sockets list */ void UserManager::AddUser(int socket, ListenSocket* via, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server) { @@ -235,7 +248,6 @@ void UserManager::QuitUser(User *user, const std::string &quitreason, const char ServerInstance->Users->uuidlist->erase(user->uuid); } - void UserManager::AddLocalClone(User *user) { local_clones[user->GetCIDRMask()]++; @@ -290,42 +302,6 @@ unsigned long UserManager::LocalCloneCount(User *user) return 0; } -/* this function counts all users connected, wether they are registered or NOT. */ -unsigned int UserManager::UserCount() -{ - /* - * XXX: Todo: - * As part of this restructuring, move clientlist/etc fields into usermanager. - * -- w00t - */ - return this->clientlist->size(); -} - -/* this counts only registered users, so that the percentages in /MAP don't mess up */ -unsigned int UserManager::RegisteredUserCount() -{ - return this->clientlist->size() - this->UnregisteredUserCount(); -} - -/* return how many users are opered */ -unsigned int UserManager::OperCount() -{ - return this->all_opers.size(); -} - -/* return how many users are unregistered */ -unsigned int UserManager::UnregisteredUserCount() -{ - return this->unregistered_count; -} - -/* return how many local registered users there are */ -unsigned int UserManager::LocalUserCount() -{ - /* Doesnt count unregistered clients */ - return (this->local_count - this->UnregisteredUserCount()); -} - void UserManager::ServerNoticeAll(const char* text, ...) { std::string message; |