2
* Copyright (C) 2004-2012 See the AUTHORS file for details.
4
* This program is free software; you can redistribute it and/or modify it
5
* under the terms of the GNU General Public License version 2 as published
6
* by the Free Software Foundation.
9
#include <znc/Modules.h>
12
class CCtcpFloodMod : public CModule {
14
MODCONSTRUCTOR(CCtcpFloodMod) {
23
// We save the settings twice because the module arguments can
24
// be more easily edited via webadmin, while the SetNV() stuff
25
// survives e.g. /msg *status reloadmod ctcpflood.
26
SetNV("secs", CString(m_iThresholdSecs));
27
SetNV("msgs", CString(m_iThresholdMsgs));
29
SetArgs(CString(m_iThresholdMsgs) + " " + CString(m_iThresholdSecs));
32
bool OnLoad(const CString& sArgs, CString& sMessage) {
33
m_iThresholdMsgs = sArgs.Token(0).ToUInt();
34
m_iThresholdSecs = sArgs.Token(1).ToUInt();
36
if (m_iThresholdMsgs == 0 || m_iThresholdSecs == 0) {
37
m_iThresholdMsgs = GetNV("msgs").ToUInt();
38
m_iThresholdSecs = GetNV("secs").ToUInt();
41
if (m_iThresholdSecs == 0)
43
if (m_iThresholdMsgs == 0)
51
EModRet Message(const CNick& Nick, const CString& sMessage) {
52
// We never block /me, because it doesn't cause a reply
53
if (sMessage.Token(0).Equals("ACTION"))
56
if (m_tLastCTCP + m_iThresholdSecs < time(NULL)) {
57
m_tLastCTCP = time(NULL);
63
if (m_iNumCTCP < m_iThresholdMsgs)
65
else if (m_iNumCTCP == m_iThresholdMsgs)
66
PutModule("Limit reached by [" + Nick.GetHostMask() + "], blocking all CTCP");
68
// Reset the timeout so that we continue blocking messages
69
m_tLastCTCP = time(NULL);
74
EModRet OnPrivCTCP(CNick& Nick, CString& sMessage) {
75
return Message(Nick, sMessage);
78
EModRet OnChanCTCP(CNick& Nick, CChan& Channel, CString& sMessage) {
79
return Message(Nick, sMessage);
82
void OnModCommand(const CString& sCommand) {
83
const CString& sCmd = sCommand.Token(0);
84
const CString& sArg = sCommand.Token(1, true);
86
if (sCmd.Equals("secs") && !sArg.empty()) {
87
m_iThresholdSecs = sArg.ToUInt();
88
if (m_iThresholdSecs == 0)
91
PutModule("Set seconds limit to [" + CString(m_iThresholdSecs) + "]");
93
} else if (sCmd.Equals("lines") && !sArg.empty()) {
94
m_iThresholdMsgs = sArg.ToUInt();
95
if (m_iThresholdMsgs == 0)
98
PutModule("Set lines limit to [" + CString(m_iThresholdMsgs) + "]");
100
} else if (sCmd.Equals("show")) {
101
PutModule("Current limit is " + CString(m_iThresholdMsgs) + " CTCPs "
102
"in " + CString(m_iThresholdSecs) + " secs");
104
PutModule("Commands: show, secs [limit], lines [limit]");
110
unsigned int m_iNumCTCP;
112
time_t m_iThresholdSecs;
113
unsigned int m_iThresholdMsgs;
116
template<> void TModInfo<CCtcpFloodMod>(CModInfo& Info) {
117
Info.SetWikiPage("ctcpflood");
118
Info.SetHasArgs(true);
119
Info.SetArgsHelpText("This user module takes none to two arguments. The first argument is the number of lines after which the flood-protection is triggered. The second argument is the time (s) to in which the number of lines is reached. The default setting is 4 CTCPs in 2 seconds");
122
USERMODULEDEFS(CCtcpFloodMod, "Don't forward CTCP floods to clients")