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)
{
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)
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)
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;
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;
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))
if (active)
{
- this->ReplaceLine(text);
+ InspIRCd::StripColor(text);
}
return MOD_RES_PASSTHRU;