]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/extra/m_rline.cpp
fixed some indentation and spacing in modules
[user/henk/code/inspircd.git] / src / modules / extra / m_rline.cpp
index 189479efc138eebf373ae6bbd4f3bbc85167c82d..2a4124c94f625b0cd2683038e67b1b3de259d82b 100644 (file)
@@ -6,7 +6,7 @@
  * See: http://www.inspircd.org/wiki/index.php/Credits
  *
  * This program is free but copyrighted software; see
- *         the file COPYING for details.
+ *            the file COPYING for details.
  *
  * ---------------------------------------------------
  */
@@ -25,7 +25,7 @@
 
 class CoreExport RLine : public XLine
 {
 public:
+ public:
 
        /** Create a R-Line.
         * @param s_time The set time
@@ -47,7 +47,7 @@ class CoreExport RLine : public XLine
                if (!regex)
                {
                        ServerInstance->SNO->WriteToSnoMask('x',"Error in regular expression: %s at offset %d: %s\n", regexs, erroffset, error);
-                       throw CoreException("Bad regex pattern.");
+                       throw ModuleException("Bad regex pattern.");
                }
        }
 
@@ -62,7 +62,7 @@ class CoreExport RLine : public XLine
        {
                std::string compare = std::string(u->nick) + "!" + u->ident + "@" + u->host + " " + u->fullname;
 
-               ServerInstance->Log(DEBUG, "Matching " + matchtext + " against string " + compare);
+               ServerInstance->Logs->Log("m_rline",DEBUG, "Matching " + matchtext + " against string " + compare);
 
                if (pcre_exec(regex, NULL, compare.c_str(), compare.length(), 0, 0, NULL, 0) > -1)
                {
@@ -91,7 +91,7 @@ class CoreExport RLine : public XLine
 
        void DisplayExpiry()
        {
-               ServerInstance->SNO->WriteToSnoMask('x',"Expiring timed R-Line %s (set by %s %d seconds ago)", this->matchtext.c_str(), this->source, this->duration);
+               ServerInstance->SNO->WriteToSnoMask('x',"Expiring timed R-Line %s (set by %s %ld seconds ago)", this->matchtext.c_str(), this->source, this->duration);
        }
 
        const char* Displayable()
@@ -131,10 +131,10 @@ class CommandRLine : public Command
                this->source = "m_rline.so";
        }
 
-       CmdResult Handle (const char* const* parameters, int pcnt, User *user)
+       CmdResult Handle (const std::vector<std::string>& parameters, User *user)
        {
 
-               if (pcnt >= 3)
+               if (parameters.size() >= 3)
                {
                        // Adding - XXX todo make this respect <insane> tag perhaps..
 
@@ -143,7 +143,7 @@ class CommandRLine : public Command
 
                        try
                        {
-                               r = new RLine(ServerInstance, ServerInstance->Time(), duration, user->nick, parameters[2], parameters[0]);
+                               r = new RLine(ServerInstance, ServerInstance->Time(), duration, user->nick.c_str(), parameters[2].c_str(), parameters[0].c_str());
                        }
                        catch (...)
                        {
@@ -156,12 +156,12 @@ class CommandRLine : public Command
                                {
                                        if (!duration)
                                        {
-                                               ServerInstance->SNO->WriteToSnoMask('x',"%s added permanent R-Line for %s.", user->nick, parameters[0]);
+                                               ServerInstance->SNO->WriteToSnoMask('x',"%s added permanent R-Line for %s.", user->nick.c_str(), parameters[0].c_str());
                                        }
                                        else
                                        {
                                                time_t c_requires_crap = duration + ServerInstance->Time();
-                                               ServerInstance->SNO->WriteToSnoMask('x', "%s added timed R-Line for %s, expires on %s", user->nick, parameters[0],
+                                               ServerInstance->SNO->WriteToSnoMask('x', "%s added timed R-Line for %s, expires on %s", user->nick.c_str(), parameters[0].c_str(),
                                                                ServerInstance->TimeString(c_requires_crap).c_str());
                                        }
 
@@ -170,20 +170,20 @@ class CommandRLine : public Command
                                else
                                {
                                        delete r;
-                                       user->WriteServ("NOTICE %s :*** R-Line for %s already exists", user->nick, parameters[0]);
+                                       user->WriteServ("NOTICE %s :*** R-Line for %s already exists", user->nick.c_str(), parameters[0].c_str());
                                }
                        }
                }
                else
                {
-                       if (ServerInstance->XLines->DelLine(parameters[0], "R", user))
+                       if (ServerInstance->XLines->DelLine(parameters[0].c_str(), "R", user))
                        {
-                               ServerInstance->SNO->WriteToSnoMask('x',"%s Removed R-Line on %s.",user->nick,parameters[0]);
+                               ServerInstance->SNO->WriteToSnoMask('x',"%s Removed R-Line on %s.",user->nick.c_str(),parameters[0].c_str());
                        }
                        else
                        {
                                // XXX todo implement stats
-                               user->WriteServ("NOTICE %s :*** R-Line %s not found in list, try /stats g.",user->nick,parameters[0]);
+                               user->WriteServ("NOTICE %s :*** R-Line %s not found in list, try /stats g.",user->nick.c_str(),parameters[0].c_str());
                        }
                }
 
@@ -196,15 +196,23 @@ class ModuleRLine : public Module
  private:
        CommandRLine *r;
        RLineFactory *f;
+       bool MatchOnNickChange;
+
  public:
        ModuleRLine(InspIRCd* Me) : Module(Me)
        {
+               OnRehash(NULL, "");
+
                // Create a new command
                r = new CommandRLine(ServerInstance);
                ServerInstance->AddCommand(r);
 
                f = new RLineFactory(ServerInstance);
                ServerInstance->XLines->RegisterFactory(f);
+
+               Implementation eventlist[] = { I_OnUserConnect, I_OnRehash, I_OnUserPostNick };
+               ServerInstance->Modules->Attach(eventlist, this, 3);
+
        }
 
        virtual ~ModuleRLine()
@@ -214,8 +222,45 @@ class ModuleRLine : public Module
 
        virtual Version GetVersion()
        {
-               return Version(1,1,0,0,VF_COMMON|VF_VENDOR,API_VERSION);
+               return Version(1,2,0,0,VF_COMMON|VF_VENDOR,API_VERSION);
+       }
+
+       virtual void OnUserConnect(User* user)
+       {
+               // Apply lines on user connect
+               XLine *rl = ServerInstance->XLines->MatchesLine("R", user);
+
+               if (rl)
+               {
+                       // Bang. :P
+                       rl->Apply(user);
+               }
+       }
+
+       virtual void OnRehash(User *user, const std::string &parameter)
+       {
+               ConfigReader Conf(ServerInstance);
+
+               MatchOnNickChange = Conf.ReadFlag("rline", "matchonnickchange", 1);
+       }
+
+       virtual void OnUserPostNick(User *user, const std::string &oldnick)
+       {
+               if (!IS_LOCAL(user))
+                       return;
+
+               if (!MatchOnNickChange)
+                       return;
+
+               XLine *rl = ServerInstance->XLines->MatchesLine("R", user);
+
+               if (rl)
+               {
+                       // Bang! :D
+                       rl->Apply(user);
+               }
        }
+
 };
 
 MODULE_INIT(ModuleRLine)