Skip to content

Commit 4818892

Browse files
committed
cherry pick of lobby fix: Adding instructions when we get a service error on conflicting joins (#511)
1 parent cee7c1a commit 4818892

File tree

9 files changed

+80
-9
lines changed

9 files changed

+80
-9
lines changed

Assets/BossRoom/Scenes/Startup.unity

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:7b2c33d4681d53ec62b32b7ff2c81123b4457d8dcd8d0b6d643097e74ae36856
3-
size 35006
2+
oid sha256:22939a0b19a2e47d1c43cf76d229f2a99bcc8511f03020367645a163b6ab2fba
3+
size 35402

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ namespace Unity.Multiplayer.Samples.BossRoom.Client
2121
/// </remarks>
2222
public class ClientMainMenuState : GameStateBehaviour
2323
{
24+
public const string AuthProfileCommandLineArg = "-AuthProfile";
2425
public override GameState ActiveState { get { return GameState.MainMenu; } }
2526

2627
[SerializeField] GameObject[] m_GameObjectsThatWillBeInjectedAutomatically;
@@ -67,7 +68,7 @@ void InjectDependenciesAndInitialize(AuthenticationServiceFacade authServiceFaca
6768
var arguments = System.Environment.GetCommandLineArgs();
6869
for (int i = 0; i < arguments.Length; i++)
6970
{
70-
if (arguments[i] == "-AuthProfile")
71+
if (arguments[i] == AuthProfileCommandLineArg)
7172
{
7273
var profileId = arguments[i + 1];
7374
unityAuthenticationInitOptions.SetProfile(profileId);

Assets/BossRoom/Scripts/Client/UI/Lobby/LobbyUIMediator.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
using System;
12
using TMPro;
23
using Unity.Multiplayer.Samples.BossRoom.Client;
34
using Unity.Multiplayer.Samples.BossRoom.Shared.Infrastructure;
4-
using Unity.Multiplayer.Samples.BossRoom.Shared.Net.UnityServices.Infrastructure;
55
using Unity.Multiplayer.Samples.BossRoom.Shared.Net.UnityServices.Lobbies;
66
using Unity.Services.Authentication;
77
using Unity.Services.Lobbies.Models;
@@ -33,7 +33,6 @@ public class LobbyUIMediator : MonoBehaviour
3333
[Inject]
3434
void InjectDependenciesAndInitialize(
3535
LobbyServiceFacade lobbyServiceFacade,
36-
IPublisher<UnityServiceErrorMessage> unityServiceErrorMessagePublisher,
3736
LocalLobbyUser localUser,
3837
LocalLobby localLobby,
3938
NameGenerationData nameGenerationData,
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using System;
2+
using Unity.Multiplayer.Samples.BossRoom.Client;
3+
using Unity.Multiplayer.Samples.BossRoom.Shared.Infrastructure;
4+
using Unity.Multiplayer.Samples.BossRoom.Shared.Net.UnityServices.Infrastructure;
5+
using Unity.Services.Lobbies;
6+
using UnityEngine;
7+
8+
namespace Unity.Multiplayer.Samples.BossRoom.Visual
9+
{
10+
public class UnityServicesUIHandler : MonoBehaviour
11+
{
12+
IDisposable m_Subscriptions;
13+
14+
void Awake()
15+
{
16+
DontDestroyOnLoad(gameObject);
17+
}
18+
19+
[Inject]
20+
void Initialize(ISubscriber<UnityServiceErrorMessage> serviceError)
21+
{
22+
m_Subscriptions = serviceError.Subscribe(ServiceErrorHandler);
23+
}
24+
25+
void ServiceErrorHandler(UnityServiceErrorMessage error)
26+
{
27+
var errorMessage = error.Message;
28+
if (error.AffectedService == UnityServiceErrorMessage.Service.Lobby)
29+
{
30+
if ((error.OriginalException as LobbyServiceException).Reason == LobbyExceptionReason.LobbyConflict)
31+
{
32+
// LobbyConflict can have multiple causes. Let's add other solutions here if there's other situations that arise for this.
33+
errorMessage += "\nSee logs for possible causes and solution.";
34+
Debug.LogError($"Got service error {error.Message} with LobbyConflict. Possible conflict cause: Trying to play with two builds on the " +
35+
$"same machine. Please use command line arg '{ClientMainMenuState.AuthProfileCommandLineArg} someName' to set a different auth profile.\n");
36+
}
37+
}
38+
39+
PopupPanel.ShowPopupPanel("Service error", errorMessage);
40+
}
41+
42+
void OnDestroy()
43+
{
44+
m_Subscriptions.Dispose();
45+
}
46+
}
47+
}

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

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ void OnServiceException(AuthenticationException e)
2424

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

27-
m_UnityServiceErrorMessagePublisher.Publish(new UnityServiceErrorMessage("Authentication Error", reason));
27+
m_UnityServiceErrorMessagePublisher.Publish(new UnityServiceErrorMessage("Authentication Error", reason, UnityServiceErrorMessage.Service.Authentication, e));
2828
}
2929

3030
public void DoSignInAsync(Action onSigninComplete, Action onFailed, InitializationOptions initializationOptions)
Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,26 @@
1+
using Unity.Services.Core;
2+
13
namespace Unity.Multiplayer.Samples.BossRoom.Shared.Net.UnityServices.Infrastructure
24
{
35
public struct UnityServiceErrorMessage
46
{
7+
public enum Service
8+
{
9+
Authentication,
10+
Lobby,
11+
}
12+
513
public string Title;
614
public string Message;
7-
public UnityServiceErrorMessage(string title, string message)
15+
public Service AffectedService;
16+
public RequestFailedException OriginalException;
17+
18+
public UnityServiceErrorMessage(string title, string message, Service service, RequestFailedException originalException = null)
819
{
920
Title = title;
1021
Message = message;
22+
AffectedService = service;
23+
OriginalException = originalException;
1124
}
1225
}
1326
}

Assets/BossRoom/Scripts/Shared/Net/UnityServices/Lobbies/LobbyAPIInterface.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ void OnServiceException(LobbyServiceException e)
6666

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

69-
m_UnityServiceErrorMessagePublisher.Publish(new UnityServiceErrorMessage("Lobby Error", reason));
69+
m_UnityServiceErrorMessagePublisher.Publish(new UnityServiceErrorMessage("Lobby Error", reason, UnityServiceErrorMessage.Service.Lobby, e));
7070
}
7171

7272
public void CreateLobbyAsync(string requesterUasId, string lobbyName, int maxPlayers, bool isPrivate, Dictionary<string, PlayerDataObject> hostUserData, Dictionary<string, DataObject> lobbyData, Action<Lobby> onComplete, Action onFailed)

Assets/BossRoom/Scripts/Shared/Net/UnityServices/Lobbies/LobbyServiceFacade.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ void OnSuccess(Lobby lobby)
125125
return;
126126
}
127127
}
128-
m_UnityServiceErrorMessagePub.Publish(new UnityServiceErrorMessage("Host left the lobby","Disconnecting."));
128+
m_UnityServiceErrorMessagePub.Publish(new UnityServiceErrorMessage("Host left the lobby","Disconnecting.", UnityServiceErrorMessage.Service.Lobby));
129129
ForceLeaveLobbyAttempt();
130130
// no need to disconnect Netcode, it should already be handled by Netcode's callback to disconnect
131131
}

0 commit comments

Comments
 (0)