]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands/cmd_part.cpp
aaff9e30fb300f35fd5e32463bd5d20ebae079a4
[user/henk/code/inspircd.git] / src / commands / cmd_part.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 "commands/cmd_part.h"
16
17 extern "C" DllExport Command* init_command(InspIRCd* Instance)
18 {
19         return new CommandPart(Instance);
20 }
21
22 CmdResult CommandPart::Handle (const char** parameters, int pcnt, User *user)
23 {
24         std::string reason;
25
26         if (IS_LOCAL(user))
27         {
28                 if (*ServerInstance->Config->FixedPart)
29                         reason = ServerInstance->Config->FixedPart;
30                 else
31                 {
32                         if (pcnt > 1)
33                                 reason = ServerInstance->Config->PrefixPart + std::string(parameters[1]) + ServerInstance->Config->SuffixPart;
34                         else
35                                 reason = "";
36                 }
37         }
38         else
39         {
40                 reason = pcnt ? parameters[1] : "";
41         }
42
43         if (ServerInstance->Parser->LoopCall(user, this, parameters, pcnt, 0))
44                 return CMD_SUCCESS;
45
46         Channel* c = ServerInstance->FindChan(parameters[0]);
47         
48         if (c)
49         {
50                 const char *rreason = reason.empty() ? NULL : reason.c_str();
51                 if (!c->PartUser(user, rreason))
52                         /* Arse, who stole our channel! :/ */
53                         delete c;
54         }
55         else
56         {
57                 user->WriteServ( "401 %s %s :No such channel", user->nick, parameters[0]);
58                 return CMD_FAILURE;
59         }
60
61         return CMD_SUCCESS;
62 }