]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_services.cpp
Framework for central regex module, and a bare-bone implementation based on InspIRCd...
[user/henk/code/inspircd.git] / src / modules / m_services.cpp
index 2ea856db2afeab2cb55f67a216b256eb323ec840..92be81f9d22711609ae545509708794399f1f491 100644 (file)
@@ -21,7 +21,7 @@ static bool kludgeme = false;
  */
 class Channel_r : public ModeHandler
 {
-       
+
  public:
        Channel_r(InspIRCd* Instance) : ModeHandler(Instance, 'r', 0, 0, false, MODETYPE_CHANNEL, false) { }
 
@@ -30,8 +30,14 @@ class Channel_r : public ModeHandler
                // only a u-lined server may add or remove the +r mode.
                if ((ServerInstance->ULine(source->nick.c_str())) || (ServerInstance->ULine(source->server)) || (!*source->server || (source->nick.find('.') != std::string::npos)))
                {
-                       channel->SetMode('r',adding);
-                       return MODEACTION_ALLOW;
+                       // Only change the mode if it's not redundant
+                       if ((adding && !channel->IsModeSet('r')) || (!adding && channel->IsModeSet('r')))
+                       {
+                               channel->SetMode('r',adding);
+                               return MODEACTION_ALLOW;
+                       }
+
+                       return MODEACTION_DENY;
                }
                else
                {
@@ -45,7 +51,7 @@ class Channel_r : public ModeHandler
  */
 class User_r : public ModeHandler
 {
-       
+
  public:
        User_r(InspIRCd* Instance) : ModeHandler(Instance, 'r', 0, 0, false, MODETYPE_USER, false) { }
 
@@ -96,7 +102,7 @@ class Channel_M : public SimpleChannelModeHandler
  */
 class ModuleServices : public Module
 {
-       
+
        Channel_r* m1;
        Channel_R* m2;
        Channel_M* m3;
@@ -106,7 +112,7 @@ class ModuleServices : public Module
        ModuleServices(InspIRCd* Me)
                : Module(Me)
        {
-               
+
                m1 = new Channel_r(ServerInstance);
                m2 = new Channel_R(ServerInstance);
                m3 = new Channel_M(ServerInstance);
@@ -116,9 +122,9 @@ class ModuleServices : public Module
                if (!ServerInstance->Modes->AddMode(m1) || !ServerInstance->Modes->AddMode(m2) || !ServerInstance->Modes->AddMode(m3)
                        || !ServerInstance->Modes->AddMode(m4) || !ServerInstance->Modes->AddMode(m5))
                {
-                       throw ModuleException("Could not add user and channel modes!");
+                       throw ModuleException("You cannot load m_services.so and m_services_account.so at the same time (or some other module has claimed our modes)!");
                }
-       
+
                kludgeme = false;
                Implementation eventlist[] = { I_OnWhois, I_OnUserPostNick, I_OnUserPreMessage, I_OnUserPreNotice, I_OnUserPreJoin };
                ServerInstance->Modules->Attach(eventlist, this, 5);
@@ -148,7 +154,7 @@ class ModuleServices : public Module
                        kludgeme = false;
                }
        }
-       
+
        virtual int OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
        {
                if (!IS_LOCAL(user))
@@ -186,12 +192,12 @@ class ModuleServices : public Module
                }
                return 0;
        }
-       
+
        virtual int OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
        {
                return OnUserPreMessage(user,dest,target_type,text,status, exempt_list);
        }
-       
+
        virtual int OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs, const std::string &keygiven)
        {
                if (chan)
@@ -228,10 +234,10 @@ class ModuleServices : public Module
                delete m4;
                delete m5;
        }
-       
+
        virtual Version GetVersion()
        {
-               return Version(1,2,0,0,VF_COMMON|VF_VENDOR,API_VERSION);
+               return Version("$Id$",VF_COMMON|VF_VENDOR,API_VERSION);
        }
 };