From ae1a1385517f85c515cd817dfb794e7585528318 Mon Sep 17 00:00:00 2001 From: MasterLaplace Date: Fri, 22 Nov 2024 23:13:34 -0500 Subject: [PATCH] refactor: simplify user update commands and improve packet sending in ClientManager --- Flakkari/Protocol/Commands.hpp | 8 ++------ Flakkari/Protocol/Header.hpp | 2 +- Flakkari/Protocol/Packet.hpp | 2 +- Flakkari/Server/Client/ClientManager.cpp | 2 +- 4 files changed, 5 insertions(+), 9 deletions(-) diff --git a/Flakkari/Protocol/Commands.hpp b/Flakkari/Protocol/Commands.hpp index d0a1f358..553dddc2 100644 --- a/Flakkari/Protocol/Commands.hpp +++ b/Flakkari/Protocol/Commands.hpp @@ -195,10 +195,8 @@ enum class CommandId : uint8_t { REQ_ENTITY_SHOOT = 28, // Server -> Client [Shoot entity]: (id)(component (position, rotation, velocity, etc)) REP_ENTITY_SHOOT = 29, // Client -> Server [Entity shot]: () // 30 - 39: User - REQ_USER_UPDATE = 30, // Client -> Server [Update user]: (event_id, state) - REP_USER_UPDATE = 31, // Server -> Client [User updated]: () - REQ_USER_UPDATES = 32, // Client -> Server [Update user multi-events]: (event_id, state|event_id, float) - REP_USER_UPDATES = 33, // Server -> Client [User updated]: () + REQ_USER_UPDATES = 30, // Client -> Server [Update user multi-events]: (event_id, state|event_id, float) + REP_USER_UPDATES = 31, // Server -> Client [User updated]: () // 40 - 49: Chat // 50 - 59: Matchmaking REQ_CREATE_ROOM = 50, // Client -> Server [Create room]: (user_id) @@ -244,8 +242,6 @@ class Commands final { case CommandId::REP_ENTITY_MOVED: return "REP_ENTITY_MOVED"; case CommandId::REQ_ENTITY_SHOOT: return "REQ_ENTITY_SHOOT"; case CommandId::REP_ENTITY_SHOOT: return "REP_ENTITY_SHOOT"; - case CommandId::REQ_USER_UPDATE: return "REQ_USER_UPDATE"; - case CommandId::REP_USER_UPDATE: return "REP_USER_UPDATE"; case CommandId::REQ_USER_UPDATES: return "REQ_USER_UPDATES"; case CommandId::REP_USER_UPDATES: return "REP_USER_UPDATES"; case CommandId::REQ_CREATE_ROOM: return "REQ_CREATE_ROOM"; diff --git a/Flakkari/Protocol/Header.hpp b/Flakkari/Protocol/Header.hpp index 8e31b937..e67212a5 100644 --- a/Flakkari/Protocol/Header.hpp +++ b/Flakkari/Protocol/Header.hpp @@ -84,7 +84,7 @@ LPL_PACKED_START * 0 1 2 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * |Priority|Api V.| CommandId | ContentLength | + * |Priority| Api V.| CommandId | ContentLength | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | SequenceNumber | * | | diff --git a/Flakkari/Protocol/Packet.hpp b/Flakkari/Protocol/Packet.hpp index 49ac8af7..7cca2bdd 100644 --- a/Flakkari/Protocol/Packet.hpp +++ b/Flakkari/Protocol/Packet.hpp @@ -47,7 +47,7 @@ template struct Packet { { std::string str = "Packet"; return str; } diff --git a/Flakkari/Server/Client/ClientManager.cpp b/Flakkari/Server/Client/ClientManager.cpp index 2ef131d5..9f7d5132 100644 --- a/Flakkari/Server/Client/ClientManager.cpp +++ b/Flakkari/Server/Client/ClientManager.cpp @@ -84,7 +84,7 @@ void ClientManager::checkInactiveClients() void ClientManager::sendPacketToClient(const std::shared_ptr &client, const Network::Buffer &packet) { - std::thread([this, client, packet] { _socket->sendTo(client, packet); }).detach(); + _socket->sendTo(client, packet); } void ClientManager::sendPacketToAllClients(const Network::Buffer &packet)