]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_noctcp.cpp
m_noctcp Use SimpleChannelModeHandler, reorder checks
[user/henk/code/inspircd.git] / src / modules / m_noctcp.cpp
index 0b4e39764151486e9b12d9a1318cd2abd5689a66..b739505798fd5da617f751876ccb2f54cb96b334 100644 (file)
 
 /* $ModDesc: Provides support for unreal-style channel mode +C */
 
-class NoCTCP : public ModeHandler
+class NoCTCP : public SimpleChannelModeHandler
 {
  public:
-       NoCTCP(Module* Creator) : ModeHandler(Creator, "noctcp", 'C', PARAM_NONE, MODETYPE_CHANNEL) { }
-
-       ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding)
-       {
-               if (adding)
-               {
-                       if (!channel->IsModeSet('C'))
-                       {
-                               channel->SetMode('C',true);
-                               return MODEACTION_ALLOW;
-                       }
-               }
-               else
-               {
-                       if (channel->IsModeSet('C'))
-                       {
-                               channel->SetMode('C',false);
-                               return MODEACTION_ALLOW;
-                       }
-               }
-
-               return MODEACTION_DENY;
-       }
+       NoCTCP(Module* Creator) : SimpleChannelModeHandler(Creator, "noctcp", 'C') { }
 };
 
 class ModuleNoCTCP : public Module
@@ -86,21 +64,20 @@ class ModuleNoCTCP : public Module
                if ((target_type == TYPE_CHANNEL) && (IS_LOCAL(user)))
                {
                        Channel* c = (Channel*)dest;
-                       ModResult res = ServerInstance->OnCheckExemption(user,c,"noctcp");
+                       if (!c->IsModeSet('C'))
+                               return MOD_RES_PASSTHRU;
+
+                       if ((text.empty()) || (text[0] != '\001') || (strncmp(text.c_str(),"\1ACTION ",8)))
+                               return MOD_RES_PASSTHRU;
 
+                       ModResult res = ServerInstance->OnCheckExemption(user,c,"noctcp");
                        if (res == MOD_RES_ALLOW)
                                return MOD_RES_PASSTHRU;
 
-                       if (!c->GetExtBanStatus(user, 'C').check(!c->IsModeSet('C')))
+                       if (!c->GetExtBanStatus(user, 'C'))
                        {
-                               if ((text.length()) && (text[0] == '\1'))
-                               {
-                                       if (strncmp(text.c_str(),"\1ACTION ",8))
-                                       {
-                                               user->WriteNumeric(ERR_NOCTCPALLOWED, "%s %s :Can't send CTCP to channel (+C set)",user->nick.c_str(), c->name.c_str());
-                                               return MOD_RES_DENY;
-                                       }
-                               }
+                               user->WriteNumeric(ERR_NOCTCPALLOWED, "%s %s :Can't send CTCP to channel (+C set)",user->nick.c_str(), c->name.c_str());
+                               return MOD_RES_DENY;
                        }
                }
                return MOD_RES_PASSTHRU;