]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_sajoin.cpp
Merge branch 'insp20' into master.
[user/henk/code/inspircd.git] / src / modules / m_sajoin.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
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>
7  *
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.
11  *
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
15  * details.
16  *
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/>.
19  */
20
21
22 #include "inspircd.h"
23
24 /** Handle /SAJOIN
25  */
26 class CommandSajoin : public Command
27 {
28  public:
29         CommandSajoin(Module* Creator) : Command(Creator,"SAJOIN", 1)
30         {
31                 allow_empty_last_param = false;
32                 flags_needed = 'o'; syntax = "[<nick>] <channel>[,<channel>]";
33                 TRANSLATE2(TR_NICK, TR_TEXT);
34         }
35
36         CmdResult Handle(const std::vector<std::string>& parameters, User* user) CXX11_OVERRIDE
37         {
38                 const unsigned int channelindex = (parameters.size() > 1) ? 1 : 0;
39                 if (CommandParser::LoopCall(user, this, parameters, channelindex))
40                         return CMD_FAILURE;
41
42                 const std::string& channel = parameters[channelindex];
43                 const std::string& nickname = parameters.size() > 1 ? parameters[0] : user->nick;
44
45                 User* dest = ServerInstance->FindNick(nickname);
46                 if ((dest) && (dest->registered == REG_ALL))
47                 {
48                         if (user != dest && !user->HasPrivPermission("users/sajoin-others", false))
49                         {
50                                 user->WriteNotice("*** You are not allowed to /SAJOIN other users (the privilege users/sajoin-others is needed to /SAJOIN others).");
51                                 return CMD_FAILURE;
52                         }
53
54                         if (dest->server->IsULine())
55                         {
56                                 user->WriteNumeric(ERR_NOPRIVILEGES, "Cannot use an SA command on a u-lined client");
57                                 return CMD_FAILURE;
58                         }
59                         if (IS_LOCAL(user) && !ServerInstance->IsChannel(channel))
60                         {
61                                 /* we didn't need to check this for each character ;) */
62                                 user->WriteNotice("*** Invalid characters in channel name or name too long");
63                                 return CMD_FAILURE;
64                         }
65
66                         Channel* chan = ServerInstance->FindChan(channel);
67                         if ((chan) && (chan->HasUser(dest)))
68                         {
69                                 user->WriteRemoteNotice("*** " + dest->nick + " is already on " + channel);
70                                 return CMD_FAILURE;
71                         }
72
73                         /* For local users, we call Channel::JoinUser which may create a channel and set its TS.
74                          * For non-local users, we just return CMD_SUCCESS, knowing this will propagate it where it needs to be
75                          * and then that server will handle the command.
76                          */
77                         LocalUser* localuser = IS_LOCAL(dest);
78                         if (localuser)
79                         {
80                                 chan = Channel::JoinUser(localuser, channel, true);
81                                 if (chan)
82                                 {
83                                         ServerInstance->SNO->WriteGlobalSno('a', user->nick+" used SAJOIN to make "+dest->nick+" join "+channel);
84                                         return CMD_SUCCESS;
85                                 }
86                                 else
87                                 {
88                                         user->WriteNotice("*** Could not join "+dest->nick+" to "+channel);
89                                         return CMD_FAILURE;
90                                 }
91                         }
92                         else
93                         {
94                                 return CMD_SUCCESS;
95                         }
96                 }
97                 else
98                 {
99                         user->WriteNotice("*** No such nickname "+nickname);
100                         return CMD_FAILURE;
101                 }
102         }
103
104         RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters) CXX11_OVERRIDE
105         {
106                 return ROUTE_OPT_UCAST(parameters[0]);
107         }
108 };
109
110 class ModuleSajoin : public Module
111 {
112         CommandSajoin cmd;
113  public:
114         ModuleSajoin()
115                 : cmd(this)
116         {
117         }
118
119         Version GetVersion() CXX11_OVERRIDE
120         {
121                 return Version("Provides command SAJOIN to allow opers to force-join users to channels", VF_OPTCOMMON | VF_VENDOR);
122         }
123 };
124
125 MODULE_INIT(ModuleSajoin)