]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/users.cpp
Roadmap item "Fix jointhrottle to not try 'throttle' clients during a netmerge (requi...
[user/henk/code/inspircd.git] / src / users.cpp
index dbe1799893bd17b54c9e86b8919fed9ac32534fe..54fa2b872bd5d5aaef5c3f38c4a22f31f7a9ab2f 100644 (file)
@@ -18,6 +18,7 @@
 #include "socketengine.h"
 #include "wildcard.h"
 #include "xline.h"
+#include "bancache.h"
 #include "commands/cmd_whowas.h"
 
 static unsigned long already_sent[MAX_DESCRIPTORS] = {0};
@@ -829,20 +830,41 @@ void User::AddClient(InspIRCd* Instance, int socket, int port, bool iscached, in
                return;
        }
 #endif
+       /*
+        * even with bancache, we still have to keep User::exempt current.
+        * besides that, if we get a positive bancache hit, we still won't fuck
+        * them over if they are exempt. -- w00t
+        */
+       New->exempt = (Instance->XLines->MatchesLine("E",New) != NULL);
 
-       New->exempt = (Instance->XLines->matches_exception(New) != NULL);
-       if (!New->exempt)
+       if (BanCacheHit *b = Instance->BanCache->GetHit(New->GetIPString()))
        {
-               ZLine* r = Instance->XLines->matches_zline(ipaddr);
-               if (r)
+               if (!b->Type.empty() && !New->exempt)
                {
-                       char reason[MAXBUF];
+                       /* user banned */
+                       Instance->Log(DEBUG, std::string("BanCache: Positive hit for ") + New->GetIPString());
                        if (*Instance->Config->MoronBanner)
                                New->WriteServ("NOTICE %s :*** %s", New->nick, Instance->Config->MoronBanner);
-                       snprintf(reason,MAXBUF,"Z-Lined: %s",r->reason);
-                       User::QuitUser(Instance, New, reason);
+                       User::QuitUser(Instance, New, b->Reason);
                        return;
                }
+               else
+               {
+                       Instance->Log(DEBUG, std::string("BanCache: Negative hit for ") + New->GetIPString());
+               }
+       }
+       else
+       {
+               if (!New->exempt)
+               {
+                       XLine* r = Instance->XLines->MatchesLine("Z",New);
+
+                       if (r)
+                       {
+                               r->Apply(New);
+                               return;
+                       }
+               }
        }
 
         if (socket > -1)
@@ -941,29 +963,21 @@ void User::FullConnect()
 
        if (!this->exempt)
        {
-               GLine* r = ServerInstance->XLines->matches_gline(this);
+               GLine *r = (GLine *)ServerInstance->XLines->MatchesLine("G", this);
 
                if (r)
                {
                        this->muted = true;
-                       char reason[MAXBUF];
-                       if (*ServerInstance->Config->MoronBanner)
-                               this->WriteServ("NOTICE %s :*** %s", this->nick, ServerInstance->Config->MoronBanner);
-                       snprintf(reason,MAXBUF,"G-Lined: %s",r->reason);
-                       User::QuitUser(ServerInstance, this, reason);
+                       r->Apply(this);
                        return;
                }
 
-               KLine* n = ServerInstance->XLines->matches_kline(this);
+               KLine *n = (KLine *)ServerInstance->XLines->MatchesLine("K", this);
 
                if (n)
                {
                        this->muted = true;
-                       char reason[MAXBUF];
-                       if (*ServerInstance->Config->MoronBanner)
-                               this->WriteServ("NOTICE %s :*** %s", this, ServerInstance->Config->MoronBanner);
-                       snprintf(reason,MAXBUF,"K-Lined: %s",n->reason);
-                       User::QuitUser(ServerInstance, this, reason);
+                       n->Apply(this);
                        return;
                }
        }
@@ -1002,6 +1016,9 @@ void User::FullConnect()
        FOREACH_MOD(I_OnPostConnect,OnPostConnect(this));
 
        ServerInstance->SNO->WriteToSnoMask('c',"Client connecting on port %d: %s!%s@%s [%s] [%s]", this->GetPort(), this->nick, this->ident, this->host, this->GetIPString(), this->fullname);
+
+       ServerInstance->Log(DEBUG, "BanCache: Adding NEGATIVE hit for %s", this->GetIPString());
+       ServerInstance->BanCache->AddHit(this->GetIPString(), "", "");
 }
 
 /** User::UpdateNick()
@@ -1064,7 +1081,7 @@ bool User::ForceNickChange(const char* newnick)
                        return false;
                }
 
-               if (ServerInstance->XLines->matches_qline(newnick))
+               if (ServerInstance->XLines->MatchesLine("Q",newnick))
                {
                        ServerInstance->stats->statsCollisions++;
                        return false;
@@ -1763,7 +1780,7 @@ ConnectClass* User::SetClass(const std::string &explicit_name)
        if (found)
        {
                /* deny change if change will take class over the limit */
-               if (found->RefCount + 1 >= found->limit)
+               if (found->limit && (found->RefCount + 1 >= found->limit))
                {
                        ServerInstance->Log(DEBUG, "OOPS: Connect class limit (%u) hit, denying", found->limit);
                        return this->MyClass;
@@ -1825,7 +1842,7 @@ void User::PurgeEmptyChannels()
                if (i2 != ServerInstance->chanlist->end())
                {
                        FOREACH_MOD(I_OnChannelDelete,OnChannelDelete(i2->second));
-                       DELETE(i2->second);
+                       delete i2->second;
                        ServerInstance->chanlist->erase(i2);
                        this->chans.erase(*n);
                }