2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
11 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
15 static char rcsid[] = "$Id: network.c,v 1.1.1.2 2001-01-19 03:33:46 bradleyb Exp $";
71 #include <Errors.h> // for appletalk networking errors
75 #define LHX(x) ((x)*(MenuHires?2:1))
76 #define LHY(y) ((y)*(MenuHires?2.4:1))
78 #define PID_LITE_INFO 43
79 #define PID_SEND_ALL_GAMEINFO 44
80 #define PID_PLAYERSINFO 45
81 #define PID_REQUEST 46
84 #define PID_ADDPLAYER 49
86 #define PID_ENDLEVEL 52
87 #define PID_QUIT_JOINING 54
88 #define PID_OBJECT_DATA 55
89 #define PID_GAME_LIST 56
90 #define PID_GAME_INFO 57
91 #define PID_PING_SEND 58
92 #define PID_PING_RETURN 59
93 #define PID_GAME_UPDATE 60
94 #define PID_ENDLEVEL_SHORT 61
95 #define PID_NAKED_PDATA 62
96 #define PID_GAME_PLAYERS 63
97 #define PID_NAMES_RETURN 64
99 #define NETGAME_ANARCHY 0
100 #define NETGAME_TEAM_ANARCHY 1
101 #define NETGAME_ROBOT_ANARCHY 2
102 #define NETGAME_COOPERATIVE 3
103 #define NETGAME_CAPTURE_FLAG 4
104 #define NETGAME_HOARD 5
105 #define NETGAME_TEAM_HOARD 6
107 #define NETSECURITY_OFF 0
108 #define NETSECURITY_WAIT_FOR_PLAYERS 1
109 #define NETSECURITY_WAIT_FOR_GAMEINFO 2
110 #define NETSECURITY_WAIT_FOR_SYNC 3
112 // MWA -- these structures are aligned -- please save me sanity and
113 // headaches by keeping alignment if these are changed!!!! Contact
116 typedef struct endlevel_info {
121 short kill_matrix[MAX_PLAYERS][MAX_PLAYERS];
126 typedef struct endlevel_info_short {
131 } endlevel_info_short;
133 // WARNING!!! This is the top part of netgame_info...if that struct changes,
134 // this struct much change as well. ie...they are aligned and the join system will
135 // not work without it.
137 // MWA if this structure changes -- please make appropriate changes to receive_netgame_info
138 // code for macintosh in netmisc.c
140 typedef struct lite_info {
143 char game_name[NETGAME_NAME_LEN+1];
144 char mission_title[MISSION_NAME_LEN+1];
145 char mission_name[9];
152 ubyte max_numplayers;
155 ubyte protocol_version;
161 // IF YOU CHANGE THE SIZE OF ANY OF THE FOLLOWING STRUCTURES
162 // MAKE THE MACINTOSH DEFINES BE THE SAME SIZE AS THE PC OR
163 // I WILL HAVE TO HURT YOU VERY BADLY!!! -- MWA
166 #define NETGAME_INFO_SIZE ( Network_game_type == IPX_GAME?355:sizeof(netgame_info) )
167 #define ALLNETPLAYERSINFO_SIZE ( Network_game_type == IPX_GAME?317:sizeof(AllNetPlayers_info) )
168 #define LITE_INFO_SIZE ( Network_game_type == IPX_GAME?72:sizeof(lite_info) )
169 #define SEQUENCE_PACKET_SIZE ( Network_game_type == IPX_GAME?34:sizeof(sequence_packet) )
170 #define FRAME_INFO_SIZE ( Network_game_type == IPX_GAME?541:sizeof(frame_info) )
171 #define IPX_SHORT_INFO_SIZE ( 490 )
173 #define NETGAME_INFO_SIZE sizeof(netgame_info)
174 #define ALLNETPLAYERSINFO_SIZE sizeof(AllNetPlayers_info)
175 #define LITE_INFO_SIZE sizeof(lite_info)
176 #define SEQUENCE_PACKET_SIZE sizeof(sequence_packet)
177 #define FRAME_INFO_SIZE sizeof(frame_info)
180 #define MAX_ACTIVE_NETGAMES 12
182 netgame_info Active_games[MAX_ACTIVE_NETGAMES];
183 AllNetPlayers_info ActiveNetPlayers[MAX_ACTIVE_NETGAMES];
184 AllNetPlayers_info *TempPlayersInfo,TempPlayersBase;
185 int NamesInfoSecurity=-1;
187 // MWAnetgame_info *TempNetInfo;
188 netgame_info TempNetInfo;
190 extern void multi_send_drop_marker (int player,vms_vector position,char messagenum,char text[]);
191 extern void multi_send_kill_goal_counts();
192 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) );
194 void network_process_naked_pdata (char *,int);
195 extern void multi_send_robot_controls(char);
197 int num_active_games = 0;
198 int PacketsPerSec=10;
199 int MaxXDataSize=NET_XDATA_SIZE;
201 int Netlife_kills=0, Netlife_killed=0;
204 int Network_active=0;
206 int Network_status = 0;
207 int Network_games_changed = 0;
209 int Network_socket = 0;
210 int Network_allow_socket_changes = 1;
212 int NetSecurityFlag=NETSECURITY_OFF;
213 int NetSecurityNum=0;
214 int Network_sending_extras=0;
215 int VerifyPlayerJoined=-1;
216 int Player_joining_extras=-1; // This is so we know who to send 'latecomer' packets to.
217 // We could just send updates to everyone but that kills the sender!
219 // For rejoin object syncing
221 int Network_rejoined = 0; // Did WE rejoin this game?
222 int Network_new_game = 0; // Is this the first level of a new game?
223 int Network_send_objects = 0; // Are we in the process of sending objects to a player?
224 int Network_send_objnum = -1; // What object are we sending next?
225 int Network_player_added = 0; // Is this a new player or a returning player?
226 int Network_send_object_mode = 0; // What type of objects are we sending, static or dynamic?
227 sequence_packet Network_player_rejoining; // Who is rejoining now?
229 fix LastPacketTime[MAX_PLAYERS]; // For timeouts of idle/crashed players
231 int PacketUrgent = 0;
233 int TotalMissedPackets=0,TotalPacketsGot=0;
235 frame_info MySyncPack,UrgentSyncPack;
236 ubyte MySyncPackInitialized = 0; // Set to 1 if the MySyncPack is zeroed.
237 ushort my_segments_checksum = 0;
239 sequence_packet My_Seq;
240 char WantPlayersInfo=0;
241 char WaitingForPlayerInfo=0;
243 char *RankStrings[]={"(unpatched) ","Cadet ","Ensign ","Lieutenant ","Lt.Commander ",
244 "Commander ","Captain ","Vice Admiral ","Admiral ","Demigod "};
246 extern obj_position Player_init[MAX_PLAYERS];
248 extern int force_cockpit_redraw;
250 #define DUMP_CLOSED 0
252 #define DUMP_ENDLEVEL 2
254 #define DUMP_ABORTED 4
255 #define DUMP_CONNECTED 5
257 #define DUMP_KICKED 7
259 extern ubyte Version_major,Version_minor;
260 extern ubyte SurfingNet;
261 extern char MaxPowerupsAllowed[MAX_POWERUP_TYPES];
262 extern char PowerupsInMine[MAX_POWERUP_TYPES];
264 extern void multi_send_stolen_items();
266 int network_wait_for_snyc();
267 extern void multi_send_wall_status (int,ubyte,ubyte,ubyte);
268 extern void multi_send_wall_status_specific (int,int,ubyte,ubyte,ubyte);
270 extern void game_disable_cheats();
273 FILE *SendLogFile,*RecieveLogFile;
274 int TTSent[100],TTRecv[100];
276 extern int Final_boss_is_dead;
278 // following is network stuff for appletalk
280 void network_dump_appletalk_player(ubyte node, ushort net, ubyte socket, int why);
282 #define NETWORK_OEM 0x10
286 int Network_game_type; // used to tell IPX vs. appletalk games
288 #define MAX_ZONES 255
289 #define MAX_ZONE_LENGTH 33
290 #define DEFAULT_ZONE_NAME "\p*"
291 #define MAX_REGISTER_TRIES 5 // maximum time we will try and register a netgame
292 char Network_zone_name[MAX_ZONE_LENGTH]; // zone name game being played in for appletalk
293 char Zone_names[MAX_ZONES][MAX_ZONE_LENGTH]; // total list of zones that we can see
294 ubyte appletalk_use_broadcast = 0;
295 ubyte Network_game_validated = 0; // validates a game before being able to join
296 ubyte Network_game_validate_choice = 0;
297 ubyte Network_appletalk_type = 0; // type of appletalk network game is being played on
299 #define ETHERTALK_TYPE 0
300 #define LOCALTALK_TYPE 1
301 #define OTHERTALK_TYPE 2
304 void network_release_registered_game(void);
312 // So you want to play a netgame, eh? Let's a get a few things
316 int save_pnum = Player_num;
318 game_disable_cheats();
320 Final_boss_is_dead=0;
321 NamesInfoSecurity=-1;
329 for (t=0;t<MAX_POWERUP_TYPES;t++)
331 MaxPowerupsAllowed[t]=0;
335 TotalMissedPackets=0; TotalPacketsGot=0;
337 memset(&Netgame, 0, sizeof(netgame_info));
338 memset(&NetPlayers,0,sizeof(AllNetPlayers_info));
339 memset(&My_Seq, 0, sizeof(sequence_packet));
340 My_Seq.type = PID_REQUEST;
341 memcpy(My_Seq.player.callsign, Players[Player_num].callsign, CALLSIGN_LEN+1);
344 Version_minor|=NETWORK_OEM;
347 My_Seq.player.version_major=Version_major;
348 My_Seq.player.version_minor=Version_minor;
349 My_Seq.player.rank=GetMyNetRanking();
351 if (Network_game_type == IPX_GAME) {
352 memcpy(My_Seq.player.network.ipx.node, ipx_get_my_local_address(), 6);
353 memcpy(My_Seq.player.network.ipx.server, ipx_get_my_server_address(), 4 );
356 My_Seq.player.network.appletalk.node = appletalk_get_my_node();
357 My_Seq.player.network.appletalk.net = appletalk_get_my_net();
358 My_Seq.player.network.appletalk.socket = appletalk_get_my_socket();
362 My_Seq.player.computer_type = MAC;
364 My_Seq.player.computer_type = DOS;
367 for (Player_num = 0; Player_num < MAX_NUM_NET_PLAYERS; Player_num++)
368 init_player_stats_game();
370 Player_num = save_pnum;
372 Network_new_game = 1;
373 Control_center_destroyed = 0;
376 Netgame.PacketsPerSec=10;
378 if ((t=args_find("-packets")))
380 Netgame.PacketsPerSec=atoi(Args[t+1]);
381 if (Netgame.PacketsPerSec<1)
382 Netgame.PacketsPerSec=1;
383 else if (Netgame.PacketsPerSec>20)
384 Netgame.PacketsPerSec=20;
385 mprintf ((0,"Will send %d packets per second",Netgame.PacketsPerSec));
387 if (args_find("-shortpackets"))
389 Netgame.ShortPackets=1;
390 mprintf ((0,"Will send short packets.\n"));
395 network_i_am_master(void)
397 // I am the lowest numbered player in this game?
401 if (!(Game_mode & GM_NETWORK))
402 return (Player_num == 0);
404 for (i = 0; i < Player_num; i++)
405 if (Players[i].connected)
410 network_who_is_master(void)
412 // Who is the master of this game?
416 if (!(Game_mode & GM_NETWORK))
417 return (Player_num == 0);
419 for (i = 0; i < N_players; i++)
420 if (Players[i].connected)
424 int network_how_many_connected()
428 for (i = 0; i < N_players; i++)
429 if (Players[i].connected)
434 #define ENDLEVEL_SEND_INTERVAL (F1_0*2)
435 #define ENDLEVEL_IDLE_TIME (F1_0*20)
438 network_endlevel_poll( int nitems, newmenu_item * menus, int * key, int citem )
440 // Polling loop for End-of-level menu
448 int previous_state[MAX_NUM_NET_PLAYERS];
449 int previous_seconds_left;
456 // Send our endlevel packet at regular intervals
458 if (timer_get_approx_seconds() > (t1+ENDLEVEL_SEND_INTERVAL))
460 network_send_endlevel_packet();
461 t1 = timer_get_approx_seconds();
464 for (i = 0; i < N_players; i++)
465 previous_state[i] = Players[i].connected;
467 previous_seconds_left = Countdown_seconds_left;
471 for (i = 0; i < N_players; i++)
473 if (Players[i].connected == 1)
475 // Check timeout for idle players
476 if (timer_get_approx_seconds() > LastPacketTime[i]+ENDLEVEL_IDLE_TIME)
478 mprintf((0, "idle timeout for player %d.\n", i));
479 Players[i].connected = 0;
480 network_send_endlevel_sub(i);
484 if ((Players[i].connected != 1) && (Players[i].connected != 5) && (Players[i].connected != 6))
486 if (Players[i].connected != 1)
488 if (Players[i].connected == 4)
492 if (num_escaped == N_players) // All players are out of the mine
494 Countdown_seconds_left = -1;
498 if (num_ready == N_players) // All players have checked in or are disconnected
508 network_endlevel_poll2( int nitems, newmenu_item * menus, int * key, int citem )
510 // Polling loop for End-of-level menu
522 // Send our endlevel packet at regular intervals
524 if (timer_get_approx_seconds() > (t1+ENDLEVEL_SEND_INTERVAL))
526 network_send_endlevel_packet();
527 t1 = timer_get_approx_seconds();
530 // mprintf ((0,"Trying to listen!\n"));
533 for (i = 0; i < N_players; i++)
535 if ((Players[i].connected != 1) && (Players[i].connected != 5) && (Players[i].connected != 6))
537 if (Players[i].connected == 4)
541 if (num_ready == N_players) // All players have checked in or are disconnected
551 extern fix StartAbortMenuTime;
554 network_endlevel_poll3( int nitems, newmenu_item * menus, int * key, int citem )
556 // Polling loop for End-of-level menu
565 if (timer_get_approx_seconds() > (StartAbortMenuTime+(F1_0 * 8)))
572 for (i = 0; i < N_players; i++)
573 if ((Players[i].connected != 1) && (Players[i].connected != 5) && (Players[i].connected != 6))
576 if (num_ready == N_players) // All players have checked in or are disconnected
583 network_endlevel(int *secret)
585 // Do whatever needs to be done between levels
593 Network_status = NETSTAT_ENDLEVEL; // We are between levels
597 network_send_endlevel_packet();
599 for (i=0; i<N_players; i++)
601 LastPacketTime[i] = timer_get_approx_seconds();
604 network_send_endlevel_packet();
605 network_send_endlevel_packet();
606 MySyncPackInitialized = 0;
608 network_update_netgame();
614 can_join_netgame(netgame_info *game,AllNetPlayers_info *people)
616 // Can this player rejoin a netgame in progress?
620 if (game->game_status == NETSTAT_STARTING)
623 if (game->game_status != NETSTAT_PLAYING)
625 mprintf ((0,"Error: Can't join because game_status !=NETSTAT_PLAYING\n"));
629 if (game->version_major==0 && Version_major>0)
631 mprintf ((0,"Error:Can't join because version majors don't match!\n"));
635 if (game->version_major>0 && Version_major==0)
637 mprintf ((0,"Error:Can't join because version majors2 don't match!\n"));
641 // Game is in progress, figure out if this guy can re-join it
643 num_players = game->numplayers;
645 if (!(game->game_flags & NETGAME_FLAG_CLOSED)) {
646 // Look for player that is not connected
648 if (game->numconnected==game->max_numplayers)
651 // mprintf ((0,"Refuse = %d\n",game->RefusePlayers));
653 if (game->RefusePlayers)
656 if (game->numplayers < game->max_numplayers)
659 if (game->numconnected<num_players)
666 mprintf ((0,"Error! Can't join because people==NULL!\n"));
670 // Search to see if we were already in this closed netgame in progress
672 for (i = 0; i < num_players; i++) {
673 if (Network_game_type == IPX_GAME) {
674 if ( (!stricmp(Players[Player_num].callsign, people->players[i].callsign)) &&
675 (!memcmp(My_Seq.player.network.ipx.node, people->players[i].network.ipx.node, 6)) &&
676 (!memcmp(My_Seq.player.network.ipx.server, people->players[i].network.ipx.server, 4)) )
679 if ( (!stricmp(Players[Player_num].callsign, people->players[i].callsign)) &&
680 (My_Seq.player.network.appletalk.node == people->players[i].network.appletalk.node) &&
681 (My_Seq.player.network.appletalk.net == people->players[i].network.appletalk.net) )
686 if (i != num_players)
689 mprintf ((0,"Error: Can't join because at end of list!\n"));
694 network_disconnect_player(int playernum)
696 // A player has disconnected from the net game, take whatever steps are
699 if (playernum == Player_num)
701 Int3(); // Weird, see Rob
705 Players[playernum].connected = 0;
706 NetPlayers.players[playernum].connected = 0;
707 if (VerifyPlayerJoined==playernum)
708 VerifyPlayerJoined=-1;
710 // create_player_appearance_effect(&Objects[Players[playernum].objnum]);
711 multi_make_player_ghost(playernum);
713 if (Newdemo_state == ND_STATE_RECORDING)
714 newdemo_record_multi_disconnect(playernum);
716 multi_strip_robots(playernum);
720 network_new_player(sequence_packet *their)
725 pnum = their->player.connected;
728 Assert(pnum < MaxNumNetPlayers);
730 objnum = Players[pnum].objnum;
732 if (Newdemo_state == ND_STATE_RECORDING) {
735 if (pnum == N_players)
739 newdemo_record_multi_connect(pnum, new_player, their->player.callsign);
742 memcpy(Players[pnum].callsign, their->player.callsign, CALLSIGN_LEN+1);
743 memcpy(NetPlayers.players[pnum].callsign, their->player.callsign, CALLSIGN_LEN+1);
746 ClipRank (&their->player.rank);
747 NetPlayers.players[pnum].rank=their->player.rank;
748 NetPlayers.players[pnum].version_major=their->player.version_major;
749 NetPlayers.players[pnum].version_minor=their->player.version_minor;
750 network_check_for_old_version(pnum);
752 if (Network_game_type == IPX_GAME) {
753 if ( (*(uint *)their->player.network.ipx.server) != 0 )
754 ipx_get_local_target( their->player.network.ipx.server, their->player.network.ipx.node, Players[pnum].net_address );
756 memcpy(Players[pnum].net_address, their->player.network.ipx.node, 6);
758 memcpy(NetPlayers.players[pnum].network.ipx.node, their->player.network.ipx.node, 6);
759 memcpy(NetPlayers.players[pnum].network.ipx.server, their->player.network.ipx.server, 4);
761 NetPlayers.players[pnum].network.appletalk.node = their->player.network.appletalk.node;
762 NetPlayers.players[pnum].network.appletalk.net = their->player.network.appletalk.net;
763 NetPlayers.players[pnum].network.appletalk.socket = their->player.network.appletalk.socket;
766 Players[pnum].n_packets_got = 0;
767 Players[pnum].connected = 1;
768 Players[pnum].net_kills_total = 0;
769 Players[pnum].net_killed_total = 0;
770 memset(kill_matrix[pnum], 0, MAX_PLAYERS*sizeof(short));
771 Players[pnum].score = 0;
772 Players[pnum].flags = 0;
773 Players[pnum].KillGoalCount=0;
775 if (pnum == N_players)
778 Netgame.numplayers = N_players;
781 digi_play_sample(SOUND_HUD_MESSAGE, F1_0);
783 ClipRank (&their->player.rank);
785 if (args_find("-norankings"))
786 HUD_init_message("'%s' %s\n",their->player.callsign, TXT_JOINING);
788 HUD_init_message("%s'%s' %s\n",RankStrings[their->player.rank],their->player.callsign, TXT_JOINING);
790 multi_make_ghost_player(pnum);
793 multi_sort_kill_list();
795 // create_player_appearance_effect(&Objects[objnum]);
798 char RefuseThisPlayer=0,WaitForRefuseAnswer=0,RefuseTeam;
799 char RefusePlayerName[12];
800 fix RefuseTimeLimit=0;
802 void network_welcome_player(sequence_packet *their)
804 // Add a player to a game already in progress
805 ubyte local_address[6];
809 WaitForRefuseAnswer=0;
811 if (args_find("-NoMatrixCheat"))
813 if (their->player.version_minor & 0x0F<3)
815 network_dump_player(their->player.network.ipx.server, their->player.network.ipx.node, DUMP_DORK);
822 // If hoard game, and this guy isn't D2 Christmas (v1.2), dump him
824 if ((Game_mode & GM_HOARD) && ((their->player.version_minor & 0x0F)<2))
826 if (Network_game_type == IPX_GAME)
827 network_dump_player(their->player.network.ipx.server, their->player.network.ipx.node, DUMP_DORK);
830 network_dump_appletalk_player(their->player.network.appletalk.node, their->player.network.appletalk.net, their->player.network.appletalk.socket, DUMP_DORK);
836 // Don't accept new players if we're ending this level. Its safe to
837 // ignore since they'll request again later
839 if ((Endlevel_sequence) || (Control_center_destroyed))
841 mprintf((0, "Ignored request from new player to join during endgame.\n"));
842 if (Network_game_type == IPX_GAME)
843 network_dump_player(their->player.network.ipx.server,their->player.network.ipx.node, DUMP_ENDLEVEL);
846 network_dump_appletalk_player(their->player.network.appletalk.node, their->player.network.appletalk.net, their->player.network.appletalk.socket, DUMP_ENDLEVEL);
851 if (Network_send_objects || Network_sending_extras)
853 // Ignore silently, we're already responding to someone and we can't
854 // do more than one person at a time. If we don't dump them they will
855 // re-request in a few seconds.
859 if (their->player.connected != Current_level_num)
861 mprintf((0, "Dumping player due to old level number.\n"));
862 if (Network_game_type == IPX_GAME)
863 network_dump_player(their->player.network.ipx.server, their->player.network.ipx.node, DUMP_LEVEL);
866 network_dump_appletalk_player(their->player.network.appletalk.node, their->player.network.appletalk.net, their->player.network.appletalk.socket, DUMP_LEVEL);
872 memset(&Network_player_rejoining, 0, sizeof(sequence_packet));
873 Network_player_added = 0;
875 if (Network_game_type == IPX_GAME) {
876 if ( (*(uint *)their->player.network.ipx.server) != 0 )
877 ipx_get_local_target( their->player.network.ipx.server, their->player.network.ipx.node, local_address );
879 memcpy(local_address, their->player.network.ipx.node, 6);
882 for (i = 0; i < N_players; i++)
884 if ( (Network_game_type == IPX_GAME) && (!stricmp(Players[i].callsign, their->player.callsign )) && (!memcmp(Players[i].net_address,local_address, 6)) )
889 #ifdef MACINTOSH // note link to above if
890 else if ( (!stricmp(Players[i].callsign, their->player.callsign)) &&
891 (NetPlayers.players[i].network.appletalk.node == their->player.network.appletalk.node) &&
892 (NetPlayers.players[i].network.appletalk.net == their->player.network.appletalk.net)) {
899 if (player_num == -1)
901 // Player is new to this game
903 if ( !(Netgame.game_flags & NETGAME_FLAG_CLOSED) && (N_players < MaxNumNetPlayers))
905 // Add player in an open slot, game not full yet
907 player_num = N_players;
908 Network_player_added = 1;
910 else if (Netgame.game_flags & NETGAME_FLAG_CLOSED)
912 // Slots are open but game is closed
914 if (Network_game_type == IPX_GAME)
915 network_dump_player(their->player.network.ipx.server, their->player.network.ipx.node, DUMP_CLOSED);
918 network_dump_appletalk_player(their->player.network.appletalk.node, their->player.network.appletalk.net, their->player.network.appletalk.socket, DUMP_CLOSED);
924 // Slots are full but game is open, see if anyone is
925 // disconnected and replace the oldest player with this new one
927 int oldest_player = -1;
928 fix oldest_time = timer_get_approx_seconds();
930 Assert(N_players == MaxNumNetPlayers);
932 for (i = 0; i < N_players; i++)
934 if ( (!Players[i].connected) && (LastPacketTime[i] < oldest_time))
936 oldest_time = LastPacketTime[i];
941 if (oldest_player == -1)
943 // Everyone is still connected
945 if (Network_game_type == IPX_GAME)
946 network_dump_player(their->player.network.ipx.server, their->player.network.ipx.node, DUMP_FULL);
949 network_dump_appletalk_player(their->player.network.appletalk.node, their->player.network.appletalk.net, their->player.network.appletalk.socket, DUMP_FULL);
957 player_num = oldest_player;
958 Network_player_added = 1;
964 // Player is reconnecting
966 if (Players[player_num].connected)
968 mprintf((0, "Extra REQUEST from player ignored.\n"));
972 if (Newdemo_state == ND_STATE_RECORDING)
973 newdemo_record_multi_reconnect(player_num);
975 Network_player_added = 0;
977 digi_play_sample(SOUND_HUD_MESSAGE, F1_0);
979 if (args_find("-norankings"))
980 HUD_init_message("'%s' %s", Players[player_num].callsign, TXT_REJOIN);
982 HUD_init_message("%s'%s' %s", RankStrings[NetPlayers.players[player_num].rank],Players[player_num].callsign, TXT_REJOIN);
985 Players[player_num].KillGoalCount=0;
987 // Send updated Objects data to the new/returning player
990 Network_player_rejoining = *their;
991 Network_player_rejoining.player.connected = player_num;
992 Network_send_objects = 1;
993 Network_send_objnum = -1;
995 network_send_objects();
998 int network_objnum_is_past(int objnum)
1000 // determine whether or not a given object number has already been sent
1001 // to a re-joining player.
1003 int player_num = Network_player_rejoining.player.connected;
1004 int obj_mode = !((object_owner[objnum] == -1) || (object_owner[objnum] == player_num));
1006 if (!Network_send_objects)
1007 return 0; // We're not sending objects to a new player
1009 if (obj_mode > Network_send_object_mode)
1011 else if (obj_mode < Network_send_object_mode)
1013 else if (objnum < Network_send_objnum)
1019 #define OBJ_PACKETS_PER_FRAME 1
1020 extern void multi_send_active_door(char);
1021 extern void multi_send_door_open_specific(int,int,int,ubyte);
1024 void network_send_door_updates(int pnum)
1026 // Send door status when new player joins
1032 // Assert (pnum>-1 && pnum<N_players);
1034 for (i = 0; i < Num_walls; i++)
1036 if ((Walls[i].type == WALL_DOOR) && ((Walls[i].state == WALL_DOOR_OPENING) || (Walls[i].state == WALL_DOOR_WAITING) || (Walls[i].state == WALL_DOOR_OPEN)))
1037 multi_send_door_open_specific(pnum,Walls[i].segnum, Walls[i].sidenum,Walls[i].flags);
1038 else if ((Walls[i].type == WALL_BLASTABLE) && (Walls[i].flags & WALL_BLASTED))
1039 multi_send_door_open_specific(pnum,Walls[i].segnum, Walls[i].sidenum,Walls[i].flags);
1040 else if ((Walls[i].type == WALL_BLASTABLE) && (Walls[i].hps != WALL_HPS))
1041 multi_send_hostage_door_status(i);
1043 multi_send_wall_status_specific(pnum,i,Walls[i].type,Walls[i].flags,Walls[i].state);
1047 extern vms_vector MarkerPoint[];
1048 void network_send_markers()
1050 // send marker positions/text to new player
1057 if (MarkerObject[(i*2)]!=-1)
1058 multi_send_drop_marker (i,MarkerPoint[(i*2)],0,MarkerMessage[i*2]);
1059 if (MarkerObject[(i*2)+1]!=-1)
1060 multi_send_drop_marker (i,MarkerPoint[(i*2)+1],1,MarkerMessage[(i*2)+1]);
1064 void network_process_monitor_vector(int vector)
1070 for (i=0; i <= Highest_segment_index; i++)
1074 for (j = 0; j < 6; j++)
1076 if ( ((tm = seg->sides[j].tmap_num2) != 0) &&
1077 ((ec = TmapInfo[tm&0x3fff].eclip_num) != -1) &&
1078 ((bm = Effects[ec].dest_bm_num) != -1) )
1080 if (vector & (1 << count))
1082 seg->sides[j].tmap_num2 = bm | (tm&0xc000);
1083 // mprintf((0, "Monitor %d blown up.\n", count));
1086 // mprintf((0, "Monitor %d intact.\n", count));
1094 int network_create_monitor_vector(void)
1097 int num_blown_bitmaps = 0;
1098 int monitor_num = 0;
1099 #define NUM_BLOWN_BITMAPS 20
1100 int blown_bitmaps[NUM_BLOWN_BITMAPS];
1104 for (i=0; i < Num_effects; i++)
1106 if (Effects[i].dest_bm_num > 0) {
1107 for (j = 0; j < num_blown_bitmaps; j++)
1108 if (blown_bitmaps[j] == Effects[i].dest_bm_num)
1110 if (j == num_blown_bitmaps) {
1111 blown_bitmaps[num_blown_bitmaps++] = Effects[i].dest_bm_num;
1112 Assert(num_blown_bitmaps < NUM_BLOWN_BITMAPS);
1117 // for (i = 0; i < num_blown_bitmaps; i++)
1118 // mprintf((0, "Blown bitmap #%d = %d.\n", i, blown_bitmaps[i]));
1120 for (i=0; i <= Highest_segment_index; i++)
1124 for (j = 0; j < 6; j++)
1126 if ((tm = seg->sides[j].tmap_num2) != 0)
1128 if ( ((ec = TmapInfo[tm&0x3fff].eclip_num) != -1) &&
1129 (Effects[ec].dest_bm_num != -1) )
1131 // mprintf((0, "Monitor %d intact.\n", monitor_num));
1133 Assert(monitor_num < 32);
1137 for (k = 0; k < num_blown_bitmaps; k++)
1139 if ((tm&0x3fff) == blown_bitmaps[k])
1141 //mprintf((0, "Monitor %d destroyed.\n", monitor_num));
1142 vector |= (1 << monitor_num);
1144 Assert(monitor_num < 32);
1152 // mprintf((0, "Final monitor vector %x.\n", vector));
1156 void network_stop_resync(sequence_packet *their)
1158 if (Network_game_type == IPX_GAME) {
1159 if ( (!memcmp(Network_player_rejoining.player.network.ipx.node, their->player.network.ipx.node, 6)) &&
1160 (!memcmp(Network_player_rejoining.player.network.ipx.server, their->player.network.ipx.server, 4)) &&
1161 (!stricmp(Network_player_rejoining.player.callsign, their->player.callsign)) )
1163 mprintf((0, "Aborting resync for player %s.\n", their->player.callsign));
1164 Network_send_objects = 0;
1165 Network_sending_extras=0;
1167 Player_joining_extras=-1;
1168 Network_send_objnum = -1;
1171 if ( (Network_player_rejoining.player.network.appletalk.node == their->player.network.appletalk.node) &&
1172 (Network_player_rejoining.player.network.appletalk.net == their->player.network.appletalk.net) &&
1173 (!stricmp(Network_player_rejoining.player.callsign, their->player.callsign)) )
1175 mprintf((0, "Aborting resync for player %s.\n", their->player.callsign));
1176 Network_send_objects = 0;
1177 Network_sending_extras=0;
1179 Player_joining_extras=-1;
1180 Network_send_objnum = -1;
1185 byte object_buffer[IPX_MAX_DATA_SIZE];
1187 void network_send_objects(void)
1189 short remote_objnum;
1193 static int obj_count = 0;
1194 static int frame_num = 0;
1196 int obj_count_frame = 0;
1197 int player_num = Network_player_rejoining.player.connected;
1199 // Send clear objects array trigger and send player num
1201 Assert(Network_send_objects != 0);
1202 Assert(player_num >= 0);
1203 Assert(player_num < MaxNumNetPlayers);
1205 if (Endlevel_sequence || Control_center_destroyed)
1207 // Endlevel started before we finished sending the goods, we'll
1208 // have to stop and try again after the level.
1210 if (Network_game_type == IPX_GAME)
1211 network_dump_player(Network_player_rejoining.player.network.ipx.server,Network_player_rejoining.player.network.ipx.node, DUMP_ENDLEVEL);
1214 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);
1216 Network_send_objects = 0;
1220 for (h = 0; h < OBJ_PACKETS_PER_FRAME; h++) // Do more than 1 per frame, try to speed it up without
1221 // over-stressing the receiver.
1223 obj_count_frame = 0;
1224 memset(object_buffer, 0, IPX_MAX_DATA_SIZE);
1225 object_buffer[0] = PID_OBJECT_DATA;
1228 if (Network_send_objnum == -1)
1231 Network_send_object_mode = 0;
1232 // mprintf((0, "Sending object array to player %d.\n", player_num));
1233 *(short *)(object_buffer+loc) = INTEL_SHORT(-1); loc += 2;
1234 object_buffer[loc] = player_num; loc += 1;
1235 loc += 2; // Placeholder for remote_objnum, not used here
1236 Network_send_objnum = 0;
1237 obj_count_frame = 1;
1241 for (i = Network_send_objnum; i <= Highest_object_index; i++)
1243 if ((Objects[i].type != OBJ_POWERUP) && (Objects[i].type != OBJ_PLAYER) &&
1244 (Objects[i].type != OBJ_CNTRLCEN) && (Objects[i].type != OBJ_GHOST) &&
1245 (Objects[i].type != OBJ_ROBOT) && (Objects[i].type != OBJ_HOSTAGE) &&
1246 !(Objects[i].type==OBJ_WEAPON && Objects[i].id==PMINE_ID))
1248 if ((Network_send_object_mode == 0) && ((object_owner[i] != -1) && (object_owner[i] != player_num)))
1250 if ((Network_send_object_mode == 1) && ((object_owner[i] == -1) || (object_owner[i] == player_num)))
1253 if ( ((IPX_MAX_DATA_SIZE-1) - loc) < (sizeof(object)+5) )
1254 break; // Not enough room for another object
1259 remote_objnum = objnum_local_to_remote((short)i, &owner);
1260 Assert(owner == object_owner[i]);
1262 *(short *)(object_buffer+loc) = INTEL_SHORT((short)i); loc += 2;
1263 object_buffer[loc] = owner; loc += 1;
1264 *(short *)(object_buffer+loc) = INTEL_SHORT(remote_objnum); loc += 2;
1266 memcpy(object_buffer+loc, &Objects[i], sizeof(object)); loc += sizeof(object);
1268 if (Network_game_type == IPX_GAME) {
1271 memcpy(&tmpobj, &(Objects[i]), sizeof(object));
1272 swap_object(&tmpobj);
1273 memcpy(&(object_buffer[loc]), &tmpobj, sizeof(object)); loc += sizeof(object);
1276 memcpy(object_buffer+loc, &Objects[i], sizeof(object)); loc += sizeof(object);
1278 // mprintf((0, "..packing object %d, remote %d\n", i, remote_objnum));
1281 if (obj_count_frame) // Send any objects we've buffered
1285 Network_send_objnum = i;
1286 object_buffer[1] = obj_count_frame; object_buffer[2] = frame_num;
1287 // mprintf((0, "Object packet %d contains %d objects.\n", frame_num, obj_count_frame));
1289 Assert(loc <= IPX_MAX_DATA_SIZE);
1291 if (Network_game_type == IPX_GAME)
1292 ipx_send_internetwork_packet_data( object_buffer, loc, Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node );
1295 appletalk_send_packet_data( object_buffer, loc, Network_player_rejoining.player.network.appletalk.node,
1296 Network_player_rejoining.player.network.appletalk.net,
1297 Network_player_rejoining.player.network.appletalk.socket);
1300 // OLD ipx_send_packet_data(object_buffer, loc, &Network_player_rejoining.player.node);
1303 if (i > Highest_object_index)
1305 if (Network_send_object_mode == 0)
1307 Network_send_objnum = 0;
1308 Network_send_object_mode = 1; // go to next mode
1312 Assert(Network_send_object_mode == 1);
1315 // Send count so other side can make sure he got them all
1316 // mprintf((0, "Sending end marker in packet #%d.\n", frame_num));
1317 mprintf((0, "Sent %d objects.\n", obj_count));
1318 object_buffer[0] = PID_OBJECT_DATA;
1319 object_buffer[1] = 1;
1320 object_buffer[2] = frame_num;
1321 *(short *)(object_buffer+3) = INTEL_SHORT(-2);
1322 *(short *)(object_buffer+6) = INTEL_SHORT(obj_count);
1323 //OLD ipx_send_packet_data(object_buffer, 8, &Network_player_rejoining.player.node);
1324 if (Network_game_type == IPX_GAME)
1325 ipx_send_internetwork_packet_data(object_buffer, 8, Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node);
1328 appletalk_send_packet_data( object_buffer, 8, Network_player_rejoining.player.network.appletalk.node,
1329 Network_player_rejoining.player.network.appletalk.net,
1330 Network_player_rejoining.player.network.appletalk.socket);
1334 // Send sync packet which tells the player who he is and to start!
1335 network_send_rejoin_sync(player_num);
1336 mprintf ((0,"VerfiyPlayerJoined is now set to %d\n",player_num));
1337 VerifyPlayerJoined=player_num;
1339 // Turn off send object mode
1340 Network_send_objnum = -1;
1341 Network_send_objects = 0;
1344 //if (!network_i_am_master ())
1345 // Int3(); // Bad!! Get Jason. Someone goofy is trying to get ahold of the game!
1347 Network_sending_extras=40; // start to send extras
1348 Player_joining_extras=player_num;
1352 } // i > Highest_object_index
1353 } // For PACKETS_PER_FRAME
1356 extern void multi_send_powerup_update();
1358 void network_send_rejoin_sync(int player_num)
1362 Players[player_num].connected = 1; // connect the new guy
1363 LastPacketTime[player_num] = timer_get_approx_seconds();
1365 if (Endlevel_sequence || Control_center_destroyed)
1367 // Endlevel started before we finished sending the goods, we'll
1368 // have to stop and try again after the level.
1370 if (Network_game_type == IPX_GAME)
1371 network_dump_player(Network_player_rejoining.player.network.ipx.server,Network_player_rejoining.player.network.ipx.node, DUMP_ENDLEVEL);
1374 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);
1376 Network_send_objects = 0;
1377 Network_sending_extras=0;
1381 if (Network_player_added)
1383 Network_player_rejoining.type = PID_ADDPLAYER;
1384 Network_player_rejoining.player.connected = player_num;
1385 network_new_player(&Network_player_rejoining);
1387 for (i = 0; i < N_players; i++)
1389 if ((i != player_num) && (i != Player_num) && (Players[i].connected))
1390 if (Network_game_type == IPX_GAME) {
1392 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);
1394 send_sequence_packet( Network_player_rejoining, NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node, Players[i].net_address);
1398 appletalk_send_packet_data( (ubyte *)&Network_player_rejoining, sizeof(sequence_packet), NetPlayers.players[i].network.appletalk.node,
1399 NetPlayers.players[i].network.appletalk.net, NetPlayers.players[i].network.appletalk.socket);
1405 // Send sync packet to the new guy
1407 network_update_netgame();
1409 // Fill in the kill list
1410 for (j=0; j<MAX_PLAYERS; j++)
1412 for (i=0; i<MAX_PLAYERS;i++)
1413 Netgame.kills[j][i] = kill_matrix[j][i];
1414 Netgame.killed[j] = Players[j].net_killed_total;
1415 Netgame.player_kills[j] = Players[j].net_kills_total;
1416 Netgame.player_score[j] = Players[j].score;
1419 Netgame.level_time = Players[Player_num].time_level;
1420 Netgame.monitor_vector = network_create_monitor_vector();
1422 mprintf((0, "Sending rejoin sync packet!!!\n"));
1424 if (Network_game_type == IPX_GAME) {
1426 ipx_send_internetwork_packet_data( (ubyte *)&Netgame, sizeof(netgame_info), Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node );
1427 ipx_send_internetwork_packet_data( (ubyte *)&NetPlayers, sizeof(AllNetPlayers_info), Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node );
1429 send_netgame_packet(Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node, NULL, 0);
1430 send_netplayers_packet(Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node);
1434 appletalk_send_packet_data( (ubyte *)&Netgame, sizeof(netgame_info), Network_player_rejoining.player.network.appletalk.node,
1435 Network_player_rejoining.player.network.appletalk.net,
1436 Network_player_rejoining.player.network.appletalk.socket);
1437 appletalk_send_packet_data( (ubyte *)&NetPlayers, sizeof(AllNetPlayers_info), Network_player_rejoining.player.network.appletalk.node,
1438 Network_player_rejoining.player.network.appletalk.net,
1439 Network_player_rejoining.player.network.appletalk.socket);
1444 void resend_sync_due_to_packet_loss_for_allender ()
1448 mprintf ((0,"I'm resending a sync packet! VPJ=%d\n",VerifyPlayerJoined));
1450 network_update_netgame();
1452 // Fill in the kill list
1453 for (j=0; j<MAX_PLAYERS; j++)
1455 for (i=0; i<MAX_PLAYERS;i++)
1456 Netgame.kills[j][i] = kill_matrix[j][i];
1457 Netgame.killed[j] = Players[j].net_killed_total;
1458 Netgame.player_kills[j] = Players[j].net_kills_total;
1459 Netgame.player_score[j] = Players[j].score;
1462 Netgame.level_time = Players[Player_num].time_level;
1463 Netgame.monitor_vector = network_create_monitor_vector();
1465 if (Network_game_type == IPX_GAME) {
1467 ipx_send_internetwork_packet_data( (ubyte *)&Netgame, sizeof(netgame_info), Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node );
1468 ipx_send_internetwork_packet_data( (ubyte *)&NetPlayers, sizeof(AllNetPlayers_info), Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node );
1470 send_netgame_packet(Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node, NULL, 0);
1471 send_netplayers_packet(Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node);
1475 appletalk_send_packet_data( (ubyte *)&Netgame, sizeof(netgame_info), Network_player_rejoining.player.network.appletalk.node,
1476 Network_player_rejoining.player.network.appletalk.net,
1477 Network_player_rejoining.player.network.appletalk.socket);
1478 appletalk_send_packet_data( (ubyte *)&NetPlayers, sizeof(AllNetPlayers_info), Network_player_rejoining.player.network.appletalk.node,
1479 Network_player_rejoining.player.network.appletalk.net,
1480 Network_player_rejoining.player.network.appletalk.socket);
1486 char * network_get_player_name( int objnum )
1488 if ( objnum < 0 ) return NULL;
1489 if ( Objects[objnum].type != OBJ_PLAYER ) return NULL;
1490 if ( Objects[objnum].id >= MAX_PLAYERS ) return NULL;
1491 if ( Objects[objnum].id >= N_players ) return NULL;
1493 return Players[Objects[objnum].id].callsign;
1497 void network_add_player(sequence_packet *p)
1501 mprintf((0, "Got add player request!\n"));
1503 for (i=0; i<N_players; i++ ) {
1504 if (Network_game_type == IPX_GAME) {
1505 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))
1506 return; // already got them
1508 if ( (NetPlayers.players[i].network.appletalk.node == p->player.network.appletalk.node) &&
1509 (NetPlayers.players[i].network.appletalk.net == p->player.network.appletalk.net))
1514 if (Network_game_type == IPX_GAME) {
1515 memcpy( NetPlayers.players[N_players].network.ipx.node, p->player.network.ipx.node, 6 );
1516 memcpy( NetPlayers.players[N_players].network.ipx.server, p->player.network.ipx.server, 4 );
1518 NetPlayers.players[N_players].network.appletalk.node = p->player.network.appletalk.node;
1519 NetPlayers.players[N_players].network.appletalk.net = p->player.network.appletalk.net;
1520 NetPlayers.players[N_players].network.appletalk.socket = p->player.network.appletalk.socket;
1523 ClipRank (&p->player.rank);
1525 memcpy( NetPlayers.players[N_players].callsign, p->player.callsign, CALLSIGN_LEN+1 );
1526 NetPlayers.players[N_players].version_major=p->player.version_major;
1527 NetPlayers.players[N_players].version_minor=p->player.version_minor;
1528 NetPlayers.players[N_players].rank=p->player.rank;
1529 NetPlayers.players[N_players].connected = 1;
1530 network_check_for_old_version (N_players);
1532 Players[N_players].KillGoalCount=0;
1533 Players[N_players].connected = 1;
1534 LastPacketTime[N_players] = timer_get_approx_seconds();
1536 Netgame.numplayers = N_players;
1538 // Broadcast updated info
1540 mprintf ((0,"sending_game_info!\n"));
1541 network_send_game_info(NULL);
1544 // One of the players decided not to join the game
1546 void network_remove_player(sequence_packet *p)
1551 for (i=0; i<N_players; i++ ) {
1552 if (Network_game_type == IPX_GAME) {
1553 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)) {
1558 if ( (NetPlayers.players[i].network.appletalk.node == p->player.network.appletalk.node) && (NetPlayers.players[i].network.appletalk.net == p->player.network.appletalk.net) ) {
1565 if (pn < 0 ) return;
1567 for (i=pn; i<N_players-1; i++ ) {
1568 if (Network_game_type == IPX_GAME) {
1569 memcpy( NetPlayers.players[i].network.ipx.node, NetPlayers.players[i+1].network.ipx.node, 6 );
1570 memcpy( NetPlayers.players[i].network.ipx.server, NetPlayers.players[i+1].network.ipx.server, 4 );
1572 NetPlayers.players[i].network.appletalk.node = NetPlayers.players[i+1].network.appletalk.node;
1573 NetPlayers.players[i].network.appletalk.net = NetPlayers.players[i+1].network.appletalk.net;
1574 NetPlayers.players[i].network.appletalk.socket = NetPlayers.players[i+1].network.appletalk.socket;
1576 memcpy( NetPlayers.players[i].callsign, NetPlayers.players[i+1].callsign, CALLSIGN_LEN+1 );
1577 NetPlayers.players[i].version_major=NetPlayers.players[i+1].version_major;
1578 NetPlayers.players[i].version_minor=NetPlayers.players[i+1].version_minor;
1580 NetPlayers.players[i].rank=NetPlayers.players[i+1].rank;
1581 ClipRank (&NetPlayers.players[i].rank);
1582 network_check_for_old_version(i);
1586 Netgame.numplayers = N_players;
1588 // Broadcast new info
1590 network_send_game_info(NULL);
1595 network_dump_player(ubyte * server, ubyte *node, int why)
1597 // Inform player that he was not chosen for the netgame
1599 sequence_packet temp;
1601 temp.type = PID_DUMP;
1602 memcpy(temp.player.callsign, Players[Player_num].callsign, CALLSIGN_LEN+1);
1603 temp.player.connected = why;
1604 if (Network_game_type == IPX_GAME) {
1606 ipx_send_internetwork_packet_data( (ubyte *)&temp, sizeof(sequence_packet), server, node);
1608 send_sequence_packet( temp, server, node, NULL);
1616 void network_dump_appletalk_player(ubyte node, ushort net, ubyte socket, int why)
1618 sequence_packet temp;
1620 temp.type = PID_DUMP;
1621 memcpy(temp.player.callsign, Players[Player_num].callsign, CALLSIGN_LEN+1);
1622 temp.player.connected = why;
1623 if (Network_game_type == APPLETALK_GAME) {
1624 appletalk_send_packet_data( (ubyte *)&temp, sizeof(sequence_packet), node, net, socket );
1632 network_send_game_list_request()
1634 // Send a broadcast request for game info
1638 mprintf((0, "Sending game_list request.\n"));
1639 me.type = PID_GAME_LIST;
1640 memcpy( me.player.callsign, Players[Player_num].callsign, CALLSIGN_LEN+1 );
1642 if (Network_game_type == IPX_GAME) {
1643 memcpy( me.player.network.ipx.node, ipx_get_my_local_address(), 6 );
1644 memcpy( me.player.network.ipx.server, ipx_get_my_server_address(), 4 );
1647 ipx_send_broadcast_packet_data( (ubyte *)&me, sizeof(sequence_packet) );
1649 send_sequence_packet( me, NULL, NULL, NULL);
1653 me.player.network.appletalk.node = appletalk_get_my_node();
1654 me.player.network.appletalk.net = appletalk_get_my_net();
1655 me.player.network.appletalk.socket = appletalk_get_my_socket();
1656 appletalk_send_game_info( (ubyte *)&me, sizeof(sequence_packet), Network_zone_name );
1661 void network_send_all_info_request(char type,int which_security)
1663 // Send a broadcast request for game info
1667 mprintf((0, "Sending all_info request.\n"));
1669 me.Security=which_security;
1671 memcpy( me.player.callsign, Players[Player_num].callsign, CALLSIGN_LEN+1 );
1673 if (Network_game_type == IPX_GAME) {
1674 memcpy( me.player.network.ipx.node, ipx_get_my_local_address(), 6 );
1675 memcpy( me.player.network.ipx.server, ipx_get_my_server_address(), 4 );
1678 ipx_send_broadcast_packet_data( (ubyte *)&me, sizeof(sequence_packet) );
1680 send_sequence_packet(me, NULL, NULL, NULL);
1684 me.player.network.appletalk.node = appletalk_get_my_node();
1685 me.player.network.appletalk.net = appletalk_get_my_net();
1686 me.player.network.appletalk.socket = appletalk_get_my_socket();
1687 appletalk_send_game_info( (ubyte *)&me, sizeof(sequence_packet), Network_zone_name );
1694 network_update_netgame(void)
1696 // Update the netgame struct with current game variables
1700 Netgame.numconnected=0;
1701 for (i=0;i<N_players;i++)
1702 if (Players[i].connected)
1703 Netgame.numconnected++;
1705 // This is great: D2 1.0 and 1.1 ignore upper part of the game_flags field of
1706 // the lite_info struct when you're sitting on the join netgame screen. We can
1707 // "sneak" Hoard information into this field. This is better than sending
1708 // another packet that could be lost in transit.
1711 if (HoardEquipped())
1713 if (Game_mode & GM_HOARD)
1715 Netgame.game_flags |=NETGAME_FLAG_HOARD;
1716 if (Game_mode & GM_TEAM)
1717 Netgame.game_flags |=NETGAME_FLAG_TEAM_HOARD;
1721 if (Network_status == NETSTAT_STARTING)
1724 Netgame.numplayers = N_players;
1725 Netgame.game_status = Network_status;
1726 Netgame.max_numplayers = MaxNumNetPlayers;
1728 for (i = 0; i < MAX_NUM_NET_PLAYERS; i++)
1730 NetPlayers.players[i].connected = Players[i].connected;
1731 for(j = 0; j < MAX_NUM_NET_PLAYERS; j++)
1732 Netgame.kills[i][j] = kill_matrix[i][j];
1734 Netgame.killed[i] = Players[i].net_killed_total;
1735 Netgame.player_kills[i] = Players[i].net_kills_total;
1736 Netgame.player_score[i] = Players[i].score;
1737 Netgame.player_flags[i] = (Players[i].flags & (PLAYER_FLAGS_BLUE_KEY | PLAYER_FLAGS_RED_KEY | PLAYER_FLAGS_GOLD_KEY));
1739 Netgame.team_kills[0] = team_kills[0];
1740 Netgame.team_kills[1] = team_kills[1];
1741 Netgame.levelnum = Current_level_num;
1747 network_send_endlevel_sub(int player_num)
1752 // Send an endlevel packet for a player
1753 end.type = PID_ENDLEVEL;
1754 end.player_num = player_num;
1755 end.connected = Players[player_num].connected;
1756 end.kills = INTEL_SHORT(Players[player_num].net_kills_total);
1757 end.killed = INTEL_SHORT(Players[player_num].net_killed_total);
1758 memcpy(end.kill_matrix, kill_matrix[player_num], MAX_PLAYERS*sizeof(short));
1760 for (i = 0; i < MAX_PLAYERS; i++)
1761 for (j = 0; j < MAX_PLAYERS; j++)
1762 end.kill_matrix[i][j] = INTEL_SHORT(end.kill_matrix[i][j]);
1764 j = j; // to satisfy compiler
1767 if (Players[player_num].connected == 1) // Still playing
1769 Assert(Control_center_destroyed);
1770 end.seconds_left = Countdown_seconds_left;
1773 // mprintf((0, "Sending endlevel packet.\n"));
1775 for (i = 0; i < N_players; i++)
1777 if ((i != Player_num) && (i!=player_num) && (Players[i].connected)) {
1778 if (Players[i].connected==1)
1779 network_send_endlevel_short_sub(player_num,i);
1781 if (Network_game_type == IPX_GAME)
1782 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);
1785 appletalk_send_packet_data( (ubyte *)&end, sizeof(endlevel_info), NetPlayers.players[i].network.appletalk.node,
1786 NetPlayers.players[i].network.appletalk.net,
1787 NetPlayers.players[i].network.appletalk.socket);
1795 network_send_endlevel_packet(void)
1797 // Send an updated endlevel status to other hosts
1799 network_send_endlevel_sub(Player_num);
1804 network_send_endlevel_short_sub(int from_player_num,int to_player)
1806 endlevel_info_short end;
1808 // Send an endlevel packet for a player
1809 end.type = PID_ENDLEVEL_SHORT;
1810 end.player_num = from_player_num;
1811 end.connected = Players[from_player_num].connected;
1812 end.seconds_left = Countdown_seconds_left;
1815 if (Players[from_player_num].connected == 1) // Still playing
1817 Assert(Control_center_destroyed);
1820 if ((to_player != Player_num) && (to_player!=from_player_num) && (Players[to_player].connected))
1822 mprintf((0, "Sending short endlevel packet to %s.\n",Players[to_player].callsign));
1823 if (Network_game_type == IPX_GAME)
1824 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);
1827 appletalk_send_packet_data( (ubyte *)&end, sizeof(endlevel_info_short), NetPlayers.players[to_player].network.appletalk.node,
1828 NetPlayers.players[to_player].network.appletalk.net,
1829 NetPlayers.players[to_player].network.appletalk.socket);
1834 extern fix ThisLevelTime;
1837 network_send_game_info(sequence_packet *their)
1839 // Send game info to someone who requested it
1841 char old_type, old_status;
1845 mprintf((0, "Sending game info.\n"));
1847 network_update_netgame(); // Update the values in the netgame struct
1849 old_type = Netgame.type;
1850 old_status = Netgame.game_status;
1852 Netgame.type = PID_GAME_INFO;
1853 NetPlayers.type = PID_PLAYERSINFO;
1855 NetPlayers.Security=Netgame.Security;
1856 Netgame.version_major=Version_major;
1857 Netgame.version_minor=Version_minor;
1859 if (Endlevel_sequence || Control_center_destroyed)
1860 Netgame.game_status = NETSTAT_ENDLEVEL;
1862 if (Netgame.PlayTimeAllowed)
1864 timevar=i2f (Netgame.PlayTimeAllowed*5*60);
1865 i=f2i(timevar-ThisLevelTime);
1867 Netgame.game_status=NETSTAT_ENDLEVEL;
1871 if (Network_game_type == IPX_GAME) {
1873 ipx_send_broadcast_packet_data((ubyte *)&Netgame, sizeof(netgame_info));
1874 ipx_send_broadcast_packet_data((ubyte *)&NetPlayers,sizeof(AllNetPlayers_info));
1876 send_netgame_packet(NULL, NULL, NULL, 0); // server == NULL says to broadcast packet
1877 send_netplayers_packet(NULL, NULL);
1879 } // nothing to do for appletalk games I think....
1881 if (Network_game_type == IPX_GAME) {
1883 ipx_send_internetwork_packet_data((ubyte *)&Netgame, sizeof(netgame_info), their->player.network.ipx.server, their->player.network.ipx.node);
1884 ipx_send_internetwork_packet_data((ubyte *)&NetPlayers,sizeof(AllNetPlayers_info),their->player.network.ipx.server,their->player.network.ipx.node);
1886 send_netgame_packet(their->player.network.ipx.server, their->player.network.ipx.node, NULL, 0);
1887 send_netplayers_packet(their->player.network.ipx.server, their->player.network.ipx.node);
1891 appletalk_send_packet_data( (ubyte *)&Netgame, sizeof(netgame_info), their->player.network.appletalk.node,
1892 their->player.network.appletalk.net, their->player.network.appletalk.socket );
1893 appletalk_send_packet_data( (ubyte *)&NetPlayers, sizeof(AllNetPlayers_info), their->player.network.appletalk.node,
1894 their->player.network.appletalk.net, their->player.network.appletalk.socket );
1899 Netgame.type = old_type;
1900 Netgame.game_status = old_status;
1903 void network_send_lite_info(sequence_packet *their)
1905 // Send game info to someone who requested it
1907 char old_type, old_status,oldstatus;
1909 mprintf((0, "Sending lite game info.\n"));
1911 network_update_netgame(); // Update the values in the netgame struct
1913 old_type = Netgame.type;
1914 old_status = Netgame.game_status;
1916 Netgame.type = PID_LITE_INFO;
1918 if (Endlevel_sequence || Control_center_destroyed)
1919 Netgame.game_status = NETSTAT_ENDLEVEL;
1921 // If hoard mode, make this game look closed even if it isn't
1922 if (HoardEquipped())
1924 if (Game_mode & GM_HOARD)
1926 oldstatus=Netgame.game_status;
1927 Netgame.game_status=NETSTAT_ENDLEVEL;
1928 Netgame.gamemode=NETGAME_CAPTURE_FLAG;
1929 if (oldstatus==NETSTAT_ENDLEVEL)
1930 Netgame.game_flags|=NETGAME_FLAG_REALLY_ENDLEVEL;
1931 if (oldstatus==NETSTAT_STARTING)
1932 Netgame.game_flags|=NETGAME_FLAG_REALLY_FORMING;
1937 if (Network_game_type == IPX_GAME) {
1939 ipx_send_broadcast_packet_data((ubyte *)&Netgame, sizeof(lite_info));
1941 send_netgame_packet(NULL, NULL, NULL, 1); // server == NULL says broadcast
1943 } // nothing to do for appletalk I think....
1945 if (Network_game_type == IPX_GAME) {
1947 ipx_send_internetwork_packet_data((ubyte *)&Netgame, sizeof(lite_info), their->player.network.ipx.server, their->player.network.ipx.node);
1949 send_netgame_packet(their->player.network.ipx.server, their->player.network.ipx.node, NULL, 1);
1953 appletalk_send_packet_data( (ubyte *)&Netgame, sizeof(lite_info), their->player.network.appletalk.node,
1954 their->player.network.appletalk.net, their->player.network.appletalk.socket );
1959 // Restore the pre-hoard mode
1960 if (HoardEquipped())
1962 if (Game_mode & GM_HOARD)
1964 if (!(Game_mode & GM_TEAM))
1965 Netgame.gamemode=NETGAME_HOARD;
1967 Netgame.gamemode=NETGAME_TEAM_HOARD;
1968 Netgame.game_flags&=~NETGAME_FLAG_REALLY_ENDLEVEL;
1969 Netgame.game_flags&=~NETGAME_FLAG_REALLY_FORMING;
1970 Netgame.game_flags&=~NETGAME_FLAG_TEAM_HOARD;
1974 Netgame.type = old_type;
1975 Netgame.game_status = old_status;
1979 void network_send_netgame_update()
1981 // Send game info to someone who requested it
1983 char old_type, old_status,i;
1985 mprintf((0, "Sending updated game info.\n"));
1987 network_update_netgame(); // Update the values in the netgame struct
1989 old_type = Netgame.type;
1990 old_status = Netgame.game_status;
1992 Netgame.type = PID_GAME_UPDATE;
1994 if (Endlevel_sequence || Control_center_destroyed)
1995 Netgame.game_status = NETSTAT_ENDLEVEL;
1997 for (i=0; i<N_players; i++ ) {
1998 if ( (Players[i].connected) && (i!=Player_num ) ) {
1999 if (Network_game_type == IPX_GAME) {
2001 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 );
2003 send_netgame_packet(NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node, Players[i].net_address, 0);
2007 appletalk_send_packet_data( (ubyte *)&Netgame, sizeof(lite_info), NetPlayers.players[i].network.appletalk.node,
2008 NetPlayers.players[i].network.appletalk.net, NetPlayers.players[i].network.appletalk.socket );
2014 Netgame.type = old_type;
2015 Netgame.game_status = old_status;
2018 int network_send_request(void)
2020 // Send a request to join a game 'Netgame'. Returns 0 if we can join this
2021 // game, non-zero if there is some problem.
2024 if (Netgame.numplayers < 1)
2027 for (i = 0; i < MAX_NUM_NET_PLAYERS; i++)
2028 if (NetPlayers.players[i].connected)
2031 Assert(i < MAX_NUM_NET_PLAYERS);
2033 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));
2035 // segments_checksum = netmisc_calc_checksum( Segments, sizeof(segment)*(Highest_segment_index+1) );
2037 My_Seq.type = PID_REQUEST;
2038 My_Seq.player.connected = Current_level_num;
2040 if (Network_game_type == IPX_GAME) {
2042 ipx_send_internetwork_packet_data((ubyte *)&My_Seq, sizeof(sequence_packet), NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node);
2044 send_sequence_packet(My_Seq, NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node, NULL);
2048 appletalk_send_packet_data( (ubyte *)&My_Seq, sizeof(sequence_packet), NetPlayers.players[i].network.appletalk.node,
2049 NetPlayers.players[i].network.appletalk.net,
2050 NetPlayers.players[i].network.appletalk.socket);
2057 int SecurityCheck=0;
2059 void network_process_gameinfo(ubyte *data)
2062 netgame_info tmp_info;
2065 netgame_info *new = (netgame_info *)data;
2068 if (Network_game_type == IPX_GAME) {
2069 receive_netgame_packet(data, &tmp_info, 0); // get correctly aligned structure
2075 WaitingForPlayerInfo=0;
2077 if (new->Security !=TempPlayersInfo->Security)
2079 Int3(); // Get Jason
2080 return; // If this first half doesn't go with the second half
2083 Network_games_changed = 1;
2085 //mprintf((0, "Got game data for game %s.\n", new->game_name));
2087 Assert (TempPlayersInfo!=NULL);
2089 for (i = 0; i < num_active_games; i++)
2091 //mprintf ((0,"GAMEINFO: Game %d is %s!\n",i,Active_games[i].game_name));
2093 if (!stricmp(Active_games[i].game_name, new->game_name) &&
2094 Active_games[i].Security==new->Security)
2098 if (i == MAX_ACTIVE_NETGAMES)
2100 mprintf((0, "Too many netgames.\n"));
2104 // MWA memcpy(&Active_games[i], data, sizeof(netgame_info));
2105 memcpy(&Active_games[i], (ubyte *)new, sizeof(netgame_info));
2106 memcpy (&ActiveNetPlayers[i],TempPlayersInfo,sizeof(AllNetPlayers_info));
2109 if (Active_games[i].Security==SecurityCheck)
2112 //mprintf ((0,"Recieved %d unique games...\n",i));
2114 if (i == num_active_games)
2117 if (Active_games[i].numplayers == 0)
2119 mprintf ((0,"DELETING THIS GAME!!!\n"));
2121 for (j = i; j < num_active_games-1; j++)
2123 memcpy(&Active_games[j], &Active_games[j+1], sizeof(netgame_info));
2124 memcpy (&ActiveNetPlayers[j],&ActiveNetPlayers[j+1],sizeof(AllNetPlayers_info));
2131 void network_process_lite_info(ubyte *data)
2137 lite_info *new = (lite_info *)data;
2140 if (Network_game_type == IPX_GAME) {
2141 receive_netgame_packet(data, (netgame_info *)&tmp_info, 1);
2146 Network_games_changed = 1;
2148 //mprintf((0, "Got game data for game %s.\n", new->game_name));
2150 for (i = 0; i < num_active_games; i++)
2152 //mprintf ((0,"GAMEINFO: Game %d is %s!\n",i,Active_games[i].game_name));
2154 if ((!stricmp(Active_games[i].game_name, new->game_name)) &&
2155 Active_games[i].Security==new->Security)
2159 if (i == MAX_ACTIVE_NETGAMES)
2161 mprintf((0, "Too many netgames.\n"));
2165 memcpy(&Active_games[i], (ubyte *)new, sizeof(lite_info));
2167 // See if this is really a Hoard game
2168 // If so, adjust all the data accordingly
2170 if (HoardEquipped())
2172 if (Active_games[i].game_flags & NETGAME_FLAG_HOARD)
2174 Active_games[i].gamemode=NETGAME_HOARD;
2175 Active_games[i].game_status=NETSTAT_PLAYING;
2177 if (Active_games[i].game_flags & NETGAME_FLAG_TEAM_HOARD)
2178 Active_games[i].gamemode=NETGAME_TEAM_HOARD;
2179 if (Active_games[i].game_flags & NETGAME_FLAG_REALLY_ENDLEVEL)
2180 Active_games[i].game_status=NETSTAT_ENDLEVEL;
2181 if (Active_games[i].game_flags & NETGAME_FLAG_REALLY_FORMING)
2182 Active_games[i].game_status=NETSTAT_STARTING;
2186 //mprintf ((0,"Recieved %d unique games...\n",i));
2188 if (i == num_active_games)
2191 if (Active_games[i].numplayers == 0)
2193 mprintf ((0,"DELETING THIS GAME!!!\n"));
2195 for (j = i; j < num_active_games-1; j++)
2197 memcpy(&Active_games[j], &Active_games[j+1], sizeof(netgame_info));
2203 void network_process_dump(sequence_packet *their)
2205 // Our request for join was denied. Tell the user why.
2209 mprintf((0, "Dumped by player %s, type %d.\n", their->player.callsign, their->player.connected));
2211 if (their->player.connected!=7)
2212 nm_messagebox(NULL, 1, TXT_OK, NET_DUMP_STRINGS(their->player.connected));
2215 for (i=0;i<N_players;i++)
2216 if (!stricmp (their->player.callsign,Players[i].callsign))
2218 if (i!=network_who_is_master())
2220 HUD_init_message ("%s attempted to kick you out.",their->player.callsign);
2224 sprintf (temp,"%s has kicked you out!",their->player.callsign);
2225 nm_messagebox(NULL, 1, TXT_OK, &temp);
2226 if (Network_status==NETSTAT_PLAYING)
2232 Network_status = NETSTAT_MENU;
2237 void network_process_request(sequence_packet *their)
2239 // Player is ready to receieve a sync packet
2242 mprintf((0, "Player %s ready for sync.\n", their->player.callsign));
2244 for (i = 0; i < N_players; i++) {
2245 if (Network_game_type == IPX_GAME) {
2246 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))) {
2247 Players[i].connected = 1;
2251 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)) ) {
2252 Players[i].connected = 1;
2259 #define REFUSE_INTERVAL F1_0 * 8
2260 extern void multi_reset_object_texture (object *);
2262 void network_process_packet(ubyte *data, int length )
2265 sequence_packet tmp_packet;
2267 sequence_packet *their = (sequence_packet *)data;
2270 if (Network_game_type == IPX_GAME) {
2271 receive_sequence_packet(data, &tmp_packet);
2272 their = &tmp_packet; // reassign their to point to correctly alinged structure
2276 //mprintf( (0, "Got packet of length %d, type %d\n", length, their->type ));
2278 // if ( length < sizeof(sequence_packet) ) return;
2284 case PID_GAME_INFO: // Jason L. says we can safely ignore this type.
2287 case PID_PLAYERSINFO:
2289 mprintf ((0,"Got a PID_PLAYERSINFO!\n"));
2291 if (Network_status==NETSTAT_WAITING)
2294 memcpy (&TempPlayersBase,data,sizeof(AllNetPlayers_info));
2296 if (Network_game_type == IPX_GAME)
2297 receive_netplayers_packet(data, &TempPlayersBase);
2299 memcpy (&TempPlayersBase,data,sizeof(AllNetPlayers_info));
2302 if (TempPlayersBase.Security!=Netgame.Security)
2304 mprintf ((0,"Bad security for PLAYERSINFO\n"));
2308 mprintf ((0,"Got a waiting PID_PLAYERSINFO!\n"));
2309 if (length!=ALLNETPLAYERSINFO_SIZE)
2311 mprintf ((0,"Invalid size for netplayers packet!\n"));
2315 TempPlayersInfo=&TempPlayersBase;
2316 WaitingForPlayerInfo=0;
2317 NetSecurityNum=TempPlayersInfo->Security;
2318 NetSecurityFlag=NETSECURITY_WAIT_FOR_SYNC;
2325 if (length != LITE_INFO_SIZE)
2327 mprintf ((0,"WARNING! Recieved invalid size for PID_LITE_INFO\n"));
2331 if (Network_status == NETSTAT_BROWSING)
2332 network_process_lite_info (data);
2336 // Someone wants a list of games
2338 if (length != SEQUENCE_PACKET_SIZE)
2340 mprintf ((0,"WARNING! Recieved invalid size for PID_GAME_LIST\n"));
2344 mprintf((0, "Got a PID_GAME_LIST!\n"));
2345 if ((Network_status == NETSTAT_PLAYING) || (Network_status == NETSTAT_STARTING) || (Network_status == NETSTAT_ENDLEVEL))
2346 if (network_i_am_master())
2347 network_send_lite_info(their);
2351 case PID_SEND_ALL_GAMEINFO:
2353 if (length != SEQUENCE_PACKET_SIZE)
2355 mprintf ((0,"WARNING! Recieved invalid size for PID_SEND_ALL_GAMEINFO\n"));
2359 if ((Network_status == NETSTAT_PLAYING) || (Network_status == NETSTAT_STARTING) || (Network_status == NETSTAT_ENDLEVEL))
2360 if (network_i_am_master() && their->Security==Netgame.Security)
2361 network_send_game_info(their);
2366 mprintf( (0, "Got NEWPLAYER message from %s.\n", their->player.callsign));
2368 if (length != SEQUENCE_PACKET_SIZE)
2370 mprintf ((0,"WARNING! Recieved invalid size for PID_ADDPLAYER\n"));
2373 mprintf( (0, "Got NEWPLAYER message from %s.\n", their->player.callsign));
2374 network_new_player(their);
2377 if (length != SEQUENCE_PACKET_SIZE)
2379 mprintf ((0,"WARNING! Recieved invalid size for PID_REQUEST\n"));
2383 mprintf( (0, "Got REQUEST from '%s'\n", their->player.callsign ));
2384 if (Network_status == NETSTAT_STARTING)
2386 // Someone wants to join our game!
2387 network_add_player(their);
2389 else if (Network_status == NETSTAT_WAITING)
2391 // Someone is ready to recieve a sync packet
2392 network_process_request(their);
2394 else if (Network_status == NETSTAT_PLAYING)
2396 // Someone wants to join a game in progress!
2397 if (Netgame.RefusePlayers)
2398 DoRefuseStuff (their);
2400 network_welcome_player(their);
2405 if (length != SEQUENCE_PACKET_SIZE)
2407 mprintf ((0,"WARNING! Recieved invalid size for PID_DUMP\n"));
2411 if (Network_status == NETSTAT_WAITING || Network_status==NETSTAT_PLAYING )
2412 network_process_dump(their);
2414 case PID_QUIT_JOINING:
2416 if (length != SEQUENCE_PACKET_SIZE)
2418 mprintf ((0,"WARNING! Recieved invalid size for PID_QUIT_JOINING\n"));
2421 if (Network_status == NETSTAT_STARTING)
2422 network_remove_player( their );
2423 else if ((Network_status == NETSTAT_PLAYING) && (Network_send_objects))
2424 network_stop_resync( their );
2428 mprintf ((0,"Got a sync packet! Network_status=%d\n",NETSTAT_WAITING));
2430 if (Network_status == NETSTAT_WAITING) {
2433 memcpy((ubyte *)&(TempNetInfo), data, sizeof(netgame_info));
2435 if (Network_game_type == IPX_GAME)
2436 receive_netgame_packet(data, &TempNetInfo, 0);
2438 memcpy((ubyte *)&(TempNetInfo), data, sizeof(netgame_info));
2441 if (TempNetInfo.Security!=Netgame.Security)
2443 mprintf ((0,"Bad security on sync packet.\n"));
2447 if (NetSecurityFlag==NETSECURITY_WAIT_FOR_SYNC)
2449 if (TempNetInfo.Security==TempPlayersInfo->Security)
2451 network_read_sync_packet (&TempNetInfo,0);
2458 NetSecurityFlag=NETSECURITY_WAIT_FOR_PLAYERS;
2459 NetSecurityNum=TempNetInfo.Security;
2461 if ( network_wait_for_playerinfo())
2462 network_read_sync_packet((netgame_info *)data,0);
2471 if ((Game_mode&GM_NETWORK) && ((Network_status == NETSTAT_PLAYING)||(Network_status == NETSTAT_ENDLEVEL) || Network_status==NETSTAT_WAITING)) {
2472 network_process_pdata((char *)data);
2475 case PID_NAKED_PDATA:
2476 if ((Game_mode&GM_NETWORK) && ((Network_status == NETSTAT_PLAYING)||(Network_status == NETSTAT_ENDLEVEL) || Network_status==NETSTAT_WAITING))
2477 network_process_naked_pdata((char *)data,length);
2480 case PID_OBJECT_DATA:
2481 if (Network_status == NETSTAT_WAITING)
2482 network_read_object_packet(data);
2485 if ((Network_status == NETSTAT_ENDLEVEL) || (Network_status == NETSTAT_PLAYING))
2486 network_read_endlevel_packet(data);
2488 mprintf((0, "Junked endlevel packet.\n"));
2490 case PID_ENDLEVEL_SHORT:
2491 if ((Network_status == NETSTAT_ENDLEVEL) || (Network_status == NETSTAT_PLAYING))
2492 network_read_endlevel_short_packet(data);
2494 mprintf((0, "Junked short endlevel packet!\n"));
2497 case PID_GAME_UPDATE:
2498 mprintf ((0,"Got a GAME_UPDATE!\n"));
2500 if (Network_status==NETSTAT_PLAYING)
2503 memcpy((ubyte *)&TempNetInfo, data, sizeof(lite_info) );
2505 if (Network_game_type == IPX_GAME)
2506 receive_netgame_packet(data, &TempNetInfo, 1);
2508 memcpy((ubyte *)&TempNetInfo, data, sizeof(lite_info) );
2510 if (TempNetInfo.Security==Netgame.Security)
2511 memcpy (&Netgame,(ubyte *)&TempNetInfo,sizeof(lite_info));
2513 if (Game_mode & GM_TEAM)
2517 for (i=0;i<N_players;i++)
2518 if (Players[i].connected)
2519 multi_reset_object_texture (&Objects[Players[i].objnum]);
2524 network_ping (PID_PING_RETURN,data[1]);
2526 case PID_PING_RETURN:
2527 network_handle_ping_return(data[1]); // data[1] is player who told us of their ping time
2529 case PID_NAMES_RETURN:
2530 if (Network_status==NETSTAT_BROWSING && NamesInfoSecurity!=-1)
2531 network_process_names_return (data);
2533 case PID_GAME_PLAYERS:
2534 // Someone wants a list of players in this game
2536 if (length != SEQUENCE_PACKET_SIZE)
2538 mprintf ((0,"WARNING! Recieved invalid size for PID_GAME_PLAYERS\n"));
2542 mprintf((0, "Got a PID_GAME_PLAYERS!\n"));
2543 if ((Network_status == NETSTAT_PLAYING) || (Network_status == NETSTAT_STARTING) || (Network_status == NETSTAT_ENDLEVEL))
2544 if (network_i_am_master() && their->Security==Netgame.Security)
2545 network_send_player_names(their);
2549 mprintf((0, "Ignoring invalid packet type.\n"));
2550 Int3(); // Invalid network packet type, see ROB
2556 void dump_segments()
2560 fp = fopen( "TEST.DMP", "wb" );
2561 fwrite( Segments, sizeof(segment)*(Highest_segment_index+1),1, fp );
2563 mprintf( (0, "SS=%d\n", sizeof(segment) ));
2569 network_read_endlevel_packet( ubyte *data )
2571 // Special packet for end of level syncing
2578 end = (endlevel_info *)data;
2580 for (i = 0; i < MAX_PLAYERS; i++)
2581 for (j = 0; j < MAX_PLAYERS; j++)
2582 end->kill_matrix[i][j] = INTEL_SHORT(end->kill_matrix[i][j]);
2583 end->kills = INTEL_SHORT(end->kills);
2584 end->killed = INTEL_SHORT(end->killed);
2587 playernum = end->player_num;
2589 Assert(playernum != Player_num);
2591 if (playernum>=N_players)
2593 Int3(); // weird, but it an happen in a coop restore game
2594 return; // if it happens in a coop restore, don't worry about it
2597 if ((Network_status == NETSTAT_PLAYING) && (end->connected != 0))
2598 return; // Only accept disconnect packets if we're not out of the level yet
2600 Players[playernum].connected = end->connected;
2601 memcpy(&kill_matrix[playernum][0], end->kill_matrix, MAX_PLAYERS*sizeof(short));
2602 Players[playernum].net_kills_total = end->kills;
2603 Players[playernum].net_killed_total = end->killed;
2605 if ((Players[playernum].connected == 1) && (end->seconds_left < Countdown_seconds_left))
2606 Countdown_seconds_left = end->seconds_left;
2608 LastPacketTime[playernum] = timer_get_approx_seconds();
2610 // mprintf((0, "Got endlevel packet from player %d.\n", playernum));
2614 network_read_endlevel_short_packet( ubyte *data )
2616 // Special packet for end of level syncing
2619 endlevel_info_short *end;
2621 end = (endlevel_info_short *)data;
2623 playernum = end->player_num;
2625 Assert(playernum != Player_num);
2627 if (playernum>=N_players)
2629 Int3(); // weird, but it can happen in a coop restore game
2630 return; // if it happens in a coop restore, don't worry about it
2633 if ((Network_status == NETSTAT_PLAYING) && (end->connected != 0))
2635 //mprintf ((0,"Returning early for short_endlevel\n"));
2636 return; // Only accept disconnect packets if we're not out of the level yet
2639 Players[playernum].connected = end->connected;
2641 if ((Players[playernum].connected == 1) && (end->seconds_left < Countdown_seconds_left))
2642 Countdown_seconds_left = end->seconds_left;
2644 LastPacketTime[playernum] = timer_get_approx_seconds();
2649 network_pack_objects(void)
2651 // Switching modes, pack the object array
2653 special_reset_objects();
2657 network_verify_objects(int remote, int local)
2660 int nplayers, got_controlcen=0;
2662 mprintf ((0,"NETWORK:remote=%d local=%d\n",remote,local));
2664 if ((remote-local) > 10)
2667 if (Game_mode & GM_MULTI_ROBOTS)
2672 for (i = 0; i <= Highest_object_index; i++)
2674 if ((Objects[i].type == OBJ_PLAYER) || (Objects[i].type == OBJ_GHOST))
2676 if (Objects[i].type == OBJ_CNTRLCEN)
2680 if (got_controlcen && (MaxNumNetPlayers<=nplayers))
2687 network_read_object_packet( ubyte *data )
2689 // Object from another net player we need to sync with
2691 short objnum, remote_objnum;
2696 static int my_pnum = 0;
2697 static int mode = 0;
2698 static int object_count = 0;
2699 static int frame_num = 0;
2702 int remote_frame_num = data[2];
2706 // mprintf((0, "Object packet %d (remote #%d) contains %d objects.\n", frame_num, remote_frame_num, nobj));
2708 for (i = 0; i < nobj; i++)
2710 objnum = INTEL_SHORT( *(short *)(data+loc) ); loc += 2;
2711 obj_owner = data[loc]; loc += 1;
2712 remote_objnum = INTEL_SHORT( *(short *)(data+loc) ); loc += 2;
2716 // Clear object array
2717 mprintf((0, "Clearing object array.\n"));
2720 Network_rejoined = 1;
2721 my_pnum = obj_owner;
2722 change_playernum_to(my_pnum);
2727 else if (objnum == -2)
2729 // Special debug checksum marker for entire send
2732 network_pack_objects();
2735 mprintf((0, "Objnum -2 found in frame local %d remote %d.\n", frame_num, remote_frame_num));
2736 mprintf((0, "Got %d objects, expected %d.\n", object_count, remote_objnum));
2737 if (remote_objnum != object_count) {
2740 if (network_verify_objects(remote_objnum, object_count))
2742 // Failed to sync up
2743 nm_messagebox(NULL, 1, TXT_OK, TXT_NET_SYNC_FAILED);
2744 Network_status = NETSTAT_MENU;
2751 if (frame_num != remote_frame_num)
2753 mprintf ((0,"Got a type 3 object packet!\n"));
2755 if ((obj_owner == my_pnum) || (obj_owner == -1))
2759 objnum = remote_objnum;
2760 //if (objnum > Highest_object_index)
2762 // Highest_object_index = objnum;
2763 // num_objects = Highest_object_index+1;
2769 network_pack_objects();
2772 objnum = obj_allocate();
2775 obj = &Objects[objnum];
2776 if (obj->segnum != -1)
2778 Assert(obj->segnum == -1);
2779 Assert(objnum < MAX_OBJECTS);
2780 memcpy(obj,data+loc,sizeof(object)); loc += sizeof(object);
2782 if (Network_game_type == IPX_GAME)
2785 segnum = obj->segnum;
2786 obj->next = obj->prev = obj->segnum = -1;
2787 obj->attached_obj = -1;
2789 obj_link(obj-Objects,segnum);
2790 if (obj_owner == my_pnum)
2791 map_objnum_local_to_local(objnum);
2792 else if (obj_owner != -1)
2793 map_objnum_local_to_remote(objnum, remote_objnum, obj_owner);
2795 object_owner[objnum] = -1;
2797 } // For a standard onbject
2798 } // For each object in packet
2801 void network_sync_poll( int nitems, newmenu_item * menus, int * key, int citem )
2803 // Polling loop waiting for sync packet to start game
2813 if (Network_status != NETSTAT_WAITING) // Status changed to playing, exit the menu
2816 if (!Network_rejoined && (timer_get_approx_seconds() > t1+F1_0*2))
2820 // Poll time expired, re-send request
2822 t1 = timer_get_approx_seconds();
2824 mprintf((0, "Re-sending join request.\n"));
2825 i = network_send_request();
2831 void network_start_poll( int nitems, newmenu_item * menus, int * key, int citem )
2838 Assert(Network_status == NETSTAT_STARTING);
2840 if (!menus[0].value) {
2842 menus[0].redraw = 1;
2845 for (i=1; i<nitems; i++ ) {
2846 if ( (i>= N_players) && (menus[i].value) ) {
2848 menus[i].redraw = 1;
2853 for (i=0; i<nitems; i++ ) {
2854 if ( menus[i].value ) {
2856 if ( nm > N_players ) {
2858 menus[i].redraw = 1;
2863 if ( nm > MaxNumNetPlayers ) {
2864 nm_messagebox( TXT_ERROR, 1, TXT_OK, "%s %d %s", TXT_SORRY_ONLY, MaxNumNetPlayers, TXT_NETPLAYERS_IN );
2865 // Turn off the last player highlighted
2866 for (i = N_players; i > 0; i--)
2867 if (menus[i].value == 1)
2870 menus[i].redraw = 1;
2875 // if (nitems > MAX_PLAYERS ) return;
2877 n = Netgame.numplayers;
2880 if (n < Netgame.numplayers )
2882 digi_play_sample (SOUND_HUD_MESSAGE,F1_0);
2884 mprintf ((0,"More players are printed!"));
2885 if (args_find("-norankings"))
2886 sprintf( menus[N_players-1].text, "%d. %-20s", N_players,NetPlayers.players[N_players-1].callsign );
2888 sprintf( menus[N_players-1].text, "%d. %s%-20s", N_players, RankStrings[NetPlayers.players[N_players-1].rank],NetPlayers.players[N_players-1].callsign );
2890 menus[N_players-1].redraw = 1;
2891 if (N_players <= MaxNumNetPlayers)
2893 menus[N_players-1].value = 1;
2896 else if ( n > Netgame.numplayers )
2898 // One got removed...
2900 digi_play_sample (SOUND_HUD_KILL,F1_0);
2902 for (i=0; i<N_players; i++ )
2905 if (args_find("-norankings"))
2906 sprintf( menus[i].text, "%d. %-20s", i+1, NetPlayers.players[i].callsign );
2908 sprintf( menus[i].text, "%d. %s%-20s", i+1, RankStrings[NetPlayers.players[i].rank],NetPlayers.players[i].callsign );
2909 if (i < MaxNumNetPlayers)
2913 menus[i].redraw = 1;
2915 for (i=N_players; i<n; i++ )
2917 sprintf( menus[i].text, "%d. ", i+1 ); // Clear out the deleted entries...
2919 menus[i].redraw = 1;
2924 int opt_cinvul, opt_team_anarchy, opt_coop, opt_show_on_map, opt_closed,opt_maxnet;
2925 int last_cinvul=0,last_maxnet,opt_team_hoard;
2926 int opt_refuse,opt_capture;
2928 void network_game_param_poll( int nitems, newmenu_item * menus, int * key, int citem )
2932 if (((HoardEquipped() && menus[opt_team_hoard].value) || (menus[opt_team_anarchy].value || menus[opt_capture].value)) && !menus[opt_closed].value && !menus[opt_refuse].value) {
2933 menus[opt_refuse].value = 1;
2934 menus[opt_refuse].redraw = 1;
2935 menus[opt_refuse-1].value = 0;
2936 menus[opt_refuse-1].redraw = 1;
2937 menus[opt_refuse-2].value = 0;
2938 menus[opt_refuse-2].redraw = 1;
2942 if (menus[opt_coop].value)
2944 if ( (menus[opt_coop].value) || ((Network_game_type == APPLETALK_GAME) && (Network_appletalk_type == LOCALTALK_TYPE) && (menus[opt_coop-1].value)) )
2949 if (menus[opt_maxnet].value>2)
2951 menus[opt_maxnet].value=2;
2952 menus[opt_maxnet].redraw=1;
2955 if (menus[opt_maxnet].max_value>2)
2957 menus[opt_maxnet].max_value=2;
2958 menus[opt_maxnet].redraw=1;
2962 if ( (Network_game_type == APPLETALK_GAME) && (Network_appletalk_type == LOCALTALK_TYPE) ) {
2963 if (menus[opt_maxnet].value > 0) {
2964 menus[opt_maxnet].value=0;
2965 menus[opt_maxnet].redraw=1;
2967 if (menus[opt_maxnet].max_value > 0) {
2968 menus[opt_maxnet].max_value=0;
2969 menus[opt_maxnet].redraw=1;
2974 if (!Netgame.game_flags & NETGAME_FLAG_SHOW_MAP)
2975 Netgame.game_flags |= NETGAME_FLAG_SHOW_MAP;
2977 if (Netgame.PlayTimeAllowed || Netgame.KillGoal)
2979 Netgame.PlayTimeAllowed=0;
2984 else // if !Coop game
2989 menus[opt_maxnet].value=6;
2990 menus[opt_maxnet].max_value=6;
2993 if ( (Network_game_type == APPLETALK_GAME) && (Network_appletalk_type == LOCALTALK_TYPE) ) {
2994 menus[opt_maxnet].value=1;
2995 menus[opt_maxnet].max_value=1;
3002 if ( last_maxnet != menus[opt_maxnet].value )
3004 sprintf( menus[opt_maxnet].text, "Maximum players: %d", menus[opt_maxnet].value+2 );
3005 last_maxnet = menus[opt_maxnet].value;
3006 menus[opt_maxnet].redraw = 1;
3010 int netgame_difficulty;
3012 int network_get_game_params( char * game_name, int *mode, int *game_flags, int *level )
3015 int opt, opt_name, opt_level, opt_mode,opt_moreopts;
3017 char name[NETGAME_NAME_LEN+1];
3019 char level_text[32];
3022 int new_mission_num;
3025 *game_flags=*game_flags;
3027 SetAllAllowablesTo (1);
3028 NamesInfoSecurity=-1;
3030 for (i=0;i<MAX_PLAYERS;i++)
3032 Players[i].callsign[0]=0;
3036 Netgame.PlayTimeAllowed=0;
3037 Netgame.Allow_marker_view=1;
3038 netgame_difficulty=Player_default_difficulty;
3040 new_mission_num = multi_choose_mission(&anarchy_only);
3042 if (new_mission_num < 0)
3045 if (!(args_find ("-packets") && args_find ("-shortpackets")))
3046 if (!network_choose_connect ())
3050 if ( (Network_game_type == APPLETALK_GAME) && (Network_appletalk_type == LOCALTALK_TYPE) )
3051 MaxNumNetPlayers = 3;
3054 strcpy(Netgame.mission_name, Mission_list[new_mission_num].filename);
3055 strcpy(Netgame.mission_title, Mission_list[new_mission_num].mission_name);
3056 Netgame.control_invul_time = control_invul_time;
3058 sprintf( name, "%s%s", Players[Player_num].callsign, TXT_S_GAME );
3059 sprintf( slevel, "1" );
3062 m[opt].type = NM_TYPE_TEXT; m[opt].text = TXT_DESCRIPTION; opt++;
3065 m[opt].type = NM_TYPE_INPUT; m[opt].text = name; m[opt].text_len = NETGAME_NAME_LEN; opt++;
3067 sprintf(level_text, "%s (1-%d)", TXT_LEVEL_, Last_level);
3069 // if (Last_secret_level < -1)
3070 // sprintf(level_text+strlen(level_text)-1, ", S1-S%d)", -Last_secret_level);
3071 // else if (Last_secret_level == -1)
3072 // sprintf(level_text+strlen(level_text)-1, ", S1)");
3074 Assert(strlen(level_text) < 32);
3076 m[opt].type = NM_TYPE_TEXT; m[opt].text = level_text; opt++;
3079 m[opt].type = NM_TYPE_INPUT; m[opt].text = slevel; m[opt].text_len=4; opt++;
3080 // m[opt].type = NM_TYPE_TEXT; m[opt].text = TXT_OPTIONS; opt++;
3083 m[opt].type = NM_TYPE_RADIO; m[opt].text = TXT_ANARCHY; m[opt].value=1; m[opt].group=0; opt++;
3084 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++;
3085 m[opt].type = NM_TYPE_RADIO; m[opt].text = TXT_ANARCHY_W_ROBOTS; m[opt].value=0; m[opt].group=0; opt++;
3086 m[opt].type = NM_TYPE_RADIO; m[opt].text = TXT_COOPERATIVE; m[opt].value=0; m[opt].group=0; opt_coop=opt; opt++;
3087 m[opt].type = NM_TYPE_RADIO; m[opt].text = "Capture the flag"; m[opt].value=0; m[opt].group=0; opt_capture=opt; opt++;
3089 if (HoardEquipped())
3091 m[opt].type = NM_TYPE_RADIO; m[opt].text = "Hoard"; m[opt].value=0; m[opt].group=0; opt++;
3092 m[opt].type = NM_TYPE_RADIO; m[opt].text = "Team Hoard"; m[opt].value=0; m[opt].group=0; opt_team_hoard=opt; opt++;
3093 m[opt].type = NM_TYPE_TEXT; m[opt].text = ""; opt++;
3096 { m[opt].type = NM_TYPE_TEXT; m[opt].text = ""; opt++; }
3098 m[opt].type = NM_TYPE_RADIO; m[opt].text = "Open game"; m[opt].group=1; m[opt].value=0; opt++;
3100 m[opt].type = NM_TYPE_RADIO; m[opt].text = TXT_CLOSED_GAME; m[opt].group=1; m[opt].value=0; opt++;
3102 m[opt].type = NM_TYPE_RADIO; m[opt].text = "Restricted Game "; m[opt].group=1; m[opt].value=Netgame.RefusePlayers; opt++;
3104 // m[opt].type = NM_TYPE_CHECK; m[opt].text = TXT_SHOW_IDS; m[opt].value=0; opt++;
3107 sprintf( srmaxnet, "Maximum players: %d", MaxNumNetPlayers);
3108 m[opt].type = NM_TYPE_SLIDER; m[opt].value=MaxNumNetPlayers-2; m[opt].text= srmaxnet; m[opt].min_value=0;
3109 m[opt].max_value=MaxNumNetPlayers-2; opt++;
3110 last_maxnet=MaxNumNetPlayers-2;
3113 m[opt].type = NM_TYPE_MENU; m[opt].text = "More options..."; opt++;
3118 ExtGameStatus=GAMESTAT_NETGAME_OPTIONS;
3119 i = newmenu_do1( NULL, NULL, opt, m, network_game_param_poll, 1 );
3121 if (i==opt_moreopts)
3123 if ( m[opt_mode+3].value )
3124 Game_mode=GM_MULTI_COOP;
3125 network_more_game_options();
3129 Netgame.RefusePlayers=m[opt_refuse].value;
3135 MaxNumNetPlayers = m[opt_maxnet].value+2;
3136 Netgame.max_numplayers=MaxNumNetPlayers;
3138 for (j = 0; j < num_active_games; j++)
3139 if (!stricmp(Active_games[j].game_name, name))
3141 nm_messagebox(TXT_ERROR, 1, TXT_OK, TXT_DUPLICATE_NAME);
3145 strcpy( game_name, name );
3148 *level = atoi(slevel);
3150 if ((*level < 1) || (*level > Last_level))
3152 nm_messagebox(TXT_ERROR, 1, TXT_OK, TXT_LEVEL_OUT_RANGE );
3153 sprintf(slevel, "1");
3156 if ( m[opt_mode].value )
3157 *mode = NETGAME_ANARCHY;
3162 nm_messagebox(TXT_SORRY, 1, TXT_OK, TXT_REGISTERED_ONLY );
3163 m[opt_mode+1].value = 0;
3164 m[opt_mode+2].value = 0;
3165 m[opt_mode+3].value = 0;
3166 if (HoardEquipped())
3167 m[opt_mode+4].value = 0;
3169 m[opt_mode].value = 1;
3173 else if (m[opt_mode+1].value) {
3174 *mode = NETGAME_TEAM_ANARCHY;
3176 else if (m[opt_capture].value)
3177 *mode = NETGAME_CAPTURE_FLAG;
3178 else if (HoardEquipped() && m[opt_capture+1].value)
3179 *mode = NETGAME_HOARD;
3180 else if (HoardEquipped() && m[opt_capture+2].value)
3181 *mode = NETGAME_TEAM_HOARD;
3182 else if (anarchy_only) {
3183 nm_messagebox(NULL, 1, TXT_OK, TXT_ANARCHY_ONLY_MISSION);
3184 m[opt_mode+2].value = 0;
3185 m[opt_mode+3].value = 0;
3186 m[opt_mode].value = 1;
3189 else if ( m[opt_mode+2].value )
3190 *mode = NETGAME_ROBOT_ANARCHY;
3191 else if ( m[opt_mode+3].value )
3192 *mode = NETGAME_COOPERATIVE;
3193 else Int3(); // Invalid mode -- see Rob
3195 if (m[opt_closed].value)
3196 Netgame.game_flags |= NETGAME_FLAG_CLOSED;
3204 network_set_game_mode(int gamemode)
3208 if ( gamemode == NETGAME_ANARCHY )
3209 Game_mode = GM_NETWORK;
3210 else if ( gamemode == NETGAME_ROBOT_ANARCHY )
3211 Game_mode = GM_NETWORK | GM_MULTI_ROBOTS;
3212 else if ( gamemode == NETGAME_COOPERATIVE )
3213 Game_mode = GM_NETWORK | GM_MULTI_COOP | GM_MULTI_ROBOTS;
3214 else if (gamemode == NETGAME_CAPTURE_FLAG)
3216 Game_mode = GM_NETWORK | GM_TEAM | GM_CAPTURE;
3220 else if (HoardEquipped() && gamemode == NETGAME_HOARD)
3221 Game_mode = GM_NETWORK | GM_HOARD;
3222 else if (HoardEquipped() && gamemode == NETGAME_TEAM_HOARD)
3224 Game_mode = GM_NETWORK | GM_HOARD | GM_TEAM;
3227 else if ( gamemode == NETGAME_TEAM_ANARCHY )
3229 Game_mode = GM_NETWORK | GM_TEAM;
3236 #ifdef MACINTOSH // minimize players on localtalk games
3237 if ( (Network_game_type == APPLETALK_GAME) && (Network_appletalk_type == LOCALTALK_TYPE) ) {
3238 if (Game_mode & GM_MULTI_ROBOTS)
3239 MaxNumNetPlayers = 2;
3241 MaxNumNetPlayers = 3;
3243 if (Game_mode & GM_MULTI_COOP)
3244 MaxNumNetPlayers = 4;
3246 MaxNumNetPlayers = 8;
3254 network_find_game(void)
3256 // Find out whether or not there is space left on this socket
3260 Network_status = NETSTAT_BROWSING;
3262 num_active_games = 0;
3264 show_boxed_message(TXT_WAIT);
3266 network_send_game_list_request();
3267 t1 = timer_get_approx_seconds() + F1_0*3;
3269 while (timer_get_approx_seconds() < t1) // Wait 3 seconds for replies
3272 clear_boxed_message();
3274 // mprintf((0, "%s %d %s\n", TXT_FOUND, num_active_games, TXT_ACTIVE_GAMES));
3276 if (num_active_games < MAX_ACTIVE_NETGAMES)
3281 void network_read_sync_packet( netgame_info * sp, int rsinit)
3284 netgame_info tmp_info;
3288 char temp_callsign[CALLSIGN_LEN+1];
3291 if ( (Network_game_type == IPX_GAME) && (sp != &Netgame) ) { // for macintosh -- get the values unpacked to our structure format
3292 receive_netgame_packet((ubyte *)sp, &tmp_info, 0);
3298 TempPlayersInfo=&NetPlayers;
3300 // This function is now called by all people entering the netgame.
3302 // mprintf( (0, "%s %d\n", TXT_STARTING_NETGAME, sp->levelnum ));
3306 memcpy( &Netgame, sp, sizeof(netgame_info) );
3307 memcpy (&NetPlayers,TempPlayersInfo,sizeof (AllNetPlayers_info));
3310 N_players = sp->numplayers;
3311 Difficulty_level = sp->difficulty;
3312 Network_status = sp->game_status;
3314 //Assert(Function_mode != FMODE_GAME);
3318 mprintf((1, "Netgame.checksum = %d, calculated checksum = %d.\n", Netgame.segments_checksum, my_segments_checksum));
3320 if (Netgame.segments_checksum != my_segments_checksum)
3322 Network_status = NETSTAT_MENU;
3323 nm_messagebox(TXT_ERROR, 1, TXT_OK, TXT_NETLEVEL_NMATCH);
3329 // Discover my player number
3331 memcpy(temp_callsign, Players[Player_num].callsign, CALLSIGN_LEN+1);
3335 for (i=0; i<MAX_NUM_NET_PLAYERS; i++ ) {
3336 Players[i].net_kills_total = 0;
3337 // Players[i].net_killed_total = 0;
3340 for (i=0; i<N_players; i++ ) {
3341 if (Network_game_type == IPX_GAME) {
3342 if ( (!memcmp( TempPlayersInfo->players[i].network.ipx.node, My_Seq.player.network.ipx.node, 6 )) && (!stricmp( TempPlayersInfo->players[i].callsign, temp_callsign)) ) {
3343 if (Player_num!=-1) {
3344 Int3(); // Hey, we've found ourselves twice
3345 mprintf ((0,"Hey, we've found ourselves twice!\n"));
3346 Network_status = NETSTAT_MENU;
3349 change_playernum_to(i);
3352 if ( (TempPlayersInfo->players[i].network.appletalk.node == My_Seq.player.network.appletalk.node) && (!stricmp( TempPlayersInfo->players[i].callsign, temp_callsign)) ) {
3353 if (Player_num!=-1) {
3354 Int3(); // Hey, we've found ourselves twice
3355 Network_status = NETSTAT_MENU;
3358 change_playernum_to(i);
3361 memcpy( Players[i].callsign, TempPlayersInfo->players[i].callsign, CALLSIGN_LEN+1 );
3363 if (Network_game_type == IPX_GAME) {
3364 if ( (*(uint *)TempPlayersInfo->players[i].network.ipx.server) != 0 )
3365 ipx_get_local_target( TempPlayersInfo->players[i].network.ipx.server, TempPlayersInfo->players[i].network.ipx.node, Players[i].net_address );
3367 memcpy( Players[i].net_address, TempPlayersInfo->players[i].network.ipx.node, 6 );
3370 Players[i].n_packets_got=0; // How many packets we got from them
3371 Players[i].n_packets_sent=0; // How many packets we sent to them
3372 Players[i].connected = TempPlayersInfo->players[i].connected;
3373 Players[i].net_kills_total = sp->player_kills[i];
3374 Players[i].net_killed_total = sp->killed[i];
3375 if ((Network_rejoined) || (i != Player_num))
3376 Players[i].score = sp->player_score[i];
3377 for (j = 0; j < MAX_NUM_NET_PLAYERS; j++)
3379 kill_matrix[i][j] = sp->kills[i][j];
3383 if ( Player_num < 0 ) {
3384 mprintf ((0,"Bad Player_num, resetting to NETSTAT_MENU!\n"));
3385 Network_status = NETSTAT_MENU;
3389 if (Network_rejoined)
3390 for (i=0; i<N_players;i++)
3391 Players[i].net_killed_total = sp->killed[i];
3393 if (Network_rejoined) {
3394 network_process_monitor_vector(sp->monitor_vector);
3395 Players[Player_num].time_level = sp->level_time;
3398 team_kills[0] = sp->team_kills[0];
3399 team_kills[1] = sp->team_kills[1];
3401 Players[Player_num].connected = 1;
3402 NetPlayers.players[Player_num].connected = 1;
3403 NetPlayers.players[Player_num].rank=GetMyNetRanking();
3405 if (!Network_rejoined)
3406 for (i=0; i<NumNetPlayerPositions; i++) {
3407 Objects[Players[i].objnum].pos = Player_init[Netgame.locations[i]].pos;
3408 Objects[Players[i].objnum].orient = Player_init[Netgame.locations[i]].orient;
3409 obj_relink(Players[i].objnum,Player_init[Netgame.locations[i]].segnum);
3412 Objects[Players[Player_num].objnum].type = OBJ_PLAYER;
3414 mprintf ((0,"Changing to NETSTAT_PLAYING!\n"));
3415 Network_status = NETSTAT_PLAYING;
3416 Function_mode = FMODE_GAME;
3417 multi_sort_kill_list();
3422 network_send_sync(void)
3426 // Randomize their starting locations...
3428 d_srand( timer_get_fixed_seconds() );
3429 for (i=0; i<NumNetPlayerPositions; i++ )
3431 if (Players[i].connected)
3432 Players[i].connected = 1; // Get rid of endlevel connect statuses
3433 if (Game_mode & GM_MULTI_COOP)
3434 Netgame.locations[i] = i;
3438 np = d_rand() % NumNetPlayerPositions;
3439 for (j=0; j<i; j++ )
3441 if (Netgame.locations[j]==np)
3448 // np is a location that is not used anywhere else..
3449 Netgame.locations[i]=np;
3450 // mprintf((0, "Player %d starting in location %d\n" ,i ,np ));
3454 // Push current data into the sync packet
3456 network_update_netgame();
3457 Netgame.game_status = NETSTAT_PLAYING;
3458 Netgame.type = PID_SYNC;
3459 Netgame.segments_checksum = my_segments_checksum;
3461 for (i=0; i<N_players; i++ ) {
3462 if ((!Players[i].connected) || (i == Player_num))
3465 if (Network_game_type == IPX_GAME) {
3466 // Send several times, extras will be ignored
3468 ipx_send_internetwork_packet_data( (ubyte *)&Netgame, sizeof(netgame_info), NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node);
3469 ipx_send_internetwork_packet_data( (ubyte *)&NetPlayers, sizeof(AllNetPlayers_info), NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node);
3471 send_netgame_packet(NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node, NULL, 0);
3472 send_netplayers_packet(NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node);
3476 appletalk_send_packet_data( (ubyte *)&Netgame, sizeof(netgame_info), NetPlayers.players[i].network.appletalk.node,
3477 NetPlayers.players[i].network.appletalk.net,
3478 NetPlayers.players[i].network.appletalk.socket);
3479 appletalk_send_packet_data( (ubyte *)&NetPlayers, sizeof(AllNetPlayers_info), NetPlayers.players[i].network.appletalk.node,
3480 NetPlayers.players[i].network.appletalk.net,
3481 NetPlayers.players[i].network.appletalk.socket);
3486 network_read_sync_packet(&Netgame,1); // Read it myself, as if I had sent it
3490 network_select_teams(void)
3493 newmenu_item m[MAX_PLAYERS+4];
3494 int choice, opt, opt_team_b;
3495 ubyte team_vector = 0;
3496 char team_names[2][CALLSIGN_LEN+1];
3498 int pnums[MAX_PLAYERS+2];
3500 // One-time initialization
3502 for (i = N_players/2; i < N_players; i++) // Put first half of players on team A
3504 team_vector |= (1 << i);
3507 sprintf(team_names[0], "%s", TXT_BLUE);
3508 sprintf(team_names[1], "%s", TXT_RED);
3510 // Here comes da menu
3512 m[0].type = NM_TYPE_INPUT; m[0].text = team_names[0]; m[0].text_len = CALLSIGN_LEN;
3515 for (i = 0; i < N_players; i++)
3517 if (!(team_vector & (1 << i)))
3519 m[opt].type = NM_TYPE_MENU; m[opt].text = NetPlayers.players[i].callsign; pnums[opt] = i; opt++;
3523 m[opt].type = NM_TYPE_INPUT; m[opt].text = team_names[1]; m[opt].text_len = CALLSIGN_LEN; opt++;
3524 for (i = 0; i < N_players; i++)
3526 if (team_vector & (1 << i))
3528 m[opt].type = NM_TYPE_MENU; m[opt].text = NetPlayers.players[i].callsign; pnums[opt] = i; opt++;
3531 m[opt].type = NM_TYPE_TEXT; m[opt].text = ""; opt++;
3532 m[opt].type = NM_TYPE_MENU; m[opt].text = TXT_ACCEPT; opt++;
3534 Assert(opt <= MAX_PLAYERS+4);
3536 choice = newmenu_do(NULL, TXT_TEAM_SELECTION, opt, m, NULL);
3538 if (choice == opt-1)
3540 if ((opt-2-opt_team_b < 2) || (opt_team_b == 1))
3542 nm_messagebox(NULL, 1, TXT_OK, TXT_TEAM_MUST_ONE);
3548 Netgame.team_vector = team_vector;
3549 strcpy(Netgame.team_name[0], team_names[0]);
3550 strcpy(Netgame.team_name[1], team_names[1]);
3554 else if ((choice > 0) && (choice < opt_team_b)) {
3555 team_vector |= (1 << pnums[choice]);
3557 else if ((choice > opt_team_b) && (choice < opt-2)) {
3558 team_vector &= ~(1 << pnums[choice]);
3560 else if (choice == -1)
3569 network_select_players(void)
3572 newmenu_item m[MAX_PLAYERS+4];
3573 char text[MAX_PLAYERS+4][45];
3575 int save_nplayers; //how may people would like to join
3577 network_add_player( &My_Seq );
3579 for (i=0; i< MAX_PLAYERS+4; i++ ) {
3580 sprintf( text[i], "%d. %-20s", i+1, "" );
3581 m[i].type = NM_TYPE_CHECK; m[i].text = text[i]; m[i].value = 0;
3584 m[0].value = 1; // Assume server will play...
3586 if (args_find("-norankings"))
3587 sprintf( text[0], "%d. %-20s", 1, Players[Player_num].callsign );
3589 sprintf( text[0], "%d. %s%-20s", 1, RankStrings[NetPlayers.players[Player_num].rank],Players[Player_num].callsign );
3591 sprintf( title, "%s %d %s", TXT_TEAM_SELECT, MaxNumNetPlayers, TXT_TEAM_PRESS_ENTER );
3594 ExtGameStatus=GAMESTAT_NETGAME_PLAYER_SELECT;
3595 j=newmenu_do1( NULL, title, MAX_PLAYERS+4, m, network_start_poll, 1 );
3597 save_nplayers = N_players;
3602 // Dump all players and go back to menu mode
3605 for (i=1; i<save_nplayers; i++) {
3606 if (Network_game_type == IPX_GAME)
3607 network_dump_player(NetPlayers.players[i].network.ipx.server,NetPlayers.players[i].network.ipx.node, DUMP_ABORTED);
3610 network_dump_appletalk_player(NetPlayers.players[i].network.appletalk.node,NetPlayers.players[i].network.appletalk.net, NetPlayers.players[i].network.appletalk.socket, DUMP_ABORTED);
3615 Netgame.numplayers = 0;
3616 network_send_game_info(0); // Tell everyone we're bailing
3618 Network_status = NETSTAT_MENU;
3622 // Count number of players chosen
3625 for (i=0; i<save_nplayers; i++ )
3631 if ( N_players > Netgame.max_numplayers) {
3633 nm_messagebox( TXT_ERROR, 1, TXT_OK, "%s %d %s", TXT_SORRY_ONLY, MaxNumNetPlayers, TXT_NETPLAYERS_IN );
3635 nm_messagebox( TXT_ERROR, 1, TXT_OK, "%s %d netplayers for this game.", TXT_SORRY_ONLY, MaxNumNetPlayers );
3637 N_players = save_nplayers;
3638 goto GetPlayersAgain;
3642 if ( N_players < 2 ) {
3643 nm_messagebox( TXT_ERROR, 1, TXT_OK, TXT_TEAM_ATLEAST_TWO );
3644 N_players = save_nplayers;
3645 goto GetPlayersAgain;
3650 if ( (Netgame.gamemode == NETGAME_TEAM_ANARCHY ||
3651 Netgame.gamemode == NETGAME_CAPTURE_FLAG || Netgame.gamemode == NETGAME_TEAM_HOARD) && (N_players < 2) ) {
3652 nm_messagebox(TXT_ERROR, 1, TXT_OK, "You must select at least two\nplayers to start a team game" );
3653 N_players = save_nplayers;
3654 goto GetPlayersAgain;
3658 // Remove players that aren't marked.
3660 for (i=0; i<save_nplayers; i++ ) {
3665 if (Network_game_type == IPX_GAME) {
3666 memcpy(NetPlayers.players[N_players].network.ipx.node, NetPlayers.players[i].network.ipx.node, 6);
3667 memcpy(NetPlayers.players[N_players].network.ipx.server, NetPlayers.players[i].network.ipx.server, 4);
3669 NetPlayers.players[N_players].network.appletalk.node = NetPlayers.players[i].network.appletalk.node;
3670 NetPlayers.players[N_players].network.appletalk.net = NetPlayers.players[i].network.appletalk.net;
3671 NetPlayers.players[N_players].network.appletalk.socket = NetPlayers.players[i].network.appletalk.socket;
3673 memcpy(NetPlayers.players[N_players].callsign, NetPlayers.players[i].callsign, CALLSIGN_LEN+1);
3674 NetPlayers.players[N_players].version_major=NetPlayers.players[i].version_major;
3675 NetPlayers.players[N_players].version_minor=NetPlayers.players[i].version_minor;
3676 NetPlayers.players[N_players].rank=NetPlayers.players[i].rank;
3677 ClipRank (&NetPlayers.players[N_players].rank);
3678 network_check_for_old_version(i);
3680 Players[N_players].connected = 1;
3685 if (Network_game_type == IPX_GAME)
3686 network_dump_player(NetPlayers.players[i].network.ipx.server,NetPlayers.players[i].network.ipx.node, DUMP_DORK);
3689 network_dump_appletalk_player(NetPlayers.players[i].network.appletalk.node,NetPlayers.players[i].network.appletalk.net, NetPlayers.players[i].network.appletalk.socket, DUMP_DORK);
3694 for (i = N_players; i < MAX_NUM_NET_PLAYERS; i++) {
3695 if (Network_game_type == IPX_GAME) {
3696 memset(NetPlayers.players[i].network.ipx.node, 0, 6);
3697 memset(NetPlayers.players[i].network.ipx.server, 0, 4);
3699 NetPlayers.players[i].network.appletalk.node = 0;
3700 NetPlayers.players[i].network.appletalk.net = 0;
3701 NetPlayers.players[i].network.appletalk.socket = 0;
3703 memset(NetPlayers.players[i].callsign, 0, CALLSIGN_LEN+1);
3704 NetPlayers.players[i].version_major=0;
3705 NetPlayers.players[i].version_minor=0;
3706 NetPlayers.players[i].rank=0;
3709 mprintf ((0,"Select teams: Game mode is %d\n",Netgame.gamemode));
3711 if (Netgame.gamemode == NETGAME_TEAM_ANARCHY ||
3712 Netgame.gamemode == NETGAME_CAPTURE_FLAG ||
3713 Netgame.gamemode == NETGAME_TEAM_HOARD)
3714 if (!network_select_teams())
3721 network_start_game()
3724 char game_name[NETGAME_NAME_LEN+1];
3725 int chosen_game_mode, game_flags, level;
3727 if (Network_game_type == IPX_GAME) {
3729 Assert( FRAME_INFO_SIZE < IPX_MAX_DATA_SIZE );
3730 mprintf((0, "Using frame_info len %d, max %d.\n", FRAME_INFO_SIZE, IPX_MAX_DATA_SIZE));
3732 if ( !Network_active )
3734 nm_messagebox(NULL, 1, TXT_OK, TXT_IPX_NOT_FOUND );
3742 Assert( FRAME_INFO_SIZE < APPLETALK_MAX_DATA_SIZE );
3743 mprintf((0, "Using frame_info len %d, max %d.\n", sizeof(frame_info), APPLETALK_MAX_DATA_SIZE));
3744 if (Appletalk_active <= 0) {
3745 switch (Appletalk_active) {
3746 case APPLETALK_NOT_OPEN:
3747 sprintf(buf, "Appletalk is not currently active.\nPlease enable AppleTalk from the\nChooser and restart Descent.");
3749 case APPLETALK_BAD_LISTENER:
3750 sprintf(buf, "The Resource Fork of Descent appears damaged.\nPlease re-install Descent or contact\nMacPlay technical support.");
3752 case APPLETALK_NO_LOCAL_ADDR:
3753 sprintf(buf, "Wow! Strange!\n\nNo Local Address.");
3755 case APPLETALK_NO_SOCKET:
3756 sprintf(buf, "All AppleTalk sockets are in use.\nTry shutting down other network\napplications and restarting Descent.\n");
3759 nm_messagebox(NULL, 1, TXT_OK, buf);
3762 strcpy(Network_zone_name, DEFAULT_ZONE_NAME);
3767 change_playernum_to(0);
3769 if (network_find_game())
3771 nm_messagebox(NULL, 1, TXT_OK, TXT_NET_FULL);
3776 i = network_get_game_params( game_name, &chosen_game_mode, &game_flags, &level );
3782 // LoadLevel(level); Old, no longer used.
3784 Netgame.difficulty = Difficulty_level;
3785 Netgame.gamemode = chosen_game_mode;
3786 Netgame.game_status = NETSTAT_STARTING;
3787 Netgame.numplayers = 0;
3788 Netgame.max_numplayers = MaxNumNetPlayers;
3789 Netgame.levelnum = level;
3790 Netgame.protocol_version = MULTI_PROTO_VERSION;
3792 strcpy(Netgame.game_name, game_name);
3794 Network_status = NETSTAT_STARTING;
3797 if (Network_game_type == APPLETALK_GAME) {
3802 show_boxed_message("Registering Netgame");
3804 err = appletalk_register_netgame( game_name, TickCount() );
3805 t1 = timer_get_fixed_seconds() + F1_0;
3806 while (timer_get_fixed_seconds() < t1) ;
3808 } while ( (err == nbpDuplicate) && (count != MAX_REGISTER_TRIES) );
3809 clear_boxed_message();
3810 if ( (err == tooManyReqs) || (count == MAX_REGISTER_TRIES) ) {
3811 nm_messagebox(NULL, 1, TXT_OK, "AppleTalk Network is too busy.\nPlease try again shortly.");
3812 Game_mode = GM_GAME_OVER;
3818 network_set_game_mode(Netgame.gamemode);
3820 d_srand( timer_get_fixed_seconds() );
3821 Netgame.Security=d_rand(); // For syncing Netgames with player packets
3823 if(network_select_players())
3825 StartNewLevel(Netgame.levelnum, 0);
3828 Game_mode = GM_GAME_OVER;
3832 void restart_net_searching(newmenu_item * m)
3836 num_active_games = 0;
3838 memset(Active_games, 0, sizeof(netgame_info)*MAX_ACTIVE_NETGAMES);
3840 for (i = 0; i < MAX_ACTIVE_NETGAMES; i++)
3842 sprintf(m[i+2].text, "%d. ",i+1);
3846 NamesInfoSecurity=-1;
3847 Network_games_changed = 1;
3850 char *ModeLetters[]={"ANRCHY","TEAM","ROBO","COOP","FLAG","HOARD","TMHOARD"};
3852 int NumActiveNetgames=0;
3854 void network_join_poll( int nitems, newmenu_item * menus, int * key, int citem )
3856 // Polling loop for Join Game menu
3858 int i, osocket,join_status,temp;
3865 if ( (Network_game_type == IPX_GAME) && Network_allow_socket_changes ) {
3866 osocket = Network_socket;
3868 if ( *key==KEY_PAGEDOWN ) { Network_socket--; *key = 0; }
3869 if ( *key==KEY_PAGEUP ) { Network_socket++; *key = 0; }
3871 if (Network_socket>99)
3873 if (Network_socket<-99)
3876 if ( Network_socket+IPX_DEFAULT_SOCKET > 0x8000 )
3877 Network_socket = 0x8000 - IPX_DEFAULT_SOCKET;
3879 if ( Network_socket+IPX_DEFAULT_SOCKET < 0 )
3880 Network_socket = IPX_DEFAULT_SOCKET;
3882 if (Network_socket != osocket ) {
3883 sprintf( menus[0].text, "\t%s %+d (PgUp/PgDn to change)", TXT_CURRENT_IPX_SOCKET, Network_socket );
3884 menus[0].redraw = 1;
3885 mprintf(( 0, "Changing to socket %d\n", Network_socket ));
3887 mprintf ((0,"netgood 1!\n"));
3888 ipx_change_default_socket( IPX_DEFAULT_SOCKET + Network_socket );
3889 mprintf ((0,"netgood 2!\n"));
3890 restart_net_searching(menus);
3891 mprintf ((0,"netgood 3!\n"));
3892 network_send_game_list_request();
3893 mprintf ((0,"netgood 4!\n"));
3898 // send a request for game info every 3 seconds
3900 if (Network_game_type == IPX_GAME) {
3901 if (timer_get_approx_seconds() > t1+F1_0*3) {
3902 t1 = timer_get_approx_seconds();
3903 network_send_game_list_request();
3906 } else if (timer_get_approx_seconds() > t1+F1_0*20) {
3908 t1 = timer_get_approx_seconds();
3909 restart_net_searching(menus);
3910 show_boxed_message("Requesting list of Netgames");
3911 network_send_game_list_request();
3912 clear_boxed_message();
3917 temp=num_active_games;
3921 NumActiveNetgames=num_active_games;
3923 if (!Network_games_changed)
3926 if (temp!=num_active_games)
3927 digi_play_sample (SOUND_HUD_MESSAGE,F1_0);
3929 Network_games_changed = 0;
3930 mprintf ((0,"JOIN POLL: I'm looking at %d games!\n",num_active_games));
3932 // Copy the active games data into the menu options
3933 for (i = 0; i < num_active_games; i++)
3935 int game_status = Active_games[i].game_status;
3936 int j,x, k,tx,ty,ta,nplayers = 0;
3937 char levelname[8],MissName[25],GameName[25],thold[2];
3940 // These next two loops protect against menu skewing
3941 // if missiontitle or gamename contain a tab
3943 for (x=0,tx=0,k=0,j=0;j<15;j++)
3945 if (Active_games[i].mission_title[j]=='\t')
3947 thold[0]=Active_games[i].mission_title[j];
3948 gr_get_string_size (thold,&tx,&ty,&ta);
3950 if ((x+=tx)>=LHX(55))
3952 MissName[k]=MissName[k+1]=MissName[k+2]='.';
3957 MissName[k++]=Active_games[i].mission_title[j];
3961 for (x=0,tx=0,k=0,j=0;j<15;j++)
3963 if (Active_games[i].game_name[j]=='\t')
3965 thold[0]=Active_games[i].game_name[j];
3966 gr_get_string_size (thold,&tx,&ty,&ta);
3968 if ((x+=tx)>=LHX(55))
3970 GameName[k]=GameName[k+1]=GameName[k+2]='.';
3974 GameName[k++]=Active_games[i].game_name[j];
3979 nplayers=Active_games[i].numconnected;
3981 if (Active_games[i].levelnum < 0)
3982 sprintf(levelname, "S%d", -Active_games[i].levelnum);
3984 sprintf(levelname, "%d", Active_games[i].levelnum);
3986 if (game_status == NETSTAT_STARTING)
3988 sprintf (menus[i+2].text,"%d.\t%s \t%s \t %d/%d \t%s \t %s \t%s",
3989 i+1,GameName,ModeLetters[Active_games[i].gamemode],nplayers,
3990 Active_games[i].max_numplayers,MissName,levelname,"Forming");
3992 else if (game_status == NETSTAT_PLAYING)
3994 join_status=can_join_netgame(&Active_games[i],NULL);
3995 // mprintf ((0,"Joinstatus=%d\n",join_status));
3998 sprintf (menus[i+2].text,"%d.\t%s \t%s \t %d/%d \t%s \t %s \t%s",
3999 i+1,GameName,ModeLetters[Active_games[i].gamemode],nplayers,
4000 Active_games[i].max_numplayers,MissName,levelname,"Open");
4001 else if (join_status==2)
4002 sprintf (menus[i+2].text,"%d.\t%s \t%s \t %d/%d \t%s \t %s \t%s",
4003 i+1,GameName,ModeLetters[Active_games[i].gamemode],nplayers,
4004 Active_games[i].max_numplayers,MissName,levelname,"Full");
4005 else if (join_status==3)
4006 sprintf (menus[i+2].text,"%d.\t%s \t%s \t %d/%d \t%s \t %s \t%s",
4007 i+1,GameName,ModeLetters[Active_games[i].gamemode],nplayers,
4008 Active_games[i].max_numplayers,MissName,levelname,"Restrict");
4010 sprintf (menus[i+2].text,"%d.\t%s \t%s \t %d/%d \t%s \t %s \t%s",
4011 i+1,GameName,ModeLetters[Active_games[i].gamemode],nplayers,
4012 Active_games[i].max_numplayers,MissName,levelname,"Closed");
4016 sprintf (menus[i+2].text,"%d.\t%s \t%s \t %d/%d \t%s \t %s \t%s",
4017 i+1,GameName,ModeLetters[Active_games[i].gamemode],nplayers,
4018 Active_games[i].max_numplayers,MissName,levelname,"Between");
4021 Assert(strlen(menus[i+2].text) < 100);
4022 menus[i+2].redraw = 1;
4025 for (i = num_active_games; i < MAX_ACTIVE_NETGAMES; i++)
4027 sprintf(menus[i+2].text, "%d. ",i+1);
4028 menus[i+2].redraw = 1;
4033 network_wait_for_sync(void)
4039 Network_status = NETSTAT_WAITING;
4041 m[0].type=NM_TYPE_TEXT; m[0].text = text;
4042 m[1].type=NM_TYPE_TEXT; m[1].text = TXT_NET_LEAVE;
4044 i = network_send_request();
4049 sprintf( m[0].text, "%s\n'%s' %s", TXT_NET_WAITING, NetPlayers.players[i].callsign, TXT_NET_TO_ENTER );
4052 choice=newmenu_do( NULL, TXT_WAIT, 2, m, network_sync_poll );
4057 if (Network_status != NETSTAT_PLAYING)
4061 // if (Network_status == NETSTAT_ENDLEVEL)
4063 // network_send_endlevel_packet(0);
4064 // longjmp(LeaveGame, 0);
4067 mprintf((0, "Aborting join.\n"));
4068 me.type = PID_QUIT_JOINING;
4069 memcpy( me.player.callsign, Players[Player_num].callsign, CALLSIGN_LEN+1 );
4070 if (Network_game_type == IPX_GAME) {
4071 memcpy( me.player.network.ipx.node, ipx_get_my_local_address(), 6 );
4072 memcpy( me.player.network.ipx.server, ipx_get_my_server_address(), 4 );
4074 ipx_send_internetwork_packet_data( (ubyte *)&me, sizeof(sequence_packet), NetPlayers.players[0].network.ipx.server, NetPlayers.players[0].network.ipx.node );
4076 send_sequence_packet(me, NetPlayers.players[0].network.ipx.server, NetPlayers.players[0].network.ipx.node, NULL);
4080 me.player.network.appletalk.node = appletalk_get_my_node();
4081 me.player.network.appletalk.net = appletalk_get_my_net();
4082 me.player.network.appletalk.socket = appletalk_get_my_socket();
4086 Function_mode = FMODE_MENU;
4087 Game_mode = GM_GAME_OVER;
4088 return(-1); // they cancelled
4094 network_request_poll( int nitems, newmenu_item * menus, int * key, int citem )
4096 // Polling loop for waiting-for-requests menu
4106 // Send our endlevel packet at regular intervals
4108 // if (timer_get_approx_seconds() > t1+ENDLEVEL_SEND_INTERVAL)
4110 // network_send_endlevel_packet();
4111 // t1 = timer_get_approx_seconds();
4116 for (i = 0; i < N_players; i++)
4118 if ((Players[i].connected == 1) || (Players[i].connected == 0))
4122 if (num_ready == N_players) // All players have checked in or are disconnected
4129 network_wait_for_requests(void)
4131 // Wait for other players to load the level before we send the sync
4135 Network_status = NETSTAT_WAITING;
4137 m[0].type=NM_TYPE_TEXT; m[0].text = TXT_NET_LEAVE;
4139 mprintf((0, "Entered wait_for_requests : N_players = %d.\n", N_players));
4141 for (choice = 0; choice < N_players; choice++)
4142 mprintf((0, "Players[%d].connected = %d.\n", choice, Players[choice].connected));
4144 Network_status = NETSTAT_WAITING;
4147 Players[Player_num].connected = 1;
4150 choice = newmenu_do(NULL, TXT_WAIT, 1, m, network_request_poll);
4155 choice = nm_messagebox(NULL, 3, TXT_YES, TXT_NO, TXT_START_NOWAIT, TXT_QUITTING_NOW);
4161 // User confirmed abort
4163 for (i=0; i < N_players; i++) {
4164 if ((Players[i].connected != 0) && (i != Player_num)) {
4165 if (Network_game_type == IPX_GAME)
4166 network_dump_player(NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node, DUMP_ABORTED);
4169 network_dump_appletalk_player(NetPlayers.players[i].network.appletalk.node, NetPlayers.players[i].network.appletalk.net, NetPlayers.players[i].network.appletalk.socket, DUMP_ABORTED);
4175 if (Network_game_type == APPLETALK_GAME)
4176 network_release_registered_game();
4178 longjmp(LeaveGame, 0);
4180 else if (choice != -2)
4185 network_level_sync(void)
4187 // Do required syncing between (before) levels
4191 mprintf((0, "Player %d entering network_level_sync.\n", Player_num));
4193 MySyncPackInitialized = 0;
4195 // my_segments_checksum = netmisc_calc_checksum(Segments, sizeof(segment)*(Highest_segment_index+1));
4197 network_flush(); // Flush any old packets
4200 result = network_wait_for_sync();
4201 else if (network_i_am_master())
4203 network_wait_for_requests();
4204 network_send_sync();
4208 result = network_wait_for_sync();
4210 network_count_powerups_in_mine();
4214 Players[Player_num].connected = 0;
4215 network_send_endlevel_packet();
4217 if (Network_game_type == APPLETALK_GAME)
4218 network_release_registered_game();
4220 longjmp(LeaveGame, 0);
4225 void network_count_powerups_in_mine(void)
4229 for (i=0;i<MAX_POWERUP_TYPES;i++)
4230 PowerupsInMine[i]=0;
4232 for (i=0;i<=Highest_object_index;i++)
4234 if (Objects[i].type==OBJ_POWERUP)
4236 PowerupsInMine[Objects[i].id]++;
4237 if (multi_powerup_is_4pack(Objects[i].id))
4238 PowerupsInMine[Objects[i].id-1]+=4;
4246 // code to release the NBP binding of an appletalk game
4248 void network_release_registered_game()
4250 if (Network_game_type == APPLETALK_GAME)
4251 appletalk_remove_netgame();
4254 // code to sort zone lists....
4256 int zone_sort_func(const char **e0, const char **e1)
4258 return strcmp(*e0, *e1);
4261 void network_get_appletalk_zone()
4263 int num_zones, i, item, default_item;
4265 char default_zone[MAX_ZONE_LENGTH]; // my zone
4267 Network_zone_name[0] = '\0';
4269 show_boxed_message("Looking for AppleTalk Zones");
4270 num_zones = appletalk_get_zone_names(&zone_list);
4271 clear_boxed_message();
4273 if (num_zones < 0) { // error in getting zone list...maybe no router available....
4274 if ( (num_zones == tooManyReqs) || (num_zones == noDataArea) ){
4275 nm_messagebox(NULL, 1, TXT_OK, "AppleTalk Network is too busy.\nPlease try again shortly.");
4276 longjmp(LeaveGame,0);
4281 if (num_zones == 0) {
4282 strcpy(Network_zone_name, DEFAULT_ZONE_NAME);
4286 if (num_zones == 1) {
4287 Network_zone_name[0] = (char)(strlen(zone_list[0]));
4288 memcpy( &(Network_zone_name[1]), zone_list[0], strlen(zone_list[0]) );
4292 // sort the zone names
4294 for (i = 0; i < num_zones; i++)
4295 strlwr(zone_list[i]);
4297 qsort(zone_list, num_zones, sizeof(char *), zone_sort_func);
4299 // get my current zone so we can highlight that one first
4301 if (appletalk_get_my_zone(default_zone))
4304 for (i = 0; i < num_zones; i++) {
4305 if ( !stricmp(zone_list[i], default_zone) ) {
4313 item = newmenu_listbox1("AppleTalk Zones", num_zones, zone_list, 0, default_item, NULL);
4318 Network_zone_name[0] = (char)(strlen(zone_list[item]));
4319 memcpy( &(Network_zone_name[1]), zone_list[item], strlen(zone_list[item]) );
4322 for (i = 0; i < num_zones; i++)
4323 d_free(zone_list[i]);
4328 void nm_draw_background1(char * filename);
4330 void network_join_game()
4333 char menu_text[MAX_ACTIVE_NETGAMES+2][200];
4335 newmenu_item m[MAX_ACTIVE_NETGAMES+2];
4337 if (Network_game_type == IPX_GAME) {
4338 if ( !Network_active )
4340 nm_messagebox(NULL, 1, TXT_OK, TXT_IPX_NOT_FOUND);
4344 } else if (Appletalk_active <= 0) {
4347 switch (Appletalk_active) {
4348 case APPLETALK_NOT_OPEN:
4349 sprintf(buf, "Appletalk is not currently active.\nPlease enable AppleTalk from the\nChooser and restart Descent.");
4351 case APPLETALK_BAD_LISTENER:
4352 sprintf(buf, "The Resource Fork of Descent appears damaged.\nPlease re-install Descent or contact\nMacPlay technical support.");
4354 case APPLETALK_NO_LOCAL_ADDR:
4355 sprintf(buf, "Wow! Strange!\n\nNo Local Address.");
4357 case APPLETALK_NO_SOCKET:
4358 sprintf(buf, "All AppleTalk sockets are in use.\nTry shutting down other network\napplications and restarting Descent.\n");
4361 nm_messagebox(NULL, 1, TXT_OK, buf);
4373 if (Network_game_type == APPLETALK_GAME)
4374 network_get_appletalk_zone();
4377 Network_send_objects = 0;
4378 Network_sending_extras=0;
4381 Network_status = NETSTAT_BROWSING; // We are looking at a game menu
4384 network_listen(); // Throw out old info
4387 if (Network_game_type == IPX_GAME)
4388 #endif // note link to if
4389 network_send_game_list_request(); // broadcast a request for lists
4391 num_active_games = 0;
4393 memset(m, 0, sizeof(newmenu_item)*MAX_ACTIVE_NETGAMES);
4394 memset(Active_games, 0, sizeof(netgame_info)*MAX_ACTIVE_NETGAMES);
4395 memset(ActiveNetPlayers,0,sizeof(AllNetPlayers_info)*MAX_ACTIVE_NETGAMES);
4397 gr_set_fontcolor(BM_XRGB(15,15,23),-1);
4399 m[0].text = menu_text[0];
4400 m[0].type = NM_TYPE_TEXT;
4401 if (Network_game_type == IPX_GAME) {
4402 if (Network_allow_socket_changes)
4403 sprintf( m[0].text, "\tCurrent IPX Socket is default %+d (PgUp/PgDn to change)", Network_socket );
4405 sprintf( m[0].text, "" );
4408 p2cstr(Network_zone_name);
4409 if (strcmp(Network_zone_name, "*")) // only print if there is a zone name
4410 sprintf(m[0].text, "\tCurrent Zone is %s", Network_zone_name); // is Network_zone_name a pascal string????
4411 c2pstr(Network_zone_name);
4415 m[1].text=menu_text[1];
4416 m[1].type=NM_TYPE_TEXT;
4417 sprintf (m[1].text,"\tGAME \tMODE \t#PLYRS \tMISSION \tLEV \tSTATUS");
4419 for (i = 0; i < MAX_ACTIVE_NETGAMES; i++) {
4420 m[i+2].text = menu_text[i+2];
4421 m[i+2].type = NM_TYPE_MENU;
4422 sprintf(m[i+2].text, "%d. ", i+1);
4426 Network_games_changed = 1;
4429 nm_draw_background1(Menu_pcx_name); //load this here so if we abort after loading level, we restore the palette
4430 gr_palette_load(gr_palette);
4431 ExtGameStatus=GAMESTAT_JOIN_NETGAME;
4432 choice=newmenu_dotiny("NETGAMES", NULL,MAX_ACTIVE_NETGAMES+2, m, network_join_poll);
4436 Network_status = NETSTAT_MENU;
4437 return; // they cancelled
4441 if (choice >=num_active_games)
4443 nm_messagebox(TXT_SORRY, 1, TXT_OK, TXT_INVALID_CHOICE);
4447 // Choice has been made and looks legit
4448 if (Active_games[choice].game_status == NETSTAT_ENDLEVEL)
4450 nm_messagebox(TXT_SORRY, 1, TXT_OK, TXT_NET_GAME_BETWEEN2);
4454 if (Active_games[choice].protocol_version != MULTI_PROTO_VERSION)
4456 if (Active_games[choice].protocol_version == 3) {
4458 nm_messagebox(TXT_SORRY, 1, TXT_OK, "Your version of Descent 2\nis incompatible with the\nDemo version");
4461 else if (Active_games[choice].protocol_version == 4) {
4463 nm_messagebox(TXT_SORRY, 1, TXT_OK, "This Demo version of\nDescent 2 is incompatible\nwith the full commercial version");
4467 nm_messagebox(TXT_SORRY, 1, TXT_OK, TXT_VERSION_MISMATCH);
4474 // Check for valid mission name
4475 mprintf((0, "Loading mission:%s.\n", Active_games[choice].mission_name));
4476 if (!load_mission_by_name(Active_games[choice].mission_name))
4478 nm_messagebox(NULL, 1, TXT_OK, TXT_MISSION_NOT_FOUND);
4484 #if defined (D2_OEM)
4486 if (Active_games[choice].levelnum>8)
4488 nm_messagebox(NULL, 1, TXT_OK, "This OEM version only supports\nthe first 8 levels!");
4494 if (!network_wait_for_all_info (choice))
4496 nm_messagebox (TXT_SORRY,1,TXT_OK,"There was a join error!");
4497 Network_status = NETSTAT_BROWSING; // We are looking at a game menu
4501 Network_status = NETSTAT_BROWSING; // We are looking at a game menu
4503 if (!can_join_netgame(&Active_games[choice],&ActiveNetPlayers[choice]))
4505 if (Active_games[choice].numplayers == Active_games[choice].max_numplayers)
4506 nm_messagebox(TXT_SORRY, 1, TXT_OK, TXT_GAME_FULL);
4508 nm_messagebox(TXT_SORRY, 1, TXT_OK, TXT_IN_PROGRESS);
4512 // Choice is valid, prepare to join in
4514 memcpy(&Netgame, &Active_games[choice], sizeof(netgame_info));
4515 memcpy (&NetPlayers,&ActiveNetPlayers[choice],sizeof(AllNetPlayers_info));
4517 Difficulty_level = Netgame.difficulty;
4518 MaxNumNetPlayers = Netgame.max_numplayers;
4519 change_playernum_to(1);
4523 // register the joining player with NBP. This will have the nice effect of a player wanting to
4524 // join to be able to see the netgame if this player were to become the master.
4526 if (Network_game_type == APPLETALK_GAME) {
4531 show_boxed_message("Registering Netgame");
4533 err = appletalk_register_netgame( Active_games[choice].game_name, TickCount() );
4534 t1 = timer_get_fixed_seconds() + F1_0;
4535 while ( timer_get_fixed_seconds() < t1 ) ;
4537 } while ( (err == nbpDuplicate) && (count != MAX_REGISTER_TRIES) );
4538 clear_boxed_message();
4539 if ( (err == tooManyReqs) || (count == MAX_REGISTER_TRIES) ) {
4540 nm_messagebox(NULL, 1, TXT_OK, "AppleTalk Network is too busy.\nPlease try again shortly.");
4546 network_set_game_mode(Netgame.gamemode);
4548 network_AdjustMaxDataSize ();
4550 StartNewLevel(Netgame.levelnum, 0);
4552 return; // look ma, we're in a game!!!
4555 void network_AdjustMaxDataSize ()
4558 if (Netgame.ShortPackets)
4559 MaxXDataSize=NET_XDATA_SIZE;
4561 MaxXDataSize=NET_XDATA_SIZE;
4565 fix StartWaitAllTime=0;
4566 int WaitAllChoice=0;
4567 #define ALL_INFO_REQUEST_INTERVAL F1_0*3
4569 void network_wait_all_poll( int nitems, newmenu_item * menus, int * key, int citem )
4577 if (timer_get_approx_seconds() > t1+ALL_INFO_REQUEST_INTERVAL)
4579 network_send_all_info_request(PID_SEND_ALL_GAMEINFO,SecurityCheck);
4580 t1 = timer_get_approx_seconds();
4583 network_do_big_wait(WaitAllChoice);
4585 if(SecurityCheck==-1)
4589 int network_wait_for_all_info (int choice)
4595 m[0].type=NM_TYPE_TEXT; m[0].text = "Press Escape to cancel";
4597 WaitAllChoice=choice;
4598 StartWaitAllTime=timer_get_approx_seconds();
4599 SecurityCheck=Active_games[choice].Security;
4603 pick=newmenu_do( NULL, "Connecting...", 1, m, network_wait_all_poll );
4605 if (pick>-1 && SecurityCheck!=-1)
4608 if (SecurityCheck==-1)
4617 void network_do_big_wait(int choice)
4620 ubyte packet[IPX_MAX_DATA_SIZE],*data;
4621 AllNetPlayers_info *temp_info;
4623 AllNetPlayers_info info_struct;
4624 ubyte apacket[APPLETALK_MAX_DATA_SIZE];
4628 if (Network_game_type == APPLETALK_GAME)
4629 size=appletalk_get_packet_data( apacket );
4632 size=ipx_get_packet_data( packet );
4637 if (Network_game_type == APPLETALK_GAME)
4647 if (Network_game_type == IPX_GAME) {
4649 memcpy((ubyte *)&TempNetInfo, data, sizeof(netgame_info));
4651 receive_netgame_packet(data, &TempNetInfo, 0);
4654 memcpy((ubyte *)&TempNetInfo, data, sizeof(netgame_info));
4656 mprintf ((0,"This is %s game with a security of %d\n",TempNetInfo.game_name,TempNetInfo.Security));
4658 if (TempNetInfo.Security !=SecurityCheck)
4660 mprintf ((0,"Bad security on big_wait...rejecting.\n"));
4664 if (NetSecurityFlag==NETSECURITY_WAIT_FOR_GAMEINFO)
4666 if (TempPlayersInfo->Security==TempNetInfo.Security)
4668 mprintf ((0,"EQUAL !: Game=%d Players=%d ",TempPlayersInfo->Security,TempNetInfo.Security));
4669 if (TempPlayersInfo->Security==SecurityCheck)
4671 memcpy (&Active_games[choice],(ubyte *)&TempNetInfo,sizeof(netgame_info));
4672 memcpy (&ActiveNetPlayers[choice],TempPlayersInfo,sizeof(AllNetPlayers_info));
4679 NetSecurityFlag=NETSECURITY_WAIT_FOR_PLAYERS;
4680 NetSecurityNum=TempNetInfo.Security;
4682 if (network_wait_for_playerinfo())
4684 mprintf ((0,"HUH? Game=%d Player=%d\n",NetSecurityNum,TempPlayersInfo->Security));
4685 memcpy (&Active_games[choice],(ubyte *)&TempNetInfo,sizeof(netgame_info));
4686 memcpy (&ActiveNetPlayers[choice],TempPlayersInfo,sizeof(AllNetPlayers_info));
4693 case PID_PLAYERSINFO:
4694 mprintf ((0,"Got a PID_PLAYERSINFO!\n"));
4696 if (Network_game_type == IPX_GAME) {
4698 temp_info=(AllNetPlayers_info *)data;
4700 receive_netplayers_packet(data, &info_struct);
4701 temp_info = &info_struct;
4704 temp_info = (AllNetPlayers_info *)data;
4706 if (temp_info->Security!=SecurityCheck)
4707 break; // If this isn't the guy we're looking for, move on
4709 memcpy (&TempPlayersBase,(ubyte *)&temp_info,sizeof(AllNetPlayers_info));
4710 TempPlayersInfo=&TempPlayersBase;
4711 WaitingForPlayerInfo=0;
4712 NetSecurityNum=TempPlayersInfo->Security;
4713 NetSecurityFlag=NETSECURITY_WAIT_FOR_GAMEINFO;
4719 void network_leave_game()
4723 network_do_frame(1, 1);
4726 fclose (SendLogFile);
4727 fclose (RecieveLogFile);
4730 if ((network_i_am_master()))
4732 while (Network_sending_extras>1 && Player_joining_extras!=-1)
4733 network_send_extras();
4735 Netgame.numplayers = 0;
4738 network_send_game_info(NULL);
4741 mprintf ((0,"HEY! I'm master and I've left.\n"));
4744 Players[Player_num].connected = 0;
4745 network_send_endlevel_packet();
4746 change_playernum_to(0);
4747 Game_mode = GM_GAME_OVER;
4748 write_player_file();
4750 // WIN(ipx_destroy_read_thread());
4755 void network_flush()
4758 ubyte apacket[APPLETALK_MAX_DATA_SIZE];
4760 ubyte packet[IPX_MAX_DATA_SIZE];
4763 if ( (Network_game_type == APPLETALK_GAME) && (Appletalk_active <= 0) )
4767 if ( Network_game_type == IPX_GAME )
4768 if (!Network_active) return;
4771 if (Network_game_type == APPLETALK_GAME)
4772 while (appletalk_get_packet_data(apacket) > 0) ;
4775 while (ipx_get_packet_data(packet) > 0) ;
4778 void network_listen()
4781 ubyte apacket[APPLETALK_MAX_DATA_SIZE];
4784 ubyte packet[IPX_MAX_DATA_SIZE];
4787 if (Network_status==NETSTAT_PLAYING && Netgame.ShortPackets && !Network_send_objects)
4789 loopmax=N_players*Netgame.PacketsPerSec;
4793 if ( (Network_game_type == APPLETALK_GAME) && (Appletalk_active <= 0) )
4797 if (Network_game_type == IPX_GAME)
4798 if (!Network_active) return;
4800 if (!(Game_mode & GM_NETWORK) && (Function_mode == FMODE_GAME))
4801 mprintf((0, "Calling network_listen() when not in net game.\n"));
4803 WaitingForPlayerInfo=1;
4804 NetSecurityFlag=NETSECURITY_OFF;
4807 if (Network_game_type == IPX_GAME) {
4808 size = ipx_get_packet_data( packet );
4810 network_process_packet( packet, size );
4813 size = ipx_get_packet_data( packet );
4817 size = appletalk_get_packet_data( apacket );
4819 network_process_packet( apacket, size );
4822 size = appletalk_get_packet_data( apacket );
4828 int network_wait_for_playerinfo()
4831 ubyte packet[IPX_MAX_DATA_SIZE];
4832 struct AllNetPlayers_info *TempInfo;
4836 AllNetPlayers_info info_struct;
4837 ubyte apacket[APPLETALK_MAX_DATA_SIZE];
4841 if ( (Network_game_type == APPLETALK_GAME) && (Appletalk_active <= 0) )
4845 if ( Network_game_type == IPX_GAME)
4846 if (!Network_active) return(0);
4848 // if (!WaitingForPlayerInfo)
4851 if (!(Game_mode & GM_NETWORK) && (Function_mode == FMODE_GAME))
4853 mprintf((0, "Calling network_wait_for_playerinfo() when not in net game.\n"));
4855 if (Network_status==NETSTAT_PLAYING)
4857 Int3(); //MY GOD! Get Jason...this is the source of many problems
4860 basetime=timer_get_approx_seconds();
4862 while (WaitingForPlayerInfo && retries<50 && (timer_get_approx_seconds()<(basetime+(F1_0*5))))
4864 if (Network_game_type == IPX_GAME) {
4865 size = ipx_get_packet_data( packet );
4869 size = appletalk_get_packet_data( apacket );
4874 if (size>0 && id==PID_PLAYERSINFO)
4877 if (Network_game_type == APPLETALK_GAME) {
4878 TempInfo = (AllNetPlayers_info *)apacket;
4880 receive_netplayers_packet(packet, &info_struct);
4881 TempInfo = &info_struct;
4884 TempInfo=(AllNetPlayers_info *)packet;
4889 if (NetSecurityFlag==NETSECURITY_WAIT_FOR_PLAYERS)
4891 if (NetSecurityNum==TempInfo->Security)
4893 mprintf ((0,"HEYEQUAL: Player=%d Game=%d\n",TempInfo->Security,NetSecurityNum));
4894 memcpy (&TempPlayersBase,(ubyte *)TempInfo,sizeof(AllNetPlayers_info));
4895 TempPlayersInfo=&TempPlayersBase;
4896 NetSecurityFlag=NETSECURITY_OFF;
4898 WaitingForPlayerInfo=0;
4906 mprintf ((0,"I'm original!\n"));
4908 NetSecurityNum=TempInfo->Security;
4909 NetSecurityFlag=NETSECURITY_WAIT_FOR_GAMEINFO;
4911 memcpy (&TempPlayersBase,(ubyte *)TempInfo,sizeof(AllNetPlayers_info));
4912 TempPlayersInfo=&TempPlayersBase;
4913 WaitingForPlayerInfo=0;
4922 void network_send_data( ubyte * ptr, int len, int urgent )
4928 fprintf (SendLogFile,"Packet type: %d Len:%d Urgent:%d TT=%d\n",ptr[0],len,urgent,TTSent[ptr[0]]);
4929 fflush (SendLogFile);
4932 if (Endlevel_sequence)
4935 if (!MySyncPackInitialized) {
4936 MySyncPackInitialized = 1;
4937 memset( &MySyncPack, 0, sizeof(frame_info) );
4943 if ((MySyncPack.data_size+len) > MaxXDataSize ) {
4945 network_do_frame(1, 0);
4946 if (MySyncPack.data_size != 0) {
4947 mprintf((0, "%d bytes were added to data by network_do_frame!\n", MySyncPack.data_size));
4950 // Int3(); // Trying to send too much!
4952 mprintf((0, "Packet overflow, sending additional packet, type %d len %d.\n", ptr[0], len));
4953 Assert(check == ptr[0]);
4956 Assert(MySyncPack.data_size+len <= MaxXDataSize);
4958 memcpy( &MySyncPack.data[MySyncPack.data_size], ptr, len );
4959 MySyncPack.data_size += len;
4962 void network_timeout_player(int playernum)
4964 // Remove a player from the game if we haven't heard from them in
4968 Assert(playernum < N_players);
4969 Assert(playernum > -1);
4971 network_disconnect_player(playernum);
4972 create_player_appearance_effect(&Objects[Players[playernum].objnum]);
4974 digi_play_sample(SOUND_HUD_MESSAGE, F1_0);
4976 HUD_init_message("%s %s", Players[playernum].callsign, TXT_DISCONNECTING);
4977 for (i = 0; i < N_players; i++)
4978 if (Players[i].connected)
4983 nm_messagebox(NULL, 1, TXT_OK, TXT_YOU_ARE_ONLY);
4987 fix last_send_time = 0;
4988 fix last_timeout_check = 0;
4991 void squish_short_frame_info(short_frame_info old_info, ubyte *data)
4997 data[0] = old_info.type; loc++; loc += 3; // skip three for pad byte
4998 tmpi = swapint(old_info.numpackets);
4999 memcpy(&(data[loc]), &tmpi, 4); loc += 4;
5001 memcpy(&(data[loc]), old_info.thepos.bytemat, 9); loc += 9;
5002 tmps = INTEL_SHORT(old_info.thepos.xo);
5003 memcpy(&(data[loc]), &tmps, 2); loc += 2;
5004 tmps = INTEL_SHORT(old_info.thepos.yo);
5005 memcpy(&(data[loc]), &tmps, 2); loc += 2;
5006 tmps = INTEL_SHORT(old_info.thepos.zo);
5007 memcpy(&(data[loc]), &tmps, 2); loc += 2;
5008 tmps = INTEL_SHORT(old_info.thepos.segment);
5009 memcpy(&(data[loc]), &tmps, 2); loc += 2;
5010 tmps = INTEL_SHORT(old_info.thepos.velx);
5011 memcpy(&(data[loc]), &tmps, 2); loc += 2;
5012 tmps = INTEL_SHORT(old_info.thepos.vely);
5013 memcpy(&(data[loc]), &tmps, 2); loc += 2;
5014 tmps = INTEL_SHORT(old_info.thepos.velz);
5015 memcpy(&(data[loc]), &tmps, 2); loc += 2;
5017 tmps = swapshort(old_info.data_size);
5018 memcpy(&(data[loc]), &tmps, 2); loc += 2;
5020 data[loc] = old_info.playernum; loc++;
5021 data[loc] = old_info.obj_render_type; loc++;
5022 data[loc] = old_info.level_num; loc++;
5023 memcpy(&(data[loc]), old_info.data, old_info.data_size);
5027 char NakedBuf[NET_XDATA_SIZE+4];
5028 int NakedPacketLen=0;
5029 int NakedPacketDestPlayer=-1;
5031 void network_do_frame(int force, int listen)
5034 short_frame_info ShortSyncPack;
5035 static fix LastEndlevel=0;
5037 if (!(Game_mode&GM_NETWORK)) return;
5039 if ((Network_status != NETSTAT_PLAYING) || (Endlevel_sequence)) // Don't send postion during escape sequence...
5044 Assert (NakedPacketDestPlayer>-1);
5045 // mprintf ((0,"Sending a naked packet to %s (%d bytes)!\n",Players[NakedPacketDestPlayer].callsign,NakedPacketLen));
5046 if (Network_game_type == IPX_GAME)
5047 ipx_send_packet_data( (ubyte *)NakedBuf, NakedPacketLen, NetPlayers.players[NakedPacketDestPlayer].network.ipx.server, NetPlayers.players[NakedPacketDestPlayer].network.ipx.node,Players[NakedPacketDestPlayer].net_address );
5050 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 );
5053 NakedPacketDestPlayer=-1;
5056 if (WaitForRefuseAnswer && timer_get_approx_seconds()>(RefuseTimeLimit+(F1_0*12)))
5057 WaitForRefuseAnswer=0;
5059 last_send_time += FrameTime;
5060 last_timeout_check += FrameTime;
5062 // Send out packet PacksPerSec times per second maximum... unless they fire, then send more often...
5063 if ( (last_send_time>F1_0/Netgame.PacketsPerSec) || (Network_laser_fired) || force || PacketUrgent ) {
5064 if ( Players[Player_num].connected ) {
5065 int objnum = Players[Player_num].objnum;
5069 multi_send_robot_frame(0);
5070 multi_send_fire(); // Do firing if needed..
5075 if (Netgame.ShortPackets)
5078 ubyte send_data[IPX_MAX_DATA_SIZE];
5081 create_shortpos(&ShortSyncPack.thepos, Objects+objnum, 0);
5082 ShortSyncPack.type = PID_PDATA;
5083 ShortSyncPack.playernum = Player_num;
5084 ShortSyncPack.obj_render_type = Objects[objnum].render_type;
5085 ShortSyncPack.level_num = Current_level_num;
5086 ShortSyncPack.data_size = MySyncPack.data_size;
5087 memcpy (&ShortSyncPack.data[0],&MySyncPack.data[0],MySyncPack.data_size);
5089 for (i=0; i<N_players; i++ ) {
5090 if ( (Players[i].connected) && (i!=Player_num ) ) {
5091 MySyncPack.numpackets = Players[i].n_packets_sent++;
5092 ShortSyncPack.numpackets=MySyncPack.numpackets;
5093 if (Network_game_type == IPX_GAME) {
5095 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 );
5097 squish_short_frame_info(ShortSyncPack, send_data);
5098 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 );
5102 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 );
5108 else // If long packets
5112 MySyncPack.type = PID_PDATA;
5113 MySyncPack.playernum = Player_num;
5114 MySyncPack.obj_render_type = Objects[objnum].render_type;
5115 MySyncPack.level_num = Current_level_num;
5116 MySyncPack.obj_segnum = Objects[objnum].segnum;
5117 MySyncPack.obj_pos = Objects[objnum].pos;
5118 MySyncPack.obj_orient = Objects[objnum].orient;
5119 MySyncPack.phys_velocity = Objects[objnum].mtype.phys_info.velocity;
5120 MySyncPack.phys_rotvel = Objects[objnum].mtype.phys_info.rotvel;
5122 send_data_size = MySyncPack.data_size; // do this so correct size data is sent
5124 #ifdef MACINTOSH // do the swap stuff
5125 if (Network_game_type == IPX_GAME) {
5126 MySyncPack.obj_segnum = INTEL_SHORT(MySyncPack.obj_segnum);
5127 MySyncPack.obj_pos.x = INTEL_INT((int)MySyncPack.obj_pos.x);
5128 MySyncPack.obj_pos.y = INTEL_INT((int)MySyncPack.obj_pos.y);
5129 MySyncPack.obj_pos.z = INTEL_INT((int)MySyncPack.obj_pos.z);
5131 MySyncPack.obj_orient.rvec.x = INTEL_INT((int)MySyncPack.obj_orient.rvec.x);
5132 MySyncPack.obj_orient.rvec.y = INTEL_INT((int)MySyncPack.obj_orient.rvec.y);
5133 MySyncPack.obj_orient.rvec.z = INTEL_INT((int)MySyncPack.obj_orient.rvec.z);
5134 MySyncPack.obj_orient.uvec.x = INTEL_INT((int)MySyncPack.obj_orient.uvec.x);
5135 MySyncPack.obj_orient.uvec.y = INTEL_INT((int)MySyncPack.obj_orient.uvec.y);
5136 MySyncPack.obj_orient.uvec.z = INTEL_INT((int)MySyncPack.obj_orient.uvec.z);
5137 MySyncPack.obj_orient.fvec.x = INTEL_INT((int)MySyncPack.obj_orient.fvec.x);
5138 MySyncPack.obj_orient.fvec.y = INTEL_INT((int)MySyncPack.obj_orient.fvec.y);
5139 MySyncPack.obj_orient.fvec.z = INTEL_INT((int)MySyncPack.obj_orient.fvec.z);
5141 MySyncPack.phys_velocity.x = INTEL_INT((int)MySyncPack.phys_velocity.x);
5142 MySyncPack.phys_velocity.y = INTEL_INT((int)MySyncPack.phys_velocity.y);
5143 MySyncPack.phys_velocity.z = INTEL_INT((int)MySyncPack.phys_velocity.z);
5145 MySyncPack.phys_rotvel.x = INTEL_INT((int)MySyncPack.phys_rotvel.x);
5146 MySyncPack.phys_rotvel.y = INTEL_INT((int)MySyncPack.phys_rotvel.y);
5147 MySyncPack.phys_rotvel.z = INTEL_INT((int)MySyncPack.phys_rotvel.z);
5149 MySyncPack.data_size = INTEL_SHORT(MySyncPack.data_size);
5153 for (i=0; i<N_players; i++ ) {
5154 if ( (Players[i].connected) && (i!=Player_num ) ) {
5155 if (Network_game_type == IPX_GAME)
5156 MySyncPack.numpackets = INTEL_INT(Players[i].n_packets_sent);
5159 MySyncPack.numpackets = Players[i].n_packets_sent;
5162 Players[i].n_packets_sent++;
5163 if (Network_game_type == IPX_GAME)
5164 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 );
5167 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);
5173 MySyncPack.data_size = 0; // Start data over at 0 length.
5174 if (Control_center_destroyed)
5177 Players[Player_num].connected=3;
5178 if (timer_get_approx_seconds() > (LastEndlevel+(F1_0/2)))
5180 network_send_endlevel_packet();
5181 LastEndlevel=timer_get_approx_seconds();
5184 //mprintf( (0, "Packet has %d bytes appended (TS=%d)\n", MySyncPack.data_size, sizeof(frame_info)-MaxXDataSize+MySyncPack.data_size ));
5191 if ((last_timeout_check > F1_0) && !(Control_center_destroyed))
5193 fix approx_time = timer_get_approx_seconds();
5194 // Check for player timeouts
5195 for (i = 0; i < N_players; i++)
5197 if ((i != Player_num) && (Players[i].connected == 1))
5199 if ((LastPacketTime[i] == 0) || (LastPacketTime[i] > approx_time))
5201 LastPacketTime[i] = approx_time;
5204 if ((approx_time - LastPacketTime[i]) > (15*F1_0))
5205 network_timeout_player(i);
5208 last_timeout_check = 0;
5214 MySyncPack.data_size = 0;
5219 if (VerifyPlayerJoined!=-1 && !(FrameCount & 63))
5220 resend_sync_due_to_packet_loss_for_allender(); // This will resend to network_player_rejoining
5222 if (Network_send_objects)
5223 network_send_objects();
5225 if (Network_sending_extras && VerifyPlayerJoined==-1)
5227 network_send_extras();
5232 int missed_packets = 0;
5234 int ConsistencyCount = 0;
5236 void network_consistency_error(void)
5238 if (++ConsistencyCount < 10)
5241 Function_mode = FMODE_MENU;
5243 nm_messagebox(NULL, 1, TXT_OK, TXT_CONSISTENCY_ERROR);
5245 nm_messagebox(NULL, 1, TXT_OK, "Failed to join the netgame.\nYou are missing packets. Check\nyour network connection and\ntry again.");
5247 Function_mode = FMODE_GAME;
5248 ConsistencyCount = 0;
5249 multi_quit_game = 1;
5250 multi_leave_menu = 1;
5251 multi_reset_stuff();
5252 Function_mode = FMODE_MENU;
5255 void network_process_pdata (char *data)
5257 Assert (Game_mode & GM_NETWORK);
5259 if (Netgame.ShortPackets)
5260 network_read_pdata_short_packet ((short_frame_info *)data);
5262 network_read_pdata_packet ((frame_info *)data);
5265 void network_read_pdata_packet(frame_info *pd )
5269 object * TheirObj = NULL;
5271 // frame_info should be aligned...for mac, make the necessary adjustments
5273 if (Network_game_type == IPX_GAME) {
5274 pd->numpackets = INTEL_INT(pd->numpackets);
5275 pd->obj_pos.x = INTEL_INT(pd->obj_pos.x);
5276 pd->obj_pos.y = INTEL_INT(pd->obj_pos.y);
5277 pd->obj_pos.z = INTEL_INT(pd->obj_pos.z);
5279 pd->obj_orient.rvec.x = (fix)INTEL_INT((int)pd->obj_orient.rvec.x);
5280 pd->obj_orient.rvec.y = (fix)INTEL_INT((int)pd->obj_orient.rvec.y);
5281 pd->obj_orient.rvec.z = (fix)INTEL_INT((int)pd->obj_orient.rvec.z);
5282 pd->obj_orient.uvec.x = (fix)INTEL_INT((int)pd->obj_orient.uvec.x);
5283 pd->obj_orient.uvec.y = (fix)INTEL_INT((int)pd->obj_orient.uvec.y);
5284 pd->obj_orient.uvec.z = (fix)INTEL_INT((int)pd->obj_orient.uvec.z);
5285 pd->obj_orient.fvec.x = (fix)INTEL_INT((int)pd->obj_orient.fvec.x);
5286 pd->obj_orient.fvec.y = (fix)INTEL_INT((int)pd->obj_orient.fvec.y);
5287 pd->obj_orient.fvec.z = (fix)INTEL_INT((int)pd->obj_orient.fvec.z);
5289 pd->phys_velocity.x = (fix)INTEL_INT((int)pd->phys_velocity.x);
5290 pd->phys_velocity.y = (fix)INTEL_INT((int)pd->phys_velocity.y);
5291 pd->phys_velocity.z = (fix)INTEL_INT((int)pd->phys_velocity.z);
5293 pd->phys_rotvel.x = (fix)INTEL_INT((int)pd->phys_rotvel.x);
5294 pd->phys_rotvel.y = (fix)INTEL_INT((int)pd->phys_rotvel.y);
5295 pd->phys_rotvel.z = (fix)INTEL_INT((int)pd->phys_rotvel.z);
5297 pd->obj_segnum = INTEL_SHORT(pd->obj_segnum);
5298 pd->data_size = INTEL_SHORT(pd->data_size);
5302 TheirPlayernum = pd->playernum;
5303 TheirObjnum = Players[pd->playernum].objnum;
5305 if (TheirPlayernum < 0) {
5306 Int3(); // This packet is bogus!!
5310 if (VerifyPlayerJoined!=-1 && TheirPlayernum==VerifyPlayerJoined)
5312 // Hurray! Someone really really got in the game (I think).
5313 mprintf ((0,"Hurray! VPJ (%d) reset!\n",VerifyPlayerJoined));
5314 VerifyPlayerJoined=-1;
5317 if (!multi_quit_game && (TheirPlayernum >= N_players)) {
5318 if (Network_status!=NETSTAT_WAITING)
5320 Int3(); // We missed an important packet!
5321 network_consistency_error();
5327 if (Endlevel_sequence || (Network_status == NETSTAT_ENDLEVEL) ) {
5328 int old_Endlevel_sequence = Endlevel_sequence;
5329 Endlevel_sequence = 1;
5330 if ( pd->data_size>0 ) {
5331 // pass pd->data to some parser function....
5332 multi_process_bigdata( pd->data, pd->data_size );
5334 Endlevel_sequence = old_Endlevel_sequence;
5337 // mprintf((0, "Gametime = %d, Frametime = %d.\n", GameTime, FrameTime));
5339 if ((byte)pd->level_num != Current_level_num)
5341 mprintf((0, "Got frame packet from player %d wrong level %d!\n", pd->playernum, pd->level_num));
5345 TheirObj = &Objects[TheirObjnum];
5347 //------------- Keep track of missed packets -----------------
5348 Players[TheirPlayernum].n_packets_got++;
5350 LastPacketTime[TheirPlayernum] = timer_get_approx_seconds();
5352 if ( pd->numpackets != Players[TheirPlayernum].n_packets_got ) {
5355 missed_packets = pd->numpackets-Players[TheirPlayernum].n_packets_got;
5356 if ((pd->numpackets-Players[TheirPlayernum].n_packets_got)>0)
5357 TotalMissedPackets += pd->numpackets-Players[TheirPlayernum].n_packets_got;
5359 if ( missed_packets > 0 )
5360 mprintf(( 0, "Missed %d packets from player #%d (%d total)\n", pd->numpackets-Players[TheirPlayernum].n_packets_got, TheirPlayernum, missed_packets ));
5362 mprintf( (0, "Got %d late packets from player #%d (%d total)\n", Players[TheirPlayernum].n_packets_got-pd->numpackets, TheirPlayernum, missed_packets ));
5365 #ifdef APPLETALK_DEBUG
5366 if (Network_game_type == APPLETALK_GAME) {
5367 if ( missed_packets > 0 )
5368 fprintf( at_fp, "Missed %d packets from player #%d (%d total)\n", pd->numpackets-Players[TheirPlayernum].n_packets_got, TheirPlayernum, missed_packets );
5370 fprintf( at_fp, "Got %d late packets from player #%d (%d total)\n", Players[TheirPlayernum].n_packets_got-pd->numpackets, TheirPlayernum, missed_packets );
5375 if (Network_game_type == IPX_GAME) {
5376 if ( missed_packets > 0 )
5377 fprintf( ipx_fp, "Missed %d packets from player #%d (%d total)\n", pd->numpackets-Players[TheirPlayernum].n_packets_got, TheirPlayernum, missed_packets );
5379 fprintf( ipx_fp, "Got %d late packets from player #%d (%d total)\n", Players[TheirPlayernum].n_packets_got-pd->numpackets, TheirPlayernum, missed_packets );
5384 Players[TheirPlayernum].n_packets_got = pd->numpackets;
5387 //------------ Read the player's ship's object info ----------------------
5388 TheirObj->pos = pd->obj_pos;
5389 TheirObj->orient = pd->obj_orient;
5390 TheirObj->mtype.phys_info.velocity = pd->phys_velocity;
5391 TheirObj->mtype.phys_info.rotvel = pd->phys_rotvel;
5393 if ((TheirObj->render_type != pd->obj_render_type) && (pd->obj_render_type == RT_POLYOBJ))
5394 multi_make_ghost_player(TheirPlayernum);
5396 obj_relink(TheirObjnum,pd->obj_segnum);
5398 if (TheirObj->movement_type == MT_PHYSICS)
5399 set_thrust_from_velocity(TheirObj);
5401 //------------ Welcome them back if reconnecting --------------
5402 if (!Players[TheirPlayernum].connected) {
5403 Players[TheirPlayernum].connected = 1;
5405 if (Newdemo_state == ND_STATE_RECORDING)
5406 newdemo_record_multi_reconnect(TheirPlayernum);
5408 multi_make_ghost_player(TheirPlayernum);
5410 create_player_appearance_effect(&Objects[TheirObjnum]);
5412 digi_play_sample( SOUND_HUD_MESSAGE, F1_0);
5414 ClipRank (&NetPlayers.players[TheirPlayernum].rank);
5416 if (args_find("-norankings"))
5417 HUD_init_message( "'%s' %s", Players[TheirPlayernum].callsign, TXT_REJOIN );
5419 HUD_init_message( "%s'%s' %s", RankStrings[NetPlayers.players[TheirPlayernum].rank],Players[TheirPlayernum].callsign, TXT_REJOIN );
5425 //------------ Parse the extra data at the end ---------------
5427 if ( pd->data_size>0 ) {
5428 // pass pd->data to some parser function....
5429 multi_process_bigdata( pd->data, pd->data_size );
5435 void get_short_frame_info(ubyte *old_info, short_frame_info *new_info)
5439 new_info->type = old_info[loc]; loc++; loc += 3; // skip three for pad byte
5440 memcpy(&(new_info->numpackets), &(old_info[loc]), 4); loc += 4;
5441 new_info->numpackets = INTEL_INT(new_info->numpackets);
5442 memcpy(new_info->thepos.bytemat, &(old_info[loc]), 9); loc += 9;
5443 memcpy(&(new_info->thepos.xo), &(old_info[loc]), 2); loc += 2;
5444 memcpy(&(new_info->thepos.yo), &(old_info[loc]), 2); loc += 2;
5445 memcpy(&(new_info->thepos.zo), &(old_info[loc]), 2); loc += 2;
5446 memcpy(&(new_info->thepos.segment), &(old_info[loc]), 2); loc += 2;
5447 memcpy(&(new_info->thepos.velx), &(old_info[loc]), 2); loc += 2;
5448 memcpy(&(new_info->thepos.vely), &(old_info[loc]), 2); loc += 2;
5449 memcpy(&(new_info->thepos.velz), &(old_info[loc]), 2); loc += 2;
5450 new_info->thepos.xo = INTEL_SHORT(new_info->thepos.xo);
5451 new_info->thepos.yo = INTEL_SHORT(new_info->thepos.yo);
5452 new_info->thepos.zo = INTEL_SHORT(new_info->thepos.zo);
5453 new_info->thepos.segment = INTEL_SHORT(new_info->thepos.segment);
5454 new_info->thepos.velx = INTEL_SHORT(new_info->thepos.velx);
5455 new_info->thepos.vely = INTEL_SHORT(new_info->thepos.vely);
5456 new_info->thepos.velz = INTEL_SHORT(new_info->thepos.velz);
5458 memcpy(&(new_info->data_size), &(old_info[loc]), 2); loc += 2;
5459 new_info->data_size = INTEL_SHORT(new_info->data_size);
5460 new_info->playernum = old_info[loc]; loc++;
5461 new_info->obj_render_type = old_info[loc]; loc++;
5462 new_info->level_num = old_info[loc]; loc++;
5463 memcpy(new_info->data, &(old_info[loc]), new_info->data_size);
5467 void network_read_pdata_short_packet(short_frame_info *pd )
5471 object * TheirObj = NULL;
5472 short_frame_info new_pd;
5474 // short frame info is not aligned because of shortpos. The mac
5475 // will call totally hacked and gross function to fix this up.
5477 if (Network_game_type == IPX_GAME) {
5479 memcpy(&new_pd, (ubyte *)pd, sizeof(short_frame_info));
5481 get_short_frame_info((ubyte *)pd, &new_pd);
5484 memcpy(&new_pd, (ubyte *)pd, sizeof(short_frame_info));
5487 TheirPlayernum = new_pd.playernum;
5488 TheirObjnum = Players[new_pd.playernum].objnum;
5490 if (TheirPlayernum < 0) {
5491 Int3(); // This packet is bogus!!
5494 if (!multi_quit_game && (TheirPlayernum >= N_players)) {
5495 if (Network_status!=NETSTAT_WAITING)
5497 Int3(); // We missed an important packet!
5498 network_consistency_error();
5505 if (VerifyPlayerJoined!=-1 && TheirPlayernum==VerifyPlayerJoined)
5507 // Hurray! Someone really really got in the game (I think).
5508 mprintf ((0,"Hurray! VPJ (%d) reset!\n",VerifyPlayerJoined));
5509 VerifyPlayerJoined=-1;
5512 if (Endlevel_sequence || (Network_status == NETSTAT_ENDLEVEL) ) {
5513 int old_Endlevel_sequence = Endlevel_sequence;
5514 Endlevel_sequence = 1;
5515 if ( new_pd.data_size>0 ) {
5516 // pass pd->data to some parser function....
5517 multi_process_bigdata( new_pd.data, new_pd.data_size );
5519 Endlevel_sequence = old_Endlevel_sequence;
5522 // mprintf((0, "Gametime = %d, Frametime = %d.\n", GameTime, FrameTime));
5524 if ((byte)new_pd.level_num != Current_level_num)
5526 mprintf((0, "Got frame packet from player %d wrong level %d!\n", new_pd.playernum, new_pd.level_num));
5530 TheirObj = &Objects[TheirObjnum];
5532 //------------- Keep track of missed packets -----------------
5533 Players[TheirPlayernum].n_packets_got++;
5535 LastPacketTime[TheirPlayernum] = timer_get_approx_seconds();
5537 if ( new_pd.numpackets != Players[TheirPlayernum].n_packets_got ) {
5540 missed_packets = new_pd.numpackets-Players[TheirPlayernum].n_packets_got;
5541 if ((new_pd.numpackets-Players[TheirPlayernum].n_packets_got)>0)
5542 TotalMissedPackets += new_pd.numpackets-Players[TheirPlayernum].n_packets_got;
5544 if ( missed_packets > 0 )
5545 mprintf( (0, "Missed %d packets from player #%d (%d total)\n", new_pd.numpackets-Players[TheirPlayernum].n_packets_got, TheirPlayernum, missed_packets ));
5547 mprintf( (0, "Got %d late packets from player #%d (%d total)\n", Players[TheirPlayernum].n_packets_got-new_pd.numpackets, TheirPlayernum, missed_packets ));
5549 Players[TheirPlayernum].n_packets_got = new_pd.numpackets;
5552 //------------ Read the player's ship's object info ----------------------
5554 extract_shortpos(TheirObj, &new_pd.thepos, 0);
5556 if ((TheirObj->render_type != new_pd.obj_render_type) && (new_pd.obj_render_type == RT_POLYOBJ))
5557 multi_make_ghost_player(TheirPlayernum);
5559 if (TheirObj->movement_type == MT_PHYSICS)
5560 set_thrust_from_velocity(TheirObj);
5562 //------------ Welcome them back if reconnecting --------------
5563 if (!Players[TheirPlayernum].connected) {
5564 Players[TheirPlayernum].connected = 1;
5566 if (Newdemo_state == ND_STATE_RECORDING)
5567 newdemo_record_multi_reconnect(TheirPlayernum);
5569 multi_make_ghost_player(TheirPlayernum);
5571 create_player_appearance_effect(&Objects[TheirObjnum]);
5573 digi_play_sample( SOUND_HUD_MESSAGE, F1_0);
5574 ClipRank (&NetPlayers.players[TheirPlayernum].rank);
5576 if (args_find("-norankings"))
5577 HUD_init_message( "'%s' %s", Players[TheirPlayernum].callsign, TXT_REJOIN );
5579 HUD_init_message( "%s'%s' %s", RankStrings[NetPlayers.players[TheirPlayernum].rank],Players[TheirPlayernum].callsign, TXT_REJOIN );
5585 //------------ Parse the extra data at the end ---------------
5587 if ( new_pd.data_size>0 ) {
5588 // pass pd->data to some parser function....
5589 multi_process_bigdata( new_pd.data, new_pd.data_size );
5595 void network_set_power (void)
5597 int opt=0,choice,opt_primary,opt_second,opt_power;
5601 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Laser upgrade"; m[opt].value=Netgame.DoLaserUpgrade; opt++;
5602 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Super lasers"; m[opt].value=Netgame.DoSuperLaser; opt++;
5603 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Quad Lasers"; m[opt].value=Netgame.DoQuadLasers; opt++;
5604 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Vulcan cannon"; m[opt].value=Netgame.DoVulcan; opt++;
5605 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Spreadfire cannon"; m[opt].value=Netgame.DoSpread; opt++;
5606 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Plasma cannon"; m[opt].value=Netgame.DoPlasma; opt++;
5607 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Fusion cannon"; m[opt].value=Netgame.DoFusions; opt++;
5608 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Gauss cannon"; m[opt].value=Netgame.DoGauss; opt++;
5609 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Helix cannon"; m[opt].value=Netgame.DoHelix; opt++;
5610 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Phoenix cannon"; m[opt].value=Netgame.DoPhoenix; opt++;
5611 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Omega cannon"; m[opt].value=Netgame.DoOmega; opt++;
5614 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Homing Missiles"; m[opt].value=Netgame.DoHoming; opt++;
5615 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Proximity Bombs"; m[opt].value=Netgame.DoProximity; opt++;
5616 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Smart Missiles"; m[opt].value=Netgame.DoSmarts; opt++;
5617 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Mega Missiles"; m[opt].value=Netgame.DoMegas; opt++;
5618 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Flash Missiles"; m[opt].value=Netgame.DoFlash; opt++;
5619 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Guided Missiles"; m[opt].value=Netgame.DoGuided; opt++;
5620 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Smart Mines"; m[opt].value=Netgame.DoSmartMine; opt++;
5621 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Mercury Missiles"; m[opt].value=Netgame.DoMercury; opt++;
5622 m[opt].type = NM_TYPE_CHECK; m[opt].text = "EarthShaker Missiles"; m[opt].value=Netgame.DoEarthShaker; opt++;
5625 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Invulnerability"; m[opt].value=Netgame.DoInvulnerability; opt++;
5626 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Cloaking"; m[opt].value=Netgame.DoCloak; opt++;
5627 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Afterburners"; m[opt].value=Netgame.DoAfterburner; opt++;
5628 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Ammo rack"; m[opt].value=Netgame.DoAmmoRack; opt++;
5629 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Energy Converter"; m[opt].value=Netgame.DoConverter; opt++;
5630 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Headlight"; m[opt].value=Netgame.DoHeadlight; opt++;
5632 choice = newmenu_do(NULL, "Objects to allow", opt, m, NULL);
5634 Netgame.DoLaserUpgrade=m[opt_primary].value;
5635 Netgame.DoSuperLaser=m[opt_primary+1].value;
5636 Netgame.DoQuadLasers=m[opt_primary+2].value;
5637 Netgame.DoVulcan=m[opt_primary+3].value;
5638 Netgame.DoSpread=m[opt_primary+4].value;
5639 Netgame.DoPlasma=m[opt_primary+5].value;
5640 Netgame.DoFusions=m[opt_primary+6].value;
5641 Netgame.DoGauss=m[opt_primary+7].value;
5642 Netgame.DoHelix=m[opt_primary+8].value;
5643 Netgame.DoPhoenix=m[opt_primary+9].value;
5644 Netgame.DoOmega=m[opt_primary+10].value;
5646 Netgame.DoHoming=m[opt_second].value;
5647 Netgame.DoProximity=m[opt_second+1].value;
5648 Netgame.DoSmarts=m[opt_second+2].value;
5649 Netgame.DoMegas=m[opt_second+3].value;
5650 Netgame.DoFlash=m[opt_second+4].value;
5651 Netgame.DoGuided=m[opt_second+5].value;
5652 Netgame.DoSmartMine=m[opt_second+6].value;
5653 Netgame.DoMercury=m[opt_second+7].value;
5654 Netgame.DoEarthShaker=m[opt_second+8].value;
5656 Netgame.DoInvulnerability=m[opt_power].value;
5657 Netgame.DoCloak=m[opt_power+1].value;
5658 Netgame.DoAfterburner=m[opt_power+2].value;
5659 Netgame.DoAmmoRack=m[opt_power+3].value;
5660 Netgame.DoConverter=m[opt_power+4].value;
5661 Netgame.DoHeadlight=m[opt_power+5].value;
5665 void SetAllAllowablesTo (int on)
5667 last_cinvul = control_invul_time = 0; //default to zero
5669 Netgame.DoMegas=Netgame.DoSmarts=Netgame.DoFusions=Netgame.DoHelix=\
5670 Netgame.DoPhoenix=Netgame.DoCloak=Netgame.DoInvulnerability=\
5671 Netgame.DoAfterburner=Netgame.DoGauss=Netgame.DoVulcan=Netgame.DoPlasma=on;
5673 Netgame.DoOmega=Netgame.DoSuperLaser=Netgame.DoProximity=\
5674 Netgame.DoSpread=Netgame.DoMercury=Netgame.DoSmartMine=Netgame.DoFlash=\
5675 Netgame.DoGuided=Netgame.DoEarthShaker=on;
5677 Netgame.DoConverter=Netgame.DoAmmoRack=Netgame.DoHeadlight=on;
5678 Netgame.DoHoming=Netgame.DoLaserUpgrade=Netgame.DoQuadLasers=on;
5679 Netgame.BrightPlayers=Netgame.invul=on;
5685 // Jeez -- mac compiler can't handle all of these on the same decl line.
5686 int opt_setpower,opt_playtime,opt_killgoal,opt_socket,opt_marker_view,opt_light,opt_show_on_map;
5687 int opt_difficulty,opt_packets,opt_short_packets, opt_bright,opt_start_invul;
5690 void network_more_options_poll( int nitems, newmenu_item * menus, int * key, int citem );
5692 void network_more_game_options ()
5695 char PlayText[80],KillText[80],srinvul[50],socket_string[5],packstring[5];
5698 sprintf (socket_string,"%d",Network_socket);
5699 sprintf (packstring,"%d",Netgame.PacketsPerSec);
5701 opt_difficulty = opt;
5702 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++;
5705 sprintf( srinvul, "%s: %d %s", TXT_REACTOR_LIFE, control_invul_time*5, TXT_MINUTES_ABBREV );
5706 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++;
5709 sprintf( PlayText, "Max time: %d %s", Netgame.PlayTimeAllowed*5, TXT_MINUTES_ABBREV );
5710 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++;
5713 sprintf( KillText, "Kill Goal: %d kills", Netgame.KillGoal*5);
5714 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++;
5716 opt_start_invul=opt;
5717 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Invulnerable when reappearing"; m[opt].value=Netgame.invul; opt++;
5719 opt_marker_view = opt;
5720 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Allow camera views from Markers"; m[opt].value=Netgame.Allow_marker_view; opt++;
5722 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Indestructible lights"; m[opt].value=Netgame.AlwaysLighting; opt++;
5725 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Bright player ships"; m[opt].value=Netgame.BrightPlayers; opt++;
5728 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Show enemy names on HUD"; m[opt].value=Netgame.ShowAllNames; opt++;
5730 opt_show_on_map=opt;
5731 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++;
5733 opt_short_packets=opt;
5734 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Short packets"; m[opt].value=Netgame.ShortPackets; opt++;
5737 m[opt].type = NM_TYPE_MENU; m[opt].text = "Set Objects allowed..."; opt++;
5739 if (Network_game_type == IPX_GAME) {
5740 m[opt].type = NM_TYPE_TEXT; m[opt].text = "Network socket"; opt++;
5742 m[opt].type = NM_TYPE_INPUT; m[opt].text = socket_string; m[opt].text_len=4; opt++;
5745 m[opt].type = NM_TYPE_TEXT; m[opt].text = "Packets per second (2 - 20)"; opt++;
5747 m[opt].type = NM_TYPE_INPUT; m[opt].text=packstring; m[opt].text_len=2; opt++;
5749 LastKillGoal=Netgame.KillGoal;
5750 LastPTA=Netgame.PlayTimeAllowed;
5754 ExtGameStatus=GAMESTAT_MORE_NETGAME_OPTIONS;
5755 i = newmenu_do1( NULL, "Additional netgame options", opt, m, network_more_options_poll, 0 );
5757 //control_invul_time = atoi( srinvul )*60*F1_0;
5758 control_invul_time = m[opt_cinvul].value;
5759 Netgame.control_invul_time = control_invul_time*5*F1_0*60;
5761 if (i==opt_setpower)
5763 network_set_power ();
5767 Netgame.PacketsPerSec=atoi(packstring);
5769 if (Netgame.PacketsPerSec>20)
5771 Netgame.PacketsPerSec=20;
5772 nm_messagebox(TXT_ERROR, 1, TXT_OK, "Packet value out of range\nSetting value to 20");
5774 if (Netgame.PacketsPerSec<2)
5776 nm_messagebox(TXT_ERROR, 1, TXT_OK, "Packet value out of range\nSetting value to 2");
5777 Netgame.PacketsPerSec=2;
5780 mprintf ((0,"Hey! Sending out %d packets per second\n",Netgame.PacketsPerSec));
5782 if (Network_game_type == IPX_GAME) {
5783 if ((atoi(socket_string))!=Network_socket) {
5784 Network_socket=atoi(socket_string);
5785 ipx_change_default_socket( IPX_DEFAULT_SOCKET + Network_socket );
5789 Netgame.invul=m[opt_start_invul].value;
5790 Netgame.BrightPlayers=m[opt_bright].value;
5791 Netgame.ShortPackets=m[opt_short_packets].value;
5792 Netgame.ShowAllNames=m[opt_show_names].value;
5793 network_AdjustMaxDataSize();
5795 Netgame.Allow_marker_view=m[opt_marker_view].value;
5796 Netgame.AlwaysLighting=m[opt_light].value;
5797 netgame_difficulty=Difficulty_level = m[opt_difficulty].value;
5798 if (m[opt_show_on_map].value)
5799 Netgame.game_flags |= NETGAME_FLAG_SHOW_MAP;
5804 void network_more_options_poll( int nitems, newmenu_item * menus, int * key, int citem )
5807 citem = citem; // kills compile warnings
5811 if ( last_cinvul != menus[opt_cinvul].value ) {
5812 sprintf( menus[opt_cinvul].text, "%s: %d %s", TXT_REACTOR_LIFE, menus[opt_cinvul].value*5, TXT_MINUTES_ABBREV );
5813 last_cinvul = menus[opt_cinvul].value;
5814 menus[opt_cinvul].redraw = 1;
5817 if (menus[opt_playtime].value!=LastPTA)
5821 nm_messagebox ("Sorry",1,TXT_OK,"Registered version only!");
5822 menus[opt_playtime].value=0;
5823 menus[opt_playtime].redraw=1;
5827 if (Game_mode & GM_MULTI_COOP)
5830 nm_messagebox ("Sorry",1,TXT_OK,"You can't change those for coop!");
5831 menus[opt_playtime].value=0;
5832 menus[opt_playtime].redraw=1;
5836 Netgame.PlayTimeAllowed=menus[opt_playtime].value;
5837 sprintf( menus[opt_playtime].text, "Max Time: %d %s", Netgame.PlayTimeAllowed*5, TXT_MINUTES_ABBREV );
5838 LastPTA=Netgame.PlayTimeAllowed;
5839 menus[opt_playtime].redraw=1;
5841 if (menus[opt_killgoal].value!=LastKillGoal)
5844 nm_messagebox ("Sorry",1,TXT_OK,"Registered version only!");
5845 menus[opt_killgoal].value=0;
5846 menus[opt_killgoal].redraw=1;
5852 if (Game_mode & GM_MULTI_COOP)
5854 nm_messagebox ("Sorry",1,TXT_OK,"You can't change those for coop!");
5855 menus[opt_killgoal].value=0;
5856 menus[opt_killgoal].redraw=1;
5862 Netgame.KillGoal=menus[opt_killgoal].value;
5863 sprintf( menus[opt_killgoal].text, "Kill Goal: %d kills", Netgame.KillGoal*5);
5864 LastKillGoal=Netgame.KillGoal;
5865 menus[opt_killgoal].redraw=1;
5869 extern void multi_send_light (int,ubyte);
5870 extern void multi_send_light_specific (int,int,ubyte);
5872 void network_send_smash_lights (int pnum)
5874 // send the lights that have been blown out
5880 for (i=0;i<=Highest_segment_index;i++)
5881 if (Light_subtracted[i])
5882 multi_send_light_specific(pnum,i,Light_subtracted[i]);
5885 extern int Num_triggers;
5886 extern void multi_send_trigger_specific (char pnum,char);
5888 void network_send_fly_thru_triggers (int pnum)
5890 // send the fly thru triggers that have been disabled
5894 for (i=0;i<Num_triggers;i++)
5895 if (Triggers[i].flags & TF_DISABLED)
5896 multi_send_trigger_specific(pnum,i);
5899 void network_send_player_flags()
5903 for (i=0;i<N_players;i++)
5904 multi_send_flags(i);
5907 void network_ping (ubyte flag,int pnum)
5912 mybuf[1]=Player_num;
5914 if (Network_game_type == IPX_GAME)
5915 ipx_send_packet_data( (ubyte *)mybuf, 2, NetPlayers.players[pnum].network.ipx.server, NetPlayers.players[pnum].network.ipx.node,Players[pnum].net_address );
5918 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);
5922 extern fix PingLaunchTime,PingReturnTime;
5924 void network_handle_ping_return (ubyte pnum)
5926 if (PingLaunchTime==0 || pnum>=N_players)
5928 mprintf ((0,"Got invalid PING RETURN from %s!\n",Players[pnum].callsign));
5932 PingReturnTime=timer_get_fixed_seconds();
5934 HUD_init_message ("Ping time for %s is %d ms!",Players[pnum].callsign,
5935 f2i(fixmul(PingReturnTime-PingLaunchTime,i2f(1000))));
5939 void network_send_ping (ubyte pnum)
5941 network_ping (PID_PING_SEND,pnum);
5944 void DoRefuseStuff (sequence_packet *their)
5946 int i,new_player_num;
5948 ClipRank (&their->player.rank);
5950 for (i=0;i<MAX_PLAYERS;i++)
5951 if (!strcmp (their->player.callsign,Players[i].callsign))
5953 network_welcome_player(their);
5957 if (!WaitForRefuseAnswer)
5959 for (i=0;i<MAX_PLAYERS;i++)
5960 if (!strcmp (their->player.callsign,Players[i].callsign))
5962 network_welcome_player(their);
5966 digi_play_sample (SOUND_HUD_JOIN_REQUEST,F1_0*2);
5968 if (Game_mode & GM_TEAM)
5972 if (!args_find("-norankings"))
5973 HUD_init_message ("%s %s wants to join",RankStrings[their->player.rank],their->player.callsign);
5975 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]);
5977 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]);
5979 // HUD_init_message ("Alt-1 to place on team %s!",Netgame.team_name[0]);
5980 // HUD_init_message ("Alt-2 to place on team %s!",Netgame.team_name[1]);
5983 HUD_init_message ("%s wants to join...press F6 to connect",their->player.callsign);
5985 strcpy (RefusePlayerName,their->player.callsign);
5986 RefuseTimeLimit=timer_get_approx_seconds();
5988 WaitForRefuseAnswer=1;
5992 for (i=0;i<MAX_PLAYERS;i++)
5993 if (!strcmp (their->player.callsign,Players[i].callsign))
5995 network_welcome_player(their);
5999 if (strcmp(their->player.callsign,RefusePlayerName))
6002 if (RefuseThisPlayer)
6006 WaitForRefuseAnswer=0;
6007 if (Game_mode & GM_TEAM)
6009 new_player_num=GetNewPlayerNumber (their);
6010 mprintf ((0,"Newplayernum=%d\n",new_player_num));
6012 Assert (RefuseTeam==1 || RefuseTeam==2);
6015 Netgame.team_vector &=(~(1<<new_player_num));
6017 Netgame.team_vector |=(1<<new_player_num);
6018 network_welcome_player(their);
6019 network_send_netgame_update ();
6022 network_welcome_player(their);
6026 if ((timer_get_approx_seconds()) > RefuseTimeLimit+REFUSE_INTERVAL)
6030 WaitForRefuseAnswer=0;
6031 if (!strcmp (their->player.callsign,RefusePlayerName)) {
6032 if (Network_game_type == IPX_GAME)
6033 network_dump_player(their->player.network.ipx.server,their->player.network.ipx.node, DUMP_DORK);
6036 network_dump_appletalk_player(their->player.network.appletalk.node,their->player.network.appletalk.net, their->player.network.appletalk.socket, DUMP_DORK);
6045 int GetNewPlayerNumber (sequence_packet *their)
6051 if ( N_players < MaxNumNetPlayers)
6056 // Slots are full but game is open, see if anyone is
6057 // disconnected and replace the oldest player with this new one
6059 int oldest_player = -1;
6060 fix oldest_time = timer_get_approx_seconds();
6062 Assert(N_players == MaxNumNetPlayers);
6064 for (i = 0; i < N_players; i++)
6066 if ( (!Players[i].connected) && (LastPacketTime[i] < oldest_time))
6068 oldest_time = LastPacketTime[i];
6072 return (oldest_player);
6076 void network_send_extras ()
6078 Assert (Player_joining_extras>-1);
6080 if (!network_i_am_master())
6082 mprintf ((0,"Hey! I'm not the master and I was gonna send info!\n"));
6084 // Network_sending_extras=0;
6089 if (Network_sending_extras==40)
6090 network_send_fly_thru_triggers(Player_joining_extras);
6091 if (Network_sending_extras==38)
6092 network_send_door_updates(Player_joining_extras);
6093 if (Network_sending_extras==35)
6094 network_send_markers();
6095 if (Network_sending_extras==30 && (Game_mode & GM_MULTI_ROBOTS))
6096 multi_send_stolen_items();
6097 if (Network_sending_extras==25 && (Netgame.PlayTimeAllowed || Netgame.KillGoal))
6098 multi_send_kill_goal_counts();
6099 if (Network_sending_extras==20)
6100 network_send_smash_lights(Player_joining_extras);
6101 if (Network_sending_extras==15)
6102 network_send_player_flags();
6103 if (Network_sending_extras==10)
6104 multi_send_powerup_update();
6105 // if (Network_sending_extras==5)
6106 // network_send_door_updates(Player_joining_extras); // twice!
6108 Network_sending_extras--;
6109 if (!Network_sending_extras)
6110 Player_joining_extras=-1;
6114 void network_send_naked_packet(char *buf, short len, int who)
6116 if (!(Game_mode&GM_NETWORK)) return;
6118 if (NakedPacketLen==0)
6120 NakedBuf[0]=PID_NAKED_PDATA;
6121 NakedBuf[1]=Player_num;
6125 if (len+NakedPacketLen>MaxXDataSize)
6127 // mprintf ((0,"Sending a naked packet of %d bytes.\n",NakedPacketLen));
6128 if (Network_game_type == IPX_GAME)
6129 ipx_send_packet_data( (ubyte *)NakedBuf, NakedPacketLen, NetPlayers.players[who].network.ipx.server, NetPlayers.players[who].network.ipx.node,Players[who].net_address );
6132 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 );
6135 memcpy (&NakedBuf[NakedPacketLen],buf,len);
6136 NakedPacketLen+=len;
6137 NakedPacketDestPlayer=who;
6141 memcpy (&NakedBuf[NakedPacketLen],buf,len);
6142 NakedPacketLen+=len;
6143 NakedPacketDestPlayer=who;
6148 void network_process_naked_pdata (char *data,int len)
6151 Assert (data[0]=PID_NAKED_PDATA);
6153 // mprintf ((0,"Processing a naked packet of %d length.\n",len));
6156 mprintf ((0,"Naked packet is bad!\n"));
6157 Int3(); // This packet is bogus!!
6161 if (!multi_quit_game && (pnum >= N_players)) {
6162 if (Network_status!=NETSTAT_WAITING)
6164 Int3(); // We missed an important packet!
6165 network_consistency_error();
6172 if (Endlevel_sequence || (Network_status == NETSTAT_ENDLEVEL) ) {
6173 int old_Endlevel_sequence = Endlevel_sequence;
6174 Endlevel_sequence = 1;
6175 multi_process_bigdata( data+2, len-2);
6176 Endlevel_sequence = old_Endlevel_sequence;
6180 multi_process_bigdata( data+2, len-2 );
6183 int ConnectionPacketLevel[]={0,1,1,1};
6184 int ConnectionSecLevel[]={12,3,5,7};
6186 int AppletalkConnectionPacketLevel[]={0,1,0};
6187 int AppletalkConnectionSecLevel[]={10,3,8};
6189 #if defined(RELEASE) && !defined(MACINTOSH) // use the code below for mac appletalk games
6190 int network_choose_connect ()
6195 int network_choose_connect ()
6200 if (Network_game_type == IPX_GAME) {
6202 m[opt].type = NM_TYPE_MENU; m[opt].text = "Local Subnet"; opt++;
6203 m[opt].type = NM_TYPE_MENU; m[opt].text = "14.4 modem over Internet"; opt++;
6204 m[opt].type = NM_TYPE_MENU; m[opt].text = "28.8 modem over Internet"; opt++;
6205 m[opt].type = NM_TYPE_MENU; m[opt].text = "ISDN or T1 over Internet"; opt++;
6207 choice = newmenu_do1( NULL, "Choose connection type", opt, m, NULL, 0 );
6212 Assert (choice>=0 && choice<=3);
6214 Netgame.ShortPackets=ConnectionPacketLevel[choice];
6215 Netgame.PacketsPerSec=ConnectionSecLevel[choice];
6220 m[opt].type = NM_TYPE_MENU; m[opt].text = "EtherTalk"; opt++;
6221 m[opt].type = NM_TYPE_MENU; m[opt].text = "LocalTalk"; opt++;
6222 m[opt].type = NM_TYPE_MENU; m[opt].text = "Other"; opt++;
6224 choice = newmenu_do1( NULL, "Choose connection type", opt, m, NULL, 0 );
6229 Network_appletalk_type = choice;
6231 Assert (choice>=0 && choice<=2);
6233 Netgame.ShortPackets=AppletalkConnectionPacketLevel[choice];
6234 Netgame.PacketsPerSec=AppletalkConnectionSecLevel[choice];
6248 SendLogFile=(FILE *)fopen ("sendlog.net","w");
6252 void OpenRecieveLog ()
6255 RecieveLogFile=(FILE *)fopen ("recvlog.net","w");
6261 int GetMyNetRanking ()
6266 if (Netlife_kills+Netlife_killed==0)
6269 rank=(int) (((float)Netlife_kills/3000.0)*8.0);
6271 eff=(int)((float)((float)Netlife_kills/((float)Netlife_killed+(float)Netlife_kills))*100.0);
6280 rank-=((59-eff)/10);
6287 mprintf ((0,"Rank is %d (%s)\n",rank+1,RankStrings[rank+1]));
6291 void ClipRank (signed char *rank)
6293 // This function insures no crashes when dealing with D2 1.0
6296 if (*rank<0 || *rank>9)
6299 void network_check_for_old_version (char pnum)
6301 if (NetPlayers.players[pnum].version_major==1 && (NetPlayers.players[pnum].version_minor & 0x0F)==0)
6302 NetPlayers.players[pnum].rank=0;
6305 void network_request_player_names (int n)
6307 network_send_all_info_request (PID_GAME_PLAYERS,Active_games[n].Security);
6308 NamesInfoSecurity=Active_games[n].Security;
6311 extern char already_showing_info;
6312 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));
6314 void network_process_names_return (char *data)
6317 char mtext[15][50],temp[50];
6318 int i,t,l,gnum,num=0,count=5,numplayers;
6320 if (NamesInfoSecurity!=(*(int *)(data+1)))
6322 mprintf ((0,"Bad security on names return!\n"));
6323 mprintf ((0,"NIS=%d data=%d\n",NamesInfoSecurity,(*(int *)(data+1))));
6327 numplayers=data[count]; count++;
6329 if (numplayers==255)
6332 NamesInfoSecurity=-1;
6333 nm_messagebox(NULL, 1, "OK", "That game is refusing\nname requests.\n");
6338 Assert (numplayers>0 && numplayers<MAX_NUM_NET_PLAYERS);
6342 m[i].text=&mtext[i];
6343 m[i].type=NM_TYPE_TEXT;
6346 for (gnum=-1,i=0;i<num_active_games;i++)
6348 if (NamesInfoSecurity==Active_games[i].Security)
6358 NamesInfoSecurity=-1;
6359 nm_messagebox(NULL, 1, "OK", "The game you have requested\nnames from is gone.\n");
6364 sprintf (mtext[num],"Players of game '%s':",Active_games[gnum].game_name); num++;
6365 for (i=0;i<numplayers;i++)
6369 mprintf ((0,"%s\n",data+count));
6371 for (t=0;t<CALLSIGN_LEN+1;t++)
6372 temp[t]=data[count++];
6373 if (args_find("-norankings"))
6374 sprintf (mtext[num],"%s",temp);
6376 sprintf (mtext[num],"%s%s",RankStrings[l],temp);
6381 if (data[count]==99)
6383 sprintf (mtext[num++]," ");
6384 sprintf (mtext[num++],"Short packets: %s",data[count+1]?"On":"Off");
6385 sprintf (mtext[num++],"Packets Per Second: %d",data[count+2]);
6388 already_showing_info=1;
6389 newmenu_dotiny2( NULL, NULL, num, m, NULL);
6390 already_showing_info=0;
6393 char NameReturning=1;
6395 void network_send_player_names (sequence_packet *their)
6397 int numconnected=0,count=0,i,t;
6402 mprintf ((0,"Got a player name without a return address! Get Jason\n"));
6406 buf[0]=PID_NAMES_RETURN; count++;
6407 (*(int *)(buf+1))=Netgame.Security; count+=4;
6411 buf[count]=255; count++;
6415 mprintf ((0,"RealSec=%d DS=%d\n",Netgame.Security,*(int *)(buf+1)));
6417 for (i=0;i<N_players;i++)
6418 if (Players[i].connected)
6421 buf[count]=numconnected; count++;
6422 for (i=0;i<N_players;i++)
6423 if (Players[i].connected)
6425 buf[count++]=NetPlayers.players[i].rank;
6427 for (t=0;t<CALLSIGN_LEN+1;t++)
6429 buf[count]=NetPlayers.players[i].callsign[t];
6435 buf[count++]=Netgame.ShortPackets;
6436 buf[count++]=Netgame.PacketsPerSec;
6439 ; // empty statement allows compilation on mac which does not have the
6440 // statement below and kills the compiler when there is no
6441 // statement following the label "sendit"
6444 ipx_send_internetwork_packet_data((ubyte *)buf, count, their->player.network.ipx.server, their->player.network.ipx.node);
6449 extern int file_exists (char *);
6451 int HoardEquipped ()
6461 if (file_exists ("hoard.ham"))