浏览代码

Merge branch 'main' into master-staging

/main
Jacob 2 年前
当前提交
8f1e5aac
共有 6 个文件被更改,包括 24 次插入24 次删除
  1. 4
      Assets/Scripts/GameLobby/NGO/RelayNGOUtpSetup.cs
  2. 22
      Assets/Scripts/GameLobby/Relay/RelayUtpSetup.cs
  3. 10
      Assets/Scripts/GameLobby/Tests/PlayMode/RelayRoundTripTests.cs
  4. 2
      Assets/Scripts/GameLobby/Tests/PlayMode/UtpTests.cs
  5. 10
      README.md

4
Assets/Scripts/GameLobby/NGO/RelayNGOUtpSetup.cs


{
RelayAPIInterface.GetJoinCodeAsync(allocation.AllocationId, OnRelayCode);
bool isSecure = false;
var endpoint = RelayUtpSetup.GetEndpointForAllocation(allocation.ServerEndpoints, allocation.RelayServer.IpV4, allocation.RelayServer.Port, out isSecure);
var endpoint = RelayUtpSetup.GetEndpointForAllocation(allocation.ServerEndpoints, out isSecure);
m_setupInGame.SetRelayServerData(RelayUtpSetup.AddressFromEndpoint(endpoint), endpoint.Port, allocation.AllocationIdBytes, allocation.Key, allocation.ConnectionData, allocation.ConnectionData, isSecure);
m_onJoin?.Invoke();
}

if (joinAllocation == null || this == null) // The returned JoinAllocation is null if allocation failed. This would be destroyed already if you quit the lobby while Relay is connecting.
return;
bool isSecure = false;
var endpoint = RelayUtpSetup.GetEndpointForAllocation(joinAllocation.ServerEndpoints, joinAllocation.RelayServer.IpV4, joinAllocation.RelayServer.Port, out isSecure);
var endpoint = RelayUtpSetup.GetEndpointForAllocation(joinAllocation.ServerEndpoints, out isSecure);
m_setupInGame.SetRelayServerData(RelayUtpSetup.AddressFromEndpoint(endpoint), endpoint.Port, joinAllocation.AllocationIdBytes, joinAllocation.Key, joinAllocation.ConnectionData, joinAllocation.HostConnectionData, isSecure);
m_onJoin?.Invoke();
}

22
Assets/Scripts/GameLobby/Relay/RelayUtpSetup.cs


/// Determine the server endpoint for connecting to the Relay server, for either an Allocation or a JoinAllocation.
/// If DTLS encryption is available, and there's a secure server endpoint available, use that as a secure connection. Otherwise, just connect to the Relay IP unsecured.
/// </summary>
public static NetworkEndPoint GetEndpointForAllocation(List<RelayServerEndpoint> endpoints, string ip, int port, out bool isSecure)
public static NetworkEndPoint GetEndpointForAllocation(List<RelayServerEndpoint> endpoints, out bool isSecure)
foreach (RelayServerEndpoint endpoint in endpoints)
{
if (endpoint.Secure && endpoint.Network == RelayServerEndpoint.NetworkOptions.Udp)
{
isSecure = true;
return NetworkEndPoint.Parse(endpoint.Host, (ushort)endpoint.Port);
}
}
isSecure = true;
var endpoint = endpoints.Find(e => e.ConnectionType == "dtls");
#else
isSecure = false;
var endpoint = endpoints.Find(e => e.ConnectionType == "udp");
isSecure = false;
return NetworkEndPoint.Parse(ip, (ushort)port);
return NetworkEndPoint.Parse(endpoint.Host, (ushort)endpoint.Port);
}
/// <summary>

m_allocation = allocation;
RelayAPIInterface.GetJoinCodeAsync(allocation.AllocationId, OnRelayCode);
bool isSecure = false;
m_endpointForServer = GetEndpointForAllocation(allocation.ServerEndpoints, allocation.RelayServer.IpV4, allocation.RelayServer.Port, out isSecure);
m_endpointForServer = GetEndpointForAllocation(allocation.ServerEndpoints, out isSecure);
BindToAllocation(m_endpointForServer, allocation.AllocationIdBytes, allocation.ConnectionData, allocation.ConnectionData, allocation.Key, 16, isSecure);
}

return;
m_allocation = joinAllocation;
bool isSecure = false;
m_endpointForServer = GetEndpointForAllocation(joinAllocation.ServerEndpoints, joinAllocation.RelayServer.IpV4, joinAllocation.RelayServer.Port, out isSecure);
m_endpointForServer = GetEndpointForAllocation(joinAllocation.ServerEndpoints, out isSecure);
BindToAllocation(m_endpointForServer, joinAllocation.AllocationIdBytes, joinAllocation.ConnectionData, joinAllocation.HostConnectionData, joinAllocation.Key, 1, isSecure);
m_localLobby.RelayServer = new ServerAddress(AddressFromEndpoint(m_endpointForServer), m_endpointForServer.Port);
}

10
Assets/Scripts/GameLobby/Tests/PlayMode/RelayRoundTripTests.cs


Assert.Greater(timeout, 0, "Timeout Check (Allocate)");
Guid allocationId = allocation.AllocationId;
var allocationIP = allocation.RelayServer.IpV4;
var allocationPort = allocation.RelayServer.Port;
var endpoint = allocation.ServerEndpoints.Find(e => e.ConnectionType == "udp");
var allocationIP = endpoint.Host;
var allocationPort = endpoint.Port;
Assert.NotNull(allocationId);
Assert.NotNull(allocationIP);
Assert.NotNull(allocationPort);

}
Assert.Greater(timeout, 0, "Timeout Check (Join)");
var codeIp = joinResponse.RelayServer.IpV4;
var codePort = joinResponse.RelayServer.Port;
var joinEndpoint = joinResponse.ServerEndpoints.Find(e => e.ConnectionType == "udp");
var codeIp = joinEndpoint.Host;
var codePort = joinEndpoint.Port;
Assert.AreEqual(codeIp, allocationIP);
Assert.AreEqual(codePort, allocationPort);
}

2
Assets/Scripts/GameLobby/Tests/PlayMode/UtpTests.cs


void OnAllocation(Allocation allocation)
{
bool isSecure = false;
NetworkEndPoint endpoint = GetEndpointForAllocation(allocation.ServerEndpoints, allocation.RelayServer.IpV4, allocation.RelayServer.Port, out isSecure);
NetworkEndPoint endpoint = GetEndpointForAllocation(allocation.ServerEndpoints, out isSecure);
OnGetEndpoint?.Invoke(endpoint, isSecure);
// The allocation will be cleaned up automatically, since we won't be pinging it regularly.
}

10
README.md


The Lobby service allows developers to create lobbies and share data between players before a real-time network connection is established. It simplifies the first step in connecting users to other services such as Relay and provides tools to allow players to find other lobbies.
The Lobby documentation contains code samples and additional information about the service. It includes comprehensive details for using Lobby along with additional code samples, and it might help you better understand the Game Lobby Sample: [http://documentation.cloud.unity3d.com/en/articles/5371715-unity-lobby-service](http://documentation.cloud.unity3d.com/en/articles/5371715-unity-lobby-service)
The Lobby documentation contains code samples and additional information about the service. It includes comprehensive details for using Lobby along with additional code samples, and it might help you better understand the Game Lobby Sample:
[docs.unity.com/lobby](http:/docs.unity.com/lobby)
[https://dashboard.unity3d.com/lobby](http://documentation.cloud.unity3d.com/en/articles/5371715-unity-lobby-service)
[https://dashboard.unity3d.com/lobby](https://dashboard.unity3d.com/lobby)
#### **Relay**

The Relay documentation contains code samples and additional information about the service. It includes comprehensive details for using Relay along with additional code samples, and it might help you better understand the Game Lobby Sample:
[http://documentation.cloud.unity3d.com/en/articles/5371723-relay-overview](http://documentation.cloud.unity3d.com/en/articles/5371723-relay-overview)
[docs.unity.com/relay](http://docs.unity.com/relay)
[https://dashboard.unity3d.com/relay](http://documentation.cloud.unity3d.com/en/articles/5371723-relay-overview)
[https://dashboard.unity3d.com/relay](https://dashboard.unity3d.com/relay)
In this sample, once players are connected to a lobby, they are connected through Relay to set up real-time data transfer over UTP. Lobby and Relay both depend on Auth for credentials. This sample uses Auth’s anonymous login feature to create semi-permanent credentials that are unique to each player but do not require developers to maintain a persistent account for them. \

正在加载...
取消
保存