qol: add dedicated server check to sessioninfo

This commit is contained in:
NOTPIES 2026-03-09 00:21:14 -03:00
parent 0e48021acd
commit c1a9648bf4
7 changed files with 37 additions and 2 deletions

2
.gitignore vendored
View file

@ -2,6 +2,8 @@
# Build outputs
# ===========================================
x64/
x64_Server_Release/
x64_Server_Debug/
Minecraft.Client/x64/
Minecraft.World/x64_Debug/
Minecraft.World/x64_Release/

View file

@ -356,6 +356,9 @@ bool CPlatformNetworkManagerStub::LeaveGame(bool bMigrateHost)
m_bLeavingGame = true;
extern bool g_connectedToDedicatedServer;
g_connectedToDedicatedServer = false;
#ifdef _WINDOWS64
WinsockNetLayer::StopAdvertising();
#endif
@ -407,8 +410,10 @@ void CPlatformNetworkManagerStub::HostGame(int localUsersMask, bool bOnlineGame,
IQNet::m_player[0].m_isRemote = false;
IQNet::m_player[0].m_isHostPlayer = true;
IQNet::s_playerCount = 1;
#ifndef WITH_SERVER_CODE
extern wchar_t g_Win64UsernameW[17];
wcscpy_s(IQNet::m_player[0].m_gamertag, 32, g_Win64UsernameW);
#endif
#endif
_HostGame( localUsersMask, publicSlots, privateSlots );
@ -454,6 +459,9 @@ int CPlatformNetworkManagerStub::JoinGame(FriendSessionInfo *searchResult, int l
IQNet::m_player[0].m_isHostPlayer = true;
wcsncpy_s(IQNet::m_player[0].m_gamertag, 32, searchResult->data.hostName, _TRUNCATE);
extern bool g_connectedToDedicatedServer;
g_connectedToDedicatedServer = searchResult->data.isDedicatedServer;
WinsockNetLayer::StopDiscovery();
if (!WinsockNetLayer::JoinGame(hostIP, hostPort))
@ -793,6 +801,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_s(info->data.hostIP, sizeof(info->data.hostIP), lanSessions[i].hostIP, _TRUNCATE);
info->data.hostPort = lanSessions[i].hostPort;
wcsncpy_s(info->data.hostName, XUSER_NAME_SIZE, lanSessions[i].hostName, _TRUNCATE);

View file

@ -70,6 +70,7 @@ typedef struct _GameSessionData
bool isReadyToJoin;
bool isJoinable;
bool isDedicatedServer;
char hostIP[64];
int hostPort;
@ -88,6 +89,7 @@ typedef struct _GameSessionData
subTexturePackId = 0;
isReadyToJoin = false;
isJoinable = true;
isDedicatedServer = false;
memset(hostIP, 0, sizeof(hostIP));
hostPort = 0;
memset(hostName, 0, sizeof(hostName));

View file

@ -306,6 +306,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;
@ -354,7 +356,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);
}

View file

@ -893,12 +893,16 @@ void MinecraftServer::stopServer()
// 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 WITH_SERVER_CODE
{
{
#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 WITH_SERVER_CODE
{
#if defined(_XBOX_ONE) || defined(__ORBIS__)
// Always save on exit! Except if saves are disabled.
@ -907,6 +911,7 @@ void MinecraftServer::stopServer()
// if trial version or saving is disabled, then don't save anything
if(m_saveOnExit && ProfileManager.IsFullVersion() && (!StorageManager.GetSaveDisabled()))
{
#endif
if (players != NULL)
{
players->saveAll(Minecraft::GetInstance()->progressRenderer, true);

View file

@ -796,6 +796,11 @@ bool WinsockNetLayer::StartAdvertising(int gamePort, const wchar_t *hostName, un
s_advertiseData.texturePackParentId = texPackId;
s_advertiseData.subTexturePackId = subTexId;
s_advertiseData.isJoinable = 0;
#ifdef WITH_SERVER_CODE
s_advertiseData.isDedicatedServer = 1;
#else
s_advertiseData.isDedicatedServer = 0;
#endif
s_hostGamePort = gamePort;
LeaveCriticalSection(&s_advertiseLock);
@ -1009,6 +1014,7 @@ DWORD WINAPI WinsockNetLayer::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;
@ -1036,6 +1042,7 @@ DWORD WINAPI WinsockNetLayer::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);

View file

@ -32,6 +32,7 @@ struct Win64LANBroadcast
DWORD texturePackParentId;
BYTE subTexturePackId;
BYTE isJoinable;
BYTE isDedicatedServer;
char playerNames[WIN64_LAN_BROADCAST_PLAYERS][XUSER_NAME_SIZE];
};
#pragma pack(pop)
@ -48,6 +49,7 @@ struct Win64LANSession
unsigned int texturePackParentId;
unsigned char subTexturePackId;
bool isJoinable;
bool isDedicatedServer;
DWORD lastSeenTick;
char playerNames[WIN64_LAN_BROADCAST_PLAYERS][XUSER_NAME_SIZE];
};