]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_sakick.cpp
Fix m_sakick to properly send local/global snomasks like other modules, instead of...
[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_NICK, TR_TEXT, 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                                         /* Success; send the global snomask */
67                                         ServerInstance->PI->SendSNONotice("A", std::string(user->nick) + " SAKICKed " + dest->nick + " on " + parameters[0]);
68                                 }
69                                 else
70                                 {
71                                         /* Sort-of-bug: If the command was issued remotely, this message won't be sent */
72                                         user->WriteServ("NOTICE %s :*** Unable to kick %s from %s", user->nick.c_str(), dest->nick.c_str(), parameters[0].c_str());
73                                         return CMD_FAILURE;
74                                 }
75                         }
76
77                         if (IS_LOCAL(user))
78                         {
79                                 /* Locally issued command; send the local snomask */
80                                 ServerInstance->SNO->WriteToSnoMask('a', std::string(user->nick) + " SAKICKed " + dest->nick + " on " + parameters[0]);
81                         }
82
83                         return CMD_SUCCESS;
84                 }
85                 else
86                 {
87                         user->WriteServ("NOTICE %s :*** Invalid nickname or channel", user->nick.c_str());
88                 }
89
90                 return CMD_FAILURE;
91         }
92 };
93
94 class ModuleSakick : public Module
95 {
96         CommandSakick*  mycommand;
97  public:
98         ModuleSakick(InspIRCd* Me)
99                 : Module(Me)
100         {
101
102                 mycommand = new CommandSakick(ServerInstance);
103                 ServerInstance->AddCommand(mycommand);
104
105         }
106
107         virtual ~ModuleSakick()
108         {
109         }
110
111         virtual Version GetVersion()
112         {
113                 return Version("$Id$", VF_COMMON|VF_VENDOR, API_VERSION);
114         }
115
116 };
117
118 MODULE_INIT(ModuleSakick)
119