summaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
authorPeter Powell <petpow@saberuk.com>2012-09-12 16:27:59 +0100
committerattilamolnar <attilamolnar@hush.com>2012-10-19 17:50:08 +0200
commit3479532178c73ae47da4729865e5bfc91a299027 (patch)
treeb696e2420e8b7fdefb78fdd9ae62559d0be43c1b /src/modules
parentaa1f46885810c4779ae539c142fdee15b556206b (diff)
Fix for #268.
- Move color stripping code to helperfuncs. - Strip color codes before matching filters.
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/m_filter.cpp24
-rw-r--r--src/modules/m_stripcolor.cpp29
2 files changed, 21 insertions, 32 deletions
diff --git a/src/modules/m_filter.cpp b/src/modules/m_filter.cpp
index 9e06ca494..89a6bb2ef 100644
--- a/src/modules/m_filter.cpp
+++ b/src/modules/m_filter.cpp
@@ -50,6 +50,7 @@ class FilterResult
bool flag_quit_message;
bool flag_privmsg;
bool flag_notice;
+ bool flag_strip_color;
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)
@@ -60,7 +61,8 @@ class FilterResult
int FillFlags(const std::string &fl)
{
flags = fl;
- flag_no_opers = flag_part_message = flag_quit_message = flag_privmsg = flag_notice = false;
+ flag_no_opers = flag_part_message = flag_quit_message = flag_privmsg =
+ flag_notice = flag_strip_color = false;
size_t x = 0;
for (std::string::const_iterator n = flags.begin(); n != flags.end(); ++n, ++x)
@@ -82,9 +84,12 @@ class FilterResult
case 'n':
flag_notice = true;
break;
+ case 'c':
+ flag_strip_color = true;
+ break;
case '*':
flag_no_opers = flag_part_message = flag_quit_message =
- flag_privmsg = flag_notice = true;
+ flag_privmsg = flag_notice = flag_strip_color = true;
break;
default:
return x;
@@ -539,14 +544,25 @@ ImplFilter::ImplFilter(ModuleFilter* mymodule, const std::string &rea, const std
FilterResult* ModuleFilter::FilterMatch(User* user, const std::string &text, int flgs)
{
+ static std::string stripped_text;
+ stripped_text.clear();
+
for (std::vector<ImplFilter>::iterator index = filters.begin(); index != filters.end(); index++)
{
+ FilterResult* filter = dynamic_cast<FilterResult*>(&(*index));
+
/* Skip ones that dont apply to us */
- if (!AppliesToMe(user, dynamic_cast<FilterResult*>(&(*index)), flgs))
+ if (!AppliesToMe(user, filter, flgs))
continue;
+ if ((filter->flag_strip_color) && (stripped_text.empty()))
+ {
+ stripped_text = text;
+ InspIRCd::StripColor(stripped_text);
+ }
+
//ServerInstance->Logs->Log("m_filter", DEBUG, "Match '%s' against '%s'", text.c_str(), index->freeform.c_str());
- if (index->regex->Matches(text))
+ if (index->regex->Matches(filter->flag_strip_color ? stripped_text : text))
{
//ServerInstance->Logs->Log("m_filter", DEBUG, "MATCH");
ImplFilter fr = *index;
diff --git a/src/modules/m_stripcolor.cpp b/src/modules/m_stripcolor.cpp
index 86f307bae..b1cc54580 100644
--- a/src/modules/m_stripcolor.cpp
+++ b/src/modules/m_stripcolor.cpp
@@ -68,33 +68,6 @@ class ModuleStripColor : public Module
ServerInstance->AddExtBanChar('S');
}
- virtual void ReplaceLine(std::string &sentence)
- {
- /* refactor this completely due to SQUIT bug since the old code would strip last char and replace with \0 --peavey */
- int seq = 0;
-
- for (std::string::iterator i = sentence.begin(); i != sentence.end();)
- {
- if (*i == 3)
- seq = 1;
- else if (seq && (( ((*i >= '0') && (*i <= '9')) || (*i == ',') ) ))
- {
- seq++;
- if ( (seq <= 4) && (*i == ',') )
- seq = 1;
- else if (seq > 3)
- seq = 0;
- }
- else
- seq = 0;
-
- if (seq || ((*i == 2) || (*i == 15) || (*i == 22) || (*i == 21) || (*i == 31)))
- i = sentence.erase(i);
- else
- ++i;
- }
- }
-
virtual ModResult OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
{
if (!IS_LOCAL(user))
@@ -119,7 +92,7 @@ class ModuleStripColor : public Module
if (active)
{
- this->ReplaceLine(text);
+ InspIRCd::StripColor(text);
}
return MOD_RES_PASSTHRU;