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