]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_filter.cpp
Fix the noctcp user mode not applying to channel CTCPs.
[user/henk/code/inspircd.git] / src / modules / m_filter.cpp
index c0798f7d0353452a9b8a8d89bd6fa37cfcd92386..6c22069935f7465756fa9217203bdbb708a3decc 100644 (file)
@@ -173,12 +173,16 @@ class CommandFilter : public Command
        }
 };
 
-class ModuleFilter : public Module, public ServerEventListener, public Stats::EventListener
+class ModuleFilter
+       : public Module
+       , public ServerProtocol::SyncEventListener
+       , public Stats::EventListener
 {
        typedef insp::flat_set<std::string, irc::insensitive_swo> ExemptTargetSet;
 
        bool initing;
        bool notifyuser;
+       bool warnonselfmsg;
        RegexFactory* factory;
        void FreeFilters();
 
@@ -331,7 +335,7 @@ bool ModuleFilter::AppliesToMe(User* user, FilterResult* filter, int iflags)
 }
 
 ModuleFilter::ModuleFilter()
-       : ServerEventListener(this)
+       : ServerProtocol::SyncEventListener(this)
        , Stats::EventListener(this)
        , initing(true)
        , filtcommand(this)
@@ -369,31 +373,49 @@ ModResult ModuleFilter::OnUserPreMessage(User* user, const MessageTarget& msgtar
        FilterResult* f = this->FilterMatch(user, details.text, flags);
        if (f)
        {
+               bool is_selfmsg = false;
                std::string target;
-               if (msgtarget.type == MessageTarget::TYPE_USER)
+               switch (msgtarget.type)
                {
-                       User* t = msgtarget.Get<User>();
-                       // Check if the target nick is exempted, if yes, ignore this message
-                       if (exemptednicks.count(t->nick))
-                               return MOD_RES_PASSTHRU;
+                       case MessageTarget::TYPE_USER:
+                       {
+                               User* t = msgtarget.Get<User>();
+                               // Check if the target nick is exempted, if yes, ignore this message
+                               if (exemptednicks.count(t->nick))
+                                       return MOD_RES_PASSTHRU;
+
+                               if (user == t)
+                                       is_selfmsg = true;
+
+                               target = t->nick;
+                               break;
+                       }
+                       case MessageTarget::TYPE_CHANNEL:
+                       {
+                               Channel* t = msgtarget.Get<Channel>();
+                               if (exemptedchans.count(t->name))
+                                       return MOD_RES_PASSTHRU;
 
-                       target = t->nick;
+                               target = t->name;
+                               break;
+                       }
+                       case MessageTarget::TYPE_SERVER:
+                               break;
                }
-               else if (msgtarget.type == MessageTarget::TYPE_CHANNEL)
-               {
-                       Channel* t = msgtarget.Get<Channel>();
-                       if (exemptedchans.count(t->name))
-                               return MOD_RES_PASSTHRU;
 
-                       target = t->name;
+               if (is_selfmsg && warnonselfmsg)
+               {
+                       ServerInstance->SNO->WriteGlobalSno('f', InspIRCd::Format("WARNING: %s's self message matched %s (%s)",
+                               user->nick.c_str(), f->freeform.c_str(), f->reason.c_str()));
+                       return MOD_RES_PASSTHRU;
                }
-               if (f->action == FA_WARN)
+               else if (f->action == FA_WARN)
                {
                        ServerInstance->SNO->WriteGlobalSno('f', InspIRCd::Format("WARNING: %s's message to %s matched %s (%s)",
                                user->nick.c_str(), target.c_str(), f->freeform.c_str(), f->reason.c_str()));
                        return MOD_RES_PASSTHRU;
                }
-               if (f->action == FA_BLOCK)
+               else if (f->action == FA_BLOCK)
                {
                        ServerInstance->SNO->WriteGlobalSno('f', InspIRCd::Format("%s had their message to %s filtered as it matched %s (%s)",
                                user->nick.c_str(), target.c_str(), f->freeform.c_str(), f->reason.c_str()));
@@ -609,6 +631,7 @@ void ModuleFilter::ReadConfig(ConfigStatus& status)
        ConfigTag* tag = ServerInstance->Config->ConfValue("filteropts");
        std::string newrxengine = tag->getString("engine");
        notifyuser = tag->getBool("notifyuser", true);
+       warnonselfmsg = tag->getBool("warnonselfmsg");
 
        factory = RegexEngine ? (RegexEngine.operator->()) : NULL;