From 137d9dd1e2b9f19181a18c0fe391c7610511a25d Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Sun, 23 Jun 2024 19:36:09 +0200 Subject: [PATCH] implement string int header --- src/Network/Core.cpp | 4 +++- src/Network/GlobalHandler.cpp | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Network/Core.cpp b/src/Network/Core.cpp index 0c51f88..122aa3a 100644 --- a/src/Network/Core.cpp +++ b/src/Network/Core.cpp @@ -190,7 +190,9 @@ void Parse(std::string Data, SOCKET CSocket) { break; } if (!Data.empty() && CSocket != -1) { - int res = send(CSocket, (Data + "\n").c_str(), int(Data.size()) + 1, 0); + Data = std::to_string(Data.size()) + ">" + Data; + debug("Sending '" + Data + "'"); + int res = send(CSocket, Data.c_str(), int(Data.size()), 0); if (res < 0) { debug("(Core) send failed with error: " + std::to_string(WSAGetLastError())); } diff --git a/src/Network/GlobalHandler.cpp b/src/Network/GlobalHandler.cpp index dc4b580..24970f8 100644 --- a/src/Network/GlobalHandler.cpp +++ b/src/Network/GlobalHandler.cpp @@ -63,6 +63,8 @@ void GameSend(std::string_view Data) { return; int32_t Size, Temp, Sent; Size = int32_t(Data.size()); + auto SizeStr = std::to_string(Size) + ">"; + send(CSocket, SizeStr.c_str(), SizeStr.size(), 0); Sent = 0; #ifdef DEBUG if (Size > 1000) { @@ -78,10 +80,10 @@ void GameSend(std::string_view Data) { Sent += Temp; } while (Sent < Size); // send separately to avoid an allocation for += "\n" - Temp = send(CSocket, "\n", 1, 0); + /*Temp = send(CSocket, "\n", 1, 0); if (!CheckBytes(Temp)) { return; - } + }*/ } void ServerSend(std::string Data, bool Rel) { if (Terminate || Data.empty())