File: network.h

package info (click to toggle)
tennix 1.1-2
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 6,720 kB
  • sloc: ansic: 2,906; cpp: 2,333; python: 275; objc: 245; makefile: 125
file content (121 lines) | stat: -rw-r--r-- 2,758 bytes parent folder | download | duplicates (4)
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121

/**
 *
 * Tennix! SDL Port
 * Copyright (C) 2003, 2007, 2008, 2009 Thomas Perl <thp@thpinfo.com>
 * 
 * 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 2
 * 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, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
 * MA  02110-1301, USA.
 *
 **/

#ifndef __NETWORK_H
#define __NETWORK_H

#include "game.h"
#include "input.h"

#include <SDL/SDL_net.h>

/* Vanity ports "STNX" and "MTNX" */
#define TENNIXNET_PORT_SLAVE 7869
#define TENNIXNET_PORT_MASTER 6869

typedef struct {
    Uint32 x;
    Uint32 y;
    Uint32 z;
    Uint32 move_x;
    Uint32 move_y;
    Uint32 move_z;
    bool ground_hit;
    char last_hit_by;
    bool inhibit_gravity;
} NetworkBall;

typedef struct {
    Uint32 x;
    Uint32 y;
    Uint32 power;
    bool use_power;
    unsigned char score;
    unsigned char desire;
    char game;
    unsigned char sets[SETS_TO_WIN*2];
    Uint32 accelerate;
} NetworkPlayer;

typedef struct {
    NetworkBall ball;
    NetworkPlayer players[MAXPLAYERS];
    unsigned char serving_player;
    referee_t referee;
    unsigned char current_set;
    winner_t winner;
    soundevent_t sound_events;
    scoreevent_t score_event;
    unsigned char score_time;
    eventcounter_t ec_game;
    eventcounter_t ec_sets;
    statusmessage_t status_message;
} NetworkGameState;

void
init_network();

void
uninit_network();

TennixNet*
network_connect(const char* host, bool master);

void
network_disconnect(TennixNet* connection);

void
network_send_input(TennixNet* connection, NetworkInputData* src);

void
network_send_state(TennixNet* connection, GameState* src);

void
network_receive(TennixNet* connection);

void
network_get_input(TennixNet* connection, NetworkInputData* dest);

void
network_get_gamestate(TennixNet* connection, GameState* dest);

void
net_serialize_ball(const Ball* src, NetworkBall* dest);

void
net_unserialize_ball(NetworkBall* src, Ball* dest);

void
net_serialize_player(const Player* src, NetworkPlayer* dest);

void
net_unserialize_player(NetworkPlayer* src, Player* dest);

void
net_serialize_gamestate(const GameState* src, NetworkGameState* dest);

void
net_unserialize_gamestate(NetworkGameState* src, GameState* dest);

#endif