2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
11 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
15 * $Source: /cvs/cvsroot/d2x/main/network.c,v $
18 * $Date: 2002-02-13 10:39:21 $
20 * FIXME: put description here
22 * $Log: not supported by cvs2svn $
23 * Revision 1.6 2001/10/23 22:03:03 bradleyb
24 * No longer #ifdef'ing out the whole file. RCS header added
82 #include <Errors.h> // for appletalk networking errors
86 void network_send_rejoin_sync(int player_num);
87 void network_update_netgame(void);
88 void network_read_endlevel_packet( ubyte *data );
89 void network_read_object_packet( ubyte *data );
90 void network_read_sync_packet( netgame_info * sp, int d1x );
92 void network_listen();
93 void network_read_pdata_packet(frame_info *pd );
95 void network_check_for_old_version (char pnum);
96 void network_send_endlevel_short_sub(int from_player_num,int to_player);
97 int network_wait_for_playerinfo();
98 void network_process_pdata (char *data);
99 void network_read_endlevel_short_packet( ubyte *data );
100 void network_ping (ubyte flag,int pnum);
101 void network_handle_ping_return (ubyte pnum);
102 void network_process_names_return (char *data);
103 void network_send_player_names (sequence_packet *their);
104 int network_choose_connect ();
105 void network_more_game_options ();
106 void network_count_powerups_in_mine(void);
107 int network_wait_for_all_info (int choice);
108 void network_do_big_wait(int choice);
109 void network_send_extras ();
110 void network_read_pdata_short_packet(short_frame_info *pd );
112 void network_AdjustMaxDataSize ();
114 void ClipRank (signed char *rank);
115 void DoRefuseStuff (sequence_packet *their);
116 void SetAllAllowablesTo (int on);
117 int GetNewPlayerNumber (sequence_packet *their);
119 #define LHX(x) ((x)*(MenuHires?2:1))
120 #define LHY(y) ((y)*(MenuHires?2.4:1))
122 #define NETSECURITY_OFF 0
123 #define NETSECURITY_WAIT_FOR_PLAYERS 1
124 #define NETSECURITY_WAIT_FOR_GAMEINFO 2
125 #define NETSECURITY_WAIT_FOR_SYNC 3
127 // MWA -- these structures are aligned -- please save me sanity and
128 // headaches by keeping alignment if these are changed!!!! Contact
131 typedef struct endlevel_info_short {
136 } endlevel_info_short;
138 // WARNING!!! This is the top part of netgame_info...if that struct changes,
139 // this struct much change as well. ie...they are aligned and the join system will
140 // not work without it.
142 // MWA if this structure changes -- please make appropriate changes to receive_netgame_info
143 // code for macintosh in netmisc.c
145 typedef struct lite_info {
148 char game_name[NETGAME_NAME_LEN+1];
149 char mission_title[MISSION_NAME_LEN+1];
150 char mission_name[9];
157 ubyte max_numplayers;
160 ubyte protocol_version;
166 // IF YOU CHANGE THE SIZE OF ANY OF THE FOLLOWING STRUCTURES
167 // MAKE THE MACINTOSH DEFINES BE THE SAME SIZE AS THE PC OR
168 // I WILL HAVE TO HURT YOU VERY BADLY!!! -- MWA
171 #define NETGAME_INFO_SIZE ( Network_game_type == IPX_GAME?355:sizeof(netgame_info) )
172 #define ALLNETPLAYERSINFO_SIZE ( Network_game_type == IPX_GAME?317:sizeof(AllNetPlayers_info) )
173 #define LITE_INFO_SIZE ( Network_game_type == IPX_GAME?72:sizeof(lite_info) )
174 #define SEQUENCE_PACKET_SIZE ( Network_game_type == IPX_GAME?34:sizeof(sequence_packet) )
175 #define FRAME_INFO_SIZE ( Network_game_type == IPX_GAME?541:sizeof(frame_info) )
176 #define IPX_SHORT_INFO_SIZE ( 490 )
178 #define NETGAME_INFO_SIZE sizeof(netgame_info)
179 #define ALLNETPLAYERSINFO_SIZE sizeof(AllNetPlayers_info)
180 #define LITE_INFO_SIZE sizeof(lite_info)
181 #define SEQUENCE_PACKET_SIZE sizeof(sequence_packet)
182 #define FRAME_INFO_SIZE sizeof(frame_info)
185 #define MAX_ACTIVE_NETGAMES 12
187 netgame_info Active_games[MAX_ACTIVE_NETGAMES];
188 AllNetPlayers_info ActiveNetPlayers[MAX_ACTIVE_NETGAMES];
189 AllNetPlayers_info *TempPlayersInfo,TempPlayersBase;
190 int NamesInfoSecurity=-1;
192 // MWAnetgame_info *TempNetInfo;
193 netgame_info TempNetInfo;
195 extern void multi_send_drop_marker (int player,vms_vector position,char messagenum,char text[]);
196 extern void multi_send_kill_goal_counts();
197 extern int newmenu_dotiny( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem) );
199 void network_process_naked_pdata (char *,int);
200 extern void multi_send_robot_controls(char);
202 int num_active_games = 0;
203 int PacketsPerSec=10;
204 int MaxXDataSize=NET_XDATA_SIZE;
206 int Netlife_kills=0, Netlife_killed=0;
209 int Network_active=0;
211 int Network_status = 0;
212 int Network_games_changed = 0;
214 int Network_socket = 0;
215 int Network_allow_socket_changes = 1;
217 int Network_initial_pps = 10;
218 int Network_initial_shortpackets = 0;
220 int NetSecurityFlag=NETSECURITY_OFF;
221 int NetSecurityNum=0;
222 int Network_sending_extras=0;
223 int VerifyPlayerJoined=-1;
224 int Player_joining_extras=-1; // This is so we know who to send 'latecomer' packets to.
225 // We could just send updates to everyone but that kills the sender!
227 // For rejoin object syncing
229 int Network_rejoined = 0; // Did WE rejoin this game?
230 int Network_new_game = 0; // Is this the first level of a new game?
231 int Network_send_objects = 0; // Are we in the process of sending objects to a player?
232 int Network_send_objnum = -1; // What object are we sending next?
233 int Network_player_added = 0; // Is this a new player or a returning player?
234 int Network_send_object_mode = 0; // What type of objects are we sending, static or dynamic?
235 sequence_packet Network_player_rejoining; // Who is rejoining now?
237 fix LastPacketTime[MAX_PLAYERS]; // For timeouts of idle/crashed players
239 int PacketUrgent = 0;
241 int TotalMissedPackets=0,TotalPacketsGot=0;
243 frame_info MySyncPack,UrgentSyncPack;
244 ubyte MySyncPackInitialized = 0; // Set to 1 if the MySyncPack is zeroed.
245 ushort my_segments_checksum = 0;
247 sequence_packet My_Seq;
248 char WantPlayersInfo=0;
249 char WaitingForPlayerInfo=0;
251 char *RankStrings[]={"(unpatched) ","Cadet ","Ensign ","Lieutenant ","Lt.Commander ",
252 "Commander ","Captain ","Vice Admiral ","Admiral ","Demigod "};
254 extern obj_position Player_init[MAX_PLAYERS];
256 extern int force_cockpit_redraw;
258 #define DUMP_CLOSED 0
260 #define DUMP_ENDLEVEL 2
262 #define DUMP_ABORTED 4
263 #define DUMP_CONNECTED 5
265 #define DUMP_KICKED 7
267 extern ubyte Version_major,Version_minor;
268 extern ubyte SurfingNet;
269 extern char MaxPowerupsAllowed[MAX_POWERUP_TYPES];
270 extern char PowerupsInMine[MAX_POWERUP_TYPES];
272 extern void multi_send_stolen_items();
274 int network_wait_for_snyc();
275 extern void multi_send_wall_status (int,ubyte,ubyte,ubyte);
276 extern void multi_send_wall_status_specific (int,int,ubyte,ubyte,ubyte);
278 extern void game_disable_cheats();
281 FILE *SendLogFile,*RecieveLogFile;
282 int TTSent[100],TTRecv[100];
284 extern int Final_boss_is_dead;
286 // following is network stuff for appletalk
288 void network_dump_appletalk_player(ubyte node, ushort net, ubyte socket, int why);
290 #define NETWORK_OEM 0x10
294 int Network_game_type; // used to tell IPX vs. appletalk games
296 #define MAX_ZONES 255
297 #define MAX_ZONE_LENGTH 33
298 #define DEFAULT_ZONE_NAME "\p*"
299 #define MAX_REGISTER_TRIES 5 // maximum time we will try and register a netgame
300 char Network_zone_name[MAX_ZONE_LENGTH]; // zone name game being played in for appletalk
301 char Zone_names[MAX_ZONES][MAX_ZONE_LENGTH]; // total list of zones that we can see
302 ubyte appletalk_use_broadcast = 0;
303 ubyte Network_game_validated = 0; // validates a game before being able to join
304 ubyte Network_game_validate_choice = 0;
305 ubyte Network_appletalk_type = 0; // type of appletalk network game is being played on
307 #define ETHERTALK_TYPE 0
308 #define LOCALTALK_TYPE 1
309 #define OTHERTALK_TYPE 2
312 void network_release_registered_game(void);
320 // So you want to play a netgame, eh? Let's a get a few things
324 int save_pnum = Player_num;
326 game_disable_cheats();
328 Final_boss_is_dead=0;
329 NamesInfoSecurity=-1;
337 for (t=0;t<MAX_POWERUP_TYPES;t++)
339 MaxPowerupsAllowed[t]=0;
343 TotalMissedPackets=0; TotalPacketsGot=0;
345 memset(&Netgame, 0, sizeof(netgame_info));
346 memset(&NetPlayers,0,sizeof(AllNetPlayers_info));
347 memset(&My_Seq, 0, sizeof(sequence_packet));
348 My_Seq.type = PID_REQUEST;
349 memcpy(My_Seq.player.callsign, Players[Player_num].callsign, CALLSIGN_LEN+1);
352 Version_minor|=NETWORK_OEM;
355 My_Seq.player.version_major=Version_major;
356 My_Seq.player.version_minor=Version_minor;
357 My_Seq.player.rank=GetMyNetRanking();
359 if (Network_game_type == IPX_GAME) {
360 memcpy(My_Seq.player.network.ipx.node, ipx_get_my_local_address(), 6);
361 memcpy(My_Seq.player.network.ipx.server, ipx_get_my_server_address(), 4 );
364 My_Seq.player.network.appletalk.node = appletalk_get_my_node();
365 My_Seq.player.network.appletalk.net = appletalk_get_my_net();
366 My_Seq.player.network.appletalk.socket = appletalk_get_my_socket();
370 My_Seq.player.computer_type = MAC;
372 My_Seq.player.computer_type = DOS;
375 for (Player_num = 0; Player_num < MAX_NUM_NET_PLAYERS; Player_num++)
376 init_player_stats_game();
378 Player_num = save_pnum;
380 Network_new_game = 1;
381 Control_center_destroyed = 0;
384 Netgame.PacketsPerSec=10;
386 if ((t=FindArg("-packets")))
388 Netgame.PacketsPerSec=atoi(Args[t+1]);
389 if (Netgame.PacketsPerSec<1)
390 Netgame.PacketsPerSec=1;
391 else if (Netgame.PacketsPerSec>20)
392 Netgame.PacketsPerSec=20;
393 mprintf ((0,"Will send %d packets per second",Netgame.PacketsPerSec));
395 if (FindArg("-shortpackets"))
397 Netgame.ShortPackets=1;
398 mprintf ((0,"Will send short packets.\n"));
403 network_i_am_master(void)
405 // I am the lowest numbered player in this game?
409 if (!(Game_mode & GM_NETWORK))
410 return (Player_num == 0);
412 for (i = 0; i < Player_num; i++)
413 if (Players[i].connected)
418 network_who_is_master(void)
420 // Who is the master of this game?
424 if (!(Game_mode & GM_NETWORK))
425 return (Player_num == 0);
427 for (i = 0; i < N_players; i++)
428 if (Players[i].connected)
432 int network_how_many_connected()
436 for (i = 0; i < N_players; i++)
437 if (Players[i].connected)
442 #define ENDLEVEL_SEND_INTERVAL (F1_0*2)
443 #define ENDLEVEL_IDLE_TIME (F1_0*20)
446 network_endlevel_poll( int nitems, newmenu_item * menus, int * key, int citem )
448 // Polling loop for End-of-level menu
456 int previous_state[MAX_NUM_NET_PLAYERS];
457 int previous_seconds_left;
464 // Send our endlevel packet at regular intervals
466 if (timer_get_approx_seconds() > (t1+ENDLEVEL_SEND_INTERVAL))
468 network_send_endlevel_packet();
469 t1 = timer_get_approx_seconds();
472 for (i = 0; i < N_players; i++)
473 previous_state[i] = Players[i].connected;
475 previous_seconds_left = Countdown_seconds_left;
479 for (i = 0; i < N_players; i++)
481 if (Players[i].connected == 1)
483 // Check timeout for idle players
484 if (timer_get_approx_seconds() > LastPacketTime[i]+ENDLEVEL_IDLE_TIME)
486 mprintf((0, "idle timeout for player %d.\n", i));
487 Players[i].connected = 0;
488 network_send_endlevel_sub(i);
492 if ((Players[i].connected != 1) && (Players[i].connected != 5) && (Players[i].connected != 6))
494 if (Players[i].connected != 1)
496 if (Players[i].connected == 4)
500 if (num_escaped == N_players) // All players are out of the mine
502 Countdown_seconds_left = -1;
506 if (num_ready == N_players) // All players have checked in or are disconnected
516 network_endlevel_poll2( int nitems, newmenu_item * menus, int * key, int citem )
518 // Polling loop for End-of-level menu
530 // Send our endlevel packet at regular intervals
532 if (timer_get_approx_seconds() > (t1+ENDLEVEL_SEND_INTERVAL))
534 network_send_endlevel_packet();
535 t1 = timer_get_approx_seconds();
538 // mprintf ((0,"Trying to listen!\n"));
541 for (i = 0; i < N_players; i++)
543 if ((Players[i].connected != 1) && (Players[i].connected != 5) && (Players[i].connected != 6))
545 if (Players[i].connected == 4)
549 if (num_ready == N_players) // All players have checked in or are disconnected
559 extern fix StartAbortMenuTime;
562 network_endlevel_poll3( int nitems, newmenu_item * menus, int * key, int citem )
564 // Polling loop for End-of-level menu
573 if (timer_get_approx_seconds() > (StartAbortMenuTime+(F1_0 * 8)))
580 for (i = 0; i < N_players; i++)
581 if ((Players[i].connected != 1) && (Players[i].connected != 5) && (Players[i].connected != 6))
584 if (num_ready == N_players) // All players have checked in or are disconnected
591 network_endlevel(int *secret)
593 // Do whatever needs to be done between levels
601 Network_status = NETSTAT_ENDLEVEL; // We are between levels
605 network_send_endlevel_packet();
607 for (i=0; i<N_players; i++)
609 LastPacketTime[i] = timer_get_approx_seconds();
612 network_send_endlevel_packet();
613 network_send_endlevel_packet();
614 MySyncPackInitialized = 0;
616 network_update_netgame();
622 can_join_netgame(netgame_info *game,AllNetPlayers_info *people)
624 // Can this player rejoin a netgame in progress?
628 if (game->game_status == NETSTAT_STARTING)
631 if (game->game_status != NETSTAT_PLAYING)
633 mprintf ((0,"Error: Can't join because game_status !=NETSTAT_PLAYING\n"));
637 if (game->version_major==0 && Version_major>0)
639 mprintf ((0,"Error:Can't join because version majors don't match!\n"));
643 if (game->version_major>0 && Version_major==0)
645 mprintf ((0,"Error:Can't join because version majors2 don't match!\n"));
649 // Game is in progress, figure out if this guy can re-join it
651 num_players = game->numplayers;
653 if (!(game->game_flags & NETGAME_FLAG_CLOSED)) {
654 // Look for player that is not connected
656 if (game->numconnected==game->max_numplayers)
659 // mprintf ((0,"Refuse = %d\n",game->RefusePlayers));
661 if (game->RefusePlayers)
664 if (game->numplayers < game->max_numplayers)
667 if (game->numconnected<num_players)
674 mprintf ((0,"Error! Can't join because people==NULL!\n"));
678 // Search to see if we were already in this closed netgame in progress
680 for (i = 0; i < num_players; i++) {
681 if (Network_game_type == IPX_GAME) {
682 if ( (!stricmp(Players[Player_num].callsign, people->players[i].callsign)) &&
683 (!memcmp(My_Seq.player.network.ipx.node, people->players[i].network.ipx.node, 6)) &&
684 (!memcmp(My_Seq.player.network.ipx.server, people->players[i].network.ipx.server, 4)) )
687 if ( (!stricmp(Players[Player_num].callsign, people->players[i].callsign)) &&
688 (My_Seq.player.network.appletalk.node == people->players[i].network.appletalk.node) &&
689 (My_Seq.player.network.appletalk.net == people->players[i].network.appletalk.net) )
694 if (i != num_players)
697 mprintf ((0,"Error: Can't join because at end of list!\n"));
702 network_disconnect_player(int playernum)
704 // A player has disconnected from the net game, take whatever steps are
707 if (playernum == Player_num)
709 Int3(); // Weird, see Rob
713 Players[playernum].connected = 0;
714 NetPlayers.players[playernum].connected = 0;
715 if (VerifyPlayerJoined==playernum)
716 VerifyPlayerJoined=-1;
718 // create_player_appearance_effect(&Objects[Players[playernum].objnum]);
719 multi_make_player_ghost(playernum);
721 if (Newdemo_state == ND_STATE_RECORDING)
722 newdemo_record_multi_disconnect(playernum);
724 multi_strip_robots(playernum);
728 network_new_player(sequence_packet *their)
733 pnum = their->player.connected;
736 Assert(pnum < MaxNumNetPlayers);
738 objnum = Players[pnum].objnum;
740 if (Newdemo_state == ND_STATE_RECORDING) {
743 if (pnum == N_players)
747 newdemo_record_multi_connect(pnum, new_player, their->player.callsign);
750 memcpy(Players[pnum].callsign, their->player.callsign, CALLSIGN_LEN+1);
751 memcpy(NetPlayers.players[pnum].callsign, their->player.callsign, CALLSIGN_LEN+1);
754 ClipRank (&their->player.rank);
755 NetPlayers.players[pnum].rank=their->player.rank;
756 NetPlayers.players[pnum].version_major=their->player.version_major;
757 NetPlayers.players[pnum].version_minor=their->player.version_minor;
758 network_check_for_old_version(pnum);
760 if (Network_game_type == IPX_GAME) {
761 if ( (*(uint *)their->player.network.ipx.server) != 0 )
762 ipx_get_local_target( their->player.network.ipx.server, their->player.network.ipx.node, Players[pnum].net_address );
764 memcpy(Players[pnum].net_address, their->player.network.ipx.node, 6);
766 memcpy(NetPlayers.players[pnum].network.ipx.node, their->player.network.ipx.node, 6);
767 memcpy(NetPlayers.players[pnum].network.ipx.server, their->player.network.ipx.server, 4);
769 NetPlayers.players[pnum].network.appletalk.node = their->player.network.appletalk.node;
770 NetPlayers.players[pnum].network.appletalk.net = their->player.network.appletalk.net;
771 NetPlayers.players[pnum].network.appletalk.socket = their->player.network.appletalk.socket;
774 Players[pnum].n_packets_got = 0;
775 Players[pnum].connected = 1;
776 Players[pnum].net_kills_total = 0;
777 Players[pnum].net_killed_total = 0;
778 memset(kill_matrix[pnum], 0, MAX_PLAYERS*sizeof(short));
779 Players[pnum].score = 0;
780 Players[pnum].flags = 0;
781 Players[pnum].KillGoalCount=0;
783 if (pnum == N_players)
786 Netgame.numplayers = N_players;
789 digi_play_sample(SOUND_HUD_MESSAGE, F1_0);
791 ClipRank (&their->player.rank);
793 if (FindArg("-norankings"))
794 HUD_init_message("'%s' %s\n",their->player.callsign, TXT_JOINING);
796 HUD_init_message("%s'%s' %s\n",RankStrings[their->player.rank],their->player.callsign, TXT_JOINING);
798 multi_make_ghost_player(pnum);
801 multi_sort_kill_list();
803 // create_player_appearance_effect(&Objects[objnum]);
806 char RefuseThisPlayer=0,WaitForRefuseAnswer=0,RefuseTeam;
807 char RefusePlayerName[12];
808 fix RefuseTimeLimit=0;
810 void network_welcome_player(sequence_packet *their)
812 // Add a player to a game already in progress
813 ubyte local_address[6];
817 WaitForRefuseAnswer=0;
819 if (FindArg("-NoMatrixCheat"))
821 if (their->player.version_minor & (0x0F<3))
823 network_dump_player(their->player.network.ipx.server, their->player.network.ipx.node, DUMP_DORK);
830 // If hoard game, and this guy isn't D2 Christmas (v1.2), dump him
832 if ((Game_mode & GM_HOARD) && ((their->player.version_minor & 0x0F)<2))
834 if (Network_game_type == IPX_GAME)
835 network_dump_player(their->player.network.ipx.server, their->player.network.ipx.node, DUMP_DORK);
838 network_dump_appletalk_player(their->player.network.appletalk.node, their->player.network.appletalk.net, their->player.network.appletalk.socket, DUMP_DORK);
844 // Don't accept new players if we're ending this level. Its safe to
845 // ignore since they'll request again later
847 if ((Endlevel_sequence) || (Control_center_destroyed))
849 mprintf((0, "Ignored request from new player to join during endgame.\n"));
850 if (Network_game_type == IPX_GAME)
851 network_dump_player(their->player.network.ipx.server,their->player.network.ipx.node, DUMP_ENDLEVEL);
854 network_dump_appletalk_player(their->player.network.appletalk.node, their->player.network.appletalk.net, their->player.network.appletalk.socket, DUMP_ENDLEVEL);
859 if (Network_send_objects || Network_sending_extras)
861 // Ignore silently, we're already responding to someone and we can't
862 // do more than one person at a time. If we don't dump them they will
863 // re-request in a few seconds.
867 if (their->player.connected != Current_level_num)
869 mprintf((0, "Dumping player due to old level number.\n"));
870 if (Network_game_type == IPX_GAME)
871 network_dump_player(their->player.network.ipx.server, their->player.network.ipx.node, DUMP_LEVEL);
874 network_dump_appletalk_player(their->player.network.appletalk.node, their->player.network.appletalk.net, their->player.network.appletalk.socket, DUMP_LEVEL);
880 memset(&Network_player_rejoining, 0, sizeof(sequence_packet));
881 Network_player_added = 0;
883 if (Network_game_type == IPX_GAME) {
884 if ( (*(uint *)their->player.network.ipx.server) != 0 )
885 ipx_get_local_target( their->player.network.ipx.server, their->player.network.ipx.node, local_address );
887 memcpy(local_address, their->player.network.ipx.node, 6);
890 for (i = 0; i < N_players; i++)
892 if ( (Network_game_type == IPX_GAME) && (!stricmp(Players[i].callsign, their->player.callsign )) && (!memcmp(Players[i].net_address,local_address, 6)) )
897 #ifdef MACINTOSH // note link to above if
898 else if ( (!stricmp(Players[i].callsign, their->player.callsign)) &&
899 (NetPlayers.players[i].network.appletalk.node == their->player.network.appletalk.node) &&
900 (NetPlayers.players[i].network.appletalk.net == their->player.network.appletalk.net)) {
907 if (player_num == -1)
909 // Player is new to this game
911 if ( !(Netgame.game_flags & NETGAME_FLAG_CLOSED) && (N_players < MaxNumNetPlayers))
913 // Add player in an open slot, game not full yet
915 player_num = N_players;
916 Network_player_added = 1;
918 else if (Netgame.game_flags & NETGAME_FLAG_CLOSED)
920 // Slots are open but game is closed
922 if (Network_game_type == IPX_GAME)
923 network_dump_player(their->player.network.ipx.server, their->player.network.ipx.node, DUMP_CLOSED);
926 network_dump_appletalk_player(their->player.network.appletalk.node, their->player.network.appletalk.net, their->player.network.appletalk.socket, DUMP_CLOSED);
932 // Slots are full but game is open, see if anyone is
933 // disconnected and replace the oldest player with this new one
935 int oldest_player = -1;
936 fix oldest_time = timer_get_approx_seconds();
938 Assert(N_players == MaxNumNetPlayers);
940 for (i = 0; i < N_players; i++)
942 if ( (!Players[i].connected) && (LastPacketTime[i] < oldest_time))
944 oldest_time = LastPacketTime[i];
949 if (oldest_player == -1)
951 // Everyone is still connected
953 if (Network_game_type == IPX_GAME)
954 network_dump_player(their->player.network.ipx.server, their->player.network.ipx.node, DUMP_FULL);
957 network_dump_appletalk_player(their->player.network.appletalk.node, their->player.network.appletalk.net, their->player.network.appletalk.socket, DUMP_FULL);
965 player_num = oldest_player;
966 Network_player_added = 1;
972 // Player is reconnecting
974 if (Players[player_num].connected)
976 mprintf((0, "Extra REQUEST from player ignored.\n"));
980 if (Newdemo_state == ND_STATE_RECORDING)
981 newdemo_record_multi_reconnect(player_num);
983 Network_player_added = 0;
985 digi_play_sample(SOUND_HUD_MESSAGE, F1_0);
987 if (FindArg("-norankings"))
988 HUD_init_message("'%s' %s", Players[player_num].callsign, TXT_REJOIN);
990 HUD_init_message("%s'%s' %s", RankStrings[NetPlayers.players[player_num].rank],Players[player_num].callsign, TXT_REJOIN);
993 Players[player_num].KillGoalCount=0;
995 // Send updated Objects data to the new/returning player
998 Network_player_rejoining = *their;
999 Network_player_rejoining.player.connected = player_num;
1000 Network_send_objects = 1;
1001 Network_send_objnum = -1;
1003 network_send_objects();
1006 int network_objnum_is_past(int objnum)
1008 // determine whether or not a given object number has already been sent
1009 // to a re-joining player.
1011 int player_num = Network_player_rejoining.player.connected;
1012 int obj_mode = !((object_owner[objnum] == -1) || (object_owner[objnum] == player_num));
1014 if (!Network_send_objects)
1015 return 0; // We're not sending objects to a new player
1017 if (obj_mode > Network_send_object_mode)
1019 else if (obj_mode < Network_send_object_mode)
1021 else if (objnum < Network_send_objnum)
1027 #define OBJ_PACKETS_PER_FRAME 1
1028 extern void multi_send_active_door(char);
1029 extern void multi_send_door_open_specific(int,int,int,ubyte);
1032 void network_send_door_updates(int pnum)
1034 // Send door status when new player joins
1040 // Assert (pnum>-1 && pnum<N_players);
1042 for (i = 0; i < Num_walls; i++)
1044 if ((Walls[i].type == WALL_DOOR) && ((Walls[i].state == WALL_DOOR_OPENING) || (Walls[i].state == WALL_DOOR_WAITING) || (Walls[i].state == WALL_DOOR_OPEN)))
1045 multi_send_door_open_specific(pnum,Walls[i].segnum, Walls[i].sidenum,Walls[i].flags);
1046 else if ((Walls[i].type == WALL_BLASTABLE) && (Walls[i].flags & WALL_BLASTED))
1047 multi_send_door_open_specific(pnum,Walls[i].segnum, Walls[i].sidenum,Walls[i].flags);
1048 else if ((Walls[i].type == WALL_BLASTABLE) && (Walls[i].hps != WALL_HPS))
1049 multi_send_hostage_door_status(i);
1051 multi_send_wall_status_specific(pnum,i,Walls[i].type,Walls[i].flags,Walls[i].state);
1055 extern vms_vector MarkerPoint[];
1056 void network_send_markers()
1058 // send marker positions/text to new player
1065 if (MarkerObject[(i*2)]!=-1)
1066 multi_send_drop_marker (i,MarkerPoint[(i*2)],0,MarkerMessage[i*2]);
1067 if (MarkerObject[(i*2)+1]!=-1)
1068 multi_send_drop_marker (i,MarkerPoint[(i*2)+1],1,MarkerMessage[(i*2)+1]);
1072 void network_process_monitor_vector(int vector)
1078 for (i=0; i <= Highest_segment_index; i++)
1082 for (j = 0; j < 6; j++)
1084 if ( ((tm = seg->sides[j].tmap_num2) != 0) &&
1085 ((ec = TmapInfo[tm&0x3fff].eclip_num) != -1) &&
1086 ((bm = Effects[ec].dest_bm_num) != -1) )
1088 if (vector & (1 << count))
1090 seg->sides[j].tmap_num2 = bm | (tm&0xc000);
1091 // mprintf((0, "Monitor %d blown up.\n", count));
1094 // mprintf((0, "Monitor %d intact.\n", count));
1102 int network_create_monitor_vector(void)
1105 int num_blown_bitmaps = 0;
1106 int monitor_num = 0;
1107 #define NUM_BLOWN_BITMAPS 20
1108 int blown_bitmaps[NUM_BLOWN_BITMAPS];
1112 for (i=0; i < Num_effects; i++)
1114 if (Effects[i].dest_bm_num > 0) {
1115 for (j = 0; j < num_blown_bitmaps; j++)
1116 if (blown_bitmaps[j] == Effects[i].dest_bm_num)
1118 if (j == num_blown_bitmaps) {
1119 blown_bitmaps[num_blown_bitmaps++] = Effects[i].dest_bm_num;
1120 Assert(num_blown_bitmaps < NUM_BLOWN_BITMAPS);
1125 // for (i = 0; i < num_blown_bitmaps; i++)
1126 // mprintf((0, "Blown bitmap #%d = %d.\n", i, blown_bitmaps[i]));
1128 for (i=0; i <= Highest_segment_index; i++)
1132 for (j = 0; j < 6; j++)
1134 if ((tm = seg->sides[j].tmap_num2) != 0)
1136 if ( ((ec = TmapInfo[tm&0x3fff].eclip_num) != -1) &&
1137 (Effects[ec].dest_bm_num != -1) )
1139 // mprintf((0, "Monitor %d intact.\n", monitor_num));
1141 Assert(monitor_num < 32);
1145 for (k = 0; k < num_blown_bitmaps; k++)
1147 if ((tm&0x3fff) == blown_bitmaps[k])
1149 //mprintf((0, "Monitor %d destroyed.\n", monitor_num));
1150 vector |= (1 << monitor_num);
1152 Assert(monitor_num < 32);
1160 // mprintf((0, "Final monitor vector %x.\n", vector));
1164 void network_stop_resync(sequence_packet *their)
1166 if (Network_game_type == IPX_GAME) {
1167 if ( (!memcmp(Network_player_rejoining.player.network.ipx.node, their->player.network.ipx.node, 6)) &&
1168 (!memcmp(Network_player_rejoining.player.network.ipx.server, their->player.network.ipx.server, 4)) &&
1169 (!stricmp(Network_player_rejoining.player.callsign, their->player.callsign)) )
1171 mprintf((0, "Aborting resync for player %s.\n", their->player.callsign));
1172 Network_send_objects = 0;
1173 Network_sending_extras=0;
1175 Player_joining_extras=-1;
1176 Network_send_objnum = -1;
1179 if ( (Network_player_rejoining.player.network.appletalk.node == their->player.network.appletalk.node) &&
1180 (Network_player_rejoining.player.network.appletalk.net == their->player.network.appletalk.net) &&
1181 (!stricmp(Network_player_rejoining.player.callsign, their->player.callsign)) )
1183 mprintf((0, "Aborting resync for player %s.\n", their->player.callsign));
1184 Network_send_objects = 0;
1185 Network_sending_extras=0;
1187 Player_joining_extras=-1;
1188 Network_send_objnum = -1;
1193 byte object_buffer[IPX_MAX_DATA_SIZE];
1195 void network_send_objects(void)
1197 short remote_objnum;
1201 static int obj_count = 0;
1202 static int frame_num = 0;
1204 int obj_count_frame = 0;
1205 int player_num = Network_player_rejoining.player.connected;
1207 // Send clear objects array trigger and send player num
1209 Assert(Network_send_objects != 0);
1210 Assert(player_num >= 0);
1211 Assert(player_num < MaxNumNetPlayers);
1213 if (Endlevel_sequence || Control_center_destroyed)
1215 // Endlevel started before we finished sending the goods, we'll
1216 // have to stop and try again after the level.
1218 if (Network_game_type == IPX_GAME)
1219 network_dump_player(Network_player_rejoining.player.network.ipx.server,Network_player_rejoining.player.network.ipx.node, DUMP_ENDLEVEL);
1222 network_dump_appletalk_player(Network_player_rejoining.player.network.appletalk.node,Network_player_rejoining.player.network.appletalk.net, Network_player_rejoining.player.network.appletalk.socket, DUMP_ENDLEVEL);
1224 Network_send_objects = 0;
1228 for (h = 0; h < OBJ_PACKETS_PER_FRAME; h++) // Do more than 1 per frame, try to speed it up without
1229 // over-stressing the receiver.
1231 obj_count_frame = 0;
1232 memset(object_buffer, 0, IPX_MAX_DATA_SIZE);
1233 object_buffer[0] = PID_OBJECT_DATA;
1236 if (Network_send_objnum == -1)
1239 Network_send_object_mode = 0;
1240 // mprintf((0, "Sending object array to player %d.\n", player_num));
1241 *(short *)(object_buffer+loc) = INTEL_SHORT(-1); loc += 2;
1242 object_buffer[loc] = player_num; loc += 1;
1243 loc += 2; // Placeholder for remote_objnum, not used here
1244 Network_send_objnum = 0;
1245 obj_count_frame = 1;
1249 for (i = Network_send_objnum; i <= Highest_object_index; i++)
1251 if ((Objects[i].type != OBJ_POWERUP) && (Objects[i].type != OBJ_PLAYER) &&
1252 (Objects[i].type != OBJ_CNTRLCEN) && (Objects[i].type != OBJ_GHOST) &&
1253 (Objects[i].type != OBJ_ROBOT) && (Objects[i].type != OBJ_HOSTAGE) &&
1254 !(Objects[i].type==OBJ_WEAPON && Objects[i].id==PMINE_ID))
1256 if ((Network_send_object_mode == 0) && ((object_owner[i] != -1) && (object_owner[i] != player_num)))
1258 if ((Network_send_object_mode == 1) && ((object_owner[i] == -1) || (object_owner[i] == player_num)))
1261 if ( ((IPX_MAX_DATA_SIZE-1) - loc) < (sizeof(object)+5) )
1262 break; // Not enough room for another object
1267 remote_objnum = objnum_local_to_remote((short)i, &owner);
1268 Assert(owner == object_owner[i]);
1270 *(short *)(object_buffer+loc) = INTEL_SHORT((short)i); loc += 2;
1271 object_buffer[loc] = owner; loc += 1;
1272 *(short *)(object_buffer+loc) = INTEL_SHORT(remote_objnum); loc += 2;
1274 memcpy(object_buffer+loc, &Objects[i], sizeof(object)); loc += sizeof(object);
1276 if (Network_game_type == IPX_GAME) {
1279 memcpy(&tmpobj, &(Objects[i]), sizeof(object));
1280 swap_object(&tmpobj);
1281 memcpy(&(object_buffer[loc]), &tmpobj, sizeof(object)); loc += sizeof(object);
1284 memcpy(object_buffer+loc, &Objects[i], sizeof(object)); loc += sizeof(object);
1286 // mprintf((0, "..packing object %d, remote %d\n", i, remote_objnum));
1289 if (obj_count_frame) // Send any objects we've buffered
1293 Network_send_objnum = i;
1294 object_buffer[1] = obj_count_frame; object_buffer[2] = frame_num;
1295 // mprintf((0, "Object packet %d contains %d objects.\n", frame_num, obj_count_frame));
1297 Assert(loc <= IPX_MAX_DATA_SIZE);
1299 if (Network_game_type == IPX_GAME)
1300 ipx_send_internetwork_packet_data( object_buffer, loc, Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node );
1303 appletalk_send_packet_data( object_buffer, loc, Network_player_rejoining.player.network.appletalk.node,
1304 Network_player_rejoining.player.network.appletalk.net,
1305 Network_player_rejoining.player.network.appletalk.socket);
1308 // OLD ipx_send_packet_data(object_buffer, loc, &Network_player_rejoining.player.node);
1311 if (i > Highest_object_index)
1313 if (Network_send_object_mode == 0)
1315 Network_send_objnum = 0;
1316 Network_send_object_mode = 1; // go to next mode
1320 Assert(Network_send_object_mode == 1);
1323 // Send count so other side can make sure he got them all
1324 // mprintf((0, "Sending end marker in packet #%d.\n", frame_num));
1325 mprintf((0, "Sent %d objects.\n", obj_count));
1326 object_buffer[0] = PID_OBJECT_DATA;
1327 object_buffer[1] = 1;
1328 object_buffer[2] = frame_num;
1329 *(short *)(object_buffer+3) = INTEL_SHORT(-2);
1330 *(short *)(object_buffer+6) = INTEL_SHORT(obj_count);
1331 //OLD ipx_send_packet_data(object_buffer, 8, &Network_player_rejoining.player.node);
1332 if (Network_game_type == IPX_GAME)
1333 ipx_send_internetwork_packet_data(object_buffer, 8, Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node);
1336 appletalk_send_packet_data( object_buffer, 8, Network_player_rejoining.player.network.appletalk.node,
1337 Network_player_rejoining.player.network.appletalk.net,
1338 Network_player_rejoining.player.network.appletalk.socket);
1342 // Send sync packet which tells the player who he is and to start!
1343 network_send_rejoin_sync(player_num);
1344 mprintf ((0,"VerfiyPlayerJoined is now set to %d\n",player_num));
1345 VerifyPlayerJoined=player_num;
1347 // Turn off send object mode
1348 Network_send_objnum = -1;
1349 Network_send_objects = 0;
1352 //if (!network_i_am_master ())
1353 // Int3(); // Bad!! Get Jason. Someone goofy is trying to get ahold of the game!
1355 Network_sending_extras=40; // start to send extras
1356 Player_joining_extras=player_num;
1360 } // i > Highest_object_index
1361 } // For PACKETS_PER_FRAME
1364 extern void multi_send_powerup_update();
1366 void network_send_rejoin_sync(int player_num)
1370 Players[player_num].connected = 1; // connect the new guy
1371 LastPacketTime[player_num] = timer_get_approx_seconds();
1373 if (Endlevel_sequence || Control_center_destroyed)
1375 // Endlevel started before we finished sending the goods, we'll
1376 // have to stop and try again after the level.
1378 if (Network_game_type == IPX_GAME)
1379 network_dump_player(Network_player_rejoining.player.network.ipx.server,Network_player_rejoining.player.network.ipx.node, DUMP_ENDLEVEL);
1382 network_dump_appletalk_player(Network_player_rejoining.player.network.appletalk.node,Network_player_rejoining.player.network.appletalk.net, Network_player_rejoining.player.network.appletalk.socket, DUMP_ENDLEVEL);
1384 Network_send_objects = 0;
1385 Network_sending_extras=0;
1389 if (Network_player_added)
1391 Network_player_rejoining.type = PID_ADDPLAYER;
1392 Network_player_rejoining.player.connected = player_num;
1393 network_new_player(&Network_player_rejoining);
1395 for (i = 0; i < N_players; i++)
1397 if ((i != player_num) && (i != Player_num) && (Players[i].connected))
1398 if (Network_game_type == IPX_GAME) {
1400 ipx_send_packet_data( (ubyte *)&Network_player_rejoining, sizeof(sequence_packet), NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node, Players[i].net_address);
1402 send_sequence_packet( Network_player_rejoining, NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node, Players[i].net_address);
1406 appletalk_send_packet_data( (ubyte *)&Network_player_rejoining, sizeof(sequence_packet), NetPlayers.players[i].network.appletalk.node,
1407 NetPlayers.players[i].network.appletalk.net, NetPlayers.players[i].network.appletalk.socket);
1413 // Send sync packet to the new guy
1415 network_update_netgame();
1417 // Fill in the kill list
1418 for (j=0; j<MAX_PLAYERS; j++)
1420 for (i=0; i<MAX_PLAYERS;i++)
1421 Netgame.kills[j][i] = kill_matrix[j][i];
1422 Netgame.killed[j] = Players[j].net_killed_total;
1423 Netgame.player_kills[j] = Players[j].net_kills_total;
1424 Netgame.player_score[j] = Players[j].score;
1427 Netgame.level_time = Players[Player_num].time_level;
1428 Netgame.monitor_vector = network_create_monitor_vector();
1430 mprintf((0, "Sending rejoin sync packet!!!\n"));
1432 if (Network_game_type == IPX_GAME) {
1434 ipx_send_internetwork_packet_data( (ubyte *)&Netgame, sizeof(netgame_info), Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node );
1435 ipx_send_internetwork_packet_data( (ubyte *)&NetPlayers, sizeof(AllNetPlayers_info), Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node );
1437 send_netgame_packet(Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node, NULL, 0);
1438 send_netplayers_packet(Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node);
1442 appletalk_send_packet_data( (ubyte *)&Netgame, sizeof(netgame_info), Network_player_rejoining.player.network.appletalk.node,
1443 Network_player_rejoining.player.network.appletalk.net,
1444 Network_player_rejoining.player.network.appletalk.socket);
1445 appletalk_send_packet_data( (ubyte *)&NetPlayers, sizeof(AllNetPlayers_info), Network_player_rejoining.player.network.appletalk.node,
1446 Network_player_rejoining.player.network.appletalk.net,
1447 Network_player_rejoining.player.network.appletalk.socket);
1452 void resend_sync_due_to_packet_loss_for_allender ()
1456 mprintf ((0,"I'm resending a sync packet! VPJ=%d\n",VerifyPlayerJoined));
1458 network_update_netgame();
1460 // Fill in the kill list
1461 for (j=0; j<MAX_PLAYERS; j++)
1463 for (i=0; i<MAX_PLAYERS;i++)
1464 Netgame.kills[j][i] = kill_matrix[j][i];
1465 Netgame.killed[j] = Players[j].net_killed_total;
1466 Netgame.player_kills[j] = Players[j].net_kills_total;
1467 Netgame.player_score[j] = Players[j].score;
1470 Netgame.level_time = Players[Player_num].time_level;
1471 Netgame.monitor_vector = network_create_monitor_vector();
1473 if (Network_game_type == IPX_GAME) {
1475 ipx_send_internetwork_packet_data( (ubyte *)&Netgame, sizeof(netgame_info), Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node );
1476 ipx_send_internetwork_packet_data( (ubyte *)&NetPlayers, sizeof(AllNetPlayers_info), Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node );
1478 send_netgame_packet(Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node, NULL, 0);
1479 send_netplayers_packet(Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node);
1483 appletalk_send_packet_data( (ubyte *)&Netgame, sizeof(netgame_info), Network_player_rejoining.player.network.appletalk.node,
1484 Network_player_rejoining.player.network.appletalk.net,
1485 Network_player_rejoining.player.network.appletalk.socket);
1486 appletalk_send_packet_data( (ubyte *)&NetPlayers, sizeof(AllNetPlayers_info), Network_player_rejoining.player.network.appletalk.node,
1487 Network_player_rejoining.player.network.appletalk.net,
1488 Network_player_rejoining.player.network.appletalk.socket);
1494 char * network_get_player_name( int objnum )
1496 if ( objnum < 0 ) return NULL;
1497 if ( Objects[objnum].type != OBJ_PLAYER ) return NULL;
1498 if ( Objects[objnum].id >= MAX_PLAYERS ) return NULL;
1499 if ( Objects[objnum].id >= N_players ) return NULL;
1501 return Players[Objects[objnum].id].callsign;
1505 void network_add_player(sequence_packet *p)
1509 mprintf((0, "Got add player request!\n"));
1511 for (i=0; i<N_players; i++ ) {
1512 if (Network_game_type == IPX_GAME) {
1513 if ( !memcmp( NetPlayers.players[i].network.ipx.node, p->player.network.ipx.node, 6) && !memcmp(NetPlayers.players[i].network.ipx.server, p->player.network.ipx.server, 4))
1514 return; // already got them
1516 if ( (NetPlayers.players[i].network.appletalk.node == p->player.network.appletalk.node) &&
1517 (NetPlayers.players[i].network.appletalk.net == p->player.network.appletalk.net))
1522 if (Network_game_type == IPX_GAME) {
1523 memcpy( NetPlayers.players[N_players].network.ipx.node, p->player.network.ipx.node, 6 );
1524 memcpy( NetPlayers.players[N_players].network.ipx.server, p->player.network.ipx.server, 4 );
1526 NetPlayers.players[N_players].network.appletalk.node = p->player.network.appletalk.node;
1527 NetPlayers.players[N_players].network.appletalk.net = p->player.network.appletalk.net;
1528 NetPlayers.players[N_players].network.appletalk.socket = p->player.network.appletalk.socket;
1531 ClipRank (&p->player.rank);
1533 memcpy( NetPlayers.players[N_players].callsign, p->player.callsign, CALLSIGN_LEN+1 );
1534 NetPlayers.players[N_players].version_major=p->player.version_major;
1535 NetPlayers.players[N_players].version_minor=p->player.version_minor;
1536 NetPlayers.players[N_players].rank=p->player.rank;
1537 NetPlayers.players[N_players].connected = 1;
1538 network_check_for_old_version (N_players);
1540 Players[N_players].KillGoalCount=0;
1541 Players[N_players].connected = 1;
1542 LastPacketTime[N_players] = timer_get_approx_seconds();
1544 Netgame.numplayers = N_players;
1546 // Broadcast updated info
1548 mprintf ((0,"sending_game_info!\n"));
1549 network_send_game_info(NULL);
1552 // One of the players decided not to join the game
1554 void network_remove_player(sequence_packet *p)
1559 for (i=0; i<N_players; i++ ) {
1560 if (Network_game_type == IPX_GAME) {
1561 if (!memcmp(NetPlayers.players[i].network.ipx.node, p->player.network.ipx.node, 6) && !memcmp(NetPlayers.players[i].network.ipx.server, p->player.network.ipx.server, 4)) {
1566 if ( (NetPlayers.players[i].network.appletalk.node == p->player.network.appletalk.node) && (NetPlayers.players[i].network.appletalk.net == p->player.network.appletalk.net) ) {
1573 if (pn < 0 ) return;
1575 for (i=pn; i<N_players-1; i++ ) {
1576 if (Network_game_type == IPX_GAME) {
1577 memcpy( NetPlayers.players[i].network.ipx.node, NetPlayers.players[i+1].network.ipx.node, 6 );
1578 memcpy( NetPlayers.players[i].network.ipx.server, NetPlayers.players[i+1].network.ipx.server, 4 );
1580 NetPlayers.players[i].network.appletalk.node = NetPlayers.players[i+1].network.appletalk.node;
1581 NetPlayers.players[i].network.appletalk.net = NetPlayers.players[i+1].network.appletalk.net;
1582 NetPlayers.players[i].network.appletalk.socket = NetPlayers.players[i+1].network.appletalk.socket;
1584 memcpy( NetPlayers.players[i].callsign, NetPlayers.players[i+1].callsign, CALLSIGN_LEN+1 );
1585 NetPlayers.players[i].version_major=NetPlayers.players[i+1].version_major;
1586 NetPlayers.players[i].version_minor=NetPlayers.players[i+1].version_minor;
1588 NetPlayers.players[i].rank=NetPlayers.players[i+1].rank;
1589 ClipRank (&NetPlayers.players[i].rank);
1590 network_check_for_old_version(i);
1594 Netgame.numplayers = N_players;
1596 // Broadcast new info
1598 network_send_game_info(NULL);
1603 network_dump_player(ubyte * server, ubyte *node, int why)
1605 // Inform player that he was not chosen for the netgame
1607 sequence_packet temp;
1609 temp.type = PID_DUMP;
1610 memcpy(temp.player.callsign, Players[Player_num].callsign, CALLSIGN_LEN+1);
1611 temp.player.connected = why;
1612 if (Network_game_type == IPX_GAME) {
1614 ipx_send_internetwork_packet_data( (ubyte *)&temp, sizeof(sequence_packet), server, node);
1616 send_sequence_packet( temp, server, node, NULL);
1624 void network_dump_appletalk_player(ubyte node, ushort net, ubyte socket, int why)
1626 sequence_packet temp;
1628 temp.type = PID_DUMP;
1629 memcpy(temp.player.callsign, Players[Player_num].callsign, CALLSIGN_LEN+1);
1630 temp.player.connected = why;
1631 if (Network_game_type == APPLETALK_GAME) {
1632 appletalk_send_packet_data( (ubyte *)&temp, sizeof(sequence_packet), node, net, socket );
1640 network_send_game_list_request()
1642 // Send a broadcast request for game info
1646 mprintf((0, "Sending game_list request.\n"));
1647 me.type = PID_GAME_LIST;
1648 memcpy( me.player.callsign, Players[Player_num].callsign, CALLSIGN_LEN+1 );
1650 if (Network_game_type == IPX_GAME) {
1651 memcpy( me.player.network.ipx.node, ipx_get_my_local_address(), 6 );
1652 memcpy( me.player.network.ipx.server, ipx_get_my_server_address(), 4 );
1655 ipx_send_broadcast_packet_data( (ubyte *)&me, sizeof(sequence_packet) );
1657 send_sequence_packet( me, NULL, NULL, NULL);
1661 me.player.network.appletalk.node = appletalk_get_my_node();
1662 me.player.network.appletalk.net = appletalk_get_my_net();
1663 me.player.network.appletalk.socket = appletalk_get_my_socket();
1664 appletalk_send_game_info( (ubyte *)&me, sizeof(sequence_packet), Network_zone_name );
1669 void network_send_all_info_request(char type,int which_security)
1671 // Send a broadcast request for game info
1675 mprintf((0, "Sending all_info request.\n"));
1677 me.Security=which_security;
1679 memcpy( me.player.callsign, Players[Player_num].callsign, CALLSIGN_LEN+1 );
1681 if (Network_game_type == IPX_GAME) {
1682 memcpy( me.player.network.ipx.node, ipx_get_my_local_address(), 6 );
1683 memcpy( me.player.network.ipx.server, ipx_get_my_server_address(), 4 );
1686 ipx_send_broadcast_packet_data( (ubyte *)&me, sizeof(sequence_packet) );
1688 send_sequence_packet(me, NULL, NULL, NULL);
1692 me.player.network.appletalk.node = appletalk_get_my_node();
1693 me.player.network.appletalk.net = appletalk_get_my_net();
1694 me.player.network.appletalk.socket = appletalk_get_my_socket();
1695 appletalk_send_game_info( (ubyte *)&me, sizeof(sequence_packet), Network_zone_name );
1702 network_update_netgame(void)
1704 // Update the netgame struct with current game variables
1708 Netgame.numconnected=0;
1709 for (i=0;i<N_players;i++)
1710 if (Players[i].connected)
1711 Netgame.numconnected++;
1713 // This is great: D2 1.0 and 1.1 ignore upper part of the game_flags field of
1714 // the lite_info struct when you're sitting on the join netgame screen. We can
1715 // "sneak" Hoard information into this field. This is better than sending
1716 // another packet that could be lost in transit.
1719 if (HoardEquipped())
1721 if (Game_mode & GM_HOARD)
1723 Netgame.game_flags |=NETGAME_FLAG_HOARD;
1724 if (Game_mode & GM_TEAM)
1725 Netgame.game_flags |=NETGAME_FLAG_TEAM_HOARD;
1729 if (Network_status == NETSTAT_STARTING)
1732 Netgame.numplayers = N_players;
1733 Netgame.game_status = Network_status;
1734 Netgame.max_numplayers = MaxNumNetPlayers;
1736 for (i = 0; i < MAX_NUM_NET_PLAYERS; i++)
1738 NetPlayers.players[i].connected = Players[i].connected;
1739 for(j = 0; j < MAX_NUM_NET_PLAYERS; j++)
1740 Netgame.kills[i][j] = kill_matrix[i][j];
1742 Netgame.killed[i] = Players[i].net_killed_total;
1743 Netgame.player_kills[i] = Players[i].net_kills_total;
1744 Netgame.player_score[i] = Players[i].score;
1745 Netgame.player_flags[i] = (Players[i].flags & (PLAYER_FLAGS_BLUE_KEY | PLAYER_FLAGS_RED_KEY | PLAYER_FLAGS_GOLD_KEY));
1747 Netgame.team_kills[0] = team_kills[0];
1748 Netgame.team_kills[1] = team_kills[1];
1749 Netgame.levelnum = Current_level_num;
1755 network_send_endlevel_sub(int player_num)
1760 // Send an endlevel packet for a player
1761 end.type = PID_ENDLEVEL;
1762 end.player_num = player_num;
1763 end.connected = Players[player_num].connected;
1764 end.kills = INTEL_SHORT(Players[player_num].net_kills_total);
1765 end.killed = INTEL_SHORT(Players[player_num].net_killed_total);
1766 memcpy(end.kill_matrix, kill_matrix[player_num], MAX_PLAYERS*sizeof(short));
1768 for (i = 0; i < MAX_PLAYERS; i++)
1769 for (j = 0; j < MAX_PLAYERS; j++)
1770 end.kill_matrix[i][j] = INTEL_SHORT(end.kill_matrix[i][j]);
1772 j = j; // to satisfy compiler
1775 if (Players[player_num].connected == 1) // Still playing
1777 Assert(Control_center_destroyed);
1778 end.seconds_left = Countdown_seconds_left;
1781 // mprintf((0, "Sending endlevel packet.\n"));
1783 for (i = 0; i < N_players; i++)
1785 if ((i != Player_num) && (i!=player_num) && (Players[i].connected)) {
1786 if (Players[i].connected==1)
1787 network_send_endlevel_short_sub(player_num,i);
1789 if (Network_game_type == IPX_GAME)
1790 ipx_send_packet_data((ubyte *)&end, sizeof(endlevel_info), NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node,Players[i].net_address);
1793 appletalk_send_packet_data( (ubyte *)&end, sizeof(endlevel_info), NetPlayers.players[i].network.appletalk.node,
1794 NetPlayers.players[i].network.appletalk.net,
1795 NetPlayers.players[i].network.appletalk.socket);
1803 network_send_endlevel_packet(void)
1805 // Send an updated endlevel status to other hosts
1807 network_send_endlevel_sub(Player_num);
1812 network_send_endlevel_short_sub(int from_player_num,int to_player)
1814 endlevel_info_short end;
1816 // Send an endlevel packet for a player
1817 end.type = PID_ENDLEVEL_SHORT;
1818 end.player_num = from_player_num;
1819 end.connected = Players[from_player_num].connected;
1820 end.seconds_left = Countdown_seconds_left;
1823 if (Players[from_player_num].connected == 1) // Still playing
1825 Assert(Control_center_destroyed);
1828 if ((to_player != Player_num) && (to_player!=from_player_num) && (Players[to_player].connected))
1830 mprintf((0, "Sending short endlevel packet to %s.\n",Players[to_player].callsign));
1831 if (Network_game_type == IPX_GAME)
1832 ipx_send_packet_data((ubyte *)&end, sizeof(endlevel_info_short), NetPlayers.players[to_player].network.ipx.server, NetPlayers.players[to_player].network.ipx.node,Players[to_player].net_address);
1835 appletalk_send_packet_data( (ubyte *)&end, sizeof(endlevel_info_short), NetPlayers.players[to_player].network.appletalk.node,
1836 NetPlayers.players[to_player].network.appletalk.net,
1837 NetPlayers.players[to_player].network.appletalk.socket);
1842 extern fix ThisLevelTime;
1845 network_send_game_info(sequence_packet *their)
1847 // Send game info to someone who requested it
1849 char old_type, old_status;
1853 mprintf((0, "Sending game info.\n"));
1855 network_update_netgame(); // Update the values in the netgame struct
1857 old_type = Netgame.type;
1858 old_status = Netgame.game_status;
1860 Netgame.type = PID_GAME_INFO;
1861 NetPlayers.type = PID_PLAYERSINFO;
1863 NetPlayers.Security=Netgame.Security;
1864 Netgame.version_major=Version_major;
1865 Netgame.version_minor=Version_minor;
1867 if (Endlevel_sequence || Control_center_destroyed)
1868 Netgame.game_status = NETSTAT_ENDLEVEL;
1870 if (Netgame.PlayTimeAllowed)
1872 timevar=i2f (Netgame.PlayTimeAllowed*5*60);
1873 i=f2i(timevar-ThisLevelTime);
1875 Netgame.game_status=NETSTAT_ENDLEVEL;
1879 if (Network_game_type == IPX_GAME) {
1881 ipx_send_broadcast_packet_data((ubyte *)&Netgame, sizeof(netgame_info));
1882 ipx_send_broadcast_packet_data((ubyte *)&NetPlayers,sizeof(AllNetPlayers_info));
1884 send_netgame_packet(NULL, NULL, NULL, 0); // server == NULL says to broadcast packet
1885 send_netplayers_packet(NULL, NULL);
1887 } // nothing to do for appletalk games I think....
1889 if (Network_game_type == IPX_GAME) {
1891 ipx_send_internetwork_packet_data((ubyte *)&Netgame, sizeof(netgame_info), their->player.network.ipx.server, their->player.network.ipx.node);
1892 ipx_send_internetwork_packet_data((ubyte *)&NetPlayers,sizeof(AllNetPlayers_info),their->player.network.ipx.server,their->player.network.ipx.node);
1894 send_netgame_packet(their->player.network.ipx.server, their->player.network.ipx.node, NULL, 0);
1895 send_netplayers_packet(their->player.network.ipx.server, their->player.network.ipx.node);
1899 appletalk_send_packet_data( (ubyte *)&Netgame, sizeof(netgame_info), their->player.network.appletalk.node,
1900 their->player.network.appletalk.net, their->player.network.appletalk.socket );
1901 appletalk_send_packet_data( (ubyte *)&NetPlayers, sizeof(AllNetPlayers_info), their->player.network.appletalk.node,
1902 their->player.network.appletalk.net, their->player.network.appletalk.socket );
1907 Netgame.type = old_type;
1908 Netgame.game_status = old_status;
1911 void network_send_lite_info(sequence_packet *their)
1913 // Send game info to someone who requested it
1915 char old_type, old_status,oldstatus;
1917 mprintf((0, "Sending lite game info.\n"));
1919 network_update_netgame(); // Update the values in the netgame struct
1921 old_type = Netgame.type;
1922 old_status = Netgame.game_status;
1924 Netgame.type = PID_LITE_INFO;
1926 if (Endlevel_sequence || Control_center_destroyed)
1927 Netgame.game_status = NETSTAT_ENDLEVEL;
1929 // If hoard mode, make this game look closed even if it isn't
1930 if (HoardEquipped())
1932 if (Game_mode & GM_HOARD)
1934 oldstatus=Netgame.game_status;
1935 Netgame.game_status=NETSTAT_ENDLEVEL;
1936 Netgame.gamemode=NETGAME_CAPTURE_FLAG;
1937 if (oldstatus==NETSTAT_ENDLEVEL)
1938 Netgame.game_flags|=NETGAME_FLAG_REALLY_ENDLEVEL;
1939 if (oldstatus==NETSTAT_STARTING)
1940 Netgame.game_flags|=NETGAME_FLAG_REALLY_FORMING;
1945 if (Network_game_type == IPX_GAME) {
1947 ipx_send_broadcast_packet_data((ubyte *)&Netgame, sizeof(lite_info));
1949 send_netgame_packet(NULL, NULL, NULL, 1); // server == NULL says broadcast
1951 } // nothing to do for appletalk I think....
1953 if (Network_game_type == IPX_GAME) {
1955 ipx_send_internetwork_packet_data((ubyte *)&Netgame, sizeof(lite_info), their->player.network.ipx.server, their->player.network.ipx.node);
1957 send_netgame_packet(their->player.network.ipx.server, their->player.network.ipx.node, NULL, 1);
1961 appletalk_send_packet_data( (ubyte *)&Netgame, sizeof(lite_info), their->player.network.appletalk.node,
1962 their->player.network.appletalk.net, their->player.network.appletalk.socket );
1967 // Restore the pre-hoard mode
1968 if (HoardEquipped())
1970 if (Game_mode & GM_HOARD)
1972 if (!(Game_mode & GM_TEAM))
1973 Netgame.gamemode=NETGAME_HOARD;
1975 Netgame.gamemode=NETGAME_TEAM_HOARD;
1976 Netgame.game_flags&=~NETGAME_FLAG_REALLY_ENDLEVEL;
1977 Netgame.game_flags&=~NETGAME_FLAG_REALLY_FORMING;
1978 Netgame.game_flags&=~NETGAME_FLAG_TEAM_HOARD;
1982 Netgame.type = old_type;
1983 Netgame.game_status = old_status;
1987 void network_send_netgame_update()
1989 // Send game info to someone who requested it
1991 char old_type, old_status;
1994 mprintf((0, "Sending updated game info.\n"));
1996 network_update_netgame(); // Update the values in the netgame struct
1998 old_type = Netgame.type;
1999 old_status = Netgame.game_status;
2001 Netgame.type = PID_GAME_UPDATE;
2003 if (Endlevel_sequence || Control_center_destroyed)
2004 Netgame.game_status = NETSTAT_ENDLEVEL;
2006 for (i=0; i<N_players; i++ ) {
2007 if ( (Players[i].connected) && (i!=Player_num ) ) {
2008 if (Network_game_type == IPX_GAME) {
2010 ipx_send_packet_data( (ubyte *)&Netgame, sizeof(lite_info), NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node,Players[i].net_address );
2012 send_netgame_packet(NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node, Players[i].net_address, 0);
2016 appletalk_send_packet_data( (ubyte *)&Netgame, sizeof(lite_info), NetPlayers.players[i].network.appletalk.node,
2017 NetPlayers.players[i].network.appletalk.net, NetPlayers.players[i].network.appletalk.socket );
2023 Netgame.type = old_type;
2024 Netgame.game_status = old_status;
2027 int network_send_request(void)
2029 // Send a request to join a game 'Netgame'. Returns 0 if we can join this
2030 // game, non-zero if there is some problem.
2033 if (Netgame.numplayers < 1)
2036 for (i = 0; i < MAX_NUM_NET_PLAYERS; i++)
2037 if (NetPlayers.players[i].connected)
2040 Assert(i < MAX_NUM_NET_PLAYERS);
2042 mprintf((0, "Sending game enroll request to player %d (%s). Serv=%x Node=%x Level=%d\n", i, Players[i].callsign,NetPlayers.players[i].network.ipx.server,NetPlayers.players[i].network.ipx.node,Netgame.levelnum));
2044 // segments_checksum = netmisc_calc_checksum( Segments, sizeof(segment)*(Highest_segment_index+1) );
2046 My_Seq.type = PID_REQUEST;
2047 My_Seq.player.connected = Current_level_num;
2049 if (Network_game_type == IPX_GAME) {
2051 ipx_send_internetwork_packet_data((ubyte *)&My_Seq, sizeof(sequence_packet), NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node);
2053 send_sequence_packet(My_Seq, NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node, NULL);
2057 appletalk_send_packet_data( (ubyte *)&My_Seq, sizeof(sequence_packet), NetPlayers.players[i].network.appletalk.node,
2058 NetPlayers.players[i].network.appletalk.net,
2059 NetPlayers.players[i].network.appletalk.socket);
2066 int SecurityCheck=0;
2068 void network_process_gameinfo(ubyte *data)
2071 netgame_info tmp_info;
2074 netgame_info *new = (netgame_info *)data;
2077 if (Network_game_type == IPX_GAME) {
2078 receive_netgame_packet(data, &tmp_info, 0); // get correctly aligned structure
2084 WaitingForPlayerInfo=0;
2086 if (new->Security !=TempPlayersInfo->Security)
2088 Int3(); // Get Jason
2089 return; // If this first half doesn't go with the second half
2092 Network_games_changed = 1;
2094 //mprintf((0, "Got game data for game %s.\n", new->game_name));
2096 Assert (TempPlayersInfo!=NULL);
2098 for (i = 0; i < num_active_games; i++)
2100 //mprintf ((0,"GAMEINFO: Game %d is %s!\n",i,Active_games[i].game_name));
2102 if (!stricmp(Active_games[i].game_name, new->game_name) &&
2103 Active_games[i].Security==new->Security)
2107 if (i == MAX_ACTIVE_NETGAMES)
2109 mprintf((0, "Too many netgames.\n"));
2113 // MWA memcpy(&Active_games[i], data, sizeof(netgame_info));
2114 memcpy(&Active_games[i], (ubyte *)new, sizeof(netgame_info));
2115 memcpy (&ActiveNetPlayers[i],TempPlayersInfo,sizeof(AllNetPlayers_info));
2118 if (Active_games[i].Security==SecurityCheck)
2121 //mprintf ((0,"Recieved %d unique games...\n",i));
2123 if (i == num_active_games)
2126 if (Active_games[i].numplayers == 0)
2128 mprintf ((0,"DELETING THIS GAME!!!\n"));
2130 for (j = i; j < num_active_games-1; j++)
2132 memcpy(&Active_games[j], &Active_games[j+1], sizeof(netgame_info));
2133 memcpy (&ActiveNetPlayers[j],&ActiveNetPlayers[j+1],sizeof(AllNetPlayers_info));
2140 void network_process_lite_info(ubyte *data)
2146 lite_info *new = (lite_info *)data;
2149 if (Network_game_type == IPX_GAME) {
2150 receive_netgame_packet(data, (netgame_info *)&tmp_info, 1);
2155 Network_games_changed = 1;
2157 //mprintf((0, "Got game data for game %s.\n", new->game_name));
2159 for (i = 0; i < num_active_games; i++)
2161 //mprintf ((0,"GAMEINFO: Game %d is %s!\n",i,Active_games[i].game_name));
2163 if ((!stricmp(Active_games[i].game_name, new->game_name)) &&
2164 Active_games[i].Security==new->Security)
2168 if (i == MAX_ACTIVE_NETGAMES)
2170 mprintf((0, "Too many netgames.\n"));
2174 memcpy(&Active_games[i], (ubyte *)new, sizeof(lite_info));
2176 // See if this is really a Hoard game
2177 // If so, adjust all the data accordingly
2179 if (HoardEquipped())
2181 if (Active_games[i].game_flags & NETGAME_FLAG_HOARD)
2183 Active_games[i].gamemode=NETGAME_HOARD;
2184 Active_games[i].game_status=NETSTAT_PLAYING;
2186 if (Active_games[i].game_flags & NETGAME_FLAG_TEAM_HOARD)
2187 Active_games[i].gamemode=NETGAME_TEAM_HOARD;
2188 if (Active_games[i].game_flags & NETGAME_FLAG_REALLY_ENDLEVEL)
2189 Active_games[i].game_status=NETSTAT_ENDLEVEL;
2190 if (Active_games[i].game_flags & NETGAME_FLAG_REALLY_FORMING)
2191 Active_games[i].game_status=NETSTAT_STARTING;
2195 //mprintf ((0,"Recieved %d unique games...\n",i));
2197 if (i == num_active_games)
2200 if (Active_games[i].numplayers == 0)
2202 mprintf ((0,"DELETING THIS GAME!!!\n"));
2204 for (j = i; j < num_active_games-1; j++)
2206 memcpy(&Active_games[j], &Active_games[j+1], sizeof(netgame_info));
2212 void network_process_dump(sequence_packet *their)
2214 // Our request for join was denied. Tell the user why.
2219 mprintf((0, "Dumped by player %s, type %d.\n", their->player.callsign, their->player.connected));
2221 if (their->player.connected!=7)
2222 nm_messagebox(NULL, 1, TXT_OK, NET_DUMP_STRINGS(their->player.connected));
2225 for (i=0;i<N_players;i++)
2226 if (!stricmp (their->player.callsign,Players[i].callsign))
2228 if (i!=network_who_is_master())
2230 HUD_init_message ("%s attempted to kick you out.",their->player.callsign);
2234 sprintf (temp,"%s has kicked you out!",their->player.callsign);
2235 nm_messagebox(NULL, 1, TXT_OK, &temp);
2236 if (Network_status==NETSTAT_PLAYING)
2242 Network_status = NETSTAT_MENU;
2247 void network_process_request(sequence_packet *their)
2249 // Player is ready to receieve a sync packet
2252 mprintf((0, "Player %s ready for sync.\n", their->player.callsign));
2254 for (i = 0; i < N_players; i++) {
2255 if (Network_game_type == IPX_GAME) {
2256 if (!memcmp(their->player.network.ipx.server, NetPlayers.players[i].network.ipx.server, 4) && !memcmp(their->player.network.ipx.node, NetPlayers.players[i].network.ipx.node, 6) && (!stricmp(their->player.callsign, NetPlayers.players[i].callsign))) {
2257 Players[i].connected = 1;
2261 if ( (their->player.network.appletalk.node == NetPlayers.players[i].network.appletalk.node) && (their->player.network.appletalk.net == NetPlayers.players[i].network.appletalk.net) && (!stricmp(their->player.callsign, NetPlayers.players[i].callsign)) ) {
2262 Players[i].connected = 1;
2269 #define REFUSE_INTERVAL F1_0 * 8
2270 extern void multi_reset_object_texture (object *);
2272 void network_process_packet(ubyte *data, int length )
2275 sequence_packet tmp_packet;
2277 sequence_packet *their = (sequence_packet *)data;
2280 if (Network_game_type == IPX_GAME) {
2281 receive_sequence_packet(data, &tmp_packet);
2282 their = &tmp_packet; // reassign their to point to correctly alinged structure
2286 //mprintf( (0, "Got packet of length %d, type %d\n", length, their->type ));
2288 // if ( length < sizeof(sequence_packet) ) return;
2294 case PID_GAME_INFO: // Jason L. says we can safely ignore this type.
2297 case PID_PLAYERSINFO:
2299 mprintf ((0,"Got a PID_PLAYERSINFO!\n"));
2301 if (Network_status==NETSTAT_WAITING)
2304 memcpy (&TempPlayersBase,data,sizeof(AllNetPlayers_info));
2306 if (Network_game_type == IPX_GAME)
2307 receive_netplayers_packet(data, &TempPlayersBase);
2309 memcpy (&TempPlayersBase,data,sizeof(AllNetPlayers_info));
2312 if (TempPlayersBase.Security!=Netgame.Security)
2314 mprintf ((0,"Bad security for PLAYERSINFO\n"));
2318 mprintf ((0,"Got a waiting PID_PLAYERSINFO!\n"));
2319 if (length!=ALLNETPLAYERSINFO_SIZE)
2321 mprintf ((0,"Invalid size for netplayers packet!\n"));
2325 TempPlayersInfo=&TempPlayersBase;
2326 WaitingForPlayerInfo=0;
2327 NetSecurityNum=TempPlayersInfo->Security;
2328 NetSecurityFlag=NETSECURITY_WAIT_FOR_SYNC;
2335 if (length != LITE_INFO_SIZE)
2337 mprintf ((0,"WARNING! Recieved invalid size for PID_LITE_INFO\n"));
2341 if (Network_status == NETSTAT_BROWSING)
2342 network_process_lite_info (data);
2346 // Someone wants a list of games
2348 if (length != SEQUENCE_PACKET_SIZE)
2350 mprintf ((0,"WARNING! Recieved invalid size for PID_GAME_LIST\n"));
2354 mprintf((0, "Got a PID_GAME_LIST!\n"));
2355 if ((Network_status == NETSTAT_PLAYING) || (Network_status == NETSTAT_STARTING) || (Network_status == NETSTAT_ENDLEVEL))
2356 if (network_i_am_master())
2357 network_send_lite_info(their);
2361 case PID_SEND_ALL_GAMEINFO:
2363 if (length != SEQUENCE_PACKET_SIZE)
2365 mprintf ((0,"WARNING! Recieved invalid size for PID_SEND_ALL_GAMEINFO\n"));
2369 if ((Network_status == NETSTAT_PLAYING) || (Network_status == NETSTAT_STARTING) || (Network_status == NETSTAT_ENDLEVEL))
2370 if (network_i_am_master() && their->Security==Netgame.Security)
2371 network_send_game_info(their);
2376 mprintf( (0, "Got NEWPLAYER message from %s.\n", their->player.callsign));
2378 if (length != SEQUENCE_PACKET_SIZE)
2380 mprintf ((0,"WARNING! Recieved invalid size for PID_ADDPLAYER\n"));
2383 mprintf( (0, "Got NEWPLAYER message from %s.\n", their->player.callsign));
2384 network_new_player(their);
2387 if (length != SEQUENCE_PACKET_SIZE)
2389 mprintf ((0,"WARNING! Recieved invalid size for PID_REQUEST\n"));
2393 mprintf( (0, "Got REQUEST from '%s'\n", their->player.callsign ));
2394 if (Network_status == NETSTAT_STARTING)
2396 // Someone wants to join our game!
2397 network_add_player(their);
2399 else if (Network_status == NETSTAT_WAITING)
2401 // Someone is ready to recieve a sync packet
2402 network_process_request(their);
2404 else if (Network_status == NETSTAT_PLAYING)
2406 // Someone wants to join a game in progress!
2407 if (Netgame.RefusePlayers)
2408 DoRefuseStuff (their);
2410 network_welcome_player(their);
2415 if (length != SEQUENCE_PACKET_SIZE)
2417 mprintf ((0,"WARNING! Recieved invalid size for PID_DUMP\n"));
2421 if (Network_status == NETSTAT_WAITING || Network_status==NETSTAT_PLAYING )
2422 network_process_dump(their);
2424 case PID_QUIT_JOINING:
2426 if (length != SEQUENCE_PACKET_SIZE)
2428 mprintf ((0,"WARNING! Recieved invalid size for PID_QUIT_JOINING\n"));
2431 if (Network_status == NETSTAT_STARTING)
2432 network_remove_player( their );
2433 else if ((Network_status == NETSTAT_PLAYING) && (Network_send_objects))
2434 network_stop_resync( their );
2438 mprintf ((0,"Got a sync packet! Network_status=%d\n",NETSTAT_WAITING));
2440 if (Network_status == NETSTAT_WAITING) {
2443 memcpy((ubyte *)&(TempNetInfo), data, sizeof(netgame_info));
2445 if (Network_game_type == IPX_GAME)
2446 receive_netgame_packet(data, &TempNetInfo, 0);
2448 memcpy((ubyte *)&(TempNetInfo), data, sizeof(netgame_info));
2451 if (TempNetInfo.Security!=Netgame.Security)
2453 mprintf ((0,"Bad security on sync packet.\n"));
2457 if (NetSecurityFlag==NETSECURITY_WAIT_FOR_SYNC)
2459 if (TempNetInfo.Security==TempPlayersInfo->Security)
2461 network_read_sync_packet (&TempNetInfo,0);
2468 NetSecurityFlag=NETSECURITY_WAIT_FOR_PLAYERS;
2469 NetSecurityNum=TempNetInfo.Security;
2471 if ( network_wait_for_playerinfo())
2472 network_read_sync_packet((netgame_info *)data,0);
2481 if ((Game_mode&GM_NETWORK) && ((Network_status == NETSTAT_PLAYING)||(Network_status == NETSTAT_ENDLEVEL) || Network_status==NETSTAT_WAITING)) {
2482 network_process_pdata((char *)data);
2485 case PID_NAKED_PDATA:
2486 if ((Game_mode&GM_NETWORK) && ((Network_status == NETSTAT_PLAYING)||(Network_status == NETSTAT_ENDLEVEL) || Network_status==NETSTAT_WAITING))
2487 network_process_naked_pdata((char *)data,length);
2490 case PID_OBJECT_DATA:
2491 if (Network_status == NETSTAT_WAITING)
2492 network_read_object_packet(data);
2495 if ((Network_status == NETSTAT_ENDLEVEL) || (Network_status == NETSTAT_PLAYING))
2496 network_read_endlevel_packet(data);
2498 mprintf((0, "Junked endlevel packet.\n"));
2500 case PID_ENDLEVEL_SHORT:
2501 if ((Network_status == NETSTAT_ENDLEVEL) || (Network_status == NETSTAT_PLAYING))
2502 network_read_endlevel_short_packet(data);
2504 mprintf((0, "Junked short endlevel packet!\n"));
2507 case PID_GAME_UPDATE:
2508 mprintf ((0,"Got a GAME_UPDATE!\n"));
2510 if (Network_status==NETSTAT_PLAYING)
2513 memcpy((ubyte *)&TempNetInfo, data, sizeof(lite_info) );
2515 if (Network_game_type == IPX_GAME)
2516 receive_netgame_packet(data, &TempNetInfo, 1);
2518 memcpy((ubyte *)&TempNetInfo, data, sizeof(lite_info) );
2520 if (TempNetInfo.Security==Netgame.Security)
2521 memcpy (&Netgame,(ubyte *)&TempNetInfo,sizeof(lite_info));
2523 if (Game_mode & GM_TEAM)
2527 for (i=0;i<N_players;i++)
2528 if (Players[i].connected)
2529 multi_reset_object_texture (&Objects[Players[i].objnum]);
2534 network_ping (PID_PING_RETURN,data[1]);
2536 case PID_PING_RETURN:
2537 network_handle_ping_return(data[1]); // data[1] is player who told us of their ping time
2539 case PID_NAMES_RETURN:
2540 if (Network_status==NETSTAT_BROWSING && NamesInfoSecurity!=-1)
2541 network_process_names_return (data);
2543 case PID_GAME_PLAYERS:
2544 // Someone wants a list of players in this game
2546 if (length != SEQUENCE_PACKET_SIZE)
2548 mprintf ((0,"WARNING! Recieved invalid size for PID_GAME_PLAYERS\n"));
2552 mprintf((0, "Got a PID_GAME_PLAYERS!\n"));
2553 if ((Network_status == NETSTAT_PLAYING) || (Network_status == NETSTAT_STARTING) || (Network_status == NETSTAT_ENDLEVEL))
2554 if (network_i_am_master() && their->Security==Netgame.Security)
2555 network_send_player_names(their);
2559 mprintf((0, "Ignoring invalid packet type.\n"));
2560 Int3(); // Invalid network packet type, see ROB
2566 void dump_segments()
2570 fp = fopen( "TEST.DMP", "wb" );
2571 fwrite( Segments, sizeof(segment)*(Highest_segment_index+1),1, fp );
2573 mprintf( (0, "SS=%d\n", sizeof(segment) ));
2579 network_read_endlevel_packet( ubyte *data )
2581 // Special packet for end of level syncing
2588 end = (endlevel_info *)data;
2590 for (i = 0; i < MAX_PLAYERS; i++)
2591 for (j = 0; j < MAX_PLAYERS; j++)
2592 end->kill_matrix[i][j] = INTEL_SHORT(end->kill_matrix[i][j]);
2593 end->kills = INTEL_SHORT(end->kills);
2594 end->killed = INTEL_SHORT(end->killed);
2597 playernum = end->player_num;
2599 Assert(playernum != Player_num);
2601 if (playernum>=N_players)
2603 Int3(); // weird, but it an happen in a coop restore game
2604 return; // if it happens in a coop restore, don't worry about it
2607 if ((Network_status == NETSTAT_PLAYING) && (end->connected != 0))
2608 return; // Only accept disconnect packets if we're not out of the level yet
2610 Players[playernum].connected = end->connected;
2611 memcpy(&kill_matrix[playernum][0], end->kill_matrix, MAX_PLAYERS*sizeof(short));
2612 Players[playernum].net_kills_total = end->kills;
2613 Players[playernum].net_killed_total = end->killed;
2615 if ((Players[playernum].connected == 1) && (end->seconds_left < Countdown_seconds_left))
2616 Countdown_seconds_left = end->seconds_left;
2618 LastPacketTime[playernum] = timer_get_approx_seconds();
2620 // mprintf((0, "Got endlevel packet from player %d.\n", playernum));
2624 network_read_endlevel_short_packet( ubyte *data )
2626 // Special packet for end of level syncing
2629 endlevel_info_short *end;
2631 end = (endlevel_info_short *)data;
2633 playernum = end->player_num;
2635 Assert(playernum != Player_num);
2637 if (playernum>=N_players)
2639 Int3(); // weird, but it can happen in a coop restore game
2640 return; // if it happens in a coop restore, don't worry about it
2643 if ((Network_status == NETSTAT_PLAYING) && (end->connected != 0))
2645 //mprintf ((0,"Returning early for short_endlevel\n"));
2646 return; // Only accept disconnect packets if we're not out of the level yet
2649 Players[playernum].connected = end->connected;
2651 if ((Players[playernum].connected == 1) && (end->seconds_left < Countdown_seconds_left))
2652 Countdown_seconds_left = end->seconds_left;
2654 LastPacketTime[playernum] = timer_get_approx_seconds();
2659 network_pack_objects(void)
2661 // Switching modes, pack the object array
2663 special_reset_objects();
2667 network_verify_objects(int remote, int local)
2670 int nplayers, got_controlcen=0;
2672 mprintf ((0,"NETWORK:remote=%d local=%d\n",remote,local));
2674 if ((remote-local) > 10)
2677 if (Game_mode & GM_MULTI_ROBOTS)
2682 for (i = 0; i <= Highest_object_index; i++)
2684 if ((Objects[i].type == OBJ_PLAYER) || (Objects[i].type == OBJ_GHOST))
2686 if (Objects[i].type == OBJ_CNTRLCEN)
2690 if (got_controlcen && (MaxNumNetPlayers<=nplayers))
2697 network_read_object_packet( ubyte *data )
2699 // Object from another net player we need to sync with
2701 short objnum, remote_objnum;
2706 static int my_pnum = 0;
2707 static int mode = 0;
2708 static int object_count = 0;
2709 static int frame_num = 0;
2712 int remote_frame_num = data[2];
2716 // mprintf((0, "Object packet %d (remote #%d) contains %d objects.\n", frame_num, remote_frame_num, nobj));
2718 for (i = 0; i < nobj; i++)
2720 objnum = INTEL_SHORT( *(short *)(data+loc) ); loc += 2;
2721 obj_owner = data[loc]; loc += 1;
2722 remote_objnum = INTEL_SHORT( *(short *)(data+loc) ); loc += 2;
2726 // Clear object array
2727 mprintf((0, "Clearing object array.\n"));
2730 Network_rejoined = 1;
2731 my_pnum = obj_owner;
2732 change_playernum_to(my_pnum);
2737 else if (objnum == -2)
2739 // Special debug checksum marker for entire send
2742 network_pack_objects();
2745 mprintf((0, "Objnum -2 found in frame local %d remote %d.\n", frame_num, remote_frame_num));
2746 mprintf((0, "Got %d objects, expected %d.\n", object_count, remote_objnum));
2747 if (remote_objnum != object_count) {
2750 if (network_verify_objects(remote_objnum, object_count))
2752 // Failed to sync up
2753 nm_messagebox(NULL, 1, TXT_OK, TXT_NET_SYNC_FAILED);
2754 Network_status = NETSTAT_MENU;
2761 if (frame_num != remote_frame_num)
2763 mprintf ((0,"Got a type 3 object packet!\n"));
2765 if ((obj_owner == my_pnum) || (obj_owner == -1))
2769 objnum = remote_objnum;
2770 //if (objnum > Highest_object_index)
2772 // Highest_object_index = objnum;
2773 // num_objects = Highest_object_index+1;
2779 network_pack_objects();
2782 objnum = obj_allocate();
2785 obj = &Objects[objnum];
2786 if (obj->segnum != -1)
2788 Assert(obj->segnum == -1);
2789 Assert(objnum < MAX_OBJECTS);
2790 memcpy(obj,data+loc,sizeof(object)); loc += sizeof(object);
2792 if (Network_game_type == IPX_GAME)
2795 segnum = obj->segnum;
2796 obj->next = obj->prev = obj->segnum = -1;
2797 obj->attached_obj = -1;
2799 obj_link(obj-Objects,segnum);
2800 if (obj_owner == my_pnum)
2801 map_objnum_local_to_local(objnum);
2802 else if (obj_owner != -1)
2803 map_objnum_local_to_remote(objnum, remote_objnum, obj_owner);
2805 object_owner[objnum] = -1;
2807 } // For a standard onbject
2808 } // For each object in packet
2811 void network_sync_poll( int nitems, newmenu_item * menus, int * key, int citem )
2813 // Polling loop waiting for sync packet to start game
2823 if (Network_status != NETSTAT_WAITING) // Status changed to playing, exit the menu
2826 if (!Network_rejoined && (timer_get_approx_seconds() > t1+F1_0*2))
2830 // Poll time expired, re-send request
2832 t1 = timer_get_approx_seconds();
2834 mprintf((0, "Re-sending join request.\n"));
2835 i = network_send_request();
2841 void network_start_poll( int nitems, newmenu_item * menus, int * key, int citem )
2848 Assert(Network_status == NETSTAT_STARTING);
2850 if (!menus[0].value) {
2852 menus[0].redraw = 1;
2855 for (i=1; i<nitems; i++ ) {
2856 if ( (i>= N_players) && (menus[i].value) ) {
2858 menus[i].redraw = 1;
2863 for (i=0; i<nitems; i++ ) {
2864 if ( menus[i].value ) {
2866 if ( nm > N_players ) {
2868 menus[i].redraw = 1;
2873 if ( nm > MaxNumNetPlayers ) {
2874 nm_messagebox( TXT_ERROR, 1, TXT_OK, "%s %d %s", TXT_SORRY_ONLY, MaxNumNetPlayers, TXT_NETPLAYERS_IN );
2875 // Turn off the last player highlighted
2876 for (i = N_players; i > 0; i--)
2877 if (menus[i].value == 1)
2880 menus[i].redraw = 1;
2885 // if (nitems > MAX_PLAYERS ) return;
2887 n = Netgame.numplayers;
2890 if (n < Netgame.numplayers )
2892 digi_play_sample (SOUND_HUD_MESSAGE,F1_0);
2894 mprintf ((0,"More players are printed!"));
2895 if (FindArg("-norankings"))
2896 sprintf( menus[N_players-1].text, "%d. %-20s", N_players,NetPlayers.players[N_players-1].callsign );
2898 sprintf( menus[N_players-1].text, "%d. %s%-20s", N_players, RankStrings[NetPlayers.players[N_players-1].rank],NetPlayers.players[N_players-1].callsign );
2900 menus[N_players-1].redraw = 1;
2901 if (N_players <= MaxNumNetPlayers)
2903 menus[N_players-1].value = 1;
2906 else if ( n > Netgame.numplayers )
2908 // One got removed...
2910 digi_play_sample (SOUND_HUD_KILL,F1_0);
2912 for (i=0; i<N_players; i++ )
2915 if (FindArg("-norankings"))
2916 sprintf( menus[i].text, "%d. %-20s", i+1, NetPlayers.players[i].callsign );
2918 sprintf( menus[i].text, "%d. %s%-20s", i+1, RankStrings[NetPlayers.players[i].rank],NetPlayers.players[i].callsign );
2919 if (i < MaxNumNetPlayers)
2923 menus[i].redraw = 1;
2925 for (i=N_players; i<n; i++ )
2927 sprintf( menus[i].text, "%d. ", i+1 ); // Clear out the deleted entries...
2929 menus[i].redraw = 1;
2934 int opt_cinvul, opt_team_anarchy, opt_coop, opt_show_on_map, opt_closed,opt_maxnet;
2935 int last_cinvul=0,last_maxnet,opt_team_hoard;
2936 int opt_refuse,opt_capture;
2938 void network_game_param_poll( int nitems, newmenu_item * menus, int * key, int citem )
2940 static int oldmaxnet=0;
2942 if (((HoardEquipped() && menus[opt_team_hoard].value) || (menus[opt_team_anarchy].value || menus[opt_capture].value)) && !menus[opt_closed].value && !menus[opt_refuse].value) {
2943 menus[opt_refuse].value = 1;
2944 menus[opt_refuse].redraw = 1;
2945 menus[opt_refuse-1].value = 0;
2946 menus[opt_refuse-1].redraw = 1;
2947 menus[opt_refuse-2].value = 0;
2948 menus[opt_refuse-2].redraw = 1;
2952 if (menus[opt_coop].value)
2954 if ( (menus[opt_coop].value) || ((Network_game_type == APPLETALK_GAME) && (Network_appletalk_type == LOCALTALK_TYPE) && (menus[opt_coop-1].value)) )
2959 if (menus[opt_maxnet].value>2)
2961 menus[opt_maxnet].value=2;
2962 menus[opt_maxnet].redraw=1;
2965 if (menus[opt_maxnet].max_value>2)
2967 menus[opt_maxnet].max_value=2;
2968 menus[opt_maxnet].redraw=1;
2972 if ( (Network_game_type == APPLETALK_GAME) && (Network_appletalk_type == LOCALTALK_TYPE) ) {
2973 if (menus[opt_maxnet].value > 0) {
2974 menus[opt_maxnet].value=0;
2975 menus[opt_maxnet].redraw=1;
2977 if (menus[opt_maxnet].max_value > 0) {
2978 menus[opt_maxnet].max_value=0;
2979 menus[opt_maxnet].redraw=1;
2984 if (!Netgame.game_flags & NETGAME_FLAG_SHOW_MAP)
2985 Netgame.game_flags |= NETGAME_FLAG_SHOW_MAP;
2987 if (Netgame.PlayTimeAllowed || Netgame.KillGoal)
2989 Netgame.PlayTimeAllowed=0;
2994 else // if !Coop game
2999 menus[opt_maxnet].value=6;
3000 menus[opt_maxnet].max_value=6;
3003 if ( (Network_game_type == APPLETALK_GAME) && (Network_appletalk_type == LOCALTALK_TYPE) ) {
3004 menus[opt_maxnet].value=1;
3005 menus[opt_maxnet].max_value=1;
3012 if ( last_maxnet != menus[opt_maxnet].value )
3014 sprintf( menus[opt_maxnet].text, "Maximum players: %d", menus[opt_maxnet].value+2 );
3015 last_maxnet = menus[opt_maxnet].value;
3016 menus[opt_maxnet].redraw = 1;
3020 int netgame_difficulty;
3022 int network_get_game_params( char * game_name, int *mode, int *game_flags, int *level )
3025 int opt, opt_name, opt_level, opt_mode,opt_moreopts;
3027 char name[NETGAME_NAME_LEN+1];
3029 char level_text[32];
3032 int new_mission_num;
3035 *game_flags=*game_flags;
3037 SetAllAllowablesTo (1);
3038 NamesInfoSecurity=-1;
3040 for (i=0;i<MAX_PLAYERS;i++)
3042 Players[i].callsign[0]=0;
3046 Netgame.PlayTimeAllowed=0;
3047 Netgame.Allow_marker_view=1;
3048 netgame_difficulty=Player_default_difficulty;
3050 new_mission_num = multi_choose_mission(&anarchy_only);
3052 if (new_mission_num < 0)
3055 if (!(FindArg ("-packets") && FindArg ("-shortpackets")))
3056 if (!network_choose_connect ())
3060 if ( (Network_game_type == APPLETALK_GAME) && (Network_appletalk_type == LOCALTALK_TYPE) )
3061 MaxNumNetPlayers = 3;
3064 strcpy(Netgame.mission_name, Mission_list[new_mission_num].filename);
3065 strcpy(Netgame.mission_title, Mission_list[new_mission_num].mission_name);
3066 Netgame.control_invul_time = control_invul_time;
3068 sprintf( name, "%s%s", Players[Player_num].callsign, TXT_S_GAME );
3069 sprintf( slevel, "1" );
3072 m[opt].type = NM_TYPE_TEXT; m[opt].text = TXT_DESCRIPTION; opt++;
3075 m[opt].type = NM_TYPE_INPUT; m[opt].text = name; m[opt].text_len = NETGAME_NAME_LEN; opt++;
3077 sprintf(level_text, "%s (1-%d)", TXT_LEVEL_, Last_level);
3079 // if (Last_secret_level < -1)
3080 // sprintf(level_text+strlen(level_text)-1, ", S1-S%d)", -Last_secret_level);
3081 // else if (Last_secret_level == -1)
3082 // sprintf(level_text+strlen(level_text)-1, ", S1)");
3084 Assert(strlen(level_text) < 32);
3086 m[opt].type = NM_TYPE_TEXT; m[opt].text = level_text; opt++;
3089 m[opt].type = NM_TYPE_INPUT; m[opt].text = slevel; m[opt].text_len=4; opt++;
3090 // m[opt].type = NM_TYPE_TEXT; m[opt].text = TXT_OPTIONS; opt++;
3093 m[opt].type = NM_TYPE_RADIO; m[opt].text = TXT_ANARCHY; m[opt].value=1; m[opt].group=0; opt++;
3094 m[opt].type = NM_TYPE_RADIO; m[opt].text = TXT_TEAM_ANARCHY; m[opt].value=0; m[opt].group=0; opt_team_anarchy=opt; opt++;
3095 m[opt].type = NM_TYPE_RADIO; m[opt].text = TXT_ANARCHY_W_ROBOTS; m[opt].value=0; m[opt].group=0; opt++;
3096 m[opt].type = NM_TYPE_RADIO; m[opt].text = TXT_COOPERATIVE; m[opt].value=0; m[opt].group=0; opt_coop=opt; opt++;
3097 m[opt].type = NM_TYPE_RADIO; m[opt].text = "Capture the flag"; m[opt].value=0; m[opt].group=0; opt_capture=opt; opt++;
3099 if (HoardEquipped())
3101 m[opt].type = NM_TYPE_RADIO; m[opt].text = "Hoard"; m[opt].value=0; m[opt].group=0; opt++;
3102 m[opt].type = NM_TYPE_RADIO; m[opt].text = "Team Hoard"; m[opt].value=0; m[opt].group=0; opt_team_hoard=opt; opt++;
3103 m[opt].type = NM_TYPE_TEXT; m[opt].text = ""; opt++;
3106 { m[opt].type = NM_TYPE_TEXT; m[opt].text = ""; opt++; }
3108 m[opt].type = NM_TYPE_RADIO; m[opt].text = "Open game"; m[opt].group=1; m[opt].value=0; opt++;
3110 m[opt].type = NM_TYPE_RADIO; m[opt].text = TXT_CLOSED_GAME; m[opt].group=1; m[opt].value=0; opt++;
3112 m[opt].type = NM_TYPE_RADIO; m[opt].text = "Restricted Game "; m[opt].group=1; m[opt].value=Netgame.RefusePlayers; opt++;
3114 // m[opt].type = NM_TYPE_CHECK; m[opt].text = TXT_SHOW_IDS; m[opt].value=0; opt++;
3117 sprintf( srmaxnet, "Maximum players: %d", MaxNumNetPlayers);
3118 m[opt].type = NM_TYPE_SLIDER; m[opt].value=MaxNumNetPlayers-2; m[opt].text= srmaxnet; m[opt].min_value=0;
3119 m[opt].max_value=MaxNumNetPlayers-2; opt++;
3120 last_maxnet=MaxNumNetPlayers-2;
3123 m[opt].type = NM_TYPE_MENU; m[opt].text = "More options..."; opt++;
3128 ExtGameStatus=GAMESTAT_NETGAME_OPTIONS;
3129 i = newmenu_do1( NULL, NULL, opt, m, network_game_param_poll, 1 );
3131 if (i==opt_moreopts)
3133 if ( m[opt_mode+3].value )
3134 Game_mode=GM_MULTI_COOP;
3135 network_more_game_options();
3139 Netgame.RefusePlayers=m[opt_refuse].value;
3145 MaxNumNetPlayers = m[opt_maxnet].value+2;
3146 Netgame.max_numplayers=MaxNumNetPlayers;
3148 for (j = 0; j < num_active_games; j++)
3149 if (!stricmp(Active_games[j].game_name, name))
3151 nm_messagebox(TXT_ERROR, 1, TXT_OK, TXT_DUPLICATE_NAME);
3155 strcpy( game_name, name );
3158 *level = atoi(slevel);
3160 if ((*level < 1) || (*level > Last_level))
3162 nm_messagebox(TXT_ERROR, 1, TXT_OK, TXT_LEVEL_OUT_RANGE );
3163 sprintf(slevel, "1");
3166 if ( m[opt_mode].value )
3167 *mode = NETGAME_ANARCHY;
3172 nm_messagebox(TXT_SORRY, 1, TXT_OK, TXT_REGISTERED_ONLY );
3173 m[opt_mode+1].value = 0;
3174 m[opt_mode+2].value = 0;
3175 m[opt_mode+3].value = 0;
3176 if (HoardEquipped())
3177 m[opt_mode+4].value = 0;
3179 m[opt_mode].value = 1;
3183 else if (m[opt_mode+1].value) {
3184 *mode = NETGAME_TEAM_ANARCHY;
3186 else if (m[opt_capture].value)
3187 *mode = NETGAME_CAPTURE_FLAG;
3188 else if (HoardEquipped() && m[opt_capture+1].value)
3189 *mode = NETGAME_HOARD;
3190 else if (HoardEquipped() && m[opt_capture+2].value)
3191 *mode = NETGAME_TEAM_HOARD;
3192 else if (anarchy_only) {
3193 nm_messagebox(NULL, 1, TXT_OK, TXT_ANARCHY_ONLY_MISSION);
3194 m[opt_mode+2].value = 0;
3195 m[opt_mode+3].value = 0;
3196 m[opt_mode].value = 1;
3199 else if ( m[opt_mode+2].value )
3200 *mode = NETGAME_ROBOT_ANARCHY;
3201 else if ( m[opt_mode+3].value )
3202 *mode = NETGAME_COOPERATIVE;
3203 else Int3(); // Invalid mode -- see Rob
3205 if (m[opt_closed].value)
3206 Netgame.game_flags |= NETGAME_FLAG_CLOSED;
3214 network_set_game_mode(int gamemode)
3218 if ( gamemode == NETGAME_ANARCHY )
3219 Game_mode = GM_NETWORK;
3220 else if ( gamemode == NETGAME_ROBOT_ANARCHY )
3221 Game_mode = GM_NETWORK | GM_MULTI_ROBOTS;
3222 else if ( gamemode == NETGAME_COOPERATIVE )
3223 Game_mode = GM_NETWORK | GM_MULTI_COOP | GM_MULTI_ROBOTS;
3224 else if (gamemode == NETGAME_CAPTURE_FLAG)
3226 Game_mode = GM_NETWORK | GM_TEAM | GM_CAPTURE;
3230 else if (HoardEquipped() && gamemode == NETGAME_HOARD)
3231 Game_mode = GM_NETWORK | GM_HOARD;
3232 else if (HoardEquipped() && gamemode == NETGAME_TEAM_HOARD)
3234 Game_mode = GM_NETWORK | GM_HOARD | GM_TEAM;
3237 else if ( gamemode == NETGAME_TEAM_ANARCHY )
3239 Game_mode = GM_NETWORK | GM_TEAM;
3246 #ifdef MACINTOSH // minimize players on localtalk games
3247 if ( (Network_game_type == APPLETALK_GAME) && (Network_appletalk_type == LOCALTALK_TYPE) ) {
3248 if (Game_mode & GM_MULTI_ROBOTS)
3249 MaxNumNetPlayers = 2;
3251 MaxNumNetPlayers = 3;
3253 if (Game_mode & GM_MULTI_COOP)
3254 MaxNumNetPlayers = 4;
3256 MaxNumNetPlayers = 8;
3264 network_find_game(void)
3266 // Find out whether or not there is space left on this socket
3270 Network_status = NETSTAT_BROWSING;
3272 num_active_games = 0;
3274 show_boxed_message(TXT_WAIT);
3276 network_send_game_list_request();
3277 t1 = timer_get_approx_seconds() + F1_0*3;
3279 while (timer_get_approx_seconds() < t1) // Wait 3 seconds for replies
3282 clear_boxed_message();
3284 // mprintf((0, "%s %d %s\n", TXT_FOUND, num_active_games, TXT_ACTIVE_GAMES));
3286 if (num_active_games < MAX_ACTIVE_NETGAMES)
3291 void network_read_sync_packet( netgame_info * sp, int rsinit)
3294 netgame_info tmp_info;
3298 char temp_callsign[CALLSIGN_LEN+1];
3301 if ( (Network_game_type == IPX_GAME) && (sp != &Netgame) ) { // for macintosh -- get the values unpacked to our structure format
3302 receive_netgame_packet((ubyte *)sp, &tmp_info, 0);
3308 TempPlayersInfo=&NetPlayers;
3310 // This function is now called by all people entering the netgame.
3312 // mprintf( (0, "%s %d\n", TXT_STARTING_NETGAME, sp->levelnum ));
3316 memcpy( &Netgame, sp, sizeof(netgame_info) );
3317 memcpy (&NetPlayers,TempPlayersInfo,sizeof (AllNetPlayers_info));
3320 N_players = sp->numplayers;
3321 Difficulty_level = sp->difficulty;
3322 Network_status = sp->game_status;
3324 //Assert(Function_mode != FMODE_GAME);
3328 mprintf((1, "Netgame.checksum = %d, calculated checksum = %d.\n", Netgame.segments_checksum, my_segments_checksum));
3330 if (Netgame.segments_checksum != my_segments_checksum)
3332 Network_status = NETSTAT_MENU;
3333 nm_messagebox(TXT_ERROR, 1, TXT_OK, TXT_NETLEVEL_NMATCH);
3339 // Discover my player number
3341 memcpy(temp_callsign, Players[Player_num].callsign, CALLSIGN_LEN+1);
3345 for (i=0; i<MAX_NUM_NET_PLAYERS; i++ ) {
3346 Players[i].net_kills_total = 0;
3347 // Players[i].net_killed_total = 0;
3350 for (i=0; i<N_players; i++ ) {
3351 if (Network_game_type == IPX_GAME) {
3352 if ( (!memcmp( TempPlayersInfo->players[i].network.ipx.node, My_Seq.player.network.ipx.node, 6 )) && (!stricmp( TempPlayersInfo->players[i].callsign, temp_callsign)) ) {
3353 if (Player_num!=-1) {
3354 Int3(); // Hey, we've found ourselves twice
3355 mprintf ((0,"Hey, we've found ourselves twice!\n"));
3356 Network_status = NETSTAT_MENU;
3359 change_playernum_to(i);
3362 if ( (TempPlayersInfo->players[i].network.appletalk.node == My_Seq.player.network.appletalk.node) && (!stricmp( TempPlayersInfo->players[i].callsign, temp_callsign)) ) {
3363 if (Player_num!=-1) {
3364 Int3(); // Hey, we've found ourselves twice
3365 Network_status = NETSTAT_MENU;
3368 change_playernum_to(i);
3371 memcpy( Players[i].callsign, TempPlayersInfo->players[i].callsign, CALLSIGN_LEN+1 );
3373 if (Network_game_type == IPX_GAME) {
3374 if ( (*(uint *)TempPlayersInfo->players[i].network.ipx.server) != 0 )
3375 ipx_get_local_target( TempPlayersInfo->players[i].network.ipx.server, TempPlayersInfo->players[i].network.ipx.node, Players[i].net_address );
3377 memcpy( Players[i].net_address, TempPlayersInfo->players[i].network.ipx.node, 6 );
3380 Players[i].n_packets_got=0; // How many packets we got from them
3381 Players[i].n_packets_sent=0; // How many packets we sent to them
3382 Players[i].connected = TempPlayersInfo->players[i].connected;
3383 Players[i].net_kills_total = sp->player_kills[i];
3384 Players[i].net_killed_total = sp->killed[i];
3385 if ((Network_rejoined) || (i != Player_num))
3386 Players[i].score = sp->player_score[i];
3387 for (j = 0; j < MAX_NUM_NET_PLAYERS; j++)
3389 kill_matrix[i][j] = sp->kills[i][j];
3393 if ( Player_num < 0 ) {
3394 mprintf ((0,"Bad Player_num, resetting to NETSTAT_MENU!\n"));
3395 Network_status = NETSTAT_MENU;
3399 if (Network_rejoined)
3400 for (i=0; i<N_players;i++)
3401 Players[i].net_killed_total = sp->killed[i];
3403 if (Network_rejoined) {
3404 network_process_monitor_vector(sp->monitor_vector);
3405 Players[Player_num].time_level = sp->level_time;
3408 team_kills[0] = sp->team_kills[0];
3409 team_kills[1] = sp->team_kills[1];
3411 Players[Player_num].connected = 1;
3412 NetPlayers.players[Player_num].connected = 1;
3413 NetPlayers.players[Player_num].rank=GetMyNetRanking();
3415 if (!Network_rejoined)
3416 for (i=0; i<NumNetPlayerPositions; i++) {
3417 Objects[Players[i].objnum].pos = Player_init[Netgame.locations[i]].pos;
3418 Objects[Players[i].objnum].orient = Player_init[Netgame.locations[i]].orient;
3419 obj_relink(Players[i].objnum,Player_init[Netgame.locations[i]].segnum);
3422 Objects[Players[Player_num].objnum].type = OBJ_PLAYER;
3424 mprintf ((0,"Changing to NETSTAT_PLAYING!\n"));
3425 Network_status = NETSTAT_PLAYING;
3426 Function_mode = FMODE_GAME;
3427 multi_sort_kill_list();
3432 network_send_sync(void)
3436 // Randomize their starting locations...
3438 d_srand( timer_get_fixed_seconds() );
3439 for (i=0; i<NumNetPlayerPositions; i++ )
3441 if (Players[i].connected)
3442 Players[i].connected = 1; // Get rid of endlevel connect statuses
3443 if (Game_mode & GM_MULTI_COOP)
3444 Netgame.locations[i] = i;
3448 np = d_rand() % NumNetPlayerPositions;
3449 for (j=0; j<i; j++ )
3451 if (Netgame.locations[j]==np)
3458 // np is a location that is not used anywhere else..
3459 Netgame.locations[i]=np;
3460 // mprintf((0, "Player %d starting in location %d\n" ,i ,np ));
3464 // Push current data into the sync packet
3466 network_update_netgame();
3467 Netgame.game_status = NETSTAT_PLAYING;
3468 Netgame.type = PID_SYNC;
3469 Netgame.segments_checksum = my_segments_checksum;
3471 for (i=0; i<N_players; i++ ) {
3472 if ((!Players[i].connected) || (i == Player_num))
3475 if (Network_game_type == IPX_GAME) {
3476 // Send several times, extras will be ignored
3478 ipx_send_internetwork_packet_data( (ubyte *)&Netgame, sizeof(netgame_info), NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node);
3479 ipx_send_internetwork_packet_data( (ubyte *)&NetPlayers, sizeof(AllNetPlayers_info), NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node);
3481 send_netgame_packet(NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node, NULL, 0);
3482 send_netplayers_packet(NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node);
3486 appletalk_send_packet_data( (ubyte *)&Netgame, sizeof(netgame_info), NetPlayers.players[i].network.appletalk.node,
3487 NetPlayers.players[i].network.appletalk.net,
3488 NetPlayers.players[i].network.appletalk.socket);
3489 appletalk_send_packet_data( (ubyte *)&NetPlayers, sizeof(AllNetPlayers_info), NetPlayers.players[i].network.appletalk.node,
3490 NetPlayers.players[i].network.appletalk.net,
3491 NetPlayers.players[i].network.appletalk.socket);
3496 network_read_sync_packet(&Netgame,1); // Read it myself, as if I had sent it
3500 network_select_teams(void)
3503 newmenu_item m[MAX_PLAYERS+4];
3504 int choice, opt, opt_team_b;
3505 ubyte team_vector = 0;
3506 char team_names[2][CALLSIGN_LEN+1];
3508 int pnums[MAX_PLAYERS+2];
3510 // One-time initialization
3512 for (i = N_players/2; i < N_players; i++) // Put first half of players on team A
3514 team_vector |= (1 << i);
3517 sprintf(team_names[0], "%s", TXT_BLUE);
3518 sprintf(team_names[1], "%s", TXT_RED);
3520 // Here comes da menu
3522 m[0].type = NM_TYPE_INPUT; m[0].text = team_names[0]; m[0].text_len = CALLSIGN_LEN;
3525 for (i = 0; i < N_players; i++)
3527 if (!(team_vector & (1 << i)))
3529 m[opt].type = NM_TYPE_MENU; m[opt].text = NetPlayers.players[i].callsign; pnums[opt] = i; opt++;
3533 m[opt].type = NM_TYPE_INPUT; m[opt].text = team_names[1]; m[opt].text_len = CALLSIGN_LEN; opt++;
3534 for (i = 0; i < N_players; i++)
3536 if (team_vector & (1 << i))
3538 m[opt].type = NM_TYPE_MENU; m[opt].text = NetPlayers.players[i].callsign; pnums[opt] = i; opt++;
3541 m[opt].type = NM_TYPE_TEXT; m[opt].text = ""; opt++;
3542 m[opt].type = NM_TYPE_MENU; m[opt].text = TXT_ACCEPT; opt++;
3544 Assert(opt <= MAX_PLAYERS+4);
3546 choice = newmenu_do(NULL, TXT_TEAM_SELECTION, opt, m, NULL);
3548 if (choice == opt-1)
3550 if ((opt-2-opt_team_b < 2) || (opt_team_b == 1))
3552 nm_messagebox(NULL, 1, TXT_OK, TXT_TEAM_MUST_ONE);
3558 Netgame.team_vector = team_vector;
3559 strcpy(Netgame.team_name[0], team_names[0]);
3560 strcpy(Netgame.team_name[1], team_names[1]);
3564 else if ((choice > 0) && (choice < opt_team_b)) {
3565 team_vector |= (1 << pnums[choice]);
3567 else if ((choice > opt_team_b) && (choice < opt-2)) {
3568 team_vector &= ~(1 << pnums[choice]);
3570 else if (choice == -1)
3579 network_select_players(void)
3582 newmenu_item m[MAX_PLAYERS+4];
3583 char text[MAX_PLAYERS+4][45];
3585 int save_nplayers; //how may people would like to join
3587 network_add_player( &My_Seq );
3589 for (i=0; i< MAX_PLAYERS+4; i++ ) {
3590 sprintf( text[i], "%d. %-20s", i+1, "" );
3591 m[i].type = NM_TYPE_CHECK; m[i].text = text[i]; m[i].value = 0;
3594 m[0].value = 1; // Assume server will play...
3596 if (FindArg("-norankings"))
3597 sprintf( text[0], "%d. %-20s", 1, Players[Player_num].callsign );
3599 sprintf( text[0], "%d. %s%-20s", 1, RankStrings[NetPlayers.players[Player_num].rank],Players[Player_num].callsign );
3601 sprintf( title, "%s %d %s", TXT_TEAM_SELECT, MaxNumNetPlayers, TXT_TEAM_PRESS_ENTER );
3604 ExtGameStatus=GAMESTAT_NETGAME_PLAYER_SELECT;
3605 j=newmenu_do1( NULL, title, MAX_PLAYERS+4, m, network_start_poll, 1 );
3607 save_nplayers = N_players;
3612 // Dump all players and go back to menu mode
3615 for (i=1; i<save_nplayers; i++) {
3616 if (Network_game_type == IPX_GAME)
3617 network_dump_player(NetPlayers.players[i].network.ipx.server,NetPlayers.players[i].network.ipx.node, DUMP_ABORTED);
3620 network_dump_appletalk_player(NetPlayers.players[i].network.appletalk.node,NetPlayers.players[i].network.appletalk.net, NetPlayers.players[i].network.appletalk.socket, DUMP_ABORTED);
3625 Netgame.numplayers = 0;
3626 network_send_game_info(0); // Tell everyone we're bailing
3628 Network_status = NETSTAT_MENU;
3632 // Count number of players chosen
3635 for (i=0; i<save_nplayers; i++ )
3641 if ( N_players > Netgame.max_numplayers) {
3643 nm_messagebox( TXT_ERROR, 1, TXT_OK, "%s %d %s", TXT_SORRY_ONLY, MaxNumNetPlayers, TXT_NETPLAYERS_IN );
3645 nm_messagebox( TXT_ERROR, 1, TXT_OK, "%s %d netplayers for this game.", TXT_SORRY_ONLY, MaxNumNetPlayers );
3647 N_players = save_nplayers;
3648 goto GetPlayersAgain;
3652 if ( N_players < 2 ) {
3653 nm_messagebox( TXT_ERROR, 1, TXT_OK, TXT_TEAM_ATLEAST_TWO );
3654 N_players = save_nplayers;
3655 goto GetPlayersAgain;
3660 if ( (Netgame.gamemode == NETGAME_TEAM_ANARCHY ||
3661 Netgame.gamemode == NETGAME_CAPTURE_FLAG || Netgame.gamemode == NETGAME_TEAM_HOARD) && (N_players < 2) ) {
3662 nm_messagebox(TXT_ERROR, 1, TXT_OK, "You must select at least two\nplayers to start a team game" );
3663 N_players = save_nplayers;
3664 goto GetPlayersAgain;
3668 // Remove players that aren't marked.
3670 for (i=0; i<save_nplayers; i++ ) {
3675 if (Network_game_type == IPX_GAME) {
3676 memcpy(NetPlayers.players[N_players].network.ipx.node, NetPlayers.players[i].network.ipx.node, 6);
3677 memcpy(NetPlayers.players[N_players].network.ipx.server, NetPlayers.players[i].network.ipx.server, 4);
3679 NetPlayers.players[N_players].network.appletalk.node = NetPlayers.players[i].network.appletalk.node;
3680 NetPlayers.players[N_players].network.appletalk.net = NetPlayers.players[i].network.appletalk.net;
3681 NetPlayers.players[N_players].network.appletalk.socket = NetPlayers.players[i].network.appletalk.socket;
3683 memcpy(NetPlayers.players[N_players].callsign, NetPlayers.players[i].callsign, CALLSIGN_LEN+1);
3684 NetPlayers.players[N_players].version_major=NetPlayers.players[i].version_major;
3685 NetPlayers.players[N_players].version_minor=NetPlayers.players[i].version_minor;
3686 NetPlayers.players[N_players].rank=NetPlayers.players[i].rank;
3687 ClipRank (&NetPlayers.players[N_players].rank);
3688 network_check_for_old_version(i);
3690 Players[N_players].connected = 1;
3695 if (Network_game_type == IPX_GAME)
3696 network_dump_player(NetPlayers.players[i].network.ipx.server,NetPlayers.players[i].network.ipx.node, DUMP_DORK);
3699 network_dump_appletalk_player(NetPlayers.players[i].network.appletalk.node,NetPlayers.players[i].network.appletalk.net, NetPlayers.players[i].network.appletalk.socket, DUMP_DORK);
3704 for (i = N_players; i < MAX_NUM_NET_PLAYERS; i++) {
3705 if (Network_game_type == IPX_GAME) {
3706 memset(NetPlayers.players[i].network.ipx.node, 0, 6);
3707 memset(NetPlayers.players[i].network.ipx.server, 0, 4);
3709 NetPlayers.players[i].network.appletalk.node = 0;
3710 NetPlayers.players[i].network.appletalk.net = 0;
3711 NetPlayers.players[i].network.appletalk.socket = 0;
3713 memset(NetPlayers.players[i].callsign, 0, CALLSIGN_LEN+1);
3714 NetPlayers.players[i].version_major=0;
3715 NetPlayers.players[i].version_minor=0;
3716 NetPlayers.players[i].rank=0;
3719 mprintf ((0,"Select teams: Game mode is %d\n",Netgame.gamemode));
3721 if (Netgame.gamemode == NETGAME_TEAM_ANARCHY ||
3722 Netgame.gamemode == NETGAME_CAPTURE_FLAG ||
3723 Netgame.gamemode == NETGAME_TEAM_HOARD)
3724 if (!network_select_teams())
3731 network_start_game()
3734 char game_name[NETGAME_NAME_LEN+1];
3735 int chosen_game_mode, game_flags, level;
3737 if (Network_game_type == IPX_GAME) {
3739 Assert( FRAME_INFO_SIZE < IPX_MAX_DATA_SIZE );
3740 mprintf((0, "Using frame_info len %d, max %d.\n", FRAME_INFO_SIZE, IPX_MAX_DATA_SIZE));
3742 if ( !Network_active )
3744 nm_messagebox(NULL, 1, TXT_OK, TXT_IPX_NOT_FOUND );
3752 Assert( FRAME_INFO_SIZE < APPLETALK_MAX_DATA_SIZE );
3753 mprintf((0, "Using frame_info len %d, max %d.\n", sizeof(frame_info), APPLETALK_MAX_DATA_SIZE));
3754 if (Appletalk_active <= 0) {
3755 switch (Appletalk_active) {
3756 case APPLETALK_NOT_OPEN:
3757 sprintf(buf, "Appletalk is not currently active.\nPlease enable AppleTalk from the\nChooser and restart Descent.");
3759 case APPLETALK_BAD_LISTENER:
3760 sprintf(buf, "The Resource Fork of Descent appears damaged.\nPlease re-install Descent or contact\nMacPlay technical support.");
3762 case APPLETALK_NO_LOCAL_ADDR:
3763 sprintf(buf, "Wow! Strange!\n\nNo Local Address.");
3765 case APPLETALK_NO_SOCKET:
3766 sprintf(buf, "All AppleTalk sockets are in use.\nTry shutting down other network\napplications and restarting Descent.\n");
3769 nm_messagebox(NULL, 1, TXT_OK, buf);
3772 strcpy(Network_zone_name, DEFAULT_ZONE_NAME);
3777 change_playernum_to(0);
3779 if (network_find_game())
3781 nm_messagebox(NULL, 1, TXT_OK, TXT_NET_FULL);
3786 i = network_get_game_params( game_name, &chosen_game_mode, &game_flags, &level );
3792 // LoadLevel(level); Old, no longer used.
3794 Netgame.difficulty = Difficulty_level;
3795 Netgame.gamemode = chosen_game_mode;
3796 Netgame.game_status = NETSTAT_STARTING;
3797 Netgame.numplayers = 0;
3798 Netgame.max_numplayers = MaxNumNetPlayers;
3799 Netgame.levelnum = level;
3800 Netgame.protocol_version = MULTI_PROTO_VERSION;
3802 strcpy(Netgame.game_name, game_name);
3804 Network_status = NETSTAT_STARTING;
3807 if (Network_game_type == APPLETALK_GAME) {
3812 show_boxed_message("Registering Netgame");
3814 err = appletalk_register_netgame( game_name, TickCount() );
3815 t1 = timer_get_fixed_seconds() + F1_0;
3816 while (timer_get_fixed_seconds() < t1) ;
3818 } while ( (err == nbpDuplicate) && (count != MAX_REGISTER_TRIES) );
3819 clear_boxed_message();
3820 if ( (err == tooManyReqs) || (count == MAX_REGISTER_TRIES) ) {
3821 nm_messagebox(NULL, 1, TXT_OK, "AppleTalk Network is too busy.\nPlease try again shortly.");
3822 Game_mode = GM_GAME_OVER;
3828 network_set_game_mode(Netgame.gamemode);
3830 d_srand( timer_get_fixed_seconds() );
3831 Netgame.Security=d_rand(); // For syncing Netgames with player packets
3833 if(network_select_players())
3835 StartNewLevel(Netgame.levelnum, 0);
3838 Game_mode = GM_GAME_OVER;
3842 void restart_net_searching(newmenu_item * m)
3846 num_active_games = 0;
3848 memset(Active_games, 0, sizeof(netgame_info)*MAX_ACTIVE_NETGAMES);
3850 for (i = 0; i < MAX_ACTIVE_NETGAMES; i++)
3852 sprintf(m[i+2].text, "%d. ",i+1);
3856 NamesInfoSecurity=-1;
3857 Network_games_changed = 1;
3860 char *ModeLetters[]={"ANRCHY","TEAM","ROBO","COOP","FLAG","HOARD","TMHOARD"};
3862 int NumActiveNetgames=0;
3864 void network_join_poll( int nitems, newmenu_item * menus, int * key, int citem )
3866 // Polling loop for Join Game menu
3868 int i, osocket,join_status,temp;
3875 if ( (Network_game_type == IPX_GAME) && Network_allow_socket_changes ) {
3876 osocket = Network_socket;
3878 if ( *key==KEY_PAGEDOWN ) { Network_socket--; *key = 0; }
3879 if ( *key==KEY_PAGEUP ) { Network_socket++; *key = 0; }
3881 if (Network_socket>99)
3883 if (Network_socket<-99)
3886 if ( Network_socket+IPX_DEFAULT_SOCKET > 0x8000 )
3887 Network_socket = 0x8000 - IPX_DEFAULT_SOCKET;
3889 if ( Network_socket+IPX_DEFAULT_SOCKET < 0 )
3890 Network_socket = IPX_DEFAULT_SOCKET;
3892 if (Network_socket != osocket ) {
3893 sprintf( menus[0].text, "\t%s %+d (PgUp/PgDn to change)", TXT_CURRENT_IPX_SOCKET, Network_socket );
3894 menus[0].redraw = 1;
3895 mprintf(( 0, "Changing to socket %d\n", Network_socket ));
3897 mprintf ((0,"netgood 1!\n"));
3898 ipx_change_default_socket( IPX_DEFAULT_SOCKET + Network_socket );
3899 mprintf ((0,"netgood 2!\n"));
3900 restart_net_searching(menus);
3901 mprintf ((0,"netgood 3!\n"));
3902 network_send_game_list_request();
3903 mprintf ((0,"netgood 4!\n"));
3908 // send a request for game info every 3 seconds
3910 if (Network_game_type == IPX_GAME) {
3911 if (timer_get_approx_seconds() > t1+F1_0*3) {
3912 t1 = timer_get_approx_seconds();
3913 network_send_game_list_request();
3916 } else if (timer_get_approx_seconds() > t1+F1_0*20) {
3918 t1 = timer_get_approx_seconds();
3919 restart_net_searching(menus);
3920 show_boxed_message("Requesting list of Netgames");
3921 network_send_game_list_request();
3922 clear_boxed_message();
3927 temp=num_active_games;
3931 NumActiveNetgames=num_active_games;
3933 if (!Network_games_changed)
3936 if (temp!=num_active_games)
3937 digi_play_sample (SOUND_HUD_MESSAGE,F1_0);
3939 Network_games_changed = 0;
3940 mprintf ((0,"JOIN POLL: I'm looking at %d games!\n",num_active_games));
3942 // Copy the active games data into the menu options
3943 for (i = 0; i < num_active_games; i++)
3945 int game_status = Active_games[i].game_status;
3946 int j,x, k,tx,ty,ta,nplayers = 0;
3947 char levelname[8],MissName[25],GameName[25],thold[2];
3950 // These next two loops protect against menu skewing
3951 // if missiontitle or gamename contain a tab
3953 for (x=0,tx=0,k=0,j=0;j<15;j++)
3955 if (Active_games[i].mission_title[j]=='\t')
3957 thold[0]=Active_games[i].mission_title[j];
3958 gr_get_string_size (thold,&tx,&ty,&ta);
3960 if ((x+=tx)>=LHX(55))
3962 MissName[k]=MissName[k+1]=MissName[k+2]='.';
3967 MissName[k++]=Active_games[i].mission_title[j];
3971 for (x=0,tx=0,k=0,j=0;j<15;j++)
3973 if (Active_games[i].game_name[j]=='\t')
3975 thold[0]=Active_games[i].game_name[j];
3976 gr_get_string_size (thold,&tx,&ty,&ta);
3978 if ((x+=tx)>=LHX(55))
3980 GameName[k]=GameName[k+1]=GameName[k+2]='.';
3984 GameName[k++]=Active_games[i].game_name[j];
3989 nplayers=Active_games[i].numconnected;
3991 if (Active_games[i].levelnum < 0)
3992 sprintf(levelname, "S%d", -Active_games[i].levelnum);
3994 sprintf(levelname, "%d", Active_games[i].levelnum);
3996 if (game_status == NETSTAT_STARTING)
3998 sprintf (menus[i+2].text,"%d.\t%s \t%s \t %d/%d \t%s \t %s \t%s",
3999 i+1,GameName,ModeLetters[Active_games[i].gamemode],nplayers,
4000 Active_games[i].max_numplayers,MissName,levelname,"Forming");
4002 else if (game_status == NETSTAT_PLAYING)
4004 join_status=can_join_netgame(&Active_games[i],NULL);
4005 // mprintf ((0,"Joinstatus=%d\n",join_status));
4008 sprintf (menus[i+2].text,"%d.\t%s \t%s \t %d/%d \t%s \t %s \t%s",
4009 i+1,GameName,ModeLetters[Active_games[i].gamemode],nplayers,
4010 Active_games[i].max_numplayers,MissName,levelname,"Open");
4011 else if (join_status==2)
4012 sprintf (menus[i+2].text,"%d.\t%s \t%s \t %d/%d \t%s \t %s \t%s",
4013 i+1,GameName,ModeLetters[Active_games[i].gamemode],nplayers,
4014 Active_games[i].max_numplayers,MissName,levelname,"Full");
4015 else if (join_status==3)
4016 sprintf (menus[i+2].text,"%d.\t%s \t%s \t %d/%d \t%s \t %s \t%s",
4017 i+1,GameName,ModeLetters[Active_games[i].gamemode],nplayers,
4018 Active_games[i].max_numplayers,MissName,levelname,"Restrict");
4020 sprintf (menus[i+2].text,"%d.\t%s \t%s \t %d/%d \t%s \t %s \t%s",
4021 i+1,GameName,ModeLetters[Active_games[i].gamemode],nplayers,
4022 Active_games[i].max_numplayers,MissName,levelname,"Closed");
4026 sprintf (menus[i+2].text,"%d.\t%s \t%s \t %d/%d \t%s \t %s \t%s",
4027 i+1,GameName,ModeLetters[Active_games[i].gamemode],nplayers,
4028 Active_games[i].max_numplayers,MissName,levelname,"Between");
4031 Assert(strlen(menus[i+2].text) < 100);
4032 menus[i+2].redraw = 1;
4035 for (i = num_active_games; i < MAX_ACTIVE_NETGAMES; i++)
4037 sprintf(menus[i+2].text, "%d. ",i+1);
4038 menus[i+2].redraw = 1;
4043 network_wait_for_sync(void)
4049 Network_status = NETSTAT_WAITING;
4051 m[0].type=NM_TYPE_TEXT; m[0].text = text;
4052 m[1].type=NM_TYPE_TEXT; m[1].text = TXT_NET_LEAVE;
4054 i = network_send_request();
4059 sprintf( m[0].text, "%s\n'%s' %s", TXT_NET_WAITING, NetPlayers.players[i].callsign, TXT_NET_TO_ENTER );
4062 choice=newmenu_do( NULL, TXT_WAIT, 2, m, network_sync_poll );
4067 if (Network_status != NETSTAT_PLAYING)
4071 // if (Network_status == NETSTAT_ENDLEVEL)
4073 // network_send_endlevel_packet(0);
4074 // longjmp(LeaveGame, 0);
4077 mprintf((0, "Aborting join.\n"));
4078 me.type = PID_QUIT_JOINING;
4079 memcpy( me.player.callsign, Players[Player_num].callsign, CALLSIGN_LEN+1 );
4080 if (Network_game_type == IPX_GAME) {
4081 memcpy( me.player.network.ipx.node, ipx_get_my_local_address(), 6 );
4082 memcpy( me.player.network.ipx.server, ipx_get_my_server_address(), 4 );
4084 ipx_send_internetwork_packet_data( (ubyte *)&me, sizeof(sequence_packet), NetPlayers.players[0].network.ipx.server, NetPlayers.players[0].network.ipx.node );
4086 send_sequence_packet(me, NetPlayers.players[0].network.ipx.server, NetPlayers.players[0].network.ipx.node, NULL);
4090 me.player.network.appletalk.node = appletalk_get_my_node();
4091 me.player.network.appletalk.net = appletalk_get_my_net();
4092 me.player.network.appletalk.socket = appletalk_get_my_socket();
4096 Function_mode = FMODE_MENU;
4097 Game_mode = GM_GAME_OVER;
4098 return(-1); // they cancelled
4104 network_request_poll( int nitems, newmenu_item * menus, int * key, int citem )
4106 // Polling loop for waiting-for-requests menu
4116 // Send our endlevel packet at regular intervals
4118 // if (timer_get_approx_seconds() > t1+ENDLEVEL_SEND_INTERVAL)
4120 // network_send_endlevel_packet();
4121 // t1 = timer_get_approx_seconds();
4126 for (i = 0; i < N_players; i++)
4128 if ((Players[i].connected == 1) || (Players[i].connected == 0))
4132 if (num_ready == N_players) // All players have checked in or are disconnected
4139 network_wait_for_requests(void)
4141 // Wait for other players to load the level before we send the sync
4145 Network_status = NETSTAT_WAITING;
4147 m[0].type=NM_TYPE_TEXT; m[0].text = TXT_NET_LEAVE;
4149 mprintf((0, "Entered wait_for_requests : N_players = %d.\n", N_players));
4151 for (choice = 0; choice < N_players; choice++)
4152 mprintf((0, "Players[%d].connected = %d.\n", choice, Players[choice].connected));
4154 Network_status = NETSTAT_WAITING;
4157 Players[Player_num].connected = 1;
4160 choice = newmenu_do(NULL, TXT_WAIT, 1, m, network_request_poll);
4165 choice = nm_messagebox(NULL, 3, TXT_YES, TXT_NO, TXT_START_NOWAIT, TXT_QUITTING_NOW);
4171 // User confirmed abort
4173 for (i=0; i < N_players; i++) {
4174 if ((Players[i].connected != 0) && (i != Player_num)) {
4175 if (Network_game_type == IPX_GAME)
4176 network_dump_player(NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node, DUMP_ABORTED);
4179 network_dump_appletalk_player(NetPlayers.players[i].network.appletalk.node, NetPlayers.players[i].network.appletalk.net, NetPlayers.players[i].network.appletalk.socket, DUMP_ABORTED);
4185 if (Network_game_type == APPLETALK_GAME)
4186 network_release_registered_game();
4188 longjmp(LeaveGame, 0);
4190 else if (choice != -2)
4195 network_level_sync(void)
4197 // Do required syncing between (before) levels
4201 mprintf((0, "Player %d entering network_level_sync.\n", Player_num));
4203 MySyncPackInitialized = 0;
4205 // my_segments_checksum = netmisc_calc_checksum(Segments, sizeof(segment)*(Highest_segment_index+1));
4207 network_flush(); // Flush any old packets
4210 result = network_wait_for_sync();
4211 else if (network_i_am_master())
4213 network_wait_for_requests();
4214 network_send_sync();
4218 result = network_wait_for_sync();
4220 network_count_powerups_in_mine();
4224 Players[Player_num].connected = 0;
4225 network_send_endlevel_packet();
4227 if (Network_game_type == APPLETALK_GAME)
4228 network_release_registered_game();
4230 longjmp(LeaveGame, 0);
4235 void network_count_powerups_in_mine(void)
4239 for (i=0;i<MAX_POWERUP_TYPES;i++)
4240 PowerupsInMine[i]=0;
4242 for (i=0;i<=Highest_object_index;i++)
4244 if (Objects[i].type==OBJ_POWERUP)
4246 PowerupsInMine[Objects[i].id]++;
4247 if (multi_powerup_is_4pack(Objects[i].id))
4248 PowerupsInMine[Objects[i].id-1]+=4;
4256 // code to release the NBP binding of an appletalk game
4258 void network_release_registered_game()
4260 if (Network_game_type == APPLETALK_GAME)
4261 appletalk_remove_netgame();
4264 // code to sort zone lists....
4266 int zone_sort_func(const char **e0, const char **e1)
4268 return strcmp(*e0, *e1);
4271 void network_get_appletalk_zone()
4273 int num_zones, i, item, default_item;
4275 char default_zone[MAX_ZONE_LENGTH]; // my zone
4277 Network_zone_name[0] = '\0';
4279 show_boxed_message("Looking for AppleTalk Zones");
4280 num_zones = appletalk_get_zone_names(&zone_list);
4281 clear_boxed_message();
4283 if (num_zones < 0) { // error in getting zone list...maybe no router available....
4284 if ( (num_zones == tooManyReqs) || (num_zones == noDataArea) ){
4285 nm_messagebox(NULL, 1, TXT_OK, "AppleTalk Network is too busy.\nPlease try again shortly.");
4286 longjmp(LeaveGame,0);
4291 if (num_zones == 0) {
4292 strcpy(Network_zone_name, DEFAULT_ZONE_NAME);
4296 if (num_zones == 1) {
4297 Network_zone_name[0] = (char)(strlen(zone_list[0]));
4298 memcpy( &(Network_zone_name[1]), zone_list[0], strlen(zone_list[0]) );
4302 // sort the zone names
4304 for (i = 0; i < num_zones; i++)
4305 strlwr(zone_list[i]);
4307 qsort(zone_list, num_zones, sizeof(char *), zone_sort_func);
4309 // get my current zone so we can highlight that one first
4311 if (appletalk_get_my_zone(default_zone))
4314 for (i = 0; i < num_zones; i++) {
4315 if ( !stricmp(zone_list[i], default_zone) ) {
4323 item = newmenu_listbox1("AppleTalk Zones", num_zones, zone_list, 0, default_item, NULL);
4328 Network_zone_name[0] = (char)(strlen(zone_list[item]));
4329 memcpy( &(Network_zone_name[1]), zone_list[item], strlen(zone_list[item]) );
4332 for (i = 0; i < num_zones; i++)
4333 d_free(zone_list[i]);
4338 void nm_draw_background1(char * filename);
4340 //moved 2000/02/07 Matt Mueller - clipped stuff from network_join_game into new network_do_join_game to allow easy joining from other funcs too.
4341 int network_do_join_game(netgame_info *jgame, AllNetPlayers_info *jplayers){
4342 if (jgame->game_status == NETSTAT_ENDLEVEL)
4344 nm_messagebox(TXT_SORRY, 1, TXT_OK, TXT_NET_GAME_BETWEEN2);
4348 if ((jgame->protocol_version != MULTI_PROTO_VERSION) &&
4349 (jgame->protocol_version != MULTI_PROTO_DXX_VER))
4351 nm_messagebox(TXT_SORRY, 1, TXT_OK, TXT_VERSION_MISMATCH);
4355 if (jgame->protocol_version == MULTI_PROTO_DXX_VER &&
4356 jgame->required_subprotocol > MULTI_PROTO_DXX_MINOR)
4358 nm_messagebox(TXT_SORRY, 1, TXT_OK, "This game uses features\nnot present in this version.");
4362 // Check for valid mission name
4363 mprintf((0, "Loading mission:%s.\n", jgame->mission_name));
4364 if (!load_mission_by_name(jgame->mission_name))
4366 nm_messagebox(NULL, 1, TXT_OK, TXT_MISSION_NOT_FOUND);
4368 //add getlevel functionality here - Victor Rachels
4375 if (!can_join_netgame(jgame, jplayers))
4377 if (jgame->numplayers == jgame->max_numplayers)
4378 nm_messagebox(TXT_SORRY, 1, TXT_OK, TXT_GAME_FULL);
4380 nm_messagebox(TXT_SORRY, 1, TXT_OK, TXT_IN_PROGRESS);
4384 // Choice is valid, prepare to join in
4386 memcpy(&Netgame, jgame, sizeof(netgame_info));
4388 Difficulty_level = Netgame.difficulty;
4389 MaxNumNetPlayers = Netgame.max_numplayers;
4390 change_playernum_to(1);
4392 network_set_game_mode(Netgame.gamemode);
4394 StartNewLevel(Netgame.levelnum, 0);
4396 return 1; // look ma, we're in a game!!!
4399 void network_join_game()
4402 char menu_text[MAX_ACTIVE_NETGAMES+2][200];
4404 newmenu_item m[MAX_ACTIVE_NETGAMES+2];
4406 if (Network_game_type == IPX_GAME) {
4407 if ( !Network_active )
4409 nm_messagebox(NULL, 1, TXT_OK, TXT_IPX_NOT_FOUND);
4413 } else if (Appletalk_active <= 0) {
4416 switch (Appletalk_active) {
4417 case APPLETALK_NOT_OPEN:
4418 sprintf(buf, "Appletalk is not currently active.\nPlease enable AppleTalk from the\nChooser and restart Descent.");
4420 case APPLETALK_BAD_LISTENER:
4421 sprintf(buf, "The Resource Fork of Descent appears damaged.\nPlease re-install Descent or contact\nMacPlay technical support.");
4423 case APPLETALK_NO_LOCAL_ADDR:
4424 sprintf(buf, "Wow! Strange!\n\nNo Local Address.");
4426 case APPLETALK_NO_SOCKET:
4427 sprintf(buf, "All AppleTalk sockets are in use.\nTry shutting down other network\napplications and restarting Descent.\n");
4430 nm_messagebox(NULL, 1, TXT_OK, buf);
4442 if (Network_game_type == APPLETALK_GAME)
4443 network_get_appletalk_zone();
4446 Network_send_objects = 0;
4447 Network_sending_extras=0;
4450 Network_status = NETSTAT_BROWSING; // We are looking at a game menu
4453 network_listen(); // Throw out old info
4456 if (Network_game_type == IPX_GAME)
4457 #endif // note link to if
4458 network_send_game_list_request(); // broadcast a request for lists
4460 num_active_games = 0;
4462 memset(m, 0, sizeof(newmenu_item)*MAX_ACTIVE_NETGAMES);
4463 memset(Active_games, 0, sizeof(netgame_info)*MAX_ACTIVE_NETGAMES);
4464 memset(ActiveNetPlayers,0,sizeof(AllNetPlayers_info)*MAX_ACTIVE_NETGAMES);
4466 gr_set_fontcolor(BM_XRGB(15,15,23),-1);
4468 m[0].text = menu_text[0];
4469 m[0].type = NM_TYPE_TEXT;
4470 if (Network_game_type == IPX_GAME) {
4471 if (Network_allow_socket_changes)
4472 sprintf( m[0].text, "\tCurrent IPX Socket is default %+d (PgUp/PgDn to change)", Network_socket );
4474 strcpy( m[0].text, "" );
4477 p2cstr(Network_zone_name);
4478 if (strcmp(Network_zone_name, "*")) // only print if there is a zone name
4479 sprintf(m[0].text, "\tCurrent Zone is %s", Network_zone_name); // is Network_zone_name a pascal string????
4480 c2pstr(Network_zone_name);
4484 m[1].text=menu_text[1];
4485 m[1].type=NM_TYPE_TEXT;
4486 sprintf (m[1].text,"\tGAME \tMODE \t#PLYRS \tMISSION \tLEV \tSTATUS");
4488 for (i = 0; i < MAX_ACTIVE_NETGAMES; i++) {
4489 m[i+2].text = menu_text[i+2];
4490 m[i+2].type = NM_TYPE_MENU;
4491 sprintf(m[i+2].text, "%d. ", i+1);
4495 Network_games_changed = 1;
4498 nm_draw_background1(Menu_pcx_name); //load this here so if we abort after loading level, we restore the palette
4499 gr_palette_load(gr_palette);
4500 ExtGameStatus=GAMESTAT_JOIN_NETGAME;
4501 choice=newmenu_dotiny("NETGAMES", NULL,MAX_ACTIVE_NETGAMES+2, m, network_join_poll);
4505 Network_status = NETSTAT_MENU;
4506 return; // they cancelled
4510 if (choice >=num_active_games)
4512 nm_messagebox(TXT_SORRY, 1, TXT_OK, TXT_INVALID_CHOICE);
4516 // Choice has been made and looks legit
4517 if (Active_games[choice].game_status == NETSTAT_ENDLEVEL)
4519 nm_messagebox(TXT_SORRY, 1, TXT_OK, TXT_NET_GAME_BETWEEN2);
4523 if (Active_games[choice].protocol_version != MULTI_PROTO_VERSION)
4525 if (Active_games[choice].protocol_version == 3) {
4527 nm_messagebox(TXT_SORRY, 1, TXT_OK, "Your version of Descent 2\nis incompatible with the\nDemo version");
4530 else if (Active_games[choice].protocol_version == 4) {
4532 nm_messagebox(TXT_SORRY, 1, TXT_OK, "This Demo version of\nDescent 2 is incompatible\nwith the full commercial version");
4536 nm_messagebox(TXT_SORRY, 1, TXT_OK, TXT_VERSION_MISMATCH);
4543 // Check for valid mission name
4544 mprintf((0, "Loading mission:%s.\n", Active_games[choice].mission_name));
4545 if (!load_mission_by_name(Active_games[choice].mission_name))
4547 nm_messagebox(NULL, 1, TXT_OK, TXT_MISSION_NOT_FOUND);
4553 #if defined (D2_OEM)
4555 if (Active_games[choice].levelnum>8)
4557 nm_messagebox(NULL, 1, TXT_OK, "This OEM version only supports\nthe first 8 levels!");
4563 if (!network_wait_for_all_info (choice))
4565 nm_messagebox (TXT_SORRY,1,TXT_OK,"There was a join error!");
4566 Network_status = NETSTAT_BROWSING; // We are looking at a game menu
4570 Network_status = NETSTAT_BROWSING; // We are looking at a game menu
4572 if (!can_join_netgame(&Active_games[choice],&ActiveNetPlayers[choice]))
4574 if (Active_games[choice].numplayers == Active_games[choice].max_numplayers)
4575 nm_messagebox(TXT_SORRY, 1, TXT_OK, TXT_GAME_FULL);
4577 nm_messagebox(TXT_SORRY, 1, TXT_OK, TXT_IN_PROGRESS);
4581 // Choice is valid, prepare to join in
4583 memcpy(&Netgame, &Active_games[choice], sizeof(netgame_info));
4584 memcpy (&NetPlayers,&ActiveNetPlayers[choice],sizeof(AllNetPlayers_info));
4586 Difficulty_level = Netgame.difficulty;
4587 MaxNumNetPlayers = Netgame.max_numplayers;
4588 change_playernum_to(1);
4592 // register the joining player with NBP. This will have the nice effect of a player wanting to
4593 // join to be able to see the netgame if this player were to become the master.
4595 if (Network_game_type == APPLETALK_GAME) {
4600 show_boxed_message("Registering Netgame");
4602 err = appletalk_register_netgame( Active_games[choice].game_name, TickCount() );
4603 t1 = timer_get_fixed_seconds() + F1_0;
4604 while ( timer_get_fixed_seconds() < t1 ) ;
4606 } while ( (err == nbpDuplicate) && (count != MAX_REGISTER_TRIES) );
4607 clear_boxed_message();
4608 if ( (err == tooManyReqs) || (count == MAX_REGISTER_TRIES) ) {
4609 nm_messagebox(NULL, 1, TXT_OK, "AppleTalk Network is too busy.\nPlease try again shortly.");
4615 network_set_game_mode(Netgame.gamemode);
4617 network_AdjustMaxDataSize ();
4619 StartNewLevel(Netgame.levelnum, 0);
4621 return; // look ma, we're in a game!!!
4624 void network_AdjustMaxDataSize ()
4627 if (Netgame.ShortPackets)
4628 MaxXDataSize=NET_XDATA_SIZE;
4630 MaxXDataSize=NET_XDATA_SIZE;
4634 fix StartWaitAllTime=0;
4635 int WaitAllChoice=0;
4636 #define ALL_INFO_REQUEST_INTERVAL F1_0*3
4638 void network_wait_all_poll( int nitems, newmenu_item * menus, int * key, int citem )
4646 if (timer_get_approx_seconds() > t1+ALL_INFO_REQUEST_INTERVAL)
4648 network_send_all_info_request(PID_SEND_ALL_GAMEINFO,SecurityCheck);
4649 t1 = timer_get_approx_seconds();
4652 network_do_big_wait(WaitAllChoice);
4654 if(SecurityCheck==-1)
4658 int network_wait_for_all_info (int choice)
4664 m[0].type=NM_TYPE_TEXT; m[0].text = "Press Escape to cancel";
4666 WaitAllChoice=choice;
4667 StartWaitAllTime=timer_get_approx_seconds();
4668 SecurityCheck=Active_games[choice].Security;
4672 pick=newmenu_do( NULL, "Connecting...", 1, m, network_wait_all_poll );
4674 if (pick>-1 && SecurityCheck!=-1)
4677 if (SecurityCheck==-1)
4686 void network_do_big_wait(int choice)
4689 ubyte packet[IPX_MAX_DATA_SIZE],*data;
4690 AllNetPlayers_info *temp_info;
4692 AllNetPlayers_info info_struct;
4693 ubyte apacket[APPLETALK_MAX_DATA_SIZE];
4697 if (Network_game_type == APPLETALK_GAME)
4698 size=appletalk_get_packet_data( apacket );
4701 size=ipx_get_packet_data( packet );
4706 if (Network_game_type == APPLETALK_GAME)
4716 if (Network_game_type == IPX_GAME) {
4718 memcpy((ubyte *)&TempNetInfo, data, sizeof(netgame_info));
4720 receive_netgame_packet(data, &TempNetInfo, 0);
4723 memcpy((ubyte *)&TempNetInfo, data, sizeof(netgame_info));
4725 mprintf ((0,"This is %s game with a security of %d\n",TempNetInfo.game_name,TempNetInfo.Security));
4727 if (TempNetInfo.Security !=SecurityCheck)
4729 mprintf ((0,"Bad security on big_wait...rejecting.\n"));
4733 if (NetSecurityFlag==NETSECURITY_WAIT_FOR_GAMEINFO)
4735 if (TempPlayersInfo->Security==TempNetInfo.Security)
4737 mprintf ((0,"EQUAL !: Game=%d Players=%d ",TempPlayersInfo->Security,TempNetInfo.Security));
4738 if (TempPlayersInfo->Security==SecurityCheck)
4740 memcpy (&Active_games[choice],(ubyte *)&TempNetInfo,sizeof(netgame_info));
4741 memcpy (&ActiveNetPlayers[choice],TempPlayersInfo,sizeof(AllNetPlayers_info));
4748 NetSecurityFlag=NETSECURITY_WAIT_FOR_PLAYERS;
4749 NetSecurityNum=TempNetInfo.Security;
4751 if (network_wait_for_playerinfo())
4753 mprintf ((0,"HUH? Game=%d Player=%d\n",NetSecurityNum,TempPlayersInfo->Security));
4754 memcpy (&Active_games[choice],(ubyte *)&TempNetInfo,sizeof(netgame_info));
4755 memcpy (&ActiveNetPlayers[choice],TempPlayersInfo,sizeof(AllNetPlayers_info));
4762 case PID_PLAYERSINFO:
4763 mprintf ((0,"Got a PID_PLAYERSINFO!\n"));
4765 if (Network_game_type == IPX_GAME) {
4767 temp_info=(AllNetPlayers_info *)data;
4769 receive_netplayers_packet(data, &info_struct);
4770 temp_info = &info_struct;
4773 temp_info = (AllNetPlayers_info *)data;
4775 if (temp_info->Security!=SecurityCheck)
4776 break; // If this isn't the guy we're looking for, move on
4778 memcpy (&TempPlayersBase,(ubyte *)&temp_info,sizeof(AllNetPlayers_info));
4779 TempPlayersInfo=&TempPlayersBase;
4780 WaitingForPlayerInfo=0;
4781 NetSecurityNum=TempPlayersInfo->Security;
4782 NetSecurityFlag=NETSECURITY_WAIT_FOR_GAMEINFO;
4788 void network_leave_game()
4792 network_do_frame(1, 1);
4795 fclose (SendLogFile);
4796 fclose (RecieveLogFile);
4799 if ((network_i_am_master()))
4801 while (Network_sending_extras>1 && Player_joining_extras!=-1)
4802 network_send_extras();
4804 Netgame.numplayers = 0;
4807 network_send_game_info(NULL);
4810 mprintf ((0,"HEY! I'm master and I've left.\n"));
4813 Players[Player_num].connected = 0;
4814 network_send_endlevel_packet();
4815 change_playernum_to(0);
4816 Game_mode = GM_GAME_OVER;
4817 write_player_file();
4819 // WIN(ipx_destroy_read_thread());
4824 void network_flush()
4827 ubyte apacket[APPLETALK_MAX_DATA_SIZE];
4829 ubyte packet[IPX_MAX_DATA_SIZE];
4832 if ( (Network_game_type == APPLETALK_GAME) && (Appletalk_active <= 0) )
4836 if ( Network_game_type == IPX_GAME )
4837 if (!Network_active) return;
4840 if (Network_game_type == APPLETALK_GAME)
4841 while (appletalk_get_packet_data(apacket) > 0) ;
4844 while (ipx_get_packet_data(packet) > 0) ;
4847 void network_listen()
4850 ubyte apacket[APPLETALK_MAX_DATA_SIZE];
4853 ubyte packet[IPX_MAX_DATA_SIZE];
4856 if (Network_status==NETSTAT_PLAYING && Netgame.ShortPackets && !Network_send_objects)
4858 loopmax=N_players*Netgame.PacketsPerSec;
4862 if ( (Network_game_type == APPLETALK_GAME) && (Appletalk_active <= 0) )
4866 if (Network_game_type == IPX_GAME)
4867 if (!Network_active) return;
4869 if (!(Game_mode & GM_NETWORK) && (Function_mode == FMODE_GAME))
4870 mprintf((0, "Calling network_listen() when not in net game.\n"));
4872 WaitingForPlayerInfo=1;
4873 NetSecurityFlag=NETSECURITY_OFF;
4876 if (Network_game_type == IPX_GAME) {
4877 size = ipx_get_packet_data( packet );
4879 network_process_packet( packet, size );
4882 size = ipx_get_packet_data( packet );
4886 size = appletalk_get_packet_data( apacket );
4888 network_process_packet( apacket, size );
4891 size = appletalk_get_packet_data( apacket );
4897 int network_wait_for_playerinfo()
4900 ubyte packet[IPX_MAX_DATA_SIZE];
4901 struct AllNetPlayers_info *TempInfo;
4905 AllNetPlayers_info info_struct;
4906 ubyte apacket[APPLETALK_MAX_DATA_SIZE];
4910 if ( (Network_game_type == APPLETALK_GAME) && (Appletalk_active <= 0) )
4914 if ( Network_game_type == IPX_GAME)
4915 if (!Network_active) return(0);
4917 // if (!WaitingForPlayerInfo)
4920 if (!(Game_mode & GM_NETWORK) && (Function_mode == FMODE_GAME))
4922 mprintf((0, "Calling network_wait_for_playerinfo() when not in net game.\n"));
4924 if (Network_status==NETSTAT_PLAYING)
4926 Int3(); //MY GOD! Get Jason...this is the source of many problems
4929 basetime=timer_get_approx_seconds();
4931 while (WaitingForPlayerInfo && retries<50 && (timer_get_approx_seconds()<(basetime+(F1_0*5))))
4933 if (Network_game_type == IPX_GAME) {
4934 size = ipx_get_packet_data( packet );
4938 size = appletalk_get_packet_data( apacket );
4943 if (size>0 && id==PID_PLAYERSINFO)
4946 if (Network_game_type == APPLETALK_GAME) {
4947 TempInfo = (AllNetPlayers_info *)apacket;
4949 receive_netplayers_packet(packet, &info_struct);
4950 TempInfo = &info_struct;
4953 TempInfo=(AllNetPlayers_info *)packet;
4958 if (NetSecurityFlag==NETSECURITY_WAIT_FOR_PLAYERS)
4960 if (NetSecurityNum==TempInfo->Security)
4962 mprintf ((0,"HEYEQUAL: Player=%d Game=%d\n",TempInfo->Security,NetSecurityNum));
4963 memcpy (&TempPlayersBase,(ubyte *)TempInfo,sizeof(AllNetPlayers_info));
4964 TempPlayersInfo=&TempPlayersBase;
4965 NetSecurityFlag=NETSECURITY_OFF;
4967 WaitingForPlayerInfo=0;
4975 mprintf ((0,"I'm original!\n"));
4977 NetSecurityNum=TempInfo->Security;
4978 NetSecurityFlag=NETSECURITY_WAIT_FOR_GAMEINFO;
4980 memcpy (&TempPlayersBase,(ubyte *)TempInfo,sizeof(AllNetPlayers_info));
4981 TempPlayersInfo=&TempPlayersBase;
4982 WaitingForPlayerInfo=0;
4991 void network_send_data( ubyte * ptr, int len, int urgent )
4997 fprintf (SendLogFile,"Packet type: %d Len:%d Urgent:%d TT=%d\n",ptr[0],len,urgent,TTSent[ptr[0]]);
4998 fflush (SendLogFile);
5001 if (Endlevel_sequence)
5004 if (!MySyncPackInitialized) {
5005 MySyncPackInitialized = 1;
5006 memset( &MySyncPack, 0, sizeof(frame_info) );
5012 if ((MySyncPack.data_size+len) > MaxXDataSize ) {
5014 network_do_frame(1, 0);
5015 if (MySyncPack.data_size != 0) {
5016 mprintf((0, "%d bytes were added to data by network_do_frame!\n", MySyncPack.data_size));
5019 // Int3(); // Trying to send too much!
5021 mprintf((0, "Packet overflow, sending additional packet, type %d len %d.\n", ptr[0], len));
5022 Assert(check == ptr[0]);
5025 Assert(MySyncPack.data_size+len <= MaxXDataSize);
5027 memcpy( &MySyncPack.data[MySyncPack.data_size], ptr, len );
5028 MySyncPack.data_size += len;
5031 void network_timeout_player(int playernum)
5033 // Remove a player from the game if we haven't heard from them in
5037 Assert(playernum < N_players);
5038 Assert(playernum > -1);
5040 network_disconnect_player(playernum);
5041 create_player_appearance_effect(&Objects[Players[playernum].objnum]);
5043 digi_play_sample(SOUND_HUD_MESSAGE, F1_0);
5045 HUD_init_message("%s %s", Players[playernum].callsign, TXT_DISCONNECTING);
5046 for (i = 0; i < N_players; i++)
5047 if (Players[i].connected)
5052 nm_messagebox(NULL, 1, TXT_OK, TXT_YOU_ARE_ONLY);
5056 fix last_send_time = 0;
5057 fix last_timeout_check = 0;
5060 void squish_short_frame_info(short_frame_info old_info, ubyte *data)
5066 data[0] = old_info.type; loc++; loc += 3; // skip three for pad byte
5067 tmpi = swapint(old_info.numpackets);
5068 memcpy(&(data[loc]), &tmpi, 4); loc += 4;
5070 memcpy(&(data[loc]), old_info.thepos.bytemat, 9); loc += 9;
5071 tmps = INTEL_SHORT(old_info.thepos.xo);
5072 memcpy(&(data[loc]), &tmps, 2); loc += 2;
5073 tmps = INTEL_SHORT(old_info.thepos.yo);
5074 memcpy(&(data[loc]), &tmps, 2); loc += 2;
5075 tmps = INTEL_SHORT(old_info.thepos.zo);
5076 memcpy(&(data[loc]), &tmps, 2); loc += 2;
5077 tmps = INTEL_SHORT(old_info.thepos.segment);
5078 memcpy(&(data[loc]), &tmps, 2); loc += 2;
5079 tmps = INTEL_SHORT(old_info.thepos.velx);
5080 memcpy(&(data[loc]), &tmps, 2); loc += 2;
5081 tmps = INTEL_SHORT(old_info.thepos.vely);
5082 memcpy(&(data[loc]), &tmps, 2); loc += 2;
5083 tmps = INTEL_SHORT(old_info.thepos.velz);
5084 memcpy(&(data[loc]), &tmps, 2); loc += 2;
5086 tmps = swapshort(old_info.data_size);
5087 memcpy(&(data[loc]), &tmps, 2); loc += 2;
5089 data[loc] = old_info.playernum; loc++;
5090 data[loc] = old_info.obj_render_type; loc++;
5091 data[loc] = old_info.level_num; loc++;
5092 memcpy(&(data[loc]), old_info.data, old_info.data_size);
5096 char NakedBuf[NET_XDATA_SIZE+4];
5097 int NakedPacketLen=0;
5098 int NakedPacketDestPlayer=-1;
5100 void network_do_frame(int force, int listen)
5103 short_frame_info ShortSyncPack;
5104 static fix LastEndlevel=0;
5106 if (!(Game_mode&GM_NETWORK)) return;
5108 if ((Network_status != NETSTAT_PLAYING) || (Endlevel_sequence)) // Don't send postion during escape sequence...
5113 Assert (NakedPacketDestPlayer>-1);
5114 // mprintf ((0,"Sending a naked packet to %s (%d bytes)!\n",Players[NakedPacketDestPlayer].callsign,NakedPacketLen));
5115 if (Network_game_type == IPX_GAME)
5116 ipx_send_packet_data( (ubyte *)NakedBuf, NakedPacketLen, NetPlayers.players[NakedPacketDestPlayer].network.ipx.server, NetPlayers.players[NakedPacketDestPlayer].network.ipx.node,Players[NakedPacketDestPlayer].net_address );
5119 appletalk_send_packet_data( (ubyte *)NakedBuf, NakedPacketLen, NetPlayers.players[NakedPacketDestPlayer].network.appletalk.node, NetPlayers.players[NakedPacketDestPlayer].network.appletalk.net,NetPlayers.players[NakedPacketDestPlayer].network.appletalk.socket );
5122 NakedPacketDestPlayer=-1;
5125 if (WaitForRefuseAnswer && timer_get_approx_seconds()>(RefuseTimeLimit+(F1_0*12)))
5126 WaitForRefuseAnswer=0;
5128 last_send_time += FrameTime;
5129 last_timeout_check += FrameTime;
5131 // Send out packet PacksPerSec times per second maximum... unless they fire, then send more often...
5132 if ( (last_send_time>F1_0/Netgame.PacketsPerSec) || (Network_laser_fired) || force || PacketUrgent ) {
5133 if ( Players[Player_num].connected ) {
5134 int objnum = Players[Player_num].objnum;
5138 multi_send_robot_frame(0);
5139 multi_send_fire(); // Do firing if needed..
5144 if (Netgame.ShortPackets)
5147 ubyte send_data[IPX_MAX_DATA_SIZE];
5150 create_shortpos(&ShortSyncPack.thepos, Objects+objnum, 0);
5151 ShortSyncPack.type = PID_PDATA;
5152 ShortSyncPack.playernum = Player_num;
5153 ShortSyncPack.obj_render_type = Objects[objnum].render_type;
5154 ShortSyncPack.level_num = Current_level_num;
5155 ShortSyncPack.data_size = MySyncPack.data_size;
5156 memcpy (&ShortSyncPack.data[0],&MySyncPack.data[0],MySyncPack.data_size);
5158 for (i=0; i<N_players; i++ ) {
5159 if ( (Players[i].connected) && (i!=Player_num ) ) {
5160 MySyncPack.numpackets = Players[i].n_packets_sent++;
5161 ShortSyncPack.numpackets=MySyncPack.numpackets;
5162 if (Network_game_type == IPX_GAME) {
5164 ipx_send_packet_data( (ubyte *)&ShortSyncPack, sizeof(short_frame_info)-MaxXDataSize+MySyncPack.data_size, NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node,Players[i].net_address );
5166 squish_short_frame_info(ShortSyncPack, send_data);
5167 ipx_send_packet_data( (ubyte *)send_data, IPX_SHORT_INFO_SIZE-MaxXDataSize+MySyncPack.data_size, NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node,Players[i].net_address );
5171 appletalk_send_packet_data( (ubyte *)&ShortSyncPack, sizeof(short_frame_info)-MaxXDataSize+MySyncPack.data_size, NetPlayers.players[i].network.appletalk.node, NetPlayers.players[i].network.appletalk.net, NetPlayers.players[i].network.appletalk.socket );
5177 else // If long packets
5181 MySyncPack.type = PID_PDATA;
5182 MySyncPack.playernum = Player_num;
5183 MySyncPack.obj_render_type = Objects[objnum].render_type;
5184 MySyncPack.level_num = Current_level_num;
5185 MySyncPack.obj_segnum = Objects[objnum].segnum;
5186 MySyncPack.obj_pos = Objects[objnum].pos;
5187 MySyncPack.obj_orient = Objects[objnum].orient;
5188 MySyncPack.phys_velocity = Objects[objnum].mtype.phys_info.velocity;
5189 MySyncPack.phys_rotvel = Objects[objnum].mtype.phys_info.rotvel;
5191 send_data_size = MySyncPack.data_size; // do this so correct size data is sent
5193 #ifdef MACINTOSH // do the swap stuff
5194 if (Network_game_type == IPX_GAME) {
5195 MySyncPack.obj_segnum = INTEL_SHORT(MySyncPack.obj_segnum);
5196 MySyncPack.obj_pos.x = INTEL_INT((int)MySyncPack.obj_pos.x);
5197 MySyncPack.obj_pos.y = INTEL_INT((int)MySyncPack.obj_pos.y);
5198 MySyncPack.obj_pos.z = INTEL_INT((int)MySyncPack.obj_pos.z);
5200 MySyncPack.obj_orient.rvec.x = INTEL_INT((int)MySyncPack.obj_orient.rvec.x);
5201 MySyncPack.obj_orient.rvec.y = INTEL_INT((int)MySyncPack.obj_orient.rvec.y);
5202 MySyncPack.obj_orient.rvec.z = INTEL_INT((int)MySyncPack.obj_orient.rvec.z);
5203 MySyncPack.obj_orient.uvec.x = INTEL_INT((int)MySyncPack.obj_orient.uvec.x);
5204 MySyncPack.obj_orient.uvec.y = INTEL_INT((int)MySyncPack.obj_orient.uvec.y);
5205 MySyncPack.obj_orient.uvec.z = INTEL_INT((int)MySyncPack.obj_orient.uvec.z);
5206 MySyncPack.obj_orient.fvec.x = INTEL_INT((int)MySyncPack.obj_orient.fvec.x);
5207 MySyncPack.obj_orient.fvec.y = INTEL_INT((int)MySyncPack.obj_orient.fvec.y);
5208 MySyncPack.obj_orient.fvec.z = INTEL_INT((int)MySyncPack.obj_orient.fvec.z);
5210 MySyncPack.phys_velocity.x = INTEL_INT((int)MySyncPack.phys_velocity.x);
5211 MySyncPack.phys_velocity.y = INTEL_INT((int)MySyncPack.phys_velocity.y);
5212 MySyncPack.phys_velocity.z = INTEL_INT((int)MySyncPack.phys_velocity.z);
5214 MySyncPack.phys_rotvel.x = INTEL_INT((int)MySyncPack.phys_rotvel.x);
5215 MySyncPack.phys_rotvel.y = INTEL_INT((int)MySyncPack.phys_rotvel.y);
5216 MySyncPack.phys_rotvel.z = INTEL_INT((int)MySyncPack.phys_rotvel.z);
5218 MySyncPack.data_size = INTEL_SHORT(MySyncPack.data_size);
5222 for (i=0; i<N_players; i++ ) {
5223 if ( (Players[i].connected) && (i!=Player_num ) ) {
5224 if (Network_game_type == IPX_GAME)
5225 MySyncPack.numpackets = INTEL_INT(Players[i].n_packets_sent);
5228 MySyncPack.numpackets = Players[i].n_packets_sent;
5231 Players[i].n_packets_sent++;
5232 if (Network_game_type == IPX_GAME)
5233 ipx_send_packet_data( (ubyte *)&MySyncPack, sizeof(frame_info)-MaxXDataSize+send_data_size, NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node,Players[i].net_address );
5236 appletalk_send_packet_data( (ubyte *)&MySyncPack, sizeof(frame_info)-MaxXDataSize+send_data_size, NetPlayers.players[i].network.appletalk.node, NetPlayers.players[i].network.appletalk.net, NetPlayers.players[i].network.appletalk.socket);
5242 MySyncPack.data_size = 0; // Start data over at 0 length.
5243 if (Control_center_destroyed)
5246 Players[Player_num].connected=3;
5247 if (timer_get_approx_seconds() > (LastEndlevel+(F1_0/2)))
5249 network_send_endlevel_packet();
5250 LastEndlevel=timer_get_approx_seconds();
5253 //mprintf( (0, "Packet has %d bytes appended (TS=%d)\n", MySyncPack.data_size, sizeof(frame_info)-MaxXDataSize+MySyncPack.data_size ));
5260 if ((last_timeout_check > F1_0) && !(Control_center_destroyed))
5262 fix approx_time = timer_get_approx_seconds();
5263 // Check for player timeouts
5264 for (i = 0; i < N_players; i++)
5266 if ((i != Player_num) && (Players[i].connected == 1))
5268 if ((LastPacketTime[i] == 0) || (LastPacketTime[i] > approx_time))
5270 LastPacketTime[i] = approx_time;
5273 if ((approx_time - LastPacketTime[i]) > (15*F1_0))
5274 network_timeout_player(i);
5277 last_timeout_check = 0;
5283 MySyncPack.data_size = 0;
5288 if (VerifyPlayerJoined!=-1 && !(FrameCount & 63))
5289 resend_sync_due_to_packet_loss_for_allender(); // This will resend to network_player_rejoining
5291 if (Network_send_objects)
5292 network_send_objects();
5294 if (Network_sending_extras && VerifyPlayerJoined==-1)
5296 network_send_extras();
5301 int missed_packets = 0;
5303 int ConsistencyCount = 0;
5305 void network_consistency_error(void)
5307 if (++ConsistencyCount < 10)
5310 Function_mode = FMODE_MENU;
5312 nm_messagebox(NULL, 1, TXT_OK, TXT_CONSISTENCY_ERROR);
5314 nm_messagebox(NULL, 1, TXT_OK, "Failed to join the netgame.\nYou are missing packets. Check\nyour network connection and\ntry again.");
5316 Function_mode = FMODE_GAME;
5317 ConsistencyCount = 0;
5318 multi_quit_game = 1;
5319 multi_leave_menu = 1;
5320 multi_reset_stuff();
5321 Function_mode = FMODE_MENU;
5324 void network_process_pdata (char *data)
5326 Assert (Game_mode & GM_NETWORK);
5328 if (Netgame.ShortPackets)
5329 network_read_pdata_short_packet ((short_frame_info *)data);
5331 network_read_pdata_packet ((frame_info *)data);
5334 void network_read_pdata_packet(frame_info *pd )
5338 object * TheirObj = NULL;
5340 // frame_info should be aligned...for mac, make the necessary adjustments
5342 if (Network_game_type == IPX_GAME) {
5343 pd->numpackets = INTEL_INT(pd->numpackets);
5344 pd->obj_pos.x = INTEL_INT(pd->obj_pos.x);
5345 pd->obj_pos.y = INTEL_INT(pd->obj_pos.y);
5346 pd->obj_pos.z = INTEL_INT(pd->obj_pos.z);
5348 pd->obj_orient.rvec.x = (fix)INTEL_INT((int)pd->obj_orient.rvec.x);
5349 pd->obj_orient.rvec.y = (fix)INTEL_INT((int)pd->obj_orient.rvec.y);
5350 pd->obj_orient.rvec.z = (fix)INTEL_INT((int)pd->obj_orient.rvec.z);
5351 pd->obj_orient.uvec.x = (fix)INTEL_INT((int)pd->obj_orient.uvec.x);
5352 pd->obj_orient.uvec.y = (fix)INTEL_INT((int)pd->obj_orient.uvec.y);
5353 pd->obj_orient.uvec.z = (fix)INTEL_INT((int)pd->obj_orient.uvec.z);
5354 pd->obj_orient.fvec.x = (fix)INTEL_INT((int)pd->obj_orient.fvec.x);
5355 pd->obj_orient.fvec.y = (fix)INTEL_INT((int)pd->obj_orient.fvec.y);
5356 pd->obj_orient.fvec.z = (fix)INTEL_INT((int)pd->obj_orient.fvec.z);
5358 pd->phys_velocity.x = (fix)INTEL_INT((int)pd->phys_velocity.x);
5359 pd->phys_velocity.y = (fix)INTEL_INT((int)pd->phys_velocity.y);
5360 pd->phys_velocity.z = (fix)INTEL_INT((int)pd->phys_velocity.z);
5362 pd->phys_rotvel.x = (fix)INTEL_INT((int)pd->phys_rotvel.x);
5363 pd->phys_rotvel.y = (fix)INTEL_INT((int)pd->phys_rotvel.y);
5364 pd->phys_rotvel.z = (fix)INTEL_INT((int)pd->phys_rotvel.z);
5366 pd->obj_segnum = INTEL_SHORT(pd->obj_segnum);
5367 pd->data_size = INTEL_SHORT(pd->data_size);
5371 TheirPlayernum = pd->playernum;
5372 TheirObjnum = Players[pd->playernum].objnum;
5374 if (TheirPlayernum < 0) {
5375 Int3(); // This packet is bogus!!
5379 if (VerifyPlayerJoined!=-1 && TheirPlayernum==VerifyPlayerJoined)
5381 // Hurray! Someone really really got in the game (I think).
5382 mprintf ((0,"Hurray! VPJ (%d) reset!\n",VerifyPlayerJoined));
5383 VerifyPlayerJoined=-1;
5386 if (!multi_quit_game && (TheirPlayernum >= N_players)) {
5387 if (Network_status!=NETSTAT_WAITING)
5389 Int3(); // We missed an important packet!
5390 network_consistency_error();
5396 if (Endlevel_sequence || (Network_status == NETSTAT_ENDLEVEL) ) {
5397 int old_Endlevel_sequence = Endlevel_sequence;
5398 Endlevel_sequence = 1;
5399 if ( pd->data_size>0 ) {
5400 // pass pd->data to some parser function....
5401 multi_process_bigdata( pd->data, pd->data_size );
5403 Endlevel_sequence = old_Endlevel_sequence;
5406 // mprintf((0, "Gametime = %d, Frametime = %d.\n", GameTime, FrameTime));
5408 if ((byte)pd->level_num != Current_level_num)
5410 mprintf((0, "Got frame packet from player %d wrong level %d!\n", pd->playernum, pd->level_num));
5414 TheirObj = &Objects[TheirObjnum];
5416 //------------- Keep track of missed packets -----------------
5417 Players[TheirPlayernum].n_packets_got++;
5419 LastPacketTime[TheirPlayernum] = timer_get_approx_seconds();
5421 if ( pd->numpackets != Players[TheirPlayernum].n_packets_got ) {
5424 missed_packets = pd->numpackets-Players[TheirPlayernum].n_packets_got;
5425 if ((pd->numpackets-Players[TheirPlayernum].n_packets_got)>0)
5426 TotalMissedPackets += pd->numpackets-Players[TheirPlayernum].n_packets_got;
5428 if ( missed_packets > 0 )
5429 mprintf(( 0, "Missed %d packets from player #%d (%d total)\n", pd->numpackets-Players[TheirPlayernum].n_packets_got, TheirPlayernum, missed_packets ));
5431 mprintf( (0, "Got %d late packets from player #%d (%d total)\n", Players[TheirPlayernum].n_packets_got-pd->numpackets, TheirPlayernum, missed_packets ));
5434 #ifdef APPLETALK_DEBUG
5435 if (Network_game_type == APPLETALK_GAME) {
5436 if ( missed_packets > 0 )
5437 fprintf( at_fp, "Missed %d packets from player #%d (%d total)\n", pd->numpackets-Players[TheirPlayernum].n_packets_got, TheirPlayernum, missed_packets );
5439 fprintf( at_fp, "Got %d late packets from player #%d (%d total)\n", Players[TheirPlayernum].n_packets_got-pd->numpackets, TheirPlayernum, missed_packets );
5444 if (Network_game_type == IPX_GAME) {
5445 if ( missed_packets > 0 )
5446 fprintf( ipx_fp, "Missed %d packets from player #%d (%d total)\n", pd->numpackets-Players[TheirPlayernum].n_packets_got, TheirPlayernum, missed_packets );
5448 fprintf( ipx_fp, "Got %d late packets from player #%d (%d total)\n", Players[TheirPlayernum].n_packets_got-pd->numpackets, TheirPlayernum, missed_packets );
5453 Players[TheirPlayernum].n_packets_got = pd->numpackets;
5456 //------------ Read the player's ship's object info ----------------------
5457 TheirObj->pos = pd->obj_pos;
5458 TheirObj->orient = pd->obj_orient;
5459 TheirObj->mtype.phys_info.velocity = pd->phys_velocity;
5460 TheirObj->mtype.phys_info.rotvel = pd->phys_rotvel;
5462 if ((TheirObj->render_type != pd->obj_render_type) && (pd->obj_render_type == RT_POLYOBJ))
5463 multi_make_ghost_player(TheirPlayernum);
5465 obj_relink(TheirObjnum,pd->obj_segnum);
5467 if (TheirObj->movement_type == MT_PHYSICS)
5468 set_thrust_from_velocity(TheirObj);
5470 //------------ Welcome them back if reconnecting --------------
5471 if (!Players[TheirPlayernum].connected) {
5472 Players[TheirPlayernum].connected = 1;
5474 if (Newdemo_state == ND_STATE_RECORDING)
5475 newdemo_record_multi_reconnect(TheirPlayernum);
5477 multi_make_ghost_player(TheirPlayernum);
5479 create_player_appearance_effect(&Objects[TheirObjnum]);
5481 digi_play_sample( SOUND_HUD_MESSAGE, F1_0);
5483 ClipRank (&NetPlayers.players[TheirPlayernum].rank);
5485 if (FindArg("-norankings"))
5486 HUD_init_message( "'%s' %s", Players[TheirPlayernum].callsign, TXT_REJOIN );
5488 HUD_init_message( "%s'%s' %s", RankStrings[NetPlayers.players[TheirPlayernum].rank],Players[TheirPlayernum].callsign, TXT_REJOIN );
5494 //------------ Parse the extra data at the end ---------------
5496 if ( pd->data_size>0 ) {
5497 // pass pd->data to some parser function....
5498 multi_process_bigdata( pd->data, pd->data_size );
5504 void get_short_frame_info(ubyte *old_info, short_frame_info *new_info)
5508 new_info->type = old_info[loc]; loc++; loc += 3; // skip three for pad byte
5509 memcpy(&(new_info->numpackets), &(old_info[loc]), 4); loc += 4;
5510 new_info->numpackets = INTEL_INT(new_info->numpackets);
5511 memcpy(new_info->thepos.bytemat, &(old_info[loc]), 9); loc += 9;
5512 memcpy(&(new_info->thepos.xo), &(old_info[loc]), 2); loc += 2;
5513 memcpy(&(new_info->thepos.yo), &(old_info[loc]), 2); loc += 2;
5514 memcpy(&(new_info->thepos.zo), &(old_info[loc]), 2); loc += 2;
5515 memcpy(&(new_info->thepos.segment), &(old_info[loc]), 2); loc += 2;
5516 memcpy(&(new_info->thepos.velx), &(old_info[loc]), 2); loc += 2;
5517 memcpy(&(new_info->thepos.vely), &(old_info[loc]), 2); loc += 2;
5518 memcpy(&(new_info->thepos.velz), &(old_info[loc]), 2); loc += 2;
5519 new_info->thepos.xo = INTEL_SHORT(new_info->thepos.xo);
5520 new_info->thepos.yo = INTEL_SHORT(new_info->thepos.yo);
5521 new_info->thepos.zo = INTEL_SHORT(new_info->thepos.zo);
5522 new_info->thepos.segment = INTEL_SHORT(new_info->thepos.segment);
5523 new_info->thepos.velx = INTEL_SHORT(new_info->thepos.velx);
5524 new_info->thepos.vely = INTEL_SHORT(new_info->thepos.vely);
5525 new_info->thepos.velz = INTEL_SHORT(new_info->thepos.velz);
5527 memcpy(&(new_info->data_size), &(old_info[loc]), 2); loc += 2;
5528 new_info->data_size = INTEL_SHORT(new_info->data_size);
5529 new_info->playernum = old_info[loc]; loc++;
5530 new_info->obj_render_type = old_info[loc]; loc++;
5531 new_info->level_num = old_info[loc]; loc++;
5532 memcpy(new_info->data, &(old_info[loc]), new_info->data_size);
5536 void network_read_pdata_short_packet(short_frame_info *pd )
5540 object * TheirObj = NULL;
5541 short_frame_info new_pd;
5543 // short frame info is not aligned because of shortpos. The mac
5544 // will call totally hacked and gross function to fix this up.
5546 if (Network_game_type == IPX_GAME) {
5548 memcpy(&new_pd, (ubyte *)pd, sizeof(short_frame_info));
5550 get_short_frame_info((ubyte *)pd, &new_pd);
5553 memcpy(&new_pd, (ubyte *)pd, sizeof(short_frame_info));
5556 TheirPlayernum = new_pd.playernum;
5557 TheirObjnum = Players[new_pd.playernum].objnum;
5559 if (TheirPlayernum < 0) {
5560 Int3(); // This packet is bogus!!
5563 if (!multi_quit_game && (TheirPlayernum >= N_players)) {
5564 if (Network_status!=NETSTAT_WAITING)
5566 Int3(); // We missed an important packet!
5567 network_consistency_error();
5574 if (VerifyPlayerJoined!=-1 && TheirPlayernum==VerifyPlayerJoined)
5576 // Hurray! Someone really really got in the game (I think).
5577 mprintf ((0,"Hurray! VPJ (%d) reset!\n",VerifyPlayerJoined));
5578 VerifyPlayerJoined=-1;
5581 if (Endlevel_sequence || (Network_status == NETSTAT_ENDLEVEL) ) {
5582 int old_Endlevel_sequence = Endlevel_sequence;
5583 Endlevel_sequence = 1;
5584 if ( new_pd.data_size>0 ) {
5585 // pass pd->data to some parser function....
5586 multi_process_bigdata( new_pd.data, new_pd.data_size );
5588 Endlevel_sequence = old_Endlevel_sequence;
5591 // mprintf((0, "Gametime = %d, Frametime = %d.\n", GameTime, FrameTime));
5593 if ((byte)new_pd.level_num != Current_level_num)
5595 mprintf((0, "Got frame packet from player %d wrong level %d!\n", new_pd.playernum, new_pd.level_num));
5599 TheirObj = &Objects[TheirObjnum];
5601 //------------- Keep track of missed packets -----------------
5602 Players[TheirPlayernum].n_packets_got++;
5604 LastPacketTime[TheirPlayernum] = timer_get_approx_seconds();
5606 if ( new_pd.numpackets != Players[TheirPlayernum].n_packets_got ) {
5609 missed_packets = new_pd.numpackets-Players[TheirPlayernum].n_packets_got;
5610 if ((new_pd.numpackets-Players[TheirPlayernum].n_packets_got)>0)
5611 TotalMissedPackets += new_pd.numpackets-Players[TheirPlayernum].n_packets_got;
5613 if ( missed_packets > 0 )
5614 mprintf( (0, "Missed %d packets from player #%d (%d total)\n", new_pd.numpackets-Players[TheirPlayernum].n_packets_got, TheirPlayernum, missed_packets ));
5616 mprintf( (0, "Got %d late packets from player #%d (%d total)\n", Players[TheirPlayernum].n_packets_got-new_pd.numpackets, TheirPlayernum, missed_packets ));
5618 Players[TheirPlayernum].n_packets_got = new_pd.numpackets;
5621 //------------ Read the player's ship's object info ----------------------
5623 extract_shortpos(TheirObj, &new_pd.thepos, 0);
5625 if ((TheirObj->render_type != new_pd.obj_render_type) && (new_pd.obj_render_type == RT_POLYOBJ))
5626 multi_make_ghost_player(TheirPlayernum);
5628 if (TheirObj->movement_type == MT_PHYSICS)
5629 set_thrust_from_velocity(TheirObj);
5631 //------------ Welcome them back if reconnecting --------------
5632 if (!Players[TheirPlayernum].connected) {
5633 Players[TheirPlayernum].connected = 1;
5635 if (Newdemo_state == ND_STATE_RECORDING)
5636 newdemo_record_multi_reconnect(TheirPlayernum);
5638 multi_make_ghost_player(TheirPlayernum);
5640 create_player_appearance_effect(&Objects[TheirObjnum]);
5642 digi_play_sample( SOUND_HUD_MESSAGE, F1_0);
5643 ClipRank (&NetPlayers.players[TheirPlayernum].rank);
5645 if (FindArg("-norankings"))
5646 HUD_init_message( "'%s' %s", Players[TheirPlayernum].callsign, TXT_REJOIN );
5648 HUD_init_message( "%s'%s' %s", RankStrings[NetPlayers.players[TheirPlayernum].rank],Players[TheirPlayernum].callsign, TXT_REJOIN );
5654 //------------ Parse the extra data at the end ---------------
5656 if ( new_pd.data_size>0 ) {
5657 // pass pd->data to some parser function....
5658 multi_process_bigdata( new_pd.data, new_pd.data_size );
5664 void network_set_power (void)
5666 int opt=0,choice,opt_primary,opt_second,opt_power;
5670 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Laser upgrade"; m[opt].value=Netgame.DoLaserUpgrade; opt++;
5671 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Super lasers"; m[opt].value=Netgame.DoSuperLaser; opt++;
5672 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Quad Lasers"; m[opt].value=Netgame.DoQuadLasers; opt++;
5673 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Vulcan cannon"; m[opt].value=Netgame.DoVulcan; opt++;
5674 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Spreadfire cannon"; m[opt].value=Netgame.DoSpread; opt++;
5675 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Plasma cannon"; m[opt].value=Netgame.DoPlasma; opt++;
5676 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Fusion cannon"; m[opt].value=Netgame.DoFusions; opt++;
5677 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Gauss cannon"; m[opt].value=Netgame.DoGauss; opt++;
5678 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Helix cannon"; m[opt].value=Netgame.DoHelix; opt++;
5679 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Phoenix cannon"; m[opt].value=Netgame.DoPhoenix; opt++;
5680 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Omega cannon"; m[opt].value=Netgame.DoOmega; opt++;
5683 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Homing Missiles"; m[opt].value=Netgame.DoHoming; opt++;
5684 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Proximity Bombs"; m[opt].value=Netgame.DoProximity; opt++;
5685 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Smart Missiles"; m[opt].value=Netgame.DoSmarts; opt++;
5686 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Mega Missiles"; m[opt].value=Netgame.DoMegas; opt++;
5687 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Flash Missiles"; m[opt].value=Netgame.DoFlash; opt++;
5688 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Guided Missiles"; m[opt].value=Netgame.DoGuided; opt++;
5689 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Smart Mines"; m[opt].value=Netgame.DoSmartMine; opt++;
5690 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Mercury Missiles"; m[opt].value=Netgame.DoMercury; opt++;
5691 m[opt].type = NM_TYPE_CHECK; m[opt].text = "EarthShaker Missiles"; m[opt].value=Netgame.DoEarthShaker; opt++;
5694 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Invulnerability"; m[opt].value=Netgame.DoInvulnerability; opt++;
5695 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Cloaking"; m[opt].value=Netgame.DoCloak; opt++;
5696 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Afterburners"; m[opt].value=Netgame.DoAfterburner; opt++;
5697 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Ammo rack"; m[opt].value=Netgame.DoAmmoRack; opt++;
5698 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Energy Converter"; m[opt].value=Netgame.DoConverter; opt++;
5699 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Headlight"; m[opt].value=Netgame.DoHeadlight; opt++;
5701 choice = newmenu_do(NULL, "Objects to allow", opt, m, NULL);
5703 Netgame.DoLaserUpgrade=m[opt_primary].value;
5704 Netgame.DoSuperLaser=m[opt_primary+1].value;
5705 Netgame.DoQuadLasers=m[opt_primary+2].value;
5706 Netgame.DoVulcan=m[opt_primary+3].value;
5707 Netgame.DoSpread=m[opt_primary+4].value;
5708 Netgame.DoPlasma=m[opt_primary+5].value;
5709 Netgame.DoFusions=m[opt_primary+6].value;
5710 Netgame.DoGauss=m[opt_primary+7].value;
5711 Netgame.DoHelix=m[opt_primary+8].value;
5712 Netgame.DoPhoenix=m[opt_primary+9].value;
5713 Netgame.DoOmega=m[opt_primary+10].value;
5715 Netgame.DoHoming=m[opt_second].value;
5716 Netgame.DoProximity=m[opt_second+1].value;
5717 Netgame.DoSmarts=m[opt_second+2].value;
5718 Netgame.DoMegas=m[opt_second+3].value;
5719 Netgame.DoFlash=m[opt_second+4].value;
5720 Netgame.DoGuided=m[opt_second+5].value;
5721 Netgame.DoSmartMine=m[opt_second+6].value;
5722 Netgame.DoMercury=m[opt_second+7].value;
5723 Netgame.DoEarthShaker=m[opt_second+8].value;
5725 Netgame.DoInvulnerability=m[opt_power].value;
5726 Netgame.DoCloak=m[opt_power+1].value;
5727 Netgame.DoAfterburner=m[opt_power+2].value;
5728 Netgame.DoAmmoRack=m[opt_power+3].value;
5729 Netgame.DoConverter=m[opt_power+4].value;
5730 Netgame.DoHeadlight=m[opt_power+5].value;
5734 void SetAllAllowablesTo (int on)
5736 last_cinvul = control_invul_time = 0; //default to zero
5738 Netgame.DoMegas=Netgame.DoSmarts=Netgame.DoFusions=Netgame.DoHelix=\
5739 Netgame.DoPhoenix=Netgame.DoCloak=Netgame.DoInvulnerability=\
5740 Netgame.DoAfterburner=Netgame.DoGauss=Netgame.DoVulcan=Netgame.DoPlasma=on;
5742 Netgame.DoOmega=Netgame.DoSuperLaser=Netgame.DoProximity=\
5743 Netgame.DoSpread=Netgame.DoMercury=Netgame.DoSmartMine=Netgame.DoFlash=\
5744 Netgame.DoGuided=Netgame.DoEarthShaker=on;
5746 Netgame.DoConverter=Netgame.DoAmmoRack=Netgame.DoHeadlight=on;
5747 Netgame.DoHoming=Netgame.DoLaserUpgrade=Netgame.DoQuadLasers=on;
5748 Netgame.BrightPlayers=Netgame.invul=on;
5754 // Jeez -- mac compiler can't handle all of these on the same decl line.
5755 int opt_setpower,opt_playtime,opt_killgoal,opt_socket,opt_marker_view,opt_light,opt_show_on_map;
5756 int opt_difficulty,opt_packets,opt_short_packets, opt_bright,opt_start_invul;
5759 void network_more_options_poll( int nitems, newmenu_item * menus, int * key, int citem );
5761 void network_more_game_options ()
5764 char PlayText[80],KillText[80],srinvul[50],socket_string[5],packstring[5];
5767 sprintf (socket_string,"%d",Network_socket);
5768 sprintf (packstring,"%d",Netgame.PacketsPerSec);
5770 opt_difficulty = opt;
5771 m[opt].type = NM_TYPE_SLIDER; m[opt].value=netgame_difficulty; m[opt].text=TXT_DIFFICULTY; m[opt].min_value=0; m[opt].max_value=(NDL-1); opt++;
5774 sprintf( srinvul, "%s: %d %s", TXT_REACTOR_LIFE, control_invul_time*5, TXT_MINUTES_ABBREV );
5775 m[opt].type = NM_TYPE_SLIDER; m[opt].value=control_invul_time; m[opt].text= srinvul; m[opt].min_value=0; m[opt].max_value=10; opt++;
5778 sprintf( PlayText, "Max time: %d %s", Netgame.PlayTimeAllowed*5, TXT_MINUTES_ABBREV );
5779 m[opt].type = NM_TYPE_SLIDER; m[opt].value=Netgame.PlayTimeAllowed; m[opt].text= PlayText; m[opt].min_value=0; m[opt].max_value=10; opt++;
5782 sprintf( KillText, "Kill Goal: %d kills", Netgame.KillGoal*5);
5783 m[opt].type = NM_TYPE_SLIDER; m[opt].value=Netgame.KillGoal; m[opt].text= KillText; m[opt].min_value=0; m[opt].max_value=10; opt++;
5785 opt_start_invul=opt;
5786 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Invulnerable when reappearing"; m[opt].value=Netgame.invul; opt++;
5788 opt_marker_view = opt;
5789 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Allow camera views from Markers"; m[opt].value=Netgame.Allow_marker_view; opt++;
5791 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Indestructible lights"; m[opt].value=Netgame.AlwaysLighting; opt++;
5794 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Bright player ships"; m[opt].value=Netgame.BrightPlayers; opt++;
5797 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Show enemy names on HUD"; m[opt].value=Netgame.ShowAllNames; opt++;
5799 opt_show_on_map=opt;
5800 m[opt].type = NM_TYPE_CHECK; m[opt].text = TXT_SHOW_ON_MAP; m[opt].value=(Netgame.game_flags & NETGAME_FLAG_SHOW_MAP); opt_show_on_map=opt; opt++;
5802 opt_short_packets=opt;
5803 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Short packets"; m[opt].value=Netgame.ShortPackets; opt++;
5806 m[opt].type = NM_TYPE_MENU; m[opt].text = "Set Objects allowed..."; opt++;
5808 if (Network_game_type == IPX_GAME) {
5809 m[opt].type = NM_TYPE_TEXT; m[opt].text = "Network socket"; opt++;
5811 m[opt].type = NM_TYPE_INPUT; m[opt].text = socket_string; m[opt].text_len=4; opt++;
5814 m[opt].type = NM_TYPE_TEXT; m[opt].text = "Packets per second (2 - 20)"; opt++;
5816 m[opt].type = NM_TYPE_INPUT; m[opt].text=packstring; m[opt].text_len=2; opt++;
5818 LastKillGoal=Netgame.KillGoal;
5819 LastPTA=Netgame.PlayTimeAllowed;
5823 ExtGameStatus=GAMESTAT_MORE_NETGAME_OPTIONS;
5824 i = newmenu_do1( NULL, "Additional netgame options", opt, m, network_more_options_poll, 0 );
5826 //control_invul_time = atoi( srinvul )*60*F1_0;
5827 control_invul_time = m[opt_cinvul].value;
5828 Netgame.control_invul_time = control_invul_time*5*F1_0*60;
5830 if (i==opt_setpower)
5832 network_set_power ();
5836 Netgame.PacketsPerSec=atoi(packstring);
5838 if (Netgame.PacketsPerSec>20)
5840 Netgame.PacketsPerSec=20;
5841 nm_messagebox(TXT_ERROR, 1, TXT_OK, "Packet value out of range\nSetting value to 20");
5843 if (Netgame.PacketsPerSec<2)
5845 nm_messagebox(TXT_ERROR, 1, TXT_OK, "Packet value out of range\nSetting value to 2");
5846 Netgame.PacketsPerSec=2;
5849 mprintf ((0,"Hey! Sending out %d packets per second\n",Netgame.PacketsPerSec));
5851 if (Network_game_type == IPX_GAME) {
5852 if ((atoi(socket_string))!=Network_socket) {
5853 Network_socket=atoi(socket_string);
5854 ipx_change_default_socket( IPX_DEFAULT_SOCKET + Network_socket );
5858 Netgame.invul=m[opt_start_invul].value;
5859 Netgame.BrightPlayers=m[opt_bright].value;
5860 Netgame.ShortPackets=m[opt_short_packets].value;
5861 Netgame.ShowAllNames=m[opt_show_names].value;
5862 network_AdjustMaxDataSize();
5864 Netgame.Allow_marker_view=m[opt_marker_view].value;
5865 Netgame.AlwaysLighting=m[opt_light].value;
5866 netgame_difficulty=Difficulty_level = m[opt_difficulty].value;
5867 if (m[opt_show_on_map].value)
5868 Netgame.game_flags |= NETGAME_FLAG_SHOW_MAP;
5873 void network_more_options_poll( int nitems, newmenu_item * menus, int * key, int citem )
5876 citem = citem; // kills compile warnings
5880 if ( last_cinvul != menus[opt_cinvul].value ) {
5881 sprintf( menus[opt_cinvul].text, "%s: %d %s", TXT_REACTOR_LIFE, menus[opt_cinvul].value*5, TXT_MINUTES_ABBREV );
5882 last_cinvul = menus[opt_cinvul].value;
5883 menus[opt_cinvul].redraw = 1;
5886 if (menus[opt_playtime].value!=LastPTA)
5890 nm_messagebox ("Sorry",1,TXT_OK,"Registered version only!");
5891 menus[opt_playtime].value=0;
5892 menus[opt_playtime].redraw=1;
5896 if (Game_mode & GM_MULTI_COOP)
5899 nm_messagebox ("Sorry",1,TXT_OK,"You can't change those for coop!");
5900 menus[opt_playtime].value=0;
5901 menus[opt_playtime].redraw=1;
5905 Netgame.PlayTimeAllowed=menus[opt_playtime].value;
5906 sprintf( menus[opt_playtime].text, "Max Time: %d %s", Netgame.PlayTimeAllowed*5, TXT_MINUTES_ABBREV );
5907 LastPTA=Netgame.PlayTimeAllowed;
5908 menus[opt_playtime].redraw=1;
5910 if (menus[opt_killgoal].value!=LastKillGoal)
5913 nm_messagebox ("Sorry",1,TXT_OK,"Registered version only!");
5914 menus[opt_killgoal].value=0;
5915 menus[opt_killgoal].redraw=1;
5921 if (Game_mode & GM_MULTI_COOP)
5923 nm_messagebox ("Sorry",1,TXT_OK,"You can't change those for coop!");
5924 menus[opt_killgoal].value=0;
5925 menus[opt_killgoal].redraw=1;
5931 Netgame.KillGoal=menus[opt_killgoal].value;
5932 sprintf( menus[opt_killgoal].text, "Kill Goal: %d kills", Netgame.KillGoal*5);
5933 LastKillGoal=Netgame.KillGoal;
5934 menus[opt_killgoal].redraw=1;
5938 extern void multi_send_light (int,ubyte);
5939 extern void multi_send_light_specific (int,int,ubyte);
5941 void network_send_smash_lights (int pnum)
5943 // send the lights that have been blown out
5949 for (i=0;i<=Highest_segment_index;i++)
5950 if (Light_subtracted[i])
5951 multi_send_light_specific(pnum,i,Light_subtracted[i]);
5954 extern int Num_triggers;
5955 extern void multi_send_trigger_specific (char pnum,char);
5957 void network_send_fly_thru_triggers (int pnum)
5959 // send the fly thru triggers that have been disabled
5963 for (i=0;i<Num_triggers;i++)
5964 if (Triggers[i].flags & TF_DISABLED)
5965 multi_send_trigger_specific(pnum,i);
5968 void network_send_player_flags()
5972 for (i=0;i<N_players;i++)
5973 multi_send_flags(i);
5976 void network_ping (ubyte flag,int pnum)
5981 mybuf[1]=Player_num;
5983 if (Network_game_type == IPX_GAME)
5984 ipx_send_packet_data( (ubyte *)mybuf, 2, NetPlayers.players[pnum].network.ipx.server, NetPlayers.players[pnum].network.ipx.node,Players[pnum].net_address );
5987 appletalk_send_packet_data( (ubyte *)mybuf, 2, NetPlayers.players[pnum].network.appletalk.node, NetPlayers.players[pnum].network.appletalk.net, NetPlayers.players[pnum].network.appletalk.socket);
5991 extern fix PingLaunchTime,PingReturnTime;
5993 void network_handle_ping_return (ubyte pnum)
5995 if (PingLaunchTime==0 || pnum>=N_players)
5997 mprintf ((0,"Got invalid PING RETURN from %s!\n",Players[pnum].callsign));
6001 PingReturnTime=timer_get_fixed_seconds();
6003 HUD_init_message ("Ping time for %s is %d ms!",Players[pnum].callsign,
6004 f2i(fixmul(PingReturnTime-PingLaunchTime,i2f(1000))));
6008 void network_send_ping (ubyte pnum)
6010 network_ping (PID_PING_SEND,pnum);
6013 void DoRefuseStuff (sequence_packet *their)
6015 int i,new_player_num;
6017 ClipRank (&their->player.rank);
6019 for (i=0;i<MAX_PLAYERS;i++)
6020 if (!strcmp (their->player.callsign,Players[i].callsign))
6022 network_welcome_player(their);
6026 if (!WaitForRefuseAnswer)
6028 for (i=0;i<MAX_PLAYERS;i++)
6029 if (!strcmp (their->player.callsign,Players[i].callsign))
6031 network_welcome_player(their);
6035 digi_play_sample (SOUND_HUD_JOIN_REQUEST,F1_0*2);
6037 if (Game_mode & GM_TEAM)
6041 if (!FindArg("-norankings"))
6042 HUD_init_message ("%s %s wants to join",RankStrings[their->player.rank],their->player.callsign);
6044 HUD_init_message ("%s joining. Alt-1 assigns to team %s. Alt-2 to team %s",their->player.callsign,Netgame.team_name[0],Netgame.team_name[1]);
6046 HUD_init_message ("%s joining. Opt-1 assigns to team %s. Opt-2 to team %s",their->player.callsign,Netgame.team_name[0],Netgame.team_name[1]);
6048 // HUD_init_message ("Alt-1 to place on team %s!",Netgame.team_name[0]);
6049 // HUD_init_message ("Alt-2 to place on team %s!",Netgame.team_name[1]);
6052 HUD_init_message ("%s wants to join...press F6 to connect",their->player.callsign);
6054 strcpy (RefusePlayerName,their->player.callsign);
6055 RefuseTimeLimit=timer_get_approx_seconds();
6057 WaitForRefuseAnswer=1;
6061 for (i=0;i<MAX_PLAYERS;i++)
6062 if (!strcmp (their->player.callsign,Players[i].callsign))
6064 network_welcome_player(their);
6068 if (strcmp(their->player.callsign,RefusePlayerName))
6071 if (RefuseThisPlayer)
6075 WaitForRefuseAnswer=0;
6076 if (Game_mode & GM_TEAM)
6078 new_player_num=GetNewPlayerNumber (their);
6079 mprintf ((0,"Newplayernum=%d\n",new_player_num));
6081 Assert (RefuseTeam==1 || RefuseTeam==2);
6084 Netgame.team_vector &=(~(1<<new_player_num));
6086 Netgame.team_vector |=(1<<new_player_num);
6087 network_welcome_player(their);
6088 network_send_netgame_update ();
6091 network_welcome_player(their);
6095 if ((timer_get_approx_seconds()) > RefuseTimeLimit+REFUSE_INTERVAL)
6099 WaitForRefuseAnswer=0;
6100 if (!strcmp (their->player.callsign,RefusePlayerName)) {
6101 if (Network_game_type == IPX_GAME)
6102 network_dump_player(their->player.network.ipx.server,their->player.network.ipx.node, DUMP_DORK);
6105 network_dump_appletalk_player(their->player.network.appletalk.node,their->player.network.appletalk.net, their->player.network.appletalk.socket, DUMP_DORK);
6114 int GetNewPlayerNumber (sequence_packet *their)
6120 if ( N_players < MaxNumNetPlayers)
6125 // Slots are full but game is open, see if anyone is
6126 // disconnected and replace the oldest player with this new one
6128 int oldest_player = -1;
6129 fix oldest_time = timer_get_approx_seconds();
6131 Assert(N_players == MaxNumNetPlayers);
6133 for (i = 0; i < N_players; i++)
6135 if ( (!Players[i].connected) && (LastPacketTime[i] < oldest_time))
6137 oldest_time = LastPacketTime[i];
6141 return (oldest_player);
6145 void network_send_extras ()
6147 Assert (Player_joining_extras>-1);
6149 if (!network_i_am_master())
6151 mprintf ((0,"Hey! I'm not the master and I was gonna send info!\n"));
6153 // Network_sending_extras=0;
6158 if (Network_sending_extras==40)
6159 network_send_fly_thru_triggers(Player_joining_extras);
6160 if (Network_sending_extras==38)
6161 network_send_door_updates(Player_joining_extras);
6162 if (Network_sending_extras==35)
6163 network_send_markers();
6164 if (Network_sending_extras==30 && (Game_mode & GM_MULTI_ROBOTS))
6165 multi_send_stolen_items();
6166 if (Network_sending_extras==25 && (Netgame.PlayTimeAllowed || Netgame.KillGoal))
6167 multi_send_kill_goal_counts();
6168 if (Network_sending_extras==20)
6169 network_send_smash_lights(Player_joining_extras);
6170 if (Network_sending_extras==15)
6171 network_send_player_flags();
6172 if (Network_sending_extras==10)
6173 multi_send_powerup_update();
6174 // if (Network_sending_extras==5)
6175 // network_send_door_updates(Player_joining_extras); // twice!
6177 Network_sending_extras--;
6178 if (!Network_sending_extras)
6179 Player_joining_extras=-1;
6183 void network_send_naked_packet(char *buf, short len, int who)
6185 if (!(Game_mode&GM_NETWORK)) return;
6187 if (NakedPacketLen==0)
6189 NakedBuf[0]=PID_NAKED_PDATA;
6190 NakedBuf[1]=Player_num;
6194 if (len+NakedPacketLen>MaxXDataSize)
6196 // mprintf ((0,"Sending a naked packet of %d bytes.\n",NakedPacketLen));
6197 if (Network_game_type == IPX_GAME)
6198 ipx_send_packet_data( (ubyte *)NakedBuf, NakedPacketLen, NetPlayers.players[who].network.ipx.server, NetPlayers.players[who].network.ipx.node,Players[who].net_address );
6201 appletalk_send_packet_data( (ubyte *)NakedBuf, NakedPacketLen, NetPlayers.players[who].network.appletalk.node, NetPlayers.players[who].network.appletalk.net, NetPlayers.players[who].network.appletalk.socket );
6204 memcpy (&NakedBuf[NakedPacketLen],buf,len);
6205 NakedPacketLen+=len;
6206 NakedPacketDestPlayer=who;
6210 memcpy (&NakedBuf[NakedPacketLen],buf,len);
6211 NakedPacketLen+=len;
6212 NakedPacketDestPlayer=who;
6217 void network_process_naked_pdata (char *data,int len)
6220 Assert (data[0]=PID_NAKED_PDATA);
6222 // mprintf ((0,"Processing a naked packet of %d length.\n",len));
6225 mprintf ((0,"Naked packet is bad!\n"));
6226 Int3(); // This packet is bogus!!
6230 if (!multi_quit_game && (pnum >= N_players)) {
6231 if (Network_status!=NETSTAT_WAITING)
6233 Int3(); // We missed an important packet!
6234 network_consistency_error();
6241 if (Endlevel_sequence || (Network_status == NETSTAT_ENDLEVEL) ) {
6242 int old_Endlevel_sequence = Endlevel_sequence;
6243 Endlevel_sequence = 1;
6244 multi_process_bigdata( data+2, len-2);
6245 Endlevel_sequence = old_Endlevel_sequence;
6249 multi_process_bigdata( data+2, len-2 );
6252 int ConnectionPacketLevel[]={0,1,1,1};
6253 int ConnectionSecLevel[]={12,3,5,7};
6255 int AppletalkConnectionPacketLevel[]={0,1,0};
6256 int AppletalkConnectionSecLevel[]={10,3,8};
6258 #if defined(RELEASE) && !defined(MACINTOSH) // use the code below for mac appletalk games
6259 int network_choose_connect ()
6264 int network_choose_connect ()
6271 if (Network_game_type == IPX_GAME) {
6273 m[opt].type = NM_TYPE_MENU; m[opt].text = "Local Subnet"; opt++;
6274 m[opt].type = NM_TYPE_MENU; m[opt].text = "14.4 modem over Internet"; opt++;
6275 m[opt].type = NM_TYPE_MENU; m[opt].text = "28.8 modem over Internet"; opt++;
6276 m[opt].type = NM_TYPE_MENU; m[opt].text = "ISDN or T1 over Internet"; opt++;
6278 choice = newmenu_do1( NULL, "Choose connection type", opt, m, NULL, 0 );
6283 Assert (choice>=0 && choice<=3);
6285 Netgame.ShortPackets=ConnectionPacketLevel[choice];
6286 Netgame.PacketsPerSec=ConnectionSecLevel[choice];
6291 m[opt].type = NM_TYPE_MENU; m[opt].text = "EtherTalk"; opt++;
6292 m[opt].type = NM_TYPE_MENU; m[opt].text = "LocalTalk"; opt++;
6293 m[opt].type = NM_TYPE_MENU; m[opt].text = "Other"; opt++;
6295 choice = newmenu_do1( NULL, "Choose connection type", opt, m, NULL, 0 );
6300 Network_appletalk_type = choice;
6302 Assert (choice>=0 && choice<=2);
6304 Netgame.ShortPackets=AppletalkConnectionPacketLevel[choice];
6305 Netgame.PacketsPerSec=AppletalkConnectionSecLevel[choice];
6319 SendLogFile=(FILE *)fopen ("sendlog.net","w");
6323 void OpenRecieveLog ()
6326 RecieveLogFile=(FILE *)fopen ("recvlog.net","w");
6332 int GetMyNetRanking ()
6337 if (Netlife_kills+Netlife_killed==0)
6340 rank=(int) (((float)Netlife_kills/3000.0)*8.0);
6342 eff=(int)((float)((float)Netlife_kills/((float)Netlife_killed+(float)Netlife_kills))*100.0);
6351 rank-=((59-eff)/10);
6358 mprintf ((0,"Rank is %d (%s)\n",rank+1,RankStrings[rank+1]));
6362 void ClipRank (signed char *rank)
6364 // This function insures no crashes when dealing with D2 1.0
6367 if (*rank<0 || *rank>9)
6370 void network_check_for_old_version (char pnum)
6372 if (NetPlayers.players[(int)pnum].version_major==1 && (NetPlayers.players[(int)pnum].version_minor & 0x0F)==0)
6373 NetPlayers.players[(int)pnum].rank=0;
6376 void network_request_player_names (int n)
6378 network_send_all_info_request (PID_GAME_PLAYERS,Active_games[n].Security);
6379 NamesInfoSecurity=Active_games[n].Security;
6382 extern char already_showing_info;
6383 extern int newmenu_dotiny2( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem));
6385 void network_process_names_return (char *data)
6388 char mtext[15][50],temp[50];
6389 int i,t,l,gnum,num=0,count=5,numplayers;
6391 if (NamesInfoSecurity!=(*(int *)(data+1)))
6393 mprintf ((0,"Bad security on names return!\n"));
6394 mprintf ((0,"NIS=%d data=%d\n",NamesInfoSecurity,(*(int *)(data+1))));
6398 numplayers=data[count]; count++;
6400 if (numplayers==255)
6403 NamesInfoSecurity=-1;
6404 nm_messagebox(NULL, 1, "OK", "That game is refusing\nname requests.\n");
6409 Assert (numplayers>0 && numplayers<MAX_NUM_NET_PLAYERS);
6413 m[i].text=(char *)&mtext[i];
6414 m[i].type=NM_TYPE_TEXT;
6417 for (gnum=-1,i=0;i<num_active_games;i++)
6419 if (NamesInfoSecurity==Active_games[i].Security)
6429 NamesInfoSecurity=-1;
6430 nm_messagebox(NULL, 1, "OK", "The game you have requested\nnames from is gone.\n");
6435 sprintf (mtext[num],"Players of game '%s':",Active_games[gnum].game_name); num++;
6436 for (i=0;i<numplayers;i++)
6440 mprintf ((0,"%s\n",data+count));
6442 for (t=0;t<CALLSIGN_LEN+1;t++)
6443 temp[t]=data[count++];
6444 if (FindArg("-norankings"))
6445 sprintf (mtext[num],"%s",temp);
6447 sprintf (mtext[num],"%s%s",RankStrings[l],temp);
6452 if (data[count]==99)
6454 sprintf (mtext[num++]," ");
6455 sprintf (mtext[num++],"Short packets: %s",data[count+1]?"On":"Off");
6456 sprintf (mtext[num++],"Packets Per Second: %d",data[count+2]);
6459 already_showing_info=1;
6460 newmenu_dotiny2( NULL, NULL, num, m, NULL);
6461 already_showing_info=0;
6464 char NameReturning=1;
6466 void network_send_player_names (sequence_packet *their)
6468 int numconnected=0,count=0,i,t;
6473 mprintf ((0,"Got a player name without a return address! Get Jason\n"));
6477 buf[0]=PID_NAMES_RETURN; count++;
6478 (*(int *)(buf+1))=Netgame.Security; count+=4;
6482 buf[count]=255; count++;
6486 mprintf ((0,"RealSec=%d DS=%d\n",Netgame.Security,*(int *)(buf+1)));
6488 for (i=0;i<N_players;i++)
6489 if (Players[i].connected)
6492 buf[count]=numconnected; count++;
6493 for (i=0;i<N_players;i++)
6494 if (Players[i].connected)
6496 buf[count++]=NetPlayers.players[i].rank;
6498 for (t=0;t<CALLSIGN_LEN+1;t++)
6500 buf[count]=NetPlayers.players[i].callsign[t];
6506 buf[count++]=Netgame.ShortPackets;
6507 buf[count++]=Netgame.PacketsPerSec;
6510 ; // empty statement allows compilation on mac which does not have the
6511 // statement below and kills the compiler when there is no
6512 // statement following the label "sendit"
6515 ipx_send_internetwork_packet_data((ubyte *)buf, count, their->player.network.ipx.server, their->player.network.ipx.node);
6520 extern int file_exists (char *);
6522 int HoardEquipped ()
6524 static int checked=-1;
6532 if (file_exists ("hoard.ham"))