Skip to content

Commit 87e20e2

Browse files
authored
feat: authentication failure message popups will tell the user to try direct ip connection option (#547)
* Moved service error popup logic to dedicated class * better error message handling for authentication errors showing the error message along with a tip - the user can always use direct ip option to connect * using a more general type of exception due to the fact that auth service can emit exceptions of multiple types - to avoid missing a handler
1 parent 46e2cef commit 87e20e2

File tree

5 files changed

+27
-16
lines changed

5 files changed

+27
-16
lines changed

Assets/BossRoom/Scripts/Client/Game/State/ClientMainMenuState.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using BossRoom.Scripts.Shared.Net.UnityServices.Auth;
2+
using Unity.Multiplayer.Samples.BossRoom.Shared;
23
using Unity.Multiplayer.Samples.BossRoom.Shared.Infrastructure;
34
using Unity.Multiplayer.Samples.BossRoom.Shared.Net.UnityServices.Lobbies;
45
using Unity.Multiplayer.Samples.BossRoom.Visual;
@@ -77,7 +78,6 @@ void OnAuthSignIn()
7778
void OnSignInFailed()
7879
{
7980
m_SignInSpinner.SetActive(false);
80-
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.");
8181
}
8282
}
8383

Assets/BossRoom/Scripts/Client/UI/UnityServicesUIHandler.cs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using System;
2-
using Unity.Multiplayer.Samples.BossRoom.Client;
2+
using Unity.Multiplayer.Samples.BossRoom.Shared;
33
using Unity.Multiplayer.Samples.BossRoom.Shared.Infrastructure;
44
using Unity.Multiplayer.Samples.BossRoom.Shared.Net.UnityServices.Infrastructure;
55
using Unity.Services.Lobbies;
@@ -25,21 +25,33 @@ void Initialize(ISubscriber<UnityServiceErrorMessage> serviceError)
2525
void ServiceErrorHandler(UnityServiceErrorMessage error)
2626
{
2727
var errorMessage = error.Message;
28-
if (error.AffectedService == UnityServiceErrorMessage.Service.Lobby)
28+
switch (error.AffectedService)
2929
{
30-
if (error.OriginalException is LobbyServiceException lobbyServiceException)
30+
case UnityServiceErrorMessage.Service.Lobby:
3131
{
32-
if (lobbyServiceException.Reason == LobbyExceptionReason.LobbyConflict)
32+
if ((error.OriginalException is LobbyServiceException {Reason: LobbyExceptionReason.LobbyConflict}))
3333
{
3434
// LobbyConflict can have multiple causes. Let's add other solutions here if there's other situations that arise for this.
3535
errorMessage += "\nSee logs for possible causes and solution.";
3636
Debug.LogError($"Got service error {error.Message} with LobbyConflict. Possible conflict cause: Trying to play with two builds on the " +
37-
$"same machine. Please use command line arg '{ProfileManager.AuthProfileCommandLineArg} someName' to set a different auth profile.\n");
37+
$"same machine. Please use command line arg '{ProfileManager.AuthProfileCommandLineArg} someName' to set a different auth profile.\n");
3838
}
39+
PopupPanel.ShowPopupPanel("Service error", errorMessage);
40+
break;
41+
}
42+
case UnityServiceErrorMessage.Service.Authentication:
43+
{
44+
PopupPanel.ShowPopupPanel(
45+
"Authentication Error",
46+
$"{error.OriginalException.Message} \n tip: You can still use the Direct IP connection option.");
47+
break;
48+
}
49+
default:
50+
{
51+
PopupPanel.ShowPopupPanel("Service error", errorMessage);
52+
break;
3953
}
4054
}
41-
42-
PopupPanel.ShowPopupPanel("Service error", errorMessage);
4355
}
4456

4557
void OnDestroy()

Assets/BossRoom/Scripts/Shared/Net/ConnectionManagement/GameNetPortal.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using Unity.Multiplayer.Samples.BossRoom.Client;
33
using Unity.Multiplayer.Samples.BossRoom.Server;
4+
using Unity.Multiplayer.Samples.BossRoom.Shared;
45
using Unity.Multiplayer.Samples.BossRoom.Shared.Infrastructure;
56
using Unity.Multiplayer.Samples.BossRoom.Shared.Net.UnityServices.Lobbies;
67
using Unity.Netcode;

Assets/BossRoom/Scripts/Shared/Net/UnityServices/Auth/AuthenticationServiceFacade.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,17 @@ void InjectDependencies(IPublisher<UnityServiceErrorMessage> unityServiceErrorMe
1818
m_UnityServiceErrorMessagePublisher = unityServiceErrorMessagePublisher;
1919
}
2020

21-
void OnServiceException(AuthenticationException e)
21+
void OnServiceException(Exception e)
2222
{
2323
Debug.LogWarning(e.Message);
24-
25-
var reason = $"{e.Message} ({e.InnerException?.Message})"; // Lobby error type, then HTTP error type.
26-
24+
var reason = $"{e.Message} ({e.InnerException?.Message})";
2725
m_UnityServiceErrorMessagePublisher.Publish(new UnityServiceErrorMessage("Authentication Error", reason, UnityServiceErrorMessage.Service.Authentication, e));
2826
}
2927

3028
public void DoSignInAsync(Action onSigninComplete, Action onFailed, InitializationOptions initializationOptions)
3129
{
3230
var task = TrySignIn(initializationOptions);
33-
UnityServiceCallsTaskWrapper.RunTask<AuthenticationException>(task, onSigninComplete, onFailed, OnServiceException);
31+
UnityServiceCallsTaskWrapper.RunTask<Exception>(task, onSigninComplete, onFailed, OnServiceException);
3432
}
3533

3634
async Task TrySignIn(InitializationOptions initializationOptions)

Assets/BossRoom/Scripts/Shared/Net/UnityServices/Infrastructure/Messages/UnityServiceErrorMessage.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Unity.Services.Core;
1+
using System;
22

33
namespace Unity.Multiplayer.Samples.BossRoom.Shared.Net.UnityServices.Infrastructure
44
{
@@ -13,9 +13,9 @@ public enum Service
1313
public string Title;
1414
public string Message;
1515
public Service AffectedService;
16-
public RequestFailedException OriginalException;
16+
public Exception OriginalException;
1717

18-
public UnityServiceErrorMessage(string title, string message, Service service, RequestFailedException originalException = null)
18+
public UnityServiceErrorMessage(string title, string message, Service service, Exception originalException = null)
1919
{
2020
Title = title;
2121
Message = message;

0 commit comments

Comments
 (0)