]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_stripcolor.cpp
Improved strhashcomp with no allocations
[user/henk/code/inspircd.git] / src / modules / m_stripcolor.cpp
index ac9a645559b7d2ffc33b0e9ed133350ef9fef88f..19c69ec4b5ea39e00e492ca0df8193da3e5d2807 100644 (file)
@@ -2,7 +2,7 @@
  *       | Inspire Internet Relay Chat Daemon |
  *       +------------------------------------+
  *
- *  Inspire is copyright (C) 2002-2004 ChatSpike-Dev.
+ *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
  *                       E-mail:
  *                <brain@chatspike.net>
  *               <Craig@chatspike.net>
@@ -21,6 +21,7 @@ using namespace std;
 #include "users.h"
 #include "channels.h"
 #include "modules.h"
+#include "helperfuncs.h"
 
 /* $ModDesc: Provides channel +S mode (strip ansi colour) */
 
@@ -30,14 +31,20 @@ class ModuleStripColor : public Module
  ConfigReader *Conf, *MyConf;
  
  public:
-       ModuleStripColor()
+       ModuleStripColor(Server* Me)
+               : Module::Module(Me)
        {
-               Srv = new Server;
+               Srv = Me;
 
                Srv->AddExtendedMode('S',MT_CHANNEL,false,0,0);
                Srv->AddExtendedMode('S',MT_CLIENT,false,0,0);
        }
 
+       void Implements(char* List)
+       {
+               List[I_OnExtendedMode] = List[I_On005Numeric] = List[I_OnUserPreMessage] = List[I_OnUserPreNotice] = 1;
+       }
+
        virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list &params)
        {
                // check if this is our mode character...
@@ -53,26 +60,11 @@ class ModuleStripColor : public Module
 
         virtual void On005Numeric(std::string &output)
         {
-                std::stringstream line(output);
-                std::string temp1, temp2;
-                while (!line.eof())
-                {
-                        line >> temp1;
-                        if (temp1.substr(0,10) == "CHANMODES=")
-                        {
-                                // append the chanmode to the end
-                                temp1 = temp1.substr(10,temp1.length());
-                                temp1 = "CHANMODES=" + temp1 + "S";
-                        }
-                        temp2 = temp2 + temp1 + " ";
-                }
-               if (temp2.length())
-                       output = temp2.substr(0,temp2.length()-1);
+               InsertMode(output,"S",4);
         }
        
        virtual ~ModuleStripColor()
        {
-               delete Srv;
        }
        
        // ANSI colour stripping by Doc (Peter Wood)
@@ -80,9 +72,9 @@ class ModuleStripColor : public Module
        {
                int i, a, len, remove;
                char sentence[MAXBUF];
-               strncpy(sentence,text.c_str(),MAXBUF);
+               strlcpy(sentence,text.c_str(),MAXBUF);
   
-               len = strlen (sentence);
+               len = strlen(sentence);
 
                for (i = 0; i < len; i++)
                {
@@ -101,23 +93,24 @@ class ModuleStripColor : public Module
                                case 3:
                                        remove = 1;
 
-                                       if (isdigit (sentence[i + remove]))
+                                       if (isdigit(sentence[i + remove]))
                                                remove++;
 
-                                       if (isdigit (sentence[i + remove]))
+                                       if (isdigit(sentence[i + remove]))
                                                remove++;
 
                                        if (sentence[i + remove] == ',')
                                        {
                                                remove += 2;
 
-                                               if (isdigit (sentence[i + remove]))
-                                               remove++;
+                                               if (isdigit(sentence[i + remove]))
+                                                       remove++;
                                        }
                                break;
                        }
 
-                       if (remove != 0) {
+                       if (remove != 0)
+                       {
                                len -= remove;
 
                                for (a = i; a <= len; a++)
@@ -129,7 +122,7 @@ class ModuleStripColor : public Module
                text = sentence;
        }
        
-       virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text)
+       virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status)
        {
                bool active = false;
                if (target_type == TYPE_USER)
@@ -149,24 +142,9 @@ class ModuleStripColor : public Module
                return 0;
        }
        
-       virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text)
+       virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status)
        {
-               bool active = false;
-               if (target_type == TYPE_USER)
-               {
-                       userrec* t = (userrec*)dest;
-                       active = (strchr(t->modes,'S') > 0);
-               }
-               else if (target_type == TYPE_CHANNEL)
-               {
-                       chanrec* t = (chanrec*)dest;
-                       active = (t->IsCustomModeSet('S'));
-               }
-               if (active)
-               {
-                       this->ReplaceLine(text);
-               }
-               return 0;
+               return OnUserPreMessage(user,dest,target_type,text,status);
        }
        
        virtual Version GetVersion()
@@ -190,9 +168,9 @@ class ModuleStripColorFactory : public ModuleFactory
        {
        }
        
-       virtual Module * CreateModule()
+       virtual Module * CreateModule(Server* Me)
        {
-               return new ModuleStripColor;
+               return new ModuleStripColor(Me);
        }
        
 };