]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/num.cpp
Update the module descriptions using mkversion.
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / num.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2018-2019 Sadie Powell <sadie@witchery.services>
5  *   Copyright (C) 2016 Attila Molnar <attilamolnar@hush.com>
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
23 #include "utils.h"
24 #include "commands.h"
25 #include "remoteuser.h"
26
27 CmdResult CommandNum::HandleServer(TreeServer* server, CommandBase::Params& params)
28 {
29         User* const target = ServerInstance->FindUUID(params[1]);
30         if (!target)
31                 return CMD_FAILURE;
32
33         LocalUser* const localtarget = IS_LOCAL(target);
34         if (!localtarget)
35                 return CMD_SUCCESS;
36
37         Numeric::Numeric numeric(ConvToNum<unsigned int>(params[2]));
38         // Passing NULL is ok, in that case the numeric source becomes this server
39         numeric.SetServer(Utils->FindServerID(params[0]));
40         numeric.GetParams().insert(numeric.GetParams().end(), params.begin()+3, params.end());
41
42         localtarget->WriteNumeric(numeric);
43         return CMD_SUCCESS;
44 }
45
46 RouteDescriptor CommandNum::GetRouting(User* user, const Params& params)
47 {
48         return ROUTE_UNICAST(params[1]);
49 }
50
51 CommandNum::Builder::Builder(SpanningTree::RemoteUser* target, const Numeric::Numeric& numeric)
52         : CmdBuilder("NUM")
53 {
54         TreeServer* const server = (numeric.GetServer() ? (static_cast<TreeServer*>(numeric.GetServer())) : Utils->TreeRoot);
55         push(server->GetId()).push(target->uuid).push(InspIRCd::Format("%03u", numeric.GetNumeric()));
56         const CommandBase::Params& params = numeric.GetParams();
57         if (!params.empty())
58         {
59                 for (CommandBase::Params::const_iterator i = params.begin(); i != params.end()-1; ++i)
60                         push(*i);
61                 push_last(params.back());
62         }
63 }