Core/Network: Refactor local/remote ip address selection code and allow using hostnames in LoginREST bnetserver config options

Port From (https://github.com/TrinityCore/TrinityCore/commit/6be536a73bc8a6e331ce20e7d19e2ea56b99b4d0)
This commit is contained in:
hondacrx
2023-08-28 11:15:57 -04:00
parent 0e3b271db3
commit c9ab9e4635
7 changed files with 49 additions and 51 deletions
+2 -2
View File
@@ -37,10 +37,10 @@ namespace Framework.Database
fileName = @"/sql/base/characters_database.sql";
break;
case "WorldDatabase":
fileName = @"/sql/TDB_full_world_1007.23041_2023_04_02.sql";
fileName = @"/sql/TDB_full_world_1015.23071_2023_07_14.sql";
break;
case "HotfixDatabase":
fileName = @"/sql/TDB_full_hotfixes_1007.23041_2023_04_02.sql";
fileName = @"/sql/TDB_full_hotfixes_1015.23071_2023_07_14.sql";
break;
}
@@ -10,7 +10,7 @@ namespace Framework.Database
const string BnetAccountInfo = "ba.id, ba.email, ba.locked, ba.lock_country, ba.last_ip, ba.LoginTicketExpiry, bab.unbandate > UNIX_TIMESTAMP() OR bab.unbandate = bab.bandate, bab.unbandate = bab.bandate";
const string BnetGameAccountInfo = "a.id, a.username, ab.unbandate, ab.unbandate = ab.bandate, aa.SecurityLevel";
PrepareStatement(LoginStatements.SEL_REALMLIST, "SELECT id, name, address, localAddress, localSubnetMask, port, icon, flag, timezone, allowedSecurityLevel, population, gamebuild, Region, Battlegroup FROM realmlist WHERE flag <> 3 ORDER BY name");
PrepareStatement(LoginStatements.SEL_REALMLIST, "SELECT id, name, address, localAddress, port, icon, flag, timezone, allowedSecurityLevel, population, gamebuild, Region, Battlegroup FROM realmlist WHERE flag <> 3 ORDER BY name");
PrepareStatement(LoginStatements.DelExpiredIpBans, "DELETE FROM ip_banned WHERE unbandate<>bandate AND unbandate<=UNIX_TIMESTAMP()");
PrepareStatement(LoginStatements.UpdExpiredAccountBans, "UPDATE account_banned SET active = 0 WHERE active = 1 AND unbandate<>bandate AND unbandate<=UNIX_TIMESTAMP()");
PrepareStatement(LoginStatements.SelIpInfo, "SELECT unbandate > UNIX_TIMESTAMP() OR unbandate = bandate AS banned, NULL as country FROM ip_banned WHERE ip = ?");
+2 -11
View File
@@ -18,7 +18,7 @@ public class Realm : IEquatable<Realm>
public IPEndPoint GetAddressForClient(IPAddress clientAddr)
{
IPAddress realmIp;
IPAddress realmIp = ExternalAddress;
// Attempt to send best address for client
if (IPAddress.IsLoopback(clientAddr))
@@ -33,13 +33,6 @@ public class Realm : IEquatable<Realm>
realmIp = LocalAddress;
}
}
else
{
if (clientAddr.AddressFamily == AddressFamily.InterNetwork && clientAddr.GetNetworkAddress(LocalSubnetMask).Equals(LocalAddress.GetNetworkAddress(LocalSubnetMask)))
realmIp = LocalAddress;
else
realmIp = ExternalAddress;
}
IPEndPoint endpoint = new(realmIp, Port);
@@ -66,7 +59,6 @@ public class Realm : IEquatable<Realm>
{
return other.ExternalAddress.Equals(ExternalAddress)
&& other.LocalAddress.Equals(LocalAddress)
&& other.LocalSubnetMask.Equals(LocalSubnetMask)
&& other.Port == Port
&& other.Name == Name
&& other.Type == Type
@@ -78,14 +70,13 @@ public class Realm : IEquatable<Realm>
public override int GetHashCode()
{
return new { ExternalAddress, LocalAddress, LocalSubnetMask, Port, Name, Type, Flags, Timezone, AllowedSecurityLevel, PopulationLevel }.GetHashCode();
return new { ExternalAddress, LocalAddress, Port, Name, Type, Flags, Timezone, AllowedSecurityLevel, PopulationLevel }.GetHashCode();
}
public RealmId Id;
public uint Build;
public IPAddress ExternalAddress;
public IPAddress LocalAddress;
public IPAddress LocalSubnetMask;
public ushort Port;
public string Name;
public string NormalizedName;
+9 -10
View File
@@ -94,23 +94,22 @@ public class RealmManager : Singleton<RealmManager>
realm.Name = result.Read<string>(1);
realm.ExternalAddress = IPAddress.Parse(result.Read<string>(2));
realm.LocalAddress = IPAddress.Parse(result.Read<string>(3));
realm.LocalSubnetMask = IPAddress.Parse(result.Read<string>(4));
realm.Port = result.Read<ushort>(5);
RealmType realmType = (RealmType)result.Read<byte>(6);
realm.Port = result.Read<ushort>(4);
RealmType realmType = (RealmType)result.Read<byte>(5);
if (realmType == RealmType.FFAPVP)
realmType = RealmType.PVP;
if (realmType >= RealmType.MaxType)
realmType = RealmType.Normal;
realm.Type = (byte)realmType;
realm.Flags = (RealmFlags)result.Read<byte>(7);
realm.Timezone = result.Read<byte>(8);
AccountTypes allowedSecurityLevel = (AccountTypes)result.Read<byte>(9);
realm.Flags = (RealmFlags)result.Read<byte>(6);
realm.Timezone = result.Read<byte>(7);
AccountTypes allowedSecurityLevel = (AccountTypes)result.Read<byte>(8);
realm.AllowedSecurityLevel = (allowedSecurityLevel <= AccountTypes.Administrator ? allowedSecurityLevel : AccountTypes.Administrator);
realm.PopulationLevel = result.Read<float>(10);
realm.Build = result.Read<uint>(11);
byte region = result.Read<byte>(12);
byte battlegroup = result.Read<byte>(13);
realm.PopulationLevel = result.Read<float>(9);
realm.Build = result.Read<uint>(10);
byte region = result.Read<byte>(11);
byte battlegroup = result.Read<byte>(12);
realm.Id = new RealmId(region, battlegroup, realmId);