2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2018 A_D <A-UNDERSCORE-D@users.noreply.github.com>
5 * Copyright (C) 2014 Daniel Vassdal <shutter@canternet.org>
6 * Copyright (C) 2013, 2017-2020 Sadie Powell <sadie@witchery.services>
7 * Copyright (C) 2012-2015 Attila Molnar <attilamolnar@hush.com>
8 * Copyright (C) 2012, 2019 Robby <robby@chatbelgie.be>
9 * Copyright (C) 2009 Uli Schlachter <psychon@inspircd.org>
10 * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
11 * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
12 * Copyright (C) 2006, 2010 Craig Edwards <brain@inspircd.org>
13 * Copyright (C) 2006 Oliver Lupton <om@inspircd.org>
15 * This file is part of InspIRCd. InspIRCd is free software: you can
16 * redistribute it and/or modify it under the terms of the GNU General Public
17 * License as published by the Free Software Foundation, version 2.
19 * This program is distributed in the hope that it will be useful, but WITHOUT
20 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
21 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
24 * You should have received a copy of the GNU General Public License
25 * along with this program. If not, see <http://www.gnu.org/licenses/>.
30 #include "modules/invite.h"
35 ERR_UNAVAILRESOURCE = 437
46 KickedUser(User* user, unsigned int Delay)
48 , expire(ServerInstance->Time() + Delay)
53 typedef std::vector<KickedUser> KickedList;
55 mutable KickedList kicked;
58 const unsigned int delay;
60 KickRejoinData(unsigned int Delay) : delay(Delay) { }
62 bool canjoin(LocalUser* user) const
64 for (KickedList::iterator i = kicked.begin(); i != kicked.end(); )
67 if (rec.expire > ServerInstance->Time())
69 if (rec.uuid == user->uuid)
75 // Expired record, remove.
76 stdalgo::vector::swaperase(kicked, i);
86 // One user can be in the list multiple times if the user gets kicked, force joins
87 // (skipping OnUserPreJoin) and gets kicked again, but that's okay because canjoin()
88 // works correctly in this case as well
89 kicked.push_back(KickedUser(user, delay));
93 /** Handles channel mode +J
95 class KickRejoin : public ParamMode<KickRejoin, SimpleExtItem<KickRejoinData> >
97 const unsigned int max;
99 KickRejoin(Module* Creator)
100 : ParamMode<KickRejoin, SimpleExtItem<KickRejoinData> >(Creator, "kicknorejoin", 'J')
103 syntax = "<seconds>";
106 ModeAction OnSet(User* source, Channel* channel, std::string& parameter) CXX11_OVERRIDE
108 unsigned int v = ConvToNum<unsigned int>(parameter);
111 source->WriteNumeric(Numerics::InvalidModeParameter(channel, this, parameter));
112 return MODEACTION_DENY;
115 if (IS_LOCAL(source) && v > max)
118 ext.set(channel, new KickRejoinData(v));
119 return MODEACTION_ALLOW;
122 void SerializeParam(Channel* chan, const KickRejoinData* krd, std::string& out)
124 out.append(ConvToStr(krd->delay));
127 std::string GetModuleSettings() const
129 return ConvToStr(max);
133 class ModuleKickNoRejoin : public Module
145 ModResult OnUserPreJoin(LocalUser* user, Channel* chan, const std::string& cname, std::string& privs, const std::string& keygiven) CXX11_OVERRIDE
149 const KickRejoinData* data = kr.ext.get(chan);
150 if ((data) && !invapi->IsInvited(user, chan) && (!data->canjoin(user)))
152 user->WriteNumeric(ERR_UNAVAILRESOURCE, chan->name, InspIRCd::Format("You must wait %u seconds after being kicked to rejoin (+J is set)", data->delay));
156 return MOD_RES_PASSTHRU;
159 void OnUserKick(User* source, Membership* memb, const std::string &reason, CUList& excepts) CXX11_OVERRIDE
161 if ((!IS_LOCAL(memb->user)) || (source == memb->user))
164 KickRejoinData* data = kr.ext.get(memb->chan);
167 data->add(memb->user);
171 Version GetVersion() CXX11_OVERRIDE
173 return Version("Adds channel mode J (kicknorejoin) which prevents users from rejoining after being kicked from a channel.", VF_VENDOR | VF_COMMON, kr.GetModuleSettings());
177 MODULE_INIT(ModuleKickNoRejoin)