diff --git a/src/Client/Systems/Menus/Menu/ButtonCallbacks.cpp b/src/Client/Systems/Menus/Menu/ButtonCallbacks.cpp index 61fb16c2..457649f4 100644 --- a/src/Client/Systems/Menus/Menu/ButtonCallbacks.cpp +++ b/src/Client/Systems/Menus/Menu/ButtonCallbacks.cpp @@ -158,6 +158,7 @@ namespace Menu { auto idsButton = Registry::getInstance().getEntitiesByComponents({typeid(Types::Button)}); auto arrButton = Registry::getInstance().getComponents(); + Logger::error("!!!!!!!!!!!sendReadyPacket!!!!!!"); Nitwork::NitworkClient::getInstance().addReadyMsg(); for (auto &id : idsButton) { Registry::getInstance().removeEntity(id); diff --git a/src/Client/Systems/Menus/Menu/MenuSystems.cpp b/src/Client/Systems/Menus/Menu/MenuSystems.cpp index 174c96e7..93a7c1c6 100644 --- a/src/Client/Systems/Menus/Menu/MenuSystems.cpp +++ b/src/Client/Systems/Menus/Menu/MenuSystems.cpp @@ -230,13 +230,28 @@ namespace Systems { Json::getInstance().getDatasFromList(jsonData)); } + static void preloadTexture() + { + std::vector textures = Json::getInstance().getDatasByKey( + {ResourcesManager::getPathByJsonType(JsonType::ENEMIES), + ResourcesManager::getPathByJsonType(JsonType::DEFAULT_PARALLAX), + ResourcesManager::getPathByJsonType(JsonType::DEFAULT_PLAYER)}, + "spritePath"); + for (auto elem : textures) { + std::string::iterator end_pos = std::remove(elem.begin(), elem.end(), '"'); + elem.erase(end_pos, elem.end()); + Raylib::TextureManager::getInstance().preloadTexture(elem); + } + } + void initSceneGame(std::size_t managerId, std::size_t systemId) { if (Scene::SceneManager::getInstance().getCurrentScene() != GAME) { return; } try { - Parallax::initParalax(); +// Parallax::initParalax(); + preloadTexture(); initHud(); } catch (std::runtime_error &err) { Logger::info(err.what()); diff --git a/src/Game/CreateMissiles.cpp b/src/Game/CreateMissiles.cpp index 656e8879..a629fd3e 100644 --- a/src/Game/CreateMissiles.cpp +++ b/src/Game/CreateMissiles.cpp @@ -86,7 +86,7 @@ namespace Systems { const std::string bulletPath = json.getDataFromJson(bulletData, "spritePath"); Types::Rect spriteRect = json.getDataFromJson(bulletData, "spriteRect"); Types::SpriteDatas - bulletDatas(bulletPath, collisionRect.width, collisionRect.height, DEFAULTLAYER, 0); + bulletDatas(bulletPath, collisionRect.width, collisionRect.height, FRONTLAYER, 0); Registry::getInstance().getComponents().insertBack(bulletDatas); Registry::getInstance().getComponents().insertBack(spriteRect); @@ -101,15 +101,15 @@ namespace Systems { std::size_t createPlayerMissile(Types::Position pos, Types::Missiles &typeOfMissile) { + Logger::fatal("Create missile"); if (typeOfMissile.type >= MAX_MISSILE_TYPE || typeOfMissile.type < 0) { throw std::runtime_error("Unknown missile type"); } - Json &json = Json::getInstance(); - std::size_t id = Registry::getInstance().addEntity(); - nlohmann::json bulletData = json.getJsonObjectById( - ResourcesManager::getPathByJsonType(JsonType::BULLETS), - getMissileIdFromType(typeOfMissile.type), - "bullets"); + Logger::fatal("Create missile2"); + Json &json = Json::getInstance(); + std::size_t id = Registry::getInstance().addEntity(); + nlohmann::json bulletData = + json.getJsonObjectById(ResourcesManager::getPathByJsonType(JsonType::BULLETS), getMissileIdFromType(typeOfMissile.type), "bullets"); Types::CollisionRect collisionRect = json.getDataFromJson(bulletData, "collisionRect"); Types::Velocity velocity = json.getDataFromJson(bulletData, "velocity"); @@ -126,6 +126,7 @@ namespace Systems { Registry::getInstance().getComponents().insertBack(playerAlliesComp); addPhysicsToEntity(bulletData, pos); + Logger::fatal("type of missile = " + std::to_string(typeOfMissile.type) + " pos = " + std::to_string(pos.x) + " " + std::to_string(pos.y)); Registry::getInstance().getComponents().insertBack(pos); Registry::getInstance().getComponents().insertBack(collisionRect); Registry::getInstance().getComponents().insertBack(missileType); diff --git a/src/Game/GameSystems.cpp b/src/Game/GameSystems.cpp index f7612007..7441255b 100644 --- a/src/Game/GameSystems.cpp +++ b/src/Game/GameSystems.cpp @@ -116,10 +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); } } @@ -148,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 06c33213..282f25a9 100644 --- a/src/Nitwork/ANitwork.cpp +++ b/src/Nitwork/ANitwork.cpp @@ -245,8 +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/MessageTypes.h b/src/Nitwork/MessageTypes.h index 8ae0e3c3..7b6db340 100644 --- a/src/Nitwork/MessageTypes.h +++ b/src/Nitwork/MessageTypes.h @@ -27,9 +27,9 @@ enum enemy_type_e { enum missileTypes_e { CLASSIC = 0, - FAST, - BOUNCE, - PERFORANT, + FAST = 1, + BOUNCE = 2, + PERFORANT = 3, MAX_MISSILE_TYPE }; 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 c1136c60..f158b5be 100644 --- a/src/Nitwork/NitworkClient.cpp +++ b/src/Nitwork/NitworkClient.cpp @@ -149,10 +149,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(NITWORK_DISCONNECT_LOBBY) + " " + std::to_string(MAGICK_DISCONNECT_LOBBY)); Packet packet( packetDisconnectLobby.action.magick, std::make_any(packetDisconnectLobby), @@ -168,10 +169,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(NITWORK_INIT) + " " + std::to_string(MAGICK_INIT)); Packet packet( packetMsgInit.action.magick, std::make_any(packetMsgInit), @@ -184,9 +186,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(NITWORK_READY) + " " + std::to_string(MAGICK_READY)); Packet packet( packetMsgReady.action.magick, std::make_any(packetMsgReady), @@ -201,7 +204,7 @@ namespace Nitwork { .header = {0, 0, 0, 0, 1, 0}, .action = { - .magick = POSITION_RELATIVE, + .magick = NITWORK_POSITION_RELATIVE, }, .msg = { @@ -225,7 +228,7 @@ namespace Nitwork { .header = {0, 0, 0, 0, 1, 0}, .action = { - .magick = NEW_MISSILE, + .magick = NITWORK_NEW_MISSILE, }, .msg = { @@ -250,7 +253,7 @@ namespace Nitwork { .header = {0, 0, 0, 0, 1, 0}, .action = { - .magick = POSITION_ABSOLUTE, + .magick = NITWORK_POSITION_ABSOLUTE, }, .msg = { @@ -273,7 +276,7 @@ namespace Nitwork { .header = {0, 0, 0, 0, 1, 0}, .action = { - .magick = LIFE_UPDATE, + .magick = NITWORK_LIFE_UPDATE, }, .msgLifeUpdate = { @@ -282,6 +285,7 @@ namespace Nitwork { .life = life, }, }; + Logger::error("------------------------------------ Sending life update msg: " + std::to_string(playerId) + " " + std::to_string(MAGICK_LIFE_UPDATE)); Packet packet( packetLifeUpdate.action.magick, std::make_any(packetLifeUpdate), @@ -297,7 +301,7 @@ namespace Nitwork { .header = {0, 0, 0, 0, 1, 0}, .action = { - .magick = ENEMY_DEATH, + .magick = NITWORK_ENEMY_DEATH, }, .msgEnemyDeath = { @@ -319,7 +323,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}, }; @@ -337,7 +341,7 @@ namespace Nitwork { .header = {0, 0, 0, 0, 1, 0}, .action = { - .magick = MISSILE_DEATH, + .magick = NITWORK_MISSILE_DEATH, }, .msgMissileDeath = { @@ -345,6 +349,7 @@ namespace Nitwork { .missileId = id, }, }; + 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), @@ -358,10 +363,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(NITWORK_LIST_LOBBY) + " " + std::to_string(MAGICK_REQUEST_LIST_LOBBY)); Packet packet( packetListLobby.action.magick, std::make_any(packetListLobby), @@ -379,7 +385,7 @@ namespace Nitwork { .header = {0, 0, 0, 0, 1, 0}, .action = { - .magick = CREATE_LOBBY, + .magick = NITWORK_CREATE_LOBBY, }, .msg = { .magick = MAGICK_CREATE_LOBBY, @@ -388,6 +394,7 @@ namespace Nitwork { .maxNbPlayer = maxNbPlayer, .ownerInfos = {.ip = "", .port = _mainServerEndpoint.port()}} }; + 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, @@ -409,10 +416,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(NITWORK_CONNECT_MAIN_SERVER) + " " + std::to_string(MAGICK_CONNECT_MAIN_SERVER)); Packet packet( packetConnectMainServer.action.magick, std::make_any(packetConnectMainServer), @@ -496,10 +504,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(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 f81c90ef..dc0659d5 100644 --- a/src/Nitwork/NitworkClient.hpp +++ b/src/Nitwork/NitworkClient.hpp @@ -239,7 +239,7 @@ namespace Nitwork { std::pair > _actionsHandlers = { { - CONNECT_LOBBY_RESP, + NITWORK_CONNECT_LOBBY_RESP, { [this](actionHandler &handler, const struct header_s &header) { handleBody(handler, header); @@ -250,7 +250,7 @@ namespace Nitwork { }, }, { - INIT, + NITWORK_INIT, { [this](actionHandler &handler, const struct header_s &header) { handleBody(handler, header); @@ -261,7 +261,7 @@ namespace Nitwork { }, }, { - START_WAVE, + NITWORK_START_WAVE, { [this](actionHandler &handler, const struct header_s &header) { handleBody(handler, header); @@ -272,7 +272,7 @@ namespace Nitwork { }, }, { - LIFE_UPDATE, + NITWORK_LIFE_UPDATE, { [this](actionHandler &handler, const struct header_s &header) { handleBody(handler, header); @@ -283,7 +283,7 @@ namespace Nitwork { } }, { - ENEMY_DEATH, + NITWORK_ENEMY_DEATH, { [this](actionHandler &handler, const struct header_s &header) { handleBody(handler, header); @@ -294,7 +294,7 @@ namespace Nitwork { } }, { - NEW_ENEMY, + NITWORK_NEW_ENEMY, { [this](actionHandler &handler, const struct header_s &header) { handleBody(handler, header); @@ -305,7 +305,7 @@ namespace Nitwork { } }, { - NEW_PLAYER, + NITWORK_NEW_PLAYER, { [this](actionHandler &handler, const struct header_s &header) { handleBody(handler, header); @@ -316,7 +316,7 @@ namespace Nitwork { } }, { - NEW_MISSILE, + NITWORK_NEW_MISSILE, { [this](actionHandler &handler, const struct header_s &header) { handleBody(handler, header); @@ -327,7 +327,7 @@ namespace Nitwork { } }, { - POSITION_RELATIVE_BROADCAST, + NITWORK_POSITION_RELATIVE_BROADCAST, { [this](actionHandler &handler, const struct header_s &header) { handleBody(handler, header); @@ -338,7 +338,7 @@ namespace Nitwork { }, }, { - POSITION_ABSOLUTE_BROADCAST, + NITWORK_POSITION_ABSOLUTE_BROADCAST, { [this](actionHandler &handler, const struct header_s &header) { handleBody(handler, header); @@ -349,7 +349,7 @@ namespace Nitwork { } }, { - PLAYER_DEATH, + NITWORK_PLAYER_DEATH, { [this](actionHandler &handler, const struct header_s &header) { handleBody(handler, header); @@ -360,7 +360,7 @@ namespace Nitwork { } }, { - MISSILE_DEATH, + NITWORK_MISSILE_DEATH, { [this](actionHandler &handler, const struct header_s &header) { handleBody(handler, header); @@ -371,7 +371,7 @@ namespace Nitwork { } }, { - LIST_LOBBY, + NITWORK_LIST_LOBBY, { [this](actionHandler &actionHandler, const struct header_s &header) { handleBody(actionHandler, header); @@ -382,7 +382,7 @@ namespace Nitwork { } }, { - CONNECT_MAIN_SERVER_RESP, + NITWORK_CONNECT_MAIN_SERVER_RESP, { [this](actionHandler &actionHandler, const struct header_s &header) { handleBody(actionHandler, header); @@ -393,7 +393,7 @@ namespace Nitwork { } }, { - END_GAME, + NITWORK_END_GAME, { [this](actionHandler &handler, const struct header_s &header) { handleBody(handler, header); @@ -409,79 +409,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 cc70aa6d..e707f94f 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; @@ -210,13 +212,14 @@ namespace Nitwork { Logger::error("Client already connected"); return; } + Logger::error("WTF WTF ICI"); _endpoints.emplace_back(endpoint); auto playerId = static_cast(_endpoints.size() - 1); auto &jsonInstance = Json::getInstance(); 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, @@ -246,7 +249,6 @@ namespace Nitwork { void NitworkServer::handleReadyMsg(const std::any & /* unused */, boost::asio::ip::udp::endpoint &endpoint) { - Logger::fatal("cacaprout"); if (_isGameStarted) { Logger::info("Game already started, connection refused"); return; @@ -263,9 +265,7 @@ namespace Nitwork { _isGameStarted = true; auto &director = Systems::SystemManagersDirector::getInstance(); std::lock_guard lock(director.mutex); - director.getSystemManager(static_cast(SystemManagers::GAME_LOGIC)) - .addSystem(Systems::waveHandler); // le sheeiiiiiitan VERIF - Logger::fatal("cacaprout"); + director.getSystemManager(static_cast(SystemManagers::GAME_LOGIC)).addSystem(Systems::waveHandler); } void @@ -285,7 +285,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 +318,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 +333,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 +359,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 +375,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 +392,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 +407,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 +423,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 +438,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 +454,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 +471,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 +485,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 +502,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 +519,7 @@ namespace Nitwork { .header = {0, 0, 0, 0, 1, 0}, .action = { - .magick = MISSILE_DEATH, + .magick = NITWORK_MISSILE_DEATH, }, .msgMissileDeath = { @@ -537,7 +537,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(packetEndGame.action.magick, std::make_any(packetEndGame)); diff --git a/src/Nitwork/NitworkServer.hpp b/src/Nitwork/NitworkServer.hpp index aed0dad8..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,59 +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/Server/Systems/Network/ServerNetwork.cpp b/src/Server/Systems/Network/ServerNetwork.cpp index fd94d528..8f835195 100644 --- a/src/Server/Systems/Network/ServerNetwork.cpp +++ b/src/Server/Systems/Network/ServerNetwork.cpp @@ -84,7 +84,7 @@ namespace Systems { Maths::addIntDecimals(msgNewBullet.pos.x), Maths::addIntDecimals(msgNewBullet.pos.y), }; - struct Types::Missiles missileType = {static_cast(msgNewBullet.missileType)}; + struct Types::Missiles missileType = {msgNewBullet.missileType}; auto id = Systems::createPlayerMissile(position, missileType); if (!arrMissiles.exist(id) || !arrHealth.exist(id)) { Logger::error("Error: missile not created"); diff --git a/src/init.cpp b/src/init.cpp index bf075f9d..aef876a2 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -65,14 +65,12 @@ void initScenes() }); auto selectLobby = enumListTosizet( {SystemManagers::MENU_SYSTEMS, - SystemManagers::NETWORK_MENU, - SystemManagers::CLIENTNETWORK, - SystemManagers::ECSSYSTEMS, - SystemManagers::GRAPHICS}); + SystemManagers::NETWORK_MENU, + SystemManagers::ECSSYSTEMS, + SystemManagers::GRAPHICS}); auto createLobby = enumListTosizet( {SystemManagers::MENU_SYSTEMS, SystemManagers::NETWORK_CREATE_LOBBY, - SystemManagers::CLIENTNETWORK, SystemManagers::ECSSYSTEMS, SystemManagers::GRAPHICS}); auto mainScene = enumListTosizet(