mirror of
https://github.com/mod-playerbots/mod-playerbots
synced 2025-11-29 15:58:20 +08:00
[Revert] Threading leftover which belonged to other related PRs's (once green needs be merged) (#1583)
* Revert "Correct side effects of mergef5ef5bd1c2(#1512)" This reverts commit966bf1d6af. * Revert "Fix ACCESS_VIOLATION in mod-playerbots: purge stale AIs, add thread-safety, and harden HasRealPlayerMaster (#1507)" This reverts commitf5ef5bd1c2.
This commit is contained in:
@@ -38,8 +38,6 @@
|
||||
#include "WorldSessionMgr.h"
|
||||
#include "DatabaseEnv.h" // Added for gender choice
|
||||
#include <algorithm> // Added for gender choice
|
||||
#include "Log.h" // removes a long-standing crash (0xC0000005 ACCESS_VIOLATION)
|
||||
#include <shared_mutex> // removes a long-standing crash (0xC0000005 ACCESS_VIOLATION)
|
||||
|
||||
class BotInitGuard
|
||||
{
|
||||
@@ -1728,70 +1726,21 @@ void PlayerbotsMgr::RemovePlayerBotData(ObjectGuid const& guid, bool is_AI)
|
||||
|
||||
PlayerbotAI* PlayerbotsMgr::GetPlayerbotAI(Player* player)
|
||||
{
|
||||
// if (!(sPlayerbotAIConfig->enabled) || !player)
|
||||
// {
|
||||
if (!(sPlayerbotAIConfig->enabled) || !player)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
// if (player->GetSession()->isLogingOut() || player->IsDuringRemoveFromWorld()) {
|
||||
// return nullptr;
|
||||
// }
|
||||
// // if (player->GetSession()->isLogingOut() || player->IsDuringRemoveFromWorld()) {
|
||||
// // return nullptr;
|
||||
// // }
|
||||
// auto itr = _playerbotsAIMap.find(player->GetGUID());
|
||||
// if (itr != _playerbotsAIMap.end())
|
||||
// {
|
||||
// if (itr->second->IsBotAI())
|
||||
// return reinterpret_cast<PlayerbotAI*>(itr->second);
|
||||
// }
|
||||
//
|
||||
// return nullptr;
|
||||
|
||||
// removes a long-standing crash (0xC0000005 ACCESS_VIOLATION)
|
||||
if (!player || !sPlayerbotAIConfig->enabled)
|
||||
return nullptr;
|
||||
|
||||
// First read the GUID into a local variable, but ONLY after the check!
|
||||
ObjectGuid guid = player->GetGUID(); // <-- OK here, we know that player != nullptr
|
||||
{
|
||||
std::shared_lock rlock(_aiMutex);
|
||||
auto it = _playerbotsAIMap.find(guid);
|
||||
if (it != _playerbotsAIMap.end() && it->second->IsBotAI())
|
||||
return static_cast<PlayerbotAI*>(it->second);
|
||||
}
|
||||
|
||||
// Transient state: NEVER break the master ⇄ bots relationship here.
|
||||
if (!ObjectAccessor::FindPlayer(guid))
|
||||
auto itr = _playerbotsAIMap.find(player->GetGUID());
|
||||
if (itr != _playerbotsAIMap.end())
|
||||
{
|
||||
RemovePlayerbotAI(guid, /*removeMgrEntry=*/false);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// removes a long-standing crash (0xC0000005 ACCESS_VIOLATION)
|
||||
PlayerbotAI* PlayerbotsMgr::GetPlayerbotAIByGuid(ObjectGuid guid)
|
||||
{
|
||||
if (!sPlayerbotAIConfig->enabled)
|
||||
return nullptr;
|
||||
|
||||
std::shared_lock rlock(_aiMutex);
|
||||
auto it = _playerbotsAIMap.find(guid);
|
||||
if (it != _playerbotsAIMap.end() && it->second->IsBotAI())
|
||||
return static_cast<PlayerbotAI*>(it->second);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void PlayerbotsMgr::RemovePlayerbotAI(ObjectGuid const& guid, bool removeMgrEntry /*= true*/)
|
||||
{
|
||||
std::unique_lock wlock(_aiMutex);
|
||||
|
||||
if (auto it = _playerbotsAIMap.find(guid); it != _playerbotsAIMap.end())
|
||||
{
|
||||
delete it->second;
|
||||
_playerbotsAIMap.erase(it);
|
||||
LOG_DEBUG("playerbots", "Removed stale AI for GUID {}",
|
||||
static_cast<uint64>(guid.GetRawValue()));
|
||||
if (itr->second->IsBotAI())
|
||||
return reinterpret_cast<PlayerbotAI*>(itr->second);
|
||||
}
|
||||
|
||||
if (removeMgrEntry)
|
||||
_playerbotsMgrMap.erase(guid); // we NO longer touch the relation in a "soft" purge
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PlayerbotMgr* PlayerbotsMgr::GetPlayerbotMgr(Player* player)
|
||||
|
||||
Reference in New Issue
Block a user