X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_filter.cpp;h=d3d3ef2185f30c041defb81fce553e3ce23d5e29;hb=93fa544b2671b078cf81ac04fbb4b48d5e2d1677;hp=7f5be3639984d53291134beb42dee8607b77ce5e;hpb=197c3445b04f16dd563426fb606c848f20f77c96;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_filter.cpp b/src/modules/m_filter.cpp index 7f5be3639..d3d3ef218 100644 --- a/src/modules/m_filter.cpp +++ b/src/modules/m_filter.cpp @@ -25,6 +25,7 @@ #include "modules/regex.h" #include "modules/server.h" #include "modules/shun.h" +#include "modules/stats.h" enum FilterFlags { @@ -160,7 +161,7 @@ class CommandFilter : public Command } }; -class ModuleFilter : public Module, public ServerEventListener +class ModuleFilter : public Module, public ServerEventListener, public Stats::EventListener { typedef insp::flat_set ExemptTargetSet; @@ -183,7 +184,7 @@ class ModuleFilter : public Module, public ServerEventListener ModuleFilter(); 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; + ModResult OnUserPreMessage(User* user, const MessageTarget& target, MessageDetails& details) CXX11_OVERRIDE; FilterResult* FilterMatch(User* user, const std::string &text, int flags); bool DeleteFilter(const std::string &freeform); std::pair AddFilter(const std::string &freeform, FilterAction type, const std::string &reason, long duration, const std::string &flags); @@ -302,6 +303,7 @@ bool ModuleFilter::AppliesToMe(User* user, FilterResult* filter, int iflags) ModuleFilter::ModuleFilter() : ServerEventListener(this) + , Stats::EventListener(this) , initing(true) , filtcommand(this) , RegexEngine(this, "regex") @@ -322,30 +324,30 @@ void ModuleFilter::FreeFilters() filters.clear(); } -ModResult ModuleFilter::OnUserPreMessage(User* user, void* dest, int target_type, std::string& text, char status, CUList& exempt_list, MessageType msgtype) +ModResult ModuleFilter::OnUserPreMessage(User* user, const MessageTarget& msgtarget, MessageDetails& details) { // Leave remote users and servers alone if (!IS_LOCAL(user)) return MOD_RES_PASSTHRU; - flags = (msgtype == MSG_PRIVMSG) ? FLAG_PRIVMSG : FLAG_NOTICE; + flags = (details.type == MSG_PRIVMSG) ? FLAG_PRIVMSG : FLAG_NOTICE; - FilterResult* f = this->FilterMatch(user, text, flags); + FilterResult* f = this->FilterMatch(user, details.text, flags); if (f) { std::string target; - if (target_type == TYPE_USER) + if (msgtarget.type == MessageTarget::TYPE_USER) { - User* t = (User*)dest; + User* t = msgtarget.Get(); // 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) + else if (msgtarget.type == MessageTarget::TYPE_CHANNEL) { - Channel* t = (Channel*)dest; + Channel* t = msgtarget.Get(); if (exemptedchans.count(t->name)) return MOD_RES_PASSTHRU; @@ -354,14 +356,14 @@ ModResult ModuleFilter::OnUserPreMessage(User* user, void* dest, int target_type if (f->action == FA_BLOCK) { ServerInstance->SNO->WriteGlobalSno('a', "FILTER: "+user->nick+" had their message filtered, target was "+target+": "+f->reason); - if (target_type == TYPE_CHANNEL) + if (msgtarget.type == MessageTarget::TYPE_CHANNEL) 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) + if (msgtarget.type == MessageTarget::TYPE_CHANNEL) 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);