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