Skip to content

Commit f5c84ee

Browse files
authored
server_crash_fix: OnPlayerGiveXP (mod-playerbots#1929)
[fef0ed4072c8_worldserver.exe_.18-12_23-30-44.txt](https://github.com/user-attachments/files/24258638/fef0ed4072c8_worldserver.exe_.18-12_23-30-44.txt) - Just added common logic and defense coding - Optimized isRandombot while at it Just for clarification i am aware the trigger of bug lies with the progression mod. Regardless it should not happen.
1 parent b6f8828 commit f5c84ee

2 files changed

Lines changed: 23 additions & 31 deletions

File tree

src/Playerbots.cpp

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -239,44 +239,39 @@ class PlayerbotsPlayerScript : public PlayerScript
239239

240240
void OnPlayerGiveXP(Player* player, uint32& amount, Unit* /*victim*/, uint8 /*xpSource*/) override
241241
{
242-
// no XP multiplier, when player is no bot.
243-
if (!player || !player->GetSession()->IsBot())
242+
if (sPlayerbotAIConfig->randomBotXPRate == 1.0f || !player || !player->IsInWorld())
243+
return;
244+
245+
PlayerbotAI* botAI = GET_PLAYERBOT_AI(player);
246+
if (!botAI || !sRandomPlayerbotMgr->IsRandomBot(player))
244247
return;
245248

246-
// no XP gain, if master is not a bot and has xp gain disabled.
247-
if (const Player* master = GET_PLAYERBOT_AI(player)->GetMaster())
249+
// No XP gain if master is a real player with XP gain disabled
250+
if (const Player* master = botAI->GetMaster())
248251
{
249-
if (!master->GetSession()->IsBot() && master->HasPlayerFlag(PLAYER_FLAGS_NO_XP_GAIN))
252+
if (WorldSession* masterSession = master->GetSession();
253+
masterSession && !masterSession->IsBot() && master->HasPlayerFlag(PLAYER_FLAGS_NO_XP_GAIN))
250254
{
251-
amount = 0;
255+
amount = 0; // disable XP multiplier
252256
return;
253257
}
254258
}
255259

256-
// early return
257-
if (sPlayerbotAIConfig->randomBotXPRate == 1.0 || !sRandomPlayerbotMgr->IsRandomBot(player))
258-
return;
259-
260-
// no XP multiplier, when bot is in a group with a real player.
260+
// No XP multiplier if bot is in a group with at least one real player
261261
if (Group* group = player->GetGroup())
262262
{
263263
for (GroupReference* gref = group->GetFirstMember(); gref; gref = gref->next())
264264
{
265-
Player* member = gref->GetSource();
266-
if (!member)
267-
{
268-
continue;
269-
}
270-
271-
if (!member->GetSession()->IsBot())
265+
if (Player* member = gref->GetSource())
272266
{
273-
return;
267+
if (!member->GetSession()->IsBot())
268+
return;
274269
}
275270
}
276271
}
277272

278-
// otherwise apply bot XP multiplier.
279-
amount = static_cast<uint32>(std::round(static_cast<float>(amount) * sPlayerbotAIConfig->randomBotXPRate));
273+
// Otherwise apply XP multiplier
274+
amount = static_cast<uint32>(std::round(amount * sPlayerbotAIConfig->randomBotXPRate));
280275
}
281276
};
282277

src/RandomPlayerbotMgr.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2594,17 +2594,14 @@ void RandomPlayerbotMgr::Refresh(Player* bot)
25942594

25952595
bool RandomPlayerbotMgr::IsRandomBot(Player* bot)
25962596
{
2597-
if (bot && GET_PLAYERBOT_AI(bot))
2598-
{
2599-
if (GET_PLAYERBOT_AI(bot)->IsRealPlayer())
2600-
return false;
2601-
}
2602-
if (bot)
2603-
{
2604-
return IsRandomBot(bot->GetGUID().GetCounter());
2605-
}
2597+
if (!bot)
2598+
return false;
26062599

2607-
return false;
2600+
PlayerbotAI* botAI = GET_PLAYERBOT_AI(bot);
2601+
if (!botAI || botAI->IsRealPlayer())
2602+
return false;
2603+
2604+
return IsRandomBot(bot->GetGUID().GetCounter());
26082605
}
26092606

26102607
bool RandomPlayerbotMgr::IsRandomBot(ObjectGuid::LowType bot)

0 commit comments

Comments
 (0)