]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_rline.cpp
m_namesx Handle colons in channel names properly
[user/henk/code/inspircd.git] / src / modules / m_rline.cpp
index 7f5eafd694590c3cb7448c38e7e5fc2a9ddf392f..28fa891b61cd1854134c73979a03107640d46bbc 100644 (file)
@@ -1,24 +1,33 @@
-/*       +------------------------------------+
- *       | Inspire Internet Relay Chat Daemon |
- *       +------------------------------------+
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
  *
- *  InspIRCd: (C) 2002-2010 InspIRCd Development Team
- * See: http://wiki.inspircd.org/Credits
+ *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
+ *   Copyright (C) 2008 Craig Edwards <craigedwards@brainbox.cc>
+ *   Copyright (C) 2008 Thomas Stagner <aquanight@inspircd.org>
+ *   Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
  *
- * This program is free but copyrighted software; see
- *            the file COPYING for details.
+ * This file is part of InspIRCd.  InspIRCd is free software: you can
+ * redistribute it and/or modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation, version 2.
  *
- * ---------------------------------------------------
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+
+/* $ModDesc: RLINE: Regexp user banning. */
+
 #include "inspircd.h"
 #include "m_regex.h"
 #include "xline.h"
 
 static bool ZlineOnMatch = false;
-static std::vector<ZLine *> background_zlines;
-
-/* $ModDesc: RLINE: Regexp user banning. */
+static bool added_zline = false;
 
 class RLine : public XLine
 {
@@ -66,8 +75,17 @@ class RLine : public XLine
 
        void Apply(User* u)
        {
-               if (ZlineOnMatch) {
-                       background_zlines.push_back(new ZLine(ServerInstance->Time(), duration ? expiry - ServerInstance->Time() : 0, ServerInstance->Config->ServerName.c_str(), reason.c_str(), u->GetIPString()));
+               if (ZlineOnMatch)
+               {
+                       ZLine* zl = new ZLine(ServerInstance->Time(), duration ? expiry - ServerInstance->Time() : 0, ServerInstance->Config->ServerName.c_str(), reason.c_str(), u->GetIPString());
+                       if (ServerInstance->XLines->AddLine(zl, NULL))
+                       {
+                               ServerInstance->SNO->WriteToSnoMask('x', "Z-line added due to R-line match on *@%s%s%s: %s",
+                                       zl->ipaddr.c_str(), zl->duration ? " to expire on " : "", zl->duration ? ServerInstance->TimeString(zl->expiry).c_str() : "", zl->reason.c_str());
+                               added_zline = true;
+                       }
+                       else
+                               delete zl;
                }
                DefaultApply(u, "R", false);
        }
@@ -190,7 +208,7 @@ class CommandRLine : public Command
 
        RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
        {
-               return ROUTE_BROADCAST;
+               return ROUTE_LOCALONLY;
        }
 };
 
@@ -201,10 +219,13 @@ class ModuleRLine : public Module
        RLineFactory f;
        CommandRLine r;
        bool MatchOnNickChange;
-       std::string RegexEngine;
 
  public:
        ModuleRLine() : rxfactory(this, "regex"), f(rxfactory), r(this, f)
+       {
+       }
+
+       void init()
        {
                OnRehash(NULL);
 
@@ -223,7 +244,7 @@ class ModuleRLine : public Module
 
        virtual Version GetVersion()
        {
-               return Version("RLINE: Regexp user banning.", VF_COMMON | VF_VENDOR, rxfactory.GetProvider());
+               return Version("RLINE: Regexp user banning.", VF_COMMON | VF_VENDOR, rxfactory ? rxfactory->name : "");
        }
 
        virtual void OnUserConnect(LocalUser* user)
@@ -242,17 +263,17 @@ class ModuleRLine : public Module
        {
                ConfigReader Conf;
 
-               if (!Conf.ReadFlag("rline", "zlineonmatch", 0) && ZlineOnMatch)
-                       background_zlines.clear();
-
                MatchOnNickChange = Conf.ReadFlag("rline", "matchonnickchange", 0);
                ZlineOnMatch = Conf.ReadFlag("rline", "zlineonmatch", 0);
                std::string newrxengine = Conf.ReadValue("rline", "engine", 0);
 
-               rxfactory.SetProvider("regex/" + newrxengine);
+               if (newrxengine.empty())
+                       rxfactory.SetProvider("regex");
+               else
+                       rxfactory.SetProvider("regex/" + newrxengine);
                if (!rxfactory)
                {
-                       ServerInstance->SNO->WriteToSnoMask('a', "WARNING: Regex engine '%s' is not loaded - R-Line functionality disabled until this is corrected.", RegexEngine.c_str());
+                       ServerInstance->SNO->WriteToSnoMask('a', "WARNING: Regex engine '%s' is not loaded - R-Line functionality disabled until this is corrected.", newrxengine.c_str());
                }
        }
 
@@ -284,21 +305,13 @@ class ModuleRLine : public Module
 
        virtual void OnBackgroundTimer(time_t curtime)
        {
-               if (!ZlineOnMatch) return;
-               for (std::vector<ZLine *>::iterator i = background_zlines.begin(); i != background_zlines.end(); i++)
+               if (added_zline)
                {
-                       ZLine *zl = *i;
-                       if (ServerInstance->XLines->AddLine(zl,NULL))
-                       {
-                               ServerInstance->SNO->WriteToSnoMask('x',"Z-line added due to R-line match on *@%s%s%s: %s", 
-                                       zl->ipaddr.c_str(), zl->duration ? " to expire on " : "", zl->duration ? ServerInstance->TimeString(zl->expiry).c_str() : "", zl->reason.c_str());
-                               ServerInstance->XLines->ApplyLines();
-                       }
+                       added_zline = false;
+                       ServerInstance->XLines->ApplyLines();
                }
-               background_zlines.clear();
        }
 
 };
 
 MODULE_INIT(ModuleRLine)
-