Skip to content

feat: better lobby exception handling [MTT-2649] #585

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 11 commits into from
Apr 6, 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
48 changes: 33 additions & 15 deletions Assets/BossRoom/Prefabs/UI/LobbyUI.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,8 @@ MonoBehaviour:
m_text: 'Your Name:'
m_isRightToLeft: 0
m_fontAsset: {fileID: 11400000, guid: 9641ce046d2227445b9684161a165f68, type: 2}
m_sharedMaterial: {fileID: -4106257185398102161, guid: 9641ce046d2227445b9684161a165f68, type: 2}
m_sharedMaterial: {fileID: -4106257185398102161, guid: 9641ce046d2227445b9684161a165f68,
type: 2}
m_fontSharedMaterials: []
m_fontMaterial: {fileID: 0}
m_fontMaterials: []
Expand Down Expand Up @@ -975,7 +976,11 @@ MonoBehaviour:
m_Calls: []
m_OnValueChanged:
m_PersistentCalls:
m_Calls: []
m_Calls: [{m_Target: {fileID: 3432713757992463987}, m_TargetAssemblyTypeName: 'Unity.Multiplayer.Samples.BossRoom.Visual.LobbyJoiningUI,
Unity.Multiplayer.Samples.BossRoom.Client', m_MethodName: SanitizeJoinCodeInputText,
m_Mode: 1, m_Arguments: {m_ObjectArgument: {fileID: 0}, m_ObjectArgumentAssemblyTypeName: 'UnityEngine.Object,
UnityEngine', m_IntArgument: 0, m_FloatArgument: 0, m_StringArgument: '',
m_BoolArgument: 0}, m_CallState: 2}]
m_CaretColor: {r: 0.19607843, g: 0.19607843, b: 0.19607843, a: 1}
m_CustomCaretColor: 0
m_SelectionColor: {r: 0.65882355, g: 0.80784315, b: 1, a: 0.7529412}
Expand Down Expand Up @@ -1189,7 +1194,8 @@ MonoBehaviour:
'
m_isRightToLeft: 0
m_fontAsset: {fileID: 11400000, guid: 1a8c97d4cbe5134499b26527f8609c7e, type: 2}
m_sharedMaterial: {fileID: -466885322316925189, guid: 1a8c97d4cbe5134499b26527f8609c7e, type: 2}
m_sharedMaterial: {fileID: -466885322316925189, guid: 1a8c97d4cbe5134499b26527f8609c7e,
type: 2}
m_fontSharedMaterials: []
m_fontMaterial: {fileID: 0}
m_fontMaterials: []
Expand Down Expand Up @@ -1323,7 +1329,8 @@ MonoBehaviour:
m_text: Lobby List
m_isRightToLeft: 0
m_fontAsset: {fileID: 11400000, guid: 1a8c97d4cbe5134499b26527f8609c7e, type: 2}
m_sharedMaterial: {fileID: -466885322316925189, guid: 1a8c97d4cbe5134499b26527f8609c7e, type: 2}
m_sharedMaterial: {fileID: -466885322316925189, guid: 1a8c97d4cbe5134499b26527f8609c7e,
type: 2}
m_fontSharedMaterials: []
m_fontMaterial: {fileID: 0}
m_fontMaterials: []
Expand Down Expand Up @@ -1840,7 +1847,8 @@ MonoBehaviour:
m_text: Join
m_isRightToLeft: 0
m_fontAsset: {fileID: 11400000, guid: 1a8c97d4cbe5134499b26527f8609c7e, type: 2}
m_sharedMaterial: {fileID: -466885322316925189, guid: 1a8c97d4cbe5134499b26527f8609c7e, type: 2}
m_sharedMaterial: {fileID: -466885322316925189, guid: 1a8c97d4cbe5134499b26527f8609c7e,
type: 2}
m_fontSharedMaterials: []
m_fontMaterial: {fileID: 0}
m_fontMaterials: []
Expand Down Expand Up @@ -1974,7 +1982,8 @@ MonoBehaviour:
m_text: Private
m_isRightToLeft: 0
m_fontAsset: {fileID: 11400000, guid: 1a8c97d4cbe5134499b26527f8609c7e, type: 2}
m_sharedMaterial: {fileID: -466885322316925189, guid: 1a8c97d4cbe5134499b26527f8609c7e, type: 2}
m_sharedMaterial: {fileID: -466885322316925189, guid: 1a8c97d4cbe5134499b26527f8609c7e,
type: 2}
m_fontSharedMaterials: []
m_fontMaterial: {fileID: 0}
m_fontMaterials: []
Expand Down Expand Up @@ -2785,7 +2794,8 @@ MonoBehaviour:
m_text: Displayed Name
m_isRightToLeft: 0
m_fontAsset: {fileID: 11400000, guid: 9641ce046d2227445b9684161a165f68, type: 2}
m_sharedMaterial: {fileID: -4106257185398102161, guid: 9641ce046d2227445b9684161a165f68, type: 2}
m_sharedMaterial: {fileID: -4106257185398102161, guid: 9641ce046d2227445b9684161a165f68,
type: 2}
m_fontSharedMaterials: []
m_fontMaterial: {fileID: 0}
m_fontMaterials: []
Expand Down Expand Up @@ -3201,7 +3211,8 @@ MonoBehaviour:
m_text: no lobbies
m_isRightToLeft: 0
m_fontAsset: {fileID: 11400000, guid: 1a8c97d4cbe5134499b26527f8609c7e, type: 2}
m_sharedMaterial: {fileID: -466885322316925189, guid: 1a8c97d4cbe5134499b26527f8609c7e, type: 2}
m_sharedMaterial: {fileID: -466885322316925189, guid: 1a8c97d4cbe5134499b26527f8609c7e,
type: 2}
m_fontSharedMaterials: []
m_fontMaterial: {fileID: 0}
m_fontMaterials: []
Expand Down Expand Up @@ -3335,7 +3346,8 @@ MonoBehaviour:
m_text: 0/4
m_isRightToLeft: 0
m_fontAsset: {fileID: 11400000, guid: 1a8c97d4cbe5134499b26527f8609c7e, type: 2}
m_sharedMaterial: {fileID: -466885322316925189, guid: 1a8c97d4cbe5134499b26527f8609c7e, type: 2}
m_sharedMaterial: {fileID: -466885322316925189, guid: 1a8c97d4cbe5134499b26527f8609c7e,
type: 2}
m_fontSharedMaterials: []
m_fontMaterial: {fileID: 0}
m_fontMaterials: []
Expand Down Expand Up @@ -3602,7 +3614,8 @@ MonoBehaviour:
m_text: Relay
m_isRightToLeft: 0
m_fontAsset: {fileID: 11400000, guid: 1a8c97d4cbe5134499b26527f8609c7e, type: 2}
m_sharedMaterial: {fileID: -466885322316925189, guid: 1a8c97d4cbe5134499b26527f8609c7e, type: 2}
m_sharedMaterial: {fileID: -466885322316925189, guid: 1a8c97d4cbe5134499b26527f8609c7e,
type: 2}
m_fontSharedMaterials: []
m_fontMaterial: {fileID: 0}
m_fontMaterials: []
Expand Down Expand Up @@ -4240,7 +4253,8 @@ MonoBehaviour:
'
m_isRightToLeft: 0
m_fontAsset: {fileID: 11400000, guid: 9641ce046d2227445b9684161a165f68, type: 2}
m_sharedMaterial: {fileID: -4106257185398102161, guid: 9641ce046d2227445b9684161a165f68, type: 2}
m_sharedMaterial: {fileID: -4106257185398102161, guid: 9641ce046d2227445b9684161a165f68,
type: 2}
m_fontSharedMaterials: []
m_fontMaterial: {fileID: 0}
m_fontMaterials: []
Expand Down Expand Up @@ -4578,7 +4592,8 @@ MonoBehaviour:
m_text: Quick Join
m_isRightToLeft: 0
m_fontAsset: {fileID: 11400000, guid: 1a8c97d4cbe5134499b26527f8609c7e, type: 2}
m_sharedMaterial: {fileID: -466885322316925189, guid: 1a8c97d4cbe5134499b26527f8609c7e, type: 2}
m_sharedMaterial: {fileID: -466885322316925189, guid: 1a8c97d4cbe5134499b26527f8609c7e,
type: 2}
m_fontSharedMaterials: []
m_fontMaterial: {fileID: 0}
m_fontMaterials: []
Expand Down Expand Up @@ -4913,7 +4928,8 @@ MonoBehaviour:
m_text: Create
m_isRightToLeft: 0
m_fontAsset: {fileID: 11400000, guid: 1a8c97d4cbe5134499b26527f8609c7e, type: 2}
m_sharedMaterial: {fileID: -466885322316925189, guid: 1a8c97d4cbe5134499b26527f8609c7e, type: 2}
m_sharedMaterial: {fileID: -466885322316925189, guid: 1a8c97d4cbe5134499b26527f8609c7e,
type: 2}
m_fontSharedMaterials: []
m_fontMaterial: {fileID: 0}
m_fontMaterials: []
Expand Down Expand Up @@ -5047,7 +5063,8 @@ MonoBehaviour:
m_text: Join an existing lobby...
m_isRightToLeft: 0
m_fontAsset: {fileID: 11400000, guid: 9641ce046d2227445b9684161a165f68, type: 2}
m_sharedMaterial: {fileID: -4106257185398102161, guid: 9641ce046d2227445b9684161a165f68, type: 2}
m_sharedMaterial: {fileID: -4106257185398102161, guid: 9641ce046d2227445b9684161a165f68,
type: 2}
m_fontSharedMaterials: []
m_fontMaterial: {fileID: 0}
m_fontMaterials: []
Expand Down Expand Up @@ -5246,7 +5263,8 @@ MonoBehaviour:
m_text: Room
m_isRightToLeft: 0
m_fontAsset: {fileID: 11400000, guid: 1a8c97d4cbe5134499b26527f8609c7e, type: 2}
m_sharedMaterial: {fileID: -466885322316925189, guid: 1a8c97d4cbe5134499b26527f8609c7e, type: 2}
m_sharedMaterial: {fileID: -466885322316925189, guid: 1a8c97d4cbe5134499b26527f8609c7e,
type: 2}
m_fontSharedMaterials: []
m_fontMaterial: {fileID: 0}
m_fontMaterials: []
Expand Down
16 changes: 15 additions & 1 deletion Assets/BossRoom/Scripts/Client/UI/Lobby/LobbyJoiningUI.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using Unity.Multiplayer.Samples.BossRoom.Shared.Infrastructure;
using Unity.Multiplayer.Samples.BossRoom.Shared.Net.UnityServices.Lobbies;
using UnityEngine;
Expand Down Expand Up @@ -57,9 +58,22 @@ void InjectDependenciesAndInitialize(
m_Subscriptions = localLobbiesRefreshedSub.Subscribe(UpdateUI);
}

/// <summary>
/// Added to the InputField component's OnValueChanged callback for the join code text.
/// </summary>
public void SanitizeJoinCodeInputText()
{
m_JoinCodeField.text = SanitizeJoinCode(m_JoinCodeField.text);
}

string SanitizeJoinCode(string dirtyString)
{
return Regex.Replace(dirtyString.ToUpper(), "[^A-Z0-9]", "");
}

public void OnJoinButtonPressed()
{
m_LobbyUIMediator.JoinLobbyWithCodeRequest(m_JoinCodeField.text.ToUpper());
m_LobbyUIMediator.JoinLobbyWithCodeRequest(SanitizeJoinCode(m_JoinCodeField.text));
}

void PeriodicRefresh(float _)
Expand Down
44 changes: 28 additions & 16 deletions Assets/BossRoom/Scripts/Client/UI/UnityServicesUIHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,26 +49,38 @@ void ServiceErrorHandler(UnityServiceErrorMessage error)

void HandleLobbyError(UnityServiceErrorMessage error)
{
var errorMessage = error.Message;

switch (((LobbyServiceException)error.OriginalException).Reason)
var exception = error.OriginalException as LobbyServiceException;
if (exception != null)
{
case LobbyExceptionReason.LobbyConflict:
{
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");
break;
}
case LobbyExceptionReason.LobbyFull:
switch (exception.Reason)
{
PopupManager.ShowPopupPanel("Failed to join lobby", "Lobby is full and can't accept more players");
// Returning out of the function because we replace default popup panel with this.
return;
// If the error is one of the following, the player needs to know about it, so show in a popup message. Otherwise, the log in the console is sufficient.
case LobbyExceptionReason.ValidationError:
PopupManager.ShowPopupPanel("Validation Error", "Validation check failed on Lobby. Is the join code correctly formatted?");
break;
case LobbyExceptionReason.LobbyNotFound:
PopupManager.ShowPopupPanel("Lobby Not Found", "Requested lobby not found. The join code is incorrect or the lobby has ended.");
break;
case LobbyExceptionReason.LobbyConflict:
// LobbyConflict can have multiple causes. Let's add other solutions here if there's other situations that arise for this.
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");
PopupManager.ShowPopupPanel("Failed to join Lobby", "Failed to join Lobby due to a conflict. See logs for more details.");
break;
case LobbyExceptionReason.NoOpenLobbies:
PopupManager.ShowPopupPanel("Failed to join Lobby", "No accessible lobbies are currently available for quick-join.");
break;
case LobbyExceptionReason.LobbyFull:
PopupManager.ShowPopupPanel("Failed to join Lobby", "Lobby is full and can't accept more players.");
break;
case LobbyExceptionReason.Unauthorized:
PopupManager.ShowPopupPanel("Lobby error", "Received HTTP error 401 Unauthorized from Lobby Service.");
break;
case LobbyExceptionReason.RequestTimeOut:
PopupManager.ShowPopupPanel("Lobby error", "Received HTTP error 408 Request timed out from Lobby Service.");
break;
}
}

PopupManager.ShowPopupPanel("Service error: " + error.Title, errorMessage);
}

void OnDestroy()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void OnClientDisconnect(ulong clientId)
{
if (m_LobbyServiceFacade.CurrentUnityLobby != null)
{
m_LobbyServiceFacade.RemovePlayerFromLobbyAsync(playerId, m_LobbyServiceFacade.CurrentUnityLobby.Id, null, null);
m_LobbyServiceFacade.RemovePlayerFromLobbyAsync(playerId, m_LobbyServiceFacade.CurrentUnityLobby.Id);
}
SessionManager<SessionPlayerData>.Instance.DisconnectClient(clientId);
}
Expand Down Expand Up @@ -209,7 +209,7 @@ void ApprovalCheck(byte[] connectionData, ulong clientId, NetworkManager.Connect
StartCoroutine(WaitToDenyApproval(connectionApprovedCallback));
if (m_LobbyServiceFacade.CurrentUnityLobby != null)
{
m_LobbyServiceFacade.RemovePlayerFromLobbyAsync(connectionPayload.playerId, m_LobbyServiceFacade.CurrentUnityLobby.Id, null, null);
m_LobbyServiceFacade.RemovePlayerFromLobbyAsync(connectionPayload.playerId, m_LobbyServiceFacade.CurrentUnityLobby.Id);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,27 +282,11 @@ public async void LeaveLobbyAsync(string lobbyId)
await m_LobbyApiInterface.RemovePlayerFromLobby(uasId, lobbyId);
}

public async void RemovePlayerFromLobbyAsync(string uasId, string lobbyId, Action onSuccess, Action onFailure)
public async void RemovePlayerFromLobbyAsync(string uasId, string lobbyId)
{
if (m_LocalUser.IsHost)
{
var lobby = await m_LobbyApiInterface.GetLobby(lobbyId);

bool playerFound = false;
foreach (var player in lobby.Players)
{
if (player.Id == uasId)
{
await m_LobbyApiInterface.RemovePlayerFromLobby(uasId, lobbyId);
playerFound = true;
break;
}
}

if (!playerFound)
{
Debug.Log($"Player {uasId} has already left the lobby.");
}
await m_LobbyApiInterface.RemovePlayerFromLobby(uasId, lobbyId);
}
else
{
Expand Down