diff options
Diffstat (limited to 'src/net.h')
| -rw-r--r-- | src/net.h | 23 |
1 files changed, 9 insertions, 14 deletions
@@ -5,32 +5,27 @@ #include "player.h" #include "hand.h" -/* - * Packet format: - * first byte: msg_type_t - * second byte: packet length - * followed by payload - */ - -// Some fixed packet indizes (to improve readability) -#define INDEX_TYPE 0 -#define INDEX_LEN 1 -#define INDEX_PAYLOAD 2 +// Offsets within the receive buffer to easily access the data fields of the received message +#define NET_MSG_OFFSET_TYPE 0 +#define NET_MSG_OFFSET_PAYLOAD_LENGTH 1 +#define NET_MSG_OFFSET_PAYLOAD 2 typedef enum { - // Specify message type identifier here + // Specify message type identifiers here msg_type_hello = 0x0, msg_type_start_game = 0x1, msg_type_deal_cards = 0x2 } msg_type_t; +// Header format typedef struct { uint8_t type; uint8_t payload_length; } msg_header_t; +// Message format typedef struct { msg_header_t hdr; @@ -43,11 +38,11 @@ int server_start(const char* port); int* server_get_players(int serversock, const uint8_t count); void server_start_game(int* clients, const uint8_t clientcount, const player_list* players); void server_deal_cards(int sock, const hand h); -void* server_recv(int sock, uint8_t wanted); +void* server_recv(int sock, msg_type_t wanted); // Client side functions int client_connect_server(const char* host, const char* port); void client_hello(int sock, const char* username); -void* client_recv(int sock, uint8_t wanted); +void* client_recv(int sock, msg_type_t wanted); #endif // OXEN_NET_H |
