X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_filter.cpp;h=34d0bebb3cce91d865a14cde6f912b69ee4175b6;hb=43b5073d6f80a8dcb7044ecd127fd5893da033ab;hp=a1ef828da044c1ecbe11f8a9bcb477c6f651016b;hpb=7bf233bf0015ab5e4c07ef8db7711154736d2355;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_filter.cpp b/src/modules/m_filter.cpp index a1ef828da..34d0bebb3 100644 --- a/src/modules/m_filter.cpp +++ b/src/modules/m_filter.cpp @@ -156,6 +156,8 @@ class CommandFilter : public Command class ModuleFilter : public Module { + typedef insp::flat_set ExemptTargetSet; + bool initing; RegexFactory* factory; void FreeFilters(); @@ -167,7 +169,11 @@ class ModuleFilter : public Module std::vector filters; int flags; - std::set exemptfromfilter; // List of channel names excluded from filtering. + // List of channel names excluded from filtering. + ExemptTargetSet exemptedchans; + + // List of target nicknames excluded from filtering. + ExemptTargetSet exemptednicks; ModuleFilter(); CullResult cull(); @@ -306,8 +312,8 @@ void ModuleFilter::FreeFilters() ModResult ModuleFilter::OnUserPreMessage(User* user, void* dest, int target_type, std::string& text, char status, CUList& exempt_list, MessageType msgtype) { - /* Leave ulines alone */ - if ((ServerInstance->ULine(user->server)) || (!IS_LOCAL(user))) + // Leave remote users and servers alone + if (!IS_LOCAL(user)) return MOD_RES_PASSTHRU; flags = (msgtype == MSG_PRIVMSG) ? FLAG_PRIVMSG : FLAG_NOTICE; @@ -319,12 +325,16 @@ 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) { Channel* t = (Channel*)dest; - if (exemptfromfilter.find(t->name) != exemptfromfilter.end()) + if (exemptedchans.count(t->name)) return MOD_RES_PASSTHRU; target = t->name; @@ -367,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; @@ -387,7 +397,7 @@ ModResult ModuleFilter::OnPreCommand(std::string &command, std::vectorConfig->ConfTags("exemptfromfilter"); - exemptfromfilter.clear(); + exemptedchans.clear(); + exemptednicks.clear(); + for (ConfigIter i = tags.first; i != tags.second; ++i) { - std::string chan = i->second->getString("channel"); - if (!chan.empty()) - exemptfromfilter.insert(chan); + ConfigTag* tag = i->second; + + // 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()) + { + if (target[0] == '#') + exemptedchans.insert(target); + else + exemptednicks.insert(target); + } } std::string newrxengine = ServerInstance->Config->ConfValue("filteropts")->getString("engine"); @@ -679,11 +699,15 @@ ModResult ModuleFilter::OnStats(char symbol, User* user, string_list &results) { for (std::vector::iterator i = filters.begin(); i != filters.end(); i++) { - results.push_back(ServerInstance->Config->ServerName+" 223 "+user->nick+" :"+RegexEngine.GetProvider()+":"+i->freeform+" "+i->GetFlags()+" "+FilterActionToString(i->action)+" "+ConvToStr(i->gline_time)+" :"+i->reason); + results.push_back("223 "+user->nick+" :"+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)); } - for (std::set::iterator i = exemptfromfilter.begin(); i != exemptfromfilter.end(); ++i) + for (ExemptTargetSet::const_iterator i = exemptednicks.begin(); i != exemptednicks.end(); ++i) { - results.push_back(ServerInstance->Config->ServerName+" 223 "+user->nick+" :EXEMPT "+(*i)); + results.push_back("223 "+user->nick+" :EXEMPT "+(*i)); } } return MOD_RES_PASSTHRU;