From 080d9e0d4c2a521e96c79b62ea4f62587e40e080 Mon Sep 17 00:00:00 2001 From: attilamolnar Date: Wed, 4 Jul 2012 15:30:15 +0200 Subject: m_messageflood Perform at most one std::map::find() per message if we aren't kicking the user --- src/modules/m_messageflood.cpp | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-) (limited to 'src/modules') diff --git a/src/modules/m_messageflood.cpp b/src/modules/m_messageflood.cpp index f3045cf52..4aebb3b40 100644 --- a/src/modules/m_messageflood.cpp +++ b/src/modules/m_messageflood.cpp @@ -41,34 +41,17 @@ class floodsettings floodsettings(bool a, int b, int c) : ban(a), secs(b), lines(c) { reset = ServerInstance->Time() + secs; - }; + } - void addmessage(User* who) + bool addmessage(User* who) { - std::map::iterator iter = counters.find(who); - if (iter != counters.end()) - { - iter->second++; - } - else - { - counters[who] = 1; - } if (ServerInstance->Time() > reset) { counters.clear(); reset = ServerInstance->Time() + secs; } - } - bool shouldkick(User* who) - { - std::map::iterator iter = counters.find(who); - if (iter != counters.end()) - { - return (iter->second >= this->lines); - } - else return false; + return (++counters[who] >= this->lines); } void clear(User* who) @@ -215,8 +198,7 @@ class ModuleMsgFlood : public Module floodsettings *f = mf.ext.get(dest); if (f) { - f->addmessage(user); - if (f->shouldkick(user)) + if (f->addmessage(user)) { /* Youre outttta here! */ f->clear(user); -- cgit v1.2.3