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