2 * $Logfile: /Freespace2/code/Network/Multi.cpp $
7 * C file that contains high-level multiplayer functions
10 * Revision 1.2 2002/05/07 03:16:47 theoddone33
11 * The Great Newline Fix
13 * Revision 1.1.1.1 2002/05/03 03:28:10 root
17 * 47 9/15/99 1:45a Dave
18 * Don't init joystick on standalone. Fixed campaign mode on standalone.
19 * Fixed no-score-report problem in TvT
21 * 46 8/24/99 1:49a Dave
22 * Fixed client-side afterburner stuttering. Added checkbox for no version
23 * checking on PXO join. Made button info passing more friendly between
26 * 45 8/22/99 5:53p Dave
27 * Scoring fixes. Added self destruct key. Put callsigns in the logfile
28 * instead of ship designations for multiplayer players.
30 * 44 8/22/99 1:19p Dave
31 * Fixed up http proxy code. Cleaned up scoring code. Reverse the order in
32 * which d3d cards are detected.
34 * 43 8/19/99 10:59a Dave
35 * Packet loss detection.
37 * 42 8/16/99 4:05p Dave
38 * Big honking checkin.
40 * 41 8/06/99 12:34a Dave
41 * Be more careful about resetting timestamps.
43 * 40 8/04/99 2:24a Dave
44 * Fixed escort gauge ordering for dogfight.
46 * 39 7/26/99 5:50p Dave
47 * Revised ingame join. Better? We'll see....
49 * 38 7/08/99 10:53a Dave
50 * New multiplayer interpolation scheme. Not 100% done yet, but still
51 * better than the old way.
53 * 37 7/06/99 4:24p Dave
54 * Mid-level checkin. Starting on some potentially cool multiplayer
57 * 36 7/03/99 5:50p Dave
58 * Make rotated bitmaps draw properly in padlock views.
60 * 35 6/21/99 7:24p Dave
61 * netplayer pain packet. Added type E unmoving beams.
63 * 34 6/07/99 9:51p Dave
64 * Consolidated all multiplayer ports into one.
66 * 33 6/04/99 9:52a Dave
67 * Fixed some rendering problems.
69 * 32 5/22/99 6:05p Dave
70 * Fixed a few localization # problems.
72 * 31 5/22/99 5:35p Dave
73 * Debrief and chatbox screens. Fixed small hi-res HUD bug.
75 * 30 5/14/99 1:59p Andsager
76 * Multiplayer message for subsystem cargo revealed.
78 * 29 4/29/99 2:29p Dave
79 * Made flak work much better in multiplayer.
81 * 28 4/28/99 11:13p Dave
82 * Temporary checkin of artillery code.
84 * 27 4/25/99 7:43p Dave
85 * Misc small bug fixes. Made sun draw properly.
87 * 26 4/25/99 3:02p Dave
88 * Build defines for the E3 build.
90 * 25 4/12/99 10:07p Dave
91 * Made network startup more forgiving. Added checkmarks to dogfight
92 * screen for players who hit commit.
94 * 24 4/09/99 2:21p Dave
95 * Multiplayer beta stuff. CD checking.
97 * 23 3/19/99 9:51a Dave
98 * Checkin to repair massive source safe crash. Also added support for
99 * pof-style nebulae, and some new weapons code.
101 * 23 3/11/99 5:53p Dave
102 * More network optimization. Spliced in Dell OEM planet bitmap crap.
104 * 22 3/10/99 6:50p Dave
105 * Changed the way we buffer packets for all clients. Optimized turret
106 * fired packets. Did some weapon firing optimizations.
108 * 21 3/09/99 6:24p Dave
109 * More work on object update revamping. Identified several sources of
110 * unnecessary bandwidth.
112 * 20 3/08/99 7:03p Dave
113 * First run of new object update system. Looks very promising.
115 * 19 3/02/99 4:40p Jasons
116 * Be more careful when calling server-lost-contact popup (make sure other
117 * popups aren't active)
119 * 18 3/01/99 7:39p Dave
120 * Added prioritizing ship respawns. Also fixed respawns in TvT so teams
121 * don't mix respawn points.
123 * 17 2/23/99 2:29p Dave
124 * First run of oldschool dogfight mode.
126 * 16 2/19/99 2:55p Dave
127 * Temporary checking to report the winner of a squad war match.
129 * 15 2/17/99 2:10p Dave
130 * First full run of squad war. All freespace and tracker side stuff
133 * 14 2/12/99 6:16p Dave
134 * Pre-mission Squad War code is 95% done.
136 * 13 2/11/99 3:08p Dave
137 * PXO refresh button. Very preliminary squad war support.
139 * 12 1/14/99 12:48a Dave
140 * Todo list bug fixes. Made a pass at putting briefing icons back into
141 * FRED. Sort of works :(
143 * 11 1/12/99 5:45p Dave
144 * Moved weapon pipeline in multiplayer to almost exclusively client side.
145 * Very good results. Bandwidth goes down, playability goes up for crappy
146 * connections. Fixed object update problem for ship subsystems.
148 * 10 12/14/98 12:13p Dave
149 * Spiffed up xfer system a bit. Put in support for squad logo file xfer.
152 * 9 12/03/98 5:22p Dave
153 * Ported over Freespace 1 multiplayer ships.tbl and weapons.tbl
156 * 8 11/19/98 4:19p Dave
157 * Put IPX sockets back in psnet. Consolidated all multiplayer config
160 * 7 11/19/98 8:03a Dave
161 * Full support for D3-style reliable sockets. Revamped packet lag/loss
162 * system, made it receiver side and at the lowest possible level.
164 * 6 11/17/98 11:12a Dave
165 * Removed player identification by address. Now assign explicit id #'s.
167 * 5 11/12/98 12:13a Dave
168 * Tidied code up for multiplayer test. Put in network support for flak
179 #include "multiutil.h"
180 #include "multimsgs.h"
182 #include "linklist.h"
188 #include "missionload.h"
189 #include "missionparse.h"
190 #include "missionshipchoice.h"
191 #include "gamesequence.h"
192 #include "freespace.h"
197 #include "stand_gui.h"
198 #include "multi_xfer.h"
201 #include "multilag.h"
202 #include "multiutil.h"
203 #include "multi_ingame.h"
208 #include "multiteamselect.h"
209 #include "multi_data.h"
210 #include "multi_kick.h"
211 #include "multi_campaign.h"
212 #include "multi_voice.h"
213 #include "multi_team.h"
214 #include "multi_respawn.h"
215 #include "multi_pmsg.h"
216 #include "multi_endgame.h"
217 #include "missiondebrief.h"
218 #include "multi_pause.h"
219 #include "multi_obj.h"
220 #include "missiongoals.h"
221 #include "multi_log.h"
222 #include "multi_rate.h"
223 #include "hudescort.h"
224 #include "alphacolors.h"
226 // ----------------------------------------------------------------------------------------
227 // Basic module scope defines
232 // #define NETGAME_SEND_TIME 1000 // time between sending netgame update packets
233 // #define STATE_SEND_TIME 1000 // time between sending netplayer state packets
234 // #define GAMEINFO_SEND_TIME 3000 // time between sending game information packets
235 // #define PING_SEND_TIME 2000 // time between player pings
236 // #define INGAME_UPDATE_TIME 1000 // time limit between ingame join operations
237 #define NETGAME_SEND_TIME 2 // time between sending netgame update packets
238 #define STATE_SEND_TIME 2 // time between sending netplayer state packets
239 #define GAMEINFO_SEND_TIME 3 // time between sending game information packets
240 #define PING_SEND_TIME 2 // time between player pings
241 #define BYTES_SENT_TIME 5 // every five seconds
244 #define CULL_ZOMBIE_TIME 1000 // zombies are checked for at this interval (in milliseconds)
246 // object update stuff
247 #define SEND_POS_INTERVAL 30 // min time in milliseconds between sending position updates
249 // local network buffer stuff
250 #define MAX_NET_BUFFER (1024 * 16) // define and variable declaration for our local tcp buffer
251 #define NUM_REENTRANT_LEVELS 3
253 // time (in fixed seconds) to put up dialog about no contect from server
254 #define MULTI_SERVER_MAX_TIMEOUT (F1_0 * 4) // after this number of milliseoncds, stop client simulation
255 #define MULTI_SERVER_MAX_TIMEOUT_LARGE (F1_0 * 40) // done anytime not in mission
256 #define MULTI_SERVER_WAIT_TIME (F1_0 * 60) // wait 60 seconds to reconnect with the server
257 #define MULTI_SERVER_GONE 1
258 #define MULTI_SERVER_ALIVE 2
260 #define DISCONNECT_TIMEOUT (F1_0 * 10) // 10 seconds to timeout someone who cannot connnect
262 // define for when to show "slow network" icon
263 #define MULTI_SERVER_SLOW_PING_TIME 700 // when average ping time to server reaches this -- display hud icon
265 // update times for clients ships based on object update level
266 #define MULTI_CLIENT_UPDATE_TIME 333
268 int Multi_display_netinfo = 1;
270 // ----------------------------------------------------------------------------------------
276 net_player Net_players[MAX_PLAYERS]; // array of all netplayers in the game
277 net_player *Net_player; // pointer to console's net_player entry
279 // network object management
280 ushort Next_ship_signature; // next permanent network signature to assign to an object
281 ushort Next_asteroid_signature; // next signature for an asteroid
282 ushort Next_non_perm_signature; // next non-permanent network signature to assign to an object
283 ushort Next_debris_signature; // next debris signature
286 netgame_info Netgame; // netgame information
287 int Multi_mission_loaded = 0; // flag, so that we dont' load the mission more than once client side
288 int Ingame_join_net_signature = -1; // signature for the player obj for use when joining ingame
289 int Multi_button_info_ok = 0; // flag saying it is ok to apply critical button info on a client machine
290 int Multi_button_info_id = 0; // identifier of the stored button info to be applying
292 // low level networking vars
293 int ADDRESS_LENGTH; // will be 6 for IPX, 4 for IP
294 int PORT_LENGTH; // will be 2 for IPX, 2 for IP
295 int HEADER_LENGTH; // 1 byte (packet type)
298 active_game* Active_game_head; // linked list of active games displayed on Join screen
299 int Active_game_count; // for interface screens as well
300 CFILE* Multi_chat_stream; // for streaming multiplayer chat strings to a file
301 int Multi_has_cd = 0; // if this machine has a cd or not (call multi_common_verify_cd() to set this)
302 int Multi_connection_speed; // connection speed of this machine.
303 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
304 short Multi_id_num = 0; // for assigning player id #'s
306 // permanent server list
307 server_item* Game_server_head; // list of permanent game servers to be querying
310 int Netgame_send_time = -1; // timestamp used to send netgame info to players before misison starts
311 int State_send_time = -1; // timestamp used to send state information to the host before a mission starts
312 int Gameinfo_send_time = -1; // timestamp used by master to send game information to clients
313 int Next_ping_time = -1; // when we should next ping all
314 int Multi_server_check_count = 0; // var to keep track of reentrancy when checking server status
315 int Next_bytes_time = -1; // bytes sent
317 // how often each player gets updated
318 int Multi_client_update_times[MAX_PLAYERS]; // client update packet timestamp
320 // local network buffer data
321 LOCAL ubyte net_buffer[NUM_REENTRANT_LEVELS][MAX_NET_BUFFER];
322 LOCAL ubyte Multi_read_count;
324 int Multi_restr_query_timestamp = -1;
325 join_request Multi_restr_join_request;
326 net_addr Multi_restr_addr;
327 int Multi_join_restr_mode = -1;
329 LOCAL fix Multi_server_wait_start; // variable to hold start time when waiting to reestablish with server
331 // non API master tracker vars
332 char Multi_tracker_login[100] = "";
333 char Multi_tracker_passwd[100] = "";
334 char Multi_tracker_squad_name[100] = "";
335 int Multi_tracker_id = -1;
336 char Multi_tracker_id_string[255];
338 // current file checksum
339 ushort Multi_current_file_checksum = 0;
340 int Multi_current_file_length = -1;
343 // -------------------------------------------------------------------------------------------------
344 // multi_init() is called only once, at game start-up. Get player address + port, initialize the
345 // network players list.
353 // read in config file
354 multi_options_read_config();
356 Assert( Net_player == NULL );
359 // clear out all netplayers
360 memset(Net_players, 0, sizeof(net_player) * MAX_PLAYERS);
361 for(idx=0; idx<MAX_PLAYERS; idx++){
362 Net_players[idx].reliable_socket = INVALID_SOCKET;
365 // initialize the local netplayer
366 Net_player = &Net_players[0];
367 Net_player->tracker_player_id = Multi_tracker_id;
368 Net_player->player = Player;
369 Net_player->flags = 0;
370 Net_player->s_info.xfer_handle = -1;
371 Net_player->player_id = multi_get_new_id();
372 Net_player->client_cinfo_seq = 0;
373 Net_player->client_server_seq = 0;
375 // get our connection speed
376 Multi_connection_speed = multi_get_connection_speed();
378 // initialize other stuff
381 // load up common multiplayer icons
382 multi_load_common_icons();
385 // this is an important function which re-initializes any variables required in multiplayer games.
386 // Always make sure globals you add are re-initialized here !!!!
387 void multi_vars_init()
389 // initialize this variable right away. Used in game_level_init for init'ing the player
390 Next_ship_signature = SHIP_SIG_MIN;
391 Next_asteroid_signature = ASTEROID_SIG_MIN;
392 Next_non_perm_signature = NPERM_SIG_MIN;
393 Next_debris_signature = DEBRIS_SIG_MIN;
395 // server-client critical stuff
396 Multi_button_info_ok = 0;
397 Multi_button_info_id = 0;
400 Ingame_join_net_signature = -1;
403 Netgame.game_state = NETGAME_STATE_FORMING;
409 Multi_mission_loaded = 0; // client side
411 // restricted game stuff
412 Multi_restr_query_timestamp = -1;
415 Multi_server_check_count = 0;
417 // reentrant variable
418 Multi_read_count = 0;
420 // unset the "have cd" var
421 // NOTE: we unset this here because we are going to be calling multi_common_verify_cd()
422 // immediately after this (in multi_level_init() to re-check the status)
425 // current file checksum
426 Multi_current_file_checksum = 0;
427 Multi_current_file_length = -1;
429 Active_game_head = NULL;
430 Game_server_head = NULL;
432 // only the server should ever care about this
436 // -------------------------------------------------------------------------------------------------
437 // multi_level_init() is called whenever the player starts a multiplayer game
441 void multi_level_init()
446 ml_string(NOX("multi_level_init()"));
448 // initialize the Net_players array
449 for(idx=0;idx<MAX_PLAYERS;idx++) {
450 // close all sockets down just for good measure
451 psnet_rel_close_socket(&Net_players[idx].reliable_socket);
453 memset(&Net_players[idx],0,sizeof(net_player));
454 Net_players[idx].reliable_socket = INVALID_SOCKET;
456 Net_players[idx].s_info.xfer_handle = -1;
457 Net_players[idx].p_info.team = 0;
460 // initialize the Players array
461 for(idx=0;idx<MAX_PLAYERS;idx++){
462 if(Player == &Players[idx]){
465 memset(&Players[idx],0,sizeof(player));
470 // initialize the fake lag/loss system
475 // initialize the kick system
478 // initialize all file xfer stuff
479 multi_xfer_init(multi_file_xfer_notify);
481 // close the chatbox (if one exists)
484 // reset the data xfer system
487 // initialize the voice system
490 // intialize the pause system
493 // initialize endgame stuff
494 multi_endgame_init();
496 // initialize respawning
497 multi_respawn_init();
499 // initialize all netgame timestamps
500 multi_reset_timestamps();
502 // flush psnet sockets
506 // multi_check_listen() calls low level psnet routine to see if we have a connection from a client we
508 void multi_check_listen()
512 PSNET_SOCKET_RELIABLE sock = INVALID_SOCKET;
514 // call psnet routine which calls select to see if we need to check for a connect from a client
515 // by passing addr, we are telling check_for_listen to do the accept and return who it was from in
517 sock = psnet_rel_check_for_listen(&addr);
518 if ( sock != INVALID_SOCKET ) {
519 // be sure that my address and the server address are set correctly.
520 if ( !psnet_same(&Psnet_my_addr, &Net_player->p_info.addr) ){
521 Net_player->p_info.addr = Psnet_my_addr;
524 if ( !psnet_same(&Psnet_my_addr, &(Netgame.server_addr)) ){
525 Netgame.server_addr = Psnet_my_addr;
528 // the connection was accepted in check_for_listen. Find the netplayer whose address we connected
529 // with and assign the socket descriptor
530 for (i = 0; i < MAX_PLAYERS; i++ ) {
531 if ( (Net_players[i].flags & NETINFO_FLAG_CONNECTED) && (!memcmp(&(addr.addr), &(Net_players[i].p_info.addr.addr), 6)) ) {
532 // mark this flag so we know he's "fully" connected
533 Net_players[i].flags |= NETINFO_FLAG_RELIABLE_CONNECTED;
534 Net_players[i].reliable_socket = sock;
536 // send player information to the joiner
537 send_accept_player_data( &Net_players[i], (Net_players[i].flags & NETINFO_FLAG_INGAME_JOIN)?1:0 );
539 // send a netgame update so the new client has all the necessary settings
540 send_netgame_update_packet();
542 // if this is a team vs. team game, send an update
543 if(Netgame.type_flags & NG_TYPE_TEAM){
544 multi_team_send_update();
548 ml_printf(NOX("Accepted TCP connection from %s"), Net_players[i].player == NULL ? NOX("Unknown") : Net_players[i].player->callsign);
553 // if we didn't find a player, close the socket
554 if ( i == MAX_PLAYERS ) {
555 nprintf(("Network", "Got accept on my listen socket, but unknown player. Closing socket.\n"));
556 psnet_rel_close_socket(&sock);
561 // returns true is server hasn't been heard from in N seconds. false otherwise
562 int multi_client_server_dead()
564 fix this_time, last_time, max;
566 // get the last time we have heard from the server. If greater than some default, then maybe
567 // display some icon on the HUD indicating slow network connection. if greater than some higher
568 // max, stop simulating on the client side until we hear from the server again.
569 this_time = timer_get_fixed_seconds();
570 last_time = Netgame.server->last_heard_time;
571 // check for wrap! must return 0
572 if ( last_time > this_time )
575 this_time -= last_time;
577 // if in mission, use the smaller timeout value. Outside of mission, use a large one.
578 if ( MULTI_IN_MISSION ){
579 max = MULTI_SERVER_MAX_TIMEOUT;
581 max = MULTI_SERVER_MAX_TIMEOUT_LARGE;
584 if ( this_time > max){
591 void multi_process_incoming(); // prototype for function later in this module
593 // function to process network data in hopes of getting info back from server
594 int multi_client_wait_on_server()
598 is_dead = multi_client_server_dead();
600 // if the server is back alive, tell our popup
602 return MULTI_SERVER_ALIVE;
605 // on release version -- keep popup active for 60 seconds, then bail
607 fix this_time = timer_get_fixed_seconds();
608 // if the timer wrapped:
609 if ( this_time < Multi_server_wait_start ) {
610 Multi_server_wait_start = timer_get_fixed_seconds();
613 // check to see if timeout expired
614 this_time -= Multi_server_wait_start;
615 if ( this_time > MULTI_SERVER_WAIT_TIME ){
616 return MULTI_SERVER_GONE;
623 // function called by multiplayer clients to stop simulating when they have not heard from the server
625 void multi_client_check_server()
629 Assert( MULTIPLAYER_CLIENT );
631 // this function can get called while in the popup code below. So we include this check as a
633 if ( Multi_server_check_count )
636 // make sure we have a valid server
637 if(Netgame.server == NULL){
641 Multi_server_check_count++;
642 if(multi_client_server_dead()){
643 Netgame.flags |= NG_FLAG_SERVER_LOST;
645 Netgame.flags &= ~(NG_FLAG_SERVER_LOST);
648 if(Netgame.flags & NG_FLAG_SERVER_LOST) {
649 if(!(Game_mode & GM_IN_MISSION) && !popup_active()){
650 // need to start a popup
651 Multi_server_wait_start = timer_get_fixed_seconds();
652 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) );
654 if ( !rval || (rval == MULTI_SERVER_GONE) ) {
655 multi_quit_game(PROMPT_NONE, MULTI_END_NOTIFY_NONE, MULTI_END_ERROR_CONTACT_LOST);
657 Netgame.flags &= ~(NG_FLAG_SERVER_LOST);
661 Multi_server_check_count--;
665 // -------------------------------------------------------------------------------------------------
666 // process_packet_normal() will determine what sort of packet it is, and send it to the appropriate spot.
667 // Prelimiary verification of the magic number and checksum are done here.
670 void process_packet_normal(ubyte* data, header *header_info)
675 process_join_packet(data, header_info);
679 process_game_chat_packet( data, header_info );
682 case NOTIFY_NEW_PLAYER:
683 process_new_player_packet(data, header_info);
687 process_hud_message(data, header_info);
690 case MISSION_MESSAGE:
691 process_mission_message_packet( data, header_info );
695 process_leave_game_packet(data, header_info);
699 process_game_query(data, header_info);
703 process_game_active_packet(data, header_info);
707 process_game_info_packet( data, header_info );
710 case SECONDARY_FIRED_AI:
711 process_secondary_fired_packet(data, header_info, 0);
714 case SECONDARY_FIRED_PLR:
715 process_secondary_fired_packet(data, header_info, 1);
718 case COUNTERMEASURE_FIRED:
719 process_countermeasure_fired_packet( data, header_info );
722 case FIRE_TURRET_WEAPON:
723 process_turret_fired_packet( data, header_info );
727 process_netgame_update_packet( data, header_info );
730 case UPDATE_DESCRIPT:
731 process_netgame_descript_packet( data, header_info );
734 case NETPLAYER_UPDATE:
735 process_netplayer_update_packet( data, header_info );
739 process_accept_packet(data, header_info);
743 multi_oo_process_update(data, header_info);
747 process_ship_kill_packet( data, header_info );
751 process_wing_create_packet( data, header_info );
755 process_ship_create_packet( data, header_info );
759 process_ship_depart_packet( data, header_info );
762 case MISSION_LOG_ENTRY:
763 process_mission_log_packet( data, header_info );
767 process_ping_packet(data, header_info);
771 process_pong_packet(data, header_info);
775 Assert(header_info->id >= 0);
777 PSNET_SOCKET_RELIABLE sock;
778 sock = INVALID_SOCKET;
780 // if I'm the server of the game, find out who this came from
781 if((Net_player != NULL) && (Net_player->flags & NETINFO_FLAG_AM_MASTER)){
782 np_index = find_player_id(header_info->id);
784 sock = Net_players[np_index].reliable_socket;
787 // otherwise always use my own socket
788 else if(Net_player != NULL){
789 sock = Net_player->reliable_socket;
792 header_info->bytes_processed = multi_xfer_process_packet(data + HEADER_LENGTH, sock) + HEADER_LENGTH;
795 case MISSION_REQUEST:
796 process_mission_request_packet(data,header_info);
800 process_mission_item_packet(data,header_info);
803 case MULTI_PAUSE_REQUEST:
804 process_multi_pause_packet(data, header_info);
808 process_ingame_nak(data, header_info);
811 case SHIPS_INGAME_PACKET:
812 process_ingame_ships_packet(data, header_info);
815 case WINGS_INGAME_PACKET:
816 process_ingame_wings_packet(data, header_info);
820 process_endgame_packet(data, header_info);
823 case OBSERVER_UPDATE:
824 process_observer_update_packet(data, header_info);
827 case NETPLAYER_SLOTS_P:
828 process_netplayer_slot_packet(data, header_info);
831 case SHIP_STATUS_CHANGE:
832 process_ship_status_packet(data, header_info);
835 case PLAYER_ORDER_PACKET:
836 process_player_order_packet(data, header_info);
839 case INGAME_SHIP_UPDATE:
840 process_ingame_ship_update_packet(data, header_info);
843 case INGAME_SHIP_REQUEST:
844 process_ingame_ship_request_packet(data, header_info);
848 process_file_sig_packet(data, header_info);
852 multi_respawn_process_packet(data,header_info);
855 case SUBSYSTEM_DESTROYED:
856 process_subsystem_destroyed_packet( data, header_info );
859 case LOAD_MISSION_NOW :
860 process_netplayer_load_packet(data, header_info);
863 case FILE_SIG_REQUEST :
864 process_file_sig_request(data, header_info);
868 process_jump_into_mission_packet(data, header_info);
871 case CLIENT_REPAIR_INFO:
872 process_repair_info_packet(data,header_info);
875 case MISSION_SYNC_DATA:
876 process_mission_sync_packet(data,header_info);
879 case STORE_MISSION_STATS:
880 process_store_stats_packet(data, header_info);
884 process_debris_update_packet(data, header_info);
887 case SHIP_WSTATE_CHANGE:
888 process_ship_weapon_change( data, header_info );
891 case WSS_UPDATE_PACKET:
892 process_wss_update_packet(data, header_info);
895 case WSS_REQUEST_PACKET:
896 process_wss_request_packet( data, header_info );
900 process_firing_info_packet( data, header_info );
904 process_cargo_revealed_packet( data, header_info);
907 case SUBSYS_CARGO_REVEALED:
908 process_subsystem_cargo_revealed_packet( data, header_info);
911 case MISSION_GOAL_INFO:
912 process_mission_goal_info_packet(data, header_info);
916 process_player_kick_packet(data, header_info);
919 case PLAYER_SETTINGS:
920 process_player_settings_packet(data, header_info);
924 process_deny_packet(data, header_info);
928 process_post_sync_data_packet(data, header_info);
932 process_wss_slots_data_packet(data,header_info);
935 case SHIELD_EXPLOSION:
936 process_shield_explosion_packet( data, header_info );
940 process_player_stats_block_packet(data, header_info);
944 process_pslot_update_packet(data,header_info);
948 process_ai_info_update_packet( data, header_info );
951 case CAMPAIGN_UPDATE :
952 multi_campaign_process_update(data,header_info);
955 case CAMPAIGN_UPDATE_INGAME:
956 multi_campaign_process_ingame_start(data,header_info);
960 multi_voice_process_packet(data,header_info);
964 multi_team_process_packet(data,header_info);
968 process_asteroid_info(data, header_info);
971 case HOST_RESTR_QUERY:
972 process_host_restr_packet(data, header_info);
976 multi_options_process_packet(data,header_info);
979 case SQUADMSG_PLAYER:
980 multi_msg_process_squadmsg_packet(data,header_info);
983 case NETGAME_END_ERROR:
984 process_netgame_end_error_packet(data,header_info);
987 case COUNTERMEASURE_SUCCESS:
988 process_countermeasure_success_packet( data, header_info );
992 process_client_update_packet(data, header_info);
996 process_countdown_packet(data, header_info);
1000 process_debrief_info( data, header_info );
1003 case ACCEPT_PLAYER_DATA:
1004 process_accept_player_data( data, header_info );
1007 case HOMING_WEAPON_UPDATE:
1008 process_homing_weapon_info( data, header_info );
1012 process_emp_effect(data, header_info);
1015 case REINFORCEMENT_AVAIL:
1016 process_reinforcement_avail( data, header_info );
1020 process_change_iff_packet(data, header_info);
1023 case PRIMARY_FIRED_NEW:
1024 process_NEW_primary_fired_packet(data, header_info);
1027 case COUNTERMEASURE_NEW:
1028 process_NEW_countermeasure_fired_packet(data, header_info);
1032 process_beam_fired_packet(data, header_info);
1036 process_sw_query_packet(data, header_info);
1040 process_event_update_packet(data, header_info);
1043 case OBJECT_UPDATE_NEW:
1044 multi_oo_process_update(data, header_info);
1048 process_weapon_detonate_packet(data, header_info);
1052 process_flak_fired_packet(data, header_info);
1055 case NETPLAYER_PAIN:
1056 process_player_pain_packet(data, header_info);
1059 case LIGHTNING_PACKET:
1060 process_lightning_packet(data, header_info);
1064 process_bytes_recvd_packet(data, header_info);
1068 process_host_captain_change_packet(data, header_info);
1072 process_self_destruct_packet(data, header_info);
1076 nprintf(("Network", "Received packet with unknown type %d\n", data[0] ));
1077 header_info->bytes_processed = 10000;
1085 // Takes a bunch of messages, check them for validity,
1086 // and pass them to multi_process_data.
1087 // --------------------^
1088 // this should be process_packet() I think, or with the new code
1089 // process_tracker_packet() as defined in MultiTracker.[h,cpp]
1090 void multi_process_bigdata(ubyte *data, int len, net_addr *from_addr, int reliable)
1092 int type, bytes_processed;
1097 // the only packets we will process from an unknown player are GAME_QUERY, GAME_INFO, JOIN, PING, PONG, ACCEPT, and GAME_ACTIVE packets
1098 player_num = find_player(from_addr);
1100 // find the player who sent the message and mark the last_heard time for this player
1101 // check to see if netplayer is null (it may be in cases such as getting lists of games from the tracker)
1102 if(player_num >= 0){
1103 Net_players[player_num].last_heard_time = timer_get_fixed_seconds();
1106 // store fields that were passed along in the message
1107 // store header information that was captured from the network-layer header
1108 memcpy(header_info.addr, from_addr->addr, 6);
1109 memcpy(header_info.net_id, from_addr->net_id, 4);
1110 header_info.port = from_addr->port;
1111 if(player_num >= 0){
1112 header_info.id = Net_players[player_num].player_id;
1114 header_info.id = -1;
1117 bytes_processed = 0;
1118 while( (bytes_processed >= 0) && (bytes_processed < len) ) {
1120 buf = &(data[bytes_processed]);
1124 // if its coming from an unknown source, there are only certain packets we will actually process
1125 if((player_num == -1) && !multi_is_valid_unknown_packet((ubyte)type)){
1129 if ( (type<0) || (type > MAX_TYPE_ID )) {
1130 nprintf( ("Network", "multi_process_bigdata: Invalid packet type %d!\n", type ));
1134 // perform any special processing checks here
1135 process_packet_normal(buf,&header_info);
1137 // MWA -- magic number was removed from header on 8/4/97. Replaced with bytes_processed
1138 // variable which gets stuffed whenever a packet is processed.
1139 bytes_processed += header_info.bytes_processed;
1142 // if this is not reliable data and we have a valid player
1143 if(Net_player != NULL){
1144 if(!MULTIPLAYER_MASTER && !reliable && (Game_mode & GM_IN_MISSION)){
1145 Net_player->cl_bytes_recvd += len;
1150 // process all reliable socket details
1151 void multi_process_reliable_details()
1156 // run reliable sockets
1161 // server operations
1162 if ( MULTIPLAYER_MASTER ){
1163 // listen for new reliable socket connections
1164 multi_check_listen();
1166 // check for any broken sockets and delete any players
1167 for(idx=0; idx<MAX_PLAYERS; idx++){
1168 // players who _should_ be validly connected
1169 if((idx != MY_NET_PLAYER_NUM) && MULTI_CONNECTED(Net_players[idx])){
1170 // if this guy's socket is broken or disconnected, kill him
1171 sock_status = psnet_rel_get_status(Net_players[idx].reliable_socket);
1172 if((sock_status == RNF_UNUSED) || (sock_status == RNF_BROKEN) || (sock_status == RNF_DISCONNECTED)){
1173 ml_string("Shutting down rel socket because of disconnect!");
1177 // if we're still waiting for this guy to connect on his reliable socket and he's timed out, boot him
1178 if(Net_players[idx].s_info.reliable_connect_time != -1){
1179 // if he's connected
1180 if(Net_players[idx].reliable_socket != INVALID_SOCKET){
1181 Net_players[idx].s_info.reliable_connect_time = -1;
1183 // if he's timed out
1184 else if(((time(NULL) - Net_players[idx].s_info.reliable_connect_time) > MULTI_RELIABLE_CONNECT_WAIT) && (Net_players[idx].reliable_socket == INVALID_SOCKET)){
1185 ml_string("Player timed out while connecting on reliable socket!");
1192 // clients should detect broken sockets
1194 extern unsigned int Serverconn;
1195 if(Serverconn != 0xffffffff){
1196 int status = psnet_rel_get_status(Serverconn);
1197 if(status == RNF_BROKEN){
1198 mprintf(("CLIENT SOCKET DISCONNECTED"));
1201 if(!multi_endgame_ending()){
1202 multi_quit_game(PROMPT_NONE, MULTI_END_NOTIFY_NONE, MULTI_END_ERROR_CONTACT_LOST);
1209 // multi_process_incoming reads incoming data off the unreliable and reliable ports and sends
1210 // the data to process_big_data
1211 void multi_process_incoming()
1214 ubyte *data, *savep;
1217 Assert( Multi_read_count < NUM_REENTRANT_LEVELS );
1218 savep = net_buffer[Multi_read_count];
1224 // get the other net players data
1225 while( (size = psnet_get(data, &from_addr))>0 ) {
1226 // ingame joiners will ignore UDP packets until they are have picked a ship and are in the mission
1227 if( (Net_player->flags & NETINFO_FLAG_INGAME_JOIN) && (Net_player->state != NETPLAYER_STATE_INGAME_SHIP_SELECT) ){
1228 //nprintf(("Network","Tossing UDP like a good little ingame joiner...\n"));
1230 // otherwise process incoming data normally
1232 multi_process_bigdata(data, size, &from_addr, 0);
1236 // read reliable sockets for data
1240 if(Net_player->flags & NETINFO_FLAG_AM_MASTER){
1241 for (idx=0;idx<MAX_PLAYERS;idx++) {
1242 if((Net_players[idx].flags & NETINFO_FLAG_CONNECTED) && (Net_player != NULL) && (Net_player->player_id != Net_players[idx].player_id)){
1243 while( (size = psnet_rel_get(Net_players[idx].reliable_socket, data, MAX_NET_BUFFER)) > 0){
1244 multi_process_bigdata(data, size, &Net_players[idx].p_info.addr, 1);
1249 // if I'm not the master of the game, read reliable data from my connection with the server
1250 if((Net_player->reliable_socket != INVALID_SOCKET) && (Net_player->reliable_socket != 0)){
1251 while( (size = psnet_rel_get(Net_player->reliable_socket,data, MAX_NET_BUFFER)) > 0){
1252 multi_process_bigdata(data, size, &Netgame.server_addr, 1);
1260 // -------------------------------------------------------------------------------------------------
1261 // multi_do_frame() is called once per game loop do update all the multiplayer objects, and send
1262 // the player data to all the other net players.
1271 dc_printf("proper eye stuff on\n");
1273 dc_printf("proper eye stuff off\n");
1277 void multi_do_frame()
1279 PSNET_TOP_LAYER_PROCESS();
1281 // always set the local player eye position/orientation here so we know its valid throughout all multiplayer
1283 if((Net_player != NULL) && eye_tog){
1284 player_get_eye(&Net_player->s_info.eye_pos, &Net_player->s_info.eye_orient);
1287 // send all buffered packets from the previous frame
1288 multi_io_send_buffered_packets();
1290 // datarate tracking
1291 multi_rate_process();
1293 // always process any pending endgame details
1294 multi_endgame_process();
1296 // process all reliable socket details, including :
1297 // 1.) Listening for new pending reliable connections (server)
1298 // 2.) Checking for broken sockets (server/client)
1299 // 3.) Checking for clients who haven't fully connected
1300 multi_process_reliable_details();
1302 // get the other net players data
1303 multi_process_incoming();
1305 // process object update datarate stuff (for clients and server both)
1306 multi_oo_rate_process();
1308 // clients should check when last time they heard from sever was -- if too long, then
1309 // pause the simulation so wait for it to possibly come back
1310 if ( (MULTIPLAYER_CLIENT) && (Net_player->flags & NETINFO_FLAG_CONNECTED) ){
1311 multi_client_check_server();
1314 // everybody pings all the time
1315 if((Next_ping_time < 0) || ((time(NULL) - Next_ping_time) > PING_SEND_TIME) ){
1316 if( (Net_player->flags & NETINFO_FLAG_AM_MASTER) ){
1317 send_netplayer_update_packet();
1321 multi_ping_send_all();
1322 Next_ping_time = time(NULL);
1325 // if I am the master, and we are not yet actually playing the mission, send off netgame
1326 // status to all other players in the game. If I am not the master of the game, and we
1327 // are not in the game, then send out my netplayer status to the host
1328 if ( (Net_player->flags & NETINFO_FLAG_CONNECTED) && !(Game_mode & GM_IN_MISSION)){
1329 if ( Net_player->flags & NETINFO_FLAG_AM_MASTER ) {
1330 if ( (Netgame_send_time < 0) || ((time(NULL) - Netgame_send_time) > NETGAME_SEND_TIME) ) {
1331 send_netgame_update_packet();
1333 Netgame_send_time = time(NULL);
1336 if ( (State_send_time < 0) || ((time(NULL) - State_send_time) > STATE_SEND_TIME) ){
1337 // observers shouldn't send an update state packet
1338 if ( !(Net_player->flags & NETINFO_FLAG_OBSERVER) ){
1339 send_netplayer_update_packet();
1342 State_send_time = time(NULL);
1346 else if ( (Net_player->flags & NETINFO_FLAG_CONNECTED) && (Game_mode & GM_IN_MISSION) ) {
1347 // if I am connected and am in the mission, do things that need to be done on a regular basis
1348 if ( Net_player->flags & NETINFO_FLAG_AM_MASTER ) {
1349 if ( (Gameinfo_send_time < 0) || ((time(NULL) - Gameinfo_send_time) > GAMEINFO_SEND_TIME)){
1350 send_game_info_packet();
1352 Gameinfo_send_time = time(NULL);
1355 // for any potential respawns
1356 multi_respawn_handle_invul_players();
1357 multi_respawn_check_ai();
1359 // for any potential ingame joiners
1360 multi_handle_ingame_joiners();
1362 // the clients need to do some processing of stuff as well
1366 // check to see if we're waiting on confirmation for a restricted ingame join
1367 if(Multi_restr_query_timestamp != -1){
1368 // if it has elapsed, unset the ingame join flag
1369 if(timestamp_elapsed(Multi_restr_query_timestamp)){
1370 Multi_restr_query_timestamp = -1;
1371 Netgame.flags &= ~(NG_FLAG_INGAME_JOINING);
1375 // while in the mission, send my PlayerControls to the host so that he can process
1377 if ( Game_mode & GM_IN_MISSION ) {
1379 extern void oo_update_time();
1383 if ( !(Net_player->flags & NETINFO_FLAG_AM_MASTER)){
1384 if(Net_player->flags & NETINFO_FLAG_OBSERVER){
1385 // if the rate limiting system says its ok
1386 if(multi_oo_cirate_can_send()){
1387 // send my observer position/object update
1388 send_observer_update_packet();
1390 } else if ( !(Player_ship->flags & SF_DEPARTING ) ){
1391 // if the rate limiting system says its ok
1392 if(multi_oo_cirate_can_send()){
1393 // use the new method
1394 multi_oo_send_control_info();
1398 // bytes received info
1399 if( (Next_bytes_time < 0) || ((time(NULL) - Next_bytes_time) > BYTES_SENT_TIME) ){
1400 if(Net_player != NULL){
1401 send_bytes_recvd_packet(Net_player);
1403 // reset bytes recvd
1404 Net_player->cl_bytes_recvd = 0;
1408 Next_bytes_time = time(NULL);
1411 // sending new objects from here is dependent on having objects only created after
1412 // the game is done moving the objects. I think that I can enforce this.
1415 // evaluate whether the time limit has been reached or max kills has been reached
1416 // Commented out by Sandeep 4/12/98, was causing problems with testing.
1417 if( ((f2fl(Netgame.options.mission_time_limit) > 0.0f) && (Missiontime > Netgame.options.mission_time_limit)) ||
1418 multi_kill_limit_reached() ) {
1420 // make sure we don't do this more than once
1421 if(Netgame.game_state == NETGAME_STATE_IN_MISSION){
1422 multi_handle_end_mission_request();
1428 // periodically send a client update packet to all clients
1429 if((Net_player != NULL) && (Net_player->flags & NETINFO_FLAG_AM_MASTER)){
1431 for(idx=0;idx<MAX_PLAYERS;idx++){
1432 if(MULTI_CONNECTED(Net_players[idx]) && (Net_player != &Net_players[idx])){
1433 if((Multi_client_update_times[idx] < 0) || timestamp_elapsed_safe(Multi_client_update_times[idx], 1000)){
1435 send_client_update_packet(&Net_players[idx]);
1437 Multi_client_update_times[idx] = timestamp(MULTI_CLIENT_UPDATE_TIME);
1443 // process any kicked player details
1444 multi_kick_process();
1446 // do any file xfer details
1449 // process any player data details (wav files, pilot pics, etc)
1452 // do any voice details
1453 multi_voice_process();
1455 // process any player messaging details
1456 multi_msg_process();
1458 // if on the standalone, do any gui stuff
1459 if(Game_mode & GM_STANDALONE_SERVER){
1463 // dogfight nonstandalone players should recalc the escort list every frame
1464 if(!(Game_mode & GM_STANDALONE_SERVER) && (Netgame.type_flags & NG_TYPE_DOGFIGHT) && MULTI_IN_MISSION){
1465 hud_setup_escort_list(0);
1469 // -------------------------------------------------------------------------------------------------
1470 // multi_pause_do_frame() is called once per game loop do update all the multiplayer objects, and send
1471 // the player data to all the other net players when the multiplayer game is paused. It only will do
1472 // checking for a few specialized packets (MULTI_UNPAUSE, etc)
1475 void multi_pause_do_frame()
1477 PSNET_TOP_LAYER_PROCESS();
1479 // always set the local player eye position/orientation here so we know its valid throughout all multiplayer
1481 // if((Net_player != NULL) && eye_tog){
1482 // player_get_eye(&Net_player->s_info.eye_pos, &Net_player->s_info.eye_orient);
1485 // send all buffered packets from the previous frame
1486 multi_io_send_buffered_packets();
1488 // always process any pending endgame details
1489 multi_endgame_process();
1491 // process all reliable socket details, including :
1492 // 1.) Listening for new pending reliable connections (server)
1493 // 2.) Checking for broken sockets (server/client)
1494 // 3.) Checking for clients who haven't fully connected
1495 multi_process_reliable_details();
1497 // these timestamps and handlers shoul be evaluated in the pause state
1498 if ( Net_player->flags & NETINFO_FLAG_AM_MASTER ) {
1499 if ( (Gameinfo_send_time < 0) || ((time(NULL) - Gameinfo_send_time) > GAMEINFO_SEND_TIME) ){
1500 send_game_info_packet();
1502 Gameinfo_send_time = time(NULL);
1506 // everybody pings all the time
1507 if((Next_ping_time < 0) || ((time(NULL) - Next_ping_time) > PING_SEND_TIME) ){
1508 multi_ping_send_all();
1510 Next_ping_time = time(NULL);
1513 // periodically send a client update packet to all clients
1514 if(Net_player->flags & NETINFO_FLAG_AM_MASTER){
1517 for(idx=0;idx<MAX_PLAYERS;idx++){
1518 if(MULTI_CONNECTED(Net_players[idx]) && (Net_player != &Net_players[idx])){
1519 if((Multi_client_update_times[idx] < 0) || timestamp_elapsed_safe(Multi_client_update_times[idx], 1000)){
1521 send_client_update_packet(&Net_players[idx]);
1523 Multi_client_update_times[idx] = timestamp(MULTI_CLIENT_UPDATE_TIME);
1528 // for any potential ingame joiners
1529 multi_handle_ingame_joiners();
1532 // do any file xfer details
1535 // process any player data details (wav files, pilot pics, etc)
1538 // get the other net players data
1539 multi_process_incoming();
1541 // do any voice details
1542 multi_voice_process();
1544 // process any player messaging details
1545 multi_msg_process();
1547 // process any kicked player details
1548 multi_kick_process();
1550 // process any pending endgame details
1551 multi_endgame_process();
1553 // process object update stuff (for clients and server both)
1554 if(MULTIPLAYER_MASTER){
1558 // if on the standalone, do any gui stuff
1559 if(Game_mode & GM_STANDALONE_SERVER){
1565 // --------------------------------------------------------------------------------
1566 // standalone_main_init() the standalone equivalent of the main menu
1569 extern int sock_inited;
1570 float frame_time = (float)1.0/(float)30.0;
1572 void standalone_main_init()
1574 std_debug_set_standalone_state_string("Main Init");
1576 Game_mode = (GM_STANDALONE_SERVER | GM_MULTIPLAYER);
1579 ml_string(NOX("Standalone server initializing"));
1581 // read in config file
1582 // multi_options_read_config();
1584 // if we failed to startup on our desired protocol, fail
1585 if((Multi_options_g.protocol == NET_IPX) && !Ipx_active){
1586 MessageBox((HWND)os_get_window(), XSTR( "You have selected IPX for multiplayer Freespace, but the IPX protocol was not detected on your machine.", 1402), "Error", MB_OK);
1589 if((Multi_options_g.protocol == NET_TCP) && !Tcp_active){
1590 MessageBox((HWND)os_get_window(), XSTR("You have selected TCP/IP for multiplayer Freespace, but the TCP/IP protocol was not detected on your machine.", 362), "Error", MB_OK);
1595 #ifdef MULTIPLAYER_BETA_BUILD
1596 Multi_options_g.protocol = NET_TCP;
1597 psnet_use_protocol(Multi_options_g.protocol);
1599 ADDRESS_LENGTH = IP_ADDRESS_LENGTH;
1600 PORT_LENGTH = IP_PORT_LENGTH;
1602 psnet_use_protocol(Multi_options_g.protocol);
1603 switch (Multi_options_g.protocol) {
1605 ADDRESS_LENGTH = IPX_ADDRESS_LENGTH;
1606 PORT_LENGTH = IPX_PORT_LENGTH;
1610 ADDRESS_LENGTH = IP_ADDRESS_LENGTH;
1611 PORT_LENGTH = IP_PORT_LENGTH;
1621 // clear out the Netgame structure and start filling in the values
1622 // NOTE : these values are not incredibly important since they will be overwritten by the host when he joins
1623 memset( &Netgame, 0, sizeof(Netgame) );
1624 Netgame.game_state = NETGAME_STATE_FORMING; // game is currently starting up
1625 Netgame.security = 0;
1626 Netgame.server_addr = Psnet_my_addr;
1628 memset(&The_mission,0,sizeof(The_mission));
1630 // reinitialize all systems
1633 // intialize endgame stuff
1634 multi_endgame_init();
1636 // clear the file xfer system
1638 multi_xfer_force_dir(CF_TYPE_MULTI_CACHE);
1643 // setup the netplayer for the standalone
1644 Net_player = &Net_players[0];
1645 Net_player->tracker_player_id = -1;
1646 Net_player->flags |= (NETINFO_FLAG_AM_MASTER | NETINFO_FLAG_CONNECTED | NETINFO_FLAG_DO_NETWORKING | NETINFO_FLAG_MISSION_OK);
1647 Net_player->state = NETPLAYER_STATE_WAITING;
1648 Net_player->player = Player;
1649 strcpy(Player->callsign, "server");
1650 Net_player->p_info.addr = Psnet_my_addr;
1651 Net_player->s_info.xfer_handle = -1;
1652 Net_player->player_id = multi_get_new_id();
1653 Netgame.server = Net_player;
1655 // maybe flag the game as having a hacked ships.tbl
1656 if(!Game_ships_tbl_valid){
1657 Netgame.flags |= NG_FLAG_HACKED_SHIPS_TBL;
1659 // maybe flag the game as having a hacked weapons.tbl
1660 if(!Game_weapons_tbl_valid){
1661 Netgame.flags |= NG_FLAG_HACKED_WEAPONS_TBL;
1665 if(game_hacked_data()){
1666 Net_player->flags |= NETINFO_FLAG_HAXOR;
1669 // setup debug flags
1670 Netgame.debug_flags = 0;
1672 if(!Cmdline_server_firing){
1673 Netgame.debug_flags |= NETD_FLAG_CLIENT_FIRING;
1675 if(!Cmdline_client_dodamage){
1676 Netgame.debug_flags |= NETD_FLAG_CLIENT_NODAMAGE;
1680 // setup the default game name for the standalone
1681 std_connect_set_gamename(NULL);
1683 // set netgame default options
1684 multi_options_set_netgame_defaults(&Netgame.options);
1686 // set local netplayer default options
1687 multi_options_set_local_defaults(&Net_player->p_info.options);
1689 // set our object update level from the standalone default
1690 Net_player->p_info.options.obj_update_level = Multi_options_g.std_datarate;
1691 switch(Net_player->p_info.options.obj_update_level){
1692 case OBJ_UPDATE_LOW:
1693 nprintf(("Network","STANDALONE USING LOW UPDATES\n"));
1695 case OBJ_UPDATE_MEDIUM:
1696 nprintf(("Network","STANDALONE USING MEDIUM UPDATES\n"));
1698 case OBJ_UPDATE_HIGH:
1699 nprintf(("Network","STANDALONE USING HIGH UPDATE\n"));
1701 case OBJ_UPDATE_LAN:
1702 nprintf(("Network","STANDALONE USING LAN UPDATE\n"));
1706 // clear out various things
1711 std_debug_set_standalone_state_string("Main Do");
1712 std_set_standalone_fps((float)0);
1713 std_multi_set_standalone_missiontime((float)0);
1715 // load my missions and campaigns
1716 multi_create_list_load_missions();
1717 multi_create_list_load_campaigns();
1719 // if this is a tracker game, validate missions
1720 if(MULTI_IS_TRACKER_GAME){
1721 multi_update_valid_missions();
1726 // --------------------------------------------------------------------------------
1727 // standalone_main_do()
1730 // DESCRIPTION : the standalone server will wait in this state until the host of the game
1731 // is "Waiting". That is, his state==NETPLAYER_STATE_WAITING, and he has finished
1732 // doing everything and wants to play the game. Once this happens, we will jump
1733 // into GS_STATE_MULTI_SERVER_WAIT
1735 void standalone_main_do()
1737 Sleep(10); // since nothing will really be going on here, we can afford to give some time
1738 // back to the operating system.
1740 // kind of a do-nothing spin state.
1741 // The standalone will eventually move into the GS_STATE_MULTI_MISSION_SYNC state when a host connects and
1742 // attempts to start a game
1745 // --------------------------------------------------------------------------------
1746 // standalone_main_close()
1749 void standalone_main_close()
1751 std_debug_set_standalone_state_string("Main Close");
1754 void multi_standalone_reset_all()
1759 ml_string(NOX("Standalone resetting"));
1761 // shut all game stuff down
1764 // reinitialize the gui
1765 std_reset_standalone_gui();
1767 // close down all sockets
1768 for(idx=0;idx<MAX_PLAYERS;idx++){
1770 // 6/25/98 -- MWA -- call delete_player here to remove the player. This closes down the socket
1771 // and marks the player as not connected anymore. It is probably cleaner to do this.
1772 if ( &Net_players[idx] != Net_player ) {
1773 delete_player( idx );
1777 // make sure we go to the proper state.
1778 if(gameseq_get_state() == GS_STATE_STANDALONE_MAIN){
1779 standalone_main_init();
1781 gameseq_post_event(GS_EVENT_STANDALONE_MAIN);
1784 // --------------------------------------------------------------------------------
1785 // multi_server_wait_init() do stuff like setting the status bits correctly
1788 void multi_standalone_wait_init()
1790 std_debug_set_standalone_state_string("Wait Do");
1791 std_multi_add_goals(); // fill in the goals for the mission into the tree view
1792 multi_reset_timestamps();
1794 // create the bogus standalone object
1795 multi_create_standalone_object();
1799 // --------------------------------------------------------------------------------
1800 // multi_server_wait_do_frame() wait for everyone to log in or the host to send commands
1803 // DESCRIPTION : we will be in this state once the host of the game is waiting for everyone
1804 // to be finished and ready to go, at which point, we will will tell everyone
1805 // to enter the game, and we will start simulating ourselves. Note that most of
1806 // this code is lifted from multi_wait_do_frame()
1807 void multi_standalone_wait_do()
1811 // --------------------------------------------------------------------------------
1812 // multi_server_wait_close() cleanup
1815 void multi_standalone_wait_close()
1817 std_debug_set_standalone_state_string("Wait Close / Game Play");
1819 // all players should reset sequencing
1821 for(idx=0;idx<MAX_PLAYERS;idx++){
1822 if(Net_player->flags & NETINFO_FLAG_CONNECTED){
1823 Net_players[idx].client_cinfo_seq = 0;
1824 Net_players[idx].client_server_seq = 0;
1830 // this is an artificial state which will push the standalone into the main state without it having to go through
1831 // the init function (which would disconnect everyone and generally just screw things up)
1832 // it will also eventually do tracker stats update
1833 extern int Multi_debrief_server_framecount;
1834 void multi_standalone_postgame_init()
1836 std_debug_set_standalone_state_string("Postgame / Send Stats");
1839 ml_string(NOX("Standlone entering postgame"));
1841 mission_goal_fail_incomplete();
1843 // handle campaign stuff
1844 if ( Game_mode & GM_CAMPAIGN_MODE ) {
1845 // MUST store goals and events first - may be used to evaluate next mission
1846 // store goals and events
1847 mission_campaign_store_goals_and_events();
1849 // evaluate next mission
1850 mission_campaign_eval_next_mission();
1853 // always set my state to be "DEBRIEF_ACCEPT"
1854 Net_player->state = NETPLAYER_STATE_DEBRIEF_ACCEPT;
1856 // mark stats as not being store yet
1857 Netgame.flags &= ~(NG_FLAG_STORED_MT_STATS);
1859 Multi_debrief_server_framecount = 0;
1861 // reset network timestamps
1862 multi_reset_timestamps();
1865 void multi_standalone_postgame_do()
1867 // wait until everyone is in the debriefing
1868 if((Netgame.game_state != NETGAME_STATE_DEBRIEF) && multi_netplayer_state_check(NETPLAYER_STATE_DEBRIEF, 1)){
1869 Netgame.game_state = NETGAME_STATE_DEBRIEF;
1870 send_netgame_update_packet();
1871 debrief_multi_server_stuff();
1874 // process server debriefing details
1875 if(Netgame.game_state == NETGAME_STATE_DEBRIEF){
1876 multi_debrief_server_process();
1880 void multi_standalone_postgame_close()
1884 void multi_reset_timestamps()
1888 for ( i = 0 ; i < MAX_PLAYERS; i++ ){
1889 Multi_client_update_times[i] = -1;
1891 Netgame_send_time = -1;
1892 Gameinfo_send_time = -1;
1893 Next_ping_time = -1;
1894 State_send_time = -1;
1895 Next_bytes_time = -1;
1897 chatbox_reset_timestamps();
1899 // do for all players so that ingame joiners work properly.
1900 for (i = 0; i < MAX_PLAYERS; i++ ) {
1901 Players[i].update_dumbfire_time = timestamp(0);
1902 Players[i].update_lock_time = timestamp(0);
1904 Net_players[i].s_info.voice_token_timestamp = -1;
1907 // reset standalone gui timestamps (these are not game critical, so there is not much danger)
1908 std_reset_timestamps();
1910 // initialize all object update timestamps
1911 multi_oo_gameplay_init();
1914 // netgame debug flags for debug console stuff
1915 DCF(netd, "change/list netgame debug flags")
1917 dc_get_arg(ARG_INT);
1919 // if we got an integer, and we're the server, change flags
1920 if((Dc_arg_type & ARG_INT) && (Net_player != NULL) && (Net_player->flags & NETINFO_FLAG_AM_MASTER) && (Dc_arg_int <= 7)){
1921 Netgame.debug_flags ^= (1<<Dc_arg_int);
1924 // display network flags
1925 dc_printf("BITS\n");
1926 // dc_printf("1 - Client side firing (%d)\n", Netgame.debug_flags & NETD_FLAG_CLIENT_FIRING ? 1 : 0);
1927 // dc_printf("2 - Client nodamage (%d)\n", Netgame.debug_flags & NETD_FLAG_CLIENT_NODAMAGE ? 1 : 0);
1930 // display any multiplayer/networking information here
1931 void multi_display_netinfo()
1933 int sx = gr_screen.max_w - 200;
1938 if(!(Game_mode & GM_MULTIPLAYER)){
1942 gr_set_color_fast(&Color_normal);
1945 if(MULTIPLAYER_MASTER){
1946 gr_string(sx, sy, "SERVER"); sy += 10;
1948 for(idx=0; idx<MAX_PLAYERS; idx++){
1949 if(MULTI_CONNECTED(Net_players[idx]) && (Net_player != &Net_players[idx]) && (Net_players[idx].player != NULL)){
1950 if(Net_players[idx].sv_last_pl < 0){
1951 gr_printf(sx, sy, "%s : %d, %d pl", Net_players[idx].player->callsign, Net_players[idx].sv_bytes_sent, 0); sy += 10;
1953 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;
1958 gr_string(sx, sy, "CLIENT"); sy += 10;
1961 if(Net_player != NULL){
1962 if(Net_player->cl_last_pl < 0){
1963 gr_printf(sx, sy, "PL : %d %d pl\n", Net_player->cl_bytes_recvd, 0); sy += 10;
1965 gr_printf(sx, sy, "PL : %d %d pl\n", Net_player->cl_bytes_recvd, Net_player->cl_last_pl); sy += 10;