Skip to content

feat: authentication failure message popups will tell the user to try direct ip connection option #547

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 4 commits into from
Mar 14, 2022
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using BossRoom.Scripts.Shared.Net.UnityServices.Auth;
using Unity.Multiplayer.Samples.BossRoom.Shared;
using Unity.Multiplayer.Samples.BossRoom.Shared.Infrastructure;
using Unity.Multiplayer.Samples.BossRoom.Shared.Net.UnityServices.Lobbies;
using Unity.Multiplayer.Samples.BossRoom.Visual;
Expand Down Expand Up @@ -77,7 +78,6 @@ void OnAuthSignIn()
void OnSignInFailed()
{
m_SignInSpinner.SetActive(false);
PopupPanel.ShowPopupPanel("Authentication Error", "For some reason we can't authenticate the user anonymously - that typically means that project is not properly set up with Unity services.");
}
}

Expand Down
26 changes: 19 additions & 7 deletions Assets/BossRoom/Scripts/Client/UI/UnityServicesUIHandler.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
using Unity.Multiplayer.Samples.BossRoom.Client;
using Unity.Multiplayer.Samples.BossRoom.Shared;
using Unity.Multiplayer.Samples.BossRoom.Shared.Infrastructure;
using Unity.Multiplayer.Samples.BossRoom.Shared.Net.UnityServices.Infrastructure;
using Unity.Services.Lobbies;
Expand All @@ -25,21 +25,33 @@ void Initialize(ISubscriber<UnityServiceErrorMessage> serviceError)
void ServiceErrorHandler(UnityServiceErrorMessage error)
{
var errorMessage = error.Message;
if (error.AffectedService == UnityServiceErrorMessage.Service.Lobby)
switch (error.AffectedService)
{
if (error.OriginalException is LobbyServiceException lobbyServiceException)
case UnityServiceErrorMessage.Service.Lobby:
{
if (lobbyServiceException.Reason == LobbyExceptionReason.LobbyConflict)
if ((error.OriginalException is 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 '{ProfileManager.AuthProfileCommandLineArg} someName' to set a different auth profile.\n");
$"same machine. Please use command line arg '{ProfileManager.AuthProfileCommandLineArg} someName' to set a different auth profile.\n");
}
PopupPanel.ShowPopupPanel("Service error", errorMessage);
break;
}
case UnityServiceErrorMessage.Service.Authentication:
{
PopupPanel.ShowPopupPanel(
"Authentication Error",
$"{error.OriginalException.Message} \n tip: You can still use the Direct IP connection option.");
break;
}
default:
{
PopupPanel.ShowPopupPanel("Service error", errorMessage);
break;
}
}

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

void OnDestroy()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using Unity.Multiplayer.Samples.BossRoom.Client;
using Unity.Multiplayer.Samples.BossRoom.Server;
using Unity.Multiplayer.Samples.BossRoom.Shared;
using Unity.Multiplayer.Samples.BossRoom.Shared.Infrastructure;
using Unity.Multiplayer.Samples.BossRoom.Shared.Net.UnityServices.Lobbies;
using Unity.Netcode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,17 @@ void InjectDependencies(IPublisher<UnityServiceErrorMessage> unityServiceErrorMe
m_UnityServiceErrorMessagePublisher = unityServiceErrorMessagePublisher;
}

void OnServiceException(AuthenticationException e)
void OnServiceException(Exception e)
{
Debug.LogWarning(e.Message);

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

var reason = $"{e.Message} ({e.InnerException?.Message})";
m_UnityServiceErrorMessagePublisher.Publish(new UnityServiceErrorMessage("Authentication Error", reason, UnityServiceErrorMessage.Service.Authentication, e));
}

public void DoSignInAsync(Action onSigninComplete, Action onFailed, InitializationOptions initializationOptions)
{
var task = TrySignIn(initializationOptions);
UnityServiceCallsTaskWrapper.RunTask<AuthenticationException>(task, onSigninComplete, onFailed, OnServiceException);
UnityServiceCallsTaskWrapper.RunTask<Exception>(task, onSigninComplete, onFailed, OnServiceException);
}

async Task TrySignIn(InitializationOptions initializationOptions)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Unity.Services.Core;
using System;

namespace Unity.Multiplayer.Samples.BossRoom.Shared.Net.UnityServices.Infrastructure
{
Expand All @@ -13,9 +13,9 @@ public enum Service
public string Title;
public string Message;
public Service AffectedService;
public RequestFailedException OriginalException;
public Exception OriginalException;

public UnityServiceErrorMessage(string title, string message, Service service, RequestFailedException originalException = null)
public UnityServiceErrorMessage(string title, string message, Service service, Exception originalException = null)
{
Title = title;
Message = message;
Expand Down