]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_stripcolor.cpp
A few more I missed.
[user/henk/code/inspircd.git] / src / modules / m_stripcolor.cpp
index 3254d98951495fcdc146f2778f6cfe71978f204a..aad253bc740bfbc1445ed6e00b3ffa80556ece6d 100644 (file)
@@ -6,15 +6,15 @@
  * See: http://www.inspircd.org/wiki/index.php/Credits
  *
  * This program is free but copyrighted software; see
- *            the file COPYING for details.
+ *         the file COPYING for details.
  *
  * ---------------------------------------------------
  */
 
+#include "inspircd.h"
 #include "users.h"
 #include "channels.h"
 #include "modules.h"
-#include "inspircd.h"
 
 /* $ModDesc: Provides channel +S mode (strip ansi colour) */
 
@@ -58,7 +58,7 @@ class UserStripColor : public ModeHandler
        ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string &parameter, bool adding)
        {
                /* Only opers can change other users modes */
-               if ((source != dest) && (!*source->oper))
+               if (source != dest)
                        return MODEACTION_DENY;
 
                if (adding)
@@ -85,17 +85,13 @@ class UserStripColor : public ModeHandler
 
 class ModuleStripColor : public Module
 {
- ConfigReader *Conf, *MyConf;
- ChannelStripColor *csc;
- UserStripColor *usc;
+       bool AllowChanOps;
+       ChannelStripColor *csc;
+       UserStripColor *usc;
  
  public:
-       ModuleStripColor(InspIRCd* Me)
-               : Module::Module(Me)
+       ModuleStripColor(InspIRCd* Me) : Module(Me)
        {
-               
-
                usc = new UserStripColor(ServerInstance);
                csc = new ChannelStripColor(ServerInstance);
 
@@ -116,56 +112,35 @@ class ModuleStripColor : public Module
                DELETE(csc);
        }
        
-       // ANSI colour stripping based on C example by Doc (Peter Wood)
        virtual void ReplaceLine(std::string &sentence)
        {
-               int i, a, len, remove;
-               len = sentence.length();
-
-               for (i = 0; i < len; i++)
-               {
-                       remove = 0;
-
-                       switch (sentence[i])
+               /* 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)
+               {
+                       if ((*i == 3))
+                               seq = 1;
+                       else if (seq && ( (*i >= '0') && (*i <= '9') || (*i == ',') ) )
                        {
-                               case 2:
-                               case 15:
-                               case 22:
-                               case 21:
-                               case 31:
-                                       remove++;
-                               break;
-
-                               case 3:
-                                       remove = 1;
-
-                                       if (isdigit(sentence[i + remove]))
-                                               remove++;
-
-                                       if (isdigit(sentence[i + remove]))
-                                               remove++;
-
-                                       if (sentence[i + remove] == ',')
-                                       {
-                                               remove += 2;
-
-                                               if (isdigit(sentence[i + remove]))
-                                                       remove++;
-                                       }
-                               break;
+                               seq++;
+                               if ( (seq <= 4) && (*i == ',') )
+                                       seq = 1;
+                               else if (seq > 3)
+                                       seq = 0;
                        }
-
-                       if (remove != 0)
+                       else
+                               seq = 0;
+                       
+                       if (seq || ((*i == 2) || (*i == 15) || (*i == 22) || (*i == 21) || (*i == 31)))
                        {
-                               len -= remove;
-
-                               for (a = i; a <= len; a++)
-                                       sentence[a] = sentence[a + remove];
-                               i--;
+                               safei = i;
+                               --i;
+                               sentence.erase(safei);
                        }
                }
        }
-       
+
        virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
        {
                if (!IS_LOCAL(user))
@@ -180,12 +155,18 @@ class ModuleStripColor : public Module
                else if (target_type == TYPE_CHANNEL)
                {
                        chanrec* t = (chanrec*)dest;
-                       active = t->IsModeSet('S');
+
+                       // 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 (active)
                {
                        this->ReplaceLine(text);
                }
+
                return 0;
        }
        
@@ -201,29 +182,4 @@ class ModuleStripColor : public Module
        
 };
 
-// stuff down here is the module-factory stuff. For basic modules you can ignore this.
-
-class ModuleStripColorFactory : public ModuleFactory
-{
- public:
-       ModuleStripColorFactory()
-       {
-       }
-       
-       ~ModuleStripColorFactory()
-       {
-       }
-       
-       virtual Module * CreateModule(InspIRCd* Me)
-       {
-               return new ModuleStripColor(Me);
-       }
-       
-};
-
-
-extern "C" void * init_module( void )
-{
-       return new ModuleStripColorFactory;
-}
-
+MODULE_INIT(ModuleStripColor)