]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/num.cpp
Merge branch 'insp20' into insp3.
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / num.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2016 Attila Molnar <attilamolnar@hush.com>
5  *
6  * This file is part of InspIRCd.  InspIRCd is free software: you can
7  * redistribute it and/or modify it under the terms of the GNU General Public
8  * License as published by the Free Software Foundation, version 2.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
13  * details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18
19
20 #include "inspircd.h"
21
22 #include "utils.h"
23 #include "commands.h"
24 #include "remoteuser.h"
25
26 CmdResult CommandNum::HandleServer(TreeServer* server, CommandBase::Params& params)
27 {
28         User* const target = ServerInstance->FindUUID(params[1]);
29         if (!target)
30                 return CMD_FAILURE;
31
32         LocalUser* const localtarget = IS_LOCAL(target);
33         if (!localtarget)
34                 return CMD_SUCCESS;
35
36         Numeric::Numeric numeric(ConvToNum<unsigned int>(params[2]));
37         // Passing NULL is ok, in that case the numeric source becomes this server
38         numeric.SetServer(Utils->FindServerID(params[0]));
39         numeric.GetParams().insert(numeric.GetParams().end(), params.begin()+3, params.end());
40
41         localtarget->WriteNumeric(numeric);
42         return CMD_SUCCESS;
43 }
44
45 RouteDescriptor CommandNum::GetRouting(User* user, const Params& params)
46 {
47         return ROUTE_UNICAST(params[1]);
48 }
49
50 CommandNum::Builder::Builder(SpanningTree::RemoteUser* target, const Numeric::Numeric& numeric)
51         : CmdBuilder("NUM")
52 {
53         TreeServer* const server = (numeric.GetServer() ? (static_cast<TreeServer*>(numeric.GetServer())) : Utils->TreeRoot);
54         push(server->GetID()).push(target->uuid).push(InspIRCd::Format("%03u", numeric.GetNumeric()));
55         const CommandBase::Params& params = numeric.GetParams();
56         if (!params.empty())
57         {
58                 for (CommandBase::Params::const_iterator i = params.begin(); i != params.end()-1; ++i)
59                         push(*i);
60                 push_last(params.back());
61         }
62 }