Core/Realms: Minor refactor to realm address storage
Port From (https://github.com/TrinityCore/TrinityCore/commit/cc6dba1376905456062d1ade8adcbaed4f8f484e)
This commit is contained in:
@@ -120,9 +120,9 @@ namespace BNetServer
|
||||
public string GetHostnameForClient(IPEndPoint address)
|
||||
{
|
||||
if (IPAddress.IsLoopback(address.Address))
|
||||
return _hostnames[0];
|
||||
return _hostnames[1];
|
||||
|
||||
return _hostnames[1];
|
||||
return _hostnames[0];
|
||||
}
|
||||
|
||||
public int GetPort() { return _port; }
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
using Framework.Constants;
|
||||
using Framework.Realm;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
|
||||
public class Realm : IEquatable<Realm>
|
||||
{
|
||||
@@ -16,28 +16,13 @@ public class Realm : IEquatable<Realm>
|
||||
NormalizedName = NormalizedName.Replace(" ", "");
|
||||
}
|
||||
|
||||
public IPEndPoint GetAddressForClient(IPAddress clientAddr)
|
||||
public IPAddress GetAddressForClient(IPAddress clientAddr)
|
||||
{
|
||||
IPAddress realmIp = ExternalAddress;
|
||||
|
||||
// Attempt to send best address for client
|
||||
if (IPAddress.IsLoopback(clientAddr))
|
||||
{
|
||||
// Try guessing if realm is also connected locally
|
||||
if (IPAddress.IsLoopback(LocalAddress) || IPAddress.IsLoopback(ExternalAddress))
|
||||
realmIp = clientAddr;
|
||||
else
|
||||
{
|
||||
// Assume that user connecting from the machine that authserver is located on
|
||||
// has all realms available in his local network
|
||||
realmIp = LocalAddress;
|
||||
}
|
||||
}
|
||||
return Addresses[1];
|
||||
|
||||
IPEndPoint endpoint = new(realmIp, Port);
|
||||
|
||||
// Return external IP
|
||||
return endpoint;
|
||||
return Addresses[0];
|
||||
}
|
||||
|
||||
public uint GetConfigId()
|
||||
@@ -57,9 +42,7 @@ public class Realm : IEquatable<Realm>
|
||||
|
||||
public bool Equals(Realm other)
|
||||
{
|
||||
return other.ExternalAddress.Equals(ExternalAddress)
|
||||
&& other.LocalAddress.Equals(LocalAddress)
|
||||
&& other.Port == Port
|
||||
return other.Port == Port
|
||||
&& other.Name == Name
|
||||
&& other.Type == Type
|
||||
&& other.Flags == Flags
|
||||
@@ -70,13 +53,12 @@ public class Realm : IEquatable<Realm>
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return new { ExternalAddress, LocalAddress, Port, Name, Type, Flags, Timezone, AllowedSecurityLevel, PopulationLevel }.GetHashCode();
|
||||
return new { Port, Name, Type, Flags, Timezone, AllowedSecurityLevel, PopulationLevel }.GetHashCode();
|
||||
}
|
||||
|
||||
public RealmId Id;
|
||||
public uint Build;
|
||||
public IPAddress ExternalAddress;
|
||||
public IPAddress LocalAddress;
|
||||
public List<IPAddress> Addresses = new();
|
||||
public ushort Port;
|
||||
public string Name;
|
||||
public string NormalizedName;
|
||||
|
||||
@@ -92,8 +92,8 @@ public class RealmManager : Singleton<RealmManager>
|
||||
var realm = new Realm();
|
||||
uint realmId = result.Read<uint>(0);
|
||||
realm.Name = result.Read<string>(1);
|
||||
realm.ExternalAddress = IPAddress.Parse(result.Read<string>(2));
|
||||
realm.LocalAddress = IPAddress.Parse(result.Read<string>(3));
|
||||
realm.Addresses.Add(IPAddress.Parse(result.Read<string>(2)));
|
||||
realm.Addresses.Add(IPAddress.Parse(result.Read<string>(3)));
|
||||
realm.Port = result.Read<ushort>(4);
|
||||
RealmType realmType = (RealmType)result.Read<byte>(5);
|
||||
if (realmType == RealmType.FFAPVP)
|
||||
@@ -120,9 +120,9 @@ public class RealmManager : Singleton<RealmManager>
|
||||
_subRegions.Add(subRegion);
|
||||
|
||||
if (!existingRealms.ContainsKey(realm.Id))
|
||||
Log.outInfo(LogFilter.Realmlist, "Added realm \"{0}\" at {1}:{2}", realm.Name, realm.ExternalAddress.ToString(), realm.Port);
|
||||
Log.outInfo(LogFilter.Realmlist, "Added realm \"{0}\" at {1}:{2}", realm.Name, realm.Addresses[0].ToString(), realm.Port);
|
||||
else
|
||||
Log.outDebug(LogFilter.Realmlist, "Updating realm \"{0}\" at {1}:{2}", realm.Name, realm.ExternalAddress.ToString(), realm.Port);
|
||||
Log.outDebug(LogFilter.Realmlist, "Updating realm \"{0}\" at {1}:{2}", realm.Name, realm.Addresses[0].ToString(), realm.Port);
|
||||
|
||||
existingRealms.Remove(realm.Id);
|
||||
}
|
||||
|
||||
@@ -490,12 +490,12 @@ namespace Game
|
||||
|
||||
if (instanceAddress.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
|
||||
{
|
||||
connectTo.Payload.Where.IPv4 = instanceAddress.Address.GetAddressBytes();
|
||||
connectTo.Payload.Where.IPv4 = instanceAddress.GetAddressBytes();
|
||||
connectTo.Payload.Where.Type = ConnectTo.AddressType.IPv4;
|
||||
}
|
||||
else
|
||||
{
|
||||
connectTo.Payload.Where.IPv6 = instanceAddress.Address.GetAddressBytes();
|
||||
connectTo.Payload.Where.IPv6 = instanceAddress.GetAddressBytes();
|
||||
connectTo.Payload.Where.Type = ConnectTo.AddressType.IPv6;
|
||||
}
|
||||
|
||||
|
||||
@@ -2443,8 +2443,8 @@ namespace Game
|
||||
return false;
|
||||
|
||||
_realm.SetName(result.Read<string>(1));
|
||||
_realm.ExternalAddress = System.Net.IPAddress.Parse(result.Read<string>(2));
|
||||
_realm.LocalAddress = System.Net.IPAddress.Parse(result.Read<string>(3));
|
||||
_realm.Addresses.Add(System.Net.IPAddress.Parse(result.Read<string>(2)));
|
||||
_realm.Addresses.Add(System.Net.IPAddress.Parse(result.Read<string>(3)));
|
||||
_realm.Port = result.Read<ushort>(4);
|
||||
_realm.Type = result.Read<byte>(5);
|
||||
_realm.Flags = (RealmFlags)result.Read<byte>(6);
|
||||
|
||||
Reference in New Issue
Block a user