]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_stripcolor.cpp
Same fixes to make this module scale much better. Dont connect on each query, keep...
[user/henk/code/inspircd.git] / src / modules / m_stripcolor.cpp
index 9b3f8c2f1d70011a155199ecaa30b1161aa614d4..420e2e6e293c1ad0413b86142b6dd2c7f1f82425 100644 (file)
 
 /** 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, bool servermode)
-       {
-               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, bool servermode)
-       {
-               /* 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') { }
 };
 
 
@@ -112,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;
@@ -134,12 +86,16 @@ class ModuleStripColor : public Module
                                        safei = i;
                                        --i;
                                        sentence.erase(safei);
+                                       ++i;
                                }
                                else
                                {
                                        sentence.erase(i);
                                        i = sentence.begin();
-                               }                       }
+                               }
+                       }
+                       else
+                               ++i;
                }
        }