Version 1.2.0 with new build/configure system
[tennix.git] / src / network.h
blob7e3331bfe098454097bc3e653d156beaa423b839
2 /**
4 * Tennix! SDL Port
5 * Copyright (C) 2003, 2007, 2008, 2009 Thomas Perl <thp@thpinfo.com>
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20 * MA 02110-1301, USA.
22 **/
24 #ifndef __NETWORK_H
25 #define __NETWORK_H
27 #include "config.h"
29 #include "game.h"
30 #include "input.h"
32 #ifdef HAVE_SDL_NET
33 #include <SDL/SDL_net.h>
34 #endif
36 /* Vanity ports "STNX" and "MTNX" */
37 #define TENNIXNET_PORT_SLAVE 7869
38 #define TENNIXNET_PORT_MASTER 6869
40 typedef struct {
41 Uint32 x;
42 Uint32 y;
43 Uint32 z;
44 Uint32 move_x;
45 Uint32 move_y;
46 Uint32 move_z;
47 bool ground_hit;
48 char last_hit_by;
49 bool inhibit_gravity;
50 } NetworkBall;
52 typedef struct {
53 Uint32 x;
54 Uint32 y;
55 Uint32 power;
56 bool use_power;
57 unsigned char score;
58 unsigned char desire;
59 char game;
60 unsigned char sets[SETS_TO_WIN*2];
61 Uint32 accelerate;
62 } NetworkPlayer;
64 typedef struct {
65 NetworkBall ball;
66 NetworkPlayer players[MAXPLAYERS];
67 unsigned char serving_player;
68 referee_t referee;
69 unsigned char current_set;
70 winner_t winner;
71 soundevent_t sound_events;
72 scoreevent_t score_event;
73 unsigned char score_time;
74 eventcounter_t ec_game;
75 eventcounter_t ec_sets;
76 statusmessage_t status_message;
77 } NetworkGameState;
79 void
80 init_network();
82 void
83 uninit_network();
85 TennixNet*
86 network_connect(const char* host, bool master);
88 void
89 network_disconnect(TennixNet* connection);
91 void
92 network_send_input(TennixNet* connection, NetworkInputData* src);
94 void
95 network_send_state(TennixNet* connection, GameState* src);
97 void
98 network_receive(TennixNet* connection);
100 void
101 network_get_input(TennixNet* connection, NetworkInputData* dest);
103 void
104 network_get_gamestate(TennixNet* connection, GameState* dest);
106 void
107 net_serialize_ball(const Ball* src, NetworkBall* dest);
109 void
110 net_unserialize_ball(NetworkBall* src, Ball* dest);
112 void
113 net_serialize_player(const Player* src, NetworkPlayer* dest);
115 void
116 net_unserialize_player(NetworkPlayer* src, Player* dest);
118 void
119 net_serialize_gamestate(const GameState* src, NetworkGameState* dest);
121 void
122 net_unserialize_gamestate(NetworkGameState* src, GameState* dest);
124 #endif