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<wchar_t, 128> 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 <createlegacy69@gmail.com>
This commit is contained in:
Siepert
2026-03-05 16:57:54 +01:00
committed by GitHub
parent a03c36f83f
commit 7d6658fe5b

View File

@@ -7,6 +7,7 @@
#include "..\..\Windows64\Network\WinsockNetLayer.h"
#include "..\..\Minecraft.h"
#include "..\..\User.h"
#include <iostream>
#endif
CPlatformNetworkManagerStub *g_pPlatformNetworkManager;
@@ -700,6 +701,7 @@ void CPlatformNetworkManagerStub::SearchForGames()
#ifdef _WINDOWS64
std::vector<Win64LANSession> 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<uint64_t>(inet_addr(ip.c_str())) | (static_cast<uint64_t>(stoi(port)) << 32));
friendsSessions[0].push_back(info);
}
}
std::fclose(file);
}
m_searchResultsCount[0] = (int)friendsSessions[0].size();
if (m_SessionsUpdatedCallback != NULL)