add result table

master
Vectozavr 2021-10-26 14:08:41 +07:00
parent 020d82cab8
commit e42aba3ee4
3 changed files with 11 additions and 5 deletions

View File

@ -19,8 +19,9 @@ void Client::updatePacket() {
void Client::processInit(sf::Packet& packet) {
sf::Uint16 targetId;
double buf[4];
int kills, deaths;
while (packet >> targetId >> buf[0] >> buf[1] >> buf[2] >> buf[3])
while (packet >> targetId >> buf[0] >> buf[1] >> buf[2] >> buf[3] >> kills >> deaths)
{
if(targetId != _socket.ownId()) {
if(_spawnPlayerCallBack != nullptr)
@ -28,6 +29,8 @@ void Client::processInit(sf::Packet& packet) {
_players[targetId]->translateToPoint(Vec3D{ buf[0], buf[1], buf[2]});
_players[targetId]->setHealth(buf[3]);
_players[targetId]->setKills(kills);
_players[targetId]->setDeaths(deaths);
}
}
}

View File

@ -72,6 +72,9 @@ public:
void addKill() { _kills++; }
void addDeath() { _deaths++; }
void setKills(int kills) { _kills = kills; }
void setDeaths(int deaths) { _deaths = deaths; }
void setDamagePlayerCallBack(std::function<void(sf::Uint16 targetId, double)> hit) {
_damagePlayerCallBack = std::move(hit);
}

View File

@ -27,11 +27,11 @@ void Server::processConnect(sf::Uint16 targetId) {
extraPacket << MsgType::NewClient << targetId;
sendPacket1 << MsgType::Init << targetId;
_players.insert({ targetId, std::make_shared<Player>() });
for (const auto& player : _players)
for (const auto& [playerId, player] : _players)
{
sendPacket1 << player.first << player.second->position().x() << player.second->position().y() << player.second->position().z() << player.second->health();
if (player.first != targetId)
_socket.sendRely(extraPacket, player.first);
sendPacket1 << playerId << player->position().x() << player->position().y() << player->position().z() << player->health() << player->kills() << player->deaths();
if (playerId != targetId)
_socket.sendRely(extraPacket, playerId);
}
_socket.sendRely(sendPacket1, targetId);