diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp index d7ab8a0a..36670e90 100644 --- a/src/server/game/Entities/Player/Player.cpp +++ b/src/server/game/Entities/Player/Player.cpp @@ -3844,6 +3844,7 @@ void Player::DeleteFromDB(ObjectGuid playerguid, uint32 accountId, bool updateRe // The house dies with the character on every removal path (final purge after the undelete // window, account unlink); the delete request already handled it, this is idempotent. sHousingMgr.DeleteHouseForOwner(playerguid); + sHousingMgr.RemoveIgnoredNeighborhoods(playerguid); //WowCommunity uint32 charDeleteMethod = sWorld->getIntConfig(CONFIG_CHARDELETE_METHOD); CharacterCacheEntry const* characterInfo = sCharacterCache->GetCharacterCacheByGuid(playerguid); diff --git a/src/server/game/Housing/HousingMgr.cpp b/src/server/game/Housing/HousingMgr.cpp index 9ed49519..0bb6b5bf 100644 --- a/src/server/game/Housing/HousingMgr.cpp +++ b/src/server/game/Housing/HousingMgr.cpp @@ -1716,6 +1716,11 @@ void HousingMgr::AddIgnoredNeighborhood(ObjectGuid playerGuid, ObjectGuid neighb CharacterDatabase.Execute(stmt); } +void HousingMgr::RemoveIgnoredNeighborhoods(ObjectGuid playerGuid) +{ + _ignoredNeighborhoods.erase(playerGuid); +} + void HousingMgr::RemoveIgnoredNeighborhood(ObjectGuid playerGuid, ObjectGuid neighborhoodGuid) { std::unordered_set& set = EnsureIgnoredNeighborhoodsLoaded(playerGuid); diff --git a/src/server/game/Housing/HousingMgr.h b/src/server/game/Housing/HousingMgr.h index 0e38dfa5..0a332b0e 100644 --- a/src/server/game/Housing/HousingMgr.h +++ b/src/server/game/Housing/HousingMgr.h @@ -380,6 +380,8 @@ public: bool IsNeighborhoodIgnored(ObjectGuid playerGuid, ObjectGuid neighborhoodGuid); void AddIgnoredNeighborhood(ObjectGuid playerGuid, ObjectGuid neighborhoodGuid); void RemoveIgnoredNeighborhood(ObjectGuid playerGuid, ObjectGuid neighborhoodGuid); + // Drops the cached list of a player that is leaving the world (reloaded from DB on next use). + void RemoveIgnoredNeighborhoods(ObjectGuid playerGuid); private: std::mutex _pendingPlotTeleportsLock; diff --git a/src/server/game/Server/WorldSession.cpp b/src/server/game/Server/WorldSession.cpp index 132612af..615c6093 100644 --- a/src/server/game/Server/WorldSession.cpp +++ b/src/server/game/Server/WorldSession.cpp @@ -37,6 +37,7 @@ #include "Group.h" #include "Guild.h" #include "GuildMgr.h" +#include "HousingMgr.h" #include "Hyperlinks.h" #include "IpAddress.h" #include "Log.h" @@ -579,6 +580,8 @@ void WorldSession::LogoutPlayer(bool save) sLFGListMgr.RemoveListingsBy(_player->GetGUID()); sLFGListMgr.RemoveApplicationsBy(_player->GetGUID()); sLFGListMgr.UnregisterSearch(_player->GetGUID()); + // The house finder ignore list is DB backed, drop the cached copy with the session. + sHousingMgr.RemoveIgnoredNeighborhoods(_player->GetGUID()); //WowCommunity if (!_player->GetLootGUID().IsEmpty()) DoLootReleaseAll(); diff --git a/src/server/scripts/Custom/FollowshipBots/AI/Followship_bots_ai_base.cpp b/src/server/scripts/Custom/FollowshipBots/AI/Followship_bots_ai_base.cpp index 24492415..d71b21ff 100644 --- a/src/server/scripts/Custom/FollowshipBots/AI/Followship_bots_ai_base.cpp +++ b/src/server/scripts/Custom/FollowshipBots/AI/Followship_bots_ai_base.cpp @@ -26,6 +26,7 @@ FSB_BaseAI::~FSB_BaseAI() { FSBChatMgr::Get()->LeaveBotChannels(me); FSBChatMgr::Get()->UnregisterActiveBot(me); + GenAINpcMemoryMgr::Get()->Erase(me->GetGUID()); delete botDungeonData; delete botBattlegroundData; } diff --git a/src/server/scripts/Custom/FollowshipBots/GenAI/GenAI_npc_memory.cpp b/src/server/scripts/Custom/FollowshipBots/GenAI/GenAI_npc_memory.cpp index f1ab1745..be4d41a0 100644 --- a/src/server/scripts/Custom/FollowshipBots/GenAI/GenAI_npc_memory.cpp +++ b/src/server/scripts/Custom/FollowshipBots/GenAI/GenAI_npc_memory.cpp @@ -72,6 +72,13 @@ void GenAINpcMemoryMgr::ClearMemory(ObjectGuid npcGuid) it->second.clear(); } +void GenAINpcMemoryMgr::Erase(ObjectGuid npcGuid) +{ + std::unique_lock lock(_mutex); + _memories.erase(npcGuid); + _questStates.erase(npcGuid); +} + void GenAINpcMemoryMgr::RemoveIfUnused(ObjectGuid npcGuid) { std::unique_lock lock(_mutex); diff --git a/src/server/scripts/Custom/FollowshipBots/GenAI/GenAI_npc_memory.h b/src/server/scripts/Custom/FollowshipBots/GenAI/GenAI_npc_memory.h index 23c939a0..c7f90692 100644 --- a/src/server/scripts/Custom/FollowshipBots/GenAI/GenAI_npc_memory.h +++ b/src/server/scripts/Custom/FollowshipBots/GenAI/GenAI_npc_memory.h @@ -39,6 +39,7 @@ public: void AddEntry(ObjectGuid npcGuid, uint32 channelId, std::string const& sender, std::string const& msg, bool isPlayer); std::deque GetMemory(ObjectGuid npcGuid) const; void ClearMemory(ObjectGuid npcGuid); + void Erase(ObjectGuid npcGuid); void RemoveIfUnused(ObjectGuid npcGuid); uint8 GetQuestState(ObjectGuid npcGuid) const; diff --git a/src/server/scripts/Custom/FollowshipBots/Handlers/Followship_bots_chat_handler.cpp b/src/server/scripts/Custom/FollowshipBots/Handlers/Followship_bots_chat_handler.cpp index 6a192a6d..d7fa84e8 100644 --- a/src/server/scripts/Custom/FollowshipBots/Handlers/Followship_bots_chat_handler.cpp +++ b/src/server/scripts/Custom/FollowshipBots/Handlers/Followship_bots_chat_handler.cpp @@ -94,8 +94,15 @@ void FSBChatMgr::UnregisterActiveBot(Creature* bot) { if (!bot) return; - std::lock_guard lock(_activeBotsMutex); - _activeBots.erase(bot->GetGUID()); + + { + std::lock_guard lock(_activeBotsMutex); + _activeBots.erase(bot->GetGUID()); + } + + // The bot is gone, its reply cooldown has no owner left to throttle. + std::lock_guard cooldownLock(_botReplyCooldownsMutex); + _botReplyCooldowns.erase(bot->GetGUID()); } std::vector FSBChatMgr::GetActiveBots() @@ -319,8 +326,14 @@ void FSBChatMgr::HandlePlayerGeneralChat(Player* player, Channel* channel, std:: if (FSBMgr::Get()->IsBotOwned(bot)) continue; - auto cdIt = _botReplyCooldowns.find(bot->GetGUID()); - if (cdIt != _botReplyCooldowns.end() && now < cdIt->second + cooldownMs) + bool onCooldown = false; + { + std::lock_guard lock(_botReplyCooldownsMutex); + auto cdIt = _botReplyCooldowns.find(bot->GetGUID()); + onCooldown = cdIt != _botReplyCooldowns.end() && now < cdIt->second + cooldownMs; + } + + if (onCooldown) continue; if (urand(0, 99) >= chance) @@ -405,7 +418,10 @@ void FSBChatMgr::HandlePlayerGeneralChat(Player* player, Channel* channel, std:: _pendingReplies.push_back(state); } - _botReplyCooldowns[bot->GetGUID()] = now; + { + std::lock_guard lock(_botReplyCooldownsMutex); + _botReplyCooldowns[bot->GetGUID()] = now; + } } } diff --git a/src/server/scripts/Custom/FollowshipBots/Handlers/Followship_bots_chat_handler.h b/src/server/scripts/Custom/FollowshipBots/Handlers/Followship_bots_chat_handler.h index 5a918bd7..66754c94 100644 --- a/src/server/scripts/Custom/FollowshipBots/Handlers/Followship_bots_chat_handler.h +++ b/src/server/scripts/Custom/FollowshipBots/Handlers/Followship_bots_chat_handler.h @@ -125,6 +125,7 @@ private: std::unordered_map _activeBots; mutable std::mutex _activeBotsMutex; std::unordered_map _botReplyCooldowns; + std::mutex _botReplyCooldownsMutex; std::vector> _pendingReplies; std::mutex _pendingRepliesMutex; diff --git a/src/server/scripts/Spells/spell_mage.cpp b/src/server/scripts/Spells/spell_mage.cpp index dec7443c..fcf14385 100644 --- a/src/server/scripts/Spells/spell_mage.cpp +++ b/src/server/scripts/Spells/spell_mage.cpp @@ -36,7 +36,10 @@ #include "TaskScheduler.h" #include "TemporarySummon.h" #include +#include +#include #include +#include enum MageSpells { @@ -1224,12 +1227,50 @@ private: }; // Track Brain Freeze boosted Flurry casts by OriginalCastId (workaround for aura interrupt issues) -// Key = Flurry(44614) CastId, Value = pending missiles for that Flurry cast -static std::unordered_map g_BrainFreezePendingMissiles; +// Key = Flurry(44614) CastId, Value = pending missiles and the time the cast stops being relevant +struct BrainFreezeCastState +{ + int32 pendingMissiles; + std::chrono::steady_clock::time_point expires; +}; + +static std::mutex g_BrainFreezeStateMutex; +static std::unordered_map g_BrainFreezePendingMissiles; // Translation map: 228596's CastId -> Flurry's CastId (so 228354 can find its counter) static std::unordered_map g_BrainFreezeCastIdChain; +// All missiles of a Flurry land within ~1.5s. Anything older belongs to a cast that never +// finished (interrupted, target lost, caster died) and must not stay cached forever. +static constexpr std::chrono::seconds BrainFreezeStateLifetime(30); + +// Must be called with g_BrainFreezeStateMutex held. +static void EraseBrainFreezeCast(ObjectGuid flurryCastId) +{ + g_BrainFreezePendingMissiles.erase(flurryCastId); + + // Every missile of the cast registers its own chain entry, all of them point at the same Flurry. + for (auto chainItr = g_BrainFreezeCastIdChain.begin(); chainItr != g_BrainFreezeCastIdChain.end();) + { + if (chainItr->second == flurryCastId) + chainItr = g_BrainFreezeCastIdChain.erase(chainItr); + else + ++chainItr; + } +} + +// Must be called with g_BrainFreezeStateMutex held. +static void PruneBrainFreezeState(std::chrono::steady_clock::time_point now) +{ + std::vector expired; + for (auto const& [castId, state] : g_BrainFreezePendingMissiles) + if (now >= state.expires) + expired.push_back(castId); + + for (ObjectGuid castId : expired) + EraseBrainFreezeCast(castId); +} + // 44614 - Flurry (cast) - Manual missile control class spell_mage_flurry : public SpellScript { @@ -1252,12 +1293,18 @@ class spell_mage_flurry : public SpellScript ObjectGuid castId = GetSpell()->m_castId; if (Aura* brainFreeze = caster->GetAura(SPELL_MAGE_BRAIN_FREEZE_BUFF)) { - g_BrainFreezePendingMissiles[castId] = numMissiles; + { + std::lock_guard lock(g_BrainFreezeStateMutex); + std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now(); + PruneBrainFreezeState(now); + g_BrainFreezePendingMissiles[castId] = { numMissiles, now + BrainFreezeStateLifetime }; + } caster->RemoveAura(brainFreeze); // Remove immediately so it doesn't get interrupted } else { - g_BrainFreezePendingMissiles.erase(castId); + std::lock_guard lock(g_BrainFreezeStateMutex); + EraseBrainFreezeCast(castId); } // Cast first missile immediately @@ -1301,7 +1348,8 @@ class spell_mage_flurry_damage_spell : public SpellScript // Check if our originalCastId (Flurry's CastId) has a Brain Freeze entry ObjectGuid flurryCastId = GetSpell()->m_originalCastId; ObjectGuid myCastId = GetSpell()->m_castId; - + + std::lock_guard lock(g_BrainFreezeStateMutex); auto it = g_BrainFreezePendingMissiles.find(flurryCastId); if (it != g_BrainFreezePendingMissiles.end()) g_BrainFreezeCastIdChain[myCastId] = flurryCastId; @@ -1352,6 +1400,7 @@ class spell_mage_flurry_missile_damage : public SpellScript // Brain Freeze: +50% damage per missile if this cast had the buff ObjectGuid damageSpellCastId = GetSpell()->m_originalCastId; + std::lock_guard lock(g_BrainFreezeStateMutex); auto chainIt = g_BrainFreezeCastIdChain.find(damageSpellCastId); if (chainIt == g_BrainFreezeCastIdChain.end()) return; @@ -1359,18 +1408,15 @@ class spell_mage_flurry_missile_damage : public SpellScript ObjectGuid flurryCastId = chainIt->second; auto it = g_BrainFreezePendingMissiles.find(flurryCastId); - if (it == g_BrainFreezePendingMissiles.end() || it->second <= 0) + if (it == g_BrainFreezePendingMissiles.end() || it->second.pendingMissiles <= 0) return; int32 currentDamage = GetHitDamage(); SetHitDamage(currentDamage + currentDamage / 2); // +50% - it->second--; // Consume one missile - if (it->second <= 0) - { - g_BrainFreezePendingMissiles.erase(it); - g_BrainFreezeCastIdChain.erase(chainIt); - } + it->second.pendingMissiles--; // Consume one missile + if (it->second.pendingMissiles <= 0) + EraseBrainFreezeCast(flurryCastId); } void Register() override