From c5b8e72f5cc510f88b9169445c56847bd01f51bb Mon Sep 17 00:00:00 2001 From: Attila Molnar Date: Fri, 23 Jan 2015 15:46:03 +0100 Subject: m_kicknorejoin Move logic that tracks kicked users into KickRejoinData --- src/modules/m_kicknorejoin.cpp | 59 ++++++++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 25 deletions(-) (limited to 'src/modules') diff --git a/src/modules/m_kicknorejoin.cpp b/src/modules/m_kicknorejoin.cpp index fdb7b8f24..5d9b7f8b9 100644 --- a/src/modules/m_kicknorejoin.cpp +++ b/src/modules/m_kicknorejoin.cpp @@ -27,12 +27,38 @@ typedef std::map delaylist; -struct KickRejoinData +class KickRejoinData { - delaylist kicked; - unsigned int delay; + mutable delaylist kicked; + + public: + const unsigned int delay; KickRejoinData(unsigned int Delay) : delay(Delay) { } + + bool canjoin(LocalUser* user) const + { + for (delaylist::iterator i = kicked.begin(); i != kicked.end(); ) + { + if (i->second > ServerInstance->Time()) + { + if (i->first == user->uuid) + return false; + ++i; + } + else + { + // Expired record, remove. + kicked.erase(i++); + } + } + return true; + } + + void add(User* user) + { + kicked[user->uuid] = ServerInstance->Time() + delay; + } }; /** Handles channel mode +J @@ -79,28 +105,11 @@ public: { if (chan) { - KickRejoinData* data = kr.ext.get(chan); - if (data) + const KickRejoinData* data = kr.ext.get(chan); + if ((data) && (!data->canjoin(user))) { - delaylist& kicked = data->kicked; - for (delaylist::iterator iter = kicked.begin(); iter != kicked.end(); ) - { - if (iter->second > ServerInstance->Time()) - { - if (iter->first == user->uuid) - { - user->WriteNumeric(ERR_DELAYREJOIN, "%s :You must wait %u seconds after being kicked to rejoin (+J)", - chan->name.c_str(), data->delay); - return MOD_RES_DENY; - } - ++iter; - } - else - { - // Expired record, remove. - kicked.erase(iter++); - } - } + user->WriteNumeric(ERR_DELAYREJOIN, "%s :You must wait %u seconds after being kicked to rejoin (+J)", chan->name.c_str(), data->delay); + return MOD_RES_DENY; } } return MOD_RES_PASSTHRU; @@ -114,7 +123,7 @@ public: KickRejoinData* data = kr.ext.get(memb->chan); if (data) { - data->kicked[memb->user->uuid] = ServerInstance->Time() + data->delay; + data->add(memb->user); } } -- cgit v1.2.3