]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_censor.cpp
Increase penalty for KNOCK
[user/henk/code/inspircd.git] / src / modules / m_censor.cpp
index 6050d49aba15f2f4951574e92a0a1aa0ffe5f068..e356ee9a75ae0e52f7040f609133acc5d7eec580 100644 (file)
@@ -2,7 +2,7 @@
  *       | Inspire Internet Relay Chat Daemon |
  *       +------------------------------------+
  *
- *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
+ *  InspIRCd: (C) 2002-2010 InspIRCd Development Team
  * See: http://wiki.inspircd.org/Credits
  *
  * This program is free but copyrighted software; see
@@ -26,7 +26,7 @@ typedef std::map<irc::string,irc::string> censor_t;
 class CensorUser : public SimpleUserModeHandler
 {
  public:
-       CensorUser(InspIRCd* Instance, Module* Creator) : SimpleUserModeHandler(Instance, Creator, 'G') { }
+       CensorUser(Module* Creator) : SimpleUserModeHandler(Creator, "censor", 'G') { }
 };
 
 /** Handles channel mode +G
@@ -34,7 +34,7 @@ class CensorUser : public SimpleUserModeHandler
 class CensorChannel : public SimpleChannelModeHandler
 {
  public:
-       CensorChannel(InspIRCd* Instance, Module* Creator) : SimpleChannelModeHandler(Instance, Creator, 'G') { }
+       CensorChannel(Module* Creator) : SimpleChannelModeHandler(Creator, "censor", 'G') { }
 };
 
 class ModuleCensor : public Module
@@ -44,23 +44,22 @@ class ModuleCensor : public Module
        CensorChannel cc;
 
  public:
-       ModuleCensor(InspIRCd* Me)
-               : Module(Me), cu(Me, this), cc(Me, this)
+       ModuleCensor() : cu(this), cc(this) { }
+
+       void init()
        {
                /* Read the configuration file on startup.
                 */
                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, I_OnRunTestSuite };
-               ServerInstance->Modules->Attach(eventlist, this, 4);
+               ServerInstance->Modules->AddService(cu);
+               ServerInstance->Modules->AddService(cc);
+               Implementation eventlist[] = { I_OnRehash, I_OnUserPreMessage, I_OnUserPreNotice };
+               ServerInstance->Modules->Attach(eventlist, this, 3);
        }
 
 
        virtual ~ModuleCensor()
        {
-               ServerInstance->Modes->DelMode(&cu);
-               ServerInstance->Modes->DelMode(&cc);
        }
 
        // format of a config entry is <badword text="shit" replace="poo">
@@ -77,10 +76,11 @@ class ModuleCensor : public Module
                {
                        active = ((Channel*)dest)->IsModeSet('G');
                        Channel* c = (Channel*)dest;
-                       if (CHANOPS_EXEMPT(ServerInstance, 'G') && c->GetStatus(user) == STATUS_OP)
-                       {
+                       ModResult res;
+                       FIRST_MOD_RESULT(OnChannelRestrictionApply, res, (user,c,"censor"));
+
+                       if (res == MOD_RES_ALLOW)
                                return MOD_RES_PASSTHRU;
-                       }
                }
 
                if (!active)
@@ -115,22 +115,20 @@ class ModuleCensor : public Module
                 * reload our config file on rehash - we must destroy and re-allocate the classes
                 * to call the constructor again and re-read our data.
                 */
-               ConfigReader* MyConf = new ConfigReader(ServerInstance);
+               ConfigReader MyConf;
                censors.clear();
 
-               for (int index = 0; index < MyConf->Enumerate("badword"); index++)
+               for (int index = 0; index < MyConf.Enumerate("badword"); index++)
                {
-                       irc::string pattern = (MyConf->ReadValue("badword","text",index)).c_str();
-                       irc::string replace = (MyConf->ReadValue("badword","replace",index)).c_str();
+                       irc::string pattern = (MyConf.ReadValue("badword","text",index)).c_str();
+                       irc::string replace = (MyConf.ReadValue("badword","replace",index)).c_str();
                        censors[pattern] = replace;
                }
-
-               delete MyConf;
        }
 
        virtual Version GetVersion()
        {
-               return Version("$Id$",VF_COMMON|VF_VENDOR,API_VERSION);
+               return Version("Provides user and channel +G mode",VF_VENDOR);
        }
 
 };