sys_session_local.h 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701
  1. /*
  2. ===========================================================================
  3. Doom 3 BFG Edition GPL Source Code
  4. Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
  6. Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. #undef private
  21. #undef protected
  22. #include "win32/win_achievements.h"
  23. #include "win32/win_signin.h"
  24. #include "sys_lobby_backend.h"
  25. #include "sys_lobby.h"
  26. class idSaveGameProcessorNextMap;
  27. class idSaveGameProcessorSaveGame;
  28. class idSaveGameProcessorLoadGame;
  29. class idSaveGameProcessorDelete;
  30. class idSaveGameProcessorEnumerateGames;
  31. /*
  32. ================================================
  33. idLobbyStub
  34. ================================================
  35. */
  36. class idLobbyStub : public idLobbyBase {
  37. public:
  38. virtual bool IsHost() const { return false; }
  39. virtual bool IsPeer() const { return false; }
  40. virtual bool HasActivePeers() const { return false; }
  41. virtual int GetNumLobbyUsers() const { return 0; }
  42. virtual int GetNumActiveLobbyUsers() const { return 0; }
  43. virtual bool IsLobbyUserConnected( int index ) const { return false; }
  44. virtual lobbyUserID_t GetLobbyUserIdByOrdinal( int userIndex ) const { return lobbyUserID_t(); }
  45. virtual int GetLobbyUserIndexFromLobbyUserID( lobbyUserID_t lobbyUserID ) const { return -1; }
  46. virtual void SendReliable( int type, idBitMsg & msg, bool callReceiveReliable = true, peerMask_t sessionUserMask = MAX_UNSIGNED_TYPE( peerMask_t ) ) {}
  47. virtual void SendReliableToLobbyUser( lobbyUserID_t lobbyUserID, int type, idBitMsg & msg ) {}
  48. virtual void SendReliableToHost( int type, idBitMsg & msg ) {}
  49. virtual const char * GetLobbyUserName( lobbyUserID_t lobbyUserID ) const { return "INVALID"; }
  50. virtual void KickLobbyUser( lobbyUserID_t lobbyUserID ) {}
  51. virtual bool IsLobbyUserValid( lobbyUserID_t lobbyUserID ) const { return false; }
  52. virtual bool IsLobbyUserLoaded( lobbyUserID_t lobbyUserID ) const { return false; }
  53. virtual bool LobbyUserHasFirstFullSnap( lobbyUserID_t lobbyUserID ) const { return false; }
  54. virtual void EnableSnapshotsForLobbyUser( lobbyUserID_t lobbyUserID ) {}
  55. virtual int GetLobbyUserSkinIndex( lobbyUserID_t lobbyUserID ) const { return 0; }
  56. virtual bool GetLobbyUserWeaponAutoReload( lobbyUserID_t lobbyUserID ) const { return false; }
  57. virtual bool GetLobbyUserWeaponAutoSwitch( lobbyUserID_t lobbyUserID ) const { return false; }
  58. virtual int GetLobbyUserLevel( lobbyUserID_t lobbyUserID ) const { return 0; }
  59. virtual int GetLobbyUserQoS( lobbyUserID_t lobbyUserID ) const { return 0; }
  60. virtual int GetLobbyUserTeam( lobbyUserID_t lobbyUserID ) const { return 0; }
  61. virtual bool SetLobbyUserTeam( lobbyUserID_t lobbyUserID, int teamNumber ) { return false; }
  62. virtual int GetLobbyUserPartyToken( lobbyUserID_t lobbyUserID ) const { return 0; }
  63. virtual idPlayerProfile * GetProfileFromLobbyUser( lobbyUserID_t lobbyUserID ) { return NULL; }
  64. virtual idLocalUser * GetLocalUserFromLobbyUser( lobbyUserID_t lobbyUserID ) { return NULL; }
  65. virtual int GetNumLobbyUsersOnTeam( int teamNumber ) const { return 0; }
  66. virtual int PeerIndexFromLobbyUser( lobbyUserID_t lobbyUserID ) const { return -1; }
  67. virtual int GetPeerTimeSinceLastPacket( int peerIndex ) const { return 0; }
  68. virtual int PeerIndexForHost() const { return -1; }
  69. virtual lobbyUserID_t AllocLobbyUserSlotForBot( const char * botName ) { return lobbyUserID_t(); }
  70. virtual void RemoveBotFromLobbyUserList( lobbyUserID_t lobbyUserID ) {}
  71. virtual bool GetLobbyUserIsBot( lobbyUserID_t lobbyUserID ) const { return false; }
  72. virtual const char * GetHostUserName() const { return "INVALID"; }
  73. virtual const idMatchParameters & GetMatchParms() const { return fakeParms; }
  74. virtual bool IsLobbyFull() const { return false; }
  75. virtual bool EnsureAllPeersHaveBaseState() { return false; }
  76. virtual bool AllPeersInGame() const { return false; }
  77. virtual int GetNumConnectedPeers() const { return 0; }
  78. virtual int GetNumConnectedPeersInGame() const { return 0; }
  79. virtual int PeerIndexOnHost() const { return -1; }
  80. virtual bool IsPeerDisconnected( int peerIndex ) const { return false; }
  81. virtual bool AllPeersHaveStaleSnapObj( int objId ) { return false; }
  82. virtual bool AllPeersHaveExpectedSnapObj( int objId ) { return false; }
  83. virtual void RefreshSnapObj( int objId ) {}
  84. virtual void MarkSnapObjDeleted( int objId ) {}
  85. virtual void AddSnapObjTemplate( int objID, idBitMsg & msg ) {}
  86. virtual void DrawDebugNetworkHUD() const {}
  87. virtual void DrawDebugNetworkHUD2() const {}
  88. virtual void DrawDebugNetworkHUD_ServerSnapshotMetrics( bool draw ) {}
  89. private:
  90. idMatchParameters fakeParms;
  91. };
  92. /*
  93. ================================================
  94. idSessionLocal
  95. ================================================
  96. */
  97. class idSessionLocal : public idSession {
  98. friend class idLeaderboards;
  99. friend class idStatsSession;
  100. friend class idLobbyBackend360;
  101. friend class idLobbyBackendPS3;
  102. friend class idSessionLocalCallbacks;
  103. friend class idPsnAsyncSubmissionLookupPS3_TitleStorage;
  104. friend class idNetSessionPort;
  105. friend class lobbyAddress_t;
  106. protected:
  107. //=====================================================================================================
  108. // Mixed Common/Platform enums/structs
  109. //=====================================================================================================
  110. // Overall state of the session
  111. enum state_t {
  112. STATE_PRESS_START, // We are at press start
  113. STATE_IDLE, // We are at the main menu
  114. STATE_PARTY_LOBBY_HOST, // We are in the party lobby menu as host
  115. STATE_PARTY_LOBBY_PEER, // We are in the party lobby menu as a peer
  116. STATE_GAME_LOBBY_HOST, // We are in the game lobby as a host
  117. STATE_GAME_LOBBY_PEER, // We are in the game lobby as a peer
  118. STATE_GAME_STATE_LOBBY_HOST, // We are in the game state lobby as a host
  119. STATE_GAME_STATE_LOBBY_PEER, // We are in the game state lobby as a peer
  120. STATE_CREATE_AND_MOVE_TO_PARTY_LOBBY, // We are creating a party lobby, and will move to that state when done
  121. STATE_CREATE_AND_MOVE_TO_GAME_LOBBY, // We are creating a game lobby, and will move to that state when done
  122. STATE_CREATE_AND_MOVE_TO_GAME_STATE_LOBBY, // We are creating a game state lobby, and will move to that state when done
  123. STATE_FIND_OR_CREATE_MATCH,
  124. STATE_CONNECT_AND_MOVE_TO_PARTY,
  125. STATE_CONNECT_AND_MOVE_TO_GAME,
  126. STATE_CONNECT_AND_MOVE_TO_GAME_STATE,
  127. STATE_BUSY, // Doing something internally like a QoS/bandwidth challenge
  128. // These are last, so >= STATE_LOADING tests work
  129. STATE_LOADING, // We are loading the map, preparing to go into a match
  130. STATE_INGAME, // We are currently in a match
  131. NUM_STATES
  132. };
  133. enum connectType_t {
  134. CONNECT_NONE = 0,
  135. CONNECT_DIRECT = 1,
  136. CONNECT_FIND_OR_CREATE = 2,
  137. };
  138. enum pendingInviteMode_t {
  139. PENDING_INVITE_NONE = 0, // No invite waiting
  140. PENDING_INVITE_WAITING = 1, // Invite is waiting
  141. PENDING_SELF_INVITE_WAITING = 2, // We invited ourselves to a match
  142. };
  143. struct contentData_t {
  144. bool isMounted;
  145. idStrStatic<128> displayName;
  146. idStrStatic< MAX_OSPATH > packageFileName;
  147. idStrStatic< MAX_OSPATH > rootPath;
  148. int dlcID;
  149. };
  150. public:
  151. idSessionLocal();
  152. virtual ~idSessionLocal();
  153. void InitBaseState();
  154. virtual bool IsPlatformPartyInLobby();
  155. // Downloadable Content
  156. virtual int GetNumContentPackages() const;
  157. virtual int GetContentPackageID( int contentIndex ) const;
  158. virtual const char * GetContentPackagePath( int contentIndex ) const;
  159. virtual int GetContentPackageIndexForID( int contentID ) const;
  160. virtual bool GetSystemMarketplaceHasNewContent() const { return marketplaceHasNewContent; }
  161. virtual void SetSystemMarketplaceHasNewContent( bool hasNewContent ) { marketplaceHasNewContent = hasNewContent; }
  162. // Lobby management
  163. virtual void CreatePartyLobby( const idMatchParameters & parms_ );
  164. virtual void FindOrCreateMatch( const idMatchParameters & parms );
  165. virtual void CreateMatch( const idMatchParameters & parms_ );
  166. virtual void CreateGameStateLobby( const idMatchParameters & parms_ );
  167. virtual void UpdatePartyParms( const idMatchParameters & parms_ );
  168. virtual void UpdateMatchParms( const idMatchParameters & parms_ );
  169. virtual void StartMatch();
  170. virtual void SetSessionOption( sessionOption_t option ) { sessionOptions |= option; }
  171. virtual void ClearSessionOption( sessionOption_t option ) { sessionOptions &= ~option; }
  172. virtual sessionState_t GetBackState();
  173. virtual void Cancel();
  174. virtual void MoveToPressStart();
  175. virtual void FinishDisconnect();
  176. virtual bool ShouldShowMigratingDialog() const; // Note this is not in sys_session.h
  177. virtual bool IsCurrentLobbyMigrating() const;
  178. virtual bool IsLosingConnectionToHost() const;
  179. // Migration
  180. virtual bool WasMigrationGame() const;
  181. virtual bool ShouldRelaunchMigrationGame() const;
  182. virtual bool GetMigrationGameData( idBitMsg & msg, bool reading );
  183. virtual bool GetMigrationGameDataUser( lobbyUserID_t lobbyUserID, idBitMsg & msg, bool reading );
  184. virtual bool WasGameLobbyCoalesced() const { return gameLobbyWasCoalesced; }
  185. // Misc
  186. virtual int GetLoadingID() { return loadingID; }
  187. virtual bool IsAboutToLoad() const { return GetGameLobby().IsLobbyActive() && GetGameLobby().startLoadingFromHost; }
  188. virtual bool GetMatchParamUpdate( int &peer, int &msg );
  189. virtual int GetInputRouting( int inputRouting[ MAX_INPUT_DEVICES ] );
  190. virtual void EndMatch( bool premature=false ); // Meant for host to end match gracefully, go back to lobby, tally scores, etc
  191. virtual void MatchFinished(); // this is for when the game is over before we go back to lobby. Need this incase the host leaves during this time
  192. virtual void QuitMatch(); // Meant for host or peer to quit the match before it ends, will instigate host migration, etc
  193. virtual void QuitMatchToTitle(); // Will forcefully quit the match and return to the title screen.
  194. virtual void LoadingFinished();
  195. virtual void Pump();
  196. virtual void ProcessSnapAckQueue();
  197. virtual sessionState_t GetState() const;
  198. virtual const char * GetStateString() const ;
  199. virtual void SendUsercmds( idBitMsg & msg );
  200. virtual void SendSnapshot( idSnapShot & ss );
  201. virtual const char * GetPeerName( int peerNum );
  202. virtual const char * GetLocalUserName( int i ) const { return signInManager->GetLocalUserByIndex( i )->GetGamerTag(); }
  203. virtual void UpdateSignInManager();
  204. virtual idPlayerProfile * GetProfileFromMasterLocalUser();
  205. virtual void PrePickNewHost( idLobby & lobby, bool forceMe, bool inviteOldHost );
  206. virtual bool PreMigrateInvite( idLobby & lobby );
  207. //=====================================================================================================
  208. // Title Storage Vars
  209. //=====================================================================================================
  210. virtual float GetTitleStorageFloat( const char * name, float defaultFloat ) const { return titleStorageVars.GetFloat( name, defaultFloat ); }
  211. virtual int GetTitleStorageInt( const char * name, int defaultInt ) const { return titleStorageVars.GetInt( name, defaultInt ); }
  212. virtual bool GetTitleStorageBool( const char * name, bool defaultBool ) const { return titleStorageVars.GetBool( name, defaultBool ); }
  213. virtual const char * GetTitleStorageString( const char * name, const char * defaultString ) const { return titleStorageVars.GetString( name, defaultString ); }
  214. virtual bool GetTitleStorageFloat( const char * name, float defaultFloat, float & out ) const { return titleStorageVars.GetFloat( name, defaultFloat, out ); }
  215. virtual bool GetTitleStorageInt( const char * name, int defaultInt, int & out ) const { return titleStorageVars.GetInt( name, defaultInt, out ); }
  216. virtual bool GetTitleStorageBool( const char * name, bool defaultBool, bool & out ) const { return titleStorageVars.GetBool( name, defaultBool, out ); }
  217. virtual bool GetTitleStorageString( const char * name, const char * defaultString, const char ** out ) const { return titleStorageVars.GetString( name, defaultString, out ); }
  218. virtual bool IsTitleStorageLoaded() { return titleStorageLoaded; }
  219. //=====================================================================================================
  220. // Voice chat
  221. //=====================================================================================================
  222. virtual voiceState_t GetLobbyUserVoiceState( lobbyUserID_t lobbyUserID );
  223. virtual voiceStateDisplay_t GetDisplayStateFromVoiceState( voiceState_t voiceState ) const;
  224. virtual void ToggleLobbyUserVoiceMute( lobbyUserID_t lobbyUserID );
  225. virtual void SetActiveChatGroup( int groupIndex );
  226. virtual void UpdateMasterUserHeadsetState();
  227. //=====================================================================================================
  228. // Bandwidth / QoS checking
  229. //=====================================================================================================
  230. virtual bool StartOrContinueBandwidthChallenge( bool forceStart );
  231. virtual void DebugSetPeerSnaprate( int peerIndex, int snapRateMS );
  232. virtual float GetIncomingByteRate();
  233. //=====================================================================================================
  234. // Invites
  235. //=====================================================================================================
  236. virtual void HandleBootableInvite( int64 lobbyId = 0 ) = 0;
  237. virtual void ClearBootableInvite() = 0;
  238. virtual void ClearPendingInvite() = 0;
  239. virtual bool HasPendingBootableInvite() = 0;
  240. virtual void SetDiscSwapMPInvite( void * parm ) = 0; // call to request a discSwap multiplayer invite
  241. virtual void * GetDiscSwapMPInviteParms() = 0;
  242. virtual bool IsDiscSwapMPInviteRequested() const { return inviteInfoRequested; }
  243. bool GetFlushedStats() { return flushedStats; }
  244. void SetFlushedStats( bool _flushedStats ) { flushedStats = _flushedStats; }
  245. //=====================================================================================================
  246. // Notifications
  247. //=====================================================================================================
  248. // This is called when a LocalUser is signed in/out
  249. virtual void OnLocalUserSignin( idLocalUser * user );
  250. virtual void OnLocalUserSignout( idLocalUser * user );
  251. // This is called when the master LocalUser is signed in/out, these are called after OnLocalUserSignin/out()
  252. virtual void OnMasterLocalUserSignout();
  253. virtual void OnMasterLocalUserSignin();
  254. // After a local user has signed in and their profile has loaded
  255. virtual void OnLocalUserProfileLoaded( idLocalUser * user );
  256. //=====================================================================================================
  257. // Platform specific (different platforms implement these differently)
  258. //=====================================================================================================
  259. virtual void Initialize() = 0;
  260. virtual void Shutdown() = 0;
  261. virtual void InitializeSoundRelatedSystems() = 0;
  262. virtual void ShutdownSoundRelatedSystems() = 0;
  263. virtual void PlatformPump() = 0;
  264. virtual void InviteFriends() = 0;
  265. virtual void InviteParty() = 0;
  266. virtual void ShowPartySessions() = 0;
  267. virtual bool ProcessInputEvent( const sysEvent_t * ev ) = 0;
  268. // Play with Friends server listing
  269. virtual int NumServers() const = 0;
  270. virtual void ListServers( const idCallback & callback ) = 0;
  271. virtual void ListServersCommon();
  272. virtual void CancelListServers() = 0;
  273. virtual void ConnectToServer( int i ) = 0;
  274. virtual const serverInfo_t * ServerInfo( int i ) const = 0;
  275. virtual const idList< idStr > * ServerPlayerList( int i );
  276. virtual void ShowServerGamerCardUI( int i ) = 0;
  277. virtual void HandleServerQueryRequest( lobbyAddress_t & remoteAddr, idBitMsg & msg, int msgType ) = 0;
  278. virtual void HandleServerQueryAck( lobbyAddress_t & remoteAddr, idBitMsg & msg ) = 0;
  279. // System UI
  280. virtual bool IsSystemUIShowing() const = 0;
  281. virtual void SetSystemUIShowing( bool show ) = 0;
  282. virtual void ShowSystemMarketplaceUI() const = 0;
  283. virtual void ShowLobbyUserGamerCardUI( lobbyUserID_t lobbyUserID ) = 0;
  284. // Leaderboards
  285. virtual void LeaderboardUpload( lobbyUserID_t lobbyUserID, const leaderboardDefinition_t * leaderboard, const column_t * stats, const idFile_Memory * attachment = NULL ) = 0;
  286. virtual void LeaderboardDownload( int sessionUserIndex, const leaderboardDefinition_t * leaderboard, int startingRank, int numRows, const idLeaderboardCallback & callback ) = 0;
  287. virtual void LeaderboardDownloadAttachment( int sessionUserIndex, const leaderboardDefinition_t * leaderboard, int64 attachmentID ) = 0;
  288. // Scoring (currently just for TrueSkill)
  289. virtual void SetLobbyUserRelativeScore( lobbyUserID_t lobbyUserID, int relativeScore, int team ) = 0;
  290. virtual void LeaderboardFlush() = 0;
  291. //=====================================================================================================i'
  292. // Savegames
  293. //=====================================================================================================
  294. virtual saveGameHandle_t SaveGameSync( const char * name, const saveFileEntryList_t & files, const idSaveGameDetails & description );
  295. virtual saveGameHandle_t SaveGameAsync( const char * name, const saveFileEntryList_t & files, const idSaveGameDetails & description );
  296. virtual saveGameHandle_t LoadGameSync( const char * name, saveFileEntryList_t & files );
  297. virtual saveGameHandle_t EnumerateSaveGamesSync();
  298. virtual saveGameHandle_t EnumerateSaveGamesAsync();
  299. virtual saveGameHandle_t DeleteSaveGameSync( const char * name );
  300. virtual saveGameHandle_t DeleteSaveGameAsync( const char * name );
  301. virtual bool IsSaveGameCompletedFromHandle( const saveGameHandle_t & handle ) const { return saveGameManager->IsSaveGameCompletedFromHandle( handle ); }
  302. virtual void CancelSaveGameWithHandle( const saveGameHandle_t & handle ) { GetSaveGameManager().CancelWithHandle( handle ); }
  303. virtual const saveGameDetailsList_t & GetEnumeratedSavegames() const { return saveGameManager->GetEnumeratedSavegames(); }
  304. virtual bool IsEnumerating() const;
  305. virtual saveGameHandle_t GetEnumerationHandle() const;
  306. virtual void SetCurrentSaveSlot( const char * slotName ) { currentSaveSlot = slotName; }
  307. virtual const char * GetCurrentSaveSlot() const { return currentSaveSlot.c_str(); }
  308. // Notifications
  309. void OnSaveCompleted( idSaveLoadParms * parms );
  310. void OnLoadCompleted( idSaveLoadParms * parms );
  311. void OnDeleteCompleted( idSaveLoadParms * parms );
  312. void OnEnumerationCompleted( idSaveLoadParms * parms );
  313. // Error checking
  314. virtual bool IsDLCAvailable( const char * mapName );
  315. virtual bool LoadGameCheckDiscNumber( idSaveLoadParms & parms );
  316. bool LoadGameCheckDescriptionFile( idSaveLoadParms & parms );
  317. // Downloadable Content
  318. virtual void EnumerateDownloadableContent() = 0;
  319. void DropClient( int peerNum, int session );
  320. protected:
  321. float GetUpstreamDropRate() { return upstreamDropRate; }
  322. float GetUpstreamQueueRate() { return upstreamQueueRate; }
  323. int GetQueuedBytes() { return queuedBytes; }
  324. //=====================================================================================================
  325. // Common functions (sys_session_local.cpp)
  326. //=====================================================================================================
  327. void HandleLobbyControllerState( int lobbyType );
  328. virtual void UpdatePendingInvite();
  329. bool HandleState();
  330. // The party and game lobby are the two platform lobbies that notify the backends (Steam/PSN/LIVE of changes)
  331. idLobby & GetPartyLobby() { return partyLobby; }
  332. const idLobby & GetPartyLobby() const { return partyLobby; }
  333. idLobby & GetGameLobby() { return gameLobby; }
  334. const idLobby & GetGameLobby() const { return gameLobby; }
  335. // Game state lobby is the lobby used while in-game. It is so the dedicated server can host this lobby
  336. // and have all platform clients join. It does NOT notify the backends of changes, it's purely for the dedicated
  337. // server to be able to host the in-game lobby.
  338. // Generally, you would call GetActingGameStateLobby. If we are not using game state lobby, GetActingGameStateLobby will return GetGameLobby insread.
  339. idLobby & GetGameStateLobby() { return gameStateLobby; }
  340. const idLobby & GetGameStateLobby() const { return gameStateLobby; }
  341. idLobby & GetActingGameStateLobby();
  342. const idLobby & GetActingGameStateLobby() const;
  343. // GetActivePlatformLobby will return either the game or party lobby, it won't return the game state lobby
  344. // This function is generally used for menus, in-game code should refer to GetActingGameStateLobby
  345. idLobby * GetActivePlatformLobby();
  346. const idLobby * GetActivePlatformLobby() const;
  347. idLobby * GetLobbyFromType( idLobby::lobbyType_t lobbyType );
  348. virtual idLobbyBase & GetPartyLobbyBase() { return partyLobby; }
  349. virtual idLobbyBase & GetGameLobbyBase() { return gameLobby; }
  350. virtual idLobbyBase & GetActingGameStateLobbyBase() { return GetActingGameStateLobby(); }
  351. virtual idLobbyBase & GetActivePlatformLobbyBase();
  352. virtual idLobbyBase & GetLobbyFromLobbyUserID( lobbyUserID_t lobbyUserID );
  353. void SetState( state_t newState );
  354. bool HandlePackets();
  355. void HandleVoiceRestrictionDialog();
  356. void SetDroppedByHost( bool dropped ) { droppedByHost = dropped; }
  357. bool GetDroppedByHost() { return droppedByHost; }
  358. public:
  359. int storedPeer;
  360. int storedMsgType;
  361. protected:
  362. static const char * stateToString[ NUM_STATES ];
  363. state_t localState;
  364. uint32 sessionOptions;
  365. connectType_t connectType;
  366. int connectTime;
  367. idLobby partyLobby;
  368. idLobby gameLobby;
  369. idLobby gameStateLobby;
  370. idLobbyStub stubLobby; // We use this when we request the active lobby when we are not in a lobby (i.e at press start)
  371. int currentID; // The host used this to send out a unique id to all users so we can identify them
  372. class idVoiceChatMgr * voiceChat;
  373. int lastVoiceSendtime;
  374. bool hasShownVoiceRestrictionDialog;
  375. pendingInviteMode_t pendingInviteMode;
  376. int pendingInviteDevice;
  377. lobbyConnectInfo_t pendingInviteConnectInfo;
  378. bool isSysUIShowing;
  379. idDict titleStorageVars;
  380. bool titleStorageLoaded;
  381. int showMigratingInfoStartTime;
  382. int nextGameCoalesceTime;
  383. bool gameLobbyWasCoalesced;
  384. int numFullSnapsReceived;
  385. bool flushedStats;
  386. int loadingID;
  387. bool inviteInfoRequested;
  388. idSaveGameProcessorSaveFiles * processorSaveFiles;
  389. idSaveGameProcessorLoadFiles * processorLoadFiles;
  390. idSaveGameProcessorDelete * processorDelete;
  391. idSaveGameProcessorEnumerateGames * processorEnumerate;
  392. idStr currentSaveSlot;
  393. saveGameHandle_t enumerationHandle;
  394. //------------------------
  395. // State functions
  396. //------------------------
  397. bool State_Party_Lobby_Host();
  398. bool State_Party_Lobby_Peer();
  399. bool State_Game_Lobby_Host();
  400. bool State_Game_Lobby_Peer();
  401. bool State_Game_State_Lobby_Host();
  402. bool State_Game_State_Lobby_Peer();
  403. bool State_Loading();
  404. bool State_InGame();
  405. bool State_Find_Or_Create_Match();
  406. bool State_Create_And_Move_To_Party_Lobby();
  407. bool State_Create_And_Move_To_Game_Lobby();
  408. bool State_Create_And_Move_To_Game_State_Lobby();
  409. bool State_Connect_And_Move_To_Party();
  410. bool State_Connect_And_Move_To_Game();
  411. bool State_Connect_And_Move_To_Game_State();
  412. bool State_Finalize_Connect();
  413. bool State_Busy();
  414. // -----------------------
  415. // Downloadable Content
  416. // -----------------------
  417. static const int MAX_CONTENT_PACKAGES = 16;
  418. idStaticList<contentData_t, MAX_CONTENT_PACKAGES> downloadedContent;
  419. bool marketplaceHasNewContent;
  420. class idQueuePacket {
  421. public:
  422. byte data[ idPacketProcessor::MAX_FINAL_PACKET_SIZE ];
  423. lobbyAddress_t address;
  424. int size;
  425. int time;
  426. bool dedicated;
  427. idQueueNode<idQueuePacket> queueNode;
  428. };
  429. idBlockAlloc< idQueuePacket, 64, TAG_NETWORKING > packetAllocator;
  430. idQueue< idQueuePacket,&idQueuePacket::queueNode > sendQueue;
  431. idQueue< idQueuePacket,&idQueuePacket::queueNode > recvQueue;
  432. float upstreamDropRate; // instant rate in B/s at which we are dropping packets due to simulated upstream saturation
  433. int upstreamDropRateTime;
  434. float upstreamQueueRate; // instant rate in B/s at which queued packets are coming out after local buffering due to upstream saturation
  435. int upstreamQueueRateTime;
  436. int queuedBytes;
  437. int waitingOnGameStateMembersToLeaveTime;
  438. int waitingOnGameStateMembersToJoinTime;
  439. void TickSendQueue();
  440. void QueuePacket( idQueue< idQueuePacket,&idQueuePacket::queueNode > & queue, int time, const lobbyAddress_t & to, const void * data, int size, bool dedicated );
  441. bool ReadRawPacketFromQueue( int time, lobbyAddress_t & from, void * data, int & size, bool & outDedicated, int maxSize );
  442. void SendRawPacket( const lobbyAddress_t & to, const void * data, int size, bool dedicated );
  443. bool ReadRawPacket( lobbyAddress_t & from, void * data, int & size, bool & outDedicated, int maxSize );
  444. void ConnectAndMoveToLobby( idLobby & lobby, const lobbyConnectInfo_t & connectInfo, bool fromInvite );
  445. void GoodbyeFromHost( idLobby & lobby, int peerNum, const lobbyAddress_t & remoteAddress, int msgType );
  446. void WriteLeaderboardToMsg( idBitMsg & msg, const leaderboardDefinition_t * leaderboard, const column_t * stats );
  447. void SendLeaderboardStatsToPlayer( lobbyUserID_t lobbyUserID, const leaderboardDefinition_t * leaderboard, const column_t * stats );
  448. void RecvLeaderboardStatsForPlayer( idBitMsg & msg );
  449. const leaderboardDefinition_t * ReadLeaderboardFromMsg( idBitMsg & msg, column_t * stats );
  450. bool RequirePersistentMaster();
  451. virtual idNetSessionPort & GetPort( bool dedicated = false ) = 0;
  452. virtual idLobbyBackend * CreateLobbyBackend( const idMatchParameters & p, float skillLevel, idLobbyBackend::lobbyBackendType_t lobbyType ) = 0;
  453. virtual idLobbyBackend * FindLobbyBackend( const idMatchParameters & p, int numPartyUsers, float skillLevel, idLobbyBackend::lobbyBackendType_t lobbyType ) = 0;
  454. virtual idLobbyBackend * JoinFromConnectInfo( const lobbyConnectInfo_t & connectInfo , idLobbyBackend::lobbyBackendType_t lobbyType ) = 0;
  455. virtual void DestroyLobbyBackend( idLobbyBackend * lobby ) = 0;
  456. virtual void PumpLobbies() = 0;
  457. virtual bool GetLobbyAddressFromNetAddress( const netadr_t & netAddr, lobbyAddress_t & outAddr ) const = 0;
  458. virtual bool GetNetAddressFromLobbyAddress( const lobbyAddress_t & lobbyAddress, netadr_t & outNetAddr ) const = 0;
  459. void HandleDedicatedServerQueryRequest( lobbyAddress_t & remoteAddr, idBitMsg & msg, int msgType );
  460. void HandleDedicatedServerQueryAck( lobbyAddress_t & remoteAddr, idBitMsg & msg );
  461. void ClearMigrationState();
  462. // this is called when the mathc is over and returning to lobby
  463. void EndMatchInternal( bool premature=false );
  464. // this is called when the game finished and we are in the end match recap
  465. void MatchFinishedInternal();
  466. void EndMatchForMigration();
  467. void MoveToPressStart( gameDialogMessages_t msg );
  468. // Voice chat
  469. void SendVoiceAudio();
  470. void HandleOobVoiceAudio( const lobbyAddress_t & from, const idBitMsg & msg );
  471. void SetVoiceGroupsToTeams();
  472. void ClearVoiceGroups();
  473. // All the new functions going here for now until it can all be cleaned up
  474. void StartSessions();
  475. void EndSessions();
  476. void SetLobbiesAreJoinable( bool joinable );
  477. void MoveToMainMenu(); // End all session (async), and return to IDLE state
  478. bool WaitOnLobbyCreate( idLobby & lobby );
  479. bool DetectDisconnectFromService( bool cancelAndShowMsg );
  480. void HandleConnectionFailed( idLobby & lobby, bool wasFull );
  481. void ConnectToNextSearchResultFailed( idLobby & lobby );
  482. bool HandleConnectAndMoveToLobby( idLobby & lobby );
  483. void VerifySnapshotInitialState();
  484. void ComputeNextGameCoalesceTime();
  485. void StartLoading();
  486. bool ShouldHavePartyLobby();
  487. void ValidateLobbies();
  488. void ValidateLobby( idLobby & lobby );
  489. void ReadTitleStorage( void * buffer, int bufferLen );
  490. bool ReadDLCInfo( idDict & dlcInfo, void * buffer, int bufferLen );
  491. idSessionCallbacks * sessionCallbacks;
  492. int offlineTransitionTimerStart;
  493. bool droppedByHost;
  494. };
  495. /*
  496. ========================
  497. idSessionLocalCallbacks
  498. The more the idLobby class needs to call back into this class, the more likely we're doing something wrong, and there is a better way.
  499. ========================
  500. */
  501. class idSessionLocalCallbacks : public idSessionCallbacks {
  502. public:
  503. idSessionLocalCallbacks( idSessionLocal * sessionLocal_ ) { sessionLocal = sessionLocal_; }
  504. virtual idLobby & GetPartyLobby() { return sessionLocal->GetPartyLobby(); }
  505. virtual idLobby & GetGameLobby() { return sessionLocal->GetGameLobby(); }
  506. virtual idLobby & GetActingGameStateLobby() { return sessionLocal->GetActingGameStateLobby(); }
  507. virtual idLobby * GetLobbyFromType( idLobby::lobbyType_t lobbyType ) { return sessionLocal->GetLobbyFromType( lobbyType ); }
  508. virtual int GetUniquePlayerId() const { return sessionLocal->currentID++; }
  509. virtual idSignInManagerBase & GetSignInManager() { return *sessionLocal->signInManager; }
  510. virtual void SendRawPacket( const lobbyAddress_t & to, const void * data, int size, bool useDirectPort ) { sessionLocal->SendRawPacket( to, data, size, useDirectPort ); }
  511. virtual bool BecomingHost( idLobby & lobby );
  512. virtual void BecameHost( idLobby & lobby );
  513. virtual bool BecomingPeer( idLobby & lobby );
  514. virtual void BecamePeer( idLobby & lobby );
  515. virtual void FailedGameMigration( idLobby & lobby );
  516. virtual void MigrationEnded( idLobby & lobby );
  517. virtual void GoodbyeFromHost( idLobby & lobby, int peerNum, const lobbyAddress_t & remoteAddress, int msgType );
  518. virtual uint32 GetSessionOptions() { return sessionLocal->sessionOptions; }
  519. virtual bool AnyPeerHasAddress( const lobbyAddress_t & remoteAddress ) const;
  520. virtual idSession::sessionState_t GetState() const { return sessionLocal->GetState(); }
  521. virtual void ClearMigrationState() { GetPartyLobby().ResetAllMigrationState(); GetGameLobby().ResetAllMigrationState(); }
  522. virtual void EndMatchInternal( bool premature=false ) { sessionLocal->EndMatchInternal( premature ); }
  523. virtual void RecvLeaderboardStats( idBitMsg & msg );
  524. virtual void ReceivedFullSnap();
  525. virtual void LeaveGameLobby();
  526. virtual void PrePickNewHost( idLobby & lobby, bool forceMe, bool inviteOldHost );
  527. virtual bool PreMigrateInvite( idLobby & lobby );
  528. virtual void HandleOobVoiceAudio( const lobbyAddress_t & from, const idBitMsg & msg ) { sessionLocal->HandleOobVoiceAudio( from, msg ); }
  529. virtual void ConnectAndMoveToLobby( idLobby::lobbyType_t destLobbyType, const lobbyConnectInfo_t & connectInfo, bool waitForPartyOk );
  530. virtual idVoiceChatMgr * GetVoiceChat() { return sessionLocal->voiceChat; }
  531. virtual void HandleServerQueryRequest( lobbyAddress_t & remoteAddr, idBitMsg & msg, int msgType );
  532. virtual void HandleServerQueryAck( lobbyAddress_t & remoteAddr, idBitMsg & msg );
  533. virtual void HandlePeerMatchParamUpdate( int peer, int msg );
  534. virtual idLobbyBackend * CreateLobbyBackend( const idMatchParameters & p, float skillLevel, idLobbyBackend::lobbyBackendType_t lobbyType );
  535. virtual idLobbyBackend * FindLobbyBackend( const idMatchParameters & p, int numPartyUsers, float skillLevel, idLobbyBackend::lobbyBackendType_t lobbyType );
  536. virtual idLobbyBackend * JoinFromConnectInfo( const lobbyConnectInfo_t & connectInfo , idLobbyBackend::lobbyBackendType_t lobbyType );
  537. virtual void DestroyLobbyBackend( idLobbyBackend * lobby );
  538. idSessionLocal * sessionLocal;
  539. };