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