Skip to content

chore/fix: remove online mode and IP/port from lobbies [MTT-3214] #595

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
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
Expand Up @@ -11,7 +11,6 @@ public class LobbyCreationUI : MonoBehaviour
[SerializeField] Toggle m_IsPrivate;
[SerializeField] CanvasGroup m_CanvasGroup;
LobbyUIMediator m_LobbyUIMediator;
OnlineMode m_OnlineMode;

void Awake()
{
Expand All @@ -26,14 +25,12 @@ void InjectDependencies(LobbyUIMediator lobbyUIMediator)

void EnableUnityRelayUI()
{
m_OnlineMode = OnlineMode.UnityRelay;

m_LoadingIndicatorObject.SetActive(false);
}

public void OnCreateClick()
{
m_LobbyUIMediator.CreateLobbyRequest(m_LobbyNameInputField.text, m_IsPrivate.isOn, 8, m_OnlineMode);
m_LobbyUIMediator.CreateLobbyRequest(m_LobbyNameInputField.text, m_IsPrivate.isOn, 8);
}

public void Show()
Expand Down
2 changes: 0 additions & 2 deletions Assets/BossRoom/Scripts/Client/UI/Lobby/LobbyListItemUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ public class LobbyListItemUI : MonoBehaviour
{
[SerializeField] TextMeshProUGUI m_lobbyNameText;
[SerializeField] TextMeshProUGUI m_lobbyCountText;
[SerializeField] TextMeshProUGUI m_OnlineModeText;

LobbyUIMediator m_LobbyUIMediator;
LocalLobby m_Data;
Expand All @@ -28,7 +27,6 @@ public void SetData(LocalLobby data)
m_Data = data;
m_lobbyNameText.SetText(data.LobbyName);
m_lobbyCountText.SetText($"{data.PlayerCount}/{data.MaxPlayerCount}");
m_OnlineModeText.SetText(data.OnlineMode.ToString());
}

public void OnClick()
Expand Down
32 changes: 6 additions & 26 deletions Assets/BossRoom/Scripts/Client/UI/Lobby/LobbyUIMediator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ void OnDestroy()

//Lobby and Relay calls done from UI

public void CreateLobbyRequest(string lobbyName, bool isPrivate, int maxPlayers, OnlineMode onlineMode)
public void CreateLobbyRequest(string lobbyName, bool isPrivate, int maxPlayers)
{
// before sending request to lobby service, populate an empty lobby name, if necessary
if (string.IsNullOrEmpty(lobbyName))
{
lobbyName = k_DefaultLobbyName;
}

m_LobbyServiceFacade.CreateLobbyAsync(lobbyName, maxPlayers, isPrivate, onlineMode, OnCreatedLobby, OnFailedLobbyCreateOrJoin);
m_LobbyServiceFacade.CreateLobbyAsync(lobbyName, maxPlayers, isPrivate, OnCreatedLobby, OnFailedLobbyCreateOrJoin);
BlockUIWhileLoadingIsInProgress();
}

Expand Down Expand Up @@ -132,37 +132,17 @@ void OnCreatedLobby(Lobby lobby)

m_GameNetPortal.PlayerName = m_LocalUser.DisplayName;

switch (m_LocalLobby.OnlineMode)
{
case OnlineMode.IpHost:
Debug.Log($"Created lobby with ID: {m_LocalLobby.LobbyID} and code {m_LocalLobby.LobbyCode}, at IP:Port {m_LocalLobby.Data.IP}:{m_LocalLobby.Data.Port}");
m_GameNetPortal.StartHost(m_LocalLobby.Data.IP, m_LocalLobby.Data.Port);
break;

case OnlineMode.UnityRelay:
Debug.Log($"Created lobby with ID: {m_LocalLobby.LobbyID} and code {m_LocalLobby.LobbyCode}, Internal Relay Join Code{m_LocalLobby.RelayJoinCode}");
m_GameNetPortal.StartUnityRelayHost();
break;
}
Debug.Log($"Created lobby with ID: {m_LocalLobby.LobbyID} and code {m_LocalLobby.LobbyCode}, Internal Relay Join Code{m_LocalLobby.RelayJoinCode}");
m_GameNetPortal.StartUnityRelayHost();
}

void OnJoinedLobby(Lobby remoteLobby)
{
m_LobbyServiceFacade.SetRemoteLobby(remoteLobby);
m_GameNetPortal.PlayerName = m_LocalUser.DisplayName;

switch (m_LocalLobby.OnlineMode)
{
case OnlineMode.IpHost:
Debug.Log($"Joined lobby with code: {m_LocalLobby.LobbyCode}, at IP:Port {m_LocalLobby.Data.IP}:{m_LocalLobby.Data.Port}");
m_ClientNetPortal.StartClient(m_LocalLobby.Data.IP, m_LocalLobby.Data.Port);
break;

case OnlineMode.UnityRelay:
Debug.Log($"Joined lobby with code: {m_LocalLobby.LobbyCode}, Internal Relay Join Code{m_LocalLobby.RelayJoinCode}");
m_ClientNetPortal.StartClientUnityRelayModeAsync(m_LocalLobby.RelayJoinCode, OnRelayJoinFailed);
break;
}
Debug.Log($"Joined lobby with code: {m_LocalLobby.LobbyCode}, Internal Relay Join Code{m_LocalLobby.RelayJoinCode}");
m_ClientNetPortal.StartClientUnityRelayModeAsync(m_LocalLobby.RelayJoinCode, OnRelayJoinFailed);

void OnRelayJoinFailed(string message)
{
Expand Down
26 changes: 10 additions & 16 deletions Assets/BossRoom/Scripts/Client/UI/RoomNameBox.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using Unity.Multiplayer.Samples.BossRoom;
using UnityEngine;
using TMPro;
using Unity.Multiplayer.Samples.BossRoom.Shared.Infrastructure;
Expand All @@ -24,29 +23,24 @@ private void InjectDependencies(LocalLobby localLobby)
UpdateUI(localLobby);
}

void Awake()
{
gameObject.SetActive(false);
}

private void OnDestroy()
{
m_LocalLobby.changed -= UpdateUI;
}

private void UpdateUI(LocalLobby localLobby)
{
switch (localLobby.OnlineMode)
if (!string.IsNullOrEmpty(localLobby.LobbyCode))
{
case OnlineMode.IpHost:
case OnlineMode.UnityRelay:
m_LobbyCode = localLobby.LobbyCode;
m_RoomNameText.text = $"Lobby Code: {m_LobbyCode}";
m_CopyToClipboardButton.gameObject.SetActive(true);
break;
case OnlineMode.Unset:
//this can happen if we launch the game while circumventing lobby logic
m_LobbyCode = "";
m_RoomNameText.text = $"-----------";
m_CopyToClipboardButton.gameObject.SetActive(false);
break;
default:
throw new ArgumentOutOfRangeException();
m_LobbyCode = localLobby.LobbyCode;
m_RoomNameText.text = $"Lobby Code: {m_LobbyCode}";
gameObject.SetActive(true);
m_CopyToClipboardButton.gameObject.SetActive(true);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Unity.Multiplayer.Samples.BossRoom.Shared.Infrastructure;
using Unity.Multiplayer.Samples.BossRoom.Shared.Net.UnityServices.Infrastructure;
using Unity.Services.Authentication;
Expand Down Expand Up @@ -145,7 +144,7 @@ void OnSuccess(Lobby lobby)
/// <summary>
/// Attempt to create a new lobby and then join it.
/// </summary>
public void CreateLobbyAsync(string lobbyName, int maxPlayers, bool isPrivate, OnlineMode onlineMode, Action<Lobby> onSuccess, Action onFailure)
public void CreateLobbyAsync(string lobbyName, int maxPlayers, bool isPrivate, Action<Lobby> onSuccess, Action onFailure)
{
if (!m_RateLimitHost.CanCall)
{
Expand All @@ -156,12 +155,7 @@ public void CreateLobbyAsync(string lobbyName, int maxPlayers, bool isPrivate, O

m_RateLimitHost.PutOnCooldown();

var initialLobbyData = new Dictionary<string, DataObject>()
{
{"OnlineMode", new DataObject(DataObject.VisibilityOptions.Public, ((int)onlineMode).ToString())}
};

m_LobbyApiInterface.CreateLobbyAsync(AuthenticationService.Instance.PlayerId, lobbyName, maxPlayers, isPrivate, m_LocalUser.GetDataForUnityServices(), initialLobbyData, onSuccess, onFailure);
m_LobbyApiInterface.CreateLobbyAsync(AuthenticationService.Instance.PlayerId, lobbyName, maxPlayers, isPrivate, m_LocalUser.GetDataForUnityServices(), null, onSuccess, onFailure);
}

/// <summary>
Expand Down Expand Up @@ -351,7 +345,7 @@ public void UpdateLobbyDataAsync(Dictionary<string, DataObject> data, Action onS
}

//we would want to lock lobbies from appearing in queries if we're in relay mode and the relay isn't fully set up yet
var shouldLock = m_LocalLobby.OnlineMode == OnlineMode.UnityRelay && string.IsNullOrEmpty(m_LocalLobby.RelayJoinCode);
var shouldLock = string.IsNullOrEmpty(m_LocalLobby.RelayJoinCode);

m_LobbyApiInterface.UpdateLobbyAsync(CurrentUnityLobby.Id, dataCurr, shouldLock, OnComplete, onFailure);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ public struct LobbyData
public bool Private { get; set; }
public int MaxPlayerCount { get; set; }

public OnlineMode OnlineMode { get; set; }
public string IP { get; set; }
public int Port { get; set; }

public LobbyData(LobbyData existing)
{
LobbyID = existing.LobbyID;
Expand All @@ -57,9 +53,6 @@ public LobbyData(LobbyData existing)
LobbyName = existing.LobbyName;
Private = existing.Private;
MaxPlayerCount = existing.MaxPlayerCount;
OnlineMode = existing.OnlineMode;
IP = existing.IP;
Port = existing.Port;
}

public LobbyData(string lobbyCode)
Expand All @@ -70,9 +63,6 @@ public LobbyData(string lobbyCode)
LobbyName = null;
Private = false;
MaxPlayerCount = -1;
OnlineMode = OnlineMode.Unset;
IP = string.Empty;
Port = 0;
}
}

Expand Down Expand Up @@ -184,18 +174,6 @@ public int MaxPlayerCount
}
}

public OnlineMode OnlineMode
{
get => m_Data.OnlineMode;
set
{
if (m_Data.OnlineMode != value)
{ m_Data.OnlineMode = value;
OnChanged();
}
}
}

public void CopyDataFrom(LobbyData data, Dictionary<string, LocalLobbyUser> currUsers)
{
m_Data = data;
Expand Down Expand Up @@ -239,10 +217,7 @@ public void CopyDataFrom(LobbyData data, Dictionary<string, LocalLobbyUser> curr
public Dictionary<string, DataObject> GetDataForUnityServices() =>
new Dictionary<string, DataObject>()
{
{"RelayJoinCode", new DataObject(DataObject.VisibilityOptions.Public, RelayJoinCode)},
{"OnlineMode", new DataObject(DataObject.VisibilityOptions.Public, ((int)Data.OnlineMode).ToString())},
{"IP", new DataObject(DataObject.VisibilityOptions.Public, Data.IP)},
{"Port", new DataObject(DataObject.VisibilityOptions.Public, Data.Port.ToString())},
{"RelayJoinCode", new DataObject(DataObject.VisibilityOptions.Public, RelayJoinCode)}
};

public void ApplyRemoteData(Lobby lobby)
Expand All @@ -257,16 +232,10 @@ public void ApplyRemoteData(Lobby lobby)
if (lobby.Data != null)
{
info.RelayJoinCode = lobby.Data.ContainsKey("RelayJoinCode") ? lobby.Data["RelayJoinCode"].Value : null; // By providing RelayCode through the lobby data with Member visibility, we ensure a client is connected to the lobby before they could attempt a relay connection, preventing timing issues between them.
info.OnlineMode = lobby.Data.ContainsKey("OnlineMode") ? (OnlineMode) int.Parse(lobby.Data["OnlineMode"].Value) : OnlineMode.Unset;
info.IP = lobby.Data.ContainsKey("IP") ? lobby.Data["IP"].Value : string.Empty;
info.Port = lobby.Data.ContainsKey("Port") ? int.Parse(lobby.Data["Port"].Value) : 0;
}
else
{
info.RelayJoinCode = null;
info.OnlineMode = OnlineMode.Unset;
info.IP = string.Empty;
info.Port = 0;
}

var lobbyUsers = new Dictionary<string, LocalLobbyUser>();
Expand Down