diff options
author | Peter Powell <petpow@saberuk.com> | 2019-06-06 16:00:24 +0100 |
---|---|---|
committer | Peter Powell <petpow@saberuk.com> | 2019-06-06 16:01:34 +0100 |
commit | 08eee19aff6451171d1c63ecdf9a2c4820bf9da0 (patch) | |
tree | d4aaca262f63bba72011372600cff95da4971cfc /src | |
parent | 87bbf574bde2149daed9f9967f33ceae13250b70 (diff) |
Make messageflood weights configurable.
Also, default TAGMSG to being worth 0.2 NOTICE/PRIVMSG. This should
prevent flood kicks from typing notifications.
Closes #1649.
Diffstat (limited to 'src')
-rw-r--r-- | src/modules/m_messageflood.cpp | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/src/modules/m_messageflood.cpp b/src/modules/m_messageflood.cpp index 3021b1771..7b96804f0 100644 --- a/src/modules/m_messageflood.cpp +++ b/src/modules/m_messageflood.cpp @@ -36,7 +36,7 @@ class floodsettings unsigned int secs; unsigned int lines; time_t reset; - insp::flat_map<User*, unsigned int> counters; + insp::flat_map<User*, double> counters; floodsettings(bool a, unsigned int b, unsigned int c) : ban(a) @@ -46,7 +46,7 @@ class floodsettings reset = ServerInstance->Time() + secs; } - bool addmessage(User* who) + bool addmessage(User* who, double weight) { if (ServerInstance->Time() > reset) { @@ -54,7 +54,8 @@ class floodsettings reset = ServerInstance->Time() + secs; } - return (++counters[who] >= this->lines); + counters[who] += weight; + return (counters[who] >= this->lines); } void clear(User* who) @@ -113,6 +114,9 @@ class ModuleMsgFlood private: CheckExemption::EventProvider exemptionprov; MsgFlood mf; + double notice; + double privmsg; + double tagmsg; public: ModuleMsgFlood() @@ -122,7 +126,15 @@ private: { } - ModResult HandleMessage(User* user, const MessageTarget& target) + void ReadConfig(ConfigStatus&) CXX11_OVERRIDE + { + ConfigTag* tag = ServerInstance->Config->ConfValue("messageflood"); + notice = tag->getFloat("notice", 1.0); + privmsg = tag->getFloat("privmsg", 1.0); + tagmsg = tag->getFloat("tagmsg", 0.2); + } + + ModResult HandleMessage(User* user, const MessageTarget& target, double weight) { if (target.type != MessageTarget::TYPE_CHANNEL) return MOD_RES_PASSTHRU; @@ -138,7 +150,7 @@ private: floodsettings *f = mf.ext.get(dest); if (f) { - if (f->addmessage(user)) + if (f->addmessage(user, weight)) { /* Youre outttta here! */ f->clear(user); @@ -163,12 +175,12 @@ private: ModResult OnUserPreMessage(User* user, const MessageTarget& target, MessageDetails& details) CXX11_OVERRIDE { - return HandleMessage(user, target); + return HandleMessage(user, target, (details.type == MSG_PRIVMSG ? privmsg : notice)); } ModResult OnUserPreTagMessage(User* user, const MessageTarget& target, CTCTags::TagMessageDetails& details) CXX11_OVERRIDE { - return HandleMessage(user, target); + return HandleMessage(user, target, tagmsg); } void Prioritize() CXX11_OVERRIDE |