From eb2c6a445c717af14c7709a67dd3ea3c12a25118 Mon Sep 17 00:00:00 2001 From: Andrew <47818697+Nyeriah@users.noreply.github.com> Date: Thu, 16 Oct 2025 07:24:23 -0300 Subject: [PATCH] feat(Scripts/Commands): Implement debug zonestats command (#23249) --- .../rev_1760478939949751800.sql | 4 +++ src/server/game/Maps/Map.cpp | 4 +-- src/server/game/Maps/Map.h | 8 ++++++ src/server/scripts/Commands/cs_debug.cpp | 28 ++++++++++++++++++- 4 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 data/sql/updates/pending_db_world/rev_1760478939949751800.sql diff --git a/data/sql/updates/pending_db_world/rev_1760478939949751800.sql b/data/sql/updates/pending_db_world/rev_1760478939949751800.sql new file mode 100644 index 000000000..82b977632 --- /dev/null +++ b/data/sql/updates/pending_db_world/rev_1760478939949751800.sql @@ -0,0 +1,4 @@ +-- +DELETE FROM `command` WHERE `name` = 'debug zonestats'; +INSERT INTO `command` (`name`, `security`, `help`) VALUES +('debug zonestats', 1, '.debug zonestats [$playerName]\nDisplays the amount of players in the player\'s current zone.'); diff --git a/src/server/game/Maps/Map.cpp b/src/server/game/Maps/Map.cpp index 906b3b966..1aa7a3ee8 100644 --- a/src/server/game/Maps/Map.cpp +++ b/src/server/game/Maps/Map.cpp @@ -417,9 +417,7 @@ void Map::UpdatePlayerZoneStats(uint32 oldZone, uint32 newZone) if (oldZone != MAP_INVALID_ZONE) { uint32& oldZoneCount = _zonePlayerCountMap[oldZone]; - if (!oldZoneCount) - LOG_ERROR("maps", "A player left zone {} (went to {}) - but there were no players in the zone!", oldZone, newZone); - else + if (oldZoneCount) --oldZoneCount; } diff --git a/src/server/game/Maps/Map.h b/src/server/game/Maps/Map.h index 06451fb1d..c820b9c29 100644 --- a/src/server/game/Maps/Map.h +++ b/src/server/game/Maps/Map.h @@ -514,6 +514,14 @@ public: void RemoveWorldObjectFromZoneWideVisibleMap(uint32 zoneId, WorldObject* obj); ZoneWideVisibleWorldObjectsSet const* GetZoneWideVisibleWorldObjectsForZone(uint32 zoneId) const; + [[nodiscard]] uint32 GetPlayerCountInZone(uint32 zoneId) const + { + if (auto const& it = _zonePlayerCountMap.find(zoneId); it != _zonePlayerCountMap.end()) + return it->second; + + return 0; + }; + private: template void InitializeObject(T* obj); diff --git a/src/server/scripts/Commands/cs_debug.cpp b/src/server/scripts/Commands/cs_debug.cpp index 40bb89b93..1113d73a5 100644 --- a/src/server/scripts/Commands/cs_debug.cpp +++ b/src/server/scripts/Commands/cs_debug.cpp @@ -100,7 +100,8 @@ public: { "dummy", HandleDebugDummyCommand, SEC_ADMINISTRATOR, Console::No }, { "mapdata", HandleDebugMapDataCommand, SEC_ADMINISTRATOR, Console::No }, { "boundary", HandleDebugBoundaryCommand, SEC_ADMINISTRATOR, Console::No }, - { "visibilitydata", HandleDebugVisibilityDataCommand, SEC_ADMINISTRATOR, Console::No } + { "visibilitydata", HandleDebugVisibilityDataCommand, SEC_ADMINISTRATOR, Console::No }, + { "zonestats", HandleDebugZoneStatsCommand, SEC_MODERATOR, Console::Yes} }; static ChatCommandTable commandTable = { @@ -1434,6 +1435,31 @@ public: handler->PSendSysMessage("Zone wide visible objects in zone: {}", zoneWideVisibleObjectsInZone); return true; } + + static bool HandleDebugZoneStatsCommand(ChatHandler* handler, Optional playerTarget) + { + if (!playerTarget) + playerTarget = PlayerIdentifier::FromTargetOrSelf(handler); + + if (!playerTarget) + { + handler->SendErrorMessage(LANG_PLAYER_NOT_FOUND); + return false; + } + + Player* player = playerTarget->GetConnectedPlayer(); + + if (!player) + { + handler->SendErrorMessage(LANG_PLAYER_NOT_FOUND); + return false; + } + + uint32 zoneId = player->GetZoneId(); + AreaTableEntry const* zoneEntry = sAreaTableStore.LookupEntry(zoneId); + handler->PSendSysMessage("Player count in zone {} ({}): {}.", zoneId, (zoneEntry ? zoneEntry->area_name[LOCALE_enUS] : ""), player->GetMap()->GetPlayerCountInZone(zoneId)); + return true; + } }; void AddSC_debug_commandscript()