summaryrefslogtreecommitdiff
path: root/plugins/StopSpamPlus
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/StopSpamPlus')
-rw-r--r--plugins/StopSpamPlus/res/stopspam.rc31
-rw-r--r--plugins/StopSpamPlus/src/events.cpp55
-rw-r--r--plugins/StopSpamPlus/src/options.cpp21
-rw-r--r--plugins/StopSpamPlus/src/resource.h10
-rw-r--r--plugins/StopSpamPlus/src/stdafx.cxx2
-rw-r--r--plugins/StopSpamPlus/src/stdafx.h31
-rw-r--r--plugins/StopSpamPlus/src/stopspam.cpp20
7 files changed, 113 insertions, 57 deletions
diff --git a/plugins/StopSpamPlus/res/stopspam.rc b/plugins/StopSpamPlus/res/stopspam.rc
index dd81fc4a9c..84aa180360 100644
--- a/plugins/StopSpamPlus/res/stopspam.rc
+++ b/plugins/StopSpamPlus/res/stopspam.rc
@@ -52,21 +52,23 @@ BEGIN
CONTROL "",IDC_PROTO,"SysListView32",LVS_REPORT | LVS_SINGLESEL | LVS_SHOWSELALWAYS | LVS_AUTOARRANGE | LVS_NOCOLUMNHEADER | LVS_NOSORTHEADER | WS_BORDER | WS_TABSTOP,24,22,216,166
END
-IDD_MAIN DIALOGEX 0, 0, 309, 189
+IDD_MAIN DIALOGEX 0, 0, 309, 197
STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD
EXSTYLE WS_EX_CONTROLPARENT
FONT 8, "MS Shell Dlg", 0, 0, 0x1
BEGIN
- EDITTEXT ID_DESCRIPTION,12,7,282,82,ES_MULTILINE | ES_AUTOVSCROLL | ES_READONLY | NOT WS_TABSTOP
- CTEXT "Do not send more than",IDC_STATIC,11,93,101,12,SS_CENTERIMAGE
- EDITTEXT ID_MAXQUESTCOUNT,113,93,30,12,ES_AUTOHSCROLL | ES_NUMBER
- LTEXT "questions to one contact (0 - for no limit)",IDC_STATIC,144,93,150,12,SS_CENTERIMAGE
+ EDITTEXT ID_DESCRIPTION,7,7,294,82,ES_MULTILINE | ES_AUTOVSCROLL | ES_READONLY | NOT WS_TABSTOP
+ LTEXT "Maximum number of questions to one contact (0 - for no limit):",IDC_STATIC,9,95,258,9,SS_CENTERIMAGE
+ EDITTEXT ID_MAXQUESTCOUNT,272,93,30,12,ES_AUTOHSCROLL | ES_NUMBER
+ CONTROL "",IDC_SPIN1,"msctls_updown32",UDS_SETBUDDYINT | UDS_ALIGNRIGHT | UDS_AUTOBUDDY | UDS_NOTHOUSANDS,291,92,11,14
+ LTEXT "Timeout in minutes to remove temporary contacts (0 - never)",IDC_STATIC,9,109,258,8,SS_CENTERIMAGE
+ EDITTEXT ID_MAXQUESTCOUNT2,272,107,30,12,ES_AUTOHSCROLL | ES_NUMBER
+ CONTROL "",IDC_SPIN2,"msctls_updown32",UDS_SETBUDDYINT | UDS_ALIGNRIGHT | UDS_AUTOBUDDY | UDS_NOTHOUSANDS,293,106,11,14
CONTROL "Enable StopSpam-StopSpam infinite talk protection",ID_INFTALKPROT,
- "Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,109,282,10
- CONTROL "Add contact permanently",ID_ADDPERMANENT,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,121,282,8
- CONTROL "Enable auth. requests blocking",ID_HANDLEAUTHREQ,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,133,270,8
- CONTROL "Answer is not case sensitive",ID_NOTCASESENS,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,145,282,8
- CONTROL "Log Spammers to system history",ID_HISTORY_LOG,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,157,282,8
+ "Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,124,282,10
+ CONTROL "Add contact permanently",ID_ADDPERMANENT,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,136,282,8
+ CONTROL "Answer is not case sensitive",ID_NOTCASESENS,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,148,282,8
+ CONTROL "Log Spammers to system history",ID_HISTORY_LOG,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,160,282,8
END
@@ -99,10 +101,8 @@ BEGIN
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 302
- VERTGUIDE, 12
- VERTGUIDE, 294
TOPMARGIN, 7
- BOTTOMMARGIN, 181
+ BOTTOMMARGIN, 189
END
END
#endif // APSTUDIO_INVOKED
@@ -144,6 +144,11 @@ BEGIN
0
END
+IDD_MAIN AFX_DIALOG_LAYOUT
+BEGIN
+ 0
+END
+
#endif // Russian (Russia) resources
/////////////////////////////////////////////////////////////////////////////
diff --git a/plugins/StopSpamPlus/src/events.cpp b/plugins/StopSpamPlus/src/events.cpp
index de5a5cfad9..067be9ac76 100644
--- a/plugins/StopSpamPlus/src/events.cpp
+++ b/plugins/StopSpamPlus/src/events.cpp
@@ -1,5 +1,7 @@
#include "stdafx.h"
+static std::map<MCONTACT, time_t> g_times;
+
int OnDbEventAdded(WPARAM, LPARAM lParam)
{
MEVENT hDbEvent = (MEVENT)lParam;
@@ -13,22 +15,21 @@ int OnDbEventAdded(WPARAM, LPARAM lParam)
return 0;
// event is an auth request
- if (!(dbei.flags & DBEF_SENT) && !(dbei.flags & DBEF_READ) && dbei.eventType == EVENTTYPE_AUTHREQUEST) {
+ if (!dbei.bSent && !dbei.bRead && dbei.eventType == EVENTTYPE_AUTHREQUEST) {
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(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(), hContact).c_str());
- ProtoChainSend(hContact, PSS_MESSAGE, 0, (LPARAM)buf);
- mir_free(buf);
- }
+ ProtoChainSend(hContact, PSS_MESSAGE, 0, T2Utf(variables_parse(g_plugin.getReply(), hContact).c_str()));
+
+ if (g_plugin.iAnswerTimeout)
+ g_times[hContact] = time(0);
g_plugin.setDword(hContact, DB_KEY_HASAUTH, hDbEvent);
Contact::RemoveFromList(hContact);
Contact::Hide(hContact);
- if (!g_plugin.HistLog)
+ if (!g_plugin.bHistLog)
db_event_delete(hDbEvent);
return 1;
}
@@ -48,10 +49,10 @@ int OnDbEventFilterAdd(WPARAM w, LPARAM l)
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->eventType != EVENTTYPE_MESSAGE || (dbei->flags & DBEF_READ) != 0)
+ if (dbei->eventType != EVENTTYPE_MESSAGE || dbei->bRead)
return 0;
- if (dbei->flags & DBEF_SENT) {
+ if (dbei->bSent) {
g_plugin.setByte(hContact, DB_KEY_HASSENT, 1);
return 0;
}
@@ -93,21 +94,20 @@ int OnDbEventFilterAdd(WPARAM w, LPARAM l)
// if answer not empty
if (answer.length() > 0) {
// if message equal right answer...
- if (g_plugin.AnswNotCaseSens ? !mir_wstrcmpi(message.c_str(), answer.c_str()) : !mir_wstrcmp(message.c_str(), answer.c_str())) {
+ if (g_plugin.bAnswNotCaseSens ? !mir_wstrcmpi(message.c_str(), answer.c_str()) : !mir_wstrcmp(message.c_str(), answer.c_str())) {
// unhide contact
Contact::Hide(hContact, false);
+ g_times.erase(hContact);
// add contact permanently and delete our temporary variables
- if (g_plugin.AddPermanent) {
+ if (g_plugin.bAddPermanent) {
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());
- ProtoChainSend(hContact, PSS_MESSAGE, 0, (LPARAM)buf);
- mir_free(buf);
+ ProtoChainSend(hContact, PSS_MESSAGE, 0, T2Utf(variables_parse(g_plugin.getCongrats(), hContact).c_str()));
// process the event
return 1;
@@ -119,7 +119,7 @@ int OnDbEventFilterAdd(WPARAM w, LPARAM l)
// if message message does not contain infintite talk protection prefix
// and question count for this contact is less then maximum
const wchar_t *pwszPrefix = TranslateT("StopSpam automatic message:\r\n");
- if ((!g_plugin.InfTalkProtection || tstring::npos == message.find(pwszPrefix)) && (!g_plugin.MaxQuestCount || g_plugin.getDword(hContact, DB_KEY_QUESTCOUNT) < g_plugin.MaxQuestCount)) {
+ if ((!g_plugin.bInfTalkProtection || tstring::npos == message.find(pwszPrefix)) && (!g_plugin.iMaxQuestCount || g_plugin.getDword(hContact, DB_KEY_QUESTCOUNT) < g_plugin.iMaxQuestCount)) {
// send question
tstring q = pwszPrefix + variables_parse(g_plugin.getQuestion(), hContact);
@@ -141,13 +141,36 @@ int OnDbEventFilterAdd(WPARAM w, LPARAM l)
return 0;
}
+void CMPlugin::Impl::OnTimer(CTimer *)
+{
+ int iTimeout = g_plugin.iAnswerTimeout;
+ if (!iTimeout)
+ return;
+
+ time_t now = time(0);
+
+ for (auto &it : g_times) {
+ if (now - it.second < iTimeout * 60)
+ continue;
+
+ if (MEVENT hDbEvent = g_plugin.getDword(it.first, DB_KEY_HASAUTH)) {
+ char *szProto = Proto_GetBaseAccountName(it.first);
+ CallProtoService(szProto, PS_AUTHDENY, hDbEvent, (LPARAM)_T2A(variables_parse(g_plugin.getReply(), it.first).c_str()));
+
+ Netlib_Logf(0, "StopSpam: removing temporary contact %d", it.first);
+ db_delete_contact(it.first);
+ g_times.erase(it.first);
+ }
+ }
+}
+
int OnShutdown(WPARAM, LPARAM)
{
for (auto &cc : Contacts()) {
if (Contact::OnList(cc))
continue;
- if (MEVENT hDbEvent = g_plugin.getByte(cc, DB_KEY_HASAUTH)) {
+ if (MEVENT hDbEvent = g_plugin.getDword(cc, DB_KEY_HASAUTH)) {
char *szProto = Proto_GetBaseAccountName(cc);
CallProtoService(szProto, PS_AUTHDENY, hDbEvent, (LPARAM)_T2A(variables_parse(g_plugin.getReply(), cc).c_str()));
}
diff --git a/plugins/StopSpamPlus/src/options.cpp b/plugins/StopSpamPlus/src/options.cpp
index 99981028c7..127288d49a 100644
--- a/plugins/StopSpamPlus/src/options.cpp
+++ b/plugins/StopSpamPlus/src/options.cpp
@@ -4,27 +4,28 @@ const wchar_t pluginDescription[] = LPGENW("No more spam! Robots can't go! Only
class COptMainDlg : public CDlgBase
{
- CCtrlEdit edtCount, edtDescr;
- CCtrlCheck chk1, chk2, chk3, chk4, chk6;
+ CCtrlEdit edtDescr;
+ CCtrlSpin spinCount, spinTimeout;
+ CCtrlCheck chk1, chk2, chk4, chk6;
public:
COptMainDlg() :
CDlgBase(g_plugin, IDD_MAIN),
- edtCount(this, ID_MAXQUESTCOUNT),
edtDescr(this, ID_DESCRIPTION),
+ spinCount(this, IDC_SPIN1, 10),
+ spinTimeout(this, IDC_SPIN2, 60),
chk1(this, ID_INFTALKPROT),
chk2(this, ID_ADDPERMANENT),
- chk3(this, ID_HANDLEAUTHREQ),
chk4(this, ID_NOTCASESENS),
chk6(this, ID_HISTORY_LOG)
{
- CreateLink(edtCount, g_plugin.MaxQuestCount);
+ CreateLink(spinCount, g_plugin.iMaxQuestCount);
+ CreateLink(spinTimeout, g_plugin.iAnswerTimeout);
- CreateLink(chk1, g_plugin.InfTalkProtection);
- CreateLink(chk2, g_plugin.AddPermanent);
- CreateLink(chk3, g_plugin.HandleAuthReq);
- CreateLink(chk4, g_plugin.AnswNotCaseSens);
- CreateLink(chk6, g_plugin.HistLog);
+ CreateLink(chk1, g_plugin.bInfTalkProtection);
+ CreateLink(chk2, g_plugin.bAddPermanent);
+ CreateLink(chk4, g_plugin.bAnswNotCaseSens);
+ CreateLink(chk6, g_plugin.bHistLog);
}
bool OnInitDialog() override
diff --git a/plugins/StopSpamPlus/src/resource.h b/plugins/StopSpamPlus/src/resource.h
index a4e7c05b61..aec5d198ba 100644
--- a/plugins/StopSpamPlus/src/resource.h
+++ b/plugins/StopSpamPlus/src/resource.h
@@ -1,6 +1,6 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
-// Used by C:\Users\georg\DiskW\miranda-ng\plugins\StopSpamPlus\res\stopspam.rc
+// Used by W:\miranda-ng\plugins\StopSpamPlus\res\stopspam.rc
//
#define IDD_MESSAGES 101
#define IDD_MAIN 102
@@ -13,21 +13,23 @@
#define ID_AUTHREPL 1007
#define ID_MAXQUESTCOUNT 1008
#define IDC_PROTO 1009
+#define ID_MAXQUESTCOUNT2 1009
#define ID_INFTALKPROT 1010
#define ID_ADDPERMANENT 1011
-#define ID_HANDLEAUTHREQ 1012
#define ID_NOTCASESENS 1013
#define ID_DIVIDER 1014
#define IDC_VARS 1015
#define ID_HISTORY_LOG 1017
+#define IDC_SPIN1 1018
+#define IDC_SPIN2 1019
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
-#define _APS_NEXT_RESOURCE_VALUE 105
+#define _APS_NEXT_RESOURCE_VALUE 106
#define _APS_NEXT_COMMAND_VALUE 40001
-#define _APS_NEXT_CONTROL_VALUE 1018
+#define _APS_NEXT_CONTROL_VALUE 1019
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
diff --git a/plugins/StopSpamPlus/src/stdafx.cxx b/plugins/StopSpamPlus/src/stdafx.cxx
index 13f28e1314..f111565f38 100644
--- a/plugins/StopSpamPlus/src/stdafx.cxx
+++ b/plugins/StopSpamPlus/src/stdafx.cxx
@@ -1,5 +1,5 @@
/*
-Copyright (C) 2012-24 Miranda NG team (https://miranda-ng.org)
+Copyright (C) 2012-25 Miranda NG team (https://miranda-ng.org)
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
diff --git a/plugins/StopSpamPlus/src/stdafx.h b/plugins/StopSpamPlus/src/stdafx.h
index 75840d2c03..66bbfb137c 100644
--- a/plugins/StopSpamPlus/src/stdafx.h
+++ b/plugins/StopSpamPlus/src/stdafx.h
@@ -4,21 +4,25 @@
// disable security warnings about "*_s" functions
#define _CRT_SECURE_NO_DEPRECATE
+#include <time.h>
+
#include <windows.h>
#include <commctrl.h>
#include <sstream>
#include <list>
+#include <map>
#include <newpluginapi.h>
+#include <m_clistint.h>
#include <m_contacts.h>
#include <m_database.h>
-#include <m_protosvc.h>
-#include <m_options.h>
-#include <m_langpack.h>
+#include <m_gui.h>
#include <m_icolib.h>
+#include <m_langpack.h>
+#include <m_netlib.h>
+#include <m_options.h>
+#include <m_protosvc.h>
#include <m_skin.h>
-#include <m_clistint.h>
-#include <m_gui.h>
#include <m_variables.h>
@@ -39,10 +43,22 @@ struct CMPlugin : public PLUGIN<CMPlugin>
{
CMPlugin();
- CMOption<bool> InfTalkProtection, AddPermanent, HandleAuthReq, AnswNotCaseSens, HistLog;
+ struct Impl
+ {
+ Impl() :
+ timerAnswer(Miranda_GetSystemWindow(), UINT_PTR(this))
+ {
+ timerAnswer.OnEvent = Callback(this, &Impl::OnTimer);
+ }
+
+ CTimer timerAnswer;
+ void OnTimer(CTimer *);
+ } m_impl;
+
+ CMOption<bool> bInfTalkProtection, bAddPermanent, bAnswNotCaseSens, bHistLog;
CMOption<wchar_t *> Question, AuthRepl, Answer, Congratulation, AnswSplitString;
CMOption<char *> DisabledProtoList;
- CMOption<uint32_t> MaxQuestCount;
+ CMOption<uint32_t> iMaxQuestCount, iAnswerTimeout;
const wchar_t* getQuestion();
const wchar_t* getReply();
@@ -55,6 +71,7 @@ struct CMPlugin : public PLUGIN<CMPlugin>
}
int Load() override;
+ int Unload() override;
};
// utils
diff --git a/plugins/StopSpamPlus/src/stopspam.cpp b/plugins/StopSpamPlus/src/stopspam.cpp
index 81de4f5c53..5e4d8482a1 100644
--- a/plugins/StopSpamPlus/src/stopspam.cpp
+++ b/plugins/StopSpamPlus/src/stopspam.cpp
@@ -25,22 +25,30 @@ CMPlugin::CMPlugin() :
Answer(MODULENAME, "Answer", L"nospam"),
Congratulation(MODULENAME, "Congratulation"),
DisabledProtoList(MODULENAME, "DisabledProtoList", "MetaContacts RSSNews"),
- InfTalkProtection(MODULENAME, "InfTalkProtection", 1),
- AddPermanent(MODULENAME, "AddPermanent", 0),
- HandleAuthReq(MODULENAME, "HandleAuthReq", 0),
- MaxQuestCount(MODULENAME, "MaxQuestCount", 2),
- AnswNotCaseSens(MODULENAME, "AnswNotCaseSens", 1),
+ bInfTalkProtection(MODULENAME, "InfTalkProtection", 1),
+ bAddPermanent(MODULENAME, "AddPermanent", 0),
+ iMaxQuestCount(MODULENAME, "MaxQuestCount", 2),
+ iAnswerTimeout(MODULENAME, "AnswerTimeout", 5),
+ bAnswNotCaseSens(MODULENAME, "AnswNotCaseSens", 1),
AnswSplitString(MODULENAME, "AnswSplitString", L"|"),
- HistLog(MODULENAME, "HistLog", 0)
+ bHistLog(MODULENAME, "HistLog", 0)
{}
/////////////////////////////////////////////////////////////////////////////////////////
int CMPlugin::Load()
{
+ m_impl.timerAnswer.Start(60000);
+
HookEvent(ME_DB_EVENT_ADDED, OnDbEventAdded);
HookEvent(ME_DB_EVENT_FILTER_ADD, OnDbEventFilterAdd);
HookEvent(ME_OPT_INITIALISE, OnOptInit);
HookEvent(ME_SYSTEM_SHUTDOWN, OnShutdown);
return 0;
}
+
+int CMPlugin::Unload()
+{
+ m_impl.timerAnswer.Stop();
+ return 0;
+}