diff options
| author | Mario Kilies <MarioKilies@GMX.net> | 2011-01-24 11:15:56 +0100 |
|---|---|---|
| committer | Mario Kilies <MarioKilies@GMX.net> | 2011-01-24 11:15:56 +0100 |
| commit | 6820c635353b25f12401f8610c140c8608051ded (patch) | |
| tree | ee3e2c284a7bae7e91d58422602259df827a1504 /src/net/comm.h | |
| parent | 322ff55a41374e39731aa53dcf6028b09c7c39c9 (diff) | |
Source code refactoring. Moved net/client/server stuff to 'net' subfolder.
Diffstat (limited to 'src/net/comm.h')
| -rw-r--r-- | src/net/comm.h | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/net/comm.h b/src/net/comm.h new file mode 100644 index 0000000..03816c8 --- /dev/null +++ b/src/net/comm.h @@ -0,0 +1,43 @@ +#ifndef OXEN_NET_H +#define OXEN_NET_H + +#include <stdint.h> +#include <stdbool.h> + +// 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 identifiers here + msg_type_hello = 0x0, + msg_type_start_game = 0x1, + msg_type_deal_cards = 0x2, + msg_type_init_stacks = 0x3, + msg_type_selected_card = 0x4, + msg_type_selected_stack_c = 0x5, + msg_type_selected_stack_s = 0x6, + msg_type_initial_stack = 0x7 +} 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; + uint8_t *payload; +} msg_t; + +// generic network functions +bool net_recv(int sock, msg_type_t wanted); +bool net_send(int sock, const msg_type_t type, void* param); + +#endif // OXEN_NET_H |
