summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2007-05-28 22:42:33 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2007-05-28 22:42:33 +0000
commit82a62fd8cb49481c5163a22f7659f1e91d98778a (patch)
tree29c47537ce0df6429762064dce150f9b5603b760 /src
parentccbf152ca4a40eadd577234011de329bf5aa292a (diff)
Make the flags work
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@7180 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src')
-rw-r--r--src/modules/extra/m_filter_pcre.cpp7
-rw-r--r--src/modules/m_filter.cpp7
-rw-r--r--src/modules/m_filter.h26
3 files changed, 33 insertions, 7 deletions
diff --git a/src/modules/extra/m_filter_pcre.cpp b/src/modules/extra/m_filter_pcre.cpp
index 7faa4a40b..8823e385e 100644
--- a/src/modules/extra/m_filter_pcre.cpp
+++ b/src/modules/extra/m_filter_pcre.cpp
@@ -57,10 +57,15 @@ class ModuleFilterPCRE : public FilterBase
{
}
- virtual FilterResult* FilterMatch(const std::string &text, int flags)
+ virtual FilterResult* FilterMatch(userrec* user, const std::string &text, int flags)
{
for (std::vector<PCREFilter>::iterator index = filters.begin(); index != filters.end(); index++)
{
+ /* Skip ones that dont apply to us */
+
+ if (!FilterBase::AppliesToMe(user, dynamic_cast<FilterResult*>(&(*index)), flags))
+ continue;
+
if (pcre_exec(index->regexp, NULL, text.c_str(), text.length(), 0, 0, NULL, 0) > -1)
{
fr = *index;
diff --git a/src/modules/m_filter.cpp b/src/modules/m_filter.cpp
index bcbf3d2bf..9dda30f66 100644
--- a/src/modules/m_filter.cpp
+++ b/src/modules/m_filter.cpp
@@ -38,10 +38,15 @@ class ModuleFilter : public FilterBase
{
}
- virtual FilterResult* FilterMatch(const std::string &text, int flags)
+ virtual FilterResult* FilterMatch(userrec* user, const std::string &text, int flags)
{
for (filter_t::iterator index = filters.begin(); index != filters.end(); index++)
{
+
+ /* Skip ones that dont apply to us */
+ if (!FilterBase::AppliesToMe(user, index->second, flags))
+ continue;
+
if (ServerInstance->MatchText(text,index->first))
{
FilterResult* fr = index->second;
diff --git a/src/modules/m_filter.h b/src/modules/m_filter.h
index 4fc7cfff4..9d0fff34b 100644
--- a/src/modules/m_filter.h
+++ b/src/modules/m_filter.h
@@ -99,7 +99,7 @@ class FilterBase : public Module
virtual ~FilterBase();
virtual void Implements(char* List);
virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list);
- virtual FilterResult* FilterMatch(const std::string &text, int flags) = 0;
+ virtual FilterResult* FilterMatch(userrec* user, const std::string &text, int flags) = 0;
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);
@@ -113,6 +113,7 @@ class FilterBase : public Module
virtual void OnDecodeMetaData(int target_type, void* target, const std::string &extname, const std::string &extdata);
virtual int OnStats(char symbol, userrec* user, string_list &results) = 0;
virtual int OnPreCommand(const std::string &command, const char** parameters, int pcnt, userrec *user, bool validated, const std::string &original_line);
+ bool AppliesToMe(userrec* user, FilterResult* filter, int flags);
};
class cmd_filter : public command_t
@@ -205,6 +206,21 @@ class cmd_filter : public command_t
}
};
+bool FilterBase::AppliesToMe(userrec* user, FilterResult* filter, int flags)
+{
+ if ((flags & FLAG_NOOPERS) && (filter->flag_no_opers) && IS_OPER(user))
+ return false;
+ if ((flags & FLAG_PRIVMSG) && (!filter->flag_privmsg))
+ return false;
+ if ((flags & FLAG_NOTICE) && (!filter->flag_notice))
+ return false;
+ if ((flags & FLAG_QUIT) && (!filter->flag_quit_message))
+ return false;
+ if ((flags & FLAG_PART) && (!filter->flag_part_message))
+ return false;
+ return true;
+}
+
FilterBase::FilterBase(InspIRCd* Me, const std::string &source) : Module(Me)
{
filtcommand = new cmd_filter(this, Me, source);
@@ -235,7 +251,7 @@ int FilterBase::OnUserPreNotice(userrec* user,void* dest,int target_type, std::s
if ((ServerInstance->ULine(user->server)) || (!IS_LOCAL(user)))
return 0;
- FilterResult* f = this->FilterMatch(text, flags);
+ FilterResult* f = this->FilterMatch(user, text, flags);
if (f)
{
std::string target = "";
@@ -295,7 +311,7 @@ int FilterBase::OnPreCommand(const std::string &command, const char** parameters
checkline = parameters[0];
replacepoint = 0;
parting = false;
- flags |= FLAG_QUIT;
+ flags = FLAG_QUIT;
}
else if (command == "PART")
{
@@ -306,7 +322,7 @@ int FilterBase::OnPreCommand(const std::string &command, const char** parameters
checkline = parameters[1];
replacepoint = 1;
parting = true;
- flags |= FLAG_PART;
+ flags = FLAG_PART;
}
else
/* We're only messing with PART and QUIT */
@@ -315,7 +331,7 @@ int FilterBase::OnPreCommand(const std::string &command, const char** parameters
FilterResult* f = NULL;
if (flags)
- f = this->FilterMatch(checkline, flags);
+ f = this->FilterMatch(user, checkline, flags);
if (!f)
/* PART or QUIT reason doesnt match a filter */