]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_sakick.cpp
Automatically register ServiceProviders created by modules
[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'; Penalty = 0; syntax = "<channel> <nick> [reason]";
31                 TRANSLATE3(TR_TEXT, TR_NICK, TR_TEXT);
32         }
33
34         CmdResult Handle (const std::vector<std::string>& parameters, User *user)
35         {
36                 User* dest = ServerInstance->FindNick(parameters[1]);
37                 Channel* channel = ServerInstance->FindChan(parameters[0]);
38                 const char* reason = "";
39
40                 if ((dest) && (dest->registered == REG_ALL) && (channel))
41                 {
42                         if (parameters.size() > 2)
43                         {
44                                 reason = parameters[2].c_str();
45                         }
46                         else
47                         {
48                                 reason = dest->nick.c_str();
49                         }
50
51                         if (ServerInstance->ULine(dest->server))
52                         {
53                                 user->WriteNumeric(ERR_NOPRIVILEGES, "%s :Cannot use an SA command on a u-lined client", user->nick.c_str());
54                                 return CMD_FAILURE;
55                         }
56
57                         /* For local clients, directly kick them. For remote clients,
58                          * just return CMD_SUCCESS knowing the protocol module will route the SAKICK to the user's
59                          * local server and that will kick them instead.
60                          */
61                         if (IS_LOCAL(dest))
62                         {
63                                 channel->KickUser(ServerInstance->FakeClient, dest, reason);
64
65                                 Channel *n = ServerInstance->FindChan(parameters[1]);
66                                 if (n && n->HasUser(dest))
67                                 {
68                                         /* Sort-of-bug: If the command was issued remotely, this message won't be sent */
69                                         user->WriteNotice("*** Unable to kick " + dest->nick + " from " + parameters[0]);
70                                         return CMD_FAILURE;
71                                 }
72                         }
73
74                         if (IS_LOCAL(user))
75                         {
76                                 /* Locally issued command; send the snomasks */
77                                 ServerInstance->SNO->WriteGlobalSno('a', user->nick + " SAKICKed " + dest->nick + " on " + parameters[0]);
78                         }
79
80                         return CMD_SUCCESS;
81                 }
82                 else
83                 {
84                         user->WriteNotice("*** Invalid nickname or channel");
85                 }
86
87                 return CMD_FAILURE;
88         }
89
90         RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
91         {
92                 User* dest = ServerInstance->FindNick(parameters[1]);
93                 if (dest)
94                         return ROUTE_OPT_UCAST(dest->server);
95                 return ROUTE_LOCALONLY;
96         }
97 };
98
99 class ModuleSakick : public Module
100 {
101         CommandSakick cmd;
102  public:
103         ModuleSakick()
104                 : cmd(this)
105         {
106         }
107
108         Version GetVersion() CXX11_OVERRIDE
109         {
110                 return Version("Provides a SAKICK command", VF_OPTCOMMON|VF_VENDOR);
111         }
112 };
113
114 MODULE_INIT(ModuleSakick)