]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_censor.cpp
Allow commands to optionally route themselves using ENCAP
[user/henk/code/inspircd.git] / src / modules / m_censor.cpp
index e561b80a1c063788cbaddaf118fce98cb14184ec..9c68be7fdcb23a62771d0d9deb7377fbe58ec063 100644 (file)
@@ -2,8 +2,8 @@
  *       | Inspire Internet Relay Chat Daemon |
  *       +------------------------------------+
  *
- *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
- * See: http://www.inspircd.org/wiki/index.php/Credits
+ *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
+ * See: http://wiki.inspircd.org/Credits
  *
  * This program is free but copyrighted software; see
  *            the file COPYING for details.
@@ -15,6 +15,7 @@
 #define _SCL_SECURE_NO_DEPRECATE
 
 #include "inspircd.h"
+#include <iostream>
 
 typedef std::map<irc::string,irc::string> censor_t;
 
@@ -39,48 +40,27 @@ class CensorChannel : public SimpleChannelModeHandler
 class ModuleCensor : public Module
 {
        censor_t censors;
-       CensorUser *cu;
-       CensorChannel *cc;
+       CensorUser cu;
+       CensorChannel cc;
 
  public:
        ModuleCensor(InspIRCd* Me)
-               : Module(Me)
+               : Module(Me), cu(Me), cc(Me)
        {
                /* Read the configuration file on startup.
                 */
-               OnRehash(NULL,"");
-               cu = new CensorUser(ServerInstance);
-               cc = new CensorChannel(ServerInstance);
-               if (!ServerInstance->Modes->AddMode(cu) || !ServerInstance->Modes->AddMode(cc))
-               {
-                       delete cu;
-                       delete cc;
+               OnRehash(NULL);
+               if (!ServerInstance->Modes->AddMode(&cu) || !ServerInstance->Modes->AddMode(&cc))
                        throw ModuleException("Could not add new modes!");
-               }
-               Implementation eventlist[] = { I_OnRehash, I_OnUserPreMessage, I_OnUserPreNotice };
-               ServerInstance->Modules->Attach(eventlist, this, 3);
+               Implementation eventlist[] = { I_OnRehash, I_OnUserPreMessage, I_OnUserPreNotice, I_OnRunTestSuite };
+               ServerInstance->Modules->Attach(eventlist, this, 4);
        }
 
 
        virtual ~ModuleCensor()
        {
-               ServerInstance->Modes->DelMode(cu);
-               ServerInstance->Modes->DelMode(cc);
-               delete cu;
-               delete cc;
-       }
-
-       virtual void ReplaceLine(irc::string &text, irc::string pattern, irc::string replace)
-       {
-               if ((!pattern.empty()) && (!text.empty()))
-               {
-                       std::string::size_type pos;
-                       while ((pos = text.find(pattern)) != irc::string::npos)
-                       {
-                               text.erase(pos,pattern.length());
-                               text.insert(pos,replace);
-                       }
-               }
+               ServerInstance->Modes->DelMode(&cu);
+               ServerInstance->Modes->DelMode(&cc);
        }
 
        // format of a config entry is <badword text="shit" replace="poo">
@@ -117,7 +97,7 @@ class ModuleCensor : public Module
                                        return 1;
                                }
 
-                               this->ReplaceLine(text2,index->first,index->second);
+                               SearchAndReplace(text2, index->first, index->second);
                        }
                }
                text = text2.c_str();
@@ -129,7 +109,7 @@ class ModuleCensor : public Module
                return OnUserPreMessage(user,dest,target_type,text,status,exempt_list);
        }
 
-       virtual void OnRehash(User* user, const std::string &parameter)
+       virtual void OnRehash(User* user)
        {
                /*
                 * reload our config file on rehash - we must destroy and re-allocate the classes