]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/coremods/core_xline/core_xline.cpp
Improve X-line text consistency.
[user/henk/code/inspircd.git] / src / coremods / core_xline / core_xline.cpp
index 94183d829cae9e276c8d57e8f49671655521a517..aa19bad34b9118feb21130383fed316f47b49d0b 100644 (file)
@@ -18,6 +18,7 @@
 
 
 #include "inspircd.h"
+#include "xline.h"
 #include "core_xline.h"
 
 bool InsaneBan::MatchesEveryone(const std::string& mask, MatcherBase& test, User* user, const char* bantype, const char* confkey)
@@ -27,14 +28,14 @@ bool InsaneBan::MatchesEveryone(const std::string& mask, MatcherBase& test, User
        if (insane->getBool(confkey))
                return false;
 
-       float itrigger = insane->getFloat("trigger", 95.5);
+       float itrigger = insane->getFloat("trigger", 95.5, 0.0, 100.0);
 
        long matches = test.Run(mask);
 
        if (!matches)
                return false;
 
-       float percent = ((float)matches / (float)ServerInstance->Users->clientlist->size()) * 100;
+       float percent = ((float)matches / (float)ServerInstance->Users->GetUsers().size()) * 100;
        if (percent > itrigger)
        {
                ServerInstance->SNO->WriteToSnoMask('a', "\2WARNING\2: %s tried to set a %s-line mask of %s, which covers %.2f%% of the network!", user->nick.c_str(), bantype, mask.c_str(), percent);
@@ -45,8 +46,8 @@ bool InsaneBan::MatchesEveryone(const std::string& mask, MatcherBase& test, User
 
 bool InsaneBan::IPHostMatcher::Check(User* user, const std::string& mask) const
 {
-       return ((InspIRCd::Match(user->MakeHost(), mask, ascii_case_insensitive_map)) ||
-                       (InspIRCd::Match(user->MakeHostIP(), mask, ascii_case_insensitive_map)));
+       return ((InspIRCd::MatchCIDR(user->MakeHost(), mask, ascii_case_insensitive_map)) ||
+                       (InspIRCd::MatchCIDR(user->MakeHostIP(), mask, ascii_case_insensitive_map)));
 }
 
 class CoreModXLine : public Module
@@ -63,6 +64,26 @@ class CoreModXLine : public Module
        {
        }
 
+       ModResult OnUserPreNick(LocalUser* user, const std::string& newnick) CXX11_OVERRIDE
+       {
+               // Check Q-lines (for local nick changes only, remote servers have our Q-lines to enforce themselves)
+
+               XLine* xline = ServerInstance->XLines->MatchesLine("Q", newnick);
+               if (!xline)
+                       return MOD_RES_PASSTHRU; // No match
+
+               // A Q-line matched the new nick, tell opers if the user is registered
+               if (user->registered == REG_ALL)
+               {
+                       ServerInstance->SNO->WriteGlobalSno('a', "Q-lined nickname %s from %s: %s",
+                               newnick.c_str(), user->GetFullRealHost().c_str(), xline->reason.c_str());
+               }
+
+               // Send a numeric because if we deny then the core doesn't reply anything
+               user->WriteNumeric(ERR_ERRONEUSNICKNAME, newnick, InspIRCd::Format("Invalid nickname: %s", xline->reason.c_str()));
+               return MOD_RES_DENY;
+       }
+
        Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides the ELINE, GLINE, KLINE, QLINE, and ZLINE commands", VF_VENDOR|VF_CORE);