]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/coremods/core_user/cmd_part.cpp
b8395f43ef43e01b6275a0b7d15e6520d16eeabe
[user/henk/code/inspircd.git] / src / coremods / core_user / cmd_part.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5  *   Copyright (C) 2007-2008 Robin Burchell <robin+git@viroteck.net>
6  *
7  * This file is part of InspIRCd.  InspIRCd is free software: you can
8  * redistribute it and/or modify it under the terms of the GNU General Public
9  * License as published by the Free Software Foundation, version 2.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
14  * details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20
21 #include "inspircd.h"
22 #include "core_user.h"
23
24 CommandPart::CommandPart(Module* parent)
25         : Command(parent, "PART", 1, 2)
26 {
27         Penalty = 5;
28         syntax = "<channel>{,<channel>} [<reason>]";
29 }
30
31 CmdResult CommandPart::Handle (const std::vector<std::string>& parameters, User *user)
32 {
33         std::string reason;
34
35         if (IS_LOCAL(user))
36         {
37                 if (!ServerInstance->Config->FixedPart.empty())
38                         reason = ServerInstance->Config->FixedPart;
39                 else if (parameters.size() > 1)
40                         reason = ServerInstance->Config->PrefixPart + parameters[1] + ServerInstance->Config->SuffixPart;
41         }
42         else
43         {
44                 if (parameters.size() > 1)
45                         reason = parameters[1];
46         }
47
48         if (CommandParser::LoopCall(user, this, parameters, 0))
49                 return CMD_SUCCESS;
50
51         Channel* c = ServerInstance->FindChan(parameters[0]);
52
53         if (c)
54         {
55                 c->PartUser(user, reason);
56         }
57         else
58         {
59                 user->WriteNumeric(ERR_NOSUCHNICK, "%s :No such nick/channel", parameters[0].c_str());
60                 return CMD_FAILURE;
61         }
62
63         return CMD_SUCCESS;
64 }
65
66 RouteDescriptor CommandPart::GetRouting(User* user, const std::vector<std::string>& parameters)
67 {
68         return (IS_LOCAL(user) ? ROUTE_LOCALONLY : ROUTE_BROADCAST);
69 }