]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_sakick.cpp
Add initial query support to m_mysql [patch by Athenon]
[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, Module* Creator) : Command(Instance, Creator,"SAKICK", "o", 2, 3, false, 0)
24         {
25                 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                                 if (!channel->ServerKickUser(dest, reason, servername))
60                                         delete channel;
61
62                                 Channel *n = ServerInstance->FindChan(parameters[1]);
63                                 if (n && n->HasUser(dest))
64                                 {
65                                         /* Sort-of-bug: If the command was issued remotely, this message won't be sent */
66                                         user->WriteServ("NOTICE %s :*** Unable to kick %s from %s", user->nick.c_str(), dest->nick.c_str(), parameters[0].c_str());
67                                         return CMD_FAILURE;
68                                 }
69                         }
70
71                         if (IS_LOCAL(user))
72                         {
73                                 /* Locally issued command; send the snomasks */
74                                 ServerInstance->SNO->WriteGlobalSno('a', std::string(user->nick) + " SAKICKed " + dest->nick + " on " + parameters[0]);
75                         }
76
77                         return CMD_SUCCESS;
78                 }
79                 else
80                 {
81                         user->WriteServ("NOTICE %s :*** Invalid nickname or channel", user->nick.c_str());
82                 }
83
84                 return CMD_FAILURE;
85         }
86 };
87
88 class ModuleSakick : public Module
89 {
90         CommandSakick cmd;
91  public:
92         ModuleSakick(InspIRCd* Me)
93                 : Module(Me), cmd(Me, this)
94         {
95                 ServerInstance->AddCommand(&cmd);
96         }
97
98         virtual ~ModuleSakick()
99         {
100         }
101
102         virtual Version GetVersion()
103         {
104                 return Version("$Id$", VF_COMMON|VF_VENDOR, API_VERSION);
105         }
106
107 };
108
109 MODULE_INIT(ModuleSakick)
110