diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/helperfuncs.cpp | 27 | ||||
-rw-r--r-- | src/modules/m_filter.cpp | 24 | ||||
-rw-r--r-- | src/modules/m_stripcolor.cpp | 29 |
3 files changed, 48 insertions, 32 deletions
diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp index a6df520c5..3efa58bba 100644 --- a/src/helperfuncs.cpp +++ b/src/helperfuncs.cpp @@ -196,6 +196,33 @@ bool InspIRCd::IsValidMask(const std::string &mask) return true; } +void InspIRCd::StripColor(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; + } +} + /* true for valid channel name, false else */ bool IsChannelHandler::Call(const char *chname, size_t max) { 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; |