]> icculus.org git repositories - taylor/freespace2.git/blob - include/multi.h
work around some gcc 3.1 weirdness
[taylor/freespace2.git] / include / multi.h
1 /*
2  * Copyright (C) Volition, Inc. 1999.  All rights reserved.
3  *
4  * All source code herein is the property of Volition, Inc. You may not sell 
5  * or otherwise commercially exploit the source or things you created based on
6  * the source.
7  */
8
9 /*
10  * $Logfile: /Freespace2/code/Network/Multi.h $
11  * $Revision$
12  * $Date$
13  * $Author$
14  *
15  * Header file which contains type definitions for multiplayer, and support for high-level
16  * multiplayer functions.
17  *
18  * $Log$
19  * Revision 1.4  2002/06/09 04:41:14  relnev
20  * added copyright header
21  *
22  * Revision 1.3  2002/06/02 06:02:59  relnev
23  * tcp.cfg namefix
24  *
25  * Revision 1.2  2002/05/26 21:27:53  theoddone33
26  * More progress (I hate psnet2)
27  *
28  * Revision 1.1.1.1  2002/05/03 03:28:12  root
29  * Initial import.
30  *
31  * 
32  * 47    8/30/99 5:01p Dave
33  * Made d3d do less state changing in the nebula. Use new chat server for
34  * PXO.
35  * 
36  * 46    8/26/99 8:51p Dave
37  * Gave multiplayer TvT messaging a heavy dose of sanity. Cheat codes.
38  * 
39  * 45    8/24/99 10:11a Dave
40  * New server version.
41  * 
42  * 44    8/24/99 1:49a Dave
43  * Fixed client-side afterburner stuttering. Added checkbox for no version
44  * checking on PXO join. Made button info passing more friendly between
45  * client and server.
46  * 
47  * 43    8/22/99 5:53p Dave
48  * Scoring fixes. Added self destruct key. Put callsigns in the logfile
49  * instead of ship designations for multiplayer players.
50  * 
51  * 42    8/22/99 1:19p Dave
52  * Fixed up http proxy code. Cleaned up scoring code. Reverse the order in
53  * which d3d cards are detected.
54  * 
55  * 41    8/19/99 10:59a Dave
56  * Packet loss detection.
57  * 
58  * 40    8/04/99 2:24a Dave
59  * Fixed escort gauge ordering for dogfight.
60  * 
61  * 39    7/30/99 7:01p Dave
62  * Dogfight escort gauge. Fixed up laser rendering in Glide.
63  * 
64  * 38    7/26/99 5:50p Dave
65  * Revised ingame join. Better? We'll see....
66  * 
67  * 37    7/22/99 7:17p Dave
68  * Fixed excessive whacks in multiplayer.
69  * 
70  * 36    7/08/99 10:53a Dave
71  * New multiplayer interpolation scheme. Not 100% done yet, but still
72  * better than the old way.
73  * 
74  * 35    7/03/99 5:50p Dave
75  * Make rotated bitmaps draw properly in padlock views.
76  * 
77  * 34    6/07/99 9:51p Dave
78  * Consolidated all multiplayer ports into one.
79  * 
80  * 33    5/17/99 9:32a Dave
81  * Bumped up server version.
82  * 
83  * 32    5/14/99 1:59p Andsager
84  * Multiplayer message for subsystem cargo revealed.
85  * 
86  * 31    4/29/99 3:02p Dave
87  * 
88  * 30    4/29/99 2:29p Dave
89  * Made flak work much better in multiplayer.
90  * 
91  * 29    4/28/99 11:13p Dave
92  * Temporary checkin of artillery code.
93  * 
94  * 28    4/25/99 7:43p Dave
95  * Misc small bug fixes. Made sun draw properly.
96  * 
97  * 27    4/21/99 6:15p Dave
98  * Did some serious housecleaning in the beam code. Made it ready to go
99  * for anti-fighter "pulse" weapons. Fixed collision pair creation. Added
100  * a handy macro for recalculating collision pairs for a given object.
101  * 
102  * 26    4/09/99 2:21p Dave
103  * Multiplayer beta stuff. CD checking.
104  * 
105  * 25    3/10/99 6:50p Dave
106  * Changed the way we buffer packets for all clients. Optimized turret
107  * fired packets. Did some weapon firing optimizations.
108  * 
109  * 24    3/08/99 7:03p Dave
110  * First run of new object update system. Looks very promising.
111  * 
112  * 23    3/01/99 7:39p Dave
113  * Added prioritizing ship respawns. Also fixed respawns in TvT so teams
114  * don't mix respawn points.
115  * 
116  * 22    2/25/99 4:19p Dave
117  * Added multiplayer_beta defines. Added cd_check define. Fixed a few
118  * release build warnings. Added more data to the squad war request and
119  * response packets.
120  * 
121  * 21    2/23/99 2:29p Dave
122  * First run of oldschool dogfight mode. 
123  * 
124  * 20    2/19/99 11:42a Dave
125  * Put in model rendering autocentering.
126  * 
127  * 19    2/17/99 2:10p Dave
128  * First full run of squad war. All freespace and tracker side stuff
129  * works.
130  * 
131  * 18    2/12/99 6:16p Dave
132  * Pre-mission Squad War code is 95% done.
133  * 
134  * 17    2/11/99 3:08p Dave
135  * PXO refresh button. Very preliminary squad war support.
136  * 
137  * 16    2/08/99 5:07p Dave
138  * FS2 chat server support. FS2 specific validated missions.
139  * 
140  * 15    1/29/99 2:08a Dave
141  * Fixed beam weapon collisions with players. Reduced size of scoring
142  * struct for multiplayer. Disabled PXO.
143  * 
144  * 14    1/14/99 12:48a Dave
145  * Todo list bug fixes. Made a pass at putting briefing icons back into
146  * FRED. Sort of works :(
147  * 
148  * 13    1/12/99 5:45p Dave
149  * Moved weapon pipeline in multiplayer to almost exclusively client side.
150  * Very good results. Bandwidth goes down, playability goes up for crappy
151  * connections. Fixed object update problem for ship subsystems.
152  * 
153  * 12    1/12/99 4:07a Dave
154  * Put in barracks code support for selecting squad logos. Properly
155  * distribute squad logos in a multiplayer game.
156  * 
157  * 11    12/14/98 12:13p Dave
158  * Spiffed up xfer system a bit. Put in support for squad logo file xfer.
159  * Need to test now.
160  * 
161  * 10    12/03/98 5:22p Dave
162  * Ported over Freespace 1 multiplayer ships.tbl and weapons.tbl
163  * checksumming.
164  * 
165  * 9     11/19/98 4:19p Dave
166  * Put IPX sockets back in psnet. Consolidated all multiplayer config
167  * files into one.
168  * 
169  * 8     11/19/98 8:03a Dave
170  * Full support for D3-style reliable sockets. Revamped packet lag/loss
171  * system, made it receiver side and at the lowest possible level.
172  * 
173  * 7     11/17/98 11:12a Dave
174  * Removed player identification by address. Now assign explicit id #'s.
175  * 
176  * 6     11/12/98 12:13a Dave
177  * Tidied code up for multiplayer test. Put in network support for flak
178  * guns.
179  * 
180  * 5     11/05/98 5:55p Dave
181  * Big pass at reducing #includes
182  * 
183  * 4     10/19/98 11:15a Dave
184  * Changed requirements for stats storing in PXO mode.
185  * 
186  * 3     10/07/98 6:27p Dave
187  * Globalized mission and campaign file extensions. Removed Silent Threat
188  * special code. Moved \cache \players and \multidata into the \data
189  * directory.
190  * 
191  * 2     10/07/98 10:53a Dave
192  * Initial checkin.
193  * 
194  * 1     10/07/98 10:50a Dave
195  * 
196  * 257   9/20/98 7:19p Dave
197  * Added CHANGE_IFF packet. 
198  * 
199  * 256   9/16/98 6:54p Dave
200  * Upped  max sexpression nodes to 1800 (from 1600). Changed FRED to sort
201  * the ship list box. Added code so that tracker stats are not stored with
202  * only 1 player.
203  * 
204  * 255   9/15/98 7:24p Dave
205  * Minor UI changes. Localized bunch of new text.
206  * 
207  * 254   9/15/98 4:03p Dave
208  * Changed readyroom and multi screens to display "st" icon for all
209  * missions with mission disk content (not necessarily just those that
210  * come with Silent Threat).
211  * 
212  * 253   9/11/98 5:08p Dave
213  * More tweaks to kick notification system.
214  * 
215  * 252   9/11/98 2:05p Allender
216  * make reinforcements work correctly in multiplayer games.  There still
217  * may be a team vs team issue that I haven't thought of yet :-(
218  * 
219  * 251   9/04/98 3:51p Dave
220  * Put in validated mission updating and application during stats
221  * updating.
222  * 
223  * 250   8/31/98 2:06p Dave
224  * Make cfile sort the ordering or vp files. Added support/checks for
225  * recognizing "mission disk" players.
226  * 
227  * 249   8/25/98 1:48p Dave
228  * First rev of EMP effect. Player side stuff basically done. Next comes
229  * AI code.
230  * 
231  * 248   8/12/98 4:53p Dave
232  * Put in 32 bit checksumming for PXO missions. No validation on the
233  * actual tracker yet, though.
234  * 
235  * 247   7/24/98 9:27a Dave
236  * Tidied up endgame sequencing by removing several old flags and
237  * standardizing _all_ endgame stuff with a single function call.
238  * 
239  * 246   7/10/98 5:04p Dave
240  * Fix connection speed bug on standalone server.
241  * 
242  * 245   7/10/98 11:52a Allender
243  * changes to the connection type
244  * 
245  * 244   7/10/98 1:13a Allender
246  * lots of small multiplayer update changes.  Code in launcher to specify
247  * connection speed.  A couple of small fixes regarding empty mission
248  * files.  Time out players after 10 second when they don't connect on
249  * their reliable socket.
250  * 
251  * 243   7/07/98 2:56p Dave
252  * 
253  * 242   7/02/98 6:16p Dave
254  * Make rear facing prediction much better. Tweak update levels and
255  * viewcone values. Make sure observers send targeting info correctly.
256  * 
257  * 241   6/30/98 2:17p Dave
258  * Revised object update system. Removed updates for all weapons. Put
259  * button info back into control info packet.
260  * 
261  * 240   6/22/98 8:36a Allender
262  * revamping of homing weapon system.  don't send as object updates
263  * anymore
264  * 
265  * 239   6/17/98 10:56a Dave
266  * Put in debug code for detecting potential tracker stats update
267  * problems.
268  * 
269  * 238   6/12/98 2:49p Dave
270  * Patch 1.02 changes.
271  * 
272  * 237   6/10/98 2:56p Dave
273  * Substantial changes to reduce bandwidth and latency problems.
274  * 
275  * 236   6/04/98 10:06p Allender
276  * upped packet version
277  * 
278  * 235   6/04/98 11:46a Dave
279  * Drastically reduce size/rate of client control info update packets. Put
280  * in rate limiting for object updating from server.
281  * 
282  *  
283  * $NoKeywords: $
284  */
285
286 #ifndef _MULTI_H
287 #define _MULTI_H
288
289 #include "psnet.h"                                      // for PSNET_SOCKET             
290 #include "player.h"
291 #include "multi_ping.h"
292 #include "missionparse.h"
293 #include "multi_options.h"
294
295 // ----------------------------------------------------------------------------------------
296 // Basic defines
297 //
298 //
299
300 struct CFILE;
301
302 // defines for checking PXO valid missions
303 #ifdef NDEBUG           
304         // NEVER COMMENT OUT THIS LINE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
305         #define PXO_CHECK_VALID_MISSIONS                                // always check for valid missions in a debug build
306 #else
307         // #define PXO_CHECK_VALID_MISSIONS                             // comment this in and out as necessary (for testing or not)
308 #endif
309
310 // name of the validated mission file for PXO missions
311 #define MULTI_VALID_MISSION_FILE                "mvalid.cfg"
312
313 // name of the file which contains known TCP addresses
314 #define IP_CONFIG_FNAME                         "tcp.cfg"
315
316 // server version and compatible version
317 // to join a game - your LOCAL.MULTI_FS_SERVER_COMPATIBLE_VERSION must be >= GAME_SERVER.MULTI_FS_SERVER_VERSION
318 // Version #. Please put the date down when you up these values
319 // NOTE: always keep SERVER_VERSION and SERVER_COMPATIBLE_VERSION the same
320 //
321 // version 32 - 1/29/99
322 // version 33 - 2/22/99
323 // version 34 - 4/8/99
324 // version 35 - 4/21/99
325 // version 36 - 4/28/99
326 // version 37 - 4/29/99
327 // version 38 - 5/17/77
328 // version 39 - 7/3/99
329 // version 40 - 7/7/99
330 // version 41 - 7/22/99
331 // version 42 - 7/26/99 (ingame join stuff)
332 // version 43 - 7/30/99
333 // version 44 - 8/24/99
334 // version 46 - 8/30/99
335 // STANDALONE_ONLY
336 #define MULTI_FS_SERVER_VERSION                                                 46
337 #define MULTI_FS_SERVER_COMPATIBLE_VERSION                      MULTI_FS_SERVER_VERSION
338
339 // version defines (i.e. demo, full version, special OEM version
340 // id's should not be > 255!!!!
341 #define NG_VERSION_ID_FULL                                              1
342
343 // set the next define to be what version you want to build for.
344 #define NG_VERSION_ID                                                   NG_VERSION_ID_FULL
345
346 // the max # of active players (flying ships)
347 #define MULTI_MAX_PLAYERS                                       12
348
349 // the total max # of connections (players + observers + (possibly)standalone server)
350 #define MULTI_MAX_CONNECTIONS                           16
351
352 // the max # of observers ever allowed
353 #define MAX_OBSERVERS                                           4
354
355 #define LOGIN_LEN                                                               33
356
357 // string length defines
358 #define MAX_GAMENAME_LEN                                        32                              // maximum length in characters of a game name
359 #define DESCRIPT_LENGTH                                         512                     // maximum length of a mission description (as specified by Fred)
360 #define MAX_PASSWD_LEN                                          16                              // maximum length of the password for a netgame
361
362 // low level networking defines
363 #define IP_ADDRESS_LENGTH                                       4                               // length of the address field for an IP address
364 #define IP_PORT_LENGTH                                          2                               // length of the port field for an IP address
365 #define IPX_ADDRESS_LENGTH                                      6                               // length of the address field for an IPX address
366 #define IPX_PORT_LENGTH                                         2                               // length of the port field for an IPX address
367
368 // netgame defines
369 #define RESPAWN_ANARCHY                                         (0xffffffff)// respawn setting for an "anarchy" style game
370 #define MP_SINGLE                                                               0                               // not playing a campaign - single mission
371 #define MP_CAMPAIGN                                                     1                               // playing a campaign
372
373 // respawn defines
374 #define RESPAWN_INVUL_TIMESTAMP                 5000                    // how long a player is invulnerable after he respawns
375 #define MAX_RESPAWN_POINTS                                      25                              // the max # of respawn points we'll keep track of for any mission
376
377 // player information defines
378 #define BUTTON_INFO_SAVE_COUNT                  30                              // how many buttons infos we keep track of for sending critical keypresses to the server
379 #define MAX_PINGS                                                               10                              // how many pings we keep track of for averaging player pings
380 #define OBJECT_UDPATE_DIFF_TOLERANCE    40000                   // how big of a difference in sequence numbers (control_info and object_updates) before we reset
381
382 // reliable connect wait
383 #define MULTI_RELIABLE_CONNECT_WAIT             15
384
385 // tracker mission validation status
386 #define MVALID_STATUS_UNKNOWN                                   -1
387 #define MVALID_STATUS_VALID                                     0
388 #define MVALID_STATUS_INVALID                                   1
389
390 // ----------------------------------------------------------------------------------------
391
392
393 // ----------------------------------------------------------------------------------------
394 // Network macros
395 //
396 //
397
398 // netplayer management
399 #define NET_PLAYER_INDEX(np)    (np-Net_players)
400 #define NET_PLAYER_NUM(np)              (NET_PLAYER_INDEX(np))
401 #define MY_NET_PLAYER_NUM               (NET_PLAYER_INDEX(Net_player))
402
403 // determine what the status of this machine is
404 #define MULTIPLAYER_MASTER                      ( (Game_mode & GM_MULTIPLAYER) && (Net_player->flags & NETINFO_FLAG_AM_MASTER) )
405 #define MULTIPLAYER_HOST                        ( (Game_mode & GM_MULTIPLAYER) && (Net_player->flags & NETINFO_FLAG_GAME_HOST) )
406 #define MULTIPLAYER_CLIENT                      ( (Game_mode & GM_MULTIPLAYER) && !(Net_player->flags & NETINFO_FLAG_AM_MASTER) )
407 #define MULTIPLAYER_STANDALONE  ( (Game_mode & GM_MULTIPLAYER) && (Net_players[0].flags & NETINFO_FLAG_AM_MASTER) && !(Net_players[0].flags & NETINFO_FLAG_GAME_HOST) )
408
409 // determine the status of the passed player
410 #define MULTI_CONNECTED(np)             (np.flags & NETINFO_FLAG_CONNECTED)
411 #define MULTI_HOST(np)                          (np.flags & NETINFO_FLAG_GAME_HOST)
412 #define MULTI_SERVER(np)                        (np.flags & NETINFO_FLAG_AM_MASTER)
413 #define MULTI_STANDALONE(np)            ((np.flags & NETINFO_FLAG_AM_MASTER) && !(np.flags & NETINFO_FLAG_GAME_HOST))
414 #define MULTI_OBSERVER(np)                      (np.flags & NETINFO_FLAG_OBSERVER)
415 #define MULTI_TEMP_OBSERVER(np) ((np.flags & NETINFO_FLAG_OBSERVER) && (np.flags & NETINFO_FLAG_OBS_PLAYER))
416 #define MULTI_PERM_OBSERVER(np) ((np.flags & NETINFO_FLAG_OBSERVER) && !(np.flags & NETINFO_FLAG_OBS_PLAYER))
417
418 // are we playing on a master tracker registered server
419 #define MULTI_IS_TRACKER_GAME    (0)
420 // ----------------------------------------------------------------------------------------
421
422
423 // ----------------------------------------------------------------------------------------
424 // Packet definitions and additional packet data types
425 //
426 //
427
428 #define NETPLAYER_SLOTS_P        0x01     // data telling clients what player has what object number ...
429 #define FIRING_INFO                                     0x02            // firing info packet
430 #define INGAME_SHIP_UPDATE       0x03     // ship status-like update for ingame joiners choosing ships.
431 #define INGAME_SHIP_REQUEST      0x04     // used for requesting a replying (confirm or no) ships for an ingame joiner
432 #define TEAM_SELECT_UPDATE       0x05     // update from host to players in team select regarding who has what ship
433 #define FILE_SIG_INFO            0x06     // file signature info ( as calculated by get_bigass_file_signature() )
434 #define RESPAWN_NOTICE           0x07     // from client to server, or server to client
435 #define LOAD_MISSION_NOW         0x08     // clients should load the mission and return an ack
436 #define FILE_SIG_REQUEST         0x09     // request from server to client for filesig info
437 #define JUMP_INTO_GAME           0x0A     // from server to client telling him to jump into the mission
438 #define RESPAWN_POINTS           0x0B     // from server to ingame joiners, giving respawn data
439 #define CLIENT_REPAIR_INFO       0x0C     // passing various data to clients indicating their repair status
440 #define CARGO_REVEALED                          0x0E            // cargo is known
441 #define SHIELD_EXPLOSION                        0x0F            // shield explosion
442
443 #define SUBSYSTEM_DESTROYED             0x10            // update about a subsystem update
444 #define MISSION_SYNC_DATA        0x11           // this is a unique packet from the host to the server in a standalone game
445 #define STORE_MISSION_STATS      0x12           // sent to client indicating the host has hit "accept" and they should update their alltime stats
446 #define DEBRIS_UPDATE            0x13           // debris position, velocity, orientation, etc update
447 #define SHIP_WSTATE_CHANGE                      0x14            // used to tell clients that a ship's primary/secondary state changed   
448 #define WSS_REQUEST_PACKET                      0x15            // from client to server, requesting to do an operation
449 #define WSS_UPDATE_PACKET                       0x16            // from server to client, given any update
450 #define KICK_PLAYER                                     0x17            // kick a specific player (sent to server by those who are allowed to do this)
451 #define MISSION_GOAL_INFO                       0x18            // update of mission goal info
452 #define ASTEROID_INFO                           0x19            // update of asteroid stuff
453 #define NETPLAYER_PAIN                          0x1A            // to notify the player of hits which he may not otherwise see
454 #define OBJECT_UPDATE_NEW                       0x1B
455 #define SUBSYS_CARGO_REVEALED           0X1C            // Capital ship cargo subsystem is known
456
457 #define POST_SYNC_DATA                          0x20            // a very large packet containing all the data players will need before going into the mission itself
458 #define PLAYER_SETTINGS                         0x21            // player settings for each individual net player
459 #define WSS_SLOTS_DATA                          0x22            // all weapon slots information for the starting wings (needs to be synched)
460 #define PLAYER_STATS                                    0x23            // stats for a given player 
461 #define SLOT_UPDATE                                     0x24            // an player slot position update in multiplayer ship/team select
462 #define TEAM_UPDATE                                     0x25            // used for performing misc operations on pregame interface screens for team vs. team games
463 #define INGAME_EXTRA                                    0x26            // extra data for ingame joiners
464 #define HOST_RESTR_QUERY                        0x27            // query the host when a player joins a restricted game
465 #define OPTIONS_UPDATE                          0x28            // options (netgame or local) update packet
466 #define CLIENT_UPDATE                           0x29            // sent from server to client periodically to update important info (pause status, etc)
467 #define CD_VERIFY                                               0x2A            // cd verification update
468 #define PRIMARY_FIRED_NEW                       0x2B            // for client-side firing - highly streamlined
469 #define COUNTERMEASURE_NEW                      0x2C            // for client-side firing
470 #define EVENT_UPDATE                                    0x2D            // event change
471
472 #define SECONDARY_FIRED_AI                      0xA0            // fired a secondary weapon (ai ship)
473 #define SECONDARY_FIRED_PLR             0xA1            // fired a secondary weapon (player ship)
474 #define COUNTERMEASURE_FIRED            0xA2            // countermeasure was fired
475 #define FIRE_TURRET_WEAPON                      0xA3            // a turret weapon was fired
476 #define SHIP_STATUS_CHANGE       0xA4     // any of the relevant ship status buttons have been hit (need ack from server)
477 #define PLAYER_ORDER_PACKET      0xA5     // ship and wing commands sent from client to server
478 #define AI_INFO_UPDATE                          0xA6            // update ai information for the given ship
479 #define CAMPAIGN_UPDATE                         0xA7            // one of several campaign informational packets
480 #define CAMPAIGN_UPDATE_INGAME  0xA8            // campaign info for ingame joiner
481 #define HOMING_WEAPON_UPDATE            0xA9            // update homing object and subsystem for homing missile
482 #define FLAK_FIRED                                      0xAA            // flak gun fired
483 #define SELF_DESTRUCT                           0xAB            // self destruct
484
485 #define JOIN                                                    0xB1            // a join request to a server
486 #define ACCEPT                                                  0xB2            // acceptance of a join packet
487 #define DENY                                                    0xB3            // a join request is denied
488 #define NOTIFY_NEW_PLAYER                       0xB4            // notify players of a new player
489 #define MISSION_REQUEST                         0xB5     // request a list of missions on the master.
490 #define MISSION_ITEM                                    0xB6            // a bundle of mission filenames
491 #define GAME_INFO                                               0xB7            // game information packet for an active server
492 #define MULTI_PAUSE_REQUEST             0xB8            // send a request to the server to pause or unpause the game
493 #define TRANSFER_HOST                           0xB9     // transfer host status to the receiver
494 #define CHANGE_SERVER_ADDR                      0xBA     // change your host_addr to this value 
495 #define ACCEPT_PLAYER_DATA                      0xBB            // player data -- sent after guy is accepted
496 #define BEAM_FIRED                                      0xBC            // a beam weapon was fired
497 #define SW_STD_QUERY                                    0xBD            // query from host to standalone server to query PXO about a squad war match
498
499 #define HUD_MSG                                         0xC1            // a hud message
500 #define LEAVE_GAME                                      0xC2            // indication that a player is leaving the game
501 #define GAME_CHAT                                               0xC3            // this chat packet used for Freespace
502 #define MISSION_MESSAGE                         0xC4            // a message (squadmate, etc)
503 #define SHIP_DEPART                                     0xC5            // a ship has left the building
504 #define SHIPS_INGAME_PACKET             0xC6     // ingame join ship data packet
505 #define WINGS_INGAME_PACKET             0xC7            // ingame join wing data packet
506 #define MISSION_END                                     0xC8     // sent from host(master) to clients indicating they should go to the debriefing
507 #define INGAME_NAK                                      0xC9     // opposite of INGAME_ACK. Uses the ACK_* defines as well.
508 #define OBSERVER_UPDATE                         0xCA     // sent from observers to server to give position and orientation
509 #define SQUADMSG_PLAYER                         0xCB            // a squadmate message command has been sent to a netplayer
510 #define OBJ_UPDATE_SYNC                         0xCC            // object update timebase syncing code
511
512 #define WEAPON_DET                                      0xD1            // a weapon has detonated, possibly with child weapons
513 #define SHIP_KILL                                               0xD2            // a ship was killed
514 #define WING_CREATE                                     0xD3            // create and warp in a wing of ships
515 #define SHIP_CREATE                                     0xD4            // create and wrap in a ship
516 #define PING                                          0xD5     // ping
517 #define PONG                                          0xD6              // pong
518 #define XFER_PACKET                           0xD7              // file xfer data of one kind or another
519 #define VOICE_PACKET                                    0xD8            // a voice streaming packet of one kind or another
520 #define NETGAME_END_ERROR                       0xD9            // the netgame has been ended by the server because of an error (passed error code)
521 #define COUNTERMEASURE_SUCCESS  0xDA            // countermeasure was successful for this player.
522 #define REINFORCEMENT_AVAIL             0xDB            // a reinforcement is available
523 #define LIGHTNING_PACKET                        0xDC            // lightning bolt packet for multiplayer nebula
524 #define BYTES_SENT                                      0xDD            // how much data we've sent/received
525
526 #define GAME_ACTIVE                                     0xE1            // info on an active game server
527 #define GAME_QUERY                                      0xE2            // request for a list of active game servers
528 #define GAME_UPDATE                                     0xE3            // update info on an active game server
529 #define NETPLAYER_UPDATE                        0xE4            // a player update packet
530 #define OBJECT_UPDATE                           0xE6            // an object update packet from server to all clients
531 #define MISSION_LOG_ENTRY                       0xE7            // ad an item into the mission log
532 #define UPDATE_DESCRIPT                         0xE8            // update the netgame description
533 #define COUNTDOWN                                               0xE9            // countdown timer for starting a game (pretty benign)
534 #define DEBRIEF_INFO                                    0xEA            // end of mission debriefing information
535 #define EMP_EFFECT                                      0xEB            // EMP effect (mission disk only)
536 #define CHANGE_IFF                                      0xEC            // change iff (1.04+ only)
537
538 #define MAX_TYPE_ID                                     0xFF            // better not try to send > 255 in a single byte buddy
539
540 // ingame ack data codes
541 #define ACK_RESPAWN_POINTS                      0x1             // from ingame joiner to server, indicating he got the respawn points packet
542 #define ACK_FILE_ACCEPTED        0x2            // server to client saying their file is valid
543 #define ACK_FILE_REJECTED        0x3            // server to client saying their file is not valid
544
545 // join request denial codes
546 #define JOIN_DENY_JR_STATE                              0               // join request is rejected because the game is not in the proper state
547 #define JOIN_DENY_JR_TRACKER_INVAL      1               // join request is rejected because the game is an MT game and the passed player info is invalid
548 #define JOIN_DENY_JR_PASSWD                     2               // join request is rejected because the game is password protected and the password sent is incorrect
549 #define JOIN_DENY_JR_CLOSED                     3               // join request is rejected because the game is closed and is currently ingame
550 #define JOIN_DENY_JR_RANK_HIGH          4               // join request is rejected because the game is rank based and the passed rank is too high
551 #define JOIN_DENY_JR_RANK_LOW                   5               // join request is rejected because the game is rank based and the passed rank is too low
552 #define JOIN_DENY_JR_DUP                                6               // join request is denied because there is an exiting netplayer with matching characteristics
553 #define JOIN_DENY_JR_FULL                               7               // join request is denied because the game is full
554 #define JOIN_DENY_JR_TEMP_CLOSED                8               // join request is denied because the _forming_ netgame has been toggled closed
555 #define JOIN_DENY_JR_BANNED                     9               // join request is denied because the player has been banned for the duration of the game
556 #define JOIN_DENY_JR_NOOBS                              10              // join request is denied because observers are not allowed
557 #define JOIN_DENY_JR_INGAME_JOIN                11              // join request is denied because someone else is already ingame joining
558 #define JOIN_DENY_JR_BAD_VERSION                12              // incompatible version types
559 #define JOIN_QUERY_RESTRICTED                   13              // poll the host of the game to see if he accepts this player
560 #define JOIN_DENY_JR_TYPE                               14              // cannot ingame join anything but dogfight games
561
562 // repair info codes
563 #define REPAIR_INFO_BEGIN                       0x1             // server to client - set your REPAIRING flags
564 #define REPAIR_INFO_END                         0x2             // server to client - unset your REPAIRING flags
565 #define REPAIR_INFO_UPDATE                      0x3             // server to client - here's some repair update info (not currently used)
566 #define REPAIR_INFO_QUEUE                       0x4             // server to client - client is queued for rearming.
567 #define REPAIR_INFO_ABORT                       0x5             // server to client - client has aborted a rearm/repair
568 #define REPAIR_INFO_BROKEN                      0x6             // server to client - client is breaking repair -- might be reestablished
569 #define REPAIR_INFO_WARP_ADD            0x7             // server to client - add client onto list of people for arriving support ship
570 #define REPAIR_INFO_WARP_REMOVE 0x8             // server to client - remove client from list of people for arriving support ship
571 #define REPAIR_INFO_ONWAY                       0x9             // server to client - repair ship on way
572 #define REPAIR_INFO_KILLED                      0xa             // server to client - repair ship was killed on way to rearm player
573 #define REPAIR_INFO_COMPLETE            0xb             // server to client - repair of your ship is complete
574
575 // debris update codes
576 #define DEBRIS_UPDATE_UPDATE                    0x1             // update a piece
577 #define DEBRIS_UPDATE_REMOVE                    0x2             // remove a piece of debris
578 #define DEBRIS_UPDATE_NUKE                              0x3             // blow up a piece of debris
579 #define DEBRIS_UPDATE_CREATE_HULL       0x4             // create a piece of debris
580
581 // weapon select/ship select update packets
582 #define WSS_WEAPON_SELECT                       0x1             // ship select stuff
583 #define WSS_SHIP_SELECT                         0x2             // weapon select stuff
584
585 // accept packet codes
586 #define ACCEPT_INGAME                           (1<<0)  // accept the player as an ingame joiner
587 #define ACCEPT_HOST                                     (1<<1)  // accept the player as the host of the game
588 #define ACCEPT_OBSERVER                         (1<<2)  // accept the player as an observer
589 #define ACCEPT_CLIENT                           (1<<3)  // accept the player as a normal, non ingame join, non host player
590
591 // accept player data codes
592 #define APD_NEXT                                                0                       // there is still more player data
593 #define APD_END_PACKET                          1                       // end of this packet
594 #define APD_END_DATA                                    2                       // end of the data
595
596 // ingame ship request codes            
597 #define INGAME_SR_REQUEST                       0x1             // request for the ship with the given net signature
598 #define INGAME_SR_CONFIRM                       0x2             // confirmation to the client that he can use the requested ship
599 #define INGAME_SR_DENY                          0x3             // deny the request the ingame joiner made for the ship
600 #define INGAME_PLAYER_CHOICE            0x4             // sent to other players informing them of ingame joiners choice
601
602 // ai info update codes
603 #define AI_UPDATE_DOCK                          0x1             // server tells clients which ships are now docked
604 #define AI_UPDATE_UNDOCK                        0x2             // server tells clients which ships have undocked
605 #define AI_UPDATE_ORDERS                        0x3             // server tells clients about new AI order for the ship
606
607 // requests to the standalong
608 #define MISSION_LIST_REQUEST            0x1             // ask for list of missions
609 #define CAMPAIGN_LIST_REQUEST           0x2             // ask for list of campaigns
610
611 // asteroid stuff
612 #define ASTEROID_CREATE                         0x1             // create an asteroid
613 #define ASTEROID_THROW                          0x2             // throw an asteroid
614 #define ASTEROID_HIT                                    0x3             // asteroid hit occured
615
616 // commands for squadmate messages
617 #define SQUAD_MSG_SHIP                          0x1
618 #define SQUAD_MSG_WING                          0x2
619 #define SQUAD_MSG_ALL                           0x3
620 #define SQUAD_MSG_REINFORCEMENT 0x4
621
622 // SW_STD_QUERY codes
623 #define SW_STD_START                                    0x1             // from host to standalone saying "query the tracker"
624 #define SW_STD_OK                                               0x2             // from standalone to host - "everything is cool"
625 #define SW_STD_BAD                                      0x3             // from standalone to host - "everything is bad"
626
627 // stats block packet
628 #define STATS_MISSION                           0                       // all stats for the mission, for one player
629 #define STATS_ALLTIME                           1                       // alltime stats, for one player
630 #define STATS_MISSION_KILLS             2                       // mission kills and assists
631 #define STATS_DOGFIGHT_KILLS            3                       // same as mission kills, but also sends per-player kills
632
633
634 // ----------------------------------------------------------------------------------------
635
636
637 // ----------------------------------------------------------------------------------------
638 // Multiplayer structure definitions
639 //
640 //
641
642 // definition of header packet used in any protocol
643 typedef struct header {
644         int             bytes_processed;                                                                                        // used to determine how many bytes this packet was
645         ubyte           net_id[4];                                                                                                      // obtained from network layer header
646         ubyte           addr[6];                                                                                                                // obtained from network-layer header
647         short           port;                                                                                                                   // obtained from network-layer header
648         short           id;                                                                                                                     // will be stuffed with player_id (short)
649 } header;
650
651 // NETPLAYER INFORMATION THE SERVER AND THE INDIVIDUAL CLIENT MUST HAVE
652 typedef struct net_player_server_info {         
653         ping_struct             ping;                                                                                                   // evaluated by the ping module
654         int                             wing_index_backup;                                                              // in case of fail on the last packet
655         int                             wing_index;                                                                                     // index of the next wing data item to be sent
656         int                             ingame_join_flags;                                                              // status flags for an ingame joiner
657         int                             invul_timestamp;                                                                        // invulnerability flag timestamp (for respawning after dying)
658         button_info             last_buttons[BUTTON_INFO_SAVE_COUNT];           // button info for sending critical control packets to the server
659         int                             last_buttons_id[BUTTON_INFO_SAVE_COUNT];        //
660         fix                             last_buttons_time[BUTTON_INFO_SAVE_COUNT];//
661         int                             num_last_buttons;                                                                       //
662         fix                             last_full_update_time;                                                  // time when server last updated this player position/orientation
663         int                             xfer_handle;                                                                            // handle to the file xfer handle (-1 if no file xfer is taking place)
664         int                             kick_timestamp;                                                                 // timestamp with which we'll disconnect a player if he hasn't reponded to a kick packet
665         int                             kick_reason;                                                                            // reason he was kicked
666         int            voice_token_timestamp;                                                   // timestamp set when a player loses a token (so we can prevent him from getting it again too quickly)
667         int                             reliable_connect_time;                                                  // after sending an accept packet, wait for this long for the guy to connect on the reliable socket
668
669         // weapon select/linking information (maintained on the server and passed on respawn to all clients)
670         char                            cur_primary_bank;                                                                       // currently selected primary bank
671         char                            cur_secondary_bank;                                                             // currently selected secondary bank
672         ubyte                           cur_link_status;                                                                        // if (1<<0) - primaries linked. if (1<<1) - secondaries are linked
673
674         // information regarding the current view position of this player.
675         vector                  eye_pos;                                                                // eye position and orientation
676         matrix                  eye_orient;
677
678         // ets information
679         ushort                  ship_ets;                                                       // ets settings (sigh......)
680
681         // tracker information
682         int                             tracker_security_last;                  // this is the value returned when getting tracker data. it must be used when "sending" tracker data
683         unsigned int    tracker_checksum;                                       // tracker checksum
684
685         // common targeting information
686         int                             target_objnum;
687
688         // rate limiting information
689         int                             rate_stamp;                                                     // rate limiting timestamp
690         int                             rate_bytes;                                                     // bytes sent this "second"
691
692         // firing info (1<<0) for primary fire, (1<<1) for secondary fired, (1<<2) for countermeasure fired, (1<<3) for afterburner on
693         // basically, we set these bits if necessary between control info sends from the client. once sent, these values are
694         // cleared until the next send time
695         ubyte                           accum_buttons;                          
696         
697         // buffered packet info
698         ubyte                                   unreliable_buffer[MAX_PACKET_SIZE];     // buffer used to buffer unreliable packets before sending as a single UDP packet
699         int                                     unreliable_buffer_size;                                 // length (in bytes) of data in unreliable send_buffer
700         ubyte                                   reliable_buffer[MAX_PACKET_SIZE];       // buffer used to buffer reliable packets before sending as a single UDP packet
701         int                                     reliable_buffer_size;                                   // length (in bytes) of data in reliable send_buffer
702 } net_player_server_info;
703
704 // NETPLAYER INFORMATION ALL COMPUTERS IN THE GAME MUST HAVE
705 typedef struct net_player_info {
706         p_object                        *p_objp;                                                                // pointer to parse object for my ship -- used with respawns
707         int                             team;                                                                   // valid for team v. team games -- which team is this guy on
708         int                             ship_index;                                                     // index into the ship choices in team select/ship select (out of 12 choices)
709         int                             ship_class;                                                     // the ship class of the players ship
710         multi_local_options options;                                            // players options settings     
711         net_addr_t                      addr;
712         char                            pxo_squad_name[LOGIN_LEN];              // PXO squadron name
713 } net_player_info;
714
715 // NETPLAYER COMMON INFORMATION
716 typedef struct net_player {
717         player_t                        *player;                                                                // stuff pertaining directly to the player (callsign, etc).
718         short                           player_id;                                                      // player id (always use this instead of ip address for identification purposes)
719         int                             tracker_player_id;            // the tracker id for this player, only matters in
720                                                                                                                                 // tracker games.       
721         int                             flags;                                                          // tells us interesting information about this player
722         int                             state;                                                          // one of the NETGAME_STATE_* flags below -- used for sequencing
723         PSNET_SOCKET_RELIABLE   reliable_socket;                // reliable socket to server
724         
725         ushort                  client_cinfo_seq;                                       // sequence # for client control info packets
726         ushort                  client_server_seq;                              // sequence # for incoming object update packets                
727         
728         fix                             last_heard_time;                                        // time when last heard from this player
729
730         net_player_server_info  s_info;                                 // server critical info
731         net_player_info                 p_info;                                 // player critical info
732
733         // bytes sent and received
734         // SERVER-side
735         int                             sv_bytes_sent;                                          // bytes we've sent to this guy (on the server) 
736         int                             sv_last_pl;                                                     // packet loss
737
738         // CLIENT-side
739         int                             cl_bytes_recvd;                                 // bytes we've received (as a client)           
740         int                             cl_last_pl;                                                     // packet loss
741 } net_player;
742
743 // structure which describes the state of the multiplayer game currently being played
744 typedef struct netgame_info {
745         char            name[MAX_GAMENAME_LEN+1];               // name of the netgame (host can set this!)
746         char            mission_name[NAME_LENGTH+1];    // current mission name (filename)
747         char            title[NAME_LENGTH+1];                   // title of the mission (as appears in the mission file)
748         char            campaign_name[NAME_LENGTH+1];   // current campaign name        
749         char            passwd[MAX_PASSWD_LEN+1];               // password for the game
750         int             version_info;                                           // version info for this game.
751         int             type_flags;                                                     // see NG_TYPE_* defines
752         int             mode;                                                                   // see NG_MODE_* defines
753         int             flags;                                                          // see NG_FLAG_* defines
754         int             rank_base;                                                      // used to compare against connecting players (rank above/rank below)   
755         int      max_players;           
756         int             game_state;                                                     // state (briefing, in mission, etc) this game is in
757         int             security;                                                       // some random number that should hopefully be unique for each game started
758                                                                                                                 // I'm also using this value to use as a starting base for the net_signature
759                                                                                                                 // for object synchronization.
760         float    ping_time;                                                     // ping time to this server
761         net_addr_t      server_addr;                                            // address of the server
762         net_player *host;
763         net_player *server;                                                     // pointer to the server                
764
765         uint respawn;
766
767         int campaign_mode;                                                      // 0 == single mission mode, 1 == starting campaign
768
769         ushort   server_update_seq;                             // the current object update reference count (server-side only)
770         int      server_update_frame_ref;               // used to determine when we should increment the server_update_seq value
771
772         multi_server_options options;                           // server options settings
773
774         ubyte           debug_flags;                                            // special debug flags (see NETD_FLAG_* defines)
775 } netgame_info;
776
777 // netgame debug flags
778 // #define NETD_FLAG_CLIENT_FIRING                              (1<<0)          // client side firing of primaries and countermeasures
779 // #define NETD_FLAG_CLIENT_NODAMAGE                    (1<<1)          // client never applies damage himself. he simply waits for blanket updates
780 #define NETD_FLAG_OBJ_NEW                                               (1<<2)          // new style of object updating
781
782 // structure for active games -- kind of like Descent, but using the linked list thing, we will
783 // be able to support many more games in the list.
784 #define AG_FLAG_COOP                                                            (1<<0)                  // is a coop game
785 #define AG_FLAG_TEAMS                                                   (1<<1)                  // is a team vs. team game
786 #define AG_FLAG_DOGFIGHT                                                (1<<2)                  // is a dogfight game
787 #define AG_FLAG_FORMING                                                 (1<<3)                  // game is currently forming
788 #define AG_FLAG_BRIEFING                                                (1<<4)                  // game is in the briefing state
789 #define AG_FLAG_DEBRIEF                                                 (1<<5)                  // game is in the debriefing state
790 #define AG_FLAG_PAUSE                                                   (1<<6)                  // game is paused
791 #define AG_FLAG_IN_MISSION                                              (1<<7)                  // game is in mission
792 #define AG_FLAG_PASSWD                                                  (1<<8)                  // is a password protected game
793 #define AG_FLAG_STANDALONE                                              (1<<9)                  // this is a standalone server
794 #define AG_FLAG_CAMPAIGN                                                (1<<10)                 // the server is playing in campaign mode
795
796 // flags for defining the connection speed
797 #define AG_FLAG_CONNECTION_SPEED_MASK           ((1<<12)|(1<<13)|(1<<14))       // mask for the connection speed
798
799 #define AG_FLAG_VALID_MISSION                                   (1<<15)                 // the mission is a "valid" tracker mission
800
801 #define AG_FLAG_CONNECTION_BIT                          12                                              // number of bits to shift right or left to get speed
802
803 #define AG_FLAG_TYPE_MASK                                               (AG_FLAG_COOP|AG_FLAG_TEAMS|AG_FLAG_DOGFIGHT)
804 #define AG_FLAG_STATE_MASK                                              (AG_FLAG_FORMING|AG_FLAG_BRIEFING|AG_FLAG_DEBRIEF|AG_FLAG_PAUSE|AG_FLAG_IN_MISSION)
805
806 typedef struct active_game {
807         active_game             *next, *prev;                           // next and previous elements in the list       
808         int                             heard_from_timer;                       // when we last heard from the game     
809         
810         char            name[MAX_GAMENAME_LEN+1];
811         char            mission_name[NAME_LENGTH+1];
812         char            title[NAME_LENGTH+1];   
813         ubyte           num_players;
814         net_addr_t      server_addr;    
815         ushort  flags;                                                          // see above AG_FLAG_* defines
816         ubyte           version,comp_version;                   // version and compatible version
817         ping_struct ping;                                                               // ping time to the server
818 } active_game;
819
820 // permanent server list (read from tcp.cfg)
821 typedef struct server_item {
822         server_item *next, *prev;
823
824         net_addr_t server_addr;
825 } server_item;
826
827 // sent to the server on a join request with various data
828 #define JOIN_FLAG_AS_OBSERVER                   (1<<0)  // wants to join as an aboserver
829 #define JOIN_FLAG_HAS_CD                                (1<<1)  // currently has a CD in the drive
830 #define JOIN_FLAG_HAXOR                                 (1<<2)  // if the player has hacked data
831 typedef struct join_request {
832         char passwd[MAX_PASSWD_LEN+1];                          // password for a password protected game
833         char callsign[CALLSIGN_LEN+1];                          // player's callsign
834         char image_filename[MAX_FILENAME_LEN+1];        // player's image filename
835         char squad_filename[MAX_FILENAME_LEN+1];        // player's squad filename      
836         ubyte player_rank;                                                              // the rank of the requesting player
837         ubyte flags;                                                                            // misc flags associated with this guy
838         int tracker_id;                                                                 // player's tracker ID #
839         multi_local_options player_options;                     // player's options
840         ubyte version, comp_version;                                    // local version and comp_version
841
842         // multiplayer squad war info
843         char pxo_squad_name[LOGIN_LEN];                         // squad name
844 } join_request;
845
846 // network buffer for sending and receiving packets
847 typedef struct network_buffer {
848         int     size;                                                                           // size of the buffer
849         ubyte   data[MAX_PACKET_SIZE];                          // MAX_PACKET_SIZE from psnet.h
850 } network_buffer;
851 // -------------------------------------------------------------------------------------
852
853
854 // ----------------------------------------------------------------------------------------
855 // Multiplayer structure flags/settings
856 //
857 //
858
859 // flags used for the net_player structure
860 #define NETINFO_FLAG_CONNECTED                          (1<<0)          // if this player connected
861 #define NETINFO_FLAG_AM_MASTER                          (1<<1)          // is this player the master
862 #define NETINFO_FLAG_MT_CONNECTED                       (1<<2)      // if everything is hunky dory with the tracker connection
863 #define NETINFO_FLAG_MT_FAILED                          (1<<3)      // all attempts to connect have failed
864 #define NETINFO_FLAG_MT_STARTUP                         (1<<4)      // the initial state (ie, we haven't tried anything yet)
865 #define NETINFO_FLAG_GAME_HOST                          (1<<5)      // I'm the host
866 #define NETINFO_FLAG_INGAME_JOIN                                (1<<6)      // means he is still in the process of joining ingame
867 #define NETINFO_FLAG_OBSERVER                                   (1<<7)      // means he's an observer
868 #define NETINFO_FLAG_OBS_PLAYER                         (1<<8)      // means he's an observer, but he was formerly a player (should show his stats)
869 #define NETINFO_FLAG_LIMBO                                              (1<<9)      // (client side) means he has to choose whether to be an observer or quit (no more respawns)
870 #define NETINFO_FLAG_MISSION_OK                         (1<<10)     // this client's mission has been verified
871 #define NETINFO_FLAG_RESPAWNING                         (1<<11)     // so that we wait on a keypress, or other user input before respawning
872 #define NETINFO_FLAG_DO_NETWORKING                      (1<<12)         // set when we can send/receive data
873 #define NETINFO_FLAG_TEAM_LOCKED                                (1<<13)         // if this is set, only the host can modify the team settings for this player
874 #define NETINFO_FLAG_TEAM_CAPTAIN                       (1<<14)         // this player is the captain of his team
875 #define NETINFO_FLAG_KICKED                                     (1<<15)         // this player was kicked
876 #define NETINFO_FLAG_ACCEPT_INGAME                      (1<<16)         // accepted ingame
877 #define NETINFO_FLAG_ACCEPT_HOST                                (1<<17)         // accetped as host
878 #define NETINFO_FLAG_ACCEPT_OBSERVER            (1<<18)         // accepted as observer
879 #define NETINFO_FLAG_ACCEPT_CLIENT                      (1<<19)         // accepted as client
880 #define NETINFO_FLAG_WARPING_OUT                                (1<<20)         // clients keep track of this for themselves to know if they should be leaving
881 #define NETINFO_FLAG_HAS_CD                                     (1<<21)         // the player has a CD in the drive
882 #define NETINFO_FLAG_RELIABLE_CONNECTED (1<<22)         // reliable socket is now active
883 #define NETINFO_FLAG_MT_GET_FAILED                      (1<<23)         // set during MT stats update process indicating we didn't properly get his stats
884 #define NETINFO_FLAG_MT_SEND_FAILED                     (1<<24)         // set during MT stats update process indicating we didn't properly send his stats
885 #define NETINFO_FLAG_MT_DONE                                    (1<<25)         // set when a player has been processed for stats (fail, succeed, or otherwise)
886 #define NETINFO_FLAG_HAXOR                                              (1<<26)         // the player has some form of hacked client data
887
888 #define NETPLAYER_IS_OBSERVER(player)           (player->flags & (NETINFO_FLAG_OBSERVER|NETINFO_FLAG_OBS_PLAYER))
889 #define NETPLAYER_IS_DEAD(player)                       (player->flags & (NETINFO_FLAG_LIMBO|NETINFO_FLAG_RESPAWNING))
890
891 // netgame modes
892 #define NG_MODE_OPEN                                                            1                               // an open game
893 #define NG_MODE_CLOSED                                                  2                               // a closed game
894 #define NG_MODE_PASSWORD                                                3                               // a password protected game
895 #define NG_MODE_RESTRICTED                                              4                               // a restricted game
896 #define NG_MODE_RANK_ABOVE                                              5                               // ranks above a certain rank are allowed
897 #define NG_MODE_RANK_BELOW                                              6                               // ranks below a certain rank are allowed
898
899 // netgame option flags
900 #define NG_FLAG_TEMP_CLOSED                                     (1<<0)          // a forming netgame is temporarily closed (should not be checked otherwise)
901 #define NG_FLAG_SERVER_LOST                                     (1<<1)          // client has temporarily lost contact with the server
902 #define NG_FLAG_INGAME_JOINING                          (1<<2)          // someone is ingame joining.
903 #define NG_FLAG_INGAME_JOINING_CRITICAL (1<<3)          // someone is ingame joining and at the critical point where we cannot do certain things.
904 #define NG_FLAG_STORED_MT_STATS                         (1<<4)          // stored tracker stats in the debriefing already
905 #define NG_FLAG_HACKED_SHIPS_TBL                                (1<<5)          // set when the server is playing with a hacked ships.tbl (only needed to notify hosts playing on a standalone)
906 #define NG_FLAG_HACKED_WEAPONS_TBL                      (1<<6)          // set when the server is playing with a hacked weapons.tbl (only needed to notify hosts playing on a standalone)
907
908 // netgame type flags
909 #define NG_TYPE_COOP                                                            (1<<0)          // cooperative mode
910 #define NG_TYPE_TVT                                                             (1<<1)          // team vs. team mode
911 #define NG_TYPE_SW                                                              (1<<2)          // squad war
912 #define NG_TYPE_TEAM                                                            ( NG_TYPE_TVT | NG_TYPE_SW )
913 #define NG_TYPE_DOGFIGHT                                                (1<<3)          // plain old dogfight mode
914
915 // state defines for netgame states
916 #define NETGAME_STATE_FORMING                                   1                               // players are joining, host is selecting missions, etc
917 #define NETGAME_STATE_BRIEFING                          2                               // players are reading the mission briefing
918 #define NETGAME_STATE_IN_MISSION                                3                               // the mission itself is being played
919 #define NETGAME_STATE_SERVER_TRANSFER           4                               // server status is being transferred from one computer to another
920 #define NETGAME_STATE_PAUSED                                    5                               // the netgame is paused
921 #define NETGAME_STATE_DEBRIEF                                   6                               // the debriefing screen                        
922 #define NETGAME_STATE_MISSION_SYNC                      7                               // client/server data sync screens before and after the briefing stage
923 #define NETGAME_STATE_ENDGAME                                   8                               // game is moving from gameplay to the debriefing state
924 #define NETGAME_STATE_STD_HOST_SETUP            9                               // the host is on the setup netgame screen for the standalone server
925 #define NETGAME_STATE_HOST_SETUP                                10                              // the host is on the setup netgame screen _non_ standalone
926
927 // state defines for netplayer states
928 #define NETPLAYER_STATE_JOINING                         0                               // joining the netgame
929 #define NETPLAYER_STATE_JOINED                          1                               // has joined and opened a reliable socket connection
930 #define NETPLAYER_STATE_MISSION_LOADING 2                               // in the process of loading the mission
931 #define NETPLAYER_STATE_MISSION_LOADED          3                               // mission loaded
932 #define NETPLAYER_STATE_BRIEFING                                4                               // in the briefing
933 #define NETPLAYER_STATE_SHIP_SELECT                     5                               // in the ship selection screen
934 #define NETPLAYER_STATE_WEAPON_SELECT           6                               // in the weapon selection screen
935 #define NETPLAYER_STATE_DATA_LOAD                       7                               // loading specific data (textures, etc)
936 #define NETPLAYER_STATE_WAITING                         8                               // waiting to do something (like enter the mission)
937 #define NETPLAYER_STATE_SLOT_ACK                                9                               // got player ship slot packets
938 #define NETPLAYER_STATE_IN_MISSION                      10                              // in the mission itself
939 #define NETPLAYER_STATE_INGAME_SHIPS            11                              // player is receiving ingame join ship data
940 #define NETPLAYER_STATE_INGAME_WINGS            12                              // player is receiving ingame join wing data
941 #define NETPLAYER_STATE_INGAME_RPTS                     13                              // player is receiving ingame join respawn data
942 #define NETPLAYER_STATE_INGAME_SHIP_SELECT 14                   // player is in the ship select screen for ingame join
943 #define NETPLAYER_STATE_DEBRIEF                         15                              // player is in the debrief state (screen)
944 #define NETPLAYER_STATE_MISSION_SYNC            16                              // player is in the mission sync screen
945 #define NETPLAYER_STATE_STD_HOST_SETUP          17                              // the host is on the setup netgame screen for the standalone server
946 #define NETPLAYER_STATE_HOST_SETUP                      18                              // the host is on the setup netgame screen _non_ standalone
947 #define NETPLAYER_STATE_SETTINGS_ACK            19                              // the player has received the player settings data for all players
948 #define NETPLAYER_STATE_SLOTS_ACK                       20                              // the player has received wss slots data (ingame join only)
949 #define NETPLAYER_STATE_POST_DATA_ACK           21                              // the player has received the post briefing data block
950 #define NETPLAYER_STATE_WSS_ACK                         22                              // have received weapon slot information
951 #define NETPLAYER_STATE_FLAG_ACK                                23                              // the player has received his flag change information
952 #define NETPLAYER_STATE_MT_STATS                                24                              // the server is in the process of requesting or updating stats from the MT
953 #define NETPLAYER_STATE_MISSION_XFER            25                              // the player is in the process of receiving a mission file
954 #define NETPLAYER_STATE_INGAME_STUFF            26                              // received ingame "stuff"  happens just before ship selection
955 #define NETPLAYER_STATE_DEBRIEF_ACCEPT          27                              // the player has hit the accept button in the debrief and is good to go
956 #define NETPLAYER_STATE_DEBRIEF_REPLAY          28                              // set on the host instead of NETPLAYER_STATE_DEBRIEF_ACCEPT to indicate he wants to replay the mission
957 #define NETPLAYER_STATE_CPOOL_ACK                       29                              // player has acked all campaign pool status data
958 #define NETPLAYER_STATE_INGAME_CINFO            30                              // player has received campaign information (ingame join only)
959
960 // defines for connection speed
961 #define CONNECTION_SPEED_NONE                                   -1                              // not really used except for error checking
962
963 #define CONNECTION_SPEED_288                                    0
964 #define CONNECTION_SPEED_56K                                    1
965 #define CONNECTION_SPEED_SISDN                          2
966 #define CONNECTION_SPEED_CABLE                          3
967 #define CONNECTION_SPEED_T1                                     4
968
969 // use this to check and see whether a netgame is anywhere in mission (paused, etc, etc)
970 #define MULTI_IN_MISSION                                                ( (Netgame.game_state == NETGAME_STATE_IN_MISSION) || (Netgame.game_state == NETGAME_STATE_PAUSED) )
971
972 extern int Multi_connection_speed;
973
974 // -------------------------------------------------------------------------------------
975
976
977 // ----------------------------------------------------------------------------------------
978 // Multiplayer global vars
979 //
980 //
981
982 // netplayer vars
983 extern net_player Net_players[MAX_PLAYERS];                                             // array of all netplayers in the game
984 extern net_player *Net_player;                                                                          // pointer to console's net_player entry
985
986 // network object management
987 #define SHIP_SIG_MIN                            1
988 #define SHIP_SIG_MAX                            (0x2fff)
989
990 #define STANDALONE_SHIP_SIG     (SHIP_SIG_MAX+1)
991 #define REAL_SHIP_SIG_MAX               (0x3fff)
992
993 #define DEBRIS_SIG_MIN                  (REAL_SHIP_SIG_MAX+1)
994 #define DEBRIS_SIG_MAX                  (0x5fff)
995
996 #define ASTEROID_SIG_MIN                (DEBRIS_SIG_MAX+1)
997 #define ASTEROID_SIG_MAX                (0x7fff)
998
999 #define NPERM_SIG_MIN                   (ASTEROID_SIG_MAX+1)
1000 #define NPERM_SIG_MAX                   (0xffff)
1001
1002 extern ushort Next_ship_signature;                                                                      // next network signature to assign to an object
1003 extern ushort Next_asteroid_signature;                                                          // next asteroid signature
1004 extern ushort Next_non_perm_signature;                                                          // next non-permanent signature
1005 extern ushort Next_debris_signature;                                                            // next debris signature
1006
1007 // netgame vars
1008 extern netgame_info Netgame;                                                                                    // netgame information
1009 extern int Multi_mission_loaded;                                                                                // flag, so that we dont' load the mission more than once client side
1010 extern ushort Multi_ingame_join_sig;                                                                    // signature for the player obj for use when joining ingame
1011 extern int Multi_button_info_ok;                                                                                // flag saying it is ok to apply critical button info on a client machine
1012 extern int Multi_button_info_id;                                                                                // identifier of the stored button info to be applying
1013
1014 // low level networking vars
1015 extern int ADDRESS_LENGTH;                                                                                              // will be 6 for IPX, 4 for IP
1016 extern int PORT_LENGTH;                                                                                                 // will be 2 for IPX, 2 for IP
1017 extern int HEADER_LENGTH;                                                                                               // 1 byte (packet type)
1018
1019 // misc data
1020 extern active_game* Active_game_head;                                                           // linked list of active games displayed on Join screen
1021 extern int Active_game_count;                                                                                   // for interface screens as well
1022 extern CFILE* Multi_chat_stream;                                                                                // for streaming multiplayer chat strings to a file
1023 extern int Multi_has_cd;                                                                                                // if this machine has a cd or not (call multi_common_verify_cd() to set this)
1024 extern int Multi_num_players_at_start;                                                          // the # of players present (kept track of only on the server) at the very start of the mission
1025 extern short Multi_id_num;                                                                                              // for assigning player id #'s
1026
1027 // permanent server list
1028 extern server_item* Game_server_head;                                                           // list of permanent game servers to be querying
1029
1030 // restricted game vars
1031 #define MULTI_QUERY_RESTR_STAMP                 5000                                            // 5 seconds to reply
1032 #define MULTI_JOIN_RESTR_MODE_1                 0                                                       // mode 1 - normal restricted join
1033 #define MULTI_JOIN_RESTR_MODE_2                 1                                                       // mode 2 - team vs. team, only team 0 has ships
1034 #define MULTI_JOIN_RESTR_MODE_3                 2                                                       // mode 3 - team vs. team, only team 1 has ships
1035 #define MULTI_JOIN_RESTR_MODE_4                 3                                                       // mode 4 - team vs. team, both teams have ships
1036
1037 extern int Multi_restr_query_timestamp;                                                 // timestamp for querying the host to see if he will allow a new player to join ingame
1038 extern join_request Multi_restr_join_request;                                   // join request for the query
1039 extern net_addr_t Multi_restr_addr;                                                                     // net address of the join request
1040 extern int Multi_join_restr_mode;                                                                       // what mode we're in
1041
1042 // non API master tracker vars
1043 extern char Multi_tracker_login[100];
1044 extern char Multi_tracker_passwd[100];
1045 extern char Multi_tracker_squad_name[100];
1046 extern int Multi_tracker_id;
1047 extern char Multi_tracker_id_string[255];
1048
1049 // current file checksum
1050 extern ushort Multi_current_file_checksum;
1051 extern int Multi_current_file_length;
1052
1053
1054 // ----------------------------------------------------------------------------------------
1055 // Multiplayer main functions
1056 //
1057 //
1058
1059 // module handling functions -------------------
1060
1061 // called at game startup
1062 void multi_init();
1063
1064 // called whenever a netgame is started
1065 void multi_level_init();
1066
1067 // reset all relevant main networking loop timestamps
1068 void multi_reset_timestamps();
1069
1070 // returns true is server hasn't been heard from in N seconds. false otherwise
1071 int multi_client_server_dead();
1072
1073
1074 // netgame data processing functions -----------
1075
1076 // do all network processing for this game frame
1077 void multi_do_frame();
1078
1079 // analog of multi_do_frame() called when netgame is in the pause state
1080 void multi_pause_do_frame();
1081
1082 // process all incoming packets
1083 // void multi_process_bigdata(ubyte* data, int size, net_addr* from_addr);
1084
1085 // process all reliable socket details
1086 void multi_process_reliable_details();
1087
1088
1089 // standalone handling functions ---------------
1090
1091 // initialize the standalone
1092 void standalone_main_init();
1093
1094 // do frame for the main standalone state
1095 void standalone_main_do();
1096
1097 // close for the main standalone state
1098 void standalone_main_close();
1099
1100 // reset all standalone stuff, including gui, networking, netgame, etc, and go into the main state
1101 void multi_standalone_reset_all();
1102
1103 // init for the wait mode of the standalone (when waiting for players to finish the briefing)
1104 void multi_standalone_wait_init();
1105
1106 // do frame for the standalone wait state (when waiting for players to finish the briefing)
1107 void multi_standalone_wait_do();
1108
1109 // close for the standalone wait state (when waiting for players to finish the briefing)
1110 void multi_standalone_wait_close();
1111
1112 // init for the standalone postgame state (when players are in the debriefing)
1113 void multi_standalone_postgame_init();
1114
1115 // do frame for the standalone postgame state (when players are in the debriefing)
1116 void multi_standalone_postgame_do();
1117
1118 // close for the standalone postgame state (when players are in the debriefing_
1119 void multi_standalone_postgame_close();
1120
1121 #endif
1122