From b4a49089c43224a59d375bf897c3d0771c90e91b Mon Sep 17 00:00:00 2001 From: romain Date: Sun, 5 Nov 2023 16:31:57 +0100 Subject: [PATCH] NITWORK: Fix connect lobby bug, (action cast bug) PATCH --- src/Game/GameSystems.cpp | 4 +-- src/Nitwork/ANitwork.cpp | 1 - src/Nitwork/ANitwork.hpp | 7 ++++ src/Nitwork/Nitwork.h | 48 +++++++++++++------------- src/Nitwork/NitworkClient.cpp | 44 ++++++++++++------------ src/Nitwork/NitworkClient.hpp | 56 +++++++++++++++---------------- src/Nitwork/NitworkMainServer.cpp | 4 +-- src/Nitwork/NitworkMainServer.hpp | 12 +++---- src/Nitwork/NitworkServer.cpp | 42 ++++++++++++----------- src/Nitwork/NitworkServer.hpp | 50 +++++++++++++-------------- src/init.cpp | 2 -- 11 files changed, 138 insertions(+), 132 deletions(-) diff --git a/src/Game/GameSystems.cpp b/src/Game/GameSystems.cpp index d7c2fcf7..2aed90ab 100644 --- a/src/Game/GameSystems.cpp +++ b/src/Game/GameSystems.cpp @@ -116,8 +116,9 @@ namespace Systems { Registry::getInstance().getComponents(); auto arrHealth = Registry::getInstance().getComponents(); + struct health_s health = {arrHealth[id].hp}; if (arrPlayer.exist(id)) { - Nitwork::NitworkClient::getInstance().addLifeUpdateMsg(arrPlayer[id].constId, {arrHealth[id].hp}); + Nitwork::NitworkClient::getInstance().addLifeUpdateMsg(arrPlayer[id].constId, health); } } @@ -146,7 +147,6 @@ namespace Systems { registry.addEventCallback(Events::ENTITY_DEATH, sendMissileDeath); #ifdef CLIENT registry.addEventCallback(Events::ENTITY_DEATH, sendPlayerDeathToServer); - registry.addEventCallback(Events::TAKE_DAMAGE, sendLifeUpdateToServer); #endif registry.addAllie(static_cast(AlliesType::PLAYERS), typeid(Types::Player)); diff --git a/src/Nitwork/ANitwork.cpp b/src/Nitwork/ANitwork.cpp index bb7e15e7..282f25a9 100644 --- a/src/Nitwork/ANitwork.cpp +++ b/src/Nitwork/ANitwork.cpp @@ -245,7 +245,6 @@ namespace Nitwork { }); for (auto &action : _actions) { try { - Logger::fatal("NITWORK: Adding action to queue: " + std::to_string(action.first.id)); action.second(action.first.data, action.first.endpoint); } catch (std::exception &e) { Logger::fatal("StartInputHandler:"); diff --git a/src/Nitwork/ANitwork.hpp b/src/Nitwork/ANitwork.hpp index c6af2dde..cc1dfba7 100644 --- a/src/Nitwork/ANitwork.hpp +++ b/src/Nitwork/ANitwork.hpp @@ -16,6 +16,7 @@ #include "B-luga/Logger.hpp" #include "INitwork.hpp" #include "Zstd.hpp" +#include namespace Nitwork { @@ -63,9 +64,15 @@ namespace Nitwork { HEADER_CODE2}; data.header = newHeader; } +#ifdef DEBUG + if constexpr (!std::is_same_v) { + Logger::fatal("id of packet = " + std::to_string(id) + " action type = " + std::to_string(data.action.magick)); + } +#endif std::shared_ptr> compressedPacket = std::make_shared>(Zstd::compress(data)); + _socket.async_send_to( boost::asio::buffer(*compressedPacket), packet.endpoint, diff --git a/src/Nitwork/Nitwork.h b/src/Nitwork/Nitwork.h index c207565c..b14e4159 100644 --- a/src/Nitwork/Nitwork.h +++ b/src/Nitwork/Nitwork.h @@ -62,30 +62,30 @@ typedef unsigned char n_nbAction_t; */ enum n_actionType_t { NO_ACTION = 0, - INIT = 1, - READY = 2, - START_WAVE = 3, - LIFE_UPDATE = 5, - ENEMY_DEATH = 6, - POSITION_RELATIVE = 7, - POSITION_ABSOLUTE = 8, - NEW_MISSILE = 9, - NEW_ENEMY = 10, - NEW_PLAYER = 11, - POSITION_RELATIVE_BROADCAST = 12, - POSITION_ABSOLUTE_BROADCAST = 13, - PLAYER_DEATH = 14, - MISSILE_DEATH = 15, - LIST_LOBBY = 16, - INFO_LOBBY = 17, - CONNECT_MAIN_SERVER = 18, - CONNECT_MAIN_SERVER_RESP = 19, - CONNECT_LOBBY = 20, - CONNECT_LOBBY_RESP = 21, - DISCONNECT_LOBBY = 22, - CREATE_LOBBY = 23, - END_GAME = 24, - N_ACTION_TYPE_MAX, + NITWORK_INIT = 1, + NITWORK_READY = 2, + NITWORK_START_WAVE = 3, + NITWORK_LIFE_UPDATE = 5, + NITWORK_ENEMY_DEATH = 6, + NITWORK_POSITION_RELATIVE = 7, + NITWORK_POSITION_ABSOLUTE = 8, + NITWORK_NEW_MISSILE = 9, + NITWORK_NEW_ENEMY = 10, + NITWORK_NEW_PLAYER = 11, + NITWORK_POSITION_RELATIVE_BROADCAST = 12, + NITWORK_POSITION_ABSOLUTE_BROADCAST = 13, + NITWORK_PLAYER_DEATH = 14, + NITWORK_MISSILE_DEATH = 15, + NITWORK_LIST_LOBBY = 16, + NITWORK_INFO_LOBBY = 17, + NITWORK_CONNECT_MAIN_SERVER = 18, + NITWORK_CONNECT_MAIN_SERVER_RESP = 19, + NITWORK_CONNECT_LOBBY = 20, + NITWORK_CONNECT_LOBBY_RESP = 21, + NITWORK_DISCONNECT_LOBBY = 22, + NITWORK_CREATE_LOBBY = 23, + NITWORK_END_GAME = 24, + NITWORK_N_ACTION_TYPE_MAX, }; PACK(struct header_s { diff --git a/src/Nitwork/NitworkClient.cpp b/src/Nitwork/NitworkClient.cpp index ba710d9b..98e7d7d3 100644 --- a/src/Nitwork/NitworkClient.cpp +++ b/src/Nitwork/NitworkClient.cpp @@ -148,11 +148,11 @@ namespace Nitwork { .header = {0, 0, 0, 0, 1, 0}, .action = { - .magick = DISCONNECT_LOBBY, + .magick = NITWORK_DISCONNECT_LOBBY, }, .msg = {.magick = MAGICK_DISCONNECT_LOBBY}, }; - Logger::error("------------------------------------ Sending disconnect lobby msg: " + std::to_string(DISCONNECT_LOBBY) + " " + std::to_string(MAGICK_DISCONNECT_LOBBY)); + Logger::error("------------------------------------ Sending disconnect lobby msg: " + std::to_string(NITWORK_DISCONNECT_LOBBY) + " " + std::to_string(MAGICK_DISCONNECT_LOBBY)); Packet packet( packetDisconnectLobby.action.magick, std::make_any(packetDisconnectLobby), @@ -168,11 +168,11 @@ namespace Nitwork { .header = {0, 0, 0, 0, 1, 0}, .action = { - .magick = INIT, + .magick = NITWORK_INIT, }, .msgInit = {.magick = MAGICK_INIT} }; - Logger::error("------------------------------------ Sending init msg: " + std::to_string(INIT) + " " + std::to_string(MAGICK_INIT)); + Logger::error("------------------------------------ Sending init msg: " + std::to_string(NITWORK_INIT) + " " + std::to_string(MAGICK_INIT)); Packet packet( packetMsgInit.action.magick, std::make_any(packetMsgInit), @@ -185,10 +185,10 @@ namespace Nitwork { std::lock_guard lock(_receivedPacketsIdsMutex); struct packetMsgReady_s packetMsgReady = { .header = {0, 0, 0, 0, 1, 0}, - .action = {.magick = READY}, + .action = {.magick = NITWORK_READY}, .msgReady = {.magick = MAGICK_READY} }; - Logger::error("------------------------------------ Sending ready msg: " + std::to_string(READY) + " " + std::to_string(MAGICK_READY)); + Logger::error("------------------------------------ Sending ready msg: " + std::to_string(NITWORK_READY) + " " + std::to_string(MAGICK_READY)); Packet packet( packetMsgReady.action.magick, std::make_any(packetMsgReady), @@ -203,7 +203,7 @@ namespace Nitwork { .header = {0, 0, 0, 0, 1, 0}, .action = { - .magick = POSITION_RELATIVE, + .magick = NITWORK_POSITION_RELATIVE, }, .msg = { @@ -227,7 +227,7 @@ namespace Nitwork { .header = {0, 0, 0, 0, 1, 0}, .action = { - .magick = NEW_MISSILE, + .magick = NITWORK_NEW_MISSILE, }, .msg = { @@ -252,7 +252,7 @@ namespace Nitwork { .header = {0, 0, 0, 0, 1, 0}, .action = { - .magick = POSITION_ABSOLUTE, + .magick = NITWORK_POSITION_ABSOLUTE, }, .msg = { @@ -275,7 +275,7 @@ namespace Nitwork { .header = {0, 0, 0, 0, 1, 0}, .action = { - .magick = LIFE_UPDATE, + .magick = NITWORK_LIFE_UPDATE, }, .msgLifeUpdate = { @@ -300,7 +300,7 @@ namespace Nitwork { .header = {0, 0, 0, 0, 1, 0}, .action = { - .magick = ENEMY_DEATH, + .magick = NITWORK_ENEMY_DEATH, }, .msgEnemyDeath = { @@ -322,7 +322,7 @@ namespace Nitwork { .header = {0, 0, 0, 0, 1, 0}, .action = { - .magick = PLAYER_DEATH, + .magick = NITWORK_PLAYER_DEATH, }, .msg = {.magick = MAGICK_PLAYER_DEATH, .playerId = id}, }; @@ -340,7 +340,7 @@ namespace Nitwork { .header = {0, 0, 0, 0, 1, 0}, .action = { - .magick = MISSILE_DEATH, + .magick = NITWORK_MISSILE_DEATH, }, .msgMissileDeath = { @@ -348,7 +348,7 @@ namespace Nitwork { .missileId = id, }, }; - Logger::error("------------------------------------ Sending missile death msg: " + std::to_string(MISSILE_DEATH) + " " + std::to_string(MAGICK_MISSILE_DEATH)); + Logger::error("------------------------------------ Sending missile death msg: " + std::to_string(NITWORK_MISSILE_DEATH) + " " + std::to_string(MAGICK_MISSILE_DEATH)); Packet packet( packetMissileDeath.action.magick, std::make_any(packetMissileDeath), @@ -362,11 +362,11 @@ namespace Nitwork { .header = {0, 0, 0, 0, 1, 0}, .action = { - .magick = LIST_LOBBY, + .magick = NITWORK_LIST_LOBBY, }, .msg = {.magick = MAGICK_REQUEST_LIST_LOBBY}, }; - Logger::error("------------------------------------ Sending list lobby msg: " + std::to_string(LIST_LOBBY) + " " + std::to_string(MAGICK_REQUEST_LIST_LOBBY)); + Logger::error("------------------------------------ Sending list lobby msg: " + std::to_string(NITWORK_LIST_LOBBY) + " " + std::to_string(MAGICK_REQUEST_LIST_LOBBY)); Packet packet( packetListLobby.action.magick, std::make_any(packetListLobby), @@ -384,7 +384,7 @@ namespace Nitwork { .header = {0, 0, 0, 0, 1, 0}, .action = { - .magick = CREATE_LOBBY, + .magick = NITWORK_CREATE_LOBBY, }, .msg = { .magick = MAGICK_CREATE_LOBBY, @@ -393,7 +393,7 @@ namespace Nitwork { .maxNbPlayer = maxNbPlayer, .ownerInfos = {.ip = "", .port = _mainServerEndpoint.port()}} }; - Logger::error("------------------------------------ Sending create lobby msg: " + std::to_string(CREATE_LOBBY) + " " + std::to_string(MAGICK_CREATE_LOBBY)); + Logger::error("------------------------------------ Sending create lobby msg: " + std::to_string(NITWORK_CREATE_LOBBY) + " " + std::to_string(MAGICK_CREATE_LOBBY)); std::strcpy(packetCreateLobby.msg.name, (name.size() > 32 ? name.substr(0, 32) : name).c_str()); std::strcpy( packetCreateLobby.msg.ownerInfos.ip, @@ -415,11 +415,11 @@ namespace Nitwork { .header = {0, 0, 0, 0, 1, 0}, .action = { - .magick = CONNECT_MAIN_SERVER, + .magick = NITWORK_CONNECT_MAIN_SERVER, }, .msg = {.magick = MAGICK_CONNECT_MAIN_SERVER}, }; - Logger::error("------------------------------------ Sending connect main server msg: " + std::to_string(CONNECT_MAIN_SERVER) + " " + std::to_string(MAGICK_CONNECT_MAIN_SERVER)); + Logger::error("------------------------------------ Sending connect main server msg: " + std::to_string(NITWORK_CONNECT_MAIN_SERVER) + " " + std::to_string(MAGICK_CONNECT_MAIN_SERVER)); Packet packet( packetConnectMainServer.action.magick, std::make_any(packetConnectMainServer), @@ -434,11 +434,11 @@ namespace Nitwork { .header = {0, 0, 0, 0, 1, 0}, .action = { - .magick = CONNECT_LOBBY, + .magick = NITWORK_CONNECT_LOBBY, }, .msg = {.magick = MAGICK_CONNECT_LOBBY}, }; - Logger::error("------------------------------------ Sending connect lobby msg: " + std::to_string(CONNECT_LOBBY) + " " + std::to_string(MAGICK_CONNECT_LOBBY)); + Logger::error("------------------------------------ Sending connect lobby msg: " + std::to_string(NITWORK_CONNECT_LOBBY) + " " + std::to_string(MAGICK_CONNECT_LOBBY)); Packet packet( packetConnectLobby.action.magick, std::make_any(packetConnectLobby), diff --git a/src/Nitwork/NitworkClient.hpp b/src/Nitwork/NitworkClient.hpp index b9a46e06..268bc6ee 100644 --- a/src/Nitwork/NitworkClient.hpp +++ b/src/Nitwork/NitworkClient.hpp @@ -226,7 +226,7 @@ namespace Nitwork { std::pair > _actionsHandlers = { { - CONNECT_LOBBY_RESP, + NITWORK_CONNECT_LOBBY_RESP, { [this](actionHandler &handler, const struct header_s &header) { handleBody(handler, header); @@ -237,7 +237,7 @@ namespace Nitwork { }, }, { - INIT, + NITWORK_INIT, { [this](actionHandler &handler, const struct header_s &header) { handleBody(handler, header); @@ -248,7 +248,7 @@ namespace Nitwork { }, }, { - START_WAVE, + NITWORK_START_WAVE, { [this](actionHandler &handler, const struct header_s &header) { handleBody(handler, header); @@ -259,7 +259,7 @@ namespace Nitwork { }, }, { - LIFE_UPDATE, + NITWORK_LIFE_UPDATE, { [this](actionHandler &handler, const struct header_s &header) { handleBody(handler, header); @@ -270,7 +270,7 @@ namespace Nitwork { } }, { - ENEMY_DEATH, + NITWORK_ENEMY_DEATH, { [this](actionHandler &handler, const struct header_s &header) { handleBody(handler, header); @@ -281,7 +281,7 @@ namespace Nitwork { } }, { - NEW_ENEMY, + NITWORK_NEW_ENEMY, { [this](actionHandler &handler, const struct header_s &header) { handleBody(handler, header); @@ -292,7 +292,7 @@ namespace Nitwork { } }, { - NEW_PLAYER, + NITWORK_NEW_PLAYER, { [this](actionHandler &handler, const struct header_s &header) { handleBody(handler, header); @@ -303,7 +303,7 @@ namespace Nitwork { } }, { - NEW_MISSILE, + NITWORK_NEW_MISSILE, { [this](actionHandler &handler, const struct header_s &header) { handleBody(handler, header); @@ -314,7 +314,7 @@ namespace Nitwork { } }, { - POSITION_RELATIVE_BROADCAST, + NITWORK_POSITION_RELATIVE_BROADCAST, { [this](actionHandler &handler, const struct header_s &header) { handleBody(handler, header); @@ -325,7 +325,7 @@ namespace Nitwork { }, }, { - POSITION_ABSOLUTE_BROADCAST, + NITWORK_POSITION_ABSOLUTE_BROADCAST, { [this](actionHandler &handler, const struct header_s &header) { handleBody(handler, header); @@ -336,7 +336,7 @@ namespace Nitwork { } }, { - PLAYER_DEATH, + NITWORK_PLAYER_DEATH, { [this](actionHandler &handler, const struct header_s &header) { handleBody(handler, header); @@ -347,7 +347,7 @@ namespace Nitwork { } }, { - MISSILE_DEATH, + NITWORK_MISSILE_DEATH, { [this](actionHandler &handler, const struct header_s &header) { handleBody(handler, header); @@ -358,7 +358,7 @@ namespace Nitwork { } }, { - LIST_LOBBY, + NITWORK_LIST_LOBBY, { [this](actionHandler &actionHandler, const struct header_s &header) { handleBody(actionHandler, header); @@ -369,7 +369,7 @@ namespace Nitwork { } }, { - CONNECT_MAIN_SERVER_RESP, + NITWORK_CONNECT_MAIN_SERVER_RESP, { [this](actionHandler &actionHandler, const struct header_s &header) { handleBody(actionHandler, header); @@ -380,7 +380,7 @@ namespace Nitwork { } }, { - END_GAME, + NITWORK_END_GAME, { [this](actionHandler &handler, const struct header_s &header) { handleBody(handler, header); @@ -396,79 +396,79 @@ namespace Nitwork { actionSender > _actionToSendHandlers = { { - CONNECT_LOBBY, + NITWORK_CONNECT_LOBBY, [this](Packet &packet) { sendData(packet); } }, { - INIT, + NITWORK_INIT, [this](Packet &packet) { sendData(packet); } }, { - READY, + NITWORK_READY, [this](Packet &packet) { sendData(packet); } }, { - POSITION_RELATIVE, + NITWORK_POSITION_RELATIVE, [this](Packet &packet) { sendData(packet); } }, { - POSITION_ABSOLUTE, + NITWORK_POSITION_ABSOLUTE, [this](Packet &packet) { sendData(packet); } }, { - NEW_MISSILE, + NITWORK_NEW_MISSILE, [this](Packet &packet) { sendData(packet); } }, { - LIFE_UPDATE, + NITWORK_LIFE_UPDATE, [this](Packet &packet) { sendData(packet); } }, { - ENEMY_DEATH, + NITWORK_ENEMY_DEATH, [this](Packet &packet) { sendData(packet); } }, { - PLAYER_DEATH, + NITWORK_PLAYER_DEATH, [this](Packet &packet) { sendData(packet); } }, { - CONNECT_MAIN_SERVER, + NITWORK_CONNECT_MAIN_SERVER, [this](Packet &packet) { sendData(packet); } }, { - LIST_LOBBY, + NITWORK_LIST_LOBBY, [this](Packet &packet) { sendData(packet); } }, { - CREATE_LOBBY, + NITWORK_CREATE_LOBBY, [this](Packet &packet) { sendData(packet); } }, { - DISCONNECT_LOBBY, + NITWORK_DISCONNECT_LOBBY, [this](Packet &packet) { sendData(packet); } diff --git a/src/Nitwork/NitworkMainServer.cpp b/src/Nitwork/NitworkMainServer.cpp index 6d0cd096..c72e20d8 100644 --- a/src/Nitwork/NitworkMainServer.cpp +++ b/src/Nitwork/NitworkMainServer.cpp @@ -62,7 +62,7 @@ namespace Nitwork { .id = 0, .nb_action = 1, .magick2 = HEADER_CODE2}, - .action = {.magick = CONNECT_MAIN_SERVER_RESP}, + .action = {.magick = NITWORK_CONNECT_MAIN_SERVER_RESP}, .msg = {.magick = MAGICK_CONNECT_MAIN_SERVER_RESP} }; @@ -155,7 +155,7 @@ namespace Nitwork { for (std::size_t i = 0; i < lobbies.size(); i++) { msg.actionLobby[i] = { - .action = {.magick = LIST_LOBBY}, + .action = {.magick = NITWORK_LIST_LOBBY}, .lobby = {.magick = MAGICK_LIST_LOBBY, .lobby = lobbies[i]} }; } diff --git a/src/Nitwork/NitworkMainServer.hpp b/src/Nitwork/NitworkMainServer.hpp index ea18c7de..6ce9e2ee 100644 --- a/src/Nitwork/NitworkMainServer.hpp +++ b/src/Nitwork/NitworkMainServer.hpp @@ -156,7 +156,7 @@ namespace Nitwork { std::map> _actionsHandlers = { { - CONNECT_MAIN_SERVER, + NITWORK_CONNECT_MAIN_SERVER, { [this](actionHandler &actionHandler, const struct header_s &header) { handleBody(actionHandler, header); @@ -167,7 +167,7 @@ namespace Nitwork { } }, { - LIST_LOBBY, + NITWORK_LIST_LOBBY, { [this](actionHandler &actionHandler, const struct header_s &header) { handleBody(actionHandler, header); @@ -178,7 +178,7 @@ namespace Nitwork { } }, { - CREATE_LOBBY, + NITWORK_CREATE_LOBBY, { [this](actionHandler &actionHandler, const struct header_s &header) { handleBody(actionHandler, header); @@ -189,7 +189,7 @@ namespace Nitwork { } }, { - INFO_LOBBY, + NITWORK_INFO_LOBBY, { [this](actionHandler &actionHandler, const struct header_s &header) { handleBody(actionHandler, header); @@ -202,13 +202,13 @@ namespace Nitwork { }; std::map _actionToSendHandlers = { { - LIST_LOBBY, + NITWORK_LIST_LOBBY, [this](Packet &packet) { sendData(packet); } }, { - CONNECT_MAIN_SERVER_RESP, + NITWORK_CONNECT_MAIN_SERVER_RESP, [this](Packet &packet) { sendData(packet); } diff --git a/src/Nitwork/NitworkServer.cpp b/src/Nitwork/NitworkServer.cpp index f9cc9f9e..2875fa39 100644 --- a/src/Nitwork/NitworkServer.cpp +++ b/src/Nitwork/NitworkServer.cpp @@ -83,11 +83,12 @@ namespace Nitwork { { // NOLINTBEGIN(cppcoreguidelines-pro-type-reinterpret-cast, // cppcoreguidelines-pro-bounds-pointer-arithmetic) - auto *action = reinterpret_cast(_receiveBuffer.data()); + auto *actionPtr = reinterpret_cast(_receiveBuffer.data()); // NOLINTEND(cppcoreguidelines-pro-type-reinterpret-cast, // cppcoreguidelines-pro-bounds-pointer-arithmetic) - auto it = _actionsHandlers.find(action->magick); + auto action = *actionPtr; + auto it = _actionsHandlers.find(action.magick); std::memmove( _receiveBuffer.data(), _receiveBuffer.data() + sizeof(struct action_s), @@ -108,7 +109,7 @@ namespace Nitwork { Logger::debug( "Received packet from " + endpoint.address().to_string() + ":" + std::to_string(endpoint.port()) + " with id " + std::to_string(header.id) + " and action of type " - + std::to_string(action->magick)); + + std::to_string(action.magick)); it->second.first(it->second.second, header); } @@ -162,7 +163,7 @@ namespace Nitwork { } struct packetCreatePlayer_s packetMsgCreatePlayer = { .header = {0, 0, 0, 0, 1, 0}, - .action = {.magick = NEW_PLAYER}, + .action = {.magick = NITWORK_NEW_PLAYER}, .msg = { .magick = MAGICK_NEW_PLAYER, .playerId = allieId, @@ -187,6 +188,7 @@ namespace Nitwork { Logger::error("Error: magick not matching"); return; } + Logger::error("magick connect lobby = " + std::to_string(msgData.magick) + " (" + MAGICK_CONNECT_LOBBY + ")"); if (_endpoints.size() >= _serverInfos.maxNbPlayer) { Logger::error("Too many clients, can't add an other one"); canConnect = false; @@ -217,7 +219,7 @@ namespace Nitwork { struct packetCreatePlayer_s packetMsgCreatePlayer = { .header = {0, 0, 0, 0, 1, 0}, - .action = {.magick = NEW_PLAYER}, + .action = {.magick = NITWORK_NEW_PLAYER}, .msg = { .magick = MAGICK_NEW_PLAYER, .playerId = playerId, @@ -285,7 +287,7 @@ namespace Nitwork { .id = 0, .nb_action = 1, .magick2 = HEADER_CODE2}, - .action = {.magick = POSITION_RELATIVE_BROADCAST}, + .action = {.magick = NITWORK_POSITION_RELATIVE_BROADCAST}, .msg = { .magick = MAGICK_POSITION_RELATIVE_BROADCAST, .pos = {.x = pos.x, .y = pos.y}, @@ -318,7 +320,7 @@ namespace Nitwork { std::lock_guard lock(_receivedPacketsIdsMutex); struct packetConnectLobbyResp_s packetConnectLobbyResp = { .header = {0, 0, 0, 0, 1, 0}, - .action = {.magick = CONNECT_LOBBY_RESP}, + .action = {.magick = NITWORK_CONNECT_LOBBY_RESP}, .msg = {.magick = MAGICK_CONNECT_LOBBY_RESP, .isOk = static_cast(canConnect)} }; Packet packet( @@ -333,7 +335,7 @@ namespace Nitwork { std::lock_guard lock(_receivedPacketsIdsMutex); struct packetInfoLobby_s packetInfo = { .header = {0, 0, 0, 0, 1, 0}, - .action = {.magick = INFO_LOBBY}, + .action = {.magick = NITWORK_INFO_LOBBY}, .msg = { .magick = MAGICK_INFO_LOBBY, .name = {}, @@ -359,7 +361,7 @@ namespace Nitwork { std::lock_guard lock(_receivedPacketsIdsMutex); struct packetCreatePlayer_s packetCreatePlayer = { .header = {0, 0, 0, 0, 1, 0}, - .action = {.magick = NEW_PLAYER}, + .action = {.magick = NITWORK_NEW_PLAYER}, .msg = playerMsg }; Packet packet( @@ -375,7 +377,7 @@ namespace Nitwork { std::lock_guard lock(_receivedPacketsIdsMutex); struct packetMsgStartWave_s packetMsgStartWave = { .header = {0, 0, 0, 0, 1, 0}, - .action = {.magick = START_WAVE}, + .action = {.magick = NITWORK_START_WAVE}, .msgStartWave = {.magick = MAGICK_START_WAVE, .waveId = waveId} }; Packet packet( @@ -392,7 +394,7 @@ namespace Nitwork { std::lock_guard lock(_receivedPacketsIdsMutex); struct packetLifeUpdate_s packetLifeUpdate = { .header = {0, 0, 0, 0, 1, 0}, - .action = {.magick = LIFE_UPDATE}, + .action = {.magick = NITWORK_LIFE_UPDATE}, .msgLifeUpdate = {.magick = MAGICK_LIFE_UPDATE, .playerId = playerId, .life = life} }; Packet packet( @@ -407,7 +409,7 @@ namespace Nitwork { std::lock_guard lock(_receivedPacketsIdsMutex); struct packetEnemyDeath_s packetEnemyDeath = { .header = {0, 0, 0, 0, 1, 0}, - .action = {.magick = ENEMY_DEATH}, + .action = {.magick = NITWORK_ENEMY_DEATH}, .msgEnemyDeath = {.magick = MAGICK_ENEMY_DEATH, .enemyId = {.id = enemyId}} }; Packet packet( @@ -423,7 +425,7 @@ namespace Nitwork { std::lock_guard lock(_receivedPacketsIdsMutex); struct packetNewEnemy_s packetNewEnemy = { .header = {0, 0, 0, 0, 1, 0}, - .action = {.magick = NEW_ENEMY}, + .action = {.magick = NITWORK_NEW_ENEMY}, .msg = {.magick = MAGICK_NEW_ENEMY, .enemyInfos = enemyInfos} }; Packet packet( @@ -438,7 +440,7 @@ namespace Nitwork { std::lock_guard lock(_receivedPacketsIdsMutex); struct packetNewBullet_s packetNewBullet = { .header = {0, 0, 0, 0, 1, 0}, - .action = {.magick = NEW_MISSILE}, + .action = {.magick = NITWORK_NEW_MISSILE}, .msg = msg }; Packet packet( @@ -454,7 +456,7 @@ namespace Nitwork { std::lock_guard lock(_receivedPacketsIdsMutex); struct packetPositionAbsoluteBroadcast_s packetPosAbsoluteBroadcast = { .header = {0, 0, 0, 0, 1, 0}, - .action = {.magick = POSITION_ABSOLUTE_BROADCAST}, + .action = {.magick = NITWORK_POSITION_ABSOLUTE_BROADCAST}, .msg = { .magick = MAGICK_POSITION_ABSOLUTE_BROADCAST, .pos = {.x = pos.x, .y = pos.y}, @@ -471,7 +473,7 @@ namespace Nitwork { std::lock_guard lock(_receivedPacketsIdsMutex); struct packetPlayerDeath_s packetPlayerDeath = { .header = {0, 0, 0, 0, 1, 0}, - .action = {.magick = PLAYER_DEATH}, + .action = {.magick = NITWORK_PLAYER_DEATH}, .msg = {.magick = MAGICK_PLAYER_DEATH, .playerId = id} }; Packet packet( @@ -485,7 +487,7 @@ namespace Nitwork { std::lock_guard lock(_receivedPacketsIdsMutex); struct packetPlayerDeath_s packetPlayerDeath = { .header = {0, 0, 0, 0, 1, 0}, - .action = {.magick = PLAYER_DEATH}, + .action = {.magick = NITWORK_PLAYER_DEATH}, .msg = {.magick = MAGICK_PLAYER_DEATH, .playerId = id} }; Packet packet( @@ -502,7 +504,7 @@ namespace Nitwork { std::lock_guard lock(_receivedPacketsIdsMutex); struct packetCreatePlayer_s packetCreatePlayer = { .header = {0, 0, 0, 0, 1, 0}, - .action = {.magick = NEW_PLAYER}, + .action = {.magick = NITWORK_NEW_PLAYER}, .msg = playerMsg }; Packet packet( @@ -519,7 +521,7 @@ namespace Nitwork { .header = {0, 0, 0, 0, 1, 0}, .action = { - .magick = MISSILE_DEATH, + .magick = NITWORK_MISSILE_DEATH, }, .msgMissileDeath = { @@ -537,7 +539,7 @@ namespace Nitwork { std::lock_guard lock(_receivedPacketsIdsMutex); struct packetEndGame_s packetEndGame = { .header = {0, 0, 0, 0, 1, 0}, - .action = {.magick = END_GAME}, + .action = {.magick = NITWORK_END_GAME}, .msg = {.magick = MAGICK_END_GAME} }; Packet packet( diff --git a/src/Nitwork/NitworkServer.hpp b/src/Nitwork/NitworkServer.hpp index 54792a93..39641a61 100644 --- a/src/Nitwork/NitworkServer.hpp +++ b/src/Nitwork/NitworkServer.hpp @@ -271,77 +271,77 @@ namespace Nitwork { * @brief a map that will be used to handle the actions, in order to receive them */ std::map> _actionsHandlers = { - {CONNECT_LOBBY, + {NITWORK_CONNECT_LOBBY, {[this](actionHandler &actionHandler, const struct header_s &header) { handleBody(actionHandler, header); }, [this](std::any &msg, boost::asio::ip::udp::endpoint &endpoint) { handleConnectLobbyMsg(msg, endpoint); }}}, - {INIT, + {NITWORK_INIT, {[this](actionHandler &actionHandler, const struct header_s &header) { handleBody(actionHandler, header); }, [this](std::any &msg, boost::asio::ip::udp::endpoint &endpoint) { handleInitMsg(msg, endpoint); }}}, - {READY, + {NITWORK_READY, {[this](actionHandler &actionHandler, const struct header_s &header) { handleBody(actionHandler, header); }, [this](std::any &msg, boost::asio::ip::udp::endpoint &endpoint) { handleReadyMsg(msg, endpoint); }}}, - {POSITION_RELATIVE, + {NITWORK_POSITION_RELATIVE, {[this](actionHandler &actionHandler, const struct header_s &header) { handleBody(actionHandler, header); }, [this](std::any &msg, boost::asio::ip::udp::endpoint &endpoint) { handleRelativePositionMsg(msg, endpoint); }}}, - {LIFE_UPDATE, + {NITWORK_LIFE_UPDATE, {[this](actionHandler &actionHandler, const struct header_s &header) { handleBody(actionHandler, header); }, [](std::any &msg, boost::asio::ip::udp::endpoint &endpoint) { Systems::handleLifeUpdateMsg(msg, endpoint); }}}, - {ENEMY_DEATH, + {NITWORK_ENEMY_DEATH, {[this](actionHandler &actionHandler, const struct header_s &header) { handleBody(actionHandler, header); }, [](std::any &msg, boost::asio::ip::udp::endpoint &endpoint) { Systems::handleClientEnemyDeath(msg, endpoint); }}}, - {NEW_MISSILE, + {NITWORK_NEW_MISSILE, {[this](actionHandler &actionHandler, const struct header_s &header) { handleBody(actionHandler, header); }, [](std::any &msg, boost::asio::ip::udp::endpoint &endpoint) { Systems::receiveNewBulletMsg(msg, endpoint); }}}, - {POSITION_ABSOLUTE, + {NITWORK_POSITION_ABSOLUTE, {[this](actionHandler &actionHandler, const struct header_s &header) { handleBody(actionHandler, header); }, [](std::any &msg, boost::asio::ip::udp::endpoint &endpoint) { Systems::receiveAbsolutePositionMsg(msg, endpoint); }}}, - {PLAYER_DEATH, + {NITWORK_PLAYER_DEATH, {[this](actionHandler &actionHandler, const struct header_s &header) { handleBody(actionHandler, header); }, [](std::any &msg, boost::asio::ip::udp::endpoint &endpoint) { Systems::receivePlayerDeathMsg(msg, endpoint); }}}, - {MISSILE_DEATH, + {NITWORK_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); }}}, - {DISCONNECT_LOBBY, + {NITWORK_DISCONNECT_LOBBY, {[this](actionHandler &actionHandler, const struct header_s &header) { handleBody(actionHandler, header); }, @@ -353,58 +353,58 @@ namespace Nitwork { * @brief a map that will be used to handle the actions, in order to send them */ std::map _actionToSendHandlers = { - {CONNECT_LOBBY_RESP, + {NITWORK_CONNECT_LOBBY_RESP, [this](Packet &packet) { sendData(packet); } }, - {INIT, + {NITWORK_INIT, [this](Packet &packet) { sendData(packet); } }, - {LIFE_UPDATE, + {NITWORK_LIFE_UPDATE, [this](Packet &packet) { sendData(packet); } }, - {START_WAVE, + {NITWORK_START_WAVE, [this](Packet &packet) { sendData(packet); } }, - {ENEMY_DEATH, + {NITWORK_ENEMY_DEATH, [this](Packet &packet) { sendData(packet); } }, - {NEW_ENEMY, + {NITWORK_NEW_ENEMY, [this](Packet &packet) { sendData(packet); } }, - {NEW_MISSILE, + {NITWORK_NEW_MISSILE, [this](Packet &packet) { sendData(packet); } }, - {NEW_PLAYER, + {NITWORK_NEW_PLAYER, [this](Packet &packet) { sendData(packet); } }, - {POSITION_RELATIVE_BROADCAST, + {NITWORK_POSITION_RELATIVE_BROADCAST, [this](Packet &packet) { sendData(packet); } }, - {POSITION_ABSOLUTE_BROADCAST, + {NITWORK_POSITION_ABSOLUTE_BROADCAST, [this](Packet &packet) { sendData(packet); } }, - {PLAYER_DEATH, + {NITWORK_PLAYER_DEATH, [this](Packet &packet) { sendData(packet); } }, - {MISSILE_DEATH, + {NITWORK_MISSILE_DEATH, [this](Packet &packet) { sendData(packet); } }, - {INFO_LOBBY, [this](Packet &packet) { + {NITWORK_INFO_LOBBY, [this](Packet &packet) { sendData(packet); }}, - {END_GAME, + {NITWORK_END_GAME, [this](Packet &packet) { sendData(packet); }}, diff --git a/src/init.cpp b/src/init.cpp index ba1f5ab8..cda2edbc 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -57,13 +57,11 @@ void initScenes() auto selectLobby = enumListTosizet( {SystemManagers::MENU_SYSTEMS, SystemManagers::NETWORK_MENU, - SystemManagers::CLIENTNETWORK, SystemManagers::ECSSYSTEMS, SystemManagers::GRAPHICS}); auto createLobby = enumListTosizet( {SystemManagers::MENU_SYSTEMS, SystemManagers::NETWORK_CREATE_LOBBY, - SystemManagers::CLIENTNETWORK, SystemManagers::ECSSYSTEMS, SystemManagers::GRAPHICS}); auto mainScene = enumListTosizet(