doom3-bfg/neo/sys/win32/win_session_local.cpp

749 lines
18 KiB
C++
Raw Normal View History

2012-11-26 18:58:24 +00:00
/*
================================================================================================
CONFIDENTIAL AND PROPRIETARY INFORMATION/NOT FOR DISCLOSURE WITHOUT WRITTEN PERMISSION
Copyright 2010 id Software LLC, a ZeniMax Media company. All Rights Reserved.
2012-11-26 18:58:24 +00:00
================================================================================================
*/
/*
================================================================================================
Contains the windows implementation of the network session
================================================================================================
*/
#pragma hdrstop
#include "precompiled.h"
2012-11-26 18:58:24 +00:00
#include "../../framework/Common_local.h"
#include "../sys_session_local.h"
#include "../sys_stats.h"
#include "../sys_savegame.h"
#include "../sys_lobby_backend_direct.h"
#include "../sys_voicechat.h"
#include "win_achievements.h"
#include "win_local.h"
/*
========================
Global variables
========================
*/
extern idCVar net_port;
class idLobbyToSessionCBLocal;
2012-11-26 18:58:24 +00:00
/*
========================
idSessionLocalWin::idSessionLocalWin
========================
*/
class idSessionLocalWin : public idSessionLocal
{
friend class idLobbyToSessionCBLocal;
2012-11-26 18:58:24 +00:00
public:
idSessionLocalWin();
virtual ~idSessionLocalWin();
2012-11-26 18:58:24 +00:00
// idSessionLocal interface
virtual void Initialize();
virtual void Shutdown();
2012-11-26 18:58:24 +00:00
virtual void InitializeSoundRelatedSystems();
virtual void ShutdownSoundRelatedSystems();
2012-11-26 18:58:24 +00:00
virtual void PlatformPump();
2012-11-26 18:58:24 +00:00
virtual void InviteFriends();
virtual void InviteParty();
virtual void ShowPartySessions();
2012-11-26 18:58:24 +00:00
virtual void ShowSystemMarketplaceUI() const;
virtual void ListServers( const idCallback& callback );
2012-11-26 18:58:24 +00:00
virtual void CancelListServers();
virtual int NumServers() const;
virtual const serverInfo_t* ServerInfo( int i ) const;
2012-11-26 18:58:24 +00:00
virtual void ConnectToServer( int i );
virtual void ShowServerGamerCardUI( int i );
2012-11-26 18:58:24 +00:00
virtual void ShowLobbyUserGamerCardUI( lobbyUserID_t lobbyUserID );
2012-11-26 18:58:24 +00:00
virtual void ShowOnlineSignin() {}
virtual void UpdateRichPresence() {}
virtual void CheckVoicePrivileges() {}
virtual bool ProcessInputEvent( const sysEvent_t* ev );
2012-11-26 18:58:24 +00:00
// System UI
virtual bool IsSystemUIShowing() const;
virtual void SetSystemUIShowing( bool show );
2012-11-26 18:58:24 +00:00
// Invites
virtual void HandleBootableInvite( int64 lobbyId = 0 );
virtual void ClearBootableInvite();
virtual void ClearPendingInvite();
virtual bool HasPendingBootableInvite();
virtual void SetDiscSwapMPInvite( void* parm );
virtual void* GetDiscSwapMPInviteParms();
2012-11-26 18:58:24 +00:00
virtual void EnumerateDownloadableContent();
virtual void HandleServerQueryRequest( lobbyAddress_t& remoteAddr, idBitMsg& msg, int msgType );
virtual void HandleServerQueryAck( lobbyAddress_t& remoteAddr, idBitMsg& msg );
2012-11-26 18:58:24 +00:00
// Leaderboards
virtual void LeaderboardUpload( lobbyUserID_t lobbyUserID, const leaderboardDefinition_t* leaderboard, const column_t* stats, const idFile_Memory* attachment = NULL );
virtual void LeaderboardDownload( int sessionUserIndex, const leaderboardDefinition_t* leaderboard, int startingRank, int numRows, const idLeaderboardCallback& callback );
virtual void LeaderboardDownloadAttachment( int sessionUserIndex, const leaderboardDefinition_t* leaderboard, int64 attachmentID );
2012-11-26 18:58:24 +00:00
// Scoring (currently just for TrueSkill)
virtual void SetLobbyUserRelativeScore( lobbyUserID_t lobbyUserID, int relativeScore, int team ) {}
2012-11-26 18:58:24 +00:00
virtual void LeaderboardFlush();
virtual idNetSessionPort& GetPort( bool dedicated = false );
virtual idLobbyBackend* CreateLobbyBackend( const idMatchParameters& p, float skillLevel, idLobbyBackend::lobbyBackendType_t lobbyType );
virtual idLobbyBackend* FindLobbyBackend( const idMatchParameters& p, int numPartyUsers, float skillLevel, idLobbyBackend::lobbyBackendType_t lobbyType );
virtual idLobbyBackend* JoinFromConnectInfo( const lobbyConnectInfo_t& connectInfo , idLobbyBackend::lobbyBackendType_t lobbyType );
virtual void DestroyLobbyBackend( idLobbyBackend* lobbyBackend );
2012-11-26 18:58:24 +00:00
virtual void PumpLobbies();
virtual void JoinAfterSwap( void* joinID );
virtual bool GetLobbyAddressFromNetAddress( const netadr_t& netAddr, lobbyAddress_t& outAddr ) const;
virtual bool GetNetAddressFromLobbyAddress( const lobbyAddress_t& lobbyAddress, netadr_t& outNetAddr ) const;
2012-11-26 18:58:24 +00:00
public:
void Connect_f( const idCmdArgs& args );
2012-11-26 18:58:24 +00:00
private:
void EnsurePort();
idLobbyBackend* CreateLobbyInternal( idLobbyBackend::lobbyBackendType_t lobbyType );
idArray< idLobbyBackend*, 3 > lobbyBackends;
2012-11-26 18:58:24 +00:00
idNetSessionPort port;
bool canJoinLocalHost;
idLobbyToSessionCBLocal* lobbyToSessionCB;
2012-11-26 18:58:24 +00:00
};
idSessionLocalWin sessionLocalWin;
idSession* session = &sessionLocalWin;
2012-11-26 18:58:24 +00:00
/*
========================
idLobbyToSessionCBLocal
========================
*/
class idLobbyToSessionCBLocal : public idLobbyToSessionCB
{
2012-11-26 18:58:24 +00:00
public:
idLobbyToSessionCBLocal( idSessionLocalWin* sessionLocalWin_ ) : sessionLocalWin( sessionLocalWin_ ) { }
virtual bool CanJoinLocalHost() const
{
sessionLocalWin->EnsurePort();
return sessionLocalWin->canJoinLocalHost;
}
virtual class idLobbyBackend* GetLobbyBackend( idLobbyBackend::lobbyBackendType_t type ) const
{
return sessionLocalWin->lobbyBackends[ type ];
}
2012-11-26 18:58:24 +00:00
private:
idSessionLocalWin* sessionLocalWin;
2012-11-26 18:58:24 +00:00
};
idLobbyToSessionCBLocal lobbyToSessionCBLocal( &sessionLocalWin );
idLobbyToSessionCB* lobbyToSessionCB = &lobbyToSessionCBLocal;
2012-11-26 18:58:24 +00:00
class idVoiceChatMgrWin : public idVoiceChatMgr
{
2012-11-26 18:58:24 +00:00
public:
virtual bool GetLocalChatDataInternal( int talkerIndex, byte* data, int& dataSize )
{
return false;
}
virtual void SubmitIncomingChatDataInternal( int talkerIndex, const byte* data, int dataSize ) { }
virtual bool TalkerHasData( int talkerIndex )
{
return false;
}
virtual bool RegisterTalkerInternal( int index )
{
return true;
}
2012-11-26 18:58:24 +00:00
virtual void UnregisterTalkerInternal( int index ) { }
};
/*
========================
idSessionLocalWin::idSessionLocalWin
========================
*/
idSessionLocalWin::idSessionLocalWin()
{
signInManager = new( TAG_SYSTEM ) idSignInManagerWin;
saveGameManager = new( TAG_SAVEGAMES ) idSaveGameManager();
voiceChat = new( TAG_SYSTEM ) idVoiceChatMgrWin();
lobbyToSessionCB = new( TAG_SYSTEM ) idLobbyToSessionCBLocal( this );
2012-11-26 18:58:24 +00:00
canJoinLocalHost = false;
2012-11-26 18:58:24 +00:00
lobbyBackends.Zero();
}
/*
========================
idSessionLocalWin::idSessionLocalWin
========================
*/
idSessionLocalWin::~idSessionLocalWin()
{
2012-11-26 18:58:24 +00:00
delete voiceChat;
delete lobbyToSessionCB;
}
/*
========================
idSessionLocalWin::Initialize
========================
*/
void idSessionLocalWin::Initialize()
{
2012-11-26 18:58:24 +00:00
idSessionLocal::Initialize();
2012-11-26 18:58:24 +00:00
// The shipping path doesn't load title storage
// Instead, we inject values through code which is protected through steam DRM
titleStorageVars.Set( "MAX_PLAYERS_ALLOWED", "8" );
titleStorageLoaded = true;
2012-11-26 18:58:24 +00:00
// First-time check for downloadable content once game is launched
EnumerateDownloadableContent();
2012-11-26 18:58:24 +00:00
GetPartyLobby().Initialize( idLobby::TYPE_PARTY, sessionCallbacks );
GetGameLobby().Initialize( idLobby::TYPE_GAME, sessionCallbacks );
GetGameStateLobby().Initialize( idLobby::TYPE_GAME_STATE, sessionCallbacks );
achievementSystem = new( TAG_SYSTEM ) idAchievementSystemWin();
2012-11-26 18:58:24 +00:00
achievementSystem->Init();
}
/*
========================
idSessionLocalWin::Shutdown
========================
*/
void idSessionLocalWin::Shutdown()
{
2012-11-26 18:58:24 +00:00
NET_VERBOSE_PRINT( "NET: Shutdown\n" );
idSessionLocal::Shutdown();
2012-11-26 18:58:24 +00:00
MoveToMainMenu();
// Wait until we fully shutdown
while( localState != STATE_IDLE && localState != STATE_PRESS_START )
{
2012-11-26 18:58:24 +00:00
Pump();
}
if( achievementSystem != NULL )
{
2012-11-26 18:58:24 +00:00
achievementSystem->Shutdown();
delete achievementSystem;
achievementSystem = NULL;
}
}
/*
========================
idSessionLocalWin::InitializeSoundRelatedSystems
========================
*/
void idSessionLocalWin::InitializeSoundRelatedSystems()
{
if( voiceChat != NULL )
{
2012-11-26 18:58:24 +00:00
voiceChat->Init( NULL );
}
}
/*
========================
idSessionLocalWin::ShutdownSoundRelatedSystems
========================
*/
void idSessionLocalWin::ShutdownSoundRelatedSystems()
{
if( voiceChat != NULL )
{
2012-11-26 18:58:24 +00:00
voiceChat->Shutdown();
}
}
/*
========================
idSessionLocalWin::PlatformPump
========================
*/
void idSessionLocalWin::PlatformPump()
{
2012-11-26 18:58:24 +00:00
}
/*
========================
idSessionLocalWin::InviteFriends
========================
*/
void idSessionLocalWin::InviteFriends()
{
2012-11-26 18:58:24 +00:00
}
/*
========================
idSessionLocalWin::InviteParty
========================
*/
void idSessionLocalWin::InviteParty()
{
2012-11-26 18:58:24 +00:00
}
/*
========================
idSessionLocalWin::ShowPartySessions
========================
*/
void idSessionLocalWin::ShowPartySessions()
{
2012-11-26 18:58:24 +00:00
}
/*
========================
idSessionLocalWin::ShowSystemMarketplaceUI
========================
*/
void idSessionLocalWin::ShowSystemMarketplaceUI() const
{
2012-11-26 18:58:24 +00:00
}
/*
========================
idSessionLocalWin::ListServers
========================
*/
void idSessionLocalWin::ListServers( const idCallback& callback )
{
2012-11-26 18:58:24 +00:00
ListServersCommon();
}
/*
========================
idSessionLocalWin::CancelListServers
========================
*/
void idSessionLocalWin::CancelListServers()
{
2012-11-26 18:58:24 +00:00
}
/*
========================
idSessionLocalWin::NumServers
========================
*/
int idSessionLocalWin::NumServers() const
{
2012-11-26 18:58:24 +00:00
return 0;
}
/*
========================
idSessionLocalWin::ServerInfo
========================
*/
const serverInfo_t* idSessionLocalWin::ServerInfo( int i ) const
{
2012-11-26 18:58:24 +00:00
return NULL;
}
/*
========================
idSessionLocalWin::ConnectToServer
========================
*/
void idSessionLocalWin::ConnectToServer( int i )
{
2012-11-26 18:58:24 +00:00
}
/*
========================
idSessionLocalWin::Connect_f
========================
*/
void idSessionLocalWin::Connect_f( const idCmdArgs& args )
{
if( args.Argc() < 2 )
{
idLib::Printf( "Usage: Connect to IP. Use with net_port. \n" );
2012-11-26 18:58:24 +00:00
return;
}
2012-11-26 18:58:24 +00:00
Cancel();
if( signInManager->GetMasterLocalUser() == NULL )
{
2012-11-26 18:58:24 +00:00
signInManager->RegisterLocalUser( 0 );
}
2012-11-26 18:58:24 +00:00
lobbyConnectInfo_t connectInfo;
Sys_StringToNetAdr( args.Argv( 1 ), &connectInfo.netAddr, true );
2012-11-26 18:58:24 +00:00
connectInfo.netAddr.port = net_port.GetInteger();
2012-11-26 18:58:24 +00:00
ConnectAndMoveToLobby( GetPartyLobby(), connectInfo, false );
}
/*
========================
void Connect_f
========================
*/
CONSOLE_COMMAND( connect, "Connect to the specified IP", NULL )
{
2012-11-26 18:58:24 +00:00
sessionLocalWin.Connect_f( args );
}
/*
========================
idSessionLocalWin::ShowServerGamerCardUI
========================
*/
void idSessionLocalWin::ShowServerGamerCardUI( int i )
{
2012-11-26 18:58:24 +00:00
}
/*
========================
idSessionLocalWin::ShowLobbyUserGamerCardUI(
========================
*/
void idSessionLocalWin::ShowLobbyUserGamerCardUI( lobbyUserID_t lobbyUserID )
{
2012-11-26 18:58:24 +00:00
}
/*
========================
idSessionLocalWin::ProcessInputEvent
========================
*/
bool idSessionLocalWin::ProcessInputEvent( const sysEvent_t* ev )
{
if( GetSignInManager().ProcessInputEvent( ev ) )
{
2012-11-26 18:58:24 +00:00
return true;
}
return false;
}
/*
========================
idSessionLocalWin::IsSystemUIShowing
========================
*/
bool idSessionLocalWin::IsSystemUIShowing() const
{
2012-11-26 18:58:24 +00:00
return !win32.activeApp || isSysUIShowing; // If the user alt+tabs away, treat it the same as bringing up the steam overlay
}
/*
========================
idSessionLocalWin::SetSystemUIShowing
========================
*/
void idSessionLocalWin::SetSystemUIShowing( bool show )
{
2012-11-26 18:58:24 +00:00
isSysUIShowing = show;
}
/*
========================
idSessionLocalWin::HandleServerQueryRequest
========================
*/
void idSessionLocalWin::HandleServerQueryRequest( lobbyAddress_t& remoteAddr, idBitMsg& msg, int msgType )
{
2012-11-26 18:58:24 +00:00
NET_VERBOSE_PRINT( "HandleServerQueryRequest from %s\n", remoteAddr.ToString() );
}
/*
========================
idSessionLocalWin::HandleServerQueryAck
========================
*/
void idSessionLocalWin::HandleServerQueryAck( lobbyAddress_t& remoteAddr, idBitMsg& msg )
{
2012-11-26 18:58:24 +00:00
NET_VERBOSE_PRINT( "HandleServerQueryAck from %s\n", remoteAddr.ToString() );
2012-11-26 18:58:24 +00:00
}
/*
========================
idSessionLocalWin::ClearBootableInvite
========================
*/
void idSessionLocalWin::ClearBootableInvite()
{
2012-11-26 18:58:24 +00:00
}
/*
========================
idSessionLocalWin::ClearPendingInvite
========================
*/
void idSessionLocalWin::ClearPendingInvite()
{
2012-11-26 18:58:24 +00:00
}
/*
========================
idSessionLocalWin::HandleBootableInvite
========================
*/
void idSessionLocalWin::HandleBootableInvite( int64 lobbyId )
{
2012-11-26 18:58:24 +00:00
}
/*
========================
idSessionLocalWin::HasPendingBootableInvite
========================
*/
bool idSessionLocalWin::HasPendingBootableInvite()
{
2012-11-26 18:58:24 +00:00
return false;
}
/*
========================
idSessionLocal::SetDiscSwapMPInvite
========================
*/
void idSessionLocalWin::SetDiscSwapMPInvite( void* parm )
{
2012-11-26 18:58:24 +00:00
}
/*
========================
idSessionLocal::GetDiscSwapMPInviteParms
========================
*/
void* idSessionLocalWin::GetDiscSwapMPInviteParms()
{
2012-11-26 18:58:24 +00:00
return NULL;
}
/*
========================
idSessionLocalWin::EnumerateDownloadableContent
========================
*/
void idSessionLocalWin::EnumerateDownloadableContent()
{
2012-11-26 18:58:24 +00:00
}
/*
========================
idSessionLocalWin::LeaderboardUpload
========================
*/
void idSessionLocalWin::LeaderboardUpload( lobbyUserID_t lobbyUserID, const leaderboardDefinition_t* leaderboard, const column_t* stats, const idFile_Memory* attachment )
{
2012-11-26 18:58:24 +00:00
}
/*
========================
idSessionLocalWin::LeaderboardFlush
========================
*/
void idSessionLocalWin::LeaderboardFlush()
{
2012-11-26 18:58:24 +00:00
}
/*
========================
idSessionLocalWin::LeaderboardDownload
========================
*/
void idSessionLocalWin::LeaderboardDownload( int sessionUserIndex, const leaderboardDefinition_t* leaderboard, int startingRank, int numRows, const idLeaderboardCallback& callback )
{
2012-11-26 18:58:24 +00:00
}
/*
========================
idSessionLocalWin::LeaderboardDownloadAttachment
========================
*/
void idSessionLocalWin::LeaderboardDownloadAttachment( int sessionUserIndex, const leaderboardDefinition_t* leaderboard, int64 attachmentID )
{
2012-11-26 18:58:24 +00:00
}
/*
========================
idSessionLocalWin::EnsurePort
========================
*/
void idSessionLocalWin::EnsurePort()
{
2012-11-26 18:58:24 +00:00
// Init the port using reqular windows sockets
if( port.IsOpen() )
{
2012-11-26 18:58:24 +00:00
return; // Already initialized
}
if( port.InitPort( net_port.GetInteger(), false ) )
{
2012-11-26 18:58:24 +00:00
canJoinLocalHost = false;
}
else
{
2012-11-26 18:58:24 +00:00
// Assume this is another instantiation on the same machine, and just init using any available port
port.InitPort( PORT_ANY, false );
canJoinLocalHost = true;
}
}
/*
========================
idSessionLocalWin::GetPort
========================
*/
idNetSessionPort& idSessionLocalWin::GetPort( bool dedicated )
{
EnsurePort();
return port;
2012-11-26 18:58:24 +00:00
}
/*
========================
idSessionLocalWin::CreateLobbyBackend
========================
*/
idLobbyBackend* idSessionLocalWin::CreateLobbyBackend( const idMatchParameters& p, float skillLevel, idLobbyBackend::lobbyBackendType_t lobbyType )
{
idLobbyBackend* lobbyBackend = CreateLobbyInternal( lobbyType );
2012-11-26 18:58:24 +00:00
lobbyBackend->StartHosting( p, skillLevel, lobbyType );
return lobbyBackend;
}
/*
========================
idSessionLocalWin::FindLobbyBackend
========================
*/
idLobbyBackend* idSessionLocalWin::FindLobbyBackend( const idMatchParameters& p, int numPartyUsers, float skillLevel, idLobbyBackend::lobbyBackendType_t lobbyType )
{
idLobbyBackend* lobbyBackend = CreateLobbyInternal( lobbyType );
2012-11-26 18:58:24 +00:00
lobbyBackend->StartFinding( p, numPartyUsers, skillLevel );
return lobbyBackend;
}
/*
========================
idSessionLocalWin::JoinFromConnectInfo
========================
*/
idLobbyBackend* idSessionLocalWin::JoinFromConnectInfo( const lobbyConnectInfo_t& connectInfo, idLobbyBackend::lobbyBackendType_t lobbyType )
{
idLobbyBackend* lobbyBackend = CreateLobbyInternal( lobbyType );
2012-11-26 18:58:24 +00:00
lobbyBackend->JoinFromConnectInfo( connectInfo );
return lobbyBackend;
}
/*
========================
idSessionLocalWin::DestroyLobbyBackend
========================
*/
void idSessionLocalWin::DestroyLobbyBackend( idLobbyBackend* lobbyBackend )
{
assert( lobbyBackend != NULL );
assert( lobbyBackends[lobbyBackend->GetLobbyType()] == lobbyBackend );
2012-11-26 18:58:24 +00:00
lobbyBackends[lobbyBackend->GetLobbyType()] = NULL;
2012-11-26 18:58:24 +00:00
lobbyBackend->Shutdown();
delete lobbyBackend;
}
/*
========================
idSessionLocalWin::PumpLobbies
========================
*/
void idSessionLocalWin::PumpLobbies()
{
2012-11-26 18:58:24 +00:00
assert( lobbyBackends[idLobbyBackend::TYPE_PARTY] == NULL || lobbyBackends[idLobbyBackend::TYPE_PARTY]->GetLobbyType() == idLobbyBackend::TYPE_PARTY );
assert( lobbyBackends[idLobbyBackend::TYPE_GAME] == NULL || lobbyBackends[idLobbyBackend::TYPE_GAME]->GetLobbyType() == idLobbyBackend::TYPE_GAME );
assert( lobbyBackends[idLobbyBackend::TYPE_GAME_STATE] == NULL || lobbyBackends[idLobbyBackend::TYPE_GAME_STATE]->GetLobbyType() == idLobbyBackend::TYPE_GAME_STATE );
2012-11-26 18:58:24 +00:00
// Pump lobbyBackends
for( int i = 0; i < lobbyBackends.Num(); i++ )
{
if( lobbyBackends[i] != NULL )
{
2012-11-26 18:58:24 +00:00
lobbyBackends[i]->Pump();
}
}
}
/*
========================
idSessionLocalWin::CreateLobbyInternal
========================
*/
idLobbyBackend* idSessionLocalWin::CreateLobbyInternal( idLobbyBackend::lobbyBackendType_t lobbyType )
{
2012-11-26 18:58:24 +00:00
EnsurePort();
idLobbyBackend* lobbyBackend = new( TAG_NETWORKING ) idLobbyBackendDirect();
2012-11-26 18:58:24 +00:00
lobbyBackend->SetLobbyType( lobbyType );
2012-11-26 18:58:24 +00:00
assert( lobbyBackends[lobbyType] == NULL );
lobbyBackends[lobbyType] = lobbyBackend;
2012-11-26 18:58:24 +00:00
return lobbyBackend;
}
/*
========================
idSessionLocalWin::JoinAfterSwap
========================
*/
void idSessionLocalWin::JoinAfterSwap( void* joinID )
{
2012-11-26 18:58:24 +00:00
}
/*
========================
idSessionLocalWin::GetLobbyAddressFromNetAddress
========================
*/
bool idSessionLocalWin::GetLobbyAddressFromNetAddress( const netadr_t& netAddr, lobbyAddress_t& outAddr ) const
{
2012-11-26 18:58:24 +00:00
return false;
}
/*
========================
idSessionLocalWin::GetNetAddressFromLobbyAddress
========================
*/
bool idSessionLocalWin::GetNetAddressFromLobbyAddress( const lobbyAddress_t& lobbyAddress, netadr_t& outNetAddr ) const
{
2012-11-26 18:58:24 +00:00
return false;
}