2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2017 B00mX0r <b00mx0r@aureus.pw>
5 * Copyright (C) 2013, 2018-2020 Sadie Powell <sadie@witchery.services>
6 * Copyright (C) 2012-2016 Attila Molnar <attilamolnar@hush.com>
7 * Copyright (C) 2012 Robby <robby@chatbelgie.be>
8 * Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
9 * Copyright (C) 2007-2008 Robin Burchell <robin+git@viroteck.net>
10 * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
11 * Copyright (C) 2006, 2010 Craig Edwards <brain@inspircd.org>
13 * This file is part of InspIRCd. InspIRCd is free software: you can
14 * redistribute it and/or modify it under the terms of the GNU General Public
15 * License as published by the Free Software Foundation, version 2.
17 * This program is distributed in the hope that it will be useful, but WITHOUT
18 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <http://www.gnu.org/licenses/>.
28 #include "modules/invite.h"
33 ERR_INVITEREMOVED = 494,
40 class CommandUninvite : public Command
44 CommandUninvite(Module* Creator)
45 : Command(Creator, "UNINVITE", 2)
48 syntax = "<nick> <channel>";
49 TRANSLATE2(TR_NICK, TR_TEXT);
52 CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE
56 u = ServerInstance->FindNickOnly(parameters[0]);
58 u = ServerInstance->FindNick(parameters[0]);
60 Channel* c = ServerInstance->FindChan(parameters[1]);
62 if ((!c) || (!u) || (u->registered != REG_ALL))
66 user->WriteNumeric(Numerics::NoSuchChannel(parameters[1]));
70 user->WriteNumeric(Numerics::NoSuchNick(parameters[0]));
78 if (c->GetPrefixValue(user) < HALFOP_VALUE)
80 user->WriteNumeric(ERR_CHANOPRIVSNEEDED, c->name, InspIRCd::Format("You must be a channel %soperator", c->GetPrefixValue(u) == HALFOP_VALUE ? "" : "half-"));
85 /* Servers remember invites only for their local users, so act
86 * only if the target is local. Otherwise the command will be
87 * passed to the target users server.
89 LocalUser* lu = IS_LOCAL(u);
92 // XXX: The source of the numeric we send must be the server of the user doing the /UNINVITE,
93 // so they don't see where the target user is connected to
94 if (!invapi->Remove(lu, c))
96 Numeric::Numeric n(ERR_NOTINVITED);
97 n.SetServer(user->server);
98 n.push(u->nick).push(c->name).push(InspIRCd::Format("Is not invited to channel %s", c->name.c_str()));
99 user->WriteRemoteNumeric(n);
103 Numeric::Numeric n(ERR_INVITEREMOVED);
104 n.SetServer(user->server);
105 n.push(c->name).push(u->nick).push("Uninvited");
106 user->WriteRemoteNumeric(n);
108 lu->WriteNumeric(RPL_UNINVITED, InspIRCd::Format("You were uninvited from %s by %s", c->name.c_str(), user->nick.c_str()));
109 c->WriteRemoteNotice(InspIRCd::Format("*** %s uninvited %s.", user->nick.c_str(), u->nick.c_str()));
115 RouteDescriptor GetRouting(User* user, const Params& parameters) CXX11_OVERRIDE
117 return ROUTE_OPT_UCAST(parameters[0]);
121 class ModuleUninvite : public Module
127 ModuleUninvite() : cmd(this)
131 Version GetVersion() CXX11_OVERRIDE
133 return Version("Adds the /UNINVITE command which allows users who have invited another user to a channel to withdraw their invite.", VF_VENDOR | VF_OPTCOMMON);
137 MODULE_INIT(ModuleUninvite)