2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
11 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
15 static char rcsid[] = "$Id: network.c,v 1.2 2001-01-20 13:49:16 bradleyb Exp $";
71 #include <Errors.h> // for appletalk networking errors
75 void network_send_rejoin_sync(int player_num);
76 void network_update_netgame(void);
77 void network_read_endlevel_packet( ubyte *data );
78 void network_read_object_packet( ubyte *data );
79 void network_read_sync_packet( netgame_info * sp, int d1x );
81 void network_listen();
82 void network_read_pdata_packet(frame_info *pd );
84 void network_check_for_old_version (char pnum);
85 void network_send_endlevel_short_sub(int from_player_num,int to_player);
86 int network_wait_for_playerinfo();
87 void network_process_pdata (char *data);
88 void network_read_endlevel_short_packet( ubyte *data );
89 void network_ping (ubyte flag,int pnum);
90 void network_handle_ping_return (ubyte pnum);
91 void network_process_names_return (char *data);
92 void network_send_player_names (sequence_packet *their);
93 int network_choose_connect ();
94 void network_more_game_options ();
95 void network_count_powerups_in_mine(void);
96 int network_wait_for_all_info (int choice);
97 void network_do_big_wait(int choice);
98 void network_send_extras ();
99 void network_read_pdata_short_packet(short_frame_info *pd );
101 void network_AdjustMaxDataSize ();
103 void ClipRank (signed char *rank);
104 void DoRefuseStuff (sequence_packet *their);
105 void SetAllAllowablesTo (int on);
106 int GetNewPlayerNumber (sequence_packet *their);
108 #define LHX(x) ((x)*(MenuHires?2:1))
109 #define LHY(y) ((y)*(MenuHires?2.4:1))
111 #define PID_LITE_INFO 43
112 #define PID_SEND_ALL_GAMEINFO 44
113 #define PID_PLAYERSINFO 45
114 #define PID_REQUEST 46
117 #define PID_ADDPLAYER 49
119 #define PID_ENDLEVEL 52
120 #define PID_QUIT_JOINING 54
121 #define PID_OBJECT_DATA 55
122 #define PID_GAME_LIST 56
123 #define PID_GAME_INFO 57
124 #define PID_PING_SEND 58
125 #define PID_PING_RETURN 59
126 #define PID_GAME_UPDATE 60
127 #define PID_ENDLEVEL_SHORT 61
128 #define PID_NAKED_PDATA 62
129 #define PID_GAME_PLAYERS 63
130 #define PID_NAMES_RETURN 64
132 #define NETGAME_ANARCHY 0
133 #define NETGAME_TEAM_ANARCHY 1
134 #define NETGAME_ROBOT_ANARCHY 2
135 #define NETGAME_COOPERATIVE 3
136 #define NETGAME_CAPTURE_FLAG 4
137 #define NETGAME_HOARD 5
138 #define NETGAME_TEAM_HOARD 6
140 #define NETSECURITY_OFF 0
141 #define NETSECURITY_WAIT_FOR_PLAYERS 1
142 #define NETSECURITY_WAIT_FOR_GAMEINFO 2
143 #define NETSECURITY_WAIT_FOR_SYNC 3
145 // MWA -- these structures are aligned -- please save me sanity and
146 // headaches by keeping alignment if these are changed!!!! Contact
149 typedef struct endlevel_info {
154 short kill_matrix[MAX_PLAYERS][MAX_PLAYERS];
159 typedef struct endlevel_info_short {
164 } endlevel_info_short;
166 // WARNING!!! This is the top part of netgame_info...if that struct changes,
167 // this struct much change as well. ie...they are aligned and the join system will
168 // not work without it.
170 // MWA if this structure changes -- please make appropriate changes to receive_netgame_info
171 // code for macintosh in netmisc.c
173 typedef struct lite_info {
176 char game_name[NETGAME_NAME_LEN+1];
177 char mission_title[MISSION_NAME_LEN+1];
178 char mission_name[9];
185 ubyte max_numplayers;
188 ubyte protocol_version;
194 // IF YOU CHANGE THE SIZE OF ANY OF THE FOLLOWING STRUCTURES
195 // MAKE THE MACINTOSH DEFINES BE THE SAME SIZE AS THE PC OR
196 // I WILL HAVE TO HURT YOU VERY BADLY!!! -- MWA
199 #define NETGAME_INFO_SIZE ( Network_game_type == IPX_GAME?355:sizeof(netgame_info) )
200 #define ALLNETPLAYERSINFO_SIZE ( Network_game_type == IPX_GAME?317:sizeof(AllNetPlayers_info) )
201 #define LITE_INFO_SIZE ( Network_game_type == IPX_GAME?72:sizeof(lite_info) )
202 #define SEQUENCE_PACKET_SIZE ( Network_game_type == IPX_GAME?34:sizeof(sequence_packet) )
203 #define FRAME_INFO_SIZE ( Network_game_type == IPX_GAME?541:sizeof(frame_info) )
204 #define IPX_SHORT_INFO_SIZE ( 490 )
206 #define NETGAME_INFO_SIZE sizeof(netgame_info)
207 #define ALLNETPLAYERSINFO_SIZE sizeof(AllNetPlayers_info)
208 #define LITE_INFO_SIZE sizeof(lite_info)
209 #define SEQUENCE_PACKET_SIZE sizeof(sequence_packet)
210 #define FRAME_INFO_SIZE sizeof(frame_info)
213 #define MAX_ACTIVE_NETGAMES 12
215 netgame_info Active_games[MAX_ACTIVE_NETGAMES];
216 AllNetPlayers_info ActiveNetPlayers[MAX_ACTIVE_NETGAMES];
217 AllNetPlayers_info *TempPlayersInfo,TempPlayersBase;
218 int NamesInfoSecurity=-1;
220 // MWAnetgame_info *TempNetInfo;
221 netgame_info TempNetInfo;
223 extern void multi_send_drop_marker (int player,vms_vector position,char messagenum,char text[]);
224 extern void multi_send_kill_goal_counts();
225 extern int newmenu_dotiny( char * title, char * subtitle, int nitems, newmenu_item * item, void (*subfunction)(int nitems,newmenu_item * items, int * last_key, int citem) );
227 void network_process_naked_pdata (char *,int);
228 extern void multi_send_robot_controls(char);
230 int num_active_games = 0;
231 int PacketsPerSec=10;
232 int MaxXDataSize=NET_XDATA_SIZE;
234 int Netlife_kills=0, Netlife_killed=0;
237 int Network_active=0;
239 int Network_status = 0;
240 int Network_games_changed = 0;
242 int Network_socket = 0;
243 int Network_allow_socket_changes = 1;
245 int NetSecurityFlag=NETSECURITY_OFF;
246 int NetSecurityNum=0;
247 int Network_sending_extras=0;
248 int VerifyPlayerJoined=-1;
249 int Player_joining_extras=-1; // This is so we know who to send 'latecomer' packets to.
250 // We could just send updates to everyone but that kills the sender!
252 // For rejoin object syncing
254 int Network_rejoined = 0; // Did WE rejoin this game?
255 int Network_new_game = 0; // Is this the first level of a new game?
256 int Network_send_objects = 0; // Are we in the process of sending objects to a player?
257 int Network_send_objnum = -1; // What object are we sending next?
258 int Network_player_added = 0; // Is this a new player or a returning player?
259 int Network_send_object_mode = 0; // What type of objects are we sending, static or dynamic?
260 sequence_packet Network_player_rejoining; // Who is rejoining now?
262 fix LastPacketTime[MAX_PLAYERS]; // For timeouts of idle/crashed players
264 int PacketUrgent = 0;
266 int TotalMissedPackets=0,TotalPacketsGot=0;
268 frame_info MySyncPack,UrgentSyncPack;
269 ubyte MySyncPackInitialized = 0; // Set to 1 if the MySyncPack is zeroed.
270 ushort my_segments_checksum = 0;
272 sequence_packet My_Seq;
273 char WantPlayersInfo=0;
274 char WaitingForPlayerInfo=0;
276 char *RankStrings[]={"(unpatched) ","Cadet ","Ensign ","Lieutenant ","Lt.Commander ",
277 "Commander ","Captain ","Vice Admiral ","Admiral ","Demigod "};
279 extern obj_position Player_init[MAX_PLAYERS];
281 extern int force_cockpit_redraw;
283 #define DUMP_CLOSED 0
285 #define DUMP_ENDLEVEL 2
287 #define DUMP_ABORTED 4
288 #define DUMP_CONNECTED 5
290 #define DUMP_KICKED 7
292 extern ubyte Version_major,Version_minor;
293 extern ubyte SurfingNet;
294 extern char MaxPowerupsAllowed[MAX_POWERUP_TYPES];
295 extern char PowerupsInMine[MAX_POWERUP_TYPES];
297 extern void multi_send_stolen_items();
299 int network_wait_for_snyc();
300 extern void multi_send_wall_status (int,ubyte,ubyte,ubyte);
301 extern void multi_send_wall_status_specific (int,int,ubyte,ubyte,ubyte);
303 extern void game_disable_cheats();
306 FILE *SendLogFile,*RecieveLogFile;
307 int TTSent[100],TTRecv[100];
309 extern int Final_boss_is_dead;
311 // following is network stuff for appletalk
313 void network_dump_appletalk_player(ubyte node, ushort net, ubyte socket, int why);
315 #define NETWORK_OEM 0x10
319 int Network_game_type; // used to tell IPX vs. appletalk games
321 #define MAX_ZONES 255
322 #define MAX_ZONE_LENGTH 33
323 #define DEFAULT_ZONE_NAME "\p*"
324 #define MAX_REGISTER_TRIES 5 // maximum time we will try and register a netgame
325 char Network_zone_name[MAX_ZONE_LENGTH]; // zone name game being played in for appletalk
326 char Zone_names[MAX_ZONES][MAX_ZONE_LENGTH]; // total list of zones that we can see
327 ubyte appletalk_use_broadcast = 0;
328 ubyte Network_game_validated = 0; // validates a game before being able to join
329 ubyte Network_game_validate_choice = 0;
330 ubyte Network_appletalk_type = 0; // type of appletalk network game is being played on
332 #define ETHERTALK_TYPE 0
333 #define LOCALTALK_TYPE 1
334 #define OTHERTALK_TYPE 2
337 void network_release_registered_game(void);
345 // So you want to play a netgame, eh? Let's a get a few things
349 int save_pnum = Player_num;
351 game_disable_cheats();
353 Final_boss_is_dead=0;
354 NamesInfoSecurity=-1;
362 for (t=0;t<MAX_POWERUP_TYPES;t++)
364 MaxPowerupsAllowed[t]=0;
368 TotalMissedPackets=0; TotalPacketsGot=0;
370 memset(&Netgame, 0, sizeof(netgame_info));
371 memset(&NetPlayers,0,sizeof(AllNetPlayers_info));
372 memset(&My_Seq, 0, sizeof(sequence_packet));
373 My_Seq.type = PID_REQUEST;
374 memcpy(My_Seq.player.callsign, Players[Player_num].callsign, CALLSIGN_LEN+1);
377 Version_minor|=NETWORK_OEM;
380 My_Seq.player.version_major=Version_major;
381 My_Seq.player.version_minor=Version_minor;
382 My_Seq.player.rank=GetMyNetRanking();
384 if (Network_game_type == IPX_GAME) {
385 memcpy(My_Seq.player.network.ipx.node, ipx_get_my_local_address(), 6);
386 memcpy(My_Seq.player.network.ipx.server, ipx_get_my_server_address(), 4 );
389 My_Seq.player.network.appletalk.node = appletalk_get_my_node();
390 My_Seq.player.network.appletalk.net = appletalk_get_my_net();
391 My_Seq.player.network.appletalk.socket = appletalk_get_my_socket();
395 My_Seq.player.computer_type = MAC;
397 My_Seq.player.computer_type = DOS;
400 for (Player_num = 0; Player_num < MAX_NUM_NET_PLAYERS; Player_num++)
401 init_player_stats_game();
403 Player_num = save_pnum;
405 Network_new_game = 1;
406 Control_center_destroyed = 0;
409 Netgame.PacketsPerSec=10;
411 if ((t=args_find("-packets")))
413 Netgame.PacketsPerSec=atoi(Args[t+1]);
414 if (Netgame.PacketsPerSec<1)
415 Netgame.PacketsPerSec=1;
416 else if (Netgame.PacketsPerSec>20)
417 Netgame.PacketsPerSec=20;
418 mprintf ((0,"Will send %d packets per second",Netgame.PacketsPerSec));
420 if (args_find("-shortpackets"))
422 Netgame.ShortPackets=1;
423 mprintf ((0,"Will send short packets.\n"));
428 network_i_am_master(void)
430 // I am the lowest numbered player in this game?
434 if (!(Game_mode & GM_NETWORK))
435 return (Player_num == 0);
437 for (i = 0; i < Player_num; i++)
438 if (Players[i].connected)
443 network_who_is_master(void)
445 // Who is the master of this game?
449 if (!(Game_mode & GM_NETWORK))
450 return (Player_num == 0);
452 for (i = 0; i < N_players; i++)
453 if (Players[i].connected)
457 int network_how_many_connected()
461 for (i = 0; i < N_players; i++)
462 if (Players[i].connected)
467 #define ENDLEVEL_SEND_INTERVAL (F1_0*2)
468 #define ENDLEVEL_IDLE_TIME (F1_0*20)
471 network_endlevel_poll( int nitems, newmenu_item * menus, int * key, int citem )
473 // Polling loop for End-of-level menu
481 int previous_state[MAX_NUM_NET_PLAYERS];
482 int previous_seconds_left;
489 // Send our endlevel packet at regular intervals
491 if (timer_get_approx_seconds() > (t1+ENDLEVEL_SEND_INTERVAL))
493 network_send_endlevel_packet();
494 t1 = timer_get_approx_seconds();
497 for (i = 0; i < N_players; i++)
498 previous_state[i] = Players[i].connected;
500 previous_seconds_left = Countdown_seconds_left;
504 for (i = 0; i < N_players; i++)
506 if (Players[i].connected == 1)
508 // Check timeout for idle players
509 if (timer_get_approx_seconds() > LastPacketTime[i]+ENDLEVEL_IDLE_TIME)
511 mprintf((0, "idle timeout for player %d.\n", i));
512 Players[i].connected = 0;
513 network_send_endlevel_sub(i);
517 if ((Players[i].connected != 1) && (Players[i].connected != 5) && (Players[i].connected != 6))
519 if (Players[i].connected != 1)
521 if (Players[i].connected == 4)
525 if (num_escaped == N_players) // All players are out of the mine
527 Countdown_seconds_left = -1;
531 if (num_ready == N_players) // All players have checked in or are disconnected
541 network_endlevel_poll2( int nitems, newmenu_item * menus, int * key, int citem )
543 // Polling loop for End-of-level menu
555 // Send our endlevel packet at regular intervals
557 if (timer_get_approx_seconds() > (t1+ENDLEVEL_SEND_INTERVAL))
559 network_send_endlevel_packet();
560 t1 = timer_get_approx_seconds();
563 // mprintf ((0,"Trying to listen!\n"));
566 for (i = 0; i < N_players; i++)
568 if ((Players[i].connected != 1) && (Players[i].connected != 5) && (Players[i].connected != 6))
570 if (Players[i].connected == 4)
574 if (num_ready == N_players) // All players have checked in or are disconnected
584 extern fix StartAbortMenuTime;
587 network_endlevel_poll3( int nitems, newmenu_item * menus, int * key, int citem )
589 // Polling loop for End-of-level menu
598 if (timer_get_approx_seconds() > (StartAbortMenuTime+(F1_0 * 8)))
605 for (i = 0; i < N_players; i++)
606 if ((Players[i].connected != 1) && (Players[i].connected != 5) && (Players[i].connected != 6))
609 if (num_ready == N_players) // All players have checked in or are disconnected
616 network_endlevel(int *secret)
618 // Do whatever needs to be done between levels
626 Network_status = NETSTAT_ENDLEVEL; // We are between levels
630 network_send_endlevel_packet();
632 for (i=0; i<N_players; i++)
634 LastPacketTime[i] = timer_get_approx_seconds();
637 network_send_endlevel_packet();
638 network_send_endlevel_packet();
639 MySyncPackInitialized = 0;
641 network_update_netgame();
647 can_join_netgame(netgame_info *game,AllNetPlayers_info *people)
649 // Can this player rejoin a netgame in progress?
653 if (game->game_status == NETSTAT_STARTING)
656 if (game->game_status != NETSTAT_PLAYING)
658 mprintf ((0,"Error: Can't join because game_status !=NETSTAT_PLAYING\n"));
662 if (game->version_major==0 && Version_major>0)
664 mprintf ((0,"Error:Can't join because version majors don't match!\n"));
668 if (game->version_major>0 && Version_major==0)
670 mprintf ((0,"Error:Can't join because version majors2 don't match!\n"));
674 // Game is in progress, figure out if this guy can re-join it
676 num_players = game->numplayers;
678 if (!(game->game_flags & NETGAME_FLAG_CLOSED)) {
679 // Look for player that is not connected
681 if (game->numconnected==game->max_numplayers)
684 // mprintf ((0,"Refuse = %d\n",game->RefusePlayers));
686 if (game->RefusePlayers)
689 if (game->numplayers < game->max_numplayers)
692 if (game->numconnected<num_players)
699 mprintf ((0,"Error! Can't join because people==NULL!\n"));
703 // Search to see if we were already in this closed netgame in progress
705 for (i = 0; i < num_players; i++) {
706 if (Network_game_type == IPX_GAME) {
707 if ( (!stricmp(Players[Player_num].callsign, people->players[i].callsign)) &&
708 (!memcmp(My_Seq.player.network.ipx.node, people->players[i].network.ipx.node, 6)) &&
709 (!memcmp(My_Seq.player.network.ipx.server, people->players[i].network.ipx.server, 4)) )
712 if ( (!stricmp(Players[Player_num].callsign, people->players[i].callsign)) &&
713 (My_Seq.player.network.appletalk.node == people->players[i].network.appletalk.node) &&
714 (My_Seq.player.network.appletalk.net == people->players[i].network.appletalk.net) )
719 if (i != num_players)
722 mprintf ((0,"Error: Can't join because at end of list!\n"));
727 network_disconnect_player(int playernum)
729 // A player has disconnected from the net game, take whatever steps are
732 if (playernum == Player_num)
734 Int3(); // Weird, see Rob
738 Players[playernum].connected = 0;
739 NetPlayers.players[playernum].connected = 0;
740 if (VerifyPlayerJoined==playernum)
741 VerifyPlayerJoined=-1;
743 // create_player_appearance_effect(&Objects[Players[playernum].objnum]);
744 multi_make_player_ghost(playernum);
746 if (Newdemo_state == ND_STATE_RECORDING)
747 newdemo_record_multi_disconnect(playernum);
749 multi_strip_robots(playernum);
753 network_new_player(sequence_packet *their)
758 pnum = their->player.connected;
761 Assert(pnum < MaxNumNetPlayers);
763 objnum = Players[pnum].objnum;
765 if (Newdemo_state == ND_STATE_RECORDING) {
768 if (pnum == N_players)
772 newdemo_record_multi_connect(pnum, new_player, their->player.callsign);
775 memcpy(Players[pnum].callsign, their->player.callsign, CALLSIGN_LEN+1);
776 memcpy(NetPlayers.players[pnum].callsign, their->player.callsign, CALLSIGN_LEN+1);
779 ClipRank (&their->player.rank);
780 NetPlayers.players[pnum].rank=their->player.rank;
781 NetPlayers.players[pnum].version_major=their->player.version_major;
782 NetPlayers.players[pnum].version_minor=their->player.version_minor;
783 network_check_for_old_version(pnum);
785 if (Network_game_type == IPX_GAME) {
786 if ( (*(uint *)their->player.network.ipx.server) != 0 )
787 ipx_get_local_target( their->player.network.ipx.server, their->player.network.ipx.node, Players[pnum].net_address );
789 memcpy(Players[pnum].net_address, their->player.network.ipx.node, 6);
791 memcpy(NetPlayers.players[pnum].network.ipx.node, their->player.network.ipx.node, 6);
792 memcpy(NetPlayers.players[pnum].network.ipx.server, their->player.network.ipx.server, 4);
794 NetPlayers.players[pnum].network.appletalk.node = their->player.network.appletalk.node;
795 NetPlayers.players[pnum].network.appletalk.net = their->player.network.appletalk.net;
796 NetPlayers.players[pnum].network.appletalk.socket = their->player.network.appletalk.socket;
799 Players[pnum].n_packets_got = 0;
800 Players[pnum].connected = 1;
801 Players[pnum].net_kills_total = 0;
802 Players[pnum].net_killed_total = 0;
803 memset(kill_matrix[pnum], 0, MAX_PLAYERS*sizeof(short));
804 Players[pnum].score = 0;
805 Players[pnum].flags = 0;
806 Players[pnum].KillGoalCount=0;
808 if (pnum == N_players)
811 Netgame.numplayers = N_players;
814 digi_play_sample(SOUND_HUD_MESSAGE, F1_0);
816 ClipRank (&their->player.rank);
818 if (args_find("-norankings"))
819 HUD_init_message("'%s' %s\n",their->player.callsign, TXT_JOINING);
821 HUD_init_message("%s'%s' %s\n",RankStrings[their->player.rank],their->player.callsign, TXT_JOINING);
823 multi_make_ghost_player(pnum);
826 multi_sort_kill_list();
828 // create_player_appearance_effect(&Objects[objnum]);
831 char RefuseThisPlayer=0,WaitForRefuseAnswer=0,RefuseTeam;
832 char RefusePlayerName[12];
833 fix RefuseTimeLimit=0;
835 void network_welcome_player(sequence_packet *their)
837 // Add a player to a game already in progress
838 ubyte local_address[6];
842 WaitForRefuseAnswer=0;
844 if (args_find("-NoMatrixCheat"))
846 if (their->player.version_minor & (0x0F<3))
848 network_dump_player(their->player.network.ipx.server, their->player.network.ipx.node, DUMP_DORK);
855 // If hoard game, and this guy isn't D2 Christmas (v1.2), dump him
857 if ((Game_mode & GM_HOARD) && ((their->player.version_minor & 0x0F)<2))
859 if (Network_game_type == IPX_GAME)
860 network_dump_player(their->player.network.ipx.server, their->player.network.ipx.node, DUMP_DORK);
863 network_dump_appletalk_player(their->player.network.appletalk.node, their->player.network.appletalk.net, their->player.network.appletalk.socket, DUMP_DORK);
869 // Don't accept new players if we're ending this level. Its safe to
870 // ignore since they'll request again later
872 if ((Endlevel_sequence) || (Control_center_destroyed))
874 mprintf((0, "Ignored request from new player to join during endgame.\n"));
875 if (Network_game_type == IPX_GAME)
876 network_dump_player(their->player.network.ipx.server,their->player.network.ipx.node, DUMP_ENDLEVEL);
879 network_dump_appletalk_player(their->player.network.appletalk.node, their->player.network.appletalk.net, their->player.network.appletalk.socket, DUMP_ENDLEVEL);
884 if (Network_send_objects || Network_sending_extras)
886 // Ignore silently, we're already responding to someone and we can't
887 // do more than one person at a time. If we don't dump them they will
888 // re-request in a few seconds.
892 if (their->player.connected != Current_level_num)
894 mprintf((0, "Dumping player due to old level number.\n"));
895 if (Network_game_type == IPX_GAME)
896 network_dump_player(their->player.network.ipx.server, their->player.network.ipx.node, DUMP_LEVEL);
899 network_dump_appletalk_player(their->player.network.appletalk.node, their->player.network.appletalk.net, their->player.network.appletalk.socket, DUMP_LEVEL);
905 memset(&Network_player_rejoining, 0, sizeof(sequence_packet));
906 Network_player_added = 0;
908 if (Network_game_type == IPX_GAME) {
909 if ( (*(uint *)their->player.network.ipx.server) != 0 )
910 ipx_get_local_target( their->player.network.ipx.server, their->player.network.ipx.node, local_address );
912 memcpy(local_address, their->player.network.ipx.node, 6);
915 for (i = 0; i < N_players; i++)
917 if ( (Network_game_type == IPX_GAME) && (!stricmp(Players[i].callsign, their->player.callsign )) && (!memcmp(Players[i].net_address,local_address, 6)) )
922 #ifdef MACINTOSH // note link to above if
923 else if ( (!stricmp(Players[i].callsign, their->player.callsign)) &&
924 (NetPlayers.players[i].network.appletalk.node == their->player.network.appletalk.node) &&
925 (NetPlayers.players[i].network.appletalk.net == their->player.network.appletalk.net)) {
932 if (player_num == -1)
934 // Player is new to this game
936 if ( !(Netgame.game_flags & NETGAME_FLAG_CLOSED) && (N_players < MaxNumNetPlayers))
938 // Add player in an open slot, game not full yet
940 player_num = N_players;
941 Network_player_added = 1;
943 else if (Netgame.game_flags & NETGAME_FLAG_CLOSED)
945 // Slots are open but game is closed
947 if (Network_game_type == IPX_GAME)
948 network_dump_player(their->player.network.ipx.server, their->player.network.ipx.node, DUMP_CLOSED);
951 network_dump_appletalk_player(their->player.network.appletalk.node, their->player.network.appletalk.net, their->player.network.appletalk.socket, DUMP_CLOSED);
957 // Slots are full but game is open, see if anyone is
958 // disconnected and replace the oldest player with this new one
960 int oldest_player = -1;
961 fix oldest_time = timer_get_approx_seconds();
963 Assert(N_players == MaxNumNetPlayers);
965 for (i = 0; i < N_players; i++)
967 if ( (!Players[i].connected) && (LastPacketTime[i] < oldest_time))
969 oldest_time = LastPacketTime[i];
974 if (oldest_player == -1)
976 // Everyone is still connected
978 if (Network_game_type == IPX_GAME)
979 network_dump_player(their->player.network.ipx.server, their->player.network.ipx.node, DUMP_FULL);
982 network_dump_appletalk_player(their->player.network.appletalk.node, their->player.network.appletalk.net, their->player.network.appletalk.socket, DUMP_FULL);
990 player_num = oldest_player;
991 Network_player_added = 1;
997 // Player is reconnecting
999 if (Players[player_num].connected)
1001 mprintf((0, "Extra REQUEST from player ignored.\n"));
1005 if (Newdemo_state == ND_STATE_RECORDING)
1006 newdemo_record_multi_reconnect(player_num);
1008 Network_player_added = 0;
1010 digi_play_sample(SOUND_HUD_MESSAGE, F1_0);
1012 if (args_find("-norankings"))
1013 HUD_init_message("'%s' %s", Players[player_num].callsign, TXT_REJOIN);
1015 HUD_init_message("%s'%s' %s", RankStrings[NetPlayers.players[player_num].rank],Players[player_num].callsign, TXT_REJOIN);
1018 Players[player_num].KillGoalCount=0;
1020 // Send updated Objects data to the new/returning player
1023 Network_player_rejoining = *their;
1024 Network_player_rejoining.player.connected = player_num;
1025 Network_send_objects = 1;
1026 Network_send_objnum = -1;
1028 network_send_objects();
1031 int network_objnum_is_past(int objnum)
1033 // determine whether or not a given object number has already been sent
1034 // to a re-joining player.
1036 int player_num = Network_player_rejoining.player.connected;
1037 int obj_mode = !((object_owner[objnum] == -1) || (object_owner[objnum] == player_num));
1039 if (!Network_send_objects)
1040 return 0; // We're not sending objects to a new player
1042 if (obj_mode > Network_send_object_mode)
1044 else if (obj_mode < Network_send_object_mode)
1046 else if (objnum < Network_send_objnum)
1052 #define OBJ_PACKETS_PER_FRAME 1
1053 extern void multi_send_active_door(char);
1054 extern void multi_send_door_open_specific(int,int,int,ubyte);
1057 void network_send_door_updates(int pnum)
1059 // Send door status when new player joins
1065 // Assert (pnum>-1 && pnum<N_players);
1067 for (i = 0; i < Num_walls; i++)
1069 if ((Walls[i].type == WALL_DOOR) && ((Walls[i].state == WALL_DOOR_OPENING) || (Walls[i].state == WALL_DOOR_WAITING) || (Walls[i].state == WALL_DOOR_OPEN)))
1070 multi_send_door_open_specific(pnum,Walls[i].segnum, Walls[i].sidenum,Walls[i].flags);
1071 else if ((Walls[i].type == WALL_BLASTABLE) && (Walls[i].flags & WALL_BLASTED))
1072 multi_send_door_open_specific(pnum,Walls[i].segnum, Walls[i].sidenum,Walls[i].flags);
1073 else if ((Walls[i].type == WALL_BLASTABLE) && (Walls[i].hps != WALL_HPS))
1074 multi_send_hostage_door_status(i);
1076 multi_send_wall_status_specific(pnum,i,Walls[i].type,Walls[i].flags,Walls[i].state);
1080 extern vms_vector MarkerPoint[];
1081 void network_send_markers()
1083 // send marker positions/text to new player
1090 if (MarkerObject[(i*2)]!=-1)
1091 multi_send_drop_marker (i,MarkerPoint[(i*2)],0,MarkerMessage[i*2]);
1092 if (MarkerObject[(i*2)+1]!=-1)
1093 multi_send_drop_marker (i,MarkerPoint[(i*2)+1],1,MarkerMessage[(i*2)+1]);
1097 void network_process_monitor_vector(int vector)
1103 for (i=0; i <= Highest_segment_index; i++)
1107 for (j = 0; j < 6; j++)
1109 if ( ((tm = seg->sides[j].tmap_num2) != 0) &&
1110 ((ec = TmapInfo[tm&0x3fff].eclip_num) != -1) &&
1111 ((bm = Effects[ec].dest_bm_num) != -1) )
1113 if (vector & (1 << count))
1115 seg->sides[j].tmap_num2 = bm | (tm&0xc000);
1116 // mprintf((0, "Monitor %d blown up.\n", count));
1119 // mprintf((0, "Monitor %d intact.\n", count));
1127 int network_create_monitor_vector(void)
1130 int num_blown_bitmaps = 0;
1131 int monitor_num = 0;
1132 #define NUM_BLOWN_BITMAPS 20
1133 int blown_bitmaps[NUM_BLOWN_BITMAPS];
1137 for (i=0; i < Num_effects; i++)
1139 if (Effects[i].dest_bm_num > 0) {
1140 for (j = 0; j < num_blown_bitmaps; j++)
1141 if (blown_bitmaps[j] == Effects[i].dest_bm_num)
1143 if (j == num_blown_bitmaps) {
1144 blown_bitmaps[num_blown_bitmaps++] = Effects[i].dest_bm_num;
1145 Assert(num_blown_bitmaps < NUM_BLOWN_BITMAPS);
1150 // for (i = 0; i < num_blown_bitmaps; i++)
1151 // mprintf((0, "Blown bitmap #%d = %d.\n", i, blown_bitmaps[i]));
1153 for (i=0; i <= Highest_segment_index; i++)
1157 for (j = 0; j < 6; j++)
1159 if ((tm = seg->sides[j].tmap_num2) != 0)
1161 if ( ((ec = TmapInfo[tm&0x3fff].eclip_num) != -1) &&
1162 (Effects[ec].dest_bm_num != -1) )
1164 // mprintf((0, "Monitor %d intact.\n", monitor_num));
1166 Assert(monitor_num < 32);
1170 for (k = 0; k < num_blown_bitmaps; k++)
1172 if ((tm&0x3fff) == blown_bitmaps[k])
1174 //mprintf((0, "Monitor %d destroyed.\n", monitor_num));
1175 vector |= (1 << monitor_num);
1177 Assert(monitor_num < 32);
1185 // mprintf((0, "Final monitor vector %x.\n", vector));
1189 void network_stop_resync(sequence_packet *their)
1191 if (Network_game_type == IPX_GAME) {
1192 if ( (!memcmp(Network_player_rejoining.player.network.ipx.node, their->player.network.ipx.node, 6)) &&
1193 (!memcmp(Network_player_rejoining.player.network.ipx.server, their->player.network.ipx.server, 4)) &&
1194 (!stricmp(Network_player_rejoining.player.callsign, their->player.callsign)) )
1196 mprintf((0, "Aborting resync for player %s.\n", their->player.callsign));
1197 Network_send_objects = 0;
1198 Network_sending_extras=0;
1200 Player_joining_extras=-1;
1201 Network_send_objnum = -1;
1204 if ( (Network_player_rejoining.player.network.appletalk.node == their->player.network.appletalk.node) &&
1205 (Network_player_rejoining.player.network.appletalk.net == their->player.network.appletalk.net) &&
1206 (!stricmp(Network_player_rejoining.player.callsign, their->player.callsign)) )
1208 mprintf((0, "Aborting resync for player %s.\n", their->player.callsign));
1209 Network_send_objects = 0;
1210 Network_sending_extras=0;
1212 Player_joining_extras=-1;
1213 Network_send_objnum = -1;
1218 byte object_buffer[IPX_MAX_DATA_SIZE];
1220 void network_send_objects(void)
1222 short remote_objnum;
1226 static int obj_count = 0;
1227 static int frame_num = 0;
1229 int obj_count_frame = 0;
1230 int player_num = Network_player_rejoining.player.connected;
1232 // Send clear objects array trigger and send player num
1234 Assert(Network_send_objects != 0);
1235 Assert(player_num >= 0);
1236 Assert(player_num < MaxNumNetPlayers);
1238 if (Endlevel_sequence || Control_center_destroyed)
1240 // Endlevel started before we finished sending the goods, we'll
1241 // have to stop and try again after the level.
1243 if (Network_game_type == IPX_GAME)
1244 network_dump_player(Network_player_rejoining.player.network.ipx.server,Network_player_rejoining.player.network.ipx.node, DUMP_ENDLEVEL);
1247 network_dump_appletalk_player(Network_player_rejoining.player.network.appletalk.node,Network_player_rejoining.player.network.appletalk.net, Network_player_rejoining.player.network.appletalk.socket, DUMP_ENDLEVEL);
1249 Network_send_objects = 0;
1253 for (h = 0; h < OBJ_PACKETS_PER_FRAME; h++) // Do more than 1 per frame, try to speed it up without
1254 // over-stressing the receiver.
1256 obj_count_frame = 0;
1257 memset(object_buffer, 0, IPX_MAX_DATA_SIZE);
1258 object_buffer[0] = PID_OBJECT_DATA;
1261 if (Network_send_objnum == -1)
1264 Network_send_object_mode = 0;
1265 // mprintf((0, "Sending object array to player %d.\n", player_num));
1266 *(short *)(object_buffer+loc) = INTEL_SHORT(-1); loc += 2;
1267 object_buffer[loc] = player_num; loc += 1;
1268 loc += 2; // Placeholder for remote_objnum, not used here
1269 Network_send_objnum = 0;
1270 obj_count_frame = 1;
1274 for (i = Network_send_objnum; i <= Highest_object_index; i++)
1276 if ((Objects[i].type != OBJ_POWERUP) && (Objects[i].type != OBJ_PLAYER) &&
1277 (Objects[i].type != OBJ_CNTRLCEN) && (Objects[i].type != OBJ_GHOST) &&
1278 (Objects[i].type != OBJ_ROBOT) && (Objects[i].type != OBJ_HOSTAGE) &&
1279 !(Objects[i].type==OBJ_WEAPON && Objects[i].id==PMINE_ID))
1281 if ((Network_send_object_mode == 0) && ((object_owner[i] != -1) && (object_owner[i] != player_num)))
1283 if ((Network_send_object_mode == 1) && ((object_owner[i] == -1) || (object_owner[i] == player_num)))
1286 if ( ((IPX_MAX_DATA_SIZE-1) - loc) < (sizeof(object)+5) )
1287 break; // Not enough room for another object
1292 remote_objnum = objnum_local_to_remote((short)i, &owner);
1293 Assert(owner == object_owner[i]);
1295 *(short *)(object_buffer+loc) = INTEL_SHORT((short)i); loc += 2;
1296 object_buffer[loc] = owner; loc += 1;
1297 *(short *)(object_buffer+loc) = INTEL_SHORT(remote_objnum); loc += 2;
1299 memcpy(object_buffer+loc, &Objects[i], sizeof(object)); loc += sizeof(object);
1301 if (Network_game_type == IPX_GAME) {
1304 memcpy(&tmpobj, &(Objects[i]), sizeof(object));
1305 swap_object(&tmpobj);
1306 memcpy(&(object_buffer[loc]), &tmpobj, sizeof(object)); loc += sizeof(object);
1309 memcpy(object_buffer+loc, &Objects[i], sizeof(object)); loc += sizeof(object);
1311 // mprintf((0, "..packing object %d, remote %d\n", i, remote_objnum));
1314 if (obj_count_frame) // Send any objects we've buffered
1318 Network_send_objnum = i;
1319 object_buffer[1] = obj_count_frame; object_buffer[2] = frame_num;
1320 // mprintf((0, "Object packet %d contains %d objects.\n", frame_num, obj_count_frame));
1322 Assert(loc <= IPX_MAX_DATA_SIZE);
1324 if (Network_game_type == IPX_GAME)
1325 ipx_send_internetwork_packet_data( object_buffer, loc, Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node );
1328 appletalk_send_packet_data( object_buffer, loc, Network_player_rejoining.player.network.appletalk.node,
1329 Network_player_rejoining.player.network.appletalk.net,
1330 Network_player_rejoining.player.network.appletalk.socket);
1333 // OLD ipx_send_packet_data(object_buffer, loc, &Network_player_rejoining.player.node);
1336 if (i > Highest_object_index)
1338 if (Network_send_object_mode == 0)
1340 Network_send_objnum = 0;
1341 Network_send_object_mode = 1; // go to next mode
1345 Assert(Network_send_object_mode == 1);
1348 // Send count so other side can make sure he got them all
1349 // mprintf((0, "Sending end marker in packet #%d.\n", frame_num));
1350 mprintf((0, "Sent %d objects.\n", obj_count));
1351 object_buffer[0] = PID_OBJECT_DATA;
1352 object_buffer[1] = 1;
1353 object_buffer[2] = frame_num;
1354 *(short *)(object_buffer+3) = INTEL_SHORT(-2);
1355 *(short *)(object_buffer+6) = INTEL_SHORT(obj_count);
1356 //OLD ipx_send_packet_data(object_buffer, 8, &Network_player_rejoining.player.node);
1357 if (Network_game_type == IPX_GAME)
1358 ipx_send_internetwork_packet_data(object_buffer, 8, Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node);
1361 appletalk_send_packet_data( object_buffer, 8, Network_player_rejoining.player.network.appletalk.node,
1362 Network_player_rejoining.player.network.appletalk.net,
1363 Network_player_rejoining.player.network.appletalk.socket);
1367 // Send sync packet which tells the player who he is and to start!
1368 network_send_rejoin_sync(player_num);
1369 mprintf ((0,"VerfiyPlayerJoined is now set to %d\n",player_num));
1370 VerifyPlayerJoined=player_num;
1372 // Turn off send object mode
1373 Network_send_objnum = -1;
1374 Network_send_objects = 0;
1377 //if (!network_i_am_master ())
1378 // Int3(); // Bad!! Get Jason. Someone goofy is trying to get ahold of the game!
1380 Network_sending_extras=40; // start to send extras
1381 Player_joining_extras=player_num;
1385 } // i > Highest_object_index
1386 } // For PACKETS_PER_FRAME
1389 extern void multi_send_powerup_update();
1391 void network_send_rejoin_sync(int player_num)
1395 Players[player_num].connected = 1; // connect the new guy
1396 LastPacketTime[player_num] = timer_get_approx_seconds();
1398 if (Endlevel_sequence || Control_center_destroyed)
1400 // Endlevel started before we finished sending the goods, we'll
1401 // have to stop and try again after the level.
1403 if (Network_game_type == IPX_GAME)
1404 network_dump_player(Network_player_rejoining.player.network.ipx.server,Network_player_rejoining.player.network.ipx.node, DUMP_ENDLEVEL);
1407 network_dump_appletalk_player(Network_player_rejoining.player.network.appletalk.node,Network_player_rejoining.player.network.appletalk.net, Network_player_rejoining.player.network.appletalk.socket, DUMP_ENDLEVEL);
1409 Network_send_objects = 0;
1410 Network_sending_extras=0;
1414 if (Network_player_added)
1416 Network_player_rejoining.type = PID_ADDPLAYER;
1417 Network_player_rejoining.player.connected = player_num;
1418 network_new_player(&Network_player_rejoining);
1420 for (i = 0; i < N_players; i++)
1422 if ((i != player_num) && (i != Player_num) && (Players[i].connected))
1423 if (Network_game_type == IPX_GAME) {
1425 ipx_send_packet_data( (ubyte *)&Network_player_rejoining, sizeof(sequence_packet), NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node, Players[i].net_address);
1427 send_sequence_packet( Network_player_rejoining, NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node, Players[i].net_address);
1431 appletalk_send_packet_data( (ubyte *)&Network_player_rejoining, sizeof(sequence_packet), NetPlayers.players[i].network.appletalk.node,
1432 NetPlayers.players[i].network.appletalk.net, NetPlayers.players[i].network.appletalk.socket);
1438 // Send sync packet to the new guy
1440 network_update_netgame();
1442 // Fill in the kill list
1443 for (j=0; j<MAX_PLAYERS; j++)
1445 for (i=0; i<MAX_PLAYERS;i++)
1446 Netgame.kills[j][i] = kill_matrix[j][i];
1447 Netgame.killed[j] = Players[j].net_killed_total;
1448 Netgame.player_kills[j] = Players[j].net_kills_total;
1449 Netgame.player_score[j] = Players[j].score;
1452 Netgame.level_time = Players[Player_num].time_level;
1453 Netgame.monitor_vector = network_create_monitor_vector();
1455 mprintf((0, "Sending rejoin sync packet!!!\n"));
1457 if (Network_game_type == IPX_GAME) {
1459 ipx_send_internetwork_packet_data( (ubyte *)&Netgame, sizeof(netgame_info), Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node );
1460 ipx_send_internetwork_packet_data( (ubyte *)&NetPlayers, sizeof(AllNetPlayers_info), Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node );
1462 send_netgame_packet(Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node, NULL, 0);
1463 send_netplayers_packet(Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node);
1467 appletalk_send_packet_data( (ubyte *)&Netgame, sizeof(netgame_info), Network_player_rejoining.player.network.appletalk.node,
1468 Network_player_rejoining.player.network.appletalk.net,
1469 Network_player_rejoining.player.network.appletalk.socket);
1470 appletalk_send_packet_data( (ubyte *)&NetPlayers, sizeof(AllNetPlayers_info), Network_player_rejoining.player.network.appletalk.node,
1471 Network_player_rejoining.player.network.appletalk.net,
1472 Network_player_rejoining.player.network.appletalk.socket);
1477 void resend_sync_due_to_packet_loss_for_allender ()
1481 mprintf ((0,"I'm resending a sync packet! VPJ=%d\n",VerifyPlayerJoined));
1483 network_update_netgame();
1485 // Fill in the kill list
1486 for (j=0; j<MAX_PLAYERS; j++)
1488 for (i=0; i<MAX_PLAYERS;i++)
1489 Netgame.kills[j][i] = kill_matrix[j][i];
1490 Netgame.killed[j] = Players[j].net_killed_total;
1491 Netgame.player_kills[j] = Players[j].net_kills_total;
1492 Netgame.player_score[j] = Players[j].score;
1495 Netgame.level_time = Players[Player_num].time_level;
1496 Netgame.monitor_vector = network_create_monitor_vector();
1498 if (Network_game_type == IPX_GAME) {
1500 ipx_send_internetwork_packet_data( (ubyte *)&Netgame, sizeof(netgame_info), Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node );
1501 ipx_send_internetwork_packet_data( (ubyte *)&NetPlayers, sizeof(AllNetPlayers_info), Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node );
1503 send_netgame_packet(Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node, NULL, 0);
1504 send_netplayers_packet(Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node);
1508 appletalk_send_packet_data( (ubyte *)&Netgame, sizeof(netgame_info), Network_player_rejoining.player.network.appletalk.node,
1509 Network_player_rejoining.player.network.appletalk.net,
1510 Network_player_rejoining.player.network.appletalk.socket);
1511 appletalk_send_packet_data( (ubyte *)&NetPlayers, sizeof(AllNetPlayers_info), Network_player_rejoining.player.network.appletalk.node,
1512 Network_player_rejoining.player.network.appletalk.net,
1513 Network_player_rejoining.player.network.appletalk.socket);
1519 char * network_get_player_name( int objnum )
1521 if ( objnum < 0 ) return NULL;
1522 if ( Objects[objnum].type != OBJ_PLAYER ) return NULL;
1523 if ( Objects[objnum].id >= MAX_PLAYERS ) return NULL;
1524 if ( Objects[objnum].id >= N_players ) return NULL;
1526 return Players[Objects[objnum].id].callsign;
1530 void network_add_player(sequence_packet *p)
1534 mprintf((0, "Got add player request!\n"));
1536 for (i=0; i<N_players; i++ ) {
1537 if (Network_game_type == IPX_GAME) {
1538 if ( !memcmp( NetPlayers.players[i].network.ipx.node, p->player.network.ipx.node, 6) && !memcmp(NetPlayers.players[i].network.ipx.server, p->player.network.ipx.server, 4))
1539 return; // already got them
1541 if ( (NetPlayers.players[i].network.appletalk.node == p->player.network.appletalk.node) &&
1542 (NetPlayers.players[i].network.appletalk.net == p->player.network.appletalk.net))
1547 if (Network_game_type == IPX_GAME) {
1548 memcpy( NetPlayers.players[N_players].network.ipx.node, p->player.network.ipx.node, 6 );
1549 memcpy( NetPlayers.players[N_players].network.ipx.server, p->player.network.ipx.server, 4 );
1551 NetPlayers.players[N_players].network.appletalk.node = p->player.network.appletalk.node;
1552 NetPlayers.players[N_players].network.appletalk.net = p->player.network.appletalk.net;
1553 NetPlayers.players[N_players].network.appletalk.socket = p->player.network.appletalk.socket;
1556 ClipRank (&p->player.rank);
1558 memcpy( NetPlayers.players[N_players].callsign, p->player.callsign, CALLSIGN_LEN+1 );
1559 NetPlayers.players[N_players].version_major=p->player.version_major;
1560 NetPlayers.players[N_players].version_minor=p->player.version_minor;
1561 NetPlayers.players[N_players].rank=p->player.rank;
1562 NetPlayers.players[N_players].connected = 1;
1563 network_check_for_old_version (N_players);
1565 Players[N_players].KillGoalCount=0;
1566 Players[N_players].connected = 1;
1567 LastPacketTime[N_players] = timer_get_approx_seconds();
1569 Netgame.numplayers = N_players;
1571 // Broadcast updated info
1573 mprintf ((0,"sending_game_info!\n"));
1574 network_send_game_info(NULL);
1577 // One of the players decided not to join the game
1579 void network_remove_player(sequence_packet *p)
1584 for (i=0; i<N_players; i++ ) {
1585 if (Network_game_type == IPX_GAME) {
1586 if (!memcmp(NetPlayers.players[i].network.ipx.node, p->player.network.ipx.node, 6) && !memcmp(NetPlayers.players[i].network.ipx.server, p->player.network.ipx.server, 4)) {
1591 if ( (NetPlayers.players[i].network.appletalk.node == p->player.network.appletalk.node) && (NetPlayers.players[i].network.appletalk.net == p->player.network.appletalk.net) ) {
1598 if (pn < 0 ) return;
1600 for (i=pn; i<N_players-1; i++ ) {
1601 if (Network_game_type == IPX_GAME) {
1602 memcpy( NetPlayers.players[i].network.ipx.node, NetPlayers.players[i+1].network.ipx.node, 6 );
1603 memcpy( NetPlayers.players[i].network.ipx.server, NetPlayers.players[i+1].network.ipx.server, 4 );
1605 NetPlayers.players[i].network.appletalk.node = NetPlayers.players[i+1].network.appletalk.node;
1606 NetPlayers.players[i].network.appletalk.net = NetPlayers.players[i+1].network.appletalk.net;
1607 NetPlayers.players[i].network.appletalk.socket = NetPlayers.players[i+1].network.appletalk.socket;
1609 memcpy( NetPlayers.players[i].callsign, NetPlayers.players[i+1].callsign, CALLSIGN_LEN+1 );
1610 NetPlayers.players[i].version_major=NetPlayers.players[i+1].version_major;
1611 NetPlayers.players[i].version_minor=NetPlayers.players[i+1].version_minor;
1613 NetPlayers.players[i].rank=NetPlayers.players[i+1].rank;
1614 ClipRank (&NetPlayers.players[i].rank);
1615 network_check_for_old_version(i);
1619 Netgame.numplayers = N_players;
1621 // Broadcast new info
1623 network_send_game_info(NULL);
1628 network_dump_player(ubyte * server, ubyte *node, int why)
1630 // Inform player that he was not chosen for the netgame
1632 sequence_packet temp;
1634 temp.type = PID_DUMP;
1635 memcpy(temp.player.callsign, Players[Player_num].callsign, CALLSIGN_LEN+1);
1636 temp.player.connected = why;
1637 if (Network_game_type == IPX_GAME) {
1639 ipx_send_internetwork_packet_data( (ubyte *)&temp, sizeof(sequence_packet), server, node);
1641 send_sequence_packet( temp, server, node, NULL);
1649 void network_dump_appletalk_player(ubyte node, ushort net, ubyte socket, int why)
1651 sequence_packet temp;
1653 temp.type = PID_DUMP;
1654 memcpy(temp.player.callsign, Players[Player_num].callsign, CALLSIGN_LEN+1);
1655 temp.player.connected = why;
1656 if (Network_game_type == APPLETALK_GAME) {
1657 appletalk_send_packet_data( (ubyte *)&temp, sizeof(sequence_packet), node, net, socket );
1665 network_send_game_list_request()
1667 // Send a broadcast request for game info
1671 mprintf((0, "Sending game_list request.\n"));
1672 me.type = PID_GAME_LIST;
1673 memcpy( me.player.callsign, Players[Player_num].callsign, CALLSIGN_LEN+1 );
1675 if (Network_game_type == IPX_GAME) {
1676 memcpy( me.player.network.ipx.node, ipx_get_my_local_address(), 6 );
1677 memcpy( me.player.network.ipx.server, ipx_get_my_server_address(), 4 );
1680 ipx_send_broadcast_packet_data( (ubyte *)&me, sizeof(sequence_packet) );
1682 send_sequence_packet( me, NULL, NULL, NULL);
1686 me.player.network.appletalk.node = appletalk_get_my_node();
1687 me.player.network.appletalk.net = appletalk_get_my_net();
1688 me.player.network.appletalk.socket = appletalk_get_my_socket();
1689 appletalk_send_game_info( (ubyte *)&me, sizeof(sequence_packet), Network_zone_name );
1694 void network_send_all_info_request(char type,int which_security)
1696 // Send a broadcast request for game info
1700 mprintf((0, "Sending all_info request.\n"));
1702 me.Security=which_security;
1704 memcpy( me.player.callsign, Players[Player_num].callsign, CALLSIGN_LEN+1 );
1706 if (Network_game_type == IPX_GAME) {
1707 memcpy( me.player.network.ipx.node, ipx_get_my_local_address(), 6 );
1708 memcpy( me.player.network.ipx.server, ipx_get_my_server_address(), 4 );
1711 ipx_send_broadcast_packet_data( (ubyte *)&me, sizeof(sequence_packet) );
1713 send_sequence_packet(me, NULL, NULL, NULL);
1717 me.player.network.appletalk.node = appletalk_get_my_node();
1718 me.player.network.appletalk.net = appletalk_get_my_net();
1719 me.player.network.appletalk.socket = appletalk_get_my_socket();
1720 appletalk_send_game_info( (ubyte *)&me, sizeof(sequence_packet), Network_zone_name );
1727 network_update_netgame(void)
1729 // Update the netgame struct with current game variables
1733 Netgame.numconnected=0;
1734 for (i=0;i<N_players;i++)
1735 if (Players[i].connected)
1736 Netgame.numconnected++;
1738 // This is great: D2 1.0 and 1.1 ignore upper part of the game_flags field of
1739 // the lite_info struct when you're sitting on the join netgame screen. We can
1740 // "sneak" Hoard information into this field. This is better than sending
1741 // another packet that could be lost in transit.
1744 if (HoardEquipped())
1746 if (Game_mode & GM_HOARD)
1748 Netgame.game_flags |=NETGAME_FLAG_HOARD;
1749 if (Game_mode & GM_TEAM)
1750 Netgame.game_flags |=NETGAME_FLAG_TEAM_HOARD;
1754 if (Network_status == NETSTAT_STARTING)
1757 Netgame.numplayers = N_players;
1758 Netgame.game_status = Network_status;
1759 Netgame.max_numplayers = MaxNumNetPlayers;
1761 for (i = 0; i < MAX_NUM_NET_PLAYERS; i++)
1763 NetPlayers.players[i].connected = Players[i].connected;
1764 for(j = 0; j < MAX_NUM_NET_PLAYERS; j++)
1765 Netgame.kills[i][j] = kill_matrix[i][j];
1767 Netgame.killed[i] = Players[i].net_killed_total;
1768 Netgame.player_kills[i] = Players[i].net_kills_total;
1769 Netgame.player_score[i] = Players[i].score;
1770 Netgame.player_flags[i] = (Players[i].flags & (PLAYER_FLAGS_BLUE_KEY | PLAYER_FLAGS_RED_KEY | PLAYER_FLAGS_GOLD_KEY));
1772 Netgame.team_kills[0] = team_kills[0];
1773 Netgame.team_kills[1] = team_kills[1];
1774 Netgame.levelnum = Current_level_num;
1780 network_send_endlevel_sub(int player_num)
1785 // Send an endlevel packet for a player
1786 end.type = PID_ENDLEVEL;
1787 end.player_num = player_num;
1788 end.connected = Players[player_num].connected;
1789 end.kills = INTEL_SHORT(Players[player_num].net_kills_total);
1790 end.killed = INTEL_SHORT(Players[player_num].net_killed_total);
1791 memcpy(end.kill_matrix, kill_matrix[player_num], MAX_PLAYERS*sizeof(short));
1793 for (i = 0; i < MAX_PLAYERS; i++)
1794 for (j = 0; j < MAX_PLAYERS; j++)
1795 end.kill_matrix[i][j] = INTEL_SHORT(end.kill_matrix[i][j]);
1797 j = j; // to satisfy compiler
1800 if (Players[player_num].connected == 1) // Still playing
1802 Assert(Control_center_destroyed);
1803 end.seconds_left = Countdown_seconds_left;
1806 // mprintf((0, "Sending endlevel packet.\n"));
1808 for (i = 0; i < N_players; i++)
1810 if ((i != Player_num) && (i!=player_num) && (Players[i].connected)) {
1811 if (Players[i].connected==1)
1812 network_send_endlevel_short_sub(player_num,i);
1814 if (Network_game_type == IPX_GAME)
1815 ipx_send_packet_data((ubyte *)&end, sizeof(endlevel_info), NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node,Players[i].net_address);
1818 appletalk_send_packet_data( (ubyte *)&end, sizeof(endlevel_info), NetPlayers.players[i].network.appletalk.node,
1819 NetPlayers.players[i].network.appletalk.net,
1820 NetPlayers.players[i].network.appletalk.socket);
1828 network_send_endlevel_packet(void)
1830 // Send an updated endlevel status to other hosts
1832 network_send_endlevel_sub(Player_num);
1837 network_send_endlevel_short_sub(int from_player_num,int to_player)
1839 endlevel_info_short end;
1841 // Send an endlevel packet for a player
1842 end.type = PID_ENDLEVEL_SHORT;
1843 end.player_num = from_player_num;
1844 end.connected = Players[from_player_num].connected;
1845 end.seconds_left = Countdown_seconds_left;
1848 if (Players[from_player_num].connected == 1) // Still playing
1850 Assert(Control_center_destroyed);
1853 if ((to_player != Player_num) && (to_player!=from_player_num) && (Players[to_player].connected))
1855 mprintf((0, "Sending short endlevel packet to %s.\n",Players[to_player].callsign));
1856 if (Network_game_type == IPX_GAME)
1857 ipx_send_packet_data((ubyte *)&end, sizeof(endlevel_info_short), NetPlayers.players[to_player].network.ipx.server, NetPlayers.players[to_player].network.ipx.node,Players[to_player].net_address);
1860 appletalk_send_packet_data( (ubyte *)&end, sizeof(endlevel_info_short), NetPlayers.players[to_player].network.appletalk.node,
1861 NetPlayers.players[to_player].network.appletalk.net,
1862 NetPlayers.players[to_player].network.appletalk.socket);
1867 extern fix ThisLevelTime;
1870 network_send_game_info(sequence_packet *their)
1872 // Send game info to someone who requested it
1874 char old_type, old_status;
1878 mprintf((0, "Sending game info.\n"));
1880 network_update_netgame(); // Update the values in the netgame struct
1882 old_type = Netgame.type;
1883 old_status = Netgame.game_status;
1885 Netgame.type = PID_GAME_INFO;
1886 NetPlayers.type = PID_PLAYERSINFO;
1888 NetPlayers.Security=Netgame.Security;
1889 Netgame.version_major=Version_major;
1890 Netgame.version_minor=Version_minor;
1892 if (Endlevel_sequence || Control_center_destroyed)
1893 Netgame.game_status = NETSTAT_ENDLEVEL;
1895 if (Netgame.PlayTimeAllowed)
1897 timevar=i2f (Netgame.PlayTimeAllowed*5*60);
1898 i=f2i(timevar-ThisLevelTime);
1900 Netgame.game_status=NETSTAT_ENDLEVEL;
1904 if (Network_game_type == IPX_GAME) {
1906 ipx_send_broadcast_packet_data((ubyte *)&Netgame, sizeof(netgame_info));
1907 ipx_send_broadcast_packet_data((ubyte *)&NetPlayers,sizeof(AllNetPlayers_info));
1909 send_netgame_packet(NULL, NULL, NULL, 0); // server == NULL says to broadcast packet
1910 send_netplayers_packet(NULL, NULL);
1912 } // nothing to do for appletalk games I think....
1914 if (Network_game_type == IPX_GAME) {
1916 ipx_send_internetwork_packet_data((ubyte *)&Netgame, sizeof(netgame_info), their->player.network.ipx.server, their->player.network.ipx.node);
1917 ipx_send_internetwork_packet_data((ubyte *)&NetPlayers,sizeof(AllNetPlayers_info),their->player.network.ipx.server,their->player.network.ipx.node);
1919 send_netgame_packet(their->player.network.ipx.server, their->player.network.ipx.node, NULL, 0);
1920 send_netplayers_packet(their->player.network.ipx.server, their->player.network.ipx.node);
1924 appletalk_send_packet_data( (ubyte *)&Netgame, sizeof(netgame_info), their->player.network.appletalk.node,
1925 their->player.network.appletalk.net, their->player.network.appletalk.socket );
1926 appletalk_send_packet_data( (ubyte *)&NetPlayers, sizeof(AllNetPlayers_info), their->player.network.appletalk.node,
1927 their->player.network.appletalk.net, their->player.network.appletalk.socket );
1932 Netgame.type = old_type;
1933 Netgame.game_status = old_status;
1936 void network_send_lite_info(sequence_packet *their)
1938 // Send game info to someone who requested it
1940 char old_type, old_status,oldstatus;
1942 mprintf((0, "Sending lite game info.\n"));
1944 network_update_netgame(); // Update the values in the netgame struct
1946 old_type = Netgame.type;
1947 old_status = Netgame.game_status;
1949 Netgame.type = PID_LITE_INFO;
1951 if (Endlevel_sequence || Control_center_destroyed)
1952 Netgame.game_status = NETSTAT_ENDLEVEL;
1954 // If hoard mode, make this game look closed even if it isn't
1955 if (HoardEquipped())
1957 if (Game_mode & GM_HOARD)
1959 oldstatus=Netgame.game_status;
1960 Netgame.game_status=NETSTAT_ENDLEVEL;
1961 Netgame.gamemode=NETGAME_CAPTURE_FLAG;
1962 if (oldstatus==NETSTAT_ENDLEVEL)
1963 Netgame.game_flags|=NETGAME_FLAG_REALLY_ENDLEVEL;
1964 if (oldstatus==NETSTAT_STARTING)
1965 Netgame.game_flags|=NETGAME_FLAG_REALLY_FORMING;
1970 if (Network_game_type == IPX_GAME) {
1972 ipx_send_broadcast_packet_data((ubyte *)&Netgame, sizeof(lite_info));
1974 send_netgame_packet(NULL, NULL, NULL, 1); // server == NULL says broadcast
1976 } // nothing to do for appletalk I think....
1978 if (Network_game_type == IPX_GAME) {
1980 ipx_send_internetwork_packet_data((ubyte *)&Netgame, sizeof(lite_info), their->player.network.ipx.server, their->player.network.ipx.node);
1982 send_netgame_packet(their->player.network.ipx.server, their->player.network.ipx.node, NULL, 1);
1986 appletalk_send_packet_data( (ubyte *)&Netgame, sizeof(lite_info), their->player.network.appletalk.node,
1987 their->player.network.appletalk.net, their->player.network.appletalk.socket );
1992 // Restore the pre-hoard mode
1993 if (HoardEquipped())
1995 if (Game_mode & GM_HOARD)
1997 if (!(Game_mode & GM_TEAM))
1998 Netgame.gamemode=NETGAME_HOARD;
2000 Netgame.gamemode=NETGAME_TEAM_HOARD;
2001 Netgame.game_flags&=~NETGAME_FLAG_REALLY_ENDLEVEL;
2002 Netgame.game_flags&=~NETGAME_FLAG_REALLY_FORMING;
2003 Netgame.game_flags&=~NETGAME_FLAG_TEAM_HOARD;
2007 Netgame.type = old_type;
2008 Netgame.game_status = old_status;
2012 void network_send_netgame_update()
2014 // Send game info to someone who requested it
2016 char old_type, old_status;
2019 mprintf((0, "Sending updated game info.\n"));
2021 network_update_netgame(); // Update the values in the netgame struct
2023 old_type = Netgame.type;
2024 old_status = Netgame.game_status;
2026 Netgame.type = PID_GAME_UPDATE;
2028 if (Endlevel_sequence || Control_center_destroyed)
2029 Netgame.game_status = NETSTAT_ENDLEVEL;
2031 for (i=0; i<N_players; i++ ) {
2032 if ( (Players[i].connected) && (i!=Player_num ) ) {
2033 if (Network_game_type == IPX_GAME) {
2035 ipx_send_packet_data( (ubyte *)&Netgame, sizeof(lite_info), NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node,Players[i].net_address );
2037 send_netgame_packet(NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node, Players[i].net_address, 0);
2041 appletalk_send_packet_data( (ubyte *)&Netgame, sizeof(lite_info), NetPlayers.players[i].network.appletalk.node,
2042 NetPlayers.players[i].network.appletalk.net, NetPlayers.players[i].network.appletalk.socket );
2048 Netgame.type = old_type;
2049 Netgame.game_status = old_status;
2052 int network_send_request(void)
2054 // Send a request to join a game 'Netgame'. Returns 0 if we can join this
2055 // game, non-zero if there is some problem.
2058 if (Netgame.numplayers < 1)
2061 for (i = 0; i < MAX_NUM_NET_PLAYERS; i++)
2062 if (NetPlayers.players[i].connected)
2065 Assert(i < MAX_NUM_NET_PLAYERS);
2067 mprintf((0, "Sending game enroll request to player %d (%s). Serv=%x Node=%x Level=%d\n", i, Players[i].callsign,NetPlayers.players[i].network.ipx.server,NetPlayers.players[i].network.ipx.node,Netgame.levelnum));
2069 // segments_checksum = netmisc_calc_checksum( Segments, sizeof(segment)*(Highest_segment_index+1) );
2071 My_Seq.type = PID_REQUEST;
2072 My_Seq.player.connected = Current_level_num;
2074 if (Network_game_type == IPX_GAME) {
2076 ipx_send_internetwork_packet_data((ubyte *)&My_Seq, sizeof(sequence_packet), NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node);
2078 send_sequence_packet(My_Seq, NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node, NULL);
2082 appletalk_send_packet_data( (ubyte *)&My_Seq, sizeof(sequence_packet), NetPlayers.players[i].network.appletalk.node,
2083 NetPlayers.players[i].network.appletalk.net,
2084 NetPlayers.players[i].network.appletalk.socket);
2091 int SecurityCheck=0;
2093 void network_process_gameinfo(ubyte *data)
2096 netgame_info tmp_info;
2099 netgame_info *new = (netgame_info *)data;
2102 if (Network_game_type == IPX_GAME) {
2103 receive_netgame_packet(data, &tmp_info, 0); // get correctly aligned structure
2109 WaitingForPlayerInfo=0;
2111 if (new->Security !=TempPlayersInfo->Security)
2113 Int3(); // Get Jason
2114 return; // If this first half doesn't go with the second half
2117 Network_games_changed = 1;
2119 //mprintf((0, "Got game data for game %s.\n", new->game_name));
2121 Assert (TempPlayersInfo!=NULL);
2123 for (i = 0; i < num_active_games; i++)
2125 //mprintf ((0,"GAMEINFO: Game %d is %s!\n",i,Active_games[i].game_name));
2127 if (!stricmp(Active_games[i].game_name, new->game_name) &&
2128 Active_games[i].Security==new->Security)
2132 if (i == MAX_ACTIVE_NETGAMES)
2134 mprintf((0, "Too many netgames.\n"));
2138 // MWA memcpy(&Active_games[i], data, sizeof(netgame_info));
2139 memcpy(&Active_games[i], (ubyte *)new, sizeof(netgame_info));
2140 memcpy (&ActiveNetPlayers[i],TempPlayersInfo,sizeof(AllNetPlayers_info));
2143 if (Active_games[i].Security==SecurityCheck)
2146 //mprintf ((0,"Recieved %d unique games...\n",i));
2148 if (i == num_active_games)
2151 if (Active_games[i].numplayers == 0)
2153 mprintf ((0,"DELETING THIS GAME!!!\n"));
2155 for (j = i; j < num_active_games-1; j++)
2157 memcpy(&Active_games[j], &Active_games[j+1], sizeof(netgame_info));
2158 memcpy (&ActiveNetPlayers[j],&ActiveNetPlayers[j+1],sizeof(AllNetPlayers_info));
2165 void network_process_lite_info(ubyte *data)
2171 lite_info *new = (lite_info *)data;
2174 if (Network_game_type == IPX_GAME) {
2175 receive_netgame_packet(data, (netgame_info *)&tmp_info, 1);
2180 Network_games_changed = 1;
2182 //mprintf((0, "Got game data for game %s.\n", new->game_name));
2184 for (i = 0; i < num_active_games; i++)
2186 //mprintf ((0,"GAMEINFO: Game %d is %s!\n",i,Active_games[i].game_name));
2188 if ((!stricmp(Active_games[i].game_name, new->game_name)) &&
2189 Active_games[i].Security==new->Security)
2193 if (i == MAX_ACTIVE_NETGAMES)
2195 mprintf((0, "Too many netgames.\n"));
2199 memcpy(&Active_games[i], (ubyte *)new, sizeof(lite_info));
2201 // See if this is really a Hoard game
2202 // If so, adjust all the data accordingly
2204 if (HoardEquipped())
2206 if (Active_games[i].game_flags & NETGAME_FLAG_HOARD)
2208 Active_games[i].gamemode=NETGAME_HOARD;
2209 Active_games[i].game_status=NETSTAT_PLAYING;
2211 if (Active_games[i].game_flags & NETGAME_FLAG_TEAM_HOARD)
2212 Active_games[i].gamemode=NETGAME_TEAM_HOARD;
2213 if (Active_games[i].game_flags & NETGAME_FLAG_REALLY_ENDLEVEL)
2214 Active_games[i].game_status=NETSTAT_ENDLEVEL;
2215 if (Active_games[i].game_flags & NETGAME_FLAG_REALLY_FORMING)
2216 Active_games[i].game_status=NETSTAT_STARTING;
2220 //mprintf ((0,"Recieved %d unique games...\n",i));
2222 if (i == num_active_games)
2225 if (Active_games[i].numplayers == 0)
2227 mprintf ((0,"DELETING THIS GAME!!!\n"));
2229 for (j = i; j < num_active_games-1; j++)
2231 memcpy(&Active_games[j], &Active_games[j+1], sizeof(netgame_info));
2237 void network_process_dump(sequence_packet *their)
2239 // Our request for join was denied. Tell the user why.
2244 mprintf((0, "Dumped by player %s, type %d.\n", their->player.callsign, their->player.connected));
2246 if (their->player.connected!=7)
2247 nm_messagebox(NULL, 1, TXT_OK, NET_DUMP_STRINGS(their->player.connected));
2250 for (i=0;i<N_players;i++)
2251 if (!stricmp (their->player.callsign,Players[i].callsign))
2253 if (i!=network_who_is_master())
2255 HUD_init_message ("%s attempted to kick you out.",their->player.callsign);
2259 sprintf (temp,"%s has kicked you out!",their->player.callsign);
2260 nm_messagebox(NULL, 1, TXT_OK, &temp);
2261 if (Network_status==NETSTAT_PLAYING)
2267 Network_status = NETSTAT_MENU;
2272 void network_process_request(sequence_packet *their)
2274 // Player is ready to receieve a sync packet
2277 mprintf((0, "Player %s ready for sync.\n", their->player.callsign));
2279 for (i = 0; i < N_players; i++) {
2280 if (Network_game_type == IPX_GAME) {
2281 if (!memcmp(their->player.network.ipx.server, NetPlayers.players[i].network.ipx.server, 4) && !memcmp(their->player.network.ipx.node, NetPlayers.players[i].network.ipx.node, 6) && (!stricmp(their->player.callsign, NetPlayers.players[i].callsign))) {
2282 Players[i].connected = 1;
2286 if ( (their->player.network.appletalk.node == NetPlayers.players[i].network.appletalk.node) && (their->player.network.appletalk.net == NetPlayers.players[i].network.appletalk.net) && (!stricmp(their->player.callsign, NetPlayers.players[i].callsign)) ) {
2287 Players[i].connected = 1;
2294 #define REFUSE_INTERVAL F1_0 * 8
2295 extern void multi_reset_object_texture (object *);
2297 void network_process_packet(ubyte *data, int length )
2300 sequence_packet tmp_packet;
2302 sequence_packet *their = (sequence_packet *)data;
2305 if (Network_game_type == IPX_GAME) {
2306 receive_sequence_packet(data, &tmp_packet);
2307 their = &tmp_packet; // reassign their to point to correctly alinged structure
2311 //mprintf( (0, "Got packet of length %d, type %d\n", length, their->type ));
2313 // if ( length < sizeof(sequence_packet) ) return;
2319 case PID_GAME_INFO: // Jason L. says we can safely ignore this type.
2322 case PID_PLAYERSINFO:
2324 mprintf ((0,"Got a PID_PLAYERSINFO!\n"));
2326 if (Network_status==NETSTAT_WAITING)
2329 memcpy (&TempPlayersBase,data,sizeof(AllNetPlayers_info));
2331 if (Network_game_type == IPX_GAME)
2332 receive_netplayers_packet(data, &TempPlayersBase);
2334 memcpy (&TempPlayersBase,data,sizeof(AllNetPlayers_info));
2337 if (TempPlayersBase.Security!=Netgame.Security)
2339 mprintf ((0,"Bad security for PLAYERSINFO\n"));
2343 mprintf ((0,"Got a waiting PID_PLAYERSINFO!\n"));
2344 if (length!=ALLNETPLAYERSINFO_SIZE)
2346 mprintf ((0,"Invalid size for netplayers packet!\n"));
2350 TempPlayersInfo=&TempPlayersBase;
2351 WaitingForPlayerInfo=0;
2352 NetSecurityNum=TempPlayersInfo->Security;
2353 NetSecurityFlag=NETSECURITY_WAIT_FOR_SYNC;
2360 if (length != LITE_INFO_SIZE)
2362 mprintf ((0,"WARNING! Recieved invalid size for PID_LITE_INFO\n"));
2366 if (Network_status == NETSTAT_BROWSING)
2367 network_process_lite_info (data);
2371 // Someone wants a list of games
2373 if (length != SEQUENCE_PACKET_SIZE)
2375 mprintf ((0,"WARNING! Recieved invalid size for PID_GAME_LIST\n"));
2379 mprintf((0, "Got a PID_GAME_LIST!\n"));
2380 if ((Network_status == NETSTAT_PLAYING) || (Network_status == NETSTAT_STARTING) || (Network_status == NETSTAT_ENDLEVEL))
2381 if (network_i_am_master())
2382 network_send_lite_info(their);
2386 case PID_SEND_ALL_GAMEINFO:
2388 if (length != SEQUENCE_PACKET_SIZE)
2390 mprintf ((0,"WARNING! Recieved invalid size for PID_SEND_ALL_GAMEINFO\n"));
2394 if ((Network_status == NETSTAT_PLAYING) || (Network_status == NETSTAT_STARTING) || (Network_status == NETSTAT_ENDLEVEL))
2395 if (network_i_am_master() && their->Security==Netgame.Security)
2396 network_send_game_info(their);
2401 mprintf( (0, "Got NEWPLAYER message from %s.\n", their->player.callsign));
2403 if (length != SEQUENCE_PACKET_SIZE)
2405 mprintf ((0,"WARNING! Recieved invalid size for PID_ADDPLAYER\n"));
2408 mprintf( (0, "Got NEWPLAYER message from %s.\n", their->player.callsign));
2409 network_new_player(their);
2412 if (length != SEQUENCE_PACKET_SIZE)
2414 mprintf ((0,"WARNING! Recieved invalid size for PID_REQUEST\n"));
2418 mprintf( (0, "Got REQUEST from '%s'\n", their->player.callsign ));
2419 if (Network_status == NETSTAT_STARTING)
2421 // Someone wants to join our game!
2422 network_add_player(their);
2424 else if (Network_status == NETSTAT_WAITING)
2426 // Someone is ready to recieve a sync packet
2427 network_process_request(their);
2429 else if (Network_status == NETSTAT_PLAYING)
2431 // Someone wants to join a game in progress!
2432 if (Netgame.RefusePlayers)
2433 DoRefuseStuff (their);
2435 network_welcome_player(their);
2440 if (length != SEQUENCE_PACKET_SIZE)
2442 mprintf ((0,"WARNING! Recieved invalid size for PID_DUMP\n"));
2446 if (Network_status == NETSTAT_WAITING || Network_status==NETSTAT_PLAYING )
2447 network_process_dump(their);
2449 case PID_QUIT_JOINING:
2451 if (length != SEQUENCE_PACKET_SIZE)
2453 mprintf ((0,"WARNING! Recieved invalid size for PID_QUIT_JOINING\n"));
2456 if (Network_status == NETSTAT_STARTING)
2457 network_remove_player( their );
2458 else if ((Network_status == NETSTAT_PLAYING) && (Network_send_objects))
2459 network_stop_resync( their );
2463 mprintf ((0,"Got a sync packet! Network_status=%d\n",NETSTAT_WAITING));
2465 if (Network_status == NETSTAT_WAITING) {
2468 memcpy((ubyte *)&(TempNetInfo), data, sizeof(netgame_info));
2470 if (Network_game_type == IPX_GAME)
2471 receive_netgame_packet(data, &TempNetInfo, 0);
2473 memcpy((ubyte *)&(TempNetInfo), data, sizeof(netgame_info));
2476 if (TempNetInfo.Security!=Netgame.Security)
2478 mprintf ((0,"Bad security on sync packet.\n"));
2482 if (NetSecurityFlag==NETSECURITY_WAIT_FOR_SYNC)
2484 if (TempNetInfo.Security==TempPlayersInfo->Security)
2486 network_read_sync_packet (&TempNetInfo,0);
2493 NetSecurityFlag=NETSECURITY_WAIT_FOR_PLAYERS;
2494 NetSecurityNum=TempNetInfo.Security;
2496 if ( network_wait_for_playerinfo())
2497 network_read_sync_packet((netgame_info *)data,0);
2506 if ((Game_mode&GM_NETWORK) && ((Network_status == NETSTAT_PLAYING)||(Network_status == NETSTAT_ENDLEVEL) || Network_status==NETSTAT_WAITING)) {
2507 network_process_pdata((char *)data);
2510 case PID_NAKED_PDATA:
2511 if ((Game_mode&GM_NETWORK) && ((Network_status == NETSTAT_PLAYING)||(Network_status == NETSTAT_ENDLEVEL) || Network_status==NETSTAT_WAITING))
2512 network_process_naked_pdata((char *)data,length);
2515 case PID_OBJECT_DATA:
2516 if (Network_status == NETSTAT_WAITING)
2517 network_read_object_packet(data);
2520 if ((Network_status == NETSTAT_ENDLEVEL) || (Network_status == NETSTAT_PLAYING))
2521 network_read_endlevel_packet(data);
2523 mprintf((0, "Junked endlevel packet.\n"));
2525 case PID_ENDLEVEL_SHORT:
2526 if ((Network_status == NETSTAT_ENDLEVEL) || (Network_status == NETSTAT_PLAYING))
2527 network_read_endlevel_short_packet(data);
2529 mprintf((0, "Junked short endlevel packet!\n"));
2532 case PID_GAME_UPDATE:
2533 mprintf ((0,"Got a GAME_UPDATE!\n"));
2535 if (Network_status==NETSTAT_PLAYING)
2538 memcpy((ubyte *)&TempNetInfo, data, sizeof(lite_info) );
2540 if (Network_game_type == IPX_GAME)
2541 receive_netgame_packet(data, &TempNetInfo, 1);
2543 memcpy((ubyte *)&TempNetInfo, data, sizeof(lite_info) );
2545 if (TempNetInfo.Security==Netgame.Security)
2546 memcpy (&Netgame,(ubyte *)&TempNetInfo,sizeof(lite_info));
2548 if (Game_mode & GM_TEAM)
2552 for (i=0;i<N_players;i++)
2553 if (Players[i].connected)
2554 multi_reset_object_texture (&Objects[Players[i].objnum]);
2559 network_ping (PID_PING_RETURN,data[1]);
2561 case PID_PING_RETURN:
2562 network_handle_ping_return(data[1]); // data[1] is player who told us of their ping time
2564 case PID_NAMES_RETURN:
2565 if (Network_status==NETSTAT_BROWSING && NamesInfoSecurity!=-1)
2566 network_process_names_return (data);
2568 case PID_GAME_PLAYERS:
2569 // Someone wants a list of players in this game
2571 if (length != SEQUENCE_PACKET_SIZE)
2573 mprintf ((0,"WARNING! Recieved invalid size for PID_GAME_PLAYERS\n"));
2577 mprintf((0, "Got a PID_GAME_PLAYERS!\n"));
2578 if ((Network_status == NETSTAT_PLAYING) || (Network_status == NETSTAT_STARTING) || (Network_status == NETSTAT_ENDLEVEL))
2579 if (network_i_am_master() && their->Security==Netgame.Security)
2580 network_send_player_names(their);
2584 mprintf((0, "Ignoring invalid packet type.\n"));
2585 Int3(); // Invalid network packet type, see ROB
2591 void dump_segments()
2595 fp = fopen( "TEST.DMP", "wb" );
2596 fwrite( Segments, sizeof(segment)*(Highest_segment_index+1),1, fp );
2598 mprintf( (0, "SS=%d\n", sizeof(segment) ));
2604 network_read_endlevel_packet( ubyte *data )
2606 // Special packet for end of level syncing
2613 end = (endlevel_info *)data;
2615 for (i = 0; i < MAX_PLAYERS; i++)
2616 for (j = 0; j < MAX_PLAYERS; j++)
2617 end->kill_matrix[i][j] = INTEL_SHORT(end->kill_matrix[i][j]);
2618 end->kills = INTEL_SHORT(end->kills);
2619 end->killed = INTEL_SHORT(end->killed);
2622 playernum = end->player_num;
2624 Assert(playernum != Player_num);
2626 if (playernum>=N_players)
2628 Int3(); // weird, but it an happen in a coop restore game
2629 return; // if it happens in a coop restore, don't worry about it
2632 if ((Network_status == NETSTAT_PLAYING) && (end->connected != 0))
2633 return; // Only accept disconnect packets if we're not out of the level yet
2635 Players[playernum].connected = end->connected;
2636 memcpy(&kill_matrix[playernum][0], end->kill_matrix, MAX_PLAYERS*sizeof(short));
2637 Players[playernum].net_kills_total = end->kills;
2638 Players[playernum].net_killed_total = end->killed;
2640 if ((Players[playernum].connected == 1) && (end->seconds_left < Countdown_seconds_left))
2641 Countdown_seconds_left = end->seconds_left;
2643 LastPacketTime[playernum] = timer_get_approx_seconds();
2645 // mprintf((0, "Got endlevel packet from player %d.\n", playernum));
2649 network_read_endlevel_short_packet( ubyte *data )
2651 // Special packet for end of level syncing
2654 endlevel_info_short *end;
2656 end = (endlevel_info_short *)data;
2658 playernum = end->player_num;
2660 Assert(playernum != Player_num);
2662 if (playernum>=N_players)
2664 Int3(); // weird, but it can happen in a coop restore game
2665 return; // if it happens in a coop restore, don't worry about it
2668 if ((Network_status == NETSTAT_PLAYING) && (end->connected != 0))
2670 //mprintf ((0,"Returning early for short_endlevel\n"));
2671 return; // Only accept disconnect packets if we're not out of the level yet
2674 Players[playernum].connected = end->connected;
2676 if ((Players[playernum].connected == 1) && (end->seconds_left < Countdown_seconds_left))
2677 Countdown_seconds_left = end->seconds_left;
2679 LastPacketTime[playernum] = timer_get_approx_seconds();
2684 network_pack_objects(void)
2686 // Switching modes, pack the object array
2688 special_reset_objects();
2692 network_verify_objects(int remote, int local)
2695 int nplayers, got_controlcen=0;
2697 mprintf ((0,"NETWORK:remote=%d local=%d\n",remote,local));
2699 if ((remote-local) > 10)
2702 if (Game_mode & GM_MULTI_ROBOTS)
2707 for (i = 0; i <= Highest_object_index; i++)
2709 if ((Objects[i].type == OBJ_PLAYER) || (Objects[i].type == OBJ_GHOST))
2711 if (Objects[i].type == OBJ_CNTRLCEN)
2715 if (got_controlcen && (MaxNumNetPlayers<=nplayers))
2722 network_read_object_packet( ubyte *data )
2724 // Object from another net player we need to sync with
2726 short objnum, remote_objnum;
2731 static int my_pnum = 0;
2732 static int mode = 0;
2733 static int object_count = 0;
2734 static int frame_num = 0;
2737 int remote_frame_num = data[2];
2741 // mprintf((0, "Object packet %d (remote #%d) contains %d objects.\n", frame_num, remote_frame_num, nobj));
2743 for (i = 0; i < nobj; i++)
2745 objnum = INTEL_SHORT( *(short *)(data+loc) ); loc += 2;
2746 obj_owner = data[loc]; loc += 1;
2747 remote_objnum = INTEL_SHORT( *(short *)(data+loc) ); loc += 2;
2751 // Clear object array
2752 mprintf((0, "Clearing object array.\n"));
2755 Network_rejoined = 1;
2756 my_pnum = obj_owner;
2757 change_playernum_to(my_pnum);
2762 else if (objnum == -2)
2764 // Special debug checksum marker for entire send
2767 network_pack_objects();
2770 mprintf((0, "Objnum -2 found in frame local %d remote %d.\n", frame_num, remote_frame_num));
2771 mprintf((0, "Got %d objects, expected %d.\n", object_count, remote_objnum));
2772 if (remote_objnum != object_count) {
2775 if (network_verify_objects(remote_objnum, object_count))
2777 // Failed to sync up
2778 nm_messagebox(NULL, 1, TXT_OK, TXT_NET_SYNC_FAILED);
2779 Network_status = NETSTAT_MENU;
2786 if (frame_num != remote_frame_num)
2788 mprintf ((0,"Got a type 3 object packet!\n"));
2790 if ((obj_owner == my_pnum) || (obj_owner == -1))
2794 objnum = remote_objnum;
2795 //if (objnum > Highest_object_index)
2797 // Highest_object_index = objnum;
2798 // num_objects = Highest_object_index+1;
2804 network_pack_objects();
2807 objnum = obj_allocate();
2810 obj = &Objects[objnum];
2811 if (obj->segnum != -1)
2813 Assert(obj->segnum == -1);
2814 Assert(objnum < MAX_OBJECTS);
2815 memcpy(obj,data+loc,sizeof(object)); loc += sizeof(object);
2817 if (Network_game_type == IPX_GAME)
2820 segnum = obj->segnum;
2821 obj->next = obj->prev = obj->segnum = -1;
2822 obj->attached_obj = -1;
2824 obj_link(obj-Objects,segnum);
2825 if (obj_owner == my_pnum)
2826 map_objnum_local_to_local(objnum);
2827 else if (obj_owner != -1)
2828 map_objnum_local_to_remote(objnum, remote_objnum, obj_owner);
2830 object_owner[objnum] = -1;
2832 } // For a standard onbject
2833 } // For each object in packet
2836 void network_sync_poll( int nitems, newmenu_item * menus, int * key, int citem )
2838 // Polling loop waiting for sync packet to start game
2848 if (Network_status != NETSTAT_WAITING) // Status changed to playing, exit the menu
2851 if (!Network_rejoined && (timer_get_approx_seconds() > t1+F1_0*2))
2855 // Poll time expired, re-send request
2857 t1 = timer_get_approx_seconds();
2859 mprintf((0, "Re-sending join request.\n"));
2860 i = network_send_request();
2866 void network_start_poll( int nitems, newmenu_item * menus, int * key, int citem )
2873 Assert(Network_status == NETSTAT_STARTING);
2875 if (!menus[0].value) {
2877 menus[0].redraw = 1;
2880 for (i=1; i<nitems; i++ ) {
2881 if ( (i>= N_players) && (menus[i].value) ) {
2883 menus[i].redraw = 1;
2888 for (i=0; i<nitems; i++ ) {
2889 if ( menus[i].value ) {
2891 if ( nm > N_players ) {
2893 menus[i].redraw = 1;
2898 if ( nm > MaxNumNetPlayers ) {
2899 nm_messagebox( TXT_ERROR, 1, TXT_OK, "%s %d %s", TXT_SORRY_ONLY, MaxNumNetPlayers, TXT_NETPLAYERS_IN );
2900 // Turn off the last player highlighted
2901 for (i = N_players; i > 0; i--)
2902 if (menus[i].value == 1)
2905 menus[i].redraw = 1;
2910 // if (nitems > MAX_PLAYERS ) return;
2912 n = Netgame.numplayers;
2915 if (n < Netgame.numplayers )
2917 digi_play_sample (SOUND_HUD_MESSAGE,F1_0);
2919 mprintf ((0,"More players are printed!"));
2920 if (args_find("-norankings"))
2921 sprintf( menus[N_players-1].text, "%d. %-20s", N_players,NetPlayers.players[N_players-1].callsign );
2923 sprintf( menus[N_players-1].text, "%d. %s%-20s", N_players, RankStrings[NetPlayers.players[N_players-1].rank],NetPlayers.players[N_players-1].callsign );
2925 menus[N_players-1].redraw = 1;
2926 if (N_players <= MaxNumNetPlayers)
2928 menus[N_players-1].value = 1;
2931 else if ( n > Netgame.numplayers )
2933 // One got removed...
2935 digi_play_sample (SOUND_HUD_KILL,F1_0);
2937 for (i=0; i<N_players; i++ )
2940 if (args_find("-norankings"))
2941 sprintf( menus[i].text, "%d. %-20s", i+1, NetPlayers.players[i].callsign );
2943 sprintf( menus[i].text, "%d. %s%-20s", i+1, RankStrings[NetPlayers.players[i].rank],NetPlayers.players[i].callsign );
2944 if (i < MaxNumNetPlayers)
2948 menus[i].redraw = 1;
2950 for (i=N_players; i<n; i++ )
2952 sprintf( menus[i].text, "%d. ", i+1 ); // Clear out the deleted entries...
2954 menus[i].redraw = 1;
2959 int opt_cinvul, opt_team_anarchy, opt_coop, opt_show_on_map, opt_closed,opt_maxnet;
2960 int last_cinvul=0,last_maxnet,opt_team_hoard;
2961 int opt_refuse,opt_capture;
2963 void network_game_param_poll( int nitems, newmenu_item * menus, int * key, int citem )
2965 static int oldmaxnet=0;
2967 if (((HoardEquipped() && menus[opt_team_hoard].value) || (menus[opt_team_anarchy].value || menus[opt_capture].value)) && !menus[opt_closed].value && !menus[opt_refuse].value) {
2968 menus[opt_refuse].value = 1;
2969 menus[opt_refuse].redraw = 1;
2970 menus[opt_refuse-1].value = 0;
2971 menus[opt_refuse-1].redraw = 1;
2972 menus[opt_refuse-2].value = 0;
2973 menus[opt_refuse-2].redraw = 1;
2977 if (menus[opt_coop].value)
2979 if ( (menus[opt_coop].value) || ((Network_game_type == APPLETALK_GAME) && (Network_appletalk_type == LOCALTALK_TYPE) && (menus[opt_coop-1].value)) )
2984 if (menus[opt_maxnet].value>2)
2986 menus[opt_maxnet].value=2;
2987 menus[opt_maxnet].redraw=1;
2990 if (menus[opt_maxnet].max_value>2)
2992 menus[opt_maxnet].max_value=2;
2993 menus[opt_maxnet].redraw=1;
2997 if ( (Network_game_type == APPLETALK_GAME) && (Network_appletalk_type == LOCALTALK_TYPE) ) {
2998 if (menus[opt_maxnet].value > 0) {
2999 menus[opt_maxnet].value=0;
3000 menus[opt_maxnet].redraw=1;
3002 if (menus[opt_maxnet].max_value > 0) {
3003 menus[opt_maxnet].max_value=0;
3004 menus[opt_maxnet].redraw=1;
3009 if (!Netgame.game_flags & NETGAME_FLAG_SHOW_MAP)
3010 Netgame.game_flags |= NETGAME_FLAG_SHOW_MAP;
3012 if (Netgame.PlayTimeAllowed || Netgame.KillGoal)
3014 Netgame.PlayTimeAllowed=0;
3019 else // if !Coop game
3024 menus[opt_maxnet].value=6;
3025 menus[opt_maxnet].max_value=6;
3028 if ( (Network_game_type == APPLETALK_GAME) && (Network_appletalk_type == LOCALTALK_TYPE) ) {
3029 menus[opt_maxnet].value=1;
3030 menus[opt_maxnet].max_value=1;
3037 if ( last_maxnet != menus[opt_maxnet].value )
3039 sprintf( menus[opt_maxnet].text, "Maximum players: %d", menus[opt_maxnet].value+2 );
3040 last_maxnet = menus[opt_maxnet].value;
3041 menus[opt_maxnet].redraw = 1;
3045 int netgame_difficulty;
3047 int network_get_game_params( char * game_name, int *mode, int *game_flags, int *level )
3050 int opt, opt_name, opt_level, opt_mode,opt_moreopts;
3052 char name[NETGAME_NAME_LEN+1];
3054 char level_text[32];
3057 int new_mission_num;
3060 *game_flags=*game_flags;
3062 SetAllAllowablesTo (1);
3063 NamesInfoSecurity=-1;
3065 for (i=0;i<MAX_PLAYERS;i++)
3067 Players[i].callsign[0]=0;
3071 Netgame.PlayTimeAllowed=0;
3072 Netgame.Allow_marker_view=1;
3073 netgame_difficulty=Player_default_difficulty;
3075 new_mission_num = multi_choose_mission(&anarchy_only);
3077 if (new_mission_num < 0)
3080 if (!(args_find ("-packets") && args_find ("-shortpackets")))
3081 if (!network_choose_connect ())
3085 if ( (Network_game_type == APPLETALK_GAME) && (Network_appletalk_type == LOCALTALK_TYPE) )
3086 MaxNumNetPlayers = 3;
3089 strcpy(Netgame.mission_name, Mission_list[new_mission_num].filename);
3090 strcpy(Netgame.mission_title, Mission_list[new_mission_num].mission_name);
3091 Netgame.control_invul_time = control_invul_time;
3093 sprintf( name, "%s%s", Players[Player_num].callsign, TXT_S_GAME );
3094 sprintf( slevel, "1" );
3097 m[opt].type = NM_TYPE_TEXT; m[opt].text = TXT_DESCRIPTION; opt++;
3100 m[opt].type = NM_TYPE_INPUT; m[opt].text = name; m[opt].text_len = NETGAME_NAME_LEN; opt++;
3102 sprintf(level_text, "%s (1-%d)", TXT_LEVEL_, Last_level);
3104 // if (Last_secret_level < -1)
3105 // sprintf(level_text+strlen(level_text)-1, ", S1-S%d)", -Last_secret_level);
3106 // else if (Last_secret_level == -1)
3107 // sprintf(level_text+strlen(level_text)-1, ", S1)");
3109 Assert(strlen(level_text) < 32);
3111 m[opt].type = NM_TYPE_TEXT; m[opt].text = level_text; opt++;
3114 m[opt].type = NM_TYPE_INPUT; m[opt].text = slevel; m[opt].text_len=4; opt++;
3115 // m[opt].type = NM_TYPE_TEXT; m[opt].text = TXT_OPTIONS; opt++;
3118 m[opt].type = NM_TYPE_RADIO; m[opt].text = TXT_ANARCHY; m[opt].value=1; m[opt].group=0; opt++;
3119 m[opt].type = NM_TYPE_RADIO; m[opt].text = TXT_TEAM_ANARCHY; m[opt].value=0; m[opt].group=0; opt_team_anarchy=opt; opt++;
3120 m[opt].type = NM_TYPE_RADIO; m[opt].text = TXT_ANARCHY_W_ROBOTS; m[opt].value=0; m[opt].group=0; opt++;
3121 m[opt].type = NM_TYPE_RADIO; m[opt].text = TXT_COOPERATIVE; m[opt].value=0; m[opt].group=0; opt_coop=opt; opt++;
3122 m[opt].type = NM_TYPE_RADIO; m[opt].text = "Capture the flag"; m[opt].value=0; m[opt].group=0; opt_capture=opt; opt++;
3124 if (HoardEquipped())
3126 m[opt].type = NM_TYPE_RADIO; m[opt].text = "Hoard"; m[opt].value=0; m[opt].group=0; opt++;
3127 m[opt].type = NM_TYPE_RADIO; m[opt].text = "Team Hoard"; m[opt].value=0; m[opt].group=0; opt_team_hoard=opt; opt++;
3128 m[opt].type = NM_TYPE_TEXT; m[opt].text = ""; opt++;
3131 { m[opt].type = NM_TYPE_TEXT; m[opt].text = ""; opt++; }
3133 m[opt].type = NM_TYPE_RADIO; m[opt].text = "Open game"; m[opt].group=1; m[opt].value=0; opt++;
3135 m[opt].type = NM_TYPE_RADIO; m[opt].text = TXT_CLOSED_GAME; m[opt].group=1; m[opt].value=0; opt++;
3137 m[opt].type = NM_TYPE_RADIO; m[opt].text = "Restricted Game "; m[opt].group=1; m[opt].value=Netgame.RefusePlayers; opt++;
3139 // m[opt].type = NM_TYPE_CHECK; m[opt].text = TXT_SHOW_IDS; m[opt].value=0; opt++;
3142 sprintf( srmaxnet, "Maximum players: %d", MaxNumNetPlayers);
3143 m[opt].type = NM_TYPE_SLIDER; m[opt].value=MaxNumNetPlayers-2; m[opt].text= srmaxnet; m[opt].min_value=0;
3144 m[opt].max_value=MaxNumNetPlayers-2; opt++;
3145 last_maxnet=MaxNumNetPlayers-2;
3148 m[opt].type = NM_TYPE_MENU; m[opt].text = "More options..."; opt++;
3153 ExtGameStatus=GAMESTAT_NETGAME_OPTIONS;
3154 i = newmenu_do1( NULL, NULL, opt, m, network_game_param_poll, 1 );
3156 if (i==opt_moreopts)
3158 if ( m[opt_mode+3].value )
3159 Game_mode=GM_MULTI_COOP;
3160 network_more_game_options();
3164 Netgame.RefusePlayers=m[opt_refuse].value;
3170 MaxNumNetPlayers = m[opt_maxnet].value+2;
3171 Netgame.max_numplayers=MaxNumNetPlayers;
3173 for (j = 0; j < num_active_games; j++)
3174 if (!stricmp(Active_games[j].game_name, name))
3176 nm_messagebox(TXT_ERROR, 1, TXT_OK, TXT_DUPLICATE_NAME);
3180 strcpy( game_name, name );
3183 *level = atoi(slevel);
3185 if ((*level < 1) || (*level > Last_level))
3187 nm_messagebox(TXT_ERROR, 1, TXT_OK, TXT_LEVEL_OUT_RANGE );
3188 sprintf(slevel, "1");
3191 if ( m[opt_mode].value )
3192 *mode = NETGAME_ANARCHY;
3197 nm_messagebox(TXT_SORRY, 1, TXT_OK, TXT_REGISTERED_ONLY );
3198 m[opt_mode+1].value = 0;
3199 m[opt_mode+2].value = 0;
3200 m[opt_mode+3].value = 0;
3201 if (HoardEquipped())
3202 m[opt_mode+4].value = 0;
3204 m[opt_mode].value = 1;
3208 else if (m[opt_mode+1].value) {
3209 *mode = NETGAME_TEAM_ANARCHY;
3211 else if (m[opt_capture].value)
3212 *mode = NETGAME_CAPTURE_FLAG;
3213 else if (HoardEquipped() && m[opt_capture+1].value)
3214 *mode = NETGAME_HOARD;
3215 else if (HoardEquipped() && m[opt_capture+2].value)
3216 *mode = NETGAME_TEAM_HOARD;
3217 else if (anarchy_only) {
3218 nm_messagebox(NULL, 1, TXT_OK, TXT_ANARCHY_ONLY_MISSION);
3219 m[opt_mode+2].value = 0;
3220 m[opt_mode+3].value = 0;
3221 m[opt_mode].value = 1;
3224 else if ( m[opt_mode+2].value )
3225 *mode = NETGAME_ROBOT_ANARCHY;
3226 else if ( m[opt_mode+3].value )
3227 *mode = NETGAME_COOPERATIVE;
3228 else Int3(); // Invalid mode -- see Rob
3230 if (m[opt_closed].value)
3231 Netgame.game_flags |= NETGAME_FLAG_CLOSED;
3239 network_set_game_mode(int gamemode)
3243 if ( gamemode == NETGAME_ANARCHY )
3244 Game_mode = GM_NETWORK;
3245 else if ( gamemode == NETGAME_ROBOT_ANARCHY )
3246 Game_mode = GM_NETWORK | GM_MULTI_ROBOTS;
3247 else if ( gamemode == NETGAME_COOPERATIVE )
3248 Game_mode = GM_NETWORK | GM_MULTI_COOP | GM_MULTI_ROBOTS;
3249 else if (gamemode == NETGAME_CAPTURE_FLAG)
3251 Game_mode = GM_NETWORK | GM_TEAM | GM_CAPTURE;
3255 else if (HoardEquipped() && gamemode == NETGAME_HOARD)
3256 Game_mode = GM_NETWORK | GM_HOARD;
3257 else if (HoardEquipped() && gamemode == NETGAME_TEAM_HOARD)
3259 Game_mode = GM_NETWORK | GM_HOARD | GM_TEAM;
3262 else if ( gamemode == NETGAME_TEAM_ANARCHY )
3264 Game_mode = GM_NETWORK | GM_TEAM;
3271 #ifdef MACINTOSH // minimize players on localtalk games
3272 if ( (Network_game_type == APPLETALK_GAME) && (Network_appletalk_type == LOCALTALK_TYPE) ) {
3273 if (Game_mode & GM_MULTI_ROBOTS)
3274 MaxNumNetPlayers = 2;
3276 MaxNumNetPlayers = 3;
3278 if (Game_mode & GM_MULTI_COOP)
3279 MaxNumNetPlayers = 4;
3281 MaxNumNetPlayers = 8;
3289 network_find_game(void)
3291 // Find out whether or not there is space left on this socket
3295 Network_status = NETSTAT_BROWSING;
3297 num_active_games = 0;
3299 show_boxed_message(TXT_WAIT);
3301 network_send_game_list_request();
3302 t1 = timer_get_approx_seconds() + F1_0*3;
3304 while (timer_get_approx_seconds() < t1) // Wait 3 seconds for replies
3307 clear_boxed_message();
3309 // mprintf((0, "%s %d %s\n", TXT_FOUND, num_active_games, TXT_ACTIVE_GAMES));
3311 if (num_active_games < MAX_ACTIVE_NETGAMES)
3316 void network_read_sync_packet( netgame_info * sp, int rsinit)
3319 netgame_info tmp_info;
3323 char temp_callsign[CALLSIGN_LEN+1];
3326 if ( (Network_game_type == IPX_GAME) && (sp != &Netgame) ) { // for macintosh -- get the values unpacked to our structure format
3327 receive_netgame_packet((ubyte *)sp, &tmp_info, 0);
3333 TempPlayersInfo=&NetPlayers;
3335 // This function is now called by all people entering the netgame.
3337 // mprintf( (0, "%s %d\n", TXT_STARTING_NETGAME, sp->levelnum ));
3341 memcpy( &Netgame, sp, sizeof(netgame_info) );
3342 memcpy (&NetPlayers,TempPlayersInfo,sizeof (AllNetPlayers_info));
3345 N_players = sp->numplayers;
3346 Difficulty_level = sp->difficulty;
3347 Network_status = sp->game_status;
3349 //Assert(Function_mode != FMODE_GAME);
3353 mprintf((1, "Netgame.checksum = %d, calculated checksum = %d.\n", Netgame.segments_checksum, my_segments_checksum));
3355 if (Netgame.segments_checksum != my_segments_checksum)
3357 Network_status = NETSTAT_MENU;
3358 nm_messagebox(TXT_ERROR, 1, TXT_OK, TXT_NETLEVEL_NMATCH);
3364 // Discover my player number