DOOM-3-BFG

DOOM 3 BFG Edition
Log | Files | Refs

sys_session_local.h (33572B)


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