diff options
author | Attila Molnar <attilamolnar@hush.com> | 2015-01-23 15:50:18 +0100 |
---|---|---|
committer | Attila Molnar <attilamolnar@hush.com> | 2015-01-23 15:50:18 +0100 |
commit | 9add848772555f527b625953cb45c46850ac1274 (patch) | |
tree | fe4e3b0bd89c2c369508b6c1612d85c1cd40cf5c /src | |
parent | c5b8e72f5cc510f88b9169445c56847bd01f51bb (diff) |
m_kicknorejoin Store kicked users in a vector
Diffstat (limited to 'src')
-rw-r--r-- | src/modules/m_kicknorejoin.cpp | 34 |
1 files changed, 26 insertions, 8 deletions
diff --git a/src/modules/m_kicknorejoin.cpp b/src/modules/m_kicknorejoin.cpp index 5d9b7f8b9..ebe2d45c9 100644 --- a/src/modules/m_kicknorejoin.cpp +++ b/src/modules/m_kicknorejoin.cpp @@ -25,11 +25,23 @@ #include "inspircd.h" -typedef std::map<std::string, time_t> delaylist; - class KickRejoinData { - mutable delaylist kicked; + struct KickedUser + { + std::string uuid; + time_t expire; + + KickedUser(User* user, unsigned int Delay) + : uuid(user->uuid) + , expire(ServerInstance->Time() + Delay) + { + } + }; + + typedef std::vector<KickedUser> KickedList; + + mutable KickedList kicked; public: const unsigned int delay; @@ -38,18 +50,21 @@ class KickRejoinData bool canjoin(LocalUser* user) const { - for (delaylist::iterator i = kicked.begin(); i != kicked.end(); ) + for (KickedList::iterator i = kicked.begin(); i != kicked.end(); ) { - if (i->second > ServerInstance->Time()) + KickedUser& rec = *i; + if (rec.expire > ServerInstance->Time()) { - if (i->first == user->uuid) + if (rec.uuid == user->uuid) return false; ++i; } else { // Expired record, remove. - kicked.erase(i++); + stdalgo::vector::swaperase(kicked, i); + if (kicked.empty()) + break; } } return true; @@ -57,7 +72,10 @@ class KickRejoinData void add(User* user) { - kicked[user->uuid] = ServerInstance->Time() + delay; + // One user can be in the list multiple times if the user gets kicked, force joins + // (skipping OnUserPreJoin) and gets kicked again, but that's okay because canjoin() + // works correctly in this case as well + kicked.push_back(KickedUser(user, delay)); } }; |