]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_sakick.cpp
201bb4259f94086a2b508d54621d22ea645d9af0
[user/henk/code/inspircd.git] / src / modules / m_sakick.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2013, 2018 Sadie Powell <sadie@witchery.services>
5  *   Copyright (C) 2012-2014, 2016 Attila Molnar <attilamolnar@hush.com>
6  *   Copyright (C) 2012, 2019 Robby <robby@chatbelgie.be>
7  *   Copyright (C) 2010 Craig Edwards <brain@inspircd.org>
8  *   Copyright (C) 2009 John Brooks <special@inspircd.org>
9  *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
10  *
11  * This file is part of InspIRCd.  InspIRCd is free software: you can
12  * redistribute it and/or modify it under the terms of the GNU General Public
13  * License as published by the Free Software Foundation, version 2.
14  *
15  * This program is distributed in the hope that it will be useful, but WITHOUT
16  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22  */
23
24
25 #include "inspircd.h"
26
27 /** Handle /SAKICK
28  */
29 class CommandSakick : public Command
30 {
31  public:
32         CommandSakick(Module* Creator) : Command(Creator,"SAKICK", 2, 3)
33         {
34                 flags_needed = 'o';
35                 syntax = "<channel> <nick> [:<reason>]";
36                 TRANSLATE3(TR_TEXT, TR_NICK, TR_TEXT);
37         }
38
39         CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE
40         {
41                 User* dest = ServerInstance->FindNick(parameters[1]);
42                 Channel* channel = ServerInstance->FindChan(parameters[0]);
43
44                 if ((dest) && (dest->registered == REG_ALL) && (channel))
45                 {
46                         const std::string& reason = (parameters.size() > 2) ? parameters[2] : dest->nick;
47
48                         if (dest->server->IsULine())
49                         {
50                                 user->WriteNumeric(ERR_NOPRIVILEGES, "Cannot use an SA command on a U-lined client");
51                                 return CMD_FAILURE;
52                         }
53
54                         if (!channel->HasUser(dest))
55                         {
56                                 user->WriteNotice("*** " + dest->nick + " is not on " + channel->name);
57                                 return CMD_FAILURE;
58                         }
59
60                         /* For local clients, directly kick them. For remote clients,
61                          * just return CMD_SUCCESS knowing the protocol module will route the SAKICK to the user's
62                          * local server and that will kick them instead.
63                          */
64                         if (IS_LOCAL(dest))
65                         {
66                                 // Target is on this server, kick them and send the snotice
67                                 channel->KickUser(ServerInstance->FakeClient, dest, reason);
68                                 ServerInstance->SNO->WriteGlobalSno('a', user->nick + " SAKICKed " + dest->nick + " on " + channel->name);
69                         }
70
71                         return CMD_SUCCESS;
72                 }
73                 else
74                 {
75                         user->WriteNotice("*** Invalid nickname or channel");
76                 }
77
78                 return CMD_FAILURE;
79         }
80
81         RouteDescriptor GetRouting(User* user, const Params& parameters) CXX11_OVERRIDE
82         {
83                 return ROUTE_OPT_UCAST(parameters[1]);
84         }
85 };
86
87 class ModuleSakick : public Module
88 {
89         CommandSakick cmd;
90  public:
91         ModuleSakick()
92                 : cmd(this)
93         {
94         }
95
96         Version GetVersion() CXX11_OVERRIDE
97         {
98                 return Version("Adds the /SAKICK command which allows server operators to kick users from a channel without having any privileges in the channel.", VF_OPTCOMMON|VF_VENDOR);
99         }
100 };
101
102 MODULE_INIT(ModuleSakick)