2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
5 * Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
6 * Copyright (C) 2004-2005, 2007 Craig Edwards <craigedwards@brainbox.cc>
8 * This file is part of InspIRCd. InspIRCd is free software: you can
9 * redistribute it and/or modify it under the terms of the GNU General Public
10 * License as published by the Free Software Foundation, version 2.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
26 class CommandSajoin : public Command
29 CommandSajoin(Module* Creator) : Command(Creator,"SAJOIN", 1)
31 allow_empty_last_param = false;
32 flags_needed = 'o'; Penalty = 0; syntax = "[<nick>] <channel>";
33 TRANSLATE2(TR_NICK, TR_TEXT);
36 CmdResult Handle (const std::vector<std::string>& parameters, User *user)
38 const std::string& channel = parameters.size() > 1 ? parameters[1] : parameters[0];
39 const std::string& nickname = parameters.size() > 1 ? parameters[0] : user->nick;
41 User* dest = ServerInstance->FindNick(nickname);
42 if ((dest) && (dest->registered == REG_ALL))
44 if (user != dest && !user->HasPrivPermission("users/sajoin-others", false))
46 user->WriteNotice("*** You are not allowed to /SAJOIN other users (the privilege users/sajoin-others is needed to /SAJOIN others).");
50 if (dest->server->IsULine())
52 user->WriteNumeric(ERR_NOPRIVILEGES, ":Cannot use an SA command on a u-lined client");
55 if (IS_LOCAL(user) && !ServerInstance->IsChannel(channel))
57 /* we didn't need to check this for each character ;) */
58 user->WriteNotice("*** Invalid characters in channel name or name too long");
62 /* For local users, we call Channel::JoinUser which may create a channel and set its TS.
63 * For non-local users, we just return CMD_SUCCESS, knowing this will propagate it where it needs to be
64 * and then that server will handle the command.
66 LocalUser* localuser = IS_LOCAL(dest);
69 Channel* n = Channel::JoinUser(localuser, channel, true);
70 if (n && n->HasUser(dest))
72 ServerInstance->SNO->WriteGlobalSno('a', user->nick+" used SAJOIN to make "+dest->nick+" join "+channel);
77 user->WriteNotice("*** Could not join "+dest->nick+" to "+channel);
88 user->WriteNotice("*** No such nickname "+nickname);
93 RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
95 User* dest = ServerInstance->FindNick(parameters[0]);
97 return ROUTE_OPT_UCAST(dest->server);
98 return ROUTE_LOCALONLY;
102 class ModuleSajoin : public Module
111 Version GetVersion() CXX11_OVERRIDE
113 return Version("Provides command SAJOIN to allow opers to force-join users to channels", VF_OPTCOMMON | VF_VENDOR);
117 MODULE_INIT(ModuleSajoin)