summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2007-05-28 22:19:26 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2007-05-28 22:19:26 +0000
commit5183b9b8207a26b6196b7da0a1d092bb1f6e8429 (patch)
tree6e9b14ba39f98d3e7694aeff4e6d0aca783cbaa0
parent30904ef950c32e03c19aaae2399bcd3b8841b42a (diff)
Stuff for flags as requested by djGrr. We aren't going all-out rediculous amount of flags on this, we're sticking with the 5 or 6 easy to remember and lumping oper-immunity into the flags (see forums)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@7178 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r--src/modules/extra/m_filter_pcre.cpp13
-rw-r--r--src/modules/m_filter.cpp16
-rw-r--r--src/modules/m_filter.h76
3 files changed, 66 insertions, 39 deletions
diff --git a/src/modules/extra/m_filter_pcre.cpp b/src/modules/extra/m_filter_pcre.cpp
index a347bcb57..bafb40070 100644
--- a/src/modules/extra/m_filter_pcre.cpp
+++ b/src/modules/extra/m_filter_pcre.cpp
@@ -28,8 +28,8 @@ class PCREFilter : public FilterResult
public:
pcre* regexp;
- PCREFilter(pcre* r, const std::string &rea, const std::string &act, long gline_time, const std::string &pat, bool operex)
- : FilterResult::FilterResult(pat, rea, act, gline_time, operex), regexp(r)
+ PCREFilter(pcre* r, const std::string &rea, const std::string &act, long gline_time, const std::string &pat, const std::string &flags)
+ : FilterResult::FilterResult(pat, rea, act, gline_time, flags), regexp(r)
{
}
@@ -97,7 +97,7 @@ class ModuleFilterPCRE : public FilterBase
}
}
- virtual std::pair<bool, std::string> AddFilter(const std::string &freeform, const std::string &type, const std::string &reason, long duration, bool operexception)
+ 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)
{
for (std::vector<PCREFilter>::iterator i = filters.begin(); i != filters.end(); i++)
{
@@ -117,7 +117,7 @@ class ModuleFilterPCRE : public FilterBase
}
else
{
- filters.push_back(PCREFilter(re, reason, type, duration, freeform, operexception));
+ filters.push_back(PCREFilter(re, reason, type, duration, freeform, flags));
return std::make_pair(true, "");
}
}
@@ -133,8 +133,7 @@ class ModuleFilterPCRE : public FilterBase
std::string pattern = MyConf.ReadValue("keyword", "pattern", index);
std::string reason = MyConf.ReadValue("keyword", "reason", index);
std::string action = MyConf.ReadValue("keyword", "action", index);
- // = MyConf.ReadFlag("keyword", "flags")
- bool operexception = false;
+ std::string flags = MyConf.ReadValue("keyword", "flags", index);
long gline_time = ServerInstance->Duration(MyConf.ReadValue("keyword", "duration", index).c_str());
re = pcre_compile(pattern.c_str(),0,&error,&erroffset,NULL);
@@ -146,7 +145,7 @@ class ModuleFilterPCRE : public FilterBase
}
else
{
- filters.push_back(PCREFilter(re, reason, action, gline_time, pattern, operexception));
+ filters.push_back(PCREFilter(re, reason, action, gline_time, pattern, flags));
ServerInstance->Log(DEFAULT,"Regular expression %s loaded.", pattern.c_str());
}
}
diff --git a/src/modules/m_filter.cpp b/src/modules/m_filter.cpp
index a8a9508c1..5d0e2ec1d 100644
--- a/src/modules/m_filter.cpp
+++ b/src/modules/m_filter.cpp
@@ -68,19 +68,14 @@ class ModuleFilter : public FilterBase
return false;
}
- virtual std::pair<bool, std::string> AddFilter(const std::string &freeform, const std::string &type, const std::string &reason, long duration, bool operexclusion)
+ 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)
{
if (filters.find(freeform) != filters.end())
{
return std::make_pair(false, "Filter already exists");
}
- FilterResult* x = new FilterResult;
- x->reason = reason;
- x->action = type;
- x->gline_time = duration;
- x->freeform = freeform;
- x->opers_exempt = operexclusion;
+ FilterResult* x = new FilterResult(freeform, reason, type, duration, flags);
filters[freeform] = x;
return std::make_pair(true, "");
@@ -105,14 +100,11 @@ class ModuleFilter : public FilterBase
std::string pattern = MyConf->ReadValue("keyword","pattern",index);
std::string reason = MyConf->ReadValue("keyword","reason",index);
std::string do_action = MyConf->ReadValue("keyword","action",index);
+ std::string flags = MyConf->ReadValue("keyword","flags",index);
long gline_time = ServerInstance->Duration(MyConf->ReadValue("keyword","duration",index).c_str());
if (do_action == "")
do_action = "none";
- FilterResult* x = new FilterResult;
- x->reason = reason;
- x->action = do_action;
- x->gline_time = gline_time;
- x->freeform = pattern;
+ FilterResult* x = new FilterResult(pattern, reason, do_action, gline_time, flags);
filters[pattern] = x;
}
DELETE(MyConf);
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 &parameter);
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);
}
}