Skip to content

lobby fix: Removing quit when lobby detects host left. #505

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions Assets/BossRoom/Scripts/Client/UI/UIQuitPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public class UIQuitPanel : MonoBehaviour

ApplicationController m_ApplicationController;

private bool m_QuitMode = true;

[Inject]
private void InjectDependencies(ApplicationController applicationController)
{
Expand All @@ -21,14 +23,21 @@ private void InjectDependencies(ApplicationController applicationController)

void OnEnable()
{
m_QuitButtonText.text = NetworkManager.Singleton != null && NetworkManager.Singleton.IsListening ?
"Leave session?" :
"Exit Game?";
m_QuitMode = NetworkManager.Singleton == null || !NetworkManager.Singleton.IsListening;
m_QuitButtonText.text = m_QuitMode ? "Exit Game?" : "Leave session?";
}

public void Quit()
{
m_ApplicationController.QuitGame();
if (m_QuitMode)
{
m_ApplicationController.QuitGame();
}
else
{
m_ApplicationController.LeaveSession();
}

gameObject.SetActive(false);
}
}
Expand Down
32 changes: 17 additions & 15 deletions Assets/BossRoom/Scripts/Shared/ApplicationController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,24 +93,26 @@ private bool OnWantToQuit()
return canQuit;
}

public void QuitGame()
public void LeaveSession()
{
if (NetworkManager.Singleton.IsListening)
{
m_LobbyServiceFacade.ForceLeaveLobbyAttempt();

// first disconnect then return to menu
var gameNetPortal = GameNetPortal.Instance;
if (gameNetPortal != null)
{
gameNetPortal.RequestDisconnect();
}
SceneManager.LoadScene("MainMenu");
}
else
m_LobbyServiceFacade.ForceLeaveLobbyAttempt();

// first disconnect then return to menu
var gameNetPortal = GameNetPortal.Instance;
if (gameNetPortal != null)
{
Application.Quit();
gameNetPortal.RequestDisconnect();
}
SceneManager.LoadScene("MainMenu");
}

public void QuitGame()
{
#if UNITY_EDITOR
UnityEditor.EditorApplication.isPlaying = false;
#else
Application.Quit();
#endif
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ void OnSuccess(Lobby lobby)
CurrentUnityLobby = lobby;
m_LocalLobby.ApplyRemoteData(lobby);

// as client, check if host is still in lobby
if (!m_LocalUser.IsHost)
{
foreach (var lobbyUser in m_LocalLobby.LobbyUsers)
Expand All @@ -126,7 +127,7 @@ void OnSuccess(Lobby lobby)
}
m_UnityServiceErrorMessagePub.Publish(new UnityServiceErrorMessage("Host left the lobby","Disconnecting."));
ForceLeaveLobbyAttempt();
m_ApplicationController.QuitGame();
// no need to disconnect Netcode, it should already be handled by Netcode's callback to disconnect
}
}
}
Expand Down