Skip to content

Commit 6cc324b

Browse files
fix
NGO v1.x compatibility for UTP v2.x
1 parent 2870963 commit 6cc324b

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

com.unity.netcode.gameobjects/Runtime/Transports/UTP/UnityTransport.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,6 +1215,31 @@ public override ulong GetCurrentRtt(ulong clientId)
12151215
return (ulong)ExtractRtt(ParseClientId(clientId));
12161216
}
12171217

1218+
#if UTP_TRANSPORT_2_0_ABOVE
1219+
/// <summary>
1220+
/// Provides the <see cref="NetworkEndpoint"/> for the NGO client identifier specified.
1221+
/// </summary>
1222+
/// <remarks>
1223+
/// - This is only really useful for direct connections.
1224+
/// - Relay connections and clients connected using a distributed authority network topology will not provide the client's actual endpoint information.
1225+
/// - For LAN topologies this should work as long as it is a direct connection and not a relay connection.
1226+
/// </remarks>
1227+
/// <param name="clientId">NGO client identifier to get endpoint information about.</param>
1228+
/// <returns><see cref="NetworkEndpoint"/></returns>
1229+
public NetworkEndpoint GetEndpoint(ulong clientId)
1230+
{
1231+
if (m_Driver.IsCreated && NetworkManager != null && NetworkManager.IsListening)
1232+
{
1233+
var transportId = NetworkManager.ConnectionManager.ClientIdToTransportId(clientId);
1234+
var networkConnection = ParseClientId(transportId);
1235+
if (m_Driver.GetConnectionState(networkConnection) == NetworkConnection.State.Connected)
1236+
{
1237+
return m_Driver.GetRemoteEndpoint(networkConnection);
1238+
}
1239+
}
1240+
return new NetworkEndpoint();
1241+
}
1242+
#else
12181243
/// <summary>
12191244
/// Provides the <see cref="NetworkEndpoint"/> for the NGO client identifier specified.
12201245
/// </summary>
@@ -1238,6 +1263,8 @@ public NetworkEndpoint GetEndpoint(ulong clientId)
12381263
}
12391264
return new NetworkEndpoint();
12401265
}
1266+
#endif
1267+
12411268

12421269
/// <summary>
12431270
/// Initializes the transport

com.unity.netcode.gameobjects/Tests/Runtime/NetworkManagerTransportTests.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,14 @@ internal class TransportEndpointTests : NetcodeIntegrationTest
173173
public IEnumerator GetEndpointReportedCorrectly()
174174
{
175175
var serverUnityTransport = m_ServerNetworkManager.NetworkConfig.NetworkTransport as UnityTransport;
176+
177+
#if UTP_TRANSPORT_2_0_ABOVE
178+
var serverEndpoint = new NetworkEndpoint();
179+
var clientEndpoint = new NetworkEndpoint();
180+
#else
176181
var serverEndpoint = new NetworkEndPoint();
177182
var clientEndpoint = new NetworkEndPoint();
183+
#endif
178184
foreach (var client in m_ClientNetworkManagers)
179185
{
180186
var unityTransport = client.NetworkConfig.NetworkTransport as UnityTransport;

0 commit comments

Comments
 (0)