Skip to content

Commit

Permalink
NPCBots: Output more info in .npcbot fix command and apply harsher …
Browse files Browse the repository at this point in the history
…measures to perform the fix. Now only in GM mode

(cherry picked from commit 7f913891901b843c78e2ee676041cf38e0e963a2)
  • Loading branch information
trickerer committed Nov 24, 2024
1 parent 169ce66 commit 591a856
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 9 deletions.
73 changes: 66 additions & 7 deletions src/server/game/AI/NpcBots/bot_ai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3476,20 +3476,79 @@ void bot_ai::ReceiveEmote(Player* player, uint32 emote)
break;
case TEXT_EMOTE_TICKLE:
{
if (master != player && !player->IsGameMaster())
if (!player->IsGameMaster())
break;

std::ostringstream report;
report << "Problems:";
report << "Bot " << me->GetName() << " (" << me->GetEntry() << "), "
<< "ai owner: " << _ownerGuid << ", data owner: " << _botData->owner << ", master guid: " << master->GetGUID().ToString() << ", "
<< "command states: " << _botCommandState << ", await states: " << uint32(_botAwaitState);

if (_ownerGuid && !HasBotCommandState(BOT_COMMAND_UNBIND) && (master->ToUnit() == me->ToUnit() || _ownerGuid != master->GetGUID().GetRawValue()))
report << "\nunit flags:";
for (UnitFlags uf : EnumUtils::Iterate<UnitFlags>())
if (me->HasUnitFlag(uf))
report << "\n " << EnumUtils::ToString(uf).Title;
report << "\nunit states:";
uint32 counter = 1;
for (uint32 st = UNIT_STATE_DIED; st <= UNIT_STATE_NO_ENVIRONMENT_UPD; st <<= 1u, ++counter)
if (me->HasUnitState(st))
report << "\n UNIT_STATE_" << counter << " (" << st << ")";

report << "\nProblems:";

if (_ownerGuid)
{
if (Player* real_owner = ObjectAccessor::FindPlayerByLowGUID(_ownerGuid))
if (HasBotCommandState(BOT_COMMAND_UNBIND))
{
report << "\n unbound, re-binding...";
RemoveBotCommandState(BOT_COMMAND_UNBIND);
}
bool invalid_master = false;
if (master->GetGUID() == me->GetGUID())
{
report << "\n master->GetGUID() == me->GetGUID()";
invalid_master = true;
}
if (_ownerGuid != _botData->owner)
{
report << "\n owner is in world by bot isn't owned by it";
if (!SetBotOwner(real_owner))
report << "\n (failed to set owner to '" << real_owner->GetName() << "'!)";
report << "\n _ownerGuid != _botData->owner";
invalid_master = true;
}
if (master->GetGUID() == me->GetGUID())
{
report << "\n _ownerGuid != master->GetGUID().GetRawValue()";
invalid_master = true;
}
if (invalid_master)
{
if (Player* real_owner = ObjectAccessor::FindPlayerByLowGUID(_ownerGuid))
{
report << "\n owner is in world by bot isn't owned by it";
if (!SetBotOwner(real_owner))
report << "\n (failed to set owner to '" << real_owner->GetName() << "'!)";
}
else
{
ObjectGuid owner_guid = ObjectGuid::Create<HighGuid::Player>(_ownerGuid);
real_owner = ObjectAccessor::FindConnectedPlayer(owner_guid);
if (real_owner)
report << "\n owner is found (connected) but not in world!";
else if (sCharacterCache->HasCharacterCacheEntry(owner_guid))
report << "\n owner is found (logged out) but not in world!";
else
report << "\n owner is not found!!!";
}
}
}
if (!_atHome)
{
report << "\n _atHome == false";
_atHome = true;
}
if (_evadeMode)
{
report << "\n _evadeMode == true";
_evadeMode = false;
}
if ((me->HasUnitFlag(UNIT_FLAG_STUNNED) || me->HasUnitState(UNIT_STATE_STUNNED)) &&
!me->HasAuraType(SPELL_AURA_MOD_STUN))
Expand Down
4 changes: 2 additions & 2 deletions src/server/game/AI/NpcBots/botcommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2691,9 +2691,9 @@ class script_bot_commands : public CommandScript
Player* owner = !bot->IsFreeBot() ? bot->GetBotOwner() : nullptr;
Player* tickler = handler->GetPlayer();

if (tickler != owner && !tickler->IsGameMaster())
if (!tickler->IsGameMaster())
{
handler->SendSysMessage("Must be in GM mode to fix other player's bot!");
handler->SendSysMessage("Must be in GM mode to use this command!");
handler->SetSentErrorMessage(true);
return false;
}
Expand Down

0 comments on commit 591a856

Please sign in to comment.