4 os.put(
static_cast<char>(message.
type));
6 switch (message.
type) {
8 os.write(
reinterpret_cast<const char*
>(&message.
msg.
cli_id),
sizeof(message.
msg.
cli_id));
13 os.write(
reinterpret_cast<const char*
>(&message.
msg.
cli_id),
sizeof(message.
msg.
cli_id));
17 os.write(
reinterpret_cast<const char*
>(&message.
id),
sizeof(message.
id));
23 os.write(
reinterpret_cast<const char*
>(&message.
id),
sizeof(message.
id));
27 os.write(
reinterpret_cast<const char*
>(&message.
id),
sizeof(message.
id));
34 os.write(
reinterpret_cast<const char*
>(&message.
id),
sizeof(message.
id));
38 os.write(
reinterpret_cast<const char*
>(&message.
id),
sizeof(message.
id));
42 os.write(
reinterpret_cast<const char*
>(&message.
msg.
status),
sizeof(message.
msg.
status));
58 switch (message.
type) {
70 is.read(
reinterpret_cast<char*
>(&message.
id),
sizeof(message.
id));
76 is.read(
reinterpret_cast<char*
>(&message.
id),
sizeof(message.
id));
80 is.read(
reinterpret_cast<char*
>(&message.
id),
sizeof(message.
id));
87 is.read(
reinterpret_cast<char*
>(&message.
id),
sizeof(message.
id));
91 is.read(
reinterpret_cast<char*
>(&message.
id),
sizeof(message.
id));
GameMessage deserialize(std::istringstream &is)
Deserializes a GameMessage object from a binary stream.
void serialize(const GameMessage &message, std::ostringstream &os)
Serializes a GameMessage object into a binary stream.
messageType
Enum representing the different types of game messages.
@ P_SHOOT
Represents a player shooting event.
@ P_CONNECT
Represents a connecting player event.
@ P_ERROR
Represents an error occurred.
@ P_DAMAGE
Represents a damage event.
@ P_KILL
Represents a kill event.
@ P_STATUS
Represents a status event.
@ P_SPAWN
Represents a spawn event.
@ P_MOVE
Represents a movement event.
@ P_DISCONNECT
Represents a disconnecting player event.
A structure representing a game message.
messageType type
The type of message (e.g., SPAWN, MOVE, etc.).
messageInfo msg
Additional information about the event (status, asset ID, and coordinates).
std::size_t id
The unique identifier for the entity or object involved in the event.
uint8_t status
Status of the event (e.g., success or failure).
uint32_t cli_id
Id of the player's client.
coord coords
Coordinates associated with the event, such as the position of an entity.
char username[9]
Username of player connecting.
int asset_id
ID representing the game asset related to the event (e.g., entity or object).