the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 237 lines 8.4 kB view raw
1#pragma once 2using namespace std; 3#include <vector> 4#include <qnet.h> 5#include "..\..\..\Minecraft.World\C4JThread.h" 6#include "NetworkPlayerInterface.h" 7#ifdef _XBOX 8#include "..\..\Xbox\Network\PlatformNetworkManagerXbox.h" 9#elif defined __PS3__ || defined __ORBIS__ || defined __PSVITA__ 10#include "..\..\Common\Network\Sony\PlatformNetworkManagerSony.h" 11#elif defined _DURANGO 12#include "..\..\Durango\Network\PlatformNetworkManagerDurango.h" 13#else 14#include "PlatformNetworkManagerStub.h" 15#endif 16#include "SessionInfo.h" 17 18#ifdef __ORBIS__ 19#include "..\..\Orbis\Network\PsPlusUpsellWrapper_Orbis.h" 20#endif 21 22class ClientConnection; 23class Minecraft; 24 25const int NON_QNET_SENDDATA_ACK_REQUIRED = 1; 26 27// This class implements the game-side interface to the networking system. As such, it is platform independent and may contain bits of game-side code where appropriate. 28// It shouldn't ever reference any platform specifics of the network implementation (eg QNET), rather it should interface with an implementation of PlatformNetworkManager to 29// provide this functionality. 30 31class CGameNetworkManager 32{ 33#ifdef _XBOX 34 friend class CPlatformNetworkManagerXbox; 35#elif defined __PS3__ || defined __ORBIS__ || defined __PSVITA__ 36 friend class CPlatformNetworkManagerSony; 37#elif defined _DURANGO 38 friend class CPlatformNetworkManagerDurango; 39#else 40 friend class CPlatformNetworkManagerStub; 41#endif 42public: 43 CGameNetworkManager(); 44 // Misc high level flow 45 46 typedef enum 47 { 48 JOINGAME_SUCCESS, 49 JOINGAME_FAIL_GENERAL, 50 JOINGAME_FAIL_SERVER_FULL 51 } eJoinGameResult; 52 53 void Initialise(); 54 void Terminate(); 55 void DoWork(); 56 bool _RunNetworkGame(LPVOID lpParameter); 57 bool StartNetworkGame(Minecraft *minecraft, LPVOID lpParameter); 58 int CorrectErrorIDS(int IDS); 59 60 // Player management 61 62 static int GetLocalPlayerMask(int playerIndex); 63 int GetPlayerCount(); 64 int GetOnlinePlayerCount(); 65 bool AddLocalPlayerByUserIndex( int userIndex ); 66 bool RemoveLocalPlayerByUserIndex( int userIndex ); 67 INetworkPlayer *GetLocalPlayerByUserIndex(int userIndex ); 68 INetworkPlayer *GetPlayerByIndex(int playerIndex); 69 INetworkPlayer *GetPlayerByXuid(PlayerUID xuid); 70 INetworkPlayer *GetPlayerBySmallId(unsigned char smallId); 71 wstring GetDisplayNameByGamertag(wstring gamertag); 72 INetworkPlayer *GetHostPlayer(); 73 void RegisterPlayerChangedCallback(int iPad, void (*callback)(void *callbackParam, INetworkPlayer *pPlayer, bool leaving), void *callbackParam); 74 void UnRegisterPlayerChangedCallback(int iPad, void (*callback)(void *callbackParam, INetworkPlayer *pPlayer, bool leaving), void *callbackParam); 75 void HandleSignInChange(); 76 bool ShouldMessageForFullSession(); 77 78 // State management 79 80 bool IsInSession(); 81 bool IsInGameplay(); 82 bool IsLeavingGame(); 83 bool IsReadyToPlayOrIdle(); 84 85 // Hosting and game type 86 87 bool SetLocalGame(bool isLocal); 88 bool IsLocalGame(); 89 void SetPrivateGame(bool isPrivate); 90 bool IsPrivateGame(); 91 void HostGame(int localUsersMask, bool bOnlineGame, bool bIsPrivate, unsigned char publicSlots = MINECRAFT_NET_MAX_PLAYERS, unsigned char privateSlots = 0); 92 bool IsHost(); 93 bool IsInStatsEnabledSession(); 94 95 // Client session discovery 96 97 bool SessionHasSpace(unsigned int spaceRequired = 1); 98 vector<FriendSessionInfo *> *GetSessionList(int iPad, int localPlayers, bool partyOnly); 99 bool GetGameSessionInfo(int iPad, SessionID sessionId,FriendSessionInfo *foundSession); 100 void SetSessionsUpdatedCallback( void (*SessionsUpdatedCallback)(LPVOID pParam), LPVOID pSearchParam ); 101 void GetFullFriendSessionInfo( FriendSessionInfo *foundSession, void (* FriendSessionUpdatedFn)(bool success, void *pParam), void *pParam ); 102 void ForceFriendsSessionRefresh(); 103 104 // Session joining and leaving 105 106 bool JoinGameFromInviteInfo( int userIndex, int userMask, const INVITE_INFO *pInviteInfo); 107 eJoinGameResult JoinGame(FriendSessionInfo *searchResult, int localUsersMask); 108 static void CancelJoinGame(LPVOID lpParam); // Not part of the shared interface 109 bool LeaveGame(bool bMigrateHost); 110 static int JoinFromInvite_SignInReturned(void *pParam,bool bContinue, int iPad); 111 void UpdateAndSetGameSessionData(INetworkPlayer *pNetworkPlayerLeaving = NULL); 112 void SendInviteGUI(int iPad); 113 void ResetLeavingGame(); 114 115 // Threads 116 117 bool IsNetworkThreadRunning(); 118 static int RunNetworkGameThreadProc( void* lpParameter ); 119 static int ServerThreadProc( void* lpParameter ); 120 static int ExitAndJoinFromInviteThreadProc( void* lpParam ); 121 122#if (defined __PS3__) || (defined __ORBIS__) || (defined __PSVITA__) 123 static int MustSignInReturned_0(void *pParam,int iPad,C4JStorage::EMessageResult result); 124 static int PSNSignInReturned_0(void* pParam, bool bContinue, int iPad); 125 126 static int MustSignInReturned_1(void *pParam,int iPad,C4JStorage::EMessageResult result); 127 static int PSNSignInReturned_1(void* pParam, bool bContinue, int iPad); 128#endif 129 130 static void _LeaveGame(); 131 static int ChangeSessionTypeThreadProc( void* lpParam ); 132 133 // System flags 134 135 void SystemFlagSet(INetworkPlayer *pNetworkPlayer, int index); 136 bool SystemFlagGet(INetworkPlayer *pNetworkPlayer, int index); 137 138 // Events 139 140 void ServerReadyCreate(bool create); // Create the signal (or set to NULL) 141 void ServerReady(); // Signal that we are ready 142 void ServerReadyWait(); // Wait for the signal 143 void ServerReadyDestroy(); // Destroy signal 144 bool ServerReadyValid(); // Is non-NULL 145 146 void ServerStoppedCreate(bool create); // Create the signal 147 void ServerStopped(); // Signal that we are ready 148 void ServerStoppedWait(); // Wait for the signal 149 void ServerStoppedDestroy(); // Destroy signal 150 bool ServerStoppedValid(); // Is non-NULL 151 152#ifdef __PSVITA__ 153 static bool usingAdhocMode(); 154 static void setAdhocMode(bool bAdhoc); 155 static void startAdhocMatching(); 156#endif 157 // Debug output 158 159 wstring GatherStats(); 160 void renderQueueMeter(); 161 wstring GatherRTTStats(); 162 163 // GUI debug output 164 165 // Used for debugging output 166 static const int messageQueue_length = 512; 167 static __int64 messageQueue[messageQueue_length]; 168 static const int byteQueue_length = 512; 169 static __int64 byteQueue[byteQueue_length]; 170 static int messageQueuePos; 171 172 // Methods called from PlatformNetworkManager 173private: 174 void StateChange_AnyToHosting(); 175 void StateChange_AnyToJoining(); 176 void StateChange_JoiningToIdle(CPlatformNetworkManager::eJoinFailedReason reason); 177 void StateChange_AnyToStarting(); 178 void StateChange_AnyToEnding(bool bStateWasPlaying); 179 void StateChange_AnyToIdle(); 180 void CreateSocket( INetworkPlayer *pNetworkPlayer, bool localPlayer ); 181 void CloseConnection( INetworkPlayer *pNetworkPlayer ); 182 void PlayerJoining( INetworkPlayer *pNetworkPlayer ); 183 void PlayerLeaving( INetworkPlayer *pNetworkPlayer ); 184 void HostChanged(); 185 void WriteStats( INetworkPlayer *pNetworkPlayer ); 186 void GameInviteReceived( int userIndex, const INVITE_INFO *pInviteInfo); 187 void HandleInviteWhenInMenus( int userIndex, const INVITE_INFO *pInviteInfo); 188 void AddLocalPlayerFailed(int idx, bool serverFull = false); 189#if defined __PS3__ || defined __PSVITA__ || defined __ORBIS__ 190 void HandleDisconnect(bool bLostRoomOnly,bool bPSNSignOut); 191#else 192 void HandleDisconnect(bool bLostRoomOnly); 193#endif 194 195 int GetPrimaryPad(); 196 int GetLockedProfile(); 197 bool IsSignedInLive(int playerIdx); 198 bool AllowedToPlayMultiplayer(int playerIdx); 199 char *GetOnlineName(int playerIdx); 200 201 C4JThread::Event* m_hServerStoppedEvent; 202 C4JThread::Event* m_hServerReadyEvent; 203 bool m_bInitialised; 204 205#ifdef _XBOX_ONE 206public: 207 void SetFullSessionMessageOnNextSessionChange() { m_bFullSessionMessageOnNextSessionChange = true; } 208#endif 209private: 210 float m_lastPlayerEventTimeStart; // For telemetry 211 static CPlatformNetworkManager *s_pPlatformNetworkManager; 212 bool m_bNetworkThreadRunning; 213 int GetJoiningReadyPercentage(); 214 bool m_bLastDisconnectWasLostRoomOnly; 215 bool m_bFullSessionMessageOnNextSessionChange; 216#if defined __PS3__ || defined __PSVITA__ || defined __ORBIS__ 217 bool m_bSignedOutofPSN; 218#endif 219 220#ifdef __ORBIS__ 221 PsPlusUpsellWrapper *m_pUpsell; 222 INVITE_INFO *m_pInviteInfo; 223 int m_iPlayerInvited; 224#endif 225 226public: 227#ifndef _XBOX 228 void FakeLocalPlayerJoined(); // Temporary method whilst we don't have real networking to make this happen 229#endif 230}; 231 232extern CGameNetworkManager g_NetworkManager; 233 234#ifdef __PS3__ 235#undef __in 236#define __out 237#endif