31 lines
730 B
C++
31 lines
730 B
C++
#include "td/protocol/packets/PlayerListPacket.h"
|
|
|
|
namespace td {
|
|
namespace protocol {
|
|
|
|
DataBuffer PlayerListPacket::Serialize(bool packetID) const {
|
|
DataBuffer data;
|
|
|
|
WritePacketID(data, packetID);
|
|
data << static_cast<std::uint8_t>(m_Players.size());
|
|
for (auto [playerID, playerInfo] : m_Players) {
|
|
data << playerID << playerInfo.name << playerInfo.team;
|
|
}
|
|
return data;
|
|
}
|
|
|
|
void PlayerListPacket::Deserialize(DataBuffer& data) {
|
|
std::uint8_t playerCount;
|
|
data >> playerCount;
|
|
|
|
for (int i = 0; i < playerCount; i++) {
|
|
std::uint8_t playerID;
|
|
PlayerInfo playerInfo;
|
|
data >> playerID >> playerInfo.name >> playerInfo.team;
|
|
m_Players.insert({ playerID, playerInfo });
|
|
}
|
|
}
|
|
|
|
} // namespace protocol
|
|
} // namespace td
|