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/treesocket1.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'modules/spanningtree/treesocket1.cpp') diff --git a/modules/spanningtree/treesocket1.cpp b/modules/spanningtree/treesocket1.cpp index 9624757fa..f49e333a8 100644 --- a/modules/spanningtree/treesocket1.cpp +++ b/modules/spanningtree/treesocket1.cpp @@ -152,7 +152,9 @@ void TreeSocket::OnError(BufferedSocketError e) void TreeSocket::SendError(const std::string& errormessage) { - WriteLine("ERROR :"+errormessage); + MessageBuilder("ERROR", true) + .Push(errormessage) + .Unicast(this); DoWrite(); LinkState = DYING; SetError(errormessage); @@ -232,11 +234,19 @@ void TreeSocket::OnDataReady() Utils->Creator->loopCall = false; } -static std::string newline("\n"); - -void TreeSocket::WriteLineInternal(const std::string& line) +void TreeSocket::SendMessage(MessageBuilder& msg) { + // Translate commands coming from servers using an older protocol + if (proto_version < PROTO_NEWEST) + { + if (!PreProcessNewProtocolMessage(msg.GetSource(), msg.GetCommand(), msg.GetParameters())) + return; + } + + const auto line = msg.ToRFC1459(); ServerInstance->Logs.RawIO(MODNAME, "S[{}] O {}", GetFd(), line); this->WriteData(line); + + static std::string newline = "\n"; this->WriteData(newline); } -- cgit v1.3.1-10-gc9f91