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