diff options
Diffstat (limited to 'src/modules/m_filter.h')
-rw-r--r-- | src/modules/m_filter.h | 76 |
1 files changed, 56 insertions, 20 deletions
diff --git a/src/modules/m_filter.h b/src/modules/m_filter.h index f7d3438bd..f8c688d70 100644 --- a/src/modules/m_filter.h +++ b/src/modules/m_filter.h @@ -20,11 +20,54 @@ class FilterResult : public classbase std::string reason; std::string action; long gline_time; - bool opers_exempt; + std::string flags; - FilterResult(const std::string free, const std::string &rea, const std::string &act, long gt, bool operex = false) : freeform(free), reason(rea), - action(act), gline_time(gt), opers_exempt(operex) + bool flag_no_opers; + bool flag_part_message; + bool flag_quit_message; + bool flag_privmsg; + bool flag_notice; + + FilterResult(const std::string free, const std::string &rea, const std::string &act, long gt, const std::string &fla) : freeform(free), reason(rea), + action(act), gline_time(gt), flags(fla) + { + this->FillFlags(flags); + } + + int FillFlags(const std::string &flags) { + flag_no_opers = flag_part_message = flag_quit_message = flag_privmsg = flag_notice = false; + size_t x = 0; + + for (std::string::const_iterator n = flags.begin(); n != flags.end(); ++n, ++x) + { + switch (*n) + { + case 'o': + flag_no_opers = true; + break; + case 'P': + flag_part_message = true; + break; + case 'q': + flag_quit_message = true; + break; + case 'p': + flag_privmsg = true; + break; + case 'n': + flag_notice = true; + break; + case '*': + flag_no_opers = flag_part_message = flag_quit_message = + flag_privmsg = flag_notice = true; + break; + default: + return x; + break; + } + } + return 0; } FilterResult() @@ -50,7 +93,7 @@ class FilterBase : public Module virtual bool DeleteFilter(const std::string &freeform) = 0; virtual void SyncFilters(Module* proto, void* opaque) = 0; virtual void SendFilter(Module* proto, void* opaque, FilterResult* iter); - virtual std::pair<bool, std::string> AddFilter(const std::string &freeform, const std::string &type, const std::string &reason, long duration, bool operexempt) = 0; + virtual std::pair<bool, std::string> AddFilter(const std::string &freeform, const std::string &type, const std::string &reason, long duration, const std::string &flags) = 0; virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list); virtual void OnRehash(userrec* user, const std::string ¶meter); virtual Version GetVersion(); @@ -98,17 +141,7 @@ class cmd_filter : public command_t std::string flags = parameters[2]; std::string reason; long duration = 0; - bool operexempt = false; - for (std::string::const_iterator n = flags.begin(); n != flags.end(); ++n) - { - switch (*n) - { - case 'o': - operexempt = true; - break; - } - } if ((type != "gline") && (type != "none") && (type != "block") && (type != "kill") && (type != "silent")) { @@ -133,12 +166,12 @@ class cmd_filter : public command_t { reason = parameters[3]; } - std::pair<bool, std::string> result = Base->AddFilter(freeform, type, reason, duration, operexempt); + std::pair<bool, std::string> result = Base->AddFilter(freeform, type, reason, duration, flags); if (result.first) { - user->WriteServ("NOTICE %s :*** Added filter '%s', type '%s'%s%s, reason: '%s'", user->nick, freeform.c_str(), + user->WriteServ("NOTICE %s :*** Added filter '%s', type '%s'%s%s, flags '%s', reason: '%s'", user->nick, freeform.c_str(), type.c_str(), (duration ? " duration: " : ""), (duration ? parameters[3] : ""), - reason.c_str()); + flags.c_str(), reason.c_str()); return CMD_SUCCESS; } else @@ -336,7 +369,7 @@ std::string FilterBase::EncodeFilter(FilterResult* filter) if (*n == ' ') *n = '\7'; - stream << x << " " << filter->action << " " << filter->opers_exempt << " " << filter->gline_time << " " << filter->reason; + stream << x << " " << filter->action << " " << (filter->flags.empty() ? "-" : filter->flags) << " " << filter->gline_time << " " << filter->reason; return stream.str(); } @@ -347,7 +380,10 @@ FilterResult FilterBase::DecodeFilter(const std::string &data) stream >> res.freeform; stream >> res.action; - stream >> res.opers_exempt; + stream >> res.flags; + if (res.flags == "-") + res.flags = ""; + res.FillFlags(res.flags); stream >> res.gline_time; res.reason = stream.str(); @@ -373,7 +409,7 @@ void FilterBase::OnDecodeMetaData(int target_type, void* target, const std::stri if ((target_type == TYPE_OTHER) && (extname == "filter")) { FilterResult data = DecodeFilter(extdata); - this->AddFilter(data.freeform, data.action, data.reason, data.gline_time, data.opers_exempt); + this->AddFilter(data.freeform, data.action, data.reason, data.gline_time, data.flags); } } |