mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-26 07:06:23 +00:00
feat(Core/Misc): implement ObjectGuid class (port from TC) (#4885)
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
|
||||
#include "Callback.h"
|
||||
#include "Common.h"
|
||||
#include "ObjectGuid.h"
|
||||
#include "QueryResult.h"
|
||||
#include "SharedDefines.h"
|
||||
#include "Timer.h"
|
||||
@@ -468,7 +469,7 @@ enum Rates
|
||||
// xinef: global storage
|
||||
struct GlobalPlayerData
|
||||
{
|
||||
uint32 guidLow;
|
||||
ObjectGuid::LowType guidLow;
|
||||
uint32 accountId;
|
||||
std::string name;
|
||||
uint8 race;
|
||||
@@ -487,7 +488,7 @@ public:
|
||||
virtual ~IWorld() {}
|
||||
virtual WorldSession* FindSession(uint32 id) const = 0;
|
||||
virtual WorldSession* FindOfflineSession(uint32 id) const = 0;
|
||||
virtual WorldSession* FindOfflineSessionForCharacterGUID(uint32 guidLow) const = 0;
|
||||
virtual WorldSession* FindOfflineSessionForCharacterGUID(ObjectGuid::LowType guidLow) const = 0;
|
||||
virtual void AddSession(WorldSession* s) = 0;
|
||||
virtual void SendAutoBroadcast() = 0;
|
||||
virtual bool KickSession(uint32 id) = 0;
|
||||
@@ -563,16 +564,16 @@ public:
|
||||
virtual void KickAllLess(AccountTypes sec) = 0;
|
||||
virtual uint32 GetNextWhoListUpdateDelaySecs() = 0;
|
||||
virtual void LoadGlobalPlayerDataStore() = 0;
|
||||
virtual uint32 GetGlobalPlayerGUID(std::string const& name) const = 0;
|
||||
virtual GlobalPlayerData const* GetGlobalPlayerData(uint32 guid) const = 0;
|
||||
virtual void AddGlobalPlayerData(uint32 guid, uint32 accountId, std::string const& name, uint8 gender, uint8 race, uint8 playerClass, uint8 level, uint16 mailCount, uint32 guildId) = 0;
|
||||
virtual void UpdateGlobalPlayerData(uint32 guid, uint8 mask, std::string const& name, uint8 level = 0, uint8 gender = 0, uint8 race = 0, uint8 playerClass = 0) = 0;
|
||||
virtual void UpdateGlobalPlayerMails(uint32 guid, int16 count, bool add = true) = 0;
|
||||
virtual void UpdateGlobalPlayerGuild(uint32 guid, uint32 guildId) = 0;
|
||||
virtual void UpdateGlobalPlayerGroup(uint32 guid, uint32 groupId) = 0;
|
||||
virtual void UpdateGlobalPlayerArenaTeam(uint32 guid, uint8 slot, uint32 arenaTeamId) = 0;
|
||||
virtual void UpdateGlobalNameData(uint32 guidLow, std::string const& oldName, std::string const& newName) = 0;
|
||||
virtual void DeleteGlobalPlayerData(uint32 guid, std::string const& name) = 0;
|
||||
virtual ObjectGuid GetGlobalPlayerGUID(std::string const& name) const = 0;
|
||||
virtual GlobalPlayerData const* GetGlobalPlayerData(ObjectGuid::LowType guid) const = 0;
|
||||
virtual void AddGlobalPlayerData(ObjectGuid::LowType guid, uint32 accountId, std::string const& name, uint8 gender, uint8 race, uint8 playerClass, uint8 level, uint16 mailCount, uint32 guildId) = 0;
|
||||
virtual void UpdateGlobalPlayerData(ObjectGuid::LowType guid, uint8 mask, std::string const& name, uint8 level = 0, uint8 gender = 0, uint8 race = 0, uint8 playerClass = 0) = 0;
|
||||
virtual void UpdateGlobalPlayerMails(ObjectGuid::LowType guid, int16 count, bool add = true) = 0;
|
||||
virtual void UpdateGlobalPlayerGuild(ObjectGuid::LowType guid, uint32 guildId) = 0;
|
||||
virtual void UpdateGlobalPlayerGroup(ObjectGuid::LowType guid, uint32 groupId) = 0;
|
||||
virtual void UpdateGlobalPlayerArenaTeam(ObjectGuid::LowType guid, uint8 slot, uint32 arenaTeamId) = 0;
|
||||
virtual void UpdateGlobalNameData(ObjectGuid::LowType guidLow, std::string const& oldName, std::string const& newName) = 0;
|
||||
virtual void DeleteGlobalPlayerData(ObjectGuid::LowType guid, std::string const& name) = 0;
|
||||
virtual void ProcessCliCommands() = 0;
|
||||
virtual void QueueCliCommand(CliCommandHolder* commandHolder) = 0;
|
||||
virtual void ForceGameEventUpdate() = 0;
|
||||
@@ -589,6 +590,7 @@ public:
|
||||
virtual time_t GetNextTimeWithMonthAndHour(int8 month, int8 hour) = 0;
|
||||
virtual std::string const& GetRealmName() const = 0;
|
||||
virtual void SetRealmName(std::string name) = 0;
|
||||
virtual void RemoveOldCorpses() = 0;
|
||||
};
|
||||
|
||||
#endif //AZEROTHCORE_IWORLD_H
|
||||
|
||||
@@ -215,13 +215,15 @@ WorldSession* World::FindOfflineSession(uint32 id) const
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
WorldSession* World::FindOfflineSessionForCharacterGUID(uint32 guidLow) const
|
||||
WorldSession* World::FindOfflineSessionForCharacterGUID(ObjectGuid::LowType guidLow) const
|
||||
{
|
||||
if (m_offlineSessions.empty())
|
||||
return nullptr;
|
||||
|
||||
for (SessionMap::const_iterator itr = m_offlineSessions.begin(); itr != m_offlineSessions.end(); ++itr)
|
||||
if (itr->second->GetGuidLow() == guidLow)
|
||||
return itr->second;
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -1488,11 +1490,6 @@ void World::SetInitialWorldSettings()
|
||||
|
||||
LoginDatabase.PExecute("UPDATE realmlist SET icon = %u, timezone = %u WHERE id = '%d'", server_type, realm_zone, realmID); // One-time query
|
||||
|
||||
///- Remove the bones (they should not exist in DB though) and old corpses after a restart
|
||||
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_OLD_CORPSES);
|
||||
stmt->setUInt32(0, 3 * DAY);
|
||||
CharacterDatabase.Execute(stmt);
|
||||
|
||||
///- Custom Hook for loading DB items
|
||||
sScriptMgr->OnLoadCustomDatabaseTable();
|
||||
|
||||
@@ -1768,9 +1765,6 @@ void World::SetInitialWorldSettings()
|
||||
LOG_INFO("server", "Loading pet level stats...");
|
||||
sObjectMgr->LoadPetLevelInfo();
|
||||
|
||||
LOG_INFO("server", "Loading Player Corpses...");
|
||||
sObjectMgr->LoadCorpses();
|
||||
|
||||
LOG_INFO("server", "Loading Player level dependent mail rewards...");
|
||||
sObjectMgr->LoadMailLevelRewards();
|
||||
|
||||
@@ -2332,7 +2326,10 @@ void World::Update(uint32 diff)
|
||||
if (m_timers[WUPDATE_CORPSES].Passed())
|
||||
{
|
||||
m_timers[WUPDATE_CORPSES].Reset();
|
||||
sObjectAccessor->RemoveOldCorpses();
|
||||
sMapMgr->DoForAllMaps([](Map* map)
|
||||
{
|
||||
map->RemoveOldCorpses();
|
||||
});
|
||||
}
|
||||
|
||||
///- Process Game events when necessary
|
||||
@@ -3225,7 +3222,7 @@ void World::LoadGlobalPlayerDataStore()
|
||||
do
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
uint32 guidLow = fields[0].GetUInt32();
|
||||
ObjectGuid::LowType guidLow = fields[0].GetUInt32();
|
||||
|
||||
// count mails
|
||||
uint16 mailCount = 0;
|
||||
@@ -3251,7 +3248,7 @@ void World::LoadGlobalPlayerDataStore()
|
||||
LOG_INFO("server", " ");
|
||||
}
|
||||
|
||||
void World::AddGlobalPlayerData(uint32 guid, uint32 accountId, std::string const& name, uint8 gender, uint8 race, uint8 playerClass, uint8 level, uint16 mailCount, uint32 guildId)
|
||||
void World::AddGlobalPlayerData(ObjectGuid::LowType guid, uint32 accountId, std::string const& name, uint8 gender, uint8 race, uint8 playerClass, uint8 level, uint16 mailCount, uint32 guildId)
|
||||
{
|
||||
GlobalPlayerData data;
|
||||
|
||||
@@ -3273,7 +3270,7 @@ void World::AddGlobalPlayerData(uint32 guid, uint32 accountId, std::string const
|
||||
_globalPlayerNameStore[name] = guid;
|
||||
}
|
||||
|
||||
void World::UpdateGlobalPlayerData(uint32 guid, uint8 mask, std::string const& name, uint8 level, uint8 gender, uint8 race, uint8 playerClass)
|
||||
void World::UpdateGlobalPlayerData(ObjectGuid::LowType guid, uint8 mask, std::string const& name, uint8 level, uint8 gender, uint8 race, uint8 playerClass)
|
||||
{
|
||||
GlobalPlayerDataMap::iterator itr = _globalPlayerDataStore.find(guid);
|
||||
if (itr == _globalPlayerDataStore.end())
|
||||
@@ -3291,11 +3288,11 @@ void World::UpdateGlobalPlayerData(uint32 guid, uint8 mask, std::string const& n
|
||||
itr->second.name = name;
|
||||
|
||||
WorldPacket data(SMSG_INVALIDATE_PLAYER, 8);
|
||||
data << MAKE_NEW_GUID(guid, 0, HIGHGUID_PLAYER);
|
||||
data << guid;
|
||||
SendGlobalMessage(&data);
|
||||
}
|
||||
|
||||
void World::UpdateGlobalPlayerMails(uint32 guid, int16 count, bool add)
|
||||
void World::UpdateGlobalPlayerMails(ObjectGuid::LowType guid, int16 count, bool add)
|
||||
{
|
||||
GlobalPlayerDataMap::iterator itr = _globalPlayerDataStore.find(guid);
|
||||
if (itr == _globalPlayerDataStore.end())
|
||||
@@ -3313,7 +3310,7 @@ void World::UpdateGlobalPlayerMails(uint32 guid, int16 count, bool add)
|
||||
itr->second.mailCount = uint16(icount + count); // addition or subtraction
|
||||
}
|
||||
|
||||
void World::UpdateGlobalPlayerGuild(uint32 guid, uint32 guildId)
|
||||
void World::UpdateGlobalPlayerGuild(ObjectGuid::LowType guid, uint32 guildId)
|
||||
{
|
||||
GlobalPlayerDataMap::iterator itr = _globalPlayerDataStore.find(guid);
|
||||
if (itr == _globalPlayerDataStore.end())
|
||||
@@ -3321,7 +3318,7 @@ void World::UpdateGlobalPlayerGuild(uint32 guid, uint32 guildId)
|
||||
|
||||
itr->second.guildId = guildId;
|
||||
}
|
||||
void World::UpdateGlobalPlayerGroup(uint32 guid, uint32 groupId)
|
||||
void World::UpdateGlobalPlayerGroup(ObjectGuid::LowType guid, uint32 groupId)
|
||||
{
|
||||
GlobalPlayerDataMap::iterator itr = _globalPlayerDataStore.find(guid);
|
||||
if (itr == _globalPlayerDataStore.end())
|
||||
@@ -3330,7 +3327,7 @@ void World::UpdateGlobalPlayerGroup(uint32 guid, uint32 groupId)
|
||||
itr->second.groupId = groupId;
|
||||
}
|
||||
|
||||
void World::UpdateGlobalPlayerArenaTeam(uint32 guid, uint8 slot, uint32 arenaTeamId)
|
||||
void World::UpdateGlobalPlayerArenaTeam(ObjectGuid::LowType guid, uint8 slot, uint32 arenaTeamId)
|
||||
{
|
||||
GlobalPlayerDataMap::iterator itr = _globalPlayerDataStore.find(guid);
|
||||
if (itr == _globalPlayerDataStore.end())
|
||||
@@ -3339,13 +3336,13 @@ void World::UpdateGlobalPlayerArenaTeam(uint32 guid, uint8 slot, uint32 arenaTea
|
||||
itr->second.arenaTeamId[slot] = arenaTeamId;
|
||||
}
|
||||
|
||||
void World::UpdateGlobalNameData(uint32 guidLow, std::string const& oldName, std::string const& newName)
|
||||
void World::UpdateGlobalNameData(ObjectGuid::LowType guidLow, std::string const& oldName, std::string const& newName)
|
||||
{
|
||||
_globalPlayerNameStore.erase(oldName);
|
||||
_globalPlayerNameStore[newName] = guidLow;
|
||||
}
|
||||
|
||||
void World::DeleteGlobalPlayerData(uint32 guid, std::string const& name)
|
||||
void World::DeleteGlobalPlayerData(ObjectGuid::LowType guid, std::string const& name)
|
||||
{
|
||||
if (guid)
|
||||
_globalPlayerDataStore.erase(guid);
|
||||
@@ -3353,7 +3350,7 @@ void World::DeleteGlobalPlayerData(uint32 guid, std::string const& name)
|
||||
_globalPlayerNameStore.erase(name);
|
||||
}
|
||||
|
||||
GlobalPlayerData const* World::GetGlobalPlayerData(uint32 guid) const
|
||||
GlobalPlayerData const* World::GetGlobalPlayerData(ObjectGuid::LowType guid) const
|
||||
{
|
||||
// Get data from global storage
|
||||
GlobalPlayerDataMap::const_iterator itr = _globalPlayerDataStore.find(guid);
|
||||
@@ -3401,12 +3398,12 @@ GlobalPlayerData const* World::GetGlobalPlayerData(uint32 guid) const
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
uint32 World::GetGlobalPlayerGUID(std::string const& name) const
|
||||
ObjectGuid World::GetGlobalPlayerGUID(std::string const& name) const
|
||||
{
|
||||
// Get data from global storage
|
||||
GlobalPlayerNameMap::const_iterator itr = _globalPlayerNameStore.find(name);
|
||||
if (itr != _globalPlayerNameStore.end())
|
||||
return itr->second;
|
||||
return ObjectGuid::Create<HighGuid::Player>(itr->second);
|
||||
|
||||
// Player is not in the global storage, try to get it from the Database
|
||||
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_DATA_BY_NAME);
|
||||
@@ -3421,7 +3418,7 @@ uint32 World::GetGlobalPlayerGUID(std::string const& name) const
|
||||
// Let's add it to the global storage
|
||||
Field* fields = result->Fetch();
|
||||
|
||||
uint32 guidLow = fields[0].GetUInt32();
|
||||
ObjectGuid::LowType guidLow = fields[0].GetUInt32();
|
||||
|
||||
LOG_INFO("server", "Player %s [GUID: %u] was not found in the global storage, but it was found in the database.", name.c_str(), guidLow);
|
||||
|
||||
@@ -3442,10 +3439,16 @@ uint32 World::GetGlobalPlayerGUID(std::string const& name) const
|
||||
{
|
||||
LOG_INFO("server", "Player %s [GUID: %u] added to the global storage.", name.c_str(), guidLow);
|
||||
|
||||
return guidLow;
|
||||
return ObjectGuid::Create<HighGuid::Player>(guidLow);
|
||||
}
|
||||
}
|
||||
|
||||
// Player not found
|
||||
return 0;
|
||||
return ObjectGuid::Empty;
|
||||
}
|
||||
|
||||
void World::RemoveOldCorpses()
|
||||
{
|
||||
m_timers[WUPDATE_CORPSES].SetCurrent(m_timers[WUPDATE_CORPSES].GetInterval());
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "Callback.h"
|
||||
#include "Common.h"
|
||||
#include "IWorld.h"
|
||||
#include "ObjectGuid.h"
|
||||
#include "QueryResult.h"
|
||||
#include "SharedDefines.h"
|
||||
#include "Timer.h"
|
||||
@@ -149,8 +150,8 @@ enum GlobalPlayerUpdateMask
|
||||
PLAYER_UPDATE_DATA_NAME = 0x10,
|
||||
};
|
||||
|
||||
typedef std::map<uint32, GlobalPlayerData> GlobalPlayerDataMap;
|
||||
typedef std::map<std::string, uint32> GlobalPlayerNameMap;
|
||||
typedef std::map<ObjectGuid::LowType, GlobalPlayerData> GlobalPlayerDataMap;
|
||||
typedef std::map<std::string, ObjectGuid::LowType> GlobalPlayerNameMap;
|
||||
|
||||
// xinef: petitions storage
|
||||
struct PetitionData
|
||||
@@ -170,7 +171,7 @@ public:
|
||||
|
||||
WorldSession* FindSession(uint32 id) const;
|
||||
WorldSession* FindOfflineSession(uint32 id) const;
|
||||
WorldSession* FindOfflineSessionForCharacterGUID(uint32 guidLow) const;
|
||||
WorldSession* FindOfflineSessionForCharacterGUID(ObjectGuid::LowType guidLow) const;
|
||||
void AddSession(WorldSession* s);
|
||||
void SendAutoBroadcast();
|
||||
bool KickSession(uint32 id);
|
||||
@@ -356,16 +357,16 @@ public:
|
||||
|
||||
// xinef: Global Player Data Storage system
|
||||
void LoadGlobalPlayerDataStore();
|
||||
uint32 GetGlobalPlayerGUID(std::string const& name) const;
|
||||
GlobalPlayerData const* GetGlobalPlayerData(uint32 guid) const;
|
||||
void AddGlobalPlayerData(uint32 guid, uint32 accountId, std::string const& name, uint8 gender, uint8 race, uint8 playerClass, uint8 level, uint16 mailCount, uint32 guildId);
|
||||
void UpdateGlobalPlayerData(uint32 guid, uint8 mask, std::string const& name, uint8 level = 0, uint8 gender = 0, uint8 race = 0, uint8 playerClass = 0);
|
||||
void UpdateGlobalPlayerMails(uint32 guid, int16 count, bool add = true);
|
||||
void UpdateGlobalPlayerGuild(uint32 guid, uint32 guildId);
|
||||
void UpdateGlobalPlayerGroup(uint32 guid, uint32 groupId);
|
||||
void UpdateGlobalPlayerArenaTeam(uint32 guid, uint8 slot, uint32 arenaTeamId);
|
||||
void UpdateGlobalNameData(uint32 guidLow, std::string const& oldName, std::string const& newName);
|
||||
void DeleteGlobalPlayerData(uint32 guid, std::string const& name);
|
||||
ObjectGuid GetGlobalPlayerGUID(std::string const& name) const;
|
||||
GlobalPlayerData const* GetGlobalPlayerData(ObjectGuid::LowType guid) const;
|
||||
void AddGlobalPlayerData(ObjectGuid::LowType guid, uint32 accountId, std::string const& name, uint8 gender, uint8 race, uint8 playerClass, uint8 level, uint16 mailCount, uint32 guildId);
|
||||
void UpdateGlobalPlayerData(ObjectGuid::LowType guid, uint8 mask, std::string const& name, uint8 level = 0, uint8 gender = 0, uint8 race = 0, uint8 playerClass = 0);
|
||||
void UpdateGlobalPlayerMails(ObjectGuid::LowType guid, int16 count, bool add = true);
|
||||
void UpdateGlobalPlayerGuild(ObjectGuid::LowType guid, uint32 guildId);
|
||||
void UpdateGlobalPlayerGroup(ObjectGuid::LowType guid, uint32 groupId);
|
||||
void UpdateGlobalPlayerArenaTeam(ObjectGuid::LowType guid, uint8 slot, uint32 arenaTeamId);
|
||||
void UpdateGlobalNameData(ObjectGuid::LowType guidLow, std::string const& oldName, std::string const& newName);
|
||||
void DeleteGlobalPlayerData(ObjectGuid::LowType guid, std::string const& name);
|
||||
|
||||
void ProcessCliCommands();
|
||||
void QueueCliCommand(CliCommandHolder* commandHolder) { cliCmdQueue.add(commandHolder); }
|
||||
@@ -394,6 +395,8 @@ public:
|
||||
std::string const& GetRealmName() const { return _realmName; } // pussywizard
|
||||
void SetRealmName(std::string name) { _realmName = name; } // pussywizard
|
||||
|
||||
void RemoveOldCorpses();
|
||||
|
||||
protected:
|
||||
void _UpdateGameTime();
|
||||
// callback for UpdateRealmCharacters
|
||||
|
||||
Reference in New Issue
Block a user