summaryrefslogtreecommitdiff
path: root/stopspam.cpp
diff options
context:
space:
mode:
authorGluzskiy Alexandr <sss123next@list.ru>2010-04-05 19:07:46 +0300
committerGluzskiy Alexandr <sss123next@list.ru>2010-04-05 19:07:46 +0300
commit9395431a6fe57538cb6e7d9900a37e8d737bc80e (patch)
tree9dd3000c978d112560bd3643533ad5ef46d8ad05 /stopspam.cpp
parent472467fdf175d80958812fcc0023b93c8bd17e02 (diff)
dos2unix string termination
Diffstat (limited to 'stopspam.cpp')
-rw-r--r--stopspam.cpp500
1 files changed, 250 insertions, 250 deletions
diff --git a/stopspam.cpp b/stopspam.cpp
index d071a08..890d559 100644
--- a/stopspam.cpp
+++ b/stopspam.cpp
@@ -1,250 +1,250 @@
-#include "headers.h"
-
-MIRANDA_HOOK_EVENT(ME_DB_CONTACT_ADDED, w, l)
-{
- return 0;
-}
-
-
-MIRANDA_HOOK_EVENT(ME_DB_EVENT_ADDED, wParam, lParam)
-{
- HANDLE hContact = (HANDLE)wParam;
- HANDLE hDbEvent = (HANDLE)lParam;
-
- DBEVENTINFO dbei = {0};
- dbei.cbSize = sizeof(dbei);
- dbei.cbBlob = CallService(MS_DB_EVENT_GETBLOBSIZE, (WPARAM)hDbEvent, 0);
- if(-1 == dbei.cbBlob)
- return 0;
-
- dbei.pBlob = new BYTE[dbei.cbBlob];
- CallService(MS_DB_EVENT_GET, lParam, (LPARAM)&dbei);
-
- // if event is in protocol that is not despammed
- if(!ProtoInList(dbei.szModule)) {
- delete dbei.pBlob;
- return 0;
- }
-
- // event is an auth request
- if(gbHandleAuthReq)
- {
- if(!(dbei.flags & DBEF_SENT) && !(dbei.flags & DBEF_READ) && dbei.eventType == EVENTTYPE_AUTHREQUEST)
- {
- HANDLE hcntct;
- hcntct=*((PHANDLE)(dbei.pBlob+sizeof(DWORD)));
-
-
- // if request is from unknown or not marked Answered contact
-
- int a = DBGetContactSettingByte(hcntct, "CList", "NotOnList", 0);
- int b = !DBGetContactSettingByte(hcntct, pluginName, "Answered", 0);
-
- if(a && b)//
- {
- // ...send message
-
- if(gbHideContacts)
- DBWriteContactSettingByte(hcntct, "CList", "Hidden", 1);
- if(gbSpecialGroup)
- DBWriteContactSettingTString(hcntct, "CList", "Group", gbSpammersGroup.c_str());
-
- BYTE msg = 1;
- if(gbInvisDisable)
- {
- if(CallProtoService(dbei.szModule, PS_GETSTATUS, 0, 0) == ID_STATUS_INVISIBLE)
- msg = 0;
- else if(DBGetContactSettingWord(hContact,dbei.szModule,"ApparentMode",0) == ID_STATUS_OFFLINE)
- msg = 0; //is it useful ?
- }
- if(msg)
- // int a = CallService(allowService.c_str(), (WPARAM)hDbEvent, (LPARAM)(variables_parse(gbAuthRepl, hcntct).c_str()));
- CallContactService(hcntct, PSS_MESSAGE, PREF_TCHAR, (LPARAM)(variables_parse(gbAuthRepl, hcntct).c_str()));
-
- delete dbei.pBlob;
- return 1;
- }
- }
- }
- delete dbei.pBlob;
- return 0;
-}
-
-MIRANDA_HOOK_EVENT(ME_DB_EVENT_FILTER_ADD, w, l)
-{
- HANDLE hContact = (HANDLE)w;
- DBEVENTINFO * dbei = (DBEVENTINFO*)l;
-
-
- // if event is in protocol that is not despammed
- if(!ProtoInList(dbei->szModule))
- {
- // ...let the event go its way
- return 0;
- }
- //do not check excluded contact
-
- if(DBGetContactSettingByte(hContact, pluginName, "Answered", 0))
- return 0;
- if(DBGetContactSettingByte(hContact, pluginName, "Excluded", 0))
- {
- if(!DBGetContactSettingByte(hContact, "CList", "NotOnList", 0))
- DBDeleteContactSetting(hContact, pluginName, "Excluded");
- return 0;
- }
- //we want block not only messages, i seen many types other eventtype flood
- if(dbei->flags & DBEF_READ)
- // ...let the event go its way
- return 0;
- //mark contact which we trying to contact for exclude from check
- if((dbei->flags & DBEF_SENT) && DBGetContactSettingByte(hContact, "CList", "NotOnList", 0)
- && (!gbMaxQuestCount || DBGetContactSettingDword(hContact, pluginName, "QuestionCount", 0) < gbMaxQuestCount) && gbExclude)
- {
- DBWriteContactSettingByte(hContact, pluginName, "Excluded", 1);
- return 0;
- }
- // if message is from known or marked Answered contact
- if(!DBGetContactSettingByte(hContact, "CList", "NotOnList", 0))
- // ...let the event go its way
- return 0;
- // if message is corrupted or empty it cannot be an answer.
- if(!dbei->cbBlob || !dbei->pBlob)
- // reject processing of the event
- return 1;
-
- tstring message;
-
- if(dbei->flags & DBEF_UTF){
- WCHAR* msg_u;
- char* msg_a = mir_strdup(( char* )dbei->pBlob );
- mir_utf8decode( msg_a, &msg_u );
-#ifdef _UNICODE
- message = msg_u;
-#else
- message = mir_u2a(msg_u);
-#endif
- }
- else{
-#ifdef _UNICODE
- message = mir_a2u((char*)(dbei->pBlob));
-#else
- message = (char*)(dbei->pBlob);
-#endif
- }
-
- // if message contains right answer...
-
- BYTE msg = 1;
- if(gbInvisDisable)
- {
- if(CallProtoService(dbei->szModule, PS_GETSTATUS, 0, 0) == ID_STATUS_INVISIBLE)
- msg = 0;
- else if(DBGetContactSettingWord(hContact,dbei->szModule,"ApparentMode",0) == ID_STATUS_OFFLINE)
- msg = 0; //is it useful ?
- }
- if(gbCaseInsensitive?(!Stricmp(message.c_str(), (variables_parse(gbAnswer, hContact).c_str()))):( !_tcscmp(message.c_str(), (variables_parse(gbAnswer, hContact).c_str()))))
- {
- // unhide contact
- DBDeleteContactSetting(hContact, "CList", "Hidden");
-
- // mark contact as Answered
- DBWriteContactSettingByte(hContact, pluginName, "Answered", 1);
-
- //add contact permanently
- if(gbAddPermanent) //do not use this )
- DBDeleteContactSetting(hContact, "CList", "NotOnList");
-
- // send congratulation
- if(msg)
- {
-#ifdef _UNICODE
- char * buf=mir_utf8encodeW(variables_parse(gbCongratulation, hContact).c_str());
- CallContactService(hContact, PSS_MESSAGE, PREF_TCHAR, (LPARAM)buf);
- mir_free(buf);
-#else
- CallContactService(hContact, PSS_MESSAGE, 0, (LPARAM)GetCongratulation().c_str());
-#endif
- }
-
- // process the event
- return 0;
- }
-
- if(gbIgnoreURL)
- if((message.find_first_of(_T("http"),0) != std::string::npos) || (message.find_first_of(_T("www"),0) != std::string::npos) || (message.find_first_of(_T(".ru"),0) != std::string::npos) || (message.find_first_of(_T(".com"),0) != std::string::npos) || (message.find_first_of(_T(".de"),0) != std::string::npos) || (message.find_first_of(_T(".cz"),0) != std::string::npos) || (message.find_first_of(_T(".org"),0) != std::string::npos) || (message.find_first_of(_T(".net"),0) != std::string::npos) || (message.find_first_of(_T(".su"),0) != std::string::npos))
- ;
- // if message message does not contain infintite talk protection prefix
- // and question count for this contact is less then maximum
- else if(msg)
- {
- if((!gbInfTalkProtection || tstring::npos==message.find(_T("StopSpam automatic message:\r\n")))
- && (!gbMaxQuestCount || DBGetContactSettingDword(hContact, pluginName, "QuestionCount", 0) < gbMaxQuestCount))
- {
- // send question
- tstring q = _T("StopSpam automatic message:\r\n") + variables_parse(gbQuestion, hContact);
-
-#ifdef _UNICODE
- char * buf=mir_utf8encodeW(q.c_str());
- CallContactService(hContact, PSS_MESSAGE, PREF_UTF, (LPARAM)buf);
- mir_free(buf);
-#else
- CallContactService(hContact, PSS_MESSAGE, 0, (LPARAM)q.c_str());
-#endif
-
- // increment question count
- DWORD questCount = DBGetContactSettingDword(hContact, pluginName, "QuestionCount", 0);
- DBWriteContactSettingDword(hContact, pluginName, "QuestionCount", questCount + 1);
- }
- else
- {
- if (gbDosServiceExist)
- {
- if(gbDosServiceIntegration)
- {
- int i;
- i = rand()%255*13;
- CallService(MS_DOS_SERVICE, (WPARAM)hContact, (LPARAM)i);
- }
- }
- if(gbIgnoreContacts)
- {
- DBWriteContactSettingDword(hContact, "Ignore", "Mask1", 0x0000007F);
- }
- }
- }
- if(gbHideContacts)
- DBWriteContactSettingByte(hContact, "CList", "Hidden", 1);
- if(gbSpecialGroup)
- DBWriteContactSettingTString(hContact, "CList", "Group", gbSpammersGroup.c_str());
- DBWriteContactSettingByte(hContact, "CList", "NotOnList", 1);
-
- // save message from contact
- dbei->flags |= DBEF_READ;
- CallService(MS_DB_EVENT_ADD, (WPARAM)hContact, (LPARAM)dbei);
-
- // reject processing of the event
- return 1;
-}
-
-
-MIRANDA_HOOK_EVENT(ME_DB_CONTACT_SETTINGCHANGED, w, l)
-{
- HANDLE hContact = (HANDLE)w;
- DBCONTACTWRITESETTING * cws = (DBCONTACTWRITESETTING*)l;
-
- // if CList/NotOnList is being deleted then remove answeredSetting
- if(strcmp(cws->szModule, "CList"))
- return 0;
- if(strcmp(cws->szSetting, "NotOnList"))
- return 0;
- if(!cws->value.type)
- {
- DBDeleteContactSetting(hContact, pluginName, "Answered");
- DBDeleteContactSetting(hContact, pluginName, "QuestionCount");
- }
-
- return 0;
-}
-
-
-
+#include "headers.h"
+
+MIRANDA_HOOK_EVENT(ME_DB_CONTACT_ADDED, w, l)
+{
+ return 0;
+}
+
+
+MIRANDA_HOOK_EVENT(ME_DB_EVENT_ADDED, wParam, lParam)
+{
+ HANDLE hContact = (HANDLE)wParam;
+ HANDLE hDbEvent = (HANDLE)lParam;
+
+ DBEVENTINFO dbei = {0};
+ dbei.cbSize = sizeof(dbei);
+ dbei.cbBlob = CallService(MS_DB_EVENT_GETBLOBSIZE, (WPARAM)hDbEvent, 0);
+ if(-1 == dbei.cbBlob)
+ return 0;
+
+ dbei.pBlob = new BYTE[dbei.cbBlob];
+ CallService(MS_DB_EVENT_GET, lParam, (LPARAM)&dbei);
+
+ // if event is in protocol that is not despammed
+ if(!ProtoInList(dbei.szModule)) {
+ delete dbei.pBlob;
+ return 0;
+ }
+
+ // event is an auth request
+ if(gbHandleAuthReq)
+ {
+ if(!(dbei.flags & DBEF_SENT) && !(dbei.flags & DBEF_READ) && dbei.eventType == EVENTTYPE_AUTHREQUEST)
+ {
+ HANDLE hcntct;
+ hcntct=*((PHANDLE)(dbei.pBlob+sizeof(DWORD)));
+
+
+ // if request is from unknown or not marked Answered contact
+
+ int a = DBGetContactSettingByte(hcntct, "CList", "NotOnList", 0);
+ int b = !DBGetContactSettingByte(hcntct, pluginName, "Answered", 0);
+
+ if(a && b)//
+ {
+ // ...send message
+
+ if(gbHideContacts)
+ DBWriteContactSettingByte(hcntct, "CList", "Hidden", 1);
+ if(gbSpecialGroup)
+ DBWriteContactSettingTString(hcntct, "CList", "Group", gbSpammersGroup.c_str());
+
+ BYTE msg = 1;
+ if(gbInvisDisable)
+ {
+ if(CallProtoService(dbei.szModule, PS_GETSTATUS, 0, 0) == ID_STATUS_INVISIBLE)
+ msg = 0;
+ else if(DBGetContactSettingWord(hContact,dbei.szModule,"ApparentMode",0) == ID_STATUS_OFFLINE)
+ msg = 0; //is it useful ?
+ }
+ if(msg)
+ // int a = CallService(allowService.c_str(), (WPARAM)hDbEvent, (LPARAM)(variables_parse(gbAuthRepl, hcntct).c_str()));
+ CallContactService(hcntct, PSS_MESSAGE, PREF_TCHAR, (LPARAM)(variables_parse(gbAuthRepl, hcntct).c_str()));
+
+ delete dbei.pBlob;
+ return 1;
+ }
+ }
+ }
+ delete dbei.pBlob;
+ return 0;
+}
+
+MIRANDA_HOOK_EVENT(ME_DB_EVENT_FILTER_ADD, w, l)
+{
+ HANDLE hContact = (HANDLE)w;
+ DBEVENTINFO * dbei = (DBEVENTINFO*)l;
+
+
+ // if event is in protocol that is not despammed
+ if(!ProtoInList(dbei->szModule))
+ {
+ // ...let the event go its way
+ return 0;
+ }
+ //do not check excluded contact
+
+ if(DBGetContactSettingByte(hContact, pluginName, "Answered", 0))
+ return 0;
+ if(DBGetContactSettingByte(hContact, pluginName, "Excluded", 0))
+ {
+ if(!DBGetContactSettingByte(hContact, "CList", "NotOnList", 0))
+ DBDeleteContactSetting(hContact, pluginName, "Excluded");
+ return 0;
+ }
+ //we want block not only messages, i seen many types other eventtype flood
+ if(dbei->flags & DBEF_READ)
+ // ...let the event go its way
+ return 0;
+ //mark contact which we trying to contact for exclude from check
+ if((dbei->flags & DBEF_SENT) && DBGetContactSettingByte(hContact, "CList", "NotOnList", 0)
+ && (!gbMaxQuestCount || DBGetContactSettingDword(hContact, pluginName, "QuestionCount", 0) < gbMaxQuestCount) && gbExclude)
+ {
+ DBWriteContactSettingByte(hContact, pluginName, "Excluded", 1);
+ return 0;
+ }
+ // if message is from known or marked Answered contact
+ if(!DBGetContactSettingByte(hContact, "CList", "NotOnList", 0))
+ // ...let the event go its way
+ return 0;
+ // if message is corrupted or empty it cannot be an answer.
+ if(!dbei->cbBlob || !dbei->pBlob)
+ // reject processing of the event
+ return 1;
+
+ tstring message;
+
+ if(dbei->flags & DBEF_UTF){
+ WCHAR* msg_u;
+ char* msg_a = mir_strdup(( char* )dbei->pBlob );
+ mir_utf8decode( msg_a, &msg_u );
+#ifdef _UNICODE
+ message = msg_u;
+#else
+ message = mir_u2a(msg_u);
+#endif
+ }
+ else{
+#ifdef _UNICODE
+ message = mir_a2u((char*)(dbei->pBlob));
+#else
+ message = (char*)(dbei->pBlob);
+#endif
+ }
+
+ // if message contains right answer...
+
+ BYTE msg = 1;
+ if(gbInvisDisable)
+ {
+ if(CallProtoService(dbei->szModule, PS_GETSTATUS, 0, 0) == ID_STATUS_INVISIBLE)
+ msg = 0;
+ else if(DBGetContactSettingWord(hContact,dbei->szModule,"ApparentMode",0) == ID_STATUS_OFFLINE)
+ msg = 0; //is it useful ?
+ }
+ if(gbCaseInsensitive?(!Stricmp(message.c_str(), (variables_parse(gbAnswer, hContact).c_str()))):( !_tcscmp(message.c_str(), (variables_parse(gbAnswer, hContact).c_str()))))
+ {
+ // unhide contact
+ DBDeleteContactSetting(hContact, "CList", "Hidden");
+
+ // mark contact as Answered
+ DBWriteContactSettingByte(hContact, pluginName, "Answered", 1);
+
+ //add contact permanently
+ if(gbAddPermanent) //do not use this )
+ DBDeleteContactSetting(hContact, "CList", "NotOnList");
+
+ // send congratulation
+ if(msg)
+ {
+#ifdef _UNICODE
+ char * buf=mir_utf8encodeW(variables_parse(gbCongratulation, hContact).c_str());
+ CallContactService(hContact, PSS_MESSAGE, PREF_TCHAR, (LPARAM)buf);
+ mir_free(buf);
+#else
+ CallContactService(hContact, PSS_MESSAGE, 0, (LPARAM)GetCongratulation().c_str());
+#endif
+ }
+
+ // process the event
+ return 0;
+ }
+
+ if(gbIgnoreURL)
+ if((message.find_first_of(_T("http"),0) != std::string::npos) || (message.find_first_of(_T("www"),0) != std::string::npos) || (message.find_first_of(_T(".ru"),0) != std::string::npos) || (message.find_first_of(_T(".com"),0) != std::string::npos) || (message.find_first_of(_T(".de"),0) != std::string::npos) || (message.find_first_of(_T(".cz"),0) != std::string::npos) || (message.find_first_of(_T(".org"),0) != std::string::npos) || (message.find_first_of(_T(".net"),0) != std::string::npos) || (message.find_first_of(_T(".su"),0) != std::string::npos))
+ ;
+ // if message message does not contain infintite talk protection prefix
+ // and question count for this contact is less then maximum
+ else if(msg)
+ {
+ if((!gbInfTalkProtection || tstring::npos==message.find(_T("StopSpam automatic message:\r\n")))
+ && (!gbMaxQuestCount || DBGetContactSettingDword(hContact, pluginName, "QuestionCount", 0) < gbMaxQuestCount))
+ {
+ // send question
+ tstring q = _T("StopSpam automatic message:\r\n") + variables_parse(gbQuestion, hContact);
+
+#ifdef _UNICODE
+ char * buf=mir_utf8encodeW(q.c_str());
+ CallContactService(hContact, PSS_MESSAGE, PREF_UTF, (LPARAM)buf);
+ mir_free(buf);
+#else
+ CallContactService(hContact, PSS_MESSAGE, 0, (LPARAM)q.c_str());
+#endif
+
+ // increment question count
+ DWORD questCount = DBGetContactSettingDword(hContact, pluginName, "QuestionCount", 0);
+ DBWriteContactSettingDword(hContact, pluginName, "QuestionCount", questCount + 1);
+ }
+ else
+ {
+ if (gbDosServiceExist)
+ {
+ if(gbDosServiceIntegration)
+ {
+ int i;
+ i = rand()%255*13;
+ CallService(MS_DOS_SERVICE, (WPARAM)hContact, (LPARAM)i);
+ }
+ }
+ if(gbIgnoreContacts)
+ {
+ DBWriteContactSettingDword(hContact, "Ignore", "Mask1", 0x0000007F);
+ }
+ }
+ }
+ if(gbHideContacts)
+ DBWriteContactSettingByte(hContact, "CList", "Hidden", 1);
+ if(gbSpecialGroup)
+ DBWriteContactSettingTString(hContact, "CList", "Group", gbSpammersGroup.c_str());
+ DBWriteContactSettingByte(hContact, "CList", "NotOnList", 1);
+
+ // save message from contact
+ dbei->flags |= DBEF_READ;
+ CallService(MS_DB_EVENT_ADD, (WPARAM)hContact, (LPARAM)dbei);
+
+ // reject processing of the event
+ return 1;
+}
+
+
+MIRANDA_HOOK_EVENT(ME_DB_CONTACT_SETTINGCHANGED, w, l)
+{
+ HANDLE hContact = (HANDLE)w;
+ DBCONTACTWRITESETTING * cws = (DBCONTACTWRITESETTING*)l;
+
+ // if CList/NotOnList is being deleted then remove answeredSetting
+ if(strcmp(cws->szModule, "CList"))
+ return 0;
+ if(strcmp(cws->szSetting, "NotOnList"))
+ return 0;
+ if(!cws->value.type)
+ {
+ DBDeleteContactSetting(hContact, pluginName, "Answered");
+ DBDeleteContactSetting(hContact, pluginName, "QuestionCount");
+ }
+
+ return 0;
+}
+
+
+