]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_sakick.cpp
[Taros] Add m_sakick.so
[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://www.inspircd.org/wiki/index.php/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, true, servername))
61                                         delete channel;
62
63                                 Channel* n = ServerInstance->FindChan(parameters[1]);
64                                 if (!n)
65                                 {
66                                         ServerInstance->SNO->WriteToSnoMask('A', std::string(user->nick)+" SAKICKed "+dest->nick+" on "+parameters[0]);
67                                         return CMD_SUCCESS;
68                                 }
69                                 else
70                                 {
71                                         if (!n->HasUser(dest))
72                                         {
73                                                 ServerInstance->SNO->WriteToSnoMask('A', std::string(user->nick)+" SAKICKed "+dest->nick+" on "+parameters[0]);
74                                                 return CMD_SUCCESS;
75                                         }
76                                         else
77                                         {
78                                                 user->WriteServ("NOTICE %s :*** Unable to kick %s from %s",user->nick.c_str(), dest->nick.c_str(), parameters[0].c_str());
79                                                 return CMD_FAILURE;
80                                         }
81                                 }
82                         }
83                         else
84                         {
85                                 ServerInstance->SNO->WriteToSnoMask('A', std::string(user->nick)+" sent remote SAKICK to kick "+dest->nick+" from "+parameters[0]);
86                         }
87
88                         return CMD_SUCCESS;
89                 }
90                 else
91                 {
92                         user->WriteServ("NOTICE %s :*** Invalid nickname or channel", user->nick.c_str());
93                 }
94
95                 return CMD_FAILURE;
96         }
97 };
98
99 class ModuleSakick : public Module
100 {
101         CommandSakick*  mycommand;
102  public:
103         ModuleSakick(InspIRCd* Me)
104                 : Module(Me)
105         {
106
107                 mycommand = new CommandSakick(ServerInstance);
108                 ServerInstance->AddCommand(mycommand);
109
110         }
111
112         virtual ~ModuleSakick()
113         {
114         }
115
116         virtual Version GetVersion()
117         {
118                 return Version("$Id$", VF_VENDOR, API_VERSION);
119         }
120
121 };
122
123 MODULE_INIT(ModuleSakick)
124