diff --git a/targets/Minecraft.Client/Common/Consoles_App.cpp b/targets/Minecraft.Client/Common/Consoles_App.cpp index 181625fa0..2eee619f6 100644 --- a/targets/Minecraft.Client/Common/Consoles_App.cpp +++ b/targets/Minecraft.Client/Common/Consoles_App.cpp @@ -3203,7 +3203,7 @@ void CMinecraftApp::HandleXuiActions(void) { SetAction(i, eAppAction_Idle); // 4J Stu - Move this state block from - // CPlatformNetworkManager::ExitAndJoinFromInviteThreadProc, + // IPlatformNetwork::ExitAndJoinFromInviteThreadProc, // as g_NetworkManager.JoinGameFromInviteInfo ultimately can // call NavigateToScene, /// and we should only be calling that from the main thread diff --git a/targets/Minecraft.Client/Common/src/Leaderboards/LeaderboardManager.h b/targets/Minecraft.Client/Common/src/Leaderboards/LeaderboardManager.h index 2031cacfb..fd7d665e2 100644 --- a/targets/Minecraft.Client/Common/src/Leaderboards/LeaderboardManager.h +++ b/targets/Minecraft.Client/Common/src/Leaderboards/LeaderboardManager.h @@ -15,7 +15,7 @@ public: static IPlatformLeaderboard* Instance() { return m_instance; } static void DeleteInstance(); - // IPlatformLeaderboard pure virtuals — subclasses must implement: + // IPlatformLeaderboard pure virtuals - subclasses must implement: // Tick, OpenSession, CloseSession, DeleteSession, WriteStats, // FlushStats, CancelOperation, isIdle diff --git a/targets/Minecraft.Client/Common/src/Network/GameNetworkManager.cpp b/targets/Minecraft.Client/Common/src/Network/GameNetworkManager.cpp index d1e087df2..067f61770 100644 --- a/targets/Minecraft.Client/Common/src/Network/GameNetworkManager.cpp +++ b/targets/Minecraft.Client/Common/src/Network/GameNetworkManager.cpp @@ -61,7 +61,7 @@ class INVITE_INFO; // Global instance CGameNetworkManager g_NetworkManager; -CPlatformNetworkManager* CGameNetworkManager::s_pPlatformNetworkManager; +IPlatformNetwork* CGameNetworkManager::s_pPlatformNetworkManager; int64_t CGameNetworkManager::messageQueue[512]; int64_t CGameNetworkManager::byteQueue[512]; @@ -80,7 +80,7 @@ void CGameNetworkManager::Initialise() { LevelRenderer::getGlobalChunkCount() / (Level::maxBuildHeight / 16); // dividing here by number of renderer chunks in one column - s_pPlatformNetworkManager = new CPlatformNetworkManagerStub(); + s_pPlatformNetworkManager = new IPlatformNetworkStub(); s_pPlatformNetworkManager->Initialise(this, flagIndexSize); m_bNetworkThreadRunning = false; m_bInitialised = true; @@ -1073,13 +1073,13 @@ void CGameNetworkManager::StateChange_AnyToJoining() { } void CGameNetworkManager::StateChange_JoiningToIdle( - CPlatformNetworkManager::eJoinFailedReason reason) { + IPlatformNetwork::eJoinFailedReason reason) { DisconnectPacket::eDisconnectReason disconnectReason; switch (reason) { - case CPlatformNetworkManager::JOIN_FAILED_SERVER_FULL: + case IPlatformNetwork::JOIN_FAILED_SERVER_FULL: disconnectReason = DisconnectPacket::eDisconnect_ServerFull; break; - case CPlatformNetworkManager::JOIN_FAILED_INSUFFICIENT_PRIVILEGES: + case IPlatformNetwork::JOIN_FAILED_INSUFFICIENT_PRIVILEGES: disconnectReason = DisconnectPacket::eDisconnect_NoMultiplayerPrivilegesJoin; app.SetAction(ProfileManager.GetPrimaryPad(), diff --git a/targets/Minecraft.Client/Common/src/Network/GameNetworkManager.h b/targets/Minecraft.Client/Common/src/Network/GameNetworkManager.h index 027344312..34a050613 100644 --- a/targets/Minecraft.Client/Common/src/Network/GameNetworkManager.h +++ b/targets/Minecraft.Client/Common/src/Network/GameNetworkManager.h @@ -8,7 +8,7 @@ #include #endif #include "4J.Common/4J_Compat.h" -#include "Minecraft.Client/Common/src/Network/PlatformNetworkManagerInterface.h" +#include "platform/IPlatformNetwork.h" #include "Minecraft.Client/include/NetTypes.h" #include "NetworkPlayerInterface.h" #include "PlatformNetworkManagerStub.h" @@ -30,7 +30,7 @@ const int NON_QNET_SENDDATA_ACK_REQUIRED = 1; // implementation of PlatformNetworkManager to provide this functionality. class CGameNetworkManager { - friend class CPlatformNetworkManagerStub; + friend class IPlatformNetworkStub; public: CGameNetworkManager(); @@ -175,7 +175,7 @@ private: void StateChange_AnyToHosting(); void StateChange_AnyToJoining(); void StateChange_JoiningToIdle( - CPlatformNetworkManager::eJoinFailedReason reason); + IPlatformNetwork::eJoinFailedReason reason); void StateChange_AnyToStarting(); void StateChange_AnyToEnding(bool bStateWasPlaying); void StateChange_AnyToIdle(); @@ -202,7 +202,7 @@ private: private: float m_lastPlayerEventTimeStart; // For telemetry - static CPlatformNetworkManager* s_pPlatformNetworkManager; + static IPlatformNetwork* s_pPlatformNetworkManager; bool m_bNetworkThreadRunning; int GetJoiningReadyPercentage(); bool m_bLastDisconnectWasLostRoomOnly; diff --git a/targets/Minecraft.Client/Common/src/Network/PlatformNetworkManagerInterface.h b/targets/Minecraft.Client/Common/src/Network/PlatformNetworkManagerInterface.h index 9593e498f..0d414ca33 100644 --- a/targets/Minecraft.Client/Common/src/Network/PlatformNetworkManagerInterface.h +++ b/targets/Minecraft.Client/Common/src/Network/PlatformNetworkManagerInterface.h @@ -31,7 +31,7 @@ typedef struct _SearchForGamesData { XOVERLAPPED* pOverlapped; } SearchForGamesData; -class CPlatformNetworkManager { +class IPlatformNetwork { friend class CGameNetworkManager; public: diff --git a/targets/Minecraft.Client/Common/src/Network/PlatformNetworkManagerStub.cpp b/targets/Minecraft.Client/Common/src/Network/PlatformNetworkManagerStub.cpp index 432b95d32..150822406 100644 --- a/targets/Minecraft.Client/Common/src/Network/PlatformNetworkManagerStub.cpp +++ b/targets/Minecraft.Client/Common/src/Network/PlatformNetworkManagerStub.cpp @@ -14,9 +14,9 @@ #include "Socket.h" #include "console_helpers/C4JThread.h" -CPlatformNetworkManagerStub* g_pPlatformNetworkManager; +IPlatformNetworkStub* g_pPlatformNetworkManager; -void CPlatformNetworkManagerStub::NotifyPlayerJoined(IQNetPlayer* pQNetPlayer) { +void IPlatformNetworkStub::NotifyPlayerJoined(IQNetPlayer* pQNetPlayer) { const char* pszDescription; // 4J Stu - We create a fake socket for every where that we need an INBOUND @@ -109,7 +109,7 @@ void CPlatformNetworkManagerStub::NotifyPlayerJoined(IQNetPlayer* pQNetPlayer) { } } -bool CPlatformNetworkManagerStub::Initialise( +bool IPlatformNetworkStub::Initialise( CGameNetworkManager* pGameNetworkManager, int flagIndexSize) { m_pGameNetworkManager = pGameNetworkManager; m_flagIndexSize = flagIndexSize; @@ -147,58 +147,58 @@ bool CPlatformNetworkManagerStub::Initialise( return true; } -void CPlatformNetworkManagerStub::Terminate() { +void IPlatformNetworkStub::Terminate() { // TODO: 4jcraft, no release of ressources } -int CPlatformNetworkManagerStub::GetJoiningReadyPercentage() { return 100; } +int IPlatformNetworkStub::GetJoiningReadyPercentage() { return 100; } -int CPlatformNetworkManagerStub::CorrectErrorIDS(int IDS) { return IDS; } +int IPlatformNetworkStub::CorrectErrorIDS(int IDS) { return IDS; } -bool CPlatformNetworkManagerStub::isSystemPrimaryPlayer( +bool IPlatformNetworkStub::isSystemPrimaryPlayer( IQNetPlayer* pQNetPlayer) { return true; } // We call this twice a frame, either side of the render call so is a good place // to "tick" things -void CPlatformNetworkManagerStub::DoWork() {} +void IPlatformNetworkStub::DoWork() {} -int CPlatformNetworkManagerStub::GetPlayerCount() { +int IPlatformNetworkStub::GetPlayerCount() { return m_pIQNet->GetPlayerCount(); } -bool CPlatformNetworkManagerStub::ShouldMessageForFullSession() { +bool IPlatformNetworkStub::ShouldMessageForFullSession() { return false; } -int CPlatformNetworkManagerStub::GetOnlinePlayerCount() { return 1; } +int IPlatformNetworkStub::GetOnlinePlayerCount() { return 1; } -int CPlatformNetworkManagerStub::GetLocalPlayerMask(int playerIndex) { +int IPlatformNetworkStub::GetLocalPlayerMask(int playerIndex) { return 1 << playerIndex; } -bool CPlatformNetworkManagerStub::AddLocalPlayerByUserIndex(int userIndex) { +bool IPlatformNetworkStub::AddLocalPlayerByUserIndex(int userIndex) { NotifyPlayerJoined(m_pIQNet->GetLocalPlayerByUserIndex(userIndex)); return (m_pIQNet->AddLocalPlayerByUserIndex(userIndex) == 0); } -bool CPlatformNetworkManagerStub::RemoveLocalPlayerByUserIndex(int userIndex) { +bool IPlatformNetworkStub::RemoveLocalPlayerByUserIndex(int userIndex) { return true; } -bool CPlatformNetworkManagerStub::IsInStatsEnabledSession() { return true; } +bool IPlatformNetworkStub::IsInStatsEnabledSession() { return true; } -bool CPlatformNetworkManagerStub::SessionHasSpace( +bool IPlatformNetworkStub::SessionHasSpace( unsigned int spaceRequired /*= 1*/) { return true; } -void CPlatformNetworkManagerStub::SendInviteGUI(int quadrant) {} +void IPlatformNetworkStub::SendInviteGUI(int quadrant) {} -bool CPlatformNetworkManagerStub::IsAddingPlayer() { return false; } +bool IPlatformNetworkStub::IsAddingPlayer() { return false; } -bool CPlatformNetworkManagerStub::LeaveGame(bool bMigrateHost) { +bool IPlatformNetworkStub::LeaveGame(bool bMigrateHost) { if (m_bLeavingGame) return true; m_bLeavingGame = true; @@ -212,12 +212,12 @@ bool CPlatformNetworkManagerStub::LeaveGame(bool bMigrateHost) { return true; } -bool CPlatformNetworkManagerStub::_LeaveGame(bool bMigrateHost, +bool IPlatformNetworkStub::_LeaveGame(bool bMigrateHost, bool bLeaveRoom) { return true; } -void CPlatformNetworkManagerStub::HostGame( +void IPlatformNetworkStub::HostGame( int localUsersMask, bool bOnlineGame, bool bIsPrivate, unsigned char publicSlots /*= MINECRAFT_NET_MAX_PLAYERS*/, unsigned char privateSlots /*= 0*/) { @@ -238,30 +238,30 @@ void CPlatformNetworkManagerStub::HostGame( // #endif } -void CPlatformNetworkManagerStub::_HostGame( +void IPlatformNetworkStub::_HostGame( int usersMask, unsigned char publicSlots /*= MINECRAFT_NET_MAX_PLAYERS*/, unsigned char privateSlots /*= 0*/) {} -bool CPlatformNetworkManagerStub::_StartGame() { return true; } +bool IPlatformNetworkStub::_StartGame() { return true; } -int CPlatformNetworkManagerStub::JoinGame(FriendSessionInfo* searchResult, +int IPlatformNetworkStub::JoinGame(FriendSessionInfo* searchResult, int localUsersMask, int primaryUserIndex) { return CGameNetworkManager::JOINGAME_SUCCESS; } -bool CPlatformNetworkManagerStub::SetLocalGame(bool isLocal) { +bool IPlatformNetworkStub::SetLocalGame(bool isLocal) { m_bIsOfflineGame = isLocal; return true; } -void CPlatformNetworkManagerStub::SetPrivateGame(bool isPrivate) { +void IPlatformNetworkStub::SetPrivateGame(bool isPrivate) { app.DebugPrintf("Setting as private game: %s\n", isPrivate ? "yes" : "no"); m_bIsPrivateGame = isPrivate; } -void CPlatformNetworkManagerStub::RegisterPlayerChangedCallback( +void IPlatformNetworkStub::RegisterPlayerChangedCallback( int iPad, void (*callback)(void* callbackParam, INetworkPlayer* pPlayer, bool leaving), @@ -270,7 +270,7 @@ void CPlatformNetworkManagerStub::RegisterPlayerChangedCallback( playerChangedCallbackParam[iPad] = callbackParam; } -void CPlatformNetworkManagerStub::UnRegisterPlayerChangedCallback( +void IPlatformNetworkStub::UnRegisterPlayerChangedCallback( int iPad, void (*callback)(void* callbackParam, INetworkPlayer* pPlayer, bool leaving), @@ -281,11 +281,11 @@ void CPlatformNetworkManagerStub::UnRegisterPlayerChangedCallback( } } -void CPlatformNetworkManagerStub::HandleSignInChange() { return; } +void IPlatformNetworkStub::HandleSignInChange() { return; } -bool CPlatformNetworkManagerStub::_RunNetworkGame() { return true; } +bool IPlatformNetworkStub::_RunNetworkGame() { return true; } -void CPlatformNetworkManagerStub::UpdateAndSetGameSessionData( +void IPlatformNetworkStub::UpdateAndSetGameSessionData( INetworkPlayer* pNetworkPlayerLeaving /*= nullptr*/) { // uint32_t playerCount = m_pIQNet->GetPlayerCount(); // @@ -332,7 +332,7 @@ void CPlatformNetworkManagerStub::UpdateAndSetGameSessionData( // app.GetGameHostOption(eGameHostOption_All); } -int CPlatformNetworkManagerStub::RemovePlayerOnSocketClosedThreadProc( +int IPlatformNetworkStub::RemovePlayerOnSocketClosedThreadProc( void* lpParam) { INetworkPlayer* pNetworkPlayer = (INetworkPlayer*)lpParam; @@ -351,12 +351,12 @@ int CPlatformNetworkManagerStub::RemovePlayerOnSocketClosedThreadProc( return g_pPlatformNetworkManager->RemoveLocalPlayer(pNetworkPlayer); } -bool CPlatformNetworkManagerStub::RemoveLocalPlayer( +bool IPlatformNetworkStub::RemoveLocalPlayer( INetworkPlayer* pNetworkPlayer) { return true; } -CPlatformNetworkManagerStub::PlayerFlags::PlayerFlags( +IPlatformNetworkStub::PlayerFlags::PlayerFlags( INetworkPlayer* pNetworkPlayer, unsigned int count) { // 4J Stu - Don't assert, just make it a multiple of 8! This count is // calculated from a load of separate values, and makes tweaking @@ -368,11 +368,11 @@ CPlatformNetworkManagerStub::PlayerFlags::PlayerFlags( memset(this->flags, 0, count / 8); this->count = count; } -CPlatformNetworkManagerStub::PlayerFlags::~PlayerFlags() { delete[] flags; } +IPlatformNetworkStub::PlayerFlags::~PlayerFlags() { delete[] flags; } // Add a player to the per system flag storage - if we've already got a player // from that system, copy its flags over -void CPlatformNetworkManagerStub::SystemFlagAddPlayer( +void IPlatformNetworkStub::SystemFlagAddPlayer( INetworkPlayer* pNetworkPlayer) { PlayerFlags* newPlayerFlags = new PlayerFlags(pNetworkPlayer, m_flagIndexSize); @@ -390,7 +390,7 @@ void CPlatformNetworkManagerStub::SystemFlagAddPlayer( // Remove a player from the per system flag storage - just maintains the // m_playerFlags vector without any gaps in it -void CPlatformNetworkManagerStub::SystemFlagRemovePlayer( +void IPlatformNetworkStub::SystemFlagRemovePlayer( INetworkPlayer* pNetworkPlayer) { for (unsigned int i = 0; i < m_playerFlags.size(); i++) { if (m_playerFlags[i]->m_pNetworkPlayer == pNetworkPlayer) { @@ -402,7 +402,7 @@ void CPlatformNetworkManagerStub::SystemFlagRemovePlayer( } } -void CPlatformNetworkManagerStub::SystemFlagReset() { +void IPlatformNetworkStub::SystemFlagReset() { for (unsigned int i = 0; i < m_playerFlags.size(); i++) { delete m_playerFlags[i]; } @@ -411,7 +411,7 @@ void CPlatformNetworkManagerStub::SystemFlagReset() { // Set a per system flag - this is done by setting the flag on every player that // shares that system -void CPlatformNetworkManagerStub::SystemFlagSet(INetworkPlayer* pNetworkPlayer, +void IPlatformNetworkStub::SystemFlagSet(INetworkPlayer* pNetworkPlayer, int index) { if ((index < 0) || (index >= m_flagIndexSize)) return; if (pNetworkPlayer == nullptr) return; @@ -426,7 +426,7 @@ void CPlatformNetworkManagerStub::SystemFlagSet(INetworkPlayer* pNetworkPlayer, // Get value of a per system flag - can be read from the flags of the passed in // player as anything else sent to that system should also have been duplicated // here -bool CPlatformNetworkManagerStub::SystemFlagGet(INetworkPlayer* pNetworkPlayer, +bool IPlatformNetworkStub::SystemFlagGet(INetworkPlayer* pNetworkPlayer, int index) { if ((index < 0) || (index >= m_flagIndexSize)) return false; if (pNetworkPlayer == nullptr) { @@ -442,9 +442,9 @@ bool CPlatformNetworkManagerStub::SystemFlagGet(INetworkPlayer* pNetworkPlayer, return false; } -std::wstring CPlatformNetworkManagerStub::GatherStats() { return L""; } +std::wstring IPlatformNetworkStub::GatherStats() { return L""; } -std::wstring CPlatformNetworkManagerStub::GatherRTTStats() { +std::wstring IPlatformNetworkStub::GatherRTTStats() { std::wstring stats(L"Rtt: "); wchar_t stat[32]; @@ -462,20 +462,20 @@ std::wstring CPlatformNetworkManagerStub::GatherRTTStats() { return stats; } -void CPlatformNetworkManagerStub::TickSearch() {} +void IPlatformNetworkStub::TickSearch() {} -void CPlatformNetworkManagerStub::SearchForGames() {} +void IPlatformNetworkStub::SearchForGames() {} -int CPlatformNetworkManagerStub::SearchForGamesThreadProc(void* lpParameter) { +int IPlatformNetworkStub::SearchForGamesThreadProc(void* lpParameter) { return 0; } -void CPlatformNetworkManagerStub::SetSearchResultsReady(int resultCount) { +void IPlatformNetworkStub::SetSearchResultsReady(int resultCount) { m_bSearchResultsReady = true; m_searchResultsCount[m_lastSearchPad] = resultCount; } -std::vector* CPlatformNetworkManagerStub::GetSessionList( +std::vector* IPlatformNetworkStub::GetSessionList( int iPad, int localPlayers, bool partyOnly) { std::vector* filteredList = new std::vector(); @@ -483,24 +483,24 @@ std::vector* CPlatformNetworkManagerStub::GetSessionList( return filteredList; } -bool CPlatformNetworkManagerStub::GetGameSessionInfo( +bool IPlatformNetworkStub::GetGameSessionInfo( int iPad, SessionID sessionId, FriendSessionInfo* foundSessionInfo) { return false; } -void CPlatformNetworkManagerStub::SetSessionsUpdatedCallback( +void IPlatformNetworkStub::SetSessionsUpdatedCallback( void (*SessionsUpdatedCallback)(void* pParam), void* pSearchParam) { m_SessionsUpdatedCallback = SessionsUpdatedCallback; m_pSearchParam = pSearchParam; } -void CPlatformNetworkManagerStub::GetFullFriendSessionInfo( +void IPlatformNetworkStub::GetFullFriendSessionInfo( FriendSessionInfo* foundSession, void (*FriendSessionUpdatedFn)(bool success, void* pParam), void* pParam) { FriendSessionUpdatedFn(true, pParam); } -void CPlatformNetworkManagerStub::ForceFriendsSessionRefresh() { +void IPlatformNetworkStub::ForceFriendsSessionRefresh() { app.DebugPrintf("Resetting friends session search data\n"); for (unsigned int i = 0; i < XUSER_MAX_COUNT; ++i) { @@ -511,7 +511,7 @@ void CPlatformNetworkManagerStub::ForceFriendsSessionRefresh() { } } -INetworkPlayer* CPlatformNetworkManagerStub::addNetworkPlayer( +INetworkPlayer* IPlatformNetworkStub::addNetworkPlayer( IQNetPlayer* pQNetPlayer) { NetworkPlayerQNet* pNetworkPlayer = new NetworkPlayerQNet(pQNetPlayer); pQNetPlayer->SetCustomDataValue((uintptr_t)pNetworkPlayer); @@ -519,7 +519,7 @@ INetworkPlayer* CPlatformNetworkManagerStub::addNetworkPlayer( return pNetworkPlayer; } -void CPlatformNetworkManagerStub::removeNetworkPlayer( +void IPlatformNetworkStub::removeNetworkPlayer( IQNetPlayer* pQNetPlayer) { INetworkPlayer* pNetworkPlayer = getNetworkPlayer(pQNetPlayer); for (auto it = currentNetworkPlayers.begin(); @@ -531,60 +531,60 @@ void CPlatformNetworkManagerStub::removeNetworkPlayer( } } -INetworkPlayer* CPlatformNetworkManagerStub::getNetworkPlayer( +INetworkPlayer* IPlatformNetworkStub::getNetworkPlayer( IQNetPlayer* pQNetPlayer) { return pQNetPlayer ? (INetworkPlayer*)(pQNetPlayer->GetCustomDataValue()) : nullptr; } -INetworkPlayer* CPlatformNetworkManagerStub::GetLocalPlayerByUserIndex( +INetworkPlayer* IPlatformNetworkStub::GetLocalPlayerByUserIndex( int userIndex) { return getNetworkPlayer(m_pIQNet->GetLocalPlayerByUserIndex(userIndex)); } -INetworkPlayer* CPlatformNetworkManagerStub::GetPlayerByIndex(int playerIndex) { +INetworkPlayer* IPlatformNetworkStub::GetPlayerByIndex(int playerIndex) { return getNetworkPlayer(m_pIQNet->GetPlayerByIndex(playerIndex)); } -INetworkPlayer* CPlatformNetworkManagerStub::GetPlayerByXuid(PlayerUID xuid) { +INetworkPlayer* IPlatformNetworkStub::GetPlayerByXuid(PlayerUID xuid) { return getNetworkPlayer(m_pIQNet->GetPlayerByXuid(xuid)); } -INetworkPlayer* CPlatformNetworkManagerStub::GetPlayerBySmallId( +INetworkPlayer* IPlatformNetworkStub::GetPlayerBySmallId( unsigned char smallId) { return getNetworkPlayer(m_pIQNet->GetPlayerBySmallId(smallId)); } -INetworkPlayer* CPlatformNetworkManagerStub::GetHostPlayer() { +INetworkPlayer* IPlatformNetworkStub::GetHostPlayer() { return getNetworkPlayer(m_pIQNet->GetHostPlayer()); } -bool CPlatformNetworkManagerStub::IsHost() { +bool IPlatformNetworkStub::IsHost() { return m_pIQNet->IsHost() && !m_bHostChanged; } -bool CPlatformNetworkManagerStub::JoinGameFromInviteInfo( +bool IPlatformNetworkStub::JoinGameFromInviteInfo( int userIndex, int userMask, const INVITE_INFO* pInviteInfo) { return (m_pIQNet->JoinGameFromInviteInfo(userIndex, userMask, pInviteInfo) == 0); } -void CPlatformNetworkManagerStub::SetSessionTexturePackParentId(int id) { +void IPlatformNetworkStub::SetSessionTexturePackParentId(int id) { m_hostGameSessionData.texturePackParentId = id; } -void CPlatformNetworkManagerStub::SetSessionSubTexturePackId(int id) { +void IPlatformNetworkStub::SetSessionSubTexturePackId(int id) { m_hostGameSessionData.subTexturePackId = id; } -void CPlatformNetworkManagerStub::Notify(int ID, uintptr_t Param) {} +void IPlatformNetworkStub::Notify(int ID, uintptr_t Param) {} -bool CPlatformNetworkManagerStub::IsInSession() { +bool IPlatformNetworkStub::IsInSession() { return m_pIQNet->GetState() != QNET_STATE_IDLE; } -bool CPlatformNetworkManagerStub::IsInGameplay() { +bool IPlatformNetworkStub::IsInGameplay() { return m_pIQNet->GetState() == QNET_STATE_GAME_PLAY; } -bool CPlatformNetworkManagerStub::IsReadyToPlayOrIdle() { return true; } +bool IPlatformNetworkStub::IsReadyToPlayOrIdle() { return true; } diff --git a/targets/Minecraft.Client/Common/src/Network/PlatformNetworkManagerStub.h b/targets/Minecraft.Client/Common/src/Network/PlatformNetworkManagerStub.h index 66e9e9ad8..4aadb32bf 100644 --- a/targets/Minecraft.Client/Common/src/Network/PlatformNetworkManagerStub.h +++ b/targets/Minecraft.Client/Common/src/Network/PlatformNetworkManagerStub.h @@ -9,7 +9,7 @@ #include "Minecraft.Client/include/SkinBox.h" #include "Minecraft.Client/include/XboxStubs.h" #include "NetworkPlayerInterface.h" -#include "PlatformNetworkManagerInterface.h" +#include "platform/IPlatformNetwork.h" #include "SessionInfo.h" #include "console_helpers/C4JThread.h" @@ -17,7 +17,7 @@ class C4JThread; class CGameNetworkManager; class INetworkPlayer; -class CPlatformNetworkManagerStub : public CPlatformNetworkManager { +class IPlatformNetworkStub : public IPlatformNetwork { friend class CGameNetworkManager; public: diff --git a/targets/minecraft/network/packet/PreLoginPacket.cpp b/targets/minecraft/network/packet/PreLoginPacket.cpp index a05dc91da..3fbfdad21 100644 --- a/targets/minecraft/network/packet/PreLoginPacket.cpp +++ b/targets/minecraft/network/packet/PreLoginPacket.cpp @@ -4,7 +4,7 @@ #include #include "Minecraft.Client/Common/src/BuildVer/BuildVer.h" -#include "Minecraft.Client/Common/src/Network/PlatformNetworkManagerInterface.h" +#include "platform/IPlatformNetwork.h" #include "Minecraft.Client/Linux/Linux_App.h" #include "Minecraft.Client/Linux/Stubs/winapi_stubs.h" #include "PacketListener.h" diff --git a/targets/minecraft/server/network/PendingConnection.cpp b/targets/minecraft/server/network/PendingConnection.cpp index 3a6963faf..e5c39a2fa 100644 --- a/targets/minecraft/server/network/PendingConnection.cpp +++ b/targets/minecraft/server/network/PendingConnection.cpp @@ -10,7 +10,7 @@ #include "Minecraft.Client/Common/App_enums.h" #include "Minecraft.Client/Common/src/BuildVer/BuildVer.h" #include "Minecraft.Client/Common/src/Network/NetworkPlayerInterface.h" -#include "Minecraft.Client/Common/src/Network/PlatformNetworkManagerInterface.h" +#include "platform/IPlatformNetwork.h" #include "Minecraft.Client/Linux/Linux_App.h" #include "Minecraft.Client/Linux/Stubs/winapi_stubs.h" #include "Minecraft.Client/include/NetTypes.h" diff --git a/targets/platform/IPlatformNetwork.h b/targets/platform/IPlatformNetwork.h index 0c94abbac..3cf1babaf 100644 --- a/targets/platform/IPlatformNetwork.h +++ b/targets/platform/IPlatformNetwork.h @@ -5,14 +5,26 @@ #include #include "../4J.Common/4J_Compat.h" +#include "Minecraft.Client/include/NetTypes.h" + +#ifndef VER_NETWORK +#define VER_NETWORK 560 +#endif +#define MINECRAFT_NET_VERSION VER_NETWORK class INetworkPlayer; -class ClientConnection; -class Minecraft; class CGameNetworkManager; struct FriendSessionInfo; -using SessionID = uint64_t; +struct SearchForGamesData { + unsigned int sessionIDCount; + XSESSION_SEARCHRESULT_HEADER* searchBuffer; + XNQOS** ppQos; + SessionID* sessionIDList; + XOVERLAPPED* pOverlapped; +}; + +// TODO: migrate C-style callbacks to std::function or std::function_ref (C++26). class IPlatformNetwork { public: enum eJoinFailedReason { @@ -23,69 +35,112 @@ public: virtual ~IPlatformNetwork() = default; + // Lifecycle virtual bool Initialise(CGameNetworkManager* pGameNetworkManager, int flagIndexSize) = 0; virtual void Terminate() = 0; virtual void DoWork() = 0; + [[nodiscard]] virtual int GetJoiningReadyPercentage() = 0; + [[nodiscard]] virtual int CorrectErrorIDS(int IDS) = 0; // Players - virtual int GetPlayerCount() = 0; - virtual int GetOnlinePlayerCount() = 0; - virtual int GetLocalPlayerMask(int playerIndex) = 0; + [[nodiscard]] virtual int GetPlayerCount() = 0; + [[nodiscard]] virtual int GetOnlinePlayerCount() = 0; + [[nodiscard]] virtual int GetLocalPlayerMask(int playerIndex) = 0; virtual bool AddLocalPlayerByUserIndex(int userIndex) = 0; virtual bool RemoveLocalPlayerByUserIndex(int userIndex) = 0; - virtual INetworkPlayer* GetLocalPlayerByUserIndex(int userIndex) = 0; - virtual INetworkPlayer* GetPlayerByIndex(int playerIndex) = 0; - virtual INetworkPlayer* GetPlayerByXuid(PlayerUID xuid) = 0; - virtual INetworkPlayer* GetPlayerBySmallId(unsigned char smallId) = 0; - virtual INetworkPlayer* GetHostPlayer() = 0; - virtual bool ShouldMessageForFullSession() = 0; + [[nodiscard]] virtual INetworkPlayer* GetLocalPlayerByUserIndex( + int userIndex) = 0; + [[nodiscard]] virtual INetworkPlayer* GetPlayerByIndex( + int playerIndex) = 0; + [[nodiscard]] virtual INetworkPlayer* GetPlayerByXuid(PlayerUID xuid) = 0; + [[nodiscard]] virtual INetworkPlayer* GetPlayerBySmallId( + unsigned char smallId) = 0; + [[nodiscard]] virtual INetworkPlayer* GetHostPlayer() = 0; + [[nodiscard]] virtual bool ShouldMessageForFullSession() = 0; - // Session - virtual bool IsHost() = 0; - virtual bool IsInSession() = 0; - virtual bool IsInGameplay() = 0; - virtual bool IsReadyToPlayOrIdle() = 0; - virtual bool IsInStatsEnabledSession() = 0; - virtual bool SessionHasSpace(unsigned int spaceRequired = 1) = 0; - virtual bool IsAddingPlayer() = 0; - virtual bool IsLocalGame() = 0; - virtual void SetLocalGame(bool isLocal) = 0; - virtual bool IsPrivateGame() = 0; - virtual void SetPrivateGame(bool isPrivate) = 0; - virtual bool IsLeavingGame() = 0; - virtual void ResetLeavingGame() = 0; + // Session state + [[nodiscard]] virtual bool IsHost() = 0; + virtual bool JoinGameFromInviteInfo(int userIndex, int userMask, + const INVITE_INFO* pInviteInfo) = 0; + virtual bool LeaveGame(bool bMigrateHost) = 0; + [[nodiscard]] virtual bool IsInSession() = 0; + [[nodiscard]] virtual bool IsInGameplay() = 0; + [[nodiscard]] virtual bool IsReadyToPlayOrIdle() = 0; + [[nodiscard]] virtual bool IsInStatsEnabledSession() = 0; + [[nodiscard]] virtual bool SessionHasSpace( + unsigned int spaceRequired = 1) = 0; + virtual void SendInviteGUI(int quadrant) = 0; + [[nodiscard]] virtual bool IsAddingPlayer() = 0; // Hosting / joining virtual void HostGame(int localUsersMask, bool bOnlineGame, bool bIsPrivate, - unsigned char publicSlots, - unsigned char privateSlots) = 0; + unsigned char publicSlots = MINECRAFT_NET_MAX_PLAYERS, + unsigned char privateSlots = 0) = 0; virtual int JoinGame(FriendSessionInfo* searchResult, int dwLocalUsersMask, int dwPrimaryUserIndex) = 0; virtual void CancelJoinGame() {} - virtual bool LeaveGame(bool bMigrateHost) = 0; - virtual void SendInviteGUI(int quadrant) = 0; - virtual int GetJoiningReadyPercentage() = 0; + virtual bool SetLocalGame(bool isLocal) = 0; + [[nodiscard]] virtual bool IsLocalGame() = 0; + virtual void SetPrivateGame(bool isPrivate) = 0; + [[nodiscard]] virtual bool IsPrivateGame() = 0; + [[nodiscard]] virtual bool IsLeavingGame() = 0; + virtual void ResetLeavingGame() = 0; // Callbacks virtual void RegisterPlayerChangedCallback( - int iPad, void (*callback)(void*, INetworkPlayer*, bool), + int iPad, + void (*callback)(void* callbackParam, INetworkPlayer* pPlayer, + bool leaving), void* callbackParam) = 0; virtual void UnRegisterPlayerChangedCallback( - int iPad, void (*callback)(void*, INetworkPlayer*, bool), + int iPad, + void (*callback)(void* callbackParam, INetworkPlayer* pPlayer, + bool leaving), void* callbackParam) = 0; virtual void HandleSignInChange() = 0; + // Game loop + virtual bool _RunNetworkGame() = 0; + virtual bool _LeaveGame(bool bMigrateHost, bool bLeaveRoom) = 0; + virtual void _HostGame( + int usersMask, unsigned char publicSlots = MINECRAFT_NET_MAX_PLAYERS, + unsigned char privateSlots = 0) = 0; + virtual bool _StartGame() = 0; + + // Session data + virtual void UpdateAndSetGameSessionData( + INetworkPlayer* pNetworkPlayerLeaving = nullptr) = 0; + virtual bool RemoveLocalPlayer(INetworkPlayer* pNetworkPlayer) = 0; + + // System flags + virtual void SystemFlagSet(INetworkPlayer* pNetworkPlayer, int index) = 0; + [[nodiscard]] virtual bool SystemFlagGet(INetworkPlayer* pNetworkPlayer, + int index) = 0; + // Stats - virtual std::wstring GatherStats() = 0; - virtual std::wstring GatherRTTStats() = 0; + [[nodiscard]] virtual std::wstring GatherStats() = 0; + [[nodiscard]] virtual std::wstring GatherRTTStats() = 0; + + // Session internals + virtual void SetSessionTexturePackParentId(int id) = 0; + virtual void SetSessionSubTexturePackId(int id) = 0; + virtual void Notify(int ID, uintptr_t Param) = 0; // Session list - virtual std::vector* GetSessionList(int iPad, - int localPlayers, - bool partyOnly) = 0; + [[nodiscard]] virtual std::vector* GetSessionList( + int iPad, int localPlayers, bool partyOnly) = 0; + [[nodiscard]] virtual bool GetGameSessionInfo( + int iPad, SessionID sessionId, FriendSessionInfo* foundSession) = 0; virtual void SetSessionsUpdatedCallback( - void (*SessionsUpdatedCallback)(void*), void* pSearchParam) = 0; + void (*SessionsUpdatedCallback)(void* pParam), + void* pSearchParam) = 0; + virtual void GetFullFriendSessionInfo( + FriendSessionInfo* foundSession, + void (*FriendSessionUpdatedFn)(bool success, void* pParam), + void* pParam) = 0; virtual void ForceFriendsSessionRefresh() = 0; + + virtual void FakeLocalPlayerJoined() {} };