mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-16 10:30:27 +00:00
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:
@@ -39,8 +39,6 @@ char serviceDescription[] = "AzerothCore World of Warcraft emulator world servic
|
||||
int m_ServiceStatus = -1;
|
||||
#endif
|
||||
|
||||
uint32 realmID; ///< Id of the realm
|
||||
|
||||
/// Print out the usage string for this program on the console.
|
||||
void usage(const char* prog)
|
||||
{
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#include "Master.h"
|
||||
#include "OpenSSLCrypto.h"
|
||||
#include "RARunnable.h"
|
||||
#include "RealmList.h"
|
||||
#include "Realm.h"
|
||||
#include "ScriptMgr.h"
|
||||
#include "SignalHandler.h"
|
||||
#include "Timer.h"
|
||||
@@ -30,6 +30,7 @@
|
||||
#include "WorldSocket.h"
|
||||
#include "WorldSocketMgr.h"
|
||||
#include "DatabaseLoader.h"
|
||||
#include "Optional.h"
|
||||
#include "SecretMgr.h"
|
||||
#include <ace/Sig_Handler.h>
|
||||
|
||||
@@ -100,6 +101,8 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
bool LoadRealmInfo();
|
||||
|
||||
Master* Master::instance()
|
||||
{
|
||||
static Master instance;
|
||||
@@ -131,7 +134,9 @@ int Master::Run()
|
||||
return 1;
|
||||
|
||||
// set server offline (not connectable)
|
||||
LoginDatabase.DirectPExecute("UPDATE realmlist SET flag = (flag & ~%u) | %u WHERE id = '%d'", REALM_FLAG_OFFLINE, REALM_FLAG_INVALID, realmID);
|
||||
LoginDatabase.DirectPExecute("UPDATE realmlist SET flag = (flag & ~%u) | %u WHERE id = '%d'", REALM_FLAG_OFFLINE, REALM_FLAG_VERSION_MISMATCH, realm.Id.Realm);
|
||||
|
||||
LoadRealmInfo();
|
||||
|
||||
// Loading modules configs
|
||||
sConfigMgr->LoadModulesConfigs();
|
||||
@@ -271,7 +276,7 @@ int Master::Run()
|
||||
}
|
||||
|
||||
// set server online (allow connecting now)
|
||||
LoginDatabase.DirectPExecute("UPDATE realmlist SET flag = flag & ~%u, population = 0 WHERE id = '%u'", REALM_FLAG_INVALID, realmID);
|
||||
LoginDatabase.DirectPExecute("UPDATE realmlist SET flag = flag & ~%u, population = 0 WHERE id = '%u'", REALM_FLAG_VERSION_MISMATCH, realm.Id.Realm);
|
||||
|
||||
LOG_INFO("server", "%s (worldserver-daemon) ready...", GitRevision::GetFullVersion());
|
||||
|
||||
@@ -295,7 +300,7 @@ int Master::Run()
|
||||
}
|
||||
|
||||
// set server offline
|
||||
LoginDatabase.DirectPExecute("UPDATE realmlist SET flag = flag | %u WHERE id = '%d'", REALM_FLAG_OFFLINE, realmID);
|
||||
LoginDatabase.DirectPExecute("UPDATE realmlist SET flag = flag | %u WHERE id = '%d'", REALM_FLAG_OFFLINE, realm.Id.Realm);
|
||||
|
||||
///- Clean database before leaving
|
||||
ClearOnlineAccounts();
|
||||
@@ -379,16 +384,16 @@ bool Master::_StartDB()
|
||||
return false;
|
||||
|
||||
///- Get the realm Id from the configuration file
|
||||
realmID = sConfigMgr->GetOption<int32>("RealmID", 0);
|
||||
if (!realmID)
|
||||
realm.Id.Realm = sConfigMgr->GetOption<int32>("RealmID", 0);
|
||||
if (!realm.Id.Realm)
|
||||
{
|
||||
LOG_ERROR("server", "Realm ID not defined in configuration file");
|
||||
return false;
|
||||
}
|
||||
else if (realmID > 255)
|
||||
else if (realm.Id.Realm > 255)
|
||||
{
|
||||
/*
|
||||
* Due to the client only being able to read a realmID
|
||||
* Due to the client only being able to read a realm.Id.Realm
|
||||
* with a size of uint8 we can "only" store up to 255 realms
|
||||
* anything further the client will behave anormaly
|
||||
*/
|
||||
@@ -396,7 +401,7 @@ bool Master::_StartDB()
|
||||
return false;
|
||||
}
|
||||
|
||||
LOG_INFO("server", "Realm running as realm ID %d", realmID);
|
||||
LOG_INFO("server", "Realm running as realm ID %d", realm.Id.Realm);
|
||||
|
||||
///- Clean the database before starting
|
||||
ClearOnlineAccounts();
|
||||
@@ -424,8 +429,55 @@ void Master::ClearOnlineAccounts()
|
||||
{
|
||||
// Reset online status for all accounts with characters on the current realm
|
||||
// pussywizard: tc query would set online=0 even if logged in on another realm >_>
|
||||
LoginDatabase.DirectPExecute("UPDATE account SET online = 0 WHERE online = %u", realmID);
|
||||
LoginDatabase.DirectPExecute("UPDATE account SET online = 0 WHERE online = %u", realm.Id.Realm);
|
||||
|
||||
// Reset online status for all characters
|
||||
CharacterDatabase.DirectExecute("UPDATE characters SET online = 0 WHERE online <> 0");
|
||||
}
|
||||
|
||||
bool LoadRealmInfo()
|
||||
{
|
||||
QueryResult result = LoginDatabase.PQuery("SELECT id, name, address, localAddress, localSubnetMask, port, icon, flag, timezone, allowedSecurityLevel, population, gamebuild FROM realmlist WHERE id = %u", realm.Id.Realm);
|
||||
if (!result)
|
||||
{
|
||||
LOG_ERROR("server.worldserver", "> Not found realm with ID %u", realm.Id.Realm);
|
||||
return false;
|
||||
}
|
||||
|
||||
Field* fields = result->Fetch();
|
||||
realm.Name = fields[1].GetString();
|
||||
realm.Port = fields[5].GetUInt16();
|
||||
|
||||
Optional<ACE_INET_Addr> externalAddress = ACE_INET_Addr(realm.Port, fields[2].GetCString(), AF_INET);
|
||||
if (!externalAddress)
|
||||
{
|
||||
LOG_ERROR("server.worldserver", "Could not resolve address %s", fields[2].GetString().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
Optional<ACE_INET_Addr> localAddress = ACE_INET_Addr(realm.Port, fields[3].GetCString(), AF_INET);
|
||||
if (!localAddress)
|
||||
{
|
||||
LOG_ERROR("server.worldserver", "Could not resolve address %s", fields[3].GetString().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
Optional<ACE_INET_Addr> localSubmask = ACE_INET_Addr(0, fields[4].GetCString(), AF_INET);
|
||||
if (!localSubmask)
|
||||
{
|
||||
LOG_ERROR("server.worldserver", "Could not resolve address %s", fields[4].GetString().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
realm.ExternalAddress = std::make_unique<ACE_INET_Addr>(*externalAddress);
|
||||
realm.LocalAddress = std::make_unique<ACE_INET_Addr>(*localAddress);
|
||||
realm.LocalSubnetMask = std::make_unique<ACE_INET_Addr>(*localSubmask);
|
||||
|
||||
realm.Type = fields[6].GetUInt8();
|
||||
realm.Flags = RealmFlags(fields[7].GetUInt8());
|
||||
realm.Timezone = fields[8].GetUInt8();
|
||||
realm.AllowedSecurityLevel = AccountTypes(fields[9].GetUInt8());
|
||||
realm.PopulationLevel = fields[10].GetFloat();
|
||||
realm.Build = fields[11].GetUInt32();
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user