2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
11 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
15 * $Source: /cvs/cvsroot/d2x/main/network.c,v $
18 * $Date: 2001-10-23 22:03:03 $
20 * FIXME: put description here
22 * $Log: not supported by cvs2svn $
79 #include <Errors.h> // for appletalk networking errors
83 void network_send_rejoin_sync(int player_num);
84 void network_update_netgame(void);
85 void network_read_endlevel_packet( ubyte *data );
86 void network_read_object_packet( ubyte *data );
87 void network_read_sync_packet( netgame_info * sp, int d1x );
89 void network_listen();
90 void network_read_pdata_packet(frame_info *pd );
92 void network_check_for_old_version (char pnum);
93 void network_send_endlevel_short_sub(int from_player_num,int to_player);
94 int network_wait_for_playerinfo();
95 void network_process_pdata (char *data);
96 void network_read_endlevel_short_packet( ubyte *data );
97 void network_ping (ubyte flag,int pnum);
98 void network_handle_ping_return (ubyte pnum);
99 void network_process_names_return (char *data);
100 void network_send_player_names (sequence_packet *their);
101 int network_choose_connect ();
102 void network_more_game_options ();
103 void network_count_powerups_in_mine(void);
104 int network_wait_for_all_info (int choice);
105 void network_do_big_wait(int choice);
106 void network_send_extras ();
107 void network_read_pdata_short_packet(short_frame_info *pd );
109 void network_AdjustMaxDataSize ();
111 void ClipRank (signed char *rank);
112 void DoRefuseStuff (sequence_packet *their);
113 void SetAllAllowablesTo (int on);
114 int GetNewPlayerNumber (sequence_packet *their);
116 #define LHX(x) ((x)*(MenuHires?2:1))
117 #define LHY(y) ((y)*(MenuHires?2.4:1))
119 #define PID_LITE_INFO 43
120 #define PID_SEND_ALL_GAMEINFO 44
121 #define PID_PLAYERSINFO 45
122 #define PID_REQUEST 46
125 #define PID_ADDPLAYER 49
127 #define PID_ENDLEVEL 52
128 #define PID_QUIT_JOINING 54
129 #define PID_OBJECT_DATA 55
130 #define PID_GAME_LIST 56
131 #define PID_GAME_INFO 57
132 #define PID_PING_SEND 58
133 #define PID_PING_RETURN 59
134 #define PID_GAME_UPDATE 60
135 #define PID_ENDLEVEL_SHORT 61
136 #define PID_NAKED_PDATA 62
137 #define PID_GAME_PLAYERS 63
138 #define PID_NAMES_RETURN 64
140 #define NETGAME_ANARCHY 0
141 #define NETGAME_TEAM_ANARCHY 1
142 #define NETGAME_ROBOT_ANARCHY 2
143 #define NETGAME_COOPERATIVE 3
144 #define NETGAME_CAPTURE_FLAG 4
145 #define NETGAME_HOARD 5
146 #define NETGAME_TEAM_HOARD 6
148 #define NETSECURITY_OFF 0
149 #define NETSECURITY_WAIT_FOR_PLAYERS 1
150 #define NETSECURITY_WAIT_FOR_GAMEINFO 2
151 #define NETSECURITY_WAIT_FOR_SYNC 3
153 // MWA -- these structures are aligned -- please save me sanity and
154 // headaches by keeping alignment if these are changed!!!! Contact
157 typedef struct endlevel_info {
162 short kill_matrix[MAX_PLAYERS][MAX_PLAYERS];
167 typedef struct endlevel_info_short {
172 } endlevel_info_short;
174 // WARNING!!! This is the top part of netgame_info...if that struct changes,
175 // this struct much change as well. ie...they are aligned and the join system will
176 // not work without it.
178 // MWA if this structure changes -- please make appropriate changes to receive_netgame_info
179 // code for macintosh in netmisc.c
181 typedef struct lite_info {
184 char game_name[NETGAME_NAME_LEN+1];
185 char mission_title[MISSION_NAME_LEN+1];
186 char mission_name[9];
193 ubyte max_numplayers;
196 ubyte protocol_version;
202 // IF YOU CHANGE THE SIZE OF ANY OF THE FOLLOWING STRUCTURES
203 // MAKE THE MACINTOSH DEFINES BE THE SAME SIZE AS THE PC OR
204 // I WILL HAVE TO HURT YOU VERY BADLY!!! -- MWA
207 #define NETGAME_INFO_SIZE ( Network_game_type == IPX_GAME?355:sizeof(netgame_info) )
208 #define ALLNETPLAYERSINFO_SIZE ( Network_game_type == IPX_GAME?317:sizeof(AllNetPlayers_info) )
209 #define LITE_INFO_SIZE ( Network_game_type == IPX_GAME?72:sizeof(lite_info) )
210 #define SEQUENCE_PACKET_SIZE ( Network_game_type == IPX_GAME?34:sizeof(sequence_packet) )
211 #define FRAME_INFO_SIZE ( Network_game_type == IPX_GAME?541:sizeof(frame_info) )
212 #define IPX_SHORT_INFO_SIZE ( 490 )
214 #define NETGAME_INFO_SIZE sizeof(netgame_info)
215 #define ALLNETPLAYERSINFO_SIZE sizeof(AllNetPlayers_info)
216 #define LITE_INFO_SIZE sizeof(lite_info)
217 #define SEQUENCE_PACKET_SIZE sizeof(sequence_packet)
218 #define FRAME_INFO_SIZE sizeof(frame_info)
221 #define MAX_ACTIVE_NETGAMES 12
223 netgame_info Active_games[MAX_ACTIVE_NETGAMES];
224 AllNetPlayers_info ActiveNetPlayers[MAX_ACTIVE_NETGAMES];
225 AllNetPlayers_info *TempPlayersInfo,TempPlayersBase;
226 int NamesInfoSecurity=-1;
228 // MWAnetgame_info *TempNetInfo;
229 netgame_info TempNetInfo;
231 extern void multi_send_drop_marker (int player,vms_vector position,char messagenum,char text[]);
232 extern void multi_send_kill_goal_counts();
233 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) );
235 void network_process_naked_pdata (char *,int);
236 extern void multi_send_robot_controls(char);
238 int num_active_games = 0;
239 int PacketsPerSec=10;
240 int MaxXDataSize=NET_XDATA_SIZE;
242 int Netlife_kills=0, Netlife_killed=0;
245 int Network_active=0;
247 int Network_status = 0;
248 int Network_games_changed = 0;
250 int Network_socket = 0;
251 int Network_allow_socket_changes = 1;
253 int Network_initial_pps = 10;
254 int Network_initial_shortpackets = 0;
256 int NetSecurityFlag=NETSECURITY_OFF;
257 int NetSecurityNum=0;
258 int Network_sending_extras=0;
259 int VerifyPlayerJoined=-1;
260 int Player_joining_extras=-1; // This is so we know who to send 'latecomer' packets to.
261 // We could just send updates to everyone but that kills the sender!
263 // For rejoin object syncing
265 int Network_rejoined = 0; // Did WE rejoin this game?
266 int Network_new_game = 0; // Is this the first level of a new game?
267 int Network_send_objects = 0; // Are we in the process of sending objects to a player?
268 int Network_send_objnum = -1; // What object are we sending next?
269 int Network_player_added = 0; // Is this a new player or a returning player?
270 int Network_send_object_mode = 0; // What type of objects are we sending, static or dynamic?
271 sequence_packet Network_player_rejoining; // Who is rejoining now?
273 fix LastPacketTime[MAX_PLAYERS]; // For timeouts of idle/crashed players
275 int PacketUrgent = 0;
277 int TotalMissedPackets=0,TotalPacketsGot=0;
279 frame_info MySyncPack,UrgentSyncPack;
280 ubyte MySyncPackInitialized = 0; // Set to 1 if the MySyncPack is zeroed.
281 ushort my_segments_checksum = 0;
283 sequence_packet My_Seq;
284 char WantPlayersInfo=0;
285 char WaitingForPlayerInfo=0;
287 char *RankStrings[]={"(unpatched) ","Cadet ","Ensign ","Lieutenant ","Lt.Commander ",
288 "Commander ","Captain ","Vice Admiral ","Admiral ","Demigod "};
290 extern obj_position Player_init[MAX_PLAYERS];
292 extern int force_cockpit_redraw;
294 #define DUMP_CLOSED 0
296 #define DUMP_ENDLEVEL 2
298 #define DUMP_ABORTED 4
299 #define DUMP_CONNECTED 5
301 #define DUMP_KICKED 7
303 extern ubyte Version_major,Version_minor;
304 extern ubyte SurfingNet;
305 extern char MaxPowerupsAllowed[MAX_POWERUP_TYPES];
306 extern char PowerupsInMine[MAX_POWERUP_TYPES];
308 extern void multi_send_stolen_items();
310 int network_wait_for_snyc();
311 extern void multi_send_wall_status (int,ubyte,ubyte,ubyte);
312 extern void multi_send_wall_status_specific (int,int,ubyte,ubyte,ubyte);
314 extern void game_disable_cheats();
317 FILE *SendLogFile,*RecieveLogFile;
318 int TTSent[100],TTRecv[100];
320 extern int Final_boss_is_dead;
322 // following is network stuff for appletalk
324 void network_dump_appletalk_player(ubyte node, ushort net, ubyte socket, int why);
326 #define NETWORK_OEM 0x10
330 int Network_game_type; // used to tell IPX vs. appletalk games
332 #define MAX_ZONES 255
333 #define MAX_ZONE_LENGTH 33
334 #define DEFAULT_ZONE_NAME "\p*"
335 #define MAX_REGISTER_TRIES 5 // maximum time we will try and register a netgame
336 char Network_zone_name[MAX_ZONE_LENGTH]; // zone name game being played in for appletalk
337 char Zone_names[MAX_ZONES][MAX_ZONE_LENGTH]; // total list of zones that we can see
338 ubyte appletalk_use_broadcast = 0;
339 ubyte Network_game_validated = 0; // validates a game before being able to join
340 ubyte Network_game_validate_choice = 0;
341 ubyte Network_appletalk_type = 0; // type of appletalk network game is being played on
343 #define ETHERTALK_TYPE 0
344 #define LOCALTALK_TYPE 1
345 #define OTHERTALK_TYPE 2
348 void network_release_registered_game(void);
356 // So you want to play a netgame, eh? Let's a get a few things
360 int save_pnum = Player_num;
362 game_disable_cheats();
364 Final_boss_is_dead=0;
365 NamesInfoSecurity=-1;
373 for (t=0;t<MAX_POWERUP_TYPES;t++)
375 MaxPowerupsAllowed[t]=0;
379 TotalMissedPackets=0; TotalPacketsGot=0;
381 memset(&Netgame, 0, sizeof(netgame_info));
382 memset(&NetPlayers,0,sizeof(AllNetPlayers_info));
383 memset(&My_Seq, 0, sizeof(sequence_packet));
384 My_Seq.type = PID_REQUEST;
385 memcpy(My_Seq.player.callsign, Players[Player_num].callsign, CALLSIGN_LEN+1);
388 Version_minor|=NETWORK_OEM;
391 My_Seq.player.version_major=Version_major;
392 My_Seq.player.version_minor=Version_minor;
393 My_Seq.player.rank=GetMyNetRanking();
395 if (Network_game_type == IPX_GAME) {
396 memcpy(My_Seq.player.network.ipx.node, ipx_get_my_local_address(), 6);
397 memcpy(My_Seq.player.network.ipx.server, ipx_get_my_server_address(), 4 );
400 My_Seq.player.network.appletalk.node = appletalk_get_my_node();
401 My_Seq.player.network.appletalk.net = appletalk_get_my_net();
402 My_Seq.player.network.appletalk.socket = appletalk_get_my_socket();
406 My_Seq.player.computer_type = MAC;
408 My_Seq.player.computer_type = DOS;
411 for (Player_num = 0; Player_num < MAX_NUM_NET_PLAYERS; Player_num++)
412 init_player_stats_game();
414 Player_num = save_pnum;
416 Network_new_game = 1;
417 Control_center_destroyed = 0;
420 Netgame.PacketsPerSec=10;
422 if ((t=FindArg("-packets")))
424 Netgame.PacketsPerSec=atoi(Args[t+1]);
425 if (Netgame.PacketsPerSec<1)
426 Netgame.PacketsPerSec=1;
427 else if (Netgame.PacketsPerSec>20)
428 Netgame.PacketsPerSec=20;
429 mprintf ((0,"Will send %d packets per second",Netgame.PacketsPerSec));
431 if (FindArg("-shortpackets"))
433 Netgame.ShortPackets=1;
434 mprintf ((0,"Will send short packets.\n"));
439 network_i_am_master(void)
441 // I am the lowest numbered player in this game?
445 if (!(Game_mode & GM_NETWORK))
446 return (Player_num == 0);
448 for (i = 0; i < Player_num; i++)
449 if (Players[i].connected)
454 network_who_is_master(void)
456 // Who is the master of this game?
460 if (!(Game_mode & GM_NETWORK))
461 return (Player_num == 0);
463 for (i = 0; i < N_players; i++)
464 if (Players[i].connected)
468 int network_how_many_connected()
472 for (i = 0; i < N_players; i++)
473 if (Players[i].connected)
478 #define ENDLEVEL_SEND_INTERVAL (F1_0*2)
479 #define ENDLEVEL_IDLE_TIME (F1_0*20)
482 network_endlevel_poll( int nitems, newmenu_item * menus, int * key, int citem )
484 // Polling loop for End-of-level menu
492 int previous_state[MAX_NUM_NET_PLAYERS];
493 int previous_seconds_left;
500 // Send our endlevel packet at regular intervals
502 if (timer_get_approx_seconds() > (t1+ENDLEVEL_SEND_INTERVAL))
504 network_send_endlevel_packet();
505 t1 = timer_get_approx_seconds();
508 for (i = 0; i < N_players; i++)
509 previous_state[i] = Players[i].connected;
511 previous_seconds_left = Countdown_seconds_left;
515 for (i = 0; i < N_players; i++)
517 if (Players[i].connected == 1)
519 // Check timeout for idle players
520 if (timer_get_approx_seconds() > LastPacketTime[i]+ENDLEVEL_IDLE_TIME)
522 mprintf((0, "idle timeout for player %d.\n", i));
523 Players[i].connected = 0;
524 network_send_endlevel_sub(i);
528 if ((Players[i].connected != 1) && (Players[i].connected != 5) && (Players[i].connected != 6))
530 if (Players[i].connected != 1)
532 if (Players[i].connected == 4)
536 if (num_escaped == N_players) // All players are out of the mine
538 Countdown_seconds_left = -1;
542 if (num_ready == N_players) // All players have checked in or are disconnected
552 network_endlevel_poll2( int nitems, newmenu_item * menus, int * key, int citem )
554 // Polling loop for End-of-level menu
566 // Send our endlevel packet at regular intervals
568 if (timer_get_approx_seconds() > (t1+ENDLEVEL_SEND_INTERVAL))
570 network_send_endlevel_packet();
571 t1 = timer_get_approx_seconds();
574 // mprintf ((0,"Trying to listen!\n"));
577 for (i = 0; i < N_players; i++)
579 if ((Players[i].connected != 1) && (Players[i].connected != 5) && (Players[i].connected != 6))
581 if (Players[i].connected == 4)
585 if (num_ready == N_players) // All players have checked in or are disconnected
595 extern fix StartAbortMenuTime;
598 network_endlevel_poll3( int nitems, newmenu_item * menus, int * key, int citem )
600 // Polling loop for End-of-level menu
609 if (timer_get_approx_seconds() > (StartAbortMenuTime+(F1_0 * 8)))
616 for (i = 0; i < N_players; i++)
617 if ((Players[i].connected != 1) && (Players[i].connected != 5) && (Players[i].connected != 6))
620 if (num_ready == N_players) // All players have checked in or are disconnected
627 network_endlevel(int *secret)
629 // Do whatever needs to be done between levels
637 Network_status = NETSTAT_ENDLEVEL; // We are between levels
641 network_send_endlevel_packet();
643 for (i=0; i<N_players; i++)
645 LastPacketTime[i] = timer_get_approx_seconds();
648 network_send_endlevel_packet();
649 network_send_endlevel_packet();
650 MySyncPackInitialized = 0;
652 network_update_netgame();
658 can_join_netgame(netgame_info *game,AllNetPlayers_info *people)
660 // Can this player rejoin a netgame in progress?
664 if (game->game_status == NETSTAT_STARTING)
667 if (game->game_status != NETSTAT_PLAYING)
669 mprintf ((0,"Error: Can't join because game_status !=NETSTAT_PLAYING\n"));
673 if (game->version_major==0 && Version_major>0)
675 mprintf ((0,"Error:Can't join because version majors don't match!\n"));
679 if (game->version_major>0 && Version_major==0)
681 mprintf ((0,"Error:Can't join because version majors2 don't match!\n"));
685 // Game is in progress, figure out if this guy can re-join it
687 num_players = game->numplayers;
689 if (!(game->game_flags & NETGAME_FLAG_CLOSED)) {
690 // Look for player that is not connected
692 if (game->numconnected==game->max_numplayers)
695 // mprintf ((0,"Refuse = %d\n",game->RefusePlayers));
697 if (game->RefusePlayers)
700 if (game->numplayers < game->max_numplayers)
703 if (game->numconnected<num_players)
710 mprintf ((0,"Error! Can't join because people==NULL!\n"));
714 // Search to see if we were already in this closed netgame in progress
716 for (i = 0; i < num_players; i++) {
717 if (Network_game_type == IPX_GAME) {
718 if ( (!stricmp(Players[Player_num].callsign, people->players[i].callsign)) &&
719 (!memcmp(My_Seq.player.network.ipx.node, people->players[i].network.ipx.node, 6)) &&
720 (!memcmp(My_Seq.player.network.ipx.server, people->players[i].network.ipx.server, 4)) )
723 if ( (!stricmp(Players[Player_num].callsign, people->players[i].callsign)) &&
724 (My_Seq.player.network.appletalk.node == people->players[i].network.appletalk.node) &&
725 (My_Seq.player.network.appletalk.net == people->players[i].network.appletalk.net) )
730 if (i != num_players)
733 mprintf ((0,"Error: Can't join because at end of list!\n"));
738 network_disconnect_player(int playernum)
740 // A player has disconnected from the net game, take whatever steps are
743 if (playernum == Player_num)
745 Int3(); // Weird, see Rob
749 Players[playernum].connected = 0;
750 NetPlayers.players[playernum].connected = 0;
751 if (VerifyPlayerJoined==playernum)
752 VerifyPlayerJoined=-1;
754 // create_player_appearance_effect(&Objects[Players[playernum].objnum]);
755 multi_make_player_ghost(playernum);
757 if (Newdemo_state == ND_STATE_RECORDING)
758 newdemo_record_multi_disconnect(playernum);
760 multi_strip_robots(playernum);
764 network_new_player(sequence_packet *their)
769 pnum = their->player.connected;
772 Assert(pnum < MaxNumNetPlayers);
774 objnum = Players[pnum].objnum;
776 if (Newdemo_state == ND_STATE_RECORDING) {
779 if (pnum == N_players)
783 newdemo_record_multi_connect(pnum, new_player, their->player.callsign);
786 memcpy(Players[pnum].callsign, their->player.callsign, CALLSIGN_LEN+1);
787 memcpy(NetPlayers.players[pnum].callsign, their->player.callsign, CALLSIGN_LEN+1);
790 ClipRank (&their->player.rank);
791 NetPlayers.players[pnum].rank=their->player.rank;
792 NetPlayers.players[pnum].version_major=their->player.version_major;
793 NetPlayers.players[pnum].version_minor=their->player.version_minor;
794 network_check_for_old_version(pnum);
796 if (Network_game_type == IPX_GAME) {
797 if ( (*(uint *)their->player.network.ipx.server) != 0 )
798 ipx_get_local_target( their->player.network.ipx.server, their->player.network.ipx.node, Players[pnum].net_address );
800 memcpy(Players[pnum].net_address, their->player.network.ipx.node, 6);
802 memcpy(NetPlayers.players[pnum].network.ipx.node, their->player.network.ipx.node, 6);
803 memcpy(NetPlayers.players[pnum].network.ipx.server, their->player.network.ipx.server, 4);
805 NetPlayers.players[pnum].network.appletalk.node = their->player.network.appletalk.node;
806 NetPlayers.players[pnum].network.appletalk.net = their->player.network.appletalk.net;
807 NetPlayers.players[pnum].network.appletalk.socket = their->player.network.appletalk.socket;
810 Players[pnum].n_packets_got = 0;
811 Players[pnum].connected = 1;
812 Players[pnum].net_kills_total = 0;
813 Players[pnum].net_killed_total = 0;
814 memset(kill_matrix[pnum], 0, MAX_PLAYERS*sizeof(short));
815 Players[pnum].score = 0;
816 Players[pnum].flags = 0;
817 Players[pnum].KillGoalCount=0;
819 if (pnum == N_players)
822 Netgame.numplayers = N_players;
825 digi_play_sample(SOUND_HUD_MESSAGE, F1_0);
827 ClipRank (&their->player.rank);
829 if (FindArg("-norankings"))
830 HUD_init_message("'%s' %s\n",their->player.callsign, TXT_JOINING);
832 HUD_init_message("%s'%s' %s\n",RankStrings[their->player.rank],their->player.callsign, TXT_JOINING);
834 multi_make_ghost_player(pnum);
837 multi_sort_kill_list();
839 // create_player_appearance_effect(&Objects[objnum]);
842 char RefuseThisPlayer=0,WaitForRefuseAnswer=0,RefuseTeam;
843 char RefusePlayerName[12];
844 fix RefuseTimeLimit=0;
846 void network_welcome_player(sequence_packet *their)
848 // Add a player to a game already in progress
849 ubyte local_address[6];
853 WaitForRefuseAnswer=0;
855 if (FindArg("-NoMatrixCheat"))
857 if (their->player.version_minor & (0x0F<3))
859 network_dump_player(their->player.network.ipx.server, their->player.network.ipx.node, DUMP_DORK);
866 // If hoard game, and this guy isn't D2 Christmas (v1.2), dump him
868 if ((Game_mode & GM_HOARD) && ((their->player.version_minor & 0x0F)<2))
870 if (Network_game_type == IPX_GAME)
871 network_dump_player(their->player.network.ipx.server, their->player.network.ipx.node, DUMP_DORK);
874 network_dump_appletalk_player(their->player.network.appletalk.node, their->player.network.appletalk.net, their->player.network.appletalk.socket, DUMP_DORK);
880 // Don't accept new players if we're ending this level. Its safe to
881 // ignore since they'll request again later
883 if ((Endlevel_sequence) || (Control_center_destroyed))
885 mprintf((0, "Ignored request from new player to join during endgame.\n"));
886 if (Network_game_type == IPX_GAME)
887 network_dump_player(their->player.network.ipx.server,their->player.network.ipx.node, DUMP_ENDLEVEL);
890 network_dump_appletalk_player(their->player.network.appletalk.node, their->player.network.appletalk.net, their->player.network.appletalk.socket, DUMP_ENDLEVEL);
895 if (Network_send_objects || Network_sending_extras)
897 // Ignore silently, we're already responding to someone and we can't
898 // do more than one person at a time. If we don't dump them they will
899 // re-request in a few seconds.
903 if (their->player.connected != Current_level_num)
905 mprintf((0, "Dumping player due to old level number.\n"));
906 if (Network_game_type == IPX_GAME)
907 network_dump_player(their->player.network.ipx.server, their->player.network.ipx.node, DUMP_LEVEL);
910 network_dump_appletalk_player(their->player.network.appletalk.node, their->player.network.appletalk.net, their->player.network.appletalk.socket, DUMP_LEVEL);
916 memset(&Network_player_rejoining, 0, sizeof(sequence_packet));
917 Network_player_added = 0;
919 if (Network_game_type == IPX_GAME) {
920 if ( (*(uint *)their->player.network.ipx.server) != 0 )
921 ipx_get_local_target( their->player.network.ipx.server, their->player.network.ipx.node, local_address );
923 memcpy(local_address, their->player.network.ipx.node, 6);
926 for (i = 0; i < N_players; i++)
928 if ( (Network_game_type == IPX_GAME) && (!stricmp(Players[i].callsign, their->player.callsign )) && (!memcmp(Players[i].net_address,local_address, 6)) )
933 #ifdef MACINTOSH // note link to above if
934 else if ( (!stricmp(Players[i].callsign, their->player.callsign)) &&
935 (NetPlayers.players[i].network.appletalk.node == their->player.network.appletalk.node) &&
936 (NetPlayers.players[i].network.appletalk.net == their->player.network.appletalk.net)) {
943 if (player_num == -1)
945 // Player is new to this game
947 if ( !(Netgame.game_flags & NETGAME_FLAG_CLOSED) && (N_players < MaxNumNetPlayers))
949 // Add player in an open slot, game not full yet
951 player_num = N_players;
952 Network_player_added = 1;
954 else if (Netgame.game_flags & NETGAME_FLAG_CLOSED)
956 // Slots are open but game is closed
958 if (Network_game_type == IPX_GAME)
959 network_dump_player(their->player.network.ipx.server, their->player.network.ipx.node, DUMP_CLOSED);
962 network_dump_appletalk_player(their->player.network.appletalk.node, their->player.network.appletalk.net, their->player.network.appletalk.socket, DUMP_CLOSED);
968 // Slots are full but game is open, see if anyone is
969 // disconnected and replace the oldest player with this new one
971 int oldest_player = -1;
972 fix oldest_time = timer_get_approx_seconds();
974 Assert(N_players == MaxNumNetPlayers);
976 for (i = 0; i < N_players; i++)
978 if ( (!Players[i].connected) && (LastPacketTime[i] < oldest_time))
980 oldest_time = LastPacketTime[i];
985 if (oldest_player == -1)
987 // Everyone is still connected
989 if (Network_game_type == IPX_GAME)
990 network_dump_player(their->player.network.ipx.server, their->player.network.ipx.node, DUMP_FULL);
993 network_dump_appletalk_player(their->player.network.appletalk.node, their->player.network.appletalk.net, their->player.network.appletalk.socket, DUMP_FULL);
1001 player_num = oldest_player;
1002 Network_player_added = 1;
1008 // Player is reconnecting
1010 if (Players[player_num].connected)
1012 mprintf((0, "Extra REQUEST from player ignored.\n"));
1016 if (Newdemo_state == ND_STATE_RECORDING)
1017 newdemo_record_multi_reconnect(player_num);
1019 Network_player_added = 0;
1021 digi_play_sample(SOUND_HUD_MESSAGE, F1_0);
1023 if (FindArg("-norankings"))
1024 HUD_init_message("'%s' %s", Players[player_num].callsign, TXT_REJOIN);
1026 HUD_init_message("%s'%s' %s", RankStrings[NetPlayers.players[player_num].rank],Players[player_num].callsign, TXT_REJOIN);
1029 Players[player_num].KillGoalCount=0;
1031 // Send updated Objects data to the new/returning player
1034 Network_player_rejoining = *their;
1035 Network_player_rejoining.player.connected = player_num;
1036 Network_send_objects = 1;
1037 Network_send_objnum = -1;
1039 network_send_objects();
1042 int network_objnum_is_past(int objnum)
1044 // determine whether or not a given object number has already been sent
1045 // to a re-joining player.
1047 int player_num = Network_player_rejoining.player.connected;
1048 int obj_mode = !((object_owner[objnum] == -1) || (object_owner[objnum] == player_num));
1050 if (!Network_send_objects)
1051 return 0; // We're not sending objects to a new player
1053 if (obj_mode > Network_send_object_mode)
1055 else if (obj_mode < Network_send_object_mode)
1057 else if (objnum < Network_send_objnum)
1063 #define OBJ_PACKETS_PER_FRAME 1
1064 extern void multi_send_active_door(char);
1065 extern void multi_send_door_open_specific(int,int,int,ubyte);
1068 void network_send_door_updates(int pnum)
1070 // Send door status when new player joins
1076 // Assert (pnum>-1 && pnum<N_players);
1078 for (i = 0; i < Num_walls; i++)
1080 if ((Walls[i].type == WALL_DOOR) && ((Walls[i].state == WALL_DOOR_OPENING) || (Walls[i].state == WALL_DOOR_WAITING) || (Walls[i].state == WALL_DOOR_OPEN)))
1081 multi_send_door_open_specific(pnum,Walls[i].segnum, Walls[i].sidenum,Walls[i].flags);
1082 else if ((Walls[i].type == WALL_BLASTABLE) && (Walls[i].flags & WALL_BLASTED))
1083 multi_send_door_open_specific(pnum,Walls[i].segnum, Walls[i].sidenum,Walls[i].flags);
1084 else if ((Walls[i].type == WALL_BLASTABLE) && (Walls[i].hps != WALL_HPS))
1085 multi_send_hostage_door_status(i);
1087 multi_send_wall_status_specific(pnum,i,Walls[i].type,Walls[i].flags,Walls[i].state);
1091 extern vms_vector MarkerPoint[];
1092 void network_send_markers()
1094 // send marker positions/text to new player
1101 if (MarkerObject[(i*2)]!=-1)
1102 multi_send_drop_marker (i,MarkerPoint[(i*2)],0,MarkerMessage[i*2]);
1103 if (MarkerObject[(i*2)+1]!=-1)
1104 multi_send_drop_marker (i,MarkerPoint[(i*2)+1],1,MarkerMessage[(i*2)+1]);
1108 void network_process_monitor_vector(int vector)
1114 for (i=0; i <= Highest_segment_index; i++)
1118 for (j = 0; j < 6; j++)
1120 if ( ((tm = seg->sides[j].tmap_num2) != 0) &&
1121 ((ec = TmapInfo[tm&0x3fff].eclip_num) != -1) &&
1122 ((bm = Effects[ec].dest_bm_num) != -1) )
1124 if (vector & (1 << count))
1126 seg->sides[j].tmap_num2 = bm | (tm&0xc000);
1127 // mprintf((0, "Monitor %d blown up.\n", count));
1130 // mprintf((0, "Monitor %d intact.\n", count));
1138 int network_create_monitor_vector(void)
1141 int num_blown_bitmaps = 0;
1142 int monitor_num = 0;
1143 #define NUM_BLOWN_BITMAPS 20
1144 int blown_bitmaps[NUM_BLOWN_BITMAPS];
1148 for (i=0; i < Num_effects; i++)
1150 if (Effects[i].dest_bm_num > 0) {
1151 for (j = 0; j < num_blown_bitmaps; j++)
1152 if (blown_bitmaps[j] == Effects[i].dest_bm_num)
1154 if (j == num_blown_bitmaps) {
1155 blown_bitmaps[num_blown_bitmaps++] = Effects[i].dest_bm_num;
1156 Assert(num_blown_bitmaps < NUM_BLOWN_BITMAPS);
1161 // for (i = 0; i < num_blown_bitmaps; i++)
1162 // mprintf((0, "Blown bitmap #%d = %d.\n", i, blown_bitmaps[i]));
1164 for (i=0; i <= Highest_segment_index; i++)
1168 for (j = 0; j < 6; j++)
1170 if ((tm = seg->sides[j].tmap_num2) != 0)
1172 if ( ((ec = TmapInfo[tm&0x3fff].eclip_num) != -1) &&
1173 (Effects[ec].dest_bm_num != -1) )
1175 // mprintf((0, "Monitor %d intact.\n", monitor_num));
1177 Assert(monitor_num < 32);
1181 for (k = 0; k < num_blown_bitmaps; k++)
1183 if ((tm&0x3fff) == blown_bitmaps[k])
1185 //mprintf((0, "Monitor %d destroyed.\n", monitor_num));
1186 vector |= (1 << monitor_num);
1188 Assert(monitor_num < 32);
1196 // mprintf((0, "Final monitor vector %x.\n", vector));
1200 void network_stop_resync(sequence_packet *their)
1202 if (Network_game_type == IPX_GAME) {
1203 if ( (!memcmp(Network_player_rejoining.player.network.ipx.node, their->player.network.ipx.node, 6)) &&
1204 (!memcmp(Network_player_rejoining.player.network.ipx.server, their->player.network.ipx.server, 4)) &&
1205 (!stricmp(Network_player_rejoining.player.callsign, their->player.callsign)) )
1207 mprintf((0, "Aborting resync for player %s.\n", their->player.callsign));
1208 Network_send_objects = 0;
1209 Network_sending_extras=0;
1211 Player_joining_extras=-1;
1212 Network_send_objnum = -1;
1215 if ( (Network_player_rejoining.player.network.appletalk.node == their->player.network.appletalk.node) &&
1216 (Network_player_rejoining.player.network.appletalk.net == their->player.network.appletalk.net) &&
1217 (!stricmp(Network_player_rejoining.player.callsign, their->player.callsign)) )
1219 mprintf((0, "Aborting resync for player %s.\n", their->player.callsign));
1220 Network_send_objects = 0;
1221 Network_sending_extras=0;
1223 Player_joining_extras=-1;
1224 Network_send_objnum = -1;
1229 byte object_buffer[IPX_MAX_DATA_SIZE];
1231 void network_send_objects(void)
1233 short remote_objnum;
1237 static int obj_count = 0;
1238 static int frame_num = 0;
1240 int obj_count_frame = 0;
1241 int player_num = Network_player_rejoining.player.connected;
1243 // Send clear objects array trigger and send player num
1245 Assert(Network_send_objects != 0);
1246 Assert(player_num >= 0);
1247 Assert(player_num < MaxNumNetPlayers);
1249 if (Endlevel_sequence || Control_center_destroyed)
1251 // Endlevel started before we finished sending the goods, we'll
1252 // have to stop and try again after the level.
1254 if (Network_game_type == IPX_GAME)
1255 network_dump_player(Network_player_rejoining.player.network.ipx.server,Network_player_rejoining.player.network.ipx.node, DUMP_ENDLEVEL);
1258 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);
1260 Network_send_objects = 0;
1264 for (h = 0; h < OBJ_PACKETS_PER_FRAME; h++) // Do more than 1 per frame, try to speed it up without
1265 // over-stressing the receiver.
1267 obj_count_frame = 0;
1268 memset(object_buffer, 0, IPX_MAX_DATA_SIZE);
1269 object_buffer[0] = PID_OBJECT_DATA;
1272 if (Network_send_objnum == -1)
1275 Network_send_object_mode = 0;
1276 // mprintf((0, "Sending object array to player %d.\n", player_num));
1277 *(short *)(object_buffer+loc) = INTEL_SHORT(-1); loc += 2;
1278 object_buffer[loc] = player_num; loc += 1;
1279 loc += 2; // Placeholder for remote_objnum, not used here
1280 Network_send_objnum = 0;
1281 obj_count_frame = 1;
1285 for (i = Network_send_objnum; i <= Highest_object_index; i++)
1287 if ((Objects[i].type != OBJ_POWERUP) && (Objects[i].type != OBJ_PLAYER) &&
1288 (Objects[i].type != OBJ_CNTRLCEN) && (Objects[i].type != OBJ_GHOST) &&
1289 (Objects[i].type != OBJ_ROBOT) && (Objects[i].type != OBJ_HOSTAGE) &&
1290 !(Objects[i].type==OBJ_WEAPON && Objects[i].id==PMINE_ID))
1292 if ((Network_send_object_mode == 0) && ((object_owner[i] != -1) && (object_owner[i] != player_num)))
1294 if ((Network_send_object_mode == 1) && ((object_owner[i] == -1) || (object_owner[i] == player_num)))
1297 if ( ((IPX_MAX_DATA_SIZE-1) - loc) < (sizeof(object)+5) )
1298 break; // Not enough room for another object
1303 remote_objnum = objnum_local_to_remote((short)i, &owner);
1304 Assert(owner == object_owner[i]);
1306 *(short *)(object_buffer+loc) = INTEL_SHORT((short)i); loc += 2;
1307 object_buffer[loc] = owner; loc += 1;
1308 *(short *)(object_buffer+loc) = INTEL_SHORT(remote_objnum); loc += 2;
1310 memcpy(object_buffer+loc, &Objects[i], sizeof(object)); loc += sizeof(object);
1312 if (Network_game_type == IPX_GAME) {
1315 memcpy(&tmpobj, &(Objects[i]), sizeof(object));
1316 swap_object(&tmpobj);
1317 memcpy(&(object_buffer[loc]), &tmpobj, sizeof(object)); loc += sizeof(object);
1320 memcpy(object_buffer+loc, &Objects[i], sizeof(object)); loc += sizeof(object);
1322 // mprintf((0, "..packing object %d, remote %d\n", i, remote_objnum));
1325 if (obj_count_frame) // Send any objects we've buffered
1329 Network_send_objnum = i;
1330 object_buffer[1] = obj_count_frame; object_buffer[2] = frame_num;
1331 // mprintf((0, "Object packet %d contains %d objects.\n", frame_num, obj_count_frame));
1333 Assert(loc <= IPX_MAX_DATA_SIZE);
1335 if (Network_game_type == IPX_GAME)
1336 ipx_send_internetwork_packet_data( object_buffer, loc, Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node );
1339 appletalk_send_packet_data( object_buffer, loc, Network_player_rejoining.player.network.appletalk.node,
1340 Network_player_rejoining.player.network.appletalk.net,
1341 Network_player_rejoining.player.network.appletalk.socket);
1344 // OLD ipx_send_packet_data(object_buffer, loc, &Network_player_rejoining.player.node);
1347 if (i > Highest_object_index)
1349 if (Network_send_object_mode == 0)
1351 Network_send_objnum = 0;
1352 Network_send_object_mode = 1; // go to next mode
1356 Assert(Network_send_object_mode == 1);
1359 // Send count so other side can make sure he got them all
1360 // mprintf((0, "Sending end marker in packet #%d.\n", frame_num));
1361 mprintf((0, "Sent %d objects.\n", obj_count));
1362 object_buffer[0] = PID_OBJECT_DATA;
1363 object_buffer[1] = 1;
1364 object_buffer[2] = frame_num;
1365 *(short *)(object_buffer+3) = INTEL_SHORT(-2);
1366 *(short *)(object_buffer+6) = INTEL_SHORT(obj_count);
1367 //OLD ipx_send_packet_data(object_buffer, 8, &Network_player_rejoining.player.node);
1368 if (Network_game_type == IPX_GAME)
1369 ipx_send_internetwork_packet_data(object_buffer, 8, Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node);
1372 appletalk_send_packet_data( object_buffer, 8, Network_player_rejoining.player.network.appletalk.node,
1373 Network_player_rejoining.player.network.appletalk.net,
1374 Network_player_rejoining.player.network.appletalk.socket);
1378 // Send sync packet which tells the player who he is and to start!
1379 network_send_rejoin_sync(player_num);
1380 mprintf ((0,"VerfiyPlayerJoined is now set to %d\n",player_num));
1381 VerifyPlayerJoined=player_num;
1383 // Turn off send object mode
1384 Network_send_objnum = -1;
1385 Network_send_objects = 0;
1388 //if (!network_i_am_master ())
1389 // Int3(); // Bad!! Get Jason. Someone goofy is trying to get ahold of the game!
1391 Network_sending_extras=40; // start to send extras
1392 Player_joining_extras=player_num;
1396 } // i > Highest_object_index
1397 } // For PACKETS_PER_FRAME
1400 extern void multi_send_powerup_update();
1402 void network_send_rejoin_sync(int player_num)
1406 Players[player_num].connected = 1; // connect the new guy
1407 LastPacketTime[player_num] = timer_get_approx_seconds();
1409 if (Endlevel_sequence || Control_center_destroyed)
1411 // Endlevel started before we finished sending the goods, we'll
1412 // have to stop and try again after the level.
1414 if (Network_game_type == IPX_GAME)
1415 network_dump_player(Network_player_rejoining.player.network.ipx.server,Network_player_rejoining.player.network.ipx.node, DUMP_ENDLEVEL);
1418 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);
1420 Network_send_objects = 0;
1421 Network_sending_extras=0;
1425 if (Network_player_added)
1427 Network_player_rejoining.type = PID_ADDPLAYER;
1428 Network_player_rejoining.player.connected = player_num;
1429 network_new_player(&Network_player_rejoining);
1431 for (i = 0; i < N_players; i++)
1433 if ((i != player_num) && (i != Player_num) && (Players[i].connected))
1434 if (Network_game_type == IPX_GAME) {
1436 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);
1438 send_sequence_packet( Network_player_rejoining, NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node, Players[i].net_address);
1442 appletalk_send_packet_data( (ubyte *)&Network_player_rejoining, sizeof(sequence_packet), NetPlayers.players[i].network.appletalk.node,
1443 NetPlayers.players[i].network.appletalk.net, NetPlayers.players[i].network.appletalk.socket);
1449 // Send sync packet to the new guy
1451 network_update_netgame();
1453 // Fill in the kill list
1454 for (j=0; j<MAX_PLAYERS; j++)
1456 for (i=0; i<MAX_PLAYERS;i++)
1457 Netgame.kills[j][i] = kill_matrix[j][i];
1458 Netgame.killed[j] = Players[j].net_killed_total;
1459 Netgame.player_kills[j] = Players[j].net_kills_total;
1460 Netgame.player_score[j] = Players[j].score;
1463 Netgame.level_time = Players[Player_num].time_level;
1464 Netgame.monitor_vector = network_create_monitor_vector();
1466 mprintf((0, "Sending rejoin sync packet!!!\n"));
1468 if (Network_game_type == IPX_GAME) {
1470 ipx_send_internetwork_packet_data( (ubyte *)&Netgame, sizeof(netgame_info), Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node );
1471 ipx_send_internetwork_packet_data( (ubyte *)&NetPlayers, sizeof(AllNetPlayers_info), Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node );
1473 send_netgame_packet(Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node, NULL, 0);
1474 send_netplayers_packet(Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node);
1478 appletalk_send_packet_data( (ubyte *)&Netgame, sizeof(netgame_info), Network_player_rejoining.player.network.appletalk.node,
1479 Network_player_rejoining.player.network.appletalk.net,
1480 Network_player_rejoining.player.network.appletalk.socket);
1481 appletalk_send_packet_data( (ubyte *)&NetPlayers, sizeof(AllNetPlayers_info), Network_player_rejoining.player.network.appletalk.node,
1482 Network_player_rejoining.player.network.appletalk.net,
1483 Network_player_rejoining.player.network.appletalk.socket);
1488 void resend_sync_due_to_packet_loss_for_allender ()
1492 mprintf ((0,"I'm resending a sync packet! VPJ=%d\n",VerifyPlayerJoined));
1494 network_update_netgame();
1496 // Fill in the kill list
1497 for (j=0; j<MAX_PLAYERS; j++)
1499 for (i=0; i<MAX_PLAYERS;i++)
1500 Netgame.kills[j][i] = kill_matrix[j][i];
1501 Netgame.killed[j] = Players[j].net_killed_total;
1502 Netgame.player_kills[j] = Players[j].net_kills_total;
1503 Netgame.player_score[j] = Players[j].score;
1506 Netgame.level_time = Players[Player_num].time_level;
1507 Netgame.monitor_vector = network_create_monitor_vector();
1509 if (Network_game_type == IPX_GAME) {
1511 ipx_send_internetwork_packet_data( (ubyte *)&Netgame, sizeof(netgame_info), Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node );
1512 ipx_send_internetwork_packet_data( (ubyte *)&NetPlayers, sizeof(AllNetPlayers_info), Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node );
1514 send_netgame_packet(Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node, NULL, 0);
1515 send_netplayers_packet(Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node);
1519 appletalk_send_packet_data( (ubyte *)&Netgame, sizeof(netgame_info), Network_player_rejoining.player.network.appletalk.node,
1520 Network_player_rejoining.player.network.appletalk.net,
1521 Network_player_rejoining.player.network.appletalk.socket);
1522 appletalk_send_packet_data( (ubyte *)&NetPlayers, sizeof(AllNetPlayers_info), Network_player_rejoining.player.network.appletalk.node,
1523 Network_player_rejoining.player.network.appletalk.net,
1524 Network_player_rejoining.player.network.appletalk.socket);
1530 char * network_get_player_name( int objnum )
1532 if ( objnum < 0 ) return NULL;
1533 if ( Objects[objnum].type != OBJ_PLAYER ) return NULL;
1534 if ( Objects[objnum].id >= MAX_PLAYERS ) return NULL;
1535 if ( Objects[objnum].id >= N_players ) return NULL;
1537 return Players[Objects[objnum].id].callsign;
1541 void network_add_player(sequence_packet *p)
1545 mprintf((0, "Got add player request!\n"));
1547 for (i=0; i<N_players; i++ ) {
1548 if (Network_game_type == IPX_GAME) {
1549 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))
1550 return; // already got them
1552 if ( (NetPlayers.players[i].network.appletalk.node == p->player.network.appletalk.node) &&
1553 (NetPlayers.players[i].network.appletalk.net == p->player.network.appletalk.net))
1558 if (Network_game_type == IPX_GAME) {
1559 memcpy( NetPlayers.players[N_players].network.ipx.node, p->player.network.ipx.node, 6 );
1560 memcpy( NetPlayers.players[N_players].network.ipx.server, p->player.network.ipx.server, 4 );
1562 NetPlayers.players[N_players].network.appletalk.node = p->player.network.appletalk.node;
1563 NetPlayers.players[N_players].network.appletalk.net = p->player.network.appletalk.net;
1564 NetPlayers.players[N_players].network.appletalk.socket = p->player.network.appletalk.socket;
1567 ClipRank (&p->player.rank);
1569 memcpy( NetPlayers.players[N_players].callsign, p->player.callsign, CALLSIGN_LEN+1 );
1570 NetPlayers.players[N_players].version_major=p->player.version_major;
1571 NetPlayers.players[N_players].version_minor=p->player.version_minor;
1572 NetPlayers.players[N_players].rank=p->player.rank;
1573 NetPlayers.players[N_players].connected = 1;
1574 network_check_for_old_version (N_players);
1576 Players[N_players].KillGoalCount=0;
1577 Players[N_players].connected = 1;
1578 LastPacketTime[N_players] = timer_get_approx_seconds();
1580 Netgame.numplayers = N_players;
1582 // Broadcast updated info
1584 mprintf ((0,"sending_game_info!\n"));
1585 network_send_game_info(NULL);
1588 // One of the players decided not to join the game
1590 void network_remove_player(sequence_packet *p)
1595 for (i=0; i<N_players; i++ ) {
1596 if (Network_game_type == IPX_GAME) {
1597 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)) {
1602 if ( (NetPlayers.players[i].network.appletalk.node == p->player.network.appletalk.node) && (NetPlayers.players[i].network.appletalk.net == p->player.network.appletalk.net) ) {
1609 if (pn < 0 ) return;
1611 for (i=pn; i<N_players-1; i++ ) {
1612 if (Network_game_type == IPX_GAME) {
1613 memcpy( NetPlayers.players[i].network.ipx.node, NetPlayers.players[i+1].network.ipx.node, 6 );
1614 memcpy( NetPlayers.players[i].network.ipx.server, NetPlayers.players[i+1].network.ipx.server, 4 );
1616 NetPlayers.players[i].network.appletalk.node = NetPlayers.players[i+1].network.appletalk.node;
1617 NetPlayers.players[i].network.appletalk.net = NetPlayers.players[i+1].network.appletalk.net;
1618 NetPlayers.players[i].network.appletalk.socket = NetPlayers.players[i+1].network.appletalk.socket;
1620 memcpy( NetPlayers.players[i].callsign, NetPlayers.players[i+1].callsign, CALLSIGN_LEN+1 );
1621 NetPlayers.players[i].version_major=NetPlayers.players[i+1].version_major;
1622 NetPlayers.players[i].version_minor=NetPlayers.players[i+1].version_minor;
1624 NetPlayers.players[i].rank=NetPlayers.players[i+1].rank;
1625 ClipRank (&NetPlayers.players[i].rank);
1626 network_check_for_old_version(i);
1630 Netgame.numplayers = N_players;
1632 // Broadcast new info
1634 network_send_game_info(NULL);
1639 network_dump_player(ubyte * server, ubyte *node, int why)
1641 // Inform player that he was not chosen for the netgame
1643 sequence_packet temp;
1645 temp.type = PID_DUMP;
1646 memcpy(temp.player.callsign, Players[Player_num].callsign, CALLSIGN_LEN+1);
1647 temp.player.connected = why;
1648 if (Network_game_type == IPX_GAME) {
1650 ipx_send_internetwork_packet_data( (ubyte *)&temp, sizeof(sequence_packet), server, node);
1652 send_sequence_packet( temp, server, node, NULL);
1660 void network_dump_appletalk_player(ubyte node, ushort net, ubyte socket, int why)
1662 sequence_packet temp;
1664 temp.type = PID_DUMP;
1665 memcpy(temp.player.callsign, Players[Player_num].callsign, CALLSIGN_LEN+1);
1666 temp.player.connected = why;
1667 if (Network_game_type == APPLETALK_GAME) {
1668 appletalk_send_packet_data( (ubyte *)&temp, sizeof(sequence_packet), node, net, socket );
1676 network_send_game_list_request()
1678 // Send a broadcast request for game info
1682 mprintf((0, "Sending game_list request.\n"));
1683 me.type = PID_GAME_LIST;
1684 memcpy( me.player.callsign, Players[Player_num].callsign, CALLSIGN_LEN+1 );
1686 if (Network_game_type == IPX_GAME) {
1687 memcpy( me.player.network.ipx.node, ipx_get_my_local_address(), 6 );
1688 memcpy( me.player.network.ipx.server, ipx_get_my_server_address(), 4 );
1691 ipx_send_broadcast_packet_data( (ubyte *)&me, sizeof(sequence_packet) );
1693 send_sequence_packet( me, NULL, NULL, NULL);
1697 me.player.network.appletalk.node = appletalk_get_my_node();
1698 me.player.network.appletalk.net = appletalk_get_my_net();
1699 me.player.network.appletalk.socket = appletalk_get_my_socket();
1700 appletalk_send_game_info( (ubyte *)&me, sizeof(sequence_packet), Network_zone_name );
1705 void network_send_all_info_request(char type,int which_security)
1707 // Send a broadcast request for game info
1711 mprintf((0, "Sending all_info request.\n"));
1713 me.Security=which_security;
1715 memcpy( me.player.callsign, Players[Player_num].callsign, CALLSIGN_LEN+1 );
1717 if (Network_game_type == IPX_GAME) {
1718 memcpy( me.player.network.ipx.node, ipx_get_my_local_address(), 6 );
1719 memcpy( me.player.network.ipx.server, ipx_get_my_server_address(), 4 );
1722 ipx_send_broadcast_packet_data( (ubyte *)&me, sizeof(sequence_packet) );
1724 send_sequence_packet(me, NULL, NULL, NULL);
1728 me.player.network.appletalk.node = appletalk_get_my_node();
1729 me.player.network.appletalk.net = appletalk_get_my_net();
1730 me.player.network.appletalk.socket = appletalk_get_my_socket();
1731 appletalk_send_game_info( (ubyte *)&me, sizeof(sequence_packet), Network_zone_name );
1738 network_update_netgame(void)
1740 // Update the netgame struct with current game variables
1744 Netgame.numconnected=0;
1745 for (i=0;i<N_players;i++)
1746 if (Players[i].connected)
1747 Netgame.numconnected++;
1749 // This is great: D2 1.0 and 1.1 ignore upper part of the game_flags field of
1750 // the lite_info struct when you're sitting on the join netgame screen. We can
1751 // "sneak" Hoard information into this field. This is better than sending
1752 // another packet that could be lost in transit.
1755 if (HoardEquipped())
1757 if (Game_mode & GM_HOARD)
1759 Netgame.game_flags |=NETGAME_FLAG_HOARD;
1760 if (Game_mode & GM_TEAM)
1761 Netgame.game_flags |=NETGAME_FLAG_TEAM_HOARD;
1765 if (Network_status == NETSTAT_STARTING)
1768 Netgame.numplayers = N_players;
1769 Netgame.game_status = Network_status;
1770 Netgame.max_numplayers = MaxNumNetPlayers;
1772 for (i = 0; i < MAX_NUM_NET_PLAYERS; i++)
1774 NetPlayers.players[i].connected = Players[i].connected;
1775 for(j = 0; j < MAX_NUM_NET_PLAYERS; j++)
1776 Netgame.kills[i][j] = kill_matrix[i][j];
1778 Netgame.killed[i] = Players[i].net_killed_total;
1779 Netgame.player_kills[i] = Players[i].net_kills_total;
1780 Netgame.player_score[i] = Players[i].score;
1781 Netgame.player_flags[i] = (Players[i].flags & (PLAYER_FLAGS_BLUE_KEY | PLAYER_FLAGS_RED_KEY | PLAYER_FLAGS_GOLD_KEY));
1783 Netgame.team_kills[0] = team_kills[0];
1784 Netgame.team_kills[1] = team_kills[1];
1785 Netgame.levelnum = Current_level_num;
1791 network_send_endlevel_sub(int player_num)
1796 // Send an endlevel packet for a player
1797 end.type = PID_ENDLEVEL;
1798 end.player_num = player_num;
1799 end.connected = Players[player_num].connected;
1800 end.kills = INTEL_SHORT(Players[player_num].net_kills_total);
1801 end.killed = INTEL_SHORT(Players[player_num].net_killed_total);
1802 memcpy(end.kill_matrix, kill_matrix[player_num], MAX_PLAYERS*sizeof(short));
1804 for (i = 0; i < MAX_PLAYERS; i++)
1805 for (j = 0; j < MAX_PLAYERS; j++)
1806 end.kill_matrix[i][j] = INTEL_SHORT(end.kill_matrix[i][j]);
1808 j = j; // to satisfy compiler
1811 if (Players[player_num].connected == 1) // Still playing
1813 Assert(Control_center_destroyed);
1814 end.seconds_left = Countdown_seconds_left;
1817 // mprintf((0, "Sending endlevel packet.\n"));
1819 for (i = 0; i < N_players; i++)
1821 if ((i != Player_num) && (i!=player_num) && (Players[i].connected)) {
1822 if (Players[i].connected==1)
1823 network_send_endlevel_short_sub(player_num,i);
1825 if (Network_game_type == IPX_GAME)
1826 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);
1829 appletalk_send_packet_data( (ubyte *)&end, sizeof(endlevel_info), NetPlayers.players[i].network.appletalk.node,
1830 NetPlayers.players[i].network.appletalk.net,
1831 NetPlayers.players[i].network.appletalk.socket);
1839 network_send_endlevel_packet(void)
1841 // Send an updated endlevel status to other hosts
1843 network_send_endlevel_sub(Player_num);
1848 network_send_endlevel_short_sub(int from_player_num,int to_player)
1850 endlevel_info_short end;
1852 // Send an endlevel packet for a player
1853 end.type = PID_ENDLEVEL_SHORT;
1854 end.player_num = from_player_num;
1855 end.connected = Players[from_player_num].connected;
1856 end.seconds_left = Countdown_seconds_left;
1859 if (Players[from_player_num].connected == 1) // Still playing
1861 Assert(Control_center_destroyed);
1864 if ((to_player != Player_num) && (to_player!=from_player_num) && (Players[to_player].connected))
1866 mprintf((0, "Sending short endlevel packet to %s.\n",Players[to_player].callsign));
1867 if (Network_game_type == IPX_GAME)
1868 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);
1871 appletalk_send_packet_data( (ubyte *)&end, sizeof(endlevel_info_short), NetPlayers.players[to_player].network.appletalk.node,
1872 NetPlayers.players[to_player].network.appletalk.net,
1873 NetPlayers.players[to_player].network.appletalk.socket);
1878 extern fix ThisLevelTime;
1881 network_send_game_info(sequence_packet *their)
1883 // Send game info to someone who requested it
1885 char old_type, old_status;
1889 mprintf((0, "Sending game info.\n"));
1891 network_update_netgame(); // Update the values in the netgame struct
1893 old_type = Netgame.type;
1894 old_status = Netgame.game_status;
1896 Netgame.type = PID_GAME_INFO;
1897 NetPlayers.type = PID_PLAYERSINFO;
1899 NetPlayers.Security=Netgame.Security;
1900 Netgame.version_major=Version_major;
1901 Netgame.version_minor=Version_minor;
1903 if (Endlevel_sequence || Control_center_destroyed)
1904 Netgame.game_status = NETSTAT_ENDLEVEL;
1906 if (Netgame.PlayTimeAllowed)
1908 timevar=i2f (Netgame.PlayTimeAllowed*5*60);
1909 i=f2i(timevar-ThisLevelTime);
1911 Netgame.game_status=NETSTAT_ENDLEVEL;
1915 if (Network_game_type == IPX_GAME) {
1917 ipx_send_broadcast_packet_data((ubyte *)&Netgame, sizeof(netgame_info));
1918 ipx_send_broadcast_packet_data((ubyte *)&NetPlayers,sizeof(AllNetPlayers_info));
1920 send_netgame_packet(NULL, NULL, NULL, 0); // server == NULL says to broadcast packet
1921 send_netplayers_packet(NULL, NULL);
1923 } // nothing to do for appletalk games I think....
1925 if (Network_game_type == IPX_GAME) {
1927 ipx_send_internetwork_packet_data((ubyte *)&Netgame, sizeof(netgame_info), their->player.network.ipx.server, their->player.network.ipx.node);
1928 ipx_send_internetwork_packet_data((ubyte *)&NetPlayers,sizeof(AllNetPlayers_info),their->player.network.ipx.server,their->player.network.ipx.node);
1930 send_netgame_packet(their->player.network.ipx.server, their->player.network.ipx.node, NULL, 0);
1931 send_netplayers_packet(their->player.network.ipx.server, their->player.network.ipx.node);
1935 appletalk_send_packet_data( (ubyte *)&Netgame, sizeof(netgame_info), their->player.network.appletalk.node,
1936 their->player.network.appletalk.net, their->player.network.appletalk.socket );
1937 appletalk_send_packet_data( (ubyte *)&NetPlayers, sizeof(AllNetPlayers_info), their->player.network.appletalk.node,
1938 their->player.network.appletalk.net, their->player.network.appletalk.socket );
1943 Netgame.type = old_type;
1944 Netgame.game_status = old_status;
1947 void network_send_lite_info(sequence_packet *their)
1949 // Send game info to someone who requested it
1951 char old_type, old_status,oldstatus;
1953 mprintf((0, "Sending lite game info.\n"));
1955 network_update_netgame(); // Update the values in the netgame struct
1957 old_type = Netgame.type;
1958 old_status = Netgame.game_status;
1960 Netgame.type = PID_LITE_INFO;
1962 if (Endlevel_sequence || Control_center_destroyed)
1963 Netgame.game_status = NETSTAT_ENDLEVEL;
1965 // If hoard mode, make this game look closed even if it isn't
1966 if (HoardEquipped())
1968 if (Game_mode & GM_HOARD)
1970 oldstatus=Netgame.game_status;
1971 Netgame.game_status=NETSTAT_ENDLEVEL;
1972 Netgame.gamemode=NETGAME_CAPTURE_FLAG;
1973 if (oldstatus==NETSTAT_ENDLEVEL)
1974 Netgame.game_flags|=NETGAME_FLAG_REALLY_ENDLEVEL;
1975 if (oldstatus==NETSTAT_STARTING)
1976 Netgame.game_flags|=NETGAME_FLAG_REALLY_FORMING;
1981 if (Network_game_type == IPX_GAME) {
1983 ipx_send_broadcast_packet_data((ubyte *)&Netgame, sizeof(lite_info));
1985 send_netgame_packet(NULL, NULL, NULL, 1); // server == NULL says broadcast
1987 } // nothing to do for appletalk I think....
1989 if (Network_game_type == IPX_GAME) {
1991 ipx_send_internetwork_packet_data((ubyte *)&Netgame, sizeof(lite_info), their->player.network.ipx.server, their->player.network.ipx.node);
1993 send_netgame_packet(their->player.network.ipx.server, their->player.network.ipx.node, NULL, 1);
1997 appletalk_send_packet_data( (ubyte *)&Netgame, sizeof(lite_info), their->player.network.appletalk.node,
1998 their->player.network.appletalk.net, their->player.network.appletalk.socket );
2003 // Restore the pre-hoard mode
2004 if (HoardEquipped())
2006 if (Game_mode & GM_HOARD)
2008 if (!(Game_mode & GM_TEAM))
2009 Netgame.gamemode=NETGAME_HOARD;
2011 Netgame.gamemode=NETGAME_TEAM_HOARD;
2012 Netgame.game_flags&=~NETGAME_FLAG_REALLY_ENDLEVEL;
2013 Netgame.game_flags&=~NETGAME_FLAG_REALLY_FORMING;
2014 Netgame.game_flags&=~NETGAME_FLAG_TEAM_HOARD;
2018 Netgame.type = old_type;
2019 Netgame.game_status = old_status;
2023 void network_send_netgame_update()
2025 // Send game info to someone who requested it
2027 char old_type, old_status;
2030 mprintf((0, "Sending updated game info.\n"));
2032 network_update_netgame(); // Update the values in the netgame struct
2034 old_type = Netgame.type;
2035 old_status = Netgame.game_status;
2037 Netgame.type = PID_GAME_UPDATE;
2039 if (Endlevel_sequence || Control_center_destroyed)
2040 Netgame.game_status = NETSTAT_ENDLEVEL;
2042 for (i=0; i<N_players; i++ ) {
2043 if ( (Players[i].connected) && (i!=Player_num ) ) {
2044 if (Network_game_type == IPX_GAME) {
2046 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 );
2048 send_netgame_packet(NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node, Players[i].net_address, 0);
2052 appletalk_send_packet_data( (ubyte *)&Netgame, sizeof(lite_info), NetPlayers.players[i].network.appletalk.node,
2053 NetPlayers.players[i].network.appletalk.net, NetPlayers.players[i].network.appletalk.socket );
2059 Netgame.type = old_type;
2060 Netgame.game_status = old_status;
2063 int network_send_request(void)
2065 // Send a request to join a game 'Netgame'. Returns 0 if we can join this
2066 // game, non-zero if there is some problem.
2069 if (Netgame.numplayers < 1)
2072 for (i = 0; i < MAX_NUM_NET_PLAYERS; i++)
2073 if (NetPlayers.players[i].connected)
2076 Assert(i < MAX_NUM_NET_PLAYERS);
2078 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));
2080 // segments_checksum = netmisc_calc_checksum( Segments, sizeof(segment)*(Highest_segment_index+1) );
2082 My_Seq.type = PID_REQUEST;
2083 My_Seq.player.connected = Current_level_num;
2085 if (Network_game_type == IPX_GAME) {
2087 ipx_send_internetwork_packet_data((ubyte *)&My_Seq, sizeof(sequence_packet), NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node);
2089 send_sequence_packet(My_Seq, NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node, NULL);
2093 appletalk_send_packet_data( (ubyte *)&My_Seq, sizeof(sequence_packet), NetPlayers.players[i].network.appletalk.node,
2094 NetPlayers.players[i].network.appletalk.net,
2095 NetPlayers.players[i].network.appletalk.socket);
2102 int SecurityCheck=0;
2104 void network_process_gameinfo(ubyte *data)
2107 netgame_info tmp_info;
2110 netgame_info *new = (netgame_info *)data;
2113 if (Network_game_type == IPX_GAME) {
2114 receive_netgame_packet(data, &tmp_info, 0); // get correctly aligned structure
2120 WaitingForPlayerInfo=0;
2122 if (new->Security !=TempPlayersInfo->Security)
2124 Int3(); // Get Jason
2125 return; // If this first half doesn't go with the second half
2128 Network_games_changed = 1;
2130 //mprintf((0, "Got game data for game %s.\n", new->game_name));
2132 Assert (TempPlayersInfo!=NULL);
2134 for (i = 0; i < num_active_games; i++)
2136 //mprintf ((0,"GAMEINFO: Game %d is %s!\n",i,Active_games[i].game_name));
2138 if (!stricmp(Active_games[i].game_name, new->game_name) &&
2139 Active_games[i].Security==new->Security)
2143 if (i == MAX_ACTIVE_NETGAMES)
2145 mprintf((0, "Too many netgames.\n"));
2149 // MWA memcpy(&Active_games[i], data, sizeof(netgame_info));
2150 memcpy(&Active_games[i], (ubyte *)new, sizeof(netgame_info));
2151 memcpy (&ActiveNetPlayers[i],TempPlayersInfo,sizeof(AllNetPlayers_info));
2154 if (Active_games[i].Security==SecurityCheck)
2157 //mprintf ((0,"Recieved %d unique games...\n",i));
2159 if (i == num_active_games)
2162 if (Active_games[i].numplayers == 0)
2164 mprintf ((0,"DELETING THIS GAME!!!\n"));
2166 for (j = i; j < num_active_games-1; j++)
2168 memcpy(&Active_games[j], &Active_games[j+1], sizeof(netgame_info));
2169 memcpy (&ActiveNetPlayers[j],&ActiveNetPlayers[j+1],sizeof(AllNetPlayers_info));
2176 void network_process_lite_info(ubyte *data)
2182 lite_info *new = (lite_info *)data;
2185 if (Network_game_type == IPX_GAME) {
2186 receive_netgame_packet(data, (netgame_info *)&tmp_info, 1);
2191 Network_games_changed = 1;
2193 //mprintf((0, "Got game data for game %s.\n", new->game_name));
2195 for (i = 0; i < num_active_games; i++)
2197 //mprintf ((0,"GAMEINFO: Game %d is %s!\n",i,Active_games[i].game_name));
2199 if ((!stricmp(Active_games[i].game_name, new->game_name)) &&
2200 Active_games[i].Security==new->Security)
2204 if (i == MAX_ACTIVE_NETGAMES)
2206 mprintf((0, "Too many netgames.\n"));
2210 memcpy(&Active_games[i], (ubyte *)new, sizeof(lite_info));
2212 // See if this is really a Hoard game
2213 // If so, adjust all the data accordingly
2215 if (HoardEquipped())
2217 if (Active_games[i].game_flags & NETGAME_FLAG_HOARD)
2219 Active_games[i].gamemode=NETGAME_HOARD;
2220 Active_games[i].game_status=NETSTAT_PLAYING;
2222 if (Active_games[i].game_flags & NETGAME_FLAG_TEAM_HOARD)
2223 Active_games[i].gamemode=NETGAME_TEAM_HOARD;
2224 if (Active_games[i].game_flags & NETGAME_FLAG_REALLY_ENDLEVEL)
2225 Active_games[i].game_status=NETSTAT_ENDLEVEL;
2226 if (Active_games[i].game_flags & NETGAME_FLAG_REALLY_FORMING)
2227 Active_games[i].game_status=NETSTAT_STARTING;
2231 //mprintf ((0,"Recieved %d unique games...\n",i));
2233 if (i == num_active_games)
2236 if (Active_games[i].numplayers == 0)
2238 mprintf ((0,"DELETING THIS GAME!!!\n"));
2240 for (j = i; j < num_active_games-1; j++)
2242 memcpy(&Active_games[j], &Active_games[j+1], sizeof(netgame_info));
2248 void network_process_dump(sequence_packet *their)
2250 // Our request for join was denied. Tell the user why.
2255 mprintf((0, "Dumped by player %s, type %d.\n", their->player.callsign, their->player.connected));
2257 if (their->player.connected!=7)
2258 nm_messagebox(NULL, 1, TXT_OK, NET_DUMP_STRINGS(their->player.connected));
2261 for (i=0;i<N_players;i++)
2262 if (!stricmp (their->player.callsign,Players[i].callsign))
2264 if (i!=network_who_is_master())
2266 HUD_init_message ("%s attempted to kick you out.",their->player.callsign);
2270 sprintf (temp,"%s has kicked you out!",their->player.callsign);
2271 nm_messagebox(NULL, 1, TXT_OK, &temp);
2272 if (Network_status==NETSTAT_PLAYING)
2278 Network_status = NETSTAT_MENU;
2283 void network_process_request(sequence_packet *their)
2285 // Player is ready to receieve a sync packet
2288 mprintf((0, "Player %s ready for sync.\n", their->player.callsign));
2290 for (i = 0; i < N_players; i++) {
2291 if (Network_game_type == IPX_GAME) {
2292 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))) {
2293 Players[i].connected = 1;
2297 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)) ) {
2298 Players[i].connected = 1;
2305 #define REFUSE_INTERVAL F1_0 * 8
2306 extern void multi_reset_object_texture (object *);
2308 void network_process_packet(ubyte *data, int length )
2311 sequence_packet tmp_packet;
2313 sequence_packet *their = (sequence_packet *)data;
2316 if (Network_game_type == IPX_GAME) {
2317 receive_sequence_packet(data, &tmp_packet);
2318 their = &tmp_packet; // reassign their to point to correctly alinged structure
2322 //mprintf( (0, "Got packet of length %d, type %d\n", length, their->type ));
2324 // if ( length < sizeof(sequence_packet) ) return;
2330 case PID_GAME_INFO: // Jason L. says we can safely ignore this type.
2333 case PID_PLAYERSINFO:
2335 mprintf ((0,"Got a PID_PLAYERSINFO!\n"));
2337 if (Network_status==NETSTAT_WAITING)
2340 memcpy (&TempPlayersBase,data,sizeof(AllNetPlayers_info));
2342 if (Network_game_type == IPX_GAME)
2343 receive_netplayers_packet(data, &TempPlayersBase);
2345 memcpy (&TempPlayersBase,data,sizeof(AllNetPlayers_info));
2348 if (TempPlayersBase.Security!=Netgame.Security)
2350 mprintf ((0,"Bad security for PLAYERSINFO\n"));
2354 mprintf ((0,"Got a waiting PID_PLAYERSINFO!\n"));
2355 if (length!=ALLNETPLAYERSINFO_SIZE)
2357 mprintf ((0,"Invalid size for netplayers packet!\n"));
2361 TempPlayersInfo=&TempPlayersBase;
2362 WaitingForPlayerInfo=0;
2363 NetSecurityNum=TempPlayersInfo->Security;
2364 NetSecurityFlag=NETSECURITY_WAIT_FOR_SYNC;
2371 if (length != LITE_INFO_SIZE)
2373 mprintf ((0,"WARNING! Recieved invalid size for PID_LITE_INFO\n"));
2377 if (Network_status == NETSTAT_BROWSING)
2378 network_process_lite_info (data);
2382 // Someone wants a list of games
2384 if (length != SEQUENCE_PACKET_SIZE)
2386 mprintf ((0,"WARNING! Recieved invalid size for PID_GAME_LIST\n"));
2390 mprintf((0, "Got a PID_GAME_LIST!\n"));
2391 if ((Network_status == NETSTAT_PLAYING) || (Network_status == NETSTAT_STARTING) || (Network_status == NETSTAT_ENDLEVEL))
2392 if (network_i_am_master())
2393 network_send_lite_info(their);
2397 case PID_SEND_ALL_GAMEINFO:
2399 if (length != SEQUENCE_PACKET_SIZE)
2401 mprintf ((0,"WARNING! Recieved invalid size for PID_SEND_ALL_GAMEINFO\n"));
2405 if ((Network_status == NETSTAT_PLAYING) || (Network_status == NETSTAT_STARTING) || (Network_status == NETSTAT_ENDLEVEL))
2406 if (network_i_am_master() && their->Security==Netgame.Security)
2407 network_send_game_info(their);
2412 mprintf( (0, "Got NEWPLAYER message from %s.\n", their->player.callsign));
2414 if (length != SEQUENCE_PACKET_SIZE)
2416 mprintf ((0,"WARNING! Recieved invalid size for PID_ADDPLAYER\n"));
2419 mprintf( (0, "Got NEWPLAYER message from %s.\n", their->player.callsign));
2420 network_new_player(their);
2423 if (length != SEQUENCE_PACKET_SIZE)
2425 mprintf ((0,"WARNING! Recieved invalid size for PID_REQUEST\n"));
2429 mprintf( (0, "Got REQUEST from '%s'\n", their->player.callsign ));
2430 if (Network_status == NETSTAT_STARTING)
2432 // Someone wants to join our game!
2433 network_add_player(their);
2435 else if (Network_status == NETSTAT_WAITING)
2437 // Someone is ready to recieve a sync packet
2438 network_process_request(their);
2440 else if (Network_status == NETSTAT_PLAYING)
2442 // Someone wants to join a game in progress!
2443 if (Netgame.RefusePlayers)
2444 DoRefuseStuff (their);
2446 network_welcome_player(their);
2451 if (length != SEQUENCE_PACKET_SIZE)
2453 mprintf ((0,"WARNING! Recieved invalid size for PID_DUMP\n"));
2457 if (Network_status == NETSTAT_WAITING || Network_status==NETSTAT_PLAYING )
2458 network_process_dump(their);
2460 case PID_QUIT_JOINING:
2462 if (length != SEQUENCE_PACKET_SIZE)
2464 mprintf ((0,"WARNING! Recieved invalid size for PID_QUIT_JOINING\n"));
2467 if (Network_status == NETSTAT_STARTING)
2468 network_remove_player( their );
2469 else if ((Network_status == NETSTAT_PLAYING) && (Network_send_objects))
2470 network_stop_resync( their );
2474 mprintf ((0,"Got a sync packet! Network_status=%d\n",NETSTAT_WAITING));
2476 if (Network_status == NETSTAT_WAITING) {
2479 memcpy((ubyte *)&(TempNetInfo), data, sizeof(netgame_info));
2481 if (Network_game_type == IPX_GAME)
2482 receive_netgame_packet(data, &TempNetInfo, 0);
2484 memcpy((ubyte *)&(TempNetInfo), data, sizeof(netgame_info));
2487 if (TempNetInfo.Security!=Netgame.Security)
2489 mprintf ((0,"Bad security on sync packet.\n"));
2493 if (NetSecurityFlag==NETSECURITY_WAIT_FOR_SYNC)
2495 if (TempNetInfo.Security==TempPlayersInfo->Security)
2497 network_read_sync_packet (&TempNetInfo,0);
2504 NetSecurityFlag=NETSECURITY_WAIT_FOR_PLAYERS;
2505 NetSecurityNum=TempNetInfo.Security;
2507 if ( network_wait_for_playerinfo())
2508 network_read_sync_packet((netgame_info *)data,0);
2517 if ((Game_mode&GM_NETWORK) && ((Network_status == NETSTAT_PLAYING)||(Network_status == NETSTAT_ENDLEVEL) || Network_status==NETSTAT_WAITING)) {
2518 network_process_pdata((char *)data);
2521 case PID_NAKED_PDATA:
2522 if ((Game_mode&GM_NETWORK) && ((Network_status == NETSTAT_PLAYING)||(Network_status == NETSTAT_ENDLEVEL) || Network_status==NETSTAT_WAITING))
2523 network_process_naked_pdata((char *)data,length);
2526 case PID_OBJECT_DATA:
2527 if (Network_status == NETSTAT_WAITING)
2528 network_read_object_packet(data);
2531 if ((Network_status == NETSTAT_ENDLEVEL) || (Network_status == NETSTAT_PLAYING))
2532 network_read_endlevel_packet(data);
2534 mprintf((0, "Junked endlevel packet.\n"));
2536 case PID_ENDLEVEL_SHORT:
2537 if ((Network_status == NETSTAT_ENDLEVEL) || (Network_status == NETSTAT_PLAYING))
2538 network_read_endlevel_short_packet(data);
2540 mprintf((0, "Junked short endlevel packet!\n"));
2543 case PID_GAME_UPDATE:
2544 mprintf ((0,"Got a GAME_UPDATE!\n"));
2546 if (Network_status==NETSTAT_PLAYING)
2549 memcpy((ubyte *)&TempNetInfo, data, sizeof(lite_info) );
2551 if (Network_game_type == IPX_GAME)
2552 receive_netgame_packet(data, &TempNetInfo, 1);
2554 memcpy((ubyte *)&TempNetInfo, data, sizeof(lite_info) );
2556 if (TempNetInfo.Security==Netgame.Security)
2557 memcpy (&Netgame,(ubyte *)&TempNetInfo,sizeof(lite_info));
2559 if (Game_mode & GM_TEAM)
2563 for (i=0;i<N_players;i++)
2564 if (Players[i].connected)
2565 multi_reset_object_texture (&Objects[Players[i].objnum]);
2570 network_ping (PID_PING_RETURN,data[1]);
2572 case PID_PING_RETURN:
2573 network_handle_ping_return(data[1]); // data[1] is player who told us of their ping time
2575 case PID_NAMES_RETURN:
2576 if (Network_status==NETSTAT_BROWSING && NamesInfoSecurity!=-1)
2577 network_process_names_return (data);
2579 case PID_GAME_PLAYERS:
2580 // Someone wants a list of players in this game
2582 if (length != SEQUENCE_PACKET_SIZE)
2584 mprintf ((0,"WARNING! Recieved invalid size for PID_GAME_PLAYERS\n"));
2588 mprintf((0, "Got a PID_GAME_PLAYERS!\n"));
2589 if ((Network_status == NETSTAT_PLAYING) || (Network_status == NETSTAT_STARTING) || (Network_status == NETSTAT_ENDLEVEL))
2590 if (network_i_am_master() && their->Security==Netgame.Security)
2591 network_send_player_names(their);
2595 mprintf((0, "Ignoring invalid packet type.\n"));
2596 Int3(); // Invalid network packet type, see ROB
2602 void dump_segments()
2606 fp = fopen( "TEST.DMP", "wb" );
2607 fwrite( Segments, sizeof(segment)*(Highest_segment_index+1),1, fp );
2609 mprintf( (0, "SS=%d\n", sizeof(segment) ));
2615 network_read_endlevel_packet( ubyte *data )
2617 // Special packet for end of level syncing
2624 end = (endlevel_info *)data;
2626 for (i = 0; i < MAX_PLAYERS; i++)
2627 for (j = 0; j < MAX_PLAYERS; j++)
2628 end->kill_matrix[i][j] = INTEL_SHORT(end->kill_matrix[i][j]);
2629 end->kills = INTEL_SHORT(end->kills);
2630 end->killed = INTEL_SHORT(end->killed);
2633 playernum = end->player_num;
2635 Assert(playernum != Player_num);
2637 if (playernum>=N_players)
2639 Int3(); // weird, but it an happen in a coop restore game
2640 return; // if it happens in a coop restore, don't worry about it
2643 if ((Network_status == NETSTAT_PLAYING) && (end->connected != 0))
2644 return; // Only accept disconnect packets if we're not out of the level yet
2646 Players[playernum].connected = end->connected;
2647 memcpy(&kill_matrix[playernum][0], end->kill_matrix, MAX_PLAYERS*sizeof(short));
2648 Players[playernum].net_kills_total = end->kills;
2649 Players[playernum].net_killed_total = end->killed;
2651 if ((Players[playernum].connected == 1) && (end->seconds_left < Countdown_seconds_left))
2652 Countdown_seconds_left = end->seconds_left;
2654 LastPacketTime[playernum] = timer_get_approx_seconds();
2656 // mprintf((0, "Got endlevel packet from player %d.\n", playernum));
2660 network_read_endlevel_short_packet( ubyte *data )
2662 // Special packet for end of level syncing
2665 endlevel_info_short *end;
2667 end = (endlevel_info_short *)data;
2669 playernum = end->player_num;
2671 Assert(playernum != Player_num);
2673 if (playernum>=N_players)
2675 Int3(); // weird, but it can happen in a coop restore game
2676 return; // if it happens in a coop restore, don't worry about it
2679 if ((Network_status == NETSTAT_PLAYING) && (end->connected != 0))
2681 //mprintf ((0,"Returning early for short_endlevel\n"));
2682 return; // Only accept disconnect packets if we're not out of the level yet
2685 Players[playernum].connected = end->connected;
2687 if ((Players[playernum].connected == 1) && (end->seconds_left < Countdown_seconds_left))
2688 Countdown_seconds_left = end->seconds_left;
2690 LastPacketTime[playernum] = timer_get_approx_seconds();
2695 network_pack_objects(void)
2697 // Switching modes, pack the object array
2699 special_reset_objects();
2703 network_verify_objects(int remote, int local)
2706 int nplayers, got_controlcen=0;
2708 mprintf ((0,"NETWORK:remote=%d local=%d\n",remote,local));
2710 if ((remote-local) > 10)
2713 if (Game_mode & GM_MULTI_ROBOTS)
2718 for (i = 0; i <= Highest_object_index; i++)
2720 if ((Objects[i].type == OBJ_PLAYER) || (Objects[i].type == OBJ_GHOST))
2722 if (Objects[i].type == OBJ_CNTRLCEN)
2726 if (got_controlcen && (MaxNumNetPlayers<=nplayers))
2733 network_read_object_packet( ubyte *data )
2735 // Object from another net player we need to sync with
2737 short objnum, remote_objnum;
2742 static int my_pnum = 0;
2743 static int mode = 0;
2744 static int object_count = 0;
2745 static int frame_num = 0;
2748 int remote_frame_num = data[2];
2752 // mprintf((0, "Object packet %d (remote #%d) contains %d objects.\n", frame_num, remote_frame_num, nobj));
2754 for (i = 0; i < nobj; i++)
2756 objnum = INTEL_SHORT( *(short *)(data+loc) ); loc += 2;
2757 obj_owner = data[loc]; loc += 1;
2758 remote_objnum = INTEL_SHORT( *(short *)(data+loc) ); loc += 2;
2762 // Clear object array
2763 mprintf((0, "Clearing object array.\n"));
2766 Network_rejoined = 1;
2767 my_pnum = obj_owner;
2768 change_playernum_to(my_pnum);
2773 else if (objnum == -2)
2775 // Special debug checksum marker for entire send
2778 network_pack_objects();
2781 mprintf((0, "Objnum -2 found in frame local %d remote %d.\n", frame_num, remote_frame_num));
2782 mprintf((0, "Got %d objects, expected %d.\n", object_count, remote_objnum));
2783 if (remote_objnum != object_count) {
2786 if (network_verify_objects(remote_objnum, object_count))
2788 // Failed to sync up
2789 nm_messagebox(NULL, 1, TXT_OK, TXT_NET_SYNC_FAILED);
2790 Network_status = NETSTAT_MENU;
2797 if (frame_num != remote_frame_num)
2799 mprintf ((0,"Got a type 3 object packet!\n"));
2801 if ((obj_owner == my_pnum) || (obj_owner == -1))
2805 objnum = remote_objnum;
2806 //if (objnum > Highest_object_index)
2808 // Highest_object_index = objnum;
2809 // num_objects = Highest_object_index+1;
2815 network_pack_objects();
2818 objnum = obj_allocate();
2821 obj = &Objects[objnum];
2822 if (obj->segnum != -1)
2824 Assert(obj->segnum == -1);
2825 Assert(objnum < MAX_OBJECTS);
2826 memcpy(obj,data+loc,sizeof(object)); loc += sizeof(object);
2828 if (Network_game_type == IPX_GAME)
2831 segnum = obj->segnum;
2832 obj->next = obj->prev = obj->segnum = -1;
2833 obj->attached_obj = -1;
2835 obj_link(obj-Objects,segnum);
2836 if (obj_owner == my_pnum)
2837 map_objnum_local_to_local(objnum);
2838 else if (obj_owner != -1)
2839 map_objnum_local_to_remote(objnum, remote_objnum, obj_owner);
2841 object_owner[objnum] = -1;
2843 } // For a standard onbject
2844 } // For each object in packet
2847 void network_sync_poll( int nitems, newmenu_item * menus, int * key, int citem )
2849 // Polling loop waiting for sync packet to start game
2859 if (Network_status != NETSTAT_WAITING) // Status changed to playing, exit the menu
2862 if (!Network_rejoined && (timer_get_approx_seconds() > t1+F1_0*2))
2866 // Poll time expired, re-send request
2868 t1 = timer_get_approx_seconds();
2870 mprintf((0, "Re-sending join request.\n"));
2871 i = network_send_request();
2877 void network_start_poll( int nitems, newmenu_item * menus, int * key, int citem )
2884 Assert(Network_status == NETSTAT_STARTING);
2886 if (!menus[0].value) {
2888 menus[0].redraw = 1;
2891 for (i=1; i<nitems; i++ ) {
2892 if ( (i>= N_players) && (menus[i].value) ) {
2894 menus[i].redraw = 1;
2899 for (i=0; i<nitems; i++ ) {
2900 if ( menus[i].value ) {
2902 if ( nm > N_players ) {
2904 menus[i].redraw = 1;
2909 if ( nm > MaxNumNetPlayers ) {
2910 nm_messagebox( TXT_ERROR, 1, TXT_OK, "%s %d %s", TXT_SORRY_ONLY, MaxNumNetPlayers, TXT_NETPLAYERS_IN );
2911 // Turn off the last player highlighted
2912 for (i = N_players; i > 0; i--)
2913 if (menus[i].value == 1)
2916 menus[i].redraw = 1;
2921 // if (nitems > MAX_PLAYERS ) return;
2923 n = Netgame.numplayers;
2926 if (n < Netgame.numplayers )
2928 digi_play_sample (SOUND_HUD_MESSAGE,F1_0);
2930 mprintf ((0,"More players are printed!"));
2931 if (FindArg("-norankings"))
2932 sprintf( menus[N_players-1].text, "%d. %-20s", N_players,NetPlayers.players[N_players-1].callsign );
2934 sprintf( menus[N_players-1].text, "%d. %s%-20s", N_players, RankStrings[NetPlayers.players[N_players-1].rank],NetPlayers.players[N_players-1].callsign );
2936 menus[N_players-1].redraw = 1;
2937 if (N_players <= MaxNumNetPlayers)
2939 menus[N_players-1].value = 1;
2942 else if ( n > Netgame.numplayers )
2944 // One got removed...
2946 digi_play_sample (SOUND_HUD_KILL,F1_0);
2948 for (i=0; i<N_players; i++ )
2951 if (FindArg("-norankings"))
2952 sprintf( menus[i].text, "%d. %-20s", i+1, NetPlayers.players[i].callsign );
2954 sprintf( menus[i].text, "%d. %s%-20s", i+1, RankStrings[NetPlayers.players[i].rank],NetPlayers.players[i].callsign );
2955 if (i < MaxNumNetPlayers)
2959 menus[i].redraw = 1;
2961 for (i=N_players; i<n; i++ )
2963 sprintf( menus[i].text, "%d. ", i+1 ); // Clear out the deleted entries...
2965 menus[i].redraw = 1;
2970 int opt_cinvul, opt_team_anarchy, opt_coop, opt_show_on_map, opt_closed,opt_maxnet;
2971 int last_cinvul=0,last_maxnet,opt_team_hoard;
2972 int opt_refuse,opt_capture;
2974 void network_game_param_poll( int nitems, newmenu_item * menus, int * key, int citem )
2976 static int oldmaxnet=0;
2978 if (((HoardEquipped() && menus[opt_team_hoard].value) || (menus[opt_team_anarchy].value || menus[opt_capture].value)) && !menus[opt_closed].value && !menus[opt_refuse].value) {
2979 menus[opt_refuse].value = 1;
2980 menus[opt_refuse].redraw = 1;
2981 menus[opt_refuse-1].value = 0;
2982 menus[opt_refuse-1].redraw = 1;
2983 menus[opt_refuse-2].value = 0;
2984 menus[opt_refuse-2].redraw = 1;
2988 if (menus[opt_coop].value)
2990 if ( (menus[opt_coop].value) || ((Network_game_type == APPLETALK_GAME) && (Network_appletalk_type == LOCALTALK_TYPE) && (menus[opt_coop-1].value)) )
2995 if (menus[opt_maxnet].value>2)
2997 menus[opt_maxnet].value=2;
2998 menus[opt_maxnet].redraw=1;
3001 if (menus[opt_maxnet].max_value>2)
3003 menus[opt_maxnet].max_value=2;
3004 menus[opt_maxnet].redraw=1;
3008 if ( (Network_game_type == APPLETALK_GAME) && (Network_appletalk_type == LOCALTALK_TYPE) ) {
3009 if (menus[opt_maxnet].value > 0) {
3010 menus[opt_maxnet].value=0;
3011 menus[opt_maxnet].redraw=1;
3013 if (menus[opt_maxnet].max_value > 0) {
3014 menus[opt_maxnet].max_value=0;
3015 menus[opt_maxnet].redraw=1;
3020 if (!Netgame.game_flags & NETGAME_FLAG_SHOW_MAP)
3021 Netgame.game_flags |= NETGAME_FLAG_SHOW_MAP;
3023 if (Netgame.PlayTimeAllowed || Netgame.KillGoal)
3025 Netgame.PlayTimeAllowed=0;
3030 else // if !Coop game
3035 menus[opt_maxnet].value=6;
3036 menus[opt_maxnet].max_value=6;
3039 if ( (Network_game_type == APPLETALK_GAME) && (Network_appletalk_type == LOCALTALK_TYPE) ) {
3040 menus[opt_maxnet].value=1;
3041 menus[opt_maxnet].max_value=1;
3048 if ( last_maxnet != menus[opt_maxnet].value )
3050 sprintf( menus[opt_maxnet].text, "Maximum players: %d", menus[opt_maxnet].value+2 );
3051 last_maxnet = menus[opt_maxnet].value;
3052 menus[opt_maxnet].redraw = 1;
3056 int netgame_difficulty;
3058 int network_get_game_params( char * game_name, int *mode, int *game_flags, int *level )
3061 int opt, opt_name, opt_level, opt_mode,opt_moreopts;
3063 char name[NETGAME_NAME_LEN+1];
3065 char level_text[32];
3068 int new_mission_num;
3071 *game_flags=*game_flags;
3073 SetAllAllowablesTo (1);
3074 NamesInfoSecurity=-1;
3076 for (i=0;i<MAX_PLAYERS;i++)
3078 Players[i].callsign[0]=0;
3082 Netgame.PlayTimeAllowed=0;
3083 Netgame.Allow_marker_view=1;
3084 netgame_difficulty=Player_default_difficulty;
3086 new_mission_num = multi_choose_mission(&anarchy_only);
3088 if (new_mission_num < 0)
3091 if (!(FindArg ("-packets") && FindArg ("-shortpackets")))
3092 if (!network_choose_connect ())
3096 if ( (Network_game_type == APPLETALK_GAME) && (Network_appletalk_type == LOCALTALK_TYPE) )
3097 MaxNumNetPlayers = 3;
3100 strcpy(Netgame.mission_name, Mission_list[new_mission_num].filename);
3101 strcpy(Netgame.mission_title, Mission_list[new_mission_num].mission_name);
3102 Netgame.control_invul_time = control_invul_time;
3104 sprintf( name, "%s%s", Players[Player_num].callsign, TXT_S_GAME );
3105 sprintf( slevel, "1" );
3108 m[opt].type = NM_TYPE_TEXT; m[opt].text = TXT_DESCRIPTION; opt++;
3111 m[opt].type = NM_TYPE_INPUT; m[opt].text = name; m[opt].text_len = NETGAME_NAME_LEN; opt++;
3113 sprintf(level_text, "%s (1-%d)", TXT_LEVEL_, Last_level);
3115 // if (Last_secret_level < -1)
3116 // sprintf(level_text+strlen(level_text)-1, ", S1-S%d)", -Last_secret_level);
3117 // else if (Last_secret_level == -1)
3118 // sprintf(level_text+strlen(level_text)-1, ", S1)");
3120 Assert(strlen(level_text) < 32);
3122 m[opt].type = NM_TYPE_TEXT; m[opt].text = level_text; opt++;
3125 m[opt].type = NM_TYPE_INPUT; m[opt].text = slevel; m[opt].text_len=4; opt++;
3126 // m[opt].type = NM_TYPE_TEXT; m[opt].text = TXT_OPTIONS; opt++;
3129 m[opt].type = NM_TYPE_RADIO; m[opt].text = TXT_ANARCHY; m[opt].value=1; m[opt].group=0; opt++;
3130 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++;
3131 m[opt].type = NM_TYPE_RADIO; m[opt].text = TXT_ANARCHY_W_ROBOTS; m[opt].value=0; m[opt].group=0; opt++;
3132 m[opt].type = NM_TYPE_RADIO; m[opt].text = TXT_COOPERATIVE; m[opt].value=0; m[opt].group=0; opt_coop=opt; opt++;
3133 m[opt].type = NM_TYPE_RADIO; m[opt].text = "Capture the flag"; m[opt].value=0; m[opt].group=0; opt_capture=opt; opt++;
3135 if (HoardEquipped())
3137 m[opt].type = NM_TYPE_RADIO; m[opt].text = "Hoard"; m[opt].value=0; m[opt].group=0; opt++;
3138 m[opt].type = NM_TYPE_RADIO; m[opt].text = "Team Hoard"; m[opt].value=0; m[opt].group=0; opt_team_hoard=opt; opt++;
3139 m[opt].type = NM_TYPE_TEXT; m[opt].text = ""; opt++;
3142 { m[opt].type = NM_TYPE_TEXT; m[opt].text = ""; opt++; }
3144 m[opt].type = NM_TYPE_RADIO; m[opt].text = "Open game"; m[opt].group=1; m[opt].value=0; opt++;
3146 m[opt].type = NM_TYPE_RADIO; m[opt].text = TXT_CLOSED_GAME; m[opt].group=1; m[opt].value=0; opt++;
3148 m[opt].type = NM_TYPE_RADIO; m[opt].text = "Restricted Game "; m[opt].group=1; m[opt].value=Netgame.RefusePlayers; opt++;
3150 // m[opt].type = NM_TYPE_CHECK; m[opt].text = TXT_SHOW_IDS; m[opt].value=0; opt++;
3153 sprintf( srmaxnet, "Maximum players: %d", MaxNumNetPlayers);
3154 m[opt].type = NM_TYPE_SLIDER; m[opt].value=MaxNumNetPlayers-2; m[opt].text= srmaxnet; m[opt].min_value=0;
3155 m[opt].max_value=MaxNumNetPlayers-2; opt++;
3156 last_maxnet=MaxNumNetPlayers-2;
3159 m[opt].type = NM_TYPE_MENU; m[opt].text = "More options..."; opt++;
3164 ExtGameStatus=GAMESTAT_NETGAME_OPTIONS;
3165 i = newmenu_do1( NULL, NULL, opt, m, network_game_param_poll, 1 );
3167 if (i==opt_moreopts)
3169 if ( m[opt_mode+3].value )
3170 Game_mode=GM_MULTI_COOP;
3171 network_more_game_options();
3175 Netgame.RefusePlayers=m[opt_refuse].value;
3181 MaxNumNetPlayers = m[opt_maxnet].value+2;
3182 Netgame.max_numplayers=MaxNumNetPlayers;
3184 for (j = 0; j < num_active_games; j++)
3185 if (!stricmp(Active_games[j].game_name, name))
3187 nm_messagebox(TXT_ERROR, 1, TXT_OK, TXT_DUPLICATE_NAME);
3191 strcpy( game_name, name );
3194 *level = atoi(slevel);
3196 if ((*level < 1) || (*level > Last_level))
3198 nm_messagebox(TXT_ERROR, 1, TXT_OK, TXT_LEVEL_OUT_RANGE );
3199 sprintf(slevel, "1");
3202 if ( m[opt_mode].value )
3203 *mode = NETGAME_ANARCHY;
3208 nm_messagebox(TXT_SORRY, 1, TXT_OK, TXT_REGISTERED_ONLY );
3209 m[opt_mode+1].value = 0;
3210 m[opt_mode+2].value = 0;
3211 m[opt_mode+3].value = 0;
3212 if (HoardEquipped())
3213 m[opt_mode+4].value = 0;
3215 m[opt_mode].value = 1;
3219 else if (m[opt_mode+1].value) {
3220 *mode = NETGAME_TEAM_ANARCHY;
3222 else if (m[opt_capture].value)
3223 *mode = NETGAME_CAPTURE_FLAG;
3224 else if (HoardEquipped() && m[opt_capture+1].value)
3225 *mode = NETGAME_HOARD;
3226 else if (HoardEquipped() && m[opt_capture+2].value)
3227 *mode = NETGAME_TEAM_HOARD;
3228 else if (anarchy_only) {
3229 nm_messagebox(NULL, 1, TXT_OK, TXT_ANARCHY_ONLY_MISSION);
3230 m[opt_mode+2].value = 0;
3231 m[opt_mode+3].value = 0;
3232 m[opt_mode].value = 1;
3235 else if ( m[opt_mode+2].value )
3236 *mode = NETGAME_ROBOT_ANARCHY;
3237 else if ( m[opt_mode+3].value )
3238 *mode = NETGAME_COOPERATIVE;
3239 else Int3(); // Invalid mode -- see Rob
3241 if (m[opt_closed].value)
3242 Netgame.game_flags |= NETGAME_FLAG_CLOSED;
3250 network_set_game_mode(int gamemode)
3254 if ( gamemode == NETGAME_ANARCHY )
3255 Game_mode = GM_NETWORK;
3256 else if ( gamemode == NETGAME_ROBOT_ANARCHY )
3257 Game_mode = GM_NETWORK | GM_MULTI_ROBOTS;
3258 else if ( gamemode == NETGAME_COOPERATIVE )
3259 Game_mode = GM_NETWORK | GM_MULTI_COOP | GM_MULTI_ROBOTS;
3260 else if (gamemode == NETGAME_CAPTURE_FLAG)
3262 Game_mode = GM_NETWORK | GM_TEAM | GM_CAPTURE;
3266 else if (HoardEquipped() && gamemode == NETGAME_HOARD)
3267 Game_mode = GM_NETWORK | GM_HOARD;
3268 else if (HoardEquipped() && gamemode == NETGAME_TEAM_HOARD)
3270 Game_mode = GM_NETWORK | GM_HOARD | GM_TEAM;
3273 else if ( gamemode == NETGAME_TEAM_ANARCHY )
3275 Game_mode = GM_NETWORK | GM_TEAM;
3282 #ifdef MACINTOSH // minimize players on localtalk games
3283 if ( (Network_game_type == APPLETALK_GAME) && (Network_appletalk_type == LOCALTALK_TYPE) ) {
3284 if (Game_mode & GM_MULTI_ROBOTS)
3285 MaxNumNetPlayers = 2;
3287 MaxNumNetPlayers = 3;
3289 if (Game_mode & GM_MULTI_COOP)
3290 MaxNumNetPlayers = 4;
3292 MaxNumNetPlayers = 8;
3300 network_find_game(void)
3302 // Find out whether or not there is space left on this socket
3306 Network_status = NETSTAT_BROWSING;
3308 num_active_games = 0;
3310 show_boxed_message(TXT_WAIT);
3312 network_send_game_list_request();
3313 t1 = timer_get_approx_seconds() + F1_0*3;
3315 while (timer_get_approx_seconds() < t1) // Wait 3 seconds for replies
3318 clear_boxed_message();
3320 // mprintf((0, "%s %d %s\n", TXT_FOUND, num_active_games, TXT_ACTIVE_GAMES));
3322 if (num_active_games < MAX_ACTIVE_NETGAMES)
3327 void network_read_sync_packet( netgame_info * sp, int rsinit)
3330 netgame_info tmp_info;
3334 char temp_callsign[CALLSIGN_LEN+1];
3337 if ( (Network_game_type == IPX_GAME) && (sp != &Netgame) ) { // for macintosh -- get the values unpacked to our structure format
3338 receive_netgame_packet((ubyte *)sp, &tmp_info, 0);
3344 TempPlayersInfo=&NetPlayers;
3346 // This function is now called by all people entering the netgame.
3348 // mprintf( (0, "%s %d\n", TXT_STARTING_NETGAME, sp->levelnum ));
3352 memcpy( &Netgame, sp, sizeof(netgame_info) );
3353 memcpy (&NetPlayers,TempPlayersInfo,sizeof (AllNetPlayers_info));
3356 N_players = sp->numplayers;
3357 Difficulty_level = sp->difficulty;
3358 Network_status = sp->game_status;
3360 //Assert(Function_mode != FMODE_GAME);
3364 mprintf((1, "Netgame.checksum = %d, calculated checksum = %d.\n", Netgame.segments_checksum, my_segments_checksum));
3366 if (Netgame.segments_checksum != my_segments_checksum)
3368 Network_status = NETSTAT_MENU;
3369 nm_messagebox(TXT_ERROR, 1, TXT_OK, TXT_NETLEVEL_NMATCH);
3375 // Discover my player number
3377 memcpy(temp_callsign, Players[Player_num].callsign, CALLSIGN_LEN+1);
3381 for (i=0; i<MAX_NUM_NET_PLAYERS; i++ ) {
3382 Players[i].net_kills_total = 0;
3383 // Players[i].net_killed_total = 0;
3386 for (i=0; i<N_players; i++ ) {
3387 if (Network_game_type == IPX_GAME) {
3388 if ( (!memcmp( TempPlayersInfo->players[i].network.ipx.node, My_Seq.player.network.ipx.node, 6 )) && (!stricmp( TempPlayersInfo->players[i].callsign, temp_callsign)) ) {
3389 if (Player_num!=-1) {
3390 Int3(); // Hey, we've found ourselves twice
3391 mprintf ((0,"Hey, we've found ourselves twice!\n"));
3392 Network_status = NETSTAT_MENU;
3395 change_playernum_to(i);
3398 if ( (TempPlayersInfo->players[i].network.appletalk.node == My_Seq.player.network.appletalk.node) && (!stricmp( TempPlayersInfo->players[i].callsign, temp_callsign)) ) {
3399 if (Player_num!=-1) {
3400 Int3(); // Hey, we've found ourselves twice
3401 Network_status = NETSTAT_MENU;
3404 change_playernum_to(i);
3407 memcpy( Players[i].callsign, TempPlayersInfo->players[i].callsign, CALLSIGN_LEN+1 );
3409 if (Network_game_type == IPX_GAME) {
3410 if ( (*(uint *)TempPlayersInfo->players[i].network.ipx.server) != 0 )
3411 ipx_get_local_target( TempPlayersInfo->players[i].network.ipx.server, TempPlayersInfo->players[i].network.ipx.node, Players[i].net_address );
3413 memcpy( Players[i].net_address, TempPlayersInfo->players[i].network.ipx.node, 6 );
3416 Players[i].n_packets_got=0; // How many packets we got from them
3417 Players[i].n_packets_sent=0; // How many packets we sent to them
3418 Players[i].connected = TempPlayersInfo->players[i].connected;
3419 Players[i].net_kills_total = sp->player_kills[i];
3420 Players[i].net_killed_total = sp->killed[i];
3421 if ((Network_rejoined) || (i != Player_num))
3422 Players[i].score = sp->player_score[i];
3423 for (j = 0; j < MAX_NUM_NET_PLAYERS; j++)
3425 kill_matrix[i][j] = sp->kills[i][j];
3429 if ( Player_num < 0 ) {
3430 mprintf ((0,"Bad Player_num, resetting to NETSTAT_MENU!\n"));
3431 Network_status = NETSTAT_MENU;
3435 if (Network_rejoined)
3436 for (i=0; i<N_players;i++)
3437 Players[i].net_killed_total = sp->killed[i];
3439 if (Network_rejoined) {
3440 network_process_monitor_vector(sp->monitor_vector);
3441 Players[Player_num].time_level = sp->level_time;
3444 team_kills[0] = sp->team_kills[0];
3445 team_kills[1] = sp->team_kills[1];
3447 Players[Player_num].connected = 1;
3448 NetPlayers.players[Player_num].connected = 1;
3449 NetPlayers.players[Player_num].rank=GetMyNetRanking();
3451 if (!Network_rejoined)
3452 for (i=0; i<NumNetPlayerPositions; i++) {
3453 Objects[Players[i].objnum].pos = Player_init[Netgame.locations[i]].pos;
3454 Objects[Players[i].objnum].orient = Player_init[Netgame.locations[i]].orient;
3455 obj_relink(Players[i].objnum,Player_init[Netgame.locations[i]].segnum);
3458 Objects[Players[Player_num].objnum].type = OBJ_PLAYER;
3460 mprintf ((0,"Changing to NETSTAT_PLAYING!\n"));
3461 Network_status = NETSTAT_PLAYING;
3462 Function_mode = FMODE_GAME;
3463 multi_sort_kill_list();
3468 network_send_sync(void)
3472 // Randomize their starting locations...
3474 d_srand( timer_get_fixed_seconds() );
3475 for (i=0; i<NumNetPlayerPositions; i++ )
3477 if (Players[i].connected)
3478 Players[i].connected = 1; // Get rid of endlevel connect statuses
3479 if (Game_mode & GM_MULTI_COOP)
3480 Netgame.locations[i] = i;
3484 np = d_rand() % NumNetPlayerPositions;
3485 for (j=0; j<i; j++ )
3487 if (Netgame.locations[j]==np)
3494 // np is a location that is not used anywhere else..
3495 Netgame.locations[i]=np;
3496 // mprintf((0, "Player %d starting in location %d\n" ,i ,np ));
3500 // Push current data into the sync packet
3502 network_update_netgame();
3503 Netgame.game_status = NETSTAT_PLAYING;
3504 Netgame.type = PID_SYNC;
3505 Netgame.segments_checksum = my_segments_checksum;
3507 for (i=0; i<N_players; i++ ) {
3508 if ((!Players[i].connected) || (i == Player_num))
3511 if (Network_game_type == IPX_GAME) {
3512 // Send several times, extras will be ignored
3514 ipx_send_internetwork_packet_data( (ubyte *)&Netgame, sizeof(netgame_info), NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node);
3515 ipx_send_internetwork_packet_data( (ubyte *)&NetPlayers, sizeof(AllNetPlayers_info), NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node);
3517 send_netgame_packet(NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node, NULL, 0);
3518 send_netplayers_packet(NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node);
3522 appletalk_send_packet_data( (ubyte *)&Netgame, sizeof(netgame_info), NetPlayers.players[i].network.appletalk.node,
3523 NetPlayers.players[i].network.appletalk.net,
3524 NetPlayers.players[i].network.appletalk.socket);
3525 appletalk_send_packet_data( (ubyte *)&NetPlayers, sizeof(AllNetPlayers_info), NetPlayers.players[i].network.appletalk.node,
3526 NetPlayers.players[i].network.appletalk.net,
3527 NetPlayers.players[i].network.appletalk.socket);
3532 network_read_sync_packet(&Netgame,1); // Read it myself, as if I had sent it
3536 network_select_teams(void)
3539 newmenu_item m[MAX_PLAYERS+4];
3540 int choice, opt, opt_team_b;
3541 ubyte team_vector = 0;
3542 char team_names[2][CALLSIGN_LEN+1];
3544 int pnums[MAX_PLAYERS+2];
3546 // One-time initialization
3548 for (i = N_players/2; i < N_players; i++) // Put first half of players on team A
3550 team_vector |= (1 << i);
3553 sprintf(team_names[0], "%s", TXT_BLUE);
3554 sprintf(team_names[1], "%s", TXT_RED);
3556 // Here comes da menu
3558 m[0].type = NM_TYPE_INPUT; m[0].text = team_names[0]; m[0].text_len = CALLSIGN_LEN;
3561 for (i = 0; i < N_players; i++)
3563 if (!(team_vector & (1 << i)))
3565 m[opt].type = NM_TYPE_MENU; m[opt].text = NetPlayers.players[i].callsign; pnums[opt] = i; opt++;
3569 m[opt].type = NM_TYPE_INPUT; m[opt].text = team_names[1]; m[opt].text_len = CALLSIGN_LEN; opt++;
3570 for (i = 0; i < N_players; i++)
3572 if (team_vector & (1 << i))
3574 m[opt].type = NM_TYPE_MENU; m[opt].text = NetPlayers.players[i].callsign; pnums[opt] = i; opt++;
3577 m[opt].type = NM_TYPE_TEXT; m[opt].text = ""; opt++;
3578 m[opt].type = NM_TYPE_MENU; m[opt].text = TXT_ACCEPT; opt++;
3580 Assert(opt <= MAX_PLAYERS+4);
3582 choice = newmenu_do(NULL, TXT_TEAM_SELECTION, opt, m, NULL);
3584 if (choice == opt-1)
3586 if ((opt-2-opt_team_b < 2) || (opt_team_b == 1))
3588 nm_messagebox(NULL, 1, TXT_OK, TXT_TEAM_MUST_ONE);
3594 Netgame.team_vector = team_vector;
3595 strcpy(Netgame.team_name[0], team_names[0]);
3596 strcpy(Netgame.team_name[1], team_names[1]);
3600 else if ((choice > 0) && (choice < opt_team_b)) {
3601 team_vector |= (1 << pnums[choice]);
3603 else if ((choice > opt_team_b) && (choice < opt-2)) {
3604 team_vector &= ~(1 << pnums[choice]);
3606 else if (choice == -1)
3615 network_select_players(void)
3618 newmenu_item m[MAX_PLAYERS+4];
3619 char text[MAX_PLAYERS+4][45];
3621 int save_nplayers; //how may people would like to join
3623 network_add_player( &My_Seq );
3625 for (i=0; i< MAX_PLAYERS+4; i++ ) {
3626 sprintf( text[i], "%d. %-20s", i+1, "" );
3627 m[i].type = NM_TYPE_CHECK; m[i].text = text[i]; m[i].value = 0;
3630 m[0].value = 1; // Assume server will play...
3632 if (FindArg("-norankings"))
3633 sprintf( text[0], "%d. %-20s", 1, Players[Player_num].callsign );
3635 sprintf( text[0], "%d. %s%-20s", 1, RankStrings[NetPlayers.players[Player_num].rank],Players[Player_num].callsign );
3637 sprintf( title, "%s %d %s", TXT_TEAM_SELECT, MaxNumNetPlayers, TXT_TEAM_PRESS_ENTER );
3640 ExtGameStatus=GAMESTAT_NETGAME_PLAYER_SELECT;
3641 j=newmenu_do1( NULL, title, MAX_PLAYERS+4, m, network_start_poll, 1 );
3643 save_nplayers = N_players;
3648 // Dump all players and go back to menu mode
3651 for (i=1; i<save_nplayers; i++) {
3652 if (Network_game_type == IPX_GAME)
3653 network_dump_player(NetPlayers.players[i].network.ipx.server,NetPlayers.players[i].network.ipx.node, DUMP_ABORTED);
3656 network_dump_appletalk_player(NetPlayers.players[i].network.appletalk.node,NetPlayers.players[i].network.appletalk.net, NetPlayers.players[i].network.appletalk.socket, DUMP_ABORTED);
3661 Netgame.numplayers = 0;
3662 network_send_game_info(0); // Tell everyone we're bailing
3664 Network_status = NETSTAT_MENU;
3668 // Count number of players chosen
3671 for (i=0; i<save_nplayers; i++ )
3677 if ( N_players > Netgame.max_numplayers) {
3679 nm_messagebox( TXT_ERROR, 1, TXT_OK, "%s %d %s", TXT_SORRY_ONLY, MaxNumNetPlayers, TXT_NETPLAYERS_IN );
3681 nm_messagebox( TXT_ERROR, 1, TXT_OK, "%s %d netplayers for this game.", TXT_SORRY_ONLY, MaxNumNetPlayers );
3683 N_players = save_nplayers;
3684 goto GetPlayersAgain;
3688 if ( N_players < 2 ) {
3689 nm_messagebox( TXT_ERROR, 1, TXT_OK, TXT_TEAM_ATLEAST_TWO );
3690 N_players = save_nplayers;
3691 goto GetPlayersAgain;
3696 if ( (Netgame.gamemode == NETGAME_TEAM_ANARCHY ||
3697 Netgame.gamemode == NETGAME_CAPTURE_FLAG || Netgame.gamemode == NETGAME_TEAM_HOARD) && (N_players < 2) ) {
3698 nm_messagebox(TXT_ERROR, 1, TXT_OK, "You must select at least two\nplayers to start a team game" );
3699 N_players = save_nplayers;
3700 goto GetPlayersAgain;
3704 // Remove players that aren't marked.
3706 for (i=0; i<save_nplayers; i++ ) {
3711 if (Network_game_type == IPX_GAME) {
3712 memcpy(NetPlayers.players[N_players].network.ipx.node, NetPlayers.players[i].network.ipx.node, 6);
3713 memcpy(NetPlayers.players[N_players].network.ipx.server, NetPlayers.players[i].network.ipx.server, 4);
3715 NetPlayers.players[N_players].network.appletalk.node = NetPlayers.players[i].network.appletalk.node;
3716 NetPlayers.players[N_players].network.appletalk.net = NetPlayers.players[i].network.appletalk.net;
3717 NetPlayers.players[N_players].network.appletalk.socket = NetPlayers.players[i].network.appletalk.socket;
3719 memcpy(NetPlayers.players[N_players].callsign, NetPlayers.players[i].callsign, CALLSIGN_LEN+1);
3720 NetPlayers.players[N_players].version_major=NetPlayers.players[i].version_major;
3721 NetPlayers.players[N_players].version_minor=NetPlayers.players[i].version_minor;
3722 NetPlayers.players[N_players].rank=NetPlayers.players[i].rank;
3723 ClipRank (&NetPlayers.players[N_players].rank);
3724 network_check_for_old_version(i);
3726 Players[N_players].connected = 1;
3731 if (Network_game_type == IPX_GAME)
3732 network_dump_player(NetPlayers.players[i].network.ipx.server,NetPlayers.players[i].network.ipx.node, DUMP_DORK);
3735 network_dump_appletalk_player(NetPlayers.players[i].network.appletalk.node,NetPlayers.players[i].network.appletalk.net, NetPlayers.players[i].network.appletalk.socket, DUMP_DORK);
3740 for (i = N_players; i < MAX_NUM_NET_PLAYERS; i++) {
3741 if (Network_game_type == IPX_GAME) {
3742 memset(NetPlayers.players[i].network.ipx.node, 0, 6);
3743 memset(NetPlayers.players[i].network.ipx.server, 0, 4);
3745 NetPlayers.players[i].network.appletalk.node = 0;
3746 NetPlayers.players[i].network.appletalk.net = 0;
3747 NetPlayers.players[i].network.appletalk.socket = 0;
3749 memset(NetPlayers.players[i].callsign, 0, CALLSIGN_LEN+1);
3750 NetPlayers.players[i].version_major=0;
3751 NetPlayers.players[i].version_minor=0;
3752 NetPlayers.players[i].rank=0;
3755 mprintf ((0,"Select teams: Game mode is %d\n",Netgame.gamemode));
3757 if (Netgame.gamemode == NETGAME_TEAM_ANARCHY ||
3758 Netgame.gamemode == NETGAME_CAPTURE_FLAG ||
3759 Netgame.gamemode == NETGAME_TEAM_HOARD)
3760 if (!network_select_teams())
3767 network_start_game()
3770 char game_name[NETGAME_NAME_LEN+1];
3771 int chosen_game_mode, game_flags, level;
3773 if (Network_game_type == IPX_GAME) {
3775 Assert( FRAME_INFO_SIZE < IPX_MAX_DATA_SIZE );
3776 mprintf((0, "Using frame_info len %d, max %d.\n", FRAME_INFO_SIZE, IPX_MAX_DATA_SIZE));
3778 if ( !Network_active )
3780 nm_messagebox(NULL, 1, TXT_OK, TXT_IPX_NOT_FOUND );
3788 Assert( FRAME_INFO_SIZE < APPLETALK_MAX_DATA_SIZE );
3789 mprintf((0, "Using frame_info len %d, max %d.\n", sizeof(frame_info), APPLETALK_MAX_DATA_SIZE));
3790 if (Appletalk_active <= 0) {
3791 switch (Appletalk_active) {
3792 case APPLETALK_NOT_OPEN:
3793 sprintf(buf, "Appletalk is not currently active.\nPlease enable AppleTalk from the\nChooser and restart Descent.");
3795 case APPLETALK_BAD_LISTENER:
3796 sprintf(buf, "The Resource Fork of Descent appears damaged.\nPlease re-install Descent or contact\nMacPlay technical support.");
3798 case APPLETALK_NO_LOCAL_ADDR:
3799 sprintf(buf, "Wow! Strange!\n\nNo Local Address.");
3801 case APPLETALK_NO_SOCKET:
3802 sprintf(buf, "All AppleTalk sockets are in use.\nTry shutting down other network\napplications and restarting Descent.\n");
3805 nm_messagebox(NULL, 1, TXT_OK, buf);
3808 strcpy(Network_zone_name, DEFAULT_ZONE_NAME);
3813 change_playernum_to(0);
3815 if (network_find_game())
3817 nm_messagebox(NULL, 1, TXT_OK, TXT_NET_FULL);
3822 i = network_get_game_params( game_name, &chosen_game_mode, &game_flags, &level );
3828 // LoadLevel(level); Old, no longer used.
3830 Netgame.difficulty = Difficulty_level;
3831 Netgame.gamemode = chosen_game_mode;
3832 Netgame.game_status = NETSTAT_STARTING;
3833 Netgame.numplayers = 0;
3834 Netgame.max_numplayers = MaxNumNetPlayers;
3835 Netgame.levelnum = level;
3836 Netgame.protocol_version = MULTI_PROTO_VERSION;
3838 strcpy(Netgame.game_name, game_name);
3840 Network_status = NETSTAT_STARTING;
3843 if (Network_game_type == APPLETALK_GAME) {
3848 show_boxed_message("Registering Netgame");
3850 err = appletalk_register_netgame( game_name, TickCount() );
3851 t1 = timer_get_fixed_seconds() + F1_0;
3852 while (timer_get_fixed_seconds() < t1) ;
3854 } while ( (err == nbpDuplicate) && (count != MAX_REGISTER_TRIES) );
3855 clear_boxed_message();
3856 if ( (err == tooManyReqs) || (count == MAX_REGISTER_TRIES) ) {
3857 nm_messagebox(NULL, 1, TXT_OK, "AppleTalk Network is too busy.\nPlease try again shortly.");
3858 Game_mode = GM_GAME_OVER;
3864 network_set_game_mode(Netgame.gamemode);
3866 d_srand( timer_get_fixed_seconds() );
3867 Netgame.Security=d_rand(); // For syncing Netgames with player packets
3869 if(network_select_players())
3871 StartNewLevel(Netgame.levelnum, 0);
3874 Game_mode = GM_GAME_OVER;
3878 void restart_net_searching(newmenu_item * m)
3882 num_active_games = 0;
3884 memset(Active_games, 0, sizeof(netgame_info)*MAX_ACTIVE_NETGAMES);
3886 for (i = 0; i < MAX_ACTIVE_NETGAMES; i++)
3888 sprintf(m[i+2].text, "%d. ",i+1);
3892 NamesInfoSecurity=-1;
3893 Network_games_changed = 1;
3896 char *ModeLetters[]={"ANRCHY","TEAM","ROBO","COOP","FLAG","HOARD","TMHOARD"};
3898 int NumActiveNetgames=0;
3900 void network_join_poll( int nitems, newmenu_item * menus, int * key, int citem )
3902 // Polling loop for Join Game menu
3904 int i, osocket,join_status,temp;
3911 if ( (Network_game_type == IPX_GAME) && Network_allow_socket_changes ) {
3912 osocket = Network_socket;
3914 if ( *key==KEY_PAGEDOWN ) { Network_socket--; *key = 0; }
3915 if ( *key==KEY_PAGEUP ) { Network_socket++; *key = 0; }
3917 if (Network_socket>99)
3919 if (Network_socket<-99)
3922 if ( Network_socket+IPX_DEFAULT_SOCKET > 0x8000 )
3923 Network_socket = 0x8000 - IPX_DEFAULT_SOCKET;
3925 if ( Network_socket+IPX_DEFAULT_SOCKET < 0 )
3926 Network_socket = IPX_DEFAULT_SOCKET;
3928 if (Network_socket != osocket ) {
3929 sprintf( menus[0].text, "\t%s %+d (PgUp/PgDn to change)", TXT_CURRENT_IPX_SOCKET, Network_socket );
3930 menus[0].redraw = 1;
3931 mprintf(( 0, "Changing to socket %d\n", Network_socket ));
3933 mprintf ((0,"netgood 1!\n"));
3934 ipx_change_default_socket( IPX_DEFAULT_SOCKET + Network_socket );
3935 mprintf ((0,"netgood 2!\n"));
3936 restart_net_searching(menus);
3937 mprintf ((0,"netgood 3!\n"));
3938 network_send_game_list_request();
3939 mprintf ((0,"netgood 4!\n"));
3944 // send a request for game info every 3 seconds
3946 if (Network_game_type == IPX_GAME) {
3947 if (timer_get_approx_seconds() > t1+F1_0*3) {
3948 t1 = timer_get_approx_seconds();
3949 network_send_game_list_request();
3952 } else if (timer_get_approx_seconds() > t1+F1_0*20) {
3954 t1 = timer_get_approx_seconds();
3955 restart_net_searching(menus);
3956 show_boxed_message("Requesting list of Netgames");
3957 network_send_game_list_request();
3958 clear_boxed_message();
3963 temp=num_active_games;
3967 NumActiveNetgames=num_active_games;
3969 if (!Network_games_changed)
3972 if (temp!=num_active_games)
3973 digi_play_sample (SOUND_HUD_MESSAGE,F1_0);
3975 Network_games_changed = 0;
3976 mprintf ((0,"JOIN POLL: I'm looking at %d games!\n",num_active_games));
3978 // Copy the active games data into the menu options
3979 for (i = 0; i < num_active_games; i++)
3981 int game_status = Active_games[i].game_status;
3982 int j,x, k,tx,ty,ta,nplayers = 0;
3983 char levelname[8],MissName[25],GameName[25],thold[2];
3986 // These next two loops protect against menu skewing
3987 // if missiontitle or gamename contain a tab
3989 for (x=0,tx=0,k=0,j=0;j<15;j++)
3991 if (Active_games[i].mission_title[j]=='\t')
3993 thold[0]=Active_games[i].mission_title[j];
3994 gr_get_string_size (thold,&tx,&ty,&ta);
3996 if ((x+=tx)>=LHX(55))
3998 MissName[k]=MissName[k+1]=MissName[k+2]='.';
4003 MissName[k++]=Active_games[i].mission_title[j];
4007 for (x=0,tx=0,k=0,j=0;j<15;j++)
4009 if (Active_games[i].game_name[j]=='\t')
4011 thold[0]=Active_games[i].game_name[j];
4012 gr_get_string_size (thold,&tx,&ty,&ta);
4014 if ((x+=tx)>=LHX(55))
4016 GameName[k]=GameName[k+1]=GameName[k+2]='.';
4020 GameName[k++]=Active_games[i].game_name[j];
4025 nplayers=Active_games[i].numconnected;
4027 if (Active_games[i].levelnum < 0)
4028 sprintf(levelname, "S%d", -Active_games[i].levelnum);
4030 sprintf(levelname, "%d", Active_games[i].levelnum);
4032 if (game_status == NETSTAT_STARTING)
4034 sprintf (menus[i+2].text,"%d.\t%s \t%s \t %d/%d \t%s \t %s \t%s",
4035 i+1,GameName,ModeLetters[Active_games[i].gamemode],nplayers,
4036 Active_games[i].max_numplayers,MissName,levelname,"Forming");
4038 else if (game_status == NETSTAT_PLAYING)
4040 join_status=can_join_netgame(&Active_games[i],NULL);
4041 // mprintf ((0,"Joinstatus=%d\n",join_status));
4044 sprintf (menus[i+2].text,"%d.\t%s \t%s \t %d/%d \t%s \t %s \t%s",
4045 i+1,GameName,ModeLetters[Active_games[i].gamemode],nplayers,
4046 Active_games[i].max_numplayers,MissName,levelname,"Open");
4047 else if (join_status==2)
4048 sprintf (menus[i+2].text,"%d.\t%s \t%s \t %d/%d \t%s \t %s \t%s",
4049 i+1,GameName,ModeLetters[Active_games[i].gamemode],nplayers,
4050 Active_games[i].max_numplayers,MissName,levelname,"Full");
4051 else if (join_status==3)
4052 sprintf (menus[i+2].text,"%d.\t%s \t%s \t %d/%d \t%s \t %s \t%s",
4053 i+1,GameName,ModeLetters[Active_games[i].gamemode],nplayers,
4054 Active_games[i].max_numplayers,MissName,levelname,"Restrict");
4056 sprintf (menus[i+2].text,"%d.\t%s \t%s \t %d/%d \t%s \t %s \t%s",
4057 i+1,GameName,ModeLetters[Active_games[i].gamemode],nplayers,
4058 Active_games[i].max_numplayers,MissName,levelname,"Closed");
4062 sprintf (menus[i+2].text,"%d.\t%s \t%s \t %d/%d \t%s \t %s \t%s",
4063 i+1,GameName,ModeLetters[Active_games[i].gamemode],nplayers,
4064 Active_games[i].max_numplayers,MissName,levelname,"Between");
4067 Assert(strlen(menus[i+2].text) < 100);
4068 menus[i+2].redraw = 1;
4071 for (i = num_active_games; i < MAX_ACTIVE_NETGAMES; i++)
4073 sprintf(menus[i+2].text, "%d. ",i+1);
4074 menus[i+2].redraw = 1;
4079 network_wait_for_sync(void)
4085 Network_status = NETSTAT_WAITING;
4087 m[0].type=NM_TYPE_TEXT; m[0].text = text;
4088 m[1].type=NM_TYPE_TEXT; m[1].text = TXT_NET_LEAVE;
4090 i = network_send_request();
4095 sprintf( m[0].text, "%s\n'%s' %s", TXT_NET_WAITING, NetPlayers.players[i].callsign, TXT_NET_TO_ENTER );
4098 choice=newmenu_do( NULL, TXT_WAIT, 2, m, network_sync_poll );
4103 if (Network_status != NETSTAT_PLAYING)
4107 // if (Network_status == NETSTAT_ENDLEVEL)
4109 // network_send_endlevel_packet(0);
4110 // longjmp(LeaveGame, 0);
4113 mprintf((0, "Aborting join.\n"));
4114 me.type = PID_QUIT_JOINING;
4115 memcpy( me.player.callsign, Players[Player_num].callsign, CALLSIGN_LEN+1 );
4116 if (Network_game_type == IPX_GAME) {
4117 memcpy( me.player.network.ipx.node, ipx_get_my_local_address(), 6 );
4118 memcpy( me.player.network.ipx.server, ipx_get_my_server_address(), 4 );
4120 ipx_send_internetwork_packet_data( (ubyte *)&me, sizeof(sequence_packet), NetPlayers.players[0].network.ipx.server, NetPlayers.players[0].network.ipx.node );
4122 send_sequence_packet(me, NetPlayers.players[0].network.ipx.server, NetPlayers.players[0].network.ipx.node, NULL);
4126 me.player.network.appletalk.node = appletalk_get_my_node();
4127 me.player.network.appletalk.net = appletalk_get_my_net();
4128 me.player.network.appletalk.socket = appletalk_get_my_socket();
4132 Function_mode = FMODE_MENU;
4133 Game_mode = GM_GAME_OVER;
4134 return(-1); // they cancelled
4140 network_request_poll( int nitems, newmenu_item * menus, int * key, int citem )
4142 // Polling loop for waiting-for-requests menu
4152 // Send our endlevel packet at regular intervals
4154 // if (timer_get_approx_seconds() > t1+ENDLEVEL_SEND_INTERVAL)
4156 // network_send_endlevel_packet();
4157 // t1 = timer_get_approx_seconds();
4162 for (i = 0; i < N_players; i++)
4164 if ((Players[i].connected == 1) || (Players[i].connected == 0))
4168 if (num_ready == N_players) // All players have checked in or are disconnected
4175 network_wait_for_requests(void)
4177 // Wait for other players to load the level before we send the sync
4181 Network_status = NETSTAT_WAITING;
4183 m[0].type=NM_TYPE_TEXT; m[0].text = TXT_NET_LEAVE;
4185 mprintf((0, "Entered wait_for_requests : N_players = %d.\n", N_players));
4187 for (choice = 0; choice < N_players; choice++)
4188 mprintf((0, "Players[%d].connected = %d.\n", choice, Players[choice].connected));
4190 Network_status = NETSTAT_WAITING;
4193 Players[Player_num].connected = 1;
4196 choice = newmenu_do(NULL, TXT_WAIT, 1, m, network_request_poll);
4201 choice = nm_messagebox(NULL, 3, TXT_YES, TXT_NO, TXT_START_NOWAIT, TXT_QUITTING_NOW);
4207 // User confirmed abort
4209 for (i=0; i < N_players; i++) {
4210 if ((Players[i].connected != 0) && (i != Player_num)) {
4211 if (Network_game_type == IPX_GAME)
4212 network_dump_player(NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node, DUMP_ABORTED);
4215 network_dump_appletalk_player(NetPlayers.players[i].network.appletalk.node, NetPlayers.players[i].network.appletalk.net, NetPlayers.players[i].network.appletalk.socket, DUMP_ABORTED);
4221 if (Network_game_type == APPLETALK_GAME)
4222 network_release_registered_game();
4224 longjmp(LeaveGame, 0);
4226 else if (choice != -2)
4231 network_level_sync(void)
4233 // Do required syncing between (before) levels
4237 mprintf((0, "Player %d entering network_level_sync.\n", Player_num));
4239 MySyncPackInitialized = 0;
4241 // my_segments_checksum = netmisc_calc_checksum(Segments, sizeof(segment)*(Highest_segment_index+1));
4243 network_flush(); // Flush any old packets
4246 result = network_wait_for_sync();
4247 else if (network_i_am_master())
4249 network_wait_for_requests();
4250 network_send_sync();
4254 result = network_wait_for_sync();
4256 network_count_powerups_in_mine();
4260 Players[Player_num].connected = 0;
4261 network_send_endlevel_packet();
4263 if (Network_game_type == APPLETALK_GAME)
4264 network_release_registered_game();
4266 longjmp(LeaveGame, 0);
4271 void network_count_powerups_in_mine(void)
4275 for (i=0;i<MAX_POWERUP_TYPES;i++)
4276 PowerupsInMine[i]=0;
4278 for (i=0;i<=Highest_object_index;i++)
4280 if (Objects[i].type==OBJ_POWERUP)
4282 PowerupsInMine[Objects[i].id]++;
4283 if (multi_powerup_is_4pack(Objects[i].id))
4284 PowerupsInMine[Objects[i].id-1]+=4;
4292 // code to release the NBP binding of an appletalk game
4294 void network_release_registered_game()
4296 if (Network_game_type == APPLETALK_GAME)
4297 appletalk_remove_netgame();
4300 // code to sort zone lists....
4302 int zone_sort_func(const char **e0, const char **e1)
4304 return strcmp(*e0, *e1);
4307 void network_get_appletalk_zone()
4309 int num_zones, i, item, default_item;
4311 char default_zone[MAX_ZONE_LENGTH]; // my zone
4313 Network_zone_name[0] = '\0';
4315 show_boxed_message("Looking for AppleTalk Zones");
4316 num_zones = appletalk_get_zone_names(&zone_list);
4317 clear_boxed_message();
4319 if (num_zones < 0) { // error in getting zone list...maybe no router available....
4320 if ( (num_zones == tooManyReqs) || (num_zones == noDataArea) ){
4321 nm_messagebox(NULL, 1, TXT_OK, "AppleTalk Network is too busy.\nPlease try again shortly.");
4322 longjmp(LeaveGame,0);
4327 if (num_zones == 0) {
4328 strcpy(Network_zone_name, DEFAULT_ZONE_NAME);
4332 if (num_zones == 1) {
4333 Network_zone_name[0] = (char)(strlen(zone_list[0]));
4334 memcpy( &(Network_zone_name[1]), zone_list[0], strlen(zone_list[0]) );
4338 // sort the zone names
4340 for (i = 0; i < num_zones; i++)
4341 strlwr(zone_list[i]);
4343 qsort(zone_list, num_zones, sizeof(char *), zone_sort_func);
4345 // get my current zone so we can highlight that one first
4347 if (appletalk_get_my_zone(default_zone))
4350 for (i = 0; i < num_zones; i++) {
4351 if ( !stricmp(zone_list[i], default_zone) ) {
4359 item = newmenu_listbox1("AppleTalk Zones", num_zones, zone_list, 0, default_item, NULL);
4364 Network_zone_name[0] = (char)(strlen(zone_list[item]));
4365 memcpy( &(Network_zone_name[1]), zone_list[item], strlen(zone_list[item]) );
4368 for (i = 0; i < num_zones; i++)
4369 d_free(zone_list[i]);
4374 void nm_draw_background1(char * filename);
4376 void network_join_game()
4379 char menu_text[MAX_ACTIVE_NETGAMES+2][200];
4381 newmenu_item m[MAX_ACTIVE_NETGAMES+2];
4383 if (Network_game_type == IPX_GAME) {
4384 if ( !Network_active )
4386 nm_messagebox(NULL, 1, TXT_OK, TXT_IPX_NOT_FOUND);
4390 } else if (Appletalk_active <= 0) {
4393 switch (Appletalk_active) {
4394 case APPLETALK_NOT_OPEN:
4395 sprintf(buf, "Appletalk is not currently active.\nPlease enable AppleTalk from the\nChooser and restart Descent.");
4397 case APPLETALK_BAD_LISTENER:
4398 sprintf(buf, "The Resource Fork of Descent appears damaged.\nPlease re-install Descent or contact\nMacPlay technical support.");
4400 case APPLETALK_NO_LOCAL_ADDR:
4401 sprintf(buf, "Wow! Strange!\n\nNo Local Address.");
4403 case APPLETALK_NO_SOCKET:
4404 sprintf(buf, "All AppleTalk sockets are in use.\nTry shutting down other network\napplications and restarting Descent.\n");
4407 nm_messagebox(NULL, 1, TXT_OK, buf);
4419 if (Network_game_type == APPLETALK_GAME)
4420 network_get_appletalk_zone();
4423 Network_send_objects = 0;
4424 Network_sending_extras=0;
4427 Network_status = NETSTAT_BROWSING; // We are looking at a game menu
4430 network_listen(); // Throw out old info
4433 if (Network_game_type == IPX_GAME)
4434 #endif // note link to if
4435 network_send_game_list_request(); // broadcast a request for lists
4437 num_active_games = 0;
4439 memset(m, 0, sizeof(newmenu_item)*MAX_ACTIVE_NETGAMES);
4440 memset(Active_games, 0, sizeof(netgame_info)*MAX_ACTIVE_NETGAMES);
4441 memset(ActiveNetPlayers,0,sizeof(AllNetPlayers_info)*MAX_ACTIVE_NETGAMES);
4443 gr_set_fontcolor(BM_XRGB(15,15,23),-1);
4445 m[0].text = menu_text[0];
4446 m[0].type = NM_TYPE_TEXT;
4447 if (Network_game_type == IPX_GAME) {
4448 if (Network_allow_socket_changes)
4449 sprintf( m[0].text, "\tCurrent IPX Socket is default %+d (PgUp/PgDn to change)", Network_socket );
4451 strcpy( m[0].text, "" );
4454 p2cstr(Network_zone_name);
4455 if (strcmp(Network_zone_name, "*")) // only print if there is a zone name
4456 sprintf(m[0].text, "\tCurrent Zone is %s", Network_zone_name); // is Network_zone_name a pascal string????
4457 c2pstr(Network_zone_name);
4461 m[1].text=menu_text[1];
4462 m[1].type=NM_TYPE_TEXT;
4463 sprintf (m[1].text,"\tGAME \tMODE \t#PLYRS \tMISSION \tLEV \tSTATUS");
4465 for (i = 0; i < MAX_ACTIVE_NETGAMES; i++) {
4466 m[i+2].text = menu_text[i+2];
4467 m[i+2].type = NM_TYPE_MENU;
4468 sprintf(m[i+2].text, "%d. ", i+1);
4472 Network_games_changed = 1;
4475 nm_draw_background1(Menu_pcx_name); //load this here so if we abort after loading level, we restore the palette
4476 gr_palette_load(gr_palette);
4477 ExtGameStatus=GAMESTAT_JOIN_NETGAME;
4478 choice=newmenu_dotiny("NETGAMES", NULL,MAX_ACTIVE_NETGAMES+2, m, network_join_poll);
4482 Network_status = NETSTAT_MENU;
4483 return; // they cancelled
4487 if (choice >=num_active_games)
4489 nm_messagebox(TXT_SORRY, 1, TXT_OK, TXT_INVALID_CHOICE);
4493 // Choice has been made and looks legit
4494 if (Active_games[choice].game_status == NETSTAT_ENDLEVEL)
4496 nm_messagebox(TXT_SORRY, 1, TXT_OK, TXT_NET_GAME_BETWEEN2);
4500 if (Active_games[choice].protocol_version != MULTI_PROTO_VERSION)
4502 if (Active_games[choice].protocol_version == 3) {
4504 nm_messagebox(TXT_SORRY, 1, TXT_OK, "Your version of Descent 2\nis incompatible with the\nDemo version");
4507 else if (Active_games[choice].protocol_version == 4) {
4509 nm_messagebox(TXT_SORRY, 1, TXT_OK, "This Demo version of\nDescent 2 is incompatible\nwith the full commercial version");
4513 nm_messagebox(TXT_SORRY, 1, TXT_OK, TXT_VERSION_MISMATCH);
4520 // Check for valid mission name
4521 mprintf((0, "Loading mission:%s.\n", Active_games[choice].mission_name));
4522 if (!load_mission_by_name(Active_games[choice].mission_name))
4524 nm_messagebox(NULL, 1, TXT_OK, TXT_MISSION_NOT_FOUND);
4530 #if defined (D2_OEM)
4532 if (Active_games[choice].levelnum>8)
4534 nm_messagebox(NULL, 1, TXT_OK, "This OEM version only supports\nthe first 8 levels!");
4540 if (!network_wait_for_all_info (choice))
4542 nm_messagebox (TXT_SORRY,1,TXT_OK,"There was a join error!");
4543 Network_status = NETSTAT_BROWSING; // We are looking at a game menu
4547 Network_status = NETSTAT_BROWSING; // We are looking at a game menu
4549 if (!can_join_netgame(&Active_games[choice],&ActiveNetPlayers[choice]))
4551 if (Active_games[choice].numplayers == Active_games[choice].max_numplayers)
4552 nm_messagebox(TXT_SORRY, 1, TXT_OK, TXT_GAME_FULL);
4554 nm_messagebox(TXT_SORRY, 1, TXT_OK, TXT_IN_PROGRESS);
4558 // Choice is valid, prepare to join in
4560 memcpy(&Netgame, &Active_games[choice], sizeof(netgame_info));
4561 memcpy (&NetPlayers,&ActiveNetPlayers[choice],sizeof(AllNetPlayers_info));
4563 Difficulty_level = Netgame.difficulty;
4564 MaxNumNetPlayers = Netgame.max_numplayers;
4565 change_playernum_to(1);
4569 // register the joining player with NBP. This will have the nice effect of a player wanting to
4570 // join to be able to see the netgame if this player were to become the master.
4572 if (Network_game_type == APPLETALK_GAME) {
4577 show_boxed_message("Registering Netgame");
4579 err = appletalk_register_netgame( Active_games[choice].game_name, TickCount() );
4580 t1 = timer_get_fixed_seconds() + F1_0;
4581 while ( timer_get_fixed_seconds() < t1 ) ;
4583 } while ( (err == nbpDuplicate) && (count != MAX_REGISTER_TRIES) );
4584 clear_boxed_message();
4585 if ( (err == tooManyReqs) || (count == MAX_REGISTER_TRIES) ) {
4586 nm_messagebox(NULL, 1, TXT_OK, "AppleTalk Network is too busy.\nPlease try again shortly.");
4592 network_set_game_mode(Netgame.gamemode);
4594 network_AdjustMaxDataSize ();
4596 StartNewLevel(Netgame.levelnum, 0);
4598 return; // look ma, we're in a game!!!
4601 void network_AdjustMaxDataSize ()
4604 if (Netgame.ShortPackets)
4605 MaxXDataSize=NET_XDATA_SIZE;
4607 MaxXDataSize=NET_XDATA_SIZE;
4611 fix StartWaitAllTime=0;
4612 int WaitAllChoice=0;
4613 #define ALL_INFO_REQUEST_INTERVAL F1_0*3
4615 void network_wait_all_poll( int nitems, newmenu_item * menus, int * key, int citem )
4623 if (timer_get_approx_seconds() > t1+ALL_INFO_REQUEST_INTERVAL)
4625 network_send_all_info_request(PID_SEND_ALL_GAMEINFO,SecurityCheck);
4626 t1 = timer_get_approx_seconds();
4629 network_do_big_wait(WaitAllChoice);
4631 if(SecurityCheck==-1)
4635 int network_wait_for_all_info (int choice)
4641 m[0].type=NM_TYPE_TEXT; m[0].text = "Press Escape to cancel";
4643 WaitAllChoice=choice;
4644 StartWaitAllTime=timer_get_approx_seconds();
4645 SecurityCheck=Active_games[choice].Security;
4649 pick=newmenu_do( NULL, "Connecting...", 1, m, network_wait_all_poll );
4651 if (pick>-1 && SecurityCheck!=-1)
4654 if (SecurityCheck==-1)
4663 void network_do_big_wait(int choice)
4666 ubyte packet[IPX_MAX_DATA_SIZE],*data;
4667 AllNetPlayers_info *temp_info;
4669 AllNetPlayers_info info_struct;
4670 ubyte apacket[APPLETALK_MAX_DATA_SIZE];
4674 if (Network_game_type == APPLETALK_GAME)
4675 size=appletalk_get_packet_data( apacket );
4678 size=ipx_get_packet_data( packet );
4683 if (Network_game_type == APPLETALK_GAME)
4693 if (Network_game_type == IPX_GAME) {
4695 memcpy((ubyte *)&TempNetInfo, data, sizeof(netgame_info));
4697 receive_netgame_packet(data, &TempNetInfo, 0);
4700 memcpy((ubyte *)&TempNetInfo, data, sizeof(netgame_info));
4702 mprintf ((0,"This is %s game with a security of %d\n",TempNetInfo.game_name,TempNetInfo.Security));
4704 if (TempNetInfo.Security !=SecurityCheck)
4706 mprintf ((0,"Bad security on big_wait...rejecting.\n"));
4710 if (NetSecurityFlag==NETSECURITY_WAIT_FOR_GAMEINFO)
4712 if (TempPlayersInfo->Security==TempNetInfo.Security)
4714 mprintf ((0,"EQUAL !: Game=%d Players=%d ",TempPlayersInfo->Security,TempNetInfo.Security));
4715 if (TempPlayersInfo->Security==SecurityCheck)
4717 memcpy (&Active_games[choice],(ubyte *)&TempNetInfo,sizeof(netgame_info));
4718 memcpy (&ActiveNetPlayers[choice],TempPlayersInfo,sizeof(AllNetPlayers_info));
4725 NetSecurityFlag=NETSECURITY_WAIT_FOR_PLAYERS;
4726 NetSecurityNum=TempNetInfo.Security;
4728 if (network_wait_for_playerinfo())
4730 mprintf ((0,"HUH? Game=%d Player=%d\n",NetSecurityNum,TempPlayersInfo->Security));
4731 memcpy (&Active_games[choice],(ubyte *)&TempNetInfo,sizeof(netgame_info));
4732 memcpy (&ActiveNetPlayers[choice],TempPlayersInfo,sizeof(AllNetPlayers_info));
4739 case PID_PLAYERSINFO:
4740 mprintf ((0,"Got a PID_PLAYERSINFO!\n"));
4742 if (Network_game_type == IPX_GAME) {
4744 temp_info=(AllNetPlayers_info *)data;
4746 receive_netplayers_packet(data, &info_struct);
4747 temp_info = &info_struct;
4750 temp_info = (AllNetPlayers_info *)data;
4752 if (temp_info->Security!=SecurityCheck)
4753 break; // If this isn't the guy we're looking for, move on
4755 memcpy (&TempPlayersBase,(ubyte *)&temp_info,sizeof(AllNetPlayers_info));
4756 TempPlayersInfo=&TempPlayersBase;
4757 WaitingForPlayerInfo=0;
4758 NetSecurityNum=TempPlayersInfo->Security;
4759 NetSecurityFlag=NETSECURITY_WAIT_FOR_GAMEINFO;
4765 void network_leave_game()
4769 network_do_frame(1, 1);
4772 fclose (SendLogFile);
4773 fclose (RecieveLogFile);
4776 if ((network_i_am_master()))
4778 while (Network_sending_extras>1 && Player_joining_extras!=-1)
4779 network_send_extras();
4781 Netgame.numplayers = 0;
4784 network_send_game_info(NULL);
4787 mprintf ((0,"HEY! I'm master and I've left.\n"));
4790 Players[Player_num].connected = 0;
4791 network_send_endlevel_packet();
4792 change_playernum_to(0);
4793 Game_mode = GM_GAME_OVER;
4794 write_player_file();
4796 // WIN(ipx_destroy_read_thread());
4801 void network_flush()
4804 ubyte apacket[APPLETALK_MAX_DATA_SIZE];
4806 ubyte packet[IPX_MAX_DATA_SIZE];
4809 if ( (Network_game_type == APPLETALK_GAME) && (Appletalk_active <= 0) )
4813 if ( Network_game_type == IPX_GAME )
4814 if (!Network_active) return;
4817 if (Network_game_type == APPLETALK_GAME)
4818 while (appletalk_get_packet_data(apacket) > 0) ;
4821 while (ipx_get_packet_data(packet) > 0) ;
4824 void network_listen()
4827 ubyte apacket[APPLETALK_MAX_DATA_SIZE];
4830 ubyte packet[IPX_MAX_DATA_SIZE];
4833 if (Network_status==NETSTAT_PLAYING && Netgame.ShortPackets && !Network_send_objects)
4835 loopmax=N_players*Netgame.PacketsPerSec;
4839 if ( (Network_game_type == APPLETALK_GAME) && (Appletalk_active <= 0) )
4843 if (Network_game_type == IPX_GAME)
4844 if (!Network_active) return;
4846 if (!(Game_mode & GM_NETWORK) && (Function_mode == FMODE_GAME))
4847 mprintf((0, "Calling network_listen() when not in net game.\n"));
4849 WaitingForPlayerInfo=1;
4850 NetSecurityFlag=NETSECURITY_OFF;
4853 if (Network_game_type == IPX_GAME) {
4854 size = ipx_get_packet_data( packet );
4856 network_process_packet( packet, size );
4859 size = ipx_get_packet_data( packet );
4863 size = appletalk_get_packet_data( apacket );
4865 network_process_packet( apacket, size );
4868 size = appletalk_get_packet_data( apacket );
4874 int network_wait_for_playerinfo()
4877 ubyte packet[IPX_MAX_DATA_SIZE];
4878 struct AllNetPlayers_info *TempInfo;
4882 AllNetPlayers_info info_struct;
4883 ubyte apacket[APPLETALK_MAX_DATA_SIZE];
4887 if ( (Network_game_type == APPLETALK_GAME) && (Appletalk_active <= 0) )
4891 if ( Network_game_type == IPX_GAME)
4892 if (!Network_active) return(0);
4894 // if (!WaitingForPlayerInfo)
4897 if (!(Game_mode & GM_NETWORK) && (Function_mode == FMODE_GAME))
4899 mprintf((0, "Calling network_wait_for_playerinfo() when not in net game.\n"));
4901 if (Network_status==NETSTAT_PLAYING)
4903 Int3(); //MY GOD! Get Jason...this is the source of many problems
4906 basetime=timer_get_approx_seconds();
4908 while (WaitingForPlayerInfo && retries<50 && (timer_get_approx_seconds()<(basetime+(F1_0*5))))
4910 if (Network_game_type == IPX_GAME) {
4911 size = ipx_get_packet_data( packet );
4915 size = appletalk_get_packet_data( apacket );
4920 if (size>0 && id==PID_PLAYERSINFO)
4923 if (Network_game_type == APPLETALK_GAME) {
4924 TempInfo = (AllNetPlayers_info *)apacket;
4926 receive_netplayers_packet(packet, &info_struct);
4927 TempInfo = &info_struct;
4930 TempInfo=(AllNetPlayers_info *)packet;
4935 if (NetSecurityFlag==NETSECURITY_WAIT_FOR_PLAYERS)
4937 if (NetSecurityNum==TempInfo->Security)
4939 mprintf ((0,"HEYEQUAL: Player=%d Game=%d\n",TempInfo->Security,NetSecurityNum));
4940 memcpy (&TempPlayersBase,(ubyte *)TempInfo,sizeof(AllNetPlayers_info));
4941 TempPlayersInfo=&TempPlayersBase;
4942 NetSecurityFlag=NETSECURITY_OFF;
4944 WaitingForPlayerInfo=0;
4952 mprintf ((0,"I'm original!\n"));
4954 NetSecurityNum=TempInfo->Security;
4955 NetSecurityFlag=NETSECURITY_WAIT_FOR_GAMEINFO;
4957 memcpy (&TempPlayersBase,(ubyte *)TempInfo,sizeof(AllNetPlayers_info));
4958 TempPlayersInfo=&TempPlayersBase;
4959 WaitingForPlayerInfo=0;
4968 void network_send_data( ubyte * ptr, int len, int urgent )
4974 fprintf (SendLogFile,"Packet type: %d Len:%d Urgent:%d TT=%d\n",ptr[0],len,urgent,TTSent[ptr[0]]);
4975 fflush (SendLogFile);
4978 if (Endlevel_sequence)
4981 if (!MySyncPackInitialized) {
4982 MySyncPackInitialized = 1;
4983 memset( &MySyncPack, 0, sizeof(frame_info) );
4989 if ((MySyncPack.data_size+len) > MaxXDataSize ) {
4991 network_do_frame(1, 0);
4992 if (MySyncPack.data_size != 0) {
4993 mprintf((0, "%d bytes were added to data by network_do_frame!\n", MySyncPack.data_size));
4996 // Int3(); // Trying to send too much!
4998 mprintf((0, "Packet overflow, sending additional packet, type %d len %d.\n", ptr[0], len));
4999 Assert(check == ptr[0]);
5002 Assert(MySyncPack.data_size+len <= MaxXDataSize);
5004 memcpy( &MySyncPack.data[MySyncPack.data_size], ptr, len );
5005 MySyncPack.data_size += len;
5008 void network_timeout_player(int playernum)
5010 // Remove a player from the game if we haven't heard from them in
5014 Assert(playernum < N_players);
5015 Assert(playernum > -1);
5017 network_disconnect_player(playernum);
5018 create_player_appearance_effect(&Objects[Players[playernum].objnum]);
5020 digi_play_sample(SOUND_HUD_MESSAGE, F1_0);
5022 HUD_init_message("%s %s", Players[playernum].callsign, TXT_DISCONNECTING);
5023 for (i = 0; i < N_players; i++)
5024 if (Players[i].connected)
5029 nm_messagebox(NULL, 1, TXT_OK, TXT_YOU_ARE_ONLY);
5033 fix last_send_time = 0;
5034 fix last_timeout_check = 0;
5037 void squish_short_frame_info(short_frame_info old_info, ubyte *data)
5043 data[0] = old_info.type; loc++; loc += 3; // skip three for pad byte
5044 tmpi = swapint(old_info.numpackets);
5045 memcpy(&(data[loc]), &tmpi, 4); loc += 4;
5047 memcpy(&(data[loc]), old_info.thepos.bytemat, 9); loc += 9;
5048 tmps = INTEL_SHORT(old_info.thepos.xo);
5049 memcpy(&(data[loc]), &tmps, 2); loc += 2;
5050 tmps = INTEL_SHORT(old_info.thepos.yo);
5051 memcpy(&(data[loc]), &tmps, 2); loc += 2;
5052 tmps = INTEL_SHORT(old_info.thepos.zo);
5053 memcpy(&(data[loc]), &tmps, 2); loc += 2;
5054 tmps = INTEL_SHORT(old_info.thepos.segment);
5055 memcpy(&(data[loc]), &tmps, 2); loc += 2;
5056 tmps = INTEL_SHORT(old_info.thepos.velx);
5057 memcpy(&(data[loc]), &tmps, 2); loc += 2;
5058 tmps = INTEL_SHORT(old_info.thepos.vely);
5059 memcpy(&(data[loc]), &tmps, 2); loc += 2;
5060 tmps = INTEL_SHORT(old_info.thepos.velz);
5061 memcpy(&(data[loc]), &tmps, 2); loc += 2;
5063 tmps = swapshort(old_info.data_size);
5064 memcpy(&(data[loc]), &tmps, 2); loc += 2;
5066 data[loc] = old_info.playernum; loc++;
5067 data[loc] = old_info.obj_render_type; loc++;
5068 data[loc] = old_info.level_num; loc++;
5069 memcpy(&(data[loc]), old_info.data, old_info.data_size);
5073 char NakedBuf[NET_XDATA_SIZE+4];
5074 int NakedPacketLen=0;
5075 int NakedPacketDestPlayer=-1;
5077 void network_do_frame(int force, int listen)
5080 short_frame_info ShortSyncPack;
5081 static fix LastEndlevel=0;
5083 if (!(Game_mode&GM_NETWORK)) return;
5085 if ((Network_status != NETSTAT_PLAYING) || (Endlevel_sequence)) // Don't send postion during escape sequence...
5090 Assert (NakedPacketDestPlayer>-1);
5091 // mprintf ((0,"Sending a naked packet to %s (%d bytes)!\n",Players[NakedPacketDestPlayer].callsign,NakedPacketLen));
5092 if (Network_game_type == IPX_GAME)
5093 ipx_send_packet_data( (ubyte *)NakedBuf, NakedPacketLen, NetPlayers.players[NakedPacketDestPlayer].network.ipx.server, NetPlayers.players[NakedPacketDestPlayer].network.ipx.node,Players[NakedPacketDestPlayer].net_address );
5096 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 );
5099 NakedPacketDestPlayer=-1;
5102 if (WaitForRefuseAnswer && timer_get_approx_seconds()>(RefuseTimeLimit+(F1_0*12)))
5103 WaitForRefuseAnswer=0;
5105 last_send_time += FrameTime;
5106 last_timeout_check += FrameTime;
5108 // Send out packet PacksPerSec times per second maximum... unless they fire, then send more often...
5109 if ( (last_send_time>F1_0/Netgame.PacketsPerSec) || (Network_laser_fired) || force || PacketUrgent ) {
5110 if ( Players[Player_num].connected ) {
5111 int objnum = Players[Player_num].objnum;
5115 multi_send_robot_frame(0);
5116 multi_send_fire(); // Do firing if needed..
5121 if (Netgame.ShortPackets)
5124 ubyte send_data[IPX_MAX_DATA_SIZE];
5127 create_shortpos(&ShortSyncPack.thepos, Objects+objnum, 0);
5128 ShortSyncPack.type = PID_PDATA;
5129 ShortSyncPack.playernum = Player_num;
5130 ShortSyncPack.obj_render_type = Objects[objnum].render_type;
5131 ShortSyncPack.level_num = Current_level_num;
5132 ShortSyncPack.data_size = MySyncPack.data_size;
5133 memcpy (&ShortSyncPack.data[0],&MySyncPack.data[0],MySyncPack.data_size);
5135 for (i=0; i<N_players; i++ ) {
5136 if ( (Players[i].connected) && (i!=Player_num ) ) {
5137 MySyncPack.numpackets = Players[i].n_packets_sent++;
5138 ShortSyncPack.numpackets=MySyncPack.numpackets;
5139 if (Network_game_type == IPX_GAME) {
5141 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 );
5143 squish_short_frame_info(ShortSyncPack, send_data);
5144 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 );
5148 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 );
5154 else // If long packets
5158 MySyncPack.type = PID_PDATA;
5159 MySyncPack.playernum = Player_num;
5160 MySyncPack.obj_render_type = Objects[objnum].render_type;
5161 MySyncPack.level_num = Current_level_num;
5162 MySyncPack.obj_segnum = Objects[objnum].segnum;
5163 MySyncPack.obj_pos = Objects[objnum].pos;
5164 MySyncPack.obj_orient = Objects[objnum].orient;
5165 MySyncPack.phys_velocity = Objects[objnum].mtype.phys_info.velocity;
5166 MySyncPack.phys_rotvel = Objects[objnum].mtype.phys_info.rotvel;
5168 send_data_size = MySyncPack.data_size; // do this so correct size data is sent
5170 #ifdef MACINTOSH // do the swap stuff
5171 if (Network_game_type == IPX_GAME) {
5172 MySyncPack.obj_segnum = INTEL_SHORT(MySyncPack.obj_segnum);
5173 MySyncPack.obj_pos.x = INTEL_INT((int)MySyncPack.obj_pos.x);
5174 MySyncPack.obj_pos.y = INTEL_INT((int)MySyncPack.obj_pos.y);
5175 MySyncPack.obj_pos.z = INTEL_INT((int)MySyncPack.obj_pos.z);
5177 MySyncPack.obj_orient.rvec.x = INTEL_INT((int)MySyncPack.obj_orient.rvec.x);
5178 MySyncPack.obj_orient.rvec.y = INTEL_INT((int)MySyncPack.obj_orient.rvec.y);
5179 MySyncPack.obj_orient.rvec.z = INTEL_INT((int)MySyncPack.obj_orient.rvec.z);
5180 MySyncPack.obj_orient.uvec.x = INTEL_INT((int)MySyncPack.obj_orient.uvec.x);
5181 MySyncPack.obj_orient.uvec.y = INTEL_INT((int)MySyncPack.obj_orient.uvec.y);
5182 MySyncPack.obj_orient.uvec.z = INTEL_INT((int)MySyncPack.obj_orient.uvec.z);
5183 MySyncPack.obj_orient.fvec.x = INTEL_INT((int)MySyncPack.obj_orient.fvec.x);
5184 MySyncPack.obj_orient.fvec.y = INTEL_INT((int)MySyncPack.obj_orient.fvec.y);
5185 MySyncPack.obj_orient.fvec.z = INTEL_INT((int)MySyncPack.obj_orient.fvec.z);
5187 MySyncPack.phys_velocity.x = INTEL_INT((int)MySyncPack.phys_velocity.x);
5188 MySyncPack.phys_velocity.y = INTEL_INT((int)MySyncPack.phys_velocity.y);
5189 MySyncPack.phys_velocity.z = INTEL_INT((int)MySyncPack.phys_velocity.z);
5191 MySyncPack.phys_rotvel.x = INTEL_INT((int)MySyncPack.phys_rotvel.x);
5192 MySyncPack.phys_rotvel.y = INTEL_INT((int)MySyncPack.phys_rotvel.y);
5193 MySyncPack.phys_rotvel.z = INTEL_INT((int)MySyncPack.phys_rotvel.z);
5195 MySyncPack.data_size = INTEL_SHORT(MySyncPack.data_size);
5199 for (i=0; i<N_players; i++ ) {
5200 if ( (Players[i].connected) && (i!=Player_num ) ) {
5201 if (Network_game_type == IPX_GAME)
5202 MySyncPack.numpackets = INTEL_INT(Players[i].n_packets_sent);
5205 MySyncPack.numpackets = Players[i].n_packets_sent;
5208 Players[i].n_packets_sent++;
5209 if (Network_game_type == IPX_GAME)
5210 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 );
5213 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);
5219 MySyncPack.data_size = 0; // Start data over at 0 length.
5220 if (Control_center_destroyed)
5223 Players[Player_num].connected=3;
5224 if (timer_get_approx_seconds() > (LastEndlevel+(F1_0/2)))
5226 network_send_endlevel_packet();
5227 LastEndlevel=timer_get_approx_seconds();
5230 //mprintf( (0, "Packet has %d bytes appended (TS=%d)\n", MySyncPack.data_size, sizeof(frame_info)-MaxXDataSize+MySyncPack.data_size ));
5237 if ((last_timeout_check > F1_0) && !(Control_center_destroyed))
5239 fix approx_time = timer_get_approx_seconds();
5240 // Check for player timeouts
5241 for (i = 0; i < N_players; i++)
5243 if ((i != Player_num) && (Players[i].connected == 1))
5245 if ((LastPacketTime[i] == 0) || (LastPacketTime[i] > approx_time))
5247 LastPacketTime[i] = approx_time;
5250 if ((approx_time - LastPacketTime[i]) > (15*F1_0))
5251 network_timeout_player(i);
5254 last_timeout_check = 0;
5260 MySyncPack.data_size = 0;
5265 if (VerifyPlayerJoined!=-1 && !(FrameCount & 63))
5266 resend_sync_due_to_packet_loss_for_allender(); // This will resend to network_player_rejoining
5268 if (Network_send_objects)
5269 network_send_objects();
5271 if (Network_sending_extras && VerifyPlayerJoined==-1)
5273 network_send_extras();
5278 int missed_packets = 0;
5280 int ConsistencyCount = 0;
5282 void network_consistency_error(void)
5284 if (++ConsistencyCount < 10)
5287 Function_mode = FMODE_MENU;
5289 nm_messagebox(NULL, 1, TXT_OK, TXT_CONSISTENCY_ERROR);
5291 nm_messagebox(NULL, 1, TXT_OK, "Failed to join the netgame.\nYou are missing packets. Check\nyour network connection and\ntry again.");
5293 Function_mode = FMODE_GAME;
5294 ConsistencyCount = 0;
5295 multi_quit_game = 1;
5296 multi_leave_menu = 1;
5297 multi_reset_stuff();
5298 Function_mode = FMODE_MENU;
5301 void network_process_pdata (char *data)
5303 Assert (Game_mode & GM_NETWORK);
5305 if (Netgame.ShortPackets)
5306 network_read_pdata_short_packet ((short_frame_info *)data);
5308 network_read_pdata_packet ((frame_info *)data);
5311 void network_read_pdata_packet(frame_info *pd )
5315 object * TheirObj = NULL;
5317 // frame_info should be aligned...for mac, make the necessary adjustments
5319 if (Network_game_type == IPX_GAME) {
5320 pd->numpackets = INTEL_INT(pd->numpackets);
5321 pd->obj_pos.x = INTEL_INT(pd->obj_pos.x);
5322 pd->obj_pos.y = INTEL_INT(pd->obj_pos.y);
5323 pd->obj_pos.z = INTEL_INT(pd->obj_pos.z);
5325 pd->obj_orient.rvec.x = (fix)INTEL_INT((int)pd->obj_orient.rvec.x);
5326 pd->obj_orient.rvec.y = (fix)INTEL_INT((int)pd->obj_orient.rvec.y);
5327 pd->obj_orient.rvec.z = (fix)INTEL_INT((int)pd->obj_orient.rvec.z);
5328 pd->obj_orient.uvec.x = (fix)INTEL_INT((int)pd->obj_orient.uvec.x);
5329 pd->obj_orient.uvec.y = (fix)INTEL_INT((int)pd->obj_orient.uvec.y);
5330 pd->obj_orient.uvec.z = (fix)INTEL_INT((int)pd->obj_orient.uvec.z);
5331 pd->obj_orient.fvec.x = (fix)INTEL_INT((int)pd->obj_orient.fvec.x);
5332 pd->obj_orient.fvec.y = (fix)INTEL_INT((int)pd->obj_orient.fvec.y);
5333 pd->obj_orient.fvec.z = (fix)INTEL_INT((int)pd->obj_orient.fvec.z);
5335 pd->phys_velocity.x = (fix)INTEL_INT((int)pd->phys_velocity.x);
5336 pd->phys_velocity.y = (fix)INTEL_INT((int)pd->phys_velocity.y);
5337 pd->phys_velocity.z = (fix)INTEL_INT((int)pd->phys_velocity.z);
5339 pd->phys_rotvel.x = (fix)INTEL_INT((int)pd->phys_rotvel.x);
5340 pd->phys_rotvel.y = (fix)INTEL_INT((int)pd->phys_rotvel.y);
5341 pd->phys_rotvel.z = (fix)INTEL_INT((int)pd->phys_rotvel.z);
5343 pd->obj_segnum = INTEL_SHORT(pd->obj_segnum);
5344 pd->data_size = INTEL_SHORT(pd->data_size);
5348 TheirPlayernum = pd->playernum;
5349 TheirObjnum = Players[pd->playernum].objnum;
5351 if (TheirPlayernum < 0) {
5352 Int3(); // This packet is bogus!!
5356 if (VerifyPlayerJoined!=-1 && TheirPlayernum==VerifyPlayerJoined)
5358 // Hurray! Someone really really got in the game (I think).
5359 mprintf ((0,"Hurray! VPJ (%d) reset!\n",VerifyPlayerJoined));
5360 VerifyPlayerJoined=-1;
5363 if (!multi_quit_game && (TheirPlayernum >= N_players)) {
5364 if (Network_status!=NETSTAT_WAITING)
5366 Int3(); // We missed an important packet!
5367 network_consistency_error();
5373 if (Endlevel_sequence || (Network_status == NETSTAT_ENDLEVEL) ) {
5374 int old_Endlevel_sequence = Endlevel_sequence;
5375 Endlevel_sequence = 1;
5376 if ( pd->data_size>0 ) {
5377 // pass pd->data to some parser function....
5378 multi_process_bigdata( pd->data, pd->data_size );
5380 Endlevel_sequence = old_Endlevel_sequence;
5383 // mprintf((0, "Gametime = %d, Frametime = %d.\n", GameTime, FrameTime));
5385 if ((byte)pd->level_num != Current_level_num)
5387 mprintf((0, "Got frame packet from player %d wrong level %d!\n", pd->playernum, pd->level_num));
5391 TheirObj = &Objects[TheirObjnum];
5393 //------------- Keep track of missed packets -----------------
5394 Players[TheirPlayernum].n_packets_got++;
5396 LastPacketTime[TheirPlayernum] = timer_get_approx_seconds();
5398 if ( pd->numpackets != Players[TheirPlayernum].n_packets_got ) {
5401 missed_packets = pd->numpackets-Players[TheirPlayernum].n_packets_got;
5402 if ((pd->numpackets-Players[TheirPlayernum].n_packets_got)>0)
5403 TotalMissedPackets += pd->numpackets-Players[TheirPlayernum].n_packets_got;
5405 if ( missed_packets > 0 )
5406 mprintf(( 0, "Missed %d packets from player #%d (%d total)\n", pd->numpackets-Players[TheirPlayernum].n_packets_got, TheirPlayernum, missed_packets ));
5408 mprintf( (0, "Got %d late packets from player #%d (%d total)\n", Players[TheirPlayernum].n_packets_got-pd->numpackets, TheirPlayernum, missed_packets ));
5411 #ifdef APPLETALK_DEBUG
5412 if (Network_game_type == APPLETALK_GAME) {
5413 if ( missed_packets > 0 )
5414 fprintf( at_fp, "Missed %d packets from player #%d (%d total)\n", pd->numpackets-Players[TheirPlayernum].n_packets_got, TheirPlayernum, missed_packets );
5416 fprintf( at_fp, "Got %d late packets from player #%d (%d total)\n", Players[TheirPlayernum].n_packets_got-pd->numpackets, TheirPlayernum, missed_packets );
5421 if (Network_game_type == IPX_GAME) {
5422 if ( missed_packets > 0 )
5423 fprintf( ipx_fp, "Missed %d packets from player #%d (%d total)\n", pd->numpackets-Players[TheirPlayernum].n_packets_got, TheirPlayernum, missed_packets );
5425 fprintf( ipx_fp, "Got %d late packets from player #%d (%d total)\n", Players[TheirPlayernum].n_packets_got-pd->numpackets, TheirPlayernum, missed_packets );
5430 Players[TheirPlayernum].n_packets_got = pd->numpackets;
5433 //------------ Read the player's ship's object info ----------------------
5434 TheirObj->pos = pd->obj_pos;
5435 TheirObj->orient = pd->obj_orient;
5436 TheirObj->mtype.phys_info.velocity = pd->phys_velocity;
5437 TheirObj->mtype.phys_info.rotvel = pd->phys_rotvel;
5439 if ((TheirObj->render_type != pd->obj_render_type) && (pd->obj_render_type == RT_POLYOBJ))
5440 multi_make_ghost_player(TheirPlayernum);
5442 obj_relink(TheirObjnum,pd->obj_segnum);
5444 if (TheirObj->movement_type == MT_PHYSICS)
5445 set_thrust_from_velocity(TheirObj);
5447 //------------ Welcome them back if reconnecting --------------
5448 if (!Players[TheirPlayernum].connected) {
5449 Players[TheirPlayernum].connected = 1;
5451 if (Newdemo_state == ND_STATE_RECORDING)
5452 newdemo_record_multi_reconnect(TheirPlayernum);
5454 multi_make_ghost_player(TheirPlayernum);
5456 create_player_appearance_effect(&Objects[TheirObjnum]);
5458 digi_play_sample( SOUND_HUD_MESSAGE, F1_0);
5460 ClipRank (&NetPlayers.players[TheirPlayernum].rank);
5462 if (FindArg("-norankings"))
5463 HUD_init_message( "'%s' %s", Players[TheirPlayernum].callsign, TXT_REJOIN );
5465 HUD_init_message( "%s'%s' %s", RankStrings[NetPlayers.players[TheirPlayernum].rank],Players[TheirPlayernum].callsign, TXT_REJOIN );
5471 //------------ Parse the extra data at the end ---------------
5473 if ( pd->data_size>0 ) {
5474 // pass pd->data to some parser function....
5475 multi_process_bigdata( pd->data, pd->data_size );
5481 void get_short_frame_info(ubyte *old_info, short_frame_info *new_info)
5485 new_info->type = old_info[loc]; loc++; loc += 3; // skip three for pad byte
5486 memcpy(&(new_info->numpackets), &(old_info[loc]), 4); loc += 4;
5487 new_info->numpackets = INTEL_INT(new_info->numpackets);
5488 memcpy(new_info->thepos.bytemat, &(old_info[loc]), 9); loc += 9;
5489 memcpy(&(new_info->thepos.xo), &(old_info[loc]), 2); loc += 2;
5490 memcpy(&(new_info->thepos.yo), &(old_info[loc]), 2); loc += 2;
5491 memcpy(&(new_info->thepos.zo), &(old_info[loc]), 2); loc += 2;
5492 memcpy(&(new_info->thepos.segment), &(old_info[loc]), 2); loc += 2;
5493 memcpy(&(new_info->thepos.velx), &(old_info[loc]), 2); loc += 2;
5494 memcpy(&(new_info->thepos.vely), &(old_info[loc]), 2); loc += 2;
5495 memcpy(&(new_info->thepos.velz), &(old_info[loc]), 2); loc += 2;
5496 new_info->thepos.xo = INTEL_SHORT(new_info->thepos.xo);
5497 new_info->thepos.yo = INTEL_SHORT(new_info->thepos.yo);
5498 new_info->thepos.zo = INTEL_SHORT(new_info->thepos.zo);
5499 new_info->thepos.segment = INTEL_SHORT(new_info->thepos.segment);
5500 new_info->thepos.velx = INTEL_SHORT(new_info->thepos.velx);
5501 new_info->thepos.vely = INTEL_SHORT(new_info->thepos.vely);
5502 new_info->thepos.velz = INTEL_SHORT(new_info->thepos.velz);
5504 memcpy(&(new_info->data_size), &(old_info[loc]), 2); loc += 2;
5505 new_info->data_size = INTEL_SHORT(new_info->data_size);
5506 new_info->playernum = old_info[loc]; loc++;
5507 new_info->obj_render_type = old_info[loc]; loc++;
5508 new_info->level_num = old_info[loc]; loc++;
5509 memcpy(new_info->data, &(old_info[loc]), new_info->data_size);
5513 void network_read_pdata_short_packet(short_frame_info *pd )
5517 object * TheirObj = NULL;
5518 short_frame_info new_pd;
5520 // short frame info is not aligned because of shortpos. The mac
5521 // will call totally hacked and gross function to fix this up.
5523 if (Network_game_type == IPX_GAME) {
5525 memcpy(&new_pd, (ubyte *)pd, sizeof(short_frame_info));
5527 get_short_frame_info((ubyte *)pd, &new_pd);
5530 memcpy(&new_pd, (ubyte *)pd, sizeof(short_frame_info));
5533 TheirPlayernum = new_pd.playernum;
5534 TheirObjnum = Players[new_pd.playernum].objnum;
5536 if (TheirPlayernum < 0) {
5537 Int3(); // This packet is bogus!!
5540 if (!multi_quit_game && (TheirPlayernum >= N_players)) {
5541 if (Network_status!=NETSTAT_WAITING)
5543 Int3(); // We missed an important packet!
5544 network_consistency_error();
5551 if (VerifyPlayerJoined!=-1 && TheirPlayernum==VerifyPlayerJoined)
5553 // Hurray! Someone really really got in the game (I think).
5554 mprintf ((0,"Hurray! VPJ (%d) reset!\n",VerifyPlayerJoined));
5555 VerifyPlayerJoined=-1;
5558 if (Endlevel_sequence || (Network_status == NETSTAT_ENDLEVEL) ) {
5559 int old_Endlevel_sequence = Endlevel_sequence;
5560 Endlevel_sequence = 1;
5561 if ( new_pd.data_size>0 ) {
5562 // pass pd->data to some parser function....
5563 multi_process_bigdata( new_pd.data, new_pd.data_size );
5565 Endlevel_sequence = old_Endlevel_sequence;
5568 // mprintf((0, "Gametime = %d, Frametime = %d.\n", GameTime, FrameTime));
5570 if ((byte)new_pd.level_num != Current_level_num)
5572 mprintf((0, "Got frame packet from player %d wrong level %d!\n", new_pd.playernum, new_pd.level_num));
5576 TheirObj = &Objects[TheirObjnum];
5578 //------------- Keep track of missed packets -----------------
5579 Players[TheirPlayernum].n_packets_got++;
5581 LastPacketTime[TheirPlayernum] = timer_get_approx_seconds();
5583 if ( new_pd.numpackets != Players[TheirPlayernum].n_packets_got ) {
5586 missed_packets = new_pd.numpackets-Players[TheirPlayernum].n_packets_got;
5587 if ((new_pd.numpackets-Players[TheirPlayernum].n_packets_got)>0)
5588 TotalMissedPackets += new_pd.numpackets-Players[TheirPlayernum].n_packets_got;
5590 if ( missed_packets > 0 )
5591 mprintf( (0, "Missed %d packets from player #%d (%d total)\n", new_pd.numpackets-Players[TheirPlayernum].n_packets_got, TheirPlayernum, missed_packets ));
5593 mprintf( (0, "Got %d late packets from player #%d (%d total)\n", Players[TheirPlayernum].n_packets_got-new_pd.numpackets, TheirPlayernum, missed_packets ));
5595 Players[TheirPlayernum].n_packets_got = new_pd.numpackets;
5598 //------------ Read the player's ship's object info ----------------------
5600 extract_shortpos(TheirObj, &new_pd.thepos, 0);
5602 if ((TheirObj->render_type != new_pd.obj_render_type) && (new_pd.obj_render_type == RT_POLYOBJ))
5603 multi_make_ghost_player(TheirPlayernum);
5605 if (TheirObj->movement_type == MT_PHYSICS)
5606 set_thrust_from_velocity(TheirObj);
5608 //------------ Welcome them back if reconnecting --------------
5609 if (!Players[TheirPlayernum].connected) {
5610 Players[TheirPlayernum].connected = 1;
5612 if (Newdemo_state == ND_STATE_RECORDING)
5613 newdemo_record_multi_reconnect(TheirPlayernum);
5615 multi_make_ghost_player(TheirPlayernum);
5617 create_player_appearance_effect(&Objects[TheirObjnum]);
5619 digi_play_sample( SOUND_HUD_MESSAGE, F1_0);
5620 ClipRank (&NetPlayers.players[TheirPlayernum].rank);
5622 if (FindArg("-norankings"))
5623 HUD_init_message( "'%s' %s", Players[TheirPlayernum].callsign, TXT_REJOIN );
5625 HUD_init_message( "%s'%s' %s", RankStrings[NetPlayers.players[TheirPlayernum].rank],Players[TheirPlayernum].callsign, TXT_REJOIN );
5631 //------------ Parse the extra data at the end ---------------
5633 if ( new_pd.data_size>0 ) {
5634 // pass pd->data to some parser function....
5635 multi_process_bigdata( new_pd.data, new_pd.data_size );
5641 void network_set_power (void)
5643 int opt=0,choice,opt_primary,opt_second,opt_power;
5647 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Laser upgrade"; m[opt].value=Netgame.DoLaserUpgrade; opt++;
5648 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Super lasers"; m[opt].value=Netgame.DoSuperLaser; opt++;
5649 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Quad Lasers"; m[opt].value=Netgame.DoQuadLasers; opt++;
5650 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Vulcan cannon"; m[opt].value=Netgame.DoVulcan; opt++;
5651 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Spreadfire cannon"; m[opt].value=Netgame.DoSpread; opt++;
5652 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Plasma cannon"; m[opt].value=Netgame.DoPlasma; opt++;
5653 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Fusion cannon"; m[opt].value=Netgame.DoFusions; opt++;
5654 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Gauss cannon"; m[opt].value=Netgame.DoGauss; opt++;
5655 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Helix cannon"; m[opt].value=Netgame.DoHelix; opt++;
5656 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Phoenix cannon"; m[opt].value=Netgame.DoPhoenix; opt++;
5657 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Omega cannon"; m[opt].value=Netgame.DoOmega; opt++;
5660 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Homing Missiles"; m[opt].value=Netgame.DoHoming; opt++;
5661 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Proximity Bombs"; m[opt].value=Netgame.DoProximity; opt++;
5662 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Smart Missiles"; m[opt].value=Netgame.DoSmarts; opt++;
5663 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Mega Missiles"; m[opt].value=Netgame.DoMegas; opt++;
5664 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Flash Missiles"; m[opt].value=Netgame.DoFlash; opt++;
5665 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Guided Missiles"; m[opt].value=Netgame.DoGuided; opt++;
5666 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Smart Mines"; m[opt].value=Netgame.DoSmartMine; opt++;
5667 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Mercury Missiles"; m[opt].value=Netgame.DoMercury; opt++;
5668 m[opt].type = NM_TYPE_CHECK; m[opt].text = "EarthShaker Missiles"; m[opt].value=Netgame.DoEarthShaker; opt++;
5671 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Invulnerability"; m[opt].value=Netgame.DoInvulnerability; opt++;
5672 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Cloaking"; m[opt].value=Netgame.DoCloak; opt++;
5673 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Afterburners"; m[opt].value=Netgame.DoAfterburner; opt++;
5674 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Ammo rack"; m[opt].value=Netgame.DoAmmoRack; opt++;
5675 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Energy Converter"; m[opt].value=Netgame.DoConverter; opt++;
5676 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Headlight"; m[opt].value=Netgame.DoHeadlight; opt++;
5678 choice = newmenu_do(NULL, "Objects to allow", opt, m, NULL);
5680 Netgame.DoLaserUpgrade=m[opt_primary].value;
5681 Netgame.DoSuperLaser=m[opt_primary+1].value;
5682 Netgame.DoQuadLasers=m[opt_primary+2].value;
5683 Netgame.DoVulcan=m[opt_primary+3].value;
5684 Netgame.DoSpread=m[opt_primary+4].value;
5685 Netgame.DoPlasma=m[opt_primary+5].value;
5686 Netgame.DoFusions=m[opt_primary+6].value;
5687 Netgame.DoGauss=m[opt_primary+7].value;
5688 Netgame.DoHelix=m[opt_primary+8].value;
5689 Netgame.DoPhoenix=m[opt_primary+9].value;
5690 Netgame.DoOmega=m[opt_primary+10].value;
5692 Netgame.DoHoming=m[opt_second].value;
5693 Netgame.DoProximity=m[opt_second+1].value;
5694 Netgame.DoSmarts=m[opt_second+2].value;
5695 Netgame.DoMegas=m[opt_second+3].value;
5696 Netgame.DoFlash=m[opt_second+4].value;
5697 Netgame.DoGuided=m[opt_second+5].value;
5698 Netgame.DoSmartMine=m[opt_second+6].value;
5699 Netgame.DoMercury=m[opt_second+7].value;
5700 Netgame.DoEarthShaker=m[opt_second+8].value;
5702 Netgame.DoInvulnerability=m[opt_power].value;
5703 Netgame.DoCloak=m[opt_power+1].value;
5704 Netgame.DoAfterburner=m[opt_power+2].value;
5705 Netgame.DoAmmoRack=m[opt_power+3].value;
5706 Netgame.DoConverter=m[opt_power+4].value;
5707 Netgame.DoHeadlight=m[opt_power+5].value;
5711 void SetAllAllowablesTo (int on)
5713 last_cinvul = control_invul_time = 0; //default to zero
5715 Netgame.DoMegas=Netgame.DoSmarts=Netgame.DoFusions=Netgame.DoHelix=\
5716 Netgame.DoPhoenix=Netgame.DoCloak=Netgame.DoInvulnerability=\
5717 Netgame.DoAfterburner=Netgame.DoGauss=Netgame.DoVulcan=Netgame.DoPlasma=on;
5719 Netgame.DoOmega=Netgame.DoSuperLaser=Netgame.DoProximity=\
5720 Netgame.DoSpread=Netgame.DoMercury=Netgame.DoSmartMine=Netgame.DoFlash=\
5721 Netgame.DoGuided=Netgame.DoEarthShaker=on;
5723 Netgame.DoConverter=Netgame.DoAmmoRack=Netgame.DoHeadlight=on;
5724 Netgame.DoHoming=Netgame.DoLaserUpgrade=Netgame.DoQuadLasers=on;
5725 Netgame.BrightPlayers=Netgame.invul=on;
5731 // Jeez -- mac compiler can't handle all of these on the same decl line.
5732 int opt_setpower,opt_playtime,opt_killgoal,opt_socket,opt_marker_view,opt_light,opt_show_on_map;
5733 int opt_difficulty,opt_packets,opt_short_packets, opt_bright,opt_start_invul;
5736 void network_more_options_poll( int nitems, newmenu_item * menus, int * key, int citem );
5738 void network_more_game_options ()
5741 char PlayText[80],KillText[80],srinvul[50],socket_string[5],packstring[5];
5744 sprintf (socket_string,"%d",Network_socket);
5745 sprintf (packstring,"%d",Netgame.PacketsPerSec);
5747 opt_difficulty = opt;
5748 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++;
5751 sprintf( srinvul, "%s: %d %s", TXT_REACTOR_LIFE, control_invul_time*5, TXT_MINUTES_ABBREV );
5752 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++;
5755 sprintf( PlayText, "Max time: %d %s", Netgame.PlayTimeAllowed*5, TXT_MINUTES_ABBREV );
5756 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++;
5759 sprintf( KillText, "Kill Goal: %d kills", Netgame.KillGoal*5);
5760 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++;
5762 opt_start_invul=opt;
5763 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Invulnerable when reappearing"; m[opt].value=Netgame.invul; opt++;
5765 opt_marker_view = opt;
5766 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Allow camera views from Markers"; m[opt].value=Netgame.Allow_marker_view; opt++;
5768 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Indestructible lights"; m[opt].value=Netgame.AlwaysLighting; opt++;
5771 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Bright player ships"; m[opt].value=Netgame.BrightPlayers; opt++;
5774 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Show enemy names on HUD"; m[opt].value=Netgame.ShowAllNames; opt++;
5776 opt_show_on_map=opt;
5777 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++;
5779 opt_short_packets=opt;
5780 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Short packets"; m[opt].value=Netgame.ShortPackets; opt++;
5783 m[opt].type = NM_TYPE_MENU; m[opt].text = "Set Objects allowed..."; opt++;
5785 if (Network_game_type == IPX_GAME) {
5786 m[opt].type = NM_TYPE_TEXT; m[opt].text = "Network socket"; opt++;
5788 m[opt].type = NM_TYPE_INPUT; m[opt].text = socket_string; m[opt].text_len=4; opt++;
5791 m[opt].type = NM_TYPE_TEXT; m[opt].text = "Packets per second (2 - 20)"; opt++;
5793 m[opt].type = NM_TYPE_INPUT; m[opt].text=packstring; m[opt].text_len=2; opt++;
5795 LastKillGoal=Netgame.KillGoal;
5796 LastPTA=Netgame.PlayTimeAllowed;
5800 ExtGameStatus=GAMESTAT_MORE_NETGAME_OPTIONS;
5801 i = newmenu_do1( NULL, "Additional netgame options", opt, m, network_more_options_poll, 0 );
5803 //control_invul_time = atoi( srinvul )*60*F1_0;
5804 control_invul_time = m[opt_cinvul].value;
5805 Netgame.control_invul_time = control_invul_time*5*F1_0*60;
5807 if (i==opt_setpower)
5809 network_set_power ();
5813 Netgame.PacketsPerSec=atoi(packstring);
5815 if (Netgame.PacketsPerSec>20)
5817 Netgame.PacketsPerSec=20;
5818 nm_messagebox(TXT_ERROR, 1, TXT_OK, "Packet value out of range\nSetting value to 20");
5820 if (Netgame.PacketsPerSec<2)
5822 nm_messagebox(TXT_ERROR, 1, TXT_OK, "Packet value out of range\nSetting value to 2");
5823 Netgame.PacketsPerSec=2;
5826 mprintf ((0,"Hey! Sending out %d packets per second\n",Netgame.PacketsPerSec));
5828 if (Network_game_type == IPX_GAME) {
5829 if ((atoi(socket_string))!=Network_socket) {
5830 Network_socket=atoi(socket_string);
5831 ipx_change_default_socket( IPX_DEFAULT_SOCKET + Network_socket );
5835 Netgame.invul=m[opt_start_invul].value;
5836 Netgame.BrightPlayers=m[opt_bright].value;
5837 Netgame.ShortPackets=m[opt_short_packets].value;
5838 Netgame.ShowAllNames=m[opt_show_names].value;
5839 network_AdjustMaxDataSize();
5841 Netgame.Allow_marker_view=m[opt_marker_view].value;
5842 Netgame.AlwaysLighting=m[opt_light].value;
5843 netgame_difficulty=Difficulty_level = m[opt_difficulty].value;
5844 if (m[opt_show_on_map].value)
5845 Netgame.game_flags |= NETGAME_FLAG_SHOW_MAP;
5850 void network_more_options_poll( int nitems, newmenu_item * menus, int * key, int citem )
5853 citem = citem; // kills compile warnings
5857 if ( last_cinvul != menus[opt_cinvul].value ) {
5858 sprintf( menus[opt_cinvul].text, "%s: %d %s", TXT_REACTOR_LIFE, menus[opt_cinvul].value*5, TXT_MINUTES_ABBREV );
5859 last_cinvul = menus[opt_cinvul].value;
5860 menus[opt_cinvul].redraw = 1;
5863 if (menus[opt_playtime].value!=LastPTA)
5867 nm_messagebox ("Sorry",1,TXT_OK,"Registered version only!");
5868 menus[opt_playtime].value=0;
5869 menus[opt_playtime].redraw=1;
5873 if (Game_mode & GM_MULTI_COOP)
5876 nm_messagebox ("Sorry",1,TXT_OK,"You can't change those for coop!");
5877 menus[opt_playtime].value=0;
5878 menus[opt_playtime].redraw=1;
5882 Netgame.PlayTimeAllowed=menus[opt_playtime].value;
5883 sprintf( menus[opt_playtime].text, "Max Time: %d %s", Netgame.PlayTimeAllowed*5, TXT_MINUTES_ABBREV );
5884 LastPTA=Netgame.PlayTimeAllowed;
5885 menus[opt_playtime].redraw=1;
5887 if (menus[opt_killgoal].value!=LastKillGoal)
5890 nm_messagebox ("Sorry",1,TXT_OK,"Registered version only!");
5891 menus[opt_killgoal].value=0;
5892 menus[opt_killgoal].redraw=1;
5898 if (Game_mode & GM_MULTI_COOP)
5900 nm_messagebox ("Sorry",1,TXT_OK,"You can't change those for coop!");
5901 menus[opt_killgoal].value=0;
5902 menus[opt_killgoal].redraw=1;
5908 Netgame.KillGoal=menus[opt_killgoal].value;
5909 sprintf( menus[opt_killgoal].text, "Kill Goal: %d kills", Netgame.KillGoal*5);
5910 LastKillGoal=Netgame.KillGoal;
5911 menus[opt_killgoal].redraw=1;
5915 extern void multi_send_light (int,ubyte);
5916 extern void multi_send_light_specific (int,int,ubyte);
5918 void network_send_smash_lights (int pnum)
5920 // send the lights that have been blown out
5926 for (i=0;i<=Highest_segment_index;i++)
5927 if (Light_subtracted[i])
5928 multi_send_light_specific(pnum,i,Light_subtracted[i]);
5931 extern int Num_triggers;
5932 extern void multi_send_trigger_specific (char pnum,char);
5934 void network_send_fly_thru_triggers (int pnum)
5936 // send the fly thru triggers that have been disabled
5940 for (i=0;i<Num_triggers;i++)
5941 if (Triggers[i].flags & TF_DISABLED)
5942 multi_send_trigger_specific(pnum,i);
5945 void network_send_player_flags()
5949 for (i=0;i<N_players;i++)
5950 multi_send_flags(i);
5953 void network_ping (ubyte flag,int pnum)
5958 mybuf[1]=Player_num;
5960 if (Network_game_type == IPX_GAME)
5961 ipx_send_packet_data( (ubyte *)mybuf, 2, NetPlayers.players[pnum].network.ipx.server, NetPlayers.players[pnum].network.ipx.node,Players[pnum].net_address );
5964 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);
5968 extern fix PingLaunchTime,PingReturnTime;
5970 void network_handle_ping_return (ubyte pnum)
5972 if (PingLaunchTime==0 || pnum>=N_players)
5974 mprintf ((0,"Got invalid PING RETURN from %s!\n",Players[pnum].callsign));
5978 PingReturnTime=timer_get_fixed_seconds();
5980 HUD_init_message ("Ping time for %s is %d ms!",Players[pnum].callsign,
5981 f2i(fixmul(PingReturnTime-PingLaunchTime,i2f(1000))));
5985 void network_send_ping (ubyte pnum)
5987 network_ping (PID_PING_SEND,pnum);
5990 void DoRefuseStuff (sequence_packet *their)
5992 int i,new_player_num;
5994 ClipRank (&their->player.rank);
5996 for (i=0;i<MAX_PLAYERS;i++)
5997 if (!strcmp (their->player.callsign,Players[i].callsign))
5999 network_welcome_player(their);
6003 if (!WaitForRefuseAnswer)
6005 for (i=0;i<MAX_PLAYERS;i++)
6006 if (!strcmp (their->player.callsign,Players[i].callsign))
6008 network_welcome_player(their);
6012 digi_play_sample (SOUND_HUD_JOIN_REQUEST,F1_0*2);
6014 if (Game_mode & GM_TEAM)
6018 if (!FindArg("-norankings"))
6019 HUD_init_message ("%s %s wants to join",RankStrings[their->player.rank],their->player.callsign);
6021 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]);
6023 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]);
6025 // HUD_init_message ("Alt-1 to place on team %s!",Netgame.team_name[0]);
6026 // HUD_init_message ("Alt-2 to place on team %s!",Netgame.team_name[1]);
6029 HUD_init_message ("%s wants to join...press F6 to connect",their->player.callsign);
6031 strcpy (RefusePlayerName,their->player.callsign);
6032 RefuseTimeLimit=timer_get_approx_seconds();
6034 WaitForRefuseAnswer=1;
6038 for (i=0;i<MAX_PLAYERS;i++)
6039 if (!strcmp (their->player.callsign,Players[i].callsign))
6041 network_welcome_player(their);
6045 if (strcmp(their->player.callsign,RefusePlayerName))
6048 if (RefuseThisPlayer)
6052 WaitForRefuseAnswer=0;
6053 if (Game_mode & GM_TEAM)
6055 new_player_num=GetNewPlayerNumber (their);
6056 mprintf ((0,"Newplayernum=%d\n",new_player_num));
6058 Assert (RefuseTeam==1 || RefuseTeam==2);
6061 Netgame.team_vector &=(~(1<<new_player_num));
6063 Netgame.team_vector |=(1<<new_player_num);
6064 network_welcome_player(their);
6065 network_send_netgame_update ();
6068 network_welcome_player(their);
6072 if ((timer_get_approx_seconds()) > RefuseTimeLimit+REFUSE_INTERVAL)
6076 WaitForRefuseAnswer=0;
6077 if (!strcmp (their->player.callsign,RefusePlayerName)) {
6078 if (Network_game_type == IPX_GAME)
6079 network_dump_player(their->player.network.ipx.server,their->player.network.ipx.node, DUMP_DORK);
6082 network_dump_appletalk_player(their->player.network.appletalk.node,their->player.network.appletalk.net, their->player.network.appletalk.socket, DUMP_DORK);
6091 int GetNewPlayerNumber (sequence_packet *their)
6097 if ( N_players < MaxNumNetPlayers)
6102 // Slots are full but game is open, see if anyone is
6103 // disconnected and replace the oldest player with this new one
6105 int oldest_player = -1;
6106 fix oldest_time = timer_get_approx_seconds();
6108 Assert(N_players == MaxNumNetPlayers);
6110 for (i = 0; i < N_players; i++)
6112 if ( (!Players[i].connected) && (LastPacketTime[i] < oldest_time))
6114 oldest_time = LastPacketTime[i];
6118 return (oldest_player);
6122 void network_send_extras ()
6124 Assert (Player_joining_extras>-1);
6126 if (!network_i_am_master())
6128 mprintf ((0,"Hey! I'm not the master and I was gonna send info!\n"));
6130 // Network_sending_extras=0;
6135 if (Network_sending_extras==40)
6136 network_send_fly_thru_triggers(Player_joining_extras);
6137 if (Network_sending_extras==38)
6138 network_send_door_updates(Player_joining_extras);
6139 if (Network_sending_extras==35)
6140 network_send_markers();
6141 if (Network_sending_extras==30 && (Game_mode & GM_MULTI_ROBOTS))
6142 multi_send_stolen_items();
6143 if (Network_sending_extras==25 && (Netgame.PlayTimeAllowed || Netgame.KillGoal))
6144 multi_send_kill_goal_counts();
6145 if (Network_sending_extras==20)
6146 network_send_smash_lights(Player_joining_extras);
6147 if (Network_sending_extras==15)
6148 network_send_player_flags();
6149 if (Network_sending_extras==10)
6150 multi_send_powerup_update();
6151 // if (Network_sending_extras==5)
6152 // network_send_door_updates(Player_joining_extras); // twice!
6154 Network_sending_extras--;
6155 if (!Network_sending_extras)
6156 Player_joining_extras=-1;
6160 void network_send_naked_packet(char *buf, short len, int who)
6162 if (!(Game_mode&GM_NETWORK)) return;
6164 if (NakedPacketLen==0)
6166 NakedBuf[0]=PID_NAKED_PDATA;
6167 NakedBuf[1]=Player_num;
6171 if (len+NakedPacketLen>MaxXDataSize)
6173 // mprintf ((0,"Sending a naked packet of %d bytes.\n",NakedPacketLen));
6174 if (Network_game_type == IPX_GAME)
6175 ipx_send_packet_data( (ubyte *)NakedBuf, NakedPacketLen, NetPlayers.players[who].network.ipx.server, NetPlayers.players[who].network.ipx.node,Players[who].net_address );
6178 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 );
6181 memcpy (&NakedBuf[NakedPacketLen],buf,len);
6182 NakedPacketLen+=len;
6183 NakedPacketDestPlayer=who;
6187 memcpy (&NakedBuf[NakedPacketLen],buf,len);
6188 NakedPacketLen+=len;
6189 NakedPacketDestPlayer=who;
6194 void network_process_naked_pdata (char *data,int len)
6197 Assert (data[0]=PID_NAKED_PDATA);
6199 // mprintf ((0,"Processing a naked packet of %d length.\n",len));
6202 mprintf ((0,"Naked packet is bad!\n"));
6203 Int3(); // This packet is bogus!!
6207 if (!multi_quit_game && (pnum >= N_players)) {
6208 if (Network_status!=NETSTAT_WAITING)
6210 Int3(); // We missed an important packet!
6211 network_consistency_error();
6218 if (Endlevel_sequence || (Network_status == NETSTAT_ENDLEVEL) ) {
6219 int old_Endlevel_sequence = Endlevel_sequence;
6220 Endlevel_sequence = 1;
6221 multi_process_bigdata( data+2, len-2);
6222 Endlevel_sequence = old_Endlevel_sequence;
6226 multi_process_bigdata( data+2, len-2 );
6229 int ConnectionPacketLevel[]={0,1,1,1};
6230 int ConnectionSecLevel[]={12,3,5,7};
6232 int AppletalkConnectionPacketLevel[]={0,1,0};
6233 int AppletalkConnectionSecLevel[]={10,3,8};
6235 #if defined(RELEASE) && !defined(MACINTOSH) // use the code below for mac appletalk games
6236 int network_choose_connect ()
6241 int network_choose_connect ()
6248 if (Network_game_type == IPX_GAME) {
6250 m[opt].type = NM_TYPE_MENU; m[opt].text = "Local Subnet"; opt++;
6251 m[opt].type = NM_TYPE_MENU; m[opt].text = "14.4 modem over Internet"; opt++;
6252 m[opt].type = NM_TYPE_MENU; m[opt].text = "28.8 modem over Internet"; opt++;
6253 m[opt].type = NM_TYPE_MENU; m[opt].text = "ISDN or T1 over Internet"; opt++;
6255 choice = newmenu_do1( NULL, "Choose connection type", opt, m, NULL, 0 );
6260 Assert (choice>=0 && choice<=3);
6262 Netgame.ShortPackets=ConnectionPacketLevel[choice];
6263 Netgame.PacketsPerSec=ConnectionSecLevel[choice];
6268 m[opt].type = NM_TYPE_MENU; m[opt].text = "EtherTalk"; opt++;
6269 m[opt].type = NM_TYPE_MENU; m[opt].text = "LocalTalk"; opt++;
6270 m[opt].type = NM_TYPE_MENU; m[opt].text = "Other"; opt++;
6272 choice = newmenu_do1( NULL, "Choose connection type", opt, m, NULL, 0 );
6277 Network_appletalk_type = choice;
6279 Assert (choice>=0 && choice<=2);
6281 Netgame.ShortPackets=AppletalkConnectionPacketLevel[choice];
6282 Netgame.PacketsPerSec=AppletalkConnectionSecLevel[choice];
6296 SendLogFile=(FILE *)fopen ("sendlog.net","w");
6300 void OpenRecieveLog ()
6303 RecieveLogFile=(FILE *)fopen ("recvlog.net","w");
6309 int GetMyNetRanking ()
6314 if (Netlife_kills+Netlife_killed==0)
6317 rank=(int) (((float)Netlife_kills/3000.0)*8.0);
6319 eff=(int)((float)((float)Netlife_kills/((float)Netlife_killed+(float)Netlife_kills))*100.0);
6328 rank-=((59-eff)/10);
6335 mprintf ((0,"Rank is %d (%s)\n",rank+1,RankStrings[rank+1]));
6339 void ClipRank (signed char *rank)
6341 // This function insures no crashes when dealing with D2 1.0
6344 if (*rank<0 || *rank>9)
6347 void network_check_for_old_version (char pnum)
6349 if (NetPlayers.players[(int)pnum].version_major==1 && (NetPlayers.players[(int)pnum].version_minor & 0x0F)==0)
6350 NetPlayers.players[(int)pnum].rank=0;
6353 void network_request_player_names (int n)
6355 network_send_all_info_request (PID_GAME_PLAYERS,Active_games[n].Security);
6356 NamesInfoSecurity=Active_games[n].Security;
6359 extern char already_showing_info;
6360 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));
6362 void network_process_names_return (char *data)
6365 char mtext[15][50],temp[50];
6366 int i,t,l,gnum,num=0,count=5,numplayers;
6368 if (NamesInfoSecurity!=(*(int *)(data+1)))
6370 mprintf ((0,"Bad security on names return!\n"));
6371 mprintf ((0,"NIS=%d data=%d\n",NamesInfoSecurity,(*(int *)(data+1))));
6375 numplayers=data[count]; count++;
6377 if (numplayers==255)
6380 NamesInfoSecurity=-1;
6381 nm_messagebox(NULL, 1, "OK", "That game is refusing\nname requests.\n");
6386 Assert (numplayers>0 && numplayers<MAX_NUM_NET_PLAYERS);
6390 m[i].text=(char *)&mtext[i];
6391 m[i].type=NM_TYPE_TEXT;
6394 for (gnum=-1,i=0;i<num_active_games;i++)
6396 if (NamesInfoSecurity==Active_games[i].Security)
6406 NamesInfoSecurity=-1;
6407 nm_messagebox(NULL, 1, "OK", "The game you have requested\nnames from is gone.\n");
6412 sprintf (mtext[num],"Players of game '%s':",Active_games[gnum].game_name); num++;
6413 for (i=0;i<numplayers;i++)
6417 mprintf ((0,"%s\n",data+count));
6419 for (t=0;t<CALLSIGN_LEN+1;t++)
6420 temp[t]=data[count++];
6421 if (FindArg("-norankings"))
6422 sprintf (mtext[num],"%s",temp);
6424 sprintf (mtext[num],"%s%s",RankStrings[l],temp);
6429 if (data[count]==99)
6431 sprintf (mtext[num++]," ");
6432 sprintf (mtext[num++],"Short packets: %s",data[count+1]?"On":"Off");
6433 sprintf (mtext[num++],"Packets Per Second: %d",data[count+2]);
6436 already_showing_info=1;
6437 newmenu_dotiny2( NULL, NULL, num, m, NULL);
6438 already_showing_info=0;
6441 char NameReturning=1;
6443 void network_send_player_names (sequence_packet *their)
6445 int numconnected=0,count=0,i,t;
6450 mprintf ((0,"Got a player name without a return address! Get Jason\n"));
6454 buf[0]=PID_NAMES_RETURN; count++;
6455 (*(int *)(buf+1))=Netgame.Security; count+=4;
6459 buf[count]=255; count++;
6463 mprintf ((0,"RealSec=%d DS=%d\n",Netgame.Security,*(int *)(buf+1)));
6465 for (i=0;i<N_players;i++)
6466 if (Players[i].connected)
6469 buf[count]=numconnected; count++;
6470 for (i=0;i<N_players;i++)
6471 if (Players[i].connected)
6473 buf[count++]=NetPlayers.players[i].rank;
6475 for (t=0;t<CALLSIGN_LEN+1;t++)
6477 buf[count]=NetPlayers.players[i].callsign[t];
6483 buf[count++]=Netgame.ShortPackets;
6484 buf[count++]=Netgame.PacketsPerSec;
6487 ; // empty statement allows compilation on mac which does not have the
6488 // statement below and kills the compiler when there is no
6489 // statement following the label "sendit"
6492 ipx_send_internetwork_packet_data((ubyte *)buf, count, their->player.network.ipx.server, their->player.network.ipx.node);
6497 extern int file_exists (char *);
6499 int HoardEquipped ()
6501 static int checked=-1;
6509 if (file_exists ("hoard.ham"))