Skip to content

Commit ae1a138

Browse files
committed
refactor: simplify user update commands and improve packet sending in ClientManager
1 parent cc407bf commit ae1a138

File tree

4 files changed

+5
-9
lines changed

4 files changed

+5
-9
lines changed

Flakkari/Protocol/Commands.hpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,8 @@ enum class CommandId : uint8_t {
195195
REQ_ENTITY_SHOOT = 28, // Server -> Client [Shoot entity]: (id)(component (position, rotation, velocity, etc))
196196
REP_ENTITY_SHOOT = 29, // Client -> Server [Entity shot]: ()
197197
// 30 - 39: User
198-
REQ_USER_UPDATE = 30, // Client -> Server [Update user]: (event_id, state)
199-
REP_USER_UPDATE = 31, // Server -> Client [User updated]: ()
200-
REQ_USER_UPDATES = 32, // Client -> Server [Update user multi-events]: (event_id, state|event_id, float)
201-
REP_USER_UPDATES = 33, // Server -> Client [User updated]: ()
198+
REQ_USER_UPDATES = 30, // Client -> Server [Update user multi-events]: (event_id, state|event_id, float)
199+
REP_USER_UPDATES = 31, // Server -> Client [User updated]: ()
202200
// 40 - 49: Chat
203201
// 50 - 59: Matchmaking
204202
REQ_CREATE_ROOM = 50, // Client -> Server [Create room]: (user_id)
@@ -244,8 +242,6 @@ class Commands final {
244242
case CommandId::REP_ENTITY_MOVED: return "REP_ENTITY_MOVED";
245243
case CommandId::REQ_ENTITY_SHOOT: return "REQ_ENTITY_SHOOT";
246244
case CommandId::REP_ENTITY_SHOOT: return "REP_ENTITY_SHOOT";
247-
case CommandId::REQ_USER_UPDATE: return "REQ_USER_UPDATE";
248-
case CommandId::REP_USER_UPDATE: return "REP_USER_UPDATE";
249245
case CommandId::REQ_USER_UPDATES: return "REQ_USER_UPDATES";
250246
case CommandId::REP_USER_UPDATES: return "REP_USER_UPDATES";
251247
case CommandId::REQ_CREATE_ROOM: return "REQ_CREATE_ROOM";

Flakkari/Protocol/Header.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ LPL_PACKED_START
8484
* 0 1 2 3
8585
* 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
8686
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
87-
* |Priority|Api V.| CommandId | ContentLength |
87+
* |Priority| Api V.| CommandId | ContentLength |
8888
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
8989
* | SequenceNumber |
9090
* | |

Flakkari/Protocol/Packet.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ template <typename Id> struct Packet {
4747
{
4848
std::string str = "Packet<Id: " + Commands::command_to_string(header._commandId) +
4949
", ContentLength: " + std::to_string(int(header._contentLength)) +
50-
", SequenceNumber: " + std::to_string(int(header._sequenceNumber)) +
50+
", SequenceNumber: " + std::to_string(long(header._sequenceNumber)) +
5151
", Payload: " + std::string((const char *) payload.data(), payload.size()) + ">";
5252
return str;
5353
}

Flakkari/Server/Client/ClientManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ void ClientManager::checkInactiveClients()
8484

8585
void ClientManager::sendPacketToClient(const std::shared_ptr<Network::Address> &client, const Network::Buffer &packet)
8686
{
87-
std::thread([this, client, packet] { _socket->sendTo(client, packet); }).detach();
87+
_socket->sendTo(client, packet);
8888
}
8989

9090
void ClientManager::sendPacketToAllClients(const Network::Buffer &packet)

0 commit comments

Comments
 (0)