summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--plugins/StopSpamPlus/res/stopspam.rc32
-rw-r--r--plugins/StopSpamPlus/src/events.cpp44
-rw-r--r--plugins/StopSpamPlus/src/options.cpp21
-rw-r--r--plugins/StopSpamPlus/src/resource.h9
-rw-r--r--plugins/StopSpamPlus/src/stdafx.h29
-rw-r--r--plugins/StopSpamPlus/src/stopspam.cpp21
6 files changed, 108 insertions, 48 deletions
diff --git a/plugins/StopSpamPlus/res/stopspam.rc b/plugins/StopSpamPlus/res/stopspam.rc
index dd81fc4a9c..6a7bd96350 100644
--- a/plugins/StopSpamPlus/res/stopspam.rc
+++ b/plugins/StopSpamPlus/res/stopspam.rc
@@ -52,21 +52,24 @@ 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 "Enable auth. requests blocking",ID_HANDLEAUTHREQ,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,148,282,8
+ CONTROL "Answer is not case sensitive",ID_NOTCASESENS,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,160,282,8
+ CONTROL "Log Spammers to system history",ID_HISTORY_LOG,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,172,282,8
END
@@ -99,10 +102,8 @@ BEGIN
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 302
- VERTGUIDE, 12
- VERTGUIDE, 294
TOPMARGIN, 7
- BOTTOMMARGIN, 181
+ BOTTOMMARGIN, 189
END
END
#endif // APSTUDIO_INVOKED
@@ -144,6 +145,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..9b7cf5cbb7 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;
@@ -19,16 +21,16 @@ int OnDbEventAdded(WPARAM, LPARAM lParam)
// 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);
- }
+ if (!g_plugin.bHandleAuthReq)
+ ProtoChainSend(hContact, PSS_MESSAGE, 0, ptrA(mir_utf8encodeW(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;
}
@@ -93,12 +95,12 @@ 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);
// add contact permanently and delete our temporary variables
- if (g_plugin.AddPermanent) {
+ if (g_plugin.bAddPermanent) {
Contact::PutOnList(hContact);
db_delete_module(hContact, MODULENAME);
}
@@ -119,7 +121,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 +143,35 @@ 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)
+ 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);
+ }
+ }
+}
+
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..0eb3114c39 100644
--- a/plugins/StopSpamPlus/src/options.cpp
+++ b/plugins/StopSpamPlus/src/options.cpp
@@ -4,27 +4,30 @@ const wchar_t pluginDescription[] = LPGENW("No more spam! Robots can't go! Only
class COptMainDlg : public CDlgBase
{
- CCtrlEdit edtCount, edtDescr;
+ CCtrlEdit edtDescr;
+ CCtrlSpin spinCount, spinTimeout;
CCtrlCheck chk1, chk2, chk3, 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(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(spinCount, g_plugin.iMaxQuestCount);
+ CreateLink(spinTimeout, g_plugin.iAnswerTimeout);
+
+ CreateLink(chk1, g_plugin.bInfTalkProtection);
+ CreateLink(chk2, g_plugin.bAddPermanent);
+ CreateLink(chk3, g_plugin.bHandleAuthReq);
+ 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..82c2cd8694 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,6 +13,7 @@
#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
@@ -20,14 +21,16 @@
#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.h b/plugins/StopSpamPlus/src/stdafx.h
index 75840d2c03..e4e3992f5b 100644
--- a/plugins/StopSpamPlus/src/stdafx.h
+++ b/plugins/StopSpamPlus/src/stdafx.h
@@ -8,17 +8,19 @@
#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 +41,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, bHandleAuthReq, 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 +69,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..fd6e3e8ebc 100644
--- a/plugins/StopSpamPlus/src/stopspam.cpp
+++ b/plugins/StopSpamPlus/src/stopspam.cpp
@@ -25,22 +25,31 @@ 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),
+ bHandleAuthReq(MODULENAME, "HandleAuthReq", 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;
+}