1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
#pragma once
using namespace std;
#include <vector>
#include "..\..\..\Minecraft.World\C4JThread.h"
#include "..\..\Common\Network\NetworkPlayerInterface.h"
#include "..\..\Common\Network\PlatformNetworkManagerInterface.h"
#include "..\..\Common\Network\SessionInfo.h"
#include "SQRNetworkPlayer.h"
// This is how often we allow a search for new games
#define MINECRAFT_PS3ROOM_SEARCH_DELAY_MILLISECONDS 30000
// This is the Sony platform specific implementation of CPlatformNetworkManager. It is implemented using SQRNetworkManager/SQRNetworkPlayer. There shouldn't be any general game code in here,
// this class is for providing a bridge between the common game-side network implementation, and the lowest level platform specific libraries.
class CPlatformNetworkManagerSony : public CPlatformNetworkManager, ISQRNetworkManagerListener
{
friend class CGameNetworkManager;
public:
virtual bool Initialise(CGameNetworkManager *pGameNetworkManager, int flagIndexSize);
virtual void Terminate();
virtual int GetJoiningReadyPercentage();
virtual int CorrectErrorIDS(int IDS);
virtual void DoWork();
virtual int GetPlayerCount();
virtual int GetOnlinePlayerCount();
virtual int GetLocalPlayerMask(int playerIndex);
virtual bool AddLocalPlayerByUserIndex( int userIndex );
virtual bool RemoveLocalPlayerByUserIndex( int userIndex );
virtual INetworkPlayer *GetLocalPlayerByUserIndex( int userIndex );
virtual INetworkPlayer *GetPlayerByIndex(int playerIndex);
virtual INetworkPlayer * GetPlayerByXuid(PlayerUID xuid);
virtual INetworkPlayer * GetPlayerBySmallId(unsigned char smallId);
virtual bool ShouldMessageForFullSession();
virtual INetworkPlayer *GetHostPlayer();
virtual bool IsHost();
virtual bool JoinGameFromInviteInfo( int userIndex, int userMask, const INVITE_INFO *pInviteInfo);
virtual bool LeaveGame(bool bMigrateHost);
virtual bool IsInSession();
virtual bool IsInGameplay();
virtual bool IsReadyToPlayOrIdle();
virtual bool IsInStatsEnabledSession();
virtual bool SessionHasSpace(unsigned int spaceRequired = 1);
virtual void SendInviteGUI(int quadrant);
virtual bool IsAddingPlayer();
virtual void HostGame(int localUsersMask, bool bOnlineGame, bool bIsPrivate, unsigned char publicSlots = MINECRAFT_NET_MAX_PLAYERS, unsigned char privateSlots = 0);
virtual int JoinGame(FriendSessionInfo *searchResult, int localUsersMask, int primaryUserIndex );
virtual bool SetLocalGame(bool isLocal);
virtual bool IsLocalGame();
virtual void SetPrivateGame(bool isPrivate);
virtual bool IsPrivateGame();
virtual bool IsLeavingGame();
virtual void ResetLeavingGame();
virtual void RegisterPlayerChangedCallback(int iPad, void (*callback)(void *callbackParam, INetworkPlayer *pPlayer, bool leaving), void *callbackParam);
virtual void UnRegisterPlayerChangedCallback(int iPad, void (*callback)(void *callbackParam, INetworkPlayer *pPlayer, bool leaving), void *callbackParam);
virtual void HandleSignInChange();
virtual bool _RunNetworkGame();
#ifdef __PSVITA__
bool usingAdhocMode() { return m_bUsingAdhocMode; }
bool setAdhocMode(bool bAdhoc);
void startAdhocMatching();
bool checkValidInviteData(const INVITE_INFO* pInviteInfo);
#endif
private:
bool isSystemPrimaryPlayer(SQRNetworkPlayer *pQNetPlayer);
virtual bool _LeaveGame(bool bMigrateHost, bool bLeaveRoom);
virtual void _HostGame(int dwUsersMask, unsigned char publicSlots = MINECRAFT_NET_MAX_PLAYERS, unsigned char privateSlots = 0);
virtual bool _StartGame();
#ifdef __PSVITA__
bool m_bUsingAdhocMode;
SQRNetworkManager_Vita* m_pSQRNet_Vita;
SQRNetworkManager_AdHoc_Vita* m_pSQRNet_Vita_Adhoc;
#endif
SQRNetworkManager * m_pSQRNet; // pointer to SQRNetworkManager interface
HANDLE m_notificationListener;
vector<SQRNetworkPlayer *> m_machineSQRPrimaryPlayers; // 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_bLeaveRoomWhenLeavingGame;
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:
virtual void UpdateAndSetGameSessionData(INetworkPlayer *pNetworkPlayerLeaving = nullptr);
private:
// TODO 4J Stu - Do we need to be able to have more than one of these?
void (*playerChangedCallback[XUSER_MAX_COUNT])(void *callbackParam, INetworkPlayer *pPlayer, bool leaving);
void *playerChangedCallbackParam[XUSER_MAX_COUNT];
static int RemovePlayerOnSocketClosedThreadProc( void* lpParam );
virtual bool RemoveLocalPlayer( INetworkPlayer *pNetworkPlayer );
// 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();
};
vector<PlayerFlags *> m_playerFlags;
void SystemFlagAddPlayer(INetworkPlayer *pNetworkPlayer);
void SystemFlagRemovePlayer(INetworkPlayer *pNetworkPlayer);
void SystemFlagReset();
public:
virtual void SystemFlagSet(INetworkPlayer *pNetworkPlayer, int index);
virtual bool SystemFlagGet(INetworkPlayer *pNetworkPlayer, int index);
// For telemetry
private:
float m_lastPlayerEventTimeStart;
public:
wstring GatherStats();
wstring GatherRTTStats();
private:
vector<FriendSessionInfo *> friendsSessions;
int m_lastSearchStartTime;
// The results that will be filled in with the current search
int m_searchResultsCount;
SQRNetworkManager::SessionSearchResult *m_pSearchResults;
int m_lastSearchPad;
bool m_bSearchPending;
LPVOID m_pSearchParam;
void (*m_SessionsUpdatedCallback)(LPVOID pParam);
C4JThread* m_SearchingThread;
void TickSearch();
vector<INetworkPlayer *>currentNetworkPlayers;
INetworkPlayer *addNetworkPlayer(SQRNetworkPlayer *pSQRPlayer);
void removeNetworkPlayer(SQRNetworkPlayer *pSQRPlayer);
static INetworkPlayer *getNetworkPlayer(SQRNetworkPlayer *pSQRPlayer);
virtual void SetSessionTexturePackParentId( int id );
virtual void SetSessionSubTexturePackId( int id );
virtual void Notify(int ID, ULONG_PTR Param);
public:
virtual vector<FriendSessionInfo *> *GetSessionList(int iPad, int localPlayers, bool partyOnly);
virtual bool GetGameSessionInfo(int iPad, SessionID sessionId,FriendSessionInfo *foundSession);
virtual void SetSessionsUpdatedCallback( void (*SessionsUpdatedCallback)(LPVOID pParam), LPVOID pSearchParam );
virtual void GetFullFriendSessionInfo( FriendSessionInfo *foundSession, void (* FriendSessionUpdatedFn)(bool success, void *pParam), void *pParam );
virtual void ForceFriendsSessionRefresh();
// ... and the new ones that have been converted to ISQRNetworkManagerListener
virtual void HandleDataReceived(SQRNetworkPlayer *playerFrom, SQRNetworkPlayer *playerTo, unsigned char *data, unsigned int dataSize);
virtual void HandlePlayerJoined(SQRNetworkPlayer *player);
virtual void HandlePlayerLeaving(SQRNetworkPlayer *player);
virtual void HandleStateChange(SQRNetworkManager::eSQRNetworkManagerState oldState, SQRNetworkManager::eSQRNetworkManagerState newState, bool idleReasonIsSessionFull);
virtual void HandleResyncPlayerRequest(SQRNetworkPlayer **aPlayers);
virtual void HandleAddLocalPlayerFailed(int idx);
virtual void HandleDisconnect(bool bLostRoomOnly,bool bPSNSignOut=false);
virtual void HandleInviteReceived( int userIndex, const SQRNetworkManager::PresenceSyncInfo *pInviteInfo);
static void SetSQRPresenceInfoFromExtData(SQRNetworkManager::PresenceSyncInfo *presence, void *pExtData, SceNpMatching2RoomId roomId, SceNpMatching2ServerId serverId);
static void MallocAndSetExtDataFromSQRPresenceInfo(void **pExtData, SQRNetworkManager::PresenceSyncInfo *presence);
};
|