net: resolve ACDREAM_TEST_HOST via DNS, not just IPAddress.Parse
Allows hostnames like `play.coldeve.ac` in ACDREAM_TEST_HOST. Previously the env var fed `IPAddress.Parse` directly and threw "An invalid IP address was specified" on anything that wasn't a literal dotted IP. Now: `IPAddress.TryParse` first (fast path, unchanged for 127.0.0.1 / literal IPs); on failure, fall back to `Dns.GetHostAddresses` and prefer the first IPv4 address (ACE + retail both use IPv4 UDP exclusively). Tested against `play.coldeve.ac:9000` — resolves to 51.79.80.150, handshake succeeds, login to character Barris works end-to-end.
This commit is contained in:
parent
99ce541fd7
commit
d1c7d4a8b6
1 changed files with 15 additions and 1 deletions
|
|
@ -1066,7 +1066,21 @@ public sealed class GameWindow : IDisposable
|
|||
|
||||
try
|
||||
{
|
||||
var endpoint = new System.Net.IPEndPoint(System.Net.IPAddress.Parse(host), int.Parse(portStr));
|
||||
// Resolve DNS names (e.g. play.coldeve.ac) as well as literal
|
||||
// IP addresses. `IPAddress.Parse` throws on hostnames; fall
|
||||
// back to `Dns.GetHostAddresses` and prefer IPv4 (ACE + retail
|
||||
// use IPv4 UDP exclusively).
|
||||
System.Net.IPAddress ip;
|
||||
if (!System.Net.IPAddress.TryParse(host, out ip!))
|
||||
{
|
||||
var addrs = System.Net.Dns.GetHostAddresses(host);
|
||||
ip = System.Array.Find(addrs,
|
||||
a => a.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
|
||||
?? (addrs.Length > 0 ? addrs[0] : throw new System.Exception(
|
||||
$"DNS resolved no addresses for '{host}'"));
|
||||
Console.WriteLine($"live: resolved {host} → {ip}");
|
||||
}
|
||||
var endpoint = new System.Net.IPEndPoint(ip, int.Parse(portStr));
|
||||
Console.WriteLine($"live: connecting to {endpoint} as {user}");
|
||||
_liveSession = new AcDream.Core.Net.WorldSession(endpoint);
|
||||
_liveSession.EntitySpawned += OnLiveEntitySpawned;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue