From e88a93d65e9be0cda925fd90d7dfac7a6361a1ed Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Wed, 7 Aug 2024 17:45:21 +0800 Subject: [PATCH] Handle command and trade check for summoned bot --- src/PlayerbotAI.cpp | 6 +--- src/PlayerbotSecurity.cpp | 33 +++++++++++----------- src/RandomPlayerbotMgr.cpp | 3 -- src/strategy/actions/TradeStatusAction.cpp | 10 +++++-- 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/PlayerbotAI.cpp b/src/PlayerbotAI.cpp index 0b4db3ef..34fba5ed 100644 --- a/src/PlayerbotAI.cpp +++ b/src/PlayerbotAI.cpp @@ -655,11 +655,7 @@ void PlayerbotAI::HandleCommand(uint32 type, std::string const text, Player* fro } if (!IsAllowedCommand(filtered) && - (master != fromPlayer || - !GetSecurity()->CheckLevelFor(PLAYERBOT_SECURITY_ALLOW_ALL, type != CHAT_MSG_WHISPER, fromPlayer))) - return; - - if (!IsAllowedCommand(filtered) && master != fromPlayer) + (!GetSecurity()->CheckLevelFor(PLAYERBOT_SECURITY_ALLOW_ALL, type != CHAT_MSG_WHISPER, fromPlayer))) return; if (type == CHAT_MSG_RAID_WARNING && filtered.find(bot->GetName()) != std::string::npos && diff --git a/src/PlayerbotSecurity.cpp b/src/PlayerbotSecurity.cpp index e7241004..0a045cdb 100644 --- a/src/PlayerbotSecurity.cpp +++ b/src/PlayerbotSecurity.cpp @@ -55,14 +55,16 @@ PlayerbotSecurityLevel PlayerbotSecurity::LevelFor(Player* from, DenyReason* rea // } Group* group = from->GetGroup(); - if (group) + if (group && group == bot->GetGroup() && !ignoreGroup && botAI->GetMaster() == from) { - for (GroupReference* gref = group->GetFirstMember(); gref; gref = gref->next()) - { - Player* player = gref->GetSource(); - if (player == bot && !ignoreGroup) - return PLAYERBOT_SECURITY_ALLOW_ALL; - } + return PLAYERBOT_SECURITY_ALLOW_ALL; + } + + if (group && group == bot->GetGroup() && !ignoreGroup && botAI->GetMaster() != from) + { + if (reason) + *reason = PLAYERBOT_DENY_NOT_YOURS; + return PLAYERBOT_SECURITY_TALK; } if (sPlayerbotAIConfig->groupInvitationPermission <= 0) @@ -137,13 +139,6 @@ PlayerbotSecurityLevel PlayerbotSecurity::LevelFor(Player* from, DenyReason* rea return PLAYERBOT_SECURITY_INVITE; } - for (GroupReference* gref = group->GetFirstMember(); gref; gref = gref->next()) - { - Player* player = gref->GetSource(); - if (player == from) - return PLAYERBOT_SECURITY_ALLOW_ALL; - } - if (group->IsFull()) { if (reason) @@ -169,11 +164,17 @@ PlayerbotSecurityLevel PlayerbotSecurity::LevelFor(Player* from, DenyReason* rea if (reason) *reason = PLAYERBOT_DENY_INVITE; - + return PLAYERBOT_SECURITY_INVITE; } - return PLAYERBOT_SECURITY_ALLOW_ALL; + if (botAI->GetMaster() == from) + return PLAYERBOT_SECURITY_ALLOW_ALL; + + if (reason) + *reason = PLAYERBOT_DENY_NOT_YOURS; + + return PLAYERBOT_SECURITY_INVITE; } bool PlayerbotSecurity::CheckLevelFor(PlayerbotSecurityLevel level, bool silent, Player* from, bool ignoreGroup) diff --git a/src/RandomPlayerbotMgr.cpp b/src/RandomPlayerbotMgr.cpp index 2655052c..29bc672d 100644 --- a/src/RandomPlayerbotMgr.cpp +++ b/src/RandomPlayerbotMgr.cpp @@ -1215,9 +1215,6 @@ void RandomPlayerbotMgr::Revive(Player* player) void RandomPlayerbotMgr::RandomTeleport(Player* bot, std::vector& locs, bool hearth) { - if (bot->IsBeingTeleported()) - return; - if (bot->InBattleground()) return; diff --git a/src/strategy/actions/TradeStatusAction.cpp b/src/strategy/actions/TradeStatusAction.cpp index b1284a80..4076277c 100644 --- a/src/strategy/actions/TradeStatusAction.cpp +++ b/src/strategy/actions/TradeStatusAction.cpp @@ -10,8 +10,10 @@ #include "GuildTaskMgr.h" #include "ItemUsageValue.h" #include "ItemVisitors.h" +#include "PlayerbotMgr.h" #include "PlayerbotSecurity.h" #include "Playerbots.h" +#include "RandomPlayerbotMgr.h" #include "SetCraftAction.h" bool TradeStatusAction::Execute(Event event) @@ -180,8 +182,12 @@ bool TradeStatusAction::CheckTrade() } return isGettingItem; } - - if (!sRandomPlayerbotMgr->IsRandomBot(bot)) + if (!bot->GetSession()) + { + return false; + } + uint32 accountId = bot->GetSession()->GetAccountId(); + if (!sPlayerbotAIConfig->IsInRandomAccountList(accountId)) { int32 botItemsMoney = CalculateCost(bot, true); int32 botMoney = bot->GetTradeData()->GetMoney() + botItemsMoney;