2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2013, 2018-2019 Sadie Powell <sadie@witchery.services>
5 * Copyright (C) 2013 Daniel Vassdal <shutter@canternet.org>
6 * Copyright (C) 2012-2014, 2016 Attila Molnar <attilamolnar@hush.com>
7 * Copyright (C) 2012, 2019 Robby <robby@chatbelgie.be>
8 * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
9 * Copyright (C) 2007, 2010 Craig Edwards <brain@inspircd.org>
10 * Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
11 * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
12 * Copyright (C) 2006 jamie <jamie@e03df62e-2008-0410-955e-edbf42e46eb7>
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/>.
32 class CommandSajoin : public Command
35 CommandSajoin(Module* Creator) : Command(Creator,"SAJOIN", 1)
37 allow_empty_last_param = false;
38 flags_needed = 'o'; syntax = "[<nick>] <channel>[,<channel>]+";
39 TRANSLATE2(TR_NICK, TR_TEXT);
42 CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE
44 const unsigned int channelindex = (parameters.size() > 1) ? 1 : 0;
45 if (CommandParser::LoopCall(user, this, parameters, channelindex))
48 const std::string& channel = parameters[channelindex];
49 const std::string& nickname = parameters.size() > 1 ? parameters[0] : user->nick;
51 User* dest = ServerInstance->FindNick(nickname);
52 if ((dest) && (dest->registered == REG_ALL))
54 if (user != dest && !user->HasPrivPermission("users/sajoin-others"))
56 user->WriteNotice("*** You are not allowed to /SAJOIN other users (the privilege users/sajoin-others is needed to /SAJOIN others).");
60 if (dest->server->IsULine())
62 user->WriteNumeric(ERR_NOPRIVILEGES, "Cannot use an SA command on a U-lined client");
65 if (IS_LOCAL(user) && !ServerInstance->IsChannel(channel))
67 /* we didn't need to check this for each character ;) */
68 user->WriteNotice("*** Invalid characters in channel name or name too long");
72 Channel* chan = ServerInstance->FindChan(channel);
73 if ((chan) && (chan->HasUser(dest)))
75 user->WriteRemoteNotice("*** " + dest->nick + " is already on " + channel);
79 /* For local users, we call Channel::JoinUser which may create a channel and set its TS.
80 * For non-local users, we just return CMD_SUCCESS, knowing this will propagate it where it needs to be
81 * and then that server will handle the command.
83 LocalUser* localuser = IS_LOCAL(dest);
86 chan = Channel::JoinUser(localuser, channel, true);
89 ServerInstance->SNO->WriteGlobalSno('a', user->nick+" used SAJOIN to make "+dest->nick+" join "+channel);
94 user->WriteNotice("*** Could not join "+dest->nick+" to "+channel);
105 user->WriteNotice("*** No such nickname: '" + nickname + "'");
110 RouteDescriptor GetRouting(User* user, const Params& parameters) CXX11_OVERRIDE
112 return ROUTE_OPT_UCAST(parameters[0]);
116 class ModuleSajoin : public Module
125 Version GetVersion() CXX11_OVERRIDE
127 return Version("Provides the SAJOIN command, allows opers to force-join users to channels", VF_OPTCOMMON | VF_VENDOR);
131 MODULE_INIT(ModuleSajoin)