mirror of
https://git.neolegacy.dev/neoStudiosLCE/neoLegacy.git
synced 2026-12-02 22:18:09 +01:00
replace WinsockNetLayer with PlatformNetworkManagerWindows, implement external server stats
This commit is contained in:
1 parent
62b92d5c0b
commit
f434aae3af
42 files changed
+2621
-3406
No files matched your search
@@ -28,6 +28,7 @@
|
||||
#ifdef _WINDOWS64
|
||||
#include "../../../Minecraft.World/NbtIo.h"
|
||||
#include "../../../Minecraft.World/compression.h"
|
||||
#include "../Network/ExternalServerList.h"
|
||||
|
||||
static wstring ReadLevelNameFromSaveFile(const wstring& filePath, bool *outHardcore = nullptr)
|
||||
{
|
||||
@@ -1811,29 +1812,7 @@ void UIScene_LoadOrJoinMenu::CheckAndJoinGame(int gameIndex)
|
||||
m_initData->iPad = 0;;
|
||||
m_initData->selectedSession = m_currentSessions->at( gameIndex );
|
||||
#ifdef _WINDOWS64
|
||||
{
|
||||
|
||||
int serverDbCount = 0;
|
||||
FILE* dbFile = fopen("servers.db", "rb");
|
||||
if (dbFile)
|
||||
{
|
||||
char magic[4] = {};
|
||||
if (fread(magic, 1, 4, dbFile) == 4 && memcmp(magic, "MCSV", 4) == 0)
|
||||
{
|
||||
uint32_t version = 0, count = 0;
|
||||
fread(&version, sizeof(uint32_t), 1, dbFile);
|
||||
fread(&count, sizeof(uint32_t), 1, dbFile);
|
||||
if (version == 1)
|
||||
serverDbCount = static_cast<int>(count);
|
||||
}
|
||||
fclose(dbFile);
|
||||
}
|
||||
int lanCount = static_cast<int>(m_currentSessions->size()) - serverDbCount;
|
||||
if (gameIndex >= lanCount && lanCount >= 0)
|
||||
m_initData->serverIndex = gameIndex - lanCount;
|
||||
else
|
||||
m_initData->serverIndex = -1;
|
||||
}
|
||||
m_initData->serverIndex = m_initData->selectedSession->savedServerIndex;
|
||||
#endif
|
||||
|
||||
if(m_initData->selectedSession->data.texturePackParentId!=0)
|
||||
@@ -1967,11 +1946,13 @@ void UIScene_LoadOrJoinMenu::UpdateGamesList()
|
||||
// If a texture pack is loading, or will be loading, then ignore this ( we are going to be destroyed anyway)
|
||||
if( Minecraft::GetInstance()->skins->getSelected()->isLoadingData() || (Minecraft::GetInstance()->skins->needsUIUpdate() || ui.IsReloadingSkin()) ) return;
|
||||
|
||||
#if !defined(_WINDOWS64)
|
||||
// if we're retrieving save info, don't show the list yet as we will be ignoring press events
|
||||
if(!m_bSavesDisplayed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
FriendSessionInfo *pSelectedSession = nullptr;
|
||||
@@ -2199,6 +2180,15 @@ void UIScene_LoadOrJoinMenu::handleTimerComplete(int id)
|
||||
{
|
||||
case JOIN_LOAD_ONLINE_TIMER_ID:
|
||||
{
|
||||
#ifdef _WINDOWS64
|
||||
if (m_currentSessions == nullptr)
|
||||
{
|
||||
UpdateGamesList();
|
||||
if (m_currentSessions == nullptr)
|
||||
addTimer(JOIN_LOAD_ONLINE_TIMER_ID, JOIN_LOAD_ONLINE_TIMER_TIME);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef _XBOX
|
||||
XPARTY_USER_LIST partyList;
|
||||
|
||||
@@ -4286,67 +4276,24 @@ void UIScene_LoadOrJoinMenu::AppendServerToFile(const wstring& ip, const wstring
|
||||
char narrowIP[256] = {};
|
||||
char narrowPort[16] = {};
|
||||
char narrowName[256] = {};
|
||||
wcstombs(narrowIP, ip.c_str(), sizeof(narrowIP) - 1);
|
||||
wcstombs(narrowPort, port.c_str(), sizeof(narrowPort) - 1);
|
||||
wcstombs(narrowName, name.c_str(), sizeof(narrowName) - 1);
|
||||
|
||||
uint16_t portNum = static_cast<uint16_t>(atoi(narrowPort));
|
||||
|
||||
struct ServerEntry { std::string ip; uint16_t port; std::string name; };
|
||||
std::vector<ServerEntry> entries;
|
||||
|
||||
FILE* file = fopen("servers.db", "rb");
|
||||
if (file)
|
||||
if (wcstombs(narrowIP, ip.c_str(), sizeof(narrowIP) - 1) == static_cast<size_t>(-1) ||
|
||||
wcstombs(narrowPort, port.c_str(), sizeof(narrowPort) - 1) == static_cast<size_t>(-1) ||
|
||||
wcstombs(narrowName, name.c_str(), sizeof(narrowName) - 1) == static_cast<size_t>(-1))
|
||||
{
|
||||
char magic[4] = {};
|
||||
if (fread(magic, 1, 4, file) == 4 && memcmp(magic, "MCSV", 4) == 0)
|
||||
{
|
||||
uint32_t version = 0, count = 0;
|
||||
fread(&version, sizeof(uint32_t), 1, file);
|
||||
fread(&count, sizeof(uint32_t), 1, file);
|
||||
if (version == 1)
|
||||
{
|
||||
for (uint32_t s = 0; s < count; s++)
|
||||
{
|
||||
uint16_t ipLen = 0, p = 0, nameLen = 0;
|
||||
if (fread(&ipLen, sizeof(uint16_t), 1, file) != 1) break;
|
||||
if (ipLen == 0 || ipLen > 256) break;
|
||||
char ipBuf[257] = {};
|
||||
if (fread(ipBuf, 1, ipLen, file) != ipLen) break;
|
||||
if (fread(&p, sizeof(uint16_t), 1, file) != 1) break;
|
||||
if (fread(&nameLen, sizeof(uint16_t), 1, file) != 1) break;
|
||||
if (nameLen > 256) break;
|
||||
char nameBuf[257] = {};
|
||||
if (nameLen > 0 && fread(nameBuf, 1, nameLen, file) != nameLen) break;
|
||||
entries.push_back({std::string(ipBuf), p, std::string(nameBuf)});
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose(file);
|
||||
app.DebugPrintf("Could not encode the external server details.");
|
||||
return;
|
||||
}
|
||||
|
||||
entries.push_back({std::string(narrowIP), portNum, std::string(narrowName)});
|
||||
|
||||
file = fopen("servers.db", "wb");
|
||||
if (file)
|
||||
char* portEnd = nullptr;
|
||||
unsigned long portNumber = strtoul(narrowPort, &portEnd, 10);
|
||||
if (narrowIP[0] == '\0' || portEnd == narrowPort || *portEnd != '\0' || portNumber == 0 || portNumber > 65535)
|
||||
{
|
||||
fwrite("MCSV", 1, 4, file);
|
||||
uint32_t version = 1;
|
||||
uint32_t count = static_cast<uint32_t>(entries.size());
|
||||
fwrite(&version, sizeof(uint32_t), 1, file);
|
||||
fwrite(&count, sizeof(uint32_t), 1, file);
|
||||
|
||||
for (size_t i = 0; i < entries.size(); i++)
|
||||
{
|
||||
uint16_t ipLen = static_cast<uint16_t>(entries[i].ip.length());
|
||||
fwrite(&ipLen, sizeof(uint16_t), 1, file);
|
||||
fwrite(entries[i].ip.c_str(), 1, ipLen, file);
|
||||
fwrite(&entries[i].port, sizeof(uint16_t), 1, file);
|
||||
uint16_t nameLen = static_cast<uint16_t>(entries[i].name.length());
|
||||
fwrite(&nameLen, sizeof(uint16_t), 1, file);
|
||||
fwrite(entries[i].name.c_str(), 1, nameLen, file);
|
||||
}
|
||||
fclose(file);
|
||||
app.DebugPrintf("The external server address or port is invalid.");
|
||||
return;
|
||||
}
|
||||
|
||||
ExternalServerList::Entry entry = { narrowIP, static_cast<uint16_t>(portNumber), narrowName };
|
||||
if (!ExternalServerList::Append(entry))
|
||||
app.DebugPrintf("Failed to save the external server list.");
|
||||
}
|
||||
#endif // _WINDOWS64
|
||||
Reference in new issue
Block a user