feat(Core/RealmList): port TrinityCore realm api (#5626)

* feat(Core/RealmList): port TrinityCore realm api

* 1

* whitespace cleanup

* Update data/sql/updates/pending_db_auth/rev_1620114805872279900.sql

Co-authored-by: Kitzunu <24550914+Kitzunu@users.noreply.github.com>

* 1

* 2

* Update data/sql/updates/pending_db_auth/rev_1620114805872279900.sql

Co-authored-by: Kitzunu <24550914+Kitzunu@users.noreply.github.com>

* `

* 1

* small corrects

* finish maybe

* realm.Id.Realm

* ws

* 1

Co-authored-by: Kitzunu <24550914+Kitzunu@users.noreply.github.com>
This commit is contained in:
Kargatum
2021-05-27 05:12:46 +07:00
committed by GitHub
parent 78e1719c80
commit ea5f5f2072
23 changed files with 536 additions and 305 deletions

View File

@@ -16,6 +16,7 @@
#include "ObjectMgr.h"
#include "Opcodes.h"
#include "Player.h"
#include "Realm.h"
#include "ScriptMgr.h"
#include "SpellMgr.h"
#include "UpdateMask.h"
@@ -114,7 +115,7 @@ bool ChatHandler::HasLowerSecurityAccount(WorldSession* target, uint32 target_ac
if (target)
target_sec = target->GetSecurity();
else if (target_account)
target_sec = AccountMgr::GetSecurity(target_account, realmID);
target_sec = AccountMgr::GetSecurity(target_account, realm.Id.Realm);
else
return true; // caller must report error for (target == nullptr && target_account == 0)

View File

@@ -57,6 +57,7 @@
#include "QuestDef.h"
#include "ReputationMgr.h"
#include "revision.h"
#include "Realm.h"
#include "SavingSystem.h"
#include "ScriptMgr.h"
#include "SkillDiscovery.h"

View File

@@ -26,6 +26,7 @@
#include "Pet.h"
#include "Player.h"
#include "PlayerDump.h"
#include "Realm.h"
#include "ReputationMgr.h"
#include "ScriptMgr.h"
#include "ServerMotd.h"
@@ -647,13 +648,13 @@ void WorldSession::HandleCharCreateCallback(PreparedQueryResult result, Characte
PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_REALM_CHARACTERS_BY_REALM);
stmt->setUInt32(0, GetAccountId());
stmt->setUInt32(1, realmID);
stmt->setUInt32(1, realm.Id.Realm);
trans->Append(stmt);
stmt = LoginDatabase.GetPreparedStatement(LOGIN_INS_REALM_CHARACTERS);
stmt->setUInt32(0, createInfo->CharCount);
stmt->setUInt32(1, GetAccountId());
stmt->setUInt32(2, realmID);
stmt->setUInt32(2, realm.Id.Realm);
trans->Append(stmt);
LoginDatabase.CommitTransaction(trans);
@@ -996,7 +997,7 @@ void WorldSession::HandlePlayerLoginFromDB(LoginQueryHolder* holder)
CharacterDatabase.Execute(stmt);
stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_ACCOUNT_ONLINE);
stmt->setUInt32(0, realmID);
stmt->setUInt32(0, realm.Id.Realm);
stmt->setUInt32(1, GetAccountId());
LoginDatabase.Execute(stmt);

View File

@@ -10,6 +10,7 @@
#include "ObjectAccessor.h"
#include "ObjectMgr.h"
#include "Player.h"
#include "Realm.h"
#include "SocialMgr.h"
#include "World.h"
#include "WorldSession.h"
@@ -52,7 +53,7 @@ void WorldSession::HandleAddFriendOpcode(WorldPacket& recv_data)
TeamId teamId = Player::TeamIdForRace(playerData->race);
FriendsResult friendResult = FRIEND_NOT_FOUND;
if (!AccountMgr::IsPlayerAccount(GetSecurity()) || sWorld->getBoolConfig(CONFIG_ALLOW_GM_FRIEND)|| AccountMgr::IsPlayerAccount(AccountMgr::GetSecurity(friendAccountId, realmID)))
if (!AccountMgr::IsPlayerAccount(GetSecurity()) || sWorld->getBoolConfig(CONFIG_ALLOW_GM_FRIEND)|| AccountMgr::IsPlayerAccount(AccountMgr::GetSecurity(friendAccountId, realm.Id.Realm)))
{
if (friendGuid)
{

View File

@@ -15,6 +15,7 @@
#include "Opcodes.h"
#include "PacketLog.h"
#include "Player.h"
#include "Realm.h"
#include "ScriptMgr.h"
#include "SharedDefines.h"
#include "Util.h"
@@ -791,7 +792,7 @@ int WorldSocket::ProcessIncoming(WorldPacket* new_pct)
int WorldSocket::HandleAuthSession(WorldPacket& recvPacket)
{
// NOTE: ATM the socket is singlethread, have this in mind ...
uint32 loginServerID, loginServerType, regionID, battlegroupID, realm;
uint32 loginServerID, loginServerType, regionID, battlegroupID, realmid;
uint64 DosResponse;
uint32 BuiltNumberClient;
std::string accountName;
@@ -817,7 +818,7 @@ int WorldSocket::HandleAuthSession(WorldPacket& recvPacket)
recvPacket.read(clientSeed);
recvPacket >> regionID;
recvPacket >> battlegroupID;
recvPacket >> realm;
recvPacket >> realmid;
recvPacket >> DosResponse;
recvPacket.read(digest);
@@ -829,7 +830,7 @@ int WorldSocket::HandleAuthSession(WorldPacket& recvPacket)
// 0 1 2 3 4 5 6 7 8 9 10
// SELECT id, sessionkey, last_ip, locked, lock_country, expansion, mutetime, locale, recruiter, os, totaltime FROM account WHERE username = ?
auto* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_ACCOUNT_INFO_BY_NAME);
stmt->setInt32(0, int32(realmID));
stmt->setInt32(0, int32(realm.Id.Realm));
stmt->setString(1, accountName);
PreparedQueryResult result = LoginDatabase.Query(stmt);
@@ -856,11 +857,10 @@ int WorldSocket::HandleAuthSession(WorldPacket& recvPacket)
stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_LAST_ATTEMPT_IP);
stmt->setString(0, address);
stmt->setString(1, accountName);
LoginDatabase.Execute(stmt);
// This also allows to check for possible "hack" attempts on account
// even if auth credentials are bad, try using the session key we have - client cannot read auth response error without it
// even if auth credentials are bad, try using the session key we have - client cannot read auth response error without it
m_Crypt.Init(account.SessionKey);
// First reject the connection if packet contains invalid data or realm state doesn't allow logging in
@@ -875,14 +875,14 @@ int WorldSocket::HandleAuthSession(WorldPacket& recvPacket)
return -1;
}
if (realm != realmID)
if (realmid != realm.Id.Realm)
{
packet.Initialize(SMSG_AUTH_RESPONSE, 1);
packet << uint8(REALM_LIST_REALM_NOT_FOUND);
SendPacket(packet);
LOG_ERROR("server", "WorldSocket::HandleAuthSession: Client %s requested connecting with realm id %u but this realm has id %u set in config.",
address.c_str(), realm, realmID);
address.c_str(), realmid, realm.Id.Realm);
sScriptMgr->OnFailedAccountLogin(account.Id);
return -1;
}

View File

@@ -54,6 +54,7 @@
#include "PetitionMgr.h"
#include "Player.h"
#include "PoolMgr.h"
#include "Realm.h"
#include "SavingSystem.h"
#include "ScriptMgr.h"
#include "ServerMotd.h"
@@ -91,6 +92,8 @@ float World::m_MaxVisibleDistanceOnContinents = DEFAULT_VISIBILITY_DISTANCE;
float World::m_MaxVisibleDistanceInInstances = DEFAULT_VISIBILITY_INSTANCE;
float World::m_MaxVisibleDistanceInBGArenas = DEFAULT_VISIBILITY_BGARENAS;
Realm realm;
/// World constructor
World::World()
{
@@ -428,7 +431,7 @@ void World::LoadConfigSettings(bool reload)
}
// Set realm id and enable db logging
sLog->SetRealmId(realmID);
sLog->SetRealmId(realm.Id.Realm);
#ifdef ELUNA
///- Initialize Lua Engine
@@ -1488,7 +1491,7 @@ void World::SetInitialWorldSettings()
uint32 realm_zone = getIntConfig(CONFIG_REALM_ZONE);
LoginDatabase.PExecute("UPDATE realmlist SET icon = %u, timezone = %u WHERE id = '%d'", server_type, realm_zone, realmID); // One-time query
LoginDatabase.PExecute("UPDATE realmlist SET icon = %u, timezone = %u WHERE id = '%d'", server_type, realm_zone, realm.Id.Realm); // One-time query
///- Custom Hook for loading DB items
sScriptMgr->OnLoadCustomDatabaseTable();
@@ -1938,7 +1941,7 @@ void World::SetInitialWorldSettings()
m_startTime = m_gameTime;
LoginDatabase.PExecute("INSERT INTO uptime (realmid, starttime, uptime, revision) VALUES(%u, %u, 0, '%s')",
realmID, uint32(m_startTime), GitRevision::GetFullVersion()); // One-time query
realm.Id.Realm, uint32(m_startTime), GitRevision::GetFullVersion()); // One-time query
m_timers[WUPDATE_WEATHERS].SetInterval(1 * IN_MILLISECONDS);
m_timers[WUPDATE_AUCTIONS].SetInterval(MINUTE * IN_MILLISECONDS);
@@ -2316,7 +2319,7 @@ void World::Update(uint32 diff)
stmt->setUInt32(0, tmpDiff);
stmt->setUInt16(1, uint16(maxOnlinePlayers));
stmt->setUInt32(2, realmID);
stmt->setUInt32(2, realm.Id.Realm);
stmt->setUInt32(3, uint32(m_startTime));
LoginDatabase.Execute(stmt);
@@ -2854,13 +2857,13 @@ void World::_UpdateRealmCharCount(PreparedQueryResult resultCharCount)
PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_REALM_CHARACTERS_BY_REALM);
stmt->setUInt32(0, accountId);
stmt->setUInt32(1, realmID);
stmt->setUInt32(1, realm.Id.Realm);
trans->Append(stmt);
stmt = LoginDatabase.GetPreparedStatement(LOGIN_INS_REALM_CHARACTERS);
stmt->setUInt8(0, charCount);
stmt->setUInt32(1, accountId);
stmt->setUInt32(2, realmID);
stmt->setUInt32(2, realm.Id.Realm);
trans->Append(stmt);
LoginDatabase.CommitTransaction(trans);
@@ -2988,7 +2991,7 @@ void World::ResetDailyQuests()
void World::LoadDBAllowedSecurityLevel()
{
PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_REALMLIST_SECURITY_LEVEL);
stmt->setInt32(0, int32(realmID));
stmt->setInt32(0, int32(realm.Id.Realm));
PreparedQueryResult result = LoginDatabase.Query(stmt);
if (result)
@@ -3451,3 +3454,13 @@ void World::RemoveOldCorpses()
{
m_timers[WUPDATE_CORPSES].SetCurrent(m_timers[WUPDATE_CORPSES].GetInterval());
}
bool World::IsPvPRealm() const
{
return getIntConfig(CONFIG_GAME_TYPE) == REALM_TYPE_PVP || getIntConfig(CONFIG_GAME_TYPE) == REALM_TYPE_RPPVP || getIntConfig(CONFIG_GAME_TYPE) == REALM_TYPE_FFA_PVP;
}
bool World::IsFFAPvPRealm() const
{
return getIntConfig(CONFIG_GAME_TYPE) == REALM_TYPE_FFA_PVP;
}

View File

@@ -29,7 +29,9 @@ class WorldPacket;
class WorldSocket;
class SystemMgr;
extern uint32 realmID;
struct Realm;
AC_GAME_API extern Realm realm;
enum ShutdownMask
{
@@ -74,18 +76,6 @@ enum BillingPlanFlags
SESSION_ENABLE_CAIS = 0x80,
};
/// Type of server, this is values from second column of Cfg_Configs.dbc
enum RealmType
{
REALM_TYPE_NORMAL = 0,
REALM_TYPE_PVP = 1,
REALM_TYPE_NORMAL2 = 4,
REALM_TYPE_RP = 6,
REALM_TYPE_RPPVP = 8,
REALM_TYPE_FFA_PVP = 16 // custom, free for all pvp mode like arena PvP in all zones except rest activated places and sanctuaries
// replaced by REALM_PVP in realm list
};
enum RealmZone
{
REALM_ZONE_UNKNOWN = 0, // any language
@@ -335,8 +325,8 @@ public:
void LoadWorldStates();
/// Are we on a "Player versus Player" server?
bool IsPvPRealm() const { return (getIntConfig(CONFIG_GAME_TYPE) == REALM_TYPE_PVP || getIntConfig(CONFIG_GAME_TYPE) == REALM_TYPE_RPPVP || getIntConfig(CONFIG_GAME_TYPE) == REALM_TYPE_FFA_PVP); }
bool IsFFAPvPRealm() const { return getIntConfig(CONFIG_GAME_TYPE) == REALM_TYPE_FFA_PVP; }
[[nodiscard]] bool IsPvPRealm() const;
[[nodiscard]] bool IsFFAPvPRealm() const;
void KickAll();
void KickAllLess(AccountTypes sec);