From fcb3090055429a108b9837dbd4ba505d9c291129 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Wed, 11 Mar 2026 21:54:40 +0000 Subject: Rework sending server protocol messages. - Replace CmdBuilder with MessageBuilder. This has a less footgun API. All message building has to go through this now so we can implement other message formats in the future. - Replace the message parsing in WriteLine with an analogue to PreProcessOldProtocolMessage. This should be much faster. - Move parameter translation from the core to spanningtree. - Change EncodeParameter to return the value instead of updating in place. - Replace the OnBuild*Message events with one OnServerMessage that can now access all parts of the message and change them. --- modules/spanningtree/utils.cpp | 43 +++++++++++------------------------------- 1 file changed, 11 insertions(+), 32 deletions(-) (limited to 'modules/spanningtree/utils.cpp') diff --git a/modules/spanningtree/utils.cpp b/modules/spanningtree/utils.cpp index 6254c0a41..e7221f0c3 100644 --- a/modules/spanningtree/utils.cpp +++ b/modules/spanningtree/utils.cpp @@ -34,7 +34,7 @@ #include "treeserver.h" #include "treesocket.h" #include "resolvers.h" -#include "commandbuilder.h" +#include "msgbuilder.h" SpanningTreeUtilities* Utils = nullptr; @@ -180,28 +180,6 @@ void SpanningTreeUtilities::GetListOfServersForChannel(const Channel* c, TreeSoc } } -void SpanningTreeUtilities::DoOneToAllButSender(const CmdBuilder& params, const TreeServer* omitroute) const -{ - const std::string& FullLine = params.str(); - - for (const auto* Route : TreeRoot->GetChildren()) - { - // Send the line if the route isn't the path to the one to be omitted - if (Route != omitroute) - { - Route->GetSocket()->WriteLine(FullLine); - } - } -} - -void SpanningTreeUtilities::DoOneToOne(const CmdBuilder& params, const Server* server) -{ - const TreeServer* ts = static_cast(server); - TreeSocket* sock = ts->GetSocket(); - if (sock) - sock->WriteLine(params); -} - void SpanningTreeUtilities::RefreshIPCache() { ValidIPs.clear(); @@ -391,14 +369,15 @@ std::shared_ptr SpanningTreeUtilities::FindLink(const std::string& name) void SpanningTreeUtilities::SendChannelMessage(const User* source, const Channel* target, const std::string& text, char status, const ClientProtocol::TagMap& tags, const CUList& exempt_list, const char* message_type, const TreeSocket* omit) const { - CmdBuilder msg(source, message_type); - msg.push_tags(tags); - msg.push_raw(' '); - if (status != 0) - msg.push_raw(status); - msg.push_raw(target->name); + MessageBuilder msg(source, message_type); + if (status) + msg.PushFmt("{}{}", status, target->name); + else + msg.Push(target->name); + msg.Push(target->name) + .PushTags(tags); if (!text.empty()) - msg.push_last(text); + msg.Push(text); TreeSocketSet list; this->GetListOfServersForChannel(target, list, status, exempt_list); @@ -406,7 +385,7 @@ void SpanningTreeUtilities::SendChannelMessage(const User* source, const Channel for (auto* Sock : list) { if (Sock != omit) - Sock->WriteLine(msg); + msg.Unicast(Sock); } } @@ -440,7 +419,7 @@ void SpanningTreeUtilities::SendListLimits(Channel* chan, TreeSocket* sock) bufferstr.pop_back(); if (sock) - sock->WriteLine(CommandMetadata::Builder(chan, "maxlist", bufferstr)); + CommandMetadata::Builder(chan, "maxlist", bufferstr).Unicast(sock); else CommandMetadata::Builder(chan, "maxlist", bufferstr).Broadcast(); } -- cgit v1.3.1-10-gc9f91