From 73f13ded4fafec6805bb4d06e0b1184c97023741 Mon Sep 17 00:00:00 2001 From: bo Date: Sun, 1 Mar 2026 14:27:00 -0600 Subject: [PATCH] Console use guid lookup when player offline When a console command is issued without a player name argument, ExtractPlayerTarget normally resolves the target via getSelectedPlayer(), which only returns online players. This change falls back to the stored console selection GUID when the selected player is offline, and looks up their name from the database if needed. This primarily benefits commands that require a player GUID or name but do not need a live Player pointer -- such as teleport or account queries. Commands that operate on a live Player object will still fail for offline targets. Impact is therefore limited to that subset of no-argument console commands. --- src/game/WorldHandlers/Chat.cpp | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/game/WorldHandlers/Chat.cpp b/src/game/WorldHandlers/Chat.cpp index 5e2708f4e..0a48ecb5b 100644 --- a/src/game/WorldHandlers/Chat.cpp +++ b/src/game/WorldHandlers/Chat.cpp @@ -3526,15 +3526,42 @@ bool ChatHandler::ExtractPlayerTarget(char** args, Player** player /*= NULL*/, O { *player = pl; } + + ObjectGuid guid = pl ? pl->GetObjectGuid() : ObjectGuid(); + + // Console with a selected player that is now offline: fall back to stored GUID + if (!pl && !m_session) + { + uint32 accountId = GetAccountId(); + auto itr = m_consoleSelectedPlayers.find(accountId); + if (itr != m_consoleSelectedPlayers.end()) + guid = itr->second; + } + // if allowed player guid (if no then only online players allowed) if (player_guid) { - *player_guid = pl ? pl->GetObjectGuid() : ObjectGuid(); + *player_guid = guid; } if (player_name) { - *player_name = pl ? pl->GetName() : ""; + if (pl) + *player_name = pl->GetName(); + else if (guid) + { + std::string name; + if (!sObjectMgr.GetPlayerNameByGUID(guid, name) || name.empty()) + { + if (player_guid) + *player_guid = ObjectGuid(); + *player_name = ""; + } + else + *player_name = name; + } + else + *player_name = ""; } }