From feeff5592455f2b38f85e5b0266a23090f06b119 Mon Sep 17 00:00:00 2001 From: piebot Date: Fri, 14 Aug 2026 13:42:38 +0300 Subject: [PATCH] LCEMP Commit: add dedicated server check to sessioninfo --- .../Common/Network/NetworkSocketLayer.cpp | 7 +++++++ Minecraft.Client/Common/Network/NetworkSocketLayer.h | 2 ++ .../Common/Network/PlatformNetworkManager.cpp | 12 ++++++++++-- Minecraft.Client/Common/Network/SessionInfo.h | 2 ++ Minecraft.Client/Extrax64Stubs.cpp | 10 +++++++++- Minecraft.Client/MinecraftServer.cpp | 9 +++++++-- 6 files changed, 37 insertions(+), 5 deletions(-) diff --git a/Minecraft.Client/Common/Network/NetworkSocketLayer.cpp b/Minecraft.Client/Common/Network/NetworkSocketLayer.cpp index be7c203f..b76c5716 100644 --- a/Minecraft.Client/Common/Network/NetworkSocketLayer.cpp +++ b/Minecraft.Client/Common/Network/NetworkSocketLayer.cpp @@ -1286,6 +1286,11 @@ bool NetworkSocketLayer::StartAdvertising(int gamePort, const wchar_t *hostName, s_advertiseData.texturePackParentId = texPackId; s_advertiseData.subTexturePackId = subTexId; s_advertiseData.isJoinable = 0; +#ifdef _DEDICATED_SERVER + s_advertiseData.isDedicatedServer = 1; +#else + s_advertiseData.isDedicatedServer = 0; +#endif s_hostGamePort = gamePort; LeaveCriticalSection(&s_advertiseLock); @@ -1666,6 +1671,7 @@ int NetworkSocketLayer::DiscoveryThreadProc(LPVOID param) s_discoveredSessions[i].texturePackParentId = broadcast->texturePackParentId; s_discoveredSessions[i].subTexturePackId = broadcast->subTexturePackId; s_discoveredSessions[i].isJoinable = (broadcast->isJoinable != 0); + s_discoveredSessions[i].isDedicatedServer = (broadcast->isDedicatedServer != 0); s_discoveredSessions[i].lastSeenTick = now; memcpy(s_discoveredSessions[i].playerNames, broadcast->playerNames, sizeof(broadcast->playerNames)); found = true; @@ -1699,6 +1705,7 @@ int NetworkSocketLayer::DiscoveryThreadProc(LPVOID param) session.texturePackParentId = broadcast->texturePackParentId; session.subTexturePackId = broadcast->subTexturePackId; session.isJoinable = (broadcast->isJoinable != 0); + session.isDedicatedServer = (broadcast->isDedicatedServer != 0); session.lastSeenTick = now; memcpy(session.playerNames, broadcast->playerNames, sizeof(broadcast->playerNames)); s_discoveredSessions.push_back(session); diff --git a/Minecraft.Client/Common/Network/NetworkSocketLayer.h b/Minecraft.Client/Common/Network/NetworkSocketLayer.h index 71b4ef8c..d3221ce7 100644 --- a/Minecraft.Client/Common/Network/NetworkSocketLayer.h +++ b/Minecraft.Client/Common/Network/NetworkSocketLayer.h @@ -116,6 +116,7 @@ struct LANBroadcast DWORD texturePackParentId; BYTE subTexturePackId; BYTE isJoinable; + BYTE isDedicatedServer; char playerNames[NETWORK_LAN_BROADCAST_PLAYERS][NETWORK_LAN_PLAYER_NAME_SIZE]; }; #pragma pack(pop) @@ -132,6 +133,7 @@ struct LANSession unsigned int texturePackParentId; unsigned char subTexturePackId; bool isJoinable; + bool isDedicatedServer; DWORD lastSeenTick; char playerNames[NETWORK_LAN_BROADCAST_PLAYERS][NETWORK_LAN_PLAYER_NAME_SIZE]; }; diff --git a/Minecraft.Client/Common/Network/PlatformNetworkManager.cpp b/Minecraft.Client/Common/Network/PlatformNetworkManager.cpp index 968ff578..bbbe7638 100644 --- a/Minecraft.Client/Common/Network/PlatformNetworkManager.cpp +++ b/Minecraft.Client/Common/Network/PlatformNetworkManager.cpp @@ -354,6 +354,10 @@ bool CPlatformNetworkManagerStub::LeaveGame(bool bMigrateHost) if( m_bLeavingGame ) return true; m_bLeavingGame = true; + + extern bool g_connectedToDedicatedServer; + g_connectedToDedicatedServer = false; + NetworkSocketLayer::StopAdvertising(); // If we are the host wait for the game server to end @@ -403,10 +407,10 @@ void CPlatformNetworkManagerStub::HostGame(int localUsersMask, bool bOnlineGame, IQNet::m_player[0].m_smallId = 0; IQNet::m_player[0].m_isRemote = false; IQNet::m_player[0].m_isHostPlayer = true; -#ifdef _WINDOWS64 + IQNet::s_playerCount = 1; +#if defined _WINDOWS64 && !defined WITH_SERVER_CODE extern wchar_t g_Win64UsernameW[17]; wcscpy_s(IQNet::m_player[0].m_gamertag, 32, g_Win64UsernameW); - IQNet::s_playerCount = 1; #endif if (getNetworkPlayer(&IQNet::m_player[0]) == NULL) @@ -454,6 +458,9 @@ int CPlatformNetworkManagerStub::JoinGame(FriendSessionInfo *searchResult, int l wcsncpy(IQNet::m_player[0].m_gamertag, searchResult->data.hostName, 31); IQNet::m_player[0].m_gamertag[31] = L'\0'; + extern bool g_connectedToDedicatedServer; + g_connectedToDedicatedServer = searchResult->data.isDedicatedServer; + NetworkSocketLayer::StopDiscovery(); if (!NetworkSocketLayer::JoinGame(hostIP, hostPort)) @@ -801,6 +808,7 @@ void CPlatformNetworkManagerStub::SearchForGames() info->data.subTexturePackId = lanSessions[i].subTexturePackId; info->data.isReadyToJoin = lanSessions[i].isJoinable; info->data.isJoinable = lanSessions[i].isJoinable; + info->data.isDedicatedServer = lanSessions[i].isDedicatedServer; strncpy(info->data.hostIP, lanSessions[i].hostIP, sizeof(info->data.hostIP) - 1); info->data.hostIP[sizeof(info->data.hostIP) - 1] = '\0'; info->data.hostPort = lanSessions[i].hostPort; diff --git a/Minecraft.Client/Common/Network/SessionInfo.h b/Minecraft.Client/Common/Network/SessionInfo.h index eb9a42a6..1844950e 100644 --- a/Minecraft.Client/Common/Network/SessionInfo.h +++ b/Minecraft.Client/Common/Network/SessionInfo.h @@ -79,6 +79,7 @@ typedef struct _GameSessionData bool isReadyToJoin; // 1 byte bool isJoinable; // 1 byte + bool isDedicatedServer; // 1 byte char hostIP[64]; // 64 bytes int hostPort; // 4 bytes @@ -97,6 +98,7 @@ typedef struct _GameSessionData subTexturePackId = 0; isReadyToJoin = false; isJoinable = true; + isDedicatedServer = false; memset(hostIP, 0, sizeof(hostIP)); hostPort = 0; memset(hostName, 0, sizeof(hostName)); diff --git a/Minecraft.Client/Extrax64Stubs.cpp b/Minecraft.Client/Extrax64Stubs.cpp index 2d50b945..2d62be5d 100644 --- a/Minecraft.Client/Extrax64Stubs.cpp +++ b/Minecraft.Client/Extrax64Stubs.cpp @@ -547,6 +547,8 @@ bool IQNet::s_isHosting = true; QNET_STATE _iQNetStubState = QNET_STATE_IDLE; +bool g_connectedToDedicatedServer = false; + void Win64_SetupRemoteQNetPlayer(IQNetPlayer *player, BYTE smallId, bool isHost, bool isLocal) { player->m_smallId = smallId; @@ -597,7 +599,13 @@ IQNetPlayer *IQNet::GetLocalPlayerByUserIndex(DWORD dwUserIndex) } static bool Win64_IsActivePlayer(IQNetPlayer *p, DWORD index) { - if (index == 0) return true; + if (index == 0) + { + extern bool g_connectedToDedicatedServer; + if (g_connectedToDedicatedServer && !IQNet::s_isHosting) + return false; + return true; + } if (p->GetCustomDataValue() != 0) return true; return (p->m_isRemote && p->m_gamertag[0] != 0); } diff --git a/Minecraft.Client/MinecraftServer.cpp b/Minecraft.Client/MinecraftServer.cpp index 09d5405c..eae6c64a 100644 --- a/Minecraft.Client/MinecraftServer.cpp +++ b/Minecraft.Client/MinecraftServer.cpp @@ -53,7 +53,7 @@ #include "ServerCommandDispatcher.h" #ifdef _DEDICATED_SERVER -#include "..\Minecraft.Server\ServerCommands.h" +#include "..\Minecraft.Server\Commands\ServerCommands.h" #endif #include "..\Minecraft.World\BiomeSource.h" @@ -1006,12 +1006,16 @@ void MinecraftServer::stopServer(bool didInit) // 4J-PB - If the primary player has signed out, then don't attempt to save anything // also need to check for a profile switch here - primary player signs out, and another player signs in before dismissing the dash -#ifdef _DURANGO +#ifdef _DEDICATED_SERVER + { + { +#elif defined(_DURANGO) // On Durango check if the primary user is signed in OR mid-sign-out if(ProfileManager.GetUser(0, true) != nullptr) #else if((m_bPrimaryPlayerSignedOut==false) && ProfileManager.IsSignedIn(ProfileManager.GetPrimaryPad())) #endif +#ifndef _DEDICATED_SERVER { #if defined(_XBOX_ONE) || defined(__ORBIS__) // Always save on exit! Except if saves are disabled. @@ -1020,6 +1024,7 @@ void MinecraftServer::stopServer(bool didInit) // if trial version or saving is disabled, then don't save anything. Also don't save anything if we didn't actually get through the server initialisation. if(m_saveOnExit && ProfileManager.IsFullVersion() && (!StorageManager.GetSaveDisabled()) && didInit) { +#endif if (players != NULL) { players->saveAll(Minecraft::GetInstance()->progressRenderer, true);