fix(Core/CreatureText): race conditions in CreatureTextMgr repeat group (#23153)

Co-authored-by: Shauren <shauren.trinity@gmail.com>
Co-authored-by: Giacomo Pozzoni <giacomopoz@gmail.com>
This commit is contained in:
天鹭
2025-10-13 08:30:32 +08:00
committed by GitHub
parent 8d4fb5b4b4
commit 074d9ebca7
4 changed files with 44 additions and 83 deletions

View File

@@ -3713,6 +3713,33 @@ bool Creature::CanGeneratePickPocketLoot() const
return (lootPickPocketRestoreTime == 0 || lootPickPocketRestoreTime < GameTime::GetGameTime().count());
}
void Creature::SetTextRepeatId(uint8 textGroup, uint8 id)
{
CreatureTextRepeatIds& repeats = m_textRepeat[textGroup];
if (std::find(repeats.begin(), repeats.end(), id) == repeats.end())
repeats.push_back(id);
else
LOG_ERROR("sql.sql", "CreatureTextMgr: TextGroup {} for Creature({}) {}, id {} already added", uint32(textGroup), GetName(), GetGUID().ToString(), uint32(id));
}
CreatureTextRepeatIds const& Creature::GetTextRepeatGroup(uint8 textGroup)
{
static CreatureTextRepeatIds const emptyIds;
CreatureTextRepeatGroup::const_iterator groupItr = m_textRepeat.find(textGroup);
if (groupItr != m_textRepeat.end())
return groupItr->second;
return emptyIds;
}
void Creature::ClearTextRepeatGroup(uint8 textGroup)
{
CreatureTextRepeatGroup::iterator groupItr = m_textRepeat.find(textGroup);
if (groupItr != m_textRepeat.end())
groupItr->second.clear();
}
void Creature::SetRespawnTime(uint32 respawn)
{
m_respawnTime = respawn ? GameTime::GetGameTime().count() + respawn : 0;

View File

@@ -39,6 +39,10 @@ class CreatureGroup;
#define MAX_VENDOR_ITEMS 150 // Limitation in 3.x.x item count in SMSG_LIST_INVENTORY
//used for handling non-repeatable random texts
typedef std::vector<uint8> CreatureTextRepeatIds;
typedef std::unordered_map<uint8, CreatureTextRepeatIds> CreatureTextRepeatGroup;
class Creature : public Unit, public GridObject<Creature>, public MovableMapObject, public UpdatableMapObject
{
public:
@@ -388,6 +392,10 @@ public:
void UpdateLeashExtensionTime();
uint8 GetLeashTimer() const;
CreatureTextRepeatIds const& GetTextRepeatGroup(uint8 textGroup);
void SetTextRepeatId(uint8 textGroup, uint8 id);
void ClearTextRepeatGroup(uint8 textGroup);
bool IsFreeToMove();
static constexpr uint32 MOVE_CIRCLE_CHECK_INTERVAL = 3000;
static constexpr uint32 MOVE_BACKWARDS_CHECK_INTERVAL = 2000;
@@ -519,6 +527,8 @@ private:
Spell const* _focusSpell; ///> Locks the target during spell cast for proper facing
CreatureTextRepeatGroup m_textRepeat;
bool _isMissingSwimmingFlagOutOfCombat;
uint32 m_assistanceTimer;