]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Don't sync xlines defined in the config and expire them on rehash.
authorPeter Powell <petpow@saberuk.com>
Fri, 21 Sep 2018 19:54:05 +0000 (20:54 +0100)
committerPeter Powell <petpow@saberuk.com>
Sun, 23 Sep 2018 12:35:15 +0000 (13:35 +0100)
Closes #1427.

include/xline.h
src/configreader.cpp
src/xline.cpp

index 9aae32b24b044068a33e5b8deb7c4de683531a06..7c102c8825c7df6469fb22d3e52b61ab22e880ed 100644 (file)
@@ -50,7 +50,12 @@ class CoreExport XLine : public classbase
         * @param t The line type, should be set by the derived class constructor
         */
        XLine(time_t s_time, long d, std::string src, std::string re, const std::string &t)
-               : set_time(s_time), duration(d), source(src), reason(re), type(t)
+               : set_time(s_time)
+               , duration(d)
+               , source(src)
+               , reason(re)
+               , type(t)
+               , from_config(false)
        {
                expiry = set_time + duration;
        }
@@ -140,6 +145,9 @@ class CoreExport XLine : public classbase
         */
        const std::string type;
 
+       // Whether this XLine was loaded from the server config.
+       bool from_config;
+
        virtual bool IsBurstable();
 };
 
@@ -523,4 +531,7 @@ class CoreExport XLineManager
         * @param stats Stats context
         */
        void InvokeStats(const std::string& type, unsigned int numeric, Stats::Context& stats);
+
+       /** Clears any XLines which were added by the server configuration. */
+       void ClearConfigLines();
 };
index 6c7cb492afe9a6a8f4828a374b9fae33c9a1595c..a8e94586d68c04e7d437006ed0706ec0d62fb035 100644 (file)
@@ -108,6 +108,7 @@ static void ReadXLine(ServerConfig* conf, const std::string& tag, const std::str
                        throw CoreException("<"+tag+":"+key+"> missing at " + ctag->getTagLocation());
                std::string reason = ctag->getString("reason", "<Config>");
                XLine* xl = make->Generate(ServerInstance->Time(), 0, "<Config>", reason, mask);
+               xl->from_config = true;
                if (!ServerInstance->XLines->AddLine(xl, NULL))
                        delete xl;
        }
@@ -446,6 +447,7 @@ void ServerConfig::Fill()
                        SocketEngine::Close(socktest);
        }
 
+       ServerInstance->XLines->ClearConfigLines();
        ReadXLine(this, "badip", "ipmask", ServerInstance->XLines->GetFactory("Z"));
        ReadXLine(this, "badnick", "nick", ServerInstance->XLines->GetFactory("Q"));
        ReadXLine(this, "badhost", "host", ServerInstance->XLines->GetFactory("K"));
index cb4f011c0fffa76f8c8caa90d01c474a2a93b34f..d07fe0dc5b61a52c4ccd169bcb51417bc710e7dc 100644 (file)
@@ -518,7 +518,7 @@ void XLine::Apply(User* u)
 
 bool XLine::IsBurstable()
 {
-       return true;
+       return !from_config;
 }
 
 void XLine::DefaultApply(User* u, const std::string &line, bool bancache)
@@ -747,3 +747,24 @@ XLineFactory* XLineManager::GetFactory(const std::string &type)
 
        return n->second;
 }
+
+void XLineManager::ClearConfigLines()
+{
+       // Nothing to do.
+       if (lookup_lines.empty())
+               return;
+
+       ServerInstance->SNO->WriteToSnoMask('x', "Server rehashing; expiring lines defined in the server config ...");
+       for (ContainerIter type = lookup_lines.begin(); type != lookup_lines.end(); ++type)
+       {
+               for (LookupIter xline = type->second.begin(); xline != type->second.end(); )
+               {
+                       // We cache this to avoid iterator invalidation.
+                       LookupIter cachedxline = xline++;
+                       if (cachedxline->second->from_config)
+                       {
+                               ExpireLine(type, cachedxline);
+                       }
+               }
+       }
+}