2
Copyright (C) 2008 Kai Hertel, André Gaul
4
This file is part of mmpong.
6
mmpong is free software: you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation, either version 3 of the License, or
9
(at your option) any later version.
11
mmpong is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU General Public License for more details.
16
You should have received a copy of the GNU General Public License
17
along with mmpong. If not, see <http://www.gnu.org/licenses/>.
20
#ifndef __MESSAGE_HEADER__
21
#define __MESSAGE_HEADER__
26
#include "dllhelper.h"
33
#define NETMESSAGE_MAXLEN 256
35
#define NETMSG_SUCCESS 0
36
#define NETMSG_ARGINVALID (-1)
37
#define NETMSG_PARTIAL (-2)
38
#define NETMSG_END_SOCKET (-3)
39
#define NETMSG_FAIL_DELIVER (-4)
40
#define NETMSG_FAIL_SOCKET (-5)
41
#define NETMSG_FAIL_CONVERT (-6)
42
#define NETMSG_FAIL_CHECKSUM (-7)
43
#define NETMSG_FAIL_SYSCRITICAL (-8)
45
enum netmessage_type {
46
NETMSG_STAT= 's', // full game state
47
NETMSG_UPDT= 'u', // game state update
48
NETMSG_EXIT= 'e', // peer exits voluntarily
49
NETMSG_KICK= 'k', // client session terminates
50
NETMSG_POS= 'p' // position update
53
// no padding for structures related to the net code
56
struct netmessage_header {
59
struct gametime_public stamp;
63
struct netmessage_header hdr;
65
char data[NETMESSAGE_MAXLEN -sizeof(struct netmessage_header)];
66
struct game_state_full {
68
struct gameplay_public game;
70
struct game_state_part { // this one might need manual adjustments to stay in sync with `struct gameplay_public`
71
struct gametime_public stamp; // time stamp
72
struct gameball_public ball;
73
struct gamepaddle_public pad[2];
81
struct netmessage_buffer {
83
struct netmessage msg;
87
EXPORT int netmessage_buffer_init(struct netmessage_buffer **);
88
EXPORT int netmessage_buffer_flush(const int, struct netmessage_buffer *);
89
EXPORT int netmessage_scrambler_init(void);
90
EXPORT int netmessage_send(const int, const enum netmessage_type, const void *, const uint16_t, struct netmessage_buffer *);
91
EXPORT int netmessage_recv(const int, struct netmessage *, const uint16_t, struct netmessage_buffer *);
92
EXPORT int netmessage_get_hdr_stamp(const struct netmessage *, struct timeval *);