From 7d6658fe5b3095f35093701b5ab669ffc291e875 Mon Sep 17 00:00:00 2001 From: Siepert <115031340+Siepert123@users.noreply.github.com> Date: Thu, 5 Mar 2026 16:57:54 +0100 Subject: [PATCH] Add servers.txt so players can add an arbitrary amount of servers to the "Join Game" list (#478) * Code to read servers.txt * logging (still doesnt work) * server names load properly hooray * remove logger as it only spews out nonsense anyways * Do not use _countof, use sizeof(label)/sizeof(wchar_t) or make label std::array and call .size() * Fix memory leak by listing info pointers * C++ style cast (i think) * this throws a RAV but why * why oh why * I just assume infos get deleted elsewhere otherwise idk why it breaks no matter what i do * they get deleted all this time ohhhhhh --------- Co-authored-by: Siepert123 --- .../Network/PlatformNetworkManagerStub.cpp | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/Minecraft.Client/Common/Network/PlatformNetworkManagerStub.cpp b/Minecraft.Client/Common/Network/PlatformNetworkManagerStub.cpp index c2466fe3..e5824bd4 100644 --- a/Minecraft.Client/Common/Network/PlatformNetworkManagerStub.cpp +++ b/Minecraft.Client/Common/Network/PlatformNetworkManagerStub.cpp @@ -7,6 +7,7 @@ #include "..\..\Windows64\Network\WinsockNetLayer.h" #include "..\..\Minecraft.h" #include "..\..\User.h" +#include #endif CPlatformNetworkManagerStub *g_pPlatformNetworkManager; @@ -700,6 +701,7 @@ void CPlatformNetworkManagerStub::SearchForGames() #ifdef _WINDOWS64 std::vector lanSessions = WinsockNetLayer::GetDiscoveredSessions(); + //THEY GET DELETED HERE DAMMIT for (size_t i = 0; i < friendsSessions[0].size(); i++) delete friendsSessions[0][i]; friendsSessions[0].clear(); @@ -730,6 +732,53 @@ void CPlatformNetworkManagerStub::SearchForGames() friendsSessions[0].push_back(info); } + std::FILE* file = std::fopen("servers.txt", "r"); + + if (file) { + wstring wline; + int phase = 0; + + string ip; + wstring port; + wstring name; + + char buffer[512]; + while (std::fgets(buffer, sizeof(buffer), file)) { + if (phase == 0) { + ip = buffer; + phase = 1; + } + else if (phase == 1) { + wline = convStringToWstring(buffer); + port = wline; + phase = 2; + } + else if (phase == 2) { + wline = convStringToWstring(buffer); + name = wline; + phase = 0; + + //THEY GET DELETED AFTER USE LIKE 30 LINES UP!! + FriendSessionInfo* info = new FriendSessionInfo(); + wchar_t label[128]; + wcsncpy_s(label, sizeof(label)/sizeof(wchar_t), name.c_str(), _TRUNCATE); + size_t nameLen = wcslen(label); + info->displayLabel = new wchar_t[nameLen+1]; + wcscpy_s(info->displayLabel, nameLen + 1, label); + info->displayLabelLength = (unsigned char)nameLen; + info->displayLabelViewableStartIndex = 0; + info->data.isReadyToJoin = true; + info->data.isJoinable = true; + strncpy_s(info->data.hostIP, sizeof(info->data.hostIP), ip.c_str(), _TRUNCATE); + info->data.hostPort = stoi(port); + info->sessionId = (SessionID)(static_cast(inet_addr(ip.c_str())) | (static_cast(stoi(port)) << 32)); + friendsSessions[0].push_back(info); + } + } + + std::fclose(file); + } + m_searchResultsCount[0] = (int)friendsSessions[0].size(); if (m_SessionsUpdatedCallback != NULL)