]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands/cmd_kick.cpp
Fix routing for normal core commands like QUIT
[user/henk/code/inspircd.git] / src / commands / cmd_kick.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 /** Handle /KICK. These command handlers can be reloaded by the core,
17  * and handle basic RFC1459 commands. Commands within modules work
18  * the same way, however, they can be fully unloaded, where these
19  * may not.
20  */
21 class CommandKick : public Command
22 {
23  public:
24         /** Constructor for kick.
25          */
26         CommandKick ( Module* parent) : Command(parent,"KICK",2,3) { syntax = "<channel> <nick>{,<nick>} [<reason>]"; }
27         /** Handle command.
28          * @param parameters The parameters to the comamnd
29          * @param pcnt The number of parameters passed to teh command
30          * @param user The user issuing the command
31          * @return A value from CmdResult to indicate command success or failure.
32          */
33         CmdResult Handle(const std::vector<std::string>& parameters, User *user);
34 };
35
36
37 /** Handle /KICK
38  */
39 CmdResult CommandKick::Handle (const std::vector<std::string>& parameters, User *user)
40 {
41         std::string reason;
42         Channel* c = ServerInstance->FindChan(parameters[0]);
43         User* u = ServerInstance->FindNick(parameters[1]);
44
45         if (ServerInstance->Parser->LoopCall(user, this, parameters, 1))
46                 return CMD_SUCCESS;
47
48         if (!u || !c)
49         {
50                 user->WriteServ( "401 %s %s :No such nick/channel", user->nick.c_str(), u ? parameters[0].c_str() : parameters[1].c_str());
51                 return CMD_FAILURE;
52         }
53
54         if ((IS_LOCAL(user)) && (!c->HasUser(user)) && (!ServerInstance->ULine(user->server)))
55         {
56                 user->WriteServ( "442 %s %s :You're not on that channel!", user->nick.c_str(), parameters[0].c_str());
57                 return CMD_FAILURE;
58         }
59
60         if (parameters.size() > 2)
61         {
62                 reason.assign(parameters[2], 0, ServerInstance->Config->Limits.MaxKick);
63         }
64         else
65         {
66                 reason.assign(user->nick, 0, ServerInstance->Config->Limits.MaxKick);
67         }
68
69         if (!c->KickUser(user, u, reason.c_str()))
70                 /* Nobody left here, delete the Channel */
71                 delete c;
72
73         return CMD_SUCCESS;
74 }
75
76 COMMAND_INIT(CommandKick)