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

@@ -947,8 +947,21 @@ bool BroadcastHelper::BroadcastSuggestThunderfury(PlayerbotAI* ai, Player* bot)
{
std::map<std::string, std::string> placeholders;
ItemTemplate const* thunderfuryProto = sObjectMgr->GetItemTemplate(19019);
placeholders["%thunderfury_link"] = GET_PLAYERBOT_AI(bot)->GetChatHelper()->FormatItem(thunderfuryProto);
// placeholders["%thunderfury_link"] = GET_PLAYERBOT_AI(bot)->GetChatHelper()->FormatItem(thunderfuryProto); // Old code
// [Crash fix] Protect from nil AI : a real player doesn't have PlayerbotAI.
// Before: direct deref GET_PLAYERBOT_AI(bot)->... could crash World/General.
if (auto* ai = GET_PLAYERBOT_AI(bot))
{
if (auto* chat = ai->GetChatHelper())
placeholders["%thunderfury_link"] = chat->FormatItem(thunderfuryProto);
else
placeholders["%thunderfury_link"] = ""; // fallback: no chat helper
}
else
{
placeholders["%thunderfury_link"] = ""; // fallback: no d'AI (real player)
}
// End crash fix
return BroadcastToChannelWithGlobalChance(
ai,
BOT_TEXT2("thunderfury_spam", placeholders),