summaryrefslogtreecommitdiff
path: root/src/net/comm.h
blob: f8715ac65c0c4fdd89440f4f5dbb5fec5108c22d (plain)
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
63
64
65
66
67
68
69
70
71
72
73
74
/*****************************************************************************
 *                          ___ __  __ ___ _ __                              *
 *                         / _ \\ \/ // _ \ '_ \                             *
 *                        | (_) |>  <|  __/ | | |                            *
 *                         \___//_/\_\\___|_| |_|                            *
 *                                                                           *
 *                             The card game                                 *
 *                                                                           *
 *  Copyright (C) 2011, Reiner Herrmann <reiner@reiner-h.de>                 *
 *                      Mario Kilies <MarioKilies@GMX.net>                   *
 *                                                                           *
 *  This program is free software; you can redistribute it and/or modify     *
 *  it under the terms of the GNU General Public License as published by     *
 *  the Free Software Foundation; either version 3 of the License, or        *
 *  (at your option) any later version.                                      *
 *                                                                           *
 *  This program is distributed in the hope that it will be useful,          *
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the             *
 *  GNU General Public License for more details.                             *
 *                                                                           *
 *  You should have received a copy of the GNU General Public License        *
 *  along with this program. If not, see <http://www.gnu.org/licenses/>.     *
 *                                                                           *
 *****************************************************************************/

#ifndef OXEN_NET_H
#define OXEN_NET_H

#include <stdint.h>
#include <stdbool.h>

// Specifies the maximum payload length in bytes
#define NET_MSG_MAX_PAYLOAD_LENGTH	255

// 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_c		= 0x0,
	msg_type_hello_s		= 0x1,
	msg_type_start_game		= 0x2,
	msg_type_deal_hand		= 0x3,
	msg_type_initial_stacks		= 0x4,
	msg_type_selected_card		= 0x5,
	msg_type_selected_card_all	= 0x6,
	msg_type_selected_stack_c	= 0x7,
	msg_type_selected_stack_s	= 0x8,
	msg_type_next_action		= 0x9,
} 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(const int sock, const msg_type_t wanted);
bool net_send(const int sock, const msg_type_t type, const void *data);

#endif // OXEN_NET_H