summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-12-12 22:51:38 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-12-12 22:51:38 +0000
commit3679c5ebb764521ec940a526af16f61985ae15da (patch)
tree7ba47a2ccce8ddca636d31c53e0d0a98ab29e182 /src
parentcc9854655d57d49aec35150799e125b0fbe23dce (diff)
New clone counting mechanism (this isnt tested yet)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@5967 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src')
-rw-r--r--src/inspircd.cpp18
-rw-r--r--src/modules/m_spanningtree.cpp2
-rw-r--r--src/users.cpp65
3 files changed, 53 insertions, 32 deletions
diff --git a/src/inspircd.cpp b/src/inspircd.cpp
index e7801f1d5..8c297af07 100644
--- a/src/inspircd.cpp
+++ b/src/inspircd.cpp
@@ -841,6 +841,24 @@ int InspIRCd::SetTimeDelta(int delta)
return old;
}
+void InspIRCd::AddLocalClone(userrec* 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(userrec* 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_spanningtree.cpp b/src/modules/m_spanningtree.cpp
index 9345b5463..a50aac256 100644
--- a/src/modules/m_spanningtree.cpp
+++ b/src/modules/m_spanningtree.cpp
@@ -1894,6 +1894,8 @@ class TreeSocket : public InspSocket
#endif
_new->SetSockAddr(AF_INET, params[6].c_str(), 0);
+ Instance->AddGlobalClone(_new);
+
this->Instance->SNO->WriteToSnoMask('C',"Client connecting at %s: %s!%s@%s [%s]",_new->server,_new->nick,_new->ident,_new->host, _new->GetIPString());
params[7] = ":" + params[7];
diff --git a/src/users.cpp b/src/users.cpp
index b568bac63..f160645e2 100644
--- a/src/users.cpp
+++ b/src/users.cpp
@@ -331,6 +331,26 @@ userrec::~userrec()
if (ip)
{
+ 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);
+ }
+ }
+
if (this->GetProtocolFamily() == AF_INET)
{
delete (sockaddr_in*)ip;
@@ -1032,6 +1052,9 @@ void userrec::AddClient(InspIRCd* Instance, int socket, int port, bool iscached,
Instance->Log(DEBUG,"Hosts set.");
+ Instance->AddLocalClone(New);
+ Instance->AddGlobalClone(New);
+
// set the registration timeout for this user
unsigned long class_regtimeout = 90;
int class_flood = 0;
@@ -1130,42 +1153,20 @@ void userrec::AddClient(InspIRCd* Instance, int socket, int port, bool iscached,
long userrec::GlobalCloneCount()
{
- char u2[128];
- long x = 0;
- strlcpy(u2, this->GetIPString(), 64);
-
- for (user_hash::const_iterator a = ServerInstance->clientlist.begin(); a != ServerInstance->clientlist.end(); a++)
- {
- /* We have to match ip's as strings - we don't know what protocol
- * a remote user may be using
- */
- if (strcasecmp(a->second->GetIPString(), u2) == 0)
- x++;
- }
-
- return x;
+ clonemap::iterator x = ServerInstance->global_clones.find(this->GetIPString());
+ if (x != ServerInstance->global_clones.end())
+ return x->second;
+ else
+ return 0;
}
long userrec::LocalCloneCount()
{
- long x = 0;
- for (std::vector<userrec*>::const_iterator a = ServerInstance->local_users.begin(); a != ServerInstance->local_users.end(); a++)
- {
- userrec* comp = *a;
-#ifdef IPV6
- /* I dont think theres any faster way of matching two ipv6 addresses than memcmp */
- in6_addr* s1 = &(((sockaddr_in6*)comp->ip)->sin6_addr);
- in6_addr* s2 = &(((sockaddr_in6*)this->ip)->sin6_addr);
- if (!memcmp(s1->s6_addr, s2->s6_addr, sizeof(in6_addr)))
- x++;
-#else
- in_addr* s1 = &((sockaddr_in*)comp->ip)->sin_addr;
- in_addr* s2 = &((sockaddr_in*)this->ip)->sin_addr;
- if (s1->s_addr == s2->s_addr)
- x++;
-#endif
- }
- return x;
+ clonemap::iterator x = ServerInstance->local_clones.find(this->GetIPString());
+ if (x != ServerInstance->local_clones.end())
+ return x->second;
+ else
+ return 0;
}
void userrec::FullConnect(CullList* Goners)