fix: clients unable to connect via hostname sometimes

This commit is contained in:
Syntriax 2025-07-20 18:36:27 +03:00
parent 1bf8238925
commit fcc5350b56
2 changed files with 14 additions and 2 deletions

2
Engine

@ -1 +1 @@
Subproject commit c8bb991865c8efc99786a9a10767f08ce7b8709c
Subproject commit 83b155fc5e8fd1892278876cb90e10dcb64e2154

View File

@ -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;
}