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-2019 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>
14 * This file is part of InspIRCd. InspIRCd is free software: you can
15 * redistribute it and/or modify it under the terms of the GNU General Public
16 * License as published by the Free Software Foundation, version 2.
18 * This program is distributed in the hope that it will be useful, but WITHOUT
19 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
29 #include "modules/invite.h"
34 ERR_UNAVAILRESOURCE = 437
45 KickedUser(User* user, unsigned int Delay)
47 , expire(ServerInstance->Time() + Delay)
52 typedef std::vector<KickedUser> KickedList;
54 mutable KickedList kicked;
57 const unsigned int delay;
59 KickRejoinData(unsigned int Delay) : delay(Delay) { }
61 bool canjoin(LocalUser* user) const
63 for (KickedList::iterator i = kicked.begin(); i != kicked.end(); )
66 if (rec.expire > ServerInstance->Time())
68 if (rec.uuid == user->uuid)
74 // Expired record, remove.
75 stdalgo::vector::swaperase(kicked, i);
85 // One user can be in the list multiple times if the user gets kicked, force joins
86 // (skipping OnUserPreJoin) and gets kicked again, but that's okay because canjoin()
87 // works correctly in this case as well
88 kicked.push_back(KickedUser(user, delay));
92 /** Handles channel mode +J
94 class KickRejoin : public ParamMode<KickRejoin, SimpleExtItem<KickRejoinData> >
96 const unsigned int max;
98 KickRejoin(Module* Creator)
99 : ParamMode<KickRejoin, SimpleExtItem<KickRejoinData> >(Creator, "kicknorejoin", 'J')
102 syntax = "<seconds>";
105 ModeAction OnSet(User* source, Channel* channel, std::string& parameter) CXX11_OVERRIDE
107 unsigned int v = ConvToNum<unsigned int>(parameter);
110 source->WriteNumeric(Numerics::InvalidModeParameter(channel, this, parameter));
111 return MODEACTION_DENY;
114 if (IS_LOCAL(source) && v > max)
117 ext.set(channel, new KickRejoinData(v));
118 return MODEACTION_ALLOW;
121 void SerializeParam(Channel* chan, const KickRejoinData* krd, std::string& out)
123 out.append(ConvToStr(krd->delay));
126 std::string GetModuleSettings() const
128 return ConvToStr(max);
132 class ModuleKickNoRejoin : public Module
144 ModResult OnUserPreJoin(LocalUser* user, Channel* chan, const std::string& cname, std::string& privs, const std::string& keygiven) CXX11_OVERRIDE
148 const KickRejoinData* data = kr.ext.get(chan);
149 if ((data) && !invapi->IsInvited(user, chan) && (!data->canjoin(user)))
151 user->WriteNumeric(ERR_UNAVAILRESOURCE, chan, InspIRCd::Format("You must wait %u seconds after being kicked to rejoin (+J is set)", data->delay));
155 return MOD_RES_PASSTHRU;
158 void OnUserKick(User* source, Membership* memb, const std::string &reason, CUList& excepts) CXX11_OVERRIDE
160 if ((!IS_LOCAL(memb->user)) || (source == memb->user))
163 KickRejoinData* data = kr.ext.get(memb->chan);
166 data->add(memb->user);
170 Version GetVersion() CXX11_OVERRIDE
172 return Version("Adds channel mode J (kicknorejoin) which prevents users from rejoining after being kicked from a channel.", VF_VENDOR | VF_COMMON, kr.GetModuleSettings());
176 MODULE_INIT(ModuleKickNoRejoin)