aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/Server
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2024-08-18 18:59:58 +0200
committerOvahlord <dreadkiller@gmx.de>2024-08-18 20:39:21 +0200
commit25ffdbc5ef0859aeaadfa132329a498e86827e68 (patch)
treed7df51da8cdc3e3df7c50e5058803f9324715ee4 /src/server/game/Server
parent0c98004896cb91ef2d22baa5569ff0e0d6cd15ee (diff)
Core/Realms: Realmlist refactors
* Removed global realm variable from World and use RealmList everywhere * Match auth build key with client version * Restored allowedSecurityLevel checks for realmlist packet building * Restored updating population field, mysteriously removed 15 years ago in f20b25d1c90f608deab28c9957b3b376ab2a0d50 (cherry picked from commit c4b710446d62c95eb8124175203fa5f394912594) # Conflicts: # sql/base/auth_database.sql
Diffstat (limited to 'src/server/game/Server')
-rw-r--r--src/server/game/Server/Packets/PartyPackets.cpp6
-rw-r--r--src/server/game/Server/Protocol/PacketLog.cpp8
-rw-r--r--src/server/game/Server/WorldSession.cpp23
-rw-r--r--src/server/game/Server/WorldSession.h4
-rw-r--r--src/server/game/Server/WorldSocket.cpp51
5 files changed, 50 insertions, 42 deletions
diff --git a/src/server/game/Server/Packets/PartyPackets.cpp b/src/server/game/Server/Packets/PartyPackets.cpp
index fc8365dd507..2d9ffc64354 100644
--- a/src/server/game/Server/Packets/PartyPackets.cpp
+++ b/src/server/game/Server/Packets/PartyPackets.cpp
@@ -19,11 +19,10 @@
#include "Pet.h"
#include "PhasingHandler.h"
#include "Player.h"
-#include "Realm.h"
+#include "RealmList.h"
#include "SpellAuraEffects.h"
#include "SpellAuras.h"
#include "Vehicle.h"
-#include "World.h"
#include "WorldSession.h"
WorldPacket const* WorldPackets::Party::PartyCommandResult::Write()
@@ -95,7 +94,8 @@ void WorldPackets::Party::PartyInvite::Initialize(Player const* inviter, int32 p
ProposedRoles = proposedRoles;
- InviterRealm = Auth::VirtualRealmInfo(realm.Id.GetAddress(), true, false, realm.Name, realm.NormalizedName);
+ if (std::shared_ptr<Realm const> realm = sRealmList->GetRealm(*inviter->m_playerData->VirtualPlayerRealm))
+ InviterRealm = Auth::VirtualRealmInfo(realm->Id.GetAddress(), true, false, realm->Name, realm->NormalizedName);
}
void WorldPackets::Party::PartyInviteResponse::Read()
diff --git a/src/server/game/Server/Protocol/PacketLog.cpp b/src/server/game/Server/Protocol/PacketLog.cpp
index 595738330d3..c912114849d 100644
--- a/src/server/game/Server/Protocol/PacketLog.cpp
+++ b/src/server/game/Server/Protocol/PacketLog.cpp
@@ -19,9 +19,8 @@
#include "Config.h"
#include "GameTime.h"
#include "IpAddress.h"
-#include "Realm.h"
+#include "RealmList.h"
#include "Timer.h"
-#include "World.h"
#include "WorldPacket.h"
#pragma pack(push, 1)
@@ -98,7 +97,10 @@ void PacketLog::Initialize()
header.Signature[0] = 'P'; header.Signature[1] = 'K'; header.Signature[2] = 'T';
header.FormatVersion = 0x0301;
header.SnifferId = 'T';
- header.Build = realm.Build;
+ if (std::shared_ptr<Realm const> currentRealm = sRealmList->GetCurrentRealm())
+ header.Build = currentRealm->Build;
+ else
+ header.Build = 0;
header.Locale[0] = 'e'; header.Locale[1] = 'n'; header.Locale[2] = 'U'; header.Locale[3] = 'S';
std::memset(header.SessionKey, 0, sizeof(header.SessionKey));
header.SniffStartUnixtime = GameTime::GetGameTime();
diff --git a/src/server/game/Server/WorldSession.cpp b/src/server/game/Server/WorldSession.cpp
index d8c4d2839c9..ba3bb98d958 100644
--- a/src/server/game/Server/WorldSession.cpp
+++ b/src/server/game/Server/WorldSession.cpp
@@ -47,7 +47,7 @@
#include "QueryHolder.h"
#include "Random.h"
#include "RBAC.h"
-#include "Realm.h"
+#include "RealmList.h"
#include "ScriptMgr.h"
#include "SocialMgr.h"
#include "WardenWin.h"
@@ -106,7 +106,7 @@ bool WorldSessionFilter::Process(WorldPacket* packet)
/// WorldSession constructor
WorldSession::WorldSession(uint32 id, std::string&& name, uint32 battlenetAccountId, std::shared_ptr<WorldSocket> sock, AccountTypes sec, uint8 expansion, time_t mute_time,
- std::string os, Minutes timezoneOffset, LocaleConstant locale, uint32 recruiter, bool isARecruiter):
+ std::string os, Minutes timezoneOffset, uint32 build, LocaleConstant locale, uint32 recruiter, bool isARecruiter):
m_muteTime(mute_time),
m_timeOutTime(0),
AntiDOS(this),
@@ -119,6 +119,7 @@ WorldSession::WorldSession(uint32 id, std::string&& name, uint32 battlenetAccoun
m_accountExpansion(expansion),
m_expansion(std::min<uint8>(expansion, sWorld->getIntConfig(CONFIG_EXPANSION))),
_os(std::move(os)),
+ _clientBuild(build),
_battlenetRequestToken(0),
_logoutTime(0),
m_inQueue(false),
@@ -797,7 +798,9 @@ void WorldSession::Handle_EarlyProccess(WorldPackets::Null& null)
void WorldSession::SendConnectToInstance(WorldPackets::Auth::ConnectToSerial serial)
{
boost::system::error_code ignored_error;
- boost::asio::ip::address instanceAddress = realm.GetAddressForClient(Trinity::Net::make_address(GetRemoteAddress(), ignored_error));
+ boost::asio::ip::address instanceAddress;
+ if (std::shared_ptr<Realm const> currentRealm = sRealmList->GetCurrentRealm())
+ instanceAddress = currentRealm->GetAddressForClient(Trinity::Net::make_address(GetRemoteAddress(), ignored_error));
_instanceConnectKey.Fields.AccountId = GetAccountId();
_instanceConnectKey.Fields.ConnectionType = CONNECTION_TYPE_INSTANCE;
@@ -1020,9 +1023,9 @@ void WorldSession::LoadPermissions()
uint8 secLevel = GetSecurity();
TC_LOG_DEBUG("rbac", "WorldSession::LoadPermissions [AccountId: {}, Name: {}, realmId: {}, secLevel: {}]",
- id, _accountName, realm.Id.Realm, secLevel);
+ id, _accountName, sRealmList->GetCurrentRealmId().Realm, secLevel);
- _RBACData = new rbac::RBACData(id, _accountName, realm.Id.Realm, secLevel);
+ _RBACData = new rbac::RBACData(id, _accountName, sRealmList->GetCurrentRealmId().Realm, secLevel);
_RBACData->LoadFromDB();
}
@@ -1032,9 +1035,9 @@ QueryCallback WorldSession::LoadPermissionsAsync()
uint8 secLevel = GetSecurity();
TC_LOG_DEBUG("rbac", "WorldSession::LoadPermissions [AccountId: {}, Name: {}, realmId: {}, secLevel: {}]",
- id, _accountName, realm.Id.Realm, secLevel);
+ id, _accountName, sRealmList->GetCurrentRealmId().Realm, secLevel);
- _RBACData = new rbac::RBACData(id, _accountName, realm.Id.Realm, secLevel);
+ _RBACData = new rbac::RBACData(id, _accountName, sRealmList->GetCurrentRealmId().Realm, secLevel);
return _RBACData->LoadFromDBAsync();
}
@@ -1097,7 +1100,7 @@ public:
stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_BATTLE_PETS);
stmt->setUInt32(0, battlenetAccountId);
- stmt->setInt32(1, realm.Id.Realm);
+ stmt->setInt32(1, sRealmList->GetCurrentRealmId().Realm);
ok = SetPreparedQuery(BATTLE_PETS, stmt) && ok;
stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_BATTLE_PET_SLOTS);
@@ -1226,7 +1229,7 @@ bool WorldSession::HasPermission(uint32 permission)
bool hasPermission = _RBACData->HasPermission(permission);
TC_LOG_DEBUG("rbac", "WorldSession::HasPermission [AccountId: {}, Name: {}, realmId: {}]",
- _RBACData->GetId(), _RBACData->GetName(), realm.Id.Realm);
+ _RBACData->GetId(), _RBACData->GetName(), sRealmList->GetCurrentRealmId().Realm);
return hasPermission;
}
@@ -1234,7 +1237,7 @@ bool WorldSession::HasPermission(uint32 permission)
void WorldSession::InvalidateRBACData()
{
TC_LOG_DEBUG("rbac", "WorldSession::Invalidaterbac::RBACData [AccountId: {}, Name: {}, realmId: {}]",
- _RBACData->GetId(), _RBACData->GetName(), realm.Id.Realm);
+ _RBACData->GetId(), _RBACData->GetName(), sRealmList->GetCurrentRealmId().Realm);
delete _RBACData;
_RBACData = nullptr;
}
diff --git a/src/server/game/Server/WorldSession.h b/src/server/game/Server/WorldSession.h
index b2f1b06868c..49cc7721504 100644
--- a/src/server/game/Server/WorldSession.h
+++ b/src/server/game/Server/WorldSession.h
@@ -938,7 +938,7 @@ class TC_GAME_API WorldSession
{
public:
WorldSession(uint32 id, std::string&& name, uint32 battlenetAccountId, std::shared_ptr<WorldSocket> sock, AccountTypes sec, uint8 expansion, time_t mute_time,
- std::string os, Minutes timezoneOffset, LocaleConstant locale, uint32 recruiter, bool isARecruiter);
+ std::string os, Minutes timezoneOffset, uint32 build, LocaleConstant locale, uint32 recruiter, bool isARecruiter);
~WorldSession();
bool PlayerLoading() const { return !m_playerLoading.IsEmpty(); }
@@ -987,6 +987,7 @@ class TC_GAME_API WorldSession
uint8 GetAccountExpansion() const { return m_accountExpansion; }
uint8 GetExpansion() const { return m_expansion; }
std::string const& GetOS() const { return _os; }
+ uint32 GetClientBuild() const { return _clientBuild; }
bool CanAccessAlliedRaces() const;
Warden* GetWarden() { return _warden.get(); }
@@ -1884,6 +1885,7 @@ class TC_GAME_API WorldSession
uint8 m_accountExpansion;
uint8 m_expansion;
std::string _os;
+ uint32 _clientBuild;
std::array<uint8, 32> _realmListSecret;
std::unordered_map<uint32 /*realmAddress*/, uint8> _realmCharacterCounts;
diff --git a/src/server/game/Server/WorldSocket.cpp b/src/server/game/Server/WorldSocket.cpp
index 688c8c5aed0..68783a321ae 100644
--- a/src/server/game/Server/WorldSocket.cpp
+++ b/src/server/game/Server/WorldSocket.cpp
@@ -616,9 +616,7 @@ struct AccountInfo
bool IsLockedToIP;
std::string LastIP;
std::string LockCountry;
- LocaleConstant Locale;
bool IsBanned;
-
} BattleNet;
struct
@@ -627,6 +625,8 @@ struct AccountInfo
std::array<uint8, 64> KeyData;
uint8 Expansion;
int64 MuteTime;
+ uint32 Build;
+ LocaleConstant Locale;
uint32 Recruiter;
std::string OS;
Minutes TimezoneOffset;
@@ -639,9 +639,9 @@ struct AccountInfo
explicit AccountInfo(Field const* fields)
{
- // 0 1 2 3 4 5 6 7 8 9 10 11 12
- // SELECT a.id, a.session_key, ba.last_ip, ba.locked, ba.lock_country, a.expansion, a.mutetime, ba.locale, a.recruiter, a.os, a.timezone_offset, ba.id, aa.SecurityLevel,
- // 13 14 15
+ // 0 1 2 3 4 5 6 7 8 9 10 11 12 13
+ // SELECT a.id, a.session_key, ba.last_ip, ba.locked, ba.lock_country, a.expansion, a.mutetime, a.client_build, a.locale, a.recruiter, a.os, a.timezone_offset, ba.id, aa.SecurityLevel,
+ // 14 15 16
// bab.unbandate > UNIX_TIMESTAMP() OR bab.unbandate = bab.bandate, ab.unbandate > UNIX_TIMESTAMP() OR ab.unbandate = ab.bandate, r.id
// FROM account a LEFT JOIN battlenet_accounts ba ON a.battlenet_account = ba.id LEFT JOIN account_access aa ON a.id = aa.AccountID AND aa.RealmID IN (-1, ?)
// LEFT JOIN battlenet_account_bans bab ON ba.id = bab.id LEFT JOIN account_banned ab ON a.id = ab.id LEFT JOIN account r ON a.id = r.recruiter
@@ -653,18 +653,19 @@ struct AccountInfo
BattleNet.LockCountry = fields[4].GetString();
Game.Expansion = fields[5].GetUInt8();
Game.MuteTime = fields[6].GetInt64();
- BattleNet.Locale = LocaleConstant(fields[7].GetUInt8());
- Game.Recruiter = fields[8].GetUInt32();
- Game.OS = fields[9].GetString();
- Game.TimezoneOffset = Minutes(fields[10].GetInt16());
- BattleNet.Id = fields[11].GetUInt32();
- Game.Security = AccountTypes(fields[12].GetUInt8());
- BattleNet.IsBanned = fields[13].GetUInt32() != 0;
- Game.IsBanned = fields[14].GetUInt32() != 0;
- Game.IsRectuiter = fields[15].GetUInt32() != 0;
-
- if (BattleNet.Locale >= TOTAL_LOCALES)
- BattleNet.Locale = LOCALE_enUS;
+ Game.Build = fields[7].GetUInt32();
+ Game.Locale = LocaleConstant(fields[8].GetUInt8());
+ Game.Recruiter = fields[9].GetUInt32();
+ Game.OS = fields[10].GetString();
+ Game.TimezoneOffset = Minutes(fields[11].GetInt16());
+ BattleNet.Id = fields[12].GetUInt32();
+ Game.Security = AccountTypes(fields[13].GetUInt8());
+ BattleNet.IsBanned = fields[14].GetUInt32() != 0;
+ Game.IsBanned = fields[15].GetUInt32() != 0;
+ Game.IsRectuiter = fields[16].GetUInt32() != 0;
+
+ if (Game.Locale >= TOTAL_LOCALES)
+ Game.Locale = LOCALE_enUS;
}
};
@@ -672,7 +673,7 @@ void WorldSocket::HandleAuthSession(std::shared_ptr<WorldPackets::Auth::AuthSess
{
// Get the account information from the auth database
LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_ACCOUNT_INFO_BY_NAME);
- stmt->setInt32(0, int32(realm.Id.Realm));
+ stmt->setInt32(0, int32(sRealmList->GetCurrentRealmId().Realm));
stmt->setString(1, authSession->RealmJoinTicket);
_queryProcessor.AddCallback(LoginDatabase.AsyncQuery(stmt).WithPreparedCallback([this, authSession = std::move(authSession)](PreparedQueryResult result) mutable
@@ -692,17 +693,17 @@ void WorldSocket::HandleAuthSessionCallback(std::shared_ptr<WorldPackets::Auth::
return;
}
- RealmBuildInfo const* buildInfo = sRealmList->GetBuildInfo(realm.Build);
+ AccountInfo account(result->Fetch());
+
+ RealmBuildInfo const* buildInfo = sRealmList->GetBuildInfo(account.Game.Build);
if (!buildInfo)
{
SendAuthResponseError(ERROR_BAD_VERSION);
- TC_LOG_ERROR("network", "WorldSocket::HandleAuthSession: Missing auth seed for realm build {} ({}).", realm.Build, GetRemoteIpAddress().to_string());
+ TC_LOG_ERROR("network", "WorldSocket::HandleAuthSession: Missing auth seed for realm build {} ({}).", account.Game.Build, GetRemoteIpAddress().to_string());
DelayedCloseSocket();
return;
}
- AccountInfo account(result->Fetch());
-
// For hook purposes, we get Remoteaddress at this point.
std::string address = GetRemoteIpAddress().to_string();
@@ -778,11 +779,11 @@ void WorldSocket::HandleAuthSessionCallback(std::shared_ptr<WorldPackets::Auth::
return;
}
- if (authSession->RealmID != realm.Id.Realm)
+ if (authSession->RealmID != sRealmList->GetCurrentRealmId().Realm)
{
SendAuthResponseError(ERROR_DENIED);
TC_LOG_ERROR("network", "WorldSocket::HandleAuthSession: Client {} requested connecting with realm id {} but this realm has id {} set in config.",
- GetRemoteIpAddress().to_string(), authSession->RealmID, realm.Id.Realm);
+ GetRemoteIpAddress().to_string(), authSession->RealmID, sRealmList->GetCurrentRealmId().Realm);
DelayedCloseSocket();
return;
}
@@ -877,7 +878,7 @@ void WorldSocket::HandleAuthSessionCallback(std::shared_ptr<WorldPackets::Auth::
_authed = true;
_worldSession = new WorldSession(account.Game.Id, std::move(authSession->RealmJoinTicket), account.BattleNet.Id, shared_from_this(), account.Game.Security,
- account.Game.Expansion, mutetime, account.Game.OS, account.Game.TimezoneOffset, account.BattleNet.Locale, account.Game.Recruiter, account.Game.IsRectuiter);
+ account.Game.Expansion, mutetime, account.Game.OS, account.Game.TimezoneOffset, account.Game.Build, account.Game.Locale, account.Game.Recruiter, account.Game.IsRectuiter);
// Initialize Warden system only if it is enabled by config
if (wardenActive)