Core/Realms: Minor refactor to realm address storage (remove LocalSubnetMask as it is now unused, db field kept for table structure compatibility with 3.3.5 branch)

This commit is contained in:
Shauren
2023-08-03 11:18:11 +02:00
parent 8594fcfe8a
commit cc6dba1376
6 changed files with 14 additions and 38 deletions

View File

@@ -140,9 +140,9 @@ std::string const& LoginRESTService::GetHostnameForClient(boost::asio::ip::addre
return _hostnames[*addressIndex];
if (address.is_loopback())
return _hostnames[0];
return _hostnames[1];
return _hostnames[1];
return _hostnames[0];
}
void LoginRESTService::Run()

View File

@@ -31,24 +31,13 @@ void Realm::SetName(std::string name)
boost::asio::ip::address Realm::GetAddressForClient(boost::asio::ip::address const& clientAddr) const
{
std::array<boost::asio::ip::address, 2> addresses = std::array{ *ExternalAddress, * LocalAddress };
if (auto addressIndex = Trinity::Net::SelectAddressForClient(clientAddr, addresses))
{
switch (*addressIndex)
{
case 0:
return *ExternalAddress;
case 1:
return *LocalAddress;
default:
break;
}
}
if (auto addressIndex = Trinity::Net::SelectAddressForClient(clientAddr, Addresses))
return Addresses[*addressIndex];
if (clientAddr.is_loopback())
return *LocalAddress;
return Addresses[1];
return *ExternalAddress;
return Addresses[0];
}
uint32 Realm::GetConfigId() const

View File

@@ -20,7 +20,7 @@
#include "Common.h"
#include "AsioHacksFwd.h"
#include <memory>
#include <vector>
enum RealmFlags
{
@@ -79,9 +79,7 @@ struct TC_SHARED_API Realm
{
Battlenet::RealmHandle Id;
uint32 Build;
std::unique_ptr<boost::asio::ip::address> ExternalAddress;
std::unique_ptr<boost::asio::ip::address> LocalAddress;
std::unique_ptr<boost::asio::ip::address> LocalSubnetMask;
std::vector<boost::asio::ip::address> Addresses;
uint16 Port;
std::string Name;
std::string NormalizedName;

View File

@@ -107,10 +107,9 @@ void RealmList::UpdateRealm(Realm& realm, Battlenet::RealmHandle const& id, uint
realm.Timezone = timezone;
realm.AllowedSecurityLevel = allowedSecurityLevel;
realm.PopulationLevel = population;
if (!realm.ExternalAddress || *realm.ExternalAddress != address)
realm.ExternalAddress = std::make_unique<boost::asio::ip::address>(std::move(address));
if (!realm.LocalAddress || *realm.LocalAddress != localAddr)
realm.LocalAddress = std::make_unique<boost::asio::ip::address>(std::move(localAddr));
realm.Addresses.resize(2);
realm.Addresses[0] = std::move(address);
realm.Addresses[1] = std::move(localAddr);
realm.Port = port;
}

View File

@@ -22,9 +22,10 @@
#include "Realm.h"
#include <array>
#include <map>
#include <memory>
#include <shared_mutex>
#include <vector>
#include <unordered_set>
#include <vector>
struct RealmBuildInfo
{

View File

@@ -617,18 +617,7 @@ bool LoadRealmInfo()
{
if (Realm const* realmListRealm = sRealmList->GetRealm(realm.Id))
{
realm.Id = realmListRealm->Id;
realm.Build = realmListRealm->Build;
realm.ExternalAddress = std::make_unique<boost::asio::ip::address>(*realmListRealm->ExternalAddress);
realm.LocalAddress = std::make_unique<boost::asio::ip::address>(*realmListRealm->LocalAddress);
realm.Port = realmListRealm->Port;
realm.Name = realmListRealm->Name;
realm.NormalizedName = realmListRealm->NormalizedName;
realm.Type = realmListRealm->Type;
realm.Flags = realmListRealm->Flags;
realm.Timezone = realmListRealm->Timezone;
realm.AllowedSecurityLevel = realmListRealm->AllowedSecurityLevel;
realm.PopulationLevel = realmListRealm->PopulationLevel;
realm = *realmListRealm;
return true;
}