update lcemp networking

This commit is contained in:
2026-08-02 03:33:11 +03:00
parent b87d044cf0
commit e254228cf5
15 changed files with 616 additions and 138 deletions
@@ -94,7 +94,7 @@ void CPlatformNetworkManagerStub::NotifyPlayerJoined(IQNetPlayer *pQNetPlayer )
if( m_pIQNet->IsHost() )
{
// 4J-PB - only the host should do this
// g_NetworkManager.UpdateAndSetGameSessionData();
g_NetworkManager.UpdateAndSetGameSessionData();
SystemFlagAddPlayer( networkPlayer );
}
@@ -141,6 +141,11 @@ void CPlatformNetworkManagerStub::NotifyPlayerLeaving(IQNetPlayer *pQNetPlayer)
g_NetworkManager.PlayerLeaving(networkPlayer);
if (m_pIQNet->IsHost())
{
g_NetworkManager.UpdateAndSetGameSessionData(networkPlayer);
}
for (int idx = 0; idx < XUSER_MAX_COUNT; ++idx)
{
if (playerChangedCallback[idx] != NULL)
@@ -239,6 +244,28 @@ void CPlatformNetworkManagerStub::DoWork()
IQNet::s_playerCount--;
}
}
for (int i = 1; i < MINECRAFT_NET_MAX_PLAYERS; i++)
{
IQNetPlayer *qp = &IQNet::m_player[i];
if (qp->GetCustomDataValue() == 0)
continue;
INetworkPlayer *np = (INetworkPlayer *)qp->GetCustomDataValue();
Socket *sock = np->GetSocket();
if (sock != NULL && sock->isClosing())
{
WinsockNetLayer::CloseConnectionBySmallId((BYTE)i);
}
}
}
if (_iQNetStubState == QNET_STATE_GAME_PLAY && !m_pIQNet->IsHost())
{
if (!WinsockNetLayer::IsConnected() && !g_NetworkManager.IsLeavingGame())
{
if (app.GetDisconnectReason() == DisconnectPacket::eDisconnect_None)
app.SetDisconnectReason(DisconnectPacket::eDisconnect_Quitting);
app.SetAction(ProfileManager.GetPrimaryPad(), eAppAction_ExitWorld, (void *)TRUE);
}
}
}
@@ -470,44 +497,48 @@ bool CPlatformNetworkManagerStub::_RunNetworkGame()
void CPlatformNetworkManagerStub::UpdateAndSetGameSessionData(INetworkPlayer *pNetworkPlayerLeaving /*= NULL*/)
{
// DWORD playerCount = m_pIQNet->GetPlayerCount();
//
// if( this->m_bLeavingGame )
// return;
//
// if( GetHostPlayer() == NULL )
// return;
//
// for(unsigned int i = 0; i < MINECRAFT_NET_MAX_PLAYERS; ++i)
// {
// if( i < playerCount )
// {
// INetworkPlayer *pNetworkPlayer = GetPlayerByIndex(i);
//
// // We can call this from NotifyPlayerLeaving but at that point the player is still considered in the session
// if( pNetworkPlayer != pNetworkPlayerLeaving )
// {
// m_hostGameSessionData.players[i] = ((NetworkPlayerXbox *)pNetworkPlayer)->GetUID();
//
// char *temp;
// temp = (char *)wstringtofilename( pNetworkPlayer->GetOnlineName() );
// memcpy(m_hostGameSessionData.szPlayers[i],temp,XUSER_NAME_SIZE);
// }
// else
// {
// m_hostGameSessionData.players[i] = NULL;
// memset(m_hostGameSessionData.szPlayers[i],0,XUSER_NAME_SIZE);
// }
// }
// else
// {
// m_hostGameSessionData.players[i] = NULL;
// memset(m_hostGameSessionData.szPlayers[i],0,XUSER_NAME_SIZE);
// }
// }
//
// m_hostGameSessionData.hostPlayerUID = ((NetworkPlayerXbox *)GetHostPlayer())->GetQNetPlayer()->GetXuid();
// m_hostGameSessionData.m_uiGameHostSettings = app.GetGameHostOption(eGameHostOption_All);
if (this->m_bLeavingGame)
return;
if (!m_pIQNet->IsHost())
return;
DWORD playerCount = m_pIQNet->GetPlayerCount();
m_hostGameSessionData.m_uiGameHostSettings = app.GetGameHostOption(eGameHostOption_All);
m_hostGameSessionData.playerCount = (unsigned char)playerCount;
for (unsigned int i = 0; i < MINECRAFT_NET_MAX_PLAYERS; ++i)
{
if (i < playerCount)
{
INetworkPlayer *pNetworkPlayer = GetPlayerByIndex(i);
if (pNetworkPlayer != NULL && pNetworkPlayer != pNetworkPlayerLeaving)
{
m_hostGameSessionData.players[i] = (GameSessionUID)(i + 1);
const wchar_t *name = pNetworkPlayer->GetOnlineName();
char nameBuf[XUSER_NAME_SIZE];
memset(nameBuf, 0, sizeof(nameBuf));
wcstombs(nameBuf, name, XUSER_NAME_SIZE - 1);
memcpy(m_hostGameSessionData.szPlayers[i], nameBuf, XUSER_NAME_SIZE);
}
else
{
m_hostGameSessionData.players[i] = 0;
memset(m_hostGameSessionData.szPlayers[i], 0, XUSER_NAME_SIZE);
}
}
else
{
m_hostGameSessionData.players[i] = 0;
memset(m_hostGameSessionData.szPlayers[i], 0, XUSER_NAME_SIZE);
}
}
// update the LAN advertiser with current player names and count
WinsockNetLayer::UpdateAdvertisePlayerNames(m_hostGameSessionData.playerCount, m_hostGameSessionData.szPlayers);
}
int CPlatformNetworkManagerStub::RemovePlayerOnSocketClosedThreadProc( void* lpParam )
@@ -728,6 +759,17 @@ void CPlatformNetworkManagerStub::SearchForGames()
info->data.playerCount = lanSessions[i].playerCount;
info->data.maxPlayers = lanSessions[i].maxPlayers;
memset(info->data.players, 0, sizeof(info->data.players));
memset(info->data.szPlayers, 0, sizeof(info->data.szPlayers));
for (int p = 0; p < MINECRAFT_NET_MAX_PLAYERS && p < lanSessions[i].playerCount; p++)
{
if (lanSessions[i].playerNames[p][0] != 0)
{
info->data.players[p] = (GameSessionUID)(p + 1);
memcpy(info->data.szPlayers[p], lanSessions[i].playerNames[p], XUSER_NAME_SIZE);
}
}
info->sessionId = (ULONGLONG)((unsigned __int64)inet_addr(lanSessions[i].hostIP) | ((unsigned __int64)lanSessions[i].hostPort << 32));
friendsSessions[0].push_back(info);
@@ -760,7 +802,19 @@ vector<FriendSessionInfo *> *CPlatformNetworkManagerStub::GetSessionList(int iPa
bool CPlatformNetworkManagerStub::GetGameSessionInfo(int iPad, SessionID sessionId, FriendSessionInfo *foundSessionInfo)
{
return false;
for (size_t i = 0; i < friendsSessions[0].size(); i++)
{
if (friendsSessions[0][i]->sessionId == sessionId)
{
if (foundSessionInfo != NULL)
{
foundSessionInfo->sessionId = friendsSessions[0][i]->sessionId;
foundSessionInfo->data = friendsSessions[0][i]->data;
foundSessionInfo->hasPartyMember = friendsSessions[0][i]->hasPartyMember;
}
return true;
}
}
}
void CPlatformNetworkManagerStub::SetSessionsUpdatedCallback( void (*SessionsUpdatedCallback)(LPVOID pParam), LPVOID pSearchParam )
@@ -830,7 +884,19 @@ INetworkPlayer * CPlatformNetworkManagerStub::GetPlayerByXuid(PlayerUID xuid)
INetworkPlayer * CPlatformNetworkManagerStub::GetPlayerBySmallId(unsigned char smallId)
{
return getNetworkPlayer(m_pIQNet->GetPlayerBySmallId(smallId));
IQNetPlayer *qnetPlayer = m_pIQNet->GetPlayerBySmallId(smallId);
if (qnetPlayer == NULL)
return NULL;
INetworkPlayer *networkPlayer = getNetworkPlayer(qnetPlayer);
if (networkPlayer == NULL && smallId != 0 && !m_pIQNet->IsHost())
{
qnetPlayer->m_isRemote = true;
qnetPlayer->m_isHostPlayer = false;
NotifyPlayerJoined(qnetPlayer);
networkPlayer = getNetworkPlayer(qnetPlayer);
}
return networkPlayer;
}
INetworkPlayer *CPlatformNetworkManagerStub::GetHostPlayer()