Skip to content
Merged
1 change: 1 addition & 0 deletions com.unity.netcode.gameobjects/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Additional documentation and release notes are available at [Multiplayer Documen

### Added

- When using UnityTransport >=2.4 and Unity >= 6000.1.0a1, SetConnectionData will accept a fully qualified hostname instead of an IP as a connect address on the client side. (#3441)

### Fixed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,7 @@ private static NetworkEndpoint ParseNetworkEndpoint(string ip, ushort port, bool
if (!NetworkEndpoint.TryParse(ip, port, out endpoint, NetworkFamily.Ipv4) &&
!NetworkEndpoint.TryParse(ip, port, out endpoint, NetworkFamily.Ipv6))
{
if (!silent)
{
Debug.LogError($"Invalid network endpoint: {ip}:{port}.");
}
return default;
}

return endpoint;
Expand Down Expand Up @@ -512,8 +509,15 @@ private bool ClientBindAndConnect()
// Verify the endpoint is valid before proceeding
if (serverEndpoint.Family == NetworkFamily.Invalid)
{
#if HOSTNAME_RESOLUTION_AVAILABLE && UTP_TRANSPORT_2_4_ABOVE
// If it's not valid, try to treat it like a URL.
InitDriver();
m_Driver.Connect(ConnectionData.Address, ConnectionData.Port);
return true;
#else
Debug.LogError($"Target server network address ({ConnectionData.Address}) is {nameof(NetworkFamily.Invalid)}!");
return false;
#endif
}

InitDriver();
Expand Down Expand Up @@ -625,7 +629,7 @@ public void SetClientRelayData(string ipAddress, ushort port, byte[] allocationI
/// <summary>
/// Sets IP and Port information. This will be ignored if using the Unity Relay and you should call <see cref="SetRelayServerData"/>
/// </summary>
/// <param name="ipv4Address">The remote IP address (despite the name, can be an IPv6 address)</param>
/// <param name="ipv4Address">The remote IP address (despite the name, can be an IPv6 address or a domain name)</param>
/// <param name="port">The remote port</param>
/// <param name="listenAddress">The local listen address</param>
public void SetConnectionData(string ipv4Address, ushort port, string listenAddress = null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@
"name": "Unity",
"expression": "6000.0.11f1",
"define": "COM_UNITY_MODULES_PHYSICS2D_LINEAR"
},
{
"name": "com.unity.transport",
"expression": "2.4.0",
"define": "UTP_TRANSPORT_2_4_ABOVE"
},
{
"name": "Unity",
"expression": "6000.1.0a1",
"define": "HOSTNAME_RESOLUTION_AVAILABLE"
}
],
"noEngineReferences": false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ public void UnityTransport_RestartSucceedsAfterFailure()

Assert.False(transport.StartServer());

LogAssert.Expect(LogType.Error, "Invalid network endpoint: 127.0.0.:4242.");
LogAssert.Expect(LogType.Error, "Network listen address (127.0.0.) is Invalid!");

transport.SetConnectionData("127.0.0.1", 4242, "127.0.0.1");
Expand All @@ -153,22 +152,6 @@ public void UnityTransport_StartServerWithoutAddresses()
transport.Shutdown();
}

// Check that StartClient returns false with bad connection data.
[Test]
public void UnityTransport_StartClientFailsWithBadAddress()
{
UnityTransport transport = new GameObject().AddComponent<UnityTransport>();
transport.Initialize();

transport.SetConnectionData("foobar", 4242);
Assert.False(transport.StartClient());

LogAssert.Expect(LogType.Error, "Invalid network endpoint: foobar:4242.");
LogAssert.Expect(LogType.Error, "Target server network address (foobar) is Invalid!");

transport.Shutdown();
}

[Test]
public void UnityTransport_EmptySecurityStringsShouldThrow([Values("", null)] string cert, [Values("", null)] string secret)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,6 @@ public IEnumerator Cleanup()
yield return null;
}

// Check that invalid endpoint addresses are detected and return false if detected
[Test]
public void DetectInvalidEndpoint()
{
using var netcodeLogAssert = new NetcodeLogAssert(true);
InitializeTransport(out m_Server, out m_ServerEvents);
InitializeTransport(out m_Clients[0], out m_ClientsEvents[0]);
m_Server.ConnectionData.Address = "Fubar";
m_Server.ConnectionData.ServerListenAddress = "Fubar";
m_Clients[0].ConnectionData.Address = "MoreFubar";
Assert.False(m_Server.StartServer(), "Server failed to detect invalid endpoint!");
Assert.False(m_Clients[0].StartClient(), "Client failed to detect invalid endpoint!");
netcodeLogAssert.LogWasReceived(LogType.Error, $"Network listen address ({m_Server.ConnectionData.Address}) is Invalid!");
netcodeLogAssert.LogWasReceived(LogType.Error, $"Target server network address ({m_Clients[0].ConnectionData.Address}) is Invalid!");
UnityTransportTestComponent.CleanUp();
}

// Check connection with a single client.
[UnityTest]
public IEnumerator ConnectSingleClient()
Expand Down