1 /*
2 Copyright (C) 1994-1995 Apogee Software, Ltd.
3 
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 
13 See the GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18 
19 */
20 //***************************************************************************
21 //
22 //   RT_NET.H - Network stuff
23 //
24 //***************************************************************************
25 
26 #ifndef _rt_net_public
27 #define _rt_net_public
28 
29 #include "develop.h"
30 #include "rottnet.h"
31 #include "rt_actor.h"
32 #include "rt_battl.h"
33 #include "rt_playr.h"
34 #include "rt_main.h"
35 
36 
37 #define MAXCMDS  256
38 
39 #define COM_DELTA   1
40 #define COM_REQUEST 2
41 #define COM_FIXUP   3
42 #define COM_TEXT    4
43 #define COM_PAUSE   5
44 #define COM_QUIT    6
45 #define COM_SYNC    7
46 #define COM_REMRID  8
47 #define COM_RESPAWN 10
48 #define COM_UNPAUSE 11
49 #define COM_SERVER  12
50 #define COM_START   13
51 #define COM_GAMEDESC 15
52 #define COM_GAMEPLAY 16
53 #define COM_GAMEMASTER 17
54 #define COM_GAMEACK 18
55 #define COM_ENDGAME  19
56 #define COM_SYNCTIME 20
57 #if (SYNCCHECK==1)
58 #define COM_SYNCCHECK 21
59 #endif
60 #define COM_SOUNDANDDELTA  22
61 #define COM_EXIT    23
62 #define COM_GAMEEND 24
63 #define COM_DELTANULL 25
64 
65 #define CHECKSYNCTIME  (VBLCOUNTER<<2)
66 
67 #define NETSYNCSERVERTIME (VBLCOUNTER)
68 #define MODEMSYNCSERVERTIME (VBLCOUNTER/4)
69 
70 #define DUMMYPACKETSIZE 20
71 
72 
73 #define COM_MAXTEXTSTRINGLENGTH 33
74 
75 // Sound defines for Remote ridicule
76 
77 #define COM_SOUND_START_TRANSMISSION  (0xff)
78 #define COM_SOUND_END_TRANSMISSION    (0xfe)
79 #define COM_SOUND_NORMAL_TRANSMISSION (0xfd)
80 #define COM_SOUND_BUFFERSIZE 256
81 
82 // Demo Delta Structure
83 typedef struct DemoType {
84   int   time;
85   short momx;
86   short momy;
87   word  dangle;
88   word  buttons;
89 } DemoType;
90 
91 // Demo Header Structure
92 typedef struct DemoHeaderType {
93   gametype demostate;
94 } DemoHeaderType;
95 
96 // Movement Queue Structure
97 typedef struct MoveType {
98   byte  type;
99   int   time;
100   short momx;
101   short momy;
102   word  dangle;
103   word  buttons;
104   char  Sounddata[0];
105 } MoveType;
106 
107 typedef struct NullMoveType {
108   byte  type;
109   int   time;
110 } NullMoveType;
111 
112 typedef struct {
113 
114   void * Commands[MAXCMDS];
115 
116 } CommandType;
117 
118 typedef struct {
119 
120   byte CommandStates[MAXCMDS];
121 
122 } CommandStatusType;
123 
124 typedef MoveType COM_SoundAndDeltaType;
125 
126 // uncomment for live remote ridicule
127 typedef struct {
128   byte  type;
129   byte  data[COM_SOUND_BUFFERSIZE];
130 //  char  data[COM_MAXTEXTSTRINGLENGTH];
131 } COM_SoundType;
132 
133 typedef struct {
134   byte  type;
135   int   synctime;
136 } COM_SyncType;
137 
138 typedef struct {
139   byte  type;
140   int   time;
141   int   synctime;
142   int   x;
143   int   y;
144   int   z;
145   word  angle;
146   word  randomindex;
147 } COM_CheckSyncType;
148 
149 typedef struct {
150   byte  type;
151   int   time;
152   byte  numpackets;
153   byte  data;
154 } COM_ServerHeaderType;
155 
156 typedef struct {
157   byte  type;
158   int   time;
159   byte   numpackets;
160 } COM_RequestType;
161 
162 typedef struct {
163   byte  type;
164   int   time;
165   byte  towho;
166   char  string[COM_MAXTEXTSTRINGLENGTH];
167 } COM_TextType;
168 
169 #define MSG_DIRECTED_TO_ALL  255
170 #define MSG_DIRECTED_TO_TEAM 254
171 
172 typedef struct {
173   byte  type;
174   int   time;
175   byte  player;
176   byte  num;
177   byte  towho;
178 } COM_RemoteRidiculeType;
179 
180 typedef struct {
181   byte  type;
182   int   time;
183   byte  numpackets;
184   byte  data;
185 } COM_FixupType;
186 
187 typedef struct {
188   byte  type;
189   int   time;
190 } COM_QuitType;
191 
192 typedef struct {
193   byte  type;
194   int   time;
195 } COM_ExitType;
196 
197 typedef struct {
198   byte  type;
199   int   time;
200 } COM_GameEndType;
201 
202 typedef struct {
203   byte  character;    // which character
204   byte  uniformcolor; // which color
205   char  codename[MAXCODENAMELENGTH];  // codename
206 } COM_PlayerDescriptionType;
207 
208 typedef struct {
209   byte  type;
210   byte  player;    // which player
211   byte  violence;
212   byte  Product;
213   unsigned Version;
214 
215   COM_PlayerDescriptionType playerdescription;
216 } COM_GamePlayerType;
217 
218 typedef struct {
219   byte  type;
220   byte  level;
221   word  mapcrc;
222   byte  violence;
223   byte  Product;
224   byte  mode;
225   unsigned Version;
226   boolean teamplay;
227   specials SpecialsTimes;
228   battle_type options;
229   char  battlefilename[20];
230   int   randomseed;
231   boolean ludicrousgibs;
232   COM_PlayerDescriptionType players[MAXPLAYERS];
233 } COM_GameMasterType;
234 
235 typedef struct {
236   byte  type;
237   byte  player; // which player
238 } COM_GameAckType;
239 
240 typedef struct {
241   byte  type;
242   int   time;
243 } COM_EndGameType;
244 
245 typedef struct {
246   byte  type;
247   int   time;
248 } COM_RespawnType;
249 
250 typedef struct {
251   byte  type;
252   int   time;
253 } COM_PauseType;
254 
255 typedef struct {
256   byte  type;
257   int   time;
258 } COM_UnPauseType;
259 
260 extern boolean  demorecord,
261 					 demoplayback;
262 extern byte     *demoptr,
263 					 *lastdemoptr,
264                 *demobuffer;
265 extern boolean  demodone;
266 
267 void     ControlPlayer (void);
268 void     ControlRemote (objtype * ob);
269 void     ControlPlayerObj (objtype * ob);
270 void InitializeGameCommands( void );
271 void ShutdownGameCommands( void );
272 void UpdateClientControls ( void );
273 void StartupClientControls ( void );
274 void ShutdownClientControls ( void );
275 void ProcessServer ( void );
276 void ServerLoop( void );
277 void SendPlayerDescription( void );
278 void SetGameDescription( void * pkt );
279 void SendGameDescription( void );
280 void SendGameAck( void );
281 void SendGameStart( void );
282 void SetupGamePlayer ( void );
283 void SetupGameMaster ( void );
284 void SetNormalHorizon (objtype * ob);
285 void SaveDemo (int demonumber);
286 void LoadDemo (int demonumber);
287 void RecordDemo ( void );
288 void SetupDemo ( void );
289 void FreeDemo ( void );
290 boolean DemoExists (int demonumber);
291 
292 void AddEndGameCommand ( void );
293 void AddTextMessage ( char * message, int length, int towho );
294 void AddEndGameCommand ( void );
295 void AddPauseStateCommand ( int type );
296 void AddRespawnCommand ( void );
297 void RecordDemoCmd (void);
298 void ResetCurrentCommand ( void );
299 void AddRemoteRidiculeCommand ( int player, int towho, int num );
300 void ProcessRemoteRidicule ( void * pkt );
301 void SyncToServer( void );
302 void AddQuitCommand ( void );
303 void AddExitCommand ( void );
304 void AddGameEndCommand ( void );
305 boolean PlayerInGame ( int p );
306 boolean ConsoleIsServer ( void );
307 
308 extern boolean IsServer;
309 extern boolean standalone;
310 extern boolean    playerdead;
311 
312 extern boolean    modemgame;
313 extern boolean    networkgame;
314 extern int        numplayers;
315 extern int        server;
316 
317 extern boolean    GamePaused;
318 extern boolean    battlegibs;
319 
320 extern boolean    remoteridicule;
321 
322 #if (SYNCCHECK==1)
323 extern int        lastsynccheck;
324 extern COM_CheckSyncType PlayerSync[MAXPLAYERS];
325 void CheckForSyncCheck ( void );
326 #endif
327 
328 int GamePacketSize( void );
329 
330 #endif
331