From fcc5350b56f6d74613bbd67678d5cb61894d1e4e Mon Sep 17 00:00:00 2001 From: Syntriax Date: Sun, 20 Jul 2025 18:36:27 +0300 Subject: [PATCH] fix: clients unable to connect via hostname sometimes --- Engine | 2 +- Shared/Network/LiteNetLib/LiteNetLibClient.cs | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Engine b/Engine index c8bb991..83b155f 160000 --- a/Engine +++ b/Engine @@ -1 +1 @@ -Subproject commit c8bb991865c8efc99786a9a10767f08ce7b8709c +Subproject commit 83b155fc5e8fd1892278876cb90e10dcb64e2154 diff --git a/Shared/Network/LiteNetLib/LiteNetLibClient.cs b/Shared/Network/LiteNetLib/LiteNetLibClient.cs index 8bc1c52..95af97b 100644 --- a/Shared/Network/LiteNetLib/LiteNetLibClient.cs +++ b/Shared/Network/LiteNetLib/LiteNetLibClient.cs @@ -1,3 +1,6 @@ +using System; +using System.Linq; +using System.Net.Sockets; using System.Threading; using System.Threading.Tasks; @@ -24,9 +27,18 @@ public class LiteNetLibClient : LiteNetLibCommunicatorBase, INetworkCommunicator password ??= string.Empty; + // Okay, for some reason sometimes LiteNetLib goes dumb when the server hostname has IPv6 address as well as IPv4 + // but the client doesn't support IPv6, it still tries to use the v6 unless we explicitly tell the ip to connect to, + // which fails to connect... So for the time being I am preferring IPv4 below over IPv6 for clients. + // TODO: I think this is something that happens on Linux only? I need to check on Windows as well just to be sure. + System.Net.IPAddress[] addresses = System.Net.Dns.GetHostAddresses(address); + string connectionAddress = addresses.FirstOrDefault(a => a.AddressFamily == AddressFamily.InterNetwork, addresses[0]).ToString(); + logger?.Log(this, $"Connecting to server at '{address}:{port}' with password '{password}'"); + logger?.Log(this, $"Resolved address for {address}: {connectionAddress}"); + Manager.Start(); - Manager.Connect(address, port, password); + Manager.Connect(connectionAddress, port, password); return this; }