diff --git a/dChatServer/ChatPacketHandler.cpp b/dChatServer/ChatPacketHandler.cpp index 10904f4b1..13565b6ae 100644 --- a/dChatServer/ChatPacketHandler.cpp +++ b/dChatServer/ChatPacketHandler.cpp @@ -399,13 +399,17 @@ void ChatPacketHandler::HandleShowAll(Packet* packet) { BitStreamUtils::WriteHeader(bitStream, ServiceType::CLIENT, MessageType::Client::SHOW_ALL_RESPONSE); bitStream.Write(!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(request.displayIndividualPlayers); bitStream.Write(request.displayZoneData); if (request.displayZoneData || request.displayIndividualPlayers) { + uint32_t writtenEntries = 0; for (auto& [playerID, playerData] : Game::playerContainer.GetAllPlayers()) { if (!playerData) continue; + writtenEntries++; bitStream.Write(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; diff --git a/dChatServer/PlayerContainer.cpp b/dChatServer/PlayerContainer.cpp index 56fc8974f..15e3a2dde 100644 --- a/dChatServer/PlayerContainer.cpp +++ b/dChatServer/PlayerContainer.cpp @@ -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);