]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/xline.cpp
Roadmap item "Fix jointhrottle to not try 'throttle' clients during a netmerge (requi...
[user/henk/code/inspircd.git] / src / xline.cpp
index b41b69c895b5f036f6e30b08b5690a456d0e7a3f..59f94ce88c82070f23cf00f190dd0bf160cf2acc 100644 (file)
@@ -16,6 +16,7 @@
 #include "inspircd.h"
 #include "wildcard.h"
 #include "xline.h"
+#include "bancache.h"
 
 /*
  * This is now version 3 of the XLine subsystem, let's see if we can get it as nice and 
@@ -73,10 +74,18 @@ void XLineManager::CheckELines()
        {
                User* u = (User*)(*u2);
 
-               for (LookupIter i = ELines.begin(); i != ELines.end(); i++)
+               /* This uses safe iteration to ensure that if a line expires here, it doenst trash the iterator */
+               LookupIter safei;
+
+               for (LookupIter i = ELines.begin(); i != ELines.end(); )
                {
+                       safei = i;
+                       safei++;
+
                        XLine *e = i->second;
                        u->exempt = e->Matches(u);
+
+                       i = safei;
                }
        }
 }
@@ -89,6 +98,21 @@ XLineLookup* XLineManager::GetAll(const std::string &type)
        if (n == lookup_lines.end())
                return NULL;
 
+       LookupIter safei;
+       const time_t current = ServerInstance->Time();
+
+       /* Expire any dead ones, before sending */
+       for (LookupIter x = n->second.begin(); x != n->second.end(); )
+       {
+               safei = x;
+               safei++;
+               if (x->second->duration && current > x->second->expiry)
+               {
+                       ExpireLine(n, x);
+               }
+               x = safei;
+       }
+
        return &(n->second);
 }
 
@@ -195,19 +219,30 @@ XLine* XLineManager::MatchesLine(const std::string &type, User* user)
 
        const time_t current = ServerInstance->Time();
 
-       for (LookupIter i = x->second.begin(); i != x->second.end(); i++)
+       LookupIter safei;
+
+       for (LookupIter i = x->second.begin(); i != x->second.end(); )
        {
+               safei = i;
+               safei++;
+
                if (i->second->Matches(user))
                {
-                       if (current > i->second->expiry)
+                       if (i->second->duration && current > i->second->expiry)
                        {
                                /* Expire the line, return nothing */
                                ExpireLine(x, i);
-                               return NULL;
+                               /* Continue, there may be another that matches
+                                * (thanks aquanight)
+                                */
+                               i = safei;
+                               continue;
                        }
                        else
                                return i->second;
                }
+
+               i = safei;
        }
        return NULL;
 }
@@ -221,19 +256,28 @@ XLine* XLineManager::MatchesLine(const std::string &type, const std::string &pat
 
        const time_t current = ServerInstance->Time();
 
-       for (LookupIter i = x->second.begin(); i != x->second.end(); i++)
+        LookupIter safei;
+
+       for (LookupIter i = x->second.begin(); i != x->second.end(); )
        {
+               safei = i;
+               safei++;
+
                if (i->second->Matches(pattern))
                {
-                       if (current > i->second->expiry)
+                       if (i->second->duration && current > i->second->expiry)
                        {
                                /* Expire the line, return nothing */
                                ExpireLine(x, i);
-                               return NULL;
+                               /* See above */
+                               i = safei;
+                               continue;
                        }
                        else
                                return i->second;
                }
+
+               i = safei;
        }
        return NULL;
 }
@@ -293,7 +337,7 @@ void XLineManager::InvokeStats(const std::string &type, int numeric, User* user,
                        safei = i;
                        safei++;
 
-                       if (current > i->second->expiry)
+                       if (i->second->duration && current > i->second->expiry)
                        {
                                ExpireLine(n, i);
                        }
@@ -340,7 +384,7 @@ void XLine::Apply(User* u)
 {
 }
 
-void XLine::DefaultApply(User* u, const std::string &line)
+void XLine::DefaultApply(User* u, const std::string &line, bool bancache)
 {
        char reason[MAXBUF];
        snprintf(reason, MAXBUF, "%s-Lined: %s", line.c_str(), this->reason);
@@ -350,6 +394,13 @@ void XLine::DefaultApply(User* u, const std::string &line)
                User::QuitUser(ServerInstance, u, line + "-Lined", reason);
        else
                User::QuitUser(ServerInstance, u, reason);
+
+
+       if (bancache)
+       {
+               ServerInstance->Log(DEBUG, std::string("BanCache: Adding positive hit (") + line + ") for " + u->GetIPString());
+               ServerInstance->BanCache->AddHit(u->GetIPString(), this->type, line + "-Lined: " + this->reason);
+       }
 }
 
 bool KLine::Matches(User *u)
@@ -370,7 +421,7 @@ bool KLine::Matches(User *u)
 
 void KLine::Apply(User* u)
 {
-       DefaultApply(u, "K");
+       DefaultApply(u, "K", (strcmp(this->identmask, "*") == 0) ? true : false);
 }
 
 bool GLine::Matches(User *u)
@@ -391,7 +442,7 @@ bool GLine::Matches(User *u)
 
 void GLine::Apply(User* u)
 {       
-       DefaultApply(u, "G");
+       DefaultApply(u, "G", (strcmp(this->identmask, "*") == 0) ? true : false);
 }
 
 bool ELine::Matches(User *u)
@@ -423,7 +474,7 @@ bool ZLine::Matches(User *u)
 
 void ZLine::Apply(User* u)
 {       
-       DefaultApply(u, "Z");
+       DefaultApply(u, "Z", true);
 }
 
 
@@ -440,8 +491,8 @@ bool QLine::Matches(User *u)
 
 void QLine::Apply(User* u)
 {       
-       /* Can we force the user to their uid here instead? */
-       DefaultApply(u, "Q");
+       /* Force to uuid on apply of qline, no need to disconnect any more :) */
+       u->ForceNickChange(u->uuid);
 }