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