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