X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_filter.cpp;h=bd19a60ba1292e5db8cb5180b49fe2ef50271b6f;hb=f471083cd0519d47c7c7a09029813ede41994f7b;hp=1e9b094f0ffb55d740eb4768050cd3983c635202;hpb=477811faefa0a5b4e7d824eaae7a755bb0cf9517;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_filter.cpp b/src/modules/m_filter.cpp index 1e9b094f0..bd19a60ba 100644 --- a/src/modules/m_filter.cpp +++ b/src/modules/m_filter.cpp @@ -156,7 +156,7 @@ class CommandFilter : public Command class ModuleFilter : public Module { - typedef std::set ExemptTargetSet; + typedef insp::flat_set ExemptTargetSet; bool initing; RegexFactory* factory; @@ -172,6 +172,9 @@ 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(); ModResult OnUserPreMessage(User* user, void* dest, int target_type, std::string& text, char status, CUList& exempt_list, MessageType msgtype) CXX11_OVERRIDE; @@ -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 ¶meters, 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 ¶meters, 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 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::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;