]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/cmd_kick.cpp
Implement feature in bug #395 reported by stealth, and tidy up a bit
[user/henk/code/inspircd.git] / src / cmd_kick.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 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 "users.h"
16 #include "inspircd.h"
17 #include "commands/cmd_kick.h"
18
19 extern "C" DllExport command_t* init_command(InspIRCd* Instance)
20 {
21         return new cmd_kick(Instance);
22 }
23
24 /** Handle /KICK
25  */
26 CmdResult cmd_kick::Handle (const char** parameters, int pcnt, userrec *user)
27 {
28         char reason[MAXKICK];
29         chanrec* c = ServerInstance->FindChan(parameters[0]);
30         userrec* u = ServerInstance->FindNick(parameters[1]);
31
32         if (!u || !c)
33         {
34                 user->WriteServ( "401 %s %s :No such nick/channel", user->nick, u ? parameters[0] : parameters[1]);
35                 return CMD_FAILURE;
36         }
37
38         if ((IS_LOCAL(user)) && (!c->HasUser(user)) && (!ServerInstance->ULine(user->server)))
39         {
40                 user->WriteServ( "442 %s %s :You're not on that channel!", user->nick, parameters[0]);
41                 return CMD_FAILURE;
42         }
43
44         if (pcnt > 2)
45         {
46                 strlcpy(reason, parameters[2], MAXKICK - 1);
47         }
48         else
49         {
50                 strlcpy(reason, user->nick, MAXKICK - 1);
51         }
52
53         if (!c->KickUser(user, u, reason))
54                 /* Nobody left here, delete the chanrec */
55                 delete c;
56
57         return CMD_SUCCESS;
58 }