Skip to content

Commit

Permalink
refactor: simplify user update commands and improve packet sending in…
Browse files Browse the repository at this point in the history
… ClientManager
  • Loading branch information
MasterLaplace committed Nov 23, 2024
1 parent cc407bf commit ae1a138
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 9 deletions.
8 changes: 2 additions & 6 deletions Flakkari/Protocol/Commands.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion Flakkari/Protocol/Header.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
* | |
Expand Down
2 changes: 1 addition & 1 deletion Flakkari/Protocol/Packet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ template <typename Id> struct Packet {
{
std::string str = "Packet<Id: " + Commands::command_to_string(header._commandId) +
", ContentLength: " + std::to_string(int(header._contentLength)) +
", SequenceNumber: " + std::to_string(int(header._sequenceNumber)) +
", SequenceNumber: " + std::to_string(long(header._sequenceNumber)) +
", Payload: " + std::string((const char *) payload.data(), payload.size()) + ">";
return str;
}
Expand Down
2 changes: 1 addition & 1 deletion Flakkari/Server/Client/ClientManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void ClientManager::checkInactiveClients()

void ClientManager::sendPacketToClient(const std::shared_ptr<Network::Address> &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)
Expand Down

0 comments on commit ae1a138

Please sign in to comment.