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 8 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
19 changes: 16 additions & 3 deletions Assets/BossRoom/Prefabs/UI/LobbyUI.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,20 @@ 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 @@ -4298,7 +4311,7 @@ MonoBehaviour:
m_faceColor:
serializedVersion: 2
rgba: 4294967295
m_fontSize: 20.3
m_fontSize: 33
m_fontSizeBase: 36
m_fontWeight: 400
m_enableAutoSizing: 1
Expand Down Expand Up @@ -5105,7 +5118,7 @@ MonoBehaviour:
m_faceColor:
serializedVersion: 2
rgba: 4294967295
m_fontSize: 20.3
m_fontSize: 33
m_fontSizeBase: 36
m_fontWeight: 400
m_enableAutoSizing: 1
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
43 changes: 28 additions & 15 deletions Assets/BossRoom/Scripts/Client/UI/UnityServicesUIHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,25 +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:
switch (exception.Reason)
{
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:
{
PopupPanel.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:
PopupPanel.ShowPopupPanel("Validation Error", "Validation check failed on Lobby. Is the join code correctly formatted?");
break;
case LobbyExceptionReason.LobbyNotFound:
PopupPanel.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");
PopupPanel.ShowPopupPanel("Failed to join Lobby", "Failed to join Lobby due to a conflict. See logs for more details.");
break;
case LobbyExceptionReason.NoOpenLobbies:
PopupPanel.ShowPopupPanel("Failed to join Lobby", "No accessible lobbies are currently available for quick-join.");
break;
case LobbyExceptionReason.LobbyFull:
PopupPanel.ShowPopupPanel("Failed to join Lobby", "Lobby is full and can't accept more players.");
break;
case LobbyExceptionReason.Unauthorized:
PopupPanel.ShowPopupPanel("Lobby error", "Received HTTP error 401 Unauthorized from Lobby Service.");
break;
case LobbyExceptionReason.RequestTimeOut:
PopupPanel.ShowPopupPanel("Lobby error", "Received HTTP error 408 Request timed out from Lobby Service.");
break;
}
}

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

void OnDestroy()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,28 +251,7 @@ public void RemovePlayerFromLobbyAsync(string uasId, string lobbyId, Action onSu
{
if (m_LocalUser.IsHost)
{
RetrieveLobbyAsync(lobbyId, OnRetrieveSuccess, onFailure);


void OnRetrieveSuccess(Lobby lobby)
{
bool playerFound = false;
foreach (var player in lobby.Players)
{
if (player.Id == uasId)
{
m_LobbyApiInterface.LeaveLobbyAsync(uasId, lobbyId, onSuccess, onFailure);
playerFound = true;
break;
}
}

if (!playerFound)
{
Debug.Log($"Player {uasId} has already left the lobby.");
}
}

m_LobbyApiInterface.LeaveLobbyAsync(uasId, lobbyId, onSuccess, onFailure);
}
else
{
Expand Down