diff --git a/Client.cpp b/Client.cpp index 32b8adb..880e3c6 100644 --- a/Client.cpp +++ b/Client.cpp @@ -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); } } } diff --git a/Player.h b/Player.h index 1eb7bc6..bb5cf40 100644 --- a/Player.h +++ b/Player.h @@ -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 hit) { _damagePlayerCallBack = std::move(hit); } diff --git a/Server.cpp b/Server.cpp index 282f270..d4b9854 100644 --- a/Server.cpp +++ b/Server.cpp @@ -27,11 +27,11 @@ void Server::processConnect(sf::Uint16 targetId) { extraPacket << MsgType::NewClient << targetId; sendPacket1 << MsgType::Init << targetId; _players.insert({ targetId, std::make_shared() }); - 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);