2 * Copyright (C) Volition, Inc. 1999. All rights reserved.
4 * All source code herein is the property of Volition, Inc. You may not sell
5 * or otherwise commercially exploit the source or things you created based on
10 * $Logfile: /Freespace2/code/Network/Multi.cpp $
15 * C file that contains high-level multiplayer functions
18 * Revision 1.5 2002/06/09 04:41:23 relnev
19 * added copyright header
21 * Revision 1.4 2002/05/27 00:40:47 theoddone33
22 * Fix net_addr vs net_addr_t
24 * Revision 1.3 2002/05/26 20:22:48 theoddone33
25 * Most of network/ works
27 * Revision 1.2 2002/05/07 03:16:47 theoddone33
28 * The Great Newline Fix
30 * Revision 1.1.1.1 2002/05/03 03:28:10 root
34 * 47 9/15/99 1:45a Dave
35 * Don't init joystick on standalone. Fixed campaign mode on standalone.
36 * Fixed no-score-report problem in TvT
38 * 46 8/24/99 1:49a Dave
39 * Fixed client-side afterburner stuttering. Added checkbox for no version
40 * checking on PXO join. Made button info passing more friendly between
43 * 45 8/22/99 5:53p Dave
44 * Scoring fixes. Added self destruct key. Put callsigns in the logfile
45 * instead of ship designations for multiplayer players.
47 * 44 8/22/99 1:19p Dave
48 * Fixed up http proxy code. Cleaned up scoring code. Reverse the order in
49 * which d3d cards are detected.
51 * 43 8/19/99 10:59a Dave
52 * Packet loss detection.
54 * 42 8/16/99 4:05p Dave
55 * Big honking checkin.
57 * 41 8/06/99 12:34a Dave
58 * Be more careful about resetting timestamps.
60 * 40 8/04/99 2:24a Dave
61 * Fixed escort gauge ordering for dogfight.
63 * 39 7/26/99 5:50p Dave
64 * Revised ingame join. Better? We'll see....
66 * 38 7/08/99 10:53a Dave
67 * New multiplayer interpolation scheme. Not 100% done yet, but still
68 * better than the old way.
70 * 37 7/06/99 4:24p Dave
71 * Mid-level checkin. Starting on some potentially cool multiplayer
74 * 36 7/03/99 5:50p Dave
75 * Make rotated bitmaps draw properly in padlock views.
77 * 35 6/21/99 7:24p Dave
78 * netplayer pain packet. Added type E unmoving beams.
80 * 34 6/07/99 9:51p Dave
81 * Consolidated all multiplayer ports into one.
83 * 33 6/04/99 9:52a Dave
84 * Fixed some rendering problems.
86 * 32 5/22/99 6:05p Dave
87 * Fixed a few localization # problems.
89 * 31 5/22/99 5:35p Dave
90 * Debrief and chatbox screens. Fixed small hi-res HUD bug.
92 * 30 5/14/99 1:59p Andsager
93 * Multiplayer message for subsystem cargo revealed.
95 * 29 4/29/99 2:29p Dave
96 * Made flak work much better in multiplayer.
98 * 28 4/28/99 11:13p Dave
99 * Temporary checkin of artillery code.
101 * 27 4/25/99 7:43p Dave
102 * Misc small bug fixes. Made sun draw properly.
104 * 26 4/25/99 3:02p Dave
105 * Build defines for the E3 build.
107 * 25 4/12/99 10:07p Dave
108 * Made network startup more forgiving. Added checkmarks to dogfight
109 * screen for players who hit commit.
111 * 24 4/09/99 2:21p Dave
112 * Multiplayer beta stuff. CD checking.
114 * 23 3/19/99 9:51a Dave
115 * Checkin to repair massive source safe crash. Also added support for
116 * pof-style nebulae, and some new weapons code.
118 * 23 3/11/99 5:53p Dave
119 * More network optimization. Spliced in Dell OEM planet bitmap crap.
121 * 22 3/10/99 6:50p Dave
122 * Changed the way we buffer packets for all clients. Optimized turret
123 * fired packets. Did some weapon firing optimizations.
125 * 21 3/09/99 6:24p Dave
126 * More work on object update revamping. Identified several sources of
127 * unnecessary bandwidth.
129 * 20 3/08/99 7:03p Dave
130 * First run of new object update system. Looks very promising.
132 * 19 3/02/99 4:40p Jasons
133 * Be more careful when calling server-lost-contact popup (make sure other
134 * popups aren't active)
136 * 18 3/01/99 7:39p Dave
137 * Added prioritizing ship respawns. Also fixed respawns in TvT so teams
138 * don't mix respawn points.
140 * 17 2/23/99 2:29p Dave
141 * First run of oldschool dogfight mode.
143 * 16 2/19/99 2:55p Dave
144 * Temporary checking to report the winner of a squad war match.
146 * 15 2/17/99 2:10p Dave
147 * First full run of squad war. All freespace and tracker side stuff
150 * 14 2/12/99 6:16p Dave
151 * Pre-mission Squad War code is 95% done.
153 * 13 2/11/99 3:08p Dave
154 * PXO refresh button. Very preliminary squad war support.
156 * 12 1/14/99 12:48a Dave
157 * Todo list bug fixes. Made a pass at putting briefing icons back into
158 * FRED. Sort of works :(
160 * 11 1/12/99 5:45p Dave
161 * Moved weapon pipeline in multiplayer to almost exclusively client side.
162 * Very good results. Bandwidth goes down, playability goes up for crappy
163 * connections. Fixed object update problem for ship subsystems.
165 * 10 12/14/98 12:13p Dave
166 * Spiffed up xfer system a bit. Put in support for squad logo file xfer.
169 * 9 12/03/98 5:22p Dave
170 * Ported over Freespace 1 multiplayer ships.tbl and weapons.tbl
173 * 8 11/19/98 4:19p Dave
174 * Put IPX sockets back in psnet. Consolidated all multiplayer config
177 * 7 11/19/98 8:03a Dave
178 * Full support for D3-style reliable sockets. Revamped packet lag/loss
179 * system, made it receiver side and at the lowest possible level.
181 * 6 11/17/98 11:12a Dave
182 * Removed player identification by address. Now assign explicit id #'s.
184 * 5 11/12/98 12:13a Dave
185 * Tidied code up for multiplayer test. Put in network support for flak
193 #include <winsock2.h>
198 #include "multiutil.h"
199 #include "multimsgs.h"
201 #include "linklist.h"
207 #include "missionload.h"
208 #include "missionparse.h"
209 #include "missionshipchoice.h"
210 #include "gamesequence.h"
211 #include "freespace.h"
216 #include "stand_server.h"
217 #include "multi_xfer.h"
220 #include "multilag.h"
221 #include "multiutil.h"
222 #include "multi_ingame.h"
227 #include "multiteamselect.h"
228 #include "multi_data.h"
229 #include "multi_kick.h"
230 #include "multi_campaign.h"
231 #include "multi_voice.h"
232 #include "multi_team.h"
233 #include "multi_respawn.h"
234 #include "multi_pmsg.h"
235 #include "multi_endgame.h"
236 #include "missiondebrief.h"
237 #include "multi_pause.h"
238 #include "multi_obj.h"
239 #include "missiongoals.h"
240 #include "multi_log.h"
241 #include "multi_rate.h"
242 #include "hudescort.h"
243 #include "alphacolors.h"
244 #include "osregistry.h"
245 #include "multi_fstracker.h"
248 // ----------------------------------------------------------------------------------------
249 // Basic module scope defines
254 // #define NETGAME_SEND_TIME 1000 // time between sending netgame update packets
255 // #define STATE_SEND_TIME 1000 // time between sending netplayer state packets
256 // #define GAMEINFO_SEND_TIME 3000 // time between sending game information packets
257 // #define PING_SEND_TIME 2000 // time between player pings
258 // #define INGAME_UPDATE_TIME 1000 // time limit between ingame join operations
259 #define NETGAME_SEND_TIME 2 // time between sending netgame update packets
260 #define STATE_SEND_TIME 2 // time between sending netplayer state packets
261 #define GAMEINFO_SEND_TIME 3 // time between sending game information packets
262 #define PING_SEND_TIME 2 // time between player pings
263 #define BYTES_SENT_TIME 5 // every five seconds
266 #define CULL_ZOMBIE_TIME 1000 // zombies are checked for at this interval (in milliseconds)
268 // object update stuff
269 #define SEND_POS_INTERVAL 30 // min time in milliseconds between sending position updates
271 // local network buffer stuff
272 #define MAX_NET_BUFFER (1024 * 16) // define and variable declaration for our local tcp buffer
273 #define NUM_REENTRANT_LEVELS 3
275 // time (in fixed seconds) to put up dialog about no contect from server
276 #define MULTI_SERVER_MAX_TIMEOUT (F1_0 * 4) // after this number of milliseoncds, stop client simulation
277 #define MULTI_SERVER_MAX_TIMEOUT_LARGE (F1_0 * 40) // done anytime not in mission
278 #define MULTI_SERVER_WAIT_TIME (F1_0 * 60) // wait 60 seconds to reconnect with the server
279 #define MULTI_SERVER_GONE 1
280 #define MULTI_SERVER_ALIVE 2
282 #define DISCONNECT_TIMEOUT (F1_0 * 10) // 10 seconds to timeout someone who cannot connnect
284 // define for when to show "slow network" icon
285 #define MULTI_SERVER_SLOW_PING_TIME 700 // when average ping time to server reaches this -- display hud icon
287 // update times for clients ships based on object update level
288 #define MULTI_CLIENT_UPDATE_TIME 333
290 int Multi_display_netinfo = 1;
292 // ----------------------------------------------------------------------------------------
298 net_player Net_players[MAX_PLAYERS]; // array of all netplayers in the game
299 net_player *Net_player; // pointer to console's net_player entry
301 // network object management
302 ushort Next_ship_signature; // next permanent network signature to assign to an object
303 ushort Next_asteroid_signature; // next signature for an asteroid
304 ushort Next_non_perm_signature; // next non-permanent network signature to assign to an object
305 ushort Next_debris_signature; // next debris signature
308 netgame_info Netgame; // netgame information
309 int Multi_mission_loaded = 0; // flag, so that we dont' load the mission more than once client side
310 int Ingame_join_net_signature = -1; // signature for the player obj for use when joining ingame
311 int Multi_button_info_ok = 0; // flag saying it is ok to apply critical button info on a client machine
312 int Multi_button_info_id = 0; // identifier of the stored button info to be applying
314 // low level networking vars
315 const int HEADER_LENGTH = 1; // 1 byte (packet type)
318 active_game* Active_game_head; // linked list of active games displayed on Join screen
319 int Active_game_count; // for interface screens as well
320 CFILE* Multi_chat_stream; // for streaming multiplayer chat strings to a file
321 int Multi_has_cd = 0; // if this machine has a cd or not (call multi_common_verify_cd() to set this)
322 int Multi_connection_speed; // connection speed of this machine.
323 int Multi_num_players_at_start = 0; // the # of players present (kept track of only on the server) at the very start of the mission
324 short Multi_id_num = 0; // for assigning player id #'s
326 // permanent server list
327 server_item* Game_server_head; // list of permanent game servers to be querying
330 time_t Netgame_send_time = -1; // timestamp used to send netgame info to players before misison starts
331 time_t State_send_time = -1; // timestamp used to send state information to the host before a mission starts
332 time_t Gameinfo_send_time = -1; // timestamp used by master to send game information to clients
333 time_t Next_ping_time = -1; // when we should next ping all
334 int Multi_server_check_count = 0; // var to keep track of reentrancy when checking server status
335 time_t Next_bytes_time = -1; // bytes sent
337 // how often each player gets updated
338 int Multi_client_update_times[MAX_PLAYERS]; // client update packet timestamp
340 // local network buffer data
341 static ubyte net_buffer[NUM_REENTRANT_LEVELS][MAX_NET_BUFFER];
342 static ubyte Multi_read_count;
344 int Multi_restr_query_timestamp = -1;
345 join_request Multi_restr_join_request;
346 net_addr_t Multi_restr_addr;
347 int Multi_join_restr_mode = -1;
349 SDL_COMPILE_TIME_ASSERT(addr, sizeof(Multi_restr_addr.addr) == IP_ADDRESS_LENGTH);
351 static fix Multi_server_wait_start; // variable to hold start time when waiting to reestablish with server
353 // non API master tracker vars
354 char Multi_tracker_login[100] = "";
355 char Multi_tracker_passwd[100] = "";
356 char Multi_tracker_squad_name[100] = "";
357 int Multi_tracker_id = -1;
358 char Multi_tracker_id_string[255];
360 // current file checksum
361 ushort Multi_current_file_checksum = 0;
362 int Multi_current_file_length = -1;
365 // -------------------------------------------------------------------------------------------------
366 // multi_init() is called only once, at game start-up. Get player address + port, initialize the
367 // network players list.
374 const char *ptr = NULL;
376 // read in config file
377 multi_options_read_config();
379 SDL_assert( Net_player == NULL );
382 // clear out all netplayers
383 memset(Net_players, 0, sizeof(net_player) * MAX_PLAYERS);
384 for(idx=0; idx<MAX_PLAYERS; idx++){
385 Net_players[idx].reliable_socket = INVALID_SOCKET;
388 // initialize the local netplayer
389 Net_player = &Net_players[0];
390 Net_player->tracker_player_id = Multi_tracker_id;
391 Net_player->player = Player;
392 Net_player->flags = 0;
393 Net_player->s_info.xfer_handle = -1;
394 Net_player->player_id = multi_get_new_id();
395 Net_player->client_cinfo_seq = 0;
396 Net_player->client_server_seq = 0;
398 // get our connection speed
399 Multi_connection_speed = multi_get_connection_speed();
401 // initialize other stuff
404 // load up common multiplayer icons
405 multi_load_common_icons();
408 // attempt to load up master tracker registry info (login and password)
409 Multi_tracker_id = -1;
411 // pxo login and password
412 ptr = os_config_read_string("PXO", "Login", NULL);
415 SDL_strlcpy(Multi_tracker_login, ptr, SDL_arraysize(Multi_tracker_login));
417 nprintf(("Network", "Error reading in PXO login data\n"));
418 SDL_zero(Multi_tracker_login);
421 ptr = os_config_read_string("PXO", "Password", NULL);
424 SDL_strlcpy(Multi_tracker_passwd, ptr, SDL_arraysize(Multi_tracker_passwd));
426 nprintf(("Network", "Error reading PXO password\n"));
427 SDL_zero(Multi_tracker_passwd);
431 ptr = os_config_read_string("PXO", "SquadName", NULL);
434 SDL_strlcpy(Multi_tracker_squad_name, ptr, SDL_arraysize(Multi_tracker_squad_name));
436 nprintf(("Network", "Error reading in PXO squad name\n"));
437 SDL_zero(Multi_tracker_squad_name);
441 // this is an important function which re-initializes any variables required in multiplayer games.
442 // Always make sure globals you add are re-initialized here !!!!
443 void multi_vars_init()
445 // initialize this variable right away. Used in game_level_init for init'ing the player
446 Next_ship_signature = SHIP_SIG_MIN;
447 Next_asteroid_signature = ASTEROID_SIG_MIN;
448 Next_non_perm_signature = NPERM_SIG_MIN;
449 Next_debris_signature = DEBRIS_SIG_MIN;
451 // server-client critical stuff
452 Multi_button_info_ok = 0;
453 Multi_button_info_id = 0;
456 Ingame_join_net_signature = -1;
459 Netgame.game_state = NETGAME_STATE_FORMING;
465 Multi_mission_loaded = 0; // client side
467 // restricted game stuff
468 Multi_restr_query_timestamp = -1;
471 Multi_server_check_count = 0;
473 // reentrant variable
474 Multi_read_count = 0;
476 // unset the "have cd" var
477 // NOTE: we unset this here because we are going to be calling multi_common_verify_cd()
478 // immediately after this (in multi_level_init() to re-check the status)
481 // current file checksum
482 Multi_current_file_checksum = 0;
483 Multi_current_file_length = -1;
485 Active_game_head = NULL;
486 Game_server_head = NULL;
488 // only the server should ever care about this
492 // -------------------------------------------------------------------------------------------------
493 // multi_level_init() is called whenever the player starts a multiplayer game
497 void multi_level_init()
502 ml_string(NOX("multi_level_init()"));
504 // initialize the Net_players array
505 for(idx=0;idx<MAX_PLAYERS;idx++) {
506 // close all sockets down just for good measure
507 psnet_rel_close_socket(&Net_players[idx].reliable_socket);
509 memset(&Net_players[idx],0,sizeof(net_player));
510 Net_players[idx].reliable_socket = INVALID_SOCKET;
512 Net_players[idx].s_info.xfer_handle = -1;
513 Net_players[idx].p_info.team = 0;
516 // initialize the Players array
517 for(idx=0;idx<MAX_PLAYERS;idx++){
518 if(Player == &Players[idx]){
521 memset(&Players[idx],0,sizeof(player));
526 // initialize the fake lag/loss system
531 // initialize the kick system
534 // initialize all file xfer stuff
535 multi_xfer_init(multi_file_xfer_notify);
537 // close the chatbox (if one exists)
540 // reset the data xfer system
543 // initialize the voice system
546 // intialize the pause system
549 // initialize endgame stuff
550 multi_endgame_init();
552 // initialize respawning
553 multi_respawn_init();
555 // initialize all netgame timestamps
556 multi_reset_timestamps();
558 // flush psnet sockets
562 // multi_check_listen() calls low level psnet routine to see if we have a connection from a client we
564 void multi_check_listen()
568 PSNET_SOCKET_RELIABLE sock = INVALID_SOCKET;
570 // call psnet routine which calls select to see if we need to check for a connect from a client
571 // by passing addr, we are telling check_for_listen to do the accept and return who it was from in
573 sock = psnet_rel_check_for_listen(&addr);
574 if ( sock != INVALID_SOCKET ) {
575 // be sure that my address and the server address are set correctly.
576 if ( !psnet_same(&Psnet_my_addr, &Net_player->p_info.addr) ){
577 Net_player->p_info.addr = Psnet_my_addr;
580 if ( !psnet_same(&Psnet_my_addr, &(Netgame.server_addr)) ){
581 Netgame.server_addr = Psnet_my_addr;
584 // the connection was accepted in check_for_listen. Find the netplayer whose address we connected
585 // with and assign the socket descriptor
586 for (i = 0; i < MAX_PLAYERS; i++ ) {
587 if ( (Net_players[i].flags & NETINFO_FLAG_CONNECTED) && (!memcmp(&(addr.addr), &(Net_players[i].p_info.addr.addr), IP_ADDRESS_LENGTH)) ) {
588 // mark this flag so we know he's "fully" connected
589 Net_players[i].flags |= NETINFO_FLAG_RELIABLE_CONNECTED;
590 Net_players[i].reliable_socket = sock;
592 // send player information to the joiner
593 send_accept_player_data( &Net_players[i], (Net_players[i].flags & NETINFO_FLAG_INGAME_JOIN)?1:0 );
595 // send a netgame update so the new client has all the necessary settings
596 send_netgame_update_packet();
598 // if this is a team vs. team game, send an update
599 if(Netgame.type_flags & NG_TYPE_TEAM){
600 multi_team_send_update();
604 ml_printf(NOX("Accepted TCP connection from %s"), Net_players[i].player == NULL ? NOX("Unknown") : Net_players[i].player->callsign);
609 // if we didn't find a player, close the socket
610 if ( i == MAX_PLAYERS ) {
611 nprintf(("Network", "Got accept on my listen socket, but unknown player. Closing socket.\n"));
612 psnet_rel_close_socket(&sock);
617 // returns true is server hasn't been heard from in N seconds. false otherwise
618 int multi_client_server_dead()
620 fix this_time, last_time, max;
622 // get the last time we have heard from the server. If greater than some default, then maybe
623 // display some icon on the HUD indicating slow network connection. if greater than some higher
624 // max, stop simulating on the client side until we hear from the server again.
625 this_time = timer_get_fixed_seconds();
626 last_time = Netgame.server->last_heard_time;
627 // check for wrap! must return 0
628 if ( last_time > this_time )
631 this_time -= last_time;
633 // if in mission, use the smaller timeout value. Outside of mission, use a large one.
634 if ( MULTI_IN_MISSION ){
635 max = MULTI_SERVER_MAX_TIMEOUT;
637 max = MULTI_SERVER_MAX_TIMEOUT_LARGE;
640 if ( this_time > max){
647 void multi_process_incoming(); // prototype for function later in this module
649 // function to process network data in hopes of getting info back from server
650 int multi_client_wait_on_server()
654 is_dead = multi_client_server_dead();
656 // if the server is back alive, tell our popup
658 return MULTI_SERVER_ALIVE;
661 // on release version -- keep popup active for 60 seconds, then bail
663 fix this_time = timer_get_fixed_seconds();
664 // if the timer wrapped:
665 if ( this_time < Multi_server_wait_start ) {
666 Multi_server_wait_start = timer_get_fixed_seconds();
669 // check to see if timeout expired
670 this_time -= Multi_server_wait_start;
671 if ( this_time > MULTI_SERVER_WAIT_TIME ){
672 return MULTI_SERVER_GONE;
679 // function called by multiplayer clients to stop simulating when they have not heard from the server
681 void multi_client_check_server()
685 SDL_assert( MULTIPLAYER_CLIENT );
687 // this function can get called while in the popup code below. So we include this check as a
689 if ( Multi_server_check_count )
692 // make sure we have a valid server
693 if(Netgame.server == NULL){
697 Multi_server_check_count++;
698 if(multi_client_server_dead()){
699 Netgame.flags |= NG_FLAG_SERVER_LOST;
701 Netgame.flags &= ~(NG_FLAG_SERVER_LOST);
704 if(Netgame.flags & NG_FLAG_SERVER_LOST) {
705 if(!(Game_mode & GM_IN_MISSION) && !popup_active()){
706 // need to start a popup
707 Multi_server_wait_start = timer_get_fixed_seconds();
708 rval = popup_till_condition( multi_client_wait_on_server, XSTR("Cancel",641), XSTR("Contact lost with server. Stopping simulation until contact reestablished. Press Cancel to exit game.",642) );
710 if ( !rval || (rval == MULTI_SERVER_GONE) ) {
711 multi_quit_game(PROMPT_NONE, MULTI_END_NOTIFY_NONE, MULTI_END_ERROR_CONTACT_LOST);
713 Netgame.flags &= ~(NG_FLAG_SERVER_LOST);
717 Multi_server_check_count--;
721 // -------------------------------------------------------------------------------------------------
722 // process_packet_normal() will determine what sort of packet it is, and send it to the appropriate spot.
723 // Prelimiary verification of the magic number and checksum are done here.
726 void process_packet_normal(ubyte* data, header *header_info)
731 process_join_packet(data, header_info);
735 process_game_chat_packet( data, header_info );
738 case NOTIFY_NEW_PLAYER:
739 process_new_player_packet(data, header_info);
743 process_hud_message(data, header_info);
746 case MISSION_MESSAGE:
747 process_mission_message_packet( data, header_info );
751 process_leave_game_packet(data, header_info);
755 process_game_query(data, header_info);
759 process_game_active_packet(data, header_info);
763 process_game_info_packet( data, header_info );
766 case SECONDARY_FIRED_AI:
767 process_secondary_fired_packet(data, header_info, 0);
770 case SECONDARY_FIRED_PLR:
771 process_secondary_fired_packet(data, header_info, 1);
774 case COUNTERMEASURE_FIRED:
775 process_countermeasure_fired_packet( data, header_info );
778 case FIRE_TURRET_WEAPON:
779 process_turret_fired_packet( data, header_info );
783 process_netgame_update_packet( data, header_info );
786 case UPDATE_DESCRIPT:
787 process_netgame_descript_packet( data, header_info );
790 case NETPLAYER_UPDATE:
791 process_netplayer_update_packet( data, header_info );
795 process_accept_packet(data, header_info);
799 multi_oo_process_update(data, header_info);
803 process_ship_kill_packet( data, header_info );
807 process_wing_create_packet( data, header_info );
811 process_ship_create_packet( data, header_info );
815 process_ship_depart_packet( data, header_info );
818 case MISSION_LOG_ENTRY:
819 process_mission_log_packet( data, header_info );
823 process_ping_packet(data, header_info);
827 process_pong_packet(data, header_info);
831 SDL_assert(header_info->id >= 0);
833 PSNET_SOCKET_RELIABLE sock;
834 sock = INVALID_SOCKET;
836 // if I'm the server of the game, find out who this came from
837 if((Net_player != NULL) && (Net_player->flags & NETINFO_FLAG_AM_MASTER)){
838 np_index = find_player_id(header_info->id);
840 sock = Net_players[np_index].reliable_socket;
843 // otherwise always use my own socket
844 else if(Net_player != NULL){
845 sock = Net_player->reliable_socket;
848 header_info->bytes_processed = multi_xfer_process_packet(data + HEADER_LENGTH, sock) + HEADER_LENGTH;
851 case MISSION_REQUEST:
852 process_mission_request_packet(data,header_info);
856 process_mission_item_packet(data,header_info);
859 case MULTI_PAUSE_REQUEST:
860 process_multi_pause_packet(data, header_info);
864 process_ingame_nak(data, header_info);
867 case SHIPS_INGAME_PACKET:
868 process_ingame_ships_packet(data, header_info);
871 case WINGS_INGAME_PACKET:
872 process_ingame_wings_packet(data, header_info);
876 process_endgame_packet(data, header_info);
879 case OBSERVER_UPDATE:
880 process_observer_update_packet(data, header_info);
883 case NETPLAYER_SLOTS_P:
884 process_netplayer_slot_packet(data, header_info);
887 case SHIP_STATUS_CHANGE:
888 process_ship_status_packet(data, header_info);
891 case PLAYER_ORDER_PACKET:
892 process_player_order_packet(data, header_info);
895 case INGAME_SHIP_UPDATE:
896 process_ingame_ship_update_packet(data, header_info);
899 case INGAME_SHIP_REQUEST:
900 process_ingame_ship_request_packet(data, header_info);
904 process_file_sig_packet(data, header_info);
908 multi_respawn_process_packet(data,header_info);
911 case SUBSYSTEM_DESTROYED:
912 process_subsystem_destroyed_packet( data, header_info );
915 case LOAD_MISSION_NOW :
916 process_netplayer_load_packet(data, header_info);
919 case FILE_SIG_REQUEST :
920 process_file_sig_request(data, header_info);
924 process_jump_into_mission_packet(data, header_info);
927 case CLIENT_REPAIR_INFO:
928 process_repair_info_packet(data,header_info);
931 case MISSION_SYNC_DATA:
932 process_mission_sync_packet(data,header_info);
935 case STORE_MISSION_STATS:
936 process_store_stats_packet(data, header_info);
940 process_debris_update_packet(data, header_info);
943 case SHIP_WSTATE_CHANGE:
944 process_ship_weapon_change( data, header_info );
947 case WSS_UPDATE_PACKET:
948 process_wss_update_packet(data, header_info);
951 case WSS_REQUEST_PACKET:
952 process_wss_request_packet( data, header_info );
956 process_firing_info_packet( data, header_info );
960 process_cargo_revealed_packet( data, header_info);
963 case SUBSYS_CARGO_REVEALED:
964 process_subsystem_cargo_revealed_packet( data, header_info);
967 case MISSION_GOAL_INFO:
968 process_mission_goal_info_packet(data, header_info);
972 process_player_kick_packet(data, header_info);
975 case PLAYER_SETTINGS:
976 process_player_settings_packet(data, header_info);
980 process_deny_packet(data, header_info);
984 process_post_sync_data_packet(data, header_info);
988 process_wss_slots_data_packet(data,header_info);
991 case SHIELD_EXPLOSION:
992 process_shield_explosion_packet( data, header_info );
996 process_player_stats_block_packet(data, header_info);
1000 process_pslot_update_packet(data,header_info);
1003 case AI_INFO_UPDATE:
1004 process_ai_info_update_packet( data, header_info );
1007 case CAMPAIGN_UPDATE :
1008 multi_campaign_process_update(data,header_info);
1011 case CAMPAIGN_UPDATE_INGAME:
1012 multi_campaign_process_ingame_start(data,header_info);
1016 multi_voice_process_packet(data,header_info);
1020 multi_team_process_packet(data,header_info);
1024 process_asteroid_info(data, header_info);
1027 case HOST_RESTR_QUERY:
1028 process_host_restr_packet(data, header_info);
1031 case OPTIONS_UPDATE:
1032 multi_options_process_packet(data,header_info);
1035 case SQUADMSG_PLAYER:
1036 multi_msg_process_squadmsg_packet(data,header_info);
1039 case NETGAME_END_ERROR:
1040 process_netgame_end_error_packet(data,header_info);
1043 case COUNTERMEASURE_SUCCESS:
1044 process_countermeasure_success_packet( data, header_info );
1048 process_client_update_packet(data, header_info);
1052 process_countdown_packet(data, header_info);
1056 process_debrief_info( data, header_info );
1059 case ACCEPT_PLAYER_DATA:
1060 process_accept_player_data( data, header_info );
1063 case HOMING_WEAPON_UPDATE:
1064 process_homing_weapon_info( data, header_info );
1068 process_emp_effect(data, header_info);
1071 case REINFORCEMENT_AVAIL:
1072 process_reinforcement_avail( data, header_info );
1076 process_change_iff_packet(data, header_info);
1079 case PRIMARY_FIRED_NEW:
1080 process_NEW_primary_fired_packet(data, header_info);
1083 case COUNTERMEASURE_NEW:
1084 process_NEW_countermeasure_fired_packet(data, header_info);
1088 process_beam_fired_packet(data, header_info);
1092 process_sw_query_packet(data, header_info);
1096 process_event_update_packet(data, header_info);
1099 case OBJECT_UPDATE_NEW:
1100 multi_oo_process_update(data, header_info);
1104 process_weapon_detonate_packet(data, header_info);
1108 process_flak_fired_packet(data, header_info);
1111 case NETPLAYER_PAIN:
1112 process_player_pain_packet(data, header_info);
1115 case LIGHTNING_PACKET:
1116 process_lightning_packet(data, header_info);
1120 process_bytes_recvd_packet(data, header_info);
1124 process_host_captain_change_packet(data, header_info);
1128 process_self_destruct_packet(data, header_info);
1132 nprintf(("Network", "Received packet with unknown type %d\n", data[0] ));
1133 header_info->bytes_processed = 10000;
1141 // Takes a bunch of messages, check them for validity,
1142 // and pass them to multi_process_data.
1143 // --------------------^
1144 // this should be process_packet() I think, or with the new code
1145 // process_tracker_packet() as defined in MultiTracker.[h,cpp]
1146 void multi_process_bigdata(ubyte *data, int len, net_addr_t *from_addr, int reliable)
1148 int type, bytes_processed;
1153 // the only packets we will process from an unknown player are GAME_QUERY, GAME_INFO, JOIN, PING, PONG, ACCEPT, and GAME_ACTIVE packets
1154 player_num = find_player(from_addr);
1156 // find the player who sent the message and mark the last_heard time for this player
1157 // check to see if netplayer is null (it may be in cases such as getting lists of games from the tracker)
1158 if(player_num >= 0){
1159 Net_players[player_num].last_heard_time = timer_get_fixed_seconds();
1162 // store fields that were passed along in the message
1163 // store header information that was captured from the network-layer header
1164 memcpy(header_info.addr, from_addr->addr, IP_ADDRESS_LENGTH);
1165 header_info.port = from_addr->port;
1166 if(player_num >= 0){
1167 header_info.id = Net_players[player_num].player_id;
1169 header_info.id = -1;
1172 bytes_processed = 0;
1173 while( (bytes_processed >= 0) && (bytes_processed < len) ) {
1175 buf = &(data[bytes_processed]);
1179 // if its coming from an unknown source, there are only certain packets we will actually process
1180 if((player_num == -1) && !multi_is_valid_unknown_packet((ubyte)type)){
1184 if ( (type<0) || (type > MAX_TYPE_ID )) {
1185 nprintf( ("Network", "multi_process_bigdata: Invalid packet type %d!\n", type ));
1189 // perform any special processing checks here
1190 process_packet_normal(buf,&header_info);
1192 // MWA -- magic number was removed from header on 8/4/97. Replaced with bytes_processed
1193 // variable which gets stuffed whenever a packet is processed.
1194 bytes_processed += header_info.bytes_processed;
1197 // if this is not reliable data and we have a valid player
1198 if(Net_player != NULL){
1199 if(!MULTIPLAYER_MASTER && !reliable && (Game_mode & GM_IN_MISSION)){
1200 Net_player->cl_bytes_recvd += len;
1205 // process all reliable socket details
1206 void multi_process_reliable_details()
1211 // run reliable sockets
1216 // server operations
1217 if ( MULTIPLAYER_MASTER ){
1218 // listen for new reliable socket connections
1219 multi_check_listen();
1221 // check for any broken sockets and delete any players
1222 for(idx=0; idx<MAX_PLAYERS; idx++){
1223 // players who _should_ be validly connected
1224 if((idx != MY_NET_PLAYER_NUM) && MULTI_CONNECTED(Net_players[idx])){
1225 // if this guy's socket is broken or disconnected, kill him
1226 sock_status = psnet_rel_get_status(Net_players[idx].reliable_socket);
1227 if((sock_status == RNF_UNUSED) || (sock_status == RNF_BROKEN) || (sock_status == RNF_DISCONNECTED)){
1228 ml_string("Shutting down rel socket because of disconnect!");
1232 // if we're still waiting for this guy to connect on his reliable socket and he's timed out, boot him
1233 if(Net_players[idx].s_info.reliable_connect_time != -1){
1234 // if he's connected
1235 if(Net_players[idx].reliable_socket != INVALID_SOCKET){
1236 Net_players[idx].s_info.reliable_connect_time = -1;
1238 // if he's timed out
1239 else if(((time(NULL) - Net_players[idx].s_info.reliable_connect_time) > MULTI_RELIABLE_CONNECT_WAIT) && (Net_players[idx].reliable_socket == INVALID_SOCKET)){
1240 ml_string("Player timed out while connecting on reliable socket!");
1247 // clients should detect broken sockets
1249 extern unsigned int Serverconn;
1250 if(Serverconn != 0xffffffff){
1251 int status = psnet_rel_get_status(Serverconn);
1252 if(status == RNF_BROKEN){
1253 mprintf(("CLIENT SOCKET DISCONNECTED"));
1256 if(!multi_endgame_ending()){
1257 multi_quit_game(PROMPT_NONE, MULTI_END_NOTIFY_NONE, MULTI_END_ERROR_CONTACT_LOST);
1264 // multi_process_incoming reads incoming data off the unreliable and reliable ports and sends
1265 // the data to process_big_data
1266 void multi_process_incoming()
1269 ubyte *data, *savep;
1270 net_addr_t from_addr;
1272 SDL_assert( Multi_read_count < NUM_REENTRANT_LEVELS );
1273 savep = net_buffer[Multi_read_count];
1279 // get the other net players data
1280 while( (size = psnet_get(data, &from_addr))>0 ) {
1281 // ingame joiners will ignore UDP packets until they are have picked a ship and are in the mission
1282 if( (Net_player->flags & NETINFO_FLAG_INGAME_JOIN) && (Net_player->state != NETPLAYER_STATE_INGAME_SHIP_SELECT) ){
1283 //nprintf(("Network","Tossing UDP like a good little ingame joiner...\n"));
1285 // otherwise process incoming data normally
1287 multi_process_bigdata(data, size, &from_addr, 0);
1291 // read reliable sockets for data
1295 if(Net_player->flags & NETINFO_FLAG_AM_MASTER){
1296 for (idx=0;idx<MAX_PLAYERS;idx++) {
1297 if((Net_players[idx].flags & NETINFO_FLAG_CONNECTED) && (Net_player != NULL) && (Net_player->player_id != Net_players[idx].player_id)){
1298 while( (size = psnet_rel_get(Net_players[idx].reliable_socket, data, MAX_NET_BUFFER)) > 0){
1299 multi_process_bigdata(data, size, &Net_players[idx].p_info.addr, 1);
1304 // if I'm not the master of the game, read reliable data from my connection with the server
1305 if((Net_player->reliable_socket != INVALID_SOCKET) && (Net_player->reliable_socket != 0)){
1306 while( (size = psnet_rel_get(Net_player->reliable_socket,data, MAX_NET_BUFFER)) > 0){
1307 multi_process_bigdata(data, size, &Netgame.server_addr, 1);
1315 // -------------------------------------------------------------------------------------------------
1316 // multi_do_frame() is called once per game loop do update all the multiplayer objects, and send
1317 // the player data to all the other net players.
1326 dc_printf("proper eye stuff on\n");
1328 dc_printf("proper eye stuff off\n");
1332 void multi_do_frame()
1334 PSNET_TOP_LAYER_PROCESS();
1336 // always set the local player eye position/orientation here so we know its valid throughout all multiplayer
1338 if((Net_player != NULL) && eye_tog){
1339 player_get_eye(&Net_player->s_info.eye_pos, &Net_player->s_info.eye_orient);
1342 // send all buffered packets from the previous frame
1343 multi_io_send_buffered_packets();
1345 // datarate tracking
1346 multi_rate_process();
1348 // always process any pending endgame details
1349 multi_endgame_process();
1351 // process all reliable socket details, including :
1352 // 1.) Listening for new pending reliable connections (server)
1353 // 2.) Checking for broken sockets (server/client)
1354 // 3.) Checking for clients who haven't fully connected
1355 multi_process_reliable_details();
1357 // get the other net players data
1358 multi_process_incoming();
1360 // process object update datarate stuff (for clients and server both)
1361 multi_oo_rate_process();
1363 // clients should check when last time they heard from sever was -- if too long, then
1364 // pause the simulation so wait for it to possibly come back
1365 if ( (MULTIPLAYER_CLIENT) && (Net_player->flags & NETINFO_FLAG_CONNECTED) ){
1366 multi_client_check_server();
1369 // everybody pings all the time
1370 if((Next_ping_time < 0) || ((time(NULL) - Next_ping_time) > PING_SEND_TIME) ){
1371 if( (Net_player->flags & NETINFO_FLAG_AM_MASTER) ){
1372 send_netplayer_update_packet();
1376 multi_ping_send_all();
1377 Next_ping_time = time(NULL);
1380 // if I am the master, and we are not yet actually playing the mission, send off netgame
1381 // status to all other players in the game. If I am not the master of the game, and we
1382 // are not in the game, then send out my netplayer status to the host
1383 if ( (Net_player->flags & NETINFO_FLAG_CONNECTED) && !(Game_mode & GM_IN_MISSION)){
1384 if ( Net_player->flags & NETINFO_FLAG_AM_MASTER ) {
1385 if ( (Netgame_send_time < 0) || ((time(NULL) - Netgame_send_time) > NETGAME_SEND_TIME) ) {
1386 send_netgame_update_packet();
1388 Netgame_send_time = time(NULL);
1391 if ( (State_send_time < 0) || ((time(NULL) - State_send_time) > STATE_SEND_TIME) ){
1392 // observers shouldn't send an update state packet
1393 if ( !(Net_player->flags & NETINFO_FLAG_OBSERVER) ){
1394 send_netplayer_update_packet();
1397 State_send_time = time(NULL);
1401 else if ( (Net_player->flags & NETINFO_FLAG_CONNECTED) && (Game_mode & GM_IN_MISSION) ) {
1402 // if I am connected and am in the mission, do things that need to be done on a regular basis
1403 if ( Net_player->flags & NETINFO_FLAG_AM_MASTER ) {
1404 if ( (Gameinfo_send_time < 0) || ((time(NULL) - Gameinfo_send_time) > GAMEINFO_SEND_TIME)){
1405 send_game_info_packet();
1407 Gameinfo_send_time = time(NULL);
1410 // for any potential respawns
1411 multi_respawn_handle_invul_players();
1412 multi_respawn_check_ai();
1414 // for any potential ingame joiners
1415 multi_handle_ingame_joiners();
1417 // the clients need to do some processing of stuff as well
1421 // check to see if we're waiting on confirmation for a restricted ingame join
1422 if(Multi_restr_query_timestamp != -1){
1423 // if it has elapsed, unset the ingame join flag
1424 if(timestamp_elapsed(Multi_restr_query_timestamp)){
1425 Multi_restr_query_timestamp = -1;
1426 Netgame.flags &= ~(NG_FLAG_INGAME_JOINING);
1430 // while in the mission, send my PlayerControls to the host so that he can process
1432 if ( Game_mode & GM_IN_MISSION ) {
1434 extern void oo_update_time();
1438 if ( !(Net_player->flags & NETINFO_FLAG_AM_MASTER)){
1439 if(Net_player->flags & NETINFO_FLAG_OBSERVER){
1440 // if the rate limiting system says its ok
1441 if(multi_oo_cirate_can_send()){
1442 // send my observer position/object update
1443 send_observer_update_packet();
1445 } else if ( !(Player_ship->flags & SF_DEPARTING ) ){
1446 // if the rate limiting system says its ok
1447 if(multi_oo_cirate_can_send()){
1448 // use the new method
1449 multi_oo_send_control_info();
1453 // bytes received info
1454 if( (Next_bytes_time < 0) || ((time(NULL) - Next_bytes_time) > BYTES_SENT_TIME) ){
1455 if(Net_player != NULL){
1456 send_bytes_recvd_packet(Net_player);
1458 // reset bytes recvd
1459 Net_player->cl_bytes_recvd = 0;
1463 Next_bytes_time = time(NULL);
1466 // sending new objects from here is dependent on having objects only created after
1467 // the game is done moving the objects. I think that I can enforce this.
1470 // evaluate whether the time limit has been reached or max kills has been reached
1471 // Commented out by Sandeep 4/12/98, was causing problems with testing.
1472 if( ((f2fl(Netgame.options.mission_time_limit) > 0.0f) && (Missiontime > Netgame.options.mission_time_limit)) ||
1473 multi_kill_limit_reached() ) {
1475 // make sure we don't do this more than once
1476 if(Netgame.game_state == NETGAME_STATE_IN_MISSION){
1477 multi_handle_end_mission_request();
1483 // periodically send a client update packet to all clients
1484 if((Net_player != NULL) && (Net_player->flags & NETINFO_FLAG_AM_MASTER)){
1486 for(idx=0;idx<MAX_PLAYERS;idx++){
1487 if(MULTI_CONNECTED(Net_players[idx]) && (Net_player != &Net_players[idx])){
1488 if((Multi_client_update_times[idx] < 0) || timestamp_elapsed_safe(Multi_client_update_times[idx], 1000)){
1490 send_client_update_packet(&Net_players[idx]);
1492 Multi_client_update_times[idx] = timestamp(MULTI_CLIENT_UPDATE_TIME);
1498 // process any kicked player details
1499 multi_kick_process();
1501 // do any file xfer details
1504 // process any player data details (wav files, pilot pics, etc)
1507 // do any voice details
1508 multi_voice_process();
1510 // process any player messaging details
1511 multi_msg_process();
1513 // process any tracker messages
1514 multi_fs_tracker_process();
1516 // if on the standalone, do any gui stuff
1517 if(Game_mode & GM_STANDALONE_SERVER){
1521 // dogfight nonstandalone players should recalc the escort list every frame
1522 if(!(Game_mode & GM_STANDALONE_SERVER) && (Netgame.type_flags & NG_TYPE_DOGFIGHT) && MULTI_IN_MISSION){
1523 hud_setup_escort_list(0);
1527 // -------------------------------------------------------------------------------------------------
1528 // multi_pause_do_frame() is called once per game loop do update all the multiplayer objects, and send
1529 // the player data to all the other net players when the multiplayer game is paused. It only will do
1530 // checking for a few specialized packets (MULTI_UNPAUSE, etc)
1533 void multi_pause_do_frame()
1535 PSNET_TOP_LAYER_PROCESS();
1537 // always set the local player eye position/orientation here so we know its valid throughout all multiplayer
1539 // if((Net_player != NULL) && eye_tog){
1540 // player_get_eye(&Net_player->s_info.eye_pos, &Net_player->s_info.eye_orient);
1543 // send all buffered packets from the previous frame
1544 multi_io_send_buffered_packets();
1546 // always process any pending endgame details
1547 multi_endgame_process();
1549 // process all reliable socket details, including :
1550 // 1.) Listening for new pending reliable connections (server)
1551 // 2.) Checking for broken sockets (server/client)
1552 // 3.) Checking for clients who haven't fully connected
1553 multi_process_reliable_details();
1555 // these timestamps and handlers shoul be evaluated in the pause state
1556 if ( Net_player->flags & NETINFO_FLAG_AM_MASTER ) {
1557 if ( (Gameinfo_send_time < 0) || ((time(NULL) - Gameinfo_send_time) > GAMEINFO_SEND_TIME) ){
1558 send_game_info_packet();
1560 Gameinfo_send_time = time(NULL);
1564 // everybody pings all the time
1565 if((Next_ping_time < 0) || ((time(NULL) - Next_ping_time) > PING_SEND_TIME) ){
1566 multi_ping_send_all();
1568 Next_ping_time = time(NULL);
1571 // periodically send a client update packet to all clients
1572 if(Net_player->flags & NETINFO_FLAG_AM_MASTER){
1575 for(idx=0;idx<MAX_PLAYERS;idx++){
1576 if(MULTI_CONNECTED(Net_players[idx]) && (Net_player != &Net_players[idx])){
1577 if((Multi_client_update_times[idx] < 0) || timestamp_elapsed_safe(Multi_client_update_times[idx], 1000)){
1579 send_client_update_packet(&Net_players[idx]);
1581 Multi_client_update_times[idx] = timestamp(MULTI_CLIENT_UPDATE_TIME);
1586 // for any potential ingame joiners
1587 multi_handle_ingame_joiners();
1590 // do any file xfer details
1593 // process any player data details (wav files, pilot pics, etc)
1596 // get the other net players data
1597 multi_process_incoming();
1599 // do any voice details
1600 multi_voice_process();
1602 // process any player messaging details
1603 multi_msg_process();
1605 // process any kicked player details
1606 multi_kick_process();
1608 // process any pending endgame details
1609 multi_endgame_process();
1611 // process object update stuff (for clients and server both)
1612 if(MULTIPLAYER_MASTER){
1616 // if on the standalone, do any gui stuff
1617 if(Game_mode & GM_STANDALONE_SERVER){
1623 // --------------------------------------------------------------------------------
1624 // standalone_main_init() the standalone equivalent of the main menu
1627 extern int sock_inited;
1628 float frame_time = (float)1.0/(float)30.0;
1630 void standalone_main_init()
1632 std_debug_set_standalone_state_string("Main Init");
1634 Game_mode = (GM_STANDALONE_SERVER | GM_MULTIPLAYER);
1637 ml_string(NOX("Standalone server initializing"));
1639 // read in config file
1640 // multi_options_read_config();
1642 // if we failed to startup on our desired protocol, fail
1643 if ( !Tcp_active ) {
1644 SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error", XSTR("You have selected TCP/IP for multiplayer Freespace, but the TCP/IP protocol was not detected on your machine.", 362), NULL);
1649 Multi_options_g.protocol = NET_TCP;
1650 psnet_use_protocol(Multi_options_g.protocol);
1652 // clear out the Netgame structure and start filling in the values
1653 // NOTE : these values are not incredibly important since they will be overwritten by the host when he joins
1654 memset( &Netgame, 0, sizeof(Netgame) );
1655 Netgame.game_state = NETGAME_STATE_FORMING; // game is currently starting up
1656 Netgame.security = 0;
1657 Netgame.server_addr = Psnet_my_addr;
1659 // reinitialize all systems
1662 // intialize endgame stuff
1663 multi_endgame_init();
1665 // clear the file xfer system
1667 multi_xfer_force_dir(CF_TYPE_MULTI_CACHE);
1672 // setup the netplayer for the standalone
1673 Net_player = &Net_players[0];
1674 Net_player->tracker_player_id = -1;
1675 Net_player->flags |= (NETINFO_FLAG_AM_MASTER | NETINFO_FLAG_CONNECTED | NETINFO_FLAG_DO_NETWORKING | NETINFO_FLAG_MISSION_OK);
1676 Net_player->state = NETPLAYER_STATE_WAITING;
1677 Net_player->player = Player;
1678 SDL_strlcpy(Player->callsign, "server", SDL_arraysize(Player->callsign));
1679 Net_player->p_info.addr = Psnet_my_addr;
1680 Net_player->s_info.xfer_handle = -1;
1681 Net_player->player_id = multi_get_new_id();
1682 Netgame.server = Net_player;
1684 // maybe flag the game as having a hacked ships.tbl
1685 if(!Game_ships_tbl_valid){
1686 Netgame.flags |= NG_FLAG_HACKED_SHIPS_TBL;
1688 // maybe flag the game as having a hacked weapons.tbl
1689 if(!Game_weapons_tbl_valid){
1690 Netgame.flags |= NG_FLAG_HACKED_WEAPONS_TBL;
1694 if(game_hacked_data()){
1695 Net_player->flags |= NETINFO_FLAG_HAXOR;
1698 // setup debug flags
1699 Netgame.debug_flags = 0;
1701 if(!Cmdline_server_firing){
1702 Netgame.debug_flags |= NETD_FLAG_CLIENT_FIRING;
1704 if(!Cmdline_client_dodamage){
1705 Netgame.debug_flags |= NETD_FLAG_CLIENT_NODAMAGE;
1709 // setup the default game name for the standalone
1710 std_connect_set_gamename(NULL);
1712 // set netgame default options
1713 multi_options_set_netgame_defaults(&Netgame.options);
1715 // set local netplayer default options
1716 multi_options_set_local_defaults(&Net_player->p_info.options);
1718 // set our object update level from the standalone default
1719 Net_player->p_info.options.obj_update_level = Multi_options_g.std_datarate;
1720 switch(Net_player->p_info.options.obj_update_level){
1721 case OBJ_UPDATE_LOW:
1722 nprintf(("Network","STANDALONE USING LOW UPDATES\n"));
1724 case OBJ_UPDATE_MEDIUM:
1725 nprintf(("Network","STANDALONE USING MEDIUM UPDATES\n"));
1727 case OBJ_UPDATE_HIGH:
1728 nprintf(("Network","STANDALONE USING HIGH UPDATE\n"));
1730 case OBJ_UPDATE_LAN:
1731 nprintf(("Network","STANDALONE USING LAN UPDATE\n"));
1735 // clear out various things
1740 // login to game tracker
1741 std_tracker_login();
1743 std_debug_set_standalone_state_string("Main Do");
1744 std_set_standalone_fps((float)0);
1745 std_multi_set_standalone_missiontime((float)0);
1747 // load my missions and campaigns
1748 multi_create_list_load_missions();
1749 multi_create_list_load_campaigns();
1751 SDL_zero(The_mission);
1753 // if this is a tracker game, validate missions
1754 if(MULTI_IS_TRACKER_GAME){
1755 multi_update_valid_missions();
1760 // --------------------------------------------------------------------------------
1761 // standalone_main_do()
1764 // DESCRIPTION : the standalone server will wait in this state until the host of the game
1765 // is "Waiting". That is, his state==NETPLAYER_STATE_WAITING, and he has finished
1766 // doing everything and wants to play the game. Once this happens, we will jump
1767 // into GS_STATE_MULTI_SERVER_WAIT
1769 void standalone_main_do()
1771 SDL_Delay(10); // since nothing will really be going on here, we can afford to give some time
1772 // back to the operating system.
1774 // kind of a do-nothing spin state.
1775 // The standalone will eventually move into the GS_STATE_MULTI_MISSION_SYNC state when a host connects and
1776 // attempts to start a game
1779 // --------------------------------------------------------------------------------
1780 // standalone_main_close()
1783 void standalone_main_close()
1785 std_debug_set_standalone_state_string("Main Close");
1788 void multi_standalone_reset_all()
1793 ml_string(NOX("Standalone resetting"));
1795 // shut all game stuff down
1798 // reinitialize the gui
1799 std_reset_standalone_gui();
1801 // close down all sockets
1802 for(idx=0;idx<MAX_PLAYERS;idx++){
1804 // 6/25/98 -- MWA -- call delete_player here to remove the player. This closes down the socket
1805 // and marks the player as not connected anymore. It is probably cleaner to do this.
1806 if ( &Net_players[idx] != Net_player ) {
1807 delete_player( idx );
1811 // make sure we go to the proper state.
1812 if(gameseq_get_state() == GS_STATE_STANDALONE_MAIN){
1813 standalone_main_init();
1815 gameseq_post_event(GS_EVENT_STANDALONE_MAIN);
1818 // --------------------------------------------------------------------------------
1819 // multi_server_wait_init() do stuff like setting the status bits correctly
1822 void multi_standalone_wait_init()
1824 std_debug_set_standalone_state_string("Wait Do");
1825 std_multi_add_goals(); // fill in the goals for the mission into the tree view
1826 multi_reset_timestamps();
1828 // create the bogus standalone object
1829 multi_create_standalone_object();
1833 // --------------------------------------------------------------------------------
1834 // multi_server_wait_do_frame() wait for everyone to log in or the host to send commands
1837 // DESCRIPTION : we will be in this state once the host of the game is waiting for everyone
1838 // to be finished and ready to go, at which point, we will will tell everyone
1839 // to enter the game, and we will start simulating ourselves. Note that most of
1840 // this code is lifted from multi_wait_do_frame()
1841 void multi_standalone_wait_do()
1845 // --------------------------------------------------------------------------------
1846 // multi_server_wait_close() cleanup
1849 void multi_standalone_wait_close()
1851 std_debug_set_standalone_state_string("Wait Close / Game Play");
1853 // all players should reset sequencing
1855 for(idx=0;idx<MAX_PLAYERS;idx++){
1856 if(Net_player->flags & NETINFO_FLAG_CONNECTED){
1857 Net_players[idx].client_cinfo_seq = 0;
1858 Net_players[idx].client_server_seq = 0;
1864 // this is an artificial state which will push the standalone into the main state without it having to go through
1865 // the init function (which would disconnect everyone and generally just screw things up)
1866 // it will also eventually do tracker stats update
1867 extern int Multi_debrief_server_framecount;
1868 void multi_standalone_postgame_init()
1870 std_debug_set_standalone_state_string("Postgame / Send Stats");
1873 ml_string(NOX("Standlone entering postgame"));
1875 mission_goal_fail_incomplete();
1877 // handle campaign stuff
1878 if ( Game_mode & GM_CAMPAIGN_MODE ) {
1879 // MUST store goals and events first - may be used to evaluate next mission
1880 // store goals and events
1881 mission_campaign_store_goals_and_events();
1883 // evaluate next mission
1884 mission_campaign_eval_next_mission();
1887 // always set my state to be "DEBRIEF_ACCEPT"
1888 Net_player->state = NETPLAYER_STATE_DEBRIEF_ACCEPT;
1890 // mark stats as not being store yet
1891 Netgame.flags &= ~(NG_FLAG_STORED_MT_STATS);
1893 Multi_debrief_server_framecount = 0;
1895 // reset network timestamps
1896 multi_reset_timestamps();
1899 void multi_standalone_postgame_do()
1901 // wait until everyone is in the debriefing
1902 if((Netgame.game_state != NETGAME_STATE_DEBRIEF) && multi_netplayer_state_check(NETPLAYER_STATE_DEBRIEF, 1)){
1903 Netgame.game_state = NETGAME_STATE_DEBRIEF;
1904 send_netgame_update_packet();
1905 debrief_multi_server_stuff();
1908 // process server debriefing details
1909 if(Netgame.game_state == NETGAME_STATE_DEBRIEF){
1910 multi_debrief_server_process();
1914 void multi_standalone_postgame_close()
1918 void multi_reset_timestamps()
1922 for ( i = 0 ; i < MAX_PLAYERS; i++ ){
1923 Multi_client_update_times[i] = -1;
1925 Netgame_send_time = -1;
1926 Gameinfo_send_time = -1;
1927 Next_ping_time = -1;
1928 State_send_time = -1;
1929 Next_bytes_time = -1;
1931 chatbox_reset_timestamps();
1933 // do for all players so that ingame joiners work properly.
1934 for (i = 0; i < MAX_PLAYERS; i++ ) {
1935 Players[i].update_dumbfire_time = timestamp(0);
1936 Players[i].update_lock_time = timestamp(0);
1938 Net_players[i].s_info.voice_token_timestamp = -1;
1941 // reset standalone gui timestamps (these are not game critical, so there is not much danger)
1942 std_reset_timestamps();
1944 // initialize all object update timestamps
1945 multi_oo_gameplay_init();
1948 // netgame debug flags for debug console stuff
1949 DCF(netd, "change/list netgame debug flags")
1951 dc_get_arg(ARG_INT);
1953 // if we got an integer, and we're the server, change flags
1954 if((Dc_arg_type & ARG_INT) && (Net_player != NULL) && (Net_player->flags & NETINFO_FLAG_AM_MASTER) && (Dc_arg_int <= 7)){
1955 Netgame.debug_flags ^= (1<<Dc_arg_int);
1958 // display network flags
1959 dc_printf("BITS\n");
1960 // dc_printf("1 - Client side firing (%d)\n", Netgame.debug_flags & NETD_FLAG_CLIENT_FIRING ? 1 : 0);
1961 // dc_printf("2 - Client nodamage (%d)\n", Netgame.debug_flags & NETD_FLAG_CLIENT_NODAMAGE ? 1 : 0);
1964 // display any multiplayer/networking information here
1965 void multi_display_netinfo()
1967 int sx = gr_screen.max_w - 200;
1972 if(!(Game_mode & GM_MULTIPLAYER)){
1976 gr_set_color_fast(&Color_normal);
1979 if(MULTIPLAYER_MASTER){
1980 gr_string(sx, sy, "SERVER"); sy += 10;
1982 for(idx=0; idx<MAX_PLAYERS; idx++){
1983 if(MULTI_CONNECTED(Net_players[idx]) && (Net_player != &Net_players[idx]) && (Net_players[idx].player != NULL)){
1984 if(Net_players[idx].sv_last_pl < 0){
1985 gr_printf(sx, sy, "%s : %d, %d pl", Net_players[idx].player->callsign, Net_players[idx].sv_bytes_sent, 0); sy += 10;
1987 gr_printf(sx, sy, "%s : %d, %d pl", Net_players[idx].player->callsign, Net_players[idx].sv_bytes_sent, Net_players[idx].sv_last_pl); sy += 10;
1992 gr_string(sx, sy, "CLIENT"); sy += 10;
1995 if(Net_player != NULL){
1996 if(Net_player->cl_last_pl < 0){
1997 gr_printf(sx, sy, "PL : %d %d pl\n", Net_player->cl_bytes_recvd, 0);// sy += 10;
1999 gr_printf(sx, sy, "PL : %d %d pl\n", Net_player->cl_bytes_recvd, Net_player->cl_last_pl);// sy += 10;