aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.Client
diff options
context:
space:
mode:
authorSiepert <115031340+Siepert123@users.noreply.github.com>2026-03-05 16:57:54 +0100
committerGitHub <noreply@github.com>2026-03-05 22:57:54 +0700
commit7d6658fe5b3095f35093701b5ab669ffc291e875 (patch)
tree89c5cd1a2b3b244d16ffc80edeb8c5b9a2ba427c /Minecraft.Client
parenta03c36f83f38c79103d6700aeae97cb681f9b36a (diff)
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>
Diffstat (limited to 'Minecraft.Client')
-rw-r--r--Minecraft.Client/Common/Network/PlatformNetworkManagerStub.cpp49
1 files changed, 49 insertions, 0 deletions
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 <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)