fix(Core): Memleaks fixes - Part II. (#5760)

This commit is contained in:
UltraNix
2021-05-14 10:15:45 +02:00
committed by GitHub
parent 1b6c2004ce
commit 8dd58ebb5b
19 changed files with 138 additions and 127 deletions
@@ -205,6 +205,7 @@ void CharacterDatabaseConnection::DoPrepareStatements()
// Chat channel handling // Chat channel handling
PrepareStatement(CHAR_INS_CHANNEL, "INSERT INTO channels(channelId, name, team, announce, lastUsed) VALUES (?, ?, ?, ?, UNIX_TIMESTAMP())", CONNECTION_ASYNC); PrepareStatement(CHAR_INS_CHANNEL, "INSERT INTO channels(channelId, name, team, announce, lastUsed) VALUES (?, ?, ?, ?, UNIX_TIMESTAMP())", CONNECTION_ASYNC);
PrepareStatement(CHAR_UPD_CHANNEL, "UPDATE channels SET announce = ?, password = ?, lastUsed = UNIX_TIMESTAMP() WHERE channelId = ?", CONNECTION_ASYNC); PrepareStatement(CHAR_UPD_CHANNEL, "UPDATE channels SET announce = ?, password = ?, lastUsed = UNIX_TIMESTAMP() WHERE channelId = ?", CONNECTION_ASYNC);
PrepareStatement(CHAR_DEL_CHANNEL, "DELETE FROM channels WHERE name = ? AND team = ?", CONNECTION_ASYNC);
PrepareStatement(CHAR_UPD_CHANNEL_USAGE, "UPDATE channels SET lastUsed = UNIX_TIMESTAMP() WHERE channelId = ?", CONNECTION_ASYNC); PrepareStatement(CHAR_UPD_CHANNEL_USAGE, "UPDATE channels SET lastUsed = UNIX_TIMESTAMP() WHERE channelId = ?", CONNECTION_ASYNC);
PrepareStatement(CHAR_DEL_OLD_CHANNELS, "DELETE FROM channels WHERE lastUsed + ? < UNIX_TIMESTAMP()", CONNECTION_ASYNC); PrepareStatement(CHAR_DEL_OLD_CHANNELS, "DELETE FROM channels WHERE lastUsed + ? < UNIX_TIMESTAMP()", CONNECTION_ASYNC);
PrepareStatement(CHAR_DEL_OLD_CHANNELS_BANS, "DELETE cb.* FROM channels_bans cb LEFT JOIN channels cn ON cb.channelId=cn.channelId WHERE cn.channelId IS NULL OR cb.banTime <= UNIX_TIMESTAMP()", CONNECTION_ASYNC); PrepareStatement(CHAR_DEL_OLD_CHANNELS_BANS, "DELETE cb.* FROM channels_bans cb LEFT JOIN channels cn ON cb.channelId=cn.channelId WHERE cn.channelId IS NULL OR cb.banTime <= UNIX_TIMESTAMP()", CONNECTION_ASYNC);
@@ -184,6 +184,7 @@ enum CharacterDatabaseStatements
CHAR_INS_CHANNEL, CHAR_INS_CHANNEL,
CHAR_UPD_CHANNEL, CHAR_UPD_CHANNEL,
CHAR_DEL_CHANNEL,
CHAR_UPD_CHANNEL_USAGE, CHAR_UPD_CHANNEL_USAGE,
CHAR_DEL_OLD_CHANNELS, CHAR_DEL_OLD_CHANNELS,
CHAR_DEL_OLD_CHANNELS_BANS, CHAR_DEL_OLD_CHANNELS_BANS,
@@ -2943,24 +2943,20 @@ void AchievementGlobalMgr::LoadRewardLocales()
{ {
Field* fields = result->Fetch(); Field* fields = result->Fetch();
uint32 ID = fields[0].GetUInt32(); uint32 ID = fields[0].GetUInt32();
std::string LocaleName = fields[1].GetString();
std::string Subject = fields[2].GetString();
std::string Text = fields[3].GetString();
if (m_achievementRewards.find(ID) == m_achievementRewards.end()) if (m_achievementRewards.find(ID) == m_achievementRewards.end())
{ {
LOG_ERROR("sql.sql", "Table `achievement_reward_locale` (Entry: %u) has locale strings for non-existing achievement reward.", ID); LOG_ERROR("sql.sql", "Table `achievement_reward_locale` (Entry: %u) has locale strings for non-existing achievement reward.", ID);
continue; continue;
} }
AchievementRewardLocale& data = m_achievementRewardLocales[ID]; LocaleConstant locale = GetLocaleByName(fields[1].GetString());
LocaleConstant locale = GetLocaleByName(LocaleName);
if (locale == LOCALE_enUS) if (locale == LOCALE_enUS)
continue; continue;
ObjectMgr::AddLocaleString(Subject, locale, data.Subject); AchievementRewardLocale& data = m_achievementRewardLocales[ID];
ObjectMgr::AddLocaleString(Text, locale, data.Text); ObjectMgr::AddLocaleString(fields[2].GetString(), locale, data.Subject);
ObjectMgr::AddLocaleString(fields[3].GetString(), locale, data.Text);
} while (result->NextRow()); } while (result->NextRow());
LOG_INFO("server", ">> Loaded %lu Achievement Reward Locale strings in %u ms", (unsigned long)m_achievementRewardLocales.size(), GetMSTimeDiffToNow(oldMSTime)); LOG_INFO("server", ">> Loaded %lu Achievement Reward Locale strings in %u ms", (unsigned long)m_achievementRewardLocales.size(), GetMSTimeDiffToNow(oldMSTime));
@@ -142,7 +142,7 @@ void AuctionHouseMgr::SendAuctionWonMail(AuctionEntry* auction, SQLTransaction&
.SendMailTo(trans, MailReceiver(bidder, auction->bidder.GetCounter()), auction, MAIL_CHECK_MASK_COPIED); .SendMailTo(trans, MailReceiver(bidder, auction->bidder.GetCounter()), auction, MAIL_CHECK_MASK_COPIED);
} }
else else
sAuctionMgr->RemoveAItem(auction->item_guid, true); sAuctionMgr->RemoveAItem(auction->item_guid, true, &trans);
} }
void AuctionHouseMgr::SendAuctionSalePendingMail(AuctionEntry* auction, SQLTransaction& trans, bool sendMail) void AuctionHouseMgr::SendAuctionSalePendingMail(AuctionEntry* auction, SQLTransaction& trans, bool sendMail)
@@ -229,7 +229,7 @@ void AuctionHouseMgr::SendAuctionExpiredMail(AuctionEntry* auction, SQLTransacti
.SendMailTo(trans, MailReceiver(owner, auction->owner.GetCounter()), auction, MAIL_CHECK_MASK_COPIED, 0); .SendMailTo(trans, MailReceiver(owner, auction->owner.GetCounter()), auction, MAIL_CHECK_MASK_COPIED, 0);
} }
else else
sAuctionMgr->RemoveAItem(auction->item_guid, true); sAuctionMgr->RemoveAItem(auction->item_guid, true, &trans);
} }
//this function sends mail to old bidder //this function sends mail to old bidder
@@ -377,7 +377,7 @@ void AuctionHouseMgr::AddAItem(Item* it)
mAitems[it->GetGUID()] = it; mAitems[it->GetGUID()] = it;
} }
bool AuctionHouseMgr::RemoveAItem(ObjectGuid itemGuid, bool deleteFromDB) bool AuctionHouseMgr::RemoveAItem(ObjectGuid itemGuid, bool deleteFromDB, SQLTransaction* trans /*= nullptr*/)
{ {
ItemMap::iterator i = mAitems.find(itemGuid); ItemMap::iterator i = mAitems.find(itemGuid);
if (i == mAitems.end()) if (i == mAitems.end())
@@ -385,10 +385,9 @@ bool AuctionHouseMgr::RemoveAItem(ObjectGuid itemGuid, bool deleteFromDB)
if (deleteFromDB) if (deleteFromDB)
{ {
SQLTransaction trans = CharacterDatabase.BeginTransaction(); ASSERT(trans);
i->second->FSetState(ITEM_REMOVED); i->second->FSetState(ITEM_REMOVED);
i->second->SaveToDB(trans); i->second->SaveToDB(*trans);
CharacterDatabase.CommitTransaction(trans);
} }
mAitems.erase(i); mAitems.erase(i);
@@ -173,7 +173,7 @@ public:
void LoadAuctions(); void LoadAuctions();
void AddAItem(Item* it); void AddAItem(Item* it);
bool RemoveAItem(ObjectGuid itemGuid, bool deleteFromDB = false); bool RemoveAItem(ObjectGuid itemGuid, bool deleteFromDB = false, SQLTransaction* trans = nullptr);
void Update(); void Update();
+4 -5
View File
@@ -461,10 +461,8 @@ void Battlefield::BroadcastPacketToWar(WorldPacket& data) const
void Battlefield::SendWarningToAllInZone(uint32 entry) void Battlefield::SendWarningToAllInZone(uint32 entry)
{ {
if (Map* map = sMapMgr->CreateBaseMap(m_MapId)) if (Creature* stalker = GetCreature(StalkerGuid))
if (Unit* unit = map->GetCreature(StalkerGuid)) sCreatureTextMgr->SendChat(stalker, (uint8)entry, nullptr, CHAT_MSG_ADDON, LANG_ADDON, TEXT_RANGE_ZONE);
if (Creature* stalker = unit->ToCreature())
sCreatureTextMgr->SendChat(stalker, (uint8)entry, nullptr, CHAT_MSG_ADDON, LANG_ADDON, TEXT_RANGE_ZONE);
} }
void Battlefield::SendWarningToPlayer(Player* player, uint32 entry) void Battlefield::SendWarningToPlayer(Player* player, uint32 entry)
@@ -814,6 +812,7 @@ Creature* Battlefield::SpawnCreature(uint32 entry, float x, float y, float z, fl
// Set creature in world // Set creature in world
map->AddToMap(creature); map->AddToMap(creature);
creature->setActive(true);
return creature; return creature;
} }
@@ -822,7 +821,7 @@ Creature* Battlefield::SpawnCreature(uint32 entry, float x, float y, float z, fl
GameObject* Battlefield::SpawnGameObject(uint32 entry, float x, float y, float z, float o) GameObject* Battlefield::SpawnGameObject(uint32 entry, float x, float y, float z, float o)
{ {
// Get map object // Get map object
Map* map = sMapMgr->CreateBaseMap(571); // *vomits* Map* map = sMapMgr->CreateBaseMap(m_MapId);
if (!map) if (!map)
return 0; return 0;
+31 -9
View File
@@ -39,28 +39,42 @@ void ChannelMgr::LoadChannels()
uint32 count = 0; uint32 count = 0;
// 0 1 2 3 4 5 // 0 1 2 3 4 5
QueryResult result = CharacterDatabase.PQuery("SELECT channelId, name, team, announce, ownership, password FROM channels WHERE team = %u ORDER BY channelId ASC", _teamId); QueryResult result = CharacterDatabase.PQuery("SELECT channelId, name, team, announce, ownership, password FROM channels ORDER BY channelId ASC");
if (!result) if (!result)
{ {
LOG_INFO("server", ">> Loaded 0 channels for %s", _teamId == TEAM_ALLIANCE ? "Alliance" : "Horde"); LOG_INFO("server", ">> Loaded 0 channels. DB table `channels` is empty.");
return; return;
} }
std::vector<std::pair<std::string, uint32>> toDelete;
do do
{ {
Field* fields = result->Fetch(); Field* fields = result->Fetch();
if (!fields)
break;
uint32 channelDBId = fields[0].GetUInt32(); uint32 channelDBId = fields[0].GetUInt32();
std::string channelName = fields[1].GetString(); std::string channelName = fields[1].GetString();
TeamId team = TeamId(fields[2].GetUInt32());
std::string password = fields[5].GetString(); std::string password = fields[5].GetString();
std::wstring channelWName;
Utf8toWStr(channelName, channelWName);
Channel* newChannel = new Channel(channelName, 0, channelDBId, TeamId(fields[2].GetUInt32()), fields[3].GetUInt8(), fields[4].GetUInt8()); std::wstring channelWName;
if (!Utf8toWStr(channelName, channelWName))
{
LOG_ERROR("server", "Failed to load channel '%s' from database - invalid utf8 sequence? Deleted.", channelName.c_str());
toDelete.push_back({ channelName, team });
continue;
}
ChannelMgr* mgr = forTeam(team);
if (!mgr)
{
LOG_ERROR("server", "Failed to load custom chat channel '%s' from database - invalid team %u. Deleted.", channelName.c_str(), team);
toDelete.push_back({ channelName, team });
continue;
}
Channel* newChannel = new Channel(channelName, 0, channelDBId, team, fields[3].GetUInt8(), fields[4].GetUInt8());
newChannel->SetPassword(password); newChannel->SetPassword(password);
channels[channelWName] = newChannel; mgr->channels[channelWName] = newChannel;
if (QueryResult banResult = CharacterDatabase.PQuery("SELECT playerGUID, banTime FROM channels_bans WHERE channelId = %u", channelDBId)) if (QueryResult banResult = CharacterDatabase.PQuery("SELECT playerGUID, banTime FROM channels_bans WHERE channelId = %u", channelDBId))
{ {
@@ -78,7 +92,15 @@ void ChannelMgr::LoadChannels()
++count; ++count;
} while (result->NextRow()); } while (result->NextRow());
LOG_INFO("server", ">> Loaded %u channels for %s in %ums", count, _teamId == TEAM_ALLIANCE ? "Alliance" : "Horde", GetMSTimeDiffToNow(oldMSTime)); for (auto pair : toDelete)
{
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CHANNEL);
stmt->setString(0, pair.first);
stmt->setUInt32(1, pair.second);
CharacterDatabase.Execute(stmt);
}
LOG_INFO("server", ">> Loaded %u channels in %ums", count, GetMSTimeDiffToNow(oldMSTime));
LOG_INFO("server", " "); LOG_INFO("server", " ");
} }
+1 -1
View File
@@ -29,7 +29,7 @@ public:
Channel* GetJoinChannel(std::string const& name, uint32 channel_id); Channel* GetJoinChannel(std::string const& name, uint32 channel_id);
Channel* GetChannel(std::string const& name, Player* p, bool pkt = true); Channel* GetChannel(std::string const& name, Player* p, bool pkt = true);
void LoadChannels(); static void LoadChannels();
static void LoadChannelRights(); static void LoadChannelRights();
static const ChannelRights& GetChannelRightsFor(const std::string& name); static const ChannelRights& GetChannelRightsFor(const std::string& name);
+7 -1
View File
@@ -19253,7 +19253,6 @@ void Player::_LoadMailedItems(Mail* mail)
} }
Item* item = NewItemOrBag(proto); Item* item = NewItemOrBag(proto);
if (!item->LoadFromDB(itemGuid, ObjectGuid::Create<HighGuid::Player>(fields[13].GetUInt32()), fields, itemTemplate)) if (!item->LoadFromDB(itemGuid, ObjectGuid::Create<HighGuid::Player>(fields[13].GetUInt32()), fields, itemTemplate))
{ {
LOG_ERROR("server", "Player::_LoadMailedItems - Item in mail (%u) doesn't exist !!!! - item guid: %u, deleted from mail", mail->messageID, itemGuid); LOG_ERROR("server", "Player::_LoadMailedItems - Item in mail (%u) doesn't exist !!!! - item guid: %u, deleted from mail", mail->messageID, itemGuid);
@@ -19319,6 +19318,13 @@ void Player::_LoadMail()
itr = GetMailBegin(); itr = GetMailBegin();
} }
// Delete mailed items aswell
// Created again below in Player::_LoadMailedItems
for (ItemMap::iterator iter = mMitems.begin(); iter != mMitems.end(); ++iter)
delete iter->second;
mMitems.clear();
//Now load the new ones //Now load the new ones
m_mailCache.clear(); m_mailCache.clear();
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_MAIL); PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_MAIL);
+5 -5
View File
@@ -12688,11 +12688,11 @@ void Unit::ApplySpellImmune(uint32 spellId, uint32 op, uint32 type, bool apply,
if (spellId == 0 && std::find_if(m_spellImmune[op].begin(), m_spellImmune[op].end(), spellIdImmunityPredicate(type)) != m_spellImmune[op].end()) if (spellId == 0 && std::find_if(m_spellImmune[op].begin(), m_spellImmune[op].end(), spellIdImmunityPredicate(type)) != m_spellImmune[op].end())
return; return;
SpellImmune Immune; SpellImmune immune;
Immune.spellId = spellId; immune.spellId = spellId;
Immune.type = type; immune.type = type;
Immune.blockType = blockType; immune.blockType = blockType;
m_spellImmune[op].push_back(Immune); m_spellImmune[op].push_back(std::move(immune));
} }
else else
{ {
+5 -3
View File
@@ -342,12 +342,14 @@ enum SpellImmuneBlockType
struct SpellImmune struct SpellImmune
{ {
SpellImmune() : spellId(0), type(IMMUNITY_EFFECT), blockType(SPELL_BLOCK_TYPE_ALL) { }
uint32 spellId; uint32 spellId;
uint32 type : 16; uint32 type;
uint32 blockType : 16; uint32 blockType;
}; };
typedef std::list<SpellImmune> SpellImmuneList; typedef std::vector<SpellImmune> SpellImmuneList;
enum UnitModifierType enum UnitModifierType
{ {
+46 -68
View File
@@ -361,14 +361,14 @@ ObjectMgr* ObjectMgr::instance()
return &instance; return &instance;
} }
void ObjectMgr::AddLocaleString(std::string const& s, LocaleConstant locale, StringVector& data) void ObjectMgr::AddLocaleString(std::string&& s, LocaleConstant locale, StringVector& data)
{ {
if (!s.empty()) if (!s.empty())
{ {
if (data.size() <= size_t(locale)) if (data.size() <= size_t(locale))
data.resize(locale + 1); data.resize(locale + 1);
data[locale] = s; data[locale] = std::move(s);
} }
} }
@@ -387,18 +387,15 @@ void ObjectMgr::LoadCreatureLocales()
{ {
Field* fields = result->Fetch(); Field* fields = result->Fetch();
uint32 ID = fields[0].GetUInt32(); uint32 ID = fields[0].GetUInt32();
std::string LocaleName = fields[1].GetString();
std::string Name = fields[2].GetString();
std::string Title = fields[3].GetString();
CreatureLocale& data = _creatureLocaleStore[ID]; LocaleConstant locale = GetLocaleByName(fields[1].GetString());
LocaleConstant locale = GetLocaleByName(LocaleName);
if (locale == LOCALE_enUS) if (locale == LOCALE_enUS)
continue; continue;
AddLocaleString(Name, locale, data.Name); CreatureLocale& data = _creatureLocaleStore[ID];
AddLocaleString(Title, locale, data.Title); AddLocaleString(fields[2].GetString(), locale, data.Name);
AddLocaleString(fields[3].GetString(), locale, data.Title);
} while (result->NextRow()); } while (result->NextRow());
LOG_INFO("server", ">> Loaded %lu Creature Locale strings in %u ms", (unsigned long)_creatureLocaleStore.size(), GetMSTimeDiffToNow(oldMSTime)); LOG_INFO("server", ">> Loaded %lu Creature Locale strings in %u ms", (unsigned long)_creatureLocaleStore.size(), GetMSTimeDiffToNow(oldMSTime));
@@ -420,20 +417,16 @@ void ObjectMgr::LoadGossipMenuItemsLocales()
{ {
Field* fields = result->Fetch(); Field* fields = result->Fetch();
uint16 MenuID = fields[0].GetUInt16(); uint16 MenuID = fields[0].GetUInt16();
uint16 OptionID = fields[1].GetUInt16(); uint16 OptionID = fields[1].GetUInt16();
std::string LocaleName = fields[2].GetString();
LocaleConstant locale = GetLocaleByName(LocaleName); LocaleConstant locale = GetLocaleByName(fields[2].GetString());
if (locale == LOCALE_enUS) if (locale == LOCALE_enUS)
continue; continue;
std::string OptionText = fields[3].GetString();
std::string BoxText = fields[4].GetString();
GossipMenuItemsLocale& data = _gossipMenuItemsLocaleStore[MAKE_PAIR32(MenuID, OptionID)]; GossipMenuItemsLocale& data = _gossipMenuItemsLocaleStore[MAKE_PAIR32(MenuID, OptionID)];
AddLocaleString(OptionText, locale, data.OptionText); AddLocaleString(fields[3].GetString(), locale, data.OptionText);
AddLocaleString(BoxText, locale, data.BoxText); AddLocaleString(fields[4].GetString(), locale, data.BoxText);
} while (result->NextRow()); } while (result->NextRow());
LOG_INFO("server", ">> Loaded %u Gossip Menu Option Locale strings in %u ms", (uint32)_gossipMenuItemsLocaleStore.size(), GetMSTimeDiffToNow(oldMSTime)); LOG_INFO("server", ">> Loaded %u Gossip Menu Option Locale strings in %u ms", (uint32)_gossipMenuItemsLocaleStore.size(), GetMSTimeDiffToNow(oldMSTime));
@@ -455,16 +448,14 @@ void ObjectMgr::LoadPointOfInterestLocales()
{ {
Field* fields = result->Fetch(); Field* fields = result->Fetch();
uint32 ID = fields[0].GetUInt32(); uint32 ID = fields[0].GetUInt32();
std::string LocaleName = fields[1].GetString();
std::string Name = fields[2].GetString();
PointOfInterestLocale& data = _pointOfInterestLocaleStore[ID]; LocaleConstant locale = GetLocaleByName(fields[1].GetString());
LocaleConstant locale = GetLocaleByName(LocaleName);
if (locale == LOCALE_enUS) if (locale == LOCALE_enUS)
continue; continue;
AddLocaleString(Name, locale, data.Name); PointOfInterestLocale& data = _pointOfInterestLocaleStore[ID];
AddLocaleString(fields[2].GetString(), locale, data.Name);
} while (result->NextRow()); } while (result->NextRow());
LOG_INFO("server", ">> Loaded %u Points Of Interest Locale strings in %u ms", (uint32)_pointOfInterestLocaleStore.size(), GetMSTimeDiffToNow(oldMSTime)); LOG_INFO("server", ">> Loaded %u Points Of Interest Locale strings in %u ms", (uint32)_pointOfInterestLocaleStore.size(), GetMSTimeDiffToNow(oldMSTime));
@@ -2380,18 +2371,15 @@ void ObjectMgr::LoadItemLocales()
{ {
Field* fields = result->Fetch(); Field* fields = result->Fetch();
uint32 ID = fields[0].GetUInt32(); uint32 ID = fields[0].GetUInt32();
std::string LocaleName = fields[1].GetString();
std::string Name = fields[2].GetString();
std::string Description = fields[3].GetString();
ItemLocale& data = _itemLocaleStore[ID]; LocaleConstant locale = GetLocaleByName(fields[1].GetString());
LocaleConstant locale = GetLocaleByName(LocaleName);
if (locale == LOCALE_enUS) if (locale == LOCALE_enUS)
continue; continue;
AddLocaleString(Name, locale, data.Name); ItemLocale& data = _itemLocaleStore[ID];
AddLocaleString(Description, locale, data.Description); AddLocaleString(fields[2].GetString(), locale, data.Name);
AddLocaleString(fields[3].GetString(), locale, data.Description);
} while (result->NextRow()); } while (result->NextRow());
LOG_INFO("server", ">> Loaded %u Item Locale strings in %u ms", (uint32)_itemLocaleStore.size(), GetMSTimeDiffToNow(oldMSTime)); LOG_INFO("server", ">> Loaded %u Item Locale strings in %u ms", (uint32)_itemLocaleStore.size(), GetMSTimeDiffToNow(oldMSTime));
@@ -3006,16 +2994,14 @@ void ObjectMgr::LoadItemSetNameLocales()
{ {
Field* fields = result->Fetch(); Field* fields = result->Fetch();
uint32 ID = fields[0].GetUInt32(); uint32 ID = fields[0].GetUInt32();
std::string LocaleName = fields[1].GetString();
std::string Name = fields[2].GetString();
ItemSetNameLocale& data = _itemSetNameLocaleStore[ID]; LocaleConstant locale = GetLocaleByName(fields[1].GetString());
LocaleConstant locale = GetLocaleByName(LocaleName);
if (locale == LOCALE_enUS) if (locale == LOCALE_enUS)
continue; continue;
AddLocaleString(Name, locale, data.Name); ItemSetNameLocale& data = _itemSetNameLocaleStore[ID];
AddLocaleString(fields[2].GetString(), locale, data.Name);
} while (result->NextRow()); } while (result->NextRow());
LOG_INFO("server", ">> Loaded %u Item Set Name Locale strings in %u ms", uint32(_itemSetNameLocaleStore.size()), GetMSTimeDiffToNow(oldMSTime)); LOG_INFO("server", ">> Loaded %u Item Set Name Locale strings in %u ms", uint32(_itemSetNameLocaleStore.size()), GetMSTimeDiffToNow(oldMSTime));
@@ -4737,14 +4723,13 @@ void ObjectMgr::LoadQuestLocales()
{ {
Field* fields = result->Fetch(); Field* fields = result->Fetch();
uint32 ID = fields[0].GetUInt32(); uint32 ID = fields[0].GetUInt32();
std::string LocaleName = fields[1].GetString();
QuestLocale& data = _questLocaleStore[ID]; LocaleConstant locale = GetLocaleByName(fields[1].GetString());
LocaleConstant locale = GetLocaleByName(LocaleName);
if (locale == LOCALE_enUS) if (locale == LOCALE_enUS)
continue; continue;
QuestLocale& data = _questLocaleStore[ID];
AddLocaleString(fields[2].GetString(), locale, data.Title); AddLocaleString(fields[2].GetString(), locale, data.Title);
AddLocaleString(fields[3].GetString(), locale, data.Details); AddLocaleString(fields[3].GetString(), locale, data.Details);
AddLocaleString(fields[4].GetString(), locale, data.Objectives); AddLocaleString(fields[4].GetString(), locale, data.Objectives);
@@ -5362,14 +5347,14 @@ void ObjectMgr::LoadPageTextLocales()
{ {
Field* fields = result->Fetch(); Field* fields = result->Fetch();
uint32 ID = fields[0].GetUInt32(); uint32 ID = fields[0].GetUInt32();
std::string LocaleName = fields[1].GetString();
std::string Text = fields[2].GetString();
PageTextLocale& data = _pageTextLocaleStore[ID]; LocaleConstant locale = GetLocaleByName(fields[1].GetString());
LocaleConstant locale = GetLocaleByName(LocaleName); if (locale == LOCALE_enUS)
continue;
AddLocaleString(Text, locale, data.Text); PageTextLocale& data = _pageTextLocaleStore[ID];
AddLocaleString(fields[2].GetString(), locale, data.Text);
} while (result->NextRow()); } while (result->NextRow());
LOG_INFO("server", ">> Loaded %u Page Text Locale strings in %u ms", (uint32)_pageTextLocaleStore.size(), GetMSTimeDiffToNow(oldMSTime)); LOG_INFO("server", ">> Loaded %u Page Text Locale strings in %u ms", (uint32)_pageTextLocaleStore.size(), GetMSTimeDiffToNow(oldMSTime));
@@ -5613,14 +5598,13 @@ void ObjectMgr::LoadNpcTextLocales()
{ {
Field* fields = result->Fetch(); Field* fields = result->Fetch();
uint32 ID = fields[0].GetUInt32(); uint32 ID = fields[0].GetUInt32();
std::string LocaleName = fields[1].GetString();
NpcTextLocale& data = _npcTextLocaleStore[ID]; LocaleConstant locale = GetLocaleByName(fields[1].GetString());
LocaleConstant locale = GetLocaleByName(LocaleName);
if (locale == LOCALE_enUS) if (locale == LOCALE_enUS)
continue; continue;
NpcTextLocale& data = _npcTextLocaleStore[ID];
for (uint8 i = 0; i < MAX_GOSSIP_TEXT_OPTIONS; ++i) for (uint8 i = 0; i < MAX_GOSSIP_TEXT_OPTIONS; ++i)
{ {
AddLocaleString(fields[2 + i * 2].GetString(), locale, data.Text_0[i]); AddLocaleString(fields[2 + i * 2].GetString(), locale, data.Text_0[i]);
@@ -6498,18 +6482,15 @@ void ObjectMgr::LoadGameObjectLocales()
{ {
Field* fields = result->Fetch(); Field* fields = result->Fetch();
uint32 ID = fields[0].GetUInt32(); uint32 ID = fields[0].GetUInt32();
std::string LocaleName = fields[1].GetString();
std::string Name = fields[2].GetString();
std::string CastBarCaption = fields[3].GetString();
GameObjectLocale& data = _gameObjectLocaleStore[ID]; LocaleConstant locale = GetLocaleByName(fields[1].GetString());
LocaleConstant locale = GetLocaleByName(LocaleName);
if (locale == LOCALE_enUS) if (locale == LOCALE_enUS)
continue; continue;
AddLocaleString(Name, locale, data.Name); GameObjectLocale& data = _gameObjectLocaleStore[ID];
AddLocaleString(CastBarCaption, locale, data.CastBarCaption); AddLocaleString(fields[2].GetString(), locale, data.Name);
AddLocaleString(fields[3].GetString(), locale, data.CastBarCaption);
} while (result->NextRow()); } while (result->NextRow());
LOG_INFO("server", ">> Loaded %u Gameobject Locale strings in %u ms", (uint32)_gameObjectLocaleStore.size(), GetMSTimeDiffToNow(oldMSTime)); LOG_INFO("server", ">> Loaded %u Gameobject Locale strings in %u ms", (uint32)_gameObjectLocaleStore.size(), GetMSTimeDiffToNow(oldMSTime));
@@ -8800,10 +8781,7 @@ void ObjectMgr::LoadBroadcastTextLocales()
{ {
Field* fields = result->Fetch(); Field* fields = result->Fetch();
uint32 id = fields[0].GetUInt32(); uint32 id = fields[0].GetUInt32();
std::string LocaleName = fields[1].GetString();
std::string MaleText = fields[2].GetString();
std::string FemaleText = fields[3].GetString();
BroadcastTextContainer::iterator bct = _broadcastTextStore.find(id); BroadcastTextContainer::iterator bct = _broadcastTextStore.find(id);
if (bct == _broadcastTextStore.end()) if (bct == _broadcastTextStore.end())
@@ -8812,12 +8790,12 @@ void ObjectMgr::LoadBroadcastTextLocales()
continue; continue;
} }
LocaleConstant locale = GetLocaleByName(LocaleName); LocaleConstant locale = GetLocaleByName(fields[1].GetString());
if (locale == LOCALE_enUS) if (locale == LOCALE_enUS)
continue; continue;
AddLocaleString(MaleText, locale, bct->second.MaleText); AddLocaleString(fields[2].GetString(), locale, bct->second.MaleText);
AddLocaleString(FemaleText, locale, bct->second.FemaleText); AddLocaleString(fields[3].GetString(), locale, bct->second.FemaleText);
} while (result->NextRow()); } while (result->NextRow());
LOG_INFO("server", ">> Loaded %u Broadcast Text Locales in %u ms", uint32(_broadcastTextStore.size()), GetMSTimeDiffToNow(oldMSTime)); LOG_INFO("server", ">> Loaded %u Broadcast Text Locales in %u ms", uint32(_broadcastTextStore.size()), GetMSTimeDiffToNow(oldMSTime));
+1 -1
View File
@@ -1326,7 +1326,7 @@ public:
return _gossipMenuItemsStore.equal_range(uiMenuId); return _gossipMenuItemsStore.equal_range(uiMenuId);
} }
static void AddLocaleString(std::string const& s, LocaleConstant locale, StringVector& data); static void AddLocaleString(std::string&& s, LocaleConstant locale, StringVector& data);
static inline void GetLocaleString(const StringVector& data, int loc_idx, std::string& value) static inline void GetLocaleString(const StringVector& data, int loc_idx, std::string& value)
{ {
if (data.size() > size_t(loc_idx) && !data[loc_idx].empty()) if (data.size() > size_t(loc_idx) && !data[loc_idx].empty())
+9 -3
View File
@@ -34,8 +34,8 @@ private:
const uint32 m_savedMana; const uint32 m_savedMana;
public: public:
LoadPetFromDBQueryHolder(uint32 petNumber, bool current, uint32 diffTime, std::string actionBar, uint32 health, uint32 mana) LoadPetFromDBQueryHolder(uint32 petNumber, bool current, uint32 diffTime, std::string&& actionBar, uint32 health, uint32 mana)
: m_petNumber(petNumber), m_current(current), m_diffTime(diffTime), m_actionBar(actionBar), : m_petNumber(petNumber), m_current(current), m_diffTime(diffTime), m_actionBar(std::move(actionBar)),
m_savedHealth(health), m_savedMana(mana) { } m_savedHealth(health), m_savedMana(mana) { }
uint32 GetPetNumber() const { return m_petNumber; } uint32 GetPetNumber() const { return m_petNumber; }
@@ -129,8 +129,14 @@ uint8 WorldSession::HandleLoadPetFromDBFirstCallback(PreparedQueryResult result,
Map* map = owner->GetMap(); Map* map = owner->GetMap();
ObjectGuid::LowType guid = map->GenerateLowGuid<HighGuid::Pet>(); ObjectGuid::LowType guid = map->GenerateLowGuid<HighGuid::Pet>();
Pet* pet = new Pet(owner, pet_type); Pet* pet = new Pet(owner, pet_type);
if (!pet->Create(guid, map, owner->GetPhaseMask(), petentry, pet_number))
{
delete pet;
return PET_LOAD_ERROR;
}
LoadPetFromDBQueryHolder* holder = new LoadPetFromDBQueryHolder(pet_number, current, uint32(time(nullptr) - fields[14].GetUInt32()), fields[13].GetString(), savedhealth, savedmana); LoadPetFromDBQueryHolder* holder = new LoadPetFromDBQueryHolder(pet_number, current, uint32(time(nullptr) - fields[14].GetUInt32()), fields[13].GetString(), savedhealth, savedmana);
if (!pet->Create(guid, map, owner->GetPhaseMask(), petentry, pet_number) || !holder->Initialize()) if (!holder->Initialize())
{ {
delete pet; delete pet;
delete holder; delete holder;
@@ -130,7 +130,7 @@ bool ChaseMovementGenerator<T>::DoUpdate(T* owner, uint32 time_diff)
} }
if (!i_path || moveToward != _movingTowards) if (!i_path || moveToward != _movingTowards)
i_path = new PathGenerator(owner); i_path = std::make_unique<PathGenerator>(owner);
float x, y, z; float x, y, z;
bool shortenPath; bool shortenPath;
@@ -188,6 +188,7 @@ bool ChaseMovementGenerator<T>::DoUpdate(T* owner, uint32 time_diff)
template<> template<>
void ChaseMovementGenerator<Player>::DoInitialize(Player* owner) void ChaseMovementGenerator<Player>::DoInitialize(Player* owner)
{ {
i_path = nullptr;
_lastTargetPosition.reset(); _lastTargetPosition.reset();
owner->AddUnitState(UNIT_STATE_CHASE); owner->AddUnitState(UNIT_STATE_CHASE);
} }
@@ -195,6 +196,7 @@ void ChaseMovementGenerator<Player>::DoInitialize(Player* owner)
template<> template<>
void ChaseMovementGenerator<Creature>::DoInitialize(Creature* owner) void ChaseMovementGenerator<Creature>::DoInitialize(Creature* owner)
{ {
i_path = nullptr;
_lastTargetPosition.reset(); _lastTargetPosition.reset();
owner->SetWalk(false); owner->SetWalk(false);
owner->AddUnitState(UNIT_STATE_CHASE); owner->AddUnitState(UNIT_STATE_CHASE);
@@ -305,7 +307,7 @@ bool FollowMovementGenerator<T>::DoUpdate(T* owner, uint32 time_diff)
return true; return true;
if (!i_path) if (!i_path)
i_path = new PathGenerator(owner); i_path = std::make_unique<PathGenerator>(owner);
float x, y, z; float x, y, z;
// select angle // select angle
@@ -376,6 +378,7 @@ void FollowMovementGenerator<Creature>::_updateSpeed(Creature* owner)
template<class T> template<class T>
void FollowMovementGenerator<T>::DoInitialize(T* owner) void FollowMovementGenerator<T>::DoInitialize(T* owner)
{ {
i_path = nullptr;
_lastTargetPosition.reset(); _lastTargetPosition.reset();
owner->AddUnitState(UNIT_STATE_FOLLOW); owner->AddUnitState(UNIT_STATE_FOLLOW);
_updateSpeed(owner); _updateSpeed(owner);
@@ -29,7 +29,7 @@ class ChaseMovementGenerator : public MovementGeneratorMedium<T, ChaseMovementGe
public: public:
ChaseMovementGenerator(Unit* target, std::optional<ChaseRange> range = {}, std::optional<ChaseAngle> angle = {}) ChaseMovementGenerator(Unit* target, std::optional<ChaseRange> range = {}, std::optional<ChaseAngle> angle = {})
: TargetedMovementGeneratorBase(target), i_path(nullptr), i_recheckDistance(0), i_recalculateTravel(true), _range(range), _angle(angle) {} : TargetedMovementGeneratorBase(target), i_path(nullptr), i_recheckDistance(0), i_recalculateTravel(true), _range(range), _angle(angle) {}
~ChaseMovementGenerator() { delete i_path; } ~ChaseMovementGenerator() { }
MovementGeneratorType GetMovementGeneratorType() { return CHASE_MOTION_TYPE; } MovementGeneratorType GetMovementGeneratorType() { return CHASE_MOTION_TYPE; }
@@ -48,7 +48,7 @@ public:
bool HasLostTarget(Unit* unit) const { return unit->GetVictim() != this->GetTarget(); } bool HasLostTarget(Unit* unit) const { return unit->GetVictim() != this->GetTarget(); }
private: private:
PathGenerator* i_path; std::unique_ptr<PathGenerator> i_path;
TimeTrackerSmall i_recheckDistance; TimeTrackerSmall i_recheckDistance;
bool i_recalculateTravel; bool i_recalculateTravel;
@@ -65,7 +65,7 @@ class FollowMovementGenerator : public MovementGeneratorMedium<T, FollowMovement
public: public:
FollowMovementGenerator(Unit* target, float range, ChaseAngle angle) FollowMovementGenerator(Unit* target, float range, ChaseAngle angle)
: TargetedMovementGeneratorBase(target), i_path(nullptr), i_recheckDistance(0), i_recalculateTravel(true), _range(range), _angle(angle) {} : TargetedMovementGeneratorBase(target), i_path(nullptr), i_recheckDistance(0), i_recalculateTravel(true), _range(range), _angle(angle) {}
~FollowMovementGenerator() { delete i_path; } ~FollowMovementGenerator() { }
MovementGeneratorType GetMovementGeneratorType() { return FOLLOW_MOTION_TYPE; } MovementGeneratorType GetMovementGeneratorType() { return FOLLOW_MOTION_TYPE; }
@@ -87,7 +87,7 @@ public:
void _updateSpeed(T* owner); void _updateSpeed(T* owner);
private: private:
PathGenerator* i_path; std::unique_ptr<PathGenerator> i_path;
TimeTrackerSmall i_recheckDistance; TimeTrackerSmall i_recheckDistance;
bool i_recalculateTravel; bool i_recalculateTravel;
+3
View File
@@ -1308,6 +1308,9 @@ void WorldSession::ProcessQueryCallbackPet()
Player* player = GetPlayer(); Player* player = GetPlayer();
if (!player) if (!player)
{ {
SQLQueryHolder* param;
_loadPetFromDBSecondCallback.get(param);
delete param;
_loadPetFromDBSecondCallback.cancel(); _loadPetFromDBSecondCallback.cancel();
} }
else if (!player->IsInWorld()) else if (!player->IsInWorld())
+3 -5
View File
@@ -174,15 +174,13 @@ void CreatureTextMgr::LoadCreatureTextLocales()
uint32 CreatureId = fields[0].GetUInt32(); uint32 CreatureId = fields[0].GetUInt32();
uint32 GroupId = fields[1].GetUInt8(); uint32 GroupId = fields[1].GetUInt8();
uint32 ID = fields[2].GetUInt8(); uint32 ID = fields[2].GetUInt8();
std::string LocaleName = fields[3].GetString();
std::string Text = fields[4].GetString();
CreatureTextLocale& data = mLocaleTextMap[CreatureTextId(CreatureId, GroupId, ID)]; LocaleConstant locale = GetLocaleByName(fields[3].GetString());
LocaleConstant locale = GetLocaleByName(LocaleName);
if (locale == LOCALE_enUS) if (locale == LOCALE_enUS)
continue; continue;
ObjectMgr::AddLocaleString(Text, locale, data.Text); CreatureTextLocale& data = mLocaleTextMap[CreatureTextId(CreatureId, GroupId, ID)];
ObjectMgr::AddLocaleString(fields[4].GetString(), locale, data.Text);
} while (result->NextRow()); } while (result->NextRow());
LOG_INFO("server", ">> Loaded %u Creature Text Locale in %u ms", uint32(mLocaleTextMap.size()), GetMSTimeDiffToNow(oldMSTime)); LOG_INFO("server", ">> Loaded %u Creature Text Locale in %u ms", uint32(mLocaleTextMap.size()), GetMSTimeDiffToNow(oldMSTime));
+1 -4
View File
@@ -2039,10 +2039,7 @@ void World::SetInitialWorldSettings()
ChannelMgr::LoadChannelRights(); ChannelMgr::LoadChannelRights();
LOG_INFO("server", "Load Channels..."); LOG_INFO("server", "Load Channels...");
ChannelMgr* mgr = ChannelMgr::forTeam(TEAM_ALLIANCE); ChannelMgr::LoadChannels();
mgr->LoadChannels();
mgr = ChannelMgr::forTeam(TEAM_HORDE);
mgr->LoadChannels();
#ifdef ELUNA #ifdef ELUNA
///- Run eluna scripts. ///- Run eluna scripts.