-
Notifications
You must be signed in to change notification settings - Fork 559
feat: bumping boss room to 1.1 #708
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
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
6f05618
After this PR https://github.com/Unity-Technologies/com.unity.netcode…
SamuelBellomo 519bd5e
Merge branch 'develop' into sam/feat/bump-NGO-to-1.1
SamuelBellomo c13ba78
Merge branch 'develop' into sam/feat/bump-NGO-to-1.1
SamuelBellomo 2a69af7
basis works, still need to debug issue with client reconnecting a sec…
SamuelBellomo 29d79b8
setting back max payload size to default value. With recent changes, …
SamuelBellomo 2b50fd9
Increasing connection approval timeout to 5 seconds, as 1 second was …
SamuelBellomo 59ab475
making diff clearer for review
SamuelBellomo d3f59da
adding better exception error
SamuelBellomo 5bb2994
using classes instead of structs now that we have managed types avail…
SamuelBellomo ab1174b
Merge branch 'develop' into sam/feat/bump-NGO-to-1.1
SamuelBellomo 2913b23
fixing null ref when doing reconnection flow
SamuelBellomo 5f3bc3e
reverting removal of utilities
SamuelBellomo b84f7a7
deprecated note
SamuelBellomo b7e83c3
better comments, cleaner easier to read code.
SamuelBellomo 243bdef
cleanup
SamuelBellomo 171a936
Update changelog
SamuelBellomo 77e8900
Merge branch 'develop' into sam/feat/bump-NGO-to-1.1
SamuelBellomo 55d13ba
adding missing PR ID
SamuelBellomo e163ce1
adding missing PR ID
SamuelBellomo b6705f4
removing useless usings
SamuelBellomo 864fead
Merge branch 'sam/feat/bump-NGO-to-1.1' of github.com:Unity-Technolog…
SamuelBellomo 2fe2683
namespace adjustements
SamuelBellomo dfda378
updating manifest and dependencies with 1.1.0 now it's released
SamuelBellomo 11f076e
Merge develop into sam/feat/bump-NGO-to-1.1
netcode-ci-service 4b79d59
Merge develop into sam/feat/bump-NGO-to-1.1
netcode-ci-service 521c019
initializing number of reconnect attempts before starting the reconne…
LPLafontaineB 48573dd
fixing player prefab being destroyed issue
SamuelBellomo 2cebbd2
Merge branch 'sam/feat/bump-NGO-to-1.1' of github.com:Unity-Technolog…
SamuelBellomo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
158 changes: 158 additions & 0 deletions
158
Assets/Scripts/ConnectionManagement/ConnectionMethod.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Unity.BossRoom.UnityServices.Lobbies; | ||
using Unity.BossRoom.Utils; | ||
using Unity.Netcode.Transports.UTP; | ||
using Unity.Networking.Transport.Relay; | ||
using Unity.Services.Authentication; | ||
using Unity.Services.Core; | ||
using Unity.Services.Relay; | ||
using Unity.Services.Relay.Models; | ||
using UnityEngine; | ||
|
||
namespace Unity.BossRoom.ConnectionManagement | ||
{ | ||
/// <summary> | ||
/// ConnectionMethod contains all setup needed to setup NGO to be ready to start a connection, either host or client side. | ||
/// Please override this abstract class to add a new transport or way of connecting. | ||
/// </summary> | ||
public abstract class ConnectionMethodBase | ||
{ | ||
protected ConnectionManager m_ConnectionManager; | ||
readonly ProfileManager m_ProfileManager; | ||
protected readonly string m_PlayerName; | ||
|
||
public abstract Task SetupHostConnectionAsync(); | ||
|
||
public abstract Task SetupClientConnectionAsync(); | ||
|
||
public ConnectionMethodBase(ConnectionManager connectionManager, ProfileManager profileManager, string playerName) | ||
{ | ||
m_ConnectionManager = connectionManager; | ||
m_ProfileManager = profileManager; | ||
m_PlayerName = playerName; | ||
} | ||
|
||
protected void SetConnectionPayload(string playerId, string playerName) | ||
{ | ||
var payload = JsonUtility.ToJson(new ConnectionPayload() | ||
{ | ||
playerId = playerId, | ||
playerName = playerName, | ||
isDebug = Debug.isDebugBuild | ||
}); | ||
|
||
var payloadBytes = System.Text.Encoding.UTF8.GetBytes(payload); | ||
|
||
m_ConnectionManager.NetworkManager.NetworkConfig.ConnectionData = payloadBytes; | ||
} | ||
|
||
protected string GetPlayerId() | ||
{ | ||
if (Services.Core.UnityServices.State != ServicesInitializationState.Initialized) | ||
{ | ||
return ClientPrefs.GetGuid() + m_ProfileManager.Profile; | ||
} | ||
|
||
return AuthenticationService.Instance.IsSignedIn ? AuthenticationService.Instance.PlayerId : ClientPrefs.GetGuid() + m_ProfileManager.Profile; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Simple IP connection setup with UTP | ||
/// </summary> | ||
class ConnectionMethodIP : ConnectionMethodBase | ||
{ | ||
string m_Ipaddress; | ||
ushort m_Port; | ||
|
||
public ConnectionMethodIP(string ip, ushort port, ConnectionManager connectionManager, ProfileManager profileManager, string playerName) | ||
: base(connectionManager, profileManager, playerName) | ||
{ | ||
m_Ipaddress = ip; | ||
m_Port = port; | ||
m_ConnectionManager = connectionManager; | ||
} | ||
|
||
public override async Task SetupClientConnectionAsync() | ||
{ | ||
SetConnectionPayload(GetPlayerId(), m_PlayerName); | ||
var utp = (UnityTransport)m_ConnectionManager.NetworkManager.NetworkConfig.NetworkTransport; | ||
utp.SetConnectionData(m_Ipaddress, m_Port); | ||
} | ||
|
||
public override async Task SetupHostConnectionAsync() | ||
{ | ||
SetConnectionPayload(GetPlayerId(), m_PlayerName); // Need to set connection payload for host as well, as host is a client too | ||
var utp = (UnityTransport)m_ConnectionManager.NetworkManager.NetworkConfig.NetworkTransport; | ||
utp.SetConnectionData(m_Ipaddress, m_Port); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// UTP's Relay connection setup | ||
/// </summary> | ||
class ConnectionMethodRelay : ConnectionMethodBase | ||
{ | ||
LobbyServiceFacade m_LobbyServiceFacade; | ||
LocalLobby m_LocalLobby; | ||
|
||
public ConnectionMethodRelay(LobbyServiceFacade lobbyServiceFacade, LocalLobby localLobby, ConnectionManager connectionManager, ProfileManager profileManager, string playerName) | ||
: base(connectionManager, profileManager, playerName) | ||
{ | ||
m_LobbyServiceFacade = lobbyServiceFacade; | ||
m_LocalLobby = localLobby; | ||
m_ConnectionManager = connectionManager; | ||
} | ||
|
||
public override async Task SetupClientConnectionAsync() | ||
{ | ||
Debug.Log("Setting up Unity Relay client"); | ||
|
||
SetConnectionPayload(GetPlayerId(), m_PlayerName); | ||
|
||
if (m_LobbyServiceFacade.CurrentUnityLobby == null) | ||
{ | ||
throw new Exception("Trying to start relay while Lobby isn't set"); | ||
} | ||
|
||
Debug.Log($"Setting Unity Relay client with join code {m_LocalLobby.RelayJoinCode}"); | ||
|
||
// Create client joining allocation from join code | ||
var joinedAllocation = await RelayService.Instance.JoinAllocationAsync(m_LocalLobby.RelayJoinCode); | ||
Debug.Log($"client: {joinedAllocation.ConnectionData[0]} {joinedAllocation.ConnectionData[1]}, " + | ||
$"host: {joinedAllocation.HostConnectionData[0]} {joinedAllocation.HostConnectionData[1]}, " + | ||
$"client: {joinedAllocation.AllocationId}"); | ||
|
||
await m_LobbyServiceFacade.UpdatePlayerRelayInfoAsync(joinedAllocation.AllocationId.ToString(), m_LocalLobby.RelayJoinCode); | ||
|
||
// Configure UTP with allocation | ||
var utp = (UnityTransport)m_ConnectionManager.NetworkManager.NetworkConfig.NetworkTransport; | ||
utp.SetRelayServerData(new RelayServerData(joinedAllocation, OnlineState.k_DtlsConnType)); | ||
} | ||
|
||
public override async Task SetupHostConnectionAsync() | ||
{ | ||
Debug.Log("Setting up Unity Relay host"); | ||
|
||
SetConnectionPayload(GetPlayerId(), m_PlayerName); // Need to set connection payload for host as well, as host is a client too | ||
|
||
// Create relay allocation | ||
Allocation hostAllocation = await RelayService.Instance.CreateAllocationAsync(m_ConnectionManager.MaxConnectedPlayers, region: null); | ||
var joinCode = await RelayService.Instance.GetJoinCodeAsync(hostAllocation.AllocationId); | ||
|
||
Debug.Log($"server: connection data: {hostAllocation.ConnectionData[0]} {hostAllocation.ConnectionData[1]}, " + | ||
$"allocation ID:{hostAllocation.AllocationId}, region:{hostAllocation.Region}"); | ||
|
||
m_LocalLobby.RelayJoinCode = joinCode; | ||
|
||
//next line enable lobby and relay services integration | ||
await m_LobbyServiceFacade.UpdateLobbyDataAsync(m_LocalLobby.GetDataForUnityServices()); | ||
await m_LobbyServiceFacade.UpdatePlayerRelayInfoAsync(hostAllocation.AllocationIdBytes.ToString(), joinCode); | ||
|
||
// Setup UTP with relay connection info | ||
var utp = (UnityTransport)m_ConnectionManager.NetworkManager.NetworkConfig.NetworkTransport; | ||
utp.SetRelayServerData(new RelayServerData(hostAllocation, OnlineState.k_DtlsConnType)); // This is with DTLS enabled for a secure connection | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.