fix: player count mismatch (#2051)

tested that showall no longer mis-reports the number of players
This commit is contained in:
David Markowitz
2026-10-28 17:20:26 -07:00
committed by GitHub
parent 0ff5d2bf87
commit 8b7d1b946b
2 changed files with 10 additions and 1 deletions

View File

@@ -399,13 +399,17 @@ void ChatPacketHandler::HandleShowAll(Packet* packet) {
BitStreamUtils::WriteHeader(bitStream, ServiceType::CLIENT, MessageType::Client::SHOW_ALL_RESPONSE);
bitStream.Write<uint8_t>(!request.displayZoneData && !request.displayIndividualPlayers);
// there is no terminator here, the client simply reads this written number of players, if there is a mismatch
// then garbage data is printed to the screen
bitStream.Write(Game::playerContainer.GetPlayerCount());
bitStream.Write(Game::playerContainer.GetSimCount());
bitStream.Write<uint8_t>(request.displayIndividualPlayers);
bitStream.Write<uint8_t>(request.displayZoneData);
if (request.displayZoneData || request.displayIndividualPlayers) {
uint32_t writtenEntries = 0;
for (auto& [playerID, playerData] : Game::playerContainer.GetAllPlayers()) {
if (!playerData) continue;
writtenEntries++;
bitStream.Write<uint8_t>(0); // structure packing
if (request.displayIndividualPlayers) bitStream.Write(LUWString(playerData.playerName));
if (request.displayZoneData) {
@@ -414,6 +418,11 @@ void ChatPacketHandler::HandleShowAll(Packet* packet) {
bitStream.Write(playerData.zoneID.GetCloneID());
}
}
if (writtenEntries != Game::playerContainer.GetPlayerCount()) {
LOG("Written players does not match actual players %i != %i", writtenEntries, Game::playerContainer.GetPlayerCount());
}
}
SystemAddress sysAddr = sender.worldServerSysAddr;
SEND_PACKET;

View File

@@ -57,7 +57,7 @@ void PlayerContainer::InsertPlayer(Packet* packet) {
data.worldServerSysAddr = packet->systemAddress;
m_Names[data.playerID] = GeneralUtils::UTF8ToUTF16(data.playerName);
m_PlayerCount++;
if (isLogin) m_PlayerCount++;
LOG("Added user: %s (%llu), zone: %i", data.playerName.c_str(), data.playerID, data.zoneID.GetMapID());
ChatWeb::SendWSPlayerUpdate(data, isLogin ? eActivityType::PlayerLoggedIn : eActivityType::PlayerChangedZone);