1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
#ifndef OXEN_NET_H
#define OXEN_NET_H
#include <stdint.h>
#include "player.h"
#include "hand.h"
#include "table_stacks.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_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 receive function
void* net_recv(int sock, msg_type_t wanted);
// Server side functions
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_t *h);
char* server_recv_hello(const uint8_t* payload, const uint8_t payload_len);
card* server_recv_selected_card(const uint8_t* payload, const uint8_t payload_len);
uint8_t* server_recv_selected_stack(const uint8_t* payload, const uint8_t payload_len);
void server_send_selected_stack(int* clients, const uint8_t clientcount, const uint8_t stackindex);
// Client side functions
int client_connect_server(const char* host, const char* port);
void client_hello(int sock, const char* username);
void client_selected_card(int sock, const card c);
void client_send_selected_stack(int sock, const uint8_t stackindex);
void* client_recv_player_list(const uint8_t* payload, const uint8_t data_len);
hand_t *client_recv_deal_cards(const uint8_t* payload, const uint8_t payload_len);
uint8_t* client_recv_selected_stack(const uint8_t* payload, const uint8_t payload_len);
#endif // OXEN_NET_H
|