]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands/cmd_kick.cpp
c7524ab4a974113ea4e14def75b135d15c4fdfba
[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://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 #include "commands/cmd_kick.h"
16
17 extern "C" DllExport Command* init_command(InspIRCd* Instance)
18 {
19         return new CommandKick(Instance);
20 }
21
22 /** Handle /KICK
23  */
24 CmdResult CommandKick::Handle (const std::vector<std::string>& parameters, User *user)
25 {
26         std::string reason;
27         Channel* c = ServerInstance->FindChan(parameters[0]);
28         User* u = ServerInstance->FindNick(parameters[1]);
29
30         if (ServerInstance->Parser->LoopCall(user, this, parameters, 1))
31                 return CMD_SUCCESS;
32
33         if (!u || !c)
34         {
35                 user->WriteServ( "401 %s %s :No such nick/channel", user->nick.c_str(), u ? parameters[0].c_str() : parameters[1].c_str());
36                 return CMD_FAILURE;
37         }
38
39         if ((IS_LOCAL(user)) && (!c->HasUser(user)) && (!ServerInstance->ULine(user->server)))
40         {
41                 user->WriteServ( "442 %s %s :You're not on that channel!", user->nick.c_str(), parameters[0].c_str());
42                 return CMD_FAILURE;
43         }
44
45         if (parameters.size() > 2)
46         {
47                 reason.assign(parameters[2], 0, ServerInstance->Config->Limits.MaxKick);
48         }
49         else
50         {
51                 reason.assign(user->nick, 0, ServerInstance->Config->Limits.MaxKick);
52         }
53
54         if (!c->KickUser(user, u, reason.c_str()))
55                 /* Nobody left here, delete the Channel */
56                 delete c;
57
58         return CMD_SUCCESS;
59 }