From 7676fd6427d089dded443a142a0a7bc5224874c3 Mon Sep 17 00:00:00 2001 From: Yunfan Li <56597220+liyunfan1223@users.noreply.github.com> Date: Mon, 31 Mar 2025 22:46:27 +0800 Subject: [PATCH] Fix multithread issue on LFG and group leave (#1143) --- src/PlayerbotAI.cpp | 8 ++++++-- src/strategy/actions/LfgActions.cpp | 31 ++++++++++++++++++++--------- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/PlayerbotAI.cpp b/src/PlayerbotAI.cpp index 150e3d75..538e1b71 100644 --- a/src/PlayerbotAI.cpp +++ b/src/PlayerbotAI.cpp @@ -374,7 +374,9 @@ void PlayerbotAI::UpdateAIGroupMembership() PlayerbotAI* leaderAI = GET_PLAYERBOT_AI(leader); if (leaderAI && !leaderAI->IsRealPlayer()) { - bot->RemoveFromGroup(); + WorldPacket* packet = new WorldPacket(CMSG_GROUP_DISBAND); + bot->GetSession()->QueuePacket(packet); + // bot->RemoveFromGroup(); ResetStrategies(); } } @@ -399,7 +401,9 @@ void PlayerbotAI::UpdateAIGroupMembership() } if (!hasRealPlayer) { - bot->RemoveFromGroup(); + WorldPacket* packet = new WorldPacket(CMSG_GROUP_DISBAND); + bot->GetSession()->QueuePacket(packet); + // bot->RemoveFromGroup(); ResetStrategies(); } } diff --git a/src/strategy/actions/LfgActions.cpp b/src/strategy/actions/LfgActions.cpp index aee25473..61687eec 100644 --- a/src/strategy/actions/LfgActions.cpp +++ b/src/strategy/actions/LfgActions.cpp @@ -12,6 +12,7 @@ #include "Opcodes.h" #include "Playerbots.h" #include "World.h" +#include "WorldPacket.h" using namespace lfg; @@ -179,9 +180,12 @@ bool LfgRoleCheckAction::Execute(Event event) // if (currentRoles == newRoles) // return false; - sLFGMgr->SetRoles(bot->GetGUID(), newRoles); - - sLFGMgr->UpdateRoleCheck(group->GetGUID(), bot->GetGUID(), newRoles); + + WorldPacket* packet = new WorldPacket(CMSG_LFG_SET_ROLES); + *packet << (uint8)newRoles; + bot->GetSession()->QueuePacket(packet); + // sLFGMgr->SetRoles(bot->GetGUID(), newRoles); + // sLFGMgr->UpdateRoleCheck(group->GetGUID(), bot->GetGUID(), newRoles); LOG_INFO("playerbots", "Bot {} {}:{} <{}>: LFG roles checked", bot->GetGUID().ToString().c_str(), bot->GetTeamId() == TEAM_ALLIANCE ? "A" : "H", bot->GetLevel(), bot->GetName().c_str()); @@ -206,11 +210,13 @@ bool LfgAcceptAction::Execute(Event event) if (bot->IsInCombat() || bot->isDead()) { - /// @FIXME: Race condition LOG_INFO("playerbots", "Bot {} {}:{} <{}> is in combat and refuses LFG proposal {}", bot->GetGUID().ToString().c_str(), bot->GetTeamId() == TEAM_ALLIANCE ? "A" : "H", bot->GetLevel(), bot->GetName().c_str(), id); - sLFGMgr->UpdateProposal(id, bot->GetGUID(), true); + WorldPacket* packet = new WorldPacket(CMSG_LFG_PROPOSAL_RESULT); + *packet << (uint32)id << (bool)false; + bot->GetSession()->QueuePacket(packet); + // sLFGMgr->UpdateProposal(id, bot->GetGUID(), true); return true; } @@ -220,8 +226,10 @@ bool LfgAcceptAction::Execute(Event event) botAI->GetAiObjectContext()->GetValue("lfg proposal")->Set(0); bot->ClearUnitState(UNIT_STATE_ALL_STATE); - /// @FIXME: Race condition - sLFGMgr->UpdateProposal(id, bot->GetGUID(), true); + WorldPacket* packet = new WorldPacket(CMSG_LFG_PROPOSAL_RESULT); + *packet << (uint32)id << (bool)true; + bot->GetSession()->QueuePacket(packet); + // sLFGMgr->UpdateProposal(id, bot->GetGUID(), true); if (sRandomPlayerbotMgr->IsRandomBot(bot) && !bot->GetGroup()) { @@ -259,7 +267,9 @@ bool LfgLeaveAction::Execute(Event event) if (sLFGMgr->GetState(bot->GetGUID()) > LFG_STATE_QUEUED) return false; - sLFGMgr->LeaveLfg(bot->GetGUID()); + WorldPacket* packet = new WorldPacket(CMSG_LFG_LEAVE); + bot->GetSession()->QueuePacket(packet); + // sLFGMgr->LeaveLfg(bot->GetGUID()); return true; } @@ -278,7 +288,10 @@ bool LfgTeleportAction::Execute(Event event) bot->ClearUnitState(UNIT_STATE_ALL_STATE); - sLFGMgr->TeleportPlayer(bot, out); + WorldPacket* packet = new WorldPacket(CMSG_LFG_TELEPORT); + *packet << out; + bot->GetSession()->QueuePacket(packet); + // sLFGMgr->TeleportPlayer(bot, out); return true; }