From 29296f3d47d407033a3d2946f8589d741a423d6e Mon Sep 17 00:00:00 2001 From: guillaume abel Date: Tue, 31 Oct 2023 22:06:00 +0100 Subject: [PATCH 01/14] SERVER-NETWORK: Add current progress --- docs/network/rfc/RFC.md | 6 ++-- src/Client/Systems/Events/EventsSystems.cpp | 1 - src/Client/Systems/Network/ClientNetwork.cpp | 24 ++++++++++++- src/ECS/ECSCustomTypes.hpp | 27 +++++++++++++++ src/ECS/Systems/BulletsSystems.cpp | 2 +- src/ECS/Systems/Systems.cpp | 10 ++++++ src/Nitwork/Nitwork.h | 21 ++++++++++-- src/Nitwork/NitworkClient.cpp | 26 ++++++++++++-- src/Nitwork/NitworkClient.hpp | 16 +++++++-- src/Nitwork/NitworkServer.cpp | 13 ++++--- src/Nitwork/NitworkServer.hpp | 16 ++++++--- src/Server/Systems/Network/ServerNetwork.cpp | 36 +++++++++++++++++++- src/Server/Systems/Network/ServerNetwork.hpp | 1 + 13 files changed, 174 insertions(+), 25 deletions(-) diff --git a/docs/network/rfc/RFC.md b/docs/network/rfc/RFC.md index c5d121ca..57d8ac51 100644 --- a/docs/network/rfc/RFC.md +++ b/docs/network/rfc/RFC.md @@ -82,7 +82,7 @@ Table of Contents 2.2.2.7.1.2. Position 2.2.2.7.1.2.1. X 2.2.2.7.1.2.2. Y - 2.2.2.8. NEW_BULLET + 2.2.2.8. NEW_MISSILE 2.2.2.8.1. Client 2.2.2.8.1.1. Magick 2.2.2.8.1.2. Position @@ -255,7 +255,7 @@ Table of Contents - ENEMY_DEATH = 6, - POSITION_RELATIVE = 7, - POSITION_ABSOLUTE = 8, - - NEW_BULLET = 9, + - NEW_MISSILE = 9, - NEW_ENEMY = 10, - NEW_PLAYER = 11, - POSITION_RELATIVE_BROADCAST = 12, @@ -598,7 +598,7 @@ Table of Contents This field must be of size 4 byte. This field is signed (so starting from -((2^32)/2) to +(((2^32)/2)-1)) -2.2.2.8. NEW_BULLET +2.2.2.8. NEW_MISSILE The Client must send a new bullet action when he launch a bullet. diff --git a/src/Client/Systems/Events/EventsSystems.cpp b/src/Client/Systems/Events/EventsSystems.cpp index 17a9106b..7f2eaf6b 100644 --- a/src/Client/Systems/Events/EventsSystems.cpp +++ b/src/Client/Systems/Events/EventsSystems.cpp @@ -133,7 +133,6 @@ namespace Systems { Nitwork::NitworkClient::getInstance().addNewBulletMsg( {Maths::removeIntDecimals(pos.x), Maths::removeIntDecimals(pos.y)}, missile.type); - createMissile(pos, missile); clock_.restart(getClockIdFromMissileType(missile.type)); } } diff --git a/src/Client/Systems/Network/ClientNetwork.cpp b/src/Client/Systems/Network/ClientNetwork.cpp index ca0ef0da..80dd564a 100644 --- a/src/Client/Systems/Network/ClientNetwork.cpp +++ b/src/Client/Systems/Network/ClientNetwork.cpp @@ -49,12 +49,34 @@ namespace Systems { } } + void receiveMissileDeath(std::any &any, boost::asio::ip::udp::endpoint & /* unused */) + { + std::lock_guard lock(Registry::getInstance().mutex); + const auto missileDeath = std::any_cast(any); + auto &missiles = Registry::getInstance().getComponents(); + auto &arrHealth = Registry::getInstance().getComponents(); + std::vector ids = missiles.getExistingsId(); + + for (auto id : ids) { + if (missiles[id].getConstId() == missileDeath.missileId) { + if (arrHealth.exist(id)) { + arrHealth[id].hp = 0; + } else { + Logger::fatal("\n\n\n!!!! Missile has no health component, but is alive !!!!\n\n\n"); + Registry::getInstance().removeEntity(id); + } + return; + } + } + } + void handleStartWave(std::any &any, boost::asio::ip::udp::endpoint & /* unused */) { auto &director = SystemManagersDirector::getInstance(); std::lock_guard lock(director.mutex); const auto wave = std::any_cast(any); Types::Enemy::setEnemyNb(wave.enemyNb); + Types::Missiles::setMissileNb(wave.missilesNb); director.getSystemManager(static_cast(Scene::SystemManagers::GAME)) .addSystem(initWave); Logger::info("Wave started"); @@ -218,7 +240,7 @@ namespace Systems { Maths::addIntDecimals(msgNewBullet.pos.y), }; struct Types::Missiles missileType = {static_cast(msgNewBullet.missileType)}; - Systems::createMissile(position, missileType); + Systems::createMissile(position, missileType, msgNewBullet.id, msgNewBullet.life); } void receiveBroadcastAbsolutePosition(std::any &any, boost::asio::ip::udp::endpoint & /* unused*/) diff --git a/src/ECS/ECSCustomTypes.hpp b/src/ECS/ECSCustomTypes.hpp index 07eee38a..4b9965c5 100644 --- a/src/ECS/ECSCustomTypes.hpp +++ b/src/ECS/ECSCustomTypes.hpp @@ -83,7 +83,34 @@ namespace Types { }; struct Missiles { + public: + Missiles(unsigned int constId, enum missileTypes_e _type = missileTypes_e::CLASSIC) : type(_type), _constId(constId) + { + } + + unsigned int getConstId() + { + return _constId; + } + + static void setMissileNb(unsigned int nb) + { + std::lock_guard lock(_mutex); + + _missileNb = nb; + } + + static unsigned int getMissileNb() + { + std::lock_guard lock(_mutex); + return _missileNb; + } + missileTypes_e type; + private: + unsigned int _constId; + static unsigned int _missileNb; + static std::mutex _mutex; }; class Physics { diff --git a/src/ECS/Systems/BulletsSystems.cpp b/src/ECS/Systems/BulletsSystems.cpp index 37869f49..52918733 100644 --- a/src/ECS/Systems/BulletsSystems.cpp +++ b/src/ECS/Systems/BulletsSystems.cpp @@ -103,7 +103,7 @@ namespace Systems { } } - void createMissile(Types::Position pos, Types::Missiles &typeOfMissile) + void createMissile(Types::Position pos, Types::Missiles &typeOfMissile, unsigned int id, ) { Json &json = Json::getInstance(); Registry::getInstance().addEntity(); diff --git a/src/ECS/Systems/Systems.cpp b/src/ECS/Systems/Systems.cpp index 139e4f29..62962d14 100644 --- a/src/ECS/Systems/Systems.cpp +++ b/src/ECS/Systems/Systems.cpp @@ -386,6 +386,7 @@ namespace Systems { static void sendDeathMsg(std::size_t arrId) { auto &arrEnemies = Registry::getInstance().getComponents(); + auto &arrMissiles = Registry::getInstance().getComponents(); #ifndef CLIENT auto &arrOtherPlayer = Registry::getInstance().getComponents(); @@ -393,6 +394,15 @@ namespace Systems { Nitwork::NitworkServer::getInstance().addPlayerDeathMsg(arrOtherPlayer[arrId].constId); } #endif + + if (arrMissiles.exist(arrId)) { +#ifdef CLIENT + Nitwork::NitworkClient::getInstance().addMissileDeathMsg(arrMissiles[arrId].getConstId()); +#else + Nitwork::NitworkServer::getInstance().addMissileDeathMsg(arrMissiles[arrId].getConstId()); +#endif + } + if (arrEnemies.exist(arrId)) { #ifdef CLIENT Nitwork::NitworkClient::getInstance().addEnemyDeathMsg(arrEnemies[arrId].getConstId().id); diff --git a/src/Nitwork/Nitwork.h b/src/Nitwork/Nitwork.h index 3de11b28..28d93f61 100644 --- a/src/Nitwork/Nitwork.h +++ b/src/Nitwork/Nitwork.h @@ -28,11 +28,12 @@ #define MAGICK_LIFE_UPDATE '\x0b' #define MAGICK_ENEMY_DEATH '\x0c' #define MAGICK_NEW_ENEMY '\x0e' - #define MAGICK_NEW_BULLET '\x0d' + #define MAGICK_NEW_MISSILE '\x0d' #define MAGICK_POSITION_RELATIVE_BROADCAST '\x0f' #define MAGICK_POSITION_ABSOLUTE_BROADCAST '\x10' #define MAGICK_NEW_PLAYER '\x0a' #define MAGICK_PLAYER_DEATH '\x11' + #define MAGICK_MISSILE_DEATH '\x12' typedef unsigned char n_magick_t; typedef int n_idsReceived_t; @@ -47,12 +48,13 @@ enum n_actionType_t { ENEMY_DEATH = 6, POSITION_RELATIVE = 7, POSITION_ABSOLUTE = 8, - NEW_BULLET = 9, + NEW_MISSILE = 9, NEW_ENEMY = 10, NEW_PLAYER = 11, POSITION_RELATIVE_BROADCAST = 12, POSITION_ABSOLUTE_BROADCAST = 13, PLAYER_DEATH = 14, + MISSILE_DEATH = 15, N_ACTION_TYPE_MAX, }; @@ -95,6 +97,7 @@ PACK(struct packetMsgReady_s { PACK(struct msgStartWave_s { n_magick_t magick; n_id_t enemyNb; + n_id_t missilesNb; }); PACK(struct packetMsgStartWave_s { @@ -156,6 +159,8 @@ PACK(struct packetNewEnemy_s { PACK(struct msgNewBullet_s { n_magick_t magick; struct position_absolute_s pos; + n_id_t id; + int life; missileTypes_e missileType; }); @@ -230,4 +235,16 @@ PACK(struct packetPlayerDeath_s { struct msgPlayerDeath_s msg; }); +/* Message Missile Death */ +PACK(struct msgMissileDeath_s { + n_magick_t magick; + n_id_t missileId; +}); + +PACK(struct packetMissileDeath_s { + struct header_s header; + struct action_s action; + struct msgMissileDeath_s msgMissileDeath; +}); + #endif diff --git a/src/Nitwork/NitworkClient.cpp b/src/Nitwork/NitworkClient.cpp index b34b0aee..c09ea6ff 100644 --- a/src/Nitwork/NitworkClient.cpp +++ b/src/Nitwork/NitworkClient.cpp @@ -140,11 +140,11 @@ namespace Nitwork { .header = {0, 0, 0, 0, 1, 0}, .action = { - .magick = NEW_BULLET, + .magick = NEW_MISSILE, }, .msg = { - .magick = MAGICK_NEW_BULLET, + .magick = MAGICK_NEW_MISSILE, .pos = pos, .missileType = missileType, }, @@ -242,4 +242,26 @@ namespace Nitwork { _serverEndpoint); addPacketToSend(packet); } + + void NitworkClient::addMissileDeathMsg(n_id_t id) + { + std::lock_guard lock(_receivedPacketsIdsMutex); + struct packetMissileDeath_s packetMissileDeath = { + .header = {0, 0, 0, 0, 1, 0}, + .action = + { + .magick = MISSILE_DEATH, + }, + .msgMissileDeath = + { + .magick = MAGICK_MISSILE_DEATH, + .missileId = id, + }, + }; + Packet packet( + packetMissileDeath.action.magick, + std::make_any(packetMissileDeath), + _serverEndpoint); + addPacketToSend(packet); + } } // namespace Nitwork diff --git a/src/Nitwork/NitworkClient.hpp b/src/Nitwork/NitworkClient.hpp index fee54d5e..4f43c1b5 100644 --- a/src/Nitwork/NitworkClient.hpp +++ b/src/Nitwork/NitworkClient.hpp @@ -37,6 +37,7 @@ namespace Nitwork { void addLifeUpdateMsg(n_id_t playerId, const struct health_s &life); void addEnemyDeathMsg(n_id_t id); void addPlayerDeathMsg(n_id_t id); + void addMissileDeathMsg(n_id_t id); private: NitworkClient(); @@ -132,7 +133,7 @@ namespace Nitwork { } }, { - NEW_BULLET, + NEW_MISSILE, { [this](actionHandler &handler, const struct header_s &header) { handleBody(handler, header); @@ -174,6 +175,17 @@ namespace Nitwork { Systems::receivePlayerDeath(any, endpoint); } } + }, + { + MISSILE_DEATH, + { + [this](actionHandler &handler, const struct header_s &header) { + handleBody(handler, header); + }, + [](std::any &any, boost::asio::ip::udp::endpoint &endpoint) { + Systems::receiveMissileDeath(any, endpoint); + } + } } }; std::map< @@ -205,7 +217,7 @@ namespace Nitwork { } }, { - NEW_BULLET, + NEW_MISSILE, [this](Packet &packet) { sendData(packet); } diff --git a/src/Nitwork/NitworkServer.cpp b/src/Nitwork/NitworkServer.cpp index fd005dc0..981de589 100644 --- a/src/Nitwork/NitworkServer.cpp +++ b/src/Nitwork/NitworkServer.cpp @@ -215,7 +215,7 @@ namespace Nitwork { Logger::info("A new client is ready, waiting for others"); return; } - addStarWaveMessage(endpoint, Types::Enemy::getEnemyNb()); + addStarWaveMessage(endpoint, Types::Enemy::getEnemyNb(), Types::Missiles::getMissileNb()); auto &director = Systems::SystemManagersDirector::getInstance(); std::lock_guard lock(director.mutex); director.getSystemManager(0).addSystem(Systems::initWave); @@ -270,13 +270,13 @@ namespace Nitwork { _playersIds[endpoint] = playerMsg.playerId; } - void NitworkServer::addStarWaveMessage(boost::asio::ip::udp::endpoint & /* unused */, n_id_t enemyId) + void NitworkServer::addStarWaveMessage(boost::asio::ip::udp::endpoint & /* unused */, n_id_t enemyNb, n_id_t missilesNb) { std::lock_guard lock(_receivedPacketsIdsMutex); struct packetMsgStartWave_s packetMsgStartWave = { .header = {0, 0, 0, 0, 1, 0}, .action = {.magick = START_WAVE}, - .msgStartWave = {.magick = MAGICK_START_WAVE, .enemyNb = enemyId} + .msgStartWave = {.magick = MAGICK_START_WAVE, .enemyNb = enemyNb, .missilesNb = missilesNb} }; Packet packet( packetMsgStartWave.action.magick, @@ -334,19 +334,18 @@ namespace Nitwork { } void NitworkServer::broadcastNewBulletMsg( - const struct msgNewBullet_s &msg, - boost::asio::ip::udp::endpoint &senderEndpoint) + const struct msgNewBullet_s &msg) { std::lock_guard lock(_receivedPacketsIdsMutex); struct packetNewBullet_s packetNewBullet = { .header = {0, 0, 0, 0, 1, 0}, - .action = {.magick = NEW_BULLET}, + .action = {.magick = NEW_MISSILE}, .msg = msg }; Packet packet( packetNewBullet.action.magick, std::make_any(packetNewBullet)); - sendToAllClientsButNotOne(packet, senderEndpoint); + sendToAllClients(packet); } void NitworkServer::broadcastAbsolutePositionMsg( diff --git a/src/Nitwork/NitworkServer.hpp b/src/Nitwork/NitworkServer.hpp index 99fccb25..44d1cca2 100644 --- a/src/Nitwork/NitworkServer.hpp +++ b/src/Nitwork/NitworkServer.hpp @@ -24,7 +24,7 @@ namespace Nitwork { bool startServer(int port, int nbPlayer, int threadNb = DEFAULT_THREAD_NB, int tick = TICKS); /* Messages creation methods */ - void addStarWaveMessage(boost::asio::ip::udp::endpoint &endpoint, n_id_t enemyId); + void addStarWaveMessage(boost::asio::ip::udp::endpoint &endpoint, n_id_t enemyNb, n_id_t missilesNb); void addLifeUpdateMessage( boost::asio::ip::udp::endpoint &endpoint, @@ -42,8 +42,7 @@ namespace Nitwork { const msgCreatePlayer_s &playerMsg); void broadcastNewBulletMsg( - const struct msgNewBullet_s &msg, - boost::asio::ip::udp::endpoint &senderEndpoint); + const struct msgNewBullet_s &msg); void broadcastAbsolutePositionMsg( const struct position_absolute_s &pos, @@ -135,7 +134,7 @@ namespace Nitwork { [](std::any &msg, boost::asio::ip::udp::endpoint &endpoint) { Systems::handleClientEnemyDeath(msg, endpoint); }}}, - {NEW_BULLET, + {NEW_MISSILE, {[this](actionHandler &actionHandler, const struct header_s &header) { handleBody(actionHandler, header); }, @@ -156,6 +155,13 @@ namespace Nitwork { [](std::any &msg, boost::asio::ip::udp::endpoint &endpoint) { Systems::receivePlayerDeathMsg(msg, endpoint); }}}, + {MISSILE_DEATH, + {[this](actionHandler &actionHandler, const struct header_s &header) { + handleBody(actionHandler, header); + }, + [](std::any &msg, boost::asio::ip::udp::endpoint &endpoint) { + Systems::handleClientMissileDeath(msg, endpoint); + }}}, }; std::map _actionToSendHandlers = { { @@ -178,7 +184,7 @@ namespace Nitwork { [this](Packet &packet) { sendData(packet); }}, - {NEW_BULLET, + {NEW_MISSILE, [this](Packet &packet) { sendData(packet); }}, diff --git a/src/Server/Systems/Network/ServerNetwork.cpp b/src/Server/Systems/Network/ServerNetwork.cpp index fcc04443..f3f3eae5 100644 --- a/src/Server/Systems/Network/ServerNetwork.cpp +++ b/src/Server/Systems/Network/ServerNetwork.cpp @@ -83,7 +83,7 @@ namespace Systems { struct Types::Missiles missileType = {static_cast(msgNewBullet.missileType)}; Systems::createMissile(position, missileType); // send bullet to clients but not the sender - Nitwork::NitworkServer::getInstance().broadcastNewBulletMsg(msgNewBullet, endpoint); + Nitwork::NitworkServer::getInstance().broadcastNewBulletMsg(msgNewBullet); } void receiveAbsolutePositionMsg(const std::any &msg, boost::asio::ip::udp::endpoint &endpoint) @@ -149,4 +149,38 @@ namespace Systems { } Logger::debug("player not found in receivePlayerDeathMsg"); } + + void handleClientMissileDeath(const std::any &msg, boost::asio::ip::udp::endpoint &endpoint) + { + std::lock_guard lock(Registry::getInstance().mutex); + const struct msgMissileDeath_s &msgMissileDeath = std::any_cast(msg); + auto ®istry = Registry::getInstance(); + + if (msgMissileDeath.magick != MAGICK_MISSILE_DEATH) { + Logger::error("Error: magick is not CLIENT_MISSILE_DEATH"); + return; + } + auto &arrMissiles = registry.getComponents(); + auto arrHealth = registry.getComponents(); + auto arrPos = registry.getComponents(); + auto ids = arrMissiles.getExistingsId(); + + for (auto &id : ids) { + if (arrMissiles[id].getConstId() == msgMissileDeath.missileId) { + if (arrHealth.exist(id) && arrPos.exist(id)) { + Nitwork::NitworkServer::getInstance().broadcastNewBulletMsg( + { + .pos = + {static_cast(Maths::removeIntDecimals(arrPos[id].x)), + static_cast(Maths::removeIntDecimals(arrPos[id].y))}, + .life = arrHealth[id].hp, + .id = msgMissileDeath.missileId, + .missileType = arrMissiles[id].type, + }); + } + return; + } + } + } + } // namespace Systems diff --git a/src/Server/Systems/Network/ServerNetwork.hpp b/src/Server/Systems/Network/ServerNetwork.hpp index bd814462..02c73ef3 100644 --- a/src/Server/Systems/Network/ServerNetwork.hpp +++ b/src/Server/Systems/Network/ServerNetwork.hpp @@ -16,4 +16,5 @@ namespace Systems { void receiveNewBulletMsg(const std::any &msg, boost::asio::ip::udp::endpoint &endpoint); void receiveAbsolutePositionMsg(const std::any &msg, boost::asio::ip::udp::endpoint &endpoint); void receivePlayerDeathMsg(const std::any &msg, boost::asio::ip::udp::endpoint &endpoint); + void handleClientMissileDeath(const std::any &msg, boost::asio::ip::udp::endpoint &endpoint); } // namespace Systems From 4427a1f945a446d05a6f429833b5fed76e5b5b6b Mon Sep 17 00:00:00 2001 From: guillaume abel Date: Tue, 31 Oct 2023 22:41:44 +0100 Subject: [PATCH 02/14] SERVER-NETWORK: Add current progress --- src/Client/Systems/Network/ClientNetwork.cpp | 8 ++++++-- src/ECS/ECSCustomTypes.hpp | 9 ++------- src/ECS/Systems/BulletsSystems.cpp | 2 +- src/ECS/Systems/Systems.hpp | 2 +- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/Client/Systems/Network/ClientNetwork.cpp b/src/Client/Systems/Network/ClientNetwork.cpp index 80dd564a..4daa9de1 100644 --- a/src/Client/Systems/Network/ClientNetwork.cpp +++ b/src/Client/Systems/Network/ClientNetwork.cpp @@ -58,7 +58,7 @@ namespace Systems { std::vector ids = missiles.getExistingsId(); for (auto id : ids) { - if (missiles[id].getConstId() == missileDeath.missileId) { + if (missiles[id].constId == missileDeath.missileId) { if (arrHealth.exist(id)) { arrHealth[id].hp = 0; } else { @@ -232,6 +232,8 @@ namespace Systems { void receiveNewBullet(std::any &any, boost::asio::ip::udp::endpoint & /* unused*/) { std::lock_guard lock(Registry::getInstance().mutex); + auto missiles = Registry::getInstance().getComponents(); + auto health = Registry::getInstance().getComponents(); const struct msgNewBullet_s &msgNewBullet = std::any_cast(any); @@ -240,7 +242,9 @@ namespace Systems { Maths::addIntDecimals(msgNewBullet.pos.y), }; struct Types::Missiles missileType = {static_cast(msgNewBullet.missileType)}; - Systems::createMissile(position, missileType, msgNewBullet.id, msgNewBullet.life); + auto id = Systems::createMissile(position, missileType); + missiles[id].constId = msgNewBullet.id; + health[id].hp = msgNewBullet.life; } void receiveBroadcastAbsolutePosition(std::any &any, boost::asio::ip::udp::endpoint & /* unused*/) diff --git a/src/ECS/ECSCustomTypes.hpp b/src/ECS/ECSCustomTypes.hpp index 4b9965c5..002f6ef5 100644 --- a/src/ECS/ECSCustomTypes.hpp +++ b/src/ECS/ECSCustomTypes.hpp @@ -84,15 +84,10 @@ namespace Types { struct Missiles { public: - Missiles(unsigned int constId, enum missileTypes_e _type = missileTypes_e::CLASSIC) : type(_type), _constId(constId) + Missiles(enum missileTypes_e _type = missileTypes_e::CLASSIC) : type(_type), constId(0) { } - unsigned int getConstId() - { - return _constId; - } - static void setMissileNb(unsigned int nb) { std::lock_guard lock(_mutex); @@ -107,8 +102,8 @@ namespace Types { } missileTypes_e type; + unsigned int constId; private: - unsigned int _constId; static unsigned int _missileNb; static std::mutex _mutex; }; diff --git a/src/ECS/Systems/BulletsSystems.cpp b/src/ECS/Systems/BulletsSystems.cpp index 52918733..396b60da 100644 --- a/src/ECS/Systems/BulletsSystems.cpp +++ b/src/ECS/Systems/BulletsSystems.cpp @@ -103,7 +103,7 @@ namespace Systems { } } - void createMissile(Types::Position pos, Types::Missiles &typeOfMissile, unsigned int id, ) + void createMissile(Types::Position pos, Types::Missiles &typeOfMissile, unsigned int id, int life) { Json &json = Json::getInstance(); Registry::getInstance().addEntity(); diff --git a/src/ECS/Systems/Systems.hpp b/src/ECS/Systems/Systems.hpp index 28e7d81d..94a6bf77 100644 --- a/src/ECS/Systems/Systems.hpp +++ b/src/ECS/Systems/Systems.hpp @@ -35,7 +35,7 @@ namespace Systems { const struct position_absolute_s &pos, const struct health_s &life, bool otherPlayer = false); - void createMissile(Types::Position pos, Types::Missiles &typeOfMissile); + std::size_t createMissile(Types::Position pos, Types::Missiles &typeOfMissile); std::vector> getECSSystems(); std::vector> getBulletSystems(); } // namespace Systems From 9961f6f7f274385b0fd888f960cd6c2c9ab65248 Mon Sep 17 00:00:00 2001 From: romain Date: Tue, 31 Oct 2023 22:44:01 +0100 Subject: [PATCH 03/14] CLIENT-NETWORK/SERVER-NETWORK: Add receive new bullet server side Upgrade create missile func in order to get the bullet's sparseArray id MINOR --- src/Client/Systems/Network/ClientNetwork.cpp | 3 ++- src/Client/Systems/Network/ClientNetwork.hpp | 1 + src/ECS/Systems/BulletsSystems.cpp | 5 +++-- src/ECS/Systems/Systems.hpp | 2 +- src/Nitwork/NitworkClient.cpp | 4 +++- src/Nitwork/NitworkServer.cpp | 21 ++++++++++++++++++++ src/Nitwork/NitworkServer.hpp | 6 ++++++ src/Server/Systems/Network/ServerNetwork.cpp | 15 ++++++++++---- 8 files changed, 48 insertions(+), 9 deletions(-) diff --git a/src/Client/Systems/Network/ClientNetwork.cpp b/src/Client/Systems/Network/ClientNetwork.cpp index 80dd564a..89b62776 100644 --- a/src/Client/Systems/Network/ClientNetwork.cpp +++ b/src/Client/Systems/Network/ClientNetwork.cpp @@ -63,6 +63,7 @@ namespace Systems { arrHealth[id].hp = 0; } else { Logger::fatal("\n\n\n!!!! Missile has no health component, but is alive !!!!\n\n\n"); + // TODO : remove missile Registry::getInstance().removeEntity(id); } return; @@ -240,7 +241,7 @@ namespace Systems { Maths::addIntDecimals(msgNewBullet.pos.y), }; struct Types::Missiles missileType = {static_cast(msgNewBullet.missileType)}; - Systems::createMissile(position, missileType, msgNewBullet.id, msgNewBullet.life); + Systems::createMissile(position, missileType); } void receiveBroadcastAbsolutePosition(std::any &any, boost::asio::ip::udp::endpoint & /* unused*/) diff --git a/src/Client/Systems/Network/ClientNetwork.hpp b/src/Client/Systems/Network/ClientNetwork.hpp index 5a5f7fee..b8aad1a1 100644 --- a/src/Client/Systems/Network/ClientNetwork.hpp +++ b/src/Client/Systems/Network/ClientNetwork.hpp @@ -15,5 +15,6 @@ namespace Systems { void receiveRelativePosition(std::any &any, boost::asio::ip::udp::endpoint &); void receiveBroadcastAbsolutePosition(std::any &any, boost::asio::ip::udp::endpoint &endpoint); void receivePlayerDeath(std::any &any, boost::asio::ip::udp::endpoint &endpoint); + void receiveMissileDeath(std::any &any, boost::asio::ip::udp::endpoint & /* unused */); std::vector> getNetworkSystems(); } // namespace Systems diff --git a/src/ECS/Systems/BulletsSystems.cpp b/src/ECS/Systems/BulletsSystems.cpp index 52918733..07781241 100644 --- a/src/ECS/Systems/BulletsSystems.cpp +++ b/src/ECS/Systems/BulletsSystems.cpp @@ -103,10 +103,10 @@ namespace Systems { } } - void createMissile(Types::Position pos, Types::Missiles &typeOfMissile, unsigned int id, ) + std::size_t createMissile(Types::Position pos, Types::Missiles &typeOfMissile) { Json &json = Json::getInstance(); - Registry::getInstance().addEntity(); + std::size_t id = Registry::getInstance().addEntity(); nlohmann::json bulletData = json.getJsonObjectById(JsonType::BULLETS, getMissileId(typeOfMissile.type), "bullets"); Types::CollisionRect collisionRect = @@ -132,6 +132,7 @@ namespace Systems { Registry::getInstance().getComponents().insertBack(healthComp); Registry::getInstance().getComponents().insertBack(damageComp); Registry::getInstance().getComponents().insertBack(deadComp); + return id; } static void updateBouncePhysics(std::vector ids) diff --git a/src/ECS/Systems/Systems.hpp b/src/ECS/Systems/Systems.hpp index 28e7d81d..94a6bf77 100644 --- a/src/ECS/Systems/Systems.hpp +++ b/src/ECS/Systems/Systems.hpp @@ -35,7 +35,7 @@ namespace Systems { const struct position_absolute_s &pos, const struct health_s &life, bool otherPlayer = false); - void createMissile(Types::Position pos, Types::Missiles &typeOfMissile); + std::size_t createMissile(Types::Position pos, Types::Missiles &typeOfMissile); std::vector> getECSSystems(); std::vector> getBulletSystems(); } // namespace Systems diff --git a/src/Nitwork/NitworkClient.cpp b/src/Nitwork/NitworkClient.cpp index c09ea6ff..2e8eade3 100644 --- a/src/Nitwork/NitworkClient.cpp +++ b/src/Nitwork/NitworkClient.cpp @@ -146,8 +146,10 @@ namespace Nitwork { { .magick = MAGICK_NEW_MISSILE, .pos = pos, + .id = 0, + .life = 0, .missileType = missileType, - }, + }, }; Packet packet( packetNewBullet.action.magick, diff --git a/src/Nitwork/NitworkServer.cpp b/src/Nitwork/NitworkServer.cpp index 981de589..0ca00689 100644 --- a/src/Nitwork/NitworkServer.cpp +++ b/src/Nitwork/NitworkServer.cpp @@ -398,6 +398,27 @@ namespace Nitwork { addPacketToSend(packet); } + void NitworkServer::addMissileDeathMsg(n_id_t id) + { + std::lock_guard lock(_receivedPacketsIdsMutex); + struct packetMissileDeath_s packetMissileDeath = { + .header = {0, 0, 0, 0, 1, 0}, + .action = + { + .magick = MISSILE_DEATH, + }, + .msgMissileDeath = + { + .magick = MAGICK_MISSILE_DEATH, + .missileId = id, + }, + }; + Packet packet( + packetMissileDeath.action.magick, + std::make_any(packetMissileDeath)); + sendToAllClients(packet); + } + n_id_t NitworkServer::getPlayerId(const boost::asio::ip::udp::endpoint &endpoint) const { return _playersIds.at(endpoint); diff --git a/src/Nitwork/NitworkServer.hpp b/src/Nitwork/NitworkServer.hpp index 44d1cca2..3b7f710a 100644 --- a/src/Nitwork/NitworkServer.hpp +++ b/src/Nitwork/NitworkServer.hpp @@ -54,6 +54,8 @@ namespace Nitwork { boost::asio::ip::udp::endpoint &endpoint, const struct msgCreatePlayer_s &playerMsg); + void addMissileDeathMsg(n_id_t id); + n_id_t getPlayerId(const boost::asio::ip::udp::endpoint &endpoint) const; private: @@ -204,6 +206,10 @@ namespace Nitwork { [this](Packet &packet) { sendData(packet); }}, + {MISSILE_DEATH, + [this](Packet &packet) { + sendData(packet); + }}, }; }; } // namespace Nitwork diff --git a/src/Server/Systems/Network/ServerNetwork.cpp b/src/Server/Systems/Network/ServerNetwork.cpp index f3f3eae5..77e7c492 100644 --- a/src/Server/Systems/Network/ServerNetwork.cpp +++ b/src/Server/Systems/Network/ServerNetwork.cpp @@ -70,19 +70,26 @@ namespace Systems { } } - void receiveNewBulletMsg(const std::any &msg, boost::asio::ip::udp::endpoint &endpoint) + void receiveNewBulletMsg(const std::any &msg, boost::asio::ip::udp::endpoint &/* unused */) { std::lock_guard lock(Registry::getInstance().mutex); + auto &arrMissiles = Registry::getInstance().getComponents(); + auto &arrHealth = Registry::getInstance().getComponents(); - const struct msgNewBullet_s &msgNewBullet = std::any_cast(msg); + struct msgNewBullet_s msgNewBullet = std::any_cast(msg); struct Types::Position position = { Maths::addIntDecimals(msgNewBullet.pos.x), Maths::addIntDecimals(msgNewBullet.pos.y), }; struct Types::Missiles missileType = {static_cast(msgNewBullet.missileType)}; - Systems::createMissile(position, missileType); - // send bullet to clients but not the sender + auto id = Systems::createMissile(position, missileType); + if (!arrMissiles.exist(id) || !arrHealth.exist(id)) { + Logger::error("Error: missile not created"); + return; + } + msgNewBullet.id = arrMissiles[id].getConstId(); + msgNewBullet.life = arrHealth[id].hp; Nitwork::NitworkServer::getInstance().broadcastNewBulletMsg(msgNewBullet); } From 914bb6934d17021e277b46ff9995a4b347c3b385 Mon Sep 17 00:00:00 2001 From: Github Actions Date: Tue, 31 Oct 2023 22:45:38 +0000 Subject: [PATCH 04/14] FORMAT-AUTO: automatic format on pull request #137 --- src/Client/Systems/Network/ClientNetwork.cpp | 12 +++---- src/ECS/ECSCustomTypes.hpp | 1 + src/ECS/Systems/BulletsSystems.cpp | 2 +- src/ECS/Systems/Systems.cpp | 2 +- src/Nitwork/NitworkClient.cpp | 2 +- src/Nitwork/NitworkServer.cpp | 9 +++--- src/Nitwork/NitworkServer.hpp | 23 +++++++------- src/Server/Systems/Network/ServerNetwork.cpp | 33 ++++++++++---------- 8 files changed, 41 insertions(+), 43 deletions(-) diff --git a/src/Client/Systems/Network/ClientNetwork.cpp b/src/Client/Systems/Network/ClientNetwork.cpp index 896375a6..c5d0fed7 100644 --- a/src/Client/Systems/Network/ClientNetwork.cpp +++ b/src/Client/Systems/Network/ClientNetwork.cpp @@ -52,8 +52,8 @@ namespace Systems { void receiveMissileDeath(std::any &any, boost::asio::ip::udp::endpoint & /* unused */) { std::lock_guard lock(Registry::getInstance().mutex); - const auto missileDeath = std::any_cast(any); - auto &missiles = Registry::getInstance().getComponents(); + const auto missileDeath = std::any_cast(any); + auto &missiles = Registry::getInstance().getComponents(); auto &arrHealth = Registry::getInstance().getComponents(); std::vector ids = missiles.getExistingsId(); @@ -233,7 +233,7 @@ namespace Systems { { std::lock_guard lock(Registry::getInstance().mutex); auto missiles = Registry::getInstance().getComponents(); - auto health = Registry::getInstance().getComponents(); + auto health = Registry::getInstance().getComponents(); const struct msgNewBullet_s &msgNewBullet = std::any_cast(any); @@ -242,9 +242,9 @@ namespace Systems { Maths::addIntDecimals(msgNewBullet.pos.y), }; struct Types::Missiles missileType = {static_cast(msgNewBullet.missileType)}; - auto id = Systems::createMissile(position, missileType); - missiles[id].constId = msgNewBullet.id; - health[id].hp = msgNewBullet.life; + auto id = Systems::createMissile(position, missileType); + missiles[id].constId = msgNewBullet.id; + health[id].hp = msgNewBullet.life; } void receiveBroadcastAbsolutePosition(std::any &any, boost::asio::ip::udp::endpoint & /* unused*/) diff --git a/src/ECS/ECSCustomTypes.hpp b/src/ECS/ECSCustomTypes.hpp index 002f6ef5..82b3bff8 100644 --- a/src/ECS/ECSCustomTypes.hpp +++ b/src/ECS/ECSCustomTypes.hpp @@ -103,6 +103,7 @@ namespace Types { missileTypes_e type; unsigned int constId; + private: static unsigned int _missileNb; static std::mutex _mutex; diff --git a/src/ECS/Systems/BulletsSystems.cpp b/src/ECS/Systems/BulletsSystems.cpp index 07781241..0beea57c 100644 --- a/src/ECS/Systems/BulletsSystems.cpp +++ b/src/ECS/Systems/BulletsSystems.cpp @@ -105,7 +105,7 @@ namespace Systems { std::size_t createMissile(Types::Position pos, Types::Missiles &typeOfMissile) { - Json &json = Json::getInstance(); + Json &json = Json::getInstance(); std::size_t id = Registry::getInstance().addEntity(); nlohmann::json bulletData = json.getJsonObjectById(JsonType::BULLETS, getMissileId(typeOfMissile.type), "bullets"); diff --git a/src/ECS/Systems/Systems.cpp b/src/ECS/Systems/Systems.cpp index d4e9086c..488b9c56 100644 --- a/src/ECS/Systems/Systems.cpp +++ b/src/ECS/Systems/Systems.cpp @@ -385,7 +385,7 @@ namespace Systems { static void sendDeathMsg(std::size_t arrId) { - auto &arrEnemies = Registry::getInstance().getComponents(); + auto &arrEnemies = Registry::getInstance().getComponents(); auto &arrMissiles = Registry::getInstance().getComponents(); #ifndef CLIENT diff --git a/src/Nitwork/NitworkClient.cpp b/src/Nitwork/NitworkClient.cpp index f20f7aab..67208a76 100644 --- a/src/Nitwork/NitworkClient.cpp +++ b/src/Nitwork/NitworkClient.cpp @@ -205,7 +205,7 @@ namespace Nitwork { .id = 0, .life = 0, .missileType = missileType, - }, + }, }; Packet packet( packetNewBullet.action.magick, diff --git a/src/Nitwork/NitworkServer.cpp b/src/Nitwork/NitworkServer.cpp index 76a85a23..d692f763 100644 --- a/src/Nitwork/NitworkServer.cpp +++ b/src/Nitwork/NitworkServer.cpp @@ -361,8 +361,7 @@ namespace Nitwork { addPacketToSend(packet); } - void NitworkServer::broadcastNewBulletMsg( - const struct msgNewBullet_s &msg) + void NitworkServer::broadcastNewBulletMsg(const struct msgNewBullet_s &msg) { std::lock_guard lock(_receivedPacketsIdsMutex); struct packetNewBullet_s packetNewBullet = { @@ -449,12 +448,12 @@ namespace Nitwork { .action = { .magick = MISSILE_DEATH, - }, + }, .msgMissileDeath = { - .magick = MAGICK_MISSILE_DEATH, + .magick = MAGICK_MISSILE_DEATH, .missileId = id, - }, + }, }; Packet packet( packetMissileDeath.action.magick, diff --git a/src/Nitwork/NitworkServer.hpp b/src/Nitwork/NitworkServer.hpp index fbeae968..166f235e 100644 --- a/src/Nitwork/NitworkServer.hpp +++ b/src/Nitwork/NitworkServer.hpp @@ -107,8 +107,7 @@ namespace Nitwork { * @param msg The infos of the bullet that will be created * @param senderEndpoint The endpoint of the client that sent the msg of hie new bullet */ - void broadcastNewBulletMsg( - const struct msgNewBullet_s &msg); + void broadcastNewBulletMsg(const struct msgNewBullet_s &msg); /** * @brief Add a msg packet that contain the new bullet msg to the clients @@ -300,12 +299,12 @@ namespace Nitwork { Systems::receivePlayerDeathMsg(msg, endpoint); }}}, {MISSILE_DEATH, - {[this](actionHandler &actionHandler, const struct header_s &header) { + {[this](actionHandler &actionHandler, const struct header_s &header) { handleBody(actionHandler, header); - }, - [](std::any &msg, boost::asio::ip::udp::endpoint &endpoint) { - Systems::handleClientMissileDeath(msg, endpoint); - }}}, + }, + [](std::any &msg, boost::asio::ip::udp::endpoint &endpoint) { + Systems::handleClientMissileDeath(msg, endpoint); + }}}, }; /** * @brief a map that will be used to handle the actions, in order to send them @@ -330,7 +329,7 @@ namespace Nitwork { {NEW_ENEMY, [this](Packet &packet) { sendData(packet); - }}, + } }, {NEW_MISSILE, [this](Packet &packet) { sendData(packet); @@ -350,11 +349,11 @@ namespace Nitwork { {PLAYER_DEATH, [this](Packet &packet) { sendData(packet); - }}, + } }, {MISSILE_DEATH, - [this](Packet &packet) { - sendData(packet); - }}, + [this](Packet &packet) { + sendData(packet); + } }, {INFO_LOBBY, [this](Packet &packet) { sendData(packet); }} diff --git a/src/Server/Systems/Network/ServerNetwork.cpp b/src/Server/Systems/Network/ServerNetwork.cpp index 8a3ccfda..f318e6d0 100644 --- a/src/Server/Systems/Network/ServerNetwork.cpp +++ b/src/Server/Systems/Network/ServerNetwork.cpp @@ -70,7 +70,7 @@ namespace Systems { } } - void receiveNewBulletMsg(const std::any &msg, boost::asio::ip::udp::endpoint &/* unused */) + void receiveNewBulletMsg(const std::any &msg, boost::asio::ip::udp::endpoint & /* unused */) { std::lock_guard lock(Registry::getInstance().mutex); auto &arrMissiles = Registry::getInstance().getComponents(); @@ -83,12 +83,12 @@ namespace Systems { Maths::addIntDecimals(msgNewBullet.pos.y), }; struct Types::Missiles missileType = {static_cast(msgNewBullet.missileType)}; - auto id = Systems::createMissile(position, missileType); + auto id = Systems::createMissile(position, missileType); if (!arrMissiles.exist(id) || !arrHealth.exist(id)) { Logger::error("Error: missile not created"); return; } - msgNewBullet.id = arrMissiles[id].constId; + msgNewBullet.id = arrMissiles[id].constId; msgNewBullet.life = arrHealth[id].hp; Nitwork::NitworkServer::getInstance().broadcastNewBulletMsg(msgNewBullet); } @@ -156,33 +156,32 @@ namespace Systems { Nitwork::NitworkServer::getInstance().addPlayerDeathMsg(msgPlayerDeath.playerId); } - void handleClientMissileDeath(const std::any &msg, boost::asio::ip::udp::endpoint &/* us=nused */) + void handleClientMissileDeath(const std::any &msg, boost::asio::ip::udp::endpoint & /* us=nused */) { std::lock_guard lock(Registry::getInstance().mutex); const struct msgMissileDeath_s &msgMissileDeath = std::any_cast(msg); - auto ®istry = Registry::getInstance(); + auto ®istry = Registry::getInstance(); if (msgMissileDeath.magick != MAGICK_MISSILE_DEATH) { Logger::error("Error: magick is not CLIENT_MISSILE_DEATH"); return; } auto &arrMissiles = registry.getComponents(); - auto arrHealth = registry.getComponents(); - auto arrPos = registry.getComponents(); - auto ids = arrMissiles.getExistingsId(); + auto arrHealth = registry.getComponents(); + auto arrPos = registry.getComponents(); + auto ids = arrMissiles.getExistingsId(); for (auto &id : ids) { if (arrMissiles[id].constId == msgMissileDeath.missileId) { if (arrHealth.exist(id) && arrPos.exist(id)) { - Nitwork::NitworkServer::getInstance().broadcastNewBulletMsg( - { - .magick = MAGICK_NEW_MISSILE, - .pos = - {static_cast(Maths::removeIntDecimals(arrPos[id].x)), - static_cast(Maths::removeIntDecimals(arrPos[id].y))}, - .id = msgMissileDeath.missileId, - .life = arrHealth[id].hp, - .missileType = arrMissiles[id].type, + Nitwork::NitworkServer::getInstance().broadcastNewBulletMsg({ + .magick = MAGICK_NEW_MISSILE, + .pos = + {static_cast(Maths::removeIntDecimals(arrPos[id].x)), + static_cast(Maths::removeIntDecimals(arrPos[id].y))}, + .id = msgMissileDeath.missileId, + .life = arrHealth[id].hp, + .missileType = arrMissiles[id].type, }); } return; From b7f0b021078bf2d8361fda1c0ad957d915f6549e Mon Sep 17 00:00:00 2001 From: mE0w Date: Thu, 2 Nov 2023 09:42:16 +0100 Subject: [PATCH 05/14] Update src/Nitwork/NitworkServer.hpp Co-authored-by: Xavier Mitault --- src/Nitwork/NitworkServer.hpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Nitwork/NitworkServer.hpp b/src/Nitwork/NitworkServer.hpp index 166f235e..e9df5806 100644 --- a/src/Nitwork/NitworkServer.hpp +++ b/src/Nitwork/NitworkServer.hpp @@ -105,7 +105,6 @@ namespace Nitwork { /** * @brief Add a msg packet that contain the new bullet msg to the clients * @param msg The infos of the bullet that will be created - * @param senderEndpoint The endpoint of the client that sent the msg of hie new bullet */ void broadcastNewBulletMsg(const struct msgNewBullet_s &msg); From d7dd089b44dd48fdc4f066da8edb01fd4bc0d6d1 Mon Sep 17 00:00:00 2001 From: mE0w Date: Thu, 2 Nov 2023 09:42:38 +0100 Subject: [PATCH 06/14] Update src/ECS/ECSCustomTypes.hpp Co-authored-by: Xavier Mitault --- src/ECS/ECSCustomTypes.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ECS/ECSCustomTypes.hpp b/src/ECS/ECSCustomTypes.hpp index 82b3bff8..2d55268d 100644 --- a/src/ECS/ECSCustomTypes.hpp +++ b/src/ECS/ECSCustomTypes.hpp @@ -84,7 +84,7 @@ namespace Types { struct Missiles { public: - Missiles(enum missileTypes_e _type = missileTypes_e::CLASSIC) : type(_type), constId(0) + Missiles(enum missileTypes_e _type = CLASSIC) : type(_type), constId(0) { } From a3264b892ceb3cfd309de4590fdea6a2427605c6 Mon Sep 17 00:00:00 2001 From: mE0w Date: Thu, 2 Nov 2023 09:43:13 +0100 Subject: [PATCH 07/14] Update docs/network/rfc/RFC.md Co-authored-by: Xavier Mitault --- docs/network/rfc/RFC.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/network/rfc/RFC.md b/docs/network/rfc/RFC.md index ea7f9534..113ff762 100644 --- a/docs/network/rfc/RFC.md +++ b/docs/network/rfc/RFC.md @@ -1046,6 +1046,7 @@ Table of Contents *** Missile ID This field correspond to the ID of the missile that died + This field must be of size 4 bytes. This field is unsigned (so starting from 0 to 2^32) This field is unique for each missile. From 63bb65be2ff5f9c9d71a2d60ff52510106ddbf05 Mon Sep 17 00:00:00 2001 From: mE0w Date: Thu, 2 Nov 2023 09:44:05 +0100 Subject: [PATCH 08/14] Update docs/network/rfc/RFC.md Co-authored-by: Xavier Mitault --- docs/network/rfc/RFC.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/network/rfc/RFC.md b/docs/network/rfc/RFC.md index 113ff762..9df26c59 100644 --- a/docs/network/rfc/RFC.md +++ b/docs/network/rfc/RFC.md @@ -905,6 +905,7 @@ Table of Contents *** Missile Health This field correspond to the health of the missile. + This field must be of size 4 bytes. *** Missile Type From 9b6ff9604c2e15d0a43d85c82d24f8cad2a47ddb Mon Sep 17 00:00:00 2001 From: mE0w Date: Thu, 2 Nov 2023 09:44:18 +0100 Subject: [PATCH 09/14] Update docs/network/rfc/RFC.md Co-authored-by: Xavier Mitault --- docs/network/rfc/RFC.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/network/rfc/RFC.md b/docs/network/rfc/RFC.md index 9df26c59..45016a53 100644 --- a/docs/network/rfc/RFC.md +++ b/docs/network/rfc/RFC.md @@ -900,6 +900,7 @@ Table of Contents *** Missile ID This field correspond to the ID of the missile. + This field must be of size 4 bytes. *** Missile Health From 386033a3b5f17286b1cc7f6a7d982a288a0febaf Mon Sep 17 00:00:00 2001 From: mE0w Date: Thu, 2 Nov 2023 09:44:38 +0100 Subject: [PATCH 10/14] Update docs/network/rfc/RFC.md Co-authored-by: Xavier Mitault --- docs/network/rfc/RFC.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/network/rfc/RFC.md b/docs/network/rfc/RFC.md index 45016a53..1b230459 100644 --- a/docs/network/rfc/RFC.md +++ b/docs/network/rfc/RFC.md @@ -554,6 +554,7 @@ Table of Contents *** Missile ID This field correspond to the ID of the missile that died + This field must be of size 4 bytes. This field is unsigned (so starting from 0 to 2^32) This field is unique for each missile. From 1f1d288b50a790eb19d7d83ef6c99090bff78669 Mon Sep 17 00:00:00 2001 From: mE0w Date: Thu, 2 Nov 2023 09:44:46 +0100 Subject: [PATCH 11/14] Update docs/network/rfc/RFC.md Co-authored-by: Xavier Mitault --- docs/network/rfc/RFC.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/network/rfc/RFC.md b/docs/network/rfc/RFC.md index 1b230459..d9920d68 100644 --- a/docs/network/rfc/RFC.md +++ b/docs/network/rfc/RFC.md @@ -442,6 +442,7 @@ Table of Contents missile. This field must be of size 4 byte. + This field must be equal to `0` *** Missile Type From b2bb2778541447581102f34d6a16c4cd1af9f74f Mon Sep 17 00:00:00 2001 From: mE0w Date: Thu, 2 Nov 2023 09:44:53 +0100 Subject: [PATCH 12/14] Update docs/network/rfc/RFC.md Co-authored-by: Xavier Mitault --- docs/network/rfc/RFC.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/network/rfc/RFC.md b/docs/network/rfc/RFC.md index d9920d68..63b5bf03 100644 --- a/docs/network/rfc/RFC.md +++ b/docs/network/rfc/RFC.md @@ -434,6 +434,7 @@ Table of Contents missile. This field must be of size 4 byte. + This field must be equal to `0` *** Missile Health From 60d2f2e40b0e97d610719fb18b2cd318ae807434 Mon Sep 17 00:00:00 2001 From: romain Date: Thu, 2 Nov 2023 09:49:21 +0100 Subject: [PATCH 13/14] RFC: Fix missing fields form missile id and health (signed or not) PATCH --- docs/network/rfc/RFC.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/network/rfc/RFC.md b/docs/network/rfc/RFC.md index ea7f9534..c0b9fa4c 100644 --- a/docs/network/rfc/RFC.md +++ b/docs/network/rfc/RFC.md @@ -901,11 +901,13 @@ Table of Contents This field correspond to the ID of the missile. This field must be of size 4 bytes. + This field is signed (so starting from -((2^32)/2) to +(((2^32)/2)-1)) *** Missile Health This field correspond to the health of the missile. This field must be of size 4 bytes. + This field is signed (so starting from -((2^32)/2) to +(((2^32)/2)-1)) *** Missile Type From e70b01b4b8a943335c37e8e96ca378366282f464 Mon Sep 17 00:00:00 2001 From: romain Date: Thu, 2 Nov 2023 09:54:48 +0100 Subject: [PATCH 14/14] NITWORK-SERVER: Update doc PATCH --- src/Nitwork/NitworkServer.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Nitwork/NitworkServer.hpp b/src/Nitwork/NitworkServer.hpp index e9df5806..d0135c1f 100644 --- a/src/Nitwork/NitworkServer.hpp +++ b/src/Nitwork/NitworkServer.hpp @@ -103,8 +103,8 @@ namespace Nitwork { const msgCreatePlayer_s &playerMsg); /** - * @brief Add a msg packet that contain the new bullet msg to the clients - * @param msg The infos of the bullet that will be created + * @brief Add a msg packet that contain the new missile msg to the clients + * @param msg The infos of the missile that will be created */ void broadcastNewBulletMsg(const struct msgNewBullet_s &msg); @@ -134,7 +134,7 @@ namespace Nitwork { const struct msgCreatePlayer_s &playerMsg); /** - * @brief Add a msg packet that contain the new bullet msg to the clients + * @brief Add a msg packet that contain the new missile msg to the clients * @param id The id of the player that died */ void addMissileDeathMsg(n_id_t id);