From b20b8cb31110ea4e2d72ce1b9252309a1ce17c4b Mon Sep 17 00:00:00 2001 From: Tropical <42101043+tropicaaal@users.noreply.github.com> Date: Thu, 9 Apr 2026 22:07:16 -0500 Subject: [PATCH] properly implement network interface stub --- targets/app/common/Game.cpp | 2 +- targets/app/common/Game_XuiActions.cpp | 2 +- .../app/common/Network/GameNetworkManager.cpp | 4 +- .../app/common/Network/GameNetworkManager.h | 11 +- .../Constraints/ChangeStateConstraint.cpp | 2 +- .../UIScene_JoinMenu.cpp | 2 +- .../UIScene_LoadOrJoinMenu.cpp | 2 +- .../UIScene_InGameHostOptionsMenu.cpp | 2 +- .../UIScene_InGameInfoMenu.cpp | 2 +- .../UIScene_InGamePlayerOptionsMenu.cpp | 2 +- .../UIScene_TeleportMenu.cpp | 2 +- targets/minecraft/client/Minecraft.cpp | 2 +- .../client/multiplayer/ClientConnection.cpp | 2 +- targets/minecraft/network/Connection.cpp | 2 +- targets/minecraft/network/Socket.cpp | 2 +- targets/minecraft/network/Socket.h | 2 +- .../network/packet/PlayerInfoPacket.cpp | 2 +- targets/minecraft/server/MinecraftServer.cpp | 2 +- targets/minecraft/server/PlayerList.cpp | 2 +- .../minecraft/server/level/EntityTracker.cpp | 2 +- .../minecraft/server/level/PlayerChunkMap.cpp | 2 +- .../minecraft/server/level/ServerLevel.cpp | 2 +- .../minecraft/server/level/ServerPlayer.cpp | 2 +- .../minecraft/server/level/TrackedEntity.cpp | 2 +- .../server/network/PendingConnection.cpp | 2 +- .../server/network/PlayerConnection.cpp | 2 +- targets/platform/NetTypes.h | 61 --- .../network/INetworkPlayer.h} | 0 .../network}/SessionInfo.h | 0 targets/platform/network/meson.build | 2 +- targets/platform/network/network.h | 2 + .../network/stub/StubNetworkPlayer.cpp | 53 ++ .../platform/network/stub/StubNetworkPlayer.h | 52 ++ .../network/stub/StubPlatformNetwork.cpp | 516 ++++++++++++++++++ .../network/stub/StubPlatformNetwork.h | 269 +++++---- 35 files changed, 816 insertions(+), 202 deletions(-) rename targets/{minecraft/network/platform/NetworkPlayerInterface.h => platform/network/INetworkPlayer.h} (100%) rename targets/{minecraft/network/platform => platform/network}/SessionInfo.h (100%) create mode 100644 targets/platform/network/stub/StubNetworkPlayer.cpp create mode 100644 targets/platform/network/stub/StubNetworkPlayer.h diff --git a/targets/app/common/Game.cpp b/targets/app/common/Game.cpp index 7bd8be6ef..b2f1c5a0a 100644 --- a/targets/app/common/Game.cpp +++ b/targets/app/common/Game.cpp @@ -32,7 +32,7 @@ #include "minecraft/client/renderer/entity/EntityRenderer.h" #include "minecraft/client/skins/TexturePack.h" #include "minecraft/network/packet/DisconnectPacket.h" -#include "minecraft/network/platform/NetworkPlayerInterface.h" +#include "platform/network/network.h" #include "minecraft/server/MinecraftServer.h" #include "minecraft/stats/StatsCounter.h" #include "minecraft/world/Container.h" diff --git a/targets/app/common/Game_XuiActions.cpp b/targets/app/common/Game_XuiActions.cpp index dde40f3ce..042cc5bdc 100644 --- a/targets/app/common/Game_XuiActions.cpp +++ b/targets/app/common/Game_XuiActions.cpp @@ -26,7 +26,7 @@ #include "minecraft/client/skins/DLCTexturePack.h" #include "minecraft/client/skins/TexturePack.h" #include "minecraft/client/skins/TexturePackRepository.h" -#include "minecraft/network/platform/NetworkPlayerInterface.h" +#include "platform/network/network.h" #include "minecraft/server/MinecraftServer.h" #include "minecraft/stats/StatsCounter.h" #include "platform/PlatformTypes.h" diff --git a/targets/app/common/Network/GameNetworkManager.cpp b/targets/app/common/Network/GameNetworkManager.cpp index e4cf90893..4a971e2a9 100644 --- a/targets/app/common/Network/GameNetworkManager.cpp +++ b/targets/app/common/Network/GameNetworkManager.cpp @@ -32,7 +32,7 @@ #include "minecraft/network/Connection.h" #include "minecraft/network/packet/DisconnectPacket.h" #include "minecraft/network/packet/PreLoginPacket.h" -#include "minecraft/network/platform/NetworkPlayerInterface.h" +#include "platform/network/network.h" #include "minecraft/server/MinecraftServer.h" #include "minecraft/server/PlayerList.h" #include "minecraft/server/ServerAction.h" @@ -381,7 +381,7 @@ bool CGameNetworkManager::StartNetworkGame(Minecraft* minecraft, Socket* socket = pNetworkPlayer->GetSocket(); app.DebugPrintf( "Closing socket due to player %d not being signed in any " - "more\n"); + "more\n", idx); if (!socket->close(false)) socket->close(true); continue; diff --git a/targets/app/common/Network/GameNetworkManager.h b/targets/app/common/Network/GameNetworkManager.h index 5cde30a6b..941e1e7b8 100644 --- a/targets/app/common/Network/GameNetworkManager.h +++ b/targets/app/common/Network/GameNetworkManager.h @@ -7,13 +7,12 @@ #if !defined(__linux__) #include #endif -#include "platform/network/IPlatformNetwork.h" #include "minecraft/network/INetworkService.h" -#include "minecraft/network/platform/NetworkPlayerInterface.h" -#include "minecraft/network/platform/SessionInfo.h" #include "platform/C4JThread.h" #include "platform/NetTypes.h" #include "platform/PlatformTypes.h" +#include "platform/network/IPlatformNetwork.h" +#include "platform/network/network.h" class ClientConnection; class Minecraft; @@ -158,7 +157,10 @@ public: static int messageQueuePos; // Methods called from PlatformNetworkManager -private: + // 4jcraft: made these public, we can't friend class StubPlatformNetwork + // here like before because that would be naming an opaque platform backend + // class, plus this API is shit so i dont care +public: void StateChange_AnyToHosting(); void StateChange_AnyToJoining(); void StateChange_JoiningToIdle(IPlatformNetwork::eJoinFailedReason reason); @@ -187,7 +189,6 @@ private: bool m_bInitialised; private: - float m_lastPlayerEventTimeStart; // For telemetry static IPlatformNetwork* s_pPlatformNetworkManager; bool m_bNetworkThreadRunning; int GetJoiningReadyPercentage(); diff --git a/targets/app/common/Tutorial/Constraints/ChangeStateConstraint.cpp b/targets/app/common/Tutorial/Constraints/ChangeStateConstraint.cpp index b7e8aa211..58c08a47d 100644 --- a/targets/app/common/Tutorial/Constraints/ChangeStateConstraint.cpp +++ b/targets/app/common/Tutorial/Constraints/ChangeStateConstraint.cpp @@ -9,7 +9,7 @@ #include "minecraft/client/multiplayer/ClientConnection.h" #include "minecraft/client/multiplayer/MultiPlayerLocalPlayer.h" #include "minecraft/network/packet/PlayerInfoPacket.h" -#include "minecraft/network/platform/NetworkPlayerInterface.h" +#include "platform/network/network.h" #include "minecraft/world/entity/player/Abilities.h" #include "minecraft/world/entity/player/Player.h" #include "minecraft/world/level/LevelSettings.h" diff --git a/targets/app/common/UI/Scenes/Frontend Menu screens/UIScene_JoinMenu.cpp b/targets/app/common/UI/Scenes/Frontend Menu screens/UIScene_JoinMenu.cpp index 0152096ce..ea463c8e7 100644 --- a/targets/app/common/UI/Scenes/Frontend Menu screens/UIScene_JoinMenu.cpp +++ b/targets/app/common/UI/Scenes/Frontend Menu screens/UIScene_JoinMenu.cpp @@ -15,7 +15,7 @@ #include "app/linux/Linux_UIController.h" #include "minecraft/GameEnums.h" #include "minecraft/GameTypes.h" -#include "minecraft/network/platform/SessionInfo.h" +#include "platform/network/network.h" #include "app/common/Audio/SoundTypes.h" #include "minecraft/world/Difficulty.h" #include "minecraft/world/level/LevelSettings.h" diff --git a/targets/app/common/UI/Scenes/Frontend Menu screens/UIScene_LoadOrJoinMenu.cpp b/targets/app/common/UI/Scenes/Frontend Menu screens/UIScene_LoadOrJoinMenu.cpp index 4e89e4cda..049b74d94 100644 --- a/targets/app/common/UI/Scenes/Frontend Menu screens/UIScene_LoadOrJoinMenu.cpp +++ b/targets/app/common/UI/Scenes/Frontend Menu screens/UIScene_LoadOrJoinMenu.cpp @@ -21,7 +21,7 @@ #include "minecraft/client/Minecraft.h" #include "minecraft/client/skins/TexturePack.h" #include "minecraft/client/skins/TexturePackRepository.h" -#include "minecraft/network/platform/SessionInfo.h" +#include "platform/network/network.h" #include "minecraft/server/MinecraftServer.h" #include "app/common/Audio/SoundTypes.h" #include "minecraft/world/level/GameRules/LevelGenerationOptions.h" diff --git a/targets/app/common/UI/Scenes/In-Game Menu Screens/UIScene_InGameHostOptionsMenu.cpp b/targets/app/common/UI/Scenes/In-Game Menu Screens/UIScene_InGameHostOptionsMenu.cpp index e1f56c6e6..f4fabe66a 100644 --- a/targets/app/common/UI/Scenes/In-Game Menu Screens/UIScene_InGameHostOptionsMenu.cpp +++ b/targets/app/common/UI/Scenes/In-Game Menu Screens/UIScene_InGameHostOptionsMenu.cpp @@ -15,7 +15,7 @@ #include "minecraft/client/multiplayer/ClientConnection.h" #include "minecraft/client/multiplayer/MultiPlayerLocalPlayer.h" #include "minecraft/network/packet/ServerSettingsChangedPacket.h" -#include "minecraft/network/platform/NetworkPlayerInterface.h" +#include "platform/network/network.h" #include "minecraft/world/entity/player/Player.h" #include "strings.h" diff --git a/targets/app/common/UI/Scenes/In-Game Menu Screens/UIScene_InGameInfoMenu.cpp b/targets/app/common/UI/Scenes/In-Game Menu Screens/UIScene_InGameInfoMenu.cpp index 2fd951e2a..7022e00e1 100644 --- a/targets/app/common/UI/Scenes/In-Game Menu Screens/UIScene_InGameInfoMenu.cpp +++ b/targets/app/common/UI/Scenes/In-Game Menu Screens/UIScene_InGameInfoMenu.cpp @@ -17,7 +17,7 @@ #include "minecraft/client/multiplayer/ClientConnection.h" #include "minecraft/client/multiplayer/MultiPlayerLocalPlayer.h" #include "minecraft/network/packet/KickPlayerPacket.h" -#include "minecraft/network/platform/NetworkPlayerInterface.h" +#include "platform/network/network.h" #include "app/common/Audio/SoundTypes.h" #include "platform/PlatformTypes.h" #include "platform/profile/profile.h" diff --git a/targets/app/common/UI/Scenes/In-Game Menu Screens/UIScene_InGamePlayerOptionsMenu.cpp b/targets/app/common/UI/Scenes/In-Game Menu Screens/UIScene_InGamePlayerOptionsMenu.cpp index 5e6dac856..e8eed0628 100644 --- a/targets/app/common/UI/Scenes/In-Game Menu Screens/UIScene_InGamePlayerOptionsMenu.cpp +++ b/targets/app/common/UI/Scenes/In-Game Menu Screens/UIScene_InGamePlayerOptionsMenu.cpp @@ -18,7 +18,7 @@ #include "minecraft/client/multiplayer/MultiPlayerLocalPlayer.h" #include "minecraft/network/packet/KickPlayerPacket.h" #include "minecraft/network/packet/PlayerInfoPacket.h" -#include "minecraft/network/platform/NetworkPlayerInterface.h" +#include "platform/network/network.h" #include "minecraft/world/entity/player/Player.h" #include "strings.h" diff --git a/targets/app/common/UI/Scenes/In-Game Menu Screens/UIScene_TeleportMenu.cpp b/targets/app/common/UI/Scenes/In-Game Menu Screens/UIScene_TeleportMenu.cpp index deacafb36..303d60426 100644 --- a/targets/app/common/UI/Scenes/In-Game Menu Screens/UIScene_TeleportMenu.cpp +++ b/targets/app/common/UI/Scenes/In-Game Menu Screens/UIScene_TeleportMenu.cpp @@ -15,7 +15,7 @@ #include "minecraft/client/Minecraft.h" #include "minecraft/client/multiplayer/ClientConnection.h" #include "minecraft/network/packet/GameCommandPacket.h" -#include "minecraft/network/platform/NetworkPlayerInterface.h" +#include "platform/network/network.h" #include "minecraft/server/commands/TeleportCommand.h" #include "app/common/Audio/SoundTypes.h" #include "strings.h" diff --git a/targets/minecraft/client/Minecraft.cpp b/targets/minecraft/client/Minecraft.cpp index 803f983e1..2ab42b8fa 100644 --- a/targets/minecraft/client/Minecraft.cpp +++ b/targets/minecraft/client/Minecraft.cpp @@ -53,7 +53,7 @@ #include "minecraft/network/INetworkService.h" #include "minecraft/network/packet/DisconnectPacket.h" #include "minecraft/network/packet/Packet.h" -#include "minecraft/network/platform/NetworkPlayerInterface.h" +#include "platform/network/network.h" #include "app/common/Audio/SoundTypes.h" #include "minecraft/stats/Stats.h" #include "minecraft/stats/StatsCounter.h" diff --git a/targets/minecraft/client/multiplayer/ClientConnection.cpp b/targets/minecraft/client/multiplayer/ClientConnection.cpp index 956924086..c03b834fe 100644 --- a/targets/minecraft/client/multiplayer/ClientConnection.cpp +++ b/targets/minecraft/client/multiplayer/ClientConnection.cpp @@ -112,7 +112,7 @@ #include "minecraft/network/packet/UpdateMobEffectPacket.h" #include "minecraft/network/packet/UpdateProgressPacket.h" #include "minecraft/network/packet/XZPacket.h" -#include "minecraft/network/platform/NetworkPlayerInterface.h" +#include "platform/network/network.h" #include "minecraft/server/MinecraftServer.h" #include "app/common/Audio/SoundTypes.h" #include "minecraft/stats/GenericStats.h" diff --git a/targets/minecraft/network/Connection.cpp b/targets/minecraft/network/Connection.cpp index c264bcf16..583c9402f 100644 --- a/targets/minecraft/network/Connection.cpp +++ b/targets/minecraft/network/Connection.cpp @@ -16,7 +16,7 @@ #include "minecraft/network/packet/KeepAlivePacket.h" #include "minecraft/network/packet/Packet.h" #include "minecraft/network/packet/PacketListener.h" -#include "minecraft/network/platform/NetworkPlayerInterface.h" +#include "platform/network/network.h" #include "minecraft/world/level/storage/ConsoleSaveFileIO/compression.h" #include "platform/ShutdownManager.h" #include "util/StringHelpers.h" diff --git a/targets/minecraft/network/Socket.cpp b/targets/minecraft/network/Socket.cpp index 87d0672f2..58f1e5b76 100644 --- a/targets/minecraft/network/Socket.cpp +++ b/targets/minecraft/network/Socket.cpp @@ -7,7 +7,7 @@ #include #include "app/common/Network/GameNetworkManager.h" -#include "minecraft/network/platform/NetworkPlayerInterface.h" +#include "platform/network/network.h" #include "minecraft/server/network/ServerConnection.h" #include "platform/NetTypes.h" #include "platform/ShutdownManager.h" diff --git a/targets/minecraft/network/Socket.h b/targets/minecraft/network/Socket.h index 787e8c251..380e6b4e1 100644 --- a/targets/minecraft/network/Socket.h +++ b/targets/minecraft/network/Socket.h @@ -12,7 +12,7 @@ #include "java/InputOutputStream/InputStream.h" #include "java/InputOutputStream/OutputStream.h" -#include "minecraft/network/platform/NetworkPlayerInterface.h" +#include "platform/network/network.h" #include "platform/C4JThread.h" class INetworkPlayer; diff --git a/targets/minecraft/network/packet/PlayerInfoPacket.cpp b/targets/minecraft/network/packet/PlayerInfoPacket.cpp index 9a90c1c8c..f86955a7e 100644 --- a/targets/minecraft/network/packet/PlayerInfoPacket.cpp +++ b/targets/minecraft/network/packet/PlayerInfoPacket.cpp @@ -1,7 +1,7 @@ #include "java/InputOutputStream/DataInputStream.h" #include "java/InputOutputStream/DataOutputStream.h" #include "minecraft/network/packet/PacketListener.h" -#include "minecraft/network/platform/NetworkPlayerInterface.h" +#include "platform/network/network.h" #include "minecraft/server/level/ServerPlayer.h" #include "minecraft/server/network/PlayerConnection.h" #ifndef __linux__ diff --git a/targets/minecraft/server/MinecraftServer.cpp b/targets/minecraft/server/MinecraftServer.cpp index fc80d358e..dce5f4509 100644 --- a/targets/minecraft/server/MinecraftServer.cpp +++ b/targets/minecraft/server/MinecraftServer.cpp @@ -31,7 +31,7 @@ #include "minecraft/network/packet/ServerSettingsChangedPacket.h" #include "minecraft/network/packet/SetTimePacket.h" #include "minecraft/network/packet/UpdateProgressPacket.h" -#include "minecraft/network/platform/NetworkPlayerInterface.h" +#include "platform/network/network.h" #include "minecraft/server/level/DerivedServerLevel.h" #include "minecraft/server/level/EntityTracker.h" #include "minecraft/server/level/ServerChunkCache.h" diff --git a/targets/minecraft/server/PlayerList.cpp b/targets/minecraft/server/PlayerList.cpp index d123c9262..5846bb049 100644 --- a/targets/minecraft/server/PlayerList.cpp +++ b/targets/minecraft/server/PlayerList.cpp @@ -36,7 +36,7 @@ #include "minecraft/network/packet/TexturePacket.h" #include "minecraft/network/packet/UpdateMobEffectPacket.h" #include "minecraft/network/packet/XZPacket.h" -#include "minecraft/network/platform/NetworkPlayerInterface.h" +#include "platform/network/network.h" #include "minecraft/server/level/EntityTracker.h" #include "minecraft/server/level/PlayerChunkMap.h" #include "minecraft/server/level/ServerChunkCache.h" diff --git a/targets/minecraft/server/level/EntityTracker.cpp b/targets/minecraft/server/level/EntityTracker.cpp index 6a3f3e1bd..e5a186478 100644 --- a/targets/minecraft/server/level/EntityTracker.cpp +++ b/targets/minecraft/server/level/EntityTracker.cpp @@ -11,7 +11,7 @@ #include "ServerPlayer.h" #include "TrackedEntity.h" #include "java/Class.h" -#include "minecraft/network/platform/NetworkPlayerInterface.h" +#include "platform/network/network.h" #include "minecraft/server/MinecraftServer.h" #include "minecraft/server/PlayerList.h" #include "minecraft/server/network/PlayerConnection.h" diff --git a/targets/minecraft/server/level/PlayerChunkMap.cpp b/targets/minecraft/server/level/PlayerChunkMap.cpp index e5f96814e..58513f308 100644 --- a/targets/minecraft/server/level/PlayerChunkMap.cpp +++ b/targets/minecraft/server/level/PlayerChunkMap.cpp @@ -19,7 +19,7 @@ #include "minecraft/network/packet/ChunkVisibilityPacket.h" #include "minecraft/network/packet/Packet.h" #include "minecraft/network/packet/TileUpdatePacket.h" -#include "minecraft/network/platform/NetworkPlayerInterface.h" +#include "platform/network/network.h" #include "minecraft/server/MinecraftServer.h" #include "minecraft/server/PlayerList.h" #include "minecraft/server/network/PlayerConnection.h" diff --git a/targets/minecraft/server/level/ServerLevel.cpp b/targets/minecraft/server/level/ServerLevel.cpp index 6a493ffa2..e041d390e 100644 --- a/targets/minecraft/server/level/ServerLevel.cpp +++ b/targets/minecraft/server/level/ServerLevel.cpp @@ -24,7 +24,7 @@ #include "minecraft/network/packet/GameEventPacket.h" #include "minecraft/network/packet/LevelParticlesPacket.h" #include "minecraft/network/packet/TileEventPacket.h" -#include "minecraft/network/platform/NetworkPlayerInterface.h" +#include "platform/network/network.h" #include "minecraft/server/MinecraftServer.h" #include "minecraft/server/PlayerList.h" #include "minecraft/server/ServerScoreboard.h" diff --git a/targets/minecraft/server/level/ServerPlayer.cpp b/targets/minecraft/server/level/ServerPlayer.cpp index da588f35a..290930124 100644 --- a/targets/minecraft/server/level/ServerPlayer.cpp +++ b/targets/minecraft/server/level/ServerPlayer.cpp @@ -45,7 +45,7 @@ #include "minecraft/network/packet/SetHealthPacket.h" #include "minecraft/network/packet/TileEditorOpenPacket.h" #include "minecraft/network/packet/UpdateMobEffectPacket.h" -#include "minecraft/network/platform/NetworkPlayerInterface.h" +#include "platform/network/network.h" #include "minecraft/server/MinecraftServer.h" #include "minecraft/server/PlayerList.h" #include "minecraft/server/network/PlayerConnection.h" diff --git a/targets/minecraft/server/level/TrackedEntity.cpp b/targets/minecraft/server/level/TrackedEntity.cpp index 47bfb3a04..254c7e8e1 100644 --- a/targets/minecraft/server/level/TrackedEntity.cpp +++ b/targets/minecraft/server/level/TrackedEntity.cpp @@ -29,7 +29,7 @@ #include "minecraft/network/packet/TeleportEntityPacket.h" #include "minecraft/network/packet/UpdateAttributesPacket.h" #include "minecraft/network/packet/UpdateMobEffectPacket.h" -#include "minecraft/network/platform/NetworkPlayerInterface.h" +#include "platform/network/network.h" #include "minecraft/server/MinecraftServer.h" #include "minecraft/server/PlayerList.h" #include "minecraft/server/network/PlayerConnection.h" diff --git a/targets/minecraft/server/network/PendingConnection.cpp b/targets/minecraft/server/network/PendingConnection.cpp index 7c1c257c3..d01771dd2 100644 --- a/targets/minecraft/server/network/PendingConnection.cpp +++ b/targets/minecraft/server/network/PendingConnection.cpp @@ -16,7 +16,7 @@ #include "minecraft/network/packet/DisconnectPacket.h" #include "minecraft/network/packet/LoginPacket.h" #include "minecraft/network/packet/PreLoginPacket.h" -#include "minecraft/network/platform/NetworkPlayerInterface.h" +#include "platform/network/network.h" #include "minecraft/server/MinecraftServer.h" #include "minecraft/server/PlayerList.h" #include "minecraft/server/level/ServerPlayer.h" diff --git a/targets/minecraft/server/network/PlayerConnection.cpp b/targets/minecraft/server/network/PlayerConnection.cpp index 62053dc4f..aa9d1132f 100644 --- a/targets/minecraft/server/network/PlayerConnection.cpp +++ b/targets/minecraft/server/network/PlayerConnection.cpp @@ -61,7 +61,7 @@ #include "minecraft/network/packet/TileUpdatePacket.h" #include "minecraft/network/packet/TradeItemPacket.h" #include "minecraft/network/packet/UseItemPacket.h" -#include "minecraft/network/platform/NetworkPlayerInterface.h" +#include "platform/network/network.h" #include "minecraft/server/MinecraftServer.h" #include "minecraft/server/PlayerList.h" #include "minecraft/server/level/ServerLevel.h" diff --git a/targets/platform/NetTypes.h b/targets/platform/NetTypes.h index 8c31bcaa7..3397058cd 100644 --- a/targets/platform/NetTypes.h +++ b/targets/platform/NetTypes.h @@ -60,67 +60,6 @@ public: } }; -class IQNetPlayer { -public: - uint8_t GetSmallId(); - void SendData(IQNetPlayer* player, const void* pvData, uint32_t dwDataSize, - uint32_t dwFlags); - bool IsSameSystem(IQNetPlayer* player); - uint32_t GetSendQueueSize(IQNetPlayer* player, uint32_t dwFlags); - uint32_t GetCurrentRtt(); - bool IsHost(); - bool IsGuest(); - bool IsLocal(); - PlayerUID GetXuid(); - const char* GetGamertag(); - int GetSessionIndex(); - bool IsTalking(); - bool IsMutedByLocalUser(uint32_t dwUserIndex); - bool HasVoice(); - bool HasCamera(); - int GetUserIndex(); - void SetCustomDataValue(uintptr_t ulpCustomDataValue); - uintptr_t GetCustomDataValue(); - -private: - uintptr_t m_customData; -}; - -enum QNET_STATE { - QNET_STATE_IDLE, - QNET_STATE_SESSION_HOSTING, - QNET_STATE_SESSION_JOINING, - QNET_STATE_GAME_LOBBY, - QNET_STATE_SESSION_REGISTERING, - QNET_STATE_SESSION_STARTING, - QNET_STATE_GAME_PLAY, - QNET_STATE_SESSION_ENDING, - QNET_STATE_SESSION_LEAVING, - QNET_STATE_SESSION_DELETING -}; - -class IQNet { -public: - int32_t AddLocalPlayerByUserIndex(uint32_t dwUserIndex); - IQNetPlayer* GetHostPlayer(); - IQNetPlayer* GetLocalPlayerByUserIndex(uint32_t dwUserIndex); - IQNetPlayer* GetPlayerByIndex(uint32_t dwPlayerIndex); - IQNetPlayer* GetPlayerBySmallId(uint8_t SmallId); - IQNetPlayer* GetPlayerByXuid(PlayerUID xuid); - uint32_t GetPlayerCount(); - QNET_STATE GetState(); - bool IsHost(); - int32_t JoinGameFromInviteInfo(uint32_t dwUserIndex, uint32_t dwUserMask, - const INVITE_INFO* pInviteInfo); - void HostGame(); - void EndGame(); - - static IQNetPlayer m_player[4]; -}; - -class IQNetCallbacks {}; -class IQNetGameSearch {}; - struct XNQOSINFO { uint8_t bFlags; uint8_t bReserved; diff --git a/targets/minecraft/network/platform/NetworkPlayerInterface.h b/targets/platform/network/INetworkPlayer.h similarity index 100% rename from targets/minecraft/network/platform/NetworkPlayerInterface.h rename to targets/platform/network/INetworkPlayer.h diff --git a/targets/minecraft/network/platform/SessionInfo.h b/targets/platform/network/SessionInfo.h similarity index 100% rename from targets/minecraft/network/platform/SessionInfo.h rename to targets/platform/network/SessionInfo.h diff --git a/targets/platform/network/meson.build b/targets/platform/network/meson.build index a7ea6b5a0..dab092568 100644 --- a/targets/platform/network/meson.build +++ b/targets/platform/network/meson.build @@ -1 +1 @@ -platform_network_sources = files('stub/StubPlatformNetwork.cpp') +platform_network_sources = files('stub/StubPlatformNetwork.cpp', 'stub/StubNetworkPlayer.cpp') diff --git a/targets/platform/network/network.h b/targets/platform/network/network.h index 47f56fc30..9cd2be5a0 100644 --- a/targets/platform/network/network.h +++ b/targets/platform/network/network.h @@ -1,6 +1,8 @@ #pragma once #include "IPlatformNetwork.h" +#include "INetworkPlayer.h" +#include "SessionInfo.h" // Function accessor backed by a function-local static (Meyers singleton). // Same shape as platform/profile/profile.h: avoids the static-init-order diff --git a/targets/platform/network/stub/StubNetworkPlayer.cpp b/targets/platform/network/stub/StubNetworkPlayer.cpp new file mode 100644 index 000000000..987768ae8 --- /dev/null +++ b/targets/platform/network/stub/StubNetworkPlayer.cpp @@ -0,0 +1,53 @@ +#include "StubNetworkPlayer.h" + +#include "StubPlatformNetwork.h" +#include "java/System.h" +#include "platform/NetTypes.h" +#include "platform/PlatformTypes.h" + +StubNetworkPlayer::StubNetworkPlayer() { m_pSocket = nullptr; } + +uint8_t StubNetworkPlayer::GetSmallId() { return 0; } +void StubNetworkPlayer::SendData(INetworkPlayer* player, const void* pvData, + int dataSize, bool lowPriority, bool ack) {} +bool StubNetworkPlayer::IsSameSystem(INetworkPlayer* player) { return true; } +int StubNetworkPlayer::GetOutstandingAckCount() { return 0; } +int StubNetworkPlayer::GetSendQueueSizeBytes(INetworkPlayer* player, + bool lowPriority) { + return 0; +} +int StubNetworkPlayer::GetSendQueueSizeMessages(INetworkPlayer* player, + bool lowPriority) { + return 0; +} +int StubNetworkPlayer::GetCurrentRtt() { return 0; } +bool StubNetworkPlayer::IsHost() { + return this == &StubPlatformNetwork::m_players[0]; +} +bool StubNetworkPlayer::IsGuest() { return false; } +bool StubNetworkPlayer::IsLocal() { return true; } +int StubNetworkPlayer::GetSessionIndex() { return 0; } +bool StubNetworkPlayer::IsTalking() { return false; } +bool StubNetworkPlayer::IsMutedByLocalUser(int dwUserIndex) { return false; } +bool StubNetworkPlayer::HasVoice() { return false; } +bool StubNetworkPlayer::HasCamera() { return false; } +void StubNetworkPlayer::SetSocket(Socket* pSocket) { m_pSocket = pSocket; } +Socket* StubNetworkPlayer::GetSocket() { return m_pSocket; } +PlayerUID StubNetworkPlayer::GetUID() { return INVALID_XUID; } +const char* StubNetworkPlayer::GetOnlineName() { return "stub"; } +std::string StubNetworkPlayer::GetDisplayName() { return "stub"; } +int StubNetworkPlayer::GetUserIndex() { + return this - &StubPlatformNetwork::m_players[0]; +} +void StubNetworkPlayer::SentChunkPacket() { + m_lastChunkPacketTime = System::currentTimeMillis(); +} +int StubNetworkPlayer::GetTimeSinceLastChunkPacket_ms() { + // If we haven't ever sent a packet, return maximum + if (m_lastChunkPacketTime == 0) { + return INT_MAX; + } + + const int64_t currentTime = System::currentTimeMillis(); + return static_cast(currentTime - m_lastChunkPacketTime); +} diff --git a/targets/platform/network/stub/StubNetworkPlayer.h b/targets/platform/network/stub/StubNetworkPlayer.h new file mode 100644 index 000000000..f317ab6d8 --- /dev/null +++ b/targets/platform/network/stub/StubNetworkPlayer.h @@ -0,0 +1,52 @@ +#pragma once + +#include + +#include + +#include "platform/network/network.h" +#include "platform/NetTypes.h" +#include "platform/PlatformTypes.h" + +class Socket; + +// This is an implementation of the INetworkPlayer interface for the supported +// QNet-backed path. It +// effectively wraps the StubNetworkPlayer class in a non-platform-specific way. It is +// managed by PlatformNetworkManagerStub. + +class StubNetworkPlayer : public INetworkPlayer { +public: + StubNetworkPlayer(); + + // Common player interface + unsigned char GetSmallId(); + void SendData(INetworkPlayer* player, const void* pvData, + int dataSize, bool lowPriority, bool ack); + bool IsSameSystem(INetworkPlayer* player); + int GetOutstandingAckCount(); + int GetSendQueueSizeBytes(INetworkPlayer* player, bool lowPriority); + int GetSendQueueSizeMessages(INetworkPlayer* player, + bool lowPriority); + int GetCurrentRtt(); + bool IsHost(); + bool IsGuest(); + bool IsLocal(); + int GetSessionIndex(); + bool IsTalking(); + bool IsMutedByLocalUser(int userIndex); + bool HasVoice(); + bool HasCamera(); + int GetUserIndex(); + void SetSocket(Socket* pSocket); + Socket* GetSocket(); + const char* GetOnlineName(); + std::string GetDisplayName(); + PlayerUID GetUID(); + void SentChunkPacket(); + int GetTimeSinceLastChunkPacket_ms(); + +private: + int64_t m_lastChunkPacketTime; + Socket* m_pSocket; +}; \ No newline at end of file diff --git a/targets/platform/network/stub/StubPlatformNetwork.cpp b/targets/platform/network/stub/StubPlatformNetwork.cpp index 1394ef82c..6ed39ac96 100644 --- a/targets/platform/network/stub/StubPlatformNetwork.cpp +++ b/targets/platform/network/stub/StubPlatformNetwork.cpp @@ -1,5 +1,15 @@ #include "StubPlatformNetwork.h" +#include +#include + +#include + +#include "StubNetworkPlayer.h" +#include "app/common/Network/GameNetworkManager.h" +#include "minecraft/network/Socket.h" +#include "platform/C4JThread.h" +#include "platform/NetTypes.h" #include "platform/network/network.h" namespace platform_internal { @@ -8,3 +18,509 @@ IPlatformNetwork& PlatformNetwork_get() { return instance; } } // namespace platform_internal + +static bool s_gameRunning = false; +StubNetworkPlayer StubPlatformNetwork::m_players[4]; + +void StubPlatformNetwork::NotifyPlayerJoined(INetworkPlayer* pQNetPlayer) { + const char* pszDescription; + + // 4J Stu - We create a fake socket for every where that we need an INBOUND + // queue of game data. Outbound is all handled by QNet so we don't need + // that. Therefore each client player has one, and the host has one for each + // client player. + bool createFakeSocket = false; + bool localPlayer = false; + + INetworkPlayer* networkPlayer = + (INetworkPlayer*)addNetworkPlayer(pQNetPlayer); + + if (pQNetPlayer->IsLocal()) { + localPlayer = true; + if (pQNetPlayer->IsHost()) { + pszDescription = "local host"; + // 4J Stu - No socket for the localhost as it uses a special + // loopback queue + + m_machineQNetPrimaryPlayers.push_back(pQNetPlayer); + } else { + pszDescription = "local"; + + // We need an inbound queue on all local players to receive data + // from the host + createFakeSocket = true; + } + } else { + if (pQNetPlayer->IsHost()) { + pszDescription = "remote host"; + } else { + pszDescription = "remote"; + + // If we are the host, then create a fake socket for every remote + // player + if (IsHost()) { + createFakeSocket = true; + } + } + + if (IsHost() && !m_bHostChanged) { + // Do we already have a primary player for this system? + bool systemHasPrimaryPlayer = false; + for (auto it = m_machineQNetPrimaryPlayers.begin(); + it < m_machineQNetPrimaryPlayers.end(); ++it) { + INetworkPlayer* pQNetPrimaryPlayer = *it; + if (pQNetPlayer->IsSameSystem(pQNetPrimaryPlayer)) { + systemHasPrimaryPlayer = true; + break; + } + } + if (!systemHasPrimaryPlayer) + m_machineQNetPrimaryPlayers.push_back(pQNetPlayer); + } + } + g_NetworkManager.PlayerJoining(networkPlayer); + + if (createFakeSocket == true && !m_bHostChanged) { + g_NetworkManager.CreateSocket(networkPlayer, localPlayer); + } + + fprintf(stderr, "Player 0x%p \"%s\" joined; %s; voice %i; camera %i.\n", + pQNetPlayer, pQNetPlayer->GetOnlineName(), pszDescription, + (int)pQNetPlayer->HasVoice(), (int)pQNetPlayer->HasCamera()); + + if (IsHost()) { + // 4J-PB - only the host should do this + // g_NetworkManager.UpdateAndSetGameSessionData(); + SystemFlagAddPlayer(networkPlayer); + } + + for (int idx = 0; idx < XUSER_MAX_COUNT; ++idx) { + if (playerChangedCallback[idx]) + playerChangedCallback[idx](networkPlayer, false); + } + + if (s_gameRunning) { + int localPlayerCount = 0; + for (unsigned int idx = 0; idx < XUSER_MAX_COUNT; ++idx) { + if (GetLocalPlayerByUserIndex(idx) != nullptr) ++localPlayerCount; + } + } +} + +bool StubPlatformNetwork::Initialise(CGameNetworkManager* pGameNetworkManager, + int flagIndexSize) { + m_pGameNetworkManager = pGameNetworkManager; + m_flagIndexSize = flagIndexSize; + + for (int i = 0; i < XUSER_MAX_COUNT; i++) { + playerChangedCallback[i] = nullptr; + } + + m_bLeavingGame = false; + m_bLeaveGameOnTick = false; + m_bHostChanged = false; + + m_bSearchResultsReady = false; + m_bSearchPending = false; + + m_bIsOfflineGame = false; + m_SessionsUpdatedCallback = nullptr; + + for (unsigned int i = 0; i < XUSER_MAX_COUNT; ++i) { + m_searchResultsCount[i] = 0; + m_lastSearchStartTime[i] = 0; + + // The results that will be filled in with the current search + m_pSearchResults[i] = nullptr; + m_pQoSResult[i] = nullptr; + m_pCurrentSearchResults[i] = nullptr; + m_pCurrentQoSResult[i] = nullptr; + m_currentSearchResultsCount[i] = 0; + } + + // Success! + return true; +} + +void StubPlatformNetwork::Terminate() { + // TODO: 4jcraft, no release of ressources +} + +int StubPlatformNetwork::GetJoiningReadyPercentage() { return 100; } + +int StubPlatformNetwork::CorrectErrorIDS(int IDS) { return IDS; } + +bool StubPlatformNetwork::isSystemPrimaryPlayer(INetworkPlayer* pQNetPlayer) { + return true; +} + +// We call this twice a frame, either side of the render call so is a good place +// to "tick" things +void StubPlatformNetwork::DoWork() {} + +int StubPlatformNetwork::GetPlayerCount() { return 1; } + +bool StubPlatformNetwork::ShouldMessageForFullSession() { return false; } + +int StubPlatformNetwork::GetOnlinePlayerCount() { return 1; } + +int StubPlatformNetwork::GetLocalPlayerMask(int playerIndex) { + return 1 << playerIndex; +} + +bool StubPlatformNetwork::AddLocalPlayerByUserIndex(int userIndex) { + NotifyPlayerJoined(GetLocalPlayerByUserIndex(userIndex)); + return true; +} + +bool StubPlatformNetwork::RemoveLocalPlayerByUserIndex(int userIndex) { + return true; +} + +bool StubPlatformNetwork::IsInStatsEnabledSession() { return true; } + +bool StubPlatformNetwork::SessionHasSpace(unsigned int spaceRequired /*= 1*/) { + return true; +} + +void StubPlatformNetwork::SendInviteGUI(int quadrant) {} + +bool StubPlatformNetwork::IsAddingPlayer() { return false; } + +bool StubPlatformNetwork::LeaveGame(bool bMigrateHost) { + if (m_bLeavingGame) return true; + + m_bLeavingGame = true; + + // If we are the host wait for the game server to end + if (IsHost() && g_NetworkManager.ServerStoppedValid()) { + s_gameRunning = false; + g_NetworkManager.ServerStoppedWait(); + g_NetworkManager.ServerStoppedDestroy(); + } + return true; +} + +bool StubPlatformNetwork::_LeaveGame(bool bMigrateHost, bool bLeaveRoom) { + return true; +} + +void StubPlatformNetwork::HostGame( + int localUsersMask, bool bOnlineGame, bool bIsPrivate, + unsigned char publicSlots /*= MINECRAFT_NET_MAX_PLAYERS*/, + unsigned char privateSlots /*= 0*/) { + // #ifdef 0 + // 4J Stu - We probably did this earlier as well, but just to be sure! + SetLocalGame(!bOnlineGame); + SetPrivateGame(bIsPrivate); + SystemFlagReset(); + + // Make sure that the Primary Pad is in by default + localUsersMask |= GetLocalPlayerMask(g_NetworkManager.GetPrimaryPad()); + + m_bLeavingGame = false; + s_gameRunning = true; + + _HostGame(localUsersMask, publicSlots, privateSlots); + // #endif +} + +void StubPlatformNetwork::_HostGame( + int usersMask, unsigned char publicSlots /*= MINECRAFT_NET_MAX_PLAYERS*/, + unsigned char privateSlots /*= 0*/) {} + +bool StubPlatformNetwork::_StartGame() { return true; } + +int StubPlatformNetwork::JoinGame(FriendSessionInfo* searchResult, + int localUsersMask, int primaryUserIndex) { + return CGameNetworkManager::JOINGAME_SUCCESS; +} + +bool StubPlatformNetwork::SetLocalGame(bool isLocal) { + m_bIsOfflineGame = isLocal; + + return true; +} + +void StubPlatformNetwork::SetPrivateGame(bool isPrivate) { + fprintf(stderr, "Setting as private game: %s\n", isPrivate ? "yes" : "no"); + m_bIsPrivateGame = isPrivate; +} + +void StubPlatformNetwork::RegisterPlayerChangedCallback( + int iPad, + std::function callback) { + playerChangedCallback[iPad] = std::move(callback); +} + +void StubPlatformNetwork::UnRegisterPlayerChangedCallback(int iPad) { + playerChangedCallback[iPad] = nullptr; +} + +void StubPlatformNetwork::HandleSignInChange() { return; } + +bool StubPlatformNetwork::_RunNetworkGame() { return true; } + +void StubPlatformNetwork::UpdateAndSetGameSessionData( + INetworkPlayer* pNetworkPlayerLeaving /*= nullptr*/) { + // uint32_t playerCount = m_player->GetPlayerCount(); + // + // if( this->m_bLeavingGame ) + // return; + // + // if( GetHostPlayer() == nullptr ) + // 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 *)wstring_to_string( + // pNetworkPlayer->GetOnlineName() ); + // memcpy(m_hostGameSessionData.szPlayers[i],temp,XUSER_NAME_SIZE); + // } + // else + // { + // m_hostGameSessionData.players[i] = nullptr; + // memset(m_hostGameSessionData.szPlayers[i],0,XUSER_NAME_SIZE); + // } + // } + // else + // { + // m_hostGameSessionData.players[i] = nullptr; + // memset(m_hostGameSessionData.szPlayers[i],0,XUSER_NAME_SIZE); + // } + // } + // + // m_hostGameSessionData.hostPlayerUID = ((NetworkPlayerXbox + // *)GetHostPlayer())->GetQNetPlayer()->GetXuid(); + // m_hostGameSessionData.m_uiGameHostSettings = + // app.GetGameHostOption(eGameHostOption_All); +} + +bool StubPlatformNetwork::RemoveLocalPlayer(INetworkPlayer* pNetworkPlayer) { + return true; +} + +StubPlatformNetwork::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 + // world/render sizes a pain if we hit an assert here + count = (count + 8 - 1) & ~(8 - 1); + // assert( ( count % 8 ) == 0 ); + this->m_pNetworkPlayer = pNetworkPlayer; + this->flags = new unsigned char[count / 8]; + memset(this->flags, 0, count / 8); + this->count = count; +} +StubPlatformNetwork::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 StubPlatformNetwork::SystemFlagAddPlayer(INetworkPlayer* pNetworkPlayer) { + PlayerFlags* newPlayerFlags = + new PlayerFlags(pNetworkPlayer, m_flagIndexSize); + // If any of our existing players are on the same system, then copy over + // flags from that one + for (unsigned int i = 0; i < m_playerFlags.size(); i++) { + if (pNetworkPlayer->IsSameSystem(m_playerFlags[i]->m_pNetworkPlayer)) { + memcpy(newPlayerFlags->flags, m_playerFlags[i]->flags, + m_playerFlags[i]->count / 8); + break; + } + } + m_playerFlags.push_back(newPlayerFlags); +} + +// Remove a player from the per system flag storage - just maintains the +// m_playerFlags vector without any gaps in it +void StubPlatformNetwork::SystemFlagRemovePlayer( + INetworkPlayer* pNetworkPlayer) { + for (unsigned int i = 0; i < m_playerFlags.size(); i++) { + if (m_playerFlags[i]->m_pNetworkPlayer == pNetworkPlayer) { + delete m_playerFlags[i]; + m_playerFlags[i] = m_playerFlags.back(); + m_playerFlags.pop_back(); + return; + } + } +} + +void StubPlatformNetwork::SystemFlagReset() { + for (unsigned int i = 0; i < m_playerFlags.size(); i++) { + delete m_playerFlags[i]; + } + m_playerFlags.clear(); +} + +// Set a per system flag - this is done by setting the flag on every player that +// shares that system +void StubPlatformNetwork::SystemFlagSet(INetworkPlayer* pNetworkPlayer, + int index) { + if ((index < 0) || (index >= m_flagIndexSize)) return; + if (pNetworkPlayer == nullptr) return; + + for (unsigned int i = 0; i < m_playerFlags.size(); i++) { + if (pNetworkPlayer->IsSameSystem(m_playerFlags[i]->m_pNetworkPlayer)) { + m_playerFlags[i]->flags[index / 8] |= (128 >> (index % 8)); + } + } +} + +// 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 StubPlatformNetwork::SystemFlagGet(INetworkPlayer* pNetworkPlayer, + int index) { + if ((index < 0) || (index >= m_flagIndexSize)) return false; + if (pNetworkPlayer == nullptr) { + return false; + } + + for (unsigned int i = 0; i < m_playerFlags.size(); i++) { + if (m_playerFlags[i]->m_pNetworkPlayer == pNetworkPlayer) { + return ((m_playerFlags[i]->flags[index / 8] & + (128 >> (index % 8))) != 0); + } + } + return false; +} + +std::string StubPlatformNetwork::GatherStats() { return ""; } + +std::string StubPlatformNetwork::GatherRTTStats() { + std::string stats("Rtt: "); + + char stat[32]; + + for (unsigned int i = 0; i < GetPlayerCount(); ++i) { + INetworkPlayer* pQNetPlayer = GetPlayerByIndex(i); + + if (!pQNetPlayer->IsLocal()) { + memset(stat, 0, 32 * sizeof(char)); + snprintf(stat, 32, "%d: %d/", i, pQNetPlayer->GetCurrentRtt()); + stats.append(stat); + } + } + return stats; +} + +void StubPlatformNetwork::TickSearch() {} + +void StubPlatformNetwork::SearchForGames() {} + +void StubPlatformNetwork::SetSearchResultsReady(int resultCount) { + m_bSearchResultsReady = true; + m_searchResultsCount[m_lastSearchPad] = resultCount; +} + +std::vector* StubPlatformNetwork::GetSessionList( + int iPad, int localPlayers, bool partyOnly) { + std::vector* filteredList = + new std::vector(); + ; + return filteredList; +} + +bool StubPlatformNetwork::GetGameSessionInfo( + int iPad, SessionID sessionId, FriendSessionInfo* foundSessionInfo) { + return false; +} + +void StubPlatformNetwork::SetSessionsUpdatedCallback( + std::function callback) { + m_SessionsUpdatedCallback = std::move(callback); +} + +void StubPlatformNetwork::GetFullFriendSessionInfo( + FriendSessionInfo* foundSession, + std::function callback) { + callback(true); +} + +void StubPlatformNetwork::ForceFriendsSessionRefresh() { + fprintf(stderr, "Resetting friends session search data\n"); + + for (unsigned int i = 0; i < XUSER_MAX_COUNT; ++i) { + m_searchResultsCount[i] = 0; + m_lastSearchStartTime[i] = 0; + delete m_pSearchResults[i]; + m_pSearchResults[i] = nullptr; + } +} + +INetworkPlayer* StubPlatformNetwork::addNetworkPlayer( + INetworkPlayer* pQNetPlayer) { + StubNetworkPlayer* pNetworkPlayer = new StubNetworkPlayer(); + currentNetworkPlayers.push_back(pNetworkPlayer); + return pNetworkPlayer; +} + +void StubPlatformNetwork::removeNetworkPlayer(INetworkPlayer* pQNetPlayer) { + INetworkPlayer* pNetworkPlayer = getNetworkPlayer(pQNetPlayer); + for (auto it = currentNetworkPlayers.begin(); + it != currentNetworkPlayers.end(); it++) { + if (*it == pNetworkPlayer) { + currentNetworkPlayers.erase(it); + return; + } + } +} + +INetworkPlayer* StubPlatformNetwork::getNetworkPlayer( + INetworkPlayer* pQNetPlayer) { + return pQNetPlayer; +} + +INetworkPlayer* StubPlatformNetwork::GetLocalPlayerByUserIndex(int userIndex) { + if (userIndex != 0) return nullptr; // 4jcraft: hack + return getNetworkPlayer(&m_players[userIndex]); +} + +INetworkPlayer* StubPlatformNetwork::GetPlayerByIndex(int playerIndex) { + return getNetworkPlayer(&m_players[0]); +} + +INetworkPlayer* StubPlatformNetwork::GetPlayerByXuid(PlayerUID xuid) { + return getNetworkPlayer(&m_players[0]); +} + +INetworkPlayer* StubPlatformNetwork::GetPlayerBySmallId(unsigned char smallId) { + return getNetworkPlayer(&m_players[0]); +} + +INetworkPlayer* StubPlatformNetwork::GetHostPlayer() { + return getNetworkPlayer(&m_players[0]); +} + +bool StubPlatformNetwork::IsHost() { return !m_bHostChanged; } + +bool StubPlatformNetwork::JoinGameFromInviteInfo( + int userIndex, int userMask, const INVITE_INFO* pInviteInfo) { + return 0; +} + +void StubPlatformNetwork::SetSessionTexturePackParentId(int id) { + m_hostGameSessionData.texturePackParentId = id; +} + +void StubPlatformNetwork::SetSessionSubTexturePackId(int id) { + m_hostGameSessionData.subTexturePackId = id; +} + +void StubPlatformNetwork::Notify(int ID, uintptr_t Param) {} + +bool StubPlatformNetwork::IsInSession() { return s_gameRunning; } +bool StubPlatformNetwork::IsInGameplay() { return s_gameRunning; } +bool StubPlatformNetwork::IsReadyToPlayOrIdle() { return true; } \ No newline at end of file diff --git a/targets/platform/network/stub/StubPlatformNetwork.h b/targets/platform/network/stub/StubPlatformNetwork.h index 086b8d37a..1c801335b 100644 --- a/targets/platform/network/stub/StubPlatformNetwork.h +++ b/targets/platform/network/stub/StubPlatformNetwork.h @@ -1,129 +1,180 @@ #pragma once +#include +// using namespace std; +#include +#include +#include "StubNetworkPlayer.h" +#include "minecraft/client/model/SkinBox.h" +#include "platform/NetTypes.h" +#include "platform/PlatformTypes.h" +#include "platform/XboxStubs.h" #include "platform/network/IPlatformNetwork.h" +#include "platform/network/network.h" -// True no-op platform network backend. Returns false / 0 / nullptr for -// every operation. The composition root can substitute a real backend -// (QNet, Steam, EOS, custom) at link time. Used as the platform default -// so consumers can call PlatformNetwork.* without nullptr checks. +class CGameNetworkManager; +class INetworkPlayer; class StubPlatformNetwork : public IPlatformNetwork { public: - bool Initialise(CGameNetworkManager* /*pGameNetworkManager*/, - int /*flagIndexSize*/) override { - return true; - } - void Terminate() override {} - void DoWork() override {} - [[nodiscard]] int GetJoiningReadyPercentage() override { return 100; } - [[nodiscard]] int CorrectErrorIDS(int IDS) override { return IDS; } + static StubNetworkPlayer m_players[4]; - [[nodiscard]] int GetPlayerCount() override { return 0; } - [[nodiscard]] int GetOnlinePlayerCount() override { return 0; } - [[nodiscard]] int GetLocalPlayerMask(int /*playerIndex*/) override { - return 0; - } - bool AddLocalPlayerByUserIndex(int /*userIndex*/) override { return false; } - bool RemoveLocalPlayerByUserIndex(int /*userIndex*/) override { - return false; - } - [[nodiscard]] INetworkPlayer* GetLocalPlayerByUserIndex( - int /*userIndex*/) override { - return nullptr; - } - [[nodiscard]] INetworkPlayer* GetPlayerByIndex( - int /*playerIndex*/) override { - return nullptr; - } - [[nodiscard]] INetworkPlayer* GetPlayerByXuid(PlayerUID /*xuid*/) override { - return nullptr; - } - [[nodiscard]] INetworkPlayer* GetPlayerBySmallId( - unsigned char /*smallId*/) override { - return nullptr; - } - [[nodiscard]] INetworkPlayer* GetHostPlayer() override { return nullptr; } - [[nodiscard]] bool ShouldMessageForFullSession() override { return false; } + bool Initialise(CGameNetworkManager* pGameNetworkManager, + int flagIndexSize); + void Terminate(); + int GetJoiningReadyPercentage(); + int CorrectErrorIDS(int IDS); - [[nodiscard]] bool IsHost() override { return true; } - bool JoinGameFromInviteInfo(int /*userIndex*/, int /*userMask*/, - const INVITE_INFO* /*pInviteInfo*/) override { - return false; - } - bool LeaveGame(bool /*bMigrateHost*/) override { return true; } - [[nodiscard]] bool IsInSession() override { return false; } - [[nodiscard]] bool IsInGameplay() override { return false; } - [[nodiscard]] bool IsReadyToPlayOrIdle() override { return true; } - [[nodiscard]] bool IsInStatsEnabledSession() override { return false; } - [[nodiscard]] bool SessionHasSpace( - unsigned int /*spaceRequired*/) override { - return true; - } - void SendInviteGUI(int /*quadrant*/) override {} - [[nodiscard]] bool IsAddingPlayer() override { return false; } + void DoWork(); + int GetPlayerCount(); + int GetOnlinePlayerCount(); + int GetLocalPlayerMask(int playerIndex); + bool AddLocalPlayerByUserIndex(int userIndex); + bool RemoveLocalPlayerByUserIndex(int userIndex); + INetworkPlayer* GetLocalPlayerByUserIndex(int userIndex); + INetworkPlayer* GetPlayerByIndex(int playerIndex); + INetworkPlayer* GetPlayerByXuid(PlayerUID xuid); + INetworkPlayer* GetPlayerBySmallId(unsigned char smallId); + bool ShouldMessageForFullSession(); - void HostGame(int /*localUsersMask*/, bool /*bOnlineGame*/, - bool /*bIsPrivate*/, unsigned char /*publicSlots*/, - unsigned char /*privateSlots*/) override {} - int JoinGame(FriendSessionInfo* /*searchResult*/, int /*dwLocalUsersMask*/, - int /*dwPrimaryUserIndex*/) override { - return 0; - } - bool SetLocalGame(bool /*isLocal*/) override { return true; } - [[nodiscard]] bool IsLocalGame() override { return true; } - void SetPrivateGame(bool /*isPrivate*/) override {} - [[nodiscard]] bool IsPrivateGame() override { return false; } - [[nodiscard]] bool IsLeavingGame() override { return false; } - void ResetLeavingGame() override {} + INetworkPlayer* GetHostPlayer(); + bool IsHost(); + bool JoinGameFromInviteInfo(int userIndex, int userMask, + const INVITE_INFO* pInviteInfo); + bool LeaveGame(bool bMigrateHost); + + bool IsInSession(); + bool IsInGameplay(); + bool IsReadyToPlayOrIdle(); + bool IsInStatsEnabledSession(); + bool SessionHasSpace(unsigned int spaceRequired = 1); + void SendInviteGUI(int quadrant); + bool IsAddingPlayer(); + + void HostGame(int localUsersMask, bool bOnlineGame, bool bIsPrivate, + unsigned char publicSlots = MINECRAFT_NET_MAX_PLAYERS, + unsigned char privateSlots = 0); + int JoinGame(FriendSessionInfo* searchResult, int localUsersMask, + int primaryUserIndex); + bool SetLocalGame(bool isLocal); + bool IsLocalGame() { return m_bIsOfflineGame; } + void SetPrivateGame(bool isPrivate); + bool IsPrivateGame() { return m_bIsPrivateGame; } + bool IsLeavingGame() { return m_bLeavingGame; } + void ResetLeavingGame() { m_bLeavingGame = false; } void RegisterPlayerChangedCallback( - int /*iPad*/, - std::function /*callback*/) override {} - void UnRegisterPlayerChangedCallback(int /*iPad*/) override {} + int iPad, + std::function callback); + void UnRegisterPlayerChangedCallback(int iPad); - void HandleSignInChange() override {} + void HandleSignInChange(); - bool _RunNetworkGame() override { return true; } - bool _LeaveGame(bool /*bMigrateHost*/, bool /*bLeaveRoom*/) override { - return true; - } - void _HostGame(int /*usersMask*/, unsigned char /*publicSlots*/, - unsigned char /*privateSlots*/) override {} - bool _StartGame() override { return true; } + bool _RunNetworkGame(); +private: + bool isSystemPrimaryPlayer(INetworkPlayer* pQNetPlayer); + bool _LeaveGame(bool bMigrateHost, bool bLeaveRoom); + void _HostGame(int dwUsersMask, + unsigned char publicSlots = MINECRAFT_NET_MAX_PLAYERS, + unsigned char privateSlots = 0); + bool _StartGame(); + + void* m_notificationListener; + + std::vector + m_machineQNetPrimaryPlayers; // collection of players that we deem to + // be the main one for that system + + bool m_bLeavingGame; + bool m_bLeaveGameOnTick; + bool m_migrateHostOnLeave; + bool m_bHostChanged; + + bool m_bIsOfflineGame; + bool m_bIsPrivateGame; + int m_flagIndexSize; + + // This is only maintained by the host, and is not valid on client machines + GameSessionData m_hostGameSessionData; + CGameNetworkManager* m_pGameNetworkManager; + +public: void UpdateAndSetGameSessionData( - INetworkPlayer* /*pNetworkPlayerLeaving*/) override {} - bool RemoveLocalPlayer(INetworkPlayer* /*pNetworkPlayer*/) override { - return false; - } + INetworkPlayer* pNetworkPlayerLeaving = nullptr); - void SystemFlagSet(INetworkPlayer* /*pNetworkPlayer*/, - int /*index*/) override {} - [[nodiscard]] bool SystemFlagGet(INetworkPlayer* /*pNetworkPlayer*/, - int /*index*/) override { - return false; - } +private: + std::function + playerChangedCallback[XUSER_MAX_COUNT]; - [[nodiscard]] std::string GatherStats() override { return {}; } - [[nodiscard]] std::string GatherRTTStats() override { return {}; } + bool RemoveLocalPlayer(INetworkPlayer* pNetworkPlayer); - void SetSessionTexturePackParentId(int /*id*/) override {} - void SetSessionSubTexturePackId(int /*id*/) override {} - void Notify(int /*ID*/, uintptr_t /*Param*/) override {} + // Things for handling per-system flags + class PlayerFlags { + public: + INetworkPlayer* m_pNetworkPlayer; + unsigned char* flags; + unsigned int count; + PlayerFlags(INetworkPlayer* pNetworkPlayer, unsigned int count); + ~PlayerFlags(); + }; + std::vector m_playerFlags; + void SystemFlagAddPlayer(INetworkPlayer* pNetworkPlayer); + void SystemFlagRemovePlayer(INetworkPlayer* pNetworkPlayer); + void SystemFlagReset(); - [[nodiscard]] std::vector* GetSessionList( - int /*iPad*/, int /*localPlayers*/, bool /*partyOnly*/) override { - return nullptr; - } - [[nodiscard]] bool GetGameSessionInfo( - int /*iPad*/, SessionID /*sessionId*/, - FriendSessionInfo* /*foundSession*/) override { - return false; - } - void SetSessionsUpdatedCallback( - std::function /*callback*/) override {} - void GetFullFriendSessionInfo( - FriendSessionInfo* /*foundSession*/, - std::function /*callback*/) override {} - void ForceFriendsSessionRefresh() override {} -}; +public: + void SystemFlagSet(INetworkPlayer* pNetworkPlayer, int index); + bool SystemFlagGet(INetworkPlayer* pNetworkPlayer, int index); + +public: + std::string GatherStats(); + std::string GatherRTTStats(); + +private: + std::vector friendsSessions[XUSER_MAX_COUNT]; + int m_searchResultsCount[XUSER_MAX_COUNT]; + int m_lastSearchStartTime[XUSER_MAX_COUNT]; + + // The results that will be filled in with the current search + XSESSION_SEARCHRESULT_HEADER* m_pSearchResults[XUSER_MAX_COUNT]; + XNQOS* m_pQoSResult[XUSER_MAX_COUNT]; + + // The results from the previous search, which are currently displayed in + // the game + XSESSION_SEARCHRESULT_HEADER* m_pCurrentSearchResults[XUSER_MAX_COUNT]; + XNQOS* m_pCurrentQoSResult[XUSER_MAX_COUNT]; + int m_currentSearchResultsCount[XUSER_MAX_COUNT]; + + int m_lastSearchPad; + bool m_bSearchResultsReady; + bool m_bSearchPending; + std::function m_SessionsUpdatedCallback; + + void TickSearch(); + void SearchForGames(); + + void SetSearchResultsReady(int resultCount = 0); + + std::vector currentNetworkPlayers; + INetworkPlayer* addNetworkPlayer(INetworkPlayer* pQNetPlayer); + void removeNetworkPlayer(INetworkPlayer* pQNetPlayer); + static INetworkPlayer* getNetworkPlayer(INetworkPlayer* pQNetPlayer); + + void SetSessionTexturePackParentId(int id); + void SetSessionSubTexturePackId(int id); + void Notify(int ID, uintptr_t Param); + +public: + std::vector* GetSessionList(int iPad, int localPlayers, + bool partyOnly); + bool GetGameSessionInfo(int iPad, SessionID sessionId, + FriendSessionInfo* foundSession); + void SetSessionsUpdatedCallback(std::function callback); + void GetFullFriendSessionInfo(FriendSessionInfo* foundSession, + std::function callback); + void ForceFriendsSessionRefresh(); + +private: + void NotifyPlayerJoined(INetworkPlayer* pQNetPlayer); +}; \ No newline at end of file