Harden playerbot logout & packet dispatch; add null-safety in chat hooks and RPG checks (#1529)

This commit is contained in:
Alex Dcnh
2025-08-11 16:27:25 +02:00
committed by GitHub
parent ddfa919154
commit e4ea8e2694
6 changed files with 276 additions and 42 deletions

View File

@@ -1227,7 +1227,7 @@ std::string const QuestObjectiveTravelDestination::getTitle()
return out.str();
}
bool RpgTravelDestination::isActive(Player* bot)
/*bool RpgTravelDestination::isActive(Player* bot) // Old Code
{
PlayerbotAI* botAI = GET_PLAYERBOT_AI(bot);
AiObjectContext* context = botAI->GetAiObjectContext();
@@ -1264,6 +1264,62 @@ bool RpgTravelDestination::isActive(Player* bot)
ReputationRank reaction = bot->GetReputationRank(factionEntry->faction);
return reaction > REP_NEUTRAL;
}*/
bool RpgTravelDestination::isActive(Player* bot)
{
// [Crash fix] Never dereference the AI if the player is real (null AI).
if (!bot)
return false;
PlayerbotAI* botAI = GET_PLAYERBOT_AI(bot);
if (!botAI)
return false; // real player (no AI) => inactive destination
AiObjectContext* context = botAI->GetAiObjectContext();
if (!context)
return false;
CreatureTemplate const* cInfo = GetCreatureTemplate();
if (!cInfo)
return false;
bool isUsefull = false;
if (cInfo->npcflag & UNIT_NPC_FLAG_VENDOR)
if (AI_VALUE2_LAZY(bool, "group or", "should sell,can sell,following party,near leader"))
isUsefull = true;
if (cInfo->npcflag & UNIT_NPC_FLAG_REPAIR)
if (AI_VALUE2_LAZY(bool, "group or", "should repair,can repair,following party,near leader"))
isUsefull = true;
if (!isUsefull)
return false;
// [Crash fix] Read the ignore list via 'context' and check that the Value exists
GuidSet const* ignoreList = nullptr;
if (auto* value = context->GetValue<GuidSet&>("ignore rpg target"))
ignoreList = &value->Get();
if (ignoreList)
{
for (ObjectGuid const& guid : *ignoreList)
{
if (guid.GetEntry() == getEntry())
return false;
}
}
// Secure access to the faction template
if (FactionTemplateEntry const* factionEntry = sFactionTemplateStore.LookupEntry(cInfo->faction))
{
ReputationRank reaction = bot->GetReputationRank(factionEntry->faction);
return reaction > REP_NEUTRAL;
}
// As a precaution, if the faction is not found, consider inactive
return false;
}
CreatureTemplate const* RpgTravelDestination::GetCreatureTemplate() { return sObjectMgr->GetCreatureTemplate(entry); }