summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorw00t <w00t@e03df62e-2008-0410-955e-edbf42e46eb7>2008-01-13 03:37:25 +0000
committerw00t <w00t@e03df62e-2008-0410-955e-edbf42e46eb7>2008-01-13 03:37:25 +0000
commit2192a9f58aae466a42d60279fb34ee3c5d2950a1 (patch)
tree7c4d2c1047154f7cab1744af9564570fc7045104 /src
parentf56b7d5e861648e5ddc1b766e40779082ebaeff1 (diff)
First UserManager overhaul: Move clone counts out of InspIRCd & User.
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@8705 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src')
-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
7 files changed, 77 insertions, 76 deletions
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());