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-04-19 21:27:00 $
20 * FIXME: put description here
22 * $Log: not supported by cvs2svn $
23 * Revision 1.8 2002/02/14 09:24:19 bradleyb
26 * Revision 1.7 2002/02/13 10:39:21 bradleyb
27 * Lotsa networking stuff from d1x
29 * Revision 1.6 2001/10/23 22:03:03 bradleyb
30 * No longer #ifdef'ing out the whole file. RCS header added
88 #include <Errors.h> // for appletalk networking errors
92 void network_send_rejoin_sync(int player_num);
93 void network_update_netgame(void);
94 void network_read_endlevel_packet( ubyte *data );
95 void network_read_object_packet( ubyte *data );
96 void network_read_sync_packet( netgame_info * sp, int d1x );
98 void network_listen();
99 void network_read_pdata_packet(frame_info *pd );
101 void network_check_for_old_version (char pnum);
102 void network_send_endlevel_short_sub(int from_player_num,int to_player);
103 int network_wait_for_playerinfo();
104 void network_process_pdata (char *data);
105 void network_read_endlevel_short_packet( ubyte *data );
106 void network_ping (ubyte flag,int pnum);
107 void network_handle_ping_return (ubyte pnum);
108 void network_process_names_return (char *data);
109 void network_send_player_names (sequence_packet *their);
110 int network_choose_connect ();
111 void network_more_game_options ();
112 void network_count_powerups_in_mine(void);
113 int network_wait_for_all_info (int choice);
114 void network_do_big_wait(int choice);
115 void network_send_extras ();
116 void network_read_pdata_short_packet(short_frame_info *pd );
118 void network_AdjustMaxDataSize ();
120 void ClipRank (signed char *rank);
121 void DoRefuseStuff (sequence_packet *their);
122 void SetAllAllowablesTo (int on);
123 int GetNewPlayerNumber (sequence_packet *their);
125 #define LHX(x) ((x)*(MenuHires?2:1))
126 #define LHY(y) ((y)*(MenuHires?2.4:1))
128 #define NETSECURITY_OFF 0
129 #define NETSECURITY_WAIT_FOR_PLAYERS 1
130 #define NETSECURITY_WAIT_FOR_GAMEINFO 2
131 #define NETSECURITY_WAIT_FOR_SYNC 3
133 // MWA -- these structures are aligned -- please save me sanity and
134 // headaches by keeping alignment if these are changed!!!! Contact
137 typedef struct endlevel_info_short {
142 } endlevel_info_short;
144 // WARNING!!! This is the top part of netgame_info...if that struct changes,
145 // this struct much change as well. ie...they are aligned and the join system will
146 // not work without it.
148 // MWA if this structure changes -- please make appropriate changes to receive_netgame_info
149 // code for macintosh in netmisc.c
151 typedef struct lite_info {
154 char game_name[NETGAME_NAME_LEN+1];
155 char mission_title[MISSION_NAME_LEN+1];
156 char mission_name[9];
163 ubyte max_numplayers;
166 ubyte protocol_version;
172 // IF YOU CHANGE THE SIZE OF ANY OF THE FOLLOWING STRUCTURES
173 // MAKE THE MACINTOSH DEFINES BE THE SAME SIZE AS THE PC OR
174 // I WILL HAVE TO HURT YOU VERY BADLY!!! -- MWA
177 #define NETGAME_INFO_SIZE ( Network_game_type == IPX_GAME?355:sizeof(netgame_info) )
178 #define ALLNETPLAYERSINFO_SIZE ( Network_game_type == IPX_GAME?317:sizeof(AllNetPlayers_info) )
179 #define LITE_INFO_SIZE ( Network_game_type == IPX_GAME?72:sizeof(lite_info) )
180 #define SEQUENCE_PACKET_SIZE ( Network_game_type == IPX_GAME?34:sizeof(sequence_packet) )
181 #define FRAME_INFO_SIZE ( Network_game_type == IPX_GAME?541:sizeof(frame_info) )
182 #define IPX_SHORT_INFO_SIZE ( 490 )
184 #define NETGAME_INFO_SIZE sizeof(netgame_info)
185 #define ALLNETPLAYERSINFO_SIZE sizeof(AllNetPlayers_info)
186 #define LITE_INFO_SIZE sizeof(lite_info)
187 #define SEQUENCE_PACKET_SIZE sizeof(sequence_packet)
188 #define FRAME_INFO_SIZE sizeof(frame_info)
191 #define MAX_ACTIVE_NETGAMES 12
193 netgame_info Active_games[MAX_ACTIVE_NETGAMES];
194 AllNetPlayers_info ActiveNetPlayers[MAX_ACTIVE_NETGAMES];
195 AllNetPlayers_info *TempPlayersInfo,TempPlayersBase;
196 int NamesInfoSecurity=-1;
198 // MWAnetgame_info *TempNetInfo;
199 netgame_info TempNetInfo;
201 extern void multi_send_drop_marker (int player,vms_vector position,char messagenum,char text[]);
202 extern void multi_send_kill_goal_counts();
203 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) );
205 void network_process_naked_pdata (char *,int);
206 extern void multi_send_robot_controls(char);
208 int num_active_games = 0;
209 int PacketsPerSec=10;
210 int MaxXDataSize=NET_XDATA_SIZE;
212 int Netlife_kills=0, Netlife_killed=0;
215 int Network_active=0;
217 int Network_status = 0;
218 int Network_games_changed = 0;
220 int Network_socket = 0;
221 int Network_allow_socket_changes = 1;
223 int Network_initial_pps = 10;
224 int Network_initial_shortpackets = 0;
226 int NetSecurityFlag=NETSECURITY_OFF;
227 int NetSecurityNum=0;
228 int Network_sending_extras=0;
229 int VerifyPlayerJoined=-1;
230 int Player_joining_extras=-1; // This is so we know who to send 'latecomer' packets to.
231 // We could just send updates to everyone but that kills the sender!
233 // For rejoin object syncing
235 int Network_rejoined = 0; // Did WE rejoin this game?
236 int Network_new_game = 0; // Is this the first level of a new game?
237 int Network_send_objects = 0; // Are we in the process of sending objects to a player?
238 int Network_send_objnum = -1; // What object are we sending next?
239 int Network_player_added = 0; // Is this a new player or a returning player?
240 int Network_send_object_mode = 0; // What type of objects are we sending, static or dynamic?
241 sequence_packet Network_player_rejoining; // Who is rejoining now?
243 fix LastPacketTime[MAX_PLAYERS]; // For timeouts of idle/crashed players
245 int PacketUrgent = 0;
247 int TotalMissedPackets=0,TotalPacketsGot=0;
249 frame_info MySyncPack,UrgentSyncPack;
250 ubyte MySyncPackInitialized = 0; // Set to 1 if the MySyncPack is zeroed.
251 ushort my_segments_checksum = 0;
253 sequence_packet My_Seq;
254 char WantPlayersInfo=0;
255 char WaitingForPlayerInfo=0;
257 char *RankStrings[]={"(unpatched) ","Cadet ","Ensign ","Lieutenant ","Lt.Commander ",
258 "Commander ","Captain ","Vice Admiral ","Admiral ","Demigod "};
260 extern obj_position Player_init[MAX_PLAYERS];
262 extern int force_cockpit_redraw;
264 #define DUMP_CLOSED 0
266 #define DUMP_ENDLEVEL 2
268 #define DUMP_ABORTED 4
269 #define DUMP_CONNECTED 5
271 #define DUMP_KICKED 7
273 extern ubyte Version_major,Version_minor;
274 extern ubyte SurfingNet;
275 extern char MaxPowerupsAllowed[MAX_POWERUP_TYPES];
276 extern char PowerupsInMine[MAX_POWERUP_TYPES];
278 extern void multi_send_stolen_items();
280 int network_wait_for_snyc();
281 extern void multi_send_wall_status (int,ubyte,ubyte,ubyte);
282 extern void multi_send_wall_status_specific (int,int,ubyte,ubyte,ubyte);
284 extern void game_disable_cheats();
287 FILE *SendLogFile,*RecieveLogFile;
288 int TTSent[100],TTRecv[100];
290 extern int Final_boss_is_dead;
292 // following is network stuff for appletalk
294 void network_dump_appletalk_player(ubyte node, ushort net, ubyte socket, int why);
296 #define NETWORK_OEM 0x10
300 int Network_game_type; // used to tell IPX vs. appletalk games
302 #define MAX_ZONES 255
303 #define MAX_ZONE_LENGTH 33
304 #define DEFAULT_ZONE_NAME "\p*"
305 #define MAX_REGISTER_TRIES 5 // maximum time we will try and register a netgame
306 char Network_zone_name[MAX_ZONE_LENGTH]; // zone name game being played in for appletalk
307 char Zone_names[MAX_ZONES][MAX_ZONE_LENGTH]; // total list of zones that we can see
308 ubyte appletalk_use_broadcast = 0;
309 ubyte Network_game_validated = 0; // validates a game before being able to join
310 ubyte Network_game_validate_choice = 0;
311 ubyte Network_appletalk_type = 0; // type of appletalk network game is being played on
313 #define ETHERTALK_TYPE 0
314 #define LOCALTALK_TYPE 1
315 #define OTHERTALK_TYPE 2
318 void network_release_registered_game(void);
326 // So you want to play a netgame, eh? Let's a get a few things
330 int save_pnum = Player_num;
332 game_disable_cheats();
334 Final_boss_is_dead=0;
335 NamesInfoSecurity=-1;
343 for (t=0;t<MAX_POWERUP_TYPES;t++)
345 MaxPowerupsAllowed[t]=0;
349 TotalMissedPackets=0; TotalPacketsGot=0;
351 memset(&Netgame, 0, sizeof(netgame_info));
352 memset(&NetPlayers,0,sizeof(AllNetPlayers_info));
353 memset(&My_Seq, 0, sizeof(sequence_packet));
354 My_Seq.type = PID_REQUEST;
355 memcpy(My_Seq.player.callsign, Players[Player_num].callsign, CALLSIGN_LEN+1);
358 Version_minor|=NETWORK_OEM;
361 My_Seq.player.version_major=Version_major;
362 My_Seq.player.version_minor=Version_minor;
363 My_Seq.player.rank=GetMyNetRanking();
365 if (Network_game_type == IPX_GAME) {
366 memcpy(My_Seq.player.network.ipx.node, ipx_get_my_local_address(), 6);
367 memcpy(My_Seq.player.network.ipx.server, ipx_get_my_server_address(), 4 );
370 My_Seq.player.network.appletalk.node = appletalk_get_my_node();
371 My_Seq.player.network.appletalk.net = appletalk_get_my_net();
372 My_Seq.player.network.appletalk.socket = appletalk_get_my_socket();
376 My_Seq.player.computer_type = MAC;
378 My_Seq.player.computer_type = DOS;
381 for (Player_num = 0; Player_num < MAX_NUM_NET_PLAYERS; Player_num++)
382 init_player_stats_game();
384 Player_num = save_pnum;
386 Network_new_game = 1;
387 Control_center_destroyed = 0;
390 Netgame.PacketsPerSec=10;
392 if ((t=FindArg("-packets")))
394 Netgame.PacketsPerSec=atoi(Args[t+1]);
395 if (Netgame.PacketsPerSec<1)
396 Netgame.PacketsPerSec=1;
397 else if (Netgame.PacketsPerSec>20)
398 Netgame.PacketsPerSec=20;
399 mprintf ((0,"Will send %d packets per second",Netgame.PacketsPerSec));
401 if (FindArg("-shortpackets"))
403 Netgame.ShortPackets=1;
404 mprintf ((0,"Will send short packets.\n"));
409 network_i_am_master(void)
411 // I am the lowest numbered player in this game?
415 if (!(Game_mode & GM_NETWORK))
416 return (Player_num == 0);
418 for (i = 0; i < Player_num; i++)
419 if (Players[i].connected)
424 network_who_is_master(void)
426 // Who is the master of this game?
430 if (!(Game_mode & GM_NETWORK))
431 return (Player_num == 0);
433 for (i = 0; i < N_players; i++)
434 if (Players[i].connected)
438 int network_how_many_connected()
442 for (i = 0; i < N_players; i++)
443 if (Players[i].connected)
448 #define ENDLEVEL_SEND_INTERVAL (F1_0*2)
449 #define ENDLEVEL_IDLE_TIME (F1_0*20)
452 network_endlevel_poll( int nitems, newmenu_item * menus, int * key, int citem )
454 // Polling loop for End-of-level menu
462 int previous_state[MAX_NUM_NET_PLAYERS];
463 int previous_seconds_left;
470 // Send our endlevel packet at regular intervals
472 if (timer_get_approx_seconds() > (t1+ENDLEVEL_SEND_INTERVAL))
474 network_send_endlevel_packet();
475 t1 = timer_get_approx_seconds();
478 for (i = 0; i < N_players; i++)
479 previous_state[i] = Players[i].connected;
481 previous_seconds_left = Countdown_seconds_left;
485 for (i = 0; i < N_players; i++)
487 if (Players[i].connected == 1)
489 // Check timeout for idle players
490 if (timer_get_approx_seconds() > LastPacketTime[i]+ENDLEVEL_IDLE_TIME)
492 mprintf((0, "idle timeout for player %d.\n", i));
493 Players[i].connected = 0;
494 network_send_endlevel_sub(i);
498 if ((Players[i].connected != 1) && (Players[i].connected != 5) && (Players[i].connected != 6))
500 if (Players[i].connected != 1)
502 if (Players[i].connected == 4)
506 if (num_escaped == N_players) // All players are out of the mine
508 Countdown_seconds_left = -1;
512 if (num_ready == N_players) // All players have checked in or are disconnected
522 network_endlevel_poll2( int nitems, newmenu_item * menus, int * key, int citem )
524 // Polling loop for End-of-level menu
536 // Send our endlevel packet at regular intervals
538 if (timer_get_approx_seconds() > (t1+ENDLEVEL_SEND_INTERVAL))
540 network_send_endlevel_packet();
541 t1 = timer_get_approx_seconds();
544 // mprintf ((0,"Trying to listen!\n"));
547 for (i = 0; i < N_players; i++)
549 if ((Players[i].connected != 1) && (Players[i].connected != 5) && (Players[i].connected != 6))
551 if (Players[i].connected == 4)
555 if (num_ready == N_players) // All players have checked in or are disconnected
565 extern fix StartAbortMenuTime;
568 network_endlevel_poll3( int nitems, newmenu_item * menus, int * key, int citem )
570 // Polling loop for End-of-level menu
579 if (timer_get_approx_seconds() > (StartAbortMenuTime+(F1_0 * 8)))
586 for (i = 0; i < N_players; i++)
587 if ((Players[i].connected != 1) && (Players[i].connected != 5) && (Players[i].connected != 6))
590 if (num_ready == N_players) // All players have checked in or are disconnected
597 network_endlevel(int *secret)
599 // Do whatever needs to be done between levels
607 Network_status = NETSTAT_ENDLEVEL; // We are between levels
611 network_send_endlevel_packet();
613 for (i=0; i<N_players; i++)
615 LastPacketTime[i] = timer_get_approx_seconds();
618 network_send_endlevel_packet();
619 network_send_endlevel_packet();
620 MySyncPackInitialized = 0;
622 network_update_netgame();
628 can_join_netgame(netgame_info *game,AllNetPlayers_info *people)
630 // Can this player rejoin a netgame in progress?
634 if (game->game_status == NETSTAT_STARTING)
637 if (game->game_status != NETSTAT_PLAYING)
639 mprintf ((0,"Error: Can't join because game_status !=NETSTAT_PLAYING\n"));
643 if (game->version_major==0 && Version_major>0)
645 mprintf ((0,"Error:Can't join because version majors don't match!\n"));
649 if (game->version_major>0 && Version_major==0)
651 mprintf ((0,"Error:Can't join because version majors2 don't match!\n"));
655 // Game is in progress, figure out if this guy can re-join it
657 num_players = game->numplayers;
659 if (!(game->game_flags & NETGAME_FLAG_CLOSED)) {
660 // Look for player that is not connected
662 if (game->numconnected==game->max_numplayers)
665 // mprintf ((0,"Refuse = %d\n",game->RefusePlayers));
667 if (game->RefusePlayers)
670 if (game->numplayers < game->max_numplayers)
673 if (game->numconnected<num_players)
680 mprintf ((0,"Error! Can't join because people==NULL!\n"));
684 // Search to see if we were already in this closed netgame in progress
686 for (i = 0; i < num_players; i++) {
687 if (Network_game_type == IPX_GAME) {
688 if ( (!stricmp(Players[Player_num].callsign, people->players[i].callsign)) &&
689 (!memcmp(My_Seq.player.network.ipx.node, people->players[i].network.ipx.node, 6)) &&
690 (!memcmp(My_Seq.player.network.ipx.server, people->players[i].network.ipx.server, 4)) )
693 if ( (!stricmp(Players[Player_num].callsign, people->players[i].callsign)) &&
694 (My_Seq.player.network.appletalk.node == people->players[i].network.appletalk.node) &&
695 (My_Seq.player.network.appletalk.net == people->players[i].network.appletalk.net) )
700 if (i != num_players)
703 mprintf ((0,"Error: Can't join because at end of list!\n"));
708 network_disconnect_player(int playernum)
710 // A player has disconnected from the net game, take whatever steps are
713 if (playernum == Player_num)
715 Int3(); // Weird, see Rob
719 Players[playernum].connected = 0;
720 NetPlayers.players[playernum].connected = 0;
721 if (VerifyPlayerJoined==playernum)
722 VerifyPlayerJoined=-1;
724 // create_player_appearance_effect(&Objects[Players[playernum].objnum]);
725 multi_make_player_ghost(playernum);
727 if (Newdemo_state == ND_STATE_RECORDING)
728 newdemo_record_multi_disconnect(playernum);
730 multi_strip_robots(playernum);
734 network_new_player(sequence_packet *their)
739 pnum = their->player.connected;
742 Assert(pnum < MaxNumNetPlayers);
744 objnum = Players[pnum].objnum;
746 if (Newdemo_state == ND_STATE_RECORDING) {
749 if (pnum == N_players)
753 newdemo_record_multi_connect(pnum, new_player, their->player.callsign);
756 memcpy(Players[pnum].callsign, their->player.callsign, CALLSIGN_LEN+1);
757 memcpy(NetPlayers.players[pnum].callsign, their->player.callsign, CALLSIGN_LEN+1);
760 ClipRank (&their->player.rank);
761 NetPlayers.players[pnum].rank=their->player.rank;
762 NetPlayers.players[pnum].version_major=their->player.version_major;
763 NetPlayers.players[pnum].version_minor=their->player.version_minor;
764 network_check_for_old_version(pnum);
766 if (Network_game_type == IPX_GAME) {
767 if ( (*(uint *)their->player.network.ipx.server) != 0 )
768 ipx_get_local_target( their->player.network.ipx.server, their->player.network.ipx.node, Players[pnum].net_address );
770 memcpy(Players[pnum].net_address, their->player.network.ipx.node, 6);
772 memcpy(NetPlayers.players[pnum].network.ipx.node, their->player.network.ipx.node, 6);
773 memcpy(NetPlayers.players[pnum].network.ipx.server, their->player.network.ipx.server, 4);
775 NetPlayers.players[pnum].network.appletalk.node = their->player.network.appletalk.node;
776 NetPlayers.players[pnum].network.appletalk.net = their->player.network.appletalk.net;
777 NetPlayers.players[pnum].network.appletalk.socket = their->player.network.appletalk.socket;
780 Players[pnum].n_packets_got = 0;
781 Players[pnum].connected = 1;
782 Players[pnum].net_kills_total = 0;
783 Players[pnum].net_killed_total = 0;
784 memset(kill_matrix[pnum], 0, MAX_PLAYERS*sizeof(short));
785 Players[pnum].score = 0;
786 Players[pnum].flags = 0;
787 Players[pnum].KillGoalCount=0;
789 if (pnum == N_players)
792 Netgame.numplayers = N_players;
795 digi_play_sample(SOUND_HUD_MESSAGE, F1_0);
797 ClipRank (&their->player.rank);
799 if (FindArg("-norankings"))
800 HUD_init_message("'%s' %s\n",their->player.callsign, TXT_JOINING);
802 HUD_init_message("%s'%s' %s\n",RankStrings[their->player.rank],their->player.callsign, TXT_JOINING);
804 multi_make_ghost_player(pnum);
807 multi_sort_kill_list();
809 // create_player_appearance_effect(&Objects[objnum]);
812 char RefuseThisPlayer=0,WaitForRefuseAnswer=0,RefuseTeam;
813 char RefusePlayerName[12];
814 fix RefuseTimeLimit=0;
816 void network_welcome_player(sequence_packet *their)
818 // Add a player to a game already in progress
819 ubyte local_address[6];
823 WaitForRefuseAnswer=0;
825 if (FindArg("-NoMatrixCheat"))
827 if (their->player.version_minor & (0x0F<3))
829 network_dump_player(their->player.network.ipx.server, their->player.network.ipx.node, DUMP_DORK);
836 // If hoard game, and this guy isn't D2 Christmas (v1.2), dump him
838 if ((Game_mode & GM_HOARD) && ((their->player.version_minor & 0x0F)<2))
840 if (Network_game_type == IPX_GAME)
841 network_dump_player(their->player.network.ipx.server, their->player.network.ipx.node, DUMP_DORK);
844 network_dump_appletalk_player(their->player.network.appletalk.node, their->player.network.appletalk.net, their->player.network.appletalk.socket, DUMP_DORK);
850 // Don't accept new players if we're ending this level. Its safe to
851 // ignore since they'll request again later
853 if ((Endlevel_sequence) || (Control_center_destroyed))
855 mprintf((0, "Ignored request from new player to join during endgame.\n"));
856 if (Network_game_type == IPX_GAME)
857 network_dump_player(their->player.network.ipx.server,their->player.network.ipx.node, DUMP_ENDLEVEL);
860 network_dump_appletalk_player(their->player.network.appletalk.node, their->player.network.appletalk.net, their->player.network.appletalk.socket, DUMP_ENDLEVEL);
865 if (Network_send_objects || Network_sending_extras)
867 // Ignore silently, we're already responding to someone and we can't
868 // do more than one person at a time. If we don't dump them they will
869 // re-request in a few seconds.
873 if (their->player.connected != Current_level_num)
875 mprintf((0, "Dumping player due to old level number.\n"));
876 if (Network_game_type == IPX_GAME)
877 network_dump_player(their->player.network.ipx.server, their->player.network.ipx.node, DUMP_LEVEL);
880 network_dump_appletalk_player(their->player.network.appletalk.node, their->player.network.appletalk.net, their->player.network.appletalk.socket, DUMP_LEVEL);
886 memset(&Network_player_rejoining, 0, sizeof(sequence_packet));
887 Network_player_added = 0;
889 if (Network_game_type == IPX_GAME) {
890 if ( (*(uint *)their->player.network.ipx.server) != 0 )
891 ipx_get_local_target( their->player.network.ipx.server, their->player.network.ipx.node, local_address );
893 memcpy(local_address, their->player.network.ipx.node, 6);
896 for (i = 0; i < N_players; i++)
898 if ( (Network_game_type == IPX_GAME) && (!stricmp(Players[i].callsign, their->player.callsign )) && (!memcmp(Players[i].net_address,local_address, 6)) )
903 #ifdef MACINTOSH // note link to above if
904 else if ( (!stricmp(Players[i].callsign, their->player.callsign)) &&
905 (NetPlayers.players[i].network.appletalk.node == their->player.network.appletalk.node) &&
906 (NetPlayers.players[i].network.appletalk.net == their->player.network.appletalk.net)) {
913 if (player_num == -1)
915 // Player is new to this game
917 if ( !(Netgame.game_flags & NETGAME_FLAG_CLOSED) && (N_players < MaxNumNetPlayers))
919 // Add player in an open slot, game not full yet
921 player_num = N_players;
922 Network_player_added = 1;
924 else if (Netgame.game_flags & NETGAME_FLAG_CLOSED)
926 // Slots are open but game is closed
928 if (Network_game_type == IPX_GAME)
929 network_dump_player(their->player.network.ipx.server, their->player.network.ipx.node, DUMP_CLOSED);
932 network_dump_appletalk_player(their->player.network.appletalk.node, their->player.network.appletalk.net, their->player.network.appletalk.socket, DUMP_CLOSED);
938 // Slots are full but game is open, see if anyone is
939 // disconnected and replace the oldest player with this new one
941 int oldest_player = -1;
942 fix oldest_time = timer_get_approx_seconds();
944 Assert(N_players == MaxNumNetPlayers);
946 for (i = 0; i < N_players; i++)
948 if ( (!Players[i].connected) && (LastPacketTime[i] < oldest_time))
950 oldest_time = LastPacketTime[i];
955 if (oldest_player == -1)
957 // Everyone is still connected
959 if (Network_game_type == IPX_GAME)
960 network_dump_player(their->player.network.ipx.server, their->player.network.ipx.node, DUMP_FULL);
963 network_dump_appletalk_player(their->player.network.appletalk.node, their->player.network.appletalk.net, their->player.network.appletalk.socket, DUMP_FULL);
971 player_num = oldest_player;
972 Network_player_added = 1;
978 // Player is reconnecting
980 if (Players[player_num].connected)
982 mprintf((0, "Extra REQUEST from player ignored.\n"));
986 if (Newdemo_state == ND_STATE_RECORDING)
987 newdemo_record_multi_reconnect(player_num);
989 Network_player_added = 0;
991 digi_play_sample(SOUND_HUD_MESSAGE, F1_0);
993 if (FindArg("-norankings"))
994 HUD_init_message("'%s' %s", Players[player_num].callsign, TXT_REJOIN);
996 HUD_init_message("%s'%s' %s", RankStrings[NetPlayers.players[player_num].rank],Players[player_num].callsign, TXT_REJOIN);
999 Players[player_num].KillGoalCount=0;
1001 // Send updated Objects data to the new/returning player
1004 Network_player_rejoining = *their;
1005 Network_player_rejoining.player.connected = player_num;
1006 Network_send_objects = 1;
1007 Network_send_objnum = -1;
1009 network_send_objects();
1012 int network_objnum_is_past(int objnum)
1014 // determine whether or not a given object number has already been sent
1015 // to a re-joining player.
1017 int player_num = Network_player_rejoining.player.connected;
1018 int obj_mode = !((object_owner[objnum] == -1) || (object_owner[objnum] == player_num));
1020 if (!Network_send_objects)
1021 return 0; // We're not sending objects to a new player
1023 if (obj_mode > Network_send_object_mode)
1025 else if (obj_mode < Network_send_object_mode)
1027 else if (objnum < Network_send_objnum)
1033 #define OBJ_PACKETS_PER_FRAME 1
1034 extern void multi_send_active_door(char);
1035 extern void multi_send_door_open_specific(int,int,int,ubyte);
1038 void network_send_door_updates(int pnum)
1040 // Send door status when new player joins
1046 // Assert (pnum>-1 && pnum<N_players);
1048 for (i = 0; i < Num_walls; i++)
1050 if ((Walls[i].type == WALL_DOOR) && ((Walls[i].state == WALL_DOOR_OPENING) || (Walls[i].state == WALL_DOOR_WAITING) || (Walls[i].state == WALL_DOOR_OPEN)))
1051 multi_send_door_open_specific(pnum,Walls[i].segnum, Walls[i].sidenum,Walls[i].flags);
1052 else if ((Walls[i].type == WALL_BLASTABLE) && (Walls[i].flags & WALL_BLASTED))
1053 multi_send_door_open_specific(pnum,Walls[i].segnum, Walls[i].sidenum,Walls[i].flags);
1054 else if ((Walls[i].type == WALL_BLASTABLE) && (Walls[i].hps != WALL_HPS))
1055 multi_send_hostage_door_status(i);
1057 multi_send_wall_status_specific(pnum,i,Walls[i].type,Walls[i].flags,Walls[i].state);
1061 extern vms_vector MarkerPoint[];
1062 void network_send_markers()
1064 // send marker positions/text to new player
1071 if (MarkerObject[(i*2)]!=-1)
1072 multi_send_drop_marker (i,MarkerPoint[(i*2)],0,MarkerMessage[i*2]);
1073 if (MarkerObject[(i*2)+1]!=-1)
1074 multi_send_drop_marker (i,MarkerPoint[(i*2)+1],1,MarkerMessage[(i*2)+1]);
1078 void network_process_monitor_vector(int vector)
1084 for (i=0; i <= Highest_segment_index; i++)
1088 for (j = 0; j < 6; j++)
1090 if ( ((tm = seg->sides[j].tmap_num2) != 0) &&
1091 ((ec = TmapInfo[tm&0x3fff].eclip_num) != -1) &&
1092 ((bm = Effects[ec].dest_bm_num) != -1) )
1094 if (vector & (1 << count))
1096 seg->sides[j].tmap_num2 = bm | (tm&0xc000);
1097 // mprintf((0, "Monitor %d blown up.\n", count));
1100 // mprintf((0, "Monitor %d intact.\n", count));
1108 int network_create_monitor_vector(void)
1111 int num_blown_bitmaps = 0;
1112 int monitor_num = 0;
1113 #define NUM_BLOWN_BITMAPS 20
1114 int blown_bitmaps[NUM_BLOWN_BITMAPS];
1118 for (i=0; i < Num_effects; i++)
1120 if (Effects[i].dest_bm_num > 0) {
1121 for (j = 0; j < num_blown_bitmaps; j++)
1122 if (blown_bitmaps[j] == Effects[i].dest_bm_num)
1124 if (j == num_blown_bitmaps) {
1125 blown_bitmaps[num_blown_bitmaps++] = Effects[i].dest_bm_num;
1126 Assert(num_blown_bitmaps < NUM_BLOWN_BITMAPS);
1131 // for (i = 0; i < num_blown_bitmaps; i++)
1132 // mprintf((0, "Blown bitmap #%d = %d.\n", i, blown_bitmaps[i]));
1134 for (i=0; i <= Highest_segment_index; i++)
1138 for (j = 0; j < 6; j++)
1140 if ((tm = seg->sides[j].tmap_num2) != 0)
1142 if ( ((ec = TmapInfo[tm&0x3fff].eclip_num) != -1) &&
1143 (Effects[ec].dest_bm_num != -1) )
1145 // mprintf((0, "Monitor %d intact.\n", monitor_num));
1147 Assert(monitor_num < 32);
1151 for (k = 0; k < num_blown_bitmaps; k++)
1153 if ((tm&0x3fff) == blown_bitmaps[k])
1155 //mprintf((0, "Monitor %d destroyed.\n", monitor_num));
1156 vector |= (1 << monitor_num);
1158 Assert(monitor_num < 32);
1166 // mprintf((0, "Final monitor vector %x.\n", vector));
1170 void network_stop_resync(sequence_packet *their)
1172 if (Network_game_type == IPX_GAME) {
1173 if ( (!memcmp(Network_player_rejoining.player.network.ipx.node, their->player.network.ipx.node, 6)) &&
1174 (!memcmp(Network_player_rejoining.player.network.ipx.server, their->player.network.ipx.server, 4)) &&
1175 (!stricmp(Network_player_rejoining.player.callsign, their->player.callsign)) )
1177 mprintf((0, "Aborting resync for player %s.\n", their->player.callsign));
1178 Network_send_objects = 0;
1179 Network_sending_extras=0;
1181 Player_joining_extras=-1;
1182 Network_send_objnum = -1;
1185 if ( (Network_player_rejoining.player.network.appletalk.node == their->player.network.appletalk.node) &&
1186 (Network_player_rejoining.player.network.appletalk.net == their->player.network.appletalk.net) &&
1187 (!stricmp(Network_player_rejoining.player.callsign, their->player.callsign)) )
1189 mprintf((0, "Aborting resync for player %s.\n", their->player.callsign));
1190 Network_send_objects = 0;
1191 Network_sending_extras=0;
1193 Player_joining_extras=-1;
1194 Network_send_objnum = -1;
1199 byte object_buffer[IPX_MAX_DATA_SIZE];
1201 void network_send_objects(void)
1203 short remote_objnum;
1207 static int obj_count = 0;
1208 static int frame_num = 0;
1210 int obj_count_frame = 0;
1211 int player_num = Network_player_rejoining.player.connected;
1213 // Send clear objects array trigger and send player num
1215 Assert(Network_send_objects != 0);
1216 Assert(player_num >= 0);
1217 Assert(player_num < MaxNumNetPlayers);
1219 if (Endlevel_sequence || Control_center_destroyed)
1221 // Endlevel started before we finished sending the goods, we'll
1222 // have to stop and try again after the level.
1224 if (Network_game_type == IPX_GAME)
1225 network_dump_player(Network_player_rejoining.player.network.ipx.server,Network_player_rejoining.player.network.ipx.node, DUMP_ENDLEVEL);
1228 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);
1230 Network_send_objects = 0;
1234 for (h = 0; h < OBJ_PACKETS_PER_FRAME; h++) // Do more than 1 per frame, try to speed it up without
1235 // over-stressing the receiver.
1237 obj_count_frame = 0;
1238 memset(object_buffer, 0, IPX_MAX_DATA_SIZE);
1239 object_buffer[0] = PID_OBJECT_DATA;
1242 if (Network_send_objnum == -1)
1245 Network_send_object_mode = 0;
1246 // mprintf((0, "Sending object array to player %d.\n", player_num));
1247 *(short *)(object_buffer+loc) = INTEL_SHORT(-1); loc += 2;
1248 object_buffer[loc] = player_num; loc += 1;
1249 loc += 2; // Placeholder for remote_objnum, not used here
1250 Network_send_objnum = 0;
1251 obj_count_frame = 1;
1255 for (i = Network_send_objnum; i <= Highest_object_index; i++)
1257 if ((Objects[i].type != OBJ_POWERUP) && (Objects[i].type != OBJ_PLAYER) &&
1258 (Objects[i].type != OBJ_CNTRLCEN) && (Objects[i].type != OBJ_GHOST) &&
1259 (Objects[i].type != OBJ_ROBOT) && (Objects[i].type != OBJ_HOSTAGE) &&
1260 !(Objects[i].type==OBJ_WEAPON && Objects[i].id==PMINE_ID))
1262 if ((Network_send_object_mode == 0) && ((object_owner[i] != -1) && (object_owner[i] != player_num)))
1264 if ((Network_send_object_mode == 1) && ((object_owner[i] == -1) || (object_owner[i] == player_num)))
1267 if ( ((IPX_MAX_DATA_SIZE-1) - loc) < (sizeof(object)+5) )
1268 break; // Not enough room for another object
1273 remote_objnum = objnum_local_to_remote((short)i, &owner);
1274 Assert(owner == object_owner[i]);
1276 *(short *)(object_buffer+loc) = INTEL_SHORT((short)i); loc += 2;
1277 object_buffer[loc] = owner; loc += 1;
1278 *(short *)(object_buffer+loc) = INTEL_SHORT(remote_objnum); loc += 2;
1280 memcpy(object_buffer+loc, &Objects[i], sizeof(object)); loc += sizeof(object);
1282 if (Network_game_type == IPX_GAME) {
1285 memcpy(&tmpobj, &(Objects[i]), sizeof(object));
1286 swap_object(&tmpobj);
1287 memcpy(&(object_buffer[loc]), &tmpobj, sizeof(object)); loc += sizeof(object);
1290 memcpy(object_buffer+loc, &Objects[i], sizeof(object)); loc += sizeof(object);
1292 // mprintf((0, "..packing object %d, remote %d\n", i, remote_objnum));
1295 if (obj_count_frame) // Send any objects we've buffered
1299 Network_send_objnum = i;
1300 object_buffer[1] = obj_count_frame; object_buffer[2] = frame_num;
1301 // mprintf((0, "Object packet %d contains %d objects.\n", frame_num, obj_count_frame));
1303 Assert(loc <= IPX_MAX_DATA_SIZE);
1305 if (Network_game_type == IPX_GAME)
1306 ipx_send_internetwork_packet_data( object_buffer, loc, Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node );
1309 appletalk_send_packet_data( object_buffer, loc, Network_player_rejoining.player.network.appletalk.node,
1310 Network_player_rejoining.player.network.appletalk.net,
1311 Network_player_rejoining.player.network.appletalk.socket);
1314 // OLD ipx_send_packet_data(object_buffer, loc, &Network_player_rejoining.player.node);
1317 if (i > Highest_object_index)
1319 if (Network_send_object_mode == 0)
1321 Network_send_objnum = 0;
1322 Network_send_object_mode = 1; // go to next mode
1326 Assert(Network_send_object_mode == 1);
1329 // Send count so other side can make sure he got them all
1330 // mprintf((0, "Sending end marker in packet #%d.\n", frame_num));
1331 mprintf((0, "Sent %d objects.\n", obj_count));
1332 object_buffer[0] = PID_OBJECT_DATA;
1333 object_buffer[1] = 1;
1334 object_buffer[2] = frame_num;
1335 *(short *)(object_buffer+3) = INTEL_SHORT(-2);
1336 *(short *)(object_buffer+6) = INTEL_SHORT(obj_count);
1337 //OLD ipx_send_packet_data(object_buffer, 8, &Network_player_rejoining.player.node);
1338 if (Network_game_type == IPX_GAME)
1339 ipx_send_internetwork_packet_data(object_buffer, 8, Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node);
1342 appletalk_send_packet_data( object_buffer, 8, Network_player_rejoining.player.network.appletalk.node,
1343 Network_player_rejoining.player.network.appletalk.net,
1344 Network_player_rejoining.player.network.appletalk.socket);
1348 // Send sync packet which tells the player who he is and to start!
1349 network_send_rejoin_sync(player_num);
1350 mprintf ((0,"VerfiyPlayerJoined is now set to %d\n",player_num));
1351 VerifyPlayerJoined=player_num;
1353 // Turn off send object mode
1354 Network_send_objnum = -1;
1355 Network_send_objects = 0;
1358 //if (!network_i_am_master ())
1359 // Int3(); // Bad!! Get Jason. Someone goofy is trying to get ahold of the game!
1361 Network_sending_extras=40; // start to send extras
1362 Player_joining_extras=player_num;
1366 } // i > Highest_object_index
1367 } // For PACKETS_PER_FRAME
1370 extern void multi_send_powerup_update();
1372 void network_send_rejoin_sync(int player_num)
1376 Players[player_num].connected = 1; // connect the new guy
1377 LastPacketTime[player_num] = timer_get_approx_seconds();
1379 if (Endlevel_sequence || Control_center_destroyed)
1381 // Endlevel started before we finished sending the goods, we'll
1382 // have to stop and try again after the level.
1384 if (Network_game_type == IPX_GAME)
1385 network_dump_player(Network_player_rejoining.player.network.ipx.server,Network_player_rejoining.player.network.ipx.node, DUMP_ENDLEVEL);
1388 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);
1390 Network_send_objects = 0;
1391 Network_sending_extras=0;
1395 if (Network_player_added)
1397 Network_player_rejoining.type = PID_ADDPLAYER;
1398 Network_player_rejoining.player.connected = player_num;
1399 network_new_player(&Network_player_rejoining);
1401 for (i = 0; i < N_players; i++)
1403 if ((i != player_num) && (i != Player_num) && (Players[i].connected))
1404 if (Network_game_type == IPX_GAME) {
1406 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);
1408 send_sequence_packet( Network_player_rejoining, NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node, Players[i].net_address);
1412 appletalk_send_packet_data( (ubyte *)&Network_player_rejoining, sizeof(sequence_packet), NetPlayers.players[i].network.appletalk.node,
1413 NetPlayers.players[i].network.appletalk.net, NetPlayers.players[i].network.appletalk.socket);
1419 // Send sync packet to the new guy
1421 network_update_netgame();
1423 // Fill in the kill list
1424 for (j=0; j<MAX_PLAYERS; j++)
1426 for (i=0; i<MAX_PLAYERS;i++)
1427 Netgame.kills[j][i] = kill_matrix[j][i];
1428 Netgame.killed[j] = Players[j].net_killed_total;
1429 Netgame.player_kills[j] = Players[j].net_kills_total;
1430 Netgame.player_score[j] = Players[j].score;
1433 Netgame.level_time = Players[Player_num].time_level;
1434 Netgame.monitor_vector = network_create_monitor_vector();
1436 mprintf((0, "Sending rejoin sync packet!!!\n"));
1438 if (Network_game_type == IPX_GAME) {
1440 ipx_send_internetwork_packet_data( (ubyte *)&Netgame, sizeof(netgame_info), Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node );
1441 ipx_send_internetwork_packet_data( (ubyte *)&NetPlayers, sizeof(AllNetPlayers_info), Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node );
1443 send_netgame_packet(Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node, NULL, 0);
1444 send_netplayers_packet(Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node);
1448 appletalk_send_packet_data( (ubyte *)&Netgame, sizeof(netgame_info), Network_player_rejoining.player.network.appletalk.node,
1449 Network_player_rejoining.player.network.appletalk.net,
1450 Network_player_rejoining.player.network.appletalk.socket);
1451 appletalk_send_packet_data( (ubyte *)&NetPlayers, sizeof(AllNetPlayers_info), Network_player_rejoining.player.network.appletalk.node,
1452 Network_player_rejoining.player.network.appletalk.net,
1453 Network_player_rejoining.player.network.appletalk.socket);
1458 void resend_sync_due_to_packet_loss_for_allender ()
1462 mprintf ((0,"I'm resending a sync packet! VPJ=%d\n",VerifyPlayerJoined));
1464 network_update_netgame();
1466 // Fill in the kill list
1467 for (j=0; j<MAX_PLAYERS; j++)
1469 for (i=0; i<MAX_PLAYERS;i++)
1470 Netgame.kills[j][i] = kill_matrix[j][i];
1471 Netgame.killed[j] = Players[j].net_killed_total;
1472 Netgame.player_kills[j] = Players[j].net_kills_total;
1473 Netgame.player_score[j] = Players[j].score;
1476 Netgame.level_time = Players[Player_num].time_level;
1477 Netgame.monitor_vector = network_create_monitor_vector();
1479 if (Network_game_type == IPX_GAME) {
1481 ipx_send_internetwork_packet_data( (ubyte *)&Netgame, sizeof(netgame_info), Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node );
1482 ipx_send_internetwork_packet_data( (ubyte *)&NetPlayers, sizeof(AllNetPlayers_info), Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node );
1484 send_netgame_packet(Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node, NULL, 0);
1485 send_netplayers_packet(Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node);
1489 appletalk_send_packet_data( (ubyte *)&Netgame, sizeof(netgame_info), Network_player_rejoining.player.network.appletalk.node,
1490 Network_player_rejoining.player.network.appletalk.net,
1491 Network_player_rejoining.player.network.appletalk.socket);
1492 appletalk_send_packet_data( (ubyte *)&NetPlayers, sizeof(AllNetPlayers_info), Network_player_rejoining.player.network.appletalk.node,
1493 Network_player_rejoining.player.network.appletalk.net,
1494 Network_player_rejoining.player.network.appletalk.socket);
1500 char * network_get_player_name( int objnum )
1502 if ( objnum < 0 ) return NULL;
1503 if ( Objects[objnum].type != OBJ_PLAYER ) return NULL;
1504 if ( Objects[objnum].id >= MAX_PLAYERS ) return NULL;
1505 if ( Objects[objnum].id >= N_players ) return NULL;
1507 return Players[Objects[objnum].id].callsign;
1511 void network_add_player(sequence_packet *p)
1515 mprintf((0, "Got add player request!\n"));
1517 for (i=0; i<N_players; i++ ) {
1518 if (Network_game_type == IPX_GAME) {
1519 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))
1520 return; // already got them
1522 if ( (NetPlayers.players[i].network.appletalk.node == p->player.network.appletalk.node) &&
1523 (NetPlayers.players[i].network.appletalk.net == p->player.network.appletalk.net))
1528 if (Network_game_type == IPX_GAME) {
1529 memcpy( NetPlayers.players[N_players].network.ipx.node, p->player.network.ipx.node, 6 );
1530 memcpy( NetPlayers.players[N_players].network.ipx.server, p->player.network.ipx.server, 4 );
1532 NetPlayers.players[N_players].network.appletalk.node = p->player.network.appletalk.node;
1533 NetPlayers.players[N_players].network.appletalk.net = p->player.network.appletalk.net;
1534 NetPlayers.players[N_players].network.appletalk.socket = p->player.network.appletalk.socket;
1537 ClipRank (&p->player.rank);
1539 memcpy( NetPlayers.players[N_players].callsign, p->player.callsign, CALLSIGN_LEN+1 );
1540 NetPlayers.players[N_players].version_major=p->player.version_major;
1541 NetPlayers.players[N_players].version_minor=p->player.version_minor;
1542 NetPlayers.players[N_players].rank=p->player.rank;
1543 NetPlayers.players[N_players].connected = 1;
1544 network_check_for_old_version (N_players);
1546 Players[N_players].KillGoalCount=0;
1547 Players[N_players].connected = 1;
1548 LastPacketTime[N_players] = timer_get_approx_seconds();
1550 Netgame.numplayers = N_players;
1552 // Broadcast updated info
1554 mprintf ((0,"sending_game_info!\n"));
1555 network_send_game_info(NULL);
1558 // One of the players decided not to join the game
1560 void network_remove_player(sequence_packet *p)
1565 for (i=0; i<N_players; i++ ) {
1566 if (Network_game_type == IPX_GAME) {
1567 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)) {
1572 if ( (NetPlayers.players[i].network.appletalk.node == p->player.network.appletalk.node) && (NetPlayers.players[i].network.appletalk.net == p->player.network.appletalk.net) ) {
1579 if (pn < 0 ) return;
1581 for (i=pn; i<N_players-1; i++ ) {
1582 if (Network_game_type == IPX_GAME) {
1583 memcpy( NetPlayers.players[i].network.ipx.node, NetPlayers.players[i+1].network.ipx.node, 6 );
1584 memcpy( NetPlayers.players[i].network.ipx.server, NetPlayers.players[i+1].network.ipx.server, 4 );
1586 NetPlayers.players[i].network.appletalk.node = NetPlayers.players[i+1].network.appletalk.node;
1587 NetPlayers.players[i].network.appletalk.net = NetPlayers.players[i+1].network.appletalk.net;
1588 NetPlayers.players[i].network.appletalk.socket = NetPlayers.players[i+1].network.appletalk.socket;
1590 memcpy( NetPlayers.players[i].callsign, NetPlayers.players[i+1].callsign, CALLSIGN_LEN+1 );
1591 NetPlayers.players[i].version_major=NetPlayers.players[i+1].version_major;
1592 NetPlayers.players[i].version_minor=NetPlayers.players[i+1].version_minor;
1594 NetPlayers.players[i].rank=NetPlayers.players[i+1].rank;
1595 ClipRank (&NetPlayers.players[i].rank);
1596 network_check_for_old_version(i);
1600 Netgame.numplayers = N_players;
1602 // Broadcast new info
1604 network_send_game_info(NULL);
1609 network_dump_player(ubyte * server, ubyte *node, int why)
1611 // Inform player that he was not chosen for the netgame
1613 sequence_packet temp;
1615 temp.type = PID_DUMP;
1616 memcpy(temp.player.callsign, Players[Player_num].callsign, CALLSIGN_LEN+1);
1617 temp.player.connected = why;
1618 if (Network_game_type == IPX_GAME) {
1620 ipx_send_internetwork_packet_data( (ubyte *)&temp, sizeof(sequence_packet), server, node);
1622 send_sequence_packet( temp, server, node, NULL);
1630 void network_dump_appletalk_player(ubyte node, ushort net, ubyte socket, int why)
1632 sequence_packet temp;
1634 temp.type = PID_DUMP;
1635 memcpy(temp.player.callsign, Players[Player_num].callsign, CALLSIGN_LEN+1);
1636 temp.player.connected = why;
1637 if (Network_game_type == APPLETALK_GAME) {
1638 appletalk_send_packet_data( (ubyte *)&temp, sizeof(sequence_packet), node, net, socket );
1646 network_send_game_list_request()
1648 // Send a broadcast request for game info
1652 mprintf((0, "Sending game_list request.\n"));
1653 me.type = PID_GAME_LIST;
1654 memcpy( me.player.callsign, Players[Player_num].callsign, CALLSIGN_LEN+1 );
1656 if (Network_game_type == IPX_GAME) {
1657 memcpy( me.player.network.ipx.node, ipx_get_my_local_address(), 6 );
1658 memcpy( me.player.network.ipx.server, ipx_get_my_server_address(), 4 );
1661 ipx_send_broadcast_packet_data( (ubyte *)&me, sizeof(sequence_packet) );
1663 send_sequence_packet( me, NULL, NULL, NULL);
1667 me.player.network.appletalk.node = appletalk_get_my_node();
1668 me.player.network.appletalk.net = appletalk_get_my_net();
1669 me.player.network.appletalk.socket = appletalk_get_my_socket();
1670 appletalk_send_game_info( (ubyte *)&me, sizeof(sequence_packet), Network_zone_name );
1675 void network_send_all_info_request(char type,int which_security)
1677 // Send a broadcast request for game info
1681 mprintf((0, "Sending all_info request.\n"));
1683 me.Security=which_security;
1685 memcpy( me.player.callsign, Players[Player_num].callsign, CALLSIGN_LEN+1 );
1687 if (Network_game_type == IPX_GAME) {
1688 memcpy( me.player.network.ipx.node, ipx_get_my_local_address(), 6 );
1689 memcpy( me.player.network.ipx.server, ipx_get_my_server_address(), 4 );
1692 ipx_send_broadcast_packet_data( (ubyte *)&me, sizeof(sequence_packet) );
1694 send_sequence_packet(me, NULL, NULL, NULL);
1698 me.player.network.appletalk.node = appletalk_get_my_node();
1699 me.player.network.appletalk.net = appletalk_get_my_net();
1700 me.player.network.appletalk.socket = appletalk_get_my_socket();
1701 appletalk_send_game_info( (ubyte *)&me, sizeof(sequence_packet), Network_zone_name );
1708 network_update_netgame(void)
1710 // Update the netgame struct with current game variables
1714 Netgame.numconnected=0;
1715 for (i=0;i<N_players;i++)
1716 if (Players[i].connected)
1717 Netgame.numconnected++;
1719 // This is great: D2 1.0 and 1.1 ignore upper part of the game_flags field of
1720 // the lite_info struct when you're sitting on the join netgame screen. We can
1721 // "sneak" Hoard information into this field. This is better than sending
1722 // another packet that could be lost in transit.
1725 if (HoardEquipped())
1727 if (Game_mode & GM_HOARD)
1729 Netgame.game_flags |=NETGAME_FLAG_HOARD;
1730 if (Game_mode & GM_TEAM)
1731 Netgame.game_flags |=NETGAME_FLAG_TEAM_HOARD;
1735 if (Network_status == NETSTAT_STARTING)
1738 Netgame.numplayers = N_players;
1739 Netgame.game_status = Network_status;
1740 Netgame.max_numplayers = MaxNumNetPlayers;
1742 for (i = 0; i < MAX_NUM_NET_PLAYERS; i++)
1744 NetPlayers.players[i].connected = Players[i].connected;
1745 for(j = 0; j < MAX_NUM_NET_PLAYERS; j++)
1746 Netgame.kills[i][j] = kill_matrix[i][j];
1748 Netgame.killed[i] = Players[i].net_killed_total;
1749 Netgame.player_kills[i] = Players[i].net_kills_total;
1750 Netgame.player_score[i] = Players[i].score;
1751 Netgame.player_flags[i] = (Players[i].flags & (PLAYER_FLAGS_BLUE_KEY | PLAYER_FLAGS_RED_KEY | PLAYER_FLAGS_GOLD_KEY));
1753 Netgame.team_kills[0] = team_kills[0];
1754 Netgame.team_kills[1] = team_kills[1];
1755 Netgame.levelnum = Current_level_num;
1761 network_send_endlevel_sub(int player_num)
1766 // Send an endlevel packet for a player
1767 end.type = PID_ENDLEVEL;
1768 end.player_num = player_num;
1769 end.connected = Players[player_num].connected;
1770 end.kills = INTEL_SHORT(Players[player_num].net_kills_total);
1771 end.killed = INTEL_SHORT(Players[player_num].net_killed_total);
1772 memcpy(end.kill_matrix, kill_matrix[player_num], MAX_PLAYERS*sizeof(short));
1774 for (i = 0; i < MAX_PLAYERS; i++)
1775 for (j = 0; j < MAX_PLAYERS; j++)
1776 end.kill_matrix[i][j] = INTEL_SHORT(end.kill_matrix[i][j]);
1778 j = j; // to satisfy compiler
1781 if (Players[player_num].connected == 1) // Still playing
1783 Assert(Control_center_destroyed);
1784 end.seconds_left = Countdown_seconds_left;
1787 // mprintf((0, "Sending endlevel packet.\n"));
1789 for (i = 0; i < N_players; i++)
1791 if ((i != Player_num) && (i!=player_num) && (Players[i].connected)) {
1792 if (Players[i].connected==1)
1793 network_send_endlevel_short_sub(player_num,i);
1795 if (Network_game_type == IPX_GAME)
1796 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);
1799 appletalk_send_packet_data( (ubyte *)&end, sizeof(endlevel_info), NetPlayers.players[i].network.appletalk.node,
1800 NetPlayers.players[i].network.appletalk.net,
1801 NetPlayers.players[i].network.appletalk.socket);
1809 network_send_endlevel_packet(void)
1811 // Send an updated endlevel status to other hosts
1813 network_send_endlevel_sub(Player_num);
1818 network_send_endlevel_short_sub(int from_player_num,int to_player)
1820 endlevel_info_short end;
1822 // Send an endlevel packet for a player
1823 end.type = PID_ENDLEVEL_SHORT;
1824 end.player_num = from_player_num;
1825 end.connected = Players[from_player_num].connected;
1826 end.seconds_left = Countdown_seconds_left;
1829 if (Players[from_player_num].connected == 1) // Still playing
1831 Assert(Control_center_destroyed);
1834 if ((to_player != Player_num) && (to_player!=from_player_num) && (Players[to_player].connected))
1836 mprintf((0, "Sending short endlevel packet to %s.\n",Players[to_player].callsign));
1837 if (Network_game_type == IPX_GAME)
1838 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);
1841 appletalk_send_packet_data( (ubyte *)&end, sizeof(endlevel_info_short), NetPlayers.players[to_player].network.appletalk.node,
1842 NetPlayers.players[to_player].network.appletalk.net,
1843 NetPlayers.players[to_player].network.appletalk.socket);
1848 extern fix ThisLevelTime;
1851 network_send_game_info(sequence_packet *their)
1853 // Send game info to someone who requested it
1855 char old_type, old_status;
1859 mprintf((0, "Sending game info.\n"));
1861 network_update_netgame(); // Update the values in the netgame struct
1863 old_type = Netgame.type;
1864 old_status = Netgame.game_status;
1866 Netgame.type = PID_GAME_INFO;
1867 NetPlayers.type = PID_PLAYERSINFO;
1869 NetPlayers.Security=Netgame.Security;
1870 Netgame.version_major=Version_major;
1871 Netgame.version_minor=Version_minor;
1873 if (Endlevel_sequence || Control_center_destroyed)
1874 Netgame.game_status = NETSTAT_ENDLEVEL;
1876 if (Netgame.PlayTimeAllowed)
1878 timevar=i2f (Netgame.PlayTimeAllowed*5*60);
1879 i=f2i(timevar-ThisLevelTime);
1881 Netgame.game_status=NETSTAT_ENDLEVEL;
1885 if (Network_game_type == IPX_GAME) {
1887 ipx_send_broadcast_packet_data((ubyte *)&Netgame, sizeof(netgame_info));
1888 ipx_send_broadcast_packet_data((ubyte *)&NetPlayers,sizeof(AllNetPlayers_info));
1890 send_netgame_packet(NULL, NULL, NULL, 0); // server == NULL says to broadcast packet
1891 send_netplayers_packet(NULL, NULL);
1893 } // nothing to do for appletalk games I think....
1895 if (Network_game_type == IPX_GAME) {
1897 ipx_send_internetwork_packet_data((ubyte *)&Netgame, sizeof(netgame_info), their->player.network.ipx.server, their->player.network.ipx.node);
1898 ipx_send_internetwork_packet_data((ubyte *)&NetPlayers,sizeof(AllNetPlayers_info),their->player.network.ipx.server,their->player.network.ipx.node);
1900 send_netgame_packet(their->player.network.ipx.server, their->player.network.ipx.node, NULL, 0);
1901 send_netplayers_packet(their->player.network.ipx.server, their->player.network.ipx.node);
1905 appletalk_send_packet_data( (ubyte *)&Netgame, sizeof(netgame_info), their->player.network.appletalk.node,
1906 their->player.network.appletalk.net, their->player.network.appletalk.socket );
1907 appletalk_send_packet_data( (ubyte *)&NetPlayers, sizeof(AllNetPlayers_info), their->player.network.appletalk.node,
1908 their->player.network.appletalk.net, their->player.network.appletalk.socket );
1913 Netgame.type = old_type;
1914 Netgame.game_status = old_status;
1917 void network_send_lite_info(sequence_packet *their)
1919 // Send game info to someone who requested it
1921 char old_type, old_status,oldstatus;
1923 mprintf((0, "Sending lite game info.\n"));
1925 network_update_netgame(); // Update the values in the netgame struct
1927 old_type = Netgame.type;
1928 old_status = Netgame.game_status;
1930 Netgame.type = PID_LITE_INFO;
1932 if (Endlevel_sequence || Control_center_destroyed)
1933 Netgame.game_status = NETSTAT_ENDLEVEL;
1935 // If hoard mode, make this game look closed even if it isn't
1936 if (HoardEquipped())
1938 if (Game_mode & GM_HOARD)
1940 oldstatus=Netgame.game_status;
1941 Netgame.game_status=NETSTAT_ENDLEVEL;
1942 Netgame.gamemode=NETGAME_CAPTURE_FLAG;
1943 if (oldstatus==NETSTAT_ENDLEVEL)
1944 Netgame.game_flags|=NETGAME_FLAG_REALLY_ENDLEVEL;
1945 if (oldstatus==NETSTAT_STARTING)
1946 Netgame.game_flags|=NETGAME_FLAG_REALLY_FORMING;
1951 if (Network_game_type == IPX_GAME) {
1953 ipx_send_broadcast_packet_data((ubyte *)&Netgame, sizeof(lite_info));
1955 send_netgame_packet(NULL, NULL, NULL, 1); // server == NULL says broadcast
1957 } // nothing to do for appletalk I think....
1959 if (Network_game_type == IPX_GAME) {
1961 ipx_send_internetwork_packet_data((ubyte *)&Netgame, sizeof(lite_info), their->player.network.ipx.server, their->player.network.ipx.node);
1963 send_netgame_packet(their->player.network.ipx.server, their->player.network.ipx.node, NULL, 1);
1967 appletalk_send_packet_data( (ubyte *)&Netgame, sizeof(lite_info), their->player.network.appletalk.node,
1968 their->player.network.appletalk.net, their->player.network.appletalk.socket );
1973 // Restore the pre-hoard mode
1974 if (HoardEquipped())
1976 if (Game_mode & GM_HOARD)
1978 if (!(Game_mode & GM_TEAM))
1979 Netgame.gamemode=NETGAME_HOARD;
1981 Netgame.gamemode=NETGAME_TEAM_HOARD;
1982 Netgame.game_flags&=~NETGAME_FLAG_REALLY_ENDLEVEL;
1983 Netgame.game_flags&=~NETGAME_FLAG_REALLY_FORMING;
1984 Netgame.game_flags&=~NETGAME_FLAG_TEAM_HOARD;
1988 Netgame.type = old_type;
1989 Netgame.game_status = old_status;
1993 void network_send_netgame_update()
1995 // Send game info to someone who requested it
1997 char old_type, old_status;
2000 mprintf((0, "Sending updated game info.\n"));
2002 network_update_netgame(); // Update the values in the netgame struct
2004 old_type = Netgame.type;
2005 old_status = Netgame.game_status;
2007 Netgame.type = PID_GAME_UPDATE;
2009 if (Endlevel_sequence || Control_center_destroyed)
2010 Netgame.game_status = NETSTAT_ENDLEVEL;
2012 for (i=0; i<N_players; i++ ) {
2013 if ( (Players[i].connected) && (i!=Player_num ) ) {
2014 if (Network_game_type == IPX_GAME) {
2016 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 );
2018 send_netgame_packet(NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node, Players[i].net_address, 0);
2022 appletalk_send_packet_data( (ubyte *)&Netgame, sizeof(lite_info), NetPlayers.players[i].network.appletalk.node,
2023 NetPlayers.players[i].network.appletalk.net, NetPlayers.players[i].network.appletalk.socket );
2029 Netgame.type = old_type;
2030 Netgame.game_status = old_status;
2033 int network_send_request(void)
2035 // Send a request to join a game 'Netgame'. Returns 0 if we can join this
2036 // game, non-zero if there is some problem.
2039 if (Netgame.numplayers < 1)
2042 for (i = 0; i < MAX_NUM_NET_PLAYERS; i++)
2043 if (NetPlayers.players[i].connected)
2046 Assert(i < MAX_NUM_NET_PLAYERS);
2048 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));
2050 // segments_checksum = netmisc_calc_checksum( Segments, sizeof(segment)*(Highest_segment_index+1) );
2052 My_Seq.type = PID_REQUEST;
2053 My_Seq.player.connected = Current_level_num;
2055 if (Network_game_type == IPX_GAME) {
2057 ipx_send_internetwork_packet_data((ubyte *)&My_Seq, sizeof(sequence_packet), NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node);
2059 send_sequence_packet(My_Seq, NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node, NULL);
2063 appletalk_send_packet_data( (ubyte *)&My_Seq, sizeof(sequence_packet), NetPlayers.players[i].network.appletalk.node,
2064 NetPlayers.players[i].network.appletalk.net,
2065 NetPlayers.players[i].network.appletalk.socket);
2072 int SecurityCheck=0;
2074 void network_process_gameinfo(ubyte *data)
2077 netgame_info tmp_info;
2080 netgame_info *new = (netgame_info *)data;
2083 if (Network_game_type == IPX_GAME) {
2084 receive_netgame_packet(data, &tmp_info, 0); // get correctly aligned structure
2090 WaitingForPlayerInfo=0;
2092 if (new->Security !=TempPlayersInfo->Security)
2094 Int3(); // Get Jason
2095 return; // If this first half doesn't go with the second half
2098 Network_games_changed = 1;
2100 //mprintf((0, "Got game data for game %s.\n", new->game_name));
2102 Assert (TempPlayersInfo!=NULL);
2104 for (i = 0; i < num_active_games; i++)
2106 //mprintf ((0,"GAMEINFO: Game %d is %s!\n",i,Active_games[i].game_name));
2108 if (!stricmp(Active_games[i].game_name, new->game_name) &&
2109 Active_games[i].Security==new->Security)
2113 if (i == MAX_ACTIVE_NETGAMES)
2115 mprintf((0, "Too many netgames.\n"));
2119 // MWA memcpy(&Active_games[i], data, sizeof(netgame_info));
2120 memcpy(&Active_games[i], (ubyte *)new, sizeof(netgame_info));
2121 memcpy (&ActiveNetPlayers[i],TempPlayersInfo,sizeof(AllNetPlayers_info));
2124 if (Active_games[i].Security==SecurityCheck)
2127 //mprintf ((0,"Recieved %d unique games...\n",i));
2129 if (i == num_active_games)
2132 if (Active_games[i].numplayers == 0)
2134 mprintf ((0,"DELETING THIS GAME!!!\n"));
2136 for (j = i; j < num_active_games-1; j++)
2138 memcpy(&Active_games[j], &Active_games[j+1], sizeof(netgame_info));
2139 memcpy (&ActiveNetPlayers[j],&ActiveNetPlayers[j+1],sizeof(AllNetPlayers_info));
2146 void network_process_lite_info(ubyte *data)
2152 lite_info *new = (lite_info *)data;
2155 if (Network_game_type == IPX_GAME) {
2156 receive_netgame_packet(data, (netgame_info *)&tmp_info, 1);
2161 Network_games_changed = 1;
2163 //mprintf((0, "Got game data for game %s.\n", new->game_name));
2165 for (i = 0; i < num_active_games; i++)
2167 //mprintf ((0,"GAMEINFO: Game %d is %s!\n",i,Active_games[i].game_name));
2169 if ((!stricmp(Active_games[i].game_name, new->game_name)) &&
2170 Active_games[i].Security==new->Security)
2174 if (i == MAX_ACTIVE_NETGAMES)
2176 mprintf((0, "Too many netgames.\n"));
2180 memcpy(&Active_games[i], (ubyte *)new, sizeof(lite_info));
2182 // See if this is really a Hoard game
2183 // If so, adjust all the data accordingly
2185 if (HoardEquipped())
2187 if (Active_games[i].game_flags & NETGAME_FLAG_HOARD)
2189 Active_games[i].gamemode=NETGAME_HOARD;
2190 Active_games[i].game_status=NETSTAT_PLAYING;
2192 if (Active_games[i].game_flags & NETGAME_FLAG_TEAM_HOARD)
2193 Active_games[i].gamemode=NETGAME_TEAM_HOARD;
2194 if (Active_games[i].game_flags & NETGAME_FLAG_REALLY_ENDLEVEL)
2195 Active_games[i].game_status=NETSTAT_ENDLEVEL;
2196 if (Active_games[i].game_flags & NETGAME_FLAG_REALLY_FORMING)
2197 Active_games[i].game_status=NETSTAT_STARTING;
2201 //mprintf ((0,"Recieved %d unique games...\n",i));
2203 if (i == num_active_games)
2206 if (Active_games[i].numplayers == 0)
2208 mprintf ((0,"DELETING THIS GAME!!!\n"));
2210 for (j = i; j < num_active_games-1; j++)
2212 memcpy(&Active_games[j], &Active_games[j+1], sizeof(netgame_info));
2218 void network_process_dump(sequence_packet *their)
2220 // Our request for join was denied. Tell the user why.
2225 mprintf((0, "Dumped by player %s, type %d.\n", their->player.callsign, their->player.connected));
2227 if (their->player.connected!=7)
2228 nm_messagebox(NULL, 1, TXT_OK, NET_DUMP_STRINGS(their->player.connected));
2231 for (i=0;i<N_players;i++)
2232 if (!stricmp (their->player.callsign,Players[i].callsign))
2234 if (i!=network_who_is_master())
2236 HUD_init_message ("%s attempted to kick you out.",their->player.callsign);
2240 sprintf (temp,"%s has kicked you out!",their->player.callsign);
2241 nm_messagebox(NULL, 1, TXT_OK, &temp);
2242 if (Network_status==NETSTAT_PLAYING)
2248 Network_status = NETSTAT_MENU;
2253 void network_process_request(sequence_packet *their)
2255 // Player is ready to receieve a sync packet
2258 mprintf((0, "Player %s ready for sync.\n", their->player.callsign));
2260 for (i = 0; i < N_players; i++) {
2261 if (Network_game_type == IPX_GAME) {
2262 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))) {
2263 Players[i].connected = 1;
2267 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)) ) {
2268 Players[i].connected = 1;
2275 #define REFUSE_INTERVAL F1_0 * 8
2276 extern void multi_reset_object_texture (object *);
2278 void network_process_packet(ubyte *data, int length )
2281 sequence_packet tmp_packet;
2283 sequence_packet *their = (sequence_packet *)data;
2286 if (Network_game_type == IPX_GAME) {
2287 receive_sequence_packet(data, &tmp_packet);
2288 their = &tmp_packet; // reassign their to point to correctly alinged structure
2292 //mprintf( (0, "Got packet of length %d, type %d\n", length, their->type ));
2294 // if ( length < sizeof(sequence_packet) ) return;
2300 case PID_GAME_INFO: // Jason L. says we can safely ignore this type.
2303 case PID_PLAYERSINFO:
2305 mprintf ((0,"Got a PID_PLAYERSINFO!\n"));
2307 if (Network_status==NETSTAT_WAITING)
2310 memcpy (&TempPlayersBase,data,sizeof(AllNetPlayers_info));
2312 if (Network_game_type == IPX_GAME)
2313 receive_netplayers_packet(data, &TempPlayersBase);
2315 memcpy (&TempPlayersBase,data,sizeof(AllNetPlayers_info));
2318 if (TempPlayersBase.Security!=Netgame.Security)
2320 mprintf ((0,"Bad security for PLAYERSINFO\n"));
2324 mprintf ((0,"Got a waiting PID_PLAYERSINFO!\n"));
2325 if (length!=ALLNETPLAYERSINFO_SIZE)
2327 mprintf ((0,"Invalid size for netplayers packet!\n"));
2331 TempPlayersInfo=&TempPlayersBase;
2332 WaitingForPlayerInfo=0;
2333 NetSecurityNum=TempPlayersInfo->Security;
2334 NetSecurityFlag=NETSECURITY_WAIT_FOR_SYNC;
2341 if (length != LITE_INFO_SIZE)
2343 mprintf ((0,"WARNING! Recieved invalid size for PID_LITE_INFO\n"));
2347 if (Network_status == NETSTAT_BROWSING)
2348 network_process_lite_info (data);
2352 // Someone wants a list of games
2354 if (length != SEQUENCE_PACKET_SIZE)
2356 mprintf ((0,"WARNING! Recieved invalid size for PID_GAME_LIST\n"));
2360 mprintf((0, "Got a PID_GAME_LIST!\n"));
2361 if ((Network_status == NETSTAT_PLAYING) || (Network_status == NETSTAT_STARTING) || (Network_status == NETSTAT_ENDLEVEL))
2362 if (network_i_am_master())
2363 network_send_lite_info(their);
2367 case PID_SEND_ALL_GAMEINFO:
2369 if (length != SEQUENCE_PACKET_SIZE)
2371 mprintf ((0,"WARNING! Recieved invalid size for PID_SEND_ALL_GAMEINFO\n"));
2375 if ((Network_status == NETSTAT_PLAYING) || (Network_status == NETSTAT_STARTING) || (Network_status == NETSTAT_ENDLEVEL))
2376 if (network_i_am_master() && their->Security==Netgame.Security)
2377 network_send_game_info(their);
2382 mprintf( (0, "Got NEWPLAYER message from %s.\n", their->player.callsign));
2384 if (length != SEQUENCE_PACKET_SIZE)
2386 mprintf ((0,"WARNING! Recieved invalid size for PID_ADDPLAYER\n"));
2389 mprintf( (0, "Got NEWPLAYER message from %s.\n", their->player.callsign));
2390 network_new_player(their);
2393 if (length != SEQUENCE_PACKET_SIZE)
2395 mprintf ((0,"WARNING! Recieved invalid size for PID_REQUEST\n"));
2399 mprintf( (0, "Got REQUEST from '%s'\n", their->player.callsign ));
2400 if (Network_status == NETSTAT_STARTING)
2402 // Someone wants to join our game!
2403 network_add_player(their);
2405 else if (Network_status == NETSTAT_WAITING)
2407 // Someone is ready to recieve a sync packet
2408 network_process_request(their);
2410 else if (Network_status == NETSTAT_PLAYING)
2412 // Someone wants to join a game in progress!
2413 if (Netgame.RefusePlayers)
2414 DoRefuseStuff (their);
2416 network_welcome_player(their);
2421 if (length != SEQUENCE_PACKET_SIZE)
2423 mprintf ((0,"WARNING! Recieved invalid size for PID_DUMP\n"));
2427 if (Network_status == NETSTAT_WAITING || Network_status==NETSTAT_PLAYING )
2428 network_process_dump(their);
2430 case PID_QUIT_JOINING:
2432 if (length != SEQUENCE_PACKET_SIZE)
2434 mprintf ((0,"WARNING! Recieved invalid size for PID_QUIT_JOINING\n"));
2437 if (Network_status == NETSTAT_STARTING)
2438 network_remove_player( their );
2439 else if ((Network_status == NETSTAT_PLAYING) && (Network_send_objects))
2440 network_stop_resync( their );
2444 mprintf ((0,"Got a sync packet! Network_status=%d\n",NETSTAT_WAITING));
2446 if (Network_status == NETSTAT_WAITING) {
2449 memcpy((ubyte *)&(TempNetInfo), data, sizeof(netgame_info));
2451 if (Network_game_type == IPX_GAME)
2452 receive_netgame_packet(data, &TempNetInfo, 0);
2454 memcpy((ubyte *)&(TempNetInfo), data, sizeof(netgame_info));
2457 if (TempNetInfo.Security!=Netgame.Security)
2459 mprintf ((0,"Bad security on sync packet.\n"));
2463 if (NetSecurityFlag==NETSECURITY_WAIT_FOR_SYNC)
2465 if (TempNetInfo.Security==TempPlayersInfo->Security)
2467 network_read_sync_packet (&TempNetInfo,0);
2474 NetSecurityFlag=NETSECURITY_WAIT_FOR_PLAYERS;
2475 NetSecurityNum=TempNetInfo.Security;
2477 if ( network_wait_for_playerinfo())
2478 network_read_sync_packet((netgame_info *)data,0);
2487 if ((Game_mode&GM_NETWORK) && ((Network_status == NETSTAT_PLAYING)||(Network_status == NETSTAT_ENDLEVEL) || Network_status==NETSTAT_WAITING)) {
2488 network_process_pdata((char *)data);
2491 case PID_NAKED_PDATA:
2492 if ((Game_mode&GM_NETWORK) && ((Network_status == NETSTAT_PLAYING)||(Network_status == NETSTAT_ENDLEVEL) || Network_status==NETSTAT_WAITING))
2493 network_process_naked_pdata((char *)data,length);
2496 case PID_OBJECT_DATA:
2497 if (Network_status == NETSTAT_WAITING)
2498 network_read_object_packet(data);
2501 if ((Network_status == NETSTAT_ENDLEVEL) || (Network_status == NETSTAT_PLAYING))
2502 network_read_endlevel_packet(data);
2504 mprintf((0, "Junked endlevel packet.\n"));
2506 case PID_ENDLEVEL_SHORT:
2507 if ((Network_status == NETSTAT_ENDLEVEL) || (Network_status == NETSTAT_PLAYING))
2508 network_read_endlevel_short_packet(data);
2510 mprintf((0, "Junked short endlevel packet!\n"));
2513 case PID_GAME_UPDATE:
2514 mprintf ((0,"Got a GAME_UPDATE!\n"));
2516 if (Network_status==NETSTAT_PLAYING)
2519 memcpy((ubyte *)&TempNetInfo, data, sizeof(lite_info) );
2521 if (Network_game_type == IPX_GAME)
2522 receive_netgame_packet(data, &TempNetInfo, 1);
2524 memcpy((ubyte *)&TempNetInfo, data, sizeof(lite_info) );
2526 if (TempNetInfo.Security==Netgame.Security)
2527 memcpy (&Netgame,(ubyte *)&TempNetInfo,sizeof(lite_info));
2529 if (Game_mode & GM_TEAM)
2533 for (i=0;i<N_players;i++)
2534 if (Players[i].connected)
2535 multi_reset_object_texture (&Objects[Players[i].objnum]);
2540 network_ping (PID_PING_RETURN,data[1]);
2542 case PID_PING_RETURN:
2543 network_handle_ping_return(data[1]); // data[1] is player who told us of their ping time
2545 case PID_NAMES_RETURN:
2546 if (Network_status==NETSTAT_BROWSING && NamesInfoSecurity!=-1)
2547 network_process_names_return (data);
2549 case PID_GAME_PLAYERS:
2550 // Someone wants a list of players in this game
2552 if (length != SEQUENCE_PACKET_SIZE)
2554 mprintf ((0,"WARNING! Recieved invalid size for PID_GAME_PLAYERS\n"));
2558 mprintf((0, "Got a PID_GAME_PLAYERS!\n"));
2559 if ((Network_status == NETSTAT_PLAYING) || (Network_status == NETSTAT_STARTING) || (Network_status == NETSTAT_ENDLEVEL))
2560 if (network_i_am_master() && their->Security==Netgame.Security)
2561 network_send_player_names(their);
2565 mprintf((0, "Ignoring invalid packet type.\n"));
2566 Int3(); // Invalid network packet type, see ROB
2572 void dump_segments()
2576 fp = fopen( "TEST.DMP", "wb" );
2577 fwrite( Segments, sizeof(segment)*(Highest_segment_index+1),1, fp );
2579 mprintf( (0, "SS=%d\n", sizeof(segment) ));
2585 network_read_endlevel_packet( ubyte *data )
2587 // Special packet for end of level syncing
2594 end = (endlevel_info *)data;
2596 for (i = 0; i < MAX_PLAYERS; i++)
2597 for (j = 0; j < MAX_PLAYERS; j++)
2598 end->kill_matrix[i][j] = INTEL_SHORT(end->kill_matrix[i][j]);
2599 end->kills = INTEL_SHORT(end->kills);
2600 end->killed = INTEL_SHORT(end->killed);
2603 playernum = end->player_num;
2605 Assert(playernum != Player_num);
2607 if (playernum>=N_players)
2609 Int3(); // weird, but it an happen in a coop restore game
2610 return; // if it happens in a coop restore, don't worry about it
2613 if ((Network_status == NETSTAT_PLAYING) && (end->connected != 0))
2614 return; // Only accept disconnect packets if we're not out of the level yet
2616 Players[playernum].connected = end->connected;
2617 memcpy(&kill_matrix[playernum][0], end->kill_matrix, MAX_PLAYERS*sizeof(short));
2618 Players[playernum].net_kills_total = end->kills;
2619 Players[playernum].net_killed_total = end->killed;
2621 if ((Players[playernum].connected == 1) && (end->seconds_left < Countdown_seconds_left))
2622 Countdown_seconds_left = end->seconds_left;
2624 LastPacketTime[playernum] = timer_get_approx_seconds();
2626 // mprintf((0, "Got endlevel packet from player %d.\n", playernum));
2630 network_read_endlevel_short_packet( ubyte *data )
2632 // Special packet for end of level syncing
2635 endlevel_info_short *end;
2637 end = (endlevel_info_short *)data;
2639 playernum = end->player_num;
2641 Assert(playernum != Player_num);
2643 if (playernum>=N_players)
2645 Int3(); // weird, but it can happen in a coop restore game
2646 return; // if it happens in a coop restore, don't worry about it
2649 if ((Network_status == NETSTAT_PLAYING) && (end->connected != 0))
2651 //mprintf ((0,"Returning early for short_endlevel\n"));
2652 return; // Only accept disconnect packets if we're not out of the level yet
2655 Players[playernum].connected = end->connected;
2657 if ((Players[playernum].connected == 1) && (end->seconds_left < Countdown_seconds_left))
2658 Countdown_seconds_left = end->seconds_left;
2660 LastPacketTime[playernum] = timer_get_approx_seconds();
2665 network_pack_objects(void)
2667 // Switching modes, pack the object array
2669 special_reset_objects();
2673 network_verify_objects(int remote, int local)
2676 int nplayers, got_controlcen=0;
2678 mprintf ((0,"NETWORK:remote=%d local=%d\n",remote,local));
2680 if ((remote-local) > 10)
2683 if (Game_mode & GM_MULTI_ROBOTS)
2688 for (i = 0; i <= Highest_object_index; i++)
2690 if ((Objects[i].type == OBJ_PLAYER) || (Objects[i].type == OBJ_GHOST))
2692 if (Objects[i].type == OBJ_CNTRLCEN)
2696 if (got_controlcen && (MaxNumNetPlayers<=nplayers))
2703 network_read_object_packet( ubyte *data )
2705 // Object from another net player we need to sync with
2707 short objnum, remote_objnum;
2712 static int my_pnum = 0;
2713 static int mode = 0;
2714 static int object_count = 0;
2715 static int frame_num = 0;
2718 int remote_frame_num = data[2];
2722 // mprintf((0, "Object packet %d (remote #%d) contains %d objects.\n", frame_num, remote_frame_num, nobj));
2724 for (i = 0; i < nobj; i++)
2726 objnum = INTEL_SHORT( *(short *)(data+loc) ); loc += 2;
2727 obj_owner = data[loc]; loc += 1;
2728 remote_objnum = INTEL_SHORT( *(short *)(data+loc) ); loc += 2;
2732 // Clear object array
2733 mprintf((0, "Clearing object array.\n"));
2736 Network_rejoined = 1;
2737 my_pnum = obj_owner;
2738 change_playernum_to(my_pnum);
2743 else if (objnum == -2)
2745 // Special debug checksum marker for entire send
2748 network_pack_objects();
2751 mprintf((0, "Objnum -2 found in frame local %d remote %d.\n", frame_num, remote_frame_num));
2752 mprintf((0, "Got %d objects, expected %d.\n", object_count, remote_objnum));
2753 if (remote_objnum != object_count) {
2756 if (network_verify_objects(remote_objnum, object_count))
2758 // Failed to sync up
2759 nm_messagebox(NULL, 1, TXT_OK, TXT_NET_SYNC_FAILED);
2760 Network_status = NETSTAT_MENU;
2767 if (frame_num != remote_frame_num)
2769 mprintf ((0,"Got a type 3 object packet!\n"));
2771 if ((obj_owner == my_pnum) || (obj_owner == -1))
2775 objnum = remote_objnum;
2776 //if (objnum > Highest_object_index)
2778 // Highest_object_index = objnum;
2779 // num_objects = Highest_object_index+1;
2785 network_pack_objects();
2788 objnum = obj_allocate();
2791 obj = &Objects[objnum];
2792 if (obj->segnum != -1)
2794 Assert(obj->segnum == -1);
2795 Assert(objnum < MAX_OBJECTS);
2796 memcpy(obj,data+loc,sizeof(object)); loc += sizeof(object);
2798 if (Network_game_type == IPX_GAME)
2801 segnum = obj->segnum;
2802 obj->next = obj->prev = obj->segnum = -1;
2803 obj->attached_obj = -1;
2805 obj_link(obj-Objects,segnum);
2806 if (obj_owner == my_pnum)
2807 map_objnum_local_to_local(objnum);
2808 else if (obj_owner != -1)
2809 map_objnum_local_to_remote(objnum, remote_objnum, obj_owner);
2811 object_owner[objnum] = -1;
2813 } // For a standard onbject
2814 } // For each object in packet
2817 void network_sync_poll( int nitems, newmenu_item * menus, int * key, int citem )
2819 // Polling loop waiting for sync packet to start game
2829 if (Network_status != NETSTAT_WAITING) // Status changed to playing, exit the menu
2832 if (!Network_rejoined && (timer_get_approx_seconds() > t1+F1_0*2))
2836 // Poll time expired, re-send request
2838 t1 = timer_get_approx_seconds();
2840 mprintf((0, "Re-sending join request.\n"));
2841 i = network_send_request();
2847 void network_start_poll( int nitems, newmenu_item * menus, int * key, int citem )
2854 Assert(Network_status == NETSTAT_STARTING);
2856 if (!menus[0].value) {
2858 menus[0].redraw = 1;
2861 for (i=1; i<nitems; i++ ) {
2862 if ( (i>= N_players) && (menus[i].value) ) {
2864 menus[i].redraw = 1;
2869 for (i=0; i<nitems; i++ ) {
2870 if ( menus[i].value ) {
2872 if ( nm > N_players ) {
2874 menus[i].redraw = 1;
2879 if ( nm > MaxNumNetPlayers ) {
2880 nm_messagebox( TXT_ERROR, 1, TXT_OK, "%s %d %s", TXT_SORRY_ONLY, MaxNumNetPlayers, TXT_NETPLAYERS_IN );
2881 // Turn off the last player highlighted
2882 for (i = N_players; i > 0; i--)
2883 if (menus[i].value == 1)
2886 menus[i].redraw = 1;
2891 // if (nitems > MAX_PLAYERS ) return;
2893 n = Netgame.numplayers;
2896 if (n < Netgame.numplayers )
2898 digi_play_sample (SOUND_HUD_MESSAGE,F1_0);
2900 mprintf ((0,"More players are printed!"));
2901 if (FindArg("-norankings"))
2902 sprintf( menus[N_players-1].text, "%d. %-20s", N_players,NetPlayers.players[N_players-1].callsign );
2904 sprintf( menus[N_players-1].text, "%d. %s%-20s", N_players, RankStrings[NetPlayers.players[N_players-1].rank],NetPlayers.players[N_players-1].callsign );
2906 menus[N_players-1].redraw = 1;
2907 if (N_players <= MaxNumNetPlayers)
2909 menus[N_players-1].value = 1;
2912 else if ( n > Netgame.numplayers )
2914 // One got removed...
2916 digi_play_sample (SOUND_HUD_KILL,F1_0);
2918 for (i=0; i<N_players; i++ )
2921 if (FindArg("-norankings"))
2922 sprintf( menus[i].text, "%d. %-20s", i+1, NetPlayers.players[i].callsign );
2924 sprintf( menus[i].text, "%d. %s%-20s", i+1, RankStrings[NetPlayers.players[i].rank],NetPlayers.players[i].callsign );
2925 if (i < MaxNumNetPlayers)
2929 menus[i].redraw = 1;
2931 for (i=N_players; i<n; i++ )
2933 sprintf( menus[i].text, "%d. ", i+1 ); // Clear out the deleted entries...
2935 menus[i].redraw = 1;
2940 int opt_cinvul, opt_team_anarchy, opt_coop, opt_show_on_map, opt_closed,opt_maxnet;
2941 int last_cinvul=0,last_maxnet,opt_team_hoard;
2942 int opt_refuse,opt_capture;
2944 void network_game_param_poll( int nitems, newmenu_item * menus, int * key, int citem )
2946 static int oldmaxnet=0;
2948 if (((HoardEquipped() && menus[opt_team_hoard].value) || (menus[opt_team_anarchy].value || menus[opt_capture].value)) && !menus[opt_closed].value && !menus[opt_refuse].value) {
2949 menus[opt_refuse].value = 1;
2950 menus[opt_refuse].redraw = 1;
2951 menus[opt_refuse-1].value = 0;
2952 menus[opt_refuse-1].redraw = 1;
2953 menus[opt_refuse-2].value = 0;
2954 menus[opt_refuse-2].redraw = 1;
2958 if (menus[opt_coop].value)
2960 if ( (menus[opt_coop].value) || ((Network_game_type == APPLETALK_GAME) && (Network_appletalk_type == LOCALTALK_TYPE) && (menus[opt_coop-1].value)) )
2965 if (menus[opt_maxnet].value>2)
2967 menus[opt_maxnet].value=2;
2968 menus[opt_maxnet].redraw=1;
2971 if (menus[opt_maxnet].max_value>2)
2973 menus[opt_maxnet].max_value=2;
2974 menus[opt_maxnet].redraw=1;
2978 if ( (Network_game_type == APPLETALK_GAME) && (Network_appletalk_type == LOCALTALK_TYPE) ) {
2979 if (menus[opt_maxnet].value > 0) {
2980 menus[opt_maxnet].value=0;
2981 menus[opt_maxnet].redraw=1;
2983 if (menus[opt_maxnet].max_value > 0) {
2984 menus[opt_maxnet].max_value=0;
2985 menus[opt_maxnet].redraw=1;
2990 if (!Netgame.game_flags & NETGAME_FLAG_SHOW_MAP)
2991 Netgame.game_flags |= NETGAME_FLAG_SHOW_MAP;
2993 if (Netgame.PlayTimeAllowed || Netgame.KillGoal)
2995 Netgame.PlayTimeAllowed=0;
3000 else // if !Coop game
3005 menus[opt_maxnet].value=6;
3006 menus[opt_maxnet].max_value=6;
3009 if ( (Network_game_type == APPLETALK_GAME) && (Network_appletalk_type == LOCALTALK_TYPE) ) {
3010 menus[opt_maxnet].value=1;
3011 menus[opt_maxnet].max_value=1;
3018 if ( last_maxnet != menus[opt_maxnet].value )
3020 sprintf( menus[opt_maxnet].text, "Maximum players: %d", menus[opt_maxnet].value+2 );
3021 last_maxnet = menus[opt_maxnet].value;
3022 menus[opt_maxnet].redraw = 1;
3026 int netgame_difficulty;
3028 int network_get_game_params( char * game_name, int *mode, int *game_flags, int *level )
3031 int opt, opt_name, opt_level, opt_mode,opt_moreopts;
3033 char name[NETGAME_NAME_LEN+1];
3035 char level_text[32];
3038 int new_mission_num;
3041 *game_flags=*game_flags;
3043 SetAllAllowablesTo (1);
3044 NamesInfoSecurity=-1;
3046 for (i=0;i<MAX_PLAYERS;i++)
3048 Players[i].callsign[0]=0;
3052 Netgame.PlayTimeAllowed=0;
3053 Netgame.Allow_marker_view=1;
3054 netgame_difficulty=Player_default_difficulty;
3056 new_mission_num = multi_choose_mission(&anarchy_only);
3058 if (new_mission_num < 0)
3061 if (!(FindArg ("-packets") && FindArg ("-shortpackets")))
3062 if (!network_choose_connect ())
3066 if ( (Network_game_type == APPLETALK_GAME) && (Network_appletalk_type == LOCALTALK_TYPE) )
3067 MaxNumNetPlayers = 3;
3070 strcpy(Netgame.mission_name, Mission_list[new_mission_num].filename);
3071 strcpy(Netgame.mission_title, Mission_list[new_mission_num].mission_name);
3072 Netgame.control_invul_time = control_invul_time;
3074 sprintf( name, "%s%s", Players[Player_num].callsign, TXT_S_GAME );
3075 sprintf( slevel, "1" );
3078 m[opt].type = NM_TYPE_TEXT; m[opt].text = TXT_DESCRIPTION; opt++;
3081 m[opt].type = NM_TYPE_INPUT; m[opt].text = name; m[opt].text_len = NETGAME_NAME_LEN; opt++;
3083 sprintf(level_text, "%s (1-%d)", TXT_LEVEL_, Last_level);
3085 // if (Last_secret_level < -1)
3086 // sprintf(level_text+strlen(level_text)-1, ", S1-S%d)", -Last_secret_level);
3087 // else if (Last_secret_level == -1)
3088 // sprintf(level_text+strlen(level_text)-1, ", S1)");
3090 Assert(strlen(level_text) < 32);
3092 m[opt].type = NM_TYPE_TEXT; m[opt].text = level_text; opt++;
3095 m[opt].type = NM_TYPE_INPUT; m[opt].text = slevel; m[opt].text_len=4; opt++;
3096 // m[opt].type = NM_TYPE_TEXT; m[opt].text = TXT_OPTIONS; opt++;
3099 m[opt].type = NM_TYPE_RADIO; m[opt].text = TXT_ANARCHY; m[opt].value=1; m[opt].group=0; opt++;
3100 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++;
3101 m[opt].type = NM_TYPE_RADIO; m[opt].text = TXT_ANARCHY_W_ROBOTS; m[opt].value=0; m[opt].group=0; opt++;
3102 m[opt].type = NM_TYPE_RADIO; m[opt].text = TXT_COOPERATIVE; m[opt].value=0; m[opt].group=0; opt_coop=opt; opt++;
3103 m[opt].type = NM_TYPE_RADIO; m[opt].text = "Capture the flag"; m[opt].value=0; m[opt].group=0; opt_capture=opt; opt++;
3105 if (HoardEquipped())
3107 m[opt].type = NM_TYPE_RADIO; m[opt].text = "Hoard"; m[opt].value=0; m[opt].group=0; opt++;
3108 m[opt].type = NM_TYPE_RADIO; m[opt].text = "Team Hoard"; m[opt].value=0; m[opt].group=0; opt_team_hoard=opt; opt++;
3109 m[opt].type = NM_TYPE_TEXT; m[opt].text = ""; opt++;
3112 { m[opt].type = NM_TYPE_TEXT; m[opt].text = ""; opt++; }
3114 m[opt].type = NM_TYPE_RADIO; m[opt].text = "Open game"; m[opt].group=1; m[opt].value=0; opt++;
3116 m[opt].type = NM_TYPE_RADIO; m[opt].text = TXT_CLOSED_GAME; m[opt].group=1; m[opt].value=0; opt++;
3118 m[opt].type = NM_TYPE_RADIO; m[opt].text = "Restricted Game "; m[opt].group=1; m[opt].value=Netgame.RefusePlayers; opt++;
3120 // m[opt].type = NM_TYPE_CHECK; m[opt].text = TXT_SHOW_IDS; m[opt].value=0; opt++;
3123 sprintf( srmaxnet, "Maximum players: %d", MaxNumNetPlayers);
3124 m[opt].type = NM_TYPE_SLIDER; m[opt].value=MaxNumNetPlayers-2; m[opt].text= srmaxnet; m[opt].min_value=0;
3125 m[opt].max_value=MaxNumNetPlayers-2; opt++;
3126 last_maxnet=MaxNumNetPlayers-2;
3129 m[opt].type = NM_TYPE_MENU; m[opt].text = "More options..."; opt++;
3134 ExtGameStatus=GAMESTAT_NETGAME_OPTIONS;
3135 i = newmenu_do1( NULL, NULL, opt, m, network_game_param_poll, 1 );
3137 if (i==opt_moreopts)
3139 if ( m[opt_mode+3].value )
3140 Game_mode=GM_MULTI_COOP;
3141 network_more_game_options();
3145 Netgame.RefusePlayers=m[opt_refuse].value;
3151 MaxNumNetPlayers = m[opt_maxnet].value+2;
3152 Netgame.max_numplayers=MaxNumNetPlayers;
3154 for (j = 0; j < num_active_games; j++)
3155 if (!stricmp(Active_games[j].game_name, name))
3157 nm_messagebox(TXT_ERROR, 1, TXT_OK, TXT_DUPLICATE_NAME);
3161 strcpy( game_name, name );
3164 *level = atoi(slevel);
3166 if ((*level < 1) || (*level > Last_level))
3168 nm_messagebox(TXT_ERROR, 1, TXT_OK, TXT_LEVEL_OUT_RANGE );
3169 sprintf(slevel, "1");
3172 if ( m[opt_mode].value )
3173 *mode = NETGAME_ANARCHY;
3178 nm_messagebox(TXT_SORRY, 1, TXT_OK, TXT_REGISTERED_ONLY );
3179 m[opt_mode+1].value = 0;
3180 m[opt_mode+2].value = 0;
3181 m[opt_mode+3].value = 0;
3182 if (HoardEquipped())
3183 m[opt_mode+4].value = 0;
3185 m[opt_mode].value = 1;
3189 else if (m[opt_mode+1].value) {
3190 *mode = NETGAME_TEAM_ANARCHY;
3192 else if (m[opt_capture].value)
3193 *mode = NETGAME_CAPTURE_FLAG;
3194 else if (HoardEquipped() && m[opt_capture+1].value)
3195 *mode = NETGAME_HOARD;
3196 else if (HoardEquipped() && m[opt_capture+2].value)
3197 *mode = NETGAME_TEAM_HOARD;
3198 else if (anarchy_only) {
3199 nm_messagebox(NULL, 1, TXT_OK, TXT_ANARCHY_ONLY_MISSION);
3200 m[opt_mode+2].value = 0;
3201 m[opt_mode+3].value = 0;
3202 m[opt_mode].value = 1;
3205 else if ( m[opt_mode+2].value )
3206 *mode = NETGAME_ROBOT_ANARCHY;
3207 else if ( m[opt_mode+3].value )
3208 *mode = NETGAME_COOPERATIVE;
3209 else Int3(); // Invalid mode -- see Rob
3211 if (m[opt_closed].value)
3212 Netgame.game_flags |= NETGAME_FLAG_CLOSED;
3220 network_set_game_mode(int gamemode)
3224 if ( gamemode == NETGAME_ANARCHY )
3225 Game_mode = GM_NETWORK;
3226 else if ( gamemode == NETGAME_ROBOT_ANARCHY )
3227 Game_mode = GM_NETWORK | GM_MULTI_ROBOTS;
3228 else if ( gamemode == NETGAME_COOPERATIVE )
3229 Game_mode = GM_NETWORK | GM_MULTI_COOP | GM_MULTI_ROBOTS;
3230 else if (gamemode == NETGAME_CAPTURE_FLAG)
3232 Game_mode = GM_NETWORK | GM_TEAM | GM_CAPTURE;
3236 else if (HoardEquipped() && gamemode == NETGAME_HOARD)
3237 Game_mode = GM_NETWORK | GM_HOARD;
3238 else if (HoardEquipped() && gamemode == NETGAME_TEAM_HOARD)
3240 Game_mode = GM_NETWORK | GM_HOARD | GM_TEAM;
3243 else if ( gamemode == NETGAME_TEAM_ANARCHY )
3245 Game_mode = GM_NETWORK | GM_TEAM;
3252 #ifdef MACINTOSH // minimize players on localtalk games
3253 if ( (Network_game_type == APPLETALK_GAME) && (Network_appletalk_type == LOCALTALK_TYPE) ) {
3254 if (Game_mode & GM_MULTI_ROBOTS)
3255 MaxNumNetPlayers = 2;
3257 MaxNumNetPlayers = 3;
3259 if (Game_mode & GM_MULTI_COOP)
3260 MaxNumNetPlayers = 4;
3262 MaxNumNetPlayers = 8;
3270 network_find_game(void)
3272 // Find out whether or not there is space left on this socket
3276 Network_status = NETSTAT_BROWSING;
3278 num_active_games = 0;
3280 show_boxed_message(TXT_WAIT);
3282 network_send_game_list_request();
3283 t1 = timer_get_approx_seconds() + F1_0*3;
3285 while (timer_get_approx_seconds() < t1) // Wait 3 seconds for replies
3288 clear_boxed_message();
3290 // mprintf((0, "%s %d %s\n", TXT_FOUND, num_active_games, TXT_ACTIVE_GAMES));
3292 if (num_active_games < MAX_ACTIVE_NETGAMES)
3297 void network_read_sync_packet( netgame_info * sp, int rsinit)
3300 netgame_info tmp_info;
3304 char temp_callsign[CALLSIGN_LEN+1];
3307 if ( (Network_game_type == IPX_GAME) && (sp != &Netgame) ) { // for macintosh -- get the values unpacked to our structure format
3308 receive_netgame_packet((ubyte *)sp, &tmp_info, 0);
3314 TempPlayersInfo=&NetPlayers;
3316 // This function is now called by all people entering the netgame.
3318 // mprintf( (0, "%s %d\n", TXT_STARTING_NETGAME, sp->levelnum ));
3322 memcpy( &Netgame, sp, sizeof(netgame_info) );
3323 memcpy (&NetPlayers,TempPlayersInfo,sizeof (AllNetPlayers_info));
3326 N_players = sp->numplayers;
3327 Difficulty_level = sp->difficulty;
3328 Network_status = sp->game_status;
3330 //Assert(Function_mode != FMODE_GAME);
3334 mprintf((1, "Netgame.checksum = %d, calculated checksum = %d.\n", Netgame.segments_checksum, my_segments_checksum));
3336 if (Netgame.segments_checksum != my_segments_checksum)
3338 Network_status = NETSTAT_MENU;
3339 nm_messagebox(TXT_ERROR, 1, TXT_OK, TXT_NETLEVEL_NMATCH);
3345 // Discover my player number
3347 memcpy(temp_callsign, Players[Player_num].callsign, CALLSIGN_LEN+1);
3351 for (i=0; i<MAX_NUM_NET_PLAYERS; i++ ) {
3352 Players[i].net_kills_total = 0;
3353 // Players[i].net_killed_total = 0;
3356 for (i=0; i<N_players; i++ ) {
3357 if (Network_game_type == IPX_GAME) {
3358 if ( (!memcmp( TempPlayersInfo->players[i].network.ipx.node, My_Seq.player.network.ipx.node, 6 )) && (!stricmp( TempPlayersInfo->players[i].callsign, temp_callsign)) ) {
3359 if (Player_num!=-1) {
3360 Int3(); // Hey, we've found ourselves twice
3361 mprintf ((0,"Hey, we've found ourselves twice!\n"));
3362 Network_status = NETSTAT_MENU;
3365 change_playernum_to(i);
3368 if ( (TempPlayersInfo->players[i].network.appletalk.node == My_Seq.player.network.appletalk.node) && (!stricmp( TempPlayersInfo->players[i].callsign, temp_callsign)) ) {
3369 if (Player_num!=-1) {
3370 Int3(); // Hey, we've found ourselves twice
3371 Network_status = NETSTAT_MENU;
3374 change_playernum_to(i);
3377 memcpy( Players[i].callsign, TempPlayersInfo->players[i].callsign, CALLSIGN_LEN+1 );
3379 if (Network_game_type == IPX_GAME) {
3380 if ( (*(uint *)TempPlayersInfo->players[i].network.ipx.server) != 0 )
3381 ipx_get_local_target( TempPlayersInfo->players[i].network.ipx.server, TempPlayersInfo->players[i].network.ipx.node, Players[i].net_address );
3383 memcpy( Players[i].net_address, TempPlayersInfo->players[i].network.ipx.node, 6 );
3386 Players[i].n_packets_got=0; // How many packets we got from them
3387 Players[i].n_packets_sent=0; // How many packets we sent to them
3388 Players[i].connected = TempPlayersInfo->players[i].connected;
3389 Players[i].net_kills_total = sp->player_kills[i];
3390 Players[i].net_killed_total = sp->killed[i];
3391 if ((Network_rejoined) || (i != Player_num))
3392 Players[i].score = sp->player_score[i];
3393 for (j = 0; j < MAX_NUM_NET_PLAYERS; j++)
3395 kill_matrix[i][j] = sp->kills[i][j];
3399 if ( Player_num < 0 ) {
3400 mprintf ((0,"Bad Player_num, resetting to NETSTAT_MENU!\n"));
3401 Network_status = NETSTAT_MENU;
3405 if (Network_rejoined)
3406 for (i=0; i<N_players;i++)
3407 Players[i].net_killed_total = sp->killed[i];
3409 if (Network_rejoined) {
3410 network_process_monitor_vector(sp->monitor_vector);
3411 Players[Player_num].time_level = sp->level_time;
3414 team_kills[0] = sp->team_kills[0];
3415 team_kills[1] = sp->team_kills[1];
3417 Players[Player_num].connected = 1;
3418 NetPlayers.players[Player_num].connected = 1;
3419 NetPlayers.players[Player_num].rank=GetMyNetRanking();
3421 if (!Network_rejoined)
3422 for (i=0; i<NumNetPlayerPositions; i++) {
3423 Objects[Players[i].objnum].pos = Player_init[Netgame.locations[i]].pos;
3424 Objects[Players[i].objnum].orient = Player_init[Netgame.locations[i]].orient;
3425 obj_relink(Players[i].objnum,Player_init[Netgame.locations[i]].segnum);
3428 Objects[Players[Player_num].objnum].type = OBJ_PLAYER;
3430 mprintf ((0,"Changing to NETSTAT_PLAYING!\n"));
3431 Network_status = NETSTAT_PLAYING;
3432 Function_mode = FMODE_GAME;
3433 multi_sort_kill_list();
3438 network_send_sync(void)
3442 // Randomize their starting locations...
3444 d_srand( timer_get_fixed_seconds() );
3445 for (i=0; i<NumNetPlayerPositions; i++ )
3447 if (Players[i].connected)
3448 Players[i].connected = 1; // Get rid of endlevel connect statuses
3449 if (Game_mode & GM_MULTI_COOP)
3450 Netgame.locations[i] = i;
3454 np = d_rand() % NumNetPlayerPositions;
3455 for (j=0; j<i; j++ )
3457 if (Netgame.locations[j]==np)
3464 // np is a location that is not used anywhere else..
3465 Netgame.locations[i]=np;
3466 // mprintf((0, "Player %d starting in location %d\n" ,i ,np ));
3470 // Push current data into the sync packet
3472 network_update_netgame();
3473 Netgame.game_status = NETSTAT_PLAYING;
3474 Netgame.type = PID_SYNC;
3475 Netgame.segments_checksum = my_segments_checksum;
3477 for (i=0; i<N_players; i++ ) {
3478 if ((!Players[i].connected) || (i == Player_num))
3481 if (Network_game_type == IPX_GAME) {
3482 // Send several times, extras will be ignored
3484 ipx_send_internetwork_packet_data( (ubyte *)&Netgame, sizeof(netgame_info), NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node);
3485 ipx_send_internetwork_packet_data( (ubyte *)&NetPlayers, sizeof(AllNetPlayers_info), NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node);
3487 send_netgame_packet(NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node, NULL, 0);
3488 send_netplayers_packet(NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node);
3492 appletalk_send_packet_data( (ubyte *)&Netgame, sizeof(netgame_info), NetPlayers.players[i].network.appletalk.node,
3493 NetPlayers.players[i].network.appletalk.net,
3494 NetPlayers.players[i].network.appletalk.socket);
3495 appletalk_send_packet_data( (ubyte *)&NetPlayers, sizeof(AllNetPlayers_info), NetPlayers.players[i].network.appletalk.node,
3496 NetPlayers.players[i].network.appletalk.net,
3497 NetPlayers.players[i].network.appletalk.socket);
3502 network_read_sync_packet(&Netgame,1); // Read it myself, as if I had sent it
3506 network_select_teams(void)
3509 newmenu_item m[MAX_PLAYERS+4];
3510 int choice, opt, opt_team_b;
3511 ubyte team_vector = 0;
3512 char team_names[2][CALLSIGN_LEN+1];
3514 int pnums[MAX_PLAYERS+2];
3516 // One-time initialization
3518 for (i = N_players/2; i < N_players; i++) // Put first half of players on team A
3520 team_vector |= (1 << i);
3523 sprintf(team_names[0], "%s", TXT_BLUE);
3524 sprintf(team_names[1], "%s", TXT_RED);
3526 // Here comes da menu
3528 m[0].type = NM_TYPE_INPUT; m[0].text = team_names[0]; m[0].text_len = CALLSIGN_LEN;
3531 for (i = 0; i < N_players; i++)
3533 if (!(team_vector & (1 << i)))
3535 m[opt].type = NM_TYPE_MENU; m[opt].text = NetPlayers.players[i].callsign; pnums[opt] = i; opt++;
3539 m[opt].type = NM_TYPE_INPUT; m[opt].text = team_names[1]; m[opt].text_len = CALLSIGN_LEN; opt++;
3540 for (i = 0; i < N_players; i++)
3542 if (team_vector & (1 << i))
3544 m[opt].type = NM_TYPE_MENU; m[opt].text = NetPlayers.players[i].callsign; pnums[opt] = i; opt++;
3547 m[opt].type = NM_TYPE_TEXT; m[opt].text = ""; opt++;
3548 m[opt].type = NM_TYPE_MENU; m[opt].text = TXT_ACCEPT; opt++;
3550 Assert(opt <= MAX_PLAYERS+4);
3552 choice = newmenu_do(NULL, TXT_TEAM_SELECTION, opt, m, NULL);
3554 if (choice == opt-1)
3556 if ((opt-2-opt_team_b < 2) || (opt_team_b == 1))
3558 nm_messagebox(NULL, 1, TXT_OK, TXT_TEAM_MUST_ONE);
3564 Netgame.team_vector = team_vector;
3565 strcpy(Netgame.team_name[0], team_names[0]);
3566 strcpy(Netgame.team_name[1], team_names[1]);
3570 else if ((choice > 0) && (choice < opt_team_b)) {
3571 team_vector |= (1 << pnums[choice]);
3573 else if ((choice > opt_team_b) && (choice < opt-2)) {
3574 team_vector &= ~(1 << pnums[choice]);
3576 else if (choice == -1)
3585 network_select_players(void)
3588 newmenu_item m[MAX_PLAYERS+4];
3589 char text[MAX_PLAYERS+4][45];
3591 int save_nplayers; //how may people would like to join
3593 network_add_player( &My_Seq );
3595 for (i=0; i< MAX_PLAYERS+4; i++ ) {
3596 sprintf( text[i], "%d. %-20s", i+1, "" );
3597 m[i].type = NM_TYPE_CHECK; m[i].text = text[i]; m[i].value = 0;
3600 m[0].value = 1; // Assume server will play...
3602 if (FindArg("-norankings"))
3603 sprintf( text[0], "%d. %-20s", 1, Players[Player_num].callsign );
3605 sprintf( text[0], "%d. %s%-20s", 1, RankStrings[NetPlayers.players[Player_num].rank],Players[Player_num].callsign );
3607 sprintf( title, "%s %d %s", TXT_TEAM_SELECT, MaxNumNetPlayers, TXT_TEAM_PRESS_ENTER );
3610 ExtGameStatus=GAMESTAT_NETGAME_PLAYER_SELECT;
3611 j=newmenu_do1( NULL, title, MAX_PLAYERS+4, m, network_start_poll, 1 );
3613 save_nplayers = N_players;
3618 // Dump all players and go back to menu mode
3621 for (i=1; i<save_nplayers; i++) {
3622 if (Network_game_type == IPX_GAME)
3623 network_dump_player(NetPlayers.players[i].network.ipx.server,NetPlayers.players[i].network.ipx.node, DUMP_ABORTED);
3626 network_dump_appletalk_player(NetPlayers.players[i].network.appletalk.node,NetPlayers.players[i].network.appletalk.net, NetPlayers.players[i].network.appletalk.socket, DUMP_ABORTED);
3631 Netgame.numplayers = 0;
3632 network_send_game_info(0); // Tell everyone we're bailing
3634 Network_status = NETSTAT_MENU;
3638 // Count number of players chosen
3641 for (i=0; i<save_nplayers; i++ )
3647 if ( N_players > Netgame.max_numplayers) {
3649 nm_messagebox( TXT_ERROR, 1, TXT_OK, "%s %d %s", TXT_SORRY_ONLY, MaxNumNetPlayers, TXT_NETPLAYERS_IN );
3651 nm_messagebox( TXT_ERROR, 1, TXT_OK, "%s %d netplayers for this game.", TXT_SORRY_ONLY, MaxNumNetPlayers );
3653 N_players = save_nplayers;
3654 goto GetPlayersAgain;
3658 if ( N_players < 2 ) {
3659 nm_messagebox( TXT_ERROR, 1, TXT_OK, TXT_TEAM_ATLEAST_TWO );
3660 N_players = save_nplayers;
3661 goto GetPlayersAgain;
3666 if ( (Netgame.gamemode == NETGAME_TEAM_ANARCHY ||
3667 Netgame.gamemode == NETGAME_CAPTURE_FLAG || Netgame.gamemode == NETGAME_TEAM_HOARD) && (N_players < 2) ) {
3668 nm_messagebox(TXT_ERROR, 1, TXT_OK, "You must select at least two\nplayers to start a team game" );
3669 N_players = save_nplayers;
3670 goto GetPlayersAgain;
3674 // Remove players that aren't marked.
3676 for (i=0; i<save_nplayers; i++ ) {
3681 if (Network_game_type == IPX_GAME) {
3682 memcpy(NetPlayers.players[N_players].network.ipx.node, NetPlayers.players[i].network.ipx.node, 6);
3683 memcpy(NetPlayers.players[N_players].network.ipx.server, NetPlayers.players[i].network.ipx.server, 4);
3685 NetPlayers.players[N_players].network.appletalk.node = NetPlayers.players[i].network.appletalk.node;
3686 NetPlayers.players[N_players].network.appletalk.net = NetPlayers.players[i].network.appletalk.net;
3687 NetPlayers.players[N_players].network.appletalk.socket = NetPlayers.players[i].network.appletalk.socket;
3689 memcpy(NetPlayers.players[N_players].callsign, NetPlayers.players[i].callsign, CALLSIGN_LEN+1);
3690 NetPlayers.players[N_players].version_major=NetPlayers.players[i].version_major;
3691 NetPlayers.players[N_players].version_minor=NetPlayers.players[i].version_minor;
3692 NetPlayers.players[N_players].rank=NetPlayers.players[i].rank;
3693 ClipRank (&NetPlayers.players[N_players].rank);
3694 network_check_for_old_version(i);
3696 Players[N_players].connected = 1;
3701 if (Network_game_type == IPX_GAME)
3702 network_dump_player(NetPlayers.players[i].network.ipx.server,NetPlayers.players[i].network.ipx.node, DUMP_DORK);
3705 network_dump_appletalk_player(NetPlayers.players[i].network.appletalk.node,NetPlayers.players[i].network.appletalk.net, NetPlayers.players[i].network.appletalk.socket, DUMP_DORK);
3710 for (i = N_players; i < MAX_NUM_NET_PLAYERS; i++) {
3711 if (Network_game_type == IPX_GAME) {
3712 memset(NetPlayers.players[i].network.ipx.node, 0, 6);
3713 memset(NetPlayers.players[i].network.ipx.server, 0, 4);
3715 NetPlayers.players[i].network.appletalk.node = 0;
3716 NetPlayers.players[i].network.appletalk.net = 0;
3717 NetPlayers.players[i].network.appletalk.socket = 0;
3719 memset(NetPlayers.players[i].callsign, 0, CALLSIGN_LEN+1);
3720 NetPlayers.players[i].version_major=0;
3721 NetPlayers.players[i].version_minor=0;
3722 NetPlayers.players[i].rank=0;
3725 mprintf ((0,"Select teams: Game mode is %d\n",Netgame.gamemode));
3727 if (Netgame.gamemode == NETGAME_TEAM_ANARCHY ||
3728 Netgame.gamemode == NETGAME_CAPTURE_FLAG ||
3729 Netgame.gamemode == NETGAME_TEAM_HOARD)
3730 if (!network_select_teams())
3737 network_start_game()
3740 char game_name[NETGAME_NAME_LEN+1];
3741 int chosen_game_mode, game_flags, level;
3743 if (Network_game_type == IPX_GAME) {
3745 Assert( FRAME_INFO_SIZE < IPX_MAX_DATA_SIZE );
3746 mprintf((0, "Using frame_info len %d, max %d.\n", FRAME_INFO_SIZE, IPX_MAX_DATA_SIZE));
3748 if ( !Network_active )
3750 nm_messagebox(NULL, 1, TXT_OK, TXT_IPX_NOT_FOUND );
3758 Assert( FRAME_INFO_SIZE < APPLETALK_MAX_DATA_SIZE );
3759 mprintf((0, "Using frame_info len %d, max %d.\n", sizeof(frame_info), APPLETALK_MAX_DATA_SIZE));
3760 if (Appletalk_active <= 0) {
3761 switch (Appletalk_active) {
3762 case APPLETALK_NOT_OPEN:
3763 sprintf(buf, "Appletalk is not currently active.\nPlease enable AppleTalk from the\nChooser and restart Descent.");
3765 case APPLETALK_BAD_LISTENER:
3766 sprintf(buf, "The Resource Fork of Descent appears damaged.\nPlease re-install Descent or contact\nMacPlay technical support.");
3768 case APPLETALK_NO_LOCAL_ADDR:
3769 sprintf(buf, "Wow! Strange!\n\nNo Local Address.");
3771 case APPLETALK_NO_SOCKET:
3772 sprintf(buf, "All AppleTalk sockets are in use.\nTry shutting down other network\napplications and restarting Descent.\n");
3775 nm_messagebox(NULL, 1, TXT_OK, buf);
3778 strcpy(Network_zone_name, DEFAULT_ZONE_NAME);
3783 change_playernum_to(0);
3785 if (network_find_game())
3787 nm_messagebox(NULL, 1, TXT_OK, TXT_NET_FULL);
3792 i = network_get_game_params( game_name, &chosen_game_mode, &game_flags, &level );
3798 // LoadLevel(level); Old, no longer used.
3800 Netgame.difficulty = Difficulty_level;
3801 Netgame.gamemode = chosen_game_mode;
3802 Netgame.game_status = NETSTAT_STARTING;
3803 Netgame.numplayers = 0;
3804 Netgame.max_numplayers = MaxNumNetPlayers;
3805 Netgame.levelnum = level;
3806 Netgame.protocol_version = MULTI_PROTO_VERSION;
3808 strcpy(Netgame.game_name, game_name);
3810 Network_status = NETSTAT_STARTING;
3813 if (Network_game_type == APPLETALK_GAME) {
3818 show_boxed_message("Registering Netgame");
3820 err = appletalk_register_netgame( game_name, TickCount() );
3821 t1 = timer_get_fixed_seconds() + F1_0;
3822 while (timer_get_fixed_seconds() < t1) ;
3824 } while ( (err == nbpDuplicate) && (count != MAX_REGISTER_TRIES) );
3825 clear_boxed_message();
3826 if ( (err == tooManyReqs) || (count == MAX_REGISTER_TRIES) ) {
3827 nm_messagebox(NULL, 1, TXT_OK, "AppleTalk Network is too busy.\nPlease try again shortly.");
3828 Game_mode = GM_GAME_OVER;
3834 network_set_game_mode(Netgame.gamemode);
3836 d_srand( timer_get_fixed_seconds() );
3837 Netgame.Security=d_rand(); // For syncing Netgames with player packets
3839 if(network_select_players())
3841 StartNewLevel(Netgame.levelnum, 0);
3844 Game_mode = GM_GAME_OVER;
3848 void restart_net_searching(newmenu_item * m)
3852 num_active_games = 0;
3854 memset(Active_games, 0, sizeof(netgame_info)*MAX_ACTIVE_NETGAMES);
3856 for (i = 0; i < MAX_ACTIVE_NETGAMES; i++)
3858 sprintf(m[i+2].text, "%d. ",i+1);
3862 NamesInfoSecurity=-1;
3863 Network_games_changed = 1;
3866 char *ModeLetters[]={"ANRCHY","TEAM","ROBO","COOP","FLAG","HOARD","TMHOARD"};
3868 int NumActiveNetgames=0;
3870 void network_join_poll( int nitems, newmenu_item * menus, int * key, int citem )
3872 // Polling loop for Join Game menu
3874 int i, osocket,join_status,temp;
3881 if ( (Network_game_type == IPX_GAME) && Network_allow_socket_changes ) {
3882 osocket = Network_socket;
3884 if ( *key==KEY_PAGEDOWN ) { Network_socket--; *key = 0; }
3885 if ( *key==KEY_PAGEUP ) { Network_socket++; *key = 0; }
3887 if (Network_socket>99)
3889 if (Network_socket<-99)
3892 if ( Network_socket+IPX_DEFAULT_SOCKET > 0x8000 )
3893 Network_socket = 0x8000 - IPX_DEFAULT_SOCKET;
3895 if ( Network_socket+IPX_DEFAULT_SOCKET < 0 )
3896 Network_socket = IPX_DEFAULT_SOCKET;
3898 if (Network_socket != osocket ) {
3899 sprintf( menus[0].text, "\t%s %+d (PgUp/PgDn to change)", TXT_CURRENT_IPX_SOCKET, Network_socket );
3900 menus[0].redraw = 1;
3901 mprintf(( 0, "Changing to socket %d\n", Network_socket ));
3903 mprintf ((0,"netgood 1!\n"));
3904 ipx_change_default_socket( IPX_DEFAULT_SOCKET + Network_socket );
3905 mprintf ((0,"netgood 2!\n"));
3906 restart_net_searching(menus);
3907 mprintf ((0,"netgood 3!\n"));
3908 network_send_game_list_request();
3909 mprintf ((0,"netgood 4!\n"));
3914 // send a request for game info every 3 seconds
3916 if (Network_game_type == IPX_GAME) {
3917 if (timer_get_approx_seconds() > t1+F1_0*3) {
3918 t1 = timer_get_approx_seconds();
3919 network_send_game_list_request();
3922 } else if (timer_get_approx_seconds() > t1+F1_0*20) {
3924 t1 = timer_get_approx_seconds();
3925 restart_net_searching(menus);
3926 show_boxed_message("Requesting list of Netgames");
3927 network_send_game_list_request();
3928 clear_boxed_message();
3933 temp=num_active_games;
3937 NumActiveNetgames=num_active_games;
3939 if (!Network_games_changed)
3942 if (temp!=num_active_games)
3943 digi_play_sample (SOUND_HUD_MESSAGE,F1_0);
3945 Network_games_changed = 0;
3946 mprintf ((0,"JOIN POLL: I'm looking at %d games!\n",num_active_games));
3948 // Copy the active games data into the menu options
3949 for (i = 0; i < num_active_games; i++)
3951 int game_status = Active_games[i].game_status;
3952 int j,x, k,tx,ty,ta,nplayers = 0;
3953 char levelname[8],MissName[25],GameName[25],thold[2];
3956 // These next two loops protect against menu skewing
3957 // if missiontitle or gamename contain a tab
3959 for (x=0,tx=0,k=0,j=0;j<15;j++)
3961 if (Active_games[i].mission_title[j]=='\t')
3963 thold[0]=Active_games[i].mission_title[j];
3964 gr_get_string_size (thold,&tx,&ty,&ta);
3966 if ((x+=tx)>=LHX(55))
3968 MissName[k]=MissName[k+1]=MissName[k+2]='.';
3973 MissName[k++]=Active_games[i].mission_title[j];
3977 for (x=0,tx=0,k=0,j=0;j<15;j++)
3979 if (Active_games[i].game_name[j]=='\t')
3981 thold[0]=Active_games[i].game_name[j];
3982 gr_get_string_size (thold,&tx,&ty,&ta);
3984 if ((x+=tx)>=LHX(55))
3986 GameName[k]=GameName[k+1]=GameName[k+2]='.';
3990 GameName[k++]=Active_games[i].game_name[j];
3995 nplayers=Active_games[i].numconnected;
3997 if (Active_games[i].levelnum < 0)
3998 sprintf(levelname, "S%d", -Active_games[i].levelnum);
4000 sprintf(levelname, "%d", Active_games[i].levelnum);
4002 if (game_status == NETSTAT_STARTING)
4004 sprintf (menus[i+2].text,"%d.\t%s \t%s \t %d/%d \t%s \t %s \t%s",
4005 i+1,GameName,ModeLetters[Active_games[i].gamemode],nplayers,
4006 Active_games[i].max_numplayers,MissName,levelname,"Forming");
4008 else if (game_status == NETSTAT_PLAYING)
4010 join_status=can_join_netgame(&Active_games[i],NULL);
4011 // mprintf ((0,"Joinstatus=%d\n",join_status));
4014 sprintf (menus[i+2].text,"%d.\t%s \t%s \t %d/%d \t%s \t %s \t%s",
4015 i+1,GameName,ModeLetters[Active_games[i].gamemode],nplayers,
4016 Active_games[i].max_numplayers,MissName,levelname,"Open");
4017 else if (join_status==2)
4018 sprintf (menus[i+2].text,"%d.\t%s \t%s \t %d/%d \t%s \t %s \t%s",
4019 i+1,GameName,ModeLetters[Active_games[i].gamemode],nplayers,
4020 Active_games[i].max_numplayers,MissName,levelname,"Full");
4021 else if (join_status==3)
4022 sprintf (menus[i+2].text,"%d.\t%s \t%s \t %d/%d \t%s \t %s \t%s",
4023 i+1,GameName,ModeLetters[Active_games[i].gamemode],nplayers,
4024 Active_games[i].max_numplayers,MissName,levelname,"Restrict");
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,"Closed");
4032 sprintf (menus[i+2].text,"%d.\t%s \t%s \t %d/%d \t%s \t %s \t%s",
4033 i+1,GameName,ModeLetters[Active_games[i].gamemode],nplayers,
4034 Active_games[i].max_numplayers,MissName,levelname,"Between");
4037 Assert(strlen(menus[i+2].text) < 100);
4038 menus[i+2].redraw = 1;
4041 for (i = num_active_games; i < MAX_ACTIVE_NETGAMES; i++)
4043 sprintf(menus[i+2].text, "%d. ",i+1);
4044 menus[i+2].redraw = 1;
4049 network_wait_for_sync(void)
4055 Network_status = NETSTAT_WAITING;
4057 m[0].type=NM_TYPE_TEXT; m[0].text = text;
4058 m[1].type=NM_TYPE_TEXT; m[1].text = TXT_NET_LEAVE;
4060 i = network_send_request();
4065 sprintf( m[0].text, "%s\n'%s' %s", TXT_NET_WAITING, NetPlayers.players[i].callsign, TXT_NET_TO_ENTER );
4068 choice=newmenu_do( NULL, TXT_WAIT, 2, m, network_sync_poll );
4073 if (Network_status != NETSTAT_PLAYING)
4077 // if (Network_status == NETSTAT_ENDLEVEL)
4079 // network_send_endlevel_packet(0);
4080 // longjmp(LeaveGame, 0);
4083 mprintf((0, "Aborting join.\n"));
4084 me.type = PID_QUIT_JOINING;
4085 memcpy( me.player.callsign, Players[Player_num].callsign, CALLSIGN_LEN+1 );
4086 if (Network_game_type == IPX_GAME) {
4087 memcpy( me.player.network.ipx.node, ipx_get_my_local_address(), 6 );
4088 memcpy( me.player.network.ipx.server, ipx_get_my_server_address(), 4 );
4090 ipx_send_internetwork_packet_data( (ubyte *)&me, sizeof(sequence_packet), NetPlayers.players[0].network.ipx.server, NetPlayers.players[0].network.ipx.node );
4092 send_sequence_packet(me, NetPlayers.players[0].network.ipx.server, NetPlayers.players[0].network.ipx.node, NULL);
4096 me.player.network.appletalk.node = appletalk_get_my_node();
4097 me.player.network.appletalk.net = appletalk_get_my_net();
4098 me.player.network.appletalk.socket = appletalk_get_my_socket();
4102 Function_mode = FMODE_MENU;
4103 Game_mode = GM_GAME_OVER;
4104 return(-1); // they cancelled
4110 network_request_poll( int nitems, newmenu_item * menus, int * key, int citem )
4112 // Polling loop for waiting-for-requests menu
4122 // Send our endlevel packet at regular intervals
4124 // if (timer_get_approx_seconds() > t1+ENDLEVEL_SEND_INTERVAL)
4126 // network_send_endlevel_packet();
4127 // t1 = timer_get_approx_seconds();
4132 for (i = 0; i < N_players; i++)
4134 if ((Players[i].connected == 1) || (Players[i].connected == 0))
4138 if (num_ready == N_players) // All players have checked in or are disconnected
4145 network_wait_for_requests(void)
4147 // Wait for other players to load the level before we send the sync
4151 Network_status = NETSTAT_WAITING;
4153 m[0].type=NM_TYPE_TEXT; m[0].text = TXT_NET_LEAVE;
4155 mprintf((0, "Entered wait_for_requests : N_players = %d.\n", N_players));
4157 for (choice = 0; choice < N_players; choice++)
4158 mprintf((0, "Players[%d].connected = %d.\n", choice, Players[choice].connected));
4160 Network_status = NETSTAT_WAITING;
4163 Players[Player_num].connected = 1;
4166 choice = newmenu_do(NULL, TXT_WAIT, 1, m, network_request_poll);
4171 choice = nm_messagebox(NULL, 3, TXT_YES, TXT_NO, TXT_START_NOWAIT, TXT_QUITTING_NOW);
4177 // User confirmed abort
4179 for (i=0; i < N_players; i++) {
4180 if ((Players[i].connected != 0) && (i != Player_num)) {
4181 if (Network_game_type == IPX_GAME)
4182 network_dump_player(NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node, DUMP_ABORTED);
4185 network_dump_appletalk_player(NetPlayers.players[i].network.appletalk.node, NetPlayers.players[i].network.appletalk.net, NetPlayers.players[i].network.appletalk.socket, DUMP_ABORTED);
4191 if (Network_game_type == APPLETALK_GAME)
4192 network_release_registered_game();
4194 longjmp(LeaveGame, 0);
4196 else if (choice != -2)
4201 network_level_sync(void)
4203 // Do required syncing between (before) levels
4207 mprintf((0, "Player %d entering network_level_sync.\n", Player_num));
4209 MySyncPackInitialized = 0;
4211 // my_segments_checksum = netmisc_calc_checksum(Segments, sizeof(segment)*(Highest_segment_index+1));
4213 network_flush(); // Flush any old packets
4216 result = network_wait_for_sync();
4217 else if (network_i_am_master())
4219 network_wait_for_requests();
4220 network_send_sync();
4224 result = network_wait_for_sync();
4226 network_count_powerups_in_mine();
4230 Players[Player_num].connected = 0;
4231 network_send_endlevel_packet();
4233 if (Network_game_type == APPLETALK_GAME)
4234 network_release_registered_game();
4236 longjmp(LeaveGame, 0);
4241 void network_count_powerups_in_mine(void)
4245 for (i=0;i<MAX_POWERUP_TYPES;i++)
4246 PowerupsInMine[i]=0;
4248 for (i=0;i<=Highest_object_index;i++)
4250 if (Objects[i].type==OBJ_POWERUP)
4252 PowerupsInMine[Objects[i].id]++;
4253 if (multi_powerup_is_4pack(Objects[i].id))
4254 PowerupsInMine[Objects[i].id-1]+=4;
4262 // code to release the NBP binding of an appletalk game
4264 void network_release_registered_game()
4266 if (Network_game_type == APPLETALK_GAME)
4267 appletalk_remove_netgame();
4270 // code to sort zone lists....
4272 int zone_sort_func(const char **e0, const char **e1)
4274 return strcmp(*e0, *e1);
4277 void network_get_appletalk_zone()
4279 int num_zones, i, item, default_item;
4281 char default_zone[MAX_ZONE_LENGTH]; // my zone
4283 Network_zone_name[0] = '\0';
4285 show_boxed_message("Looking for AppleTalk Zones");
4286 num_zones = appletalk_get_zone_names(&zone_list);
4287 clear_boxed_message();
4289 if (num_zones < 0) { // error in getting zone list...maybe no router available....
4290 if ( (num_zones == tooManyReqs) || (num_zones == noDataArea) ){
4291 nm_messagebox(NULL, 1, TXT_OK, "AppleTalk Network is too busy.\nPlease try again shortly.");
4292 longjmp(LeaveGame,0);
4297 if (num_zones == 0) {
4298 strcpy(Network_zone_name, DEFAULT_ZONE_NAME);
4302 if (num_zones == 1) {
4303 Network_zone_name[0] = (char)(strlen(zone_list[0]));
4304 memcpy( &(Network_zone_name[1]), zone_list[0], strlen(zone_list[0]) );
4308 // sort the zone names
4310 for (i = 0; i < num_zones; i++)
4311 strlwr(zone_list[i]);
4313 qsort(zone_list, num_zones, sizeof(char *), zone_sort_func);
4315 // get my current zone so we can highlight that one first
4317 if (appletalk_get_my_zone(default_zone))
4320 for (i = 0; i < num_zones; i++) {
4321 if ( !stricmp(zone_list[i], default_zone) ) {
4329 item = newmenu_listbox1("AppleTalk Zones", num_zones, zone_list, 0, default_item, NULL);
4334 Network_zone_name[0] = (char)(strlen(zone_list[item]));
4335 memcpy( &(Network_zone_name[1]), zone_list[item], strlen(zone_list[item]) );
4338 for (i = 0; i < num_zones; i++)
4339 d_free(zone_list[i]);
4344 void nm_draw_background1(char * filename);
4346 //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.
4347 int network_do_join_game(netgame_info *jgame, AllNetPlayers_info *jplayers){
4348 if (jgame->game_status == NETSTAT_ENDLEVEL)
4350 nm_messagebox(TXT_SORRY, 1, TXT_OK, TXT_NET_GAME_BETWEEN2);
4354 if ((jgame->protocol_version != MULTI_PROTO_VERSION) &&
4355 (jgame->protocol_version != MULTI_PROTO_D2X_VER))
4357 nm_messagebox(TXT_SORRY, 1, TXT_OK, TXT_VERSION_MISMATCH);
4361 if (jgame->protocol_version == MULTI_PROTO_D2X_VER &&
4362 jgame->required_subprotocol > MULTI_PROTO_D2X_MINOR)
4364 nm_messagebox(TXT_SORRY, 1, TXT_OK, "This game uses features\nnot present in this version.");
4368 // Check for valid mission name
4369 mprintf((0, "Loading mission:%s.\n", jgame->mission_name));
4370 if (!load_mission_by_name(jgame->mission_name))
4372 nm_messagebox(NULL, 1, TXT_OK, TXT_MISSION_NOT_FOUND);
4374 //add getlevel functionality here - Victor Rachels
4381 if (!can_join_netgame(jgame, jplayers))
4383 if (jgame->numplayers == jgame->max_numplayers)
4384 nm_messagebox(TXT_SORRY, 1, TXT_OK, TXT_GAME_FULL);
4386 nm_messagebox(TXT_SORRY, 1, TXT_OK, TXT_IN_PROGRESS);
4390 // Choice is valid, prepare to join in
4392 memcpy(&Netgame, jgame, sizeof(netgame_info));
4394 Difficulty_level = Netgame.difficulty;
4395 MaxNumNetPlayers = Netgame.max_numplayers;
4396 change_playernum_to(1);
4398 network_set_game_mode(Netgame.gamemode);
4400 StartNewLevel(Netgame.levelnum, 0);
4402 return 1; // look ma, we're in a game!!!
4405 void network_join_game()
4408 char menu_text[MAX_ACTIVE_NETGAMES+2][200];
4410 newmenu_item m[MAX_ACTIVE_NETGAMES+2];
4412 if (Network_game_type == IPX_GAME) {
4413 if ( !Network_active )
4415 nm_messagebox(NULL, 1, TXT_OK, TXT_IPX_NOT_FOUND);
4419 } else if (Appletalk_active <= 0) {
4422 switch (Appletalk_active) {
4423 case APPLETALK_NOT_OPEN:
4424 sprintf(buf, "Appletalk is not currently active.\nPlease enable AppleTalk from the\nChooser and restart Descent.");
4426 case APPLETALK_BAD_LISTENER:
4427 sprintf(buf, "The Resource Fork of Descent appears damaged.\nPlease re-install Descent or contact\nMacPlay technical support.");
4429 case APPLETALK_NO_LOCAL_ADDR:
4430 sprintf(buf, "Wow! Strange!\n\nNo Local Address.");
4432 case APPLETALK_NO_SOCKET:
4433 sprintf(buf, "All AppleTalk sockets are in use.\nTry shutting down other network\napplications and restarting Descent.\n");
4436 nm_messagebox(NULL, 1, TXT_OK, buf);
4448 if (Network_game_type == APPLETALK_GAME)
4449 network_get_appletalk_zone();
4452 Network_send_objects = 0;
4453 Network_sending_extras=0;
4456 Network_status = NETSTAT_BROWSING; // We are looking at a game menu
4459 network_listen(); // Throw out old info
4462 if (Network_game_type == IPX_GAME)
4463 #endif // note link to if
4464 network_send_game_list_request(); // broadcast a request for lists
4466 num_active_games = 0;
4468 memset(m, 0, sizeof(newmenu_item)*MAX_ACTIVE_NETGAMES);
4469 memset(Active_games, 0, sizeof(netgame_info)*MAX_ACTIVE_NETGAMES);
4470 memset(ActiveNetPlayers,0,sizeof(AllNetPlayers_info)*MAX_ACTIVE_NETGAMES);
4472 gr_set_fontcolor(BM_XRGB(15,15,23),-1);
4474 m[0].text = menu_text[0];
4475 m[0].type = NM_TYPE_TEXT;
4476 if (Network_game_type == IPX_GAME) {
4477 if (Network_allow_socket_changes)
4478 sprintf( m[0].text, "\tCurrent IPX Socket is default %+d (PgUp/PgDn to change)", Network_socket );
4480 strcpy( m[0].text, "" );
4483 p2cstr(Network_zone_name);
4484 if (strcmp(Network_zone_name, "*")) // only print if there is a zone name
4485 sprintf(m[0].text, "\tCurrent Zone is %s", Network_zone_name); // is Network_zone_name a pascal string????
4486 c2pstr(Network_zone_name);
4490 m[1].text=menu_text[1];
4491 m[1].type=NM_TYPE_TEXT;
4492 sprintf (m[1].text,"\tGAME \tMODE \t#PLYRS \tMISSION \tLEV \tSTATUS");
4494 for (i = 0; i < MAX_ACTIVE_NETGAMES; i++) {
4495 m[i+2].text = menu_text[i+2];
4496 m[i+2].type = NM_TYPE_MENU;
4497 sprintf(m[i+2].text, "%d. ", i+1);
4501 Network_games_changed = 1;
4504 nm_draw_background1(Menu_pcx_name); //load this here so if we abort after loading level, we restore the palette
4505 gr_palette_load(gr_palette);
4506 ExtGameStatus=GAMESTAT_JOIN_NETGAME;
4507 choice=newmenu_dotiny("NETGAMES", NULL,MAX_ACTIVE_NETGAMES+2, m, network_join_poll);
4511 Network_status = NETSTAT_MENU;
4512 return; // they cancelled
4516 if (choice >=num_active_games)
4518 nm_messagebox(TXT_SORRY, 1, TXT_OK, TXT_INVALID_CHOICE);
4522 // Choice has been made and looks legit
4523 if (Active_games[choice].game_status == NETSTAT_ENDLEVEL)
4525 nm_messagebox(TXT_SORRY, 1, TXT_OK, TXT_NET_GAME_BETWEEN2);
4529 if (Active_games[choice].protocol_version != MULTI_PROTO_VERSION)
4531 if (Active_games[choice].protocol_version == 3) {
4533 nm_messagebox(TXT_SORRY, 1, TXT_OK, "Your version of Descent 2\nis incompatible with the\nDemo version");
4536 else if (Active_games[choice].protocol_version == 4) {
4538 nm_messagebox(TXT_SORRY, 1, TXT_OK, "This Demo version of\nDescent 2 is incompatible\nwith the full commercial version");
4542 nm_messagebox(TXT_SORRY, 1, TXT_OK, TXT_VERSION_MISMATCH);
4549 // Check for valid mission name
4550 mprintf((0, "Loading mission:%s.\n", Active_games[choice].mission_name));
4551 if (!load_mission_by_name(Active_games[choice].mission_name))
4553 nm_messagebox(NULL, 1, TXT_OK, TXT_MISSION_NOT_FOUND);
4559 #if defined (D2_OEM)
4561 if (Active_games[choice].levelnum>8)
4563 nm_messagebox(NULL, 1, TXT_OK, "This OEM version only supports\nthe first 8 levels!");
4569 if (!network_wait_for_all_info (choice))
4571 nm_messagebox (TXT_SORRY,1,TXT_OK,"There was a join error!");
4572 Network_status = NETSTAT_BROWSING; // We are looking at a game menu
4576 Network_status = NETSTAT_BROWSING; // We are looking at a game menu
4578 if (!can_join_netgame(&Active_games[choice],&ActiveNetPlayers[choice]))
4580 if (Active_games[choice].numplayers == Active_games[choice].max_numplayers)
4581 nm_messagebox(TXT_SORRY, 1, TXT_OK, TXT_GAME_FULL);
4583 nm_messagebox(TXT_SORRY, 1, TXT_OK, TXT_IN_PROGRESS);
4587 // Choice is valid, prepare to join in
4589 memcpy(&Netgame, &Active_games[choice], sizeof(netgame_info));
4590 memcpy (&NetPlayers,&ActiveNetPlayers[choice],sizeof(AllNetPlayers_info));
4592 Difficulty_level = Netgame.difficulty;
4593 MaxNumNetPlayers = Netgame.max_numplayers;
4594 change_playernum_to(1);
4598 // register the joining player with NBP. This will have the nice effect of a player wanting to
4599 // join to be able to see the netgame if this player were to become the master.
4601 if (Network_game_type == APPLETALK_GAME) {
4606 show_boxed_message("Registering Netgame");
4608 err = appletalk_register_netgame( Active_games[choice].game_name, TickCount() );
4609 t1 = timer_get_fixed_seconds() + F1_0;
4610 while ( timer_get_fixed_seconds() < t1 ) ;
4612 } while ( (err == nbpDuplicate) && (count != MAX_REGISTER_TRIES) );
4613 clear_boxed_message();
4614 if ( (err == tooManyReqs) || (count == MAX_REGISTER_TRIES) ) {
4615 nm_messagebox(NULL, 1, TXT_OK, "AppleTalk Network is too busy.\nPlease try again shortly.");
4621 network_set_game_mode(Netgame.gamemode);
4623 network_AdjustMaxDataSize ();
4625 StartNewLevel(Netgame.levelnum, 0);
4627 return; // look ma, we're in a game!!!
4630 void network_AdjustMaxDataSize ()
4633 if (Netgame.ShortPackets)
4634 MaxXDataSize=NET_XDATA_SIZE;
4636 MaxXDataSize=NET_XDATA_SIZE;
4640 fix StartWaitAllTime=0;
4641 int WaitAllChoice=0;
4642 #define ALL_INFO_REQUEST_INTERVAL F1_0*3
4644 void network_wait_all_poll( int nitems, newmenu_item * menus, int * key, int citem )
4652 if (timer_get_approx_seconds() > t1+ALL_INFO_REQUEST_INTERVAL)
4654 network_send_all_info_request(PID_SEND_ALL_GAMEINFO,SecurityCheck);
4655 t1 = timer_get_approx_seconds();
4658 network_do_big_wait(WaitAllChoice);
4660 if(SecurityCheck==-1)
4664 int network_wait_for_all_info (int choice)
4670 m[0].type=NM_TYPE_TEXT; m[0].text = "Press Escape to cancel";
4672 WaitAllChoice=choice;
4673 StartWaitAllTime=timer_get_approx_seconds();
4674 SecurityCheck=Active_games[choice].Security;
4678 pick=newmenu_do( NULL, "Connecting...", 1, m, network_wait_all_poll );
4680 if (pick>-1 && SecurityCheck!=-1)
4683 if (SecurityCheck==-1)
4692 void network_do_big_wait(int choice)
4695 ubyte packet[IPX_MAX_DATA_SIZE],*data;
4696 AllNetPlayers_info *temp_info;
4698 AllNetPlayers_info info_struct;
4699 ubyte apacket[APPLETALK_MAX_DATA_SIZE];
4703 if (Network_game_type == APPLETALK_GAME)
4704 size=appletalk_get_packet_data( apacket );
4707 size=ipx_get_packet_data( packet );
4712 if (Network_game_type == APPLETALK_GAME)
4722 if (Network_game_type == IPX_GAME) {
4724 memcpy((ubyte *)&TempNetInfo, data, sizeof(netgame_info));
4726 receive_netgame_packet(data, &TempNetInfo, 0);
4729 memcpy((ubyte *)&TempNetInfo, data, sizeof(netgame_info));
4731 mprintf ((0,"This is %s game with a security of %d\n",TempNetInfo.game_name,TempNetInfo.Security));
4733 if (TempNetInfo.Security !=SecurityCheck)
4735 mprintf ((0,"Bad security on big_wait...rejecting.\n"));
4739 if (NetSecurityFlag==NETSECURITY_WAIT_FOR_GAMEINFO)
4741 if (TempPlayersInfo->Security==TempNetInfo.Security)
4743 mprintf ((0,"EQUAL !: Game=%d Players=%d ",TempPlayersInfo->Security,TempNetInfo.Security));
4744 if (TempPlayersInfo->Security==SecurityCheck)
4746 memcpy (&Active_games[choice],(ubyte *)&TempNetInfo,sizeof(netgame_info));
4747 memcpy (&ActiveNetPlayers[choice],TempPlayersInfo,sizeof(AllNetPlayers_info));
4754 NetSecurityFlag=NETSECURITY_WAIT_FOR_PLAYERS;
4755 NetSecurityNum=TempNetInfo.Security;
4757 if (network_wait_for_playerinfo())
4759 mprintf ((0,"HUH? Game=%d Player=%d\n",NetSecurityNum,TempPlayersInfo->Security));
4760 memcpy (&Active_games[choice],(ubyte *)&TempNetInfo,sizeof(netgame_info));
4761 memcpy (&ActiveNetPlayers[choice],TempPlayersInfo,sizeof(AllNetPlayers_info));
4768 case PID_PLAYERSINFO:
4769 mprintf ((0,"Got a PID_PLAYERSINFO!\n"));
4771 if (Network_game_type == IPX_GAME) {
4773 temp_info=(AllNetPlayers_info *)data;
4775 receive_netplayers_packet(data, &info_struct);
4776 temp_info = &info_struct;
4779 temp_info = (AllNetPlayers_info *)data;
4781 if (temp_info->Security!=SecurityCheck)
4782 break; // If this isn't the guy we're looking for, move on
4784 memcpy (&TempPlayersBase,(ubyte *)&temp_info,sizeof(AllNetPlayers_info));
4785 TempPlayersInfo=&TempPlayersBase;
4786 WaitingForPlayerInfo=0;
4787 NetSecurityNum=TempPlayersInfo->Security;
4788 NetSecurityFlag=NETSECURITY_WAIT_FOR_GAMEINFO;
4794 void network_leave_game()
4798 network_do_frame(1, 1);
4801 fclose (SendLogFile);
4802 fclose (RecieveLogFile);
4805 if ((network_i_am_master()))
4807 while (Network_sending_extras>1 && Player_joining_extras!=-1)
4808 network_send_extras();
4810 Netgame.numplayers = 0;
4813 network_send_game_info(NULL);
4816 mprintf ((0,"HEY! I'm master and I've left.\n"));
4819 Players[Player_num].connected = 0;
4820 network_send_endlevel_packet();
4821 change_playernum_to(0);
4822 Game_mode = GM_GAME_OVER;
4823 write_player_file();
4825 // WIN(ipx_destroy_read_thread());
4830 void network_flush()
4833 ubyte apacket[APPLETALK_MAX_DATA_SIZE];
4835 ubyte packet[IPX_MAX_DATA_SIZE];
4838 if ( (Network_game_type == APPLETALK_GAME) && (Appletalk_active <= 0) )
4842 if ( Network_game_type == IPX_GAME )
4843 if (!Network_active) return;
4846 if (Network_game_type == APPLETALK_GAME)
4847 while (appletalk_get_packet_data(apacket) > 0) ;
4850 while (ipx_get_packet_data(packet) > 0) ;
4853 void network_listen()
4856 ubyte apacket[APPLETALK_MAX_DATA_SIZE];
4859 ubyte packet[IPX_MAX_DATA_SIZE];
4862 if (Network_status==NETSTAT_PLAYING && Netgame.ShortPackets && !Network_send_objects)
4864 loopmax=N_players*Netgame.PacketsPerSec;
4868 if ( (Network_game_type == APPLETALK_GAME) && (Appletalk_active <= 0) )
4872 if (Network_game_type == IPX_GAME)
4873 if (!Network_active) return;
4875 if (!(Game_mode & GM_NETWORK) && (Function_mode == FMODE_GAME))
4876 mprintf((0, "Calling network_listen() when not in net game.\n"));
4878 WaitingForPlayerInfo=1;
4879 NetSecurityFlag=NETSECURITY_OFF;
4882 if (Network_game_type == IPX_GAME) {
4883 size = ipx_get_packet_data( packet );
4885 network_process_packet( packet, size );
4888 size = ipx_get_packet_data( packet );
4892 size = appletalk_get_packet_data( apacket );
4894 network_process_packet( apacket, size );
4897 size = appletalk_get_packet_data( apacket );
4903 int network_wait_for_playerinfo()
4906 ubyte packet[IPX_MAX_DATA_SIZE];
4907 struct AllNetPlayers_info *TempInfo;
4911 AllNetPlayers_info info_struct;
4912 ubyte apacket[APPLETALK_MAX_DATA_SIZE];
4916 if ( (Network_game_type == APPLETALK_GAME) && (Appletalk_active <= 0) )
4920 if ( Network_game_type == IPX_GAME)
4921 if (!Network_active) return(0);
4923 // if (!WaitingForPlayerInfo)
4926 if (!(Game_mode & GM_NETWORK) && (Function_mode == FMODE_GAME))
4928 mprintf((0, "Calling network_wait_for_playerinfo() when not in net game.\n"));
4930 if (Network_status==NETSTAT_PLAYING)
4932 Int3(); //MY GOD! Get Jason...this is the source of many problems
4935 basetime=timer_get_approx_seconds();
4937 while (WaitingForPlayerInfo && retries<50 && (timer_get_approx_seconds()<(basetime+(F1_0*5))))
4939 if (Network_game_type == IPX_GAME) {
4940 size = ipx_get_packet_data( packet );
4944 size = appletalk_get_packet_data( apacket );
4949 if (size>0 && id==PID_PLAYERSINFO)
4952 if (Network_game_type == APPLETALK_GAME) {
4953 TempInfo = (AllNetPlayers_info *)apacket;
4955 receive_netplayers_packet(packet, &info_struct);
4956 TempInfo = &info_struct;
4959 TempInfo=(AllNetPlayers_info *)packet;
4964 if (NetSecurityFlag==NETSECURITY_WAIT_FOR_PLAYERS)
4966 if (NetSecurityNum==TempInfo->Security)
4968 mprintf ((0,"HEYEQUAL: Player=%d Game=%d\n",TempInfo->Security,NetSecurityNum));
4969 memcpy (&TempPlayersBase,(ubyte *)TempInfo,sizeof(AllNetPlayers_info));
4970 TempPlayersInfo=&TempPlayersBase;
4971 NetSecurityFlag=NETSECURITY_OFF;
4973 WaitingForPlayerInfo=0;
4981 mprintf ((0,"I'm original!\n"));
4983 NetSecurityNum=TempInfo->Security;
4984 NetSecurityFlag=NETSECURITY_WAIT_FOR_GAMEINFO;
4986 memcpy (&TempPlayersBase,(ubyte *)TempInfo,sizeof(AllNetPlayers_info));
4987 TempPlayersInfo=&TempPlayersBase;
4988 WaitingForPlayerInfo=0;
4997 void network_send_data( ubyte * ptr, int len, int urgent )
5003 fprintf (SendLogFile,"Packet type: %d Len:%d Urgent:%d TT=%d\n",ptr[0],len,urgent,TTSent[ptr[0]]);
5004 fflush (SendLogFile);
5007 if (Endlevel_sequence)
5010 if (!MySyncPackInitialized) {
5011 MySyncPackInitialized = 1;
5012 memset( &MySyncPack, 0, sizeof(frame_info) );
5018 if ((MySyncPack.data_size+len) > MaxXDataSize ) {
5020 network_do_frame(1, 0);
5021 if (MySyncPack.data_size != 0) {
5022 mprintf((0, "%d bytes were added to data by network_do_frame!\n", MySyncPack.data_size));
5025 // Int3(); // Trying to send too much!
5027 mprintf((0, "Packet overflow, sending additional packet, type %d len %d.\n", ptr[0], len));
5028 Assert(check == ptr[0]);
5031 Assert(MySyncPack.data_size+len <= MaxXDataSize);
5033 memcpy( &MySyncPack.data[MySyncPack.data_size], ptr, len );
5034 MySyncPack.data_size += len;
5037 void network_timeout_player(int playernum)
5039 // Remove a player from the game if we haven't heard from them in
5043 Assert(playernum < N_players);
5044 Assert(playernum > -1);
5046 network_disconnect_player(playernum);
5047 create_player_appearance_effect(&Objects[Players[playernum].objnum]);
5049 digi_play_sample(SOUND_HUD_MESSAGE, F1_0);
5051 HUD_init_message("%s %s", Players[playernum].callsign, TXT_DISCONNECTING);
5052 for (i = 0; i < N_players; i++)
5053 if (Players[i].connected)
5058 nm_messagebox(NULL, 1, TXT_OK, TXT_YOU_ARE_ONLY);
5062 fix last_send_time = 0;
5063 fix last_timeout_check = 0;
5066 void squish_short_frame_info(short_frame_info old_info, ubyte *data)
5072 data[0] = old_info.type; loc++; loc += 3; // skip three for pad byte
5073 tmpi = swapint(old_info.numpackets);
5074 memcpy(&(data[loc]), &tmpi, 4); loc += 4;
5076 memcpy(&(data[loc]), old_info.thepos.bytemat, 9); loc += 9;
5077 tmps = INTEL_SHORT(old_info.thepos.xo);
5078 memcpy(&(data[loc]), &tmps, 2); loc += 2;
5079 tmps = INTEL_SHORT(old_info.thepos.yo);
5080 memcpy(&(data[loc]), &tmps, 2); loc += 2;
5081 tmps = INTEL_SHORT(old_info.thepos.zo);
5082 memcpy(&(data[loc]), &tmps, 2); loc += 2;
5083 tmps = INTEL_SHORT(old_info.thepos.segment);
5084 memcpy(&(data[loc]), &tmps, 2); loc += 2;
5085 tmps = INTEL_SHORT(old_info.thepos.velx);
5086 memcpy(&(data[loc]), &tmps, 2); loc += 2;
5087 tmps = INTEL_SHORT(old_info.thepos.vely);
5088 memcpy(&(data[loc]), &tmps, 2); loc += 2;
5089 tmps = INTEL_SHORT(old_info.thepos.velz);
5090 memcpy(&(data[loc]), &tmps, 2); loc += 2;
5092 tmps = swapshort(old_info.data_size);
5093 memcpy(&(data[loc]), &tmps, 2); loc += 2;
5095 data[loc] = old_info.playernum; loc++;
5096 data[loc] = old_info.obj_render_type; loc++;
5097 data[loc] = old_info.level_num; loc++;
5098 memcpy(&(data[loc]), old_info.data, old_info.data_size);
5102 char NakedBuf[NET_XDATA_SIZE+4];
5103 int NakedPacketLen=0;
5104 int NakedPacketDestPlayer=-1;
5106 void network_do_frame(int force, int listen)
5109 short_frame_info ShortSyncPack;
5110 static fix LastEndlevel=0;
5112 if (!(Game_mode&GM_NETWORK)) return;
5114 if ((Network_status != NETSTAT_PLAYING) || (Endlevel_sequence)) // Don't send postion during escape sequence...
5119 Assert (NakedPacketDestPlayer>-1);
5120 // mprintf ((0,"Sending a naked packet to %s (%d bytes)!\n",Players[NakedPacketDestPlayer].callsign,NakedPacketLen));
5121 if (Network_game_type == IPX_GAME)
5122 ipx_send_packet_data( (ubyte *)NakedBuf, NakedPacketLen, NetPlayers.players[NakedPacketDestPlayer].network.ipx.server, NetPlayers.players[NakedPacketDestPlayer].network.ipx.node,Players[NakedPacketDestPlayer].net_address );
5125 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 );
5128 NakedPacketDestPlayer=-1;
5131 if (WaitForRefuseAnswer && timer_get_approx_seconds()>(RefuseTimeLimit+(F1_0*12)))
5132 WaitForRefuseAnswer=0;
5134 last_send_time += FrameTime;
5135 last_timeout_check += FrameTime;
5137 // Send out packet PacksPerSec times per second maximum... unless they fire, then send more often...
5138 if ( (last_send_time>F1_0/Netgame.PacketsPerSec) || (Network_laser_fired) || force || PacketUrgent ) {
5139 if ( Players[Player_num].connected ) {
5140 int objnum = Players[Player_num].objnum;
5144 multi_send_robot_frame(0);
5145 multi_send_fire(); // Do firing if needed..
5150 if (Netgame.ShortPackets)
5153 ubyte send_data[IPX_MAX_DATA_SIZE];
5156 create_shortpos(&ShortSyncPack.thepos, Objects+objnum, 0);
5157 ShortSyncPack.type = PID_PDATA;
5158 ShortSyncPack.playernum = Player_num;
5159 ShortSyncPack.obj_render_type = Objects[objnum].render_type;
5160 ShortSyncPack.level_num = Current_level_num;
5161 ShortSyncPack.data_size = MySyncPack.data_size;
5162 memcpy (&ShortSyncPack.data[0],&MySyncPack.data[0],MySyncPack.data_size);
5164 for (i=0; i<N_players; i++ ) {
5165 if ( (Players[i].connected) && (i!=Player_num ) ) {
5166 MySyncPack.numpackets = Players[i].n_packets_sent++;
5167 ShortSyncPack.numpackets=MySyncPack.numpackets;
5168 if (Network_game_type == IPX_GAME) {
5170 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 );
5172 squish_short_frame_info(ShortSyncPack, send_data);
5173 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 );
5177 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 );
5183 else // If long packets
5187 MySyncPack.type = PID_PDATA;
5188 MySyncPack.playernum = Player_num;
5189 MySyncPack.obj_render_type = Objects[objnum].render_type;
5190 MySyncPack.level_num = Current_level_num;
5191 MySyncPack.obj_segnum = Objects[objnum].segnum;
5192 MySyncPack.obj_pos = Objects[objnum].pos;
5193 MySyncPack.obj_orient = Objects[objnum].orient;
5194 MySyncPack.phys_velocity = Objects[objnum].mtype.phys_info.velocity;
5195 MySyncPack.phys_rotvel = Objects[objnum].mtype.phys_info.rotvel;
5197 send_data_size = MySyncPack.data_size; // do this so correct size data is sent
5199 #ifdef MACINTOSH // do the swap stuff
5200 if (Network_game_type == IPX_GAME) {
5201 MySyncPack.obj_segnum = INTEL_SHORT(MySyncPack.obj_segnum);
5202 MySyncPack.obj_pos.x = INTEL_INT((int)MySyncPack.obj_pos.x);
5203 MySyncPack.obj_pos.y = INTEL_INT((int)MySyncPack.obj_pos.y);
5204 MySyncPack.obj_pos.z = INTEL_INT((int)MySyncPack.obj_pos.z);
5206 MySyncPack.obj_orient.rvec.x = INTEL_INT((int)MySyncPack.obj_orient.rvec.x);
5207 MySyncPack.obj_orient.rvec.y = INTEL_INT((int)MySyncPack.obj_orient.rvec.y);
5208 MySyncPack.obj_orient.rvec.z = INTEL_INT((int)MySyncPack.obj_orient.rvec.z);
5209 MySyncPack.obj_orient.uvec.x = INTEL_INT((int)MySyncPack.obj_orient.uvec.x);
5210 MySyncPack.obj_orient.uvec.y = INTEL_INT((int)MySyncPack.obj_orient.uvec.y);
5211 MySyncPack.obj_orient.uvec.z = INTEL_INT((int)MySyncPack.obj_orient.uvec.z);
5212 MySyncPack.obj_orient.fvec.x = INTEL_INT((int)MySyncPack.obj_orient.fvec.x);
5213 MySyncPack.obj_orient.fvec.y = INTEL_INT((int)MySyncPack.obj_orient.fvec.y);
5214 MySyncPack.obj_orient.fvec.z = INTEL_INT((int)MySyncPack.obj_orient.fvec.z);
5216 MySyncPack.phys_velocity.x = INTEL_INT((int)MySyncPack.phys_velocity.x);
5217 MySyncPack.phys_velocity.y = INTEL_INT((int)MySyncPack.phys_velocity.y);
5218 MySyncPack.phys_velocity.z = INTEL_INT((int)MySyncPack.phys_velocity.z);
5220 MySyncPack.phys_rotvel.x = INTEL_INT((int)MySyncPack.phys_rotvel.x);
5221 MySyncPack.phys_rotvel.y = INTEL_INT((int)MySyncPack.phys_rotvel.y);
5222 MySyncPack.phys_rotvel.z = INTEL_INT((int)MySyncPack.phys_rotvel.z);
5224 MySyncPack.data_size = INTEL_SHORT(MySyncPack.data_size);
5228 for (i=0; i<N_players; i++ ) {
5229 if ( (Players[i].connected) && (i!=Player_num ) ) {
5230 if (Network_game_type == IPX_GAME)
5231 MySyncPack.numpackets = INTEL_INT(Players[i].n_packets_sent);
5234 MySyncPack.numpackets = Players[i].n_packets_sent;
5237 Players[i].n_packets_sent++;
5238 if (Network_game_type == IPX_GAME)
5239 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 );
5242 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);
5248 MySyncPack.data_size = 0; // Start data over at 0 length.
5249 if (Control_center_destroyed)
5252 Players[Player_num].connected=3;
5253 if (timer_get_approx_seconds() > (LastEndlevel+(F1_0/2)))
5255 network_send_endlevel_packet();
5256 LastEndlevel=timer_get_approx_seconds();
5259 //mprintf( (0, "Packet has %d bytes appended (TS=%d)\n", MySyncPack.data_size, sizeof(frame_info)-MaxXDataSize+MySyncPack.data_size ));
5266 if ((last_timeout_check > F1_0) && !(Control_center_destroyed))
5268 fix approx_time = timer_get_approx_seconds();
5269 // Check for player timeouts
5270 for (i = 0; i < N_players; i++)
5272 if ((i != Player_num) && (Players[i].connected == 1))
5274 if ((LastPacketTime[i] == 0) || (LastPacketTime[i] > approx_time))
5276 LastPacketTime[i] = approx_time;
5279 if ((approx_time - LastPacketTime[i]) > (15*F1_0))
5280 network_timeout_player(i);
5283 last_timeout_check = 0;
5289 MySyncPack.data_size = 0;
5294 if (VerifyPlayerJoined!=-1 && !(FrameCount & 63))
5295 resend_sync_due_to_packet_loss_for_allender(); // This will resend to network_player_rejoining
5297 if (Network_send_objects)
5298 network_send_objects();
5300 if (Network_sending_extras && VerifyPlayerJoined==-1)
5302 network_send_extras();
5307 int missed_packets = 0;
5309 int ConsistencyCount = 0;
5311 void network_consistency_error(void)
5313 if (++ConsistencyCount < 10)
5316 Function_mode = FMODE_MENU;
5318 nm_messagebox(NULL, 1, TXT_OK, TXT_CONSISTENCY_ERROR);
5320 nm_messagebox(NULL, 1, TXT_OK, "Failed to join the netgame.\nYou are missing packets. Check\nyour network connection and\ntry again.");
5322 Function_mode = FMODE_GAME;
5323 ConsistencyCount = 0;
5324 multi_quit_game = 1;
5325 multi_leave_menu = 1;
5326 multi_reset_stuff();
5327 Function_mode = FMODE_MENU;
5330 void network_process_pdata (char *data)
5332 Assert (Game_mode & GM_NETWORK);
5334 if (Netgame.ShortPackets)
5335 network_read_pdata_short_packet ((short_frame_info *)data);
5337 network_read_pdata_packet ((frame_info *)data);
5340 void network_read_pdata_packet(frame_info *pd )
5344 object * TheirObj = NULL;
5346 // frame_info should be aligned...for mac, make the necessary adjustments
5348 if (Network_game_type == IPX_GAME) {
5349 pd->numpackets = INTEL_INT(pd->numpackets);
5350 pd->obj_pos.x = INTEL_INT(pd->obj_pos.x);
5351 pd->obj_pos.y = INTEL_INT(pd->obj_pos.y);
5352 pd->obj_pos.z = INTEL_INT(pd->obj_pos.z);
5354 pd->obj_orient.rvec.x = (fix)INTEL_INT((int)pd->obj_orient.rvec.x);
5355 pd->obj_orient.rvec.y = (fix)INTEL_INT((int)pd->obj_orient.rvec.y);
5356 pd->obj_orient.rvec.z = (fix)INTEL_INT((int)pd->obj_orient.rvec.z);
5357 pd->obj_orient.uvec.x = (fix)INTEL_INT((int)pd->obj_orient.uvec.x);
5358 pd->obj_orient.uvec.y = (fix)INTEL_INT((int)pd->obj_orient.uvec.y);
5359 pd->obj_orient.uvec.z = (fix)INTEL_INT((int)pd->obj_orient.uvec.z);
5360 pd->obj_orient.fvec.x = (fix)INTEL_INT((int)pd->obj_orient.fvec.x);
5361 pd->obj_orient.fvec.y = (fix)INTEL_INT((int)pd->obj_orient.fvec.y);
5362 pd->obj_orient.fvec.z = (fix)INTEL_INT((int)pd->obj_orient.fvec.z);
5364 pd->phys_velocity.x = (fix)INTEL_INT((int)pd->phys_velocity.x);
5365 pd->phys_velocity.y = (fix)INTEL_INT((int)pd->phys_velocity.y);
5366 pd->phys_velocity.z = (fix)INTEL_INT((int)pd->phys_velocity.z);
5368 pd->phys_rotvel.x = (fix)INTEL_INT((int)pd->phys_rotvel.x);
5369 pd->phys_rotvel.y = (fix)INTEL_INT((int)pd->phys_rotvel.y);
5370 pd->phys_rotvel.z = (fix)INTEL_INT((int)pd->phys_rotvel.z);
5372 pd->obj_segnum = INTEL_SHORT(pd->obj_segnum);
5373 pd->data_size = INTEL_SHORT(pd->data_size);
5377 TheirPlayernum = pd->playernum;
5378 TheirObjnum = Players[pd->playernum].objnum;
5380 if (TheirPlayernum < 0) {
5381 Int3(); // This packet is bogus!!
5385 if (VerifyPlayerJoined!=-1 && TheirPlayernum==VerifyPlayerJoined)
5387 // Hurray! Someone really really got in the game (I think).
5388 mprintf ((0,"Hurray! VPJ (%d) reset!\n",VerifyPlayerJoined));
5389 VerifyPlayerJoined=-1;
5392 if (!multi_quit_game && (TheirPlayernum >= N_players)) {
5393 if (Network_status!=NETSTAT_WAITING)
5395 Int3(); // We missed an important packet!
5396 network_consistency_error();
5402 if (Endlevel_sequence || (Network_status == NETSTAT_ENDLEVEL) ) {
5403 int old_Endlevel_sequence = Endlevel_sequence;
5404 Endlevel_sequence = 1;
5405 if ( pd->data_size>0 ) {
5406 // pass pd->data to some parser function....
5407 multi_process_bigdata( pd->data, pd->data_size );
5409 Endlevel_sequence = old_Endlevel_sequence;
5412 // mprintf((0, "Gametime = %d, Frametime = %d.\n", GameTime, FrameTime));
5414 if ((byte)pd->level_num != Current_level_num)
5416 mprintf((0, "Got frame packet from player %d wrong level %d!\n", pd->playernum, pd->level_num));
5420 TheirObj = &Objects[TheirObjnum];
5422 //------------- Keep track of missed packets -----------------
5423 Players[TheirPlayernum].n_packets_got++;
5425 LastPacketTime[TheirPlayernum] = timer_get_approx_seconds();
5427 if ( pd->numpackets != Players[TheirPlayernum].n_packets_got ) {
5430 missed_packets = pd->numpackets-Players[TheirPlayernum].n_packets_got;
5431 if ((pd->numpackets-Players[TheirPlayernum].n_packets_got)>0)
5432 TotalMissedPackets += pd->numpackets-Players[TheirPlayernum].n_packets_got;
5434 if ( missed_packets > 0 )
5435 mprintf(( 0, "Missed %d packets from player #%d (%d total)\n", pd->numpackets-Players[TheirPlayernum].n_packets_got, TheirPlayernum, missed_packets ));
5437 mprintf( (0, "Got %d late packets from player #%d (%d total)\n", Players[TheirPlayernum].n_packets_got-pd->numpackets, TheirPlayernum, missed_packets ));
5440 #ifdef APPLETALK_DEBUG
5441 if (Network_game_type == APPLETALK_GAME) {
5442 if ( missed_packets > 0 )
5443 fprintf( at_fp, "Missed %d packets from player #%d (%d total)\n", pd->numpackets-Players[TheirPlayernum].n_packets_got, TheirPlayernum, missed_packets );
5445 fprintf( at_fp, "Got %d late packets from player #%d (%d total)\n", Players[TheirPlayernum].n_packets_got-pd->numpackets, TheirPlayernum, missed_packets );
5450 if (Network_game_type == IPX_GAME) {
5451 if ( missed_packets > 0 )
5452 fprintf( ipx_fp, "Missed %d packets from player #%d (%d total)\n", pd->numpackets-Players[TheirPlayernum].n_packets_got, TheirPlayernum, missed_packets );
5454 fprintf( ipx_fp, "Got %d late packets from player #%d (%d total)\n", Players[TheirPlayernum].n_packets_got-pd->numpackets, TheirPlayernum, missed_packets );
5459 Players[TheirPlayernum].n_packets_got = pd->numpackets;
5462 //------------ Read the player's ship's object info ----------------------
5463 TheirObj->pos = pd->obj_pos;
5464 TheirObj->orient = pd->obj_orient;
5465 TheirObj->mtype.phys_info.velocity = pd->phys_velocity;
5466 TheirObj->mtype.phys_info.rotvel = pd->phys_rotvel;
5468 if ((TheirObj->render_type != pd->obj_render_type) && (pd->obj_render_type == RT_POLYOBJ))
5469 multi_make_ghost_player(TheirPlayernum);
5471 obj_relink(TheirObjnum,pd->obj_segnum);
5473 if (TheirObj->movement_type == MT_PHYSICS)
5474 set_thrust_from_velocity(TheirObj);
5476 //------------ Welcome them back if reconnecting --------------
5477 if (!Players[TheirPlayernum].connected) {
5478 Players[TheirPlayernum].connected = 1;
5480 if (Newdemo_state == ND_STATE_RECORDING)
5481 newdemo_record_multi_reconnect(TheirPlayernum);
5483 multi_make_ghost_player(TheirPlayernum);
5485 create_player_appearance_effect(&Objects[TheirObjnum]);
5487 digi_play_sample( SOUND_HUD_MESSAGE, F1_0);
5489 ClipRank (&NetPlayers.players[TheirPlayernum].rank);
5491 if (FindArg("-norankings"))
5492 HUD_init_message( "'%s' %s", Players[TheirPlayernum].callsign, TXT_REJOIN );
5494 HUD_init_message( "%s'%s' %s", RankStrings[NetPlayers.players[TheirPlayernum].rank],Players[TheirPlayernum].callsign, TXT_REJOIN );
5500 //------------ Parse the extra data at the end ---------------
5502 if ( pd->data_size>0 ) {
5503 // pass pd->data to some parser function....
5504 multi_process_bigdata( pd->data, pd->data_size );
5510 void get_short_frame_info(ubyte *old_info, short_frame_info *new_info)
5514 new_info->type = old_info[loc]; loc++; loc += 3; // skip three for pad byte
5515 memcpy(&(new_info->numpackets), &(old_info[loc]), 4); loc += 4;
5516 new_info->numpackets = INTEL_INT(new_info->numpackets);
5517 memcpy(new_info->thepos.bytemat, &(old_info[loc]), 9); loc += 9;
5518 memcpy(&(new_info->thepos.xo), &(old_info[loc]), 2); loc += 2;
5519 memcpy(&(new_info->thepos.yo), &(old_info[loc]), 2); loc += 2;
5520 memcpy(&(new_info->thepos.zo), &(old_info[loc]), 2); loc += 2;
5521 memcpy(&(new_info->thepos.segment), &(old_info[loc]), 2); loc += 2;
5522 memcpy(&(new_info->thepos.velx), &(old_info[loc]), 2); loc += 2;
5523 memcpy(&(new_info->thepos.vely), &(old_info[loc]), 2); loc += 2;
5524 memcpy(&(new_info->thepos.velz), &(old_info[loc]), 2); loc += 2;
5525 new_info->thepos.xo = INTEL_SHORT(new_info->thepos.xo);
5526 new_info->thepos.yo = INTEL_SHORT(new_info->thepos.yo);
5527 new_info->thepos.zo = INTEL_SHORT(new_info->thepos.zo);
5528 new_info->thepos.segment = INTEL_SHORT(new_info->thepos.segment);
5529 new_info->thepos.velx = INTEL_SHORT(new_info->thepos.velx);
5530 new_info->thepos.vely = INTEL_SHORT(new_info->thepos.vely);
5531 new_info->thepos.velz = INTEL_SHORT(new_info->thepos.velz);
5533 memcpy(&(new_info->data_size), &(old_info[loc]), 2); loc += 2;
5534 new_info->data_size = INTEL_SHORT(new_info->data_size);
5535 new_info->playernum = old_info[loc]; loc++;
5536 new_info->obj_render_type = old_info[loc]; loc++;
5537 new_info->level_num = old_info[loc]; loc++;
5538 memcpy(new_info->data, &(old_info[loc]), new_info->data_size);
5542 void network_read_pdata_short_packet(short_frame_info *pd )
5546 object * TheirObj = NULL;
5547 short_frame_info new_pd;
5549 // short frame info is not aligned because of shortpos. The mac
5550 // will call totally hacked and gross function to fix this up.
5552 if (Network_game_type == IPX_GAME) {
5554 memcpy(&new_pd, (ubyte *)pd, sizeof(short_frame_info));
5556 get_short_frame_info((ubyte *)pd, &new_pd);
5559 memcpy(&new_pd, (ubyte *)pd, sizeof(short_frame_info));
5562 TheirPlayernum = new_pd.playernum;
5563 TheirObjnum = Players[new_pd.playernum].objnum;
5565 if (TheirPlayernum < 0) {
5566 Int3(); // This packet is bogus!!
5569 if (!multi_quit_game && (TheirPlayernum >= N_players)) {
5570 if (Network_status!=NETSTAT_WAITING)
5572 Int3(); // We missed an important packet!
5573 network_consistency_error();
5580 if (VerifyPlayerJoined!=-1 && TheirPlayernum==VerifyPlayerJoined)
5582 // Hurray! Someone really really got in the game (I think).
5583 mprintf ((0,"Hurray! VPJ (%d) reset!\n",VerifyPlayerJoined));
5584 VerifyPlayerJoined=-1;
5587 if (Endlevel_sequence || (Network_status == NETSTAT_ENDLEVEL) ) {
5588 int old_Endlevel_sequence = Endlevel_sequence;
5589 Endlevel_sequence = 1;
5590 if ( new_pd.data_size>0 ) {
5591 // pass pd->data to some parser function....
5592 multi_process_bigdata( new_pd.data, new_pd.data_size );
5594 Endlevel_sequence = old_Endlevel_sequence;
5597 // mprintf((0, "Gametime = %d, Frametime = %d.\n", GameTime, FrameTime));
5599 if ((byte)new_pd.level_num != Current_level_num)
5601 mprintf((0, "Got frame packet from player %d wrong level %d!\n", new_pd.playernum, new_pd.level_num));
5605 TheirObj = &Objects[TheirObjnum];
5607 //------------- Keep track of missed packets -----------------
5608 Players[TheirPlayernum].n_packets_got++;
5610 LastPacketTime[TheirPlayernum] = timer_get_approx_seconds();
5612 if ( new_pd.numpackets != Players[TheirPlayernum].n_packets_got ) {
5615 missed_packets = new_pd.numpackets-Players[TheirPlayernum].n_packets_got;
5616 if ((new_pd.numpackets-Players[TheirPlayernum].n_packets_got)>0)
5617 TotalMissedPackets += new_pd.numpackets-Players[TheirPlayernum].n_packets_got;
5619 if ( missed_packets > 0 )
5620 mprintf( (0, "Missed %d packets from player #%d (%d total)\n", new_pd.numpackets-Players[TheirPlayernum].n_packets_got, TheirPlayernum, missed_packets ));
5622 mprintf( (0, "Got %d late packets from player #%d (%d total)\n", Players[TheirPlayernum].n_packets_got-new_pd.numpackets, TheirPlayernum, missed_packets ));
5624 Players[TheirPlayernum].n_packets_got = new_pd.numpackets;
5627 //------------ Read the player's ship's object info ----------------------
5629 extract_shortpos(TheirObj, &new_pd.thepos, 0);
5631 if ((TheirObj->render_type != new_pd.obj_render_type) && (new_pd.obj_render_type == RT_POLYOBJ))
5632 multi_make_ghost_player(TheirPlayernum);
5634 if (TheirObj->movement_type == MT_PHYSICS)
5635 set_thrust_from_velocity(TheirObj);
5637 //------------ Welcome them back if reconnecting --------------
5638 if (!Players[TheirPlayernum].connected) {
5639 Players[TheirPlayernum].connected = 1;
5641 if (Newdemo_state == ND_STATE_RECORDING)
5642 newdemo_record_multi_reconnect(TheirPlayernum);
5644 multi_make_ghost_player(TheirPlayernum);
5646 create_player_appearance_effect(&Objects[TheirObjnum]);
5648 digi_play_sample( SOUND_HUD_MESSAGE, F1_0);
5649 ClipRank (&NetPlayers.players[TheirPlayernum].rank);
5651 if (FindArg("-norankings"))
5652 HUD_init_message( "'%s' %s", Players[TheirPlayernum].callsign, TXT_REJOIN );
5654 HUD_init_message( "%s'%s' %s", RankStrings[NetPlayers.players[TheirPlayernum].rank],Players[TheirPlayernum].callsign, TXT_REJOIN );
5660 //------------ Parse the extra data at the end ---------------
5662 if ( new_pd.data_size>0 ) {
5663 // pass pd->data to some parser function....
5664 multi_process_bigdata( new_pd.data, new_pd.data_size );
5670 void network_set_power (void)
5672 int opt=0,choice,opt_primary,opt_second,opt_power;
5676 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Laser upgrade"; m[opt].value=Netgame.DoLaserUpgrade; opt++;
5677 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Super lasers"; m[opt].value=Netgame.DoSuperLaser; opt++;
5678 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Quad Lasers"; m[opt].value=Netgame.DoQuadLasers; opt++;
5679 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Vulcan cannon"; m[opt].value=Netgame.DoVulcan; opt++;
5680 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Spreadfire cannon"; m[opt].value=Netgame.DoSpread; opt++;
5681 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Plasma cannon"; m[opt].value=Netgame.DoPlasma; opt++;
5682 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Fusion cannon"; m[opt].value=Netgame.DoFusions; opt++;
5683 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Gauss cannon"; m[opt].value=Netgame.DoGauss; opt++;
5684 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Helix cannon"; m[opt].value=Netgame.DoHelix; opt++;
5685 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Phoenix cannon"; m[opt].value=Netgame.DoPhoenix; opt++;
5686 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Omega cannon"; m[opt].value=Netgame.DoOmega; opt++;
5689 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Homing Missiles"; m[opt].value=Netgame.DoHoming; opt++;
5690 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Proximity Bombs"; m[opt].value=Netgame.DoProximity; opt++;
5691 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Smart Missiles"; m[opt].value=Netgame.DoSmarts; opt++;
5692 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Mega Missiles"; m[opt].value=Netgame.DoMegas; opt++;
5693 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Flash Missiles"; m[opt].value=Netgame.DoFlash; opt++;
5694 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Guided Missiles"; m[opt].value=Netgame.DoGuided; opt++;
5695 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Smart Mines"; m[opt].value=Netgame.DoSmartMine; opt++;
5696 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Mercury Missiles"; m[opt].value=Netgame.DoMercury; opt++;
5697 m[opt].type = NM_TYPE_CHECK; m[opt].text = "EarthShaker Missiles"; m[opt].value=Netgame.DoEarthShaker; opt++;
5700 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Invulnerability"; m[opt].value=Netgame.DoInvulnerability; opt++;
5701 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Cloaking"; m[opt].value=Netgame.DoCloak; opt++;
5702 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Afterburners"; m[opt].value=Netgame.DoAfterburner; opt++;
5703 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Ammo rack"; m[opt].value=Netgame.DoAmmoRack; opt++;
5704 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Energy Converter"; m[opt].value=Netgame.DoConverter; opt++;
5705 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Headlight"; m[opt].value=Netgame.DoHeadlight; opt++;
5707 choice = newmenu_do(NULL, "Objects to allow", opt, m, NULL);
5709 Netgame.DoLaserUpgrade=m[opt_primary].value;
5710 Netgame.DoSuperLaser=m[opt_primary+1].value;
5711 Netgame.DoQuadLasers=m[opt_primary+2].value;
5712 Netgame.DoVulcan=m[opt_primary+3].value;
5713 Netgame.DoSpread=m[opt_primary+4].value;
5714 Netgame.DoPlasma=m[opt_primary+5].value;
5715 Netgame.DoFusions=m[opt_primary+6].value;
5716 Netgame.DoGauss=m[opt_primary+7].value;
5717 Netgame.DoHelix=m[opt_primary+8].value;
5718 Netgame.DoPhoenix=m[opt_primary+9].value;
5719 Netgame.DoOmega=m[opt_primary+10].value;
5721 Netgame.DoHoming=m[opt_second].value;
5722 Netgame.DoProximity=m[opt_second+1].value;
5723 Netgame.DoSmarts=m[opt_second+2].value;
5724 Netgame.DoMegas=m[opt_second+3].value;
5725 Netgame.DoFlash=m[opt_second+4].value;
5726 Netgame.DoGuided=m[opt_second+5].value;
5727 Netgame.DoSmartMine=m[opt_second+6].value;
5728 Netgame.DoMercury=m[opt_second+7].value;
5729 Netgame.DoEarthShaker=m[opt_second+8].value;
5731 Netgame.DoInvulnerability=m[opt_power].value;
5732 Netgame.DoCloak=m[opt_power+1].value;
5733 Netgame.DoAfterburner=m[opt_power+2].value;
5734 Netgame.DoAmmoRack=m[opt_power+3].value;
5735 Netgame.DoConverter=m[opt_power+4].value;
5736 Netgame.DoHeadlight=m[opt_power+5].value;
5740 void SetAllAllowablesTo (int on)
5742 last_cinvul = control_invul_time = 0; //default to zero
5744 Netgame.DoMegas=Netgame.DoSmarts=Netgame.DoFusions=Netgame.DoHelix=\
5745 Netgame.DoPhoenix=Netgame.DoCloak=Netgame.DoInvulnerability=\
5746 Netgame.DoAfterburner=Netgame.DoGauss=Netgame.DoVulcan=Netgame.DoPlasma=on;
5748 Netgame.DoOmega=Netgame.DoSuperLaser=Netgame.DoProximity=\
5749 Netgame.DoSpread=Netgame.DoMercury=Netgame.DoSmartMine=Netgame.DoFlash=\
5750 Netgame.DoGuided=Netgame.DoEarthShaker=on;
5752 Netgame.DoConverter=Netgame.DoAmmoRack=Netgame.DoHeadlight=on;
5753 Netgame.DoHoming=Netgame.DoLaserUpgrade=Netgame.DoQuadLasers=on;
5754 Netgame.BrightPlayers=Netgame.invul=on;
5760 // Jeez -- mac compiler can't handle all of these on the same decl line.
5761 int opt_setpower,opt_playtime,opt_killgoal,opt_socket,opt_marker_view,opt_light,opt_show_on_map;
5762 int opt_difficulty,opt_packets,opt_short_packets, opt_bright,opt_start_invul;
5765 void network_more_options_poll( int nitems, newmenu_item * menus, int * key, int citem );
5767 void network_more_game_options ()
5770 char PlayText[80],KillText[80],srinvul[50],socket_string[5],packstring[5];
5773 sprintf (socket_string,"%d",Network_socket);
5774 sprintf (packstring,"%d",Netgame.PacketsPerSec);
5776 opt_difficulty = opt;
5777 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++;
5780 sprintf( srinvul, "%s: %d %s", TXT_REACTOR_LIFE, control_invul_time*5, TXT_MINUTES_ABBREV );
5781 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++;
5784 sprintf( PlayText, "Max time: %d %s", Netgame.PlayTimeAllowed*5, TXT_MINUTES_ABBREV );
5785 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++;
5788 sprintf( KillText, "Kill Goal: %d kills", Netgame.KillGoal*5);
5789 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++;
5791 opt_start_invul=opt;
5792 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Invulnerable when reappearing"; m[opt].value=Netgame.invul; opt++;
5794 opt_marker_view = opt;
5795 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Allow camera views from Markers"; m[opt].value=Netgame.Allow_marker_view; opt++;
5797 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Indestructible lights"; m[opt].value=Netgame.AlwaysLighting; opt++;
5800 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Bright player ships"; m[opt].value=Netgame.BrightPlayers; opt++;
5803 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Show enemy names on HUD"; m[opt].value=Netgame.ShowAllNames; opt++;
5805 opt_show_on_map=opt;
5806 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++;
5808 opt_short_packets=opt;
5809 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Short packets"; m[opt].value=Netgame.ShortPackets; opt++;
5812 m[opt].type = NM_TYPE_MENU; m[opt].text = "Set Objects allowed..."; opt++;
5814 if (Network_game_type == IPX_GAME) {
5815 m[opt].type = NM_TYPE_TEXT; m[opt].text = "Network socket"; opt++;
5817 m[opt].type = NM_TYPE_INPUT; m[opt].text = socket_string; m[opt].text_len=4; opt++;
5820 m[opt].type = NM_TYPE_TEXT; m[opt].text = "Packets per second (2 - 20)"; opt++;
5822 m[opt].type = NM_TYPE_INPUT; m[opt].text=packstring; m[opt].text_len=2; opt++;
5824 LastKillGoal=Netgame.KillGoal;
5825 LastPTA=Netgame.PlayTimeAllowed;
5829 ExtGameStatus=GAMESTAT_MORE_NETGAME_OPTIONS;
5830 i = newmenu_do1( NULL, "Additional netgame options", opt, m, network_more_options_poll, 0 );
5832 //control_invul_time = atoi( srinvul )*60*F1_0;
5833 control_invul_time = m[opt_cinvul].value;
5834 Netgame.control_invul_time = control_invul_time*5*F1_0*60;
5836 if (i==opt_setpower)
5838 network_set_power ();
5842 Netgame.PacketsPerSec=atoi(packstring);
5844 if (Netgame.PacketsPerSec>20)
5846 Netgame.PacketsPerSec=20;
5847 nm_messagebox(TXT_ERROR, 1, TXT_OK, "Packet value out of range\nSetting value to 20");
5849 if (Netgame.PacketsPerSec<2)
5851 nm_messagebox(TXT_ERROR, 1, TXT_OK, "Packet value out of range\nSetting value to 2");
5852 Netgame.PacketsPerSec=2;
5855 mprintf ((0,"Hey! Sending out %d packets per second\n",Netgame.PacketsPerSec));
5857 if (Network_game_type == IPX_GAME) {
5858 if ((atoi(socket_string))!=Network_socket) {
5859 Network_socket=atoi(socket_string);
5860 ipx_change_default_socket( IPX_DEFAULT_SOCKET + Network_socket );
5864 Netgame.invul=m[opt_start_invul].value;
5865 Netgame.BrightPlayers=m[opt_bright].value;
5866 Netgame.ShortPackets=m[opt_short_packets].value;
5867 Netgame.ShowAllNames=m[opt_show_names].value;
5868 network_AdjustMaxDataSize();
5870 Netgame.Allow_marker_view=m[opt_marker_view].value;
5871 Netgame.AlwaysLighting=m[opt_light].value;
5872 netgame_difficulty=Difficulty_level = m[opt_difficulty].value;
5873 if (m[opt_show_on_map].value)
5874 Netgame.game_flags |= NETGAME_FLAG_SHOW_MAP;
5879 void network_more_options_poll( int nitems, newmenu_item * menus, int * key, int citem )
5882 citem = citem; // kills compile warnings
5886 if ( last_cinvul != menus[opt_cinvul].value ) {
5887 sprintf( menus[opt_cinvul].text, "%s: %d %s", TXT_REACTOR_LIFE, menus[opt_cinvul].value*5, TXT_MINUTES_ABBREV );
5888 last_cinvul = menus[opt_cinvul].value;
5889 menus[opt_cinvul].redraw = 1;
5892 if (menus[opt_playtime].value!=LastPTA)
5896 nm_messagebox ("Sorry",1,TXT_OK,"Registered version only!");
5897 menus[opt_playtime].value=0;
5898 menus[opt_playtime].redraw=1;
5902 if (Game_mode & GM_MULTI_COOP)
5905 nm_messagebox ("Sorry",1,TXT_OK,"You can't change those for coop!");
5906 menus[opt_playtime].value=0;
5907 menus[opt_playtime].redraw=1;
5911 Netgame.PlayTimeAllowed=menus[opt_playtime].value;
5912 sprintf( menus[opt_playtime].text, "Max Time: %d %s", Netgame.PlayTimeAllowed*5, TXT_MINUTES_ABBREV );
5913 LastPTA=Netgame.PlayTimeAllowed;
5914 menus[opt_playtime].redraw=1;
5916 if (menus[opt_killgoal].value!=LastKillGoal)
5919 nm_messagebox ("Sorry",1,TXT_OK,"Registered version only!");
5920 menus[opt_killgoal].value=0;
5921 menus[opt_killgoal].redraw=1;
5927 if (Game_mode & GM_MULTI_COOP)
5929 nm_messagebox ("Sorry",1,TXT_OK,"You can't change those for coop!");
5930 menus[opt_killgoal].value=0;
5931 menus[opt_killgoal].redraw=1;
5937 Netgame.KillGoal=menus[opt_killgoal].value;
5938 sprintf( menus[opt_killgoal].text, "Kill Goal: %d kills", Netgame.KillGoal*5);
5939 LastKillGoal=Netgame.KillGoal;
5940 menus[opt_killgoal].redraw=1;
5944 extern void multi_send_light (int,ubyte);
5945 extern void multi_send_light_specific (int,int,ubyte);
5947 void network_send_smash_lights (int pnum)
5949 // send the lights that have been blown out
5955 for (i=0;i<=Highest_segment_index;i++)
5956 if (Light_subtracted[i])
5957 multi_send_light_specific(pnum,i,Light_subtracted[i]);
5960 extern int Num_triggers;
5961 extern void multi_send_trigger_specific (char pnum,char);
5963 void network_send_fly_thru_triggers (int pnum)
5965 // send the fly thru triggers that have been disabled
5969 for (i=0;i<Num_triggers;i++)
5970 if (Triggers[i].flags & TF_DISABLED)
5971 multi_send_trigger_specific(pnum,i);
5974 void network_send_player_flags()
5978 for (i=0;i<N_players;i++)
5979 multi_send_flags(i);
5982 void network_ping (ubyte flag,int pnum)
5987 mybuf[1]=Player_num;
5989 if (Network_game_type == IPX_GAME)
5990 ipx_send_packet_data( (ubyte *)mybuf, 2, NetPlayers.players[pnum].network.ipx.server, NetPlayers.players[pnum].network.ipx.node,Players[pnum].net_address );
5993 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);
5997 extern fix PingLaunchTime,PingReturnTime;
5999 void network_handle_ping_return (ubyte pnum)
6001 if (PingLaunchTime==0 || pnum>=N_players)
6003 mprintf ((0,"Got invalid PING RETURN from %s!\n",Players[pnum].callsign));
6007 PingReturnTime=timer_get_fixed_seconds();
6009 HUD_init_message ("Ping time for %s is %d ms!",Players[pnum].callsign,
6010 f2i(fixmul(PingReturnTime-PingLaunchTime,i2f(1000))));
6014 void network_send_ping (ubyte pnum)
6016 network_ping (PID_PING_SEND,pnum);
6019 void DoRefuseStuff (sequence_packet *their)
6021 int i,new_player_num;
6023 ClipRank (&their->player.rank);
6025 for (i=0;i<MAX_PLAYERS;i++)
6026 if (!strcmp (their->player.callsign,Players[i].callsign))
6028 network_welcome_player(their);
6032 if (!WaitForRefuseAnswer)
6034 for (i=0;i<MAX_PLAYERS;i++)
6035 if (!strcmp (their->player.callsign,Players[i].callsign))
6037 network_welcome_player(their);
6041 digi_play_sample (SOUND_HUD_JOIN_REQUEST,F1_0*2);
6043 if (Game_mode & GM_TEAM)
6047 if (!FindArg("-norankings"))
6048 HUD_init_message ("%s %s wants to join",RankStrings[their->player.rank],their->player.callsign);
6050 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]);
6052 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]);
6054 // HUD_init_message ("Alt-1 to place on team %s!",Netgame.team_name[0]);
6055 // HUD_init_message ("Alt-2 to place on team %s!",Netgame.team_name[1]);
6058 HUD_init_message ("%s wants to join...press F6 to connect",their->player.callsign);
6060 strcpy (RefusePlayerName,their->player.callsign);
6061 RefuseTimeLimit=timer_get_approx_seconds();
6063 WaitForRefuseAnswer=1;
6067 for (i=0;i<MAX_PLAYERS;i++)
6068 if (!strcmp (their->player.callsign,Players[i].callsign))
6070 network_welcome_player(their);
6074 if (strcmp(their->player.callsign,RefusePlayerName))
6077 if (RefuseThisPlayer)
6081 WaitForRefuseAnswer=0;
6082 if (Game_mode & GM_TEAM)
6084 new_player_num=GetNewPlayerNumber (their);
6085 mprintf ((0,"Newplayernum=%d\n",new_player_num));
6087 Assert (RefuseTeam==1 || RefuseTeam==2);
6090 Netgame.team_vector &=(~(1<<new_player_num));
6092 Netgame.team_vector |=(1<<new_player_num);
6093 network_welcome_player(their);
6094 network_send_netgame_update ();
6097 network_welcome_player(their);
6101 if ((timer_get_approx_seconds()) > RefuseTimeLimit+REFUSE_INTERVAL)
6105 WaitForRefuseAnswer=0;
6106 if (!strcmp (their->player.callsign,RefusePlayerName)) {
6107 if (Network_game_type == IPX_GAME)
6108 network_dump_player(their->player.network.ipx.server,their->player.network.ipx.node, DUMP_DORK);
6111 network_dump_appletalk_player(their->player.network.appletalk.node,their->player.network.appletalk.net, their->player.network.appletalk.socket, DUMP_DORK);
6120 int GetNewPlayerNumber (sequence_packet *their)
6126 if ( N_players < MaxNumNetPlayers)
6131 // Slots are full but game is open, see if anyone is
6132 // disconnected and replace the oldest player with this new one
6134 int oldest_player = -1;
6135 fix oldest_time = timer_get_approx_seconds();
6137 Assert(N_players == MaxNumNetPlayers);
6139 for (i = 0; i < N_players; i++)
6141 if ( (!Players[i].connected) && (LastPacketTime[i] < oldest_time))
6143 oldest_time = LastPacketTime[i];
6147 return (oldest_player);
6151 void network_send_extras ()
6153 Assert (Player_joining_extras>-1);
6155 if (!network_i_am_master())
6157 mprintf ((0,"Hey! I'm not the master and I was gonna send info!\n"));
6159 // Network_sending_extras=0;
6164 if (Network_sending_extras==40)
6165 network_send_fly_thru_triggers(Player_joining_extras);
6166 if (Network_sending_extras==38)
6167 network_send_door_updates(Player_joining_extras);
6168 if (Network_sending_extras==35)
6169 network_send_markers();
6170 if (Network_sending_extras==30 && (Game_mode & GM_MULTI_ROBOTS))
6171 multi_send_stolen_items();
6172 if (Network_sending_extras==25 && (Netgame.PlayTimeAllowed || Netgame.KillGoal))
6173 multi_send_kill_goal_counts();
6174 if (Network_sending_extras==20)
6175 network_send_smash_lights(Player_joining_extras);
6176 if (Network_sending_extras==15)
6177 network_send_player_flags();
6178 if (Network_sending_extras==10)
6179 multi_send_powerup_update();
6180 // if (Network_sending_extras==5)
6181 // network_send_door_updates(Player_joining_extras); // twice!
6183 Network_sending_extras--;
6184 if (!Network_sending_extras)
6185 Player_joining_extras=-1;
6189 void network_send_naked_packet(char *buf, short len, int who)
6191 if (!(Game_mode&GM_NETWORK)) return;
6193 if (NakedPacketLen==0)
6195 NakedBuf[0]=PID_NAKED_PDATA;
6196 NakedBuf[1]=Player_num;
6200 if (len+NakedPacketLen>MaxXDataSize)
6202 // mprintf ((0,"Sending a naked packet of %d bytes.\n",NakedPacketLen));
6203 if (Network_game_type == IPX_GAME)
6204 ipx_send_packet_data( (ubyte *)NakedBuf, NakedPacketLen, NetPlayers.players[who].network.ipx.server, NetPlayers.players[who].network.ipx.node,Players[who].net_address );
6207 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 );
6210 memcpy (&NakedBuf[NakedPacketLen],buf,len);
6211 NakedPacketLen+=len;
6212 NakedPacketDestPlayer=who;
6216 memcpy (&NakedBuf[NakedPacketLen],buf,len);
6217 NakedPacketLen+=len;
6218 NakedPacketDestPlayer=who;
6223 void network_process_naked_pdata (char *data,int len)
6226 Assert (data[0]=PID_NAKED_PDATA);
6228 // mprintf ((0,"Processing a naked packet of %d length.\n",len));
6231 mprintf ((0,"Naked packet is bad!\n"));
6232 Int3(); // This packet is bogus!!
6236 if (!multi_quit_game && (pnum >= N_players)) {
6237 if (Network_status!=NETSTAT_WAITING)
6239 Int3(); // We missed an important packet!
6240 network_consistency_error();
6247 if (Endlevel_sequence || (Network_status == NETSTAT_ENDLEVEL) ) {
6248 int old_Endlevel_sequence = Endlevel_sequence;
6249 Endlevel_sequence = 1;
6250 multi_process_bigdata( data+2, len-2);
6251 Endlevel_sequence = old_Endlevel_sequence;
6255 multi_process_bigdata( data+2, len-2 );
6258 int ConnectionPacketLevel[]={0,1,1,1};
6259 int ConnectionSecLevel[]={12,3,5,7};
6261 int AppletalkConnectionPacketLevel[]={0,1,0};
6262 int AppletalkConnectionSecLevel[]={10,3,8};
6264 #if defined(RELEASE) && !defined(MACINTOSH) // use the code below for mac appletalk games
6265 int network_choose_connect ()
6270 int network_choose_connect ()
6277 if (Network_game_type == IPX_GAME) {
6279 m[opt].type = NM_TYPE_MENU; m[opt].text = "Local Subnet"; opt++;
6280 m[opt].type = NM_TYPE_MENU; m[opt].text = "14.4 modem over Internet"; opt++;
6281 m[opt].type = NM_TYPE_MENU; m[opt].text = "28.8 modem over Internet"; opt++;
6282 m[opt].type = NM_TYPE_MENU; m[opt].text = "ISDN or T1 over Internet"; opt++;
6284 choice = newmenu_do1( NULL, "Choose connection type", opt, m, NULL, 0 );
6289 Assert (choice>=0 && choice<=3);
6291 Netgame.ShortPackets=ConnectionPacketLevel[choice];
6292 Netgame.PacketsPerSec=ConnectionSecLevel[choice];
6297 m[opt].type = NM_TYPE_MENU; m[opt].text = "EtherTalk"; opt++;
6298 m[opt].type = NM_TYPE_MENU; m[opt].text = "LocalTalk"; opt++;
6299 m[opt].type = NM_TYPE_MENU; m[opt].text = "Other"; opt++;
6301 choice = newmenu_do1( NULL, "Choose connection type", opt, m, NULL, 0 );
6306 Network_appletalk_type = choice;
6308 Assert (choice>=0 && choice<=2);
6310 Netgame.ShortPackets=AppletalkConnectionPacketLevel[choice];
6311 Netgame.PacketsPerSec=AppletalkConnectionSecLevel[choice];
6325 SendLogFile=(FILE *)fopen ("sendlog.net","w");
6329 void OpenRecieveLog ()
6332 RecieveLogFile=(FILE *)fopen ("recvlog.net","w");
6338 int GetMyNetRanking ()
6343 if (Netlife_kills+Netlife_killed==0)
6346 rank=(int) (((float)Netlife_kills/3000.0)*8.0);
6348 eff=(int)((float)((float)Netlife_kills/((float)Netlife_killed+(float)Netlife_kills))*100.0);
6357 rank-=((59-eff)/10);
6364 mprintf ((0,"Rank is %d (%s)\n",rank+1,RankStrings[rank+1]));
6368 void ClipRank (signed char *rank)
6370 // This function insures no crashes when dealing with D2 1.0
6373 if (*rank<0 || *rank>9)
6376 void network_check_for_old_version (char pnum)
6378 if (NetPlayers.players[(int)pnum].version_major==1 && (NetPlayers.players[(int)pnum].version_minor & 0x0F)==0)
6379 NetPlayers.players[(int)pnum].rank=0;
6382 void network_request_player_names (int n)
6384 network_send_all_info_request (PID_GAME_PLAYERS,Active_games[n].Security);
6385 NamesInfoSecurity=Active_games[n].Security;
6388 extern char already_showing_info;
6389 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));
6391 void network_process_names_return (char *data)
6394 char mtext[15][50],temp[50];
6395 int i,t,l,gnum,num=0,count=5,numplayers;
6397 if (NamesInfoSecurity!=(*(int *)(data+1)))
6399 mprintf ((0,"Bad security on names return!\n"));
6400 mprintf ((0,"NIS=%d data=%d\n",NamesInfoSecurity,(*(int *)(data+1))));
6404 numplayers=data[count]; count++;
6406 if (numplayers==255)
6409 NamesInfoSecurity=-1;
6410 nm_messagebox(NULL, 1, "OK", "That game is refusing\nname requests.\n");
6415 Assert (numplayers>0 && numplayers<MAX_NUM_NET_PLAYERS);
6419 m[i].text=(char *)&mtext[i];
6420 m[i].type=NM_TYPE_TEXT;
6423 for (gnum=-1,i=0;i<num_active_games;i++)
6425 if (NamesInfoSecurity==Active_games[i].Security)
6435 NamesInfoSecurity=-1;
6436 nm_messagebox(NULL, 1, "OK", "The game you have requested\nnames from is gone.\n");
6441 sprintf (mtext[num],"Players of game '%s':",Active_games[gnum].game_name); num++;
6442 for (i=0;i<numplayers;i++)
6446 mprintf ((0,"%s\n",data+count));
6448 for (t=0;t<CALLSIGN_LEN+1;t++)
6449 temp[t]=data[count++];
6450 if (FindArg("-norankings"))
6451 sprintf (mtext[num],"%s",temp);
6453 sprintf (mtext[num],"%s%s",RankStrings[l],temp);
6458 if (data[count]==99)
6460 sprintf (mtext[num++]," ");
6461 sprintf (mtext[num++],"Short packets: %s",data[count+1]?"On":"Off");
6462 sprintf (mtext[num++],"Packets Per Second: %d",data[count+2]);
6465 already_showing_info=1;
6466 newmenu_dotiny2( NULL, NULL, num, m, NULL);
6467 already_showing_info=0;
6470 char NameReturning=1;
6472 void network_send_player_names (sequence_packet *their)
6474 int numconnected=0,count=0,i,t;
6479 mprintf ((0,"Got a player name without a return address! Get Jason\n"));
6483 buf[0]=PID_NAMES_RETURN; count++;
6484 (*(int *)(buf+1))=Netgame.Security; count+=4;
6488 buf[count]=255; count++;
6492 mprintf ((0,"RealSec=%d DS=%d\n",Netgame.Security,*(int *)(buf+1)));
6494 for (i=0;i<N_players;i++)
6495 if (Players[i].connected)
6498 buf[count]=numconnected; count++;
6499 for (i=0;i<N_players;i++)
6500 if (Players[i].connected)
6502 buf[count++]=NetPlayers.players[i].rank;
6504 for (t=0;t<CALLSIGN_LEN+1;t++)
6506 buf[count]=NetPlayers.players[i].callsign[t];
6512 buf[count++]=Netgame.ShortPackets;
6513 buf[count++]=Netgame.PacketsPerSec;
6516 ; // empty statement allows compilation on mac which does not have the
6517 // statement below and kills the compiler when there is no
6518 // statement following the label "sendit"
6521 ipx_send_internetwork_packet_data((ubyte *)buf, count, their->player.network.ipx.server, their->player.network.ipx.node);
6526 int HoardEquipped ()
6528 static int checked=-1;
6535 if (cfexist("hoard.ham"))