]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_censor.cpp
Move OnSync{Channel,Network,User} to ServerEventListener.
[user/henk/code/inspircd.git] / src / modules / m_censor.cpp
index a523346a7725098d1807928c57cd41a8bcb4a7b4..6394ba9d011a357512157613abb47a575de3efa4 100644 (file)
  */
 
 
-#define _CRT_SECURE_NO_DEPRECATE
-#define _SCL_SECURE_NO_DEPRECATE
-
 #include "inspircd.h"
-#include <iostream>
+#include "modules/exemption.h"
 
-typedef std::map<irc::string,irc::string> censor_t;
-
-/** Handles usermode +G
- */
-class CensorUser : public SimpleUserModeHandler
-{
- public:
-       CensorUser(Module* Creator) : SimpleUserModeHandler(Creator, "u_censor", 'G') { }
-};
-
-/** Handles channel mode +G
- */
-class CensorChannel : public SimpleChannelModeHandler
-{
- public:
-       CensorChannel(Module* Creator) : SimpleChannelModeHandler(Creator, "censor", 'G') { }
-};
+typedef insp::flat_map<irc::string, irc::string> censor_t;
 
 class ModuleCensor : public Module
 {
+       CheckExemption::EventProvider exemptionprov;
        censor_t censors;
-       CensorUser cu;
-       CensorChannel cc;
+       SimpleUserModeHandler cu;
+       SimpleChannelModeHandler cc;
 
  public:
-       ModuleCensor() : cu(this), cc(this) { }
+       ModuleCensor()
+               : exemptionprov(this)
+               , cu(this, "u_censor", 'G')
+               , cc(this, "censor", 'G')
+       {
+       }
 
        // format of a config entry is <badword text="shit" replace="poo">
        ModResult OnUserPreMessage(User* user, void* dest, int target_type, std::string& text, char status, CUList& exempt_list, MessageType msgtype) CXX11_OVERRIDE
@@ -67,7 +54,7 @@ class ModuleCensor : public Module
                {
                        Channel* c = (Channel*)dest;
                        active = c->IsModeSet(cc);
-                       ModResult res = ServerInstance->OnCheckExemption(user,c,"censor");
+                       ModResult res = CheckExemption::Call(exemptionprov, user, c, "censor");
 
                        if (res == MOD_RES_ALLOW)
                                return MOD_RES_PASSTHRU;
@@ -83,11 +70,11 @@ class ModuleCensor : public Module
                        {
                                if (index->second.empty())
                                {
-                                       user->WriteNumeric(ERR_WORDFILTERED, "%s %s :Your message contained a censored word, and was blocked", ((Channel*)dest)->name.c_str(), index->first.c_str());
+                                       user->WriteNumeric(ERR_WORDFILTERED, ((target_type == TYPE_CHANNEL) ? ((Channel*)dest)->name : ((User*)dest)->nick), index->first.c_str(), "Your message contained a censored word, and was blocked");
                                        return MOD_RES_DENY;
                                }
 
-                               SearchAndReplace(text2, index->first, index->second);
+                               stdalgo::string::replace_all(text2, index->first, index->second);
                        }
                }
                text = text2.c_str();