Skip to content

Commit

Permalink
Merge branch 'develop' into sam/chore/bump-unity-2021.3.10f1
Browse files Browse the repository at this point in the history
* develop:
  feat: upgrade lobby [MTT-3962][MTT-4105][MTT-4052] (#737)
  fix: shield charge trigger reset & reuse cooldown populated [MTT-4100] (#742)

# Conflicts:
#	CHANGELOG.md
#	Packages/manifest.json
#	Packages/packages-lock.json
  • Loading branch information
SamuelBellomo committed Sep 26, 2022
2 parents 9a8e31f + e484dc6 commit bbca4ef
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 35 deletions.
4 changes: 2 additions & 2 deletions Assets/GameData/Action/Tank/TankShieldBuff.asset
Git LFS file not shown
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ async Task<bool> JoinRelayServerAsync()

try
{
var (ipv4Address, port, allocationIdBytes, connectionData, hostConnectionData, key) =
var (ipv4Address, port, allocationIdBytes, allocationId, connectionData, hostConnectionData, key) =
await UnityRelayUtilities.JoinRelayServerFromJoinCode(m_LocalLobby.RelayJoinCode);

await m_LobbyServiceFacade.UpdatePlayerRelayInfoAsync(allocationIdBytes.ToString(), m_LocalLobby.RelayJoinCode);
await m_LobbyServiceFacade.UpdatePlayerRelayInfoAsync(allocationId.ToString(), m_LocalLobby.RelayJoinCode);
var utp = (UnityTransport)m_ConnectionManager.NetworkManager.NetworkConfig.NetworkTransport;
utp.SetClientRelayData(ipv4Address, port, allocationIdBytes, key, connectionData, hostConnectionData, isSecure: true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class ClientReconnectingState : ClientConnectingState
string m_LobbyCode = "";
int m_NbAttempts;

const float k_TimeBetweenAttempts = 5;

public override void Enter()
{
m_LobbyCode = m_LobbyServiceFacade.CurrentUnityLobby != null ? m_LobbyServiceFacade.CurrentUnityLobby.LobbyCode : "";
Expand Down Expand Up @@ -71,6 +73,15 @@ public override void OnDisconnectReasonReceived(ConnectStatus disconnectReason)

IEnumerator ReconnectCoroutine()
{
// If not on first attempt, wait some time before trying again, so that if the issue causing the disconnect
// is temporary, it has time to fix itself before we try again. Here we are using a simple fixed cooldown
// but we could want to use exponential backoff instead, to wait a longer time between each failed attempt.
// See https://en.wikipedia.org/wiki/Exponential_backoff
if (m_NbAttempts > 0)
{
yield return new WaitForSeconds(k_TimeBetweenAttempts);
}

Debug.Log("Lost connection to host, trying to reconnect...");

m_ConnectionManager.NetworkManager.Shutdown();
Expand All @@ -79,26 +90,34 @@ IEnumerator ReconnectCoroutine()
Debug.Log($"Reconnecting attempt {m_NbAttempts + 1}/{m_ConnectionManager.NbReconnectAttempts}...");
m_ReconnectMessagePublisher.Publish(new ReconnectMessage(m_NbAttempts, m_ConnectionManager.NbReconnectAttempts));
m_NbAttempts++;
if (!string.IsNullOrEmpty(m_LobbyCode))
if (!string.IsNullOrEmpty(m_LobbyCode)) // Attempting to reconnect to lobby.
{
var leavingLobby = m_LobbyServiceFacade.EndTracking();
yield return new WaitUntil(() => leavingLobby.IsCompleted);
var joiningLobby = m_LobbyServiceFacade.TryJoinLobbyAsync("", m_LobbyCode);
yield return new WaitUntil(() => joiningLobby.IsCompleted);
if (joiningLobby.Result.Success)
// When using Lobby with Relay, if a user is disconnected from the Relay server, the server will notify
// the Lobby service and mark the user as disconnected, but will not remove them from the lobby. They
// then have some time to attempt to reconnect (defined by the "Disconnect removal time" parameter on
// the dashboard), after which they will be removed from the lobby completely.
// See https://docs.unity.com/lobby/reconnect-to-lobby.html
var reconnectingToLobby = m_LobbyServiceFacade.ReconnectToLobbyAsync(m_LocalLobby?.LobbyID);
yield return new WaitUntil(() => reconnectingToLobby.IsCompleted);

// If succeeded, attempt to connect to Relay
if (!reconnectingToLobby.IsFaulted && reconnectingToLobby.Result != null)
{
m_LobbyServiceFacade.SetRemoteLobby(joiningLobby.Result.Lobby);
// If this fails, the OnClientDisconnect callback will be invoked by Netcode
var connectingToRelay = ConnectClientAsync();
yield return new WaitUntil(() => connectingToRelay.IsCompleted);
}
else
{
Debug.Log("Failed joining lobby.");
Debug.Log("Failed reconnecting to lobby.");
// Calling OnClientDisconnect to mark this attempt as failed and either start a new one or give up
// and return to the Offline state
OnClientDisconnect(0);
}
}
else
else // If not using Lobby, simply try to reconnect to the server directly
{
// If this fails, the OnClientDisconnect callback will be invoked by Netcode
var connectingClient = ConnectClientAsync();
yield return new WaitUntil(() => connectingClient.IsCompleted);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,6 @@ public override void OnClientDisconnect(ulong clientId)
var playerId = SessionManager<SessionPlayerData>.Instance.GetPlayerId(clientId);
if (playerId != null)
{
if (m_LobbyServiceFacade.CurrentUnityLobby != null)
{
m_LobbyServiceFacade.RemovePlayerFromLobbyAsync(playerId, m_LobbyServiceFacade.CurrentUnityLobby.Id);
}

var sessionData = SessionManager<SessionPlayerData>.Instance.GetPlayerData(playerId);
if (sessionData.HasValue)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ private void StopChargingUp(ServerCharacter parent)

parent.serverAnimationHandler.NetworkAnimator.SetTrigger(Config.Anim2);

parent.serverAnimationHandler.NetworkAnimator.ResetTrigger(Config.Anim);

//tell the animator controller to enter "invincibility mode" (where we don't flinch from damage)
if (Mathf.Approximately(GetPercentChargedUp(), 1f))
{
Expand Down
29 changes: 16 additions & 13 deletions Assets/Scripts/UnityServices/Lobbies/LobbyAPIInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

namespace Unity.BossRoom.UnityServices.Lobbies
{
using Lobbies = Unity.Services.Lobbies.Lobbies;

/// <summary>
/// Wrapper for all the interactions with the Lobby API.
/// </summary>
Expand Down Expand Up @@ -82,24 +80,24 @@ public async Task<Lobby> CreateLobby(string requesterUasId, string lobbyName, in
Data = lobbyData
};

return await ExceptionHandling(Lobbies.Instance.CreateLobbyAsync(lobbyName, maxPlayers, createOptions));
return await ExceptionHandling(LobbyService.Instance.CreateLobbyAsync(lobbyName, maxPlayers, createOptions));
}

public async Task DeleteLobby(string lobbyId)
{
await ExceptionHandling(Lobbies.Instance.DeleteLobbyAsync(lobbyId));
await ExceptionHandling(LobbyService.Instance.DeleteLobbyAsync(lobbyId));
}

public async Task<Lobby> JoinLobbyByCode(string requesterUasId, string lobbyCode, Dictionary<string, PlayerDataObject> localUserData)
{
JoinLobbyByCodeOptions joinOptions = new JoinLobbyByCodeOptions { Player = new Player(id: requesterUasId, data: localUserData) };
return await ExceptionHandling(Lobbies.Instance.JoinLobbyByCodeAsync(lobbyCode, joinOptions));
return await ExceptionHandling(LobbyService.Instance.JoinLobbyByCodeAsync(lobbyCode, joinOptions));
}

public async Task<Lobby> JoinLobbyById(string requesterUasId, string lobbyId, Dictionary<string, PlayerDataObject> localUserData)
{
JoinLobbyByIdOptions joinOptions = new JoinLobbyByIdOptions { Player = new Player(id: requesterUasId, data: localUserData) };
return await ExceptionHandling(Lobbies.Instance.JoinLobbyByIdAsync(lobbyId, joinOptions));
return await ExceptionHandling(LobbyService.Instance.JoinLobbyByIdAsync(lobbyId, joinOptions));
}

public async Task<Lobby> QuickJoinLobby(string requesterUasId, Dictionary<string, PlayerDataObject> localUserData)
Expand All @@ -110,14 +108,19 @@ public async Task<Lobby> QuickJoinLobby(string requesterUasId, Dictionary<string
Player = new Player(id: requesterUasId, data: localUserData)
};

return await ExceptionHandling(Lobbies.Instance.QuickJoinLobbyAsync(joinRequest));
return await ExceptionHandling(LobbyService.Instance.QuickJoinLobbyAsync(joinRequest));
}

public async Task<Lobby> ReconnectToLobby(string lobbyId)
{
return await ExceptionHandling(LobbyService.Instance.ReconnectToLobbyAsync(lobbyId));
}

public async Task RemovePlayerFromLobby(string requesterUasId, string lobbyId)
{
try
{
await ExceptionHandling(Lobbies.Instance.RemovePlayerAsync(lobbyId, requesterUasId));
await ExceptionHandling(LobbyService.Instance.RemovePlayerAsync(lobbyId, requesterUasId));
}
catch (LobbyServiceException e)
when (e is { Reason: LobbyExceptionReason.PlayerNotFound })
Expand All @@ -135,18 +138,18 @@ public async Task<QueryResponse> QueryAllLobbies()
Order = m_Order
};

return await ExceptionHandling(Lobbies.Instance.QueryLobbiesAsync(queryOptions));
return await ExceptionHandling(LobbyService.Instance.QueryLobbiesAsync(queryOptions));
}

public async Task<Lobby> GetLobby(string lobbyId)
{
return await ExceptionHandling(Lobbies.Instance.GetLobbyAsync(lobbyId));
return await ExceptionHandling(LobbyService.Instance.GetLobbyAsync(lobbyId));
}

public async Task<Lobby> UpdateLobby(string lobbyId, Dictionary<string, DataObject> data, bool shouldLock)
{
UpdateLobbyOptions updateOptions = new UpdateLobbyOptions { Data = data, IsLocked = shouldLock };
return await ExceptionHandling(Lobbies.Instance.UpdateLobbyAsync(lobbyId, updateOptions));
return await ExceptionHandling(LobbyService.Instance.UpdateLobbyAsync(lobbyId, updateOptions));
}

public async Task<Lobby> UpdatePlayer(string lobbyId, string playerId, Dictionary<string, PlayerDataObject> data, string allocationId, string connectionInfo)
Expand All @@ -157,12 +160,12 @@ public async Task<Lobby> UpdatePlayer(string lobbyId, string playerId, Dictionar
AllocationId = allocationId,
ConnectionInfo = connectionInfo
};
return await ExceptionHandling(Lobbies.Instance.UpdatePlayerAsync(lobbyId, playerId, updateOptions));
return await ExceptionHandling(LobbyService.Instance.UpdatePlayerAsync(lobbyId, playerId, updateOptions));
}

public async void SendHeartbeatPing(string lobbyId)
{
await ExceptionHandling(Lobbies.Instance.SendHeartbeatPingAsync(lobbyId));
await ExceptionHandling(LobbyService.Instance.SendHeartbeatPingAsync(lobbyId));
}
}
}
5 changes: 5 additions & 0 deletions Assets/Scripts/UnityServices/Lobbies/LobbyServiceFacade.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,11 @@ public async Task RetrieveAndPublishLobbyListAsync()
}
}

public async Task<Lobby> ReconnectToLobbyAsync(string lobbyId)
{
return await m_LobbyApiInterface.ReconnectToLobby(lobbyId);
}

/// <summary>
/// Attempt to leave a lobby
/// </summary>
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Additional documentation and release notes are available at [Multiplayer Documen
* Instead of a NetworkBehaviour that carries a WinState netvar we now pass the win state on the server to the PostGame scene and it then stores that state in the netvar, eliminating the need to preserve a NetworkBehaviour-bearing gameObject across scenes. (#724)
* Bump to NGO 1.0.1 (#720)
* Reduced the MaxPacketQueueSize UTP parameter value from 512 to 256 (#728). This reduces the amount of memory used by UTP by around 1 MB. Boss Room does not need a bigger queue size than this because there can only be 7 clients connected to a host and UTP already limits the maximum number of in-flight packets to 32 per connection.
* Updated Lobby package to 1.0.3 and reworked our auto-reconnect flow to use the Reconnect feature from the Lobby API (#737). Now, clients do not leave the lobby when they are disconnected, and the host does not remove them from it. They are marked as disconnected by the Relay server and can attempt to reconnect to the lobby directly, until a certain timeout (specified by the Disconnect removal time parameer, set in the dashboard configuration).
* Cleanup
* Namespaces in the project have been changed to map to their assembly definitions (#732)
* Numerous name changes for fields and variables to match their new type names (#732)
Expand All @@ -46,6 +47,7 @@ Additional documentation and release notes are available at [Multiplayer Documen
* Some NetworkBehaviours are disabled instead of being destroyed (#718) - This preserves the index order for NetworkBehaviours between server and clients, resulting in no indexing issue for sending/receiving RPCs.
* Scene Bootstrapper: future proofing bootstrap scene so we don't rely on Startup's path. MTT-3707. (#735)
* Better instructions for host listen IP. (#738) Most useful cases are usually 127.0.0.1 and 0.0.0.0.
* Tank's shield charge animation not getting stuck due to multiple invocations. (#742)

## [v1.3.0-pre] - 2022-06-23

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static async
}

public static async
Task<(string ipv4address, ushort port, byte[] allocationIdBytes, byte[] connectionData, byte[]
Task<(string ipv4address, ushort port, byte[] allocationIdBytes, Guid allocationId, byte[] connectionData, byte[]
hostConnectionData, byte[] key)> JoinRelayServerFromJoinCode(string joinCode)
{
JoinAllocation allocation;
Expand All @@ -62,7 +62,7 @@ public static async
Debug.Log($"client: {allocation.AllocationId}");

var dtlsEndpoint = allocation.ServerEndpoints.First(e => e.ConnectionType == k_KDtlsConnType);
return (dtlsEndpoint.Host, (ushort)dtlsEndpoint.Port, allocation.AllocationIdBytes,
return (dtlsEndpoint.Host, (ushort)dtlsEndpoint.Port, allocation.AllocationIdBytes, allocation.AllocationId,
allocation.ConnectionData, allocation.HostConnectionData, allocation.Key);
}
}
Expand Down
2 changes: 1 addition & 1 deletion Packages/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"com.unity.postprocessing": "3.2.2",
"com.unity.render-pipelines.universal": "12.1.7",
"com.unity.services.authentication": "2.1.1",
"com.unity.services.lobby": "1.0.1",
"com.unity.services.lobby": "1.0.3",
"com.unity.services.relay": "1.0.3",
"com.unity.test-framework": "1.1.31",
"com.unity.textmeshpro": "3.0.6",
Expand Down
2 changes: 1 addition & 1 deletion Packages/packages-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@
"url": "https://packages.unity.com"
},
"com.unity.services.lobby": {
"version": "1.0.1",
"version": "1.0.3",
"depth": 0,
"source": "registry",
"dependencies": {
Expand Down

0 comments on commit bbca4ef

Please sign in to comment.