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.
19 static char rcsid[] = "$Id: network.c,v 1.5 2001-10-19 00:31:51 bradleyb Exp $";
73 #include <Errors.h> // for appletalk networking errors
77 void network_send_rejoin_sync(int player_num);
78 void network_update_netgame(void);
79 void network_read_endlevel_packet( ubyte *data );
80 void network_read_object_packet( ubyte *data );
81 void network_read_sync_packet( netgame_info * sp, int d1x );
83 void network_listen();
84 void network_read_pdata_packet(frame_info *pd );
86 void network_check_for_old_version (char pnum);
87 void network_send_endlevel_short_sub(int from_player_num,int to_player);
88 int network_wait_for_playerinfo();
89 void network_process_pdata (char *data);
90 void network_read_endlevel_short_packet( ubyte *data );
91 void network_ping (ubyte flag,int pnum);
92 void network_handle_ping_return (ubyte pnum);
93 void network_process_names_return (char *data);
94 void network_send_player_names (sequence_packet *their);
95 int network_choose_connect ();
96 void network_more_game_options ();
97 void network_count_powerups_in_mine(void);
98 int network_wait_for_all_info (int choice);
99 void network_do_big_wait(int choice);
100 void network_send_extras ();
101 void network_read_pdata_short_packet(short_frame_info *pd );
103 void network_AdjustMaxDataSize ();
105 void ClipRank (signed char *rank);
106 void DoRefuseStuff (sequence_packet *their);
107 void SetAllAllowablesTo (int on);
108 int GetNewPlayerNumber (sequence_packet *their);
110 #define LHX(x) ((x)*(MenuHires?2:1))
111 #define LHY(y) ((y)*(MenuHires?2.4:1))
113 #define PID_LITE_INFO 43
114 #define PID_SEND_ALL_GAMEINFO 44
115 #define PID_PLAYERSINFO 45
116 #define PID_REQUEST 46
119 #define PID_ADDPLAYER 49
121 #define PID_ENDLEVEL 52
122 #define PID_QUIT_JOINING 54
123 #define PID_OBJECT_DATA 55
124 #define PID_GAME_LIST 56
125 #define PID_GAME_INFO 57
126 #define PID_PING_SEND 58
127 #define PID_PING_RETURN 59
128 #define PID_GAME_UPDATE 60
129 #define PID_ENDLEVEL_SHORT 61
130 #define PID_NAKED_PDATA 62
131 #define PID_GAME_PLAYERS 63
132 #define PID_NAMES_RETURN 64
134 #define NETGAME_ANARCHY 0
135 #define NETGAME_TEAM_ANARCHY 1
136 #define NETGAME_ROBOT_ANARCHY 2
137 #define NETGAME_COOPERATIVE 3
138 #define NETGAME_CAPTURE_FLAG 4
139 #define NETGAME_HOARD 5
140 #define NETGAME_TEAM_HOARD 6
142 #define NETSECURITY_OFF 0
143 #define NETSECURITY_WAIT_FOR_PLAYERS 1
144 #define NETSECURITY_WAIT_FOR_GAMEINFO 2
145 #define NETSECURITY_WAIT_FOR_SYNC 3
147 // MWA -- these structures are aligned -- please save me sanity and
148 // headaches by keeping alignment if these are changed!!!! Contact
151 typedef struct endlevel_info {
156 short kill_matrix[MAX_PLAYERS][MAX_PLAYERS];
161 typedef struct endlevel_info_short {
166 } endlevel_info_short;
168 // WARNING!!! This is the top part of netgame_info...if that struct changes,
169 // this struct much change as well. ie...they are aligned and the join system will
170 // not work without it.
172 // MWA if this structure changes -- please make appropriate changes to receive_netgame_info
173 // code for macintosh in netmisc.c
175 typedef struct lite_info {
178 char game_name[NETGAME_NAME_LEN+1];
179 char mission_title[MISSION_NAME_LEN+1];
180 char mission_name[9];
187 ubyte max_numplayers;
190 ubyte protocol_version;
196 // IF YOU CHANGE THE SIZE OF ANY OF THE FOLLOWING STRUCTURES
197 // MAKE THE MACINTOSH DEFINES BE THE SAME SIZE AS THE PC OR
198 // I WILL HAVE TO HURT YOU VERY BADLY!!! -- MWA
201 #define NETGAME_INFO_SIZE ( Network_game_type == IPX_GAME?355:sizeof(netgame_info) )
202 #define ALLNETPLAYERSINFO_SIZE ( Network_game_type == IPX_GAME?317:sizeof(AllNetPlayers_info) )
203 #define LITE_INFO_SIZE ( Network_game_type == IPX_GAME?72:sizeof(lite_info) )
204 #define SEQUENCE_PACKET_SIZE ( Network_game_type == IPX_GAME?34:sizeof(sequence_packet) )
205 #define FRAME_INFO_SIZE ( Network_game_type == IPX_GAME?541:sizeof(frame_info) )
206 #define IPX_SHORT_INFO_SIZE ( 490 )
208 #define NETGAME_INFO_SIZE sizeof(netgame_info)
209 #define ALLNETPLAYERSINFO_SIZE sizeof(AllNetPlayers_info)
210 #define LITE_INFO_SIZE sizeof(lite_info)
211 #define SEQUENCE_PACKET_SIZE sizeof(sequence_packet)
212 #define FRAME_INFO_SIZE sizeof(frame_info)
215 #define MAX_ACTIVE_NETGAMES 12
217 netgame_info Active_games[MAX_ACTIVE_NETGAMES];
218 AllNetPlayers_info ActiveNetPlayers[MAX_ACTIVE_NETGAMES];
219 AllNetPlayers_info *TempPlayersInfo,TempPlayersBase;
220 int NamesInfoSecurity=-1;
222 // MWAnetgame_info *TempNetInfo;
223 netgame_info TempNetInfo;
225 extern void multi_send_drop_marker (int player,vms_vector position,char messagenum,char text[]);
226 extern void multi_send_kill_goal_counts();
227 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) );
229 void network_process_naked_pdata (char *,int);
230 extern void multi_send_robot_controls(char);
232 int num_active_games = 0;
233 int PacketsPerSec=10;
234 int MaxXDataSize=NET_XDATA_SIZE;
236 int Netlife_kills=0, Netlife_killed=0;
239 int Network_active=0;
241 int Network_status = 0;
242 int Network_games_changed = 0;
244 int Network_socket = 0;
245 int Network_allow_socket_changes = 1;
247 int Network_initial_pps = 10;
248 int Network_initial_shortpackets = 0;
250 int NetSecurityFlag=NETSECURITY_OFF;
251 int NetSecurityNum=0;
252 int Network_sending_extras=0;
253 int VerifyPlayerJoined=-1;
254 int Player_joining_extras=-1; // This is so we know who to send 'latecomer' packets to.
255 // We could just send updates to everyone but that kills the sender!
257 // For rejoin object syncing
259 int Network_rejoined = 0; // Did WE rejoin this game?
260 int Network_new_game = 0; // Is this the first level of a new game?
261 int Network_send_objects = 0; // Are we in the process of sending objects to a player?
262 int Network_send_objnum = -1; // What object are we sending next?
263 int Network_player_added = 0; // Is this a new player or a returning player?
264 int Network_send_object_mode = 0; // What type of objects are we sending, static or dynamic?
265 sequence_packet Network_player_rejoining; // Who is rejoining now?
267 fix LastPacketTime[MAX_PLAYERS]; // For timeouts of idle/crashed players
269 int PacketUrgent = 0;
271 int TotalMissedPackets=0,TotalPacketsGot=0;
273 frame_info MySyncPack,UrgentSyncPack;
274 ubyte MySyncPackInitialized = 0; // Set to 1 if the MySyncPack is zeroed.
275 ushort my_segments_checksum = 0;
277 sequence_packet My_Seq;
278 char WantPlayersInfo=0;
279 char WaitingForPlayerInfo=0;
281 char *RankStrings[]={"(unpatched) ","Cadet ","Ensign ","Lieutenant ","Lt.Commander ",
282 "Commander ","Captain ","Vice Admiral ","Admiral ","Demigod "};
284 extern obj_position Player_init[MAX_PLAYERS];
286 extern int force_cockpit_redraw;
288 #define DUMP_CLOSED 0
290 #define DUMP_ENDLEVEL 2
292 #define DUMP_ABORTED 4
293 #define DUMP_CONNECTED 5
295 #define DUMP_KICKED 7
297 extern ubyte Version_major,Version_minor;
298 extern ubyte SurfingNet;
299 extern char MaxPowerupsAllowed[MAX_POWERUP_TYPES];
300 extern char PowerupsInMine[MAX_POWERUP_TYPES];
302 extern void multi_send_stolen_items();
304 int network_wait_for_snyc();
305 extern void multi_send_wall_status (int,ubyte,ubyte,ubyte);
306 extern void multi_send_wall_status_specific (int,int,ubyte,ubyte,ubyte);
308 extern void game_disable_cheats();
311 FILE *SendLogFile,*RecieveLogFile;
312 int TTSent[100],TTRecv[100];
314 extern int Final_boss_is_dead;
316 // following is network stuff for appletalk
318 void network_dump_appletalk_player(ubyte node, ushort net, ubyte socket, int why);
320 #define NETWORK_OEM 0x10
324 int Network_game_type; // used to tell IPX vs. appletalk games
326 #define MAX_ZONES 255
327 #define MAX_ZONE_LENGTH 33
328 #define DEFAULT_ZONE_NAME "\p*"
329 #define MAX_REGISTER_TRIES 5 // maximum time we will try and register a netgame
330 char Network_zone_name[MAX_ZONE_LENGTH]; // zone name game being played in for appletalk
331 char Zone_names[MAX_ZONES][MAX_ZONE_LENGTH]; // total list of zones that we can see
332 ubyte appletalk_use_broadcast = 0;
333 ubyte Network_game_validated = 0; // validates a game before being able to join
334 ubyte Network_game_validate_choice = 0;
335 ubyte Network_appletalk_type = 0; // type of appletalk network game is being played on
337 #define ETHERTALK_TYPE 0
338 #define LOCALTALK_TYPE 1
339 #define OTHERTALK_TYPE 2
342 void network_release_registered_game(void);
350 // So you want to play a netgame, eh? Let's a get a few things
354 int save_pnum = Player_num;
356 game_disable_cheats();
358 Final_boss_is_dead=0;
359 NamesInfoSecurity=-1;
367 for (t=0;t<MAX_POWERUP_TYPES;t++)
369 MaxPowerupsAllowed[t]=0;
373 TotalMissedPackets=0; TotalPacketsGot=0;
375 memset(&Netgame, 0, sizeof(netgame_info));
376 memset(&NetPlayers,0,sizeof(AllNetPlayers_info));
377 memset(&My_Seq, 0, sizeof(sequence_packet));
378 My_Seq.type = PID_REQUEST;
379 memcpy(My_Seq.player.callsign, Players[Player_num].callsign, CALLSIGN_LEN+1);
382 Version_minor|=NETWORK_OEM;
385 My_Seq.player.version_major=Version_major;
386 My_Seq.player.version_minor=Version_minor;
387 My_Seq.player.rank=GetMyNetRanking();
389 if (Network_game_type == IPX_GAME) {
390 memcpy(My_Seq.player.network.ipx.node, ipx_get_my_local_address(), 6);
391 memcpy(My_Seq.player.network.ipx.server, ipx_get_my_server_address(), 4 );
394 My_Seq.player.network.appletalk.node = appletalk_get_my_node();
395 My_Seq.player.network.appletalk.net = appletalk_get_my_net();
396 My_Seq.player.network.appletalk.socket = appletalk_get_my_socket();
400 My_Seq.player.computer_type = MAC;
402 My_Seq.player.computer_type = DOS;
405 for (Player_num = 0; Player_num < MAX_NUM_NET_PLAYERS; Player_num++)
406 init_player_stats_game();
408 Player_num = save_pnum;
410 Network_new_game = 1;
411 Control_center_destroyed = 0;
414 Netgame.PacketsPerSec=10;
416 if ((t=FindArg("-packets")))
418 Netgame.PacketsPerSec=atoi(Args[t+1]);
419 if (Netgame.PacketsPerSec<1)
420 Netgame.PacketsPerSec=1;
421 else if (Netgame.PacketsPerSec>20)
422 Netgame.PacketsPerSec=20;
423 mprintf ((0,"Will send %d packets per second",Netgame.PacketsPerSec));
425 if (FindArg("-shortpackets"))
427 Netgame.ShortPackets=1;
428 mprintf ((0,"Will send short packets.\n"));
433 network_i_am_master(void)
435 // I am the lowest numbered player in this game?
439 if (!(Game_mode & GM_NETWORK))
440 return (Player_num == 0);
442 for (i = 0; i < Player_num; i++)
443 if (Players[i].connected)
448 network_who_is_master(void)
450 // Who is the master of this game?
454 if (!(Game_mode & GM_NETWORK))
455 return (Player_num == 0);
457 for (i = 0; i < N_players; i++)
458 if (Players[i].connected)
462 int network_how_many_connected()
466 for (i = 0; i < N_players; i++)
467 if (Players[i].connected)
472 #define ENDLEVEL_SEND_INTERVAL (F1_0*2)
473 #define ENDLEVEL_IDLE_TIME (F1_0*20)
476 network_endlevel_poll( int nitems, newmenu_item * menus, int * key, int citem )
478 // Polling loop for End-of-level menu
486 int previous_state[MAX_NUM_NET_PLAYERS];
487 int previous_seconds_left;
494 // Send our endlevel packet at regular intervals
496 if (timer_get_approx_seconds() > (t1+ENDLEVEL_SEND_INTERVAL))
498 network_send_endlevel_packet();
499 t1 = timer_get_approx_seconds();
502 for (i = 0; i < N_players; i++)
503 previous_state[i] = Players[i].connected;
505 previous_seconds_left = Countdown_seconds_left;
509 for (i = 0; i < N_players; i++)
511 if (Players[i].connected == 1)
513 // Check timeout for idle players
514 if (timer_get_approx_seconds() > LastPacketTime[i]+ENDLEVEL_IDLE_TIME)
516 mprintf((0, "idle timeout for player %d.\n", i));
517 Players[i].connected = 0;
518 network_send_endlevel_sub(i);
522 if ((Players[i].connected != 1) && (Players[i].connected != 5) && (Players[i].connected != 6))
524 if (Players[i].connected != 1)
526 if (Players[i].connected == 4)
530 if (num_escaped == N_players) // All players are out of the mine
532 Countdown_seconds_left = -1;
536 if (num_ready == N_players) // All players have checked in or are disconnected
546 network_endlevel_poll2( int nitems, newmenu_item * menus, int * key, int citem )
548 // Polling loop for End-of-level menu
560 // Send our endlevel packet at regular intervals
562 if (timer_get_approx_seconds() > (t1+ENDLEVEL_SEND_INTERVAL))
564 network_send_endlevel_packet();
565 t1 = timer_get_approx_seconds();
568 // mprintf ((0,"Trying to listen!\n"));
571 for (i = 0; i < N_players; i++)
573 if ((Players[i].connected != 1) && (Players[i].connected != 5) && (Players[i].connected != 6))
575 if (Players[i].connected == 4)
579 if (num_ready == N_players) // All players have checked in or are disconnected
589 extern fix StartAbortMenuTime;
592 network_endlevel_poll3( int nitems, newmenu_item * menus, int * key, int citem )
594 // Polling loop for End-of-level menu
603 if (timer_get_approx_seconds() > (StartAbortMenuTime+(F1_0 * 8)))
610 for (i = 0; i < N_players; i++)
611 if ((Players[i].connected != 1) && (Players[i].connected != 5) && (Players[i].connected != 6))
614 if (num_ready == N_players) // All players have checked in or are disconnected
621 network_endlevel(int *secret)
623 // Do whatever needs to be done between levels
631 Network_status = NETSTAT_ENDLEVEL; // We are between levels
635 network_send_endlevel_packet();
637 for (i=0; i<N_players; i++)
639 LastPacketTime[i] = timer_get_approx_seconds();
642 network_send_endlevel_packet();
643 network_send_endlevel_packet();
644 MySyncPackInitialized = 0;
646 network_update_netgame();
652 can_join_netgame(netgame_info *game,AllNetPlayers_info *people)
654 // Can this player rejoin a netgame in progress?
658 if (game->game_status == NETSTAT_STARTING)
661 if (game->game_status != NETSTAT_PLAYING)
663 mprintf ((0,"Error: Can't join because game_status !=NETSTAT_PLAYING\n"));
667 if (game->version_major==0 && Version_major>0)
669 mprintf ((0,"Error:Can't join because version majors don't match!\n"));
673 if (game->version_major>0 && Version_major==0)
675 mprintf ((0,"Error:Can't join because version majors2 don't match!\n"));
679 // Game is in progress, figure out if this guy can re-join it
681 num_players = game->numplayers;
683 if (!(game->game_flags & NETGAME_FLAG_CLOSED)) {
684 // Look for player that is not connected
686 if (game->numconnected==game->max_numplayers)
689 // mprintf ((0,"Refuse = %d\n",game->RefusePlayers));
691 if (game->RefusePlayers)
694 if (game->numplayers < game->max_numplayers)
697 if (game->numconnected<num_players)
704 mprintf ((0,"Error! Can't join because people==NULL!\n"));
708 // Search to see if we were already in this closed netgame in progress
710 for (i = 0; i < num_players; i++) {
711 if (Network_game_type == IPX_GAME) {
712 if ( (!stricmp(Players[Player_num].callsign, people->players[i].callsign)) &&
713 (!memcmp(My_Seq.player.network.ipx.node, people->players[i].network.ipx.node, 6)) &&
714 (!memcmp(My_Seq.player.network.ipx.server, people->players[i].network.ipx.server, 4)) )
717 if ( (!stricmp(Players[Player_num].callsign, people->players[i].callsign)) &&
718 (My_Seq.player.network.appletalk.node == people->players[i].network.appletalk.node) &&
719 (My_Seq.player.network.appletalk.net == people->players[i].network.appletalk.net) )
724 if (i != num_players)
727 mprintf ((0,"Error: Can't join because at end of list!\n"));
732 network_disconnect_player(int playernum)
734 // A player has disconnected from the net game, take whatever steps are
737 if (playernum == Player_num)
739 Int3(); // Weird, see Rob
743 Players[playernum].connected = 0;
744 NetPlayers.players[playernum].connected = 0;
745 if (VerifyPlayerJoined==playernum)
746 VerifyPlayerJoined=-1;
748 // create_player_appearance_effect(&Objects[Players[playernum].objnum]);
749 multi_make_player_ghost(playernum);
751 if (Newdemo_state == ND_STATE_RECORDING)
752 newdemo_record_multi_disconnect(playernum);
754 multi_strip_robots(playernum);
758 network_new_player(sequence_packet *their)
763 pnum = their->player.connected;
766 Assert(pnum < MaxNumNetPlayers);
768 objnum = Players[pnum].objnum;
770 if (Newdemo_state == ND_STATE_RECORDING) {
773 if (pnum == N_players)
777 newdemo_record_multi_connect(pnum, new_player, their->player.callsign);
780 memcpy(Players[pnum].callsign, their->player.callsign, CALLSIGN_LEN+1);
781 memcpy(NetPlayers.players[pnum].callsign, their->player.callsign, CALLSIGN_LEN+1);
784 ClipRank (&their->player.rank);
785 NetPlayers.players[pnum].rank=their->player.rank;
786 NetPlayers.players[pnum].version_major=their->player.version_major;
787 NetPlayers.players[pnum].version_minor=their->player.version_minor;
788 network_check_for_old_version(pnum);
790 if (Network_game_type == IPX_GAME) {
791 if ( (*(uint *)their->player.network.ipx.server) != 0 )
792 ipx_get_local_target( their->player.network.ipx.server, their->player.network.ipx.node, Players[pnum].net_address );
794 memcpy(Players[pnum].net_address, their->player.network.ipx.node, 6);
796 memcpy(NetPlayers.players[pnum].network.ipx.node, their->player.network.ipx.node, 6);
797 memcpy(NetPlayers.players[pnum].network.ipx.server, their->player.network.ipx.server, 4);
799 NetPlayers.players[pnum].network.appletalk.node = their->player.network.appletalk.node;
800 NetPlayers.players[pnum].network.appletalk.net = their->player.network.appletalk.net;
801 NetPlayers.players[pnum].network.appletalk.socket = their->player.network.appletalk.socket;
804 Players[pnum].n_packets_got = 0;
805 Players[pnum].connected = 1;
806 Players[pnum].net_kills_total = 0;
807 Players[pnum].net_killed_total = 0;
808 memset(kill_matrix[pnum], 0, MAX_PLAYERS*sizeof(short));
809 Players[pnum].score = 0;
810 Players[pnum].flags = 0;
811 Players[pnum].KillGoalCount=0;
813 if (pnum == N_players)
816 Netgame.numplayers = N_players;
819 digi_play_sample(SOUND_HUD_MESSAGE, F1_0);
821 ClipRank (&their->player.rank);
823 if (FindArg("-norankings"))
824 HUD_init_message("'%s' %s\n",their->player.callsign, TXT_JOINING);
826 HUD_init_message("%s'%s' %s\n",RankStrings[their->player.rank],their->player.callsign, TXT_JOINING);
828 multi_make_ghost_player(pnum);
831 multi_sort_kill_list();
833 // create_player_appearance_effect(&Objects[objnum]);
836 char RefuseThisPlayer=0,WaitForRefuseAnswer=0,RefuseTeam;
837 char RefusePlayerName[12];
838 fix RefuseTimeLimit=0;
840 void network_welcome_player(sequence_packet *their)
842 // Add a player to a game already in progress
843 ubyte local_address[6];
847 WaitForRefuseAnswer=0;
849 if (FindArg("-NoMatrixCheat"))
851 if (their->player.version_minor & (0x0F<3))
853 network_dump_player(their->player.network.ipx.server, their->player.network.ipx.node, DUMP_DORK);
860 // If hoard game, and this guy isn't D2 Christmas (v1.2), dump him
862 if ((Game_mode & GM_HOARD) && ((their->player.version_minor & 0x0F)<2))
864 if (Network_game_type == IPX_GAME)
865 network_dump_player(their->player.network.ipx.server, their->player.network.ipx.node, DUMP_DORK);
868 network_dump_appletalk_player(their->player.network.appletalk.node, their->player.network.appletalk.net, their->player.network.appletalk.socket, DUMP_DORK);
874 // Don't accept new players if we're ending this level. Its safe to
875 // ignore since they'll request again later
877 if ((Endlevel_sequence) || (Control_center_destroyed))
879 mprintf((0, "Ignored request from new player to join during endgame.\n"));
880 if (Network_game_type == IPX_GAME)
881 network_dump_player(their->player.network.ipx.server,their->player.network.ipx.node, DUMP_ENDLEVEL);
884 network_dump_appletalk_player(their->player.network.appletalk.node, their->player.network.appletalk.net, their->player.network.appletalk.socket, DUMP_ENDLEVEL);
889 if (Network_send_objects || Network_sending_extras)
891 // Ignore silently, we're already responding to someone and we can't
892 // do more than one person at a time. If we don't dump them they will
893 // re-request in a few seconds.
897 if (their->player.connected != Current_level_num)
899 mprintf((0, "Dumping player due to old level number.\n"));
900 if (Network_game_type == IPX_GAME)
901 network_dump_player(their->player.network.ipx.server, their->player.network.ipx.node, DUMP_LEVEL);
904 network_dump_appletalk_player(their->player.network.appletalk.node, their->player.network.appletalk.net, their->player.network.appletalk.socket, DUMP_LEVEL);
910 memset(&Network_player_rejoining, 0, sizeof(sequence_packet));
911 Network_player_added = 0;
913 if (Network_game_type == IPX_GAME) {
914 if ( (*(uint *)their->player.network.ipx.server) != 0 )
915 ipx_get_local_target( their->player.network.ipx.server, their->player.network.ipx.node, local_address );
917 memcpy(local_address, their->player.network.ipx.node, 6);
920 for (i = 0; i < N_players; i++)
922 if ( (Network_game_type == IPX_GAME) && (!stricmp(Players[i].callsign, their->player.callsign )) && (!memcmp(Players[i].net_address,local_address, 6)) )
927 #ifdef MACINTOSH // note link to above if
928 else if ( (!stricmp(Players[i].callsign, their->player.callsign)) &&
929 (NetPlayers.players[i].network.appletalk.node == their->player.network.appletalk.node) &&
930 (NetPlayers.players[i].network.appletalk.net == their->player.network.appletalk.net)) {
937 if (player_num == -1)
939 // Player is new to this game
941 if ( !(Netgame.game_flags & NETGAME_FLAG_CLOSED) && (N_players < MaxNumNetPlayers))
943 // Add player in an open slot, game not full yet
945 player_num = N_players;
946 Network_player_added = 1;
948 else if (Netgame.game_flags & NETGAME_FLAG_CLOSED)
950 // Slots are open but game is closed
952 if (Network_game_type == IPX_GAME)
953 network_dump_player(their->player.network.ipx.server, their->player.network.ipx.node, DUMP_CLOSED);
956 network_dump_appletalk_player(their->player.network.appletalk.node, their->player.network.appletalk.net, their->player.network.appletalk.socket, DUMP_CLOSED);
962 // Slots are full but game is open, see if anyone is
963 // disconnected and replace the oldest player with this new one
965 int oldest_player = -1;
966 fix oldest_time = timer_get_approx_seconds();
968 Assert(N_players == MaxNumNetPlayers);
970 for (i = 0; i < N_players; i++)
972 if ( (!Players[i].connected) && (LastPacketTime[i] < oldest_time))
974 oldest_time = LastPacketTime[i];
979 if (oldest_player == -1)
981 // Everyone is still connected
983 if (Network_game_type == IPX_GAME)
984 network_dump_player(their->player.network.ipx.server, their->player.network.ipx.node, DUMP_FULL);
987 network_dump_appletalk_player(their->player.network.appletalk.node, their->player.network.appletalk.net, their->player.network.appletalk.socket, DUMP_FULL);
995 player_num = oldest_player;
996 Network_player_added = 1;
1002 // Player is reconnecting
1004 if (Players[player_num].connected)
1006 mprintf((0, "Extra REQUEST from player ignored.\n"));
1010 if (Newdemo_state == ND_STATE_RECORDING)
1011 newdemo_record_multi_reconnect(player_num);
1013 Network_player_added = 0;
1015 digi_play_sample(SOUND_HUD_MESSAGE, F1_0);
1017 if (FindArg("-norankings"))
1018 HUD_init_message("'%s' %s", Players[player_num].callsign, TXT_REJOIN);
1020 HUD_init_message("%s'%s' %s", RankStrings[NetPlayers.players[player_num].rank],Players[player_num].callsign, TXT_REJOIN);
1023 Players[player_num].KillGoalCount=0;
1025 // Send updated Objects data to the new/returning player
1028 Network_player_rejoining = *their;
1029 Network_player_rejoining.player.connected = player_num;
1030 Network_send_objects = 1;
1031 Network_send_objnum = -1;
1033 network_send_objects();
1036 int network_objnum_is_past(int objnum)
1038 // determine whether or not a given object number has already been sent
1039 // to a re-joining player.
1041 int player_num = Network_player_rejoining.player.connected;
1042 int obj_mode = !((object_owner[objnum] == -1) || (object_owner[objnum] == player_num));
1044 if (!Network_send_objects)
1045 return 0; // We're not sending objects to a new player
1047 if (obj_mode > Network_send_object_mode)
1049 else if (obj_mode < Network_send_object_mode)
1051 else if (objnum < Network_send_objnum)
1057 #define OBJ_PACKETS_PER_FRAME 1
1058 extern void multi_send_active_door(char);
1059 extern void multi_send_door_open_specific(int,int,int,ubyte);
1062 void network_send_door_updates(int pnum)
1064 // Send door status when new player joins
1070 // Assert (pnum>-1 && pnum<N_players);
1072 for (i = 0; i < Num_walls; i++)
1074 if ((Walls[i].type == WALL_DOOR) && ((Walls[i].state == WALL_DOOR_OPENING) || (Walls[i].state == WALL_DOOR_WAITING) || (Walls[i].state == WALL_DOOR_OPEN)))
1075 multi_send_door_open_specific(pnum,Walls[i].segnum, Walls[i].sidenum,Walls[i].flags);
1076 else if ((Walls[i].type == WALL_BLASTABLE) && (Walls[i].flags & WALL_BLASTED))
1077 multi_send_door_open_specific(pnum,Walls[i].segnum, Walls[i].sidenum,Walls[i].flags);
1078 else if ((Walls[i].type == WALL_BLASTABLE) && (Walls[i].hps != WALL_HPS))
1079 multi_send_hostage_door_status(i);
1081 multi_send_wall_status_specific(pnum,i,Walls[i].type,Walls[i].flags,Walls[i].state);
1085 extern vms_vector MarkerPoint[];
1086 void network_send_markers()
1088 // send marker positions/text to new player
1095 if (MarkerObject[(i*2)]!=-1)
1096 multi_send_drop_marker (i,MarkerPoint[(i*2)],0,MarkerMessage[i*2]);
1097 if (MarkerObject[(i*2)+1]!=-1)
1098 multi_send_drop_marker (i,MarkerPoint[(i*2)+1],1,MarkerMessage[(i*2)+1]);
1102 void network_process_monitor_vector(int vector)
1108 for (i=0; i <= Highest_segment_index; i++)
1112 for (j = 0; j < 6; j++)
1114 if ( ((tm = seg->sides[j].tmap_num2) != 0) &&
1115 ((ec = TmapInfo[tm&0x3fff].eclip_num) != -1) &&
1116 ((bm = Effects[ec].dest_bm_num) != -1) )
1118 if (vector & (1 << count))
1120 seg->sides[j].tmap_num2 = bm | (tm&0xc000);
1121 // mprintf((0, "Monitor %d blown up.\n", count));
1124 // mprintf((0, "Monitor %d intact.\n", count));
1132 int network_create_monitor_vector(void)
1135 int num_blown_bitmaps = 0;
1136 int monitor_num = 0;
1137 #define NUM_BLOWN_BITMAPS 20
1138 int blown_bitmaps[NUM_BLOWN_BITMAPS];
1142 for (i=0; i < Num_effects; i++)
1144 if (Effects[i].dest_bm_num > 0) {
1145 for (j = 0; j < num_blown_bitmaps; j++)
1146 if (blown_bitmaps[j] == Effects[i].dest_bm_num)
1148 if (j == num_blown_bitmaps) {
1149 blown_bitmaps[num_blown_bitmaps++] = Effects[i].dest_bm_num;
1150 Assert(num_blown_bitmaps < NUM_BLOWN_BITMAPS);
1155 // for (i = 0; i < num_blown_bitmaps; i++)
1156 // mprintf((0, "Blown bitmap #%d = %d.\n", i, blown_bitmaps[i]));
1158 for (i=0; i <= Highest_segment_index; i++)
1162 for (j = 0; j < 6; j++)
1164 if ((tm = seg->sides[j].tmap_num2) != 0)
1166 if ( ((ec = TmapInfo[tm&0x3fff].eclip_num) != -1) &&
1167 (Effects[ec].dest_bm_num != -1) )
1169 // mprintf((0, "Monitor %d intact.\n", monitor_num));
1171 Assert(monitor_num < 32);
1175 for (k = 0; k < num_blown_bitmaps; k++)
1177 if ((tm&0x3fff) == blown_bitmaps[k])
1179 //mprintf((0, "Monitor %d destroyed.\n", monitor_num));
1180 vector |= (1 << monitor_num);
1182 Assert(monitor_num < 32);
1190 // mprintf((0, "Final monitor vector %x.\n", vector));
1194 void network_stop_resync(sequence_packet *their)
1196 if (Network_game_type == IPX_GAME) {
1197 if ( (!memcmp(Network_player_rejoining.player.network.ipx.node, their->player.network.ipx.node, 6)) &&
1198 (!memcmp(Network_player_rejoining.player.network.ipx.server, their->player.network.ipx.server, 4)) &&
1199 (!stricmp(Network_player_rejoining.player.callsign, their->player.callsign)) )
1201 mprintf((0, "Aborting resync for player %s.\n", their->player.callsign));
1202 Network_send_objects = 0;
1203 Network_sending_extras=0;
1205 Player_joining_extras=-1;
1206 Network_send_objnum = -1;
1209 if ( (Network_player_rejoining.player.network.appletalk.node == their->player.network.appletalk.node) &&
1210 (Network_player_rejoining.player.network.appletalk.net == their->player.network.appletalk.net) &&
1211 (!stricmp(Network_player_rejoining.player.callsign, their->player.callsign)) )
1213 mprintf((0, "Aborting resync for player %s.\n", their->player.callsign));
1214 Network_send_objects = 0;
1215 Network_sending_extras=0;
1217 Player_joining_extras=-1;
1218 Network_send_objnum = -1;
1223 byte object_buffer[IPX_MAX_DATA_SIZE];
1225 void network_send_objects(void)
1227 short remote_objnum;
1231 static int obj_count = 0;
1232 static int frame_num = 0;
1234 int obj_count_frame = 0;
1235 int player_num = Network_player_rejoining.player.connected;
1237 // Send clear objects array trigger and send player num
1239 Assert(Network_send_objects != 0);
1240 Assert(player_num >= 0);
1241 Assert(player_num < MaxNumNetPlayers);
1243 if (Endlevel_sequence || Control_center_destroyed)
1245 // Endlevel started before we finished sending the goods, we'll
1246 // have to stop and try again after the level.
1248 if (Network_game_type == IPX_GAME)
1249 network_dump_player(Network_player_rejoining.player.network.ipx.server,Network_player_rejoining.player.network.ipx.node, DUMP_ENDLEVEL);
1252 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);
1254 Network_send_objects = 0;
1258 for (h = 0; h < OBJ_PACKETS_PER_FRAME; h++) // Do more than 1 per frame, try to speed it up without
1259 // over-stressing the receiver.
1261 obj_count_frame = 0;
1262 memset(object_buffer, 0, IPX_MAX_DATA_SIZE);
1263 object_buffer[0] = PID_OBJECT_DATA;
1266 if (Network_send_objnum == -1)
1269 Network_send_object_mode = 0;
1270 // mprintf((0, "Sending object array to player %d.\n", player_num));
1271 *(short *)(object_buffer+loc) = INTEL_SHORT(-1); loc += 2;
1272 object_buffer[loc] = player_num; loc += 1;
1273 loc += 2; // Placeholder for remote_objnum, not used here
1274 Network_send_objnum = 0;
1275 obj_count_frame = 1;
1279 for (i = Network_send_objnum; i <= Highest_object_index; i++)
1281 if ((Objects[i].type != OBJ_POWERUP) && (Objects[i].type != OBJ_PLAYER) &&
1282 (Objects[i].type != OBJ_CNTRLCEN) && (Objects[i].type != OBJ_GHOST) &&
1283 (Objects[i].type != OBJ_ROBOT) && (Objects[i].type != OBJ_HOSTAGE) &&
1284 !(Objects[i].type==OBJ_WEAPON && Objects[i].id==PMINE_ID))
1286 if ((Network_send_object_mode == 0) && ((object_owner[i] != -1) && (object_owner[i] != player_num)))
1288 if ((Network_send_object_mode == 1) && ((object_owner[i] == -1) || (object_owner[i] == player_num)))
1291 if ( ((IPX_MAX_DATA_SIZE-1) - loc) < (sizeof(object)+5) )
1292 break; // Not enough room for another object
1297 remote_objnum = objnum_local_to_remote((short)i, &owner);
1298 Assert(owner == object_owner[i]);
1300 *(short *)(object_buffer+loc) = INTEL_SHORT((short)i); loc += 2;
1301 object_buffer[loc] = owner; loc += 1;
1302 *(short *)(object_buffer+loc) = INTEL_SHORT(remote_objnum); loc += 2;
1304 memcpy(object_buffer+loc, &Objects[i], sizeof(object)); loc += sizeof(object);
1306 if (Network_game_type == IPX_GAME) {
1309 memcpy(&tmpobj, &(Objects[i]), sizeof(object));
1310 swap_object(&tmpobj);
1311 memcpy(&(object_buffer[loc]), &tmpobj, sizeof(object)); loc += sizeof(object);
1314 memcpy(object_buffer+loc, &Objects[i], sizeof(object)); loc += sizeof(object);
1316 // mprintf((0, "..packing object %d, remote %d\n", i, remote_objnum));
1319 if (obj_count_frame) // Send any objects we've buffered
1323 Network_send_objnum = i;
1324 object_buffer[1] = obj_count_frame; object_buffer[2] = frame_num;
1325 // mprintf((0, "Object packet %d contains %d objects.\n", frame_num, obj_count_frame));
1327 Assert(loc <= IPX_MAX_DATA_SIZE);
1329 if (Network_game_type == IPX_GAME)
1330 ipx_send_internetwork_packet_data( object_buffer, loc, Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node );
1333 appletalk_send_packet_data( object_buffer, loc, Network_player_rejoining.player.network.appletalk.node,
1334 Network_player_rejoining.player.network.appletalk.net,
1335 Network_player_rejoining.player.network.appletalk.socket);
1338 // OLD ipx_send_packet_data(object_buffer, loc, &Network_player_rejoining.player.node);
1341 if (i > Highest_object_index)
1343 if (Network_send_object_mode == 0)
1345 Network_send_objnum = 0;
1346 Network_send_object_mode = 1; // go to next mode
1350 Assert(Network_send_object_mode == 1);
1353 // Send count so other side can make sure he got them all
1354 // mprintf((0, "Sending end marker in packet #%d.\n", frame_num));
1355 mprintf((0, "Sent %d objects.\n", obj_count));
1356 object_buffer[0] = PID_OBJECT_DATA;
1357 object_buffer[1] = 1;
1358 object_buffer[2] = frame_num;
1359 *(short *)(object_buffer+3) = INTEL_SHORT(-2);
1360 *(short *)(object_buffer+6) = INTEL_SHORT(obj_count);
1361 //OLD ipx_send_packet_data(object_buffer, 8, &Network_player_rejoining.player.node);
1362 if (Network_game_type == IPX_GAME)
1363 ipx_send_internetwork_packet_data(object_buffer, 8, Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node);
1366 appletalk_send_packet_data( object_buffer, 8, Network_player_rejoining.player.network.appletalk.node,
1367 Network_player_rejoining.player.network.appletalk.net,
1368 Network_player_rejoining.player.network.appletalk.socket);
1372 // Send sync packet which tells the player who he is and to start!
1373 network_send_rejoin_sync(player_num);
1374 mprintf ((0,"VerfiyPlayerJoined is now set to %d\n",player_num));
1375 VerifyPlayerJoined=player_num;
1377 // Turn off send object mode
1378 Network_send_objnum = -1;
1379 Network_send_objects = 0;
1382 //if (!network_i_am_master ())
1383 // Int3(); // Bad!! Get Jason. Someone goofy is trying to get ahold of the game!
1385 Network_sending_extras=40; // start to send extras
1386 Player_joining_extras=player_num;
1390 } // i > Highest_object_index
1391 } // For PACKETS_PER_FRAME
1394 extern void multi_send_powerup_update();
1396 void network_send_rejoin_sync(int player_num)
1400 Players[player_num].connected = 1; // connect the new guy
1401 LastPacketTime[player_num] = timer_get_approx_seconds();
1403 if (Endlevel_sequence || Control_center_destroyed)
1405 // Endlevel started before we finished sending the goods, we'll
1406 // have to stop and try again after the level.
1408 if (Network_game_type == IPX_GAME)
1409 network_dump_player(Network_player_rejoining.player.network.ipx.server,Network_player_rejoining.player.network.ipx.node, DUMP_ENDLEVEL);
1412 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);
1414 Network_send_objects = 0;
1415 Network_sending_extras=0;
1419 if (Network_player_added)
1421 Network_player_rejoining.type = PID_ADDPLAYER;
1422 Network_player_rejoining.player.connected = player_num;
1423 network_new_player(&Network_player_rejoining);
1425 for (i = 0; i < N_players; i++)
1427 if ((i != player_num) && (i != Player_num) && (Players[i].connected))
1428 if (Network_game_type == IPX_GAME) {
1430 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);
1432 send_sequence_packet( Network_player_rejoining, NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node, Players[i].net_address);
1436 appletalk_send_packet_data( (ubyte *)&Network_player_rejoining, sizeof(sequence_packet), NetPlayers.players[i].network.appletalk.node,
1437 NetPlayers.players[i].network.appletalk.net, NetPlayers.players[i].network.appletalk.socket);
1443 // Send sync packet to the new guy
1445 network_update_netgame();
1447 // Fill in the kill list
1448 for (j=0; j<MAX_PLAYERS; j++)
1450 for (i=0; i<MAX_PLAYERS;i++)
1451 Netgame.kills[j][i] = kill_matrix[j][i];
1452 Netgame.killed[j] = Players[j].net_killed_total;
1453 Netgame.player_kills[j] = Players[j].net_kills_total;
1454 Netgame.player_score[j] = Players[j].score;
1457 Netgame.level_time = Players[Player_num].time_level;
1458 Netgame.monitor_vector = network_create_monitor_vector();
1460 mprintf((0, "Sending rejoin sync packet!!!\n"));
1462 if (Network_game_type == IPX_GAME) {
1464 ipx_send_internetwork_packet_data( (ubyte *)&Netgame, sizeof(netgame_info), Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node );
1465 ipx_send_internetwork_packet_data( (ubyte *)&NetPlayers, sizeof(AllNetPlayers_info), Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node );
1467 send_netgame_packet(Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node, NULL, 0);
1468 send_netplayers_packet(Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node);
1472 appletalk_send_packet_data( (ubyte *)&Netgame, sizeof(netgame_info), Network_player_rejoining.player.network.appletalk.node,
1473 Network_player_rejoining.player.network.appletalk.net,
1474 Network_player_rejoining.player.network.appletalk.socket);
1475 appletalk_send_packet_data( (ubyte *)&NetPlayers, sizeof(AllNetPlayers_info), Network_player_rejoining.player.network.appletalk.node,
1476 Network_player_rejoining.player.network.appletalk.net,
1477 Network_player_rejoining.player.network.appletalk.socket);
1482 void resend_sync_due_to_packet_loss_for_allender ()
1486 mprintf ((0,"I'm resending a sync packet! VPJ=%d\n",VerifyPlayerJoined));
1488 network_update_netgame();
1490 // Fill in the kill list
1491 for (j=0; j<MAX_PLAYERS; j++)
1493 for (i=0; i<MAX_PLAYERS;i++)
1494 Netgame.kills[j][i] = kill_matrix[j][i];
1495 Netgame.killed[j] = Players[j].net_killed_total;
1496 Netgame.player_kills[j] = Players[j].net_kills_total;
1497 Netgame.player_score[j] = Players[j].score;
1500 Netgame.level_time = Players[Player_num].time_level;
1501 Netgame.monitor_vector = network_create_monitor_vector();
1503 if (Network_game_type == IPX_GAME) {
1505 ipx_send_internetwork_packet_data( (ubyte *)&Netgame, sizeof(netgame_info), Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node );
1506 ipx_send_internetwork_packet_data( (ubyte *)&NetPlayers, sizeof(AllNetPlayers_info), Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node );
1508 send_netgame_packet(Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node, NULL, 0);
1509 send_netplayers_packet(Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node);
1513 appletalk_send_packet_data( (ubyte *)&Netgame, sizeof(netgame_info), Network_player_rejoining.player.network.appletalk.node,
1514 Network_player_rejoining.player.network.appletalk.net,
1515 Network_player_rejoining.player.network.appletalk.socket);
1516 appletalk_send_packet_data( (ubyte *)&NetPlayers, sizeof(AllNetPlayers_info), Network_player_rejoining.player.network.appletalk.node,
1517 Network_player_rejoining.player.network.appletalk.net,
1518 Network_player_rejoining.player.network.appletalk.socket);
1524 char * network_get_player_name( int objnum )
1526 if ( objnum < 0 ) return NULL;
1527 if ( Objects[objnum].type != OBJ_PLAYER ) return NULL;
1528 if ( Objects[objnum].id >= MAX_PLAYERS ) return NULL;
1529 if ( Objects[objnum].id >= N_players ) return NULL;
1531 return Players[Objects[objnum].id].callsign;
1535 void network_add_player(sequence_packet *p)
1539 mprintf((0, "Got add player request!\n"));
1541 for (i=0; i<N_players; i++ ) {
1542 if (Network_game_type == IPX_GAME) {
1543 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))
1544 return; // already got them
1546 if ( (NetPlayers.players[i].network.appletalk.node == p->player.network.appletalk.node) &&
1547 (NetPlayers.players[i].network.appletalk.net == p->player.network.appletalk.net))
1552 if (Network_game_type == IPX_GAME) {
1553 memcpy( NetPlayers.players[N_players].network.ipx.node, p->player.network.ipx.node, 6 );
1554 memcpy( NetPlayers.players[N_players].network.ipx.server, p->player.network.ipx.server, 4 );
1556 NetPlayers.players[N_players].network.appletalk.node = p->player.network.appletalk.node;
1557 NetPlayers.players[N_players].network.appletalk.net = p->player.network.appletalk.net;
1558 NetPlayers.players[N_players].network.appletalk.socket = p->player.network.appletalk.socket;
1561 ClipRank (&p->player.rank);
1563 memcpy( NetPlayers.players[N_players].callsign, p->player.callsign, CALLSIGN_LEN+1 );
1564 NetPlayers.players[N_players].version_major=p->player.version_major;
1565 NetPlayers.players[N_players].version_minor=p->player.version_minor;
1566 NetPlayers.players[N_players].rank=p->player.rank;
1567 NetPlayers.players[N_players].connected = 1;
1568 network_check_for_old_version (N_players);
1570 Players[N_players].KillGoalCount=0;
1571 Players[N_players].connected = 1;
1572 LastPacketTime[N_players] = timer_get_approx_seconds();
1574 Netgame.numplayers = N_players;
1576 // Broadcast updated info
1578 mprintf ((0,"sending_game_info!\n"));
1579 network_send_game_info(NULL);
1582 // One of the players decided not to join the game
1584 void network_remove_player(sequence_packet *p)
1589 for (i=0; i<N_players; i++ ) {
1590 if (Network_game_type == IPX_GAME) {
1591 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)) {
1596 if ( (NetPlayers.players[i].network.appletalk.node == p->player.network.appletalk.node) && (NetPlayers.players[i].network.appletalk.net == p->player.network.appletalk.net) ) {
1603 if (pn < 0 ) return;
1605 for (i=pn; i<N_players-1; i++ ) {
1606 if (Network_game_type == IPX_GAME) {
1607 memcpy( NetPlayers.players[i].network.ipx.node, NetPlayers.players[i+1].network.ipx.node, 6 );
1608 memcpy( NetPlayers.players[i].network.ipx.server, NetPlayers.players[i+1].network.ipx.server, 4 );
1610 NetPlayers.players[i].network.appletalk.node = NetPlayers.players[i+1].network.appletalk.node;
1611 NetPlayers.players[i].network.appletalk.net = NetPlayers.players[i+1].network.appletalk.net;
1612 NetPlayers.players[i].network.appletalk.socket = NetPlayers.players[i+1].network.appletalk.socket;
1614 memcpy( NetPlayers.players[i].callsign, NetPlayers.players[i+1].callsign, CALLSIGN_LEN+1 );
1615 NetPlayers.players[i].version_major=NetPlayers.players[i+1].version_major;
1616 NetPlayers.players[i].version_minor=NetPlayers.players[i+1].version_minor;
1618 NetPlayers.players[i].rank=NetPlayers.players[i+1].rank;
1619 ClipRank (&NetPlayers.players[i].rank);
1620 network_check_for_old_version(i);
1624 Netgame.numplayers = N_players;
1626 // Broadcast new info
1628 network_send_game_info(NULL);
1633 network_dump_player(ubyte * server, ubyte *node, int why)
1635 // Inform player that he was not chosen for the netgame
1637 sequence_packet temp;
1639 temp.type = PID_DUMP;
1640 memcpy(temp.player.callsign, Players[Player_num].callsign, CALLSIGN_LEN+1);
1641 temp.player.connected = why;
1642 if (Network_game_type == IPX_GAME) {
1644 ipx_send_internetwork_packet_data( (ubyte *)&temp, sizeof(sequence_packet), server, node);
1646 send_sequence_packet( temp, server, node, NULL);
1654 void network_dump_appletalk_player(ubyte node, ushort net, ubyte socket, int why)
1656 sequence_packet temp;
1658 temp.type = PID_DUMP;
1659 memcpy(temp.player.callsign, Players[Player_num].callsign, CALLSIGN_LEN+1);
1660 temp.player.connected = why;
1661 if (Network_game_type == APPLETALK_GAME) {
1662 appletalk_send_packet_data( (ubyte *)&temp, sizeof(sequence_packet), node, net, socket );
1670 network_send_game_list_request()
1672 // Send a broadcast request for game info
1676 mprintf((0, "Sending game_list request.\n"));
1677 me.type = PID_GAME_LIST;
1678 memcpy( me.player.callsign, Players[Player_num].callsign, CALLSIGN_LEN+1 );
1680 if (Network_game_type == IPX_GAME) {
1681 memcpy( me.player.network.ipx.node, ipx_get_my_local_address(), 6 );
1682 memcpy( me.player.network.ipx.server, ipx_get_my_server_address(), 4 );
1685 ipx_send_broadcast_packet_data( (ubyte *)&me, sizeof(sequence_packet) );
1687 send_sequence_packet( me, NULL, NULL, NULL);
1691 me.player.network.appletalk.node = appletalk_get_my_node();
1692 me.player.network.appletalk.net = appletalk_get_my_net();
1693 me.player.network.appletalk.socket = appletalk_get_my_socket();
1694 appletalk_send_game_info( (ubyte *)&me, sizeof(sequence_packet), Network_zone_name );
1699 void network_send_all_info_request(char type,int which_security)
1701 // Send a broadcast request for game info
1705 mprintf((0, "Sending all_info request.\n"));
1707 me.Security=which_security;
1709 memcpy( me.player.callsign, Players[Player_num].callsign, CALLSIGN_LEN+1 );
1711 if (Network_game_type == IPX_GAME) {
1712 memcpy( me.player.network.ipx.node, ipx_get_my_local_address(), 6 );
1713 memcpy( me.player.network.ipx.server, ipx_get_my_server_address(), 4 );
1716 ipx_send_broadcast_packet_data( (ubyte *)&me, sizeof(sequence_packet) );
1718 send_sequence_packet(me, NULL, NULL, NULL);
1722 me.player.network.appletalk.node = appletalk_get_my_node();
1723 me.player.network.appletalk.net = appletalk_get_my_net();
1724 me.player.network.appletalk.socket = appletalk_get_my_socket();
1725 appletalk_send_game_info( (ubyte *)&me, sizeof(sequence_packet), Network_zone_name );
1732 network_update_netgame(void)
1734 // Update the netgame struct with current game variables
1738 Netgame.numconnected=0;
1739 for (i=0;i<N_players;i++)
1740 if (Players[i].connected)
1741 Netgame.numconnected++;
1743 // This is great: D2 1.0 and 1.1 ignore upper part of the game_flags field of
1744 // the lite_info struct when you're sitting on the join netgame screen. We can
1745 // "sneak" Hoard information into this field. This is better than sending
1746 // another packet that could be lost in transit.
1749 if (HoardEquipped())
1751 if (Game_mode & GM_HOARD)
1753 Netgame.game_flags |=NETGAME_FLAG_HOARD;
1754 if (Game_mode & GM_TEAM)
1755 Netgame.game_flags |=NETGAME_FLAG_TEAM_HOARD;
1759 if (Network_status == NETSTAT_STARTING)
1762 Netgame.numplayers = N_players;
1763 Netgame.game_status = Network_status;
1764 Netgame.max_numplayers = MaxNumNetPlayers;
1766 for (i = 0; i < MAX_NUM_NET_PLAYERS; i++)
1768 NetPlayers.players[i].connected = Players[i].connected;
1769 for(j = 0; j < MAX_NUM_NET_PLAYERS; j++)
1770 Netgame.kills[i][j] = kill_matrix[i][j];
1772 Netgame.killed[i] = Players[i].net_killed_total;
1773 Netgame.player_kills[i] = Players[i].net_kills_total;
1774 Netgame.player_score[i] = Players[i].score;
1775 Netgame.player_flags[i] = (Players[i].flags & (PLAYER_FLAGS_BLUE_KEY | PLAYER_FLAGS_RED_KEY | PLAYER_FLAGS_GOLD_KEY));
1777 Netgame.team_kills[0] = team_kills[0];
1778 Netgame.team_kills[1] = team_kills[1];
1779 Netgame.levelnum = Current_level_num;
1785 network_send_endlevel_sub(int player_num)
1790 // Send an endlevel packet for a player
1791 end.type = PID_ENDLEVEL;
1792 end.player_num = player_num;
1793 end.connected = Players[player_num].connected;
1794 end.kills = INTEL_SHORT(Players[player_num].net_kills_total);
1795 end.killed = INTEL_SHORT(Players[player_num].net_killed_total);
1796 memcpy(end.kill_matrix, kill_matrix[player_num], MAX_PLAYERS*sizeof(short));
1798 for (i = 0; i < MAX_PLAYERS; i++)
1799 for (j = 0; j < MAX_PLAYERS; j++)
1800 end.kill_matrix[i][j] = INTEL_SHORT(end.kill_matrix[i][j]);
1802 j = j; // to satisfy compiler
1805 if (Players[player_num].connected == 1) // Still playing
1807 Assert(Control_center_destroyed);
1808 end.seconds_left = Countdown_seconds_left;
1811 // mprintf((0, "Sending endlevel packet.\n"));
1813 for (i = 0; i < N_players; i++)
1815 if ((i != Player_num) && (i!=player_num) && (Players[i].connected)) {
1816 if (Players[i].connected==1)
1817 network_send_endlevel_short_sub(player_num,i);
1819 if (Network_game_type == IPX_GAME)
1820 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);
1823 appletalk_send_packet_data( (ubyte *)&end, sizeof(endlevel_info), NetPlayers.players[i].network.appletalk.node,
1824 NetPlayers.players[i].network.appletalk.net,
1825 NetPlayers.players[i].network.appletalk.socket);
1833 network_send_endlevel_packet(void)
1835 // Send an updated endlevel status to other hosts
1837 network_send_endlevel_sub(Player_num);
1842 network_send_endlevel_short_sub(int from_player_num,int to_player)
1844 endlevel_info_short end;
1846 // Send an endlevel packet for a player
1847 end.type = PID_ENDLEVEL_SHORT;
1848 end.player_num = from_player_num;
1849 end.connected = Players[from_player_num].connected;
1850 end.seconds_left = Countdown_seconds_left;
1853 if (Players[from_player_num].connected == 1) // Still playing
1855 Assert(Control_center_destroyed);
1858 if ((to_player != Player_num) && (to_player!=from_player_num) && (Players[to_player].connected))
1860 mprintf((0, "Sending short endlevel packet to %s.\n",Players[to_player].callsign));
1861 if (Network_game_type == IPX_GAME)
1862 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);
1865 appletalk_send_packet_data( (ubyte *)&end, sizeof(endlevel_info_short), NetPlayers.players[to_player].network.appletalk.node,
1866 NetPlayers.players[to_player].network.appletalk.net,
1867 NetPlayers.players[to_player].network.appletalk.socket);
1872 extern fix ThisLevelTime;
1875 network_send_game_info(sequence_packet *their)
1877 // Send game info to someone who requested it
1879 char old_type, old_status;
1883 mprintf((0, "Sending game info.\n"));
1885 network_update_netgame(); // Update the values in the netgame struct
1887 old_type = Netgame.type;
1888 old_status = Netgame.game_status;
1890 Netgame.type = PID_GAME_INFO;
1891 NetPlayers.type = PID_PLAYERSINFO;
1893 NetPlayers.Security=Netgame.Security;
1894 Netgame.version_major=Version_major;
1895 Netgame.version_minor=Version_minor;
1897 if (Endlevel_sequence || Control_center_destroyed)
1898 Netgame.game_status = NETSTAT_ENDLEVEL;
1900 if (Netgame.PlayTimeAllowed)
1902 timevar=i2f (Netgame.PlayTimeAllowed*5*60);
1903 i=f2i(timevar-ThisLevelTime);
1905 Netgame.game_status=NETSTAT_ENDLEVEL;
1909 if (Network_game_type == IPX_GAME) {
1911 ipx_send_broadcast_packet_data((ubyte *)&Netgame, sizeof(netgame_info));
1912 ipx_send_broadcast_packet_data((ubyte *)&NetPlayers,sizeof(AllNetPlayers_info));
1914 send_netgame_packet(NULL, NULL, NULL, 0); // server == NULL says to broadcast packet
1915 send_netplayers_packet(NULL, NULL);
1917 } // nothing to do for appletalk games I think....
1919 if (Network_game_type == IPX_GAME) {
1921 ipx_send_internetwork_packet_data((ubyte *)&Netgame, sizeof(netgame_info), their->player.network.ipx.server, their->player.network.ipx.node);
1922 ipx_send_internetwork_packet_data((ubyte *)&NetPlayers,sizeof(AllNetPlayers_info),their->player.network.ipx.server,their->player.network.ipx.node);
1924 send_netgame_packet(their->player.network.ipx.server, their->player.network.ipx.node, NULL, 0);
1925 send_netplayers_packet(their->player.network.ipx.server, their->player.network.ipx.node);
1929 appletalk_send_packet_data( (ubyte *)&Netgame, sizeof(netgame_info), their->player.network.appletalk.node,
1930 their->player.network.appletalk.net, their->player.network.appletalk.socket );
1931 appletalk_send_packet_data( (ubyte *)&NetPlayers, sizeof(AllNetPlayers_info), their->player.network.appletalk.node,
1932 their->player.network.appletalk.net, their->player.network.appletalk.socket );
1937 Netgame.type = old_type;
1938 Netgame.game_status = old_status;
1941 void network_send_lite_info(sequence_packet *their)
1943 // Send game info to someone who requested it
1945 char old_type, old_status,oldstatus;
1947 mprintf((0, "Sending lite game info.\n"));
1949 network_update_netgame(); // Update the values in the netgame struct
1951 old_type = Netgame.type;
1952 old_status = Netgame.game_status;
1954 Netgame.type = PID_LITE_INFO;
1956 if (Endlevel_sequence || Control_center_destroyed)
1957 Netgame.game_status = NETSTAT_ENDLEVEL;
1959 // If hoard mode, make this game look closed even if it isn't
1960 if (HoardEquipped())
1962 if (Game_mode & GM_HOARD)
1964 oldstatus=Netgame.game_status;
1965 Netgame.game_status=NETSTAT_ENDLEVEL;
1966 Netgame.gamemode=NETGAME_CAPTURE_FLAG;
1967 if (oldstatus==NETSTAT_ENDLEVEL)
1968 Netgame.game_flags|=NETGAME_FLAG_REALLY_ENDLEVEL;
1969 if (oldstatus==NETSTAT_STARTING)
1970 Netgame.game_flags|=NETGAME_FLAG_REALLY_FORMING;
1975 if (Network_game_type == IPX_GAME) {
1977 ipx_send_broadcast_packet_data((ubyte *)&Netgame, sizeof(lite_info));
1979 send_netgame_packet(NULL, NULL, NULL, 1); // server == NULL says broadcast
1981 } // nothing to do for appletalk I think....
1983 if (Network_game_type == IPX_GAME) {
1985 ipx_send_internetwork_packet_data((ubyte *)&Netgame, sizeof(lite_info), their->player.network.ipx.server, their->player.network.ipx.node);
1987 send_netgame_packet(their->player.network.ipx.server, their->player.network.ipx.node, NULL, 1);
1991 appletalk_send_packet_data( (ubyte *)&Netgame, sizeof(lite_info), their->player.network.appletalk.node,
1992 their->player.network.appletalk.net, their->player.network.appletalk.socket );
1997 // Restore the pre-hoard mode
1998 if (HoardEquipped())
2000 if (Game_mode & GM_HOARD)
2002 if (!(Game_mode & GM_TEAM))
2003 Netgame.gamemode=NETGAME_HOARD;
2005 Netgame.gamemode=NETGAME_TEAM_HOARD;
2006 Netgame.game_flags&=~NETGAME_FLAG_REALLY_ENDLEVEL;
2007 Netgame.game_flags&=~NETGAME_FLAG_REALLY_FORMING;
2008 Netgame.game_flags&=~NETGAME_FLAG_TEAM_HOARD;
2012 Netgame.type = old_type;
2013 Netgame.game_status = old_status;
2017 void network_send_netgame_update()
2019 // Send game info to someone who requested it
2021 char old_type, old_status;
2024 mprintf((0, "Sending updated game info.\n"));
2026 network_update_netgame(); // Update the values in the netgame struct
2028 old_type = Netgame.type;
2029 old_status = Netgame.game_status;
2031 Netgame.type = PID_GAME_UPDATE;
2033 if (Endlevel_sequence || Control_center_destroyed)
2034 Netgame.game_status = NETSTAT_ENDLEVEL;
2036 for (i=0; i<N_players; i++ ) {
2037 if ( (Players[i].connected) && (i!=Player_num ) ) {
2038 if (Network_game_type == IPX_GAME) {
2040 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 );
2042 send_netgame_packet(NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node, Players[i].net_address, 0);
2046 appletalk_send_packet_data( (ubyte *)&Netgame, sizeof(lite_info), NetPlayers.players[i].network.appletalk.node,
2047 NetPlayers.players[i].network.appletalk.net, NetPlayers.players[i].network.appletalk.socket );
2053 Netgame.type = old_type;
2054 Netgame.game_status = old_status;
2057 int network_send_request(void)
2059 // Send a request to join a game 'Netgame'. Returns 0 if we can join this
2060 // game, non-zero if there is some problem.
2063 if (Netgame.numplayers < 1)
2066 for (i = 0; i < MAX_NUM_NET_PLAYERS; i++)
2067 if (NetPlayers.players[i].connected)
2070 Assert(i < MAX_NUM_NET_PLAYERS);
2072 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));
2074 // segments_checksum = netmisc_calc_checksum( Segments, sizeof(segment)*(Highest_segment_index+1) );
2076 My_Seq.type = PID_REQUEST;
2077 My_Seq.player.connected = Current_level_num;
2079 if (Network_game_type == IPX_GAME) {
2081 ipx_send_internetwork_packet_data((ubyte *)&My_Seq, sizeof(sequence_packet), NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node);
2083 send_sequence_packet(My_Seq, NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node, NULL);
2087 appletalk_send_packet_data( (ubyte *)&My_Seq, sizeof(sequence_packet), NetPlayers.players[i].network.appletalk.node,
2088 NetPlayers.players[i].network.appletalk.net,
2089 NetPlayers.players[i].network.appletalk.socket);
2096 int SecurityCheck=0;
2098 void network_process_gameinfo(ubyte *data)
2101 netgame_info tmp_info;
2104 netgame_info *new = (netgame_info *)data;
2107 if (Network_game_type == IPX_GAME) {
2108 receive_netgame_packet(data, &tmp_info, 0); // get correctly aligned structure
2114 WaitingForPlayerInfo=0;
2116 if (new->Security !=TempPlayersInfo->Security)
2118 Int3(); // Get Jason
2119 return; // If this first half doesn't go with the second half
2122 Network_games_changed = 1;
2124 //mprintf((0, "Got game data for game %s.\n", new->game_name));
2126 Assert (TempPlayersInfo!=NULL);
2128 for (i = 0; i < num_active_games; i++)
2130 //mprintf ((0,"GAMEINFO: Game %d is %s!\n",i,Active_games[i].game_name));
2132 if (!stricmp(Active_games[i].game_name, new->game_name) &&
2133 Active_games[i].Security==new->Security)
2137 if (i == MAX_ACTIVE_NETGAMES)
2139 mprintf((0, "Too many netgames.\n"));
2143 // MWA memcpy(&Active_games[i], data, sizeof(netgame_info));
2144 memcpy(&Active_games[i], (ubyte *)new, sizeof(netgame_info));
2145 memcpy (&ActiveNetPlayers[i],TempPlayersInfo,sizeof(AllNetPlayers_info));
2148 if (Active_games[i].Security==SecurityCheck)
2151 //mprintf ((0,"Recieved %d unique games...\n",i));
2153 if (i == num_active_games)
2156 if (Active_games[i].numplayers == 0)
2158 mprintf ((0,"DELETING THIS GAME!!!\n"));
2160 for (j = i; j < num_active_games-1; j++)
2162 memcpy(&Active_games[j], &Active_games[j+1], sizeof(netgame_info));
2163 memcpy (&ActiveNetPlayers[j],&ActiveNetPlayers[j+1],sizeof(AllNetPlayers_info));
2170 void network_process_lite_info(ubyte *data)
2176 lite_info *new = (lite_info *)data;
2179 if (Network_game_type == IPX_GAME) {
2180 receive_netgame_packet(data, (netgame_info *)&tmp_info, 1);
2185 Network_games_changed = 1;
2187 //mprintf((0, "Got game data for game %s.\n", new->game_name));
2189 for (i = 0; i < num_active_games; i++)
2191 //mprintf ((0,"GAMEINFO: Game %d is %s!\n",i,Active_games[i].game_name));
2193 if ((!stricmp(Active_games[i].game_name, new->game_name)) &&
2194 Active_games[i].Security==new->Security)
2198 if (i == MAX_ACTIVE_NETGAMES)
2200 mprintf((0, "Too many netgames.\n"));
2204 memcpy(&Active_games[i], (ubyte *)new, sizeof(lite_info));
2206 // See if this is really a Hoard game
2207 // If so, adjust all the data accordingly
2209 if (HoardEquipped())
2211 if (Active_games[i].game_flags & NETGAME_FLAG_HOARD)
2213 Active_games[i].gamemode=NETGAME_HOARD;
2214 Active_games[i].game_status=NETSTAT_PLAYING;
2216 if (Active_games[i].game_flags & NETGAME_FLAG_TEAM_HOARD)
2217 Active_games[i].gamemode=NETGAME_TEAM_HOARD;
2218 if (Active_games[i].game_flags & NETGAME_FLAG_REALLY_ENDLEVEL)
2219 Active_games[i].game_status=NETSTAT_ENDLEVEL;
2220 if (Active_games[i].game_flags & NETGAME_FLAG_REALLY_FORMING)
2221 Active_games[i].game_status=NETSTAT_STARTING;
2225 //mprintf ((0,"Recieved %d unique games...\n",i));
2227 if (i == num_active_games)
2230 if (Active_games[i].numplayers == 0)
2232 mprintf ((0,"DELETING THIS GAME!!!\n"));
2234 for (j = i; j < num_active_games-1; j++)
2236 memcpy(&Active_games[j], &Active_games[j+1], sizeof(netgame_info));
2242 void network_process_dump(sequence_packet *their)
2244 // Our request for join was denied. Tell the user why.
2249 mprintf((0, "Dumped by player %s, type %d.\n", their->player.callsign, their->player.connected));
2251 if (their->player.connected!=7)
2252 nm_messagebox(NULL, 1, TXT_OK, NET_DUMP_STRINGS(their->player.connected));
2255 for (i=0;i<N_players;i++)
2256 if (!stricmp (their->player.callsign,Players[i].callsign))
2258 if (i!=network_who_is_master())
2260 HUD_init_message ("%s attempted to kick you out.",their->player.callsign);
2264 sprintf (temp,"%s has kicked you out!",their->player.callsign);
2265 nm_messagebox(NULL, 1, TXT_OK, &temp);
2266 if (Network_status==NETSTAT_PLAYING)
2272 Network_status = NETSTAT_MENU;
2277 void network_process_request(sequence_packet *their)
2279 // Player is ready to receieve a sync packet
2282 mprintf((0, "Player %s ready for sync.\n", their->player.callsign));
2284 for (i = 0; i < N_players; i++) {
2285 if (Network_game_type == IPX_GAME) {
2286 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))) {
2287 Players[i].connected = 1;
2291 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)) ) {
2292 Players[i].connected = 1;
2299 #define REFUSE_INTERVAL F1_0 * 8
2300 extern void multi_reset_object_texture (object *);
2302 void network_process_packet(ubyte *data, int length )
2305 sequence_packet tmp_packet;
2307 sequence_packet *their = (sequence_packet *)data;
2310 if (Network_game_type == IPX_GAME) {
2311 receive_sequence_packet(data, &tmp_packet);
2312 their = &tmp_packet; // reassign their to point to correctly alinged structure
2316 //mprintf( (0, "Got packet of length %d, type %d\n", length, their->type ));
2318 // if ( length < sizeof(sequence_packet) ) return;
2324 case PID_GAME_INFO: // Jason L. says we can safely ignore this type.
2327 case PID_PLAYERSINFO:
2329 mprintf ((0,"Got a PID_PLAYERSINFO!\n"));
2331 if (Network_status==NETSTAT_WAITING)
2334 memcpy (&TempPlayersBase,data,sizeof(AllNetPlayers_info));
2336 if (Network_game_type == IPX_GAME)
2337 receive_netplayers_packet(data, &TempPlayersBase);
2339 memcpy (&TempPlayersBase,data,sizeof(AllNetPlayers_info));
2342 if (TempPlayersBase.Security!=Netgame.Security)
2344 mprintf ((0,"Bad security for PLAYERSINFO\n"));
2348 mprintf ((0,"Got a waiting PID_PLAYERSINFO!\n"));
2349 if (length!=ALLNETPLAYERSINFO_SIZE)
2351 mprintf ((0,"Invalid size for netplayers packet!\n"));
2355 TempPlayersInfo=&TempPlayersBase;
2356 WaitingForPlayerInfo=0;
2357 NetSecurityNum=TempPlayersInfo->Security;
2358 NetSecurityFlag=NETSECURITY_WAIT_FOR_SYNC;
2365 if (length != LITE_INFO_SIZE)
2367 mprintf ((0,"WARNING! Recieved invalid size for PID_LITE_INFO\n"));
2371 if (Network_status == NETSTAT_BROWSING)
2372 network_process_lite_info (data);
2376 // Someone wants a list of games
2378 if (length != SEQUENCE_PACKET_SIZE)
2380 mprintf ((0,"WARNING! Recieved invalid size for PID_GAME_LIST\n"));
2384 mprintf((0, "Got a PID_GAME_LIST!\n"));
2385 if ((Network_status == NETSTAT_PLAYING) || (Network_status == NETSTAT_STARTING) || (Network_status == NETSTAT_ENDLEVEL))
2386 if (network_i_am_master())
2387 network_send_lite_info(their);
2391 case PID_SEND_ALL_GAMEINFO:
2393 if (length != SEQUENCE_PACKET_SIZE)
2395 mprintf ((0,"WARNING! Recieved invalid size for PID_SEND_ALL_GAMEINFO\n"));
2399 if ((Network_status == NETSTAT_PLAYING) || (Network_status == NETSTAT_STARTING) || (Network_status == NETSTAT_ENDLEVEL))
2400 if (network_i_am_master() && their->Security==Netgame.Security)
2401 network_send_game_info(their);
2406 mprintf( (0, "Got NEWPLAYER message from %s.\n", their->player.callsign));
2408 if (length != SEQUENCE_PACKET_SIZE)
2410 mprintf ((0,"WARNING! Recieved invalid size for PID_ADDPLAYER\n"));
2413 mprintf( (0, "Got NEWPLAYER message from %s.\n", their->player.callsign));
2414 network_new_player(their);
2417 if (length != SEQUENCE_PACKET_SIZE)
2419 mprintf ((0,"WARNING! Recieved invalid size for PID_REQUEST\n"));
2423 mprintf( (0, "Got REQUEST from '%s'\n", their->player.callsign ));
2424 if (Network_status == NETSTAT_STARTING)
2426 // Someone wants to join our game!
2427 network_add_player(their);
2429 else if (Network_status == NETSTAT_WAITING)
2431 // Someone is ready to recieve a sync packet
2432 network_process_request(their);
2434 else if (Network_status == NETSTAT_PLAYING)
2436 // Someone wants to join a game in progress!
2437 if (Netgame.RefusePlayers)
2438 DoRefuseStuff (their);
2440 network_welcome_player(their);
2445 if (length != SEQUENCE_PACKET_SIZE)
2447 mprintf ((0,"WARNING! Recieved invalid size for PID_DUMP\n"));
2451 if (Network_status == NETSTAT_WAITING || Network_status==NETSTAT_PLAYING )
2452 network_process_dump(their);
2454 case PID_QUIT_JOINING:
2456 if (length != SEQUENCE_PACKET_SIZE)
2458 mprintf ((0,"WARNING! Recieved invalid size for PID_QUIT_JOINING\n"));
2461 if (Network_status == NETSTAT_STARTING)
2462 network_remove_player( their );
2463 else if ((Network_status == NETSTAT_PLAYING) && (Network_send_objects))
2464 network_stop_resync( their );
2468 mprintf ((0,"Got a sync packet! Network_status=%d\n",NETSTAT_WAITING));
2470 if (Network_status == NETSTAT_WAITING) {
2473 memcpy((ubyte *)&(TempNetInfo), data, sizeof(netgame_info));
2475 if (Network_game_type == IPX_GAME)
2476 receive_netgame_packet(data, &TempNetInfo, 0);
2478 memcpy((ubyte *)&(TempNetInfo), data, sizeof(netgame_info));
2481 if (TempNetInfo.Security!=Netgame.Security)
2483 mprintf ((0,"Bad security on sync packet.\n"));
2487 if (NetSecurityFlag==NETSECURITY_WAIT_FOR_SYNC)
2489 if (TempNetInfo.Security==TempPlayersInfo->Security)
2491 network_read_sync_packet (&TempNetInfo,0);
2498 NetSecurityFlag=NETSECURITY_WAIT_FOR_PLAYERS;
2499 NetSecurityNum=TempNetInfo.Security;
2501 if ( network_wait_for_playerinfo())
2502 network_read_sync_packet((netgame_info *)data,0);
2511 if ((Game_mode&GM_NETWORK) && ((Network_status == NETSTAT_PLAYING)||(Network_status == NETSTAT_ENDLEVEL) || Network_status==NETSTAT_WAITING)) {
2512 network_process_pdata((char *)data);
2515 case PID_NAKED_PDATA:
2516 if ((Game_mode&GM_NETWORK) && ((Network_status == NETSTAT_PLAYING)||(Network_status == NETSTAT_ENDLEVEL) || Network_status==NETSTAT_WAITING))
2517 network_process_naked_pdata((char *)data,length);
2520 case PID_OBJECT_DATA:
2521 if (Network_status == NETSTAT_WAITING)
2522 network_read_object_packet(data);
2525 if ((Network_status == NETSTAT_ENDLEVEL) || (Network_status == NETSTAT_PLAYING))
2526 network_read_endlevel_packet(data);
2528 mprintf((0, "Junked endlevel packet.\n"));
2530 case PID_ENDLEVEL_SHORT:
2531 if ((Network_status == NETSTAT_ENDLEVEL) || (Network_status == NETSTAT_PLAYING))
2532 network_read_endlevel_short_packet(data);
2534 mprintf((0, "Junked short endlevel packet!\n"));
2537 case PID_GAME_UPDATE:
2538 mprintf ((0,"Got a GAME_UPDATE!\n"));
2540 if (Network_status==NETSTAT_PLAYING)
2543 memcpy((ubyte *)&TempNetInfo, data, sizeof(lite_info) );
2545 if (Network_game_type == IPX_GAME)
2546 receive_netgame_packet(data, &TempNetInfo, 1);
2548 memcpy((ubyte *)&TempNetInfo, data, sizeof(lite_info) );
2550 if (TempNetInfo.Security==Netgame.Security)
2551 memcpy (&Netgame,(ubyte *)&TempNetInfo,sizeof(lite_info));
2553 if (Game_mode & GM_TEAM)
2557 for (i=0;i<N_players;i++)
2558 if (Players[i].connected)
2559 multi_reset_object_texture (&Objects[Players[i].objnum]);
2564 network_ping (PID_PING_RETURN,data[1]);
2566 case PID_PING_RETURN:
2567 network_handle_ping_return(data[1]); // data[1] is player who told us of their ping time
2569 case PID_NAMES_RETURN:
2570 if (Network_status==NETSTAT_BROWSING && NamesInfoSecurity!=-1)
2571 network_process_names_return (data);
2573 case PID_GAME_PLAYERS:
2574 // Someone wants a list of players in this game
2576 if (length != SEQUENCE_PACKET_SIZE)
2578 mprintf ((0,"WARNING! Recieved invalid size for PID_GAME_PLAYERS\n"));
2582 mprintf((0, "Got a PID_GAME_PLAYERS!\n"));
2583 if ((Network_status == NETSTAT_PLAYING) || (Network_status == NETSTAT_STARTING) || (Network_status == NETSTAT_ENDLEVEL))
2584 if (network_i_am_master() && their->Security==Netgame.Security)
2585 network_send_player_names(their);
2589 mprintf((0, "Ignoring invalid packet type.\n"));
2590 Int3(); // Invalid network packet type, see ROB
2596 void dump_segments()
2600 fp = fopen( "TEST.DMP", "wb" );
2601 fwrite( Segments, sizeof(segment)*(Highest_segment_index+1),1, fp );
2603 mprintf( (0, "SS=%d\n", sizeof(segment) ));
2609 network_read_endlevel_packet( ubyte *data )
2611 // Special packet for end of level syncing
2618 end = (endlevel_info *)data;
2620 for (i = 0; i < MAX_PLAYERS; i++)
2621 for (j = 0; j < MAX_PLAYERS; j++)
2622 end->kill_matrix[i][j] = INTEL_SHORT(end->kill_matrix[i][j]);
2623 end->kills = INTEL_SHORT(end->kills);
2624 end->killed = INTEL_SHORT(end->killed);
2627 playernum = end->player_num;
2629 Assert(playernum != Player_num);
2631 if (playernum>=N_players)
2633 Int3(); // weird, but it an happen in a coop restore game
2634 return; // if it happens in a coop restore, don't worry about it
2637 if ((Network_status == NETSTAT_PLAYING) && (end->connected != 0))
2638 return; // Only accept disconnect packets if we're not out of the level yet
2640 Players[playernum].connected = end->connected;
2641 memcpy(&kill_matrix[playernum][0], end->kill_matrix, MAX_PLAYERS*sizeof(short));
2642 Players[playernum].net_kills_total = end->kills;
2643 Players[playernum].net_killed_total = end->killed;
2645 if ((Players[playernum].connected == 1) && (end->seconds_left < Countdown_seconds_left))
2646 Countdown_seconds_left = end->seconds_left;
2648 LastPacketTime[playernum] = timer_get_approx_seconds();
2650 // mprintf((0, "Got endlevel packet from player %d.\n", playernum));
2654 network_read_endlevel_short_packet( ubyte *data )
2656 // Special packet for end of level syncing
2659 endlevel_info_short *end;
2661 end = (endlevel_info_short *)data;
2663 playernum = end->player_num;
2665 Assert(playernum != Player_num);
2667 if (playernum>=N_players)
2669 Int3(); // weird, but it can happen in a coop restore game
2670 return; // if it happens in a coop restore, don't worry about it
2673 if ((Network_status == NETSTAT_PLAYING) && (end->connected != 0))
2675 //mprintf ((0,"Returning early for short_endlevel\n"));
2676 return; // Only accept disconnect packets if we're not out of the level yet
2679 Players[playernum].connected = end->connected;
2681 if ((Players[playernum].connected == 1) && (end->seconds_left < Countdown_seconds_left))
2682 Countdown_seconds_left = end->seconds_left;
2684 LastPacketTime[playernum] = timer_get_approx_seconds();
2689 network_pack_objects(void)
2691 // Switching modes, pack the object array
2693 special_reset_objects();
2697 network_verify_objects(int remote, int local)
2700 int nplayers, got_controlcen=0;
2702 mprintf ((0,"NETWORK:remote=%d local=%d\n",remote,local));
2704 if ((remote-local) > 10)
2707 if (Game_mode & GM_MULTI_ROBOTS)
2712 for (i = 0; i <= Highest_object_index; i++)
2714 if ((Objects[i].type == OBJ_PLAYER) || (Objects[i].type == OBJ_GHOST))
2716 if (Objects[i].type == OBJ_CNTRLCEN)
2720 if (got_controlcen && (MaxNumNetPlayers<=nplayers))
2727 network_read_object_packet( ubyte *data )
2729 // Object from another net player we need to sync with
2731 short objnum, remote_objnum;
2736 static int my_pnum = 0;
2737 static int mode = 0;
2738 static int object_count = 0;
2739 static int frame_num = 0;
2742 int remote_frame_num = data[2];
2746 // mprintf((0, "Object packet %d (remote #%d) contains %d objects.\n", frame_num, remote_frame_num, nobj));
2748 for (i = 0; i < nobj; i++)
2750 objnum = INTEL_SHORT( *(short *)(data+loc) ); loc += 2;
2751 obj_owner = data[loc]; loc += 1;
2752 remote_objnum = INTEL_SHORT( *(short *)(data+loc) ); loc += 2;
2756 // Clear object array
2757 mprintf((0, "Clearing object array.\n"));
2760 Network_rejoined = 1;
2761 my_pnum = obj_owner;
2762 change_playernum_to(my_pnum);
2767 else if (objnum == -2)
2769 // Special debug checksum marker for entire send
2772 network_pack_objects();
2775 mprintf((0, "Objnum -2 found in frame local %d remote %d.\n", frame_num, remote_frame_num));
2776 mprintf((0, "Got %d objects, expected %d.\n", object_count, remote_objnum));
2777 if (remote_objnum != object_count) {
2780 if (network_verify_objects(remote_objnum, object_count))
2782 // Failed to sync up
2783 nm_messagebox(NULL, 1, TXT_OK, TXT_NET_SYNC_FAILED);
2784 Network_status = NETSTAT_MENU;
2791 if (frame_num != remote_frame_num)
2793 mprintf ((0,"Got a type 3 object packet!\n"));
2795 if ((obj_owner == my_pnum) || (obj_owner == -1))
2799 objnum = remote_objnum;
2800 //if (objnum > Highest_object_index)
2802 // Highest_object_index = objnum;
2803 // num_objects = Highest_object_index+1;
2809 network_pack_objects();
2812 objnum = obj_allocate();
2815 obj = &Objects[objnum];
2816 if (obj->segnum != -1)
2818 Assert(obj->segnum == -1);
2819 Assert(objnum < MAX_OBJECTS);
2820 memcpy(obj,data+loc,sizeof(object)); loc += sizeof(object);
2822 if (Network_game_type == IPX_GAME)
2825 segnum = obj->segnum;
2826 obj->next = obj->prev = obj->segnum = -1;
2827 obj->attached_obj = -1;
2829 obj_link(obj-Objects,segnum);
2830 if (obj_owner == my_pnum)
2831 map_objnum_local_to_local(objnum);
2832 else if (obj_owner != -1)
2833 map_objnum_local_to_remote(objnum, remote_objnum, obj_owner);
2835 object_owner[objnum] = -1;
2837 } // For a standard onbject
2838 } // For each object in packet
2841 void network_sync_poll( int nitems, newmenu_item * menus, int * key, int citem )
2843 // Polling loop waiting for sync packet to start game
2853 if (Network_status != NETSTAT_WAITING) // Status changed to playing, exit the menu
2856 if (!Network_rejoined && (timer_get_approx_seconds() > t1+F1_0*2))
2860 // Poll time expired, re-send request
2862 t1 = timer_get_approx_seconds();
2864 mprintf((0, "Re-sending join request.\n"));
2865 i = network_send_request();
2871 void network_start_poll( int nitems, newmenu_item * menus, int * key, int citem )
2878 Assert(Network_status == NETSTAT_STARTING);
2880 if (!menus[0].value) {
2882 menus[0].redraw = 1;
2885 for (i=1; i<nitems; i++ ) {
2886 if ( (i>= N_players) && (menus[i].value) ) {
2888 menus[i].redraw = 1;
2893 for (i=0; i<nitems; i++ ) {
2894 if ( menus[i].value ) {
2896 if ( nm > N_players ) {
2898 menus[i].redraw = 1;
2903 if ( nm > MaxNumNetPlayers ) {
2904 nm_messagebox( TXT_ERROR, 1, TXT_OK, "%s %d %s", TXT_SORRY_ONLY, MaxNumNetPlayers, TXT_NETPLAYERS_IN );
2905 // Turn off the last player highlighted
2906 for (i = N_players; i > 0; i--)
2907 if (menus[i].value == 1)
2910 menus[i].redraw = 1;
2915 // if (nitems > MAX_PLAYERS ) return;
2917 n = Netgame.numplayers;
2920 if (n < Netgame.numplayers )
2922 digi_play_sample (SOUND_HUD_MESSAGE,F1_0);
2924 mprintf ((0,"More players are printed!"));
2925 if (FindArg("-norankings"))
2926 sprintf( menus[N_players-1].text, "%d. %-20s", N_players,NetPlayers.players[N_players-1].callsign );
2928 sprintf( menus[N_players-1].text, "%d. %s%-20s", N_players, RankStrings[NetPlayers.players[N_players-1].rank],NetPlayers.players[N_players-1].callsign );
2930 menus[N_players-1].redraw = 1;
2931 if (N_players <= MaxNumNetPlayers)
2933 menus[N_players-1].value = 1;
2936 else if ( n > Netgame.numplayers )
2938 // One got removed...
2940 digi_play_sample (SOUND_HUD_KILL,F1_0);
2942 for (i=0; i<N_players; i++ )
2945 if (FindArg("-norankings"))
2946 sprintf( menus[i].text, "%d. %-20s", i+1, NetPlayers.players[i].callsign );
2948 sprintf( menus[i].text, "%d. %s%-20s", i+1, RankStrings[NetPlayers.players[i].rank],NetPlayers.players[i].callsign );
2949 if (i < MaxNumNetPlayers)
2953 menus[i].redraw = 1;
2955 for (i=N_players; i<n; i++ )
2957 sprintf( menus[i].text, "%d. ", i+1 ); // Clear out the deleted entries...
2959 menus[i].redraw = 1;
2964 int opt_cinvul, opt_team_anarchy, opt_coop, opt_show_on_map, opt_closed,opt_maxnet;
2965 int last_cinvul=0,last_maxnet,opt_team_hoard;
2966 int opt_refuse,opt_capture;
2968 void network_game_param_poll( int nitems, newmenu_item * menus, int * key, int citem )
2970 static int oldmaxnet=0;
2972 if (((HoardEquipped() && menus[opt_team_hoard].value) || (menus[opt_team_anarchy].value || menus[opt_capture].value)) && !menus[opt_closed].value && !menus[opt_refuse].value) {
2973 menus[opt_refuse].value = 1;
2974 menus[opt_refuse].redraw = 1;
2975 menus[opt_refuse-1].value = 0;
2976 menus[opt_refuse-1].redraw = 1;
2977 menus[opt_refuse-2].value = 0;
2978 menus[opt_refuse-2].redraw = 1;
2982 if (menus[opt_coop].value)
2984 if ( (menus[opt_coop].value) || ((Network_game_type == APPLETALK_GAME) && (Network_appletalk_type == LOCALTALK_TYPE) && (menus[opt_coop-1].value)) )
2989 if (menus[opt_maxnet].value>2)
2991 menus[opt_maxnet].value=2;
2992 menus[opt_maxnet].redraw=1;
2995 if (menus[opt_maxnet].max_value>2)
2997 menus[opt_maxnet].max_value=2;
2998 menus[opt_maxnet].redraw=1;
3002 if ( (Network_game_type == APPLETALK_GAME) && (Network_appletalk_type == LOCALTALK_TYPE) ) {
3003 if (menus[opt_maxnet].value > 0) {
3004 menus[opt_maxnet].value=0;
3005 menus[opt_maxnet].redraw=1;
3007 if (menus[opt_maxnet].max_value > 0) {
3008 menus[opt_maxnet].max_value=0;
3009 menus[opt_maxnet].redraw=1;
3014 if (!Netgame.game_flags & NETGAME_FLAG_SHOW_MAP)
3015 Netgame.game_flags |= NETGAME_FLAG_SHOW_MAP;
3017 if (Netgame.PlayTimeAllowed || Netgame.KillGoal)
3019 Netgame.PlayTimeAllowed=0;
3024 else // if !Coop game
3029 menus[opt_maxnet].value=6;
3030 menus[opt_maxnet].max_value=6;
3033 if ( (Network_game_type == APPLETALK_GAME) && (Network_appletalk_type == LOCALTALK_TYPE) ) {
3034 menus[opt_maxnet].value=1;
3035 menus[opt_maxnet].max_value=1;
3042 if ( last_maxnet != menus[opt_maxnet].value )
3044 sprintf( menus[opt_maxnet].text, "Maximum players: %d", menus[opt_maxnet].value+2 );
3045 last_maxnet = menus[opt_maxnet].value;
3046 menus[opt_maxnet].redraw = 1;
3050 int netgame_difficulty;
3052 int network_get_game_params( char * game_name, int *mode, int *game_flags, int *level )
3055 int opt, opt_name, opt_level, opt_mode,opt_moreopts;
3057 char name[NETGAME_NAME_LEN+1];
3059 char level_text[32];
3062 int new_mission_num;
3065 *game_flags=*game_flags;
3067 SetAllAllowablesTo (1);
3068 NamesInfoSecurity=-1;
3070 for (i=0;i<MAX_PLAYERS;i++)
3072 Players[i].callsign[0]=0;
3076 Netgame.PlayTimeAllowed=0;
3077 Netgame.Allow_marker_view=1;
3078 netgame_difficulty=Player_default_difficulty;
3080 new_mission_num = multi_choose_mission(&anarchy_only);
3082 if (new_mission_num < 0)
3085 if (!(FindArg ("-packets") && FindArg ("-shortpackets")))
3086 if (!network_choose_connect ())
3090 if ( (Network_game_type == APPLETALK_GAME) && (Network_appletalk_type == LOCALTALK_TYPE) )
3091 MaxNumNetPlayers = 3;
3094 strcpy(Netgame.mission_name, Mission_list[new_mission_num].filename);
3095 strcpy(Netgame.mission_title, Mission_list[new_mission_num].mission_name);
3096 Netgame.control_invul_time = control_invul_time;
3098 sprintf( name, "%s%s", Players[Player_num].callsign, TXT_S_GAME );
3099 sprintf( slevel, "1" );
3102 m[opt].type = NM_TYPE_TEXT; m[opt].text = TXT_DESCRIPTION; opt++;
3105 m[opt].type = NM_TYPE_INPUT; m[opt].text = name; m[opt].text_len = NETGAME_NAME_LEN; opt++;
3107 sprintf(level_text, "%s (1-%d)", TXT_LEVEL_, Last_level);
3109 // if (Last_secret_level < -1)
3110 // sprintf(level_text+strlen(level_text)-1, ", S1-S%d)", -Last_secret_level);
3111 // else if (Last_secret_level == -1)
3112 // sprintf(level_text+strlen(level_text)-1, ", S1)");
3114 Assert(strlen(level_text) < 32);
3116 m[opt].type = NM_TYPE_TEXT; m[opt].text = level_text; opt++;
3119 m[opt].type = NM_TYPE_INPUT; m[opt].text = slevel; m[opt].text_len=4; opt++;
3120 // m[opt].type = NM_TYPE_TEXT; m[opt].text = TXT_OPTIONS; opt++;
3123 m[opt].type = NM_TYPE_RADIO; m[opt].text = TXT_ANARCHY; m[opt].value=1; m[opt].group=0; opt++;
3124 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++;
3125 m[opt].type = NM_TYPE_RADIO; m[opt].text = TXT_ANARCHY_W_ROBOTS; m[opt].value=0; m[opt].group=0; opt++;
3126 m[opt].type = NM_TYPE_RADIO; m[opt].text = TXT_COOPERATIVE; m[opt].value=0; m[opt].group=0; opt_coop=opt; opt++;
3127 m[opt].type = NM_TYPE_RADIO; m[opt].text = "Capture the flag"; m[opt].value=0; m[opt].group=0; opt_capture=opt; opt++;
3129 if (HoardEquipped())
3131 m[opt].type = NM_TYPE_RADIO; m[opt].text = "Hoard"; m[opt].value=0; m[opt].group=0; opt++;
3132 m[opt].type = NM_TYPE_RADIO; m[opt].text = "Team Hoard"; m[opt].value=0; m[opt].group=0; opt_team_hoard=opt; opt++;
3133 m[opt].type = NM_TYPE_TEXT; m[opt].text = ""; opt++;
3136 { m[opt].type = NM_TYPE_TEXT; m[opt].text = ""; opt++; }
3138 m[opt].type = NM_TYPE_RADIO; m[opt].text = "Open game"; m[opt].group=1; m[opt].value=0; opt++;
3140 m[opt].type = NM_TYPE_RADIO; m[opt].text = TXT_CLOSED_GAME; m[opt].group=1; m[opt].value=0; opt++;
3142 m[opt].type = NM_TYPE_RADIO; m[opt].text = "Restricted Game "; m[opt].group=1; m[opt].value=Netgame.RefusePlayers; opt++;
3144 // m[opt].type = NM_TYPE_CHECK; m[opt].text = TXT_SHOW_IDS; m[opt].value=0; opt++;
3147 sprintf( srmaxnet, "Maximum players: %d", MaxNumNetPlayers);
3148 m[opt].type = NM_TYPE_SLIDER; m[opt].value=MaxNumNetPlayers-2; m[opt].text= srmaxnet; m[opt].min_value=0;
3149 m[opt].max_value=MaxNumNetPlayers-2; opt++;
3150 last_maxnet=MaxNumNetPlayers-2;
3153 m[opt].type = NM_TYPE_MENU; m[opt].text = "More options..."; opt++;
3158 ExtGameStatus=GAMESTAT_NETGAME_OPTIONS;
3159 i = newmenu_do1( NULL, NULL, opt, m, network_game_param_poll, 1 );
3161 if (i==opt_moreopts)
3163 if ( m[opt_mode+3].value )
3164 Game_mode=GM_MULTI_COOP;
3165 network_more_game_options();
3169 Netgame.RefusePlayers=m[opt_refuse].value;
3175 MaxNumNetPlayers = m[opt_maxnet].value+2;
3176 Netgame.max_numplayers=MaxNumNetPlayers;
3178 for (j = 0; j < num_active_games; j++)
3179 if (!stricmp(Active_games[j].game_name, name))
3181 nm_messagebox(TXT_ERROR, 1, TXT_OK, TXT_DUPLICATE_NAME);
3185 strcpy( game_name, name );
3188 *level = atoi(slevel);
3190 if ((*level < 1) || (*level > Last_level))
3192 nm_messagebox(TXT_ERROR, 1, TXT_OK, TXT_LEVEL_OUT_RANGE );
3193 sprintf(slevel, "1");
3196 if ( m[opt_mode].value )
3197 *mode = NETGAME_ANARCHY;
3202 nm_messagebox(TXT_SORRY, 1, TXT_OK, TXT_REGISTERED_ONLY );
3203 m[opt_mode+1].value = 0;
3204 m[opt_mode+2].value = 0;
3205 m[opt_mode+3].value = 0;
3206 if (HoardEquipped())
3207 m[opt_mode+4].value = 0;
3209 m[opt_mode].value = 1;
3213 else if (m[opt_mode+1].value) {
3214 *mode = NETGAME_TEAM_ANARCHY;
3216 else if (m[opt_capture].value)
3217 *mode = NETGAME_CAPTURE_FLAG;
3218 else if (HoardEquipped() && m[opt_capture+1].value)
3219 *mode = NETGAME_HOARD;
3220 else if (HoardEquipped() && m[opt_capture+2].value)
3221 *mode = NETGAME_TEAM_HOARD;
3222 else if (anarchy_only) {
3223 nm_messagebox(NULL, 1, TXT_OK, TXT_ANARCHY_ONLY_MISSION);
3224 m[opt_mode+2].value = 0;
3225 m[opt_mode+3].value = 0;
3226 m[opt_mode].value = 1;
3229 else if ( m[opt_mode+2].value )
3230 *mode = NETGAME_ROBOT_ANARCHY;
3231 else if ( m[opt_mode+3].value )
3232 *mode = NETGAME_COOPERATIVE;
3233 else Int3(); // Invalid mode -- see Rob
3235 if (m[opt_closed].value)
3236 Netgame.game_flags |= NETGAME_FLAG_CLOSED;
3244 network_set_game_mode(int gamemode)
3248 if ( gamemode == NETGAME_ANARCHY )
3249 Game_mode = GM_NETWORK;
3250 else if ( gamemode == NETGAME_ROBOT_ANARCHY )
3251 Game_mode = GM_NETWORK | GM_MULTI_ROBOTS;
3252 else if ( gamemode == NETGAME_COOPERATIVE )
3253 Game_mode = GM_NETWORK | GM_MULTI_COOP | GM_MULTI_ROBOTS;
3254 else if (gamemode == NETGAME_CAPTURE_FLAG)
3256 Game_mode = GM_NETWORK | GM_TEAM | GM_CAPTURE;
3260 else if (HoardEquipped() && gamemode == NETGAME_HOARD)
3261 Game_mode = GM_NETWORK | GM_HOARD;
3262 else if (HoardEquipped() && gamemode == NETGAME_TEAM_HOARD)
3264 Game_mode = GM_NETWORK | GM_HOARD | GM_TEAM;
3267 else if ( gamemode == NETGAME_TEAM_ANARCHY )
3269 Game_mode = GM_NETWORK | GM_TEAM;
3276 #ifdef MACINTOSH // minimize players on localtalk games
3277 if ( (Network_game_type == APPLETALK_GAME) && (Network_appletalk_type == LOCALTALK_TYPE) ) {
3278 if (Game_mode & GM_MULTI_ROBOTS)
3279 MaxNumNetPlayers = 2;
3281 MaxNumNetPlayers = 3;
3283 if (Game_mode & GM_MULTI_COOP)
3284 MaxNumNetPlayers = 4;
3286 MaxNumNetPlayers = 8;
3294 network_find_game(void)
3296 // Find out whether or not there is space left on this socket
3300 Network_status = NETSTAT_BROWSING;
3302 num_active_games = 0;
3304 show_boxed_message(TXT_WAIT);
3306 network_send_game_list_request();
3307 t1 = timer_get_approx_seconds() + F1_0*3;
3309 while (timer_get_approx_seconds() < t1) // Wait 3 seconds for replies
3312 clear_boxed_message();
3314 // mprintf((0, "%s %d %s\n", TXT_FOUND, num_active_games, TXT_ACTIVE_GAMES));
3316 if (num_active_games < MAX_ACTIVE_NETGAMES)
3321 void network_read_sync_packet( netgame_info * sp, int rsinit)
3324 netgame_info tmp_info;
3328 char temp_callsign[CALLSIGN_LEN+1];
3331 if ( (Network_game_type == IPX_GAME) && (sp != &Netgame) ) { // for macintosh -- get the values unpacked to our structure format
3332 receive_netgame_packet((ubyte *)sp, &tmp_info, 0);
3338 TempPlayersInfo=&NetPlayers;
3340 // This function is now called by all people entering the netgame.
3342 // mprintf( (0, "%s %d\n", TXT_STARTING_NETGAME, sp->levelnum ));
3346 memcpy( &Netgame, sp, sizeof(netgame_info) );
3347 memcpy (&NetPlayers,TempPlayersInfo,sizeof (AllNetPlayers_info));
3350 N_players = sp->numplayers;
3351 Difficulty_level = sp->difficulty;
3352 Network_status = sp->game_status;
3354 //Assert(Function_mode != FMODE_GAME);
3358 mprintf((1, "Netgame.checksum = %d, calculated checksum = %d.\n", Netgame.segments_checksum, my_segments_checksum));
3360 if (Netgame.segments_checksum != my_segments_checksum)
3362 Network_status = NETSTAT_MENU;
3363 nm_messagebox(TXT_ERROR, 1, TXT_OK, TXT_NETLEVEL_NMATCH);
3369 // Discover my player number
3371 memcpy(temp_callsign, Players[Player_num].callsign, CALLSIGN_LEN+1);
3375 for (i=0; i<MAX_NUM_NET_PLAYERS; i++ ) {
3376 Players[i].net_kills_total = 0;
3377 // Players[i].net_killed_total = 0;
3380 for (i=0; i<N_players; i++ ) {
3381 if (Network_game_type == IPX_GAME) {
3382 if ( (!memcmp( TempPlayersInfo->players[i].network.ipx.node, My_Seq.player.network.ipx.node, 6 )) && (!stricmp( TempPlayersInfo->players[i].callsign, temp_callsign)) ) {
3383 if (Player_num!=-1) {
3384 Int3(); // Hey, we've found ourselves twice
3385 mprintf ((0,"Hey, we've found ourselves twice!\n"));
3386 Network_status = NETSTAT_MENU;
3389 change_playernum_to(i);
3392 if ( (TempPlayersInfo->players[i].network.appletalk.node == My_Seq.player.network.appletalk.node) && (!stricmp( TempPlayersInfo->players[i].callsign, temp_callsign)) ) {
3393 if (Player_num!=-1) {
3394 Int3(); // Hey, we've found ourselves twice
3395 Network_status = NETSTAT_MENU;
3398 change_playernum_to(i);
3401 memcpy( Players[i].callsign, TempPlayersInfo->players[i].callsign, CALLSIGN_LEN+1 );
3403 if (Network_game_type == IPX_GAME) {
3404 if ( (*(uint *)TempPlayersInfo->players[i].network.ipx.server) != 0 )
3405 ipx_get_local_target( TempPlayersInfo->players[i].network.ipx.server, TempPlayersInfo->players[i].network.ipx.node, Players[i].net_address );
3407 memcpy( Players[i].net_address, TempPlayersInfo->players[i].network.ipx.node, 6 );
3410 Players[i].n_packets_got=0; // How many packets we got from them
3411 Players[i].n_packets_sent=0; // How many packets we sent to them
3412 Players[i].connected = TempPlayersInfo->players[i].connected;
3413 Players[i].net_kills_total = sp->player_kills[i];
3414 Players[i].net_killed_total = sp->killed[i];
3415 if ((Network_rejoined) || (i != Player_num))
3416 Players[i].score = sp->player_score[i];
3417 for (j = 0; j < MAX_NUM_NET_PLAYERS; j++)
3419 kill_matrix[i][j] = sp->kills[i][j];
3423 if ( Player_num < 0 ) {
3424 mprintf ((0,"Bad Player_num, resetting to NETSTAT_MENU!\n"));
3425 Network_status = NETSTAT_MENU;
3429 if (Network_rejoined)
3430 for (i=0; i<N_players;i++)
3431 Players[i].net_killed_total = sp->killed[i];
3433 if (Network_rejoined) {
3434 network_process_monitor_vector(sp->monitor_vector);
3435 Players[Player_num].time_level = sp->level_time;
3438 team_kills[0] = sp->team_kills[0];
3439 team_kills[1] = sp->team_kills[1];
3441 Players[Player_num].connected = 1;
3442 NetPlayers.players[Player_num].connected = 1;
3443 NetPlayers.players[Player_num].rank=GetMyNetRanking();
3445 if (!Network_rejoined)
3446 for (i=0; i<NumNetPlayerPositions; i++) {
3447 Objects[Players[i].objnum].pos = Player_init[Netgame.locations[i]].pos;
3448 Objects[Players[i].objnum].orient = Player_init[Netgame.locations[i]].orient;
3449 obj_relink(Players[i].objnum,Player_init[Netgame.locations[i]].segnum);
3452 Objects[Players[Player_num].objnum].type = OBJ_PLAYER;
3454 mprintf ((0,"Changing to NETSTAT_PLAYING!\n"));
3455 Network_status = NETSTAT_PLAYING;
3456 Function_mode = FMODE_GAME;
3457 multi_sort_kill_list();
3462 network_send_sync(void)
3466 // Randomize their starting locations...
3468 d_srand( timer_get_fixed_seconds() );
3469 for (i=0; i<NumNetPlayerPositions; i++ )
3471 if (Players[i].connected)
3472 Players[i].connected = 1; // Get rid of endlevel connect statuses
3473 if (Game_mode & GM_MULTI_COOP)
3474 Netgame.locations[i] = i;
3478 np = d_rand() % NumNetPlayerPositions;
3479 for (j=0; j<i; j++ )
3481 if (Netgame.locations[j]==np)
3488 // np is a location that is not used anywhere else..
3489 Netgame.locations[i]=np;
3490 // mprintf((0, "Player %d starting in location %d\n" ,i ,np ));
3494 // Push current data into the sync packet
3496 network_update_netgame();
3497 Netgame.game_status = NETSTAT_PLAYING;
3498 Netgame.type = PID_SYNC;
3499 Netgame.segments_checksum = my_segments_checksum;
3501 for (i=0; i<N_players; i++ ) {
3502 if ((!Players[i].connected) || (i == Player_num))
3505 if (Network_game_type == IPX_GAME) {
3506 // Send several times, extras will be ignored
3508 ipx_send_internetwork_packet_data( (ubyte *)&Netgame, sizeof(netgame_info), NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node);
3509 ipx_send_internetwork_packet_data( (ubyte *)&NetPlayers, sizeof(AllNetPlayers_info), NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node);
3511 send_netgame_packet(NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node, NULL, 0);
3512 send_netplayers_packet(NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node);
3516 appletalk_send_packet_data( (ubyte *)&Netgame, sizeof(netgame_info), NetPlayers.players[i].network.appletalk.node,
3517 NetPlayers.players[i].network.appletalk.net,
3518 NetPlayers.players[i].network.appletalk.socket);
3519 appletalk_send_packet_data( (ubyte *)&NetPlayers, sizeof(AllNetPlayers_info), NetPlayers.players[i].network.appletalk.node,
3520 NetPlayers.players[i].network.appletalk.net,
3521 NetPlayers.players[i].network.appletalk.socket);
3526 network_read_sync_packet(&Netgame,1); // Read it myself, as if I had sent it
3530 network_select_teams(void)
3533 newmenu_item m[MAX_PLAYERS+4];
3534 int choice, opt, opt_team_b;
3535 ubyte team_vector = 0;
3536 char team_names[2][CALLSIGN_LEN+1];
3538 int pnums[MAX_PLAYERS+2];
3540 // One-time initialization
3542 for (i = N_players/2; i < N_players; i++) // Put first half of players on team A
3544 team_vector |= (1 << i);
3547 sprintf(team_names[0], "%s", TXT_BLUE);
3548 sprintf(team_names[1], "%s", TXT_RED);
3550 // Here comes da menu
3552 m[0].type = NM_TYPE_INPUT; m[0].text = team_names[0]; m[0].text_len = CALLSIGN_LEN;
3555 for (i = 0; i < N_players; i++)
3557 if (!(team_vector & (1 << i)))
3559 m[opt].type = NM_TYPE_MENU; m[opt].text = NetPlayers.players[i].callsign; pnums[opt] = i; opt++;
3563 m[opt].type = NM_TYPE_INPUT; m[opt].text = team_names[1]; m[opt].text_len = CALLSIGN_LEN; opt++;
3564 for (i = 0; i < N_players; i++)
3566 if (team_vector & (1 << i))
3568 m[opt].type = NM_TYPE_MENU; m[opt].text = NetPlayers.players[i].callsign; pnums[opt] = i; opt++;
3571 m[opt].type = NM_TYPE_TEXT; m[opt].text = ""; opt++;
3572 m[opt].type = NM_TYPE_MENU; m[opt].text = TXT_ACCEPT; opt++;
3574 Assert(opt <= MAX_PLAYERS+4);
3576 choice = newmenu_do(NULL, TXT_TEAM_SELECTION, opt, m, NULL);
3578 if (choice == opt-1)
3580 if ((opt-2-opt_team_b < 2) || (opt_team_b == 1))
3582 nm_messagebox(NULL, 1, TXT_OK, TXT_TEAM_MUST_ONE);
3588 Netgame.team_vector = team_vector;
3589 strcpy(Netgame.team_name[0], team_names[0]);
3590 strcpy(Netgame.team_name[1], team_names[1]);
3594 else if ((choice > 0) && (choice < opt_team_b)) {
3595 team_vector |= (1 << pnums[choice]);
3597 else if ((choice > opt_team_b) && (choice < opt-2)) {
3598 team_vector &= ~(1 << pnums[choice]);
3600 else if (choice == -1)
3609 network_select_players(void)
3612 newmenu_item m[MAX_PLAYERS+4];
3613 char text[MAX_PLAYERS+4][45];
3615 int save_nplayers; //how may people would like to join
3617 network_add_player( &My_Seq );
3619 for (i=0; i< MAX_PLAYERS+4; i++ ) {
3620 sprintf( text[i], "%d. %-20s", i+1, "" );
3621 m[i].type = NM_TYPE_CHECK; m[i].text = text[i]; m[i].value = 0;
3624 m[0].value = 1; // Assume server will play...
3626 if (FindArg("-norankings"))
3627 sprintf( text[0], "%d. %-20s", 1, Players[Player_num].callsign );
3629 sprintf( text[0], "%d. %s%-20s", 1, RankStrings[NetPlayers.players[Player_num].rank],Players[Player_num].callsign );
3631 sprintf( title, "%s %d %s", TXT_TEAM_SELECT, MaxNumNetPlayers, TXT_TEAM_PRESS_ENTER );
3634 ExtGameStatus=GAMESTAT_NETGAME_PLAYER_SELECT;
3635 j=newmenu_do1( NULL, title, MAX_PLAYERS+4, m, network_start_poll, 1 );
3637 save_nplayers = N_players;
3642 // Dump all players and go back to menu mode
3645 for (i=1; i<save_nplayers; i++) {
3646 if (Network_game_type == IPX_GAME)
3647 network_dump_player(NetPlayers.players[i].network.ipx.server,NetPlayers.players[i].network.ipx.node, DUMP_ABORTED);
3650 network_dump_appletalk_player(NetPlayers.players[i].network.appletalk.node,NetPlayers.players[i].network.appletalk.net, NetPlayers.players[i].network.appletalk.socket, DUMP_ABORTED);
3655 Netgame.numplayers = 0;
3656 network_send_game_info(0); // Tell everyone we're bailing
3658 Network_status = NETSTAT_MENU;
3662 // Count number of players chosen
3665 for (i=0; i<save_nplayers; i++ )
3671 if ( N_players > Netgame.max_numplayers) {
3673 nm_messagebox( TXT_ERROR, 1, TXT_OK, "%s %d %s", TXT_SORRY_ONLY, MaxNumNetPlayers, TXT_NETPLAYERS_IN );
3675 nm_messagebox( TXT_ERROR, 1, TXT_OK, "%s %d netplayers for this game.", TXT_SORRY_ONLY, MaxNumNetPlayers );
3677 N_players = save_nplayers;
3678 goto GetPlayersAgain;
3682 if ( N_players < 2 ) {
3683 nm_messagebox( TXT_ERROR, 1, TXT_OK, TXT_TEAM_ATLEAST_TWO );
3684 N_players = save_nplayers;
3685 goto GetPlayersAgain;
3690 if ( (Netgame.gamemode == NETGAME_TEAM_ANARCHY ||
3691 Netgame.gamemode == NETGAME_CAPTURE_FLAG || Netgame.gamemode == NETGAME_TEAM_HOARD) && (N_players < 2) ) {
3692 nm_messagebox(TXT_ERROR, 1, TXT_OK, "You must select at least two\nplayers to start a team game" );
3693 N_players = save_nplayers;
3694 goto GetPlayersAgain;
3698 // Remove players that aren't marked.
3700 for (i=0; i<save_nplayers; i++ ) {
3705 if (Network_game_type == IPX_GAME) {
3706 memcpy(NetPlayers.players[N_players].network.ipx.node, NetPlayers.players[i].network.ipx.node, 6);
3707 memcpy(NetPlayers.players[N_players].network.ipx.server, NetPlayers.players[i].network.ipx.server, 4);
3709 NetPlayers.players[N_players].network.appletalk.node = NetPlayers.players[i].network.appletalk.node;
3710 NetPlayers.players[N_players].network.appletalk.net = NetPlayers.players[i].network.appletalk.net;
3711 NetPlayers.players[N_players].network.appletalk.socket = NetPlayers.players[i].network.appletalk.socket;
3713 memcpy(NetPlayers.players[N_players].callsign, NetPlayers.players[i].callsign, CALLSIGN_LEN+1);
3714 NetPlayers.players[N_players].version_major=NetPlayers.players[i].version_major;
3715 NetPlayers.players[N_players].version_minor=NetPlayers.players[i].version_minor;
3716 NetPlayers.players[N_players].rank=NetPlayers.players[i].rank;
3717 ClipRank (&NetPlayers.players[N_players].rank);
3718 network_check_for_old_version(i);
3720 Players[N_players].connected = 1;
3725 if (Network_game_type == IPX_GAME)
3726 network_dump_player(NetPlayers.players[i].network.ipx.server,NetPlayers.players[i].network.ipx.node, DUMP_DORK);
3729 network_dump_appletalk_player(NetPlayers.players[i].network.appletalk.node,NetPlayers.players[i].network.appletalk.net, NetPlayers.players[i].network.appletalk.socket, DUMP_DORK);
3734 for (i = N_players; i < MAX_NUM_NET_PLAYERS; i++) {
3735 if (Network_game_type == IPX_GAME) {
3736 memset(NetPlayers.players[i].network.ipx.node, 0, 6);
3737 memset(NetPlayers.players[i].network.ipx.server, 0, 4);
3739 NetPlayers.players[i].network.appletalk.node = 0;
3740 NetPlayers.players[i].network.appletalk.net = 0;
3741 NetPlayers.players[i].network.appletalk.socket = 0;
3743 memset(NetPlayers.players[i].callsign, 0, CALLSIGN_LEN+1);
3744 NetPlayers.players[i].version_major=0;
3745 NetPlayers.players[i].version_minor=0;
3746 NetPlayers.players[i].rank=0;
3749 mprintf ((0,"Select teams: Game mode is %d\n",Netgame.gamemode));
3751 if (Netgame.gamemode == NETGAME_TEAM_ANARCHY ||
3752 Netgame.gamemode == NETGAME_CAPTURE_FLAG ||
3753 Netgame.gamemode == NETGAME_TEAM_HOARD)
3754 if (!network_select_teams())
3761 network_start_game()
3764 char game_name[NETGAME_NAME_LEN+1];
3765 int chosen_game_mode, game_flags, level;
3767 if (Network_game_type == IPX_GAME) {
3769 Assert( FRAME_INFO_SIZE < IPX_MAX_DATA_SIZE );
3770 mprintf((0, "Using frame_info len %d, max %d.\n", FRAME_INFO_SIZE, IPX_MAX_DATA_SIZE));
3772 if ( !Network_active )
3774 nm_messagebox(NULL, 1, TXT_OK, TXT_IPX_NOT_FOUND );
3782 Assert( FRAME_INFO_SIZE < APPLETALK_MAX_DATA_SIZE );
3783 mprintf((0, "Using frame_info len %d, max %d.\n", sizeof(frame_info), APPLETALK_MAX_DATA_SIZE));
3784 if (Appletalk_active <= 0) {
3785 switch (Appletalk_active) {
3786 case APPLETALK_NOT_OPEN:
3787 sprintf(buf, "Appletalk is not currently active.\nPlease enable AppleTalk from the\nChooser and restart Descent.");
3789 case APPLETALK_BAD_LISTENER:
3790 sprintf(buf, "The Resource Fork of Descent appears damaged.\nPlease re-install Descent or contact\nMacPlay technical support.");
3792 case APPLETALK_NO_LOCAL_ADDR:
3793 sprintf(buf, "Wow! Strange!\n\nNo Local Address.");
3795 case APPLETALK_NO_SOCKET:
3796 sprintf(buf, "All AppleTalk sockets are in use.\nTry shutting down other network\napplications and restarting Descent.\n");
3799 nm_messagebox(NULL, 1, TXT_OK, buf);
3802 strcpy(Network_zone_name, DEFAULT_ZONE_NAME);
3807 change_playernum_to(0);
3809 if (network_find_game())
3811 nm_messagebox(NULL, 1, TXT_OK, TXT_NET_FULL);
3816 i = network_get_game_params( game_name, &chosen_game_mode, &game_flags, &level );
3822 // LoadLevel(level); Old, no longer used.
3824 Netgame.difficulty = Difficulty_level;
3825 Netgame.gamemode = chosen_game_mode;
3826 Netgame.game_status = NETSTAT_STARTING;
3827 Netgame.numplayers = 0;
3828 Netgame.max_numplayers = MaxNumNetPlayers;
3829 Netgame.levelnum = level;
3830 Netgame.protocol_version = MULTI_PROTO_VERSION;
3832 strcpy(Netgame.game_name, game_name);
3834 Network_status = NETSTAT_STARTING;
3837 if (Network_game_type == APPLETALK_GAME) {
3842 show_boxed_message("Registering Netgame");
3844 err = appletalk_register_netgame( game_name, TickCount() );
3845 t1 = timer_get_fixed_seconds() + F1_0;
3846 while (timer_get_fixed_seconds() < t1) ;
3848 } while ( (err == nbpDuplicate) && (count != MAX_REGISTER_TRIES) );
3849 clear_boxed_message();
3850 if ( (err == tooManyReqs) || (count == MAX_REGISTER_TRIES) ) {
3851 nm_messagebox(NULL, 1, TXT_OK, "AppleTalk Network is too busy.\nPlease try again shortly.");
3852 Game_mode = GM_GAME_OVER;
3858 network_set_game_mode(Netgame.gamemode);
3860 d_srand( timer_get_fixed_seconds() );
3861 Netgame.Security=d_rand(); // For syncing Netgames with player packets
3863 if(network_select_players())
3865 StartNewLevel(Netgame.levelnum, 0);
3868 Game_mode = GM_GAME_OVER;
3872 void restart_net_searching(newmenu_item * m)
3876 num_active_games = 0;
3878 memset(Active_games, 0, sizeof(netgame_info)*MAX_ACTIVE_NETGAMES);
3880 for (i = 0; i < MAX_ACTIVE_NETGAMES; i++)
3882 sprintf(m[i+2].text, "%d. ",i+1);
3886 NamesInfoSecurity=-1;
3887 Network_games_changed = 1;
3890 char *ModeLetters[]={"ANRCHY","TEAM","ROBO","COOP","FLAG","HOARD","TMHOARD"};
3892 int NumActiveNetgames=0;
3894 void network_join_poll( int nitems, newmenu_item * menus, int * key, int citem )
3896 // Polling loop for Join Game menu
3898 int i, osocket,join_status,temp;
3905 if ( (Network_game_type == IPX_GAME) && Network_allow_socket_changes ) {
3906 osocket = Network_socket;
3908 if ( *key==KEY_PAGEDOWN ) { Network_socket--; *key = 0; }
3909 if ( *key==KEY_PAGEUP ) { Network_socket++; *key = 0; }
3911 if (Network_socket>99)
3913 if (Network_socket<-99)
3916 if ( Network_socket+IPX_DEFAULT_SOCKET > 0x8000 )
3917 Network_socket = 0x8000 - IPX_DEFAULT_SOCKET;
3919 if ( Network_socket+IPX_DEFAULT_SOCKET < 0 )
3920 Network_socket = IPX_DEFAULT_SOCKET;
3922 if (Network_socket != osocket ) {
3923 sprintf( menus[0].text, "\t%s %+d (PgUp/PgDn to change)", TXT_CURRENT_IPX_SOCKET, Network_socket );
3924 menus[0].redraw = 1;
3925 mprintf(( 0, "Changing to socket %d\n", Network_socket ));
3927 mprintf ((0,"netgood 1!\n"));
3928 ipx_change_default_socket( IPX_DEFAULT_SOCKET + Network_socket );
3929 mprintf ((0,"netgood 2!\n"));
3930 restart_net_searching(menus);
3931 mprintf ((0,"netgood 3!\n"));
3932 network_send_game_list_request();
3933 mprintf ((0,"netgood 4!\n"));
3938 // send a request for game info every 3 seconds
3940 if (Network_game_type == IPX_GAME) {
3941 if (timer_get_approx_seconds() > t1+F1_0*3) {
3942 t1 = timer_get_approx_seconds();
3943 network_send_game_list_request();
3946 } else if (timer_get_approx_seconds() > t1+F1_0*20) {
3948 t1 = timer_get_approx_seconds();
3949 restart_net_searching(menus);
3950 show_boxed_message("Requesting list of Netgames");
3951 network_send_game_list_request();
3952 clear_boxed_message();
3957 temp=num_active_games;
3961 NumActiveNetgames=num_active_games;
3963 if (!Network_games_changed)
3966 if (temp!=num_active_games)
3967 digi_play_sample (SOUND_HUD_MESSAGE,F1_0);
3969 Network_games_changed = 0;
3970 mprintf ((0,"JOIN POLL: I'm looking at %d games!\n",num_active_games));
3972 // Copy the active games data into the menu options
3973 for (i = 0; i < num_active_games; i++)
3975 int game_status = Active_games[i].game_status;
3976 int j,x, k,tx,ty,ta,nplayers = 0;
3977 char levelname[8],MissName[25],GameName[25],thold[2];
3980 // These next two loops protect against menu skewing
3981 // if missiontitle or gamename contain a tab
3983 for (x=0,tx=0,k=0,j=0;j<15;j++)
3985 if (Active_games[i].mission_title[j]=='\t')
3987 thold[0]=Active_games[i].mission_title[j];
3988 gr_get_string_size (thold,&tx,&ty,&ta);
3990 if ((x+=tx)>=LHX(55))
3992 MissName[k]=MissName[k+1]=MissName[k+2]='.';
3997 MissName[k++]=Active_games[i].mission_title[j];
4001 for (x=0,tx=0,k=0,j=0;j<15;j++)
4003 if (Active_games[i].game_name[j]=='\t')
4005 thold[0]=Active_games[i].game_name[j];
4006 gr_get_string_size (thold,&tx,&ty,&ta);
4008 if ((x+=tx)>=LHX(55))
4010 GameName[k]=GameName[k+1]=GameName[k+2]='.';
4014 GameName[k++]=Active_games[i].game_name[j];
4019 nplayers=Active_games[i].numconnected;
4021 if (Active_games[i].levelnum < 0)
4022 sprintf(levelname, "S%d", -Active_games[i].levelnum);
4024 sprintf(levelname, "%d", Active_games[i].levelnum);
4026 if (game_status == NETSTAT_STARTING)
4028 sprintf (menus[i+2].text,"%d.\t%s \t%s \t %d/%d \t%s \t %s \t%s",
4029 i+1,GameName,ModeLetters[Active_games[i].gamemode],nplayers,
4030 Active_games[i].max_numplayers,MissName,levelname,"Forming");
4032 else if (game_status == NETSTAT_PLAYING)
4034 join_status=can_join_netgame(&Active_games[i],NULL);
4035 // mprintf ((0,"Joinstatus=%d\n",join_status));
4038 sprintf (menus[i+2].text,"%d.\t%s \t%s \t %d/%d \t%s \t %s \t%s",
4039 i+1,GameName,ModeLetters[Active_games[i].gamemode],nplayers,
4040 Active_games[i].max_numplayers,MissName,levelname,"Open");
4041 else if (join_status==2)
4042 sprintf (menus[i+2].text,"%d.\t%s \t%s \t %d/%d \t%s \t %s \t%s",
4043 i+1,GameName,ModeLetters[Active_games[i].gamemode],nplayers,
4044 Active_games[i].max_numplayers,MissName,levelname,"Full");
4045 else if (join_status==3)
4046 sprintf (menus[i+2].text,"%d.\t%s \t%s \t %d/%d \t%s \t %s \t%s",
4047 i+1,GameName,ModeLetters[Active_games[i].gamemode],nplayers,
4048 Active_games[i].max_numplayers,MissName,levelname,"Restrict");
4050 sprintf (menus[i+2].text,"%d.\t%s \t%s \t %d/%d \t%s \t %s \t%s",
4051 i+1,GameName,ModeLetters[Active_games[i].gamemode],nplayers,
4052 Active_games[i].max_numplayers,MissName,levelname,"Closed");
4056 sprintf (menus[i+2].text,"%d.\t%s \t%s \t %d/%d \t%s \t %s \t%s",
4057 i+1,GameName,ModeLetters[Active_games[i].gamemode],nplayers,
4058 Active_games[i].max_numplayers,MissName,levelname,"Between");
4061 Assert(strlen(menus[i+2].text) < 100);
4062 menus[i+2].redraw = 1;
4065 for (i = num_active_games; i < MAX_ACTIVE_NETGAMES; i++)
4067 sprintf(menus[i+2].text, "%d. ",i+1);
4068 menus[i+2].redraw = 1;
4073 network_wait_for_sync(void)
4079 Network_status = NETSTAT_WAITING;
4081 m[0].type=NM_TYPE_TEXT; m[0].text = text;
4082 m[1].type=NM_TYPE_TEXT; m[1].text = TXT_NET_LEAVE;
4084 i = network_send_request();
4089 sprintf( m[0].text, "%s\n'%s' %s", TXT_NET_WAITING, NetPlayers.players[i].callsign, TXT_NET_TO_ENTER );
4092 choice=newmenu_do( NULL, TXT_WAIT, 2, m, network_sync_poll );
4097 if (Network_status != NETSTAT_PLAYING)
4101 // if (Network_status == NETSTAT_ENDLEVEL)
4103 // network_send_endlevel_packet(0);
4104 // longjmp(LeaveGame, 0);
4107 mprintf((0, "Aborting join.\n"));
4108 me.type = PID_QUIT_JOINING;
4109 memcpy( me.player.callsign, Players[Player_num].callsign, CALLSIGN_LEN+1 );
4110 if (Network_game_type == IPX_GAME) {
4111 memcpy( me.player.network.ipx.node, ipx_get_my_local_address(), 6 );
4112 memcpy( me.player.network.ipx.server, ipx_get_my_server_address(), 4 );
4114 ipx_send_internetwork_packet_data( (ubyte *)&me, sizeof(sequence_packet), NetPlayers.players[0].network.ipx.server, NetPlayers.players[0].network.ipx.node );
4116 send_sequence_packet(me, NetPlayers.players[0].network.ipx.server, NetPlayers.players[0].network.ipx.node, NULL);
4120 me.player.network.appletalk.node = appletalk_get_my_node();
4121 me.player.network.appletalk.net = appletalk_get_my_net();
4122 me.player.network.appletalk.socket = appletalk_get_my_socket();
4126 Function_mode = FMODE_MENU;
4127 Game_mode = GM_GAME_OVER;
4128 return(-1); // they cancelled
4134 network_request_poll( int nitems, newmenu_item * menus, int * key, int citem )
4136 // Polling loop for waiting-for-requests menu
4146 // Send our endlevel packet at regular intervals
4148 // if (timer_get_approx_seconds() > t1+ENDLEVEL_SEND_INTERVAL)
4150 // network_send_endlevel_packet();
4151 // t1 = timer_get_approx_seconds();
4156 for (i = 0; i < N_players; i++)
4158 if ((Players[i].connected == 1) || (Players[i].connected == 0))
4162 if (num_ready == N_players) // All players have checked in or are disconnected
4169 network_wait_for_requests(void)
4171 // Wait for other players to load the level before we send the sync
4175 Network_status = NETSTAT_WAITING;
4177 m[0].type=NM_TYPE_TEXT; m[0].text = TXT_NET_LEAVE;
4179 mprintf((0, "Entered wait_for_requests : N_players = %d.\n", N_players));
4181 for (choice = 0; choice < N_players; choice++)
4182 mprintf((0, "Players[%d].connected = %d.\n", choice, Players[choice].connected));
4184 Network_status = NETSTAT_WAITING;
4187 Players[Player_num].connected = 1;
4190 choice = newmenu_do(NULL, TXT_WAIT, 1, m, network_request_poll);
4195 choice = nm_messagebox(NULL, 3, TXT_YES, TXT_NO, TXT_START_NOWAIT, TXT_QUITTING_NOW);
4201 // User confirmed abort
4203 for (i=0; i < N_players; i++) {
4204 if ((Players[i].connected != 0) && (i != Player_num)) {
4205 if (Network_game_type == IPX_GAME)
4206 network_dump_player(NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node, DUMP_ABORTED);
4209 network_dump_appletalk_player(NetPlayers.players[i].network.appletalk.node, NetPlayers.players[i].network.appletalk.net, NetPlayers.players[i].network.appletalk.socket, DUMP_ABORTED);
4215 if (Network_game_type == APPLETALK_GAME)
4216 network_release_registered_game();
4218 longjmp(LeaveGame, 0);
4220 else if (choice != -2)
4225 network_level_sync(void)
4227 // Do required syncing between (before) levels
4231 mprintf((0, "Player %d entering network_level_sync.\n", Player_num));
4233 MySyncPackInitialized = 0;
4235 // my_segments_checksum = netmisc_calc_checksum(Segments, sizeof(segment)*(Highest_segment_index+1));
4237 network_flush(); // Flush any old packets
4240 result = network_wait_for_sync();
4241 else if (network_i_am_master())
4243 network_wait_for_requests();
4244 network_send_sync();
4248 result = network_wait_for_sync();
4250 network_count_powerups_in_mine();
4254 Players[Player_num].connected = 0;
4255 network_send_endlevel_packet();
4257 if (Network_game_type == APPLETALK_GAME)
4258 network_release_registered_game();
4260 longjmp(LeaveGame, 0);
4265 void network_count_powerups_in_mine(void)
4269 for (i=0;i<MAX_POWERUP_TYPES;i++)
4270 PowerupsInMine[i]=0;
4272 for (i=0;i<=Highest_object_index;i++)
4274 if (Objects[i].type==OBJ_POWERUP)
4276 PowerupsInMine[Objects[i].id]++;
4277 if (multi_powerup_is_4pack(Objects[i].id))
4278 PowerupsInMine[Objects[i].id-1]+=4;
4286 // code to release the NBP binding of an appletalk game
4288 void network_release_registered_game()
4290 if (Network_game_type == APPLETALK_GAME)
4291 appletalk_remove_netgame();
4294 // code to sort zone lists....
4296 int zone_sort_func(const char **e0, const char **e1)
4298 return strcmp(*e0, *e1);
4301 void network_get_appletalk_zone()
4303 int num_zones, i, item, default_item;
4305 char default_zone[MAX_ZONE_LENGTH]; // my zone
4307 Network_zone_name[0] = '\0';
4309 show_boxed_message("Looking for AppleTalk Zones");
4310 num_zones = appletalk_get_zone_names(&zone_list);
4311 clear_boxed_message();
4313 if (num_zones < 0) { // error in getting zone list...maybe no router available....
4314 if ( (num_zones == tooManyReqs) || (num_zones == noDataArea) ){
4315 nm_messagebox(NULL, 1, TXT_OK, "AppleTalk Network is too busy.\nPlease try again shortly.");
4316 longjmp(LeaveGame,0);
4321 if (num_zones == 0) {
4322 strcpy(Network_zone_name, DEFAULT_ZONE_NAME);
4326 if (num_zones == 1) {
4327 Network_zone_name[0] = (char)(strlen(zone_list[0]));
4328 memcpy( &(Network_zone_name[1]), zone_list[0], strlen(zone_list[0]) );
4332 // sort the zone names
4334 for (i = 0; i < num_zones; i++)
4335 strlwr(zone_list[i]);
4337 qsort(zone_list, num_zones, sizeof(char *), zone_sort_func);
4339 // get my current zone so we can highlight that one first
4341 if (appletalk_get_my_zone(default_zone))
4344 for (i = 0; i < num_zones; i++) {
4345 if ( !stricmp(zone_list[i], default_zone) ) {
4353 item = newmenu_listbox1("AppleTalk Zones", num_zones, zone_list, 0, default_item, NULL);
4358 Network_zone_name[0] = (char)(strlen(zone_list[item]));
4359 memcpy( &(Network_zone_name[1]), zone_list[item], strlen(zone_list[item]) );
4362 for (i = 0; i < num_zones; i++)
4363 d_free(zone_list[i]);
4368 void nm_draw_background1(char * filename);
4370 void network_join_game()
4373 char menu_text[MAX_ACTIVE_NETGAMES+2][200];
4375 newmenu_item m[MAX_ACTIVE_NETGAMES+2];
4377 if (Network_game_type == IPX_GAME) {
4378 if ( !Network_active )
4380 nm_messagebox(NULL, 1, TXT_OK, TXT_IPX_NOT_FOUND);
4384 } else if (Appletalk_active <= 0) {
4387 switch (Appletalk_active) {
4388 case APPLETALK_NOT_OPEN:
4389 sprintf(buf, "Appletalk is not currently active.\nPlease enable AppleTalk from the\nChooser and restart Descent.");
4391 case APPLETALK_BAD_LISTENER:
4392 sprintf(buf, "The Resource Fork of Descent appears damaged.\nPlease re-install Descent or contact\nMacPlay technical support.");
4394 case APPLETALK_NO_LOCAL_ADDR:
4395 sprintf(buf, "Wow! Strange!\n\nNo Local Address.");
4397 case APPLETALK_NO_SOCKET:
4398 sprintf(buf, "All AppleTalk sockets are in use.\nTry shutting down other network\napplications and restarting Descent.\n");
4401 nm_messagebox(NULL, 1, TXT_OK, buf);
4413 if (Network_game_type == APPLETALK_GAME)
4414 network_get_appletalk_zone();
4417 Network_send_objects = 0;
4418 Network_sending_extras=0;
4421 Network_status = NETSTAT_BROWSING; // We are looking at a game menu
4424 network_listen(); // Throw out old info
4427 if (Network_game_type == IPX_GAME)
4428 #endif // note link to if
4429 network_send_game_list_request(); // broadcast a request for lists
4431 num_active_games = 0;
4433 memset(m, 0, sizeof(newmenu_item)*MAX_ACTIVE_NETGAMES);
4434 memset(Active_games, 0, sizeof(netgame_info)*MAX_ACTIVE_NETGAMES);
4435 memset(ActiveNetPlayers,0,sizeof(AllNetPlayers_info)*MAX_ACTIVE_NETGAMES);
4437 gr_set_fontcolor(BM_XRGB(15,15,23),-1);
4439 m[0].text = menu_text[0];
4440 m[0].type = NM_TYPE_TEXT;
4441 if (Network_game_type == IPX_GAME) {
4442 if (Network_allow_socket_changes)
4443 sprintf( m[0].text, "\tCurrent IPX Socket is default %+d (PgUp/PgDn to change)", Network_socket );
4445 strcpy( m[0].text, "" );
4448 p2cstr(Network_zone_name);
4449 if (strcmp(Network_zone_name, "*")) // only print if there is a zone name
4450 sprintf(m[0].text, "\tCurrent Zone is %s", Network_zone_name); // is Network_zone_name a pascal string????
4451 c2pstr(Network_zone_name);
4455 m[1].text=menu_text[1];
4456 m[1].type=NM_TYPE_TEXT;
4457 sprintf (m[1].text,"\tGAME \tMODE \t#PLYRS \tMISSION \tLEV \tSTATUS");
4459 for (i = 0; i < MAX_ACTIVE_NETGAMES; i++) {
4460 m[i+2].text = menu_text[i+2];
4461 m[i+2].type = NM_TYPE_MENU;
4462 sprintf(m[i+2].text, "%d. ", i+1);
4466 Network_games_changed = 1;
4469 nm_draw_background1(Menu_pcx_name); //load this here so if we abort after loading level, we restore the palette
4470 gr_palette_load(gr_palette);
4471 ExtGameStatus=GAMESTAT_JOIN_NETGAME;
4472 choice=newmenu_dotiny("NETGAMES", NULL,MAX_ACTIVE_NETGAMES+2, m, network_join_poll);
4476 Network_status = NETSTAT_MENU;
4477 return; // they cancelled
4481 if (choice >=num_active_games)
4483 nm_messagebox(TXT_SORRY, 1, TXT_OK, TXT_INVALID_CHOICE);
4487 // Choice has been made and looks legit
4488 if (Active_games[choice].game_status == NETSTAT_ENDLEVEL)
4490 nm_messagebox(TXT_SORRY, 1, TXT_OK, TXT_NET_GAME_BETWEEN2);
4494 if (Active_games[choice].protocol_version != MULTI_PROTO_VERSION)
4496 if (Active_games[choice].protocol_version == 3) {
4498 nm_messagebox(TXT_SORRY, 1, TXT_OK, "Your version of Descent 2\nis incompatible with the\nDemo version");
4501 else if (Active_games[choice].protocol_version == 4) {
4503 nm_messagebox(TXT_SORRY, 1, TXT_OK, "This Demo version of\nDescent 2 is incompatible\nwith the full commercial version");
4507 nm_messagebox(TXT_SORRY, 1, TXT_OK, TXT_VERSION_MISMATCH);
4514 // Check for valid mission name
4515 mprintf((0, "Loading mission:%s.\n", Active_games[choice].mission_name));
4516 if (!load_mission_by_name(Active_games[choice].mission_name))
4518 nm_messagebox(NULL, 1, TXT_OK, TXT_MISSION_NOT_FOUND);
4524 #if defined (D2_OEM)
4526 if (Active_games[choice].levelnum>8)
4528 nm_messagebox(NULL, 1, TXT_OK, "This OEM version only supports\nthe first 8 levels!");
4534 if (!network_wait_for_all_info (choice))
4536 nm_messagebox (TXT_SORRY,1,TXT_OK,"There was a join error!");
4537 Network_status = NETSTAT_BROWSING; // We are looking at a game menu
4541 Network_status = NETSTAT_BROWSING; // We are looking at a game menu
4543 if (!can_join_netgame(&Active_games[choice],&ActiveNetPlayers[choice]))
4545 if (Active_games[choice].numplayers == Active_games[choice].max_numplayers)
4546 nm_messagebox(TXT_SORRY, 1, TXT_OK, TXT_GAME_FULL);
4548 nm_messagebox(TXT_SORRY, 1, TXT_OK, TXT_IN_PROGRESS);
4552 // Choice is valid, prepare to join in
4554 memcpy(&Netgame, &Active_games[choice], sizeof(netgame_info));
4555 memcpy (&NetPlayers,&ActiveNetPlayers[choice],sizeof(AllNetPlayers_info));
4557 Difficulty_level = Netgame.difficulty;
4558 MaxNumNetPlayers = Netgame.max_numplayers;
4559 change_playernum_to(1);
4563 // register the joining player with NBP. This will have the nice effect of a player wanting to
4564 // join to be able to see the netgame if this player were to become the master.
4566 if (Network_game_type == APPLETALK_GAME) {
4571 show_boxed_message("Registering Netgame");
4573 err = appletalk_register_netgame( Active_games[choice].game_name, TickCount() );
4574 t1 = timer_get_fixed_seconds() + F1_0;
4575 while ( timer_get_fixed_seconds() < t1 ) ;
4577 } while ( (err == nbpDuplicate) && (count != MAX_REGISTER_TRIES) );
4578 clear_boxed_message();
4579 if ( (err == tooManyReqs) || (count == MAX_REGISTER_TRIES) ) {
4580 nm_messagebox(NULL, 1, TXT_OK, "AppleTalk Network is too busy.\nPlease try again shortly.");
4586 network_set_game_mode(Netgame.gamemode);
4588 network_AdjustMaxDataSize ();
4590 StartNewLevel(Netgame.levelnum, 0);
4592 return; // look ma, we're in a game!!!
4595 void network_AdjustMaxDataSize ()
4598 if (Netgame.ShortPackets)
4599 MaxXDataSize=NET_XDATA_SIZE;
4601 MaxXDataSize=NET_XDATA_SIZE;
4605 fix StartWaitAllTime=0;
4606 int WaitAllChoice=0;
4607 #define ALL_INFO_REQUEST_INTERVAL F1_0*3
4609 void network_wait_all_poll( int nitems, newmenu_item * menus, int * key, int citem )
4617 if (timer_get_approx_seconds() > t1+ALL_INFO_REQUEST_INTERVAL)
4619 network_send_all_info_request(PID_SEND_ALL_GAMEINFO,SecurityCheck);
4620 t1 = timer_get_approx_seconds();
4623 network_do_big_wait(WaitAllChoice);
4625 if(SecurityCheck==-1)
4629 int network_wait_for_all_info (int choice)
4635 m[0].type=NM_TYPE_TEXT; m[0].text = "Press Escape to cancel";
4637 WaitAllChoice=choice;
4638 StartWaitAllTime=timer_get_approx_seconds();
4639 SecurityCheck=Active_games[choice].Security;
4643 pick=newmenu_do( NULL, "Connecting...", 1, m, network_wait_all_poll );
4645 if (pick>-1 && SecurityCheck!=-1)
4648 if (SecurityCheck==-1)
4657 void network_do_big_wait(int choice)
4660 ubyte packet[IPX_MAX_DATA_SIZE],*data;
4661 AllNetPlayers_info *temp_info;
4663 AllNetPlayers_info info_struct;
4664 ubyte apacket[APPLETALK_MAX_DATA_SIZE];
4668 if (Network_game_type == APPLETALK_GAME)
4669 size=appletalk_get_packet_data( apacket );
4672 size=ipx_get_packet_data( packet );
4677 if (Network_game_type == APPLETALK_GAME)
4687 if (Network_game_type == IPX_GAME) {
4689 memcpy((ubyte *)&TempNetInfo, data, sizeof(netgame_info));
4691 receive_netgame_packet(data, &TempNetInfo, 0);
4694 memcpy((ubyte *)&TempNetInfo, data, sizeof(netgame_info));
4696 mprintf ((0,"This is %s game with a security of %d\n",TempNetInfo.game_name,TempNetInfo.Security));
4698 if (TempNetInfo.Security !=SecurityCheck)
4700 mprintf ((0,"Bad security on big_wait...rejecting.\n"));
4704 if (NetSecurityFlag==NETSECURITY_WAIT_FOR_GAMEINFO)
4706 if (TempPlayersInfo->Security==TempNetInfo.Security)
4708 mprintf ((0,"EQUAL !: Game=%d Players=%d ",TempPlayersInfo->Security,TempNetInfo.Security));
4709 if (TempPlayersInfo->Security==SecurityCheck)
4711 memcpy (&Active_games[choice],(ubyte *)&TempNetInfo,sizeof(netgame_info));
4712 memcpy (&ActiveNetPlayers[choice],TempPlayersInfo,sizeof(AllNetPlayers_info));
4719 NetSecurityFlag=NETSECURITY_WAIT_FOR_PLAYERS;
4720 NetSecurityNum=TempNetInfo.Security;
4722 if (network_wait_for_playerinfo())
4724 mprintf ((0,"HUH? Game=%d Player=%d\n",NetSecurityNum,TempPlayersInfo->Security));
4725 memcpy (&Active_games[choice],(ubyte *)&TempNetInfo,sizeof(netgame_info));
4726 memcpy (&ActiveNetPlayers[choice],TempPlayersInfo,sizeof(AllNetPlayers_info));
4733 case PID_PLAYERSINFO:
4734 mprintf ((0,"Got a PID_PLAYERSINFO!\n"));
4736 if (Network_game_type == IPX_GAME) {
4738 temp_info=(AllNetPlayers_info *)data;
4740 receive_netplayers_packet(data, &info_struct);
4741 temp_info = &info_struct;
4744 temp_info = (AllNetPlayers_info *)data;
4746 if (temp_info->Security!=SecurityCheck)
4747 break; // If this isn't the guy we're looking for, move on
4749 memcpy (&TempPlayersBase,(ubyte *)&temp_info,sizeof(AllNetPlayers_info));
4750 TempPlayersInfo=&TempPlayersBase;
4751 WaitingForPlayerInfo=0;
4752 NetSecurityNum=TempPlayersInfo->Security;
4753 NetSecurityFlag=NETSECURITY_WAIT_FOR_GAMEINFO;
4759 void network_leave_game()
4763 network_do_frame(1, 1);
4766 fclose (SendLogFile);
4767 fclose (RecieveLogFile);
4770 if ((network_i_am_master()))
4772 while (Network_sending_extras>1 && Player_joining_extras!=-1)
4773 network_send_extras();
4775 Netgame.numplayers = 0;
4778 network_send_game_info(NULL);
4781 mprintf ((0,"HEY! I'm master and I've left.\n"));
4784 Players[Player_num].connected = 0;
4785 network_send_endlevel_packet();
4786 change_playernum_to(0);
4787 Game_mode = GM_GAME_OVER;
4788 write_player_file();
4790 // WIN(ipx_destroy_read_thread());
4795 void network_flush()
4798 ubyte apacket[APPLETALK_MAX_DATA_SIZE];
4800 ubyte packet[IPX_MAX_DATA_SIZE];
4803 if ( (Network_game_type == APPLETALK_GAME) && (Appletalk_active <= 0) )
4807 if ( Network_game_type == IPX_GAME )
4808 if (!Network_active) return;
4811 if (Network_game_type == APPLETALK_GAME)
4812 while (appletalk_get_packet_data(apacket) > 0) ;
4815 while (ipx_get_packet_data(packet) > 0) ;
4818 void network_listen()
4821 ubyte apacket[APPLETALK_MAX_DATA_SIZE];
4824 ubyte packet[IPX_MAX_DATA_SIZE];
4827 if (Network_status==NETSTAT_PLAYING && Netgame.ShortPackets && !Network_send_objects)
4829 loopmax=N_players*Netgame.PacketsPerSec;
4833 if ( (Network_game_type == APPLETALK_GAME) && (Appletalk_active <= 0) )
4837 if (Network_game_type == IPX_GAME)
4838 if (!Network_active) return;
4840 if (!(Game_mode & GM_NETWORK) && (Function_mode == FMODE_GAME))
4841 mprintf((0, "Calling network_listen() when not in net game.\n"));
4843 WaitingForPlayerInfo=1;
4844 NetSecurityFlag=NETSECURITY_OFF;
4847 if (Network_game_type == IPX_GAME) {
4848 size = ipx_get_packet_data( packet );
4850 network_process_packet( packet, size );
4853 size = ipx_get_packet_data( packet );
4857 size = appletalk_get_packet_data( apacket );
4859 network_process_packet( apacket, size );
4862 size = appletalk_get_packet_data( apacket );
4868 int network_wait_for_playerinfo()
4871 ubyte packet[IPX_MAX_DATA_SIZE];
4872 struct AllNetPlayers_info *TempInfo;
4876 AllNetPlayers_info info_struct;
4877 ubyte apacket[APPLETALK_MAX_DATA_SIZE];
4881 if ( (Network_game_type == APPLETALK_GAME) && (Appletalk_active <= 0) )
4885 if ( Network_game_type == IPX_GAME)
4886 if (!Network_active) return(0);
4888 // if (!WaitingForPlayerInfo)
4891 if (!(Game_mode & GM_NETWORK) && (Function_mode == FMODE_GAME))
4893 mprintf((0, "Calling network_wait_for_playerinfo() when not in net game.\n"));
4895 if (Network_status==NETSTAT_PLAYING)
4897 Int3(); //MY GOD! Get Jason...this is the source of many problems
4900 basetime=timer_get_approx_seconds();
4902 while (WaitingForPlayerInfo && retries<50 && (timer_get_approx_seconds()<(basetime+(F1_0*5))))
4904 if (Network_game_type == IPX_GAME) {
4905 size = ipx_get_packet_data( packet );
4909 size = appletalk_get_packet_data( apacket );
4914 if (size>0 && id==PID_PLAYERSINFO)
4917 if (Network_game_type == APPLETALK_GAME) {
4918 TempInfo = (AllNetPlayers_info *)apacket;
4920 receive_netplayers_packet(packet, &info_struct);
4921 TempInfo = &info_struct;
4924 TempInfo=(AllNetPlayers_info *)packet;
4929 if (NetSecurityFlag==NETSECURITY_WAIT_FOR_PLAYERS)
4931 if (NetSecurityNum==TempInfo->Security)
4933 mprintf ((0,"HEYEQUAL: Player=%d Game=%d\n",TempInfo->Security,NetSecurityNum));
4934 memcpy (&TempPlayersBase,(ubyte *)TempInfo,sizeof(AllNetPlayers_info));
4935 TempPlayersInfo=&TempPlayersBase;
4936 NetSecurityFlag=NETSECURITY_OFF;
4938 WaitingForPlayerInfo=0;
4946 mprintf ((0,"I'm original!\n"));
4948 NetSecurityNum=TempInfo->Security;
4949 NetSecurityFlag=NETSECURITY_WAIT_FOR_GAMEINFO;
4951 memcpy (&TempPlayersBase,(ubyte *)TempInfo,sizeof(AllNetPlayers_info));
4952 TempPlayersInfo=&TempPlayersBase;
4953 WaitingForPlayerInfo=0;
4962 void network_send_data( ubyte * ptr, int len, int urgent )
4968 fprintf (SendLogFile,"Packet type: %d Len:%d Urgent:%d TT=%d\n",ptr[0],len,urgent,TTSent[ptr[0]]);
4969 fflush (SendLogFile);
4972 if (Endlevel_sequence)
4975 if (!MySyncPackInitialized) {
4976 MySyncPackInitialized = 1;
4977 memset( &MySyncPack, 0, sizeof(frame_info) );
4983 if ((MySyncPack.data_size+len) > MaxXDataSize ) {
4985 network_do_frame(1, 0);
4986 if (MySyncPack.data_size != 0) {
4987 mprintf((0, "%d bytes were added to data by network_do_frame!\n", MySyncPack.data_size));
4990 // Int3(); // Trying to send too much!
4992 mprintf((0, "Packet overflow, sending additional packet, type %d len %d.\n", ptr[0], len));
4993 Assert(check == ptr[0]);
4996 Assert(MySyncPack.data_size+len <= MaxXDataSize);
4998 memcpy( &MySyncPack.data[MySyncPack.data_size], ptr, len );
4999 MySyncPack.data_size += len;
5002 void network_timeout_player(int playernum)
5004 // Remove a player from the game if we haven't heard from them in
5008 Assert(playernum < N_players);
5009 Assert(playernum > -1);
5011 network_disconnect_player(playernum);
5012 create_player_appearance_effect(&Objects[Players[playernum].objnum]);
5014 digi_play_sample(SOUND_HUD_MESSAGE, F1_0);
5016 HUD_init_message("%s %s", Players[playernum].callsign, TXT_DISCONNECTING);
5017 for (i = 0; i < N_players; i++)
5018 if (Players[i].connected)
5023 nm_messagebox(NULL, 1, TXT_OK, TXT_YOU_ARE_ONLY);
5027 fix last_send_time = 0;
5028 fix last_timeout_check = 0;
5031 void squish_short_frame_info(short_frame_info old_info, ubyte *data)
5037 data[0] = old_info.type; loc++; loc += 3; // skip three for pad byte
5038 tmpi = swapint(old_info.numpackets);
5039 memcpy(&(data[loc]), &tmpi, 4); loc += 4;
5041 memcpy(&(data[loc]), old_info.thepos.bytemat, 9); loc += 9;
5042 tmps = INTEL_SHORT(old_info.thepos.xo);
5043 memcpy(&(data[loc]), &tmps, 2); loc += 2;
5044 tmps = INTEL_SHORT(old_info.thepos.yo);
5045 memcpy(&(data[loc]), &tmps, 2); loc += 2;
5046 tmps = INTEL_SHORT(old_info.thepos.zo);
5047 memcpy(&(data[loc]), &tmps, 2); loc += 2;
5048 tmps = INTEL_SHORT(old_info.thepos.segment);
5049 memcpy(&(data[loc]), &tmps, 2); loc += 2;
5050 tmps = INTEL_SHORT(old_info.thepos.velx);
5051 memcpy(&(data[loc]), &tmps, 2); loc += 2;
5052 tmps = INTEL_SHORT(old_info.thepos.vely);
5053 memcpy(&(data[loc]), &tmps, 2); loc += 2;
5054 tmps = INTEL_SHORT(old_info.thepos.velz);
5055 memcpy(&(data[loc]), &tmps, 2); loc += 2;
5057 tmps = swapshort(old_info.data_size);
5058 memcpy(&(data[loc]), &tmps, 2); loc += 2;
5060 data[loc] = old_info.playernum; loc++;
5061 data[loc] = old_info.obj_render_type; loc++;
5062 data[loc] = old_info.level_num; loc++;
5063 memcpy(&(data[loc]), old_info.data, old_info.data_size);
5067 char NakedBuf[NET_XDATA_SIZE+4];
5068 int NakedPacketLen=0;
5069 int NakedPacketDestPlayer=-1;
5071 void network_do_frame(int force, int listen)
5074 short_frame_info ShortSyncPack;
5075 static fix LastEndlevel=0;
5077 if (!(Game_mode&GM_NETWORK)) return;
5079 if ((Network_status != NETSTAT_PLAYING) || (Endlevel_sequence)) // Don't send postion during escape sequence...
5084 Assert (NakedPacketDestPlayer>-1);
5085 // mprintf ((0,"Sending a naked packet to %s (%d bytes)!\n",Players[NakedPacketDestPlayer].callsign,NakedPacketLen));
5086 if (Network_game_type == IPX_GAME)
5087 ipx_send_packet_data( (ubyte *)NakedBuf, NakedPacketLen, NetPlayers.players[NakedPacketDestPlayer].network.ipx.server, NetPlayers.players[NakedPacketDestPlayer].network.ipx.node,Players[NakedPacketDestPlayer].net_address );
5090 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 );
5093 NakedPacketDestPlayer=-1;
5096 if (WaitForRefuseAnswer && timer_get_approx_seconds()>(RefuseTimeLimit+(F1_0*12)))
5097 WaitForRefuseAnswer=0;
5099 last_send_time += FrameTime;
5100 last_timeout_check += FrameTime;
5102 // Send out packet PacksPerSec times per second maximum... unless they fire, then send more often...
5103 if ( (last_send_time>F1_0/Netgame.PacketsPerSec) || (Network_laser_fired) || force || PacketUrgent ) {
5104 if ( Players[Player_num].connected ) {
5105 int objnum = Players[Player_num].objnum;
5109 multi_send_robot_frame(0);
5110 multi_send_fire(); // Do firing if needed..
5115 if (Netgame.ShortPackets)
5118 ubyte send_data[IPX_MAX_DATA_SIZE];
5121 create_shortpos(&ShortSyncPack.thepos, Objects+objnum, 0);
5122 ShortSyncPack.type = PID_PDATA;
5123 ShortSyncPack.playernum = Player_num;
5124 ShortSyncPack.obj_render_type = Objects[objnum].render_type;
5125 ShortSyncPack.level_num = Current_level_num;
5126 ShortSyncPack.data_size = MySyncPack.data_size;
5127 memcpy (&ShortSyncPack.data[0],&MySyncPack.data[0],MySyncPack.data_size);
5129 for (i=0; i<N_players; i++ ) {
5130 if ( (Players[i].connected) && (i!=Player_num ) ) {
5131 MySyncPack.numpackets = Players[i].n_packets_sent++;
5132 ShortSyncPack.numpackets=MySyncPack.numpackets;
5133 if (Network_game_type == IPX_GAME) {
5135 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 );
5137 squish_short_frame_info(ShortSyncPack, send_data);
5138 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 );
5142 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 );
5148 else // If long packets
5152 MySyncPack.type = PID_PDATA;
5153 MySyncPack.playernum = Player_num;
5154 MySyncPack.obj_render_type = Objects[objnum].render_type;
5155 MySyncPack.level_num = Current_level_num;
5156 MySyncPack.obj_segnum = Objects[objnum].segnum;
5157 MySyncPack.obj_pos = Objects[objnum].pos;
5158 MySyncPack.obj_orient = Objects[objnum].orient;
5159 MySyncPack.phys_velocity = Objects[objnum].mtype.phys_info.velocity;
5160 MySyncPack.phys_rotvel = Objects[objnum].mtype.phys_info.rotvel;
5162 send_data_size = MySyncPack.data_size; // do this so correct size data is sent
5164 #ifdef MACINTOSH // do the swap stuff
5165 if (Network_game_type == IPX_GAME) {
5166 MySyncPack.obj_segnum = INTEL_SHORT(MySyncPack.obj_segnum);
5167 MySyncPack.obj_pos.x = INTEL_INT((int)MySyncPack.obj_pos.x);
5168 MySyncPack.obj_pos.y = INTEL_INT((int)MySyncPack.obj_pos.y);
5169 MySyncPack.obj_pos.z = INTEL_INT((int)MySyncPack.obj_pos.z);
5171 MySyncPack.obj_orient.rvec.x = INTEL_INT((int)MySyncPack.obj_orient.rvec.x);
5172 MySyncPack.obj_orient.rvec.y = INTEL_INT((int)MySyncPack.obj_orient.rvec.y);
5173 MySyncPack.obj_orient.rvec.z = INTEL_INT((int)MySyncPack.obj_orient.rvec.z);
5174 MySyncPack.obj_orient.uvec.x = INTEL_INT((int)MySyncPack.obj_orient.uvec.x);
5175 MySyncPack.obj_orient.uvec.y = INTEL_INT((int)MySyncPack.obj_orient.uvec.y);
5176 MySyncPack.obj_orient.uvec.z = INTEL_INT((int)MySyncPack.obj_orient.uvec.z);
5177 MySyncPack.obj_orient.fvec.x = INTEL_INT((int)MySyncPack.obj_orient.fvec.x);
5178 MySyncPack.obj_orient.fvec.y = INTEL_INT((int)MySyncPack.obj_orient.fvec.y);
5179 MySyncPack.obj_orient.fvec.z = INTEL_INT((int)MySyncPack.obj_orient.fvec.z);
5181 MySyncPack.phys_velocity.x = INTEL_INT((int)MySyncPack.phys_velocity.x);
5182 MySyncPack.phys_velocity.y = INTEL_INT((int)MySyncPack.phys_velocity.y);
5183 MySyncPack.phys_velocity.z = INTEL_INT((int)MySyncPack.phys_velocity.z);
5185 MySyncPack.phys_rotvel.x = INTEL_INT((int)MySyncPack.phys_rotvel.x);
5186 MySyncPack.phys_rotvel.y = INTEL_INT((int)MySyncPack.phys_rotvel.y);
5187 MySyncPack.phys_rotvel.z = INTEL_INT((int)MySyncPack.phys_rotvel.z);
5189 MySyncPack.data_size = INTEL_SHORT(MySyncPack.data_size);
5193 for (i=0; i<N_players; i++ ) {
5194 if ( (Players[i].connected) && (i!=Player_num ) ) {
5195 if (Network_game_type == IPX_GAME)
5196 MySyncPack.numpackets = INTEL_INT(Players[i].n_packets_sent);
5199 MySyncPack.numpackets = Players[i].n_packets_sent;
5202 Players[i].n_packets_sent++;
5203 if (Network_game_type == IPX_GAME)
5204 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 );
5207 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);
5213 MySyncPack.data_size = 0; // Start data over at 0 length.
5214 if (Control_center_destroyed)
5217 Players[Player_num].connected=3;
5218 if (timer_get_approx_seconds() > (LastEndlevel+(F1_0/2)))
5220 network_send_endlevel_packet();
5221 LastEndlevel=timer_get_approx_seconds();
5224 //mprintf( (0, "Packet has %d bytes appended (TS=%d)\n", MySyncPack.data_size, sizeof(frame_info)-MaxXDataSize+MySyncPack.data_size ));
5231 if ((last_timeout_check > F1_0) && !(Control_center_destroyed))
5233 fix approx_time = timer_get_approx_seconds();
5234 // Check for player timeouts
5235 for (i = 0; i < N_players; i++)
5237 if ((i != Player_num) && (Players[i].connected == 1))
5239 if ((LastPacketTime[i] == 0) || (LastPacketTime[i] > approx_time))
5241 LastPacketTime[i] = approx_time;
5244 if ((approx_time - LastPacketTime[i]) > (15*F1_0))
5245 network_timeout_player(i);
5248 last_timeout_check = 0;
5254 MySyncPack.data_size = 0;
5259 if (VerifyPlayerJoined!=-1 && !(FrameCount & 63))
5260 resend_sync_due_to_packet_loss_for_allender(); // This will resend to network_player_rejoining
5262 if (Network_send_objects)
5263 network_send_objects();
5265 if (Network_sending_extras && VerifyPlayerJoined==-1)
5267 network_send_extras();
5272 int missed_packets = 0;
5274 int ConsistencyCount = 0;
5276 void network_consistency_error(void)
5278 if (++ConsistencyCount < 10)
5281 Function_mode = FMODE_MENU;
5283 nm_messagebox(NULL, 1, TXT_OK, TXT_CONSISTENCY_ERROR);
5285 nm_messagebox(NULL, 1, TXT_OK, "Failed to join the netgame.\nYou are missing packets. Check\nyour network connection and\ntry again.");
5287 Function_mode = FMODE_GAME;
5288 ConsistencyCount = 0;
5289 multi_quit_game = 1;
5290 multi_leave_menu = 1;
5291 multi_reset_stuff();
5292 Function_mode = FMODE_MENU;
5295 void network_process_pdata (char *data)
5297 Assert (Game_mode & GM_NETWORK);
5299 if (Netgame.ShortPackets)
5300 network_read_pdata_short_packet ((short_frame_info *)data);
5302 network_read_pdata_packet ((frame_info *)data);
5305 void network_read_pdata_packet(frame_info *pd )
5309 object * TheirObj = NULL;
5311 // frame_info should be aligned...for mac, make the necessary adjustments
5313 if (Network_game_type == IPX_GAME) {
5314 pd->numpackets = INTEL_INT(pd->numpackets);
5315 pd->obj_pos.x = INTEL_INT(pd->obj_pos.x);
5316 pd->obj_pos.y = INTEL_INT(pd->obj_pos.y);
5317 pd->obj_pos.z = INTEL_INT(pd->obj_pos.z);
5319 pd->obj_orient.rvec.x = (fix)INTEL_INT((int)pd->obj_orient.rvec.x);
5320 pd->obj_orient.rvec.y = (fix)INTEL_INT((int)pd->obj_orient.rvec.y);
5321 pd->obj_orient.rvec.z = (fix)INTEL_INT((int)pd->obj_orient.rvec.z);
5322 pd->obj_orient.uvec.x = (fix)INTEL_INT((int)pd->obj_orient.uvec.x);
5323 pd->obj_orient.uvec.y = (fix)INTEL_INT((int)pd->obj_orient.uvec.y);
5324 pd->obj_orient.uvec.z = (fix)INTEL_INT((int)pd->obj_orient.uvec.z);
5325 pd->obj_orient.fvec.x = (fix)INTEL_INT((int)pd->obj_orient.fvec.x);
5326 pd->obj_orient.fvec.y = (fix)INTEL_INT((int)pd->obj_orient.fvec.y);
5327 pd->obj_orient.fvec.z = (fix)INTEL_INT((int)pd->obj_orient.fvec.z);
5329 pd->phys_velocity.x = (fix)INTEL_INT((int)pd->phys_velocity.x);
5330 pd->phys_velocity.y = (fix)INTEL_INT((int)pd->phys_velocity.y);
5331 pd->phys_velocity.z = (fix)INTEL_INT((int)pd->phys_velocity.z);
5333 pd->phys_rotvel.x = (fix)INTEL_INT((int)pd->phys_rotvel.x);
5334 pd->phys_rotvel.y = (fix)INTEL_INT((int)pd->phys_rotvel.y);
5335 pd->phys_rotvel.z = (fix)INTEL_INT((int)pd->phys_rotvel.z);
5337 pd->obj_segnum = INTEL_SHORT(pd->obj_segnum);
5338 pd->data_size = INTEL_SHORT(pd->data_size);
5342 TheirPlayernum = pd->playernum;
5343 TheirObjnum = Players[pd->playernum].objnum;
5345 if (TheirPlayernum < 0) {
5346 Int3(); // This packet is bogus!!
5350 if (VerifyPlayerJoined!=-1 && TheirPlayernum==VerifyPlayerJoined)
5352 // Hurray! Someone really really got in the game (I think).
5353 mprintf ((0,"Hurray! VPJ (%d) reset!\n",VerifyPlayerJoined));
5354 VerifyPlayerJoined=-1;
5357 if (!multi_quit_game && (TheirPlayernum >= N_players)) {
5358 if (Network_status!=NETSTAT_WAITING)
5360 Int3(); // We missed an important packet!
5361 network_consistency_error();
5367 if (Endlevel_sequence || (Network_status == NETSTAT_ENDLEVEL) ) {
5368 int old_Endlevel_sequence = Endlevel_sequence;
5369 Endlevel_sequence = 1;
5370 if ( pd->data_size>0 ) {
5371 // pass pd->data to some parser function....
5372 multi_process_bigdata( pd->data, pd->data_size );
5374 Endlevel_sequence = old_Endlevel_sequence;
5377 // mprintf((0, "Gametime = %d, Frametime = %d.\n", GameTime, FrameTime));
5379 if ((byte)pd->level_num != Current_level_num)
5381 mprintf((0, "Got frame packet from player %d wrong level %d!\n", pd->playernum, pd->level_num));
5385 TheirObj = &Objects[TheirObjnum];
5387 //------------- Keep track of missed packets -----------------
5388 Players[TheirPlayernum].n_packets_got++;
5390 LastPacketTime[TheirPlayernum] = timer_get_approx_seconds();
5392 if ( pd->numpackets != Players[TheirPlayernum].n_packets_got ) {
5395 missed_packets = pd->numpackets-Players[TheirPlayernum].n_packets_got;
5396 if ((pd->numpackets-Players[TheirPlayernum].n_packets_got)>0)
5397 TotalMissedPackets += pd->numpackets-Players[TheirPlayernum].n_packets_got;
5399 if ( missed_packets > 0 )
5400 mprintf(( 0, "Missed %d packets from player #%d (%d total)\n", pd->numpackets-Players[TheirPlayernum].n_packets_got, TheirPlayernum, missed_packets ));
5402 mprintf( (0, "Got %d late packets from player #%d (%d total)\n", Players[TheirPlayernum].n_packets_got-pd->numpackets, TheirPlayernum, missed_packets ));
5405 #ifdef APPLETALK_DEBUG
5406 if (Network_game_type == APPLETALK_GAME) {
5407 if ( missed_packets > 0 )
5408 fprintf( at_fp, "Missed %d packets from player #%d (%d total)\n", pd->numpackets-Players[TheirPlayernum].n_packets_got, TheirPlayernum, missed_packets );
5410 fprintf( at_fp, "Got %d late packets from player #%d (%d total)\n", Players[TheirPlayernum].n_packets_got-pd->numpackets, TheirPlayernum, missed_packets );
5415 if (Network_game_type == IPX_GAME) {
5416 if ( missed_packets > 0 )
5417 fprintf( ipx_fp, "Missed %d packets from player #%d (%d total)\n", pd->numpackets-Players[TheirPlayernum].n_packets_got, TheirPlayernum, missed_packets );
5419 fprintf( ipx_fp, "Got %d late packets from player #%d (%d total)\n", Players[TheirPlayernum].n_packets_got-pd->numpackets, TheirPlayernum, missed_packets );
5424 Players[TheirPlayernum].n_packets_got = pd->numpackets;
5427 //------------ Read the player's ship's object info ----------------------
5428 TheirObj->pos = pd->obj_pos;
5429 TheirObj->orient = pd->obj_orient;
5430 TheirObj->mtype.phys_info.velocity = pd->phys_velocity;
5431 TheirObj->mtype.phys_info.rotvel = pd->phys_rotvel;
5433 if ((TheirObj->render_type != pd->obj_render_type) && (pd->obj_render_type == RT_POLYOBJ))
5434 multi_make_ghost_player(TheirPlayernum);
5436 obj_relink(TheirObjnum,pd->obj_segnum);
5438 if (TheirObj->movement_type == MT_PHYSICS)
5439 set_thrust_from_velocity(TheirObj);
5441 //------------ Welcome them back if reconnecting --------------
5442 if (!Players[TheirPlayernum].connected) {
5443 Players[TheirPlayernum].connected = 1;
5445 if (Newdemo_state == ND_STATE_RECORDING)
5446 newdemo_record_multi_reconnect(TheirPlayernum);
5448 multi_make_ghost_player(TheirPlayernum);
5450 create_player_appearance_effect(&Objects[TheirObjnum]);
5452 digi_play_sample( SOUND_HUD_MESSAGE, F1_0);
5454 ClipRank (&NetPlayers.players[TheirPlayernum].rank);
5456 if (FindArg("-norankings"))
5457 HUD_init_message( "'%s' %s", Players[TheirPlayernum].callsign, TXT_REJOIN );
5459 HUD_init_message( "%s'%s' %s", RankStrings[NetPlayers.players[TheirPlayernum].rank],Players[TheirPlayernum].callsign, TXT_REJOIN );
5465 //------------ Parse the extra data at the end ---------------
5467 if ( pd->data_size>0 ) {
5468 // pass pd->data to some parser function....
5469 multi_process_bigdata( pd->data, pd->data_size );
5475 void get_short_frame_info(ubyte *old_info, short_frame_info *new_info)
5479 new_info->type = old_info[loc]; loc++; loc += 3; // skip three for pad byte
5480 memcpy(&(new_info->numpackets), &(old_info[loc]), 4); loc += 4;
5481 new_info->numpackets = INTEL_INT(new_info->numpackets);
5482 memcpy(new_info->thepos.bytemat, &(old_info[loc]), 9); loc += 9;
5483 memcpy(&(new_info->thepos.xo), &(old_info[loc]), 2); loc += 2;
5484 memcpy(&(new_info->thepos.yo), &(old_info[loc]), 2); loc += 2;
5485 memcpy(&(new_info->thepos.zo), &(old_info[loc]), 2); loc += 2;
5486 memcpy(&(new_info->thepos.segment), &(old_info[loc]), 2); loc += 2;
5487 memcpy(&(new_info->thepos.velx), &(old_info[loc]), 2); loc += 2;
5488 memcpy(&(new_info->thepos.vely), &(old_info[loc]), 2); loc += 2;
5489 memcpy(&(new_info->thepos.velz), &(old_info[loc]), 2); loc += 2;
5490 new_info->thepos.xo = INTEL_SHORT(new_info->thepos.xo);
5491 new_info->thepos.yo = INTEL_SHORT(new_info->thepos.yo);
5492 new_info->thepos.zo = INTEL_SHORT(new_info->thepos.zo);
5493 new_info->thepos.segment = INTEL_SHORT(new_info->thepos.segment);
5494 new_info->thepos.velx = INTEL_SHORT(new_info->thepos.velx);
5495 new_info->thepos.vely = INTEL_SHORT(new_info->thepos.vely);
5496 new_info->thepos.velz = INTEL_SHORT(new_info->thepos.velz);
5498 memcpy(&(new_info->data_size), &(old_info[loc]), 2); loc += 2;
5499 new_info->data_size = INTEL_SHORT(new_info->data_size);
5500 new_info->playernum = old_info[loc]; loc++;
5501 new_info->obj_render_type = old_info[loc]; loc++;
5502 new_info->level_num = old_info[loc]; loc++;
5503 memcpy(new_info->data, &(old_info[loc]), new_info->data_size);
5507 void network_read_pdata_short_packet(short_frame_info *pd )
5511 object * TheirObj = NULL;
5512 short_frame_info new_pd;
5514 // short frame info is not aligned because of shortpos. The mac
5515 // will call totally hacked and gross function to fix this up.
5517 if (Network_game_type == IPX_GAME) {
5519 memcpy(&new_pd, (ubyte *)pd, sizeof(short_frame_info));
5521 get_short_frame_info((ubyte *)pd, &new_pd);
5524 memcpy(&new_pd, (ubyte *)pd, sizeof(short_frame_info));
5527 TheirPlayernum = new_pd.playernum;
5528 TheirObjnum = Players[new_pd.playernum].objnum;
5530 if (TheirPlayernum < 0) {
5531 Int3(); // This packet is bogus!!
5534 if (!multi_quit_game && (TheirPlayernum >= N_players)) {
5535 if (Network_status!=NETSTAT_WAITING)
5537 Int3(); // We missed an important packet!
5538 network_consistency_error();
5545 if (VerifyPlayerJoined!=-1 && TheirPlayernum==VerifyPlayerJoined)
5547 // Hurray! Someone really really got in the game (I think).
5548 mprintf ((0,"Hurray! VPJ (%d) reset!\n",VerifyPlayerJoined));
5549 VerifyPlayerJoined=-1;
5552 if (Endlevel_sequence || (Network_status == NETSTAT_ENDLEVEL) ) {
5553 int old_Endlevel_sequence = Endlevel_sequence;
5554 Endlevel_sequence = 1;
5555 if ( new_pd.data_size>0 ) {
5556 // pass pd->data to some parser function....
5557 multi_process_bigdata( new_pd.data, new_pd.data_size );
5559 Endlevel_sequence = old_Endlevel_sequence;
5562 // mprintf((0, "Gametime = %d, Frametime = %d.\n", GameTime, FrameTime));
5564 if ((byte)new_pd.level_num != Current_level_num)
5566 mprintf((0, "Got frame packet from player %d wrong level %d!\n", new_pd.playernum, new_pd.level_num));
5570 TheirObj = &Objects[TheirObjnum];
5572 //------------- Keep track of missed packets -----------------
5573 Players[TheirPlayernum].n_packets_got++;
5575 LastPacketTime[TheirPlayernum] = timer_get_approx_seconds();
5577 if ( new_pd.numpackets != Players[TheirPlayernum].n_packets_got ) {
5580 missed_packets = new_pd.numpackets-Players[TheirPlayernum].n_packets_got;
5581 if ((new_pd.numpackets-Players[TheirPlayernum].n_packets_got)>0)
5582 TotalMissedPackets += new_pd.numpackets-Players[TheirPlayernum].n_packets_got;
5584 if ( missed_packets > 0 )
5585 mprintf( (0, "Missed %d packets from player #%d (%d total)\n", new_pd.numpackets-Players[TheirPlayernum].n_packets_got, TheirPlayernum, missed_packets ));
5587 mprintf( (0, "Got %d late packets from player #%d (%d total)\n", Players[TheirPlayernum].n_packets_got-new_pd.numpackets, TheirPlayernum, missed_packets ));
5589 Players[TheirPlayernum].n_packets_got = new_pd.numpackets;
5592 //------------ Read the player's ship's object info ----------------------
5594 extract_shortpos(TheirObj, &new_pd.thepos, 0);
5596 if ((TheirObj->render_type != new_pd.obj_render_type) && (new_pd.obj_render_type == RT_POLYOBJ))
5597 multi_make_ghost_player(TheirPlayernum);
5599 if (TheirObj->movement_type == MT_PHYSICS)
5600 set_thrust_from_velocity(TheirObj);
5602 //------------ Welcome them back if reconnecting --------------
5603 if (!Players[TheirPlayernum].connected) {
5604 Players[TheirPlayernum].connected = 1;
5606 if (Newdemo_state == ND_STATE_RECORDING)
5607 newdemo_record_multi_reconnect(TheirPlayernum);
5609 multi_make_ghost_player(TheirPlayernum);
5611 create_player_appearance_effect(&Objects[TheirObjnum]);
5613 digi_play_sample( SOUND_HUD_MESSAGE, F1_0);
5614 ClipRank (&NetPlayers.players[TheirPlayernum].rank);
5616 if (FindArg("-norankings"))
5617 HUD_init_message( "'%s' %s", Players[TheirPlayernum].callsign, TXT_REJOIN );
5619 HUD_init_message( "%s'%s' %s", RankStrings[NetPlayers.players[TheirPlayernum].rank],Players[TheirPlayernum].callsign, TXT_REJOIN );
5625 //------------ Parse the extra data at the end ---------------
5627 if ( new_pd.data_size>0 ) {
5628 // pass pd->data to some parser function....
5629 multi_process_bigdata( new_pd.data, new_pd.data_size );
5635 void network_set_power (void)
5637 int opt=0,choice,opt_primary,opt_second,opt_power;
5641 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Laser upgrade"; m[opt].value=Netgame.DoLaserUpgrade; opt++;
5642 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Super lasers"; m[opt].value=Netgame.DoSuperLaser; opt++;
5643 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Quad Lasers"; m[opt].value=Netgame.DoQuadLasers; opt++;
5644 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Vulcan cannon"; m[opt].value=Netgame.DoVulcan; opt++;
5645 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Spreadfire cannon"; m[opt].value=Netgame.DoSpread; opt++;
5646 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Plasma cannon"; m[opt].value=Netgame.DoPlasma; opt++;
5647 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Fusion cannon"; m[opt].value=Netgame.DoFusions; opt++;
5648 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Gauss cannon"; m[opt].value=Netgame.DoGauss; opt++;
5649 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Helix cannon"; m[opt].value=Netgame.DoHelix; opt++;
5650 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Phoenix cannon"; m[opt].value=Netgame.DoPhoenix; opt++;
5651 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Omega cannon"; m[opt].value=Netgame.DoOmega; opt++;
5654 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Homing Missiles"; m[opt].value=Netgame.DoHoming; opt++;
5655 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Proximity Bombs"; m[opt].value=Netgame.DoProximity; opt++;
5656 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Smart Missiles"; m[opt].value=Netgame.DoSmarts; opt++;
5657 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Mega Missiles"; m[opt].value=Netgame.DoMegas; opt++;
5658 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Flash Missiles"; m[opt].value=Netgame.DoFlash; opt++;
5659 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Guided Missiles"; m[opt].value=Netgame.DoGuided; opt++;
5660 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Smart Mines"; m[opt].value=Netgame.DoSmartMine; opt++;
5661 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Mercury Missiles"; m[opt].value=Netgame.DoMercury; opt++;
5662 m[opt].type = NM_TYPE_CHECK; m[opt].text = "EarthShaker Missiles"; m[opt].value=Netgame.DoEarthShaker; opt++;
5665 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Invulnerability"; m[opt].value=Netgame.DoInvulnerability; opt++;
5666 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Cloaking"; m[opt].value=Netgame.DoCloak; opt++;
5667 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Afterburners"; m[opt].value=Netgame.DoAfterburner; opt++;
5668 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Ammo rack"; m[opt].value=Netgame.DoAmmoRack; opt++;
5669 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Energy Converter"; m[opt].value=Netgame.DoConverter; opt++;
5670 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Headlight"; m[opt].value=Netgame.DoHeadlight; opt++;
5672 choice = newmenu_do(NULL, "Objects to allow", opt, m, NULL);
5674 Netgame.DoLaserUpgrade=m[opt_primary].value;
5675 Netgame.DoSuperLaser=m[opt_primary+1].value;
5676 Netgame.DoQuadLasers=m[opt_primary+2].value;
5677 Netgame.DoVulcan=m[opt_primary+3].value;
5678 Netgame.DoSpread=m[opt_primary+4].value;
5679 Netgame.DoPlasma=m[opt_primary+5].value;
5680 Netgame.DoFusions=m[opt_primary+6].value;
5681 Netgame.DoGauss=m[opt_primary+7].value;
5682 Netgame.DoHelix=m[opt_primary+8].value;
5683 Netgame.DoPhoenix=m[opt_primary+9].value;
5684 Netgame.DoOmega=m[opt_primary+10].value;
5686 Netgame.DoHoming=m[opt_second].value;
5687 Netgame.DoProximity=m[opt_second+1].value;
5688 Netgame.DoSmarts=m[opt_second+2].value;
5689 Netgame.DoMegas=m[opt_second+3].value;
5690 Netgame.DoFlash=m[opt_second+4].value;
5691 Netgame.DoGuided=m[opt_second+5].value;
5692 Netgame.DoSmartMine=m[opt_second+6].value;
5693 Netgame.DoMercury=m[opt_second+7].value;
5694 Netgame.DoEarthShaker=m[opt_second+8].value;
5696 Netgame.DoInvulnerability=m[opt_power].value;
5697 Netgame.DoCloak=m[opt_power+1].value;
5698 Netgame.DoAfterburner=m[opt_power+2].value;
5699 Netgame.DoAmmoRack=m[opt_power+3].value;
5700 Netgame.DoConverter=m[opt_power+4].value;
5701 Netgame.DoHeadlight=m[opt_power+5].value;
5705 void SetAllAllowablesTo (int on)
5707 last_cinvul = control_invul_time = 0; //default to zero
5709 Netgame.DoMegas=Netgame.DoSmarts=Netgame.DoFusions=Netgame.DoHelix=\
5710 Netgame.DoPhoenix=Netgame.DoCloak=Netgame.DoInvulnerability=\
5711 Netgame.DoAfterburner=Netgame.DoGauss=Netgame.DoVulcan=Netgame.DoPlasma=on;
5713 Netgame.DoOmega=Netgame.DoSuperLaser=Netgame.DoProximity=\
5714 Netgame.DoSpread=Netgame.DoMercury=Netgame.DoSmartMine=Netgame.DoFlash=\
5715 Netgame.DoGuided=Netgame.DoEarthShaker=on;
5717 Netgame.DoConverter=Netgame.DoAmmoRack=Netgame.DoHeadlight=on;
5718 Netgame.DoHoming=Netgame.DoLaserUpgrade=Netgame.DoQuadLasers=on;
5719 Netgame.BrightPlayers=Netgame.invul=on;
5725 // Jeez -- mac compiler can't handle all of these on the same decl line.
5726 int opt_setpower,opt_playtime,opt_killgoal,opt_socket,opt_marker_view,opt_light,opt_show_on_map;
5727 int opt_difficulty,opt_packets,opt_short_packets, opt_bright,opt_start_invul;
5730 void network_more_options_poll( int nitems, newmenu_item * menus, int * key, int citem );
5732 void network_more_game_options ()
5735 char PlayText[80],KillText[80],srinvul[50],socket_string[5],packstring[5];
5738 sprintf (socket_string,"%d",Network_socket);
5739 sprintf (packstring,"%d",Netgame.PacketsPerSec);
5741 opt_difficulty = opt;
5742 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++;
5745 sprintf( srinvul, "%s: %d %s", TXT_REACTOR_LIFE, control_invul_time*5, TXT_MINUTES_ABBREV );
5746 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++;
5749 sprintf( PlayText, "Max time: %d %s", Netgame.PlayTimeAllowed*5, TXT_MINUTES_ABBREV );
5750 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++;
5753 sprintf( KillText, "Kill Goal: %d kills", Netgame.KillGoal*5);
5754 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++;
5756 opt_start_invul=opt;
5757 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Invulnerable when reappearing"; m[opt].value=Netgame.invul; opt++;
5759 opt_marker_view = opt;
5760 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Allow camera views from Markers"; m[opt].value=Netgame.Allow_marker_view; opt++;
5762 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Indestructible lights"; m[opt].value=Netgame.AlwaysLighting; opt++;
5765 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Bright player ships"; m[opt].value=Netgame.BrightPlayers; opt++;
5768 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Show enemy names on HUD"; m[opt].value=Netgame.ShowAllNames; opt++;
5770 opt_show_on_map=opt;
5771 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++;
5773 opt_short_packets=opt;
5774 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Short packets"; m[opt].value=Netgame.ShortPackets; opt++;
5777 m[opt].type = NM_TYPE_MENU; m[opt].text = "Set Objects allowed..."; opt++;
5779 if (Network_game_type == IPX_GAME) {
5780 m[opt].type = NM_TYPE_TEXT; m[opt].text = "Network socket"; opt++;
5782 m[opt].type = NM_TYPE_INPUT; m[opt].text = socket_string; m[opt].text_len=4; opt++;
5785 m[opt].type = NM_TYPE_TEXT; m[opt].text = "Packets per second (2 - 20)"; opt++;
5787 m[opt].type = NM_TYPE_INPUT; m[opt].text=packstring; m[opt].text_len=2; opt++;
5789 LastKillGoal=Netgame.KillGoal;
5790 LastPTA=Netgame.PlayTimeAllowed;
5794 ExtGameStatus=GAMESTAT_MORE_NETGAME_OPTIONS;
5795 i = newmenu_do1( NULL, "Additional netgame options", opt, m, network_more_options_poll, 0 );
5797 //control_invul_time = atoi( srinvul )*60*F1_0;
5798 control_invul_time = m[opt_cinvul].value;
5799 Netgame.control_invul_time = control_invul_time*5*F1_0*60;
5801 if (i==opt_setpower)
5803 network_set_power ();
5807 Netgame.PacketsPerSec=atoi(packstring);
5809 if (Netgame.PacketsPerSec>20)
5811 Netgame.PacketsPerSec=20;
5812 nm_messagebox(TXT_ERROR, 1, TXT_OK, "Packet value out of range\nSetting value to 20");
5814 if (Netgame.PacketsPerSec<2)
5816 nm_messagebox(TXT_ERROR, 1, TXT_OK, "Packet value out of range\nSetting value to 2");
5817 Netgame.PacketsPerSec=2;
5820 mprintf ((0,"Hey! Sending out %d packets per second\n",Netgame.PacketsPerSec));
5822 if (Network_game_type == IPX_GAME) {
5823 if ((atoi(socket_string))!=Network_socket) {
5824 Network_socket=atoi(socket_string);
5825 ipx_change_default_socket( IPX_DEFAULT_SOCKET + Network_socket );
5829 Netgame.invul=m[opt_start_invul].value;
5830 Netgame.BrightPlayers=m[opt_bright].value;
5831 Netgame.ShortPackets=m[opt_short_packets].value;
5832 Netgame.ShowAllNames=m[opt_show_names].value;
5833 network_AdjustMaxDataSize();
5835 Netgame.Allow_marker_view=m[opt_marker_view].value;
5836 Netgame.AlwaysLighting=m[opt_light].value;
5837 netgame_difficulty=Difficulty_level = m[opt_difficulty].value;
5838 if (m[opt_show_on_map].value)
5839 Netgame.game_flags |= NETGAME_FLAG_SHOW_MAP;
5844 void network_more_options_poll( int nitems, newmenu_item * menus, int * key, int citem )
5847 citem = citem; // kills compile warnings
5851 if ( last_cinvul != menus[opt_cinvul].value ) {
5852 sprintf( menus[opt_cinvul].text, "%s: %d %s", TXT_REACTOR_LIFE, menus[opt_cinvul].value*5, TXT_MINUTES_ABBREV );
5853 last_cinvul = menus[opt_cinvul].value;
5854 menus[opt_cinvul].redraw = 1;
5857 if (menus[opt_playtime].value!=LastPTA)
5861 nm_messagebox ("Sorry",1,TXT_OK,"Registered version only!");
5862 menus[opt_playtime].value=0;
5863 menus[opt_playtime].redraw=1;
5867 if (Game_mode & GM_MULTI_COOP)
5870 nm_messagebox ("Sorry",1,TXT_OK,"You can't change those for coop!");
5871 menus[opt_playtime].value=0;
5872 menus[opt_playtime].redraw=1;
5876 Netgame.PlayTimeAllowed=menus[opt_playtime].value;
5877 sprintf( menus[opt_playtime].text, "Max Time: %d %s", Netgame.PlayTimeAllowed*5, TXT_MINUTES_ABBREV );
5878 LastPTA=Netgame.PlayTimeAllowed;
5879 menus[opt_playtime].redraw=1;
5881 if (menus[opt_killgoal].value!=LastKillGoal)
5884 nm_messagebox ("Sorry",1,TXT_OK,"Registered version only!");
5885 menus[opt_killgoal].value=0;
5886 menus[opt_killgoal].redraw=1;
5892 if (Game_mode & GM_MULTI_COOP)
5894 nm_messagebox ("Sorry",1,TXT_OK,"You can't change those for coop!");
5895 menus[opt_killgoal].value=0;
5896 menus[opt_killgoal].redraw=1;
5902 Netgame.KillGoal=menus[opt_killgoal].value;
5903 sprintf( menus[opt_killgoal].text, "Kill Goal: %d kills", Netgame.KillGoal*5);
5904 LastKillGoal=Netgame.KillGoal;
5905 menus[opt_killgoal].redraw=1;
5909 extern void multi_send_light (int,ubyte);
5910 extern void multi_send_light_specific (int,int,ubyte);
5912 void network_send_smash_lights (int pnum)
5914 // send the lights that have been blown out
5920 for (i=0;i<=Highest_segment_index;i++)
5921 if (Light_subtracted[i])
5922 multi_send_light_specific(pnum,i,Light_subtracted[i]);
5925 extern int Num_triggers;
5926 extern void multi_send_trigger_specific (char pnum,char);
5928 void network_send_fly_thru_triggers (int pnum)
5930 // send the fly thru triggers that have been disabled
5934 for (i=0;i<Num_triggers;i++)
5935 if (Triggers[i].flags & TF_DISABLED)
5936 multi_send_trigger_specific(pnum,i);
5939 void network_send_player_flags()
5943 for (i=0;i<N_players;i++)
5944 multi_send_flags(i);
5947 void network_ping (ubyte flag,int pnum)
5952 mybuf[1]=Player_num;
5954 if (Network_game_type == IPX_GAME)
5955 ipx_send_packet_data( (ubyte *)mybuf, 2, NetPlayers.players[pnum].network.ipx.server, NetPlayers.players[pnum].network.ipx.node,Players[pnum].net_address );
5958 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);
5962 extern fix PingLaunchTime,PingReturnTime;
5964 void network_handle_ping_return (ubyte pnum)
5966 if (PingLaunchTime==0 || pnum>=N_players)
5968 mprintf ((0,"Got invalid PING RETURN from %s!\n",Players[pnum].callsign));
5972 PingReturnTime=timer_get_fixed_seconds();
5974 HUD_init_message ("Ping time for %s is %d ms!",Players[pnum].callsign,
5975 f2i(fixmul(PingReturnTime-PingLaunchTime,i2f(1000))));
5979 void network_send_ping (ubyte pnum)
5981 network_ping (PID_PING_SEND,pnum);
5984 void DoRefuseStuff (sequence_packet *their)
5986 int i,new_player_num;
5988 ClipRank (&their->player.rank);
5990 for (i=0;i<MAX_PLAYERS;i++)
5991 if (!strcmp (their->player.callsign,Players[i].callsign))
5993 network_welcome_player(their);
5997 if (!WaitForRefuseAnswer)
5999 for (i=0;i<MAX_PLAYERS;i++)
6000 if (!strcmp (their->player.callsign,Players[i].callsign))
6002 network_welcome_player(their);
6006 digi_play_sample (SOUND_HUD_JOIN_REQUEST,F1_0*2);
6008 if (Game_mode & GM_TEAM)
6012 if (!FindArg("-norankings"))
6013 HUD_init_message ("%s %s wants to join",RankStrings[their->player.rank],their->player.callsign);
6015 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]);
6017 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]);
6019 // HUD_init_message ("Alt-1 to place on team %s!",Netgame.team_name[0]);
6020 // HUD_init_message ("Alt-2 to place on team %s!",Netgame.team_name[1]);
6023 HUD_init_message ("%s wants to join...press F6 to connect",their->player.callsign);
6025 strcpy (RefusePlayerName,their->player.callsign);
6026 RefuseTimeLimit=timer_get_approx_seconds();
6028 WaitForRefuseAnswer=1;
6032 for (i=0;i<MAX_PLAYERS;i++)
6033 if (!strcmp (their->player.callsign,Players[i].callsign))
6035 network_welcome_player(their);
6039 if (strcmp(their->player.callsign,RefusePlayerName))
6042 if (RefuseThisPlayer)
6046 WaitForRefuseAnswer=0;
6047 if (Game_mode & GM_TEAM)
6049 new_player_num=GetNewPlayerNumber (their);
6050 mprintf ((0,"Newplayernum=%d\n",new_player_num));
6052 Assert (RefuseTeam==1 || RefuseTeam==2);
6055 Netgame.team_vector &=(~(1<<new_player_num));
6057 Netgame.team_vector |=(1<<new_player_num);
6058 network_welcome_player(their);
6059 network_send_netgame_update ();
6062 network_welcome_player(their);
6066 if ((timer_get_approx_seconds()) > RefuseTimeLimit+REFUSE_INTERVAL)
6070 WaitForRefuseAnswer=0;
6071 if (!strcmp (their->player.callsign,RefusePlayerName)) {
6072 if (Network_game_type == IPX_GAME)
6073 network_dump_player(their->player.network.ipx.server,their->player.network.ipx.node, DUMP_DORK);
6076 network_dump_appletalk_player(their->player.network.appletalk.node,their->player.network.appletalk.net, their->player.network.appletalk.socket, DUMP_DORK);
6085 int GetNewPlayerNumber (sequence_packet *their)
6091 if ( N_players < MaxNumNetPlayers)
6096 // Slots are full but game is open, see if anyone is
6097 // disconnected and replace the oldest player with this new one
6099 int oldest_player = -1;
6100 fix oldest_time = timer_get_approx_seconds();
6102 Assert(N_players == MaxNumNetPlayers);
6104 for (i = 0; i < N_players; i++)
6106 if ( (!Players[i].connected) && (LastPacketTime[i] < oldest_time))
6108 oldest_time = LastPacketTime[i];
6112 return (oldest_player);
6116 void network_send_extras ()
6118 Assert (Player_joining_extras>-1);
6120 if (!network_i_am_master())
6122 mprintf ((0,"Hey! I'm not the master and I was gonna send info!\n"));
6124 // Network_sending_extras=0;
6129 if (Network_sending_extras==40)
6130 network_send_fly_thru_triggers(Player_joining_extras);
6131 if (Network_sending_extras==38)
6132 network_send_door_updates(Player_joining_extras);
6133 if (Network_sending_extras==35)
6134 network_send_markers();
6135 if (Network_sending_extras==30 && (Game_mode & GM_MULTI_ROBOTS))
6136 multi_send_stolen_items();
6137 if (Network_sending_extras==25 && (Netgame.PlayTimeAllowed || Netgame.KillGoal))
6138 multi_send_kill_goal_counts();
6139 if (Network_sending_extras==20)
6140 network_send_smash_lights(Player_joining_extras);
6141 if (Network_sending_extras==15)
6142 network_send_player_flags();
6143 if (Network_sending_extras==10)
6144 multi_send_powerup_update();
6145 // if (Network_sending_extras==5)
6146 // network_send_door_updates(Player_joining_extras); // twice!
6148 Network_sending_extras--;
6149 if (!Network_sending_extras)
6150 Player_joining_extras=-1;
6154 void network_send_naked_packet(char *buf, short len, int who)
6156 if (!(Game_mode&GM_NETWORK)) return;
6158 if (NakedPacketLen==0)
6160 NakedBuf[0]=PID_NAKED_PDATA;
6161 NakedBuf[1]=Player_num;
6165 if (len+NakedPacketLen>MaxXDataSize)
6167 // mprintf ((0,"Sending a naked packet of %d bytes.\n",NakedPacketLen));
6168 if (Network_game_type == IPX_GAME)
6169 ipx_send_packet_data( (ubyte *)NakedBuf, NakedPacketLen, NetPlayers.players[who].network.ipx.server, NetPlayers.players[who].network.ipx.node,Players[who].net_address );
6172 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 );
6175 memcpy (&NakedBuf[NakedPacketLen],buf,len);
6176 NakedPacketLen+=len;
6177 NakedPacketDestPlayer=who;
6181 memcpy (&NakedBuf[NakedPacketLen],buf,len);
6182 NakedPacketLen+=len;
6183 NakedPacketDestPlayer=who;
6188 void network_process_naked_pdata (char *data,int len)
6191 Assert (data[0]=PID_NAKED_PDATA);
6193 // mprintf ((0,"Processing a naked packet of %d length.\n",len));
6196 mprintf ((0,"Naked packet is bad!\n"));
6197 Int3(); // This packet is bogus!!
6201 if (!multi_quit_game && (pnum >= N_players)) {
6202 if (Network_status!=NETSTAT_WAITING)
6204 Int3(); // We missed an important packet!
6205 network_consistency_error();
6212 if (Endlevel_sequence || (Network_status == NETSTAT_ENDLEVEL) ) {
6213 int old_Endlevel_sequence = Endlevel_sequence;
6214 Endlevel_sequence = 1;
6215 multi_process_bigdata( data+2, len-2);
6216 Endlevel_sequence = old_Endlevel_sequence;
6220 multi_process_bigdata( data+2, len-2 );
6223 int ConnectionPacketLevel[]={0,1,1,1};
6224 int ConnectionSecLevel[]={12,3,5,7};
6226 int AppletalkConnectionPacketLevel[]={0,1,0};
6227 int AppletalkConnectionSecLevel[]={10,3,8};
6229 #if defined(RELEASE) && !defined(MACINTOSH) // use the code below for mac appletalk games
6230 int network_choose_connect ()
6235 int network_choose_connect ()
6242 if (Network_game_type == IPX_GAME) {
6244 m[opt].type = NM_TYPE_MENU; m[opt].text = "Local Subnet"; opt++;
6245 m[opt].type = NM_TYPE_MENU; m[opt].text = "14.4 modem over Internet"; opt++;
6246 m[opt].type = NM_TYPE_MENU; m[opt].text = "28.8 modem over Internet"; opt++;
6247 m[opt].type = NM_TYPE_MENU; m[opt].text = "ISDN or T1 over Internet"; opt++;
6249 choice = newmenu_do1( NULL, "Choose connection type", opt, m, NULL, 0 );
6254 Assert (choice>=0 && choice<=3);
6256 Netgame.ShortPackets=ConnectionPacketLevel[choice];
6257 Netgame.PacketsPerSec=ConnectionSecLevel[choice];
6262 m[opt].type = NM_TYPE_MENU; m[opt].text = "EtherTalk"; opt++;
6263 m[opt].type = NM_TYPE_MENU; m[opt].text = "LocalTalk"; opt++;
6264 m[opt].type = NM_TYPE_MENU; m[opt].text = "Other"; opt++;
6266 choice = newmenu_do1( NULL, "Choose connection type", opt, m, NULL, 0 );
6271 Network_appletalk_type = choice;
6273 Assert (choice>=0 && choice<=2);
6275 Netgame.ShortPackets=AppletalkConnectionPacketLevel[choice];
6276 Netgame.PacketsPerSec=AppletalkConnectionSecLevel[choice];
6290 SendLogFile=(FILE *)fopen ("sendlog.net","w");
6294 void OpenRecieveLog ()
6297 RecieveLogFile=(FILE *)fopen ("recvlog.net","w");
6303 int GetMyNetRanking ()
6308 if (Netlife_kills+Netlife_killed==0)
6311 rank=(int) (((float)Netlife_kills/3000.0)*8.0);
6313 eff=(int)((float)((float)Netlife_kills/((float)Netlife_killed+(float)Netlife_kills))*100.0);
6322 rank-=((59-eff)/10);
6329 mprintf ((0,"Rank is %d (%s)\n",rank+1,RankStrings[rank+1]));
6333 void ClipRank (signed char *rank)
6335 // This function insures no crashes when dealing with D2 1.0
6338 if (*rank<0 || *rank>9)
6341 void network_check_for_old_version (char pnum)
6343 if (NetPlayers.players[(int)pnum].version_major==1 && (NetPlayers.players[(int)pnum].version_minor & 0x0F)==0)
6344 NetPlayers.players[(int)pnum].rank=0;
6347 void network_request_player_names (int n)
6349 network_send_all_info_request (PID_GAME_PLAYERS,Active_games[n].Security);
6350 NamesInfoSecurity=Active_games[n].Security;
6353 extern char already_showing_info;
6354 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));
6356 void network_process_names_return (char *data)
6359 char mtext[15][50],temp[50];
6360 int i,t,l,gnum,num=0,count=5,numplayers;
6362 if (NamesInfoSecurity!=(*(int *)(data+1)))
6364 mprintf ((0,"Bad security on names return!\n"));
6365 mprintf ((0,"NIS=%d data=%d\n",NamesInfoSecurity,(*(int *)(data+1))));
6369 numplayers=data[count]; count++;
6371 if (numplayers==255)
6374 NamesInfoSecurity=-1;
6375 nm_messagebox(NULL, 1, "OK", "That game is refusing\nname requests.\n");
6380 Assert (numplayers>0 && numplayers<MAX_NUM_NET_PLAYERS);
6384 m[i].text=(char *)&mtext[i];
6385 m[i].type=NM_TYPE_TEXT;
6388 for (gnum=-1,i=0;i<num_active_games;i++)
6390 if (NamesInfoSecurity==Active_games[i].Security)
6400 NamesInfoSecurity=-1;
6401 nm_messagebox(NULL, 1, "OK", "The game you have requested\nnames from is gone.\n");
6406 sprintf (mtext[num],"Players of game '%s':",Active_games[gnum].game_name); num++;
6407 for (i=0;i<numplayers;i++)
6411 mprintf ((0,"%s\n",data+count));
6413 for (t=0;t<CALLSIGN_LEN+1;t++)
6414 temp[t]=data[count++];
6415 if (FindArg("-norankings"))
6416 sprintf (mtext[num],"%s",temp);
6418 sprintf (mtext[num],"%s%s",RankStrings[l],temp);
6423 if (data[count]==99)
6425 sprintf (mtext[num++]," ");
6426 sprintf (mtext[num++],"Short packets: %s",data[count+1]?"On":"Off");
6427 sprintf (mtext[num++],"Packets Per Second: %d",data[count+2]);
6430 already_showing_info=1;
6431 newmenu_dotiny2( NULL, NULL, num, m, NULL);
6432 already_showing_info=0;
6435 char NameReturning=1;
6437 void network_send_player_names (sequence_packet *their)
6439 int numconnected=0,count=0,i,t;
6444 mprintf ((0,"Got a player name without a return address! Get Jason\n"));
6448 buf[0]=PID_NAMES_RETURN; count++;
6449 (*(int *)(buf+1))=Netgame.Security; count+=4;
6453 buf[count]=255; count++;
6457 mprintf ((0,"RealSec=%d DS=%d\n",Netgame.Security,*(int *)(buf+1)));
6459 for (i=0;i<N_players;i++)
6460 if (Players[i].connected)
6463 buf[count]=numconnected; count++;
6464 for (i=0;i<N_players;i++)
6465 if (Players[i].connected)
6467 buf[count++]=NetPlayers.players[i].rank;
6469 for (t=0;t<CALLSIGN_LEN+1;t++)
6471 buf[count]=NetPlayers.players[i].callsign[t];
6477 buf[count++]=Netgame.ShortPackets;
6478 buf[count++]=Netgame.PacketsPerSec;
6481 ; // empty statement allows compilation on mac which does not have the
6482 // statement below and kills the compiler when there is no
6483 // statement following the label "sendit"
6486 ipx_send_internetwork_packet_data((ubyte *)buf, count, their->player.network.ipx.server, their->player.network.ipx.node);
6491 extern int file_exists (char *);
6493 int HoardEquipped ()
6495 static int checked=-1;
6503 if (file_exists ("hoard.ham"))