]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_shun.cpp
converting m_d* done
[user/henk/code/inspircd.git] / src / modules / m_shun.cpp
index e728fe2f1249cf9f31c9dc8e548bc954f23d6bd2..95c7cd37b1c51052890b4dea0abdbcf96e03cfbd 100644 (file)
@@ -15,7 +15,7 @@ class Shun : public XLine
 public:
        std::string matchtext;
 
-       Shun(InspIRCd* Instance, time_t s_time, long d, const char* src, const char* re, const char *shunmask) : XLine(Instance, s_time, d, src, re, "S")
+       Shun(InspIRCd* Instance, time_t s_time, long d, const char* src, const char* re, const char *shunmask) : XLine(Instance, s_time, d, src, re, "SHUN")
        {
                this->matchtext = shunmask;
        }
@@ -32,15 +32,17 @@ public:
                return false;
        }
 
-       // XXX unused, why do we *have* to implement this
        bool Matches(const std::string &s)
        {
+               if (matchtext == s)
+                       return true;
                return false;
        }
 
        void Apply(User *u)
        {
-               // Application is done by the module.
+               if (!u->GetExt("shunned"))
+                       u->Extend("shunned");
        }
 
 
@@ -55,6 +57,21 @@ public:
        }
 };
 
+/** An XLineFactory specialized to generate shun pointers
+ */
+class ShunFactory : public XLineFactory
+{
+ public:
+       ShunFactory(InspIRCd* Instance) : XLineFactory(Instance, "SHUN") { }
+
+       /** Generate a shun
+       */
+       XLine* Generate(time_t set_time, long duration, const char* source, const char* reason, const char* xline_specific_mask)
+       {
+               return new Shun(ServerInstance, set_time, duration, source, reason, xline_specific_mask);
+       }
+};
+
 //typedef std::vector<Shun> shunlist;
 
 class cmd_shun : public Command
@@ -75,7 +92,7 @@ class cmd_shun : public Command
 
                if(pcnt == 1)
                {
-                       if (ServerInstance->XLines->DelLine(parameters[0], "S", user))
+                       if (ServerInstance->XLines->DelLine(parameters[0], "SHUN", user))
                        {
                                ServerInstance->SNO->WriteToSnoMask('x',"%s Removed shun on %s.",user->nick,parameters[0]);
                        }
@@ -134,19 +151,26 @@ class cmd_shun : public Command
 class ModuleShun : public Module
 {
        cmd_shun* mycommand;
+       ShunFactory *f;
 
  public:
        ModuleShun(InspIRCd* Me) : Module(Me)
        {
+               f = new ShunFactory(ServerInstance);
+               ServerInstance->XLines->RegisterFactory(f);
+
                mycommand = new cmd_shun(ServerInstance);
                ServerInstance->AddCommand(mycommand);
+
+               Implementation eventlist[] = { I_OnStats, I_OnPreCommand, I_OnUserConnect };
+               ServerInstance->Modules->Attach(eventlist, this, 3);
        }
 
-       void Implements(char* List)
+       virtual ~ModuleShun()
        {
-               List[I_OnPreCommand] = List[I_OnStats] = 1;
+               ServerInstance->XLines->UnregisterFactory(f);
        }
-       
+
        virtual int OnStats(char symbol, User* user, string_list& out)
        {
                // XXX write me
@@ -156,24 +180,30 @@ class ModuleShun : public Module
                return 0;
        }
 
+       virtual void OnUserConnect(User* user)
+       {
+               if (!IS_LOCAL(user))
+                       return;
+
+               // Apply lines on user connect
+               XLine *rl = ServerInstance->XLines->MatchesLine("SHUN", user);
+
+               if (rl)
+               {
+                       // Bang. :P
+                       rl->Apply(user);
+               }
+       }
+
        virtual int OnPreCommand(const std::string &command, const char* const*parameters, int pcnt, User* user, bool validated, const std::string &original_line)
        {
                if((command != "PONG") && (command != "PING"))
                {
-                       // Don't let them issue cmd if they are shunned..
-                       XLine *rl = ServerInstance->XLines->MatchesLine("S", user);
-
-                       if (rl)
-                       {
+                       if (user->GetExt("shunned"))
                                return 1;
-                       }
                }
-               
-               return 0;
-       }
 
-       virtual ~ModuleShun()
-       {
+               return 0;
        }
 
        virtual Version GetVersion()