diff options
-rw-r--r-- | plugins/ExternalAPI/m_stopspam.h | 35 | ||||
-rw-r--r-- | plugins/StopSpamMod/src/init.cpp | 20 | ||||
-rw-r--r-- | plugins/StopSpamMod/src/options.cpp | 48 | ||||
-rw-r--r-- | plugins/StopSpamMod/src/stopspam.cpp | 24 | ||||
-rw-r--r-- | plugins/StopSpamMod/src/utilities.cpp | 28 | ||||
-rw-r--r-- | plugins/StopSpamPlus/src/events.cpp | 83 | ||||
-rw-r--r-- | plugins/StopSpamPlus/src/options.cpp | 12 | ||||
-rw-r--r-- | plugins/StopSpamPlus/src/services.cpp | 7 | ||||
-rw-r--r-- | plugins/StopSpamPlus/src/stdafx.h | 16 | ||||
-rw-r--r-- | plugins/StopSpamPlus/src/stopspam.cpp | 4 | ||||
-rw-r--r-- | plugins/StopSpamPlus/src/utils.cpp | 34 | ||||
-rw-r--r-- | plugins/StopSpamPlus/stopspam.vcxproj | 1 | ||||
-rw-r--r-- | plugins/StopSpamPlus/stopspam.vcxproj.filters | 3 |
13 files changed, 114 insertions, 201 deletions
diff --git a/plugins/ExternalAPI/m_stopspam.h b/plugins/ExternalAPI/m_stopspam.h deleted file mode 100644 index 692630eaaa..0000000000 --- a/plugins/ExternalAPI/m_stopspam.h +++ /dev/null @@ -1,35 +0,0 @@ -/*
-
-Miranda NG: the free IM client for Microsoft* Windows*
-
-Copyright (C) 2012-23 Miranda NG team (https://miranda-ng.org),
-Copyright (c) 2004-009 Roman Miklashevsky, A. Petkevich, Kosh&chka, persei
-
-This program is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation; either version 2
-of the License, or (at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
-
-#ifndef M_STOPSPAM_H__
-#define M_STOPSPAM_H__
-
-#define CS_NOTPASSED 0
-#define CS_PASSED 1
-
-//check is contact pass the stopspam
-//wParam=(HANDLE)hContact
-//lParam=0
-//returns a "Contact Stae" flag
-#define MS_STOPSPAM_CONTACTPASSED "StopSpam/IsContactPassed"
-
-#endif
\ No newline at end of file diff --git a/plugins/StopSpamMod/src/init.cpp b/plugins/StopSpamMod/src/init.cpp index c989aae78f..91e926469d 100644 --- a/plugins/StopSpamMod/src/init.cpp +++ b/plugins/StopSpamMod/src/init.cpp @@ -38,23 +38,23 @@ BOOL gbCaseInsensitive = 0; BOOL gbRegexMatch = 0;
BOOL gbInvisDisable = 0;
BOOL gbIgnoreURL = 1;
-BOOL gbLogToFile=0;
-BOOL gbAutoAuth=0;
-BOOL gbAutoAddToServerList=0;
-BOOL gbAutoReqAuth=1;
+BOOL gbLogToFile = 0;
+BOOL gbAutoAuth = 0;
+BOOL gbAutoAddToServerList = 0;
+BOOL gbAutoReqAuth = 1;
BOOL gbMathExpression = 0;
HANDLE hStopSpamLogDirH = nullptr;
wstring gbSpammersGroup = L"Spammers";
-wstring gbAutoAuthGroup = L"NotSpammers";
+wstring gbAutoAuthGroup = L"NotSpammers";
wstring gbQuestion;
wstring gbAnswer;
wstring gbCongratulation;
std::wstring gbAuthRepl;
extern const wchar_t *defQuestion, *defCongrats, *defAuthReply;
-extern int RemoveTmp(WPARAM,LPARAM);
+extern int RemoveTmp(WPARAM, LPARAM);
/////////////////////////////////////////////////////////////////////////////////////////
// returns plugin's extended information
@@ -69,7 +69,7 @@ PLUGININFOEX pluginInfoEx = { __AUTHORWEB,
UNICODE_AWARE,
// {94CED94C-A94A-4BB1-ACBD-5CC6EBB689D4}
- {0x94ced94c, 0xa94a, 0x4bb1, {0xac, 0xbd, 0x5c, 0xc6, 0xeb, 0xb6, 0x89, 0xd4}}
+ { 0x94ced94c, 0xa94a, 0x4bb1, { 0xac, 0xbd, 0x5c, 0xc6, 0xeb, 0xb6, 0x89, 0xd4 } }
};
CMPlugin::CMPlugin() :
@@ -78,7 +78,7 @@ CMPlugin::CMPlugin() : /////////////////////////////////////////////////////////////////////////////////////////
-extern wstring DBGetContactSettingStringPAN(MCONTACT hContact, char const * szModule, char const * szSetting, wstring errorValue);
+extern wstring DBGetContactSettingStringPAN(MCONTACT hContact, char const *szModule, char const *szSetting, wstring errorValue);
void InitVars()
{
@@ -116,9 +116,9 @@ static int OnSystemModulesLoaded(WPARAM, LPARAM) gbVarsServiceExist = TRUE;
InitVars();
- if(gbDelExcluded)
+ if (gbDelExcluded)
mir_forkthread(&CleanThread);
-
+
// Folders plugin support
hStopSpamLogDirH = FoldersRegisterCustomPathW(LPGEN("StopSpam"), LPGEN("StopSpam Logs"), FOLDER_LOGS);
return 0;
diff --git a/plugins/StopSpamMod/src/options.cpp b/plugins/StopSpamMod/src/options.cpp index c610a4aa24..1958598f63 100644 --- a/plugins/StopSpamMod/src/options.cpp +++ b/plugins/StopSpamMod/src/options.cpp @@ -25,13 +25,16 @@ const wchar_t *defAuthReply = LPGENW("StopSpam: send a message and reply to an a class COptMainDlg : public CDlgBase
{
+ CCtrlCheck chk_INFTALKPROT, chk_ADDPERMANENT, chk_HANDLEAUTHREQ, chk_HIDECONTACTS, chk_IGNORESPAMMERS, chk_LOGSPAMTOFILE;
+ CCtrlData ctrl_DESCRIPTION;
+ CCtrlSpin edit_MAXQUESTCOUNT;
+
public:
COptMainDlg() : CDlgBase(g_plugin, IDD_MAIN),
chk_INFTALKPROT(this, ID_INFTALKPROT), chk_ADDPERMANENT(this, ID_ADDPERMANENT), chk_HANDLEAUTHREQ(this, ID_HANDLEAUTHREQ),
chk_HIDECONTACTS(this, ID_HIDECONTACTS), chk_IGNORESPAMMERS(this, ID_IGNORESPAMMERS), chk_LOGSPAMTOFILE(this, ID_LOGSPAMTOFILE),
ctrl_DESCRIPTION(this, ID_DESCRIPTION), edit_MAXQUESTCOUNT(this, ID_MAXQUESTCOUNT)
- {
- }
+ {}
bool OnInitDialog() override
{
@@ -57,15 +60,13 @@ public: g_plugin.setByte("LogSpamToFile", gbLogToFile = chk_LOGSPAMTOFILE.GetState());
return true;
}
-
-private:
- CCtrlCheck chk_INFTALKPROT, chk_ADDPERMANENT, chk_HANDLEAUTHREQ, chk_HIDECONTACTS, chk_IGNORESPAMMERS, chk_LOGSPAMTOFILE;
- CCtrlData ctrl_DESCRIPTION;
- CCtrlSpin edit_MAXQUESTCOUNT;
};
class COptMessagesDlg : public CDlgBase
{
+ CCtrlEdit edit_QUESTION, edit_ANSWER, edit_CONGRATULATION, edit_AUTHREPL;
+ CCtrlButton btn_RESTOREDEFAULTS, btn_VARS;
+
public:
COptMessagesDlg() : CDlgBase(g_plugin, IDD_MESSAGES),
edit_QUESTION(this, ID_QUESTION), edit_ANSWER(this, ID_ANSWER), edit_CONGRATULATION(this, ID_CONGRATULATION), edit_AUTHREPL(this, ID_AUTHREPL),
@@ -102,25 +103,24 @@ public: return true;
}
- void onClick_RESTOREDEFAULTS(CCtrlButton*)
+ void onClick_RESTOREDEFAULTS(CCtrlButton *)
{
edit_QUESTION.SetText(TranslateW(defQuestion));
edit_ANSWER.SetText(L"nospam");
edit_AUTHREPL.SetText(TranslateW(defAuthReply));
edit_CONGRATULATION.SetText(TranslateW(defCongrats));
}
- void onClick_VARS(CCtrlButton*)
+ void onClick_VARS(CCtrlButton *)
{
variables_showhelp(m_hwnd, WM_COMMAND, VHF_FULLDLG | VHF_SETLASTSUBJECT, nullptr, nullptr);
}
-private:
- CCtrlEdit edit_QUESTION, edit_ANSWER, edit_CONGRATULATION, edit_AUTHREPL;
- CCtrlButton btn_RESTOREDEFAULTS, btn_VARS;
-
};
class COptProtoDlg : public CDlgBase
{
+ CCtrlListBox list_USEDPROTO, list_ALLPROTO;
+ CCtrlButton btn_ADD, btn_REMOVE, btn_ADDALL, btn_REMOVEALL;
+
public:
COptProtoDlg() : CDlgBase(g_plugin, IDD_PROTO),
list_USEDPROTO(this, ID_USEDPROTO), list_ALLPROTO(this, ID_ALLPROTO),
@@ -131,7 +131,7 @@ public: btn_ADDALL.OnClick = Callback(this, &COptProtoDlg::onClick_ADDALL);
btn_REMOVEALL.OnClick = Callback(this, &COptProtoDlg::onClick_REMOVEALL);
}
-
+
bool OnInitDialog() override
{
for (auto &pa : Accounts()) {
@@ -141,10 +141,9 @@ public: }
return true;
}
-
+
bool OnApply() override
{
-
LRESULT count = list_USEDPROTO.GetCount();
std::ostringstream out;
for (int i = 0; i < count; ++i) {
@@ -156,19 +155,21 @@ public: return true;
}
- void onClick_ADD(CCtrlButton*)
+ void onClick_ADD(CCtrlButton *)
{
list_USEDPROTO.AddString(list_ALLPROTO.GetItemText(list_ALLPROTO.GetCurSel()));
list_ALLPROTO.DeleteString(list_ALLPROTO.GetCurSel());
this->NotifyChange();
}
- void onClick_REMOVE(CCtrlButton*)
+
+ void onClick_REMOVE(CCtrlButton *)
{
list_ALLPROTO.AddString(list_USEDPROTO.GetItemText(list_USEDPROTO.GetCurSel()));
list_USEDPROTO.DeleteString(list_USEDPROTO.GetCurSel());
this->NotifyChange();
}
- void onClick_ADDALL(CCtrlButton*)
+
+ void onClick_ADDALL(CCtrlButton *)
{
for (;;) {
int count = list_ALLPROTO.GetCount();
@@ -179,7 +180,8 @@ public: }
this->NotifyChange();
}
- void onClick_REMOVEALL(CCtrlButton*)
+
+ void onClick_REMOVEALL(CCtrlButton *)
{
for (;;) {
int count = list_USEDPROTO.GetCount();
@@ -190,10 +192,6 @@ public: }
this->NotifyChange();
}
-private:
- CCtrlListBox list_USEDPROTO, list_ALLPROTO;
- CCtrlButton btn_ADD, btn_REMOVE, btn_ADDALL, btn_REMOVEALL;
-
};
class COptAdvancedDlg : public CDlgBase
@@ -282,7 +280,7 @@ public: return true;
}
- void onClick_MATH_DETAILS(CCtrlButton*)
+ void onClick_MATH_DETAILS(CCtrlButton *)
{
MessageBox(m_hwnd, TranslateT("If math expression is turned on, you can use following expression in message text:\nXX+XX-X/X*X\neach X will be replaced by one random number and answer will be expression result.\nMessage must contain only one expression without spaces."), TranslateT("Info"), MB_OK);
}
diff --git a/plugins/StopSpamMod/src/stopspam.cpp b/plugins/StopSpamMod/src/stopspam.cpp index ae9e4bcb9e..ec80f97f3b 100644 --- a/plugins/StopSpamMod/src/stopspam.cpp +++ b/plugins/StopSpamMod/src/stopspam.cpp @@ -70,7 +70,7 @@ int OnDbEventFilterAdd(WPARAM hContact, LPARAM l) return 0; // if event is in protocol that is not despammed - DBEVENTINFO * dbei = (DBEVENTINFO*)l; + DBEVENTINFO *dbei = (DBEVENTINFO *)l; if (!ProtoInList(dbei->szModule)) return 0; // ...let the event go its way @@ -87,18 +87,18 @@ int OnDbEventFilterAdd(WPARAM hContact, LPARAM l) // we want block not only messages, i seen many types other eventtype flood if (dbei->flags & DBEF_READ) return 0; // ...let the event go its way - + // mark contact which we trying to contact for exclude from check if ((dbei->flags & DBEF_SENT) && !Contact::OnList(hContact) && (!gbMaxQuestCount || g_plugin.getDword(hContact, "QuestionCount") < gbMaxQuestCount) && gbExclude) { g_plugin.setByte(hContact, "Excluded", 1); return 0; } - + // if message is from known or marked Answered contact if (Contact::OnList(hContact)) return 0; // ...let the event go its way - + // if message is corrupted or empty it cannot be an answer. if (!dbei->cbBlob || !dbei->pBlob) // reject processing of the event @@ -106,9 +106,9 @@ int OnDbEventFilterAdd(WPARAM hContact, LPARAM l) wstring message; if (dbei->flags & DBEF_UTF) - message = ptrW(mir_utf8decodeW((char*)dbei->pBlob)); + message = ptrW(mir_utf8decodeW((char *)dbei->pBlob)); else - message = _A2T((char*)(dbei->pBlob)); + message = _A2T((char *)(dbei->pBlob)); // if message contains right answer... @@ -147,7 +147,7 @@ int OnDbEventFilterAdd(WPARAM hContact, LPARAM l) answered = boost::regex_search(msg.begin(), msg.end(), expr); } } - + if (answered) { // unhide contact Contact::Hide(hContact, false); @@ -166,7 +166,7 @@ int OnDbEventFilterAdd(WPARAM hContact, LPARAM l) wstring prot = DBGetContactSettingStringPAN(NULL, dbei->szModule, "AM_BaseProto", L""); // for notICQ protocols or disable auto auth. request if ((Stricmp(L"ICQ", prot.c_str())) || (!gbAutoReqAuth)) { - char * buf = mir_utf8encodeW(variables_parse(gbCongratulation, hContact).c_str()); + char *buf = mir_utf8encodeW(variables_parse(gbCongratulation, hContact).c_str()); ProtoChainSend(hContact, PSS_MESSAGE, 0, (LPARAM)buf); mir_free(buf); } @@ -180,7 +180,7 @@ int OnDbEventFilterAdd(WPARAM hContact, LPARAM l) Clist_SetGroup(hContact, gbAutoAuthGroup.c_str()); Contact::PutOnList(hContact); } - + // auto auth. request with send congratulation if (gbAutoReqAuth) ProtoChainSend(hContact, PSS_AUTHREQUEST, 0, (LPARAM)variables_parse(gbCongratulation, hContact).c_str()); @@ -199,7 +199,7 @@ int OnDbEventFilterAdd(WPARAM hContact, LPARAM l) wstring q; if (gbInfTalkProtection) q += L"StopSpam automatic message:\r\n"; - + if (gbMathExpression) { //parse math expression in question wstring tmp_question = gbQuestion; std::list<int> args; @@ -219,7 +219,7 @@ int OnDbEventFilterAdd(WPARAM hContact, LPARAM l) actions.push_back(gbQuestion[p1]); ++p1; } - + int math_answer = 0; math_answer = args.front(); args.pop_front(); @@ -282,7 +282,7 @@ int OnDbEventFilterAdd(WPARAM hContact, LPARAM l) int OnDbContactSettingChanged(WPARAM w, LPARAM l) { MCONTACT hContact = (MCONTACT)w; - DBCONTACTWRITESETTING * cws = (DBCONTACTWRITESETTING*)l; + auto *cws = (DBCONTACTWRITESETTING *)l; // if CList/NotOnList is being deleted then remove answeredSetting if (strcmp(cws->szModule, "CList")) diff --git a/plugins/StopSpamMod/src/utilities.cpp b/plugins/StopSpamMod/src/utilities.cpp index da3e855812..b7aac4ddb4 100644 --- a/plugins/StopSpamMod/src/utilities.cpp +++ b/plugins/StopSpamMod/src/utilities.cpp @@ -17,18 +17,18 @@ #include "stdafx.h"
-wstring DBGetContactSettingStringPAN(MCONTACT hContact, char const * szModule, char const * szSetting, wstring errorValue)
+wstring DBGetContactSettingStringPAN(MCONTACT hContact, char const *szModule, char const *szSetting, wstring errorValue)
{
DBVARIANT dbv;
- if (db_get_ws(hContact, szModule, szSetting, &dbv))
+ if (db_get_ws(hContact, szModule, szSetting, &dbv))
return errorValue;
-
+
errorValue = dbv.pwszVal;
db_free(&dbv);
return errorValue;
}
-std::string DBGetContactSettingStringPAN_A(MCONTACT hContact, char const * szModule, char const * szSetting, std::string errorValue)
+std::string DBGetContactSettingStringPAN_A(MCONTACT hContact, char const *szModule, char const *szSetting, std::string errorValue)
{
DBVARIANT dbv;
if (db_get_s(hContact, szModule, szSetting, &dbv))
@@ -39,11 +39,11 @@ std::string DBGetContactSettingStringPAN_A(MCONTACT hContact, char const * szMod return errorValue;
}
-wstring& GetDlgItemString(HWND hwnd, int id)
+wstring &GetDlgItemString(HWND hwnd, int id)
{
HWND h = GetDlgItem(hwnd, id);
int len = GetWindowTextLength(h);
- wchar_t * buf = new wchar_t[len + 1];
+ wchar_t *buf = new wchar_t[len + 1];
GetWindowText(h, buf, len + 1);
static wstring s;
s = buf;
@@ -65,7 +65,7 @@ bool ProtoInList(const char *szProto) return std::string::npos != GetProtoList().find(std::string(szProto) + "\r\n");
}
-void DeleteCListGroupsByName(wchar_t* szGroupName)
+void DeleteCListGroupsByName(wchar_t *szGroupName)
{
uint8_t ConfirmDelete = Clist::ConfirmDelete;
if (ConfirmDelete)
@@ -94,7 +94,7 @@ wstring variables_parse(wstring const &tstrFormat, MCONTACT hContact) fi.szFormat.w = wcsdup(tstrFormat.c_str());
fi.hContact = hContact;
fi.flags = FIF_UNICODE;
- wchar_t *tszParsed = (wchar_t*)CallService(MS_VARS_FORMATSTRING, (WPARAM)&fi, 0);
+ wchar_t *tszParsed = (wchar_t *)CallService(MS_VARS_FORMATSTRING, (WPARAM)&fi, 0);
free(fi.szFormat.w);
if (tszParsed) {
@@ -194,7 +194,7 @@ void LogSpamToFile(MCONTACT hContact, wstring message) // Name, UID and Protocol Log line
LogProtocol = DBGetContactSettingStringPAN(hContact, "Protocol", "p", L"");
- LogContactName = (wchar_t*)Clist_GetContactDisplayName(hContact);
+ LogContactName = (wchar_t *)Clist_GetContactDisplayName(hContact);
LogContactId = (LogProtocol == L"") ? L"" : GetContactUid(hContact, LogProtocol);
// Name, UID and Protocol Log line
@@ -215,7 +215,7 @@ mir_cs clean_mutex; void __cdecl CleanProtocolExclThread(void *param)
{
- const char *szProto = (const char*)param;
+ const char *szProto = (const char *)param;
while (true) {
int status = Proto_GetStatus(szProto);
@@ -242,7 +242,7 @@ void __cdecl CleanProtocolExclThread(void *param) mir_free(param);
}
-void __cdecl CleanThread(void*)
+void __cdecl CleanThread(void *)
{
std::list<std::string> protocols;
for (auto &pa : Accounts())
@@ -262,7 +262,7 @@ void HistoryLog(MCONTACT hContact, char *data, int event_type, int flags) Event.flags = flags | DBEF_UTF;
Event.timestamp = (uint32_t)time(0);
Event.cbBlob = (uint32_t)mir_strlen(data) + 1;
- Event.pBlob = (uint8_t*)_strdup(data);
+ Event.pBlob = (uint8_t *)_strdup(data);
db_event_add(hContact, &Event);
}
@@ -277,7 +277,7 @@ void HistoryLogFunc(MCONTACT hContact, std::string message) msg.append("Protocol: ").append(Proto_GetBaseAccountName(hContact)).append(" Contact: ");
msg.append(toUTF8(Clist_GetContactDisplayName(hContact))).append(" ID: ");
msg.append(toUTF8(GetContactUid(hContact, toUTF16(Proto_GetBaseAccountName(hContact)))));
- HistoryLog(NULL, (char*)msg.c_str(), EVENTTYPE_MESSAGE, DBEF_READ);
+ HistoryLog(NULL, (char *)msg.c_str(), EVENTTYPE_MESSAGE, DBEF_READ);
}
}
@@ -301,7 +301,7 @@ std::string get_random_num(int length) std::string chars("123456789");
std::string data;
boost::random_device rng;
- boost::variate_generator<boost::random_device&, boost::uniform_int<>> gen(rng, boost::uniform_int<>(0, (int)chars.length() - 1));
+ boost::variate_generator<boost::random_device &, boost::uniform_int<>> gen(rng, boost::uniform_int<>(0, (int)chars.length() - 1));
for (int i = 0; i < length; ++i)
data += chars[gen()];
return data;
diff --git a/plugins/StopSpamPlus/src/events.cpp b/plugins/StopSpamPlus/src/events.cpp index fcea573c55..de5a5cfad9 100644 --- a/plugins/StopSpamPlus/src/events.cpp +++ b/plugins/StopSpamPlus/src/events.cpp @@ -14,22 +14,20 @@ int OnDbEventAdded(WPARAM, LPARAM lParam) // event is an auth request
if (!(dbei.flags & DBEF_SENT) && !(dbei.flags & DBEF_READ) && dbei.eventType == EVENTTYPE_AUTHREQUEST) {
- MCONTACT hcntct = DbGetAuthEventContact(&dbei);
+ MCONTACT hContact = DbGetAuthEventContact(&dbei);
// if request is from unknown or not marked Answered contact
//and if I don't sent message to this contact
- if (!Contact::OnList(hcntct) && !g_plugin.getByte(hcntct, DB_KEY_ANSWERED) && !IsExistMyMessage(hcntct)) {
+ if (!Contact::OnList(hContact) && !g_plugin.getByte(hContact, DB_KEY_ANSWERED) && !g_plugin.getByte(hContact, DB_KEY_HASSENT)) {
if (!g_plugin.HandleAuthReq) {
- char *buf = mir_utf8encodeW(variables_parse(g_plugin.getReply(), hcntct).c_str());
- ProtoChainSend(hcntct, PSS_MESSAGE, 0, (LPARAM)buf);
+ char *buf = mir_utf8encodeW(variables_parse(g_plugin.getReply(), hContact).c_str());
+ ProtoChainSend(hContact, PSS_MESSAGE, 0, (LPARAM)buf);
mir_free(buf);
}
- // ...send message
- CallProtoService(dbei.szModule, PS_AUTHDENY, hDbEvent, (LPARAM)_T2A(variables_parse(g_plugin.getReply(), hcntct).c_str()));
-
- Contact::RemoveFromList(hcntct);
- Contact::Hide(hcntct);
+ g_plugin.setDword(hContact, DB_KEY_HASAUTH, hDbEvent);
+ Contact::RemoveFromList(hContact);
+ Contact::Hide(hContact);
if (!g_plugin.HistLog)
db_event_delete(hDbEvent);
return 1;
@@ -41,32 +39,29 @@ int OnDbEventAdded(WPARAM, LPARAM lParam) int OnDbEventFilterAdd(WPARAM w, LPARAM l)
{
MCONTACT hContact = (MCONTACT)w;
- DBEVENTINFO *dbei = (DBEVENTINFO*)l;
+ DBEVENTINFO *dbei = (DBEVENTINFO *)l;
if (dbei == nullptr || dbei->szModule == nullptr) //fix potential DEP crash
return 0;
// if event is in protocol that is not despammed
if (g_plugin.ProtoDisabled(dbei->szModule))
- // ...let the event go its way
- return 0;
+ return 0; // ...let the event go its way
// if event is not a message, or if the message has been read or sent...
- if (dbei->flags & DBEF_SENT || dbei->flags & DBEF_READ || dbei->eventType != EVENTTYPE_MESSAGE)
- // ...let the event go its way
+ if (dbei->eventType != EVENTTYPE_MESSAGE || (dbei->flags & DBEF_READ) != 0)
return 0;
- // if message is from known or marked Answered contact
- if (g_plugin.getByte(hContact, DB_KEY_ANSWERED))
- // ...let the event go its way
+ if (dbei->flags & DBEF_SENT) {
+ g_plugin.setByte(hContact, DB_KEY_HASSENT, 1);
return 0;
+ }
- // checking if message from self-added contact
- //Contact in Not in list icq group
- if (Contact::OnList(hContact) && db_get_w(hContact, dbei->szModule, "SrvGroupId", -1) != 1)
+ // if message is from known or marked Answered contact
+ if (g_plugin.getByte(hContact, DB_KEY_ANSWERED) || g_plugin.getByte(hContact, DB_KEY_HASSENT))
return 0;
- //if I sent message to this contact
- if (IsExistMyMessage(hContact))
+ // checking if message from self-added contact
+ if (Contact::OnList(hContact))
return 0;
// if message is corrupted or empty it cannot be an answer.
@@ -77,12 +72,12 @@ int OnDbEventFilterAdd(WPARAM w, LPARAM l) tstring message;
if (dbei->flags & DBEF_UTF) {
- wchar_t* msg_u = mir_utf8decodeW((char*)dbei->pBlob);
+ wchar_t *msg_u = mir_utf8decodeW((char *)dbei->pBlob);
message = msg_u;
mir_free(msg_u);
}
else {
- wchar_t* msg_u = mir_a2u((char*)(dbei->pBlob));
+ wchar_t *msg_u = mir_a2u((char *)(dbei->pBlob));
message = msg_u;
mir_free(msg_u);
}
@@ -102,16 +97,15 @@ int OnDbEventFilterAdd(WPARAM w, LPARAM l) // unhide contact
Contact::Hide(hContact, false);
- // mark contact as Answered
- g_plugin.setByte(hContact, DB_KEY_ANSWERED, 1);
-
- //add contact permanently
- if (g_plugin.AddPermanent)
+ // add contact permanently and delete our temporary variables
+ if (g_plugin.AddPermanent) {
Contact::PutOnList(hContact);
+ db_delete_module(hContact, MODULENAME);
+ }
+ else g_plugin.setByte(hContact, DB_KEY_ANSWERED, 1);
// send congratulation
-
- char * buf = mir_utf8encodeW(variables_parse(g_plugin.getCongrats(), hContact).c_str());
+ char *buf = mir_utf8encodeW(variables_parse(g_plugin.getCongrats(), hContact).c_str());
ProtoChainSend(hContact, PSS_MESSAGE, 0, (LPARAM)buf);
mir_free(buf);
@@ -129,12 +123,10 @@ int OnDbEventFilterAdd(WPARAM w, LPARAM l) // send question
tstring q = pwszPrefix + variables_parse(g_plugin.getQuestion(), hContact);
-
- char * buf = mir_utf8encodeW(q.c_str());
+ char *buf = mir_utf8encodeW(q.c_str());
ProtoChainSend(hContact, PSS_MESSAGE, 0, (LPARAM)buf);
mir_free(buf);
-
// increment question count
uint32_t questCount = g_plugin.getDword(hContact, DB_KEY_QUESTCOUNT);
g_plugin.setDword(hContact, DB_KEY_QUESTCOUNT, questCount + 1);
@@ -149,20 +141,17 @@ int OnDbEventFilterAdd(WPARAM w, LPARAM l) return 0;
}
-int OnDbContactSettingchanged(WPARAM hContact, LPARAM l)
+int OnShutdown(WPARAM, LPARAM)
{
- DBCONTACTWRITESETTING *cws = (DBCONTACTWRITESETTING*)l;
+ for (auto &cc : Contacts()) {
+ if (Contact::OnList(cc))
+ continue;
- // if CList/NotOnList is being deleted then remove DB_KEY_ANSWERED
- if (strcmp(cws->szModule, "CList"))
- return 0;
- if (strcmp(cws->szSetting, "NotOnList"))
- return 0;
-
- if (!cws->value.type) {
- g_plugin.delSetting(hContact, DB_KEY_ANSWERED);
- g_plugin.delSetting(hContact, DB_KEY_QUESTCOUNT);
+ if (MEVENT hDbEvent = g_plugin.getByte(cc, DB_KEY_HASAUTH)) {
+ char *szProto = Proto_GetBaseAccountName(cc);
+ CallProtoService(szProto, PS_AUTHDENY, hDbEvent, (LPARAM)_T2A(variables_parse(g_plugin.getReply(), cc).c_str()));
+ }
}
-
+
return 0;
-}
+}
\ No newline at end of file diff --git a/plugins/StopSpamPlus/src/options.cpp b/plugins/StopSpamPlus/src/options.cpp index 2d55ef9309..99981028c7 100644 --- a/plugins/StopSpamPlus/src/options.cpp +++ b/plugins/StopSpamPlus/src/options.cpp @@ -73,12 +73,12 @@ public: return true;
}
- void onHelp(CCtrlButton*)
+ void onHelp(CCtrlButton *)
{
variables_showhelp(m_hwnd, WM_COMMAND, VHF_FULLDLG | VHF_SETLASTSUBJECT, nullptr, nullptr);
}
- void onRestore(CCtrlButton*)
+ void onRestore(CCtrlButton *)
{
g_plugin.delSetting(g_plugin.AuthRepl.GetDBSettingName());
g_plugin.delSetting(g_plugin.Question.GetDBSettingName());
@@ -89,7 +89,7 @@ public: edtCongrat.SetText(g_plugin.getCongrats());
edtReply.SetText(g_plugin.getReply());
edtDivider.SetText(g_plugin.AnswSplitString.Default());
-
+
NotifyChange();
}
};
@@ -148,14 +148,14 @@ public: continue;
if (m_accounts.GetCheckState(i) == 0)
- out << (char*)item.lParam << " ";
+ out << (char *)item.lParam << " ";
}
- g_plugin.DisabledProtoList = (char*)out.str().c_str();
+ g_plugin.DisabledProtoList = (char *)out.str().c_str();
return true;
}
- void list_OnItemChanged(CCtrlListView::TEventInfo*)
+ void list_OnItemChanged(CCtrlListView::TEventInfo *)
{
if (m_bInitialized)
NotifyChange();
diff --git a/plugins/StopSpamPlus/src/services.cpp b/plugins/StopSpamPlus/src/services.cpp index ed57888afb..1c3435988b 100644 --- a/plugins/StopSpamPlus/src/services.cpp +++ b/plugins/StopSpamPlus/src/services.cpp @@ -9,13 +9,10 @@ INT_PTR IsContactPassed(WPARAM hContact, LPARAM /*lParam*/) if (!g_plugin.ProtoDisabled(szProto))
return CS_PASSED;
- if (g_plugin.getByte(hContact, DB_KEY_ANSWERED))
+ if (g_plugin.getByte(hContact, DB_KEY_ANSWERED) || g_plugin.getByte(hContact, DB_KEY_HASSENT))
return CS_PASSED;
- if (Contact::OnList(hContact) && db_get_w(hContact, szProto, "SrvGroupId", -1) != 1)
- return CS_PASSED;
-
- if (IsExistMyMessage(hContact))
+ if (Contact::OnList(hContact))
return CS_PASSED;
return CS_NOTPASSED;
diff --git a/plugins/StopSpamPlus/src/stdafx.h b/plugins/StopSpamPlus/src/stdafx.h index 84916a972f..75840d2c03 100644 --- a/plugins/StopSpamPlus/src/stdafx.h +++ b/plugins/StopSpamPlus/src/stdafx.h @@ -20,7 +20,6 @@ #include <m_clistint.h>
#include <m_gui.h>
-#include <m_stopspam.h>
#include <m_variables.h>
typedef std::wstring tstring;
@@ -32,6 +31,8 @@ typedef std::wstring tstring; #define MODULENAME LPGEN("StopSpam")
#define DB_KEY_ANSWERED "Answered"
+#define DB_KEY_HASAUTH "HasAuth"
+#define DB_KEY_HASSENT "HasSent"
#define DB_KEY_QUESTCOUNT "QuestionCount"
struct CMPlugin : public PLUGIN<CMPlugin>
@@ -57,14 +58,13 @@ struct CMPlugin : public PLUGIN<CMPlugin> };
// utils
-tstring &GetDlgItemString(HWND hwnd, int id);
-bool IsExistMyMessage(MCONTACT hContact);
tstring variables_parse(const wchar_t *tstrFormat, MCONTACT hContact);
tstring trim(tstring const &tstr, tstring const &trimChars = L" \f\n\r\t\v");
-INT_PTR IsContactPassed(WPARAM wParam, LPARAM /*lParam*/);
-int OnDbEventAdded(WPARAM wParam, LPARAM lParam);
-int OnDbEventFilterAdd(WPARAM w, LPARAM l);
-int OnOptInit(WPARAM w, LPARAM l);
-int OnDbContactSettingchanged(WPARAM hContact, LPARAM l);
+INT_PTR IsContactPassed(WPARAM, LPARAM);
+int OnDbEventAdded(WPARAM, LPARAM);
+int OnDbEventFilterAdd(WPARAM, LPARAM);
+int OnOptInit(WPARAM, LPARAM);
+int OnShutdown(WPARAM, LPARAM);
+
#endif
diff --git a/plugins/StopSpamPlus/src/stopspam.cpp b/plugins/StopSpamPlus/src/stopspam.cpp index c042e4fd4c..81de4f5c53 100644 --- a/plugins/StopSpamPlus/src/stopspam.cpp +++ b/plugins/StopSpamPlus/src/stopspam.cpp @@ -38,11 +38,9 @@ CMPlugin::CMPlugin() : int CMPlugin::Load()
{
- CreateServiceFunction(MS_STOPSPAM_CONTACTPASSED, IsContactPassed);
-
HookEvent(ME_DB_EVENT_ADDED, OnDbEventAdded);
HookEvent(ME_DB_EVENT_FILTER_ADD, OnDbEventFilterAdd);
HookEvent(ME_OPT_INITIALISE, OnOptInit);
- HookEvent(ME_DB_CONTACT_SETTINGCHANGED, OnDbContactSettingchanged);
+ HookEvent(ME_SYSTEM_SHUTDOWN, OnShutdown);
return 0;
}
diff --git a/plugins/StopSpamPlus/src/utils.cpp b/plugins/StopSpamPlus/src/utils.cpp index 427495026c..91378b7181 100644 --- a/plugins/StopSpamPlus/src/utils.cpp +++ b/plugins/StopSpamPlus/src/utils.cpp @@ -1,35 +1,5 @@ #include "stdafx.h"
-tstring& GetDlgItemString(HWND hwnd, int id)
-{
- HWND h = GetDlgItem(hwnd, id);
- int len = GetWindowTextLength(h);
- wchar_t * buf = new wchar_t[len + 1];
- GetWindowText(h, buf, len + 1);
- static tstring s;
- s = buf;
- delete[]buf;
- return s;
-}
-
-bool IsExistMyMessage(MCONTACT hContact)
-{
- DB::ECPTR pCursor(DB::Events(hContact));
- while (MEVENT hDbEvent = pCursor.FetchNext()) {
- DBEVENTINFO dbei = {};
- if (db_event_get(hDbEvent, &dbei))
- break;
-
- if (dbei.flags & DBEF_SENT){
- // mark contact as Answered
- g_plugin.setByte(hContact, DB_KEY_ANSWERED, 1);
- // ...let the event go its way
- return true;
- }
- }
- return false;
-}
-
tstring variables_parse(const wchar_t *tstrFormat, MCONTACT hContact)
{
if (ServiceExists(MS_VARS_FORMATSTRING)) {
@@ -38,7 +8,7 @@ tstring variables_parse(const wchar_t *tstrFormat, MCONTACT hContact) fi.szFormat.w = wcsdup(tstrFormat);
fi.hContact = hContact;
fi.flags = FIF_UNICODE;
- wchar_t *tszParsed = (wchar_t*)CallService(MS_VARS_FORMATSTRING, (WPARAM)&fi, 0);
+ wchar_t *tszParsed = (wchar_t *)CallService(MS_VARS_FORMATSTRING, (WPARAM)&fi, 0);
free(fi.szFormat.w);
if (tszParsed) {
tstring tstrResult = tszParsed;
@@ -49,7 +19,7 @@ tstring variables_parse(const wchar_t *tstrFormat, MCONTACT hContact) return tstrFormat;
}
-tstring trim(const tstring &tstr, const tstring& trimChars)
+tstring trim(const tstring &tstr, const tstring &trimChars)
{
size_t s = tstr.find_first_not_of(trimChars);
size_t e = tstr.find_last_not_of(trimChars);
diff --git a/plugins/StopSpamPlus/stopspam.vcxproj b/plugins/StopSpamPlus/stopspam.vcxproj index ca3ec31db4..e09b1892e4 100644 --- a/plugins/StopSpamPlus/stopspam.vcxproj +++ b/plugins/StopSpamPlus/stopspam.vcxproj @@ -28,7 +28,6 @@ <ItemGroup>
<ClCompile Include="src\events.cpp" />
<ClCompile Include="src\options.cpp" />
- <ClCompile Include="src\services.cpp" />
<ClCompile Include="src\settings.cpp" />
<ClCompile Include="src\stdafx.cxx">
<PrecompiledHeader>Create</PrecompiledHeader>
diff --git a/plugins/StopSpamPlus/stopspam.vcxproj.filters b/plugins/StopSpamPlus/stopspam.vcxproj.filters index 3227d52b41..b50f611162 100644 --- a/plugins/StopSpamPlus/stopspam.vcxproj.filters +++ b/plugins/StopSpamPlus/stopspam.vcxproj.filters @@ -8,9 +8,6 @@ <ClCompile Include="src\options.cpp">
<Filter>Source Files</Filter>
</ClCompile>
- <ClCompile Include="src\services.cpp">
- <Filter>Source Files</Filter>
- </ClCompile>
<ClCompile Include="src\settings.cpp">
<Filter>Source Files</Filter>
</ClCompile>
|