]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_sajoin.cpp
Merge insp20
[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", 2)
30         {
31                 allow_empty_last_param = false;
32                 flags_needed = 'o'; Penalty = 0; syntax = "<nick> <channel>";
33                 TRANSLATE2(TR_NICK, TR_TEXT);
34         }
35
36         CmdResult Handle (const std::vector<std::string>& parameters, User *user)
37         {
38                 User* dest = ServerInstance->FindNick(parameters[0]);
39                 if ((dest) && (dest->registered == REG_ALL))
40                 {
41                         if (dest->server->IsULine())
42                         {
43                                 user->WriteNumeric(ERR_NOPRIVILEGES, ":Cannot use an SA command on a u-lined client");
44                                 return CMD_FAILURE;
45                         }
46                         if (IS_LOCAL(user) && !ServerInstance->IsChannel(parameters[1]))
47                         {
48                                 /* we didn't need to check this for each character ;) */
49                                 user->WriteNotice("*** Invalid characters in channel name or name too long");
50                                 return CMD_FAILURE;
51                         }
52
53                         /* For local users, we call Channel::JoinUser which may create a channel and set its TS.
54                          * For non-local users, we just return CMD_SUCCESS, knowing this will propagate it where it needs to be
55                          * and then that server will handle the command.
56                          */
57                         LocalUser* localuser = IS_LOCAL(dest);
58                         if (localuser)
59                         {
60                                 Channel* n = Channel::JoinUser(localuser, parameters[1], true);
61                                 if (n && n->HasUser(dest))
62                                 {
63                                         ServerInstance->SNO->WriteGlobalSno('a', user->nick+" used SAJOIN to make "+dest->nick+" join "+parameters[1]);
64                                         return CMD_SUCCESS;
65                                 }
66                                 else
67                                 {
68                                         user->WriteNotice("*** Could not join "+dest->nick+" to "+parameters[1]);
69                                         return CMD_FAILURE;
70                                 }
71                         }
72                         else
73                         {
74                                 return CMD_SUCCESS;
75                         }
76                 }
77                 else
78                 {
79                         user->WriteNotice("*** No such nickname "+parameters[0]);
80                         return CMD_FAILURE;
81                 }
82         }
83
84         RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
85         {
86                 User* dest = ServerInstance->FindNick(parameters[0]);
87                 if (dest)
88                         return ROUTE_OPT_UCAST(dest->server);
89                 return ROUTE_LOCALONLY;
90         }
91 };
92
93 class ModuleSajoin : public Module
94 {
95         CommandSajoin cmd;
96  public:
97         ModuleSajoin()
98                 : cmd(this)
99         {
100         }
101
102         Version GetVersion() CXX11_OVERRIDE
103         {
104                 return Version("Provides command SAJOIN to allow opers to force-join users to channels", VF_OPTCOMMON | VF_VENDOR);
105         }
106 };
107
108 MODULE_INIT(ModuleSajoin)