diff options
| author | 2026-03-11 21:54:40 +0000 | |
|---|---|---|
| committer | 2026-03-12 00:18:06 +0000 | |
| commit | fcb3090055429a108b9837dbd4ba505d9c291129 (patch) | |
| tree | 5c55fd77d3b24adeda54e250d91b2a44badc9c5d /modules/spanningtree/utils.cpp | |
| parent | Mark all acting extbans as MATCH_REQUIRE_CHANNEL. (diff) | |
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.
Diffstat (limited to 'modules/spanningtree/utils.cpp')
| -rw-r--r-- | modules/spanningtree/utils.cpp | 43 |
1 files changed, 11 insertions, 32 deletions
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<const TreeServer*>(server); - TreeSocket* sock = ts->GetSocket(); - if (sock) - sock->WriteLine(params); -} - void SpanningTreeUtilities::RefreshIPCache() { ValidIPs.clear(); @@ -391,14 +369,15 @@ std::shared_ptr<Link> 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(); } |
