diff options
author | Attila Molnar <attilamolnar@hush.com> | 2014-04-11 15:25:54 +0200 |
---|---|---|
committer | Attila Molnar <attilamolnar@hush.com> | 2014-04-11 15:25:54 +0200 |
commit | 557c02839bec991dd846a6dc12ce7ba52de1525c (patch) | |
tree | f640e68d6ea26b498be0052c5e6ce5866d69de69 | |
parent | 1453b889ef1045eceed8c2d489531ff5be96ada2 (diff) |
m_filter Allow exemption of messages sent to nicks specified in <exemptfromfilter> tags
Issue #655
-rw-r--r-- | docs/conf/filter.conf.example | 9 | ||||
-rw-r--r-- | src/modules/m_filter.cpp | 20 |
2 files changed, 28 insertions, 1 deletions
diff --git a/docs/conf/filter.conf.example b/docs/conf/filter.conf.example index 447d6274c..ef7f50588 100644 --- a/docs/conf/filter.conf.example +++ b/docs/conf/filter.conf.example @@ -59,3 +59,12 @@ # You may specify specific channels that are exempt from being filtered: #<exemptfromfilter target="#opers"> #<exemptfromfilter target="#help"> + +# You can also exempt messages from being filtered if they are sent to +# specific nicks. +# Example that exempts all messages sent *to* NickServ: +#<exemptfromfilter target="NickServ"> + +# Note that messages *from* services are never subject to filtering; +# <exemptfromfilter> tags are only for exempting messages sent *to* the +# configured targets. diff --git a/src/modules/m_filter.cpp b/src/modules/m_filter.cpp index 1e9b094f0..bfec54059 100644 --- a/src/modules/m_filter.cpp +++ b/src/modules/m_filter.cpp @@ -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; @@ -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) @@ -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"); @@ -691,6 +705,10 @@ ModResult ModuleFilter::OnStats(char symbol, User* user, string_list &results) { results.push_back("223 "+user->nick+" :EXEMPT "+(*i)); } + for (ExemptTargetSet::const_iterator i = exemptednicks.begin(); i != exemptednicks.end(); ++i) + { + results.push_back("223 "+user->nick+" :EXEMPT "+(*i)); + } } return MOD_RES_PASSTHRU; } |