Пример #1
0
//-------------------------------------------------------------------------
void CGameLobbyManager::LeaveGameSession(ELeavingSessionReason reason)
{
	CryLog("CGameLobbyManager::LeaveGameSession() reason=%i multiplayer %d", (int) reason, gEnv->bMultiplayer);
	// Tell the game lobby that we want to quit
	// Note: If we're leaving in a group (because the squad is quitting) then we need to do special behaviour:
	//					If we're the squad session host then we need to tell the rest of the squad to quit
	//					If we're the game session host then the rest of the squad has to quit before we do

	if(gEnv->bMultiplayer || reason == eLSR_SwitchGameType)
	{
		if (IsLobbyMerging())
		{
			CancelMoveSession(m_primaryLobby);
		}

		bool canLeaveNow = true;
		CSquadManager *pSquadManager = g_pGame->GetSquadManager();

		ELobbyState lobbyState = m_primaryLobby->GetState();
		if (lobbyState != eLS_Game)
		{
			// If we're in a squad and we're the game session host then we need to be careful about leaving
			if (pSquadManager != NULL && pSquadManager->HaveSquadMates())
			{
				if (reason == eLSR_Menu)
				{
					// User requested quit
					//	- If we're not the squad session host then we're the only person leaving so we can do it straight away
					//	- If we're not the game session host then there are no ordering issues so again, we can just leave
					if (pSquadManager->InCharge())
					{
						if (m_primaryLobby->IsServer())
						{
							CryLog("  we're trying to leave but we're the squad and game host, need to leave last");
							pSquadManager->TellMembersToLeaveGameSession();
							canLeaveNow = false;
						}
						else
						{
							CryLog("  we're not the game host, can leave now");
							pSquadManager->TellMembersToLeaveGameSession();
						}
					}
				}
				else if (reason == eLSR_ReceivedSquadLeavingFromSquadHost)
				{
					// Squad leader requested quit
					if (m_primaryLobby->IsServer())
					{
						canLeaveNow = false;
					}
				}
				else if (reason == eLSR_ReceivedSquadLeavingFromGameHost)
				{
					pSquadManager->TellMembersToLeaveGameSession();
				}
			}
		}
		else
		{
			CryLog("  leaving a game that is not in the lobby state, tell the squad manager");
			pSquadManager->LeftGameSessionInProgress();
		}

		if (canLeaveNow)
		{
			m_primaryLobby->LeaveSession(true);
		}
		else
		{
			m_primaryLobby->LeaveAfterSquadMembers();
		}
	}
}