summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorattilamolnar <attilamolnar@hush.com>2012-07-04 15:30:15 +0200
committerattilamolnar <attilamolnar@hush.com>2012-08-08 13:35:21 +0200
commit080d9e0d4c2a521e96c79b62ea4f62587e40e080 (patch)
tree12c4f513cc0a540bbf43ea71c7700154f2054bac
parent6e2b6aae53f007df51a4ded1058d2bc790a3892d (diff)
m_messageflood Perform at most one std::map::find() per message if we aren't kicking the user
-rw-r--r--src/modules/m_messageflood.cpp26
1 files changed, 4 insertions, 22 deletions
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<User*,int>::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<User*,int>::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);