X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_kicknorejoin.cpp;h=cc899282fccd7447a5fb36ff6b5dbfc9821cf3aa;hb=3151d60c1ecc9462e4c335282ee6c31672f45111;hp=5d9b7f8b95c140f2435b0c23954ef48a4d81b0c9;hpb=c5b8e72f5cc510f88b9169445c56847bd01f51bb;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_kicknorejoin.cpp b/src/modules/m_kicknorejoin.cpp index 5d9b7f8b9..cc899282f 100644 --- a/src/modules/m_kicknorejoin.cpp +++ b/src/modules/m_kicknorejoin.cpp @@ -1,13 +1,15 @@ /* * InspIRCd -- Internet Relay Chat Daemon * + * Copyright (C) 2018 A_D + * Copyright (C) 2014 Daniel Vassdal + * Copyright (C) 2013, 2017-2020 Sadie Powell + * Copyright (C) 2012-2015 Attila Molnar + * Copyright (C) 2012, 2019 Robby + * Copyright (C) 2009 Uli Schlachter * Copyright (C) 2009 Daniel De Graaf - * Copyright (C) 2008 Pippijn van Steenhoven * Copyright (C) 2007 Dennis Friis - * Copyright (C) 2006-2007 Robin Burchell - * Copyright (C) 2006 John Brooks - * Copyright (C) 2006 Craig Edwards - * Copyright (C) 2006 Oliver Lupton + * Copyright (C) 2006, 2010 Craig Edwards * * This file is part of InspIRCd. InspIRCd is free software: you can * redistribute it and/or modify it under the terms of the GNU General Public @@ -24,12 +26,32 @@ #include "inspircd.h" +#include "modules/invite.h" + +enum +{ + // From RFC 2182. + ERR_UNAVAILRESOURCE = 437 +}; -typedef std::map 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 KickedList; + + mutable KickedList kicked; public: const unsigned int delay; @@ -38,18 +60,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 +82,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)); } }; @@ -65,20 +93,25 @@ class KickRejoinData */ class KickRejoin : public ParamMode > { - static const unsigned int max = 60; + const unsigned int max; public: KickRejoin(Module* Creator) : ParamMode >(Creator, "kicknorejoin", 'J') + , max(60) { + syntax = ""; } - ModeAction OnSet(User* source, Channel* channel, std::string& parameter) + ModeAction OnSet(User* source, Channel* channel, std::string& parameter) CXX11_OVERRIDE { - int v = ConvToInt(parameter); + unsigned int v = ConvToNum(parameter); if (v <= 0) + { + source->WriteNumeric(Numerics::InvalidModeParameter(channel, this, parameter)); return MODEACTION_DENY; + } - if ((IS_LOCAL(source) && ((unsigned int)v > max))) + if (IS_LOCAL(source) && v > max) v = max; ext.set(channel, new KickRejoinData(v)); @@ -89,15 +122,22 @@ class KickRejoin : public ParamMode > { out.append(ConvToStr(krd->delay)); } + + std::string GetModuleSettings() const + { + return ConvToStr(max); + } }; class ModuleKickNoRejoin : public Module { KickRejoin kr; + Invite::API invapi; public: ModuleKickNoRejoin() : kr(this) + , invapi(this) { } @@ -106,9 +146,9 @@ public: if (chan) { const KickRejoinData* data = kr.ext.get(chan); - if ((data) && (!data->canjoin(user))) + if ((data) && !invapi->IsInvited(user, chan) && (!data->canjoin(user))) { - user->WriteNumeric(ERR_DELAYREJOIN, "%s :You must wait %u seconds after being kicked to rejoin (+J)", chan->name.c_str(), data->delay); + user->WriteNumeric(ERR_UNAVAILRESOURCE, chan->name, InspIRCd::Format("You must wait %u seconds after being kicked to rejoin (+J is set)", data->delay)); return MOD_RES_DENY; } } @@ -129,7 +169,7 @@ public: Version GetVersion() CXX11_OVERRIDE { - return Version("Channel mode to delay rejoin after kick", VF_VENDOR); + return Version("Adds channel mode J (kicknorejoin) which prevents users from rejoining after being kicked from a channel.", VF_VENDOR | VF_COMMON, kr.GetModuleSettings()); } };