//-------------------------------------------------------------------------
int CCryLobbySessionHandler::EndSession()
{
	if (IPlayerProfileManager *pPlayerProfileManager = g_pGame->GetIGameFramework()->GetIPlayerProfileManager())
	{
#if defined(XENON) || defined(PS3)
		pPlayerProfileManager->SetCanProcessOnlineAttributes(true);
#endif

		CPlayerProgression *pPlayerProgression = CPlayerProgression::GetInstance();
		if (pPlayerProgression)
		{
			pPlayerProgression->OnEndSession();
		}

		CGameLobbyManager *pLobbyManager = g_pGame->GetGameLobbyManager();
		if (pLobbyManager)
		{
			const unsigned int controllerIndex = pPlayerProfileManager->GetExclusiveControllerDeviceIndex();
			if (pLobbyManager->GetOnlineState(controllerIndex) == eOS_SignedIn)
			{
				CryLog("CCryLobbySessionHandler::EndSession() saving profile");
				//Quitting the session from in game
				g_pGame->GetProfileOptions()->SaveProfile(ePR_All);
			}
			else
			{
				CryLog("CCryLobbySessionHandler::EndSession() not saving as we're signed out");
			}
		}
	}

	return (int) eCLE_Success;
}
//-------------------------------------------------------------------------
void CCryLobbySessionHandler::LeaveSession()
{
	CGameLobbyManager* pGameLobbyManager = g_pGame->GetGameLobbyManager();
	if (pGameLobbyManager)
	{
		pGameLobbyManager->LeaveGameSession(CGameLobbyManager::eLSR_Menu);
	}
}
CGameAchievements::~CGameAchievements()
{
	CGameLobbyManager *pGameLobbyManager = g_pGame->GetGameLobbyManager();
	if(pGameLobbyManager)
	{
		pGameLobbyManager->RemovePrivateGameListener(this);
	}

	g_pGame->GetIGameFramework()->UnregisterListener(this);
	RemoveHUDEventListeners();
}
//-------------------------------------------------------------------------
bool CCryLobbySessionHandler::IsMultiplayer() const
{
	bool result = false;

	CGameLobbyManager *pLobbyManager = g_pGame->GetGameLobbyManager();
	if (pLobbyManager)
	{
		result = pLobbyManager->IsMultiplayer();
	}

	return result;
}
Esempio n. 5
0
void CUILobbyMP::SetMultiplayer( bool bIsMultiplayer )
{
	CGameLobbyManager *pGameLobbyMgr = g_pGame->GetGameLobbyManager();
	CSquadManager *pSquadMgr = g_pGame->GetSquadManager();

	if(pGameLobbyMgr)
	{
		pGameLobbyMgr->SetMultiplayer(bIsMultiplayer);
	}

	if(pSquadMgr)
	{
		pSquadMgr->SetMultiplayer(bIsMultiplayer);
	}

	gEnv->bMultiplayer = bIsMultiplayer;
}
CGameAchievements::CGameAchievements()
: m_lastPlayerThrownObject(0)
, m_lastPlayerKillBulletId(0)
, m_lastPlayerKillGrenadeId(0)
, m_killsWithOneGrenade(0)
, m_allowAchievements(true)
{
	m_lastPlayerKillBulletId = 0;
	g_pGame->GetIGameFramework()->RegisterListener(this, "CGameAchievements", FRAMEWORKLISTENERPRIORITY_GAME);

	CGameLobbyManager *pGameLobbyManager = g_pGame->GetGameLobbyManager();
	CRY_ASSERT(pGameLobbyManager || gEnv->IsEditor());
	if(pGameLobbyManager)
	{
		pGameLobbyManager->AddPrivateGameListener(this);
	}
}
Esempio n. 7
0
CGameAchievements::CGameAchievements()
: m_lastPlayerThrownObject(0)
, m_lastPlayerKillBulletId(0)
, m_lastPlayerKillGrenadeId(0)
, m_killsWithOneGrenade(0)
, m_HMGHitType(-1)
, m_gaussBulletHitType(-1)
, m_allowAchievements(true)
{
	m_lastPlayerKillBulletId = 0;
	g_pGame->GetIGameFramework()->RegisterListener(this, "CGameAchievements", eFLPriority_Game);

	CGameLobbyManager *pGameLobbyManager = g_pGame->GetGameLobbyManager();
	CRY_ASSERT(pGameLobbyManager || gEnv->IsEditor());
	if(pGameLobbyManager)
	{
		pGameLobbyManager->AddPrivateGameListener(this);
	}
}
Esempio n. 8
0
void CUILobbyMP::JoinGame(int sessionID)
{
	bool result = false;

	CGameLobby *pGameLobby = g_pGame->GetGameLobby();
	CGameLobbyManager *pGameLobbyMgr = g_pGame->GetGameLobbyManager();
	CSquadManager *pSquadMgr = g_pGame->GetSquadManager();

	if(pGameLobbyMgr)
	{
		pGameLobbyMgr->SetMultiplayer(true);
	}

	if(pSquadMgr)
	{
		pSquadMgr->SetMultiplayer(true);
	}

	if(pGameLobby && m_FoundServers.size() > sessionID)
		result = pGameLobby->JoinServer(m_FoundServers[sessionID].m_id, m_FoundServers[sessionID].m_data.m_name, CryMatchMakingInvalidConnectionUID, false);
	return;
}
Esempio n. 9
0
//Handles online state changes - when you sign out it returns you
void CGameLobbyManager::OnlineCallback(UCryLobbyEventData eventData, void *arg)
{
	if (g_pGameCVars->g_ProcessOnlineCallbacks == 0)
		return;

	if(eventData.pOnlineStateData)
	{
		CGameLobbyManager *pLobbyManager = static_cast<CGameLobbyManager*>(arg);
		CRY_ASSERT(eventData.pOnlineStateData->m_user < MAX_LOCAL_USERS);
		pLobbyManager->m_onlineState[eventData.pOnlineStateData->m_user] = eventData.pOnlineStateData->m_curState;

		IPlayerProfileManager *pPlayerProfileManager = gEnv->pGame->GetIGameFramework()->GetIPlayerProfileManager();
		uint32 userIndex = pPlayerProfileManager ? pPlayerProfileManager->GetExclusiveControllerDeviceIndex() : 0;

#ifndef _RELEASE
		const char *pEventType = "eOS_Unknown";
		if (eventData.pOnlineStateData->m_curState == eOS_SignedOut)
		{
			pEventType = "eOS_SignedOut";
		}
		else if (eventData.pOnlineStateData->m_curState == eOS_SigningIn)
		{
			pEventType = "eOS_SigningIn";
		}
		else if (eventData.pOnlineStateData->m_curState == eOS_SignedIn)
		{
			pEventType = "eOS_SignedIn";
		}
		CryLog("[GameLobbyManager] OnlineCallback: eventType=%s, user=%u, currentUser=%u", pEventType, eventData.pOnlineStateData->m_user, userIndex);

		ICryLobby *pLobby = gEnv->pNetwork->GetLobby();
		if (g_pGameCVars->autotest_enabled && pLobby != NULL && (pLobby->GetLobbyServiceType() == eCLS_LAN))
		{
			// Don't care about signing out if we're in the autotester and in LAN mode
			return;
		}
#endif




		{
			EOnlineState onlineState = eventData.pOnlineStateData->m_curState;
			if(onlineState == eOS_SignedOut)
			{
				if(eventData.pOnlineStateData->m_reason != eCLE_CyclingForInvite)
				{
#ifdef USE_C2_FRONTEND
					CFlashFrontEnd *pFlashFrontEnd = g_pGame->GetFlashMenu();
					CMPMenuHub *pMPMenuHub = pFlashFrontEnd ? pFlashFrontEnd->GetMPMenu() : NULL;

					if(pMPMenuHub)
					{
#if INCLUDE_DEDICATED_LEADERBOARDS
						pFlashFrontEnd->ClearDelaySessionLeave();
#endif
						pMPMenuHub->OnlineStateChanged(eventData.pOnlineStateData->m_curState, eventData.pOnlineStateData->m_reason, eventData.pOnlineStateData->m_serviceConnected);
					}
#endif //#ifdef USE_C2_FRONTEND

#if !defined(XENON) && !defined(PS3)
					IPlayerProfileManager *pPPM = gEnv->pGame->GetIGameFramework()->GetIPlayerProfileManager();
					if(pPPM)
					{
						pPPM->ClearOnlineAttributes();
					}
#endif

#ifdef GAME_IS_CRYSIS2
					CWarningsManager *pWM = g_pGame->GetWarnings();
					if(pWM)
					{
						pWM->RemoveWarning("ChatRestricted");
					}
#endif
				}

				pLobbyManager->LeaveGameSession(eLSR_SignedOut);
			}					
		}
	}
}
Esempio n. 10
0
//Handles online state changes - when you sign out it returns you
void CGameLobbyManager::OnlineCallback(UCryLobbyEventData eventData, void *arg)
{
	if (g_pGameCVars->g_ProcessOnlineCallbacks == 0)
		return;

	if(eventData.pOnlineStateData)
	{
		CGameLobbyManager *pLobbyManager = static_cast<CGameLobbyManager*>(arg);

#if defined(DEDICATED_SERVER)
		EOnlineState previousState = pLobbyManager->m_onlineState[eventData.pOnlineStateData->m_user];
#endif

		CRY_ASSERT(eventData.pOnlineStateData->m_user < MAX_LOCAL_USERS);
		pLobbyManager->m_onlineState[eventData.pOnlineStateData->m_user] = eventData.pOnlineStateData->m_curState;

		uint32 userIndex = g_pGame->GetExclusiveControllerDeviceIndex();

		ICryLobby *pLobby = FakeGetLobby();

#ifndef _RELEASE
		const char *pEventType = "eOS_Unknown";
		if (eventData.pOnlineStateData->m_curState == eOS_SignedOut)
		{
			pEventType = "eOS_SignedOut";
		}
		else if (eventData.pOnlineStateData->m_curState == eOS_SigningIn)
		{
			pEventType = "eOS_SigningIn";
		}
		else if (eventData.pOnlineStateData->m_curState == eOS_SignedIn)
		{
			pEventType = "eOS_SignedIn";
		}
		CryLog("[GameLobbyManager] OnlineCallback: eventType=%s, user=%u, currentUser=%u", pEventType, eventData.pOnlineStateData->m_user, userIndex);

		if (g_pGameCVars->autotest_enabled && pLobby != NULL && (pLobby->GetLobbyServiceType() == eCLS_LAN))
		{
			// Don't care about signing out if we're in the autotester and in LAN mode
			return;
		}
#endif

		{
			EOnlineState onlineState = eventData.pOnlineStateData->m_curState;
			if(onlineState == eOS_SignedOut)
			{
				if(pLobby && pLobby->GetLobbyServiceType() == eCLS_Online)
				{
					if(eventData.pOnlineStateData->m_reason != eCLE_CyclingForInvite)
					{
						CErrorHandling *pErrorHandling = CErrorHandling::GetInstance();
						if (pErrorHandling)
						{
							pErrorHandling->OnFatalError(CErrorHandling::eFE_PlatformServiceSignedOut);
						}
						else
						{
							pLobbyManager->LeaveGameSession(eLSR_SignedOut);
						}

						IPlayerProfileManager *pPPM = g_pGame->GetIGameFramework()->GetIPlayerProfileManager();
						if(pPPM)
						{
							pPPM->ClearOnlineAttributes();
						}

#if 0 // old frontend
						CWarningsManager *pWM = g_pGame->GetWarnings();
						if(pWM)
						{
							pWM->RemoveWarning("ChatRestricted");
						}
#endif 
					}


#if defined(DEDICATED_SERVER)
					if (previousState != eOS_SignedOut)
					{
						CryLogAlways("We've been signed out, reason=%u, bailing", eventData.pOnlineStateData->m_reason);
						gEnv->pConsole->ExecuteString("quit", false, true);
					}
#endif
				}
			}					
		}
	}
}
//------------------------------------------------------------------------
void CMatchMakingHandler::OnSearchResult( SCrySessionSearchResult* pSession )
{
	//session will expire at the end of the callback
	//so copy it into a results structure (we need lots of details to pass to the matchmaking part
	//store it in a map (indexed via sessionID?)
	//pass the index to the lua


	CGameLobbyManager* pLobbyManager = g_pGame->GetGameLobbyManager();
	if( pLobbyManager )
	{
		CGameLobby* pLobby = pLobbyManager->GetGameLobby();
		
		//first check if this result refers to a lobby we're in/hosting
		if( pLobby->IsCurrentSessionId( pSession->m_id ) )
		{
			//this is the session for the lobby we are in, early out
			return;
		}
		//also check secondary lobby
		if( CGameLobby* pSecondaryLobby = pLobbyManager->GetNextGameLobby() )	
		{
			if( ( pSecondaryLobby->IsCurrentSessionId( pSession->m_id ) ) )
			{
				//this is the session for the lobby we are going to, early out
				return;
			}
		}
		
		const CGameLobby::EActiveStatus activeStatus = (CGameLobby::EActiveStatus) GameLobbyData::GetSearchResultsData( pSession, LID_MATCHDATA_ACTIVE );
		bool bIsBadServer = pLobby->IsBadServer( pSession->m_id );
		const int skillRank = pLobby->CalculateAverageSkill();
		const int sessionSkillRank = GameLobbyData::GetSearchResultsData( pSession, LID_MATCHDATA_SKILL );
		const int sessionLanguageId = GameLobbyData::GetSearchResultsData( pSession, LID_MATCHDATA_LANGUAGE );

		float sessionScore = LegacyC2MatchMakingScore( pSession, pLobby, false );

		int32 region = 0;
#if GAMELOBBY_USE_COUNTRY_FILTERING
		region = GameLobbyData::GetSearchResultsData( pSession, LID_MATCHDATA_COUNTRY );
#endif //GAMELOBBY_USE_COUNTRY_FILTERING

#if defined(TRACK_MATCHMAKING)
		if( CMatchmakingTelemetry* pMMTel = g_pGame->GetMatchMakingTelemetry() )
		{
			pMMTel->AddEvent( SMMFoundSessionEvent( pSession, activeStatus, skillRank - sessionSkillRank, region, sessionLanguageId, bIsBadServer, sessionScore ) );
		}
#endif //defined(TRACK_MATCHMAKING)

		HSCRIPTFUNCTION scriptFunction;

		if( m_pScript->GetValue( "OnSearchResult", scriptFunction ) )  
		{
			//Make a table to hold the search result
			SmartScriptTable result( gEnv->pScriptSystem );

			SessionDetails newSession;
			newSession.m_id = pSession->m_id;
			cry_strcpy( newSession.m_name, pSession->m_data.m_name );

			//capture the session ID in a map
			std::pair< TSessionIdMap::iterator, bool > insertResult = m_sessionIdMap.insert( std::make_pair( m_sessionIdIndex++, newSession ) );

			if( insertResult.second )
			{
				CryLog( "MMLua: Adding a server with parameters ping %d, status %d, avSkill %d", pSession->m_ping, activeStatus, sessionSkillRank );

				result->SetValue( "SessionId", insertResult.first->first );
				result->SetValue( "SearchId", s_currentMMSearchID );

				float timeSinceStarted = gEnv->pTimer->GetFrameStartTime().GetSeconds() - m_startTime;
				result->SetValue( "TimeFound", timeSinceStarted );
				
				//make a sub table to hold all the known session parameters	
				SmartScriptTable parameters( gEnv->pScriptSystem );
				result->SetValue( "Parameters", parameters );

				parameters->SetValue( "ActiveStatus", activeStatus );
				parameters->SetValue( "ServerAvSkill", sessionSkillRank );
				parameters->SetValue( "Region", region );
				parameters->SetValue( "Language", sessionLanguageId );
				parameters->SetValue( "BadServer", bIsBadServer );
				parameters->SetValue( "Ping", pSession->m_ping );
				parameters->SetValue( "FilledSlots", pSession->m_numFilledSlots );

				Script::Call( gEnv->pScriptSystem, scriptFunction, m_pScript, result );
				gEnv->pScriptSystem->ReleaseFunc( scriptFunction );
			}
		}
	}
}