Skip to content

Update Relay SDK version #909

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 5 commits into from
Jun 17, 2021
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
36 changes: 9 additions & 27 deletions com.unity.multiplayer.transport.utp/Runtime/UTPTransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ private enum State
[SerializeField] private string m_ServerAddress = "127.0.0.1";
[SerializeField] private ushort m_ServerPort = 7777;
[SerializeField] private int m_RelayMaxPlayers = 10;
[SerializeField] private string m_RelayServer = "https://relay-allocations-stg.cloud.unity3d.com";
[SerializeField] private string m_RelayServer = "https://relay-allocations.cloud.unity3d.com";

private State m_State = State.Disconnected;
private NetworkDriver m_Driver;
Expand Down Expand Up @@ -95,20 +95,10 @@ private IEnumerator ClientBindAndConnect(SocketTask task)
var allocation = joinTask.Result.Result.Data.Allocation;

serverEndpoint = NetworkEndPoint.Parse(allocation.RelayServer.IpV4, (ushort)allocation.RelayServer.Port);
#if RELAY_BIGENDIAN
// TODO: endianess of Relay server does not match
var allocationIdArray = allocation.AllocationId.ToByteArray();
Array.Reverse(allocationIdArray, 0, 4);
Array.Reverse(allocationIdArray, 4, 2);
Array.Reverse(allocationIdArray, 6, 2);
var allocationId = RelayAllocationId.FromByteArray(allocationIdArray);
#else
var allocationId = RelayAllocationId.FromByteArray(allocation.AllocationId.ToByteArray());
#endif

// TODO: workaround for receiving 271 bytes in connection data
var connectionData = RelayConnectionData.FromByteArray(allocation.ConnectionData.Take(255).ToArray());
var hostConnectionData = RelayConnectionData.FromByteArray(allocation.HostConnectionData.Take(255).ToArray());
var allocationId = RelayAllocationId.FromByteArray(allocation.AllocationIdBytes);

var connectionData = RelayConnectionData.FromByteArray(allocation.ConnectionData);
var hostConnectionData = RelayConnectionData.FromByteArray(allocation.HostConnectionData);
var key = RelayHMACKey.FromByteArray(allocation.Key);

Debug.Log($"client: {allocation.ConnectionData[0]} {allocation.ConnectionData[1]}");
Expand Down Expand Up @@ -240,17 +230,9 @@ private IEnumerator StartRelayServer(SocketTask task)

var serverEndpoint = NetworkEndPoint.Parse(allocation.RelayServer.IpV4, (ushort)allocation.RelayServer.Port);
// Debug.Log($"Relay Server endpoint: {allocation.RelayServer.IpV4}:{(ushort)allocation.RelayServer.Port}");
#if RELAY_BIGENDIAN
var allocationIdArray = allocation.AllocationId.ToByteArray();
Array.Reverse(allocationIdArray, 0, 4);
Array.Reverse(allocationIdArray, 4, 2);
Array.Reverse(allocationIdArray, 6, 2);
var allocationId = RelayAllocationId.FromByteArray(allocationIdArray);
#else
var allocationId = RelayAllocationId.FromByteArray(allocation.AllocationId.ToByteArray());
#endif
// TODO: connectionData should be 255 bytes, but we are getting 16 extra bytes
var connectionData = RelayConnectionData.FromByteArray(allocation.ConnectionData.Take(255).ToArray());
var allocationId = RelayAllocationId.FromByteArray(allocation.AllocationIdBytes);

var connectionData = RelayConnectionData.FromByteArray(allocation.ConnectionData);
var key = RelayHMACKey.FromByteArray(allocation.Key);


Expand Down Expand Up @@ -385,7 +367,7 @@ public override void Init()
m_MessageBuffer = new byte[m_MessageBufferSize];
#if ENABLE_RELAY_SERVICE
if (m_ProtocolType == ProtocolType.RelayUnityTransport) {
Unity.Services.Relay.Configuration.BasePath = m_RelayServer;
Unity.Services.Relay.RelayService.Configuration.BasePath = m_RelayServer;
UnityServices.Initialize();
}
#endif
Expand Down
10 changes: 5 additions & 5 deletions testproject/Assets/Scripts/ConnectionModeScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ private void Start()
if (NetworkManager.Singleton.GetComponent<UTPTransport>().Protocol == UTPTransport.ProtocolType.RelayUnityTransport)
{
m_JoinCodeInput.SetActive(true);
m_ConnectionModeButtons.SetActive(false || Authentication.IsSignedIn);
m_AuthenticationButtons.SetActive(NetworkManager.Singleton && !NetworkManager.Singleton.IsListening && !Authentication.IsSignedIn);
m_ConnectionModeButtons.SetActive(false || AuthenticationService.Instance.IsSignedIn);
m_AuthenticationButtons.SetActive(NetworkManager.Singleton && !NetworkManager.Singleton.IsListening && !AuthenticationService.Instance.IsSignedIn);
}
else
#endif
Expand Down Expand Up @@ -128,10 +128,10 @@ public async void OnSignIn()
{
#if ENABLE_RELAY_SERVICE
await UnityServices.Initialize();
await Authentication.SignInAnonymously();
Debug.Log($"Logging in with PlayerID {Authentication.PlayerId}");
await AuthenticationService.Instance.SignInAnonymouslyAsync();
Debug.Log($"Logging in with PlayerID {AuthenticationService.Instance.PlayerId}");

if (Authentication.IsSignedIn)
if (AuthenticationService.Instance.IsSignedIn)
{
m_ConnectionModeButtons.SetActive(true);
m_AuthenticationButtons.SetActive(false);
Expand Down
6 changes: 3 additions & 3 deletions testproject/Assets/Scripts/UIController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ public async void OnSignIn()
#if ENABLE_RELAY_SERVICE
await UnityServices.Initialize();
Debug.Log("OnSignIn");
await Authentication.SignInAnonymously();
Debug.Log($"Logging in with PlayerID {Authentication.PlayerId}");
await AuthenticationService.Instance.SignInAnonymouslyAsync();
Debug.Log($"Logging in with PlayerID {AuthenticationService.Instance.PlayerId}");

if (Authentication.IsSignedIn) {
if (AuthenticationService.Instance.IsSignedIn) {
ButtonsRoot.SetActive(true);
JoinCode.SetActive(true);
AuthButton.SetActive(false);
Expand Down
6 changes: 3 additions & 3 deletions testproject/Packages/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
"com.unity.multiplayer.mlapi": "file:../../com.unity.multiplayer.mlapi",
"com.unity.multiplayer.transport.utp": "file:../../com.unity.multiplayer.transport.utp",
"com.unity.package-validation-suite": "0.19.2-preview",
"com.unity.services.authentication": "0.3.1-preview",
"com.unity.services.core": "0.1.0-preview",
"com.unity.services.relay": "0.0.1-preview.3",
"com.unity.services.authentication": "0.5.0-preview",
"com.unity.services.core": "1.1.0-pre.2",
"com.unity.services.relay": "0.0.1-preview.5",
"com.unity.test-framework": "1.1.24",
"com.unity.textmeshpro": "3.0.4",
"com.unity.timeline": "1.5.2",
Expand Down
30 changes: 6 additions & 24 deletions testproject/Packages/packages-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,34 +116,32 @@
"url": "https://packages.unity.com"
},
"com.unity.services.authentication": {
"version": "0.3.1-preview",
"version": "0.5.0-preview",
"depth": 0,
"source": "registry",
"dependencies": {
"nuget.moq": "1.0.0",
"com.unity.nuget.newtonsoft-json": "2.0.0",
"com.unity.services.core": "0.2.0-preview",
"com.unity.services.core": "1.1.0-pre.2",
"com.unity.modules.unitywebrequest": "1.0.0"
},
"url": "https://artifactory.prd.cds.internal.unity3d.com/artifactory/api/npm/upm-candidates"
},
"com.unity.services.core": {
"version": "0.2.0-preview",
"depth": 1,
"version": "1.1.0-pre.2",
"depth": 0,
"source": "registry",
"dependencies": {
"nuget.moq": "1.0.0",
"com.unity.modules.unitywebrequest": "1.0.0",
"com.unity.nuget.newtonsoft-json": "2.0.0"
},
"url": "https://artifactory.prd.cds.internal.unity3d.com/artifactory/api/npm/upm-candidates"
},
"com.unity.services.relay": {
"version": "0.0.1-preview.3",
"version": "0.0.1-preview.5",
"depth": 0,
"source": "registry",
"dependencies": {
"com.unity.services.core": "0.2.0-preview",
"com.unity.services.core": "1.1.0-pre.2",
"com.unity.modules.unitywebrequest": "1.0.0",
"com.unity.modules.unitywebrequestassetbundle": "1.0.0",
"com.unity.modules.unitywebrequestaudio": "1.0.0",
Expand Down Expand Up @@ -205,22 +203,6 @@
"com.unity.modules.imgui": "1.0.0"
}
},
"nuget.castle-core": {
"version": "1.0.1",
"depth": 2,
"source": "registry",
"dependencies": {},
"url": "https://packages.unity.com"
},
"nuget.moq": {
"version": "1.0.0",
"depth": 1,
"source": "registry",
"dependencies": {
"nuget.castle-core": "1.0.1"
},
"url": "https://packages.unity.com"
},
"com.unity.modules.ai": {
"version": "1.0.0",
"depth": 0,
Expand Down
2 changes: 1 addition & 1 deletion testproject/ProjectSettings/ProjectSettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ PlayerSettings:
webGLThreadsSupport: 0
webGLDecompressionFallback: 0
scriptingDefineSymbols:
1: AUTHENTICATION_TESTING_STAGING_UAS;RELAY_BIGENDIAN
1: AUTHENTICATION_TESTING_STAGING_UAS;
additionalCompilerArguments: {}
platformArchitecture: {}
scriptingBackend: {}
Expand Down