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