fix: Ensure server listing address is used when set in config (#1960)

This commit is contained in:
Joshua Kappers 2024-09-22 00:34:56 -05:00 committed by GitHub
parent 2a7aa1905b
commit 3a3c651b85
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -41,6 +41,8 @@ namespace Server.Misc
public static bool AutoDetect { get; private set; }
private static bool _useServerListingAddressConfig { get; set; }
public static void Configure()
{
Address = ServerConfiguration.GetOrUpdateSetting("serverListing.address", null);
@ -60,6 +62,13 @@ namespace Server.Misc
else
{
Resolve(Address, out _publicAddress);
if (_publicAddress != null)
{
_useServerListingAddressConfig = true;
logger.Information("Server listing address set from config: {address}", _publicAddress);
}
}
}
@ -79,9 +88,14 @@ namespace Server.Misc
var localAddress = ipep.Address;
var localPort = ipep.Port;
if (IsPrivateNetwork(localAddress))
if (_useServerListingAddressConfig)
{
localAddress = _publicAddress;
}
else if (IsPrivateNetwork(localAddress))
{
ipep = (IPEndPoint)ns.Connection.RemoteEndPoint;
if (ipep == null || !IsPrivateNetwork(ipep.Address) && _publicAddress != null)
{
localAddress = _publicAddress;