fix: clients unable to connect via hostname sometimes
This commit is contained in:
2
Engine
2
Engine
Submodule Engine updated: c8bb991865...83b155fc5e
@@ -1,3 +1,6 @@
|
|||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net.Sockets;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@@ -24,9 +27,18 @@ public class LiteNetLibClient : LiteNetLibCommunicatorBase, INetworkCommunicator
|
|||||||
|
|
||||||
password ??= string.Empty;
|
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, $"Connecting to server at '{address}:{port}' with password '{password}'");
|
||||||
|
logger?.Log(this, $"Resolved address for {address}: {connectionAddress}");
|
||||||
|
|
||||||
Manager.Start();
|
Manager.Start();
|
||||||
Manager.Connect(address, port, password);
|
Manager.Connect(connectionAddress, port, password);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user