summaryrefslogtreecommitdiff
path: root/stopspam.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'stopspam.cpp')
-rwxr-xr-x[-rw-r--r--]stopspam.cpp72
1 files changed, 68 insertions, 4 deletions
diff --git a/stopspam.cpp b/stopspam.cpp
index 8ca9111..7df9a0b 100644..100755
--- a/stopspam.cpp
+++ b/stopspam.cpp
@@ -133,6 +133,7 @@ MIRANDA_HOOK_EVENT(ME_DB_EVENT_FILTER_ADD, w, l)
// if message contains right answer...
BYTE msg = 1;
+ static int math_answer = 0;
if(gbInvisDisable)
{
if(CallProtoService(dbei->szModule, PS_GETSTATUS, 0, 0) == ID_STATUS_INVISIBLE)
@@ -155,9 +156,9 @@ MIRANDA_HOOK_EVENT(ME_DB_EVENT_FILTER_ADD, w, l)
}
else
{
- std::string check(toUTF8(variables_parse(gbAnswer, hContact))), msg(toUTF8(message));
- boost::regex expr(check);
- answered = boost::regex_search(msg.begin(), msg.end(), expr);
+ std::string check(toUTF8(variables_parse(gbAnswer, hContact))), msg(toUTF8(message));
+ boost::regex expr(check);
+ answered = boost::regex_search(msg.begin(), msg.end(), expr);
}
}
if(answered)
@@ -219,7 +220,70 @@ MIRANDA_HOOK_EVENT(ME_DB_EVENT_FILTER_ADD, w, l)
tstring q;
if(gbInfTalkProtection)
q += _T("StopSpam automatic message:\r\n");
- q += variables_parse(gbQuestion, hContact);
+ if(gbMathExpression)
+ { //parse math expression in question
+ tstring tmp_question = gbQuestion;
+ std::list<int> args;
+ std::list<TCHAR> actions;
+ std::string arg;
+ tstring::size_type p1 = gbQuestion.find(_T("X")), p2 = 0;
+ const tstring expr_chars = _T("X+-/*");
+ while(expr_chars.find(gbQuestion[p1]) != tstring::npos)
+ {
+ p2 = p1;
+ for(p1 = gbQuestion.find(_T("X"), p1); p1 != tstring::npos; ++p1)
+ arg += get_random_num(1);
+#ifdef UNICODE
+ tmp_question.replace(p2, arg.size(), toUTF16(arg));
+#else
+ tmp_question.replace(p2, arg.size(), arg);
+#endif
+ args.push_back(atoi(arg.c_str()));
+ actions.push_back(gbQuestion[p1]);
+ ++p1;
+ }
+ math_answer = args.front();
+ args.pop_front();
+ while(!args.empty())
+ {
+ if(!actions.empty())
+ {
+ switch(actions.front())
+ {
+ case _T('+'):
+ {
+ math_answer += args.front();
+ args.pop_front();
+ }
+ break;
+ case _T('-'):
+ {
+ math_answer -= args.front();
+ args.pop_front();
+ }
+ break;
+ case _T('/'):
+ {
+ math_answer /= args.front();
+ args.pop_front();
+ }
+ break;
+ case _T('*'):
+ {
+ math_answer *= args.front();
+ args.pop_front();
+ }
+ break;
+ }
+ actions.pop_front();
+ }
+ else
+ break;
+ }
+ q += variables_parse(tmp_question, hContact);
+ }
+ else
+ q += variables_parse(gbQuestion, hContact);
#ifdef _UNICODE
char * buf=mir_utf8encodeW(q.c_str());