summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/inspircd.h26
-rw-r--r--include/usermanager.h46
-rw-r--r--include/users.h16
-rw-r--r--src/inspircd.cpp19
-rw-r--r--src/modules/m_cgiirc.cpp18
-rw-r--r--src/modules/m_check.cpp2
-rw-r--r--src/modules/m_clones.cpp3
-rw-r--r--src/modules/m_spanningtree/treesocket1.cpp2
-rw-r--r--src/usermanager.cpp58
-rw-r--r--src/users.cpp51
10 files changed, 128 insertions, 113 deletions
diff --git a/include/inspircd.h b/include/inspircd.h
index 7db8bf210..c60f7c230 100644
--- a/include/inspircd.h
+++ b/include/inspircd.h
@@ -32,6 +32,7 @@
#include "inspircd_config.h"
#include "uid.h"
#include "users.h"
+#include "usermanager.h"
#include "channels.h"
#include "socket.h"
#include "mode.h"
@@ -211,9 +212,6 @@ class serverstats : public classbase
/** A list of failed port bindings, used for informational purposes on startup */
typedef std::vector<std::pair<std::string, long> > FailedPortList;
-/** A list of ip addresses cross referenced against clone counts */
-typedef std::map<irc::string, unsigned int> clonemap;
-
class InspIRCd;
DEFINE_HANDLER1(ProcessUserHandler, void, User*);
@@ -433,14 +431,6 @@ class CoreExport InspIRCd : public classbase
*/
std::list<User*> all_opers;
- /** Map of local ip addresses for clone counting
- */
- clonemap local_clones;
-
- /** Map of global ip addresses for clone counting
- */
- clonemap global_clones;
-
/** DNS class, provides resolver facilities to the core and modules
*/
DNS* Res;
@@ -453,6 +443,10 @@ class CoreExport InspIRCd : public classbase
*/
XLineManager* XLines;
+ /** User manager. Various methods and data associated with users.
+ */
+ UserManager *Users;
+
/** Set to the current signal recieved
*/
int s_signal;
@@ -472,16 +466,6 @@ class CoreExport InspIRCd : public classbase
* @return The old time delta
*/
int SetTimeDelta(int delta);
-
- /** Add a user to the local clone map
- * @param user The user to add
- */
- void AddLocalClone(User* user);
-
- /** Add a user to the global clone map
- * @param user The user to add
- */
- void AddGlobalClone(User* user);
/** Number of users with a certain mode set on them
*/
diff --git a/include/usermanager.h b/include/usermanager.h
index f8337ff8c..5ca6401bb 100644
--- a/include/usermanager.h
+++ b/include/usermanager.h
@@ -14,15 +14,61 @@
#ifndef __USERMANAGER_H
#define __USERMANAGER_H
+/** A list of ip addresses cross referenced against clone counts */
+typedef std::map<irc::string, unsigned int> clonemap;
+
class CoreExport UserManager : public classbase
{
private:
InspIRCd *ServerInstance;
+
+ /** Map of local ip addresses for clone counting
+ */
+ clonemap local_clones;
public:
UserManager(InspIRCd *Instance)
{
ServerInstance = Instance;
}
+
+ /** Map of global ip addresses for clone counting
+ * XXX - this should be private, but m_clones depends on it currently.
+ */
+ clonemap global_clones;
+
+ /** Add a user to the local clone map
+ * @param user The user to add
+ */
+ void AddLocalClone(User *user);
+
+ /** Add a user to the global clone map
+ * @param user The user to add
+ */
+ void AddGlobalClone(User *user);
+
+ /** Remove all clone counts from the user, you should
+ * use this if you change the user's IP address
+ * after they have registered.
+ * @param user The user to remove
+ */
+ void RemoveCloneCounts(User *user);
+
+ /** Return the number of global clones of this user
+ * @param user The user to get a count for
+ * @return The global clone count of this user
+ */
+ unsigned long GlobalCloneCount(User *user);
+
+ /** Return the number of local clones of this user
+ * @param user The user to get a count for
+ * @return The local clone count of this user
+ */
+ unsigned long LocalCloneCount(User *user);
+
+
+
+
+ void RemoveCloneCounts();
};
#endif
diff --git a/include/users.h b/include/users.h
index dbcc345cb..67ea63a31 100644
--- a/include/users.h
+++ b/include/users.h
@@ -933,22 +933,6 @@ class CoreExport User : public connection
*/
void UnOper();
- /** Return the number of global clones of this user
- * @return The global clone count of this user
- */
- unsigned long GlobalCloneCount();
-
- /** Return the number of local clones of this user
- * @return The local clone count of this user
- */
- unsigned long LocalCloneCount();
-
- /** Remove all clone counts from the user, you should
- * use this if you change the user's IP address in
- * User::ip after they have registered.
- */
- void RemoveCloneCounts();
-
/** Write text to this user, appending CR/LF.
* @param text A std::string to send to the user
*/
diff --git a/src/inspircd.cpp b/src/inspircd.cpp
index 6a32e2fc1..e52aa8fc2 100644
--- a/src/inspircd.cpp
+++ b/src/inspircd.cpp
@@ -325,6 +325,7 @@ InspIRCd::InspIRCd(int argc, char** argv)
this->Timers = new TimerManager(this);
this->Parser = new CommandParser(this);
this->XLines = new XLineManager(this);
+ this->Users = new UserManager(this);
this->Config->argv = argv;
this->Config->argc = argc;
@@ -748,24 +749,6 @@ int InspIRCd::SetTimeDelta(int delta)
return old;
}
-void InspIRCd::AddLocalClone(User* user)
-{
- clonemap::iterator x = local_clones.find(user->GetIPString());
- if (x != local_clones.end())
- x->second++;
- else
- local_clones[user->GetIPString()] = 1;
-}
-
-void InspIRCd::AddGlobalClone(User* user)
-{
- clonemap::iterator y = global_clones.find(user->GetIPString());
- if (y != global_clones.end())
- y->second++;
- else
- global_clones[user->GetIPString()] = 1;
-}
-
int InspIRCd::GetTimeDelta()
{
return time_delta;
diff --git a/src/modules/m_cgiirc.cpp b/src/modules/m_cgiirc.cpp
index ec91dd559..b971532db 100644
--- a/src/modules/m_cgiirc.cpp
+++ b/src/modules/m_cgiirc.cpp
@@ -295,7 +295,7 @@ public:
if(user->GetExt("cgiirc_webirc_ip", webirc_ip))
{
bool valid=false;
- user->RemoveCloneCounts();
+ ServerInstance->Users->RemoveCloneCounts(user);
#ifdef IPV6
valid = (inet_pton(AF_INET6, webirc_ip->c_str(), &((sockaddr_in6*)user->ip)->sin6_addr) > 0);
@@ -309,8 +309,8 @@ public:
delete webirc_ip;
user->InvalidateCache();
user->Shrink("cgiirc_webirc_ip");
- ServerInstance->AddLocalClone(user);
- ServerInstance->AddGlobalClone(user);
+ ServerInstance->Users->AddLocalClone(user);
+ ServerInstance->Users->AddGlobalClone(user);
user->CheckClass();
}
}
@@ -326,7 +326,7 @@ public:
user->InvalidateCache();
bool valid = false;
- user->RemoveCloneCounts();
+ ServerInstance->Users->RemoveCloneCounts(user);
#ifdef IPV6
if (user->GetProtocolFamily() == AF_INET6)
valid = (inet_pton(AF_INET6, user->password, &((sockaddr_in6*)user->ip)->sin6_addr) > 0);
@@ -336,8 +336,8 @@ public:
if (inet_aton(user->password, &((sockaddr_in*)user->ip)->sin_addr))
valid = true;
#endif
- ServerInstance->AddLocalClone(user);
- ServerInstance->AddGlobalClone(user);
+ ServerInstance->Users->AddLocalClone(user);
+ ServerInstance->Users->AddGlobalClone(user);
user->CheckClass();
if (valid)
@@ -396,15 +396,15 @@ public:
user->Extend("cgiirc_realhost", new std::string(user->host));
user->Extend("cgiirc_realip", new std::string(user->GetIPString()));
- user->RemoveCloneCounts();
+ ServerInstance->Users->RemoveCloneCounts(user);
#ifdef IPV6
if (user->GetProtocolFamily() == AF_INET6)
inet_pton(AF_INET6, newip, &((sockaddr_in6*)user->ip)->sin6_addr);
else
#endif
inet_aton(newip, &((sockaddr_in*)user->ip)->sin_addr);
- ServerInstance->AddLocalClone(user);
- ServerInstance->AddGlobalClone(user);
+ ServerInstance->Users->AddLocalClone(user);
+ ServerInstance->Users->AddGlobalClone(user);
user->CheckClass();
try
{
diff --git a/src/modules/m_check.cpp b/src/modules/m_check.cpp
index 8c1a63652..cc8c7846b 100644
--- a/src/modules/m_check.cpp
+++ b/src/modules/m_check.cpp
@@ -119,7 +119,7 @@ class CommandCheck : public Command
/*
* Unlike Asuka, I define a clone as coming from the same host. --w00t
*/
- snprintf(tmpbuf, MAXBUF, "%lu %s%s (%s@%s) %s ", i->first->GlobalCloneCount(), targchan->GetAllPrefixChars(i->first), i->first->nick, i->first->ident, i->first->dhost, i->first->fullname);
+ snprintf(tmpbuf, MAXBUF, "%lu %s%s (%s@%s) %s ", ServerInstance->Users->GlobalCloneCount(i->first), targchan->GetAllPrefixChars(i->first), i->first->nick, i->first->ident, i->first->dhost, i->first->fullname);
user->WriteServ(checkstr + " member " + tmpbuf);
}
}
diff --git a/src/modules/m_clones.cpp b/src/modules/m_clones.cpp
index e9f757249..0c1cdff2f 100644
--- a/src/modules/m_clones.cpp
+++ b/src/modules/m_clones.cpp
@@ -44,7 +44,8 @@ class CommandClones : public Command
user->WriteServ(clonesstr + " START");
/* hostname or other */
- for (clonemap::iterator x = ServerInstance->global_clones.begin(); x != ServerInstance->global_clones.end(); x++)
+ // XXX I really don't like marking global_clones public for this. at all. -- w00t
+ for (clonemap::iterator x = ServerInstance->Users->global_clones.begin(); x != ServerInstance->Users->global_clones.end(); x++)
{
if (x->second >= limit)
user->WriteServ(clonesstr + " "+ ConvToStr(x->second) + " " + assign(x->first));
diff --git a/src/modules/m_spanningtree/treesocket1.cpp b/src/modules/m_spanningtree/treesocket1.cpp
index 169a138e3..407717bde 100644
--- a/src/modules/m_spanningtree/treesocket1.cpp
+++ b/src/modules/m_spanningtree/treesocket1.cpp
@@ -1116,7 +1116,7 @@ bool TreeSocket::ParseUID(const std::string &source, std::deque<std::string> &pa
#endif
_new->SetSockAddr(AF_INET, params[7].c_str(), 0);
- Instance->AddGlobalClone(_new);
+ Instance->Users->AddGlobalClone(_new);
bool dosend = !(((this->Utils->quiet_bursts) && (this->bursting || Utils->FindRemoteBurstServer(remoteserver))) || (this->Instance->SilentULine(_new->server)));
diff --git a/src/usermanager.cpp b/src/usermanager.cpp
index 3bf17cda2..2bb4ee685 100644
--- a/src/usermanager.cpp
+++ b/src/usermanager.cpp
@@ -15,3 +15,61 @@
#include "inspircd.h"
+void UserManager::AddLocalClone(User *user)
+{
+ clonemap::iterator x = local_clones.find(user->GetIPString());
+ if (x != local_clones.end())
+ x->second++;
+ else
+ local_clones[user->GetIPString()] = 1;
+}
+
+void UserManager::AddGlobalClone(User *user)
+{
+ clonemap::iterator y = global_clones.find(user->GetIPString());
+ if (y != global_clones.end())
+ y->second++;
+ else
+ global_clones[user->GetIPString()] = 1;
+}
+
+void UserManager::RemoveCloneCounts(User *user)
+{
+ clonemap::iterator x = local_clones.find(user->GetIPString());
+ if (x != local_clones.end())
+ {
+ x->second--;
+ if (!x->second)
+ {
+ local_clones.erase(x);
+ }
+ }
+
+ clonemap::iterator y = global_clones.find(user->GetIPString());
+ if (y != global_clones.end())
+ {
+ y->second--;
+ if (!y->second)
+ {
+ global_clones.erase(y);
+ }
+ }
+}
+
+unsigned long UserManager::GlobalCloneCount(User *user)
+{
+ clonemap::iterator x = global_clones.find(user->GetIPString());
+ if (x != global_clones.end())
+ return x->second;
+ else
+ return 0;
+}
+
+unsigned long UserManager::LocalCloneCount(User *user)
+{
+ clonemap::iterator x = local_clones.find(user->GetIPString());
+ if (x != local_clones.end())
+ return x->second;
+ else
+ return 0;
+}
diff --git a/src/users.cpp b/src/users.cpp
index 8384b4e26..22dead793 100644
--- a/src/users.cpp
+++ b/src/users.cpp
@@ -212,29 +212,6 @@ User::User(InspIRCd* Instance, const std::string &uid) : ServerInstance(Instance
throw CoreException("Duplicate UUID "+std::string(uuid)+" in User constructor");
}
-void User::RemoveCloneCounts()
-{
- clonemap::iterator x = ServerInstance->local_clones.find(this->GetIPString());
- if (x != ServerInstance->local_clones.end())
- {
- x->second--;
- if (!x->second)
- {
- ServerInstance->local_clones.erase(x);
- }
- }
-
- clonemap::iterator y = ServerInstance->global_clones.find(this->GetIPString());
- if (y != ServerInstance->global_clones.end())
- {
- y->second--;
- if (!y->second)
- {
- ServerInstance->global_clones.erase(y);
- }
- }
-}
-
User::~User()
{
/* NULL for remote users :) */
@@ -255,7 +232,7 @@ User::~User()
free(operquit);
if (ip)
{
- this->RemoveCloneCounts();
+ ServerInstance->Users->RemoveCloneCounts(this);
if (this->GetProtocolFamily() == AF_INET)
{
@@ -801,8 +778,8 @@ void User::AddClient(InspIRCd* Instance, int socket, int port, bool iscached, in
New->dhost[j] = New->host[j] = *temp;
New->dhost[j] = New->host[j] = 0;
- Instance->AddLocalClone(New);
- Instance->AddGlobalClone(New);
+ Instance->Users->AddLocalClone(New);
+ Instance->Users->AddGlobalClone(New);
/*
* First class check. We do this again in FullConnect after DNS is done, and NICK/USER is recieved.
@@ -909,24 +886,6 @@ void User::AddClient(InspIRCd* Instance, int socket, int port, bool iscached, in
}
}
-unsigned long User::GlobalCloneCount()
-{
- clonemap::iterator x = ServerInstance->global_clones.find(this->GetIPString());
- if (x != ServerInstance->global_clones.end())
- return x->second;
- else
- return 0;
-}
-
-unsigned long User::LocalCloneCount()
-{
- clonemap::iterator x = ServerInstance->local_clones.find(this->GetIPString());
- if (x != ServerInstance->local_clones.end())
- return x->second;
- else
- return 0;
-}
-
/*
* Check class restrictions
*/
@@ -939,13 +898,13 @@ void User::CheckClass()
User::QuitUser(ServerInstance, this, "Unauthorised connection");
return;
}
- else if ((a->GetMaxLocal()) && (this->LocalCloneCount() > a->GetMaxLocal()))
+ else if ((a->GetMaxLocal()) && (ServerInstance->Users->LocalCloneCount(this) > a->GetMaxLocal()))
{
User::QuitUser(ServerInstance, this, "No more connections allowed from your host via this connect class (local)");
ServerInstance->WriteOpers("*** WARNING: maximum LOCAL connections (%ld) exceeded for IP %s", a->GetMaxLocal(), this->GetIPString());
return;
}
- else if ((a->GetMaxGlobal()) && (this->GlobalCloneCount() > a->GetMaxGlobal()))
+ else if ((a->GetMaxGlobal()) && (ServerInstance->Users->GlobalCloneCount(this) > a->GetMaxGlobal()))
{
User::QuitUser(ServerInstance, this, "No more connections allowed from your host via this connect class (global)");
ServerInstance->WriteOpers("*** WARNING: maximum GLOBAL connections (%ld) exceeded for IP %s", a->GetMaxGlobal(), this->GetIPString());