]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_sakick.cpp
d6b6e965bde7742470cd0c6d9b9ece44f8d7486e
[user/henk/code/inspircd.git] / src / modules / m_sakick.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15
16 /* $ModDesc: Provides a SAKICK command */
17
18 /** Handle /SAKICK
19  */
20 class CommandSakick : public Command
21 {
22  public:
23         CommandSakick(Module* Creator) : Command(Creator,"SAKICK", 2, 3)
24         {
25                 flags_needed = 'o'; Penalty = 0; syntax = "<channel> <nick> [reason]";
26                 TRANSLATE4(TR_TEXT, TR_NICK, TR_TEXT, TR_END);
27         }
28
29         CmdResult Handle (const std::vector<std::string>& parameters, User *user)
30         {
31                 User* dest = ServerInstance->FindNick(parameters[1]);
32                 Channel* channel = ServerInstance->FindChan(parameters[0]);
33                 const char* reason = "";
34
35                 if (dest && channel)
36                 {
37                         if (parameters.size() > 2)
38                         {
39                                 reason = parameters[2].c_str();
40                         }
41                         else
42                         {
43                                 reason = dest->nick.c_str();
44                         }
45
46                         if (ServerInstance->ULine(dest->server))
47                         {
48                                 user->WriteNumeric(ERR_NOPRIVILEGES, "%s :Cannot use an SA command on a u-lined client", user->nick.c_str());
49                                 return CMD_FAILURE;
50                         }
51
52                         /* For local clients, directly kick them. For remote clients,
53                          * just return CMD_SUCCESS knowing the protocol module will route the SAKICK to the user's
54                          * local server and that will kick them instead.
55                          */
56                         if (IS_LOCAL(dest))
57                         {
58                                 channel->KickUser(ServerInstance->FakeClient, dest, reason);
59
60                                 Channel *n = ServerInstance->FindChan(parameters[1]);
61                                 if (n && n->HasUser(dest))
62                                 {
63                                         /* Sort-of-bug: If the command was issued remotely, this message won't be sent */
64                                         user->WriteServ("NOTICE %s :*** Unable to kick %s from %s", user->nick.c_str(), dest->nick.c_str(), parameters[0].c_str());
65                                         return CMD_FAILURE;
66                                 }
67                         }
68
69                         if (IS_LOCAL(user))
70                         {
71                                 /* Locally issued command; send the snomasks */
72                                 ServerInstance->SNO->WriteGlobalSno('a', std::string(user->nick) + " SAKICKed " + dest->nick + " on " + parameters[0]);
73                         }
74
75                         return CMD_SUCCESS;
76                 }
77                 else
78                 {
79                         user->WriteServ("NOTICE %s :*** Invalid nickname or channel", user->nick.c_str());
80                 }
81
82                 return CMD_FAILURE;
83         }
84
85         RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
86         {
87                 User* dest = ServerInstance->FindNick(parameters[1]);
88                 if (dest)
89                         return ROUTE_OPT_UCAST(dest->server);
90                 return ROUTE_LOCALONLY;
91         }
92 };
93
94 class ModuleSakick : public Module
95 {
96         CommandSakick cmd;
97  public:
98         ModuleSakick()
99                 : cmd(this)
100         {
101                 ServerInstance->AddCommand(&cmd);
102         }
103
104         virtual ~ModuleSakick()
105         {
106         }
107
108         virtual Version GetVersion()
109         {
110                 return Version("Provides a SAKICK command", VF_OPTCOMMON|VF_VENDOR);
111         }
112
113 };
114
115 MODULE_INIT(ModuleSakick)
116