1 /* 2 * file network.h - shared functions for server and clients 3 * 4 * $Id: network.h,v 1.36 2006/02/10 15:07:42 fzago Exp $ 5 * 6 * Program XBLAST 7 * (C) by Oliver Vogel (e-mail: m.vogel@ndh.net) 8 * 9 * This program is free software; you can redistribute it and/or modify 10 * it under the terms of the GNU General Public License as published 11 * by the Free Software Foundation; either version 2; or (at your option) 12 * any later version 13 * 14 * This program is distributed in the hope that it will be entertaining, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILTY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 17 * Public License for more details. 18 * 19 * You should have received a copy of the GNU General Public License along 20 * with this program; if not, write to the Free Software Foundation, Inc. 21 * 675 Mass Ave, Cambridge, MA 02139, USA. 22 */ 23 #ifndef XBLAST_NETWORK_H 24 #define XBLAST_NETWORK_H 25 26 /* 27 * game config atoms in remote database 28 */ 29 #define LOCALGAMECONFIG(id) atomArrayHost0[id] 30 #define SERVERGAMECONFIG atomServer 31 /* 32 * type definition for network events 33 */ 34 typedef enum 35 { 36 XBNW_None = 0, 37 XBNW_Accepted, /* connection to client accepted */ 38 XBNW_GameConfig, /* client has send game config */ 39 XBNW_RightPlayerConfig, /* client has send player config */ 40 XBNW_LeftPlayerConfig, /* client has send player config */ 41 XBNW_Joy1PlayerConfig, /* client has send player config */ 42 XBNW_Joy2PlayerConfig, /* client has send player config */ 43 XBNW_Disconnected, /* connection to client accepted */ 44 XBNW_StartGame, /* server wants to start game */ 45 XBNW_EndOfInit, /* client is initialized */ 46 XBNW_LevelConfig, /* server has sent level data 10 */ 47 XBNW_SyncEndOfInit, /* sync after level intro */ 48 XBNW_SyncLevelIntro, /* sync after level intro */ 49 XBNW_SyncLevelResult, /* sync before level results are calculated */ 50 XBNW_SyncLevelEnd, /* sync after level end */ 51 XBNW_SyncScoreboard, /* sync after scoreboard 15 */ 52 XBNW_HostIsIn, /* host is in game */ 53 XBNW_HostIsOut, /* host is out of game */ 54 XBNW_TeamChange, /* Team Change */ 55 XBNW_TeamChangeData, /* Team Change Data */ 56 XBNW_Error, /* error while writing to host */ 57 XBNW_PingReceived, /* received ping from client */ 58 XBNW_NetworkGame, /* a new network game was added to the list */ 59 XBNW_HostChange, /* host state changed */ 60 /* no new message behind this line */ 61 XBNW_MAX 62 } XBNetworkEvent; 63 64 /* 65 * type definition for network events 66 */ 67 typedef enum 68 { 69 XBNT_None = 0, /* no networking going on */ 70 XBNT_Server, /* acting as server */ 71 XBNT_Client, /* acting as client */ 72 XBNT_MAX 73 } XBNetworkType; 74 75 /* client state */ 76 typedef enum 77 { 78 XBHS_None, 79 XBHS_Wait, /* waiting for client to send player data */ 80 XBHS_In, /* client is in the game */ 81 XBHS_Out, /* client is out of the game */ 82 XBHS_Server, /* host is server */ 83 XBHS_Ready, /* host is ready to start */ 84 /*---*/ 85 NUM_XBHS 86 } XBHostState; 87 88 /* team state */ 89 typedef enum 90 { 91 XBTS_Invalid, /* invalid team tag */ 92 XBTS_None, /* no team tag */ 93 XBTS_Red, /* unknown if this is good */ 94 XBTS_Green, 95 XBTS_Blue, 96 XBTS_Out, 97 /*---*/ 98 NUM_XBTS 99 } XBTeamState; 100 101 /* special codes for winning team */ 102 #define TEAM_NOWINNER 255 103 #define TEAM_LOCALASYNC 254 104 #define TEAM_ASYNC 253 105 #define TEAM_UNDEF 252 106 107 /* team color assignment */ 108 extern const XBColor teamColors[NUM_XBTS]; 109 110 /* results of game config receive/create */ 111 typedef enum 112 { 113 XBGC_Unfinished, /* still waiting for data */ 114 XBGC_HostInvalid, /* invalid host id */ 115 XBGC_Empty, /* game config with no players received */ 116 XBGC_TooManyPlayers, /* game config contains too many players to handle */ 117 XBGC_NoVersion, /* no version found */ 118 XBGC_Local, /* local game config received */ 119 XBGC_Global, /* global game config with all players received */ 120 XBGC_Error, /* game config received is invalid */ 121 XBGC_SingleTeam, /* single team for all players when creating */ 122 } XBGameConfigResult; 123 124 /* 125 * global prototypes 126 */ 127 128 /* init */ 129 extern void Network_ClearHost (unsigned id); 130 extern void Network_Clear (void); 131 132 /* events */ 133 extern void Network_ClearEvents (void); 134 extern XBNetworkEvent Network_GetEvent (unsigned *pId); 135 extern void Network_QueueEvent (XBNetworkEvent msg, unsigned id); 136 137 /* type of network */ 138 extern XBNetworkType Network_GetType (void); 139 extern void Network_SetType (XBNetworkType type); 140 141 /* local host id */ 142 extern void Network_ReceiveLocalHostId (unsigned id); 143 extern unsigned char Network_LocalHostId (void); 144 145 /* ping times */ 146 extern int Network_GetPingTime (unsigned id); 147 extern void Network_ReceivePing (unsigned id, int ping); 148 149 /* player atoms */ 150 extern XBAtom Network_GetPlayer (unsigned id, int player); 151 extern XBAtom Network_GetPlayer2 (unsigned id, int player); 152 extern void Network_SetPlayer (unsigned id, int player, XBAtom atom); 153 extern void Network_SetPlayer2 (unsigned id, int player, XBAtom atom); 154 extern XBBool Network_GetFirstOtherPlayer (unsigned char id, unsigned char pl, unsigned char *host, 155 unsigned char *player); 156 extern XBBool Network_GetNextOtherPlayer (unsigned char id, unsigned char pl, unsigned char *host, 157 unsigned char *player); 158 /* host data */ 159 extern unsigned Network_HostPlayerMax (unsigned); 160 161 /* game configs */ 162 extern XBGameConfigResult Network_CreateGlobalGameConfig (CFGGame * cfg); 163 extern XBGameConfigResult Network_ReceiveGameConfig (unsigned id, const char *data); 164 extern unsigned Network_CreateLocalPlayers (unsigned); 165 extern unsigned Network_CreateGlobalPlayers (unsigned); 166 extern unsigned Network_GetMaskBytes (void); 167 168 /* player configs */ 169 extern XBAtom Network_ReceivePlayerConfig (CFGType cfgType, unsigned id, int player, 170 const char *line); 171 172 /* state requests */ 173 extern XBBool Network_ReceiveHostState (unsigned id, XBHostState state); 174 extern XBBool Network_ReceiveTeamState (unsigned host, unsigned player, XBTeamState team); 175 extern XBBool Network_ReceiveHostStateReq (unsigned who, unsigned id, XBHostState state); 176 extern XBBool Network_ReceiveTeamStateReq (unsigned who, unsigned host, unsigned player, 177 XBTeamState team); 178 extern void Network_SetDefaultTeams (unsigned host, unsigned player); 179 extern XBTeamState Network_GetDefaultTeam (unsigned id, unsigned player); 180 extern XBHostState Network_GetHostState (unsigned id); 181 extern XBBool Network_HostIsIn (unsigned id); 182 extern XBHostState *Network_GetHostStateReq (unsigned id); 183 extern XBTeamState Network_GetTeamState (unsigned id, unsigned pl); 184 extern XBTeamState *Network_GetTeamStateReq (unsigned id, unsigned pl); 185 extern XBBool Network_HostReqClientsAgree (unsigned host, XBHostState state); 186 extern XBBool Network_ClientsReady (void); 187 extern XBBool Network_TeamReqClientsAgree (unsigned host, unsigned player, unsigned state); 188 189 #endif 190 /* 191 * end of file network.h 192 */ 193