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 static char rcsid[] = "$Id: network.c,v 1.2 2001-01-20 13:49:16 bradleyb Exp $";
71 #include <Errors.h> // for appletalk networking errors
75 void network_send_rejoin_sync(int player_num);
76 void network_update_netgame(void);
77 void network_read_endlevel_packet( ubyte *data );
78 void network_read_object_packet( ubyte *data );
79 void network_read_sync_packet( netgame_info * sp, int d1x );
81 void network_listen();
82 void network_read_pdata_packet(frame_info *pd );
84 void network_check_for_old_version (char pnum);
85 void network_send_endlevel_short_sub(int from_player_num,int to_player);
86 int network_wait_for_playerinfo();
87 void network_process_pdata (char *data);
88 void network_read_endlevel_short_packet( ubyte *data );
89 void network_ping (ubyte flag,int pnum);
90 void network_handle_ping_return (ubyte pnum);
91 void network_process_names_return (char *data);
92 void network_send_player_names (sequence_packet *their);
93 int network_choose_connect ();
94 void network_more_game_options ();
95 void network_count_powerups_in_mine(void);
96 int network_wait_for_all_info (int choice);
97 void network_do_big_wait(int choice);
98 void network_send_extras ();
99 void network_read_pdata_short_packet(short_frame_info *pd );
101 void network_AdjustMaxDataSize ();
103 void ClipRank (signed char *rank);
104 void DoRefuseStuff (sequence_packet *their);
105 void SetAllAllowablesTo (int on);
106 int GetNewPlayerNumber (sequence_packet *their);
108 #define LHX(x) ((x)*(MenuHires?2:1))
109 #define LHY(y) ((y)*(MenuHires?2.4:1))
111 #define PID_LITE_INFO 43
112 #define PID_SEND_ALL_GAMEINFO 44
113 #define PID_PLAYERSINFO 45
114 #define PID_REQUEST 46
117 #define PID_ADDPLAYER 49
119 #define PID_ENDLEVEL 52
120 #define PID_QUIT_JOINING 54
121 #define PID_OBJECT_DATA 55
122 #define PID_GAME_LIST 56
123 #define PID_GAME_INFO 57
124 #define PID_PING_SEND 58
125 #define PID_PING_RETURN 59
126 #define PID_GAME_UPDATE 60
127 #define PID_ENDLEVEL_SHORT 61
128 #define PID_NAKED_PDATA 62
129 #define PID_GAME_PLAYERS 63
130 #define PID_NAMES_RETURN 64
132 #define NETGAME_ANARCHY 0
133 #define NETGAME_TEAM_ANARCHY 1
134 #define NETGAME_ROBOT_ANARCHY 2
135 #define NETGAME_COOPERATIVE 3
136 #define NETGAME_CAPTURE_FLAG 4
137 #define NETGAME_HOARD 5
138 #define NETGAME_TEAM_HOARD 6
140 #define NETSECURITY_OFF 0
141 #define NETSECURITY_WAIT_FOR_PLAYERS 1
142 #define NETSECURITY_WAIT_FOR_GAMEINFO 2
143 #define NETSECURITY_WAIT_FOR_SYNC 3
145 // MWA -- these structures are aligned -- please save me sanity and
146 // headaches by keeping alignment if these are changed!!!! Contact
149 typedef struct endlevel_info {
154 short kill_matrix[MAX_PLAYERS][MAX_PLAYERS];
159 typedef struct endlevel_info_short {
164 } endlevel_info_short;
166 // WARNING!!! This is the top part of netgame_info...if that struct changes,
167 // this struct much change as well. ie...they are aligned and the join system will
168 // not work without it.
170 // MWA if this structure changes -- please make appropriate changes to receive_netgame_info
171 // code for macintosh in netmisc.c
173 typedef struct lite_info {
176 char game_name[NETGAME_NAME_LEN+1];
177 char mission_title[MISSION_NAME_LEN+1];
178 char mission_name[9];
185 ubyte max_numplayers;
188 ubyte protocol_version;
194 // IF YOU CHANGE THE SIZE OF ANY OF THE FOLLOWING STRUCTURES
195 // MAKE THE MACINTOSH DEFINES BE THE SAME SIZE AS THE PC OR
196 // I WILL HAVE TO HURT YOU VERY BADLY!!! -- MWA
199 #define NETGAME_INFO_SIZE ( Network_game_type == IPX_GAME?355:sizeof(netgame_info) )
200 #define ALLNETPLAYERSINFO_SIZE ( Network_game_type == IPX_GAME?317:sizeof(AllNetPlayers_info) )
201 #define LITE_INFO_SIZE ( Network_game_type == IPX_GAME?72:sizeof(lite_info) )
202 #define SEQUENCE_PACKET_SIZE ( Network_game_type == IPX_GAME?34:sizeof(sequence_packet) )
203 #define FRAME_INFO_SIZE ( Network_game_type == IPX_GAME?541:sizeof(frame_info) )
204 #define IPX_SHORT_INFO_SIZE ( 490 )
206 #define NETGAME_INFO_SIZE sizeof(netgame_info)
207 #define ALLNETPLAYERSINFO_SIZE sizeof(AllNetPlayers_info)
208 #define LITE_INFO_SIZE sizeof(lite_info)
209 #define SEQUENCE_PACKET_SIZE sizeof(sequence_packet)
210 #define FRAME_INFO_SIZE sizeof(frame_info)
213 #define MAX_ACTIVE_NETGAMES 12
215 netgame_info Active_games[MAX_ACTIVE_NETGAMES];
216 AllNetPlayers_info ActiveNetPlayers[MAX_ACTIVE_NETGAMES];
217 AllNetPlayers_info *TempPlayersInfo,TempPlayersBase;
218 int NamesInfoSecurity=-1;
220 // MWAnetgame_info *TempNetInfo;
221 netgame_info TempNetInfo;
223 extern void multi_send_drop_marker (int player,vms_vector position,char messagenum,char text[]);
224 extern void multi_send_kill_goal_counts();
225 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) );
227 void network_process_naked_pdata (char *,int);
228 extern void multi_send_robot_controls(char);
230 int num_active_games = 0;
231 int PacketsPerSec=10;
232 int MaxXDataSize=NET_XDATA_SIZE;
234 int Netlife_kills=0, Netlife_killed=0;
237 int Network_active=0;
239 int Network_status = 0;
240 int Network_games_changed = 0;
242 int Network_socket = 0;
243 int Network_allow_socket_changes = 1;
245 int NetSecurityFlag=NETSECURITY_OFF;
246 int NetSecurityNum=0;
247 int Network_sending_extras=0;
248 int VerifyPlayerJoined=-1;
249 int Player_joining_extras=-1; // This is so we know who to send 'latecomer' packets to.
250 // We could just send updates to everyone but that kills the sender!
252 // For rejoin object syncing
254 int Network_rejoined = 0; // Did WE rejoin this game?
255 int Network_new_game = 0; // Is this the first level of a new game?
256 int Network_send_objects = 0; // Are we in the process of sending objects to a player?
257 int Network_send_objnum = -1; // What object are we sending next?
258 int Network_player_added = 0; // Is this a new player or a returning player?
259 int Network_send_object_mode = 0; // What type of objects are we sending, static or dynamic?
260 sequence_packet Network_player_rejoining; // Who is rejoining now?
262 fix LastPacketTime[MAX_PLAYERS]; // For timeouts of idle/crashed players
264 int PacketUrgent = 0;
266 int TotalMissedPackets=0,TotalPacketsGot=0;
268 frame_info MySyncPack,UrgentSyncPack;
269 ubyte MySyncPackInitialized = 0; // Set to 1 if the MySyncPack is zeroed.
270 ushort my_segments_checksum = 0;
272 sequence_packet My_Seq;
273 char WantPlayersInfo=0;
274 char WaitingForPlayerInfo=0;
276 char *RankStrings[]={"(unpatched) ","Cadet ","Ensign ","Lieutenant ","Lt.Commander ",
277 "Commander ","Captain ","Vice Admiral ","Admiral ","Demigod "};
279 extern obj_position Player_init[MAX_PLAYERS];
281 extern int force_cockpit_redraw;
283 #define DUMP_CLOSED 0
285 #define DUMP_ENDLEVEL 2
287 #define DUMP_ABORTED 4
288 #define DUMP_CONNECTED 5
290 #define DUMP_KICKED 7
292 extern ubyte Version_major,Version_minor;
293 extern ubyte SurfingNet;
294 extern char MaxPowerupsAllowed[MAX_POWERUP_TYPES];
295 extern char PowerupsInMine[MAX_POWERUP_TYPES];
297 extern void multi_send_stolen_items();
299 int network_wait_for_snyc();
300 extern void multi_send_wall_status (int,ubyte,ubyte,ubyte);
301 extern void multi_send_wall_status_specific (int,int,ubyte,ubyte,ubyte);
303 extern void game_disable_cheats();
306 FILE *SendLogFile,*RecieveLogFile;
307 int TTSent[100],TTRecv[100];
309 extern int Final_boss_is_dead;
311 // following is network stuff for appletalk
313 void network_dump_appletalk_player(ubyte node, ushort net, ubyte socket, int why);
315 #define NETWORK_OEM 0x10
319 int Network_game_type; // used to tell IPX vs. appletalk games
321 #define MAX_ZONES 255
322 #define MAX_ZONE_LENGTH 33
323 #define DEFAULT_ZONE_NAME "\p*"
324 #define MAX_REGISTER_TRIES 5 // maximum time we will try and register a netgame
325 char Network_zone_name[MAX_ZONE_LENGTH]; // zone name game being played in for appletalk
326 char Zone_names[MAX_ZONES][MAX_ZONE_LENGTH]; // total list of zones that we can see
327 ubyte appletalk_use_broadcast = 0;
328 ubyte Network_game_validated = 0; // validates a game before being able to join
329 ubyte Network_game_validate_choice = 0;
330 ubyte Network_appletalk_type = 0; // type of appletalk network game is being played on
332 #define ETHERTALK_TYPE 0
333 #define LOCALTALK_TYPE 1
334 #define OTHERTALK_TYPE 2
337 void network_release_registered_game(void);
345 // So you want to play a netgame, eh? Let's a get a few things
349 int save_pnum = Player_num;
351 game_disable_cheats();
353 Final_boss_is_dead=0;
354 NamesInfoSecurity=-1;
362 for (t=0;t<MAX_POWERUP_TYPES;t++)
364 MaxPowerupsAllowed[t]=0;
368 TotalMissedPackets=0; TotalPacketsGot=0;
370 memset(&Netgame, 0, sizeof(netgame_info));
371 memset(&NetPlayers,0,sizeof(AllNetPlayers_info));
372 memset(&My_Seq, 0, sizeof(sequence_packet));
373 My_Seq.type = PID_REQUEST;
374 memcpy(My_Seq.player.callsign, Players[Player_num].callsign, CALLSIGN_LEN+1);
377 Version_minor|=NETWORK_OEM;
380 My_Seq.player.version_major=Version_major;
381 My_Seq.player.version_minor=Version_minor;
382 My_Seq.player.rank=GetMyNetRanking();
384 if (Network_game_type == IPX_GAME) {
385 memcpy(My_Seq.player.network.ipx.node, ipx_get_my_local_address(), 6);
386 memcpy(My_Seq.player.network.ipx.server, ipx_get_my_server_address(), 4 );
389 My_Seq.player.network.appletalk.node = appletalk_get_my_node();
390 My_Seq.player.network.appletalk.net = appletalk_get_my_net();
391 My_Seq.player.network.appletalk.socket = appletalk_get_my_socket();
395 My_Seq.player.computer_type = MAC;
397 My_Seq.player.computer_type = DOS;
400 for (Player_num = 0; Player_num < MAX_NUM_NET_PLAYERS; Player_num++)
401 init_player_stats_game();
403 Player_num = save_pnum;
405 Network_new_game = 1;
406 Control_center_destroyed = 0;
409 Netgame.PacketsPerSec=10;
411 if ((t=args_find("-packets")))
413 Netgame.PacketsPerSec=atoi(Args[t+1]);
414 if (Netgame.PacketsPerSec<1)
415 Netgame.PacketsPerSec=1;
416 else if (Netgame.PacketsPerSec>20)
417 Netgame.PacketsPerSec=20;
418 mprintf ((0,"Will send %d packets per second",Netgame.PacketsPerSec));
420 if (args_find("-shortpackets"))
422 Netgame.ShortPackets=1;
423 mprintf ((0,"Will send short packets.\n"));
428 network_i_am_master(void)
430 // I am the lowest numbered player in this game?
434 if (!(Game_mode & GM_NETWORK))
435 return (Player_num == 0);
437 for (i = 0; i < Player_num; i++)
438 if (Players[i].connected)
443 network_who_is_master(void)
445 // Who is the master of this game?
449 if (!(Game_mode & GM_NETWORK))
450 return (Player_num == 0);
452 for (i = 0; i < N_players; i++)
453 if (Players[i].connected)
457 int network_how_many_connected()
461 for (i = 0; i < N_players; i++)
462 if (Players[i].connected)
467 #define ENDLEVEL_SEND_INTERVAL (F1_0*2)
468 #define ENDLEVEL_IDLE_TIME (F1_0*20)
471 network_endlevel_poll( int nitems, newmenu_item * menus, int * key, int citem )
473 // Polling loop for End-of-level menu
481 int previous_state[MAX_NUM_NET_PLAYERS];
482 int previous_seconds_left;
489 // Send our endlevel packet at regular intervals
491 if (timer_get_approx_seconds() > (t1+ENDLEVEL_SEND_INTERVAL))
493 network_send_endlevel_packet();
494 t1 = timer_get_approx_seconds();
497 for (i = 0; i < N_players; i++)
498 previous_state[i] = Players[i].connected;
500 previous_seconds_left = Countdown_seconds_left;
504 for (i = 0; i < N_players; i++)
506 if (Players[i].connected == 1)
508 // Check timeout for idle players
509 if (timer_get_approx_seconds() > LastPacketTime[i]+ENDLEVEL_IDLE_TIME)
511 mprintf((0, "idle timeout for player %d.\n", i));
512 Players[i].connected = 0;
513 network_send_endlevel_sub(i);
517 if ((Players[i].connected != 1) && (Players[i].connected != 5) && (Players[i].connected != 6))
519 if (Players[i].connected != 1)
521 if (Players[i].connected == 4)
525 if (num_escaped == N_players) // All players are out of the mine
527 Countdown_seconds_left = -1;
531 if (num_ready == N_players) // All players have checked in or are disconnected
541 network_endlevel_poll2( int nitems, newmenu_item * menus, int * key, int citem )
543 // Polling loop for End-of-level menu
555 // Send our endlevel packet at regular intervals
557 if (timer_get_approx_seconds() > (t1+ENDLEVEL_SEND_INTERVAL))
559 network_send_endlevel_packet();
560 t1 = timer_get_approx_seconds();
563 // mprintf ((0,"Trying to listen!\n"));
566 for (i = 0; i < N_players; i++)
568 if ((Players[i].connected != 1) && (Players[i].connected != 5) && (Players[i].connected != 6))
570 if (Players[i].connected == 4)
574 if (num_ready == N_players) // All players have checked in or are disconnected
584 extern fix StartAbortMenuTime;
587 network_endlevel_poll3( int nitems, newmenu_item * menus, int * key, int citem )
589 // Polling loop for End-of-level menu
598 if (timer_get_approx_seconds() > (StartAbortMenuTime+(F1_0 * 8)))
605 for (i = 0; i < N_players; i++)
606 if ((Players[i].connected != 1) && (Players[i].connected != 5) && (Players[i].connected != 6))
609 if (num_ready == N_players) // All players have checked in or are disconnected
616 network_endlevel(int *secret)
618 // Do whatever needs to be done between levels
626 Network_status = NETSTAT_ENDLEVEL; // We are between levels
630 network_send_endlevel_packet();
632 for (i=0; i<N_players; i++)
634 LastPacketTime[i] = timer_get_approx_seconds();
637 network_send_endlevel_packet();
638 network_send_endlevel_packet();
639 MySyncPackInitialized = 0;
641 network_update_netgame();
647 can_join_netgame(netgame_info *game,AllNetPlayers_info *people)
649 // Can this player rejoin a netgame in progress?
653 if (game->game_status == NETSTAT_STARTING)
656 if (game->game_status != NETSTAT_PLAYING)
658 mprintf ((0,"Error: Can't join because game_status !=NETSTAT_PLAYING\n"));
662 if (game->version_major==0 && Version_major>0)
664 mprintf ((0,"Error:Can't join because version majors don't match!\n"));
668 if (game->version_major>0 && Version_major==0)
670 mprintf ((0,"Error:Can't join because version majors2 don't match!\n"));
674 // Game is in progress, figure out if this guy can re-join it
676 num_players = game->numplayers;
678 if (!(game->game_flags & NETGAME_FLAG_CLOSED)) {
679 // Look for player that is not connected
681 if (game->numconnected==game->max_numplayers)
684 // mprintf ((0,"Refuse = %d\n",game->RefusePlayers));
686 if (game->RefusePlayers)
689 if (game->numplayers < game->max_numplayers)
692 if (game->numconnected<num_players)
699 mprintf ((0,"Error! Can't join because people==NULL!\n"));
703 // Search to see if we were already in this closed netgame in progress
705 for (i = 0; i < num_players; i++) {
706 if (Network_game_type == IPX_GAME) {
707 if ( (!stricmp(Players[Player_num].callsign, people->players[i].callsign)) &&
708 (!memcmp(My_Seq.player.network.ipx.node, people->players[i].network.ipx.node, 6)) &&
709 (!memcmp(My_Seq.player.network.ipx.server, people->players[i].network.ipx.server, 4)) )
712 if ( (!stricmp(Players[Player_num].callsign, people->players[i].callsign)) &&
713 (My_Seq.player.network.appletalk.node == people->players[i].network.appletalk.node) &&
714 (My_Seq.player.network.appletalk.net == people->players[i].network.appletalk.net) )
719 if (i != num_players)
722 mprintf ((0,"Error: Can't join because at end of list!\n"));
727 network_disconnect_player(int playernum)
729 // A player has disconnected from the net game, take whatever steps are
732 if (playernum == Player_num)
734 Int3(); // Weird, see Rob
738 Players[playernum].connected = 0;
739 NetPlayers.players[playernum].connected = 0;
740 if (VerifyPlayerJoined==playernum)
741 VerifyPlayerJoined=-1;
743 // create_player_appearance_effect(&Objects[Players[playernum].objnum]);
744 multi_make_player_ghost(playernum);
746 if (Newdemo_state == ND_STATE_RECORDING)
747 newdemo_record_multi_disconnect(playernum);
749 multi_strip_robots(playernum);
753 network_new_player(sequence_packet *their)
758 pnum = their->player.connected;
761 Assert(pnum < MaxNumNetPlayers);
763 objnum = Players[pnum].objnum;
765 if (Newdemo_state == ND_STATE_RECORDING) {
768 if (pnum == N_players)
772 newdemo_record_multi_connect(pnum, new_player, their->player.callsign);
775 memcpy(Players[pnum].callsign, their->player.callsign, CALLSIGN_LEN+1);
776 memcpy(NetPlayers.players[pnum].callsign, their->player.callsign, CALLSIGN_LEN+1);
779 ClipRank (&their->player.rank);
780 NetPlayers.players[pnum].rank=their->player.rank;
781 NetPlayers.players[pnum].version_major=their->player.version_major;
782 NetPlayers.players[pnum].version_minor=their->player.version_minor;
783 network_check_for_old_version(pnum);
785 if (Network_game_type == IPX_GAME) {
786 if ( (*(uint *)their->player.network.ipx.server) != 0 )
787 ipx_get_local_target( their->player.network.ipx.server, their->player.network.ipx.node, Players[pnum].net_address );
789 memcpy(Players[pnum].net_address, their->player.network.ipx.node, 6);
791 memcpy(NetPlayers.players[pnum].network.ipx.node, their->player.network.ipx.node, 6);
792 memcpy(NetPlayers.players[pnum].network.ipx.server, their->player.network.ipx.server, 4);
794 NetPlayers.players[pnum].network.appletalk.node = their->player.network.appletalk.node;
795 NetPlayers.players[pnum].network.appletalk.net = their->player.network.appletalk.net;
796 NetPlayers.players[pnum].network.appletalk.socket = their->player.network.appletalk.socket;
799 Players[pnum].n_packets_got = 0;
800 Players[pnum].connected = 1;
801 Players[pnum].net_kills_total = 0;
802 Players[pnum].net_killed_total = 0;
803 memset(kill_matrix[pnum], 0, MAX_PLAYERS*sizeof(short));
804 Players[pnum].score = 0;
805 Players[pnum].flags = 0;
806 Players[pnum].KillGoalCount=0;
808 if (pnum == N_players)
811 Netgame.numplayers = N_players;
814 digi_play_sample(SOUND_HUD_MESSAGE, F1_0);
816 ClipRank (&their->player.rank);
818 if (args_find("-norankings"))
819 HUD_init_message("'%s' %s\n",their->player.callsign, TXT_JOINING);
821 HUD_init_message("%s'%s' %s\n",RankStrings[their->player.rank],their->player.callsign, TXT_JOINING);
823 multi_make_ghost_player(pnum);
826 multi_sort_kill_list();
828 // create_player_appearance_effect(&Objects[objnum]);
831 char RefuseThisPlayer=0,WaitForRefuseAnswer=0,RefuseTeam;
832 char RefusePlayerName[12];
833 fix RefuseTimeLimit=0;
835 void network_welcome_player(sequence_packet *their)
837 // Add a player to a game already in progress
838 ubyte local_address[6];
842 WaitForRefuseAnswer=0;
844 if (args_find("-NoMatrixCheat"))
846 if (their->player.version_minor & (0x0F<3))
848 network_dump_player(their->player.network.ipx.server, their->player.network.ipx.node, DUMP_DORK);
855 // If hoard game, and this guy isn't D2 Christmas (v1.2), dump him
857 if ((Game_mode & GM_HOARD) && ((their->player.version_minor & 0x0F)<2))
859 if (Network_game_type == IPX_GAME)
860 network_dump_player(their->player.network.ipx.server, their->player.network.ipx.node, DUMP_DORK);
863 network_dump_appletalk_player(their->player.network.appletalk.node, their->player.network.appletalk.net, their->player.network.appletalk.socket, DUMP_DORK);
869 // Don't accept new players if we're ending this level. Its safe to
870 // ignore since they'll request again later
872 if ((Endlevel_sequence) || (Control_center_destroyed))
874 mprintf((0, "Ignored request from new player to join during endgame.\n"));
875 if (Network_game_type == IPX_GAME)
876 network_dump_player(their->player.network.ipx.server,their->player.network.ipx.node, DUMP_ENDLEVEL);
879 network_dump_appletalk_player(their->player.network.appletalk.node, their->player.network.appletalk.net, their->player.network.appletalk.socket, DUMP_ENDLEVEL);
884 if (Network_send_objects || Network_sending_extras)
886 // Ignore silently, we're already responding to someone and we can't
887 // do more than one person at a time. If we don't dump them they will
888 // re-request in a few seconds.
892 if (their->player.connected != Current_level_num)
894 mprintf((0, "Dumping player due to old level number.\n"));
895 if (Network_game_type == IPX_GAME)
896 network_dump_player(their->player.network.ipx.server, their->player.network.ipx.node, DUMP_LEVEL);
899 network_dump_appletalk_player(their->player.network.appletalk.node, their->player.network.appletalk.net, their->player.network.appletalk.socket, DUMP_LEVEL);
905 memset(&Network_player_rejoining, 0, sizeof(sequence_packet));
906 Network_player_added = 0;
908 if (Network_game_type == IPX_GAME) {
909 if ( (*(uint *)their->player.network.ipx.server) != 0 )
910 ipx_get_local_target( their->player.network.ipx.server, their->player.network.ipx.node, local_address );
912 memcpy(local_address, their->player.network.ipx.node, 6);
915 for (i = 0; i < N_players; i++)
917 if ( (Network_game_type == IPX_GAME) && (!stricmp(Players[i].callsign, their->player.callsign )) && (!memcmp(Players[i].net_address,local_address, 6)) )
922 #ifdef MACINTOSH // note link to above if
923 else if ( (!stricmp(Players[i].callsign, their->player.callsign)) &&
924 (NetPlayers.players[i].network.appletalk.node == their->player.network.appletalk.node) &&
925 (NetPlayers.players[i].network.appletalk.net == their->player.network.appletalk.net)) {
932 if (player_num == -1)
934 // Player is new to this game
936 if ( !(Netgame.game_flags & NETGAME_FLAG_CLOSED) && (N_players < MaxNumNetPlayers))
938 // Add player in an open slot, game not full yet
940 player_num = N_players;
941 Network_player_added = 1;
943 else if (Netgame.game_flags & NETGAME_FLAG_CLOSED)
945 // Slots are open but game is closed
947 if (Network_game_type == IPX_GAME)
948 network_dump_player(their->player.network.ipx.server, their->player.network.ipx.node, DUMP_CLOSED);
951 network_dump_appletalk_player(their->player.network.appletalk.node, their->player.network.appletalk.net, their->player.network.appletalk.socket, DUMP_CLOSED);
957 // Slots are full but game is open, see if anyone is
958 // disconnected and replace the oldest player with this new one
960 int oldest_player = -1;
961 fix oldest_time = timer_get_approx_seconds();
963 Assert(N_players == MaxNumNetPlayers);
965 for (i = 0; i < N_players; i++)
967 if ( (!Players[i].connected) && (LastPacketTime[i] < oldest_time))
969 oldest_time = LastPacketTime[i];
974 if (oldest_player == -1)
976 // Everyone is still connected
978 if (Network_game_type == IPX_GAME)
979 network_dump_player(their->player.network.ipx.server, their->player.network.ipx.node, DUMP_FULL);
982 network_dump_appletalk_player(their->player.network.appletalk.node, their->player.network.appletalk.net, their->player.network.appletalk.socket, DUMP_FULL);
990 player_num = oldest_player;
991 Network_player_added = 1;
997 // Player is reconnecting
999 if (Players[player_num].connected)
1001 mprintf((0, "Extra REQUEST from player ignored.\n"));
1005 if (Newdemo_state == ND_STATE_RECORDING)
1006 newdemo_record_multi_reconnect(player_num);
1008 Network_player_added = 0;
1010 digi_play_sample(SOUND_HUD_MESSAGE, F1_0);
1012 if (args_find("-norankings"))
1013 HUD_init_message("'%s' %s", Players[player_num].callsign, TXT_REJOIN);
1015 HUD_init_message("%s'%s' %s", RankStrings[NetPlayers.players[player_num].rank],Players[player_num].callsign, TXT_REJOIN);
1018 Players[player_num].KillGoalCount=0;
1020 // Send updated Objects data to the new/returning player
1023 Network_player_rejoining = *their;
1024 Network_player_rejoining.player.connected = player_num;
1025 Network_send_objects = 1;
1026 Network_send_objnum = -1;
1028 network_send_objects();
1031 int network_objnum_is_past(int objnum)
1033 // determine whether or not a given object number has already been sent
1034 // to a re-joining player.
1036 int player_num = Network_player_rejoining.player.connected;
1037 int obj_mode = !((object_owner[objnum] == -1) || (object_owner[objnum] == player_num));
1039 if (!Network_send_objects)
1040 return 0; // We're not sending objects to a new player
1042 if (obj_mode > Network_send_object_mode)
1044 else if (obj_mode < Network_send_object_mode)
1046 else if (objnum < Network_send_objnum)
1052 #define OBJ_PACKETS_PER_FRAME 1
1053 extern void multi_send_active_door(char);
1054 extern void multi_send_door_open_specific(int,int,int,ubyte);
1057 void network_send_door_updates(int pnum)
1059 // Send door status when new player joins
1065 // Assert (pnum>-1 && pnum<N_players);
1067 for (i = 0; i < Num_walls; i++)
1069 if ((Walls[i].type == WALL_DOOR) && ((Walls[i].state == WALL_DOOR_OPENING) || (Walls[i].state == WALL_DOOR_WAITING) || (Walls[i].state == WALL_DOOR_OPEN)))
1070 multi_send_door_open_specific(pnum,Walls[i].segnum, Walls[i].sidenum,Walls[i].flags);
1071 else if ((Walls[i].type == WALL_BLASTABLE) && (Walls[i].flags & WALL_BLASTED))
1072 multi_send_door_open_specific(pnum,Walls[i].segnum, Walls[i].sidenum,Walls[i].flags);
1073 else if ((Walls[i].type == WALL_BLASTABLE) && (Walls[i].hps != WALL_HPS))
1074 multi_send_hostage_door_status(i);
1076 multi_send_wall_status_specific(pnum,i,Walls[i].type,Walls[i].flags,Walls[i].state);
1080 extern vms_vector MarkerPoint[];
1081 void network_send_markers()
1083 // send marker positions/text to new player
1090 if (MarkerObject[(i*2)]!=-1)
1091 multi_send_drop_marker (i,MarkerPoint[(i*2)],0,MarkerMessage[i*2]);
1092 if (MarkerObject[(i*2)+1]!=-1)
1093 multi_send_drop_marker (i,MarkerPoint[(i*2)+1],1,MarkerMessage[(i*2)+1]);
1097 void network_process_monitor_vector(int vector)
1103 for (i=0; i <= Highest_segment_index; i++)
1107 for (j = 0; j < 6; j++)
1109 if ( ((tm = seg->sides[j].tmap_num2) != 0) &&
1110 ((ec = TmapInfo[tm&0x3fff].eclip_num) != -1) &&
1111 ((bm = Effects[ec].dest_bm_num) != -1) )
1113 if (vector & (1 << count))
1115 seg->sides[j].tmap_num2 = bm | (tm&0xc000);
1116 // mprintf((0, "Monitor %d blown up.\n", count));
1119 // mprintf((0, "Monitor %d intact.\n", count));
1127 int network_create_monitor_vector(void)
1130 int num_blown_bitmaps = 0;
1131 int monitor_num = 0;
1132 #define NUM_BLOWN_BITMAPS 20
1133 int blown_bitmaps[NUM_BLOWN_BITMAPS];
1137 for (i=0; i < Num_effects; i++)
1139 if (Effects[i].dest_bm_num > 0) {
1140 for (j = 0; j < num_blown_bitmaps; j++)
1141 if (blown_bitmaps[j] == Effects[i].dest_bm_num)
1143 if (j == num_blown_bitmaps) {
1144 blown_bitmaps[num_blown_bitmaps++] = Effects[i].dest_bm_num;
1145 Assert(num_blown_bitmaps < NUM_BLOWN_BITMAPS);
1150 // for (i = 0; i < num_blown_bitmaps; i++)
1151 // mprintf((0, "Blown bitmap #%d = %d.\n", i, blown_bitmaps[i]));
1153 for (i=0; i <= Highest_segment_index; i++)
1157 for (j = 0; j < 6; j++)
1159 if ((tm = seg->sides[j].tmap_num2) != 0)
1161 if ( ((ec = TmapInfo[tm&0x3fff].eclip_num) != -1) &&
1162 (Effects[ec].dest_bm_num != -1) )
1164 // mprintf((0, "Monitor %d intact.\n", monitor_num));
1166 Assert(monitor_num < 32);
1170 for (k = 0; k < num_blown_bitmaps; k++)
1172 if ((tm&0x3fff) == blown_bitmaps[k])
1174 //mprintf((0, "Monitor %d destroyed.\n", monitor_num));
1175 vector |= (1 << monitor_num);
1177 Assert(monitor_num < 32);
1185 // mprintf((0, "Final monitor vector %x.\n", vector));
1189 void network_stop_resync(sequence_packet *their)
1191 if (Network_game_type == IPX_GAME) {
1192 if ( (!memcmp(Network_player_rejoining.player.network.ipx.node, their->player.network.ipx.node, 6)) &&
1193 (!memcmp(Network_player_rejoining.player.network.ipx.server, their->player.network.ipx.server, 4)) &&
1194 (!stricmp(Network_player_rejoining.player.callsign, their->player.callsign)) )
1196 mprintf((0, "Aborting resync for player %s.\n", their->player.callsign));
1197 Network_send_objects = 0;
1198 Network_sending_extras=0;
1200 Player_joining_extras=-1;
1201 Network_send_objnum = -1;
1204 if ( (Network_player_rejoining.player.network.appletalk.node == their->player.network.appletalk.node) &&
1205 (Network_player_rejoining.player.network.appletalk.net == their->player.network.appletalk.net) &&
1206 (!stricmp(Network_player_rejoining.player.callsign, their->player.callsign)) )
1208 mprintf((0, "Aborting resync for player %s.\n", their->player.callsign));
1209 Network_send_objects = 0;
1210 Network_sending_extras=0;
1212 Player_joining_extras=-1;
1213 Network_send_objnum = -1;
1218 byte object_buffer[IPX_MAX_DATA_SIZE];
1220 void network_send_objects(void)
1222 short remote_objnum;
1226 static int obj_count = 0;
1227 static int frame_num = 0;
1229 int obj_count_frame = 0;
1230 int player_num = Network_player_rejoining.player.connected;
1232 // Send clear objects array trigger and send player num
1234 Assert(Network_send_objects != 0);
1235 Assert(player_num >= 0);
1236 Assert(player_num < MaxNumNetPlayers);
1238 if (Endlevel_sequence || Control_center_destroyed)
1240 // Endlevel started before we finished sending the goods, we'll
1241 // have to stop and try again after the level.
1243 if (Network_game_type == IPX_GAME)
1244 network_dump_player(Network_player_rejoining.player.network.ipx.server,Network_player_rejoining.player.network.ipx.node, DUMP_ENDLEVEL);
1247 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);
1249 Network_send_objects = 0;
1253 for (h = 0; h < OBJ_PACKETS_PER_FRAME; h++) // Do more than 1 per frame, try to speed it up without
1254 // over-stressing the receiver.
1256 obj_count_frame = 0;
1257 memset(object_buffer, 0, IPX_MAX_DATA_SIZE);
1258 object_buffer[0] = PID_OBJECT_DATA;
1261 if (Network_send_objnum == -1)
1264 Network_send_object_mode = 0;
1265 // mprintf((0, "Sending object array to player %d.\n", player_num));
1266 *(short *)(object_buffer+loc) = INTEL_SHORT(-1); loc += 2;
1267 object_buffer[loc] = player_num; loc += 1;
1268 loc += 2; // Placeholder for remote_objnum, not used here
1269 Network_send_objnum = 0;
1270 obj_count_frame = 1;
1274 for (i = Network_send_objnum; i <= Highest_object_index; i++)
1276 if ((Objects[i].type != OBJ_POWERUP) && (Objects[i].type != OBJ_PLAYER) &&
1277 (Objects[i].type != OBJ_CNTRLCEN) && (Objects[i].type != OBJ_GHOST) &&
1278 (Objects[i].type != OBJ_ROBOT) && (Objects[i].type != OBJ_HOSTAGE) &&
1279 !(Objects[i].type==OBJ_WEAPON && Objects[i].id==PMINE_ID))
1281 if ((Network_send_object_mode == 0) && ((object_owner[i] != -1) && (object_owner[i] != player_num)))
1283 if ((Network_send_object_mode == 1) && ((object_owner[i] == -1) || (object_owner[i] == player_num)))
1286 if ( ((IPX_MAX_DATA_SIZE-1) - loc) < (sizeof(object)+5) )
1287 break; // Not enough room for another object
1292 remote_objnum = objnum_local_to_remote((short)i, &owner);
1293 Assert(owner == object_owner[i]);
1295 *(short *)(object_buffer+loc) = INTEL_SHORT((short)i); loc += 2;
1296 object_buffer[loc] = owner; loc += 1;
1297 *(short *)(object_buffer+loc) = INTEL_SHORT(remote_objnum); loc += 2;
1299 memcpy(object_buffer+loc, &Objects[i], sizeof(object)); loc += sizeof(object);
1301 if (Network_game_type == IPX_GAME) {
1304 memcpy(&tmpobj, &(Objects[i]), sizeof(object));
1305 swap_object(&tmpobj);
1306 memcpy(&(object_buffer[loc]), &tmpobj, sizeof(object)); loc += sizeof(object);
1309 memcpy(object_buffer+loc, &Objects[i], sizeof(object)); loc += sizeof(object);
1311 // mprintf((0, "..packing object %d, remote %d\n", i, remote_objnum));
1314 if (obj_count_frame) // Send any objects we've buffered
1318 Network_send_objnum = i;
1319 object_buffer[1] = obj_count_frame; object_buffer[2] = frame_num;
1320 // mprintf((0, "Object packet %d contains %d objects.\n", frame_num, obj_count_frame));
1322 Assert(loc <= IPX_MAX_DATA_SIZE);
1324 if (Network_game_type == IPX_GAME)
1325 ipx_send_internetwork_packet_data( object_buffer, loc, Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node );
1328 appletalk_send_packet_data( object_buffer, loc, Network_player_rejoining.player.network.appletalk.node,
1329 Network_player_rejoining.player.network.appletalk.net,
1330 Network_player_rejoining.player.network.appletalk.socket);
1333 // OLD ipx_send_packet_data(object_buffer, loc, &Network_player_rejoining.player.node);
1336 if (i > Highest_object_index)
1338 if (Network_send_object_mode == 0)
1340 Network_send_objnum = 0;
1341 Network_send_object_mode = 1; // go to next mode
1345 Assert(Network_send_object_mode == 1);
1348 // Send count so other side can make sure he got them all
1349 // mprintf((0, "Sending end marker in packet #%d.\n", frame_num));
1350 mprintf((0, "Sent %d objects.\n", obj_count));
1351 object_buffer[0] = PID_OBJECT_DATA;
1352 object_buffer[1] = 1;
1353 object_buffer[2] = frame_num;
1354 *(short *)(object_buffer+3) = INTEL_SHORT(-2);
1355 *(short *)(object_buffer+6) = INTEL_SHORT(obj_count);
1356 //OLD ipx_send_packet_data(object_buffer, 8, &Network_player_rejoining.player.node);
1357 if (Network_game_type == IPX_GAME)
1358 ipx_send_internetwork_packet_data(object_buffer, 8, Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node);
1361 appletalk_send_packet_data( object_buffer, 8, Network_player_rejoining.player.network.appletalk.node,
1362 Network_player_rejoining.player.network.appletalk.net,
1363 Network_player_rejoining.player.network.appletalk.socket);
1367 // Send sync packet which tells the player who he is and to start!
1368 network_send_rejoin_sync(player_num);
1369 mprintf ((0,"VerfiyPlayerJoined is now set to %d\n",player_num));
1370 VerifyPlayerJoined=player_num;
1372 // Turn off send object mode
1373 Network_send_objnum = -1;
1374 Network_send_objects = 0;
1377 //if (!network_i_am_master ())
1378 // Int3(); // Bad!! Get Jason. Someone goofy is trying to get ahold of the game!
1380 Network_sending_extras=40; // start to send extras
1381 Player_joining_extras=player_num;
1385 } // i > Highest_object_index
1386 } // For PACKETS_PER_FRAME
1389 extern void multi_send_powerup_update();
1391 void network_send_rejoin_sync(int player_num)
1395 Players[player_num].connected = 1; // connect the new guy
1396 LastPacketTime[player_num] = timer_get_approx_seconds();
1398 if (Endlevel_sequence || Control_center_destroyed)
1400 // Endlevel started before we finished sending the goods, we'll
1401 // have to stop and try again after the level.
1403 if (Network_game_type == IPX_GAME)
1404 network_dump_player(Network_player_rejoining.player.network.ipx.server,Network_player_rejoining.player.network.ipx.node, DUMP_ENDLEVEL);
1407 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);
1409 Network_send_objects = 0;
1410 Network_sending_extras=0;
1414 if (Network_player_added)
1416 Network_player_rejoining.type = PID_ADDPLAYER;
1417 Network_player_rejoining.player.connected = player_num;
1418 network_new_player(&Network_player_rejoining);
1420 for (i = 0; i < N_players; i++)
1422 if ((i != player_num) && (i != Player_num) && (Players[i].connected))
1423 if (Network_game_type == IPX_GAME) {
1425 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);
1427 send_sequence_packet( Network_player_rejoining, NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node, Players[i].net_address);
1431 appletalk_send_packet_data( (ubyte *)&Network_player_rejoining, sizeof(sequence_packet), NetPlayers.players[i].network.appletalk.node,
1432 NetPlayers.players[i].network.appletalk.net, NetPlayers.players[i].network.appletalk.socket);
1438 // Send sync packet to the new guy
1440 network_update_netgame();
1442 // Fill in the kill list
1443 for (j=0; j<MAX_PLAYERS; j++)
1445 for (i=0; i<MAX_PLAYERS;i++)
1446 Netgame.kills[j][i] = kill_matrix[j][i];
1447 Netgame.killed[j] = Players[j].net_killed_total;
1448 Netgame.player_kills[j] = Players[j].net_kills_total;
1449 Netgame.player_score[j] = Players[j].score;
1452 Netgame.level_time = Players[Player_num].time_level;
1453 Netgame.monitor_vector = network_create_monitor_vector();
1455 mprintf((0, "Sending rejoin sync packet!!!\n"));
1457 if (Network_game_type == IPX_GAME) {
1459 ipx_send_internetwork_packet_data( (ubyte *)&Netgame, sizeof(netgame_info), Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node );
1460 ipx_send_internetwork_packet_data( (ubyte *)&NetPlayers, sizeof(AllNetPlayers_info), Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node );
1462 send_netgame_packet(Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node, NULL, 0);
1463 send_netplayers_packet(Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node);
1467 appletalk_send_packet_data( (ubyte *)&Netgame, sizeof(netgame_info), Network_player_rejoining.player.network.appletalk.node,
1468 Network_player_rejoining.player.network.appletalk.net,
1469 Network_player_rejoining.player.network.appletalk.socket);
1470 appletalk_send_packet_data( (ubyte *)&NetPlayers, sizeof(AllNetPlayers_info), Network_player_rejoining.player.network.appletalk.node,
1471 Network_player_rejoining.player.network.appletalk.net,
1472 Network_player_rejoining.player.network.appletalk.socket);
1477 void resend_sync_due_to_packet_loss_for_allender ()
1481 mprintf ((0,"I'm resending a sync packet! VPJ=%d\n",VerifyPlayerJoined));
1483 network_update_netgame();
1485 // Fill in the kill list
1486 for (j=0; j<MAX_PLAYERS; j++)
1488 for (i=0; i<MAX_PLAYERS;i++)
1489 Netgame.kills[j][i] = kill_matrix[j][i];
1490 Netgame.killed[j] = Players[j].net_killed_total;
1491 Netgame.player_kills[j] = Players[j].net_kills_total;
1492 Netgame.player_score[j] = Players[j].score;
1495 Netgame.level_time = Players[Player_num].time_level;
1496 Netgame.monitor_vector = network_create_monitor_vector();
1498 if (Network_game_type == IPX_GAME) {
1500 ipx_send_internetwork_packet_data( (ubyte *)&Netgame, sizeof(netgame_info), Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node );
1501 ipx_send_internetwork_packet_data( (ubyte *)&NetPlayers, sizeof(AllNetPlayers_info), Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node );
1503 send_netgame_packet(Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node, NULL, 0);
1504 send_netplayers_packet(Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node);
1508 appletalk_send_packet_data( (ubyte *)&Netgame, sizeof(netgame_info), Network_player_rejoining.player.network.appletalk.node,
1509 Network_player_rejoining.player.network.appletalk.net,
1510 Network_player_rejoining.player.network.appletalk.socket);
1511 appletalk_send_packet_data( (ubyte *)&NetPlayers, sizeof(AllNetPlayers_info), Network_player_rejoining.player.network.appletalk.node,
1512 Network_player_rejoining.player.network.appletalk.net,
1513 Network_player_rejoining.player.network.appletalk.socket);
1519 char * network_get_player_name( int objnum )
1521 if ( objnum < 0 ) return NULL;
1522 if ( Objects[objnum].type != OBJ_PLAYER ) return NULL;
1523 if ( Objects[objnum].id >= MAX_PLAYERS ) return NULL;
1524 if ( Objects[objnum].id >= N_players ) return NULL;
1526 return Players[Objects[objnum].id].callsign;
1530 void network_add_player(sequence_packet *p)
1534 mprintf((0, "Got add player request!\n"));
1536 for (i=0; i<N_players; i++ ) {
1537 if (Network_game_type == IPX_GAME) {
1538 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))
1539 return; // already got them
1541 if ( (NetPlayers.players[i].network.appletalk.node == p->player.network.appletalk.node) &&
1542 (NetPlayers.players[i].network.appletalk.net == p->player.network.appletalk.net))
1547 if (Network_game_type == IPX_GAME) {
1548 memcpy( NetPlayers.players[N_players].network.ipx.node, p->player.network.ipx.node, 6 );
1549 memcpy( NetPlayers.players[N_players].network.ipx.server, p->player.network.ipx.server, 4 );
1551 NetPlayers.players[N_players].network.appletalk.node = p->player.network.appletalk.node;
1552 NetPlayers.players[N_players].network.appletalk.net = p->player.network.appletalk.net;
1553 NetPlayers.players[N_players].network.appletalk.socket = p->player.network.appletalk.socket;
1556 ClipRank (&p->player.rank);
1558 memcpy( NetPlayers.players[N_players].callsign, p->player.callsign, CALLSIGN_LEN+1 );
1559 NetPlayers.players[N_players].version_major=p->player.version_major;
1560 NetPlayers.players[N_players].version_minor=p->player.version_minor;
1561 NetPlayers.players[N_players].rank=p->player.rank;
1562 NetPlayers.players[N_players].connected = 1;
1563 network_check_for_old_version (N_players);
1565 Players[N_players].KillGoalCount=0;
1566 Players[N_players].connected = 1;
1567 LastPacketTime[N_players] = timer_get_approx_seconds();
1569 Netgame.numplayers = N_players;
1571 // Broadcast updated info
1573 mprintf ((0,"sending_game_info!\n"));
1574 network_send_game_info(NULL);
1577 // One of the players decided not to join the game
1579 void network_remove_player(sequence_packet *p)
1584 for (i=0; i<N_players; i++ ) {
1585 if (Network_game_type == IPX_GAME) {
1586 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)) {
1591 if ( (NetPlayers.players[i].network.appletalk.node == p->player.network.appletalk.node) && (NetPlayers.players[i].network.appletalk.net == p->player.network.appletalk.net) ) {
1598 if (pn < 0 ) return;
1600 for (i=pn; i<N_players-1; i++ ) {
1601 if (Network_game_type == IPX_GAME) {
1602 memcpy( NetPlayers.players[i].network.ipx.node, NetPlayers.players[i+1].network.ipx.node, 6 );
1603 memcpy( NetPlayers.players[i].network.ipx.server, NetPlayers.players[i+1].network.ipx.server, 4 );
1605 NetPlayers.players[i].network.appletalk.node = NetPlayers.players[i+1].network.appletalk.node;
1606 NetPlayers.players[i].network.appletalk.net = NetPlayers.players[i+1].network.appletalk.net;
1607 NetPlayers.players[i].network.appletalk.socket = NetPlayers.players[i+1].network.appletalk.socket;
1609 memcpy( NetPlayers.players[i].callsign, NetPlayers.players[i+1].callsign, CALLSIGN_LEN+1 );
1610 NetPlayers.players[i].version_major=NetPlayers.players[i+1].version_major;
1611 NetPlayers.players[i].version_minor=NetPlayers.players[i+1].version_minor;
1613 NetPlayers.players[i].rank=NetPlayers.players[i+1].rank;
1614 ClipRank (&NetPlayers.players[i].rank);
1615 network_check_for_old_version(i);
1619 Netgame.numplayers = N_players;
1621 // Broadcast new info
1623 network_send_game_info(NULL);
1628 network_dump_player(ubyte * server, ubyte *node, int why)
1630 // Inform player that he was not chosen for the netgame
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 == IPX_GAME) {
1639 ipx_send_internetwork_packet_data( (ubyte *)&temp, sizeof(sequence_packet), server, node);
1641 send_sequence_packet( temp, server, node, NULL);
1649 void network_dump_appletalk_player(ubyte node, ushort net, ubyte socket, int why)
1651 sequence_packet temp;
1653 temp.type = PID_DUMP;
1654 memcpy(temp.player.callsign, Players[Player_num].callsign, CALLSIGN_LEN+1);
1655 temp.player.connected = why;
1656 if (Network_game_type == APPLETALK_GAME) {
1657 appletalk_send_packet_data( (ubyte *)&temp, sizeof(sequence_packet), node, net, socket );
1665 network_send_game_list_request()
1667 // Send a broadcast request for game info
1671 mprintf((0, "Sending game_list request.\n"));
1672 me.type = PID_GAME_LIST;
1673 memcpy( me.player.callsign, Players[Player_num].callsign, CALLSIGN_LEN+1 );
1675 if (Network_game_type == IPX_GAME) {
1676 memcpy( me.player.network.ipx.node, ipx_get_my_local_address(), 6 );
1677 memcpy( me.player.network.ipx.server, ipx_get_my_server_address(), 4 );
1680 ipx_send_broadcast_packet_data( (ubyte *)&me, sizeof(sequence_packet) );
1682 send_sequence_packet( me, NULL, NULL, NULL);
1686 me.player.network.appletalk.node = appletalk_get_my_node();
1687 me.player.network.appletalk.net = appletalk_get_my_net();
1688 me.player.network.appletalk.socket = appletalk_get_my_socket();
1689 appletalk_send_game_info( (ubyte *)&me, sizeof(sequence_packet), Network_zone_name );
1694 void network_send_all_info_request(char type,int which_security)
1696 // Send a broadcast request for game info
1700 mprintf((0, "Sending all_info request.\n"));
1702 me.Security=which_security;
1704 memcpy( me.player.callsign, Players[Player_num].callsign, CALLSIGN_LEN+1 );
1706 if (Network_game_type == IPX_GAME) {
1707 memcpy( me.player.network.ipx.node, ipx_get_my_local_address(), 6 );
1708 memcpy( me.player.network.ipx.server, ipx_get_my_server_address(), 4 );
1711 ipx_send_broadcast_packet_data( (ubyte *)&me, sizeof(sequence_packet) );
1713 send_sequence_packet(me, NULL, NULL, NULL);
1717 me.player.network.appletalk.node = appletalk_get_my_node();
1718 me.player.network.appletalk.net = appletalk_get_my_net();
1719 me.player.network.appletalk.socket = appletalk_get_my_socket();
1720 appletalk_send_game_info( (ubyte *)&me, sizeof(sequence_packet), Network_zone_name );
1727 network_update_netgame(void)
1729 // Update the netgame struct with current game variables
1733 Netgame.numconnected=0;
1734 for (i=0;i<N_players;i++)
1735 if (Players[i].connected)
1736 Netgame.numconnected++;
1738 // This is great: D2 1.0 and 1.1 ignore upper part of the game_flags field of
1739 // the lite_info struct when you're sitting on the join netgame screen. We can
1740 // "sneak" Hoard information into this field. This is better than sending
1741 // another packet that could be lost in transit.
1744 if (HoardEquipped())
1746 if (Game_mode & GM_HOARD)
1748 Netgame.game_flags |=NETGAME_FLAG_HOARD;
1749 if (Game_mode & GM_TEAM)
1750 Netgame.game_flags |=NETGAME_FLAG_TEAM_HOARD;
1754 if (Network_status == NETSTAT_STARTING)
1757 Netgame.numplayers = N_players;
1758 Netgame.game_status = Network_status;
1759 Netgame.max_numplayers = MaxNumNetPlayers;
1761 for (i = 0; i < MAX_NUM_NET_PLAYERS; i++)
1763 NetPlayers.players[i].connected = Players[i].connected;
1764 for(j = 0; j < MAX_NUM_NET_PLAYERS; j++)
1765 Netgame.kills[i][j] = kill_matrix[i][j];
1767 Netgame.killed[i] = Players[i].net_killed_total;
1768 Netgame.player_kills[i] = Players[i].net_kills_total;
1769 Netgame.player_score[i] = Players[i].score;
1770 Netgame.player_flags[i] = (Players[i].flags & (PLAYER_FLAGS_BLUE_KEY | PLAYER_FLAGS_RED_KEY | PLAYER_FLAGS_GOLD_KEY));
1772 Netgame.team_kills[0] = team_kills[0];
1773 Netgame.team_kills[1] = team_kills[1];
1774 Netgame.levelnum = Current_level_num;
1780 network_send_endlevel_sub(int player_num)
1785 // Send an endlevel packet for a player
1786 end.type = PID_ENDLEVEL;
1787 end.player_num = player_num;
1788 end.connected = Players[player_num].connected;
1789 end.kills = INTEL_SHORT(Players[player_num].net_kills_total);
1790 end.killed = INTEL_SHORT(Players[player_num].net_killed_total);
1791 memcpy(end.kill_matrix, kill_matrix[player_num], MAX_PLAYERS*sizeof(short));
1793 for (i = 0; i < MAX_PLAYERS; i++)
1794 for (j = 0; j < MAX_PLAYERS; j++)
1795 end.kill_matrix[i][j] = INTEL_SHORT(end.kill_matrix[i][j]);
1797 j = j; // to satisfy compiler
1800 if (Players[player_num].connected == 1) // Still playing
1802 Assert(Control_center_destroyed);
1803 end.seconds_left = Countdown_seconds_left;
1806 // mprintf((0, "Sending endlevel packet.\n"));
1808 for (i = 0; i < N_players; i++)
1810 if ((i != Player_num) && (i!=player_num) && (Players[i].connected)) {
1811 if (Players[i].connected==1)
1812 network_send_endlevel_short_sub(player_num,i);
1814 if (Network_game_type == IPX_GAME)
1815 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);
1818 appletalk_send_packet_data( (ubyte *)&end, sizeof(endlevel_info), NetPlayers.players[i].network.appletalk.node,
1819 NetPlayers.players[i].network.appletalk.net,
1820 NetPlayers.players[i].network.appletalk.socket);
1828 network_send_endlevel_packet(void)
1830 // Send an updated endlevel status to other hosts
1832 network_send_endlevel_sub(Player_num);
1837 network_send_endlevel_short_sub(int from_player_num,int to_player)
1839 endlevel_info_short end;
1841 // Send an endlevel packet for a player
1842 end.type = PID_ENDLEVEL_SHORT;
1843 end.player_num = from_player_num;
1844 end.connected = Players[from_player_num].connected;
1845 end.seconds_left = Countdown_seconds_left;
1848 if (Players[from_player_num].connected == 1) // Still playing
1850 Assert(Control_center_destroyed);
1853 if ((to_player != Player_num) && (to_player!=from_player_num) && (Players[to_player].connected))
1855 mprintf((0, "Sending short endlevel packet to %s.\n",Players[to_player].callsign));
1856 if (Network_game_type == IPX_GAME)
1857 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);
1860 appletalk_send_packet_data( (ubyte *)&end, sizeof(endlevel_info_short), NetPlayers.players[to_player].network.appletalk.node,
1861 NetPlayers.players[to_player].network.appletalk.net,
1862 NetPlayers.players[to_player].network.appletalk.socket);
1867 extern fix ThisLevelTime;
1870 network_send_game_info(sequence_packet *their)
1872 // Send game info to someone who requested it
1874 char old_type, old_status;
1878 mprintf((0, "Sending game info.\n"));
1880 network_update_netgame(); // Update the values in the netgame struct
1882 old_type = Netgame.type;
1883 old_status = Netgame.game_status;
1885 Netgame.type = PID_GAME_INFO;
1886 NetPlayers.type = PID_PLAYERSINFO;
1888 NetPlayers.Security=Netgame.Security;
1889 Netgame.version_major=Version_major;
1890 Netgame.version_minor=Version_minor;
1892 if (Endlevel_sequence || Control_center_destroyed)
1893 Netgame.game_status = NETSTAT_ENDLEVEL;
1895 if (Netgame.PlayTimeAllowed)
1897 timevar=i2f (Netgame.PlayTimeAllowed*5*60);
1898 i=f2i(timevar-ThisLevelTime);
1900 Netgame.game_status=NETSTAT_ENDLEVEL;
1904 if (Network_game_type == IPX_GAME) {
1906 ipx_send_broadcast_packet_data((ubyte *)&Netgame, sizeof(netgame_info));
1907 ipx_send_broadcast_packet_data((ubyte *)&NetPlayers,sizeof(AllNetPlayers_info));
1909 send_netgame_packet(NULL, NULL, NULL, 0); // server == NULL says to broadcast packet
1910 send_netplayers_packet(NULL, NULL);
1912 } // nothing to do for appletalk games I think....
1914 if (Network_game_type == IPX_GAME) {
1916 ipx_send_internetwork_packet_data((ubyte *)&Netgame, sizeof(netgame_info), their->player.network.ipx.server, their->player.network.ipx.node);
1917 ipx_send_internetwork_packet_data((ubyte *)&NetPlayers,sizeof(AllNetPlayers_info),their->player.network.ipx.server,their->player.network.ipx.node);
1919 send_netgame_packet(their->player.network.ipx.server, their->player.network.ipx.node, NULL, 0);
1920 send_netplayers_packet(their->player.network.ipx.server, their->player.network.ipx.node);
1924 appletalk_send_packet_data( (ubyte *)&Netgame, sizeof(netgame_info), their->player.network.appletalk.node,
1925 their->player.network.appletalk.net, their->player.network.appletalk.socket );
1926 appletalk_send_packet_data( (ubyte *)&NetPlayers, sizeof(AllNetPlayers_info), their->player.network.appletalk.node,
1927 their->player.network.appletalk.net, their->player.network.appletalk.socket );
1932 Netgame.type = old_type;
1933 Netgame.game_status = old_status;
1936 void network_send_lite_info(sequence_packet *their)
1938 // Send game info to someone who requested it
1940 char old_type, old_status,oldstatus;
1942 mprintf((0, "Sending lite game info.\n"));
1944 network_update_netgame(); // Update the values in the netgame struct
1946 old_type = Netgame.type;
1947 old_status = Netgame.game_status;
1949 Netgame.type = PID_LITE_INFO;
1951 if (Endlevel_sequence || Control_center_destroyed)
1952 Netgame.game_status = NETSTAT_ENDLEVEL;
1954 // If hoard mode, make this game look closed even if it isn't
1955 if (HoardEquipped())
1957 if (Game_mode & GM_HOARD)
1959 oldstatus=Netgame.game_status;
1960 Netgame.game_status=NETSTAT_ENDLEVEL;
1961 Netgame.gamemode=NETGAME_CAPTURE_FLAG;
1962 if (oldstatus==NETSTAT_ENDLEVEL)
1963 Netgame.game_flags|=NETGAME_FLAG_REALLY_ENDLEVEL;
1964 if (oldstatus==NETSTAT_STARTING)
1965 Netgame.game_flags|=NETGAME_FLAG_REALLY_FORMING;
1970 if (Network_game_type == IPX_GAME) {
1972 ipx_send_broadcast_packet_data((ubyte *)&Netgame, sizeof(lite_info));
1974 send_netgame_packet(NULL, NULL, NULL, 1); // server == NULL says broadcast
1976 } // nothing to do for appletalk I think....
1978 if (Network_game_type == IPX_GAME) {
1980 ipx_send_internetwork_packet_data((ubyte *)&Netgame, sizeof(lite_info), their->player.network.ipx.server, their->player.network.ipx.node);
1982 send_netgame_packet(their->player.network.ipx.server, their->player.network.ipx.node, NULL, 1);
1986 appletalk_send_packet_data( (ubyte *)&Netgame, sizeof(lite_info), their->player.network.appletalk.node,
1987 their->player.network.appletalk.net, their->player.network.appletalk.socket );
1992 // Restore the pre-hoard mode
1993 if (HoardEquipped())
1995 if (Game_mode & GM_HOARD)
1997 if (!(Game_mode & GM_TEAM))
1998 Netgame.gamemode=NETGAME_HOARD;
2000 Netgame.gamemode=NETGAME_TEAM_HOARD;
2001 Netgame.game_flags&=~NETGAME_FLAG_REALLY_ENDLEVEL;
2002 Netgame.game_flags&=~NETGAME_FLAG_REALLY_FORMING;
2003 Netgame.game_flags&=~NETGAME_FLAG_TEAM_HOARD;
2007 Netgame.type = old_type;
2008 Netgame.game_status = old_status;
2012 void network_send_netgame_update()
2014 // Send game info to someone who requested it
2016 char old_type, old_status;
2019 mprintf((0, "Sending updated game info.\n"));
2021 network_update_netgame(); // Update the values in the netgame struct
2023 old_type = Netgame.type;
2024 old_status = Netgame.game_status;
2026 Netgame.type = PID_GAME_UPDATE;
2028 if (Endlevel_sequence || Control_center_destroyed)
2029 Netgame.game_status = NETSTAT_ENDLEVEL;
2031 for (i=0; i<N_players; i++ ) {
2032 if ( (Players[i].connected) && (i!=Player_num ) ) {
2033 if (Network_game_type == IPX_GAME) {
2035 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 );
2037 send_netgame_packet(NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node, Players[i].net_address, 0);
2041 appletalk_send_packet_data( (ubyte *)&Netgame, sizeof(lite_info), NetPlayers.players[i].network.appletalk.node,
2042 NetPlayers.players[i].network.appletalk.net, NetPlayers.players[i].network.appletalk.socket );
2048 Netgame.type = old_type;
2049 Netgame.game_status = old_status;
2052 int network_send_request(void)
2054 // Send a request to join a game 'Netgame'. Returns 0 if we can join this
2055 // game, non-zero if there is some problem.
2058 if (Netgame.numplayers < 1)
2061 for (i = 0; i < MAX_NUM_NET_PLAYERS; i++)
2062 if (NetPlayers.players[i].connected)
2065 Assert(i < MAX_NUM_NET_PLAYERS);
2067 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));
2069 // segments_checksum = netmisc_calc_checksum( Segments, sizeof(segment)*(Highest_segment_index+1) );
2071 My_Seq.type = PID_REQUEST;
2072 My_Seq.player.connected = Current_level_num;
2074 if (Network_game_type == IPX_GAME) {
2076 ipx_send_internetwork_packet_data((ubyte *)&My_Seq, sizeof(sequence_packet), NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node);
2078 send_sequence_packet(My_Seq, NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node, NULL);
2082 appletalk_send_packet_data( (ubyte *)&My_Seq, sizeof(sequence_packet), NetPlayers.players[i].network.appletalk.node,
2083 NetPlayers.players[i].network.appletalk.net,
2084 NetPlayers.players[i].network.appletalk.socket);
2091 int SecurityCheck=0;
2093 void network_process_gameinfo(ubyte *data)
2096 netgame_info tmp_info;
2099 netgame_info *new = (netgame_info *)data;
2102 if (Network_game_type == IPX_GAME) {
2103 receive_netgame_packet(data, &tmp_info, 0); // get correctly aligned structure
2109 WaitingForPlayerInfo=0;
2111 if (new->Security !=TempPlayersInfo->Security)
2113 Int3(); // Get Jason
2114 return; // If this first half doesn't go with the second half
2117 Network_games_changed = 1;
2119 //mprintf((0, "Got game data for game %s.\n", new->game_name));
2121 Assert (TempPlayersInfo!=NULL);
2123 for (i = 0; i < num_active_games; i++)
2125 //mprintf ((0,"GAMEINFO: Game %d is %s!\n",i,Active_games[i].game_name));
2127 if (!stricmp(Active_games[i].game_name, new->game_name) &&
2128 Active_games[i].Security==new->Security)
2132 if (i == MAX_ACTIVE_NETGAMES)
2134 mprintf((0, "Too many netgames.\n"));
2138 // MWA memcpy(&Active_games[i], data, sizeof(netgame_info));
2139 memcpy(&Active_games[i], (ubyte *)new, sizeof(netgame_info));
2140 memcpy (&ActiveNetPlayers[i],TempPlayersInfo,sizeof(AllNetPlayers_info));
2143 if (Active_games[i].Security==SecurityCheck)
2146 //mprintf ((0,"Recieved %d unique games...\n",i));
2148 if (i == num_active_games)
2151 if (Active_games[i].numplayers == 0)
2153 mprintf ((0,"DELETING THIS GAME!!!\n"));
2155 for (j = i; j < num_active_games-1; j++)
2157 memcpy(&Active_games[j], &Active_games[j+1], sizeof(netgame_info));
2158 memcpy (&ActiveNetPlayers[j],&ActiveNetPlayers[j+1],sizeof(AllNetPlayers_info));
2165 void network_process_lite_info(ubyte *data)
2171 lite_info *new = (lite_info *)data;
2174 if (Network_game_type == IPX_GAME) {
2175 receive_netgame_packet(data, (netgame_info *)&tmp_info, 1);
2180 Network_games_changed = 1;
2182 //mprintf((0, "Got game data for game %s.\n", new->game_name));
2184 for (i = 0; i < num_active_games; i++)
2186 //mprintf ((0,"GAMEINFO: Game %d is %s!\n",i,Active_games[i].game_name));
2188 if ((!stricmp(Active_games[i].game_name, new->game_name)) &&
2189 Active_games[i].Security==new->Security)
2193 if (i == MAX_ACTIVE_NETGAMES)
2195 mprintf((0, "Too many netgames.\n"));
2199 memcpy(&Active_games[i], (ubyte *)new, sizeof(lite_info));
2201 // See if this is really a Hoard game
2202 // If so, adjust all the data accordingly
2204 if (HoardEquipped())
2206 if (Active_games[i].game_flags & NETGAME_FLAG_HOARD)
2208 Active_games[i].gamemode=NETGAME_HOARD;
2209 Active_games[i].game_status=NETSTAT_PLAYING;
2211 if (Active_games[i].game_flags & NETGAME_FLAG_TEAM_HOARD)
2212 Active_games[i].gamemode=NETGAME_TEAM_HOARD;
2213 if (Active_games[i].game_flags & NETGAME_FLAG_REALLY_ENDLEVEL)
2214 Active_games[i].game_status=NETSTAT_ENDLEVEL;
2215 if (Active_games[i].game_flags & NETGAME_FLAG_REALLY_FORMING)
2216 Active_games[i].game_status=NETSTAT_STARTING;
2220 //mprintf ((0,"Recieved %d unique games...\n",i));
2222 if (i == num_active_games)
2225 if (Active_games[i].numplayers == 0)
2227 mprintf ((0,"DELETING THIS GAME!!!\n"));
2229 for (j = i; j < num_active_games-1; j++)
2231 memcpy(&Active_games[j], &Active_games[j+1], sizeof(netgame_info));
2237 void network_process_dump(sequence_packet *their)
2239 // Our request for join was denied. Tell the user why.
2244 mprintf((0, "Dumped by player %s, type %d.\n", their->player.callsign, their->player.connected));
2246 if (their->player.connected!=7)
2247 nm_messagebox(NULL, 1, TXT_OK, NET_DUMP_STRINGS(their->player.connected));
2250 for (i=0;i<N_players;i++)
2251 if (!stricmp (their->player.callsign,Players[i].callsign))
2253 if (i!=network_who_is_master())
2255 HUD_init_message ("%s attempted to kick you out.",their->player.callsign);
2259 sprintf (temp,"%s has kicked you out!",their->player.callsign);
2260 nm_messagebox(NULL, 1, TXT_OK, &temp);
2261 if (Network_status==NETSTAT_PLAYING)
2267 Network_status = NETSTAT_MENU;
2272 void network_process_request(sequence_packet *their)
2274 // Player is ready to receieve a sync packet
2277 mprintf((0, "Player %s ready for sync.\n", their->player.callsign));
2279 for (i = 0; i < N_players; i++) {
2280 if (Network_game_type == IPX_GAME) {
2281 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))) {
2282 Players[i].connected = 1;
2286 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)) ) {
2287 Players[i].connected = 1;
2294 #define REFUSE_INTERVAL F1_0 * 8
2295 extern void multi_reset_object_texture (object *);
2297 void network_process_packet(ubyte *data, int length )
2300 sequence_packet tmp_packet;
2302 sequence_packet *their = (sequence_packet *)data;
2305 if (Network_game_type == IPX_GAME) {
2306 receive_sequence_packet(data, &tmp_packet);
2307 their = &tmp_packet; // reassign their to point to correctly alinged structure
2311 //mprintf( (0, "Got packet of length %d, type %d\n", length, their->type ));
2313 // if ( length < sizeof(sequence_packet) ) return;
2319 case PID_GAME_INFO: // Jason L. says we can safely ignore this type.
2322 case PID_PLAYERSINFO:
2324 mprintf ((0,"Got a PID_PLAYERSINFO!\n"));
2326 if (Network_status==NETSTAT_WAITING)
2329 memcpy (&TempPlayersBase,data,sizeof(AllNetPlayers_info));
2331 if (Network_game_type == IPX_GAME)
2332 receive_netplayers_packet(data, &TempPlayersBase);
2334 memcpy (&TempPlayersBase,data,sizeof(AllNetPlayers_info));
2337 if (TempPlayersBase.Security!=Netgame.Security)
2339 mprintf ((0,"Bad security for PLAYERSINFO\n"));
2343 mprintf ((0,"Got a waiting PID_PLAYERSINFO!\n"));
2344 if (length!=ALLNETPLAYERSINFO_SIZE)
2346 mprintf ((0,"Invalid size for netplayers packet!\n"));
2350 TempPlayersInfo=&TempPlayersBase;
2351 WaitingForPlayerInfo=0;
2352 NetSecurityNum=TempPlayersInfo->Security;
2353 NetSecurityFlag=NETSECURITY_WAIT_FOR_SYNC;
2360 if (length != LITE_INFO_SIZE)
2362 mprintf ((0,"WARNING! Recieved invalid size for PID_LITE_INFO\n"));
2366 if (Network_status == NETSTAT_BROWSING)
2367 network_process_lite_info (data);
2371 // Someone wants a list of games
2373 if (length != SEQUENCE_PACKET_SIZE)
2375 mprintf ((0,"WARNING! Recieved invalid size for PID_GAME_LIST\n"));
2379 mprintf((0, "Got a PID_GAME_LIST!\n"));
2380 if ((Network_status == NETSTAT_PLAYING) || (Network_status == NETSTAT_STARTING) || (Network_status == NETSTAT_ENDLEVEL))
2381 if (network_i_am_master())
2382 network_send_lite_info(their);
2386 case PID_SEND_ALL_GAMEINFO:
2388 if (length != SEQUENCE_PACKET_SIZE)
2390 mprintf ((0,"WARNING! Recieved invalid size for PID_SEND_ALL_GAMEINFO\n"));
2394 if ((Network_status == NETSTAT_PLAYING) || (Network_status == NETSTAT_STARTING) || (Network_status == NETSTAT_ENDLEVEL))
2395 if (network_i_am_master() && their->Security==Netgame.Security)
2396 network_send_game_info(their);
2401 mprintf( (0, "Got NEWPLAYER message from %s.\n", their->player.callsign));
2403 if (length != SEQUENCE_PACKET_SIZE)
2405 mprintf ((0,"WARNING! Recieved invalid size for PID_ADDPLAYER\n"));
2408 mprintf( (0, "Got NEWPLAYER message from %s.\n", their->player.callsign));
2409 network_new_player(their);
2412 if (length != SEQUENCE_PACKET_SIZE)
2414 mprintf ((0,"WARNING! Recieved invalid size for PID_REQUEST\n"));
2418 mprintf( (0, "Got REQUEST from '%s'\n", their->player.callsign ));
2419 if (Network_status == NETSTAT_STARTING)
2421 // Someone wants to join our game!
2422 network_add_player(their);
2424 else if (Network_status == NETSTAT_WAITING)
2426 // Someone is ready to recieve a sync packet
2427 network_process_request(their);
2429 else if (Network_status == NETSTAT_PLAYING)
2431 // Someone wants to join a game in progress!
2432 if (Netgame.RefusePlayers)
2433 DoRefuseStuff (their);
2435 network_welcome_player(their);
2440 if (length != SEQUENCE_PACKET_SIZE)
2442 mprintf ((0,"WARNING! Recieved invalid size for PID_DUMP\n"));
2446 if (Network_status == NETSTAT_WAITING || Network_status==NETSTAT_PLAYING )
2447 network_process_dump(their);
2449 case PID_QUIT_JOINING:
2451 if (length != SEQUENCE_PACKET_SIZE)
2453 mprintf ((0,"WARNING! Recieved invalid size for PID_QUIT_JOINING\n"));
2456 if (Network_status == NETSTAT_STARTING)
2457 network_remove_player( their );
2458 else if ((Network_status == NETSTAT_PLAYING) && (Network_send_objects))
2459 network_stop_resync( their );
2463 mprintf ((0,"Got a sync packet! Network_status=%d\n",NETSTAT_WAITING));
2465 if (Network_status == NETSTAT_WAITING) {
2468 memcpy((ubyte *)&(TempNetInfo), data, sizeof(netgame_info));
2470 if (Network_game_type == IPX_GAME)
2471 receive_netgame_packet(data, &TempNetInfo, 0);
2473 memcpy((ubyte *)&(TempNetInfo), data, sizeof(netgame_info));
2476 if (TempNetInfo.Security!=Netgame.Security)
2478 mprintf ((0,"Bad security on sync packet.\n"));
2482 if (NetSecurityFlag==NETSECURITY_WAIT_FOR_SYNC)
2484 if (TempNetInfo.Security==TempPlayersInfo->Security)
2486 network_read_sync_packet (&TempNetInfo,0);
2493 NetSecurityFlag=NETSECURITY_WAIT_FOR_PLAYERS;
2494 NetSecurityNum=TempNetInfo.Security;
2496 if ( network_wait_for_playerinfo())
2497 network_read_sync_packet((netgame_info *)data,0);
2506 if ((Game_mode&GM_NETWORK) && ((Network_status == NETSTAT_PLAYING)||(Network_status == NETSTAT_ENDLEVEL) || Network_status==NETSTAT_WAITING)) {
2507 network_process_pdata((char *)data);
2510 case PID_NAKED_PDATA:
2511 if ((Game_mode&GM_NETWORK) && ((Network_status == NETSTAT_PLAYING)||(Network_status == NETSTAT_ENDLEVEL) || Network_status==NETSTAT_WAITING))
2512 network_process_naked_pdata((char *)data,length);
2515 case PID_OBJECT_DATA:
2516 if (Network_status == NETSTAT_WAITING)
2517 network_read_object_packet(data);
2520 if ((Network_status == NETSTAT_ENDLEVEL) || (Network_status == NETSTAT_PLAYING))
2521 network_read_endlevel_packet(data);
2523 mprintf((0, "Junked endlevel packet.\n"));
2525 case PID_ENDLEVEL_SHORT:
2526 if ((Network_status == NETSTAT_ENDLEVEL) || (Network_status == NETSTAT_PLAYING))
2527 network_read_endlevel_short_packet(data);
2529 mprintf((0, "Junked short endlevel packet!\n"));
2532 case PID_GAME_UPDATE:
2533 mprintf ((0,"Got a GAME_UPDATE!\n"));
2535 if (Network_status==NETSTAT_PLAYING)
2538 memcpy((ubyte *)&TempNetInfo, data, sizeof(lite_info) );
2540 if (Network_game_type == IPX_GAME)
2541 receive_netgame_packet(data, &TempNetInfo, 1);
2543 memcpy((ubyte *)&TempNetInfo, data, sizeof(lite_info) );
2545 if (TempNetInfo.Security==Netgame.Security)
2546 memcpy (&Netgame,(ubyte *)&TempNetInfo,sizeof(lite_info));
2548 if (Game_mode & GM_TEAM)
2552 for (i=0;i<N_players;i++)
2553 if (Players[i].connected)
2554 multi_reset_object_texture (&Objects[Players[i].objnum]);
2559 network_ping (PID_PING_RETURN,data[1]);
2561 case PID_PING_RETURN:
2562 network_handle_ping_return(data[1]); // data[1] is player who told us of their ping time
2564 case PID_NAMES_RETURN:
2565 if (Network_status==NETSTAT_BROWSING && NamesInfoSecurity!=-1)
2566 network_process_names_return (data);
2568 case PID_GAME_PLAYERS:
2569 // Someone wants a list of players in this game
2571 if (length != SEQUENCE_PACKET_SIZE)
2573 mprintf ((0,"WARNING! Recieved invalid size for PID_GAME_PLAYERS\n"));
2577 mprintf((0, "Got a PID_GAME_PLAYERS!\n"));
2578 if ((Network_status == NETSTAT_PLAYING) || (Network_status == NETSTAT_STARTING) || (Network_status == NETSTAT_ENDLEVEL))
2579 if (network_i_am_master() && their->Security==Netgame.Security)
2580 network_send_player_names(their);
2584 mprintf((0, "Ignoring invalid packet type.\n"));
2585 Int3(); // Invalid network packet type, see ROB
2591 void dump_segments()
2595 fp = fopen( "TEST.DMP", "wb" );
2596 fwrite( Segments, sizeof(segment)*(Highest_segment_index+1),1, fp );
2598 mprintf( (0, "SS=%d\n", sizeof(segment) ));
2604 network_read_endlevel_packet( ubyte *data )
2606 // Special packet for end of level syncing
2613 end = (endlevel_info *)data;
2615 for (i = 0; i < MAX_PLAYERS; i++)
2616 for (j = 0; j < MAX_PLAYERS; j++)
2617 end->kill_matrix[i][j] = INTEL_SHORT(end->kill_matrix[i][j]);
2618 end->kills = INTEL_SHORT(end->kills);
2619 end->killed = INTEL_SHORT(end->killed);
2622 playernum = end->player_num;
2624 Assert(playernum != Player_num);
2626 if (playernum>=N_players)
2628 Int3(); // weird, but it an happen in a coop restore game
2629 return; // if it happens in a coop restore, don't worry about it
2632 if ((Network_status == NETSTAT_PLAYING) && (end->connected != 0))
2633 return; // Only accept disconnect packets if we're not out of the level yet
2635 Players[playernum].connected = end->connected;
2636 memcpy(&kill_matrix[playernum][0], end->kill_matrix, MAX_PLAYERS*sizeof(short));
2637 Players[playernum].net_kills_total = end->kills;
2638 Players[playernum].net_killed_total = end->killed;
2640 if ((Players[playernum].connected == 1) && (end->seconds_left < Countdown_seconds_left))
2641 Countdown_seconds_left = end->seconds_left;
2643 LastPacketTime[playernum] = timer_get_approx_seconds();
2645 // mprintf((0, "Got endlevel packet from player %d.\n", playernum));
2649 network_read_endlevel_short_packet( ubyte *data )
2651 // Special packet for end of level syncing
2654 endlevel_info_short *end;
2656 end = (endlevel_info_short *)data;
2658 playernum = end->player_num;
2660 Assert(playernum != Player_num);
2662 if (playernum>=N_players)
2664 Int3(); // weird, but it can happen in a coop restore game
2665 return; // if it happens in a coop restore, don't worry about it
2668 if ((Network_status == NETSTAT_PLAYING) && (end->connected != 0))
2670 //mprintf ((0,"Returning early for short_endlevel\n"));
2671 return; // Only accept disconnect packets if we're not out of the level yet
2674 Players[playernum].connected = end->connected;
2676 if ((Players[playernum].connected == 1) && (end->seconds_left < Countdown_seconds_left))
2677 Countdown_seconds_left = end->seconds_left;
2679 LastPacketTime[playernum] = timer_get_approx_seconds();
2684 network_pack_objects(void)
2686 // Switching modes, pack the object array
2688 special_reset_objects();
2692 network_verify_objects(int remote, int local)
2695 int nplayers, got_controlcen=0;
2697 mprintf ((0,"NETWORK:remote=%d local=%d\n",remote,local));
2699 if ((remote-local) > 10)
2702 if (Game_mode & GM_MULTI_ROBOTS)
2707 for (i = 0; i <= Highest_object_index; i++)
2709 if ((Objects[i].type == OBJ_PLAYER) || (Objects[i].type == OBJ_GHOST))
2711 if (Objects[i].type == OBJ_CNTRLCEN)
2715 if (got_controlcen && (MaxNumNetPlayers<=nplayers))
2722 network_read_object_packet( ubyte *data )
2724 // Object from another net player we need to sync with
2726 short objnum, remote_objnum;
2731 static int my_pnum = 0;
2732 static int mode = 0;
2733 static int object_count = 0;
2734 static int frame_num = 0;
2737 int remote_frame_num = data[2];
2741 // mprintf((0, "Object packet %d (remote #%d) contains %d objects.\n", frame_num, remote_frame_num, nobj));
2743 for (i = 0; i < nobj; i++)
2745 objnum = INTEL_SHORT( *(short *)(data+loc) ); loc += 2;
2746 obj_owner = data[loc]; loc += 1;
2747 remote_objnum = INTEL_SHORT( *(short *)(data+loc) ); loc += 2;
2751 // Clear object array
2752 mprintf((0, "Clearing object array.\n"));
2755 Network_rejoined = 1;
2756 my_pnum = obj_owner;
2757 change_playernum_to(my_pnum);
2762 else if (objnum == -2)
2764 // Special debug checksum marker for entire send
2767 network_pack_objects();
2770 mprintf((0, "Objnum -2 found in frame local %d remote %d.\n", frame_num, remote_frame_num));
2771 mprintf((0, "Got %d objects, expected %d.\n", object_count, remote_objnum));
2772 if (remote_objnum != object_count) {
2775 if (network_verify_objects(remote_objnum, object_count))
2777 // Failed to sync up
2778 nm_messagebox(NULL, 1, TXT_OK, TXT_NET_SYNC_FAILED);
2779 Network_status = NETSTAT_MENU;
2786 if (frame_num != remote_frame_num)
2788 mprintf ((0,"Got a type 3 object packet!\n"));
2790 if ((obj_owner == my_pnum) || (obj_owner == -1))
2794 objnum = remote_objnum;
2795 //if (objnum > Highest_object_index)
2797 // Highest_object_index = objnum;
2798 // num_objects = Highest_object_index+1;
2804 network_pack_objects();
2807 objnum = obj_allocate();
2810 obj = &Objects[objnum];
2811 if (obj->segnum != -1)
2813 Assert(obj->segnum == -1);
2814 Assert(objnum < MAX_OBJECTS);
2815 memcpy(obj,data+loc,sizeof(object)); loc += sizeof(object);
2817 if (Network_game_type == IPX_GAME)
2820 segnum = obj->segnum;
2821 obj->next = obj->prev = obj->segnum = -1;
2822 obj->attached_obj = -1;
2824 obj_link(obj-Objects,segnum);
2825 if (obj_owner == my_pnum)
2826 map_objnum_local_to_local(objnum);
2827 else if (obj_owner != -1)
2828 map_objnum_local_to_remote(objnum, remote_objnum, obj_owner);
2830 object_owner[objnum] = -1;
2832 } // For a standard onbject
2833 } // For each object in packet
2836 void network_sync_poll( int nitems, newmenu_item * menus, int * key, int citem )
2838 // Polling loop waiting for sync packet to start game
2848 if (Network_status != NETSTAT_WAITING) // Status changed to playing, exit the menu
2851 if (!Network_rejoined && (timer_get_approx_seconds() > t1+F1_0*2))
2855 // Poll time expired, re-send request
2857 t1 = timer_get_approx_seconds();
2859 mprintf((0, "Re-sending join request.\n"));
2860 i = network_send_request();
2866 void network_start_poll( int nitems, newmenu_item * menus, int * key, int citem )
2873 Assert(Network_status == NETSTAT_STARTING);
2875 if (!menus[0].value) {
2877 menus[0].redraw = 1;
2880 for (i=1; i<nitems; i++ ) {
2881 if ( (i>= N_players) && (menus[i].value) ) {
2883 menus[i].redraw = 1;
2888 for (i=0; i<nitems; i++ ) {
2889 if ( menus[i].value ) {
2891 if ( nm > N_players ) {
2893 menus[i].redraw = 1;
2898 if ( nm > MaxNumNetPlayers ) {
2899 nm_messagebox( TXT_ERROR, 1, TXT_OK, "%s %d %s", TXT_SORRY_ONLY, MaxNumNetPlayers, TXT_NETPLAYERS_IN );
2900 // Turn off the last player highlighted
2901 for (i = N_players; i > 0; i--)
2902 if (menus[i].value == 1)
2905 menus[i].redraw = 1;
2910 // if (nitems > MAX_PLAYERS ) return;
2912 n = Netgame.numplayers;
2915 if (n < Netgame.numplayers )
2917 digi_play_sample (SOUND_HUD_MESSAGE,F1_0);
2919 mprintf ((0,"More players are printed!"));
2920 if (args_find("-norankings"))
2921 sprintf( menus[N_players-1].text, "%d. %-20s", N_players,NetPlayers.players[N_players-1].callsign );
2923 sprintf( menus[N_players-1].text, "%d. %s%-20s", N_players, RankStrings[NetPlayers.players[N_players-1].rank],NetPlayers.players[N_players-1].callsign );
2925 menus[N_players-1].redraw = 1;
2926 if (N_players <= MaxNumNetPlayers)
2928 menus[N_players-1].value = 1;
2931 else if ( n > Netgame.numplayers )
2933 // One got removed...
2935 digi_play_sample (SOUND_HUD_KILL,F1_0);
2937 for (i=0; i<N_players; i++ )
2940 if (args_find("-norankings"))
2941 sprintf( menus[i].text, "%d. %-20s", i+1, NetPlayers.players[i].callsign );
2943 sprintf( menus[i].text, "%d. %s%-20s", i+1, RankStrings[NetPlayers.players[i].rank],NetPlayers.players[i].callsign );
2944 if (i < MaxNumNetPlayers)
2948 menus[i].redraw = 1;
2950 for (i=N_players; i<n; i++ )
2952 sprintf( menus[i].text, "%d. ", i+1 ); // Clear out the deleted entries...
2954 menus[i].redraw = 1;
2959 int opt_cinvul, opt_team_anarchy, opt_coop, opt_show_on_map, opt_closed,opt_maxnet;
2960 int last_cinvul=0,last_maxnet,opt_team_hoard;
2961 int opt_refuse,opt_capture;
2963 void network_game_param_poll( int nitems, newmenu_item * menus, int * key, int citem )
2965 static int oldmaxnet=0;
2967 if (((HoardEquipped() && menus[opt_team_hoard].value) || (menus[opt_team_anarchy].value || menus[opt_capture].value)) && !menus[opt_closed].value && !menus[opt_refuse].value) {
2968 menus[opt_refuse].value = 1;
2969 menus[opt_refuse].redraw = 1;
2970 menus[opt_refuse-1].value = 0;
2971 menus[opt_refuse-1].redraw = 1;
2972 menus[opt_refuse-2].value = 0;
2973 menus[opt_refuse-2].redraw = 1;
2977 if (menus[opt_coop].value)
2979 if ( (menus[opt_coop].value) || ((Network_game_type == APPLETALK_GAME) && (Network_appletalk_type == LOCALTALK_TYPE) && (menus[opt_coop-1].value)) )
2984 if (menus[opt_maxnet].value>2)
2986 menus[opt_maxnet].value=2;
2987 menus[opt_maxnet].redraw=1;
2990 if (menus[opt_maxnet].max_value>2)
2992 menus[opt_maxnet].max_value=2;
2993 menus[opt_maxnet].redraw=1;
2997 if ( (Network_game_type == APPLETALK_GAME) && (Network_appletalk_type == LOCALTALK_TYPE) ) {
2998 if (menus[opt_maxnet].value > 0) {
2999 menus[opt_maxnet].value=0;
3000 menus[opt_maxnet].redraw=1;
3002 if (menus[opt_maxnet].max_value > 0) {
3003 menus[opt_maxnet].max_value=0;
3004 menus[opt_maxnet].redraw=1;
3009 if (!Netgame.game_flags & NETGAME_FLAG_SHOW_MAP)
3010 Netgame.game_flags |= NETGAME_FLAG_SHOW_MAP;
3012 if (Netgame.PlayTimeAllowed || Netgame.KillGoal)
3014 Netgame.PlayTimeAllowed=0;
3019 else // if !Coop game
3024 menus[opt_maxnet].value=6;
3025 menus[opt_maxnet].max_value=6;
3028 if ( (Network_game_type == APPLETALK_GAME) && (Network_appletalk_type == LOCALTALK_TYPE) ) {
3029 menus[opt_maxnet].value=1;
3030 menus[opt_maxnet].max_value=1;
3037 if ( last_maxnet != menus[opt_maxnet].value )
3039 sprintf( menus[opt_maxnet].text, "Maximum players: %d", menus[opt_maxnet].value+2 );
3040 last_maxnet = menus[opt_maxnet].value;
3041 menus[opt_maxnet].redraw = 1;
3045 int netgame_difficulty;
3047 int network_get_game_params( char * game_name, int *mode, int *game_flags, int *level )
3050 int opt, opt_name, opt_level, opt_mode,opt_moreopts;
3052 char name[NETGAME_NAME_LEN+1];
3054 char level_text[32];
3057 int new_mission_num;
3060 *game_flags=*game_flags;
3062 SetAllAllowablesTo (1);
3063 NamesInfoSecurity=-1;
3065 for (i=0;i<MAX_PLAYERS;i++)
3067 Players[i].callsign[0]=0;
3071 Netgame.PlayTimeAllowed=0;
3072 Netgame.Allow_marker_view=1;
3073 netgame_difficulty=Player_default_difficulty;
3075 new_mission_num = multi_choose_mission(&anarchy_only);
3077 if (new_mission_num < 0)
3080 if (!(args_find ("-packets") && args_find ("-shortpackets")))
3081 if (!network_choose_connect ())
3085 if ( (Network_game_type == APPLETALK_GAME) && (Network_appletalk_type == LOCALTALK_TYPE) )
3086 MaxNumNetPlayers = 3;
3089 strcpy(Netgame.mission_name, Mission_list[new_mission_num].filename);
3090 strcpy(Netgame.mission_title, Mission_list[new_mission_num].mission_name);
3091 Netgame.control_invul_time = control_invul_time;
3093 sprintf( name, "%s%s", Players[Player_num].callsign, TXT_S_GAME );
3094 sprintf( slevel, "1" );
3097 m[opt].type = NM_TYPE_TEXT; m[opt].text = TXT_DESCRIPTION; opt++;
3100 m[opt].type = NM_TYPE_INPUT; m[opt].text = name; m[opt].text_len = NETGAME_NAME_LEN; opt++;
3102 sprintf(level_text, "%s (1-%d)", TXT_LEVEL_, Last_level);
3104 // if (Last_secret_level < -1)
3105 // sprintf(level_text+strlen(level_text)-1, ", S1-S%d)", -Last_secret_level);
3106 // else if (Last_secret_level == -1)
3107 // sprintf(level_text+strlen(level_text)-1, ", S1)");
3109 Assert(strlen(level_text) < 32);
3111 m[opt].type = NM_TYPE_TEXT; m[opt].text = level_text; opt++;
3114 m[opt].type = NM_TYPE_INPUT; m[opt].text = slevel; m[opt].text_len=4; opt++;
3115 // m[opt].type = NM_TYPE_TEXT; m[opt].text = TXT_OPTIONS; opt++;
3118 m[opt].type = NM_TYPE_RADIO; m[opt].text = TXT_ANARCHY; m[opt].value=1; m[opt].group=0; opt++;
3119 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++;
3120 m[opt].type = NM_TYPE_RADIO; m[opt].text = TXT_ANARCHY_W_ROBOTS; m[opt].value=0; m[opt].group=0; opt++;
3121 m[opt].type = NM_TYPE_RADIO; m[opt].text = TXT_COOPERATIVE; m[opt].value=0; m[opt].group=0; opt_coop=opt; opt++;
3122 m[opt].type = NM_TYPE_RADIO; m[opt].text = "Capture the flag"; m[opt].value=0; m[opt].group=0; opt_capture=opt; opt++;
3124 if (HoardEquipped())
3126 m[opt].type = NM_TYPE_RADIO; m[opt].text = "Hoard"; m[opt].value=0; m[opt].group=0; opt++;
3127 m[opt].type = NM_TYPE_RADIO; m[opt].text = "Team Hoard"; m[opt].value=0; m[opt].group=0; opt_team_hoard=opt; opt++;
3128 m[opt].type = NM_TYPE_TEXT; m[opt].text = ""; opt++;
3131 { m[opt].type = NM_TYPE_TEXT; m[opt].text = ""; opt++; }
3133 m[opt].type = NM_TYPE_RADIO; m[opt].text = "Open game"; m[opt].group=1; m[opt].value=0; opt++;
3135 m[opt].type = NM_TYPE_RADIO; m[opt].text = TXT_CLOSED_GAME; m[opt].group=1; m[opt].value=0; opt++;
3137 m[opt].type = NM_TYPE_RADIO; m[opt].text = "Restricted Game "; m[opt].group=1; m[opt].value=Netgame.RefusePlayers; opt++;
3139 // m[opt].type = NM_TYPE_CHECK; m[opt].text = TXT_SHOW_IDS; m[opt].value=0; opt++;
3142 sprintf( srmaxnet, "Maximum players: %d", MaxNumNetPlayers);
3143 m[opt].type = NM_TYPE_SLIDER; m[opt].value=MaxNumNetPlayers-2; m[opt].text= srmaxnet; m[opt].min_value=0;
3144 m[opt].max_value=MaxNumNetPlayers-2; opt++;
3145 last_maxnet=MaxNumNetPlayers-2;
3148 m[opt].type = NM_TYPE_MENU; m[opt].text = "More options..."; opt++;
3153 ExtGameStatus=GAMESTAT_NETGAME_OPTIONS;
3154 i = newmenu_do1( NULL, NULL, opt, m, network_game_param_poll, 1 );
3156 if (i==opt_moreopts)
3158 if ( m[opt_mode+3].value )
3159 Game_mode=GM_MULTI_COOP;
3160 network_more_game_options();
3164 Netgame.RefusePlayers=m[opt_refuse].value;
3170 MaxNumNetPlayers = m[opt_maxnet].value+2;
3171 Netgame.max_numplayers=MaxNumNetPlayers;
3173 for (j = 0; j < num_active_games; j++)
3174 if (!stricmp(Active_games[j].game_name, name))
3176 nm_messagebox(TXT_ERROR, 1, TXT_OK, TXT_DUPLICATE_NAME);
3180 strcpy( game_name, name );
3183 *level = atoi(slevel);
3185 if ((*level < 1) || (*level > Last_level))
3187 nm_messagebox(TXT_ERROR, 1, TXT_OK, TXT_LEVEL_OUT_RANGE );
3188 sprintf(slevel, "1");
3191 if ( m[opt_mode].value )
3192 *mode = NETGAME_ANARCHY;
3197 nm_messagebox(TXT_SORRY, 1, TXT_OK, TXT_REGISTERED_ONLY );
3198 m[opt_mode+1].value = 0;
3199 m[opt_mode+2].value = 0;
3200 m[opt_mode+3].value = 0;
3201 if (HoardEquipped())
3202 m[opt_mode+4].value = 0;
3204 m[opt_mode].value = 1;
3208 else if (m[opt_mode+1].value) {
3209 *mode = NETGAME_TEAM_ANARCHY;
3211 else if (m[opt_capture].value)
3212 *mode = NETGAME_CAPTURE_FLAG;
3213 else if (HoardEquipped() && m[opt_capture+1].value)
3214 *mode = NETGAME_HOARD;
3215 else if (HoardEquipped() && m[opt_capture+2].value)
3216 *mode = NETGAME_TEAM_HOARD;
3217 else if (anarchy_only) {
3218 nm_messagebox(NULL, 1, TXT_OK, TXT_ANARCHY_ONLY_MISSION);
3219 m[opt_mode+2].value = 0;
3220 m[opt_mode+3].value = 0;
3221 m[opt_mode].value = 1;
3224 else if ( m[opt_mode+2].value )
3225 *mode = NETGAME_ROBOT_ANARCHY;
3226 else if ( m[opt_mode+3].value )
3227 *mode = NETGAME_COOPERATIVE;
3228 else Int3(); // Invalid mode -- see Rob
3230 if (m[opt_closed].value)
3231 Netgame.game_flags |= NETGAME_FLAG_CLOSED;
3239 network_set_game_mode(int gamemode)
3243 if ( gamemode == NETGAME_ANARCHY )
3244 Game_mode = GM_NETWORK;
3245 else if ( gamemode == NETGAME_ROBOT_ANARCHY )
3246 Game_mode = GM_NETWORK | GM_MULTI_ROBOTS;
3247 else if ( gamemode == NETGAME_COOPERATIVE )
3248 Game_mode = GM_NETWORK | GM_MULTI_COOP | GM_MULTI_ROBOTS;
3249 else if (gamemode == NETGAME_CAPTURE_FLAG)
3251 Game_mode = GM_NETWORK | GM_TEAM | GM_CAPTURE;
3255 else if (HoardEquipped() && gamemode == NETGAME_HOARD)
3256 Game_mode = GM_NETWORK | GM_HOARD;
3257 else if (HoardEquipped() && gamemode == NETGAME_TEAM_HOARD)
3259 Game_mode = GM_NETWORK | GM_HOARD | GM_TEAM;
3262 else if ( gamemode == NETGAME_TEAM_ANARCHY )
3264 Game_mode = GM_NETWORK | GM_TEAM;
3271 #ifdef MACINTOSH // minimize players on localtalk games
3272 if ( (Network_game_type == APPLETALK_GAME) && (Network_appletalk_type == LOCALTALK_TYPE) ) {
3273 if (Game_mode & GM_MULTI_ROBOTS)
3274 MaxNumNetPlayers = 2;
3276 MaxNumNetPlayers = 3;
3278 if (Game_mode & GM_MULTI_COOP)
3279 MaxNumNetPlayers = 4;
3281 MaxNumNetPlayers = 8;
3289 network_find_game(void)
3291 // Find out whether or not there is space left on this socket
3295 Network_status = NETSTAT_BROWSING;
3297 num_active_games = 0;
3299 show_boxed_message(TXT_WAIT);
3301 network_send_game_list_request();
3302 t1 = timer_get_approx_seconds() + F1_0*3;
3304 while (timer_get_approx_seconds() < t1) // Wait 3 seconds for replies
3307 clear_boxed_message();
3309 // mprintf((0, "%s %d %s\n", TXT_FOUND, num_active_games, TXT_ACTIVE_GAMES));
3311 if (num_active_games < MAX_ACTIVE_NETGAMES)
3316 void network_read_sync_packet( netgame_info * sp, int rsinit)
3319 netgame_info tmp_info;
3323 char temp_callsign[CALLSIGN_LEN+1];
3326 if ( (Network_game_type == IPX_GAME) && (sp != &Netgame) ) { // for macintosh -- get the values unpacked to our structure format
3327 receive_netgame_packet((ubyte *)sp, &tmp_info, 0);
3333 TempPlayersInfo=&NetPlayers;
3335 // This function is now called by all people entering the netgame.
3337 // mprintf( (0, "%s %d\n", TXT_STARTING_NETGAME, sp->levelnum ));
3341 memcpy( &Netgame, sp, sizeof(netgame_info) );
3342 memcpy (&NetPlayers,TempPlayersInfo,sizeof (AllNetPlayers_info));
3345 N_players = sp->numplayers;
3346 Difficulty_level = sp->difficulty;
3347 Network_status = sp->game_status;
3349 //Assert(Function_mode != FMODE_GAME);
3353 mprintf((1, "Netgame.checksum = %d, calculated checksum = %d.\n", Netgame.segments_checksum, my_segments_checksum));
3355 if (Netgame.segments_checksum != my_segments_checksum)
3357 Network_status = NETSTAT_MENU;
3358 nm_messagebox(TXT_ERROR, 1, TXT_OK, TXT_NETLEVEL_NMATCH);
3364 // Discover my player number
3366 memcpy(temp_callsign, Players[Player_num].callsign, CALLSIGN_LEN+1);
3370 for (i=0; i<MAX_NUM_NET_PLAYERS; i++ ) {
3371 Players[i].net_kills_total = 0;
3372 // Players[i].net_killed_total = 0;
3375 for (i=0; i<N_players; i++ ) {
3376 if (Network_game_type == IPX_GAME) {
3377 if ( (!memcmp( TempPlayersInfo->players[i].network.ipx.node, My_Seq.player.network.ipx.node, 6 )) && (!stricmp( TempPlayersInfo->players[i].callsign, temp_callsign)) ) {
3378 if (Player_num!=-1) {
3379 Int3(); // Hey, we've found ourselves twice
3380 mprintf ((0,"Hey, we've found ourselves twice!\n"));
3381 Network_status = NETSTAT_MENU;
3384 change_playernum_to(i);
3387 if ( (TempPlayersInfo->players[i].network.appletalk.node == My_Seq.player.network.appletalk.node) && (!stricmp( TempPlayersInfo->players[i].callsign, temp_callsign)) ) {
3388 if (Player_num!=-1) {
3389 Int3(); // Hey, we've found ourselves twice
3390 Network_status = NETSTAT_MENU;
3393 change_playernum_to(i);
3396 memcpy( Players[i].callsign, TempPlayersInfo->players[i].callsign, CALLSIGN_LEN+1 );
3398 if (Network_game_type == IPX_GAME) {
3399 if ( (*(uint *)TempPlayersInfo->players[i].network.ipx.server) != 0 )
3400 ipx_get_local_target( TempPlayersInfo->players[i].network.ipx.server, TempPlayersInfo->players[i].network.ipx.node, Players[i].net_address );
3402 memcpy( Players[i].net_address, TempPlayersInfo->players[i].network.ipx.node, 6 );
3405 Players[i].n_packets_got=0; // How many packets we got from them
3406 Players[i].n_packets_sent=0; // How many packets we sent to them
3407 Players[i].connected = TempPlayersInfo->players[i].connected;
3408 Players[i].net_kills_total = sp->player_kills[i];
3409 Players[i].net_killed_total = sp->killed[i];
3410 if ((Network_rejoined) || (i != Player_num))
3411 Players[i].score = sp->player_score[i];
3412 for (j = 0; j < MAX_NUM_NET_PLAYERS; j++)
3414 kill_matrix[i][j] = sp->kills[i][j];
3418 if ( Player_num < 0 ) {
3419 mprintf ((0,"Bad Player_num, resetting to NETSTAT_MENU!\n"));
3420 Network_status = NETSTAT_MENU;
3424 if (Network_rejoined)
3425 for (i=0; i<N_players;i++)
3426 Players[i].net_killed_total = sp->killed[i];
3428 if (Network_rejoined) {
3429 network_process_monitor_vector(sp->monitor_vector);
3430 Players[Player_num].time_level = sp->level_time;
3433 team_kills[0] = sp->team_kills[0];
3434 team_kills[1] = sp->team_kills[1];
3436 Players[Player_num].connected = 1;
3437 NetPlayers.players[Player_num].connected = 1;
3438 NetPlayers.players[Player_num].rank=GetMyNetRanking();
3440 if (!Network_rejoined)
3441 for (i=0; i<NumNetPlayerPositions; i++) {
3442 Objects[Players[i].objnum].pos = Player_init[Netgame.locations[i]].pos;
3443 Objects[Players[i].objnum].orient = Player_init[Netgame.locations[i]].orient;
3444 obj_relink(Players[i].objnum,Player_init[Netgame.locations[i]].segnum);
3447 Objects[Players[Player_num].objnum].type = OBJ_PLAYER;
3449 mprintf ((0,"Changing to NETSTAT_PLAYING!\n"));
3450 Network_status = NETSTAT_PLAYING;
3451 Function_mode = FMODE_GAME;
3452 multi_sort_kill_list();
3457 network_send_sync(void)
3461 // Randomize their starting locations...
3463 d_srand( timer_get_fixed_seconds() );
3464 for (i=0; i<NumNetPlayerPositions; i++ )
3466 if (Players[i].connected)
3467 Players[i].connected = 1; // Get rid of endlevel connect statuses
3468 if (Game_mode & GM_MULTI_COOP)
3469 Netgame.locations[i] = i;
3473 np = d_rand() % NumNetPlayerPositions;
3474 for (j=0; j<i; j++ )
3476 if (Netgame.locations[j]==np)
3483 // np is a location that is not used anywhere else..
3484 Netgame.locations[i]=np;
3485 // mprintf((0, "Player %d starting in location %d\n" ,i ,np ));
3489 // Push current data into the sync packet
3491 network_update_netgame();
3492 Netgame.game_status = NETSTAT_PLAYING;
3493 Netgame.type = PID_SYNC;
3494 Netgame.segments_checksum = my_segments_checksum;
3496 for (i=0; i<N_players; i++ ) {
3497 if ((!Players[i].connected) || (i == Player_num))
3500 if (Network_game_type == IPX_GAME) {
3501 // Send several times, extras will be ignored
3503 ipx_send_internetwork_packet_data( (ubyte *)&Netgame, sizeof(netgame_info), NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node);
3504 ipx_send_internetwork_packet_data( (ubyte *)&NetPlayers, sizeof(AllNetPlayers_info), NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node);
3506 send_netgame_packet(NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node, NULL, 0);
3507 send_netplayers_packet(NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node);
3511 appletalk_send_packet_data( (ubyte *)&Netgame, sizeof(netgame_info), NetPlayers.players[i].network.appletalk.node,
3512 NetPlayers.players[i].network.appletalk.net,
3513 NetPlayers.players[i].network.appletalk.socket);
3514 appletalk_send_packet_data( (ubyte *)&NetPlayers, sizeof(AllNetPlayers_info), NetPlayers.players[i].network.appletalk.node,
3515 NetPlayers.players[i].network.appletalk.net,
3516 NetPlayers.players[i].network.appletalk.socket);
3521 network_read_sync_packet(&Netgame,1); // Read it myself, as if I had sent it
3525 network_select_teams(void)
3528 newmenu_item m[MAX_PLAYERS+4];
3529 int choice, opt, opt_team_b;
3530 ubyte team_vector = 0;
3531 char team_names[2][CALLSIGN_LEN+1];
3533 int pnums[MAX_PLAYERS+2];
3535 // One-time initialization
3537 for (i = N_players/2; i < N_players; i++) // Put first half of players on team A
3539 team_vector |= (1 << i);
3542 sprintf(team_names[0], "%s", TXT_BLUE);
3543 sprintf(team_names[1], "%s", TXT_RED);
3545 // Here comes da menu
3547 m[0].type = NM_TYPE_INPUT; m[0].text = team_names[0]; m[0].text_len = CALLSIGN_LEN;
3550 for (i = 0; i < N_players; i++)
3552 if (!(team_vector & (1 << i)))
3554 m[opt].type = NM_TYPE_MENU; m[opt].text = NetPlayers.players[i].callsign; pnums[opt] = i; opt++;
3558 m[opt].type = NM_TYPE_INPUT; m[opt].text = team_names[1]; m[opt].text_len = CALLSIGN_LEN; opt++;
3559 for (i = 0; i < N_players; i++)
3561 if (team_vector & (1 << i))
3563 m[opt].type = NM_TYPE_MENU; m[opt].text = NetPlayers.players[i].callsign; pnums[opt] = i; opt++;
3566 m[opt].type = NM_TYPE_TEXT; m[opt].text = ""; opt++;
3567 m[opt].type = NM_TYPE_MENU; m[opt].text = TXT_ACCEPT; opt++;
3569 Assert(opt <= MAX_PLAYERS+4);
3571 choice = newmenu_do(NULL, TXT_TEAM_SELECTION, opt, m, NULL);
3573 if (choice == opt-1)
3575 if ((opt-2-opt_team_b < 2) || (opt_team_b == 1))
3577 nm_messagebox(NULL, 1, TXT_OK, TXT_TEAM_MUST_ONE);
3583 Netgame.team_vector = team_vector;
3584 strcpy(Netgame.team_name[0], team_names[0]);
3585 strcpy(Netgame.team_name[1], team_names[1]);
3589 else if ((choice > 0) && (choice < opt_team_b)) {
3590 team_vector |= (1 << pnums[choice]);
3592 else if ((choice > opt_team_b) && (choice < opt-2)) {
3593 team_vector &= ~(1 << pnums[choice]);
3595 else if (choice == -1)
3604 network_select_players(void)
3607 newmenu_item m[MAX_PLAYERS+4];
3608 char text[MAX_PLAYERS+4][45];
3610 int save_nplayers; //how may people would like to join
3612 network_add_player( &My_Seq );
3614 for (i=0; i< MAX_PLAYERS+4; i++ ) {
3615 sprintf( text[i], "%d. %-20s", i+1, "" );
3616 m[i].type = NM_TYPE_CHECK; m[i].text = text[i]; m[i].value = 0;
3619 m[0].value = 1; // Assume server will play...
3621 if (args_find("-norankings"))
3622 sprintf( text[0], "%d. %-20s", 1, Players[Player_num].callsign );
3624 sprintf( text[0], "%d. %s%-20s", 1, RankStrings[NetPlayers.players[Player_num].rank],Players[Player_num].callsign );
3626 sprintf( title, "%s %d %s", TXT_TEAM_SELECT, MaxNumNetPlayers, TXT_TEAM_PRESS_ENTER );
3629 ExtGameStatus=GAMESTAT_NETGAME_PLAYER_SELECT;
3630 j=newmenu_do1( NULL, title, MAX_PLAYERS+4, m, network_start_poll, 1 );
3632 save_nplayers = N_players;
3637 // Dump all players and go back to menu mode
3640 for (i=1; i<save_nplayers; i++) {
3641 if (Network_game_type == IPX_GAME)
3642 network_dump_player(NetPlayers.players[i].network.ipx.server,NetPlayers.players[i].network.ipx.node, DUMP_ABORTED);
3645 network_dump_appletalk_player(NetPlayers.players[i].network.appletalk.node,NetPlayers.players[i].network.appletalk.net, NetPlayers.players[i].network.appletalk.socket, DUMP_ABORTED);
3650 Netgame.numplayers = 0;
3651 network_send_game_info(0); // Tell everyone we're bailing
3653 Network_status = NETSTAT_MENU;
3657 // Count number of players chosen
3660 for (i=0; i<save_nplayers; i++ )
3666 if ( N_players > Netgame.max_numplayers) {
3668 nm_messagebox( TXT_ERROR, 1, TXT_OK, "%s %d %s", TXT_SORRY_ONLY, MaxNumNetPlayers, TXT_NETPLAYERS_IN );
3670 nm_messagebox( TXT_ERROR, 1, TXT_OK, "%s %d netplayers for this game.", TXT_SORRY_ONLY, MaxNumNetPlayers );
3672 N_players = save_nplayers;
3673 goto GetPlayersAgain;
3677 if ( N_players < 2 ) {
3678 nm_messagebox( TXT_ERROR, 1, TXT_OK, TXT_TEAM_ATLEAST_TWO );
3679 N_players = save_nplayers;
3680 goto GetPlayersAgain;
3685 if ( (Netgame.gamemode == NETGAME_TEAM_ANARCHY ||
3686 Netgame.gamemode == NETGAME_CAPTURE_FLAG || Netgame.gamemode == NETGAME_TEAM_HOARD) && (N_players < 2) ) {
3687 nm_messagebox(TXT_ERROR, 1, TXT_OK, "You must select at least two\nplayers to start a team game" );
3688 N_players = save_nplayers;
3689 goto GetPlayersAgain;
3693 // Remove players that aren't marked.
3695 for (i=0; i<save_nplayers; i++ ) {
3700 if (Network_game_type == IPX_GAME) {
3701 memcpy(NetPlayers.players[N_players].network.ipx.node, NetPlayers.players[i].network.ipx.node, 6);
3702 memcpy(NetPlayers.players[N_players].network.ipx.server, NetPlayers.players[i].network.ipx.server, 4);
3704 NetPlayers.players[N_players].network.appletalk.node = NetPlayers.players[i].network.appletalk.node;
3705 NetPlayers.players[N_players].network.appletalk.net = NetPlayers.players[i].network.appletalk.net;
3706 NetPlayers.players[N_players].network.appletalk.socket = NetPlayers.players[i].network.appletalk.socket;
3708 memcpy(NetPlayers.players[N_players].callsign, NetPlayers.players[i].callsign, CALLSIGN_LEN+1);
3709 NetPlayers.players[N_players].version_major=NetPlayers.players[i].version_major;
3710 NetPlayers.players[N_players].version_minor=NetPlayers.players[i].version_minor;
3711 NetPlayers.players[N_players].rank=NetPlayers.players[i].rank;
3712 ClipRank (&NetPlayers.players[N_players].rank);
3713 network_check_for_old_version(i);
3715 Players[N_players].connected = 1;
3720 if (Network_game_type == IPX_GAME)
3721 network_dump_player(NetPlayers.players[i].network.ipx.server,NetPlayers.players[i].network.ipx.node, DUMP_DORK);
3724 network_dump_appletalk_player(NetPlayers.players[i].network.appletalk.node,NetPlayers.players[i].network.appletalk.net, NetPlayers.players[i].network.appletalk.socket, DUMP_DORK);
3729 for (i = N_players; i < MAX_NUM_NET_PLAYERS; i++) {
3730 if (Network_game_type == IPX_GAME) {
3731 memset(NetPlayers.players[i].network.ipx.node, 0, 6);
3732 memset(NetPlayers.players[i].network.ipx.server, 0, 4);
3734 NetPlayers.players[i].network.appletalk.node = 0;
3735 NetPlayers.players[i].network.appletalk.net = 0;
3736 NetPlayers.players[i].network.appletalk.socket = 0;
3738 memset(NetPlayers.players[i].callsign, 0, CALLSIGN_LEN+1);
3739 NetPlayers.players[i].version_major=0;
3740 NetPlayers.players[i].version_minor=0;
3741 NetPlayers.players[i].rank=0;
3744 mprintf ((0,"Select teams: Game mode is %d\n",Netgame.gamemode));
3746 if (Netgame.gamemode == NETGAME_TEAM_ANARCHY ||
3747 Netgame.gamemode == NETGAME_CAPTURE_FLAG ||
3748 Netgame.gamemode == NETGAME_TEAM_HOARD)
3749 if (!network_select_teams())
3756 network_start_game()
3759 char game_name[NETGAME_NAME_LEN+1];
3760 int chosen_game_mode, game_flags, level;
3762 if (Network_game_type == IPX_GAME) {
3764 Assert( FRAME_INFO_SIZE < IPX_MAX_DATA_SIZE );
3765 mprintf((0, "Using frame_info len %d, max %d.\n", FRAME_INFO_SIZE, IPX_MAX_DATA_SIZE));
3767 if ( !Network_active )
3769 nm_messagebox(NULL, 1, TXT_OK, TXT_IPX_NOT_FOUND );
3777 Assert( FRAME_INFO_SIZE < APPLETALK_MAX_DATA_SIZE );
3778 mprintf((0, "Using frame_info len %d, max %d.\n", sizeof(frame_info), APPLETALK_MAX_DATA_SIZE));
3779 if (Appletalk_active <= 0) {
3780 switch (Appletalk_active) {
3781 case APPLETALK_NOT_OPEN:
3782 sprintf(buf, "Appletalk is not currently active.\nPlease enable AppleTalk from the\nChooser and restart Descent.");
3784 case APPLETALK_BAD_LISTENER:
3785 sprintf(buf, "The Resource Fork of Descent appears damaged.\nPlease re-install Descent or contact\nMacPlay technical support.");
3787 case APPLETALK_NO_LOCAL_ADDR:
3788 sprintf(buf, "Wow! Strange!\n\nNo Local Address.");
3790 case APPLETALK_NO_SOCKET:
3791 sprintf(buf, "All AppleTalk sockets are in use.\nTry shutting down other network\napplications and restarting Descent.\n");
3794 nm_messagebox(NULL, 1, TXT_OK, buf);
3797 strcpy(Network_zone_name, DEFAULT_ZONE_NAME);
3802 change_playernum_to(0);
3804 if (network_find_game())
3806 nm_messagebox(NULL, 1, TXT_OK, TXT_NET_FULL);
3811 i = network_get_game_params( game_name, &chosen_game_mode, &game_flags, &level );
3817 // LoadLevel(level); Old, no longer used.
3819 Netgame.difficulty = Difficulty_level;
3820 Netgame.gamemode = chosen_game_mode;
3821 Netgame.game_status = NETSTAT_STARTING;
3822 Netgame.numplayers = 0;
3823 Netgame.max_numplayers = MaxNumNetPlayers;
3824 Netgame.levelnum = level;
3825 Netgame.protocol_version = MULTI_PROTO_VERSION;
3827 strcpy(Netgame.game_name, game_name);
3829 Network_status = NETSTAT_STARTING;
3832 if (Network_game_type == APPLETALK_GAME) {
3837 show_boxed_message("Registering Netgame");
3839 err = appletalk_register_netgame( game_name, TickCount() );
3840 t1 = timer_get_fixed_seconds() + F1_0;
3841 while (timer_get_fixed_seconds() < t1) ;
3843 } while ( (err == nbpDuplicate) && (count != MAX_REGISTER_TRIES) );
3844 clear_boxed_message();
3845 if ( (err == tooManyReqs) || (count == MAX_REGISTER_TRIES) ) {
3846 nm_messagebox(NULL, 1, TXT_OK, "AppleTalk Network is too busy.\nPlease try again shortly.");
3847 Game_mode = GM_GAME_OVER;
3853 network_set_game_mode(Netgame.gamemode);
3855 d_srand( timer_get_fixed_seconds() );
3856 Netgame.Security=d_rand(); // For syncing Netgames with player packets
3858 if(network_select_players())
3860 StartNewLevel(Netgame.levelnum, 0);
3863 Game_mode = GM_GAME_OVER;
3867 void restart_net_searching(newmenu_item * m)
3871 num_active_games = 0;
3873 memset(Active_games, 0, sizeof(netgame_info)*MAX_ACTIVE_NETGAMES);
3875 for (i = 0; i < MAX_ACTIVE_NETGAMES; i++)
3877 sprintf(m[i+2].text, "%d. ",i+1);
3881 NamesInfoSecurity=-1;
3882 Network_games_changed = 1;
3885 char *ModeLetters[]={"ANRCHY","TEAM","ROBO","COOP","FLAG","HOARD","TMHOARD"};
3887 int NumActiveNetgames=0;
3889 void network_join_poll( int nitems, newmenu_item * menus, int * key, int citem )
3891 // Polling loop for Join Game menu
3893 int i, osocket,join_status,temp;
3900 if ( (Network_game_type == IPX_GAME) && Network_allow_socket_changes ) {
3901 osocket = Network_socket;
3903 if ( *key==KEY_PAGEDOWN ) { Network_socket--; *key = 0; }
3904 if ( *key==KEY_PAGEUP ) { Network_socket++; *key = 0; }
3906 if (Network_socket>99)
3908 if (Network_socket<-99)
3911 if ( Network_socket+IPX_DEFAULT_SOCKET > 0x8000 )
3912 Network_socket = 0x8000 - IPX_DEFAULT_SOCKET;
3914 if ( Network_socket+IPX_DEFAULT_SOCKET < 0 )
3915 Network_socket = IPX_DEFAULT_SOCKET;
3917 if (Network_socket != osocket ) {
3918 sprintf( menus[0].text, "\t%s %+d (PgUp/PgDn to change)", TXT_CURRENT_IPX_SOCKET, Network_socket );
3919 menus[0].redraw = 1;
3920 mprintf(( 0, "Changing to socket %d\n", Network_socket ));
3922 mprintf ((0,"netgood 1!\n"));
3923 ipx_change_default_socket( IPX_DEFAULT_SOCKET + Network_socket );
3924 mprintf ((0,"netgood 2!\n"));
3925 restart_net_searching(menus);
3926 mprintf ((0,"netgood 3!\n"));
3927 network_send_game_list_request();
3928 mprintf ((0,"netgood 4!\n"));
3933 // send a request for game info every 3 seconds
3935 if (Network_game_type == IPX_GAME) {
3936 if (timer_get_approx_seconds() > t1+F1_0*3) {
3937 t1 = timer_get_approx_seconds();
3938 network_send_game_list_request();
3941 } else if (timer_get_approx_seconds() > t1+F1_0*20) {
3943 t1 = timer_get_approx_seconds();
3944 restart_net_searching(menus);
3945 show_boxed_message("Requesting list of Netgames");
3946 network_send_game_list_request();
3947 clear_boxed_message();
3952 temp=num_active_games;
3956 NumActiveNetgames=num_active_games;
3958 if (!Network_games_changed)
3961 if (temp!=num_active_games)
3962 digi_play_sample (SOUND_HUD_MESSAGE,F1_0);
3964 Network_games_changed = 0;
3965 mprintf ((0,"JOIN POLL: I'm looking at %d games!\n",num_active_games));
3967 // Copy the active games data into the menu options
3968 for (i = 0; i < num_active_games; i++)
3970 int game_status = Active_games[i].game_status;
3971 int j,x, k,tx,ty,ta,nplayers = 0;
3972 char levelname[8],MissName[25],GameName[25],thold[2];
3975 // These next two loops protect against menu skewing
3976 // if missiontitle or gamename contain a tab
3978 for (x=0,tx=0,k=0,j=0;j<15;j++)
3980 if (Active_games[i].mission_title[j]=='\t')
3982 thold[0]=Active_games[i].mission_title[j];
3983 gr_get_string_size (thold,&tx,&ty,&ta);
3985 if ((x+=tx)>=LHX(55))
3987 MissName[k]=MissName[k+1]=MissName[k+2]='.';
3992 MissName[k++]=Active_games[i].mission_title[j];
3996 for (x=0,tx=0,k=0,j=0;j<15;j++)
3998 if (Active_games[i].game_name[j]=='\t')
4000 thold[0]=Active_games[i].game_name[j];
4001 gr_get_string_size (thold,&tx,&ty,&ta);
4003 if ((x+=tx)>=LHX(55))
4005 GameName[k]=GameName[k+1]=GameName[k+2]='.';
4009 GameName[k++]=Active_games[i].game_name[j];
4014 nplayers=Active_games[i].numconnected;
4016 if (Active_games[i].levelnum < 0)
4017 sprintf(levelname, "S%d", -Active_games[i].levelnum);
4019 sprintf(levelname, "%d", Active_games[i].levelnum);
4021 if (game_status == NETSTAT_STARTING)
4023 sprintf (menus[i+2].text,"%d.\t%s \t%s \t %d/%d \t%s \t %s \t%s",
4024 i+1,GameName,ModeLetters[Active_games[i].gamemode],nplayers,
4025 Active_games[i].max_numplayers,MissName,levelname,"Forming");
4027 else if (game_status == NETSTAT_PLAYING)
4029 join_status=can_join_netgame(&Active_games[i],NULL);
4030 // mprintf ((0,"Joinstatus=%d\n",join_status));
4033 sprintf (menus[i+2].text,"%d.\t%s \t%s \t %d/%d \t%s \t %s \t%s",
4034 i+1,GameName,ModeLetters[Active_games[i].gamemode],nplayers,
4035 Active_games[i].max_numplayers,MissName,levelname,"Open");
4036 else if (join_status==2)
4037 sprintf (menus[i+2].text,"%d.\t%s \t%s \t %d/%d \t%s \t %s \t%s",
4038 i+1,GameName,ModeLetters[Active_games[i].gamemode],nplayers,
4039 Active_games[i].max_numplayers,MissName,levelname,"Full");
4040 else if (join_status==3)
4041 sprintf (menus[i+2].text,"%d.\t%s \t%s \t %d/%d \t%s \t %s \t%s",
4042 i+1,GameName,ModeLetters[Active_games[i].gamemode],nplayers,
4043 Active_games[i].max_numplayers,MissName,levelname,"Restrict");
4045 sprintf (menus[i+2].text,"%d.\t%s \t%s \t %d/%d \t%s \t %s \t%s",
4046 i+1,GameName,ModeLetters[Active_games[i].gamemode],nplayers,
4047 Active_games[i].max_numplayers,MissName,levelname,"Closed");
4051 sprintf (menus[i+2].text,"%d.\t%s \t%s \t %d/%d \t%s \t %s \t%s",
4052 i+1,GameName,ModeLetters[Active_games[i].gamemode],nplayers,
4053 Active_games[i].max_numplayers,MissName,levelname,"Between");
4056 Assert(strlen(menus[i+2].text) < 100);
4057 menus[i+2].redraw = 1;
4060 for (i = num_active_games; i < MAX_ACTIVE_NETGAMES; i++)
4062 sprintf(menus[i+2].text, "%d. ",i+1);
4063 menus[i+2].redraw = 1;
4068 network_wait_for_sync(void)
4074 Network_status = NETSTAT_WAITING;
4076 m[0].type=NM_TYPE_TEXT; m[0].text = text;
4077 m[1].type=NM_TYPE_TEXT; m[1].text = TXT_NET_LEAVE;
4079 i = network_send_request();
4084 sprintf( m[0].text, "%s\n'%s' %s", TXT_NET_WAITING, NetPlayers.players[i].callsign, TXT_NET_TO_ENTER );
4087 choice=newmenu_do( NULL, TXT_WAIT, 2, m, network_sync_poll );
4092 if (Network_status != NETSTAT_PLAYING)
4096 // if (Network_status == NETSTAT_ENDLEVEL)
4098 // network_send_endlevel_packet(0);
4099 // longjmp(LeaveGame, 0);
4102 mprintf((0, "Aborting join.\n"));
4103 me.type = PID_QUIT_JOINING;
4104 memcpy( me.player.callsign, Players[Player_num].callsign, CALLSIGN_LEN+1 );
4105 if (Network_game_type == IPX_GAME) {
4106 memcpy( me.player.network.ipx.node, ipx_get_my_local_address(), 6 );
4107 memcpy( me.player.network.ipx.server, ipx_get_my_server_address(), 4 );
4109 ipx_send_internetwork_packet_data( (ubyte *)&me, sizeof(sequence_packet), NetPlayers.players[0].network.ipx.server, NetPlayers.players[0].network.ipx.node );
4111 send_sequence_packet(me, NetPlayers.players[0].network.ipx.server, NetPlayers.players[0].network.ipx.node, NULL);
4115 me.player.network.appletalk.node = appletalk_get_my_node();
4116 me.player.network.appletalk.net = appletalk_get_my_net();
4117 me.player.network.appletalk.socket = appletalk_get_my_socket();
4121 Function_mode = FMODE_MENU;
4122 Game_mode = GM_GAME_OVER;
4123 return(-1); // they cancelled
4129 network_request_poll( int nitems, newmenu_item * menus, int * key, int citem )
4131 // Polling loop for waiting-for-requests menu
4141 // Send our endlevel packet at regular intervals
4143 // if (timer_get_approx_seconds() > t1+ENDLEVEL_SEND_INTERVAL)
4145 // network_send_endlevel_packet();
4146 // t1 = timer_get_approx_seconds();
4151 for (i = 0; i < N_players; i++)
4153 if ((Players[i].connected == 1) || (Players[i].connected == 0))
4157 if (num_ready == N_players) // All players have checked in or are disconnected
4164 network_wait_for_requests(void)
4166 // Wait for other players to load the level before we send the sync
4170 Network_status = NETSTAT_WAITING;
4172 m[0].type=NM_TYPE_TEXT; m[0].text = TXT_NET_LEAVE;
4174 mprintf((0, "Entered wait_for_requests : N_players = %d.\n", N_players));
4176 for (choice = 0; choice < N_players; choice++)
4177 mprintf((0, "Players[%d].connected = %d.\n", choice, Players[choice].connected));
4179 Network_status = NETSTAT_WAITING;
4182 Players[Player_num].connected = 1;
4185 choice = newmenu_do(NULL, TXT_WAIT, 1, m, network_request_poll);
4190 choice = nm_messagebox(NULL, 3, TXT_YES, TXT_NO, TXT_START_NOWAIT, TXT_QUITTING_NOW);
4196 // User confirmed abort
4198 for (i=0; i < N_players; i++) {
4199 if ((Players[i].connected != 0) && (i != Player_num)) {
4200 if (Network_game_type == IPX_GAME)
4201 network_dump_player(NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node, DUMP_ABORTED);
4204 network_dump_appletalk_player(NetPlayers.players[i].network.appletalk.node, NetPlayers.players[i].network.appletalk.net, NetPlayers.players[i].network.appletalk.socket, DUMP_ABORTED);
4210 if (Network_game_type == APPLETALK_GAME)
4211 network_release_registered_game();
4213 longjmp(LeaveGame, 0);
4215 else if (choice != -2)
4220 network_level_sync(void)
4222 // Do required syncing between (before) levels
4226 mprintf((0, "Player %d entering network_level_sync.\n", Player_num));
4228 MySyncPackInitialized = 0;
4230 // my_segments_checksum = netmisc_calc_checksum(Segments, sizeof(segment)*(Highest_segment_index+1));
4232 network_flush(); // Flush any old packets
4235 result = network_wait_for_sync();
4236 else if (network_i_am_master())
4238 network_wait_for_requests();
4239 network_send_sync();
4243 result = network_wait_for_sync();
4245 network_count_powerups_in_mine();
4249 Players[Player_num].connected = 0;
4250 network_send_endlevel_packet();
4252 if (Network_game_type == APPLETALK_GAME)
4253 network_release_registered_game();
4255 longjmp(LeaveGame, 0);
4260 void network_count_powerups_in_mine(void)
4264 for (i=0;i<MAX_POWERUP_TYPES;i++)
4265 PowerupsInMine[i]=0;
4267 for (i=0;i<=Highest_object_index;i++)
4269 if (Objects[i].type==OBJ_POWERUP)
4271 PowerupsInMine[Objects[i].id]++;
4272 if (multi_powerup_is_4pack(Objects[i].id))
4273 PowerupsInMine[Objects[i].id-1]+=4;
4281 // code to release the NBP binding of an appletalk game
4283 void network_release_registered_game()
4285 if (Network_game_type == APPLETALK_GAME)
4286 appletalk_remove_netgame();
4289 // code to sort zone lists....
4291 int zone_sort_func(const char **e0, const char **e1)
4293 return strcmp(*e0, *e1);
4296 void network_get_appletalk_zone()
4298 int num_zones, i, item, default_item;
4300 char default_zone[MAX_ZONE_LENGTH]; // my zone
4302 Network_zone_name[0] = '\0';
4304 show_boxed_message("Looking for AppleTalk Zones");
4305 num_zones = appletalk_get_zone_names(&zone_list);
4306 clear_boxed_message();
4308 if (num_zones < 0) { // error in getting zone list...maybe no router available....
4309 if ( (num_zones == tooManyReqs) || (num_zones == noDataArea) ){
4310 nm_messagebox(NULL, 1, TXT_OK, "AppleTalk Network is too busy.\nPlease try again shortly.");
4311 longjmp(LeaveGame,0);
4316 if (num_zones == 0) {
4317 strcpy(Network_zone_name, DEFAULT_ZONE_NAME);
4321 if (num_zones == 1) {
4322 Network_zone_name[0] = (char)(strlen(zone_list[0]));
4323 memcpy( &(Network_zone_name[1]), zone_list[0], strlen(zone_list[0]) );
4327 // sort the zone names
4329 for (i = 0; i < num_zones; i++)
4330 strlwr(zone_list[i]);
4332 qsort(zone_list, num_zones, sizeof(char *), zone_sort_func);
4334 // get my current zone so we can highlight that one first
4336 if (appletalk_get_my_zone(default_zone))
4339 for (i = 0; i < num_zones; i++) {
4340 if ( !stricmp(zone_list[i], default_zone) ) {
4348 item = newmenu_listbox1("AppleTalk Zones", num_zones, zone_list, 0, default_item, NULL);
4353 Network_zone_name[0] = (char)(strlen(zone_list[item]));
4354 memcpy( &(Network_zone_name[1]), zone_list[item], strlen(zone_list[item]) );
4357 for (i = 0; i < num_zones; i++)
4358 d_free(zone_list[i]);
4363 void nm_draw_background1(char * filename);
4365 void network_join_game()
4368 char menu_text[MAX_ACTIVE_NETGAMES+2][200];
4370 newmenu_item m[MAX_ACTIVE_NETGAMES+2];
4372 if (Network_game_type == IPX_GAME) {
4373 if ( !Network_active )
4375 nm_messagebox(NULL, 1, TXT_OK, TXT_IPX_NOT_FOUND);
4379 } else if (Appletalk_active <= 0) {
4382 switch (Appletalk_active) {
4383 case APPLETALK_NOT_OPEN:
4384 sprintf(buf, "Appletalk is not currently active.\nPlease enable AppleTalk from the\nChooser and restart Descent.");
4386 case APPLETALK_BAD_LISTENER:
4387 sprintf(buf, "The Resource Fork of Descent appears damaged.\nPlease re-install Descent or contact\nMacPlay technical support.");
4389 case APPLETALK_NO_LOCAL_ADDR:
4390 sprintf(buf, "Wow! Strange!\n\nNo Local Address.");
4392 case APPLETALK_NO_SOCKET:
4393 sprintf(buf, "All AppleTalk sockets are in use.\nTry shutting down other network\napplications and restarting Descent.\n");
4396 nm_messagebox(NULL, 1, TXT_OK, buf);
4408 if (Network_game_type == APPLETALK_GAME)
4409 network_get_appletalk_zone();
4412 Network_send_objects = 0;
4413 Network_sending_extras=0;
4416 Network_status = NETSTAT_BROWSING; // We are looking at a game menu
4419 network_listen(); // Throw out old info
4422 if (Network_game_type == IPX_GAME)
4423 #endif // note link to if
4424 network_send_game_list_request(); // broadcast a request for lists
4426 num_active_games = 0;
4428 memset(m, 0, sizeof(newmenu_item)*MAX_ACTIVE_NETGAMES);
4429 memset(Active_games, 0, sizeof(netgame_info)*MAX_ACTIVE_NETGAMES);
4430 memset(ActiveNetPlayers,0,sizeof(AllNetPlayers_info)*MAX_ACTIVE_NETGAMES);
4432 gr_set_fontcolor(BM_XRGB(15,15,23),-1);
4434 m[0].text = menu_text[0];
4435 m[0].type = NM_TYPE_TEXT;
4436 if (Network_game_type == IPX_GAME) {
4437 if (Network_allow_socket_changes)
4438 sprintf( m[0].text, "\tCurrent IPX Socket is default %+d (PgUp/PgDn to change)", Network_socket );
4440 strcpy( m[0].text, "" );
4443 p2cstr(Network_zone_name);
4444 if (strcmp(Network_zone_name, "*")) // only print if there is a zone name
4445 sprintf(m[0].text, "\tCurrent Zone is %s", Network_zone_name); // is Network_zone_name a pascal string????
4446 c2pstr(Network_zone_name);
4450 m[1].text=menu_text[1];
4451 m[1].type=NM_TYPE_TEXT;
4452 sprintf (m[1].text,"\tGAME \tMODE \t#PLYRS \tMISSION \tLEV \tSTATUS");
4454 for (i = 0; i < MAX_ACTIVE_NETGAMES; i++) {
4455 m[i+2].text = menu_text[i+2];
4456 m[i+2].type = NM_TYPE_MENU;
4457 sprintf(m[i+2].text, "%d. ", i+1);
4461 Network_games_changed = 1;
4464 nm_draw_background1(Menu_pcx_name); //load this here so if we abort after loading level, we restore the palette
4465 gr_palette_load(gr_palette);
4466 ExtGameStatus=GAMESTAT_JOIN_NETGAME;
4467 choice=newmenu_dotiny("NETGAMES", NULL,MAX_ACTIVE_NETGAMES+2, m, network_join_poll);
4471 Network_status = NETSTAT_MENU;
4472 return; // they cancelled
4476 if (choice >=num_active_games)
4478 nm_messagebox(TXT_SORRY, 1, TXT_OK, TXT_INVALID_CHOICE);
4482 // Choice has been made and looks legit
4483 if (Active_games[choice].game_status == NETSTAT_ENDLEVEL)
4485 nm_messagebox(TXT_SORRY, 1, TXT_OK, TXT_NET_GAME_BETWEEN2);
4489 if (Active_games[choice].protocol_version != MULTI_PROTO_VERSION)
4491 if (Active_games[choice].protocol_version == 3) {
4493 nm_messagebox(TXT_SORRY, 1, TXT_OK, "Your version of Descent 2\nis incompatible with the\nDemo version");
4496 else if (Active_games[choice].protocol_version == 4) {
4498 nm_messagebox(TXT_SORRY, 1, TXT_OK, "This Demo version of\nDescent 2 is incompatible\nwith the full commercial version");
4502 nm_messagebox(TXT_SORRY, 1, TXT_OK, TXT_VERSION_MISMATCH);
4509 // Check for valid mission name
4510 mprintf((0, "Loading mission:%s.\n", Active_games[choice].mission_name));
4511 if (!load_mission_by_name(Active_games[choice].mission_name))
4513 nm_messagebox(NULL, 1, TXT_OK, TXT_MISSION_NOT_FOUND);
4519 #if defined (D2_OEM)
4521 if (Active_games[choice].levelnum>8)
4523 nm_messagebox(NULL, 1, TXT_OK, "This OEM version only supports\nthe first 8 levels!");
4529 if (!network_wait_for_all_info (choice))
4531 nm_messagebox (TXT_SORRY,1,TXT_OK,"There was a join error!");
4532 Network_status = NETSTAT_BROWSING; // We are looking at a game menu
4536 Network_status = NETSTAT_BROWSING; // We are looking at a game menu
4538 if (!can_join_netgame(&Active_games[choice],&ActiveNetPlayers[choice]))
4540 if (Active_games[choice].numplayers == Active_games[choice].max_numplayers)
4541 nm_messagebox(TXT_SORRY, 1, TXT_OK, TXT_GAME_FULL);
4543 nm_messagebox(TXT_SORRY, 1, TXT_OK, TXT_IN_PROGRESS);
4547 // Choice is valid, prepare to join in
4549 memcpy(&Netgame, &Active_games[choice], sizeof(netgame_info));
4550 memcpy (&NetPlayers,&ActiveNetPlayers[choice],sizeof(AllNetPlayers_info));
4552 Difficulty_level = Netgame.difficulty;
4553 MaxNumNetPlayers = Netgame.max_numplayers;
4554 change_playernum_to(1);
4558 // register the joining player with NBP. This will have the nice effect of a player wanting to
4559 // join to be able to see the netgame if this player were to become the master.
4561 if (Network_game_type == APPLETALK_GAME) {
4566 show_boxed_message("Registering Netgame");
4568 err = appletalk_register_netgame( Active_games[choice].game_name, TickCount() );
4569 t1 = timer_get_fixed_seconds() + F1_0;
4570 while ( timer_get_fixed_seconds() < t1 ) ;
4572 } while ( (err == nbpDuplicate) && (count != MAX_REGISTER_TRIES) );
4573 clear_boxed_message();
4574 if ( (err == tooManyReqs) || (count == MAX_REGISTER_TRIES) ) {
4575 nm_messagebox(NULL, 1, TXT_OK, "AppleTalk Network is too busy.\nPlease try again shortly.");
4581 network_set_game_mode(Netgame.gamemode);
4583 network_AdjustMaxDataSize ();
4585 StartNewLevel(Netgame.levelnum, 0);
4587 return; // look ma, we're in a game!!!
4590 void network_AdjustMaxDataSize ()
4593 if (Netgame.ShortPackets)
4594 MaxXDataSize=NET_XDATA_SIZE;
4596 MaxXDataSize=NET_XDATA_SIZE;
4600 fix StartWaitAllTime=0;
4601 int WaitAllChoice=0;
4602 #define ALL_INFO_REQUEST_INTERVAL F1_0*3
4604 void network_wait_all_poll( int nitems, newmenu_item * menus, int * key, int citem )
4612 if (timer_get_approx_seconds() > t1+ALL_INFO_REQUEST_INTERVAL)
4614 network_send_all_info_request(PID_SEND_ALL_GAMEINFO,SecurityCheck);
4615 t1 = timer_get_approx_seconds();
4618 network_do_big_wait(WaitAllChoice);
4620 if(SecurityCheck==-1)
4624 int network_wait_for_all_info (int choice)
4630 m[0].type=NM_TYPE_TEXT; m[0].text = "Press Escape to cancel";
4632 WaitAllChoice=choice;
4633 StartWaitAllTime=timer_get_approx_seconds();
4634 SecurityCheck=Active_games[choice].Security;
4638 pick=newmenu_do( NULL, "Connecting...", 1, m, network_wait_all_poll );
4640 if (pick>-1 && SecurityCheck!=-1)
4643 if (SecurityCheck==-1)
4652 void network_do_big_wait(int choice)
4655 ubyte packet[IPX_MAX_DATA_SIZE],*data;
4656 AllNetPlayers_info *temp_info;
4658 AllNetPlayers_info info_struct;
4659 ubyte apacket[APPLETALK_MAX_DATA_SIZE];
4663 if (Network_game_type == APPLETALK_GAME)
4664 size=appletalk_get_packet_data( apacket );
4667 size=ipx_get_packet_data( packet );
4672 if (Network_game_type == APPLETALK_GAME)
4682 if (Network_game_type == IPX_GAME) {
4684 memcpy((ubyte *)&TempNetInfo, data, sizeof(netgame_info));
4686 receive_netgame_packet(data, &TempNetInfo, 0);
4689 memcpy((ubyte *)&TempNetInfo, data, sizeof(netgame_info));
4691 mprintf ((0,"This is %s game with a security of %d\n",TempNetInfo.game_name,TempNetInfo.Security));
4693 if (TempNetInfo.Security !=SecurityCheck)
4695 mprintf ((0,"Bad security on big_wait...rejecting.\n"));
4699 if (NetSecurityFlag==NETSECURITY_WAIT_FOR_GAMEINFO)
4701 if (TempPlayersInfo->Security==TempNetInfo.Security)
4703 mprintf ((0,"EQUAL !: Game=%d Players=%d ",TempPlayersInfo->Security,TempNetInfo.Security));
4704 if (TempPlayersInfo->Security==SecurityCheck)
4706 memcpy (&Active_games[choice],(ubyte *)&TempNetInfo,sizeof(netgame_info));
4707 memcpy (&ActiveNetPlayers[choice],TempPlayersInfo,sizeof(AllNetPlayers_info));
4714 NetSecurityFlag=NETSECURITY_WAIT_FOR_PLAYERS;
4715 NetSecurityNum=TempNetInfo.Security;
4717 if (network_wait_for_playerinfo())
4719 mprintf ((0,"HUH? Game=%d Player=%d\n",NetSecurityNum,TempPlayersInfo->Security));
4720 memcpy (&Active_games[choice],(ubyte *)&TempNetInfo,sizeof(netgame_info));
4721 memcpy (&ActiveNetPlayers[choice],TempPlayersInfo,sizeof(AllNetPlayers_info));
4728 case PID_PLAYERSINFO:
4729 mprintf ((0,"Got a PID_PLAYERSINFO!\n"));
4731 if (Network_game_type == IPX_GAME) {
4733 temp_info=(AllNetPlayers_info *)data;
4735 receive_netplayers_packet(data, &info_struct);
4736 temp_info = &info_struct;
4739 temp_info = (AllNetPlayers_info *)data;
4741 if (temp_info->Security!=SecurityCheck)
4742 break; // If this isn't the guy we're looking for, move on
4744 memcpy (&TempPlayersBase,(ubyte *)&temp_info,sizeof(AllNetPlayers_info));
4745 TempPlayersInfo=&TempPlayersBase;
4746 WaitingForPlayerInfo=0;
4747 NetSecurityNum=TempPlayersInfo->Security;
4748 NetSecurityFlag=NETSECURITY_WAIT_FOR_GAMEINFO;
4754 void network_leave_game()
4758 network_do_frame(1, 1);
4761 fclose (SendLogFile);
4762 fclose (RecieveLogFile);
4765 if ((network_i_am_master()))
4767 while (Network_sending_extras>1 && Player_joining_extras!=-1)
4768 network_send_extras();
4770 Netgame.numplayers = 0;
4773 network_send_game_info(NULL);
4776 mprintf ((0,"HEY! I'm master and I've left.\n"));
4779 Players[Player_num].connected = 0;
4780 network_send_endlevel_packet();
4781 change_playernum_to(0);
4782 Game_mode = GM_GAME_OVER;
4783 write_player_file();
4785 // WIN(ipx_destroy_read_thread());
4790 void network_flush()
4793 ubyte apacket[APPLETALK_MAX_DATA_SIZE];
4795 ubyte packet[IPX_MAX_DATA_SIZE];
4798 if ( (Network_game_type == APPLETALK_GAME) && (Appletalk_active <= 0) )
4802 if ( Network_game_type == IPX_GAME )
4803 if (!Network_active) return;
4806 if (Network_game_type == APPLETALK_GAME)
4807 while (appletalk_get_packet_data(apacket) > 0) ;
4810 while (ipx_get_packet_data(packet) > 0) ;
4813 void network_listen()
4816 ubyte apacket[APPLETALK_MAX_DATA_SIZE];
4819 ubyte packet[IPX_MAX_DATA_SIZE];
4822 if (Network_status==NETSTAT_PLAYING && Netgame.ShortPackets && !Network_send_objects)
4824 loopmax=N_players*Netgame.PacketsPerSec;
4828 if ( (Network_game_type == APPLETALK_GAME) && (Appletalk_active <= 0) )
4832 if (Network_game_type == IPX_GAME)
4833 if (!Network_active) return;
4835 if (!(Game_mode & GM_NETWORK) && (Function_mode == FMODE_GAME))
4836 mprintf((0, "Calling network_listen() when not in net game.\n"));
4838 WaitingForPlayerInfo=1;
4839 NetSecurityFlag=NETSECURITY_OFF;
4842 if (Network_game_type == IPX_GAME) {
4843 size = ipx_get_packet_data( packet );
4845 network_process_packet( packet, size );
4848 size = ipx_get_packet_data( packet );
4852 size = appletalk_get_packet_data( apacket );
4854 network_process_packet( apacket, size );
4857 size = appletalk_get_packet_data( apacket );
4863 int network_wait_for_playerinfo()
4866 ubyte packet[IPX_MAX_DATA_SIZE];
4867 struct AllNetPlayers_info *TempInfo;
4871 AllNetPlayers_info info_struct;
4872 ubyte apacket[APPLETALK_MAX_DATA_SIZE];
4876 if ( (Network_game_type == APPLETALK_GAME) && (Appletalk_active <= 0) )
4880 if ( Network_game_type == IPX_GAME)
4881 if (!Network_active) return(0);
4883 // if (!WaitingForPlayerInfo)
4886 if (!(Game_mode & GM_NETWORK) && (Function_mode == FMODE_GAME))
4888 mprintf((0, "Calling network_wait_for_playerinfo() when not in net game.\n"));
4890 if (Network_status==NETSTAT_PLAYING)
4892 Int3(); //MY GOD! Get Jason...this is the source of many problems
4895 basetime=timer_get_approx_seconds();
4897 while (WaitingForPlayerInfo && retries<50 && (timer_get_approx_seconds()<(basetime+(F1_0*5))))
4899 if (Network_game_type == IPX_GAME) {
4900 size = ipx_get_packet_data( packet );
4904 size = appletalk_get_packet_data( apacket );
4909 if (size>0 && id==PID_PLAYERSINFO)
4912 if (Network_game_type == APPLETALK_GAME) {
4913 TempInfo = (AllNetPlayers_info *)apacket;
4915 receive_netplayers_packet(packet, &info_struct);
4916 TempInfo = &info_struct;
4919 TempInfo=(AllNetPlayers_info *)packet;
4924 if (NetSecurityFlag==NETSECURITY_WAIT_FOR_PLAYERS)
4926 if (NetSecurityNum==TempInfo->Security)
4928 mprintf ((0,"HEYEQUAL: Player=%d Game=%d\n",TempInfo->Security,NetSecurityNum));
4929 memcpy (&TempPlayersBase,(ubyte *)TempInfo,sizeof(AllNetPlayers_info));
4930 TempPlayersInfo=&TempPlayersBase;
4931 NetSecurityFlag=NETSECURITY_OFF;
4933 WaitingForPlayerInfo=0;
4941 mprintf ((0,"I'm original!\n"));
4943 NetSecurityNum=TempInfo->Security;
4944 NetSecurityFlag=NETSECURITY_WAIT_FOR_GAMEINFO;
4946 memcpy (&TempPlayersBase,(ubyte *)TempInfo,sizeof(AllNetPlayers_info));
4947 TempPlayersInfo=&TempPlayersBase;
4948 WaitingForPlayerInfo=0;
4957 void network_send_data( ubyte * ptr, int len, int urgent )
4963 fprintf (SendLogFile,"Packet type: %d Len:%d Urgent:%d TT=%d\n",ptr[0],len,urgent,TTSent[ptr[0]]);
4964 fflush (SendLogFile);
4967 if (Endlevel_sequence)
4970 if (!MySyncPackInitialized) {
4971 MySyncPackInitialized = 1;
4972 memset( &MySyncPack, 0, sizeof(frame_info) );
4978 if ((MySyncPack.data_size+len) > MaxXDataSize ) {
4980 network_do_frame(1, 0);
4981 if (MySyncPack.data_size != 0) {
4982 mprintf((0, "%d bytes were added to data by network_do_frame!\n", MySyncPack.data_size));
4985 // Int3(); // Trying to send too much!
4987 mprintf((0, "Packet overflow, sending additional packet, type %d len %d.\n", ptr[0], len));
4988 Assert(check == ptr[0]);
4991 Assert(MySyncPack.data_size+len <= MaxXDataSize);
4993 memcpy( &MySyncPack.data[MySyncPack.data_size], ptr, len );
4994 MySyncPack.data_size += len;
4997 void network_timeout_player(int playernum)
4999 // Remove a player from the game if we haven't heard from them in
5003 Assert(playernum < N_players);
5004 Assert(playernum > -1);
5006 network_disconnect_player(playernum);
5007 create_player_appearance_effect(&Objects[Players[playernum].objnum]);
5009 digi_play_sample(SOUND_HUD_MESSAGE, F1_0);
5011 HUD_init_message("%s %s", Players[playernum].callsign, TXT_DISCONNECTING);
5012 for (i = 0; i < N_players; i++)
5013 if (Players[i].connected)
5018 nm_messagebox(NULL, 1, TXT_OK, TXT_YOU_ARE_ONLY);
5022 fix last_send_time = 0;
5023 fix last_timeout_check = 0;
5026 void squish_short_frame_info(short_frame_info old_info, ubyte *data)
5032 data[0] = old_info.type; loc++; loc += 3; // skip three for pad byte
5033 tmpi = swapint(old_info.numpackets);
5034 memcpy(&(data[loc]), &tmpi, 4); loc += 4;
5036 memcpy(&(data[loc]), old_info.thepos.bytemat, 9); loc += 9;
5037 tmps = INTEL_SHORT(old_info.thepos.xo);
5038 memcpy(&(data[loc]), &tmps, 2); loc += 2;
5039 tmps = INTEL_SHORT(old_info.thepos.yo);
5040 memcpy(&(data[loc]), &tmps, 2); loc += 2;
5041 tmps = INTEL_SHORT(old_info.thepos.zo);
5042 memcpy(&(data[loc]), &tmps, 2); loc += 2;
5043 tmps = INTEL_SHORT(old_info.thepos.segment);
5044 memcpy(&(data[loc]), &tmps, 2); loc += 2;
5045 tmps = INTEL_SHORT(old_info.thepos.velx);
5046 memcpy(&(data[loc]), &tmps, 2); loc += 2;
5047 tmps = INTEL_SHORT(old_info.thepos.vely);
5048 memcpy(&(data[loc]), &tmps, 2); loc += 2;
5049 tmps = INTEL_SHORT(old_info.thepos.velz);
5050 memcpy(&(data[loc]), &tmps, 2); loc += 2;
5052 tmps = swapshort(old_info.data_size);
5053 memcpy(&(data[loc]), &tmps, 2); loc += 2;
5055 data[loc] = old_info.playernum; loc++;
5056 data[loc] = old_info.obj_render_type; loc++;
5057 data[loc] = old_info.level_num; loc++;
5058 memcpy(&(data[loc]), old_info.data, old_info.data_size);
5062 char NakedBuf[NET_XDATA_SIZE+4];
5063 int NakedPacketLen=0;
5064 int NakedPacketDestPlayer=-1;
5066 void network_do_frame(int force, int listen)
5069 short_frame_info ShortSyncPack;
5070 static fix LastEndlevel=0;
5072 if (!(Game_mode&GM_NETWORK)) return;
5074 if ((Network_status != NETSTAT_PLAYING) || (Endlevel_sequence)) // Don't send postion during escape sequence...
5079 Assert (NakedPacketDestPlayer>-1);
5080 // mprintf ((0,"Sending a naked packet to %s (%d bytes)!\n",Players[NakedPacketDestPlayer].callsign,NakedPacketLen));
5081 if (Network_game_type == IPX_GAME)
5082 ipx_send_packet_data( (ubyte *)NakedBuf, NakedPacketLen, NetPlayers.players[NakedPacketDestPlayer].network.ipx.server, NetPlayers.players[NakedPacketDestPlayer].network.ipx.node,Players[NakedPacketDestPlayer].net_address );
5085 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 );
5088 NakedPacketDestPlayer=-1;
5091 if (WaitForRefuseAnswer && timer_get_approx_seconds()>(RefuseTimeLimit+(F1_0*12)))
5092 WaitForRefuseAnswer=0;
5094 last_send_time += FrameTime;
5095 last_timeout_check += FrameTime;
5097 // Send out packet PacksPerSec times per second maximum... unless they fire, then send more often...
5098 if ( (last_send_time>F1_0/Netgame.PacketsPerSec) || (Network_laser_fired) || force || PacketUrgent ) {
5099 if ( Players[Player_num].connected ) {
5100 int objnum = Players[Player_num].objnum;
5104 multi_send_robot_frame(0);
5105 multi_send_fire(); // Do firing if needed..
5110 if (Netgame.ShortPackets)
5113 ubyte send_data[IPX_MAX_DATA_SIZE];
5116 create_shortpos(&ShortSyncPack.thepos, Objects+objnum, 0);
5117 ShortSyncPack.type = PID_PDATA;
5118 ShortSyncPack.playernum = Player_num;
5119 ShortSyncPack.obj_render_type = Objects[objnum].render_type;
5120 ShortSyncPack.level_num = Current_level_num;
5121 ShortSyncPack.data_size = MySyncPack.data_size;
5122 memcpy (&ShortSyncPack.data[0],&MySyncPack.data[0],MySyncPack.data_size);
5124 for (i=0; i<N_players; i++ ) {
5125 if ( (Players[i].connected) && (i!=Player_num ) ) {
5126 MySyncPack.numpackets = Players[i].n_packets_sent++;
5127 ShortSyncPack.numpackets=MySyncPack.numpackets;
5128 if (Network_game_type == IPX_GAME) {
5130 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 );
5132 squish_short_frame_info(ShortSyncPack, send_data);
5133 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 );
5137 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 );
5143 else // If long packets
5147 MySyncPack.type = PID_PDATA;
5148 MySyncPack.playernum = Player_num;
5149 MySyncPack.obj_render_type = Objects[objnum].render_type;
5150 MySyncPack.level_num = Current_level_num;
5151 MySyncPack.obj_segnum = Objects[objnum].segnum;
5152 MySyncPack.obj_pos = Objects[objnum].pos;
5153 MySyncPack.obj_orient = Objects[objnum].orient;
5154 MySyncPack.phys_velocity = Objects[objnum].mtype.phys_info.velocity;
5155 MySyncPack.phys_rotvel = Objects[objnum].mtype.phys_info.rotvel;
5157 send_data_size = MySyncPack.data_size; // do this so correct size data is sent
5159 #ifdef MACINTOSH // do the swap stuff
5160 if (Network_game_type == IPX_GAME) {
5161 MySyncPack.obj_segnum = INTEL_SHORT(MySyncPack.obj_segnum);
5162 MySyncPack.obj_pos.x = INTEL_INT((int)MySyncPack.obj_pos.x);
5163 MySyncPack.obj_pos.y = INTEL_INT((int)MySyncPack.obj_pos.y);
5164 MySyncPack.obj_pos.z = INTEL_INT((int)MySyncPack.obj_pos.z);
5166 MySyncPack.obj_orient.rvec.x = INTEL_INT((int)MySyncPack.obj_orient.rvec.x);
5167 MySyncPack.obj_orient.rvec.y = INTEL_INT((int)MySyncPack.obj_orient.rvec.y);
5168 MySyncPack.obj_orient.rvec.z = INTEL_INT((int)MySyncPack.obj_orient.rvec.z);
5169 MySyncPack.obj_orient.uvec.x = INTEL_INT((int)MySyncPack.obj_orient.uvec.x);
5170 MySyncPack.obj_orient.uvec.y = INTEL_INT((int)MySyncPack.obj_orient.uvec.y);
5171 MySyncPack.obj_orient.uvec.z = INTEL_INT((int)MySyncPack.obj_orient.uvec.z);
5172 MySyncPack.obj_orient.fvec.x = INTEL_INT((int)MySyncPack.obj_orient.fvec.x);
5173 MySyncPack.obj_orient.fvec.y = INTEL_INT((int)MySyncPack.obj_orient.fvec.y);
5174 MySyncPack.obj_orient.fvec.z = INTEL_INT((int)MySyncPack.obj_orient.fvec.z);
5176 MySyncPack.phys_velocity.x = INTEL_INT((int)MySyncPack.phys_velocity.x);
5177 MySyncPack.phys_velocity.y = INTEL_INT((int)MySyncPack.phys_velocity.y);
5178 MySyncPack.phys_velocity.z = INTEL_INT((int)MySyncPack.phys_velocity.z);
5180 MySyncPack.phys_rotvel.x = INTEL_INT((int)MySyncPack.phys_rotvel.x);
5181 MySyncPack.phys_rotvel.y = INTEL_INT((int)MySyncPack.phys_rotvel.y);
5182 MySyncPack.phys_rotvel.z = INTEL_INT((int)MySyncPack.phys_rotvel.z);
5184 MySyncPack.data_size = INTEL_SHORT(MySyncPack.data_size);
5188 for (i=0; i<N_players; i++ ) {
5189 if ( (Players[i].connected) && (i!=Player_num ) ) {
5190 if (Network_game_type == IPX_GAME)
5191 MySyncPack.numpackets = INTEL_INT(Players[i].n_packets_sent);
5194 MySyncPack.numpackets = Players[i].n_packets_sent;
5197 Players[i].n_packets_sent++;
5198 if (Network_game_type == IPX_GAME)
5199 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 );
5202 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);
5208 MySyncPack.data_size = 0; // Start data over at 0 length.
5209 if (Control_center_destroyed)
5212 Players[Player_num].connected=3;
5213 if (timer_get_approx_seconds() > (LastEndlevel+(F1_0/2)))
5215 network_send_endlevel_packet();
5216 LastEndlevel=timer_get_approx_seconds();
5219 //mprintf( (0, "Packet has %d bytes appended (TS=%d)\n", MySyncPack.data_size, sizeof(frame_info)-MaxXDataSize+MySyncPack.data_size ));
5226 if ((last_timeout_check > F1_0) && !(Control_center_destroyed))
5228 fix approx_time = timer_get_approx_seconds();
5229 // Check for player timeouts
5230 for (i = 0; i < N_players; i++)
5232 if ((i != Player_num) && (Players[i].connected == 1))
5234 if ((LastPacketTime[i] == 0) || (LastPacketTime[i] > approx_time))
5236 LastPacketTime[i] = approx_time;
5239 if ((approx_time - LastPacketTime[i]) > (15*F1_0))
5240 network_timeout_player(i);
5243 last_timeout_check = 0;
5249 MySyncPack.data_size = 0;
5254 if (VerifyPlayerJoined!=-1 && !(FrameCount & 63))
5255 resend_sync_due_to_packet_loss_for_allender(); // This will resend to network_player_rejoining
5257 if (Network_send_objects)
5258 network_send_objects();
5260 if (Network_sending_extras && VerifyPlayerJoined==-1)
5262 network_send_extras();
5267 int missed_packets = 0;
5269 int ConsistencyCount = 0;
5271 void network_consistency_error(void)
5273 if (++ConsistencyCount < 10)
5276 Function_mode = FMODE_MENU;
5278 nm_messagebox(NULL, 1, TXT_OK, TXT_CONSISTENCY_ERROR);
5280 nm_messagebox(NULL, 1, TXT_OK, "Failed to join the netgame.\nYou are missing packets. Check\nyour network connection and\ntry again.");
5282 Function_mode = FMODE_GAME;
5283 ConsistencyCount = 0;
5284 multi_quit_game = 1;
5285 multi_leave_menu = 1;
5286 multi_reset_stuff();
5287 Function_mode = FMODE_MENU;
5290 void network_process_pdata (char *data)
5292 Assert (Game_mode & GM_NETWORK);
5294 if (Netgame.ShortPackets)
5295 network_read_pdata_short_packet ((short_frame_info *)data);
5297 network_read_pdata_packet ((frame_info *)data);
5300 void network_read_pdata_packet(frame_info *pd )
5304 object * TheirObj = NULL;
5306 // frame_info should be aligned...for mac, make the necessary adjustments
5308 if (Network_game_type == IPX_GAME) {
5309 pd->numpackets = INTEL_INT(pd->numpackets);
5310 pd->obj_pos.x = INTEL_INT(pd->obj_pos.x);
5311 pd->obj_pos.y = INTEL_INT(pd->obj_pos.y);
5312 pd->obj_pos.z = INTEL_INT(pd->obj_pos.z);
5314 pd->obj_orient.rvec.x = (fix)INTEL_INT((int)pd->obj_orient.rvec.x);
5315 pd->obj_orient.rvec.y = (fix)INTEL_INT((int)pd->obj_orient.rvec.y);
5316 pd->obj_orient.rvec.z = (fix)INTEL_INT((int)pd->obj_orient.rvec.z);
5317 pd->obj_orient.uvec.x = (fix)INTEL_INT((int)pd->obj_orient.uvec.x);
5318 pd->obj_orient.uvec.y = (fix)INTEL_INT((int)pd->obj_orient.uvec.y);
5319 pd->obj_orient.uvec.z = (fix)INTEL_INT((int)pd->obj_orient.uvec.z);
5320 pd->obj_orient.fvec.x = (fix)INTEL_INT((int)pd->obj_orient.fvec.x);
5321 pd->obj_orient.fvec.y = (fix)INTEL_INT((int)pd->obj_orient.fvec.y);
5322 pd->obj_orient.fvec.z = (fix)INTEL_INT((int)pd->obj_orient.fvec.z);
5324 pd->phys_velocity.x = (fix)INTEL_INT((int)pd->phys_velocity.x);
5325 pd->phys_velocity.y = (fix)INTEL_INT((int)pd->phys_velocity.y);
5326 pd->phys_velocity.z = (fix)INTEL_INT((int)pd->phys_velocity.z);
5328 pd->phys_rotvel.x = (fix)INTEL_INT((int)pd->phys_rotvel.x);
5329 pd->phys_rotvel.y = (fix)INTEL_INT((int)pd->phys_rotvel.y);
5330 pd->phys_rotvel.z = (fix)INTEL_INT((int)pd->phys_rotvel.z);
5332 pd->obj_segnum = INTEL_SHORT(pd->obj_segnum);
5333 pd->data_size = INTEL_SHORT(pd->data_size);
5337 TheirPlayernum = pd->playernum;
5338 TheirObjnum = Players[pd->playernum].objnum;
5340 if (TheirPlayernum < 0) {
5341 Int3(); // This packet is bogus!!
5345 if (VerifyPlayerJoined!=-1 && TheirPlayernum==VerifyPlayerJoined)
5347 // Hurray! Someone really really got in the game (I think).
5348 mprintf ((0,"Hurray! VPJ (%d) reset!\n",VerifyPlayerJoined));
5349 VerifyPlayerJoined=-1;
5352 if (!multi_quit_game && (TheirPlayernum >= N_players)) {
5353 if (Network_status!=NETSTAT_WAITING)
5355 Int3(); // We missed an important packet!
5356 network_consistency_error();
5362 if (Endlevel_sequence || (Network_status == NETSTAT_ENDLEVEL) ) {
5363 int old_Endlevel_sequence = Endlevel_sequence;
5364 Endlevel_sequence = 1;
5365 if ( pd->data_size>0 ) {
5366 // pass pd->data to some parser function....
5367 multi_process_bigdata( pd->data, pd->data_size );
5369 Endlevel_sequence = old_Endlevel_sequence;
5372 // mprintf((0, "Gametime = %d, Frametime = %d.\n", GameTime, FrameTime));
5374 if ((byte)pd->level_num != Current_level_num)
5376 mprintf((0, "Got frame packet from player %d wrong level %d!\n", pd->playernum, pd->level_num));
5380 TheirObj = &Objects[TheirObjnum];
5382 //------------- Keep track of missed packets -----------------
5383 Players[TheirPlayernum].n_packets_got++;
5385 LastPacketTime[TheirPlayernum] = timer_get_approx_seconds();
5387 if ( pd->numpackets != Players[TheirPlayernum].n_packets_got ) {
5390 missed_packets = pd->numpackets-Players[TheirPlayernum].n_packets_got;
5391 if ((pd->numpackets-Players[TheirPlayernum].n_packets_got)>0)
5392 TotalMissedPackets += pd->numpackets-Players[TheirPlayernum].n_packets_got;
5394 if ( missed_packets > 0 )
5395 mprintf(( 0, "Missed %d packets from player #%d (%d total)\n", pd->numpackets-Players[TheirPlayernum].n_packets_got, TheirPlayernum, missed_packets ));
5397 mprintf( (0, "Got %d late packets from player #%d (%d total)\n", Players[TheirPlayernum].n_packets_got-pd->numpackets, TheirPlayernum, missed_packets ));
5400 #ifdef APPLETALK_DEBUG
5401 if (Network_game_type == APPLETALK_GAME) {
5402 if ( missed_packets > 0 )
5403 fprintf( at_fp, "Missed %d packets from player #%d (%d total)\n", pd->numpackets-Players[TheirPlayernum].n_packets_got, TheirPlayernum, missed_packets );
5405 fprintf( at_fp, "Got %d late packets from player #%d (%d total)\n", Players[TheirPlayernum].n_packets_got-pd->numpackets, TheirPlayernum, missed_packets );
5410 if (Network_game_type == IPX_GAME) {
5411 if ( missed_packets > 0 )
5412 fprintf( ipx_fp, "Missed %d packets from player #%d (%d total)\n", pd->numpackets-Players[TheirPlayernum].n_packets_got, TheirPlayernum, missed_packets );
5414 fprintf( ipx_fp, "Got %d late packets from player #%d (%d total)\n", Players[TheirPlayernum].n_packets_got-pd->numpackets, TheirPlayernum, missed_packets );
5419 Players[TheirPlayernum].n_packets_got = pd->numpackets;
5422 //------------ Read the player's ship's object info ----------------------
5423 TheirObj->pos = pd->obj_pos;
5424 TheirObj->orient = pd->obj_orient;
5425 TheirObj->mtype.phys_info.velocity = pd->phys_velocity;
5426 TheirObj->mtype.phys_info.rotvel = pd->phys_rotvel;
5428 if ((TheirObj->render_type != pd->obj_render_type) && (pd->obj_render_type == RT_POLYOBJ))
5429 multi_make_ghost_player(TheirPlayernum);
5431 obj_relink(TheirObjnum,pd->obj_segnum);
5433 if (TheirObj->movement_type == MT_PHYSICS)
5434 set_thrust_from_velocity(TheirObj);
5436 //------------ Welcome them back if reconnecting --------------
5437 if (!Players[TheirPlayernum].connected) {
5438 Players[TheirPlayernum].connected = 1;
5440 if (Newdemo_state == ND_STATE_RECORDING)
5441 newdemo_record_multi_reconnect(TheirPlayernum);
5443 multi_make_ghost_player(TheirPlayernum);
5445 create_player_appearance_effect(&Objects[TheirObjnum]);
5447 digi_play_sample( SOUND_HUD_MESSAGE, F1_0);
5449 ClipRank (&NetPlayers.players[TheirPlayernum].rank);
5451 if (args_find("-norankings"))
5452 HUD_init_message( "'%s' %s", Players[TheirPlayernum].callsign, TXT_REJOIN );
5454 HUD_init_message( "%s'%s' %s", RankStrings[NetPlayers.players[TheirPlayernum].rank],Players[TheirPlayernum].callsign, TXT_REJOIN );
5460 //------------ Parse the extra data at the end ---------------
5462 if ( pd->data_size>0 ) {
5463 // pass pd->data to some parser function....
5464 multi_process_bigdata( pd->data, pd->data_size );
5470 void get_short_frame_info(ubyte *old_info, short_frame_info *new_info)
5474 new_info->type = old_info[loc]; loc++; loc += 3; // skip three for pad byte
5475 memcpy(&(new_info->numpackets), &(old_info[loc]), 4); loc += 4;
5476 new_info->numpackets = INTEL_INT(new_info->numpackets);
5477 memcpy(new_info->thepos.bytemat, &(old_info[loc]), 9); loc += 9;
5478 memcpy(&(new_info->thepos.xo), &(old_info[loc]), 2); loc += 2;
5479 memcpy(&(new_info->thepos.yo), &(old_info[loc]), 2); loc += 2;
5480 memcpy(&(new_info->thepos.zo), &(old_info[loc]), 2); loc += 2;
5481 memcpy(&(new_info->thepos.segment), &(old_info[loc]), 2); loc += 2;
5482 memcpy(&(new_info->thepos.velx), &(old_info[loc]), 2); loc += 2;
5483 memcpy(&(new_info->thepos.vely), &(old_info[loc]), 2); loc += 2;
5484 memcpy(&(new_info->thepos.velz), &(old_info[loc]), 2); loc += 2;
5485 new_info->thepos.xo = INTEL_SHORT(new_info->thepos.xo);
5486 new_info->thepos.yo = INTEL_SHORT(new_info->thepos.yo);
5487 new_info->thepos.zo = INTEL_SHORT(new_info->thepos.zo);
5488 new_info->thepos.segment = INTEL_SHORT(new_info->thepos.segment);
5489 new_info->thepos.velx = INTEL_SHORT(new_info->thepos.velx);
5490 new_info->thepos.vely = INTEL_SHORT(new_info->thepos.vely);
5491 new_info->thepos.velz = INTEL_SHORT(new_info->thepos.velz);
5493 memcpy(&(new_info->data_size), &(old_info[loc]), 2); loc += 2;
5494 new_info->data_size = INTEL_SHORT(new_info->data_size);
5495 new_info->playernum = old_info[loc]; loc++;
5496 new_info->obj_render_type = old_info[loc]; loc++;
5497 new_info->level_num = old_info[loc]; loc++;
5498 memcpy(new_info->data, &(old_info[loc]), new_info->data_size);
5502 void network_read_pdata_short_packet(short_frame_info *pd )
5506 object * TheirObj = NULL;
5507 short_frame_info new_pd;
5509 // short frame info is not aligned because of shortpos. The mac
5510 // will call totally hacked and gross function to fix this up.
5512 if (Network_game_type == IPX_GAME) {
5514 memcpy(&new_pd, (ubyte *)pd, sizeof(short_frame_info));
5516 get_short_frame_info((ubyte *)pd, &new_pd);
5519 memcpy(&new_pd, (ubyte *)pd, sizeof(short_frame_info));
5522 TheirPlayernum = new_pd.playernum;
5523 TheirObjnum = Players[new_pd.playernum].objnum;
5525 if (TheirPlayernum < 0) {
5526 Int3(); // This packet is bogus!!
5529 if (!multi_quit_game && (TheirPlayernum >= N_players)) {
5530 if (Network_status!=NETSTAT_WAITING)
5532 Int3(); // We missed an important packet!
5533 network_consistency_error();
5540 if (VerifyPlayerJoined!=-1 && TheirPlayernum==VerifyPlayerJoined)
5542 // Hurray! Someone really really got in the game (I think).
5543 mprintf ((0,"Hurray! VPJ (%d) reset!\n",VerifyPlayerJoined));
5544 VerifyPlayerJoined=-1;
5547 if (Endlevel_sequence || (Network_status == NETSTAT_ENDLEVEL) ) {
5548 int old_Endlevel_sequence = Endlevel_sequence;
5549 Endlevel_sequence = 1;
5550 if ( new_pd.data_size>0 ) {
5551 // pass pd->data to some parser function....
5552 multi_process_bigdata( new_pd.data, new_pd.data_size );
5554 Endlevel_sequence = old_Endlevel_sequence;
5557 // mprintf((0, "Gametime = %d, Frametime = %d.\n", GameTime, FrameTime));
5559 if ((byte)new_pd.level_num != Current_level_num)
5561 mprintf((0, "Got frame packet from player %d wrong level %d!\n", new_pd.playernum, new_pd.level_num));
5565 TheirObj = &Objects[TheirObjnum];
5567 //------------- Keep track of missed packets -----------------
5568 Players[TheirPlayernum].n_packets_got++;
5570 LastPacketTime[TheirPlayernum] = timer_get_approx_seconds();
5572 if ( new_pd.numpackets != Players[TheirPlayernum].n_packets_got ) {
5575 missed_packets = new_pd.numpackets-Players[TheirPlayernum].n_packets_got;
5576 if ((new_pd.numpackets-Players[TheirPlayernum].n_packets_got)>0)
5577 TotalMissedPackets += new_pd.numpackets-Players[TheirPlayernum].n_packets_got;
5579 if ( missed_packets > 0 )
5580 mprintf( (0, "Missed %d packets from player #%d (%d total)\n", new_pd.numpackets-Players[TheirPlayernum].n_packets_got, TheirPlayernum, missed_packets ));
5582 mprintf( (0, "Got %d late packets from player #%d (%d total)\n", Players[TheirPlayernum].n_packets_got-new_pd.numpackets, TheirPlayernum, missed_packets ));
5584 Players[TheirPlayernum].n_packets_got = new_pd.numpackets;
5587 //------------ Read the player's ship's object info ----------------------
5589 extract_shortpos(TheirObj, &new_pd.thepos, 0);
5591 if ((TheirObj->render_type != new_pd.obj_render_type) && (new_pd.obj_render_type == RT_POLYOBJ))
5592 multi_make_ghost_player(TheirPlayernum);
5594 if (TheirObj->movement_type == MT_PHYSICS)
5595 set_thrust_from_velocity(TheirObj);
5597 //------------ Welcome them back if reconnecting --------------
5598 if (!Players[TheirPlayernum].connected) {
5599 Players[TheirPlayernum].connected = 1;
5601 if (Newdemo_state == ND_STATE_RECORDING)
5602 newdemo_record_multi_reconnect(TheirPlayernum);
5604 multi_make_ghost_player(TheirPlayernum);
5606 create_player_appearance_effect(&Objects[TheirObjnum]);
5608 digi_play_sample( SOUND_HUD_MESSAGE, F1_0);
5609 ClipRank (&NetPlayers.players[TheirPlayernum].rank);
5611 if (args_find("-norankings"))
5612 HUD_init_message( "'%s' %s", Players[TheirPlayernum].callsign, TXT_REJOIN );
5614 HUD_init_message( "%s'%s' %s", RankStrings[NetPlayers.players[TheirPlayernum].rank],Players[TheirPlayernum].callsign, TXT_REJOIN );
5620 //------------ Parse the extra data at the end ---------------
5622 if ( new_pd.data_size>0 ) {
5623 // pass pd->data to some parser function....
5624 multi_process_bigdata( new_pd.data, new_pd.data_size );
5630 void network_set_power (void)
5632 int opt=0,choice,opt_primary,opt_second,opt_power;
5636 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Laser upgrade"; m[opt].value=Netgame.DoLaserUpgrade; opt++;
5637 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Super lasers"; m[opt].value=Netgame.DoSuperLaser; opt++;
5638 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Quad Lasers"; m[opt].value=Netgame.DoQuadLasers; opt++;
5639 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Vulcan cannon"; m[opt].value=Netgame.DoVulcan; opt++;
5640 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Spreadfire cannon"; m[opt].value=Netgame.DoSpread; opt++;
5641 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Plasma cannon"; m[opt].value=Netgame.DoPlasma; opt++;
5642 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Fusion cannon"; m[opt].value=Netgame.DoFusions; opt++;
5643 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Gauss cannon"; m[opt].value=Netgame.DoGauss; opt++;
5644 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Helix cannon"; m[opt].value=Netgame.DoHelix; opt++;
5645 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Phoenix cannon"; m[opt].value=Netgame.DoPhoenix; opt++;
5646 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Omega cannon"; m[opt].value=Netgame.DoOmega; opt++;
5649 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Homing Missiles"; m[opt].value=Netgame.DoHoming; opt++;
5650 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Proximity Bombs"; m[opt].value=Netgame.DoProximity; opt++;
5651 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Smart Missiles"; m[opt].value=Netgame.DoSmarts; opt++;
5652 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Mega Missiles"; m[opt].value=Netgame.DoMegas; opt++;
5653 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Flash Missiles"; m[opt].value=Netgame.DoFlash; opt++;
5654 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Guided Missiles"; m[opt].value=Netgame.DoGuided; opt++;
5655 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Smart Mines"; m[opt].value=Netgame.DoSmartMine; opt++;
5656 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Mercury Missiles"; m[opt].value=Netgame.DoMercury; opt++;
5657 m[opt].type = NM_TYPE_CHECK; m[opt].text = "EarthShaker Missiles"; m[opt].value=Netgame.DoEarthShaker; opt++;
5660 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Invulnerability"; m[opt].value=Netgame.DoInvulnerability; opt++;
5661 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Cloaking"; m[opt].value=Netgame.DoCloak; opt++;
5662 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Afterburners"; m[opt].value=Netgame.DoAfterburner; opt++;
5663 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Ammo rack"; m[opt].value=Netgame.DoAmmoRack; opt++;
5664 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Energy Converter"; m[opt].value=Netgame.DoConverter; opt++;
5665 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Headlight"; m[opt].value=Netgame.DoHeadlight; opt++;
5667 choice = newmenu_do(NULL, "Objects to allow", opt, m, NULL);
5669 Netgame.DoLaserUpgrade=m[opt_primary].value;
5670 Netgame.DoSuperLaser=m[opt_primary+1].value;
5671 Netgame.DoQuadLasers=m[opt_primary+2].value;
5672 Netgame.DoVulcan=m[opt_primary+3].value;
5673 Netgame.DoSpread=m[opt_primary+4].value;
5674 Netgame.DoPlasma=m[opt_primary+5].value;
5675 Netgame.DoFusions=m[opt_primary+6].value;
5676 Netgame.DoGauss=m[opt_primary+7].value;
5677 Netgame.DoHelix=m[opt_primary+8].value;
5678 Netgame.DoPhoenix=m[opt_primary+9].value;
5679 Netgame.DoOmega=m[opt_primary+10].value;
5681 Netgame.DoHoming=m[opt_second].value;
5682 Netgame.DoProximity=m[opt_second+1].value;
5683 Netgame.DoSmarts=m[opt_second+2].value;
5684 Netgame.DoMegas=m[opt_second+3].value;
5685 Netgame.DoFlash=m[opt_second+4].value;
5686 Netgame.DoGuided=m[opt_second+5].value;
5687 Netgame.DoSmartMine=m[opt_second+6].value;
5688 Netgame.DoMercury=m[opt_second+7].value;
5689 Netgame.DoEarthShaker=m[opt_second+8].value;
5691 Netgame.DoInvulnerability=m[opt_power].value;
5692 Netgame.DoCloak=m[opt_power+1].value;
5693 Netgame.DoAfterburner=m[opt_power+2].value;
5694 Netgame.DoAmmoRack=m[opt_power+3].value;
5695 Netgame.DoConverter=m[opt_power+4].value;
5696 Netgame.DoHeadlight=m[opt_power+5].value;
5700 void SetAllAllowablesTo (int on)
5702 last_cinvul = control_invul_time = 0; //default to zero
5704 Netgame.DoMegas=Netgame.DoSmarts=Netgame.DoFusions=Netgame.DoHelix=\
5705 Netgame.DoPhoenix=Netgame.DoCloak=Netgame.DoInvulnerability=\
5706 Netgame.DoAfterburner=Netgame.DoGauss=Netgame.DoVulcan=Netgame.DoPlasma=on;
5708 Netgame.DoOmega=Netgame.DoSuperLaser=Netgame.DoProximity=\
5709 Netgame.DoSpread=Netgame.DoMercury=Netgame.DoSmartMine=Netgame.DoFlash=\
5710 Netgame.DoGuided=Netgame.DoEarthShaker=on;
5712 Netgame.DoConverter=Netgame.DoAmmoRack=Netgame.DoHeadlight=on;
5713 Netgame.DoHoming=Netgame.DoLaserUpgrade=Netgame.DoQuadLasers=on;
5714 Netgame.BrightPlayers=Netgame.invul=on;
5720 // Jeez -- mac compiler can't handle all of these on the same decl line.
5721 int opt_setpower,opt_playtime,opt_killgoal,opt_socket,opt_marker_view,opt_light,opt_show_on_map;
5722 int opt_difficulty,opt_packets,opt_short_packets, opt_bright,opt_start_invul;
5725 void network_more_options_poll( int nitems, newmenu_item * menus, int * key, int citem );
5727 void network_more_game_options ()
5730 char PlayText[80],KillText[80],srinvul[50],socket_string[5],packstring[5];
5733 sprintf (socket_string,"%d",Network_socket);
5734 sprintf (packstring,"%d",Netgame.PacketsPerSec);
5736 opt_difficulty = opt;
5737 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++;
5740 sprintf( srinvul, "%s: %d %s", TXT_REACTOR_LIFE, control_invul_time*5, TXT_MINUTES_ABBREV );
5741 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++;
5744 sprintf( PlayText, "Max time: %d %s", Netgame.PlayTimeAllowed*5, TXT_MINUTES_ABBREV );
5745 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++;
5748 sprintf( KillText, "Kill Goal: %d kills", Netgame.KillGoal*5);
5749 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++;
5751 opt_start_invul=opt;
5752 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Invulnerable when reappearing"; m[opt].value=Netgame.invul; opt++;
5754 opt_marker_view = opt;
5755 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Allow camera views from Markers"; m[opt].value=Netgame.Allow_marker_view; opt++;
5757 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Indestructible lights"; m[opt].value=Netgame.AlwaysLighting; opt++;
5760 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Bright player ships"; m[opt].value=Netgame.BrightPlayers; opt++;
5763 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Show enemy names on HUD"; m[opt].value=Netgame.ShowAllNames; opt++;
5765 opt_show_on_map=opt;
5766 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++;
5768 opt_short_packets=opt;
5769 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Short packets"; m[opt].value=Netgame.ShortPackets; opt++;
5772 m[opt].type = NM_TYPE_MENU; m[opt].text = "Set Objects allowed..."; opt++;
5774 if (Network_game_type == IPX_GAME) {
5775 m[opt].type = NM_TYPE_TEXT; m[opt].text = "Network socket"; opt++;
5777 m[opt].type = NM_TYPE_INPUT; m[opt].text = socket_string; m[opt].text_len=4; opt++;
5780 m[opt].type = NM_TYPE_TEXT; m[opt].text = "Packets per second (2 - 20)"; opt++;
5782 m[opt].type = NM_TYPE_INPUT; m[opt].text=packstring; m[opt].text_len=2; opt++;
5784 LastKillGoal=Netgame.KillGoal;
5785 LastPTA=Netgame.PlayTimeAllowed;
5789 ExtGameStatus=GAMESTAT_MORE_NETGAME_OPTIONS;
5790 i = newmenu_do1( NULL, "Additional netgame options", opt, m, network_more_options_poll, 0 );
5792 //control_invul_time = atoi( srinvul )*60*F1_0;
5793 control_invul_time = m[opt_cinvul].value;
5794 Netgame.control_invul_time = control_invul_time*5*F1_0*60;
5796 if (i==opt_setpower)
5798 network_set_power ();
5802 Netgame.PacketsPerSec=atoi(packstring);
5804 if (Netgame.PacketsPerSec>20)
5806 Netgame.PacketsPerSec=20;
5807 nm_messagebox(TXT_ERROR, 1, TXT_OK, "Packet value out of range\nSetting value to 20");
5809 if (Netgame.PacketsPerSec<2)
5811 nm_messagebox(TXT_ERROR, 1, TXT_OK, "Packet value out of range\nSetting value to 2");
5812 Netgame.PacketsPerSec=2;
5815 mprintf ((0,"Hey! Sending out %d packets per second\n",Netgame.PacketsPerSec));
5817 if (Network_game_type == IPX_GAME) {
5818 if ((atoi(socket_string))!=Network_socket) {
5819 Network_socket=atoi(socket_string);
5820 ipx_change_default_socket( IPX_DEFAULT_SOCKET + Network_socket );
5824 Netgame.invul=m[opt_start_invul].value;
5825 Netgame.BrightPlayers=m[opt_bright].value;
5826 Netgame.ShortPackets=m[opt_short_packets].value;
5827 Netgame.ShowAllNames=m[opt_show_names].value;
5828 network_AdjustMaxDataSize();
5830 Netgame.Allow_marker_view=m[opt_marker_view].value;
5831 Netgame.AlwaysLighting=m[opt_light].value;
5832 netgame_difficulty=Difficulty_level = m[opt_difficulty].value;
5833 if (m[opt_show_on_map].value)
5834 Netgame.game_flags |= NETGAME_FLAG_SHOW_MAP;
5839 void network_more_options_poll( int nitems, newmenu_item * menus, int * key, int citem )
5842 citem = citem; // kills compile warnings
5846 if ( last_cinvul != menus[opt_cinvul].value ) {
5847 sprintf( menus[opt_cinvul].text, "%s: %d %s", TXT_REACTOR_LIFE, menus[opt_cinvul].value*5, TXT_MINUTES_ABBREV );
5848 last_cinvul = menus[opt_cinvul].value;
5849 menus[opt_cinvul].redraw = 1;
5852 if (menus[opt_playtime].value!=LastPTA)
5856 nm_messagebox ("Sorry",1,TXT_OK,"Registered version only!");
5857 menus[opt_playtime].value=0;
5858 menus[opt_playtime].redraw=1;
5862 if (Game_mode & GM_MULTI_COOP)
5865 nm_messagebox ("Sorry",1,TXT_OK,"You can't change those for coop!");
5866 menus[opt_playtime].value=0;
5867 menus[opt_playtime].redraw=1;
5871 Netgame.PlayTimeAllowed=menus[opt_playtime].value;
5872 sprintf( menus[opt_playtime].text, "Max Time: %d %s", Netgame.PlayTimeAllowed*5, TXT_MINUTES_ABBREV );
5873 LastPTA=Netgame.PlayTimeAllowed;
5874 menus[opt_playtime].redraw=1;
5876 if (menus[opt_killgoal].value!=LastKillGoal)
5879 nm_messagebox ("Sorry",1,TXT_OK,"Registered version only!");
5880 menus[opt_killgoal].value=0;
5881 menus[opt_killgoal].redraw=1;
5887 if (Game_mode & GM_MULTI_COOP)
5889 nm_messagebox ("Sorry",1,TXT_OK,"You can't change those for coop!");
5890 menus[opt_killgoal].value=0;
5891 menus[opt_killgoal].redraw=1;
5897 Netgame.KillGoal=menus[opt_killgoal].value;
5898 sprintf( menus[opt_killgoal].text, "Kill Goal: %d kills", Netgame.KillGoal*5);
5899 LastKillGoal=Netgame.KillGoal;
5900 menus[opt_killgoal].redraw=1;
5904 extern void multi_send_light (int,ubyte);
5905 extern void multi_send_light_specific (int,int,ubyte);
5907 void network_send_smash_lights (int pnum)
5909 // send the lights that have been blown out
5915 for (i=0;i<=Highest_segment_index;i++)
5916 if (Light_subtracted[i])
5917 multi_send_light_specific(pnum,i,Light_subtracted[i]);
5920 extern int Num_triggers;
5921 extern void multi_send_trigger_specific (char pnum,char);
5923 void network_send_fly_thru_triggers (int pnum)
5925 // send the fly thru triggers that have been disabled
5929 for (i=0;i<Num_triggers;i++)
5930 if (Triggers[i].flags & TF_DISABLED)
5931 multi_send_trigger_specific(pnum,i);
5934 void network_send_player_flags()
5938 for (i=0;i<N_players;i++)
5939 multi_send_flags(i);
5942 void network_ping (ubyte flag,int pnum)
5947 mybuf[1]=Player_num;
5949 if (Network_game_type == IPX_GAME)
5950 ipx_send_packet_data( (ubyte *)mybuf, 2, NetPlayers.players[pnum].network.ipx.server, NetPlayers.players[pnum].network.ipx.node,Players[pnum].net_address );
5953 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);
5957 extern fix PingLaunchTime,PingReturnTime;
5959 void network_handle_ping_return (ubyte pnum)
5961 if (PingLaunchTime==0 || pnum>=N_players)
5963 mprintf ((0,"Got invalid PING RETURN from %s!\n",Players[pnum].callsign));
5967 PingReturnTime=timer_get_fixed_seconds();
5969 HUD_init_message ("Ping time for %s is %d ms!",Players[pnum].callsign,
5970 f2i(fixmul(PingReturnTime-PingLaunchTime,i2f(1000))));
5974 void network_send_ping (ubyte pnum)
5976 network_ping (PID_PING_SEND,pnum);
5979 void DoRefuseStuff (sequence_packet *their)
5981 int i,new_player_num;
5983 ClipRank (&their->player.rank);
5985 for (i=0;i<MAX_PLAYERS;i++)
5986 if (!strcmp (their->player.callsign,Players[i].callsign))
5988 network_welcome_player(their);
5992 if (!WaitForRefuseAnswer)
5994 for (i=0;i<MAX_PLAYERS;i++)
5995 if (!strcmp (their->player.callsign,Players[i].callsign))
5997 network_welcome_player(their);
6001 digi_play_sample (SOUND_HUD_JOIN_REQUEST,F1_0*2);
6003 if (Game_mode & GM_TEAM)
6007 if (!args_find("-norankings"))
6008 HUD_init_message ("%s %s wants to join",RankStrings[their->player.rank],their->player.callsign);
6010 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]);
6012 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]);
6014 // HUD_init_message ("Alt-1 to place on team %s!",Netgame.team_name[0]);
6015 // HUD_init_message ("Alt-2 to place on team %s!",Netgame.team_name[1]);
6018 HUD_init_message ("%s wants to join...press F6 to connect",their->player.callsign);
6020 strcpy (RefusePlayerName,their->player.callsign);
6021 RefuseTimeLimit=timer_get_approx_seconds();
6023 WaitForRefuseAnswer=1;
6027 for (i=0;i<MAX_PLAYERS;i++)
6028 if (!strcmp (their->player.callsign,Players[i].callsign))
6030 network_welcome_player(their);
6034 if (strcmp(their->player.callsign,RefusePlayerName))
6037 if (RefuseThisPlayer)
6041 WaitForRefuseAnswer=0;
6042 if (Game_mode & GM_TEAM)
6044 new_player_num=GetNewPlayerNumber (their);
6045 mprintf ((0,"Newplayernum=%d\n",new_player_num));
6047 Assert (RefuseTeam==1 || RefuseTeam==2);
6050 Netgame.team_vector &=(~(1<<new_player_num));
6052 Netgame.team_vector |=(1<<new_player_num);
6053 network_welcome_player(their);
6054 network_send_netgame_update ();
6057 network_welcome_player(their);
6061 if ((timer_get_approx_seconds()) > RefuseTimeLimit+REFUSE_INTERVAL)
6065 WaitForRefuseAnswer=0;
6066 if (!strcmp (their->player.callsign,RefusePlayerName)) {
6067 if (Network_game_type == IPX_GAME)
6068 network_dump_player(their->player.network.ipx.server,their->player.network.ipx.node, DUMP_DORK);
6071 network_dump_appletalk_player(their->player.network.appletalk.node,their->player.network.appletalk.net, their->player.network.appletalk.socket, DUMP_DORK);
6080 int GetNewPlayerNumber (sequence_packet *their)
6086 if ( N_players < MaxNumNetPlayers)
6091 // Slots are full but game is open, see if anyone is
6092 // disconnected and replace the oldest player with this new one
6094 int oldest_player = -1;
6095 fix oldest_time = timer_get_approx_seconds();
6097 Assert(N_players == MaxNumNetPlayers);
6099 for (i = 0; i < N_players; i++)
6101 if ( (!Players[i].connected) && (LastPacketTime[i] < oldest_time))
6103 oldest_time = LastPacketTime[i];
6107 return (oldest_player);
6111 void network_send_extras ()
6113 Assert (Player_joining_extras>-1);
6115 if (!network_i_am_master())
6117 mprintf ((0,"Hey! I'm not the master and I was gonna send info!\n"));
6119 // Network_sending_extras=0;
6124 if (Network_sending_extras==40)
6125 network_send_fly_thru_triggers(Player_joining_extras);
6126 if (Network_sending_extras==38)
6127 network_send_door_updates(Player_joining_extras);
6128 if (Network_sending_extras==35)
6129 network_send_markers();
6130 if (Network_sending_extras==30 && (Game_mode & GM_MULTI_ROBOTS))
6131 multi_send_stolen_items();
6132 if (Network_sending_extras==25 && (Netgame.PlayTimeAllowed || Netgame.KillGoal))
6133 multi_send_kill_goal_counts();
6134 if (Network_sending_extras==20)
6135 network_send_smash_lights(Player_joining_extras);
6136 if (Network_sending_extras==15)
6137 network_send_player_flags();
6138 if (Network_sending_extras==10)
6139 multi_send_powerup_update();
6140 // if (Network_sending_extras==5)
6141 // network_send_door_updates(Player_joining_extras); // twice!
6143 Network_sending_extras--;
6144 if (!Network_sending_extras)
6145 Player_joining_extras=-1;
6149 void network_send_naked_packet(char *buf, short len, int who)
6151 if (!(Game_mode&GM_NETWORK)) return;
6153 if (NakedPacketLen==0)
6155 NakedBuf[0]=PID_NAKED_PDATA;
6156 NakedBuf[1]=Player_num;
6160 if (len+NakedPacketLen>MaxXDataSize)
6162 // mprintf ((0,"Sending a naked packet of %d bytes.\n",NakedPacketLen));
6163 if (Network_game_type == IPX_GAME)
6164 ipx_send_packet_data( (ubyte *)NakedBuf, NakedPacketLen, NetPlayers.players[who].network.ipx.server, NetPlayers.players[who].network.ipx.node,Players[who].net_address );
6167 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 );
6170 memcpy (&NakedBuf[NakedPacketLen],buf,len);
6171 NakedPacketLen+=len;
6172 NakedPacketDestPlayer=who;
6176 memcpy (&NakedBuf[NakedPacketLen],buf,len);
6177 NakedPacketLen+=len;
6178 NakedPacketDestPlayer=who;
6183 void network_process_naked_pdata (char *data,int len)
6186 Assert (data[0]=PID_NAKED_PDATA);
6188 // mprintf ((0,"Processing a naked packet of %d length.\n",len));
6191 mprintf ((0,"Naked packet is bad!\n"));
6192 Int3(); // This packet is bogus!!
6196 if (!multi_quit_game && (pnum >= N_players)) {
6197 if (Network_status!=NETSTAT_WAITING)
6199 Int3(); // We missed an important packet!
6200 network_consistency_error();
6207 if (Endlevel_sequence || (Network_status == NETSTAT_ENDLEVEL) ) {
6208 int old_Endlevel_sequence = Endlevel_sequence;
6209 Endlevel_sequence = 1;
6210 multi_process_bigdata( data+2, len-2);
6211 Endlevel_sequence = old_Endlevel_sequence;
6215 multi_process_bigdata( data+2, len-2 );
6218 int ConnectionPacketLevel[]={0,1,1,1};
6219 int ConnectionSecLevel[]={12,3,5,7};
6221 int AppletalkConnectionPacketLevel[]={0,1,0};
6222 int AppletalkConnectionSecLevel[]={10,3,8};
6224 #if defined(RELEASE) && !defined(MACINTOSH) // use the code below for mac appletalk games
6225 int network_choose_connect ()
6230 int network_choose_connect ()
6237 if (Network_game_type == IPX_GAME) {
6239 m[opt].type = NM_TYPE_MENU; m[opt].text = "Local Subnet"; opt++;
6240 m[opt].type = NM_TYPE_MENU; m[opt].text = "14.4 modem over Internet"; opt++;
6241 m[opt].type = NM_TYPE_MENU; m[opt].text = "28.8 modem over Internet"; opt++;
6242 m[opt].type = NM_TYPE_MENU; m[opt].text = "ISDN or T1 over Internet"; opt++;
6244 choice = newmenu_do1( NULL, "Choose connection type", opt, m, NULL, 0 );
6249 Assert (choice>=0 && choice<=3);
6251 Netgame.ShortPackets=ConnectionPacketLevel[choice];
6252 Netgame.PacketsPerSec=ConnectionSecLevel[choice];
6257 m[opt].type = NM_TYPE_MENU; m[opt].text = "EtherTalk"; opt++;
6258 m[opt].type = NM_TYPE_MENU; m[opt].text = "LocalTalk"; opt++;
6259 m[opt].type = NM_TYPE_MENU; m[opt].text = "Other"; opt++;
6261 choice = newmenu_do1( NULL, "Choose connection type", opt, m, NULL, 0 );
6266 Network_appletalk_type = choice;
6268 Assert (choice>=0 && choice<=2);
6270 Netgame.ShortPackets=AppletalkConnectionPacketLevel[choice];
6271 Netgame.PacketsPerSec=AppletalkConnectionSecLevel[choice];
6285 SendLogFile=(FILE *)fopen ("sendlog.net","w");
6289 void OpenRecieveLog ()
6292 RecieveLogFile=(FILE *)fopen ("recvlog.net","w");
6298 int GetMyNetRanking ()
6303 if (Netlife_kills+Netlife_killed==0)
6306 rank=(int) (((float)Netlife_kills/3000.0)*8.0);
6308 eff=(int)((float)((float)Netlife_kills/((float)Netlife_killed+(float)Netlife_kills))*100.0);
6317 rank-=((59-eff)/10);
6324 mprintf ((0,"Rank is %d (%s)\n",rank+1,RankStrings[rank+1]));
6328 void ClipRank (signed char *rank)
6330 // This function insures no crashes when dealing with D2 1.0
6333 if (*rank<0 || *rank>9)
6336 void network_check_for_old_version (char pnum)
6338 if (NetPlayers.players[(int)pnum].version_major==1 && (NetPlayers.players[(int)pnum].version_minor & 0x0F)==0)
6339 NetPlayers.players[(int)pnum].rank=0;
6342 void network_request_player_names (int n)
6344 network_send_all_info_request (PID_GAME_PLAYERS,Active_games[n].Security);
6345 NamesInfoSecurity=Active_games[n].Security;
6348 extern char already_showing_info;
6349 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));
6351 void network_process_names_return (char *data)
6354 char mtext[15][50],temp[50];
6355 int i,t,l,gnum,num=0,count=5,numplayers;
6357 if (NamesInfoSecurity!=(*(int *)(data+1)))
6359 mprintf ((0,"Bad security on names return!\n"));
6360 mprintf ((0,"NIS=%d data=%d\n",NamesInfoSecurity,(*(int *)(data+1))));
6364 numplayers=data[count]; count++;
6366 if (numplayers==255)
6369 NamesInfoSecurity=-1;
6370 nm_messagebox(NULL, 1, "OK", "That game is refusing\nname requests.\n");
6375 Assert (numplayers>0 && numplayers<MAX_NUM_NET_PLAYERS);
6379 m[i].text=(char *)&mtext[i];
6380 m[i].type=NM_TYPE_TEXT;
6383 for (gnum=-1,i=0;i<num_active_games;i++)
6385 if (NamesInfoSecurity==Active_games[i].Security)
6395 NamesInfoSecurity=-1;
6396 nm_messagebox(NULL, 1, "OK", "The game you have requested\nnames from is gone.\n");
6401 sprintf (mtext[num],"Players of game '%s':",Active_games[gnum].game_name); num++;
6402 for (i=0;i<numplayers;i++)
6406 mprintf ((0,"%s\n",data+count));
6408 for (t=0;t<CALLSIGN_LEN+1;t++)
6409 temp[t]=data[count++];
6410 if (args_find("-norankings"))
6411 sprintf (mtext[num],"%s",temp);
6413 sprintf (mtext[num],"%s%s",RankStrings[l],temp);
6418 if (data[count]==99)
6420 sprintf (mtext[num++]," ");
6421 sprintf (mtext[num++],"Short packets: %s",data[count+1]?"On":"Off");
6422 sprintf (mtext[num++],"Packets Per Second: %d",data[count+2]);
6425 already_showing_info=1;
6426 newmenu_dotiny2( NULL, NULL, num, m, NULL);
6427 already_showing_info=0;
6430 char NameReturning=1;
6432 void network_send_player_names (sequence_packet *their)
6434 int numconnected=0,count=0,i,t;
6439 mprintf ((0,"Got a player name without a return address! Get Jason\n"));
6443 buf[0]=PID_NAMES_RETURN; count++;
6444 (*(int *)(buf+1))=Netgame.Security; count+=4;
6448 buf[count]=255; count++;
6452 mprintf ((0,"RealSec=%d DS=%d\n",Netgame.Security,*(int *)(buf+1)));
6454 for (i=0;i<N_players;i++)
6455 if (Players[i].connected)
6458 buf[count]=numconnected; count++;
6459 for (i=0;i<N_players;i++)
6460 if (Players[i].connected)
6462 buf[count++]=NetPlayers.players[i].rank;
6464 for (t=0;t<CALLSIGN_LEN+1;t++)
6466 buf[count]=NetPlayers.players[i].callsign[t];
6472 buf[count++]=Netgame.ShortPackets;
6473 buf[count++]=Netgame.PacketsPerSec;
6476 ; // empty statement allows compilation on mac which does not have the
6477 // statement below and kills the compiler when there is no
6478 // statement following the label "sendit"
6481 ipx_send_internetwork_packet_data((ubyte *)buf, count, their->player.network.ipx.server, their->player.network.ipx.node);
6486 extern int file_exists (char *);
6488 int HoardEquipped ()
6490 static int checked=-1;
6498 if (file_exists ("hoard.ham"))