aboutsummaryrefslogtreecommitdiffstats
path: root/modules/spanningtree/num.cpp
diff options
context:
space:
mode:
authorGravatar Sadie Powell2024-07-17 00:06:50 +0100
committerGravatar Sadie Powell2024-07-17 00:06:50 +0100
commit889d521e05f2e922683d48c74eb00290e7a2f548 (patch)
treeb4c56bd4cdf0881601c7e4d6ff571e491af10bf4 /modules/spanningtree/num.cpp
parentUse std::endian from C++20 in the sha1 module. (diff)
Shuffle the modules about a bit.
Diffstat (limited to 'modules/spanningtree/num.cpp')
-rw-r--r--modules/spanningtree/num.cpp64
1 files changed, 64 insertions, 0 deletions
diff --git a/modules/spanningtree/num.cpp b/modules/spanningtree/num.cpp
new file mode 100644
index 000000000..0ca0ae9ca
--- /dev/null
+++ b/modules/spanningtree/num.cpp
@@ -0,0 +1,64 @@
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
+ *
+ * Copyright (C) 2018, 2020, 2022-2023 Sadie Powell <sadie@witchery.services>
+ * Copyright (C) 2016 Attila Molnar <attilamolnar@hush.com>
+ *
+ * This file is part of InspIRCd. InspIRCd is free software: you can
+ * redistribute it and/or modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation, version 2.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "inspircd.h"
+
+#include "utils.h"
+#include "commands.h"
+#include "remoteuser.h"
+
+CmdResult CommandNum::HandleServer(TreeServer* server, CommandBase::Params& params)
+{
+ User* const target = ServerInstance->Users.FindUUID(params[1]);
+ if (!target)
+ return CmdResult::FAILURE;
+
+ LocalUser* const localtarget = IS_LOCAL(target);
+ if (!localtarget)
+ return CmdResult::SUCCESS;
+
+ Numeric::Numeric numeric(ConvToNum<unsigned int>(params[2]));
+ // Passing NULL is ok, in that case the numeric source becomes this server
+ numeric.SetServer(Utils->FindServerID(params[0]));
+ numeric.GetParams().insert(numeric.GetParams().end(), params.begin()+3, params.end());
+
+ localtarget->WriteNumeric(numeric);
+ return CmdResult::SUCCESS;
+}
+
+RouteDescriptor CommandNum::GetRouting(User* user, const Params& params)
+{
+ return ROUTE_UNICAST(params[1]);
+}
+
+CommandNum::Builder::Builder(SpanningTree::RemoteUser* target, const Numeric::Numeric& numeric)
+ : CmdBuilder("NUM")
+{
+ TreeServer* const server = (numeric.GetServer() ? (static_cast<TreeServer*>(numeric.GetServer())) : Utils->TreeRoot);
+ push(server->GetId()).push(target->uuid).push(fmt::format("{:03}", numeric.GetNumeric()));
+ const CommandBase::Params& params = numeric.GetParams();
+ if (!params.empty())
+ {
+ for (CommandBase::Params::const_iterator i = params.begin(); i != params.end()-1; ++i)
+ push(*i);
+ push_last(params.back());
+ }
+ push_tags(params.GetTags());
+}