]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_stripcolor.cpp
converting m_d* done
[user/henk/code/inspircd.git] / src / modules / m_stripcolor.cpp
index 8cb939534ea06c2f3fd94476878229044ecdff8d..420e2e6e293c1ad0413b86142b6dd2c7f1f82425 100644 (file)
@@ -2,7 +2,7 @@
  *       | Inspire Internet Relay Chat Daemon |
  *       +------------------------------------+
  *
- *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
+ *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
  * See: http://www.inspircd.org/wiki/index.php/Credits
  *
  * This program is free but copyrighted software; see
 
 /** Handles channel mode +S
  */
-class ChannelStripColor : public ModeHandler
+class ChannelStripColor : public SimpleChannelModeHandler
 {
  public:
-       ChannelStripColor(InspIRCd* Instance) : ModeHandler(Instance, 'S', 0, 0, false, MODETYPE_CHANNEL, false) { }
-
-       ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding)
-       {
-               if (adding)
-               {
-                       if (!channel->IsModeSet('S'))
-                       {
-                               channel->SetMode('S',true);
-                               return MODEACTION_ALLOW;
-                       }
-               }
-               else
-               {
-                       if (channel->IsModeSet('S'))
-                       {
-                               channel->SetMode('S',false);
-                               return MODEACTION_ALLOW;
-                       }
-               }
-
-               return MODEACTION_DENY;
-       }
+       ChannelStripColor(InspIRCd* Instance) : SimpleChannelModeHandler(Instance, 'S') { }
 };
 
 /** Handles user mode +S
  */
-class UserStripColor : public ModeHandler
+class UserStripColor : public SimpleUserModeHandler
 {
  public:
-       UserStripColor(InspIRCd* Instance) : ModeHandler(Instance, 'S', 0, 0, false, MODETYPE_USER, false) { }
-
-       ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding)
-       {
-               /* Only opers can change other users modes */
-               if (source != dest)
-                       return MODEACTION_DENY;
-
-               if (adding)
-               {
-                       if (!dest->IsModeSet('S'))
-                       {
-                               dest->SetMode('S',true);
-                               return MODEACTION_ALLOW;
-                       }
-               }
-               else
-               {
-                       if (dest->IsModeSet('S'))
-                       {
-                               dest->SetMode('S',false);
-                               return MODEACTION_ALLOW;
-                       }
-               }
-
-               return MODEACTION_DENY;
-       }
+       UserStripColor(InspIRCd* Instance) : SimpleUserModeHandler(Instance, 'S') { }
 };
 
 
@@ -92,16 +44,12 @@ class ModuleStripColor : public Module
                usc = new UserStripColor(ServerInstance);
                csc = new ChannelStripColor(ServerInstance);
 
-               if (!ServerInstance->AddMode(usc) || !ServerInstance->AddMode(csc))
+               if (!ServerInstance->Modes->AddMode(usc) || !ServerInstance->Modes->AddMode(csc))
                        throw ModuleException("Could not add new modes!");
                Implementation eventlist[] = { I_OnUserPreMessage, I_OnUserPreNotice };
                ServerInstance->Modules->Attach(eventlist, this, 2);
        }
 
-       void Implements(char* List)
-       {
-               List[I_OnUserPreMessage] = List[I_OnUserPreNotice] = 1;
-       }
 
        virtual ~ModuleStripColor()
        {
@@ -116,7 +64,7 @@ class ModuleStripColor : public Module
                /* refactor this completely due to SQUIT bug since the old code would strip last char and replace with \0 --peavey */
                int seq = 0;
                std::string::iterator i,safei;
-               for (i = sentence.begin(); i != sentence.end(); ++i)
+               for (i = sentence.begin(); i != sentence.end();)
                {
                        if ((*i == 3))
                                seq = 1;
@@ -133,10 +81,21 @@ class ModuleStripColor : public Module
                        
                        if (seq || ((*i == 2) || (*i == 15) || (*i == 22) || (*i == 21) || (*i == 31)))
                        {
-                               safei = i;
-                               --i;
-                               sentence.erase(safei);
+                               if (i != sentence.begin())
+                               {
+                                       safei = i;
+                                       --i;
+                                       sentence.erase(safei);
+                                       ++i;
+                               }
+                               else
+                               {
+                                       sentence.erase(i);
+                                       i = sentence.begin();
+                               }
                        }
+                       else
+                               ++i;
                }
        }
 
@@ -157,8 +116,12 @@ class ModuleStripColor : public Module
 
                        // check if we allow ops to bypass filtering, if we do, check if they're opped accordingly.
                        // note: short circut logic here, don't wreck it. -- w00t
-                       if (!CHANOPS_EXEMPT(ServerInstance, 'S') || CHANOPS_EXEMPT(ServerInstance, 'S') && t->GetStatus(user) != STATUS_OP)
-                               active = t->IsModeSet('S');
+                       if (CHANOPS_EXEMPT(ServerInstance, 'S') && t->GetStatus(user) == STATUS_OP)
+                       {
+                               return 0;
+                       }
+
+                       active = t->IsModeSet('S');
                }
 
                if (active)
@@ -176,7 +139,7 @@ class ModuleStripColor : 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);
        }
        
 };