Skip to content

lobby fix: Adding instructions when we get a service error on conflicting joins #511

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
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
4 changes: 2 additions & 2 deletions Assets/BossRoom/Scenes/Startup.unity
Git LFS file not shown
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace Unity.Multiplayer.Samples.BossRoom.Client
/// </remarks>
public class ClientMainMenuState : GameStateBehaviour
{
public const string AuthProfileCommandLineArg = "-AuthProfile";
public override GameState ActiveState { get { return GameState.MainMenu; } }

[SerializeField] GameObject[] m_GameObjectsThatWillBeInjectedAutomatically;
Expand Down Expand Up @@ -67,7 +68,7 @@ void InjectDependenciesAndInitialize(AuthenticationServiceFacade authServiceFaca
var arguments = System.Environment.GetCommandLineArgs();
for (int i = 0; i < arguments.Length; i++)
{
if (arguments[i] == "-AuthProfile")
if (arguments[i] == AuthProfileCommandLineArg)
{
var profileId = arguments[i + 1];
unityAuthenticationInitOptions.SetProfile(profileId);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using TMPro;
using Unity.Multiplayer.Samples.BossRoom.Client;
using Unity.Multiplayer.Samples.BossRoom.Shared.Infrastructure;
using Unity.Multiplayer.Samples.BossRoom.Shared.Net.UnityServices.Infrastructure;
using Unity.Multiplayer.Samples.BossRoom.Shared.Net.UnityServices.Lobbies;
using Unity.Services.Authentication;
using Unity.Services.Lobbies.Models;
Expand Down Expand Up @@ -31,7 +31,6 @@ public class LobbyUIMediator : MonoBehaviour
[Inject]
void InjectDependenciesAndInitialize(
LobbyServiceFacade lobbyServiceFacade,
IPublisher<UnityServiceErrorMessage> unityServiceErrorMessagePublisher,
LocalLobbyUser localUser,
LocalLobby localLobby,
NameGenerationData nameGenerationData,
Expand Down
47 changes: 47 additions & 0 deletions Assets/BossRoom/Scripts/Client/UI/UnityServicesUIHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using Unity.Multiplayer.Samples.BossRoom.Client;
using Unity.Multiplayer.Samples.BossRoom.Shared.Infrastructure;
using Unity.Multiplayer.Samples.BossRoom.Shared.Net.UnityServices.Infrastructure;
using Unity.Services.Lobbies;
using UnityEngine;

namespace Unity.Multiplayer.Samples.BossRoom.Visual
{
public class UnityServicesUIHandler : MonoBehaviour
{
IDisposable m_Subscriptions;

void Awake()
{
DontDestroyOnLoad(gameObject);
}

[Inject]
void Initialize(ISubscriber<UnityServiceErrorMessage> serviceError)
{
m_Subscriptions = serviceError.Subscribe(ServiceErrorHandler);
}

void ServiceErrorHandler(UnityServiceErrorMessage error)
{
var errorMessage = error.Message;
if (error.AffectedService == UnityServiceErrorMessage.Service.Lobby)
{
if ((error.OriginalException as LobbyServiceException).Reason == LobbyExceptionReason.LobbyConflict)
{
// LobbyConflict can have multiple causes. Let's add other solutions here if there's other situations that arise for this.
errorMessage += "\nSee logs for possible causes and solution.";
Debug.LogError($"Got service error {error.Message} with LobbyConflict. Possible conflict cause: Trying to play with two builds on the " +
$"same machine. Please use command line arg '{ClientMainMenuState.AuthProfileCommandLineArg} someName' to set a different auth profile.\n");
}
}

PopupPanel.ShowPopupPanel("Service error", errorMessage);
}

void OnDestroy()
{
m_Subscriptions.Dispose();
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void OnServiceException(AuthenticationException e)

var reason = $"{e.Message} ({e.InnerException?.Message})"; // Lobby error type, then HTTP error type.

m_UnityServiceErrorMessagePublisher.Publish(new UnityServiceErrorMessage("Authentication Error", reason));
m_UnityServiceErrorMessagePublisher.Publish(new UnityServiceErrorMessage("Authentication Error", reason, UnityServiceErrorMessage.Service.Authentication, e));
}

public void DoSignInAsync(Action onSigninComplete, Action onFailed, InitializationOptions initializationOptions)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
using Unity.Services.Core;

namespace Unity.Multiplayer.Samples.BossRoom.Shared.Net.UnityServices.Infrastructure
{
public struct UnityServiceErrorMessage
{
public enum Service
{
Authentication,
Lobby,
}

public string Title;
public string Message;
public UnityServiceErrorMessage(string title, string message)
public Service AffectedService;
public RequestFailedException OriginalException;

public UnityServiceErrorMessage(string title, string message, Service service, RequestFailedException originalException = null)
{
Title = title;
Message = message;
AffectedService = service;
OriginalException = originalException;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void OnServiceException(LobbyServiceException e)

var reason = $"{e.Message} ({e.InnerException?.Message})"; // Lobby error type, then HTTP error type.

m_UnityServiceErrorMessagePublisher.Publish(new UnityServiceErrorMessage("Lobby Error", reason));
m_UnityServiceErrorMessagePublisher.Publish(new UnityServiceErrorMessage("Lobby Error", reason, UnityServiceErrorMessage.Service.Lobby, e));
}

public void CreateLobbyAsync(string requesterUasId, string lobbyName, int maxPlayers, bool isPrivate, Dictionary<string, PlayerDataObject> hostUserData, Dictionary<string, DataObject> lobbyData, Action<Lobby> onComplete, Action onFailed)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ void OnSuccess(Lobby lobby)
return;
}
}
m_UnityServiceErrorMessagePub.Publish(new UnityServiceErrorMessage("Host left the lobby","Disconnecting."));
m_UnityServiceErrorMessagePub.Publish(new UnityServiceErrorMessage("Host left the lobby","Disconnecting.", UnityServiceErrorMessage.Service.Lobby));
ForceLeaveLobbyAttempt();
m_ApplicationController.QuitGame();
}
Expand Down