aboutsummaryrefslogtreecommitdiffstats
path: root/modules/spanningtree/treesocket1.cpp
diff options
context:
space:
mode:
authorGravatar Sadie Powell2026-03-11 21:54:40 +0000
committerGravatar Sadie Powell2026-03-12 00:18:06 +0000
commitfcb3090055429a108b9837dbd4ba505d9c291129 (patch)
tree5c55fd77d3b24adeda54e250d91b2a44badc9c5d /modules/spanningtree/treesocket1.cpp
parentMark 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/treesocket1.cpp')
-rw-r--r--modules/spanningtree/treesocket1.cpp18
1 files changed, 14 insertions, 4 deletions
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);
}