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