mirror of
https://github.com/4jcraft/4jcraft.git
synced 2026-05-07 06:39:19 +00:00
properly implement network interface stub
This commit is contained in:
parent
8552634614
commit
b20b8cb311
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -7,13 +7,12 @@
|
|||
#if !defined(__linux__)
|
||||
#include <qnet.h>
|
||||
#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();
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
#include <vector>
|
||||
|
||||
#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"
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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__
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
platform_network_sources = files('stub/StubPlatformNetwork.cpp')
|
||||
platform_network_sources = files('stub/StubPlatformNetwork.cpp', 'stub/StubNetworkPlayer.cpp')
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
53
targets/platform/network/stub/StubNetworkPlayer.cpp
Normal file
53
targets/platform/network/stub/StubNetworkPlayer.cpp
Normal file
|
|
@ -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<int>(currentTime - m_lastChunkPacketTime);
|
||||
}
|
||||
52
targets/platform/network/stub/StubNetworkPlayer.h
Normal file
52
targets/platform/network/stub/StubNetworkPlayer.h
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#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;
|
||||
};
|
||||
|
|
@ -1,5 +1,15 @@
|
|||
#include "StubPlatformNetwork.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <wchar.h>
|
||||
|
||||
#include <compare>
|
||||
|
||||
#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<void(INetworkPlayer* pPlayer, bool leaving)> 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<FriendSessionInfo*>* StubPlatformNetwork::GetSessionList(
|
||||
int iPad, int localPlayers, bool partyOnly) {
|
||||
std::vector<FriendSessionInfo*>* filteredList =
|
||||
new std::vector<FriendSessionInfo*>();
|
||||
;
|
||||
return filteredList;
|
||||
}
|
||||
|
||||
bool StubPlatformNetwork::GetGameSessionInfo(
|
||||
int iPad, SessionID sessionId, FriendSessionInfo* foundSessionInfo) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void StubPlatformNetwork::SetSessionsUpdatedCallback(
|
||||
std::function<void()> callback) {
|
||||
m_SessionsUpdatedCallback = std::move(callback);
|
||||
}
|
||||
|
||||
void StubPlatformNetwork::GetFullFriendSessionInfo(
|
||||
FriendSessionInfo* foundSession,
|
||||
std::function<void(bool success)> 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; }
|
||||
|
|
@ -1,129 +1,180 @@
|
|||
#pragma once
|
||||
#include <stdint.h>
|
||||
// using namespace std;
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#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<void(INetworkPlayer*, bool)> /*callback*/) override {}
|
||||
void UnRegisterPlayerChangedCallback(int /*iPad*/) override {}
|
||||
int iPad,
|
||||
std::function<void(INetworkPlayer* pPlayer, bool leaving)> 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<INetworkPlayer*>
|
||||
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<void(INetworkPlayer* pPlayer, bool leaving)>
|
||||
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<PlayerFlags*> m_playerFlags;
|
||||
void SystemFlagAddPlayer(INetworkPlayer* pNetworkPlayer);
|
||||
void SystemFlagRemovePlayer(INetworkPlayer* pNetworkPlayer);
|
||||
void SystemFlagReset();
|
||||
|
||||
[[nodiscard]] std::vector<FriendSessionInfo*>* 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<void()> /*callback*/) override {}
|
||||
void GetFullFriendSessionInfo(
|
||||
FriendSessionInfo* /*foundSession*/,
|
||||
std::function<void(bool)> /*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<FriendSessionInfo*> 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<void()> m_SessionsUpdatedCallback;
|
||||
|
||||
void TickSearch();
|
||||
void SearchForGames();
|
||||
|
||||
void SetSearchResultsReady(int resultCount = 0);
|
||||
|
||||
std::vector<INetworkPlayer*> 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<FriendSessionInfo*>* GetSessionList(int iPad, int localPlayers,
|
||||
bool partyOnly);
|
||||
bool GetGameSessionInfo(int iPad, SessionID sessionId,
|
||||
FriendSessionInfo* foundSession);
|
||||
void SetSessionsUpdatedCallback(std::function<void()> callback);
|
||||
void GetFullFriendSessionInfo(FriendSessionInfo* foundSession,
|
||||
std::function<void(bool success)> callback);
|
||||
void ForceFriendsSessionRefresh();
|
||||
|
||||
private:
|
||||
void NotifyPlayerJoined(INetworkPlayer* pQNetPlayer);
|
||||
};
|
||||
Loading…
Reference in a new issue