]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_filter.cpp
Add the override keyword in places that it is missing.
[user/henk/code/inspircd.git] / src / modules / m_filter.cpp
index 1e9b094f0ffb55d740eb4768050cd3983c635202..8e43d276755078620d738d726bfad1eb296bd7e8 100644 (file)
@@ -146,9 +146,9 @@ class CommandFilter : public Command
                flags_needed = 'o';
                this->syntax = "<filter-definition> <action> <flags> [<gline-duration>] :<reason>";
        }
-       CmdResult Handle(const std::vector<std::string>&, User*);
+       CmdResult Handle(const std::vector<std::string>& , User* ) CXX11_OVERRIDE;
 
-       RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
+       RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters) CXX11_OVERRIDE
        {
                return ROUTE_BROADCAST;
        }
@@ -156,7 +156,7 @@ class CommandFilter : public Command
 
 class ModuleFilter : public Module
 {
-       typedef std::set<std::string, irc::insensitive_swo> ExemptTargetSet;
+       typedef insp::flat_set<std::string, irc::insensitive_swo> ExemptTargetSet;
 
        bool initing;
        RegexFactory* factory;
@@ -172,8 +172,11 @@ class ModuleFilter : public Module
        // List of channel names excluded from filtering.
        ExemptTargetSet exemptedchans;
 
+       // List of target nicknames excluded from filtering.
+       ExemptTargetSet exemptednicks;
+
        ModuleFilter();
-       CullResult cull();
+       CullResult cull() CXX11_OVERRIDE;
        ModResult OnUserPreMessage(User* user, void* dest, int target_type, std::string& text, char status, CUList& exempt_list, MessageType msgtype) CXX11_OVERRIDE;
        FilterResult* FilterMatch(User* user, const std::string &text, int flags);
        bool DeleteFilter(const std::string &freeform);
@@ -184,7 +187,7 @@ class ModuleFilter : public Module
        FilterResult DecodeFilter(const std::string &data);
        void OnSyncNetwork(ProtocolInterface::Server& server) CXX11_OVERRIDE;
        void OnDecodeMetaData(Extensible* target, const std::string &extname, const std::string &extdata) CXX11_OVERRIDE;
-       ModResult OnStats(char symbol, User* user, string_list &results) CXX11_OVERRIDE;
+       ModResult OnStats(Stats::Context& stats) CXX11_OVERRIDE;
        ModResult OnPreCommand(std::string &command, std::vector<std::string> &parameters, LocalUser *user, bool validated, const std::string &original_line) CXX11_OVERRIDE;
        void OnUnloadModule(Module* mod) CXX11_OVERRIDE;
        bool AppliesToMe(User* user, FilterResult* filter, int flags);
@@ -322,6 +325,10 @@ ModResult ModuleFilter::OnUserPreMessage(User* user, void* dest, int target_type
                if (target_type == TYPE_USER)
                {
                        User* t = (User*)dest;
+                       // Check if the target nick is exempted, if yes, ignore this message
+                       if (exemptednicks.count(t->nick))
+                               return MOD_RES_PASSTHRU;
+
                        target = t->nick;
                }
                else if (target_type == TYPE_CHANNEL)
@@ -336,14 +343,14 @@ ModResult ModuleFilter::OnUserPreMessage(User* user, void* dest, int target_type
                {
                        ServerInstance->SNO->WriteGlobalSno('a', "FILTER: "+user->nick+" had their message filtered, target was "+target+": "+f->reason);
                        if (target_type == TYPE_CHANNEL)
-                               user->WriteNumeric(ERR_CANNOTSENDTOCHAN, "%s :Message to channel blocked and opers notified (%s)", target.c_str(), f->reason.c_str());
+                               user->WriteNumeric(ERR_CANNOTSENDTOCHAN, target, InspIRCd::Format("Message to channel blocked and opers notified (%s)", f->reason.c_str()));
                        else
                                user->WriteNotice("Your message to "+target+" was blocked and opers notified: "+f->reason);
                }
                else if (f->action == FA_SILENT)
                {
                        if (target_type == TYPE_CHANNEL)
-                               user->WriteNumeric(ERR_CANNOTSENDTOCHAN, "%s :Message to channel blocked (%s)", target.c_str(), f->reason.c_str());
+                               user->WriteNumeric(ERR_CANNOTSENDTOCHAN, target, InspIRCd::Format("Message to channel blocked (%s)", f->reason.c_str()));
                        else
                                user->WriteNotice("Your message to "+target+" was blocked: "+f->reason);
                }
@@ -370,7 +377,7 @@ ModResult ModuleFilter::OnUserPreMessage(User* user, void* dest, int target_type
 
 ModResult ModuleFilter::OnPreCommand(std::string &command, std::vector<std::string> &parameters, LocalUser *user, bool validated, const std::string &original_line)
 {
-       if (validated && IS_LOCAL(user))
+       if (validated)
        {
                flags = 0;
                bool parting;
@@ -444,6 +451,8 @@ void ModuleFilter::ReadConfig(ConfigStatus& status)
 {
        ConfigTagList tags = ServerInstance->Config->ConfTags("exemptfromfilter");
        exemptedchans.clear();
+       exemptednicks.clear();
+
        for (ConfigIter i = tags.first; i != tags.second; ++i)
        {
                ConfigTag* tag = i->second;
@@ -451,7 +460,12 @@ void ModuleFilter::ReadConfig(ConfigStatus& status)
                // If "target" is not found, try the old "channel" key to keep compatibility with 2.0 configs
                const std::string target = tag->getString("target", tag->getString("channel"));
                if (!target.empty())
-                       exemptedchans.insert(target);
+               {
+                       if (target[0] == '#')
+                               exemptedchans.insert(target);
+                       else
+                               exemptednicks.insert(target);
+               }
        }
 
        std::string newrxengine = ServerInstance->Config->ConfValue("filteropts")->getString("engine");
@@ -618,17 +632,15 @@ std::pair<bool, std::string> ModuleFilter::AddFilter(const std::string &freeform
 
 bool ModuleFilter::StringToFilterAction(const std::string& str, FilterAction& fa)
 {
-       irc::string s(str.c_str());
-
-       if (s == "gline")
+       if (stdalgo::string::equalsci(str, "gline"))
                fa = FA_GLINE;
-       else if (s == "block")
+       else if (stdalgo::string::equalsci(str, "block"))
                fa = FA_BLOCK;
-       else if (s == "silent")
+       else if (stdalgo::string::equalsci(str, "silent"))
                fa = FA_SILENT;
-       else if (s == "kill")
+       else if (stdalgo::string::equalsci(str, "kill"))
                fa = FA_KILL;
-       else if (s == "none")
+       else if (stdalgo::string::equalsci(str, "none"))
                fa = FA_NONE;
        else
                return false;
@@ -679,17 +691,21 @@ void ModuleFilter::ReadFilters()
        }
 }
 
-ModResult ModuleFilter::OnStats(char symbol, User* user, string_list &results)
+ModResult ModuleFilter::OnStats(Stats::Context& stats)
 {
-       if (symbol == 's')
+       if (stats.GetSymbol() == 's')
        {
                for (std::vector<FilterResult>::iterator i = filters.begin(); i != filters.end(); i++)
                {
-                       results.push_back("223 "+user->nick+" :"+RegexEngine.GetProvider()+":"+i->freeform+" "+i->GetFlags()+" "+FilterActionToString(i->action)+" "+ConvToStr(i->gline_time)+" :"+i->reason);
+                       stats.AddRow(223, RegexEngine.GetProvider()+":"+i->freeform+" "+i->GetFlags()+" "+FilterActionToString(i->action)+" "+ConvToStr(i->gline_time)+" :"+i->reason);
                }
                for (ExemptTargetSet::const_iterator i = exemptedchans.begin(); i != exemptedchans.end(); ++i)
                {
-                       results.push_back("223 "+user->nick+" :EXEMPT "+(*i));
+                       stats.AddRow(223, "EXEMPT "+(*i));
+               }
+               for (ExemptTargetSet::const_iterator i = exemptednicks.begin(); i != exemptednicks.end(); ++i)
+               {
+                       stats.AddRow(223, "EXEMPT "+(*i));
                }
        }
        return MOD_RES_PASSTHRU;