1 /* $Id: network.c,v 1.24 2003-10-12 09:38:48 btb Exp $ */
3 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
4 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
5 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
6 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
7 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
8 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
9 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
10 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
11 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
12 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
17 * Routines for managing network play.
26 static char rcsid[] = "$Id: network.c,v 1.24 2003-10-12 09:38:48 btb Exp $";
79 #include <Errors.h> // for appletalk networking errors
83 #define LHX(x) ((x)*(MenuHires?2:1))
84 #define LHY(y) ((y)*(MenuHires?2.4:1))
86 /* the following are the possible packet identificators.
87 * they are stored in the "type" field of the packet structs.
88 * they are offset 4 bytes from the beginning of the raw IPX data
89 * because of the "driver's" ipx_packetnum (see linuxnet.c).
91 #define PID_LITE_INFO 43 // 0x2B lite game info
92 #define PID_SEND_ALL_GAMEINFO 44 // 0x2C plz send more than lite only
93 #define PID_PLAYERSINFO 45 // 0x2D here's my name & personal data
94 #define PID_REQUEST 46 // 0x2E may i join, plz send sync
95 #define PID_SYNC 47 // 0x2F master says: enter mine now!
96 #define PID_PDATA 48 // 0x30
97 #define PID_ADDPLAYER 49
99 #define PID_DUMP 51 // 0x33 you can't join this game
100 #define PID_ENDLEVEL 52
102 #define PID_QUIT_JOINING 54
103 #define PID_OBJECT_DATA 55 // array of bots, players, powerups, ...
104 #define PID_GAME_LIST 56 // 0x38 give me the list of your games
105 #define PID_GAME_INFO 57 // 0x39 here's a game i've started
106 #define PID_PING_SEND 58
107 #define PID_PING_RETURN 59
108 #define PID_GAME_UPDATE 60 // inform about new player/team change
109 #define PID_ENDLEVEL_SHORT 61
110 #define PID_NAKED_PDATA 62
111 #define PID_GAME_PLAYERS 63
112 #define PID_NAMES_RETURN 64 // 0x40
115 #define NETGAME_ANARCHY 0
116 #define NETGAME_TEAM_ANARCHY 1
117 #define NETGAME_ROBOT_ANARCHY 2
118 #define NETGAME_COOPERATIVE 3
119 #define NETGAME_CAPTURE_FLAG 4
120 #define NETGAME_HOARD 5
121 #define NETGAME_TEAM_HOARD 6
123 /* The following are values for NetSecurityFlag */
124 #define NETSECURITY_OFF 0
125 #define NETSECURITY_WAIT_FOR_PLAYERS 1
126 #define NETSECURITY_WAIT_FOR_GAMEINFO 2
127 #define NETSECURITY_WAIT_FOR_SYNC 3
128 /* The NetSecurityNum and the "Security" field of the network structs
129 * identifies a netgame. It is a random number chosen by the network master
130 * (the one that did "start netgame").
133 // MWA -- these structures are aligned -- please save me sanity and
134 // headaches by keeping alignment if these are changed!!!! Contact
137 typedef struct endlevel_info {
142 short kill_matrix[MAX_PLAYERS][MAX_PLAYERS];
147 typedef struct endlevel_info_short {
152 } endlevel_info_short;
154 // WARNING!!! This is the top part of netgame_info...if that struct changes,
155 // this struct much change as well. ie...they are aligned and the join system will
156 // not work without it.
158 // MWA if this structure changes -- please make appropriate changes to receive_netgame_info
159 // code for macintosh in netmisc.c
161 typedef struct lite_info {
164 char game_name[NETGAME_NAME_LEN+1];
165 char mission_title[MISSION_NAME_LEN+1];
166 char mission_name[9];
173 ubyte max_numplayers;
176 ubyte protocol_version;
180 } __pack__ lite_info;
182 // IF YOU CHANGE THE SIZE OF ANY OF THE FOLLOWING STRUCTURES
183 // MAKE THE MACINTOSH DEFINES BE THE SAME SIZE AS THE PC OR
184 // I WILL HAVE TO HURT YOU VERY BADLY!!! -- MWA
187 #define NETGAME_INFO_SIZE ( Network_game_type == IPX_GAME?355:sizeof(netgame_info) )
188 #define ALLNETPLAYERSINFO_SIZE ( Network_game_type == IPX_GAME?317:sizeof(AllNetPlayers_info) )
189 #define LITE_INFO_SIZE ( Network_game_type == IPX_GAME?72:sizeof(lite_info) )
190 #define SEQUENCE_PACKET_SIZE ( Network_game_type == IPX_GAME?34:sizeof(sequence_packet) )
191 #define FRAME_INFO_SIZE ( Network_game_type == IPX_GAME?541:sizeof(frame_info) )
192 #define IPX_SHORT_INFO_SIZE ( 490 )
194 #define NETGAME_INFO_SIZE sizeof(netgame_info)
195 #define ALLNETPLAYERSINFO_SIZE sizeof(AllNetPlayers_info)
196 #define LITE_INFO_SIZE sizeof(lite_info)
197 #define SEQUENCE_PACKET_SIZE sizeof(sequence_packet)
198 #define FRAME_INFO_SIZE sizeof(frame_info)
199 #define IPX_SHORT_INFO_SIZE sizeof(short_frame_info)
202 #define MAX_ACTIVE_NETGAMES 12
204 netgame_info Active_games[MAX_ACTIVE_NETGAMES];
205 AllNetPlayers_info ActiveNetPlayers[MAX_ACTIVE_NETGAMES];
206 AllNetPlayers_info *TempPlayersInfo,TempPlayersBase;
207 int NamesInfoSecurity=-1;
209 // MWAnetgame_info *TempNetInfo;
210 netgame_info TempNetInfo;
212 extern void multi_send_drop_marker (int player,vms_vector position,char messagenum,char text[]);
213 extern void multi_send_kill_goal_counts();
214 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) );
216 void network_process_naked_pdata (char *,int);
217 extern void multi_send_robot_controls(char);
219 void network_flush();
220 void network_listen();
221 void network_update_netgame();
222 void network_check_for_old_version(char pnum);
223 void network_send_objects();
224 void network_send_rejoin_sync(int player_num);
225 void network_send_game_info(sequence_packet *their);
226 void network_send_endlevel_short_sub(int from_player_num, int to_player);
227 void network_read_sync_packet(netgame_info * sp, int rsinit);
228 int network_wait_for_playerinfo();
229 void network_process_pdata(char *data);
230 void network_read_object_packet(ubyte *data );
231 void network_read_endlevel_packet(ubyte *data );
232 void network_read_endlevel_short_packet(ubyte *data );
233 void network_ping(ubyte flat, int pnum);
234 void network_handle_ping_return(ubyte pnum);
235 void network_process_names_return(char *data);
236 void network_send_player_names(sequence_packet *their);
237 int network_choose_connect();
238 void network_more_game_options();
239 void network_count_powerups_in_mine();
240 int network_wait_for_all_info(int choice);
241 void network_AdjustMaxDataSize();
242 void network_do_big_wait(int choice);
243 void network_send_extras();
244 void network_read_pdata_packet(frame_info *pd);
245 void network_read_pdata_short_packet(short_frame_info *pd);
247 void ClipRank(signed char *rank);
248 void DoRefuseStuff(sequence_packet *their);
249 int GetNewPlayerNumber(sequence_packet *their);
250 void SetAllAllowablesTo(int on);
252 int num_active_games = 0;
253 int PacketsPerSec=10;
254 int MaxXDataSize=NET_XDATA_SIZE;
256 int Netlife_kills=0, Netlife_killed=0;
259 int Network_active=0;
261 int Network_status = 0;
262 int Network_games_changed = 0;
264 int Network_socket = 0;
265 int Network_allow_socket_changes = 1;
267 int NetSecurityFlag=NETSECURITY_OFF;
268 int NetSecurityNum=0;
269 int Network_sending_extras=0;
270 int VerifyPlayerJoined=-1;
271 int Player_joining_extras=-1; // This is so we know who to send 'latecomer' packets to.
272 // We could just send updates to everyone but that kills the sender!
274 // For rejoin object syncing
276 int Network_rejoined = 0; // Did WE rejoin this game?
277 int Network_new_game = 0; // Is this the first level of a new game?
278 int Network_send_objects = 0; // Are we in the process of sending objects to a player?
279 int Network_send_objnum = -1; // What object are we sending next?
280 int Network_player_added = 0; // Is this a new player or a returning player?
281 int Network_send_object_mode = 0; // What type of objects are we sending, static or dynamic?
282 sequence_packet Network_player_rejoining; // Who is rejoining now?
284 fix LastPacketTime[MAX_PLAYERS]; // For timeouts of idle/crashed players
286 int PacketUrgent = 0;
288 int TotalMissedPackets=0,TotalPacketsGot=0;
290 frame_info MySyncPack,UrgentSyncPack;
291 ubyte MySyncPackInitialized = 0; // Set to 1 if the MySyncPack is zeroed.
292 ushort my_segments_checksum = 0;
294 sequence_packet My_Seq;
295 char WantPlayersInfo=0;
296 char WaitingForPlayerInfo=0;
298 char *RankStrings[]={"(unpatched) ","Cadet ","Ensign ","Lieutenant ","Lt.Commander ",
299 "Commander ","Captain ","Vice Admiral ","Admiral ","Demigod "};
301 extern obj_position Player_init[MAX_PLAYERS];
303 extern int force_cockpit_redraw;
305 // reasons for a packet with type PID_DUMP
306 #define DUMP_CLOSED 0 // no new players allowed after game started
307 #define DUMP_FULL 1 // player cound maxed out
308 #define DUMP_ENDLEVEL 2
310 #define DUMP_ABORTED 4
311 #define DUMP_CONNECTED 5 // never used
313 #define DUMP_KICKED 7 // never used
315 extern ubyte Version_major,Version_minor;
316 extern ubyte SurfingNet;
317 extern char MaxPowerupsAllowed[MAX_POWERUP_TYPES];
318 extern char PowerupsInMine[MAX_POWERUP_TYPES];
320 extern void multi_send_stolen_items();
322 int network_wait_for_snyc();
323 extern void multi_send_wall_status (int,ubyte,ubyte,ubyte);
324 extern void multi_send_wall_status_specific (int,int,ubyte,ubyte,ubyte);
326 extern void game_disable_cheats();
330 FILE *SendLogFile,*RecieveLogFile;
331 int TTSent[100],TTRecv[100];
334 extern int Final_boss_is_dead;
336 // following is network stuff for appletalk
338 void network_dump_appletalk_player(ubyte node, ushort net, ubyte socket, int why);
340 #define NETWORK_OEM 0x10
344 int Network_game_type; // used to tell IPX vs. appletalk games
346 #define MAX_ZONES 255
347 #define MAX_ZONE_LENGTH 33
348 #define DEFAULT_ZONE_NAME "\p*"
349 #define MAX_REGISTER_TRIES 5 // maximum time we will try and register a netgame
350 char Network_zone_name[MAX_ZONE_LENGTH]; // zone name game being played in for appletalk
351 char Zone_names[MAX_ZONES][MAX_ZONE_LENGTH]; // total list of zones that we can see
352 ubyte appletalk_use_broadcast = 0;
353 ubyte Network_game_validated = 0; // validates a game before being able to join
354 ubyte Network_game_validate_choice = 0;
355 ubyte Network_appletalk_type = 0; // type of appletalk network game is being played on
357 #define ETHERTALK_TYPE 0
358 #define LOCALTALK_TYPE 1
359 #define OTHERTALK_TYPE 2
362 void network_release_registered_game(void);
370 // So you want to play a netgame, eh? Let's a get a few things
374 int save_pnum = Player_num;
376 game_disable_cheats();
378 Final_boss_is_dead=0;
379 NamesInfoSecurity=-1;
387 for (t=0;t<MAX_POWERUP_TYPES;t++)
389 MaxPowerupsAllowed[t]=0;
393 TotalMissedPackets=0; TotalPacketsGot=0;
395 memset(&Netgame, 0, sizeof(netgame_info));
396 memset(&NetPlayers,0,sizeof(AllNetPlayers_info));
397 memset(&My_Seq, 0, sizeof(sequence_packet));
398 My_Seq.type = PID_REQUEST;
399 memcpy(My_Seq.player.callsign, Players[Player_num].callsign, CALLSIGN_LEN+1);
402 Version_minor|=NETWORK_OEM;
404 My_Seq.player.version_major=Version_major;
405 My_Seq.player.version_minor=Version_minor;
406 My_Seq.player.rank=GetMyNetRanking();
408 if (Network_game_type == IPX_GAME) {
409 memcpy(My_Seq.player.network.ipx.node, ipx_get_my_local_address(), 6);
410 memcpy(My_Seq.player.network.ipx.server, ipx_get_my_server_address(), 4 );
413 My_Seq.player.network.appletalk.node = appletalk_get_my_node();
414 My_Seq.player.network.appletalk.net = appletalk_get_my_net();
415 My_Seq.player.network.appletalk.socket = appletalk_get_my_socket();
419 My_Seq.player.computer_type = MAC;
421 My_Seq.player.computer_type = DOS;
424 for (Player_num = 0; Player_num < MAX_NUM_NET_PLAYERS; Player_num++)
425 init_player_stats_game();
427 Player_num = save_pnum;
429 Network_new_game = 1;
430 Control_center_destroyed = 0;
433 Netgame.PacketsPerSec=10;
435 if ((t=FindArg("-packets")))
437 Netgame.PacketsPerSec=atoi(Args[t+1]);
438 if (Netgame.PacketsPerSec<1)
439 Netgame.PacketsPerSec=1;
440 else if (Netgame.PacketsPerSec>20)
441 Netgame.PacketsPerSec=20;
442 mprintf ((0,"Will send %d packets per second",Netgame.PacketsPerSec));
444 if (FindArg("-shortpackets"))
446 Netgame.ShortPackets=1;
447 mprintf ((0,"Will send short packets.\n"));
452 network_i_am_master(void)
454 // I am the lowest numbered player in this game?
458 if (!(Game_mode & GM_NETWORK))
459 return (Player_num == 0);
461 for (i = 0; i < Player_num; i++)
462 if (Players[i].connected)
467 int network_who_is_master(void)
469 // Who is the master of this game?
473 if (!(Game_mode & GM_NETWORK))
474 return (Player_num == 0);
476 for (i = 0; i < N_players; i++)
477 if (Players[i].connected)
481 int network_how_many_connected()
485 for (i = 0; i < N_players; i++)
486 if (Players[i].connected)
491 #define ENDLEVEL_SEND_INTERVAL (F1_0*2)
492 #define ENDLEVEL_IDLE_TIME (F1_0*20)
495 network_endlevel_poll( int nitems, newmenu_item * menus, int * key, int citem )
497 // Polling loop for End-of-level menu
505 int previous_state[MAX_NUM_NET_PLAYERS];
506 int previous_seconds_left;
513 // Send our endlevel packet at regular intervals
515 if (timer_get_approx_seconds() > (t1+ENDLEVEL_SEND_INTERVAL))
517 network_send_endlevel_packet();
518 t1 = timer_get_approx_seconds();
521 for (i = 0; i < N_players; i++)
522 previous_state[i] = Players[i].connected;
524 previous_seconds_left = Countdown_seconds_left;
528 for (i = 0; i < N_players; i++)
530 if (Players[i].connected == 1)
532 // Check timeout for idle players
533 if (timer_get_approx_seconds() > LastPacketTime[i]+ENDLEVEL_IDLE_TIME)
535 mprintf((0, "idle timeout for player %d.\n", i));
536 Players[i].connected = 0;
537 network_send_endlevel_sub(i);
541 if ((Players[i].connected != 1) && (Players[i].connected != 5) && (Players[i].connected != 6))
543 if (Players[i].connected != 1)
545 if (Players[i].connected == 4)
549 if (num_escaped == N_players) // All players are out of the mine
551 Countdown_seconds_left = -1;
555 if (num_ready == N_players) // All players have checked in or are disconnected
565 network_endlevel_poll2( int nitems, newmenu_item * menus, int * key, int citem )
567 // Polling loop for End-of-level menu
579 // Send our endlevel packet at regular intervals
581 if (timer_get_approx_seconds() > (t1+ENDLEVEL_SEND_INTERVAL))
583 network_send_endlevel_packet();
584 t1 = timer_get_approx_seconds();
587 // mprintf ((0,"Trying to listen!\n"));
590 for (i = 0; i < N_players; i++)
592 if ((Players[i].connected != 1) && (Players[i].connected != 5) && (Players[i].connected != 6))
594 if (Players[i].connected == 4)
598 if (num_ready == N_players) // All players have checked in or are disconnected
608 extern fix StartAbortMenuTime;
611 network_endlevel_poll3( int nitems, newmenu_item * menus, int * key, int citem )
613 // Polling loop for End-of-level menu
622 if (timer_get_approx_seconds() > (StartAbortMenuTime+(F1_0 * 8)))
629 for (i = 0; i < N_players; i++)
630 if ((Players[i].connected != 1) && (Players[i].connected != 5) && (Players[i].connected != 6))
633 if (num_ready == N_players) // All players have checked in or are disconnected
640 network_endlevel(int *secret)
642 // Do whatever needs to be done between levels
650 Network_status = NETSTAT_ENDLEVEL; // We are between levels
654 network_send_endlevel_packet();
656 for (i=0; i<N_players; i++)
658 LastPacketTime[i] = timer_get_approx_seconds();
661 network_send_endlevel_packet();
662 network_send_endlevel_packet();
663 MySyncPackInitialized = 0;
665 network_update_netgame();
671 can_join_netgame(netgame_info *game,AllNetPlayers_info *people)
673 // Can this player rejoin a netgame in progress?
677 if (game->game_status == NETSTAT_STARTING)
680 if (game->game_status != NETSTAT_PLAYING)
682 mprintf ((0,"Error: Can't join because game_status !=NETSTAT_PLAYING\n"));
686 if (game->version_major==0 && Version_major>0)
688 mprintf ((0,"Error:Can't join because version majors don't match!\n"));
692 if (game->version_major>0 && Version_major==0)
694 mprintf ((0,"Error:Can't join because version majors2 don't match!\n"));
698 // Game is in progress, figure out if this guy can re-join it
700 num_players = game->numplayers;
702 if (!(game->game_flags & NETGAME_FLAG_CLOSED)) {
703 // Look for player that is not connected
705 if (game->numconnected==game->max_numplayers)
708 // mprintf ((0,"Refuse = %d\n",game->RefusePlayers));
710 if (game->RefusePlayers)
713 if (game->numplayers < game->max_numplayers)
716 if (game->numconnected<num_players)
723 mprintf ((0,"Error! Can't join because people==NULL!\n"));
727 // Search to see if we were already in this closed netgame in progress
729 for (i = 0; i < num_players; i++) {
730 if (Network_game_type == IPX_GAME) {
731 if ( (!stricmp(Players[Player_num].callsign, people->players[i].callsign)) &&
732 (!memcmp(My_Seq.player.network.ipx.node, people->players[i].network.ipx.node, 6)) &&
733 (!memcmp(My_Seq.player.network.ipx.server, people->players[i].network.ipx.server, 4)) )
736 if ( (!stricmp(Players[Player_num].callsign, people->players[i].callsign)) &&
737 (My_Seq.player.network.appletalk.node == people->players[i].network.appletalk.node) &&
738 (My_Seq.player.network.appletalk.net == people->players[i].network.appletalk.net) )
743 if (i != num_players)
746 mprintf ((0,"Error: Can't join because at end of list!\n"));
751 network_disconnect_player(int playernum)
753 // A player has disconnected from the net game, take whatever steps are
756 if (playernum == Player_num)
758 Int3(); // Weird, see Rob
762 Players[playernum].connected = 0;
763 NetPlayers.players[playernum].connected = 0;
764 if (VerifyPlayerJoined==playernum)
765 VerifyPlayerJoined=-1;
767 // create_player_appearance_effect(&Objects[Players[playernum].objnum]);
768 multi_make_player_ghost(playernum);
770 if (Newdemo_state == ND_STATE_RECORDING)
771 newdemo_record_multi_disconnect(playernum);
773 multi_strip_robots(playernum);
777 network_new_player(sequence_packet *their)
782 pnum = their->player.connected;
785 Assert(pnum < MaxNumNetPlayers);
787 objnum = Players[pnum].objnum;
789 if (Newdemo_state == ND_STATE_RECORDING) {
792 if (pnum == N_players)
796 newdemo_record_multi_connect(pnum, new_player, their->player.callsign);
799 memcpy(Players[pnum].callsign, their->player.callsign, CALLSIGN_LEN+1);
800 memcpy(NetPlayers.players[pnum].callsign, their->player.callsign, CALLSIGN_LEN+1);
803 ClipRank (&their->player.rank);
804 NetPlayers.players[pnum].rank=their->player.rank;
805 NetPlayers.players[pnum].version_major=their->player.version_major;
806 NetPlayers.players[pnum].version_minor=their->player.version_minor;
807 network_check_for_old_version(pnum);
809 if (Network_game_type == IPX_GAME) {
810 if ( (*(uint *)their->player.network.ipx.server) != 0 )
811 ipx_get_local_target( their->player.network.ipx.server, their->player.network.ipx.node, Players[pnum].net_address );
813 memcpy(Players[pnum].net_address, their->player.network.ipx.node, 6);
815 memcpy(NetPlayers.players[pnum].network.ipx.node, their->player.network.ipx.node, 6);
816 memcpy(NetPlayers.players[pnum].network.ipx.server, their->player.network.ipx.server, 4);
818 NetPlayers.players[pnum].network.appletalk.node = their->player.network.appletalk.node;
819 NetPlayers.players[pnum].network.appletalk.net = their->player.network.appletalk.net;
820 NetPlayers.players[pnum].network.appletalk.socket = their->player.network.appletalk.socket;
823 Players[pnum].n_packets_got = 0;
824 Players[pnum].connected = 1;
825 Players[pnum].net_kills_total = 0;
826 Players[pnum].net_killed_total = 0;
827 memset(kill_matrix[pnum], 0, MAX_PLAYERS*sizeof(short));
828 Players[pnum].score = 0;
829 Players[pnum].flags = 0;
830 Players[pnum].KillGoalCount=0;
832 if (pnum == N_players)
835 Netgame.numplayers = N_players;
838 digi_play_sample(SOUND_HUD_MESSAGE, F1_0);
840 ClipRank (&their->player.rank);
842 if (FindArg("-norankings"))
843 HUD_init_message("'%s' %s\n",their->player.callsign, TXT_JOINING);
845 HUD_init_message("%s'%s' %s\n",RankStrings[their->player.rank],their->player.callsign, TXT_JOINING);
847 multi_make_ghost_player(pnum);
850 multi_sort_kill_list();
852 // create_player_appearance_effect(&Objects[objnum]);
855 char RefuseThisPlayer=0,WaitForRefuseAnswer=0,RefuseTeam;
856 char RefusePlayerName[12];
857 fix RefuseTimeLimit=0;
859 void network_welcome_player(sequence_packet *their)
861 // Add a player to a game already in progress
862 ubyte local_address[6];
866 WaitForRefuseAnswer=0;
868 if (FindArg("-NoMatrixCheat"))
870 if ((their->player.version_minor & 0x0F) < 3)
872 network_dump_player(their->player.network.ipx.server, their->player.network.ipx.node, DUMP_DORK);
879 // If hoard game, and this guy isn't D2 Christmas (v1.2), dump him
881 if ((Game_mode & GM_HOARD) && ((their->player.version_minor & 0x0F)<2))
883 if (Network_game_type == IPX_GAME)
884 network_dump_player(their->player.network.ipx.server, their->player.network.ipx.node, DUMP_DORK);
887 network_dump_appletalk_player(their->player.network.appletalk.node, their->player.network.appletalk.net, their->player.network.appletalk.socket, DUMP_DORK);
893 // Don't accept new players if we're ending this level. Its safe to
894 // ignore since they'll request again later
896 if ((Endlevel_sequence) || (Control_center_destroyed))
898 mprintf((0, "Ignored request from new player to join during endgame.\n"));
899 if (Network_game_type == IPX_GAME)
900 network_dump_player(their->player.network.ipx.server,their->player.network.ipx.node, DUMP_ENDLEVEL);
903 network_dump_appletalk_player(their->player.network.appletalk.node, their->player.network.appletalk.net, their->player.network.appletalk.socket, DUMP_ENDLEVEL);
908 if (Network_send_objects || Network_sending_extras)
910 // Ignore silently, we're already responding to someone and we can't
911 // do more than one person at a time. If we don't dump them they will
912 // re-request in a few seconds.
916 if (their->player.connected != Current_level_num)
918 mprintf((0, "Dumping player due to old level number.\n"));
919 if (Network_game_type == IPX_GAME)
920 network_dump_player(their->player.network.ipx.server, their->player.network.ipx.node, DUMP_LEVEL);
923 network_dump_appletalk_player(their->player.network.appletalk.node, their->player.network.appletalk.net, their->player.network.appletalk.socket, DUMP_LEVEL);
929 memset(&Network_player_rejoining, 0, sizeof(sequence_packet));
930 Network_player_added = 0;
932 if (Network_game_type == IPX_GAME) {
933 if ( (*(uint *)their->player.network.ipx.server) != 0 )
934 ipx_get_local_target( their->player.network.ipx.server, their->player.network.ipx.node, local_address );
936 memcpy(local_address, their->player.network.ipx.node, 6);
939 for (i = 0; i < N_players; i++)
941 if ( (Network_game_type == IPX_GAME) && (!stricmp(Players[i].callsign, their->player.callsign )) && (!memcmp(Players[i].net_address,local_address, 6)) )
946 #ifdef MACINTOSH // note link to above if
947 else if ( (!stricmp(Players[i].callsign, their->player.callsign)) &&
948 (NetPlayers.players[i].network.appletalk.node == their->player.network.appletalk.node) &&
949 (NetPlayers.players[i].network.appletalk.net == their->player.network.appletalk.net)) {
956 if (player_num == -1)
958 // Player is new to this game
960 if ( !(Netgame.game_flags & NETGAME_FLAG_CLOSED) && (N_players < MaxNumNetPlayers))
962 // Add player in an open slot, game not full yet
964 player_num = N_players;
965 Network_player_added = 1;
967 else if (Netgame.game_flags & NETGAME_FLAG_CLOSED)
969 // Slots are open but game is closed
971 if (Network_game_type == IPX_GAME)
972 network_dump_player(their->player.network.ipx.server, their->player.network.ipx.node, DUMP_CLOSED);
975 network_dump_appletalk_player(their->player.network.appletalk.node, their->player.network.appletalk.net, their->player.network.appletalk.socket, DUMP_CLOSED);
981 // Slots are full but game is open, see if anyone is
982 // disconnected and replace the oldest player with this new one
984 int oldest_player = -1;
985 fix oldest_time = timer_get_approx_seconds();
987 Assert(N_players == MaxNumNetPlayers);
989 for (i = 0; i < N_players; i++)
991 if ( (!Players[i].connected) && (LastPacketTime[i] < oldest_time))
993 oldest_time = LastPacketTime[i];
998 if (oldest_player == -1)
1000 // Everyone is still connected
1002 if (Network_game_type == IPX_GAME)
1003 network_dump_player(their->player.network.ipx.server, their->player.network.ipx.node, DUMP_FULL);
1006 network_dump_appletalk_player(their->player.network.appletalk.node, their->player.network.appletalk.net, their->player.network.appletalk.socket, DUMP_FULL);
1014 player_num = oldest_player;
1015 Network_player_added = 1;
1021 // Player is reconnecting
1023 if (Players[player_num].connected)
1025 mprintf((0, "Extra REQUEST from player ignored.\n"));
1029 if (Newdemo_state == ND_STATE_RECORDING)
1030 newdemo_record_multi_reconnect(player_num);
1032 Network_player_added = 0;
1034 digi_play_sample(SOUND_HUD_MESSAGE, F1_0);
1036 if (FindArg("-norankings"))
1037 HUD_init_message("'%s' %s", Players[player_num].callsign, TXT_REJOIN);
1039 HUD_init_message("%s'%s' %s", RankStrings[NetPlayers.players[player_num].rank],Players[player_num].callsign, TXT_REJOIN);
1042 Players[player_num].KillGoalCount=0;
1044 // Send updated Objects data to the new/returning player
1047 Network_player_rejoining = *their;
1048 Network_player_rejoining.player.connected = player_num;
1049 Network_send_objects = 1;
1050 Network_send_objnum = -1;
1052 network_send_objects();
1055 int network_objnum_is_past(int objnum)
1057 // determine whether or not a given object number has already been sent
1058 // to a re-joining player.
1060 int player_num = Network_player_rejoining.player.connected;
1061 int obj_mode = !((object_owner[objnum] == -1) || (object_owner[objnum] == player_num));
1063 if (!Network_send_objects)
1064 return 0; // We're not sending objects to a new player
1066 if (obj_mode > Network_send_object_mode)
1068 else if (obj_mode < Network_send_object_mode)
1070 else if (objnum < Network_send_objnum)
1076 #define OBJ_PACKETS_PER_FRAME 1
1077 extern void multi_send_active_door(char);
1078 extern void multi_send_door_open_specific(int,int,int,ubyte);
1081 void network_send_door_updates(int pnum)
1083 // Send door status when new player joins
1089 // Assert (pnum>-1 && pnum<N_players);
1091 for (i = 0; i < Num_walls; i++)
1093 if ((Walls[i].type == WALL_DOOR) && ((Walls[i].state == WALL_DOOR_OPENING) || (Walls[i].state == WALL_DOOR_WAITING) || (Walls[i].state == WALL_DOOR_OPEN)))
1094 multi_send_door_open_specific(pnum,Walls[i].segnum, Walls[i].sidenum,Walls[i].flags);
1095 else if ((Walls[i].type == WALL_BLASTABLE) && (Walls[i].flags & WALL_BLASTED))
1096 multi_send_door_open_specific(pnum,Walls[i].segnum, Walls[i].sidenum,Walls[i].flags);
1097 else if ((Walls[i].type == WALL_BLASTABLE) && (Walls[i].hps != WALL_HPS))
1098 multi_send_hostage_door_status(i);
1100 multi_send_wall_status_specific(pnum,i,Walls[i].type,Walls[i].flags,Walls[i].state);
1104 extern vms_vector MarkerPoint[];
1105 void network_send_markers()
1107 // send marker positions/text to new player
1112 for (i = 0; i < N_players; i++)
1114 if (MarkerObject[(i*2)]!=-1)
1115 multi_send_drop_marker (i,MarkerPoint[(i*2)],0,MarkerMessage[i*2]);
1116 if (MarkerObject[(i*2)+1]!=-1)
1117 multi_send_drop_marker (i,MarkerPoint[(i*2)+1],1,MarkerMessage[(i*2)+1]);
1121 void network_process_monitor_vector(int vector)
1127 for (i=0; i <= Highest_segment_index; i++)
1131 for (j = 0; j < 6; j++)
1133 if ( ((tm = seg->sides[j].tmap_num2) != 0) &&
1134 ((ec = TmapInfo[tm&0x3fff].eclip_num) != -1) &&
1135 ((bm = Effects[ec].dest_bm_num) != -1) )
1137 if (vector & (1 << count))
1139 seg->sides[j].tmap_num2 = bm | (tm&0xc000);
1140 // mprintf((0, "Monitor %d blown up.\n", count));
1143 // mprintf((0, "Monitor %d intact.\n", count));
1151 int network_create_monitor_vector(void)
1154 int num_blown_bitmaps = 0;
1155 int monitor_num = 0;
1156 #define NUM_BLOWN_BITMAPS 20
1157 int blown_bitmaps[NUM_BLOWN_BITMAPS];
1161 for (i=0; i < Num_effects; i++)
1163 if (Effects[i].dest_bm_num > 0) {
1164 for (j = 0; j < num_blown_bitmaps; j++)
1165 if (blown_bitmaps[j] == Effects[i].dest_bm_num)
1167 if (j == num_blown_bitmaps) {
1168 blown_bitmaps[num_blown_bitmaps++] = Effects[i].dest_bm_num;
1169 Assert(num_blown_bitmaps < NUM_BLOWN_BITMAPS);
1174 // for (i = 0; i < num_blown_bitmaps; i++)
1175 // mprintf((0, "Blown bitmap #%d = %d.\n", i, blown_bitmaps[i]));
1177 for (i=0; i <= Highest_segment_index; i++)
1181 for (j = 0; j < 6; j++)
1183 if ((tm = seg->sides[j].tmap_num2) != 0)
1185 if ( ((ec = TmapInfo[tm&0x3fff].eclip_num) != -1) &&
1186 (Effects[ec].dest_bm_num != -1) )
1188 // mprintf((0, "Monitor %d intact.\n", monitor_num));
1190 Assert(monitor_num < 32);
1194 for (k = 0; k < num_blown_bitmaps; k++)
1196 if ((tm&0x3fff) == blown_bitmaps[k])
1198 //mprintf((0, "Monitor %d destroyed.\n", monitor_num));
1199 vector |= (1 << monitor_num);
1201 Assert(monitor_num < 32);
1209 // mprintf((0, "Final monitor vector %x.\n", vector));
1213 void network_stop_resync(sequence_packet *their)
1215 if (Network_game_type == IPX_GAME) {
1216 if ( (!memcmp(Network_player_rejoining.player.network.ipx.node, their->player.network.ipx.node, 6)) &&
1217 (!memcmp(Network_player_rejoining.player.network.ipx.server, their->player.network.ipx.server, 4)) &&
1218 (!stricmp(Network_player_rejoining.player.callsign, their->player.callsign)) )
1220 mprintf((0, "Aborting resync for player %s.\n", their->player.callsign));
1221 Network_send_objects = 0;
1222 Network_sending_extras=0;
1224 Player_joining_extras=-1;
1225 Network_send_objnum = -1;
1228 if ( (Network_player_rejoining.player.network.appletalk.node == their->player.network.appletalk.node) &&
1229 (Network_player_rejoining.player.network.appletalk.net == their->player.network.appletalk.net) &&
1230 (!stricmp(Network_player_rejoining.player.callsign, their->player.callsign)) )
1232 mprintf((0, "Aborting resync for player %s.\n", their->player.callsign));
1233 Network_send_objects = 0;
1234 Network_sending_extras=0;
1236 Player_joining_extras=-1;
1237 Network_send_objnum = -1;
1242 sbyte object_buffer[IPX_MAX_DATA_SIZE];
1244 void network_send_objects(void)
1246 short remote_objnum;
1250 static int obj_count = 0;
1251 static int frame_num = 0;
1253 int obj_count_frame = 0;
1254 int player_num = Network_player_rejoining.player.connected;
1256 // Send clear objects array trigger and send player num
1258 Assert(Network_send_objects != 0);
1259 Assert(player_num >= 0);
1260 Assert(player_num < MaxNumNetPlayers);
1262 if (Endlevel_sequence || Control_center_destroyed)
1264 // Endlevel started before we finished sending the goods, we'll
1265 // have to stop and try again after the level.
1267 if (Network_game_type == IPX_GAME)
1268 network_dump_player(Network_player_rejoining.player.network.ipx.server,Network_player_rejoining.player.network.ipx.node, DUMP_ENDLEVEL);
1271 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);
1273 Network_send_objects = 0;
1277 for (h = 0; h < OBJ_PACKETS_PER_FRAME; h++) // Do more than 1 per frame, try to speed it up without
1278 // over-stressing the receiver.
1280 obj_count_frame = 0;
1281 memset(object_buffer, 0, IPX_MAX_DATA_SIZE);
1282 object_buffer[0] = PID_OBJECT_DATA;
1285 if (Network_send_objnum == -1)
1288 Network_send_object_mode = 0;
1289 // mprintf((0, "Sending object array to player %d.\n", player_num));
1290 *(short *)(object_buffer+loc) = INTEL_SHORT(-1); loc += 2;
1291 object_buffer[loc] = player_num; loc += 1;
1292 /* Placeholder for remote_objnum, not used here */ loc += 2;
1293 Network_send_objnum = 0;
1294 obj_count_frame = 1;
1298 for (i = Network_send_objnum; i <= Highest_object_index; i++)
1300 if ((Objects[i].type != OBJ_POWERUP) && (Objects[i].type != OBJ_PLAYER) &&
1301 (Objects[i].type != OBJ_CNTRLCEN) && (Objects[i].type != OBJ_GHOST) &&
1302 (Objects[i].type != OBJ_ROBOT) && (Objects[i].type != OBJ_HOSTAGE) &&
1303 !(Objects[i].type==OBJ_WEAPON && Objects[i].id==PMINE_ID))
1305 if ((Network_send_object_mode == 0) && ((object_owner[i] != -1) && (object_owner[i] != player_num)))
1307 if ((Network_send_object_mode == 1) && ((object_owner[i] == -1) || (object_owner[i] == player_num)))
1310 if ( ((IPX_MAX_DATA_SIZE-1) - loc) < (sizeof(object)+5) )
1311 break; // Not enough room for another object
1316 remote_objnum = objnum_local_to_remote((short)i, &owner);
1317 Assert(owner == object_owner[i]);
1319 *(short *)(object_buffer+loc) = INTEL_SHORT((short)i); loc += 2;
1320 object_buffer[loc] = owner; loc += 1;
1321 *(short *)(object_buffer+loc) = INTEL_SHORT(remote_objnum); loc += 2;
1322 memcpy(&object_buffer[loc], &Objects[i], sizeof(object));
1323 if (Network_game_type == IPX_GAME)
1324 swap_object((object *)&object_buffer[loc]);
1325 loc += sizeof(object);
1326 // mprintf((0, "..packing object %d, remote %d\n", i, remote_objnum));
1329 if (obj_count_frame) // Send any objects we've buffered
1333 Network_send_objnum = i;
1334 object_buffer[1] = obj_count_frame; object_buffer[2] = frame_num;
1335 // mprintf((0, "Object packet %d contains %d objects.\n", frame_num, obj_count_frame));
1337 Assert(loc <= IPX_MAX_DATA_SIZE);
1339 if (Network_game_type == IPX_GAME)
1340 ipx_send_internetwork_packet_data( object_buffer, loc, Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node );
1343 appletalk_send_packet_data( object_buffer, loc, Network_player_rejoining.player.network.appletalk.node,
1344 Network_player_rejoining.player.network.appletalk.net,
1345 Network_player_rejoining.player.network.appletalk.socket);
1348 // OLD ipx_send_packet_data(object_buffer, loc, &Network_player_rejoining.player.node);
1351 if (i > Highest_object_index)
1353 if (Network_send_object_mode == 0)
1355 Network_send_objnum = 0;
1356 Network_send_object_mode = 1; // go to next mode
1360 Assert(Network_send_object_mode == 1);
1363 // Send count so other side can make sure he got them all
1364 // mprintf((0, "Sending end marker in packet #%d.\n", frame_num));
1365 mprintf((0, "Sent %d objects.\n", obj_count));
1366 object_buffer[0] = PID_OBJECT_DATA;
1367 object_buffer[1] = 1;
1368 object_buffer[2] = frame_num;
1369 *(short *)(object_buffer+3) = INTEL_SHORT(-2);
1370 *(short *)(object_buffer+6) = INTEL_SHORT(obj_count);
1371 //OLD ipx_send_packet_data(object_buffer, 8, &Network_player_rejoining.player.node);
1372 if (Network_game_type == IPX_GAME)
1373 ipx_send_internetwork_packet_data(object_buffer, 8, Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node);
1376 appletalk_send_packet_data( object_buffer, 8, Network_player_rejoining.player.network.appletalk.node,
1377 Network_player_rejoining.player.network.appletalk.net,
1378 Network_player_rejoining.player.network.appletalk.socket);
1382 // Send sync packet which tells the player who he is and to start!
1383 network_send_rejoin_sync(player_num);
1384 mprintf ((0,"VerfiyPlayerJoined is now set to %d\n",player_num));
1385 VerifyPlayerJoined=player_num;
1387 // Turn off send object mode
1388 Network_send_objnum = -1;
1389 Network_send_objects = 0;
1392 //if (!network_i_am_master ())
1393 // Int3(); // Bad!! Get Jason. Someone goofy is trying to get ahold of the game!
1395 Network_sending_extras=40; // start to send extras
1396 Player_joining_extras=player_num;
1400 } // i > Highest_object_index
1401 } // For PACKETS_PER_FRAME
1404 extern void multi_send_powerup_update();
1406 void network_send_rejoin_sync(int player_num)
1410 Players[player_num].connected = 1; // connect the new guy
1411 LastPacketTime[player_num] = timer_get_approx_seconds();
1413 if (Endlevel_sequence || Control_center_destroyed)
1415 // Endlevel started before we finished sending the goods, we'll
1416 // have to stop and try again after the level.
1418 if (Network_game_type == IPX_GAME)
1419 network_dump_player(Network_player_rejoining.player.network.ipx.server,Network_player_rejoining.player.network.ipx.node, DUMP_ENDLEVEL);
1422 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);
1424 Network_send_objects = 0;
1425 Network_sending_extras=0;
1429 if (Network_player_added)
1431 Network_player_rejoining.type = PID_ADDPLAYER;
1432 Network_player_rejoining.player.connected = player_num;
1433 network_new_player(&Network_player_rejoining);
1435 for (i = 0; i < N_players; i++)
1437 if ((i != player_num) && (i != Player_num) && (Players[i].connected))
1438 if (Network_game_type == IPX_GAME) {
1439 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) {
1469 send_internetwork_full_netgame_packet(Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node);
1470 send_netplayers_packet(Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node);
1473 appletalk_send_packet_data( (ubyte *)&Netgame, sizeof(netgame_info), Network_player_rejoining.player.network.appletalk.node,
1474 Network_player_rejoining.player.network.appletalk.net,
1475 Network_player_rejoining.player.network.appletalk.socket);
1476 appletalk_send_packet_data( (ubyte *)&NetPlayers, sizeof(AllNetPlayers_info), Network_player_rejoining.player.network.appletalk.node,
1477 Network_player_rejoining.player.network.appletalk.net,
1478 Network_player_rejoining.player.network.appletalk.socket);
1483 void resend_sync_due_to_packet_loss_for_allender ()
1487 mprintf ((0,"I'm resending a sync packet! VPJ=%d\n",VerifyPlayerJoined));
1489 network_update_netgame();
1491 // Fill in the kill list
1492 for (j=0; j<MAX_PLAYERS; j++)
1494 for (i=0; i<MAX_PLAYERS;i++)
1495 Netgame.kills[j][i] = kill_matrix[j][i];
1496 Netgame.killed[j] = Players[j].net_killed_total;
1497 Netgame.player_kills[j] = Players[j].net_kills_total;
1498 Netgame.player_score[j] = Players[j].score;
1501 Netgame.level_time = Players[Player_num].time_level;
1502 Netgame.monitor_vector = network_create_monitor_vector();
1504 if (Network_game_type == IPX_GAME) {
1505 send_internetwork_full_netgame_packet(Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node);
1506 send_netplayers_packet(Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node);
1509 appletalk_send_packet_data( (ubyte *)&Netgame, sizeof(netgame_info), Network_player_rejoining.player.network.appletalk.node,
1510 Network_player_rejoining.player.network.appletalk.net,
1511 Network_player_rejoining.player.network.appletalk.socket);
1512 appletalk_send_packet_data( (ubyte *)&NetPlayers, sizeof(AllNetPlayers_info), Network_player_rejoining.player.network.appletalk.node,
1513 Network_player_rejoining.player.network.appletalk.net,
1514 Network_player_rejoining.player.network.appletalk.socket);
1520 char * network_get_player_name( int objnum )
1522 if ( objnum < 0 ) return NULL;
1523 if ( Objects[objnum].type != OBJ_PLAYER ) return NULL;
1524 if ( Objects[objnum].id >= MAX_PLAYERS ) return NULL;
1525 if ( Objects[objnum].id >= N_players ) return NULL;
1527 return Players[Objects[objnum].id].callsign;
1531 void network_add_player(sequence_packet *p)
1535 mprintf((0, "Got add player request!\n"));
1537 for (i=0; i<N_players; i++ ) {
1538 if (Network_game_type == IPX_GAME) {
1539 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))
1540 return; // already got them
1542 if ( (NetPlayers.players[i].network.appletalk.node == p->player.network.appletalk.node) &&
1543 (NetPlayers.players[i].network.appletalk.net == p->player.network.appletalk.net))
1548 if (Network_game_type == IPX_GAME) {
1549 memcpy( NetPlayers.players[N_players].network.ipx.node, p->player.network.ipx.node, 6 );
1550 memcpy( NetPlayers.players[N_players].network.ipx.server, p->player.network.ipx.server, 4 );
1552 NetPlayers.players[N_players].network.appletalk.node = p->player.network.appletalk.node;
1553 NetPlayers.players[N_players].network.appletalk.net = p->player.network.appletalk.net;
1554 NetPlayers.players[N_players].network.appletalk.socket = p->player.network.appletalk.socket;
1557 ClipRank (&p->player.rank);
1559 memcpy( NetPlayers.players[N_players].callsign, p->player.callsign, CALLSIGN_LEN+1 );
1560 NetPlayers.players[N_players].version_major=p->player.version_major;
1561 NetPlayers.players[N_players].version_minor=p->player.version_minor;
1562 NetPlayers.players[N_players].rank=p->player.rank;
1563 NetPlayers.players[N_players].connected = 1;
1564 network_check_for_old_version (N_players);
1566 Players[N_players].KillGoalCount=0;
1567 Players[N_players].connected = 1;
1568 LastPacketTime[N_players] = timer_get_approx_seconds();
1570 Netgame.numplayers = N_players;
1572 // Broadcast updated info
1574 mprintf ((0,"sending_game_info!\n"));
1575 network_send_game_info(NULL);
1578 // One of the players decided not to join the game
1580 void network_remove_player(sequence_packet *p)
1585 for (i=0; i<N_players; i++ ) {
1586 if (Network_game_type == IPX_GAME) {
1587 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)) {
1592 if ( (NetPlayers.players[i].network.appletalk.node == p->player.network.appletalk.node) && (NetPlayers.players[i].network.appletalk.net == p->player.network.appletalk.net) ) {
1599 if (pn < 0 ) return;
1601 for (i=pn; i<N_players-1; i++ ) {
1602 if (Network_game_type == IPX_GAME) {
1603 memcpy( NetPlayers.players[i].network.ipx.node, NetPlayers.players[i+1].network.ipx.node, 6 );
1604 memcpy( NetPlayers.players[i].network.ipx.server, NetPlayers.players[i+1].network.ipx.server, 4 );
1606 NetPlayers.players[i].network.appletalk.node = NetPlayers.players[i+1].network.appletalk.node;
1607 NetPlayers.players[i].network.appletalk.net = NetPlayers.players[i+1].network.appletalk.net;
1608 NetPlayers.players[i].network.appletalk.socket = NetPlayers.players[i+1].network.appletalk.socket;
1610 memcpy( NetPlayers.players[i].callsign, NetPlayers.players[i+1].callsign, CALLSIGN_LEN+1 );
1611 NetPlayers.players[i].version_major=NetPlayers.players[i+1].version_major;
1612 NetPlayers.players[i].version_minor=NetPlayers.players[i+1].version_minor;
1614 NetPlayers.players[i].rank=NetPlayers.players[i+1].rank;
1615 ClipRank (&NetPlayers.players[i].rank);
1616 network_check_for_old_version(i);
1620 Netgame.numplayers = N_players;
1622 // Broadcast new info
1624 network_send_game_info(NULL);
1629 network_dump_player(ubyte * server, ubyte *node, int why)
1631 // Inform player that he was not chosen for the netgame
1633 sequence_packet temp;
1635 temp.type = PID_DUMP;
1636 memcpy(temp.player.callsign, Players[Player_num].callsign, CALLSIGN_LEN+1);
1637 temp.player.connected = why;
1638 if (Network_game_type == IPX_GAME) {
1639 send_internetwork_sequence_packet(temp, server, node);
1646 void network_dump_appletalk_player(ubyte node, ushort net, ubyte socket, int why)
1648 sequence_packet temp;
1650 temp.type = PID_DUMP;
1651 memcpy(temp.player.callsign, Players[Player_num].callsign, CALLSIGN_LEN+1);
1652 temp.player.connected = why;
1653 if (Network_game_type == APPLETALK_GAME) {
1654 appletalk_send_packet_data( (ubyte *)&temp, sizeof(sequence_packet), node, net, socket );
1662 network_send_game_list_request()
1664 // Send a broadcast request for game info
1668 mprintf((0, "Sending game_list request.\n"));
1669 me.type = PID_GAME_LIST;
1670 memcpy( me.player.callsign, Players[Player_num].callsign, CALLSIGN_LEN+1 );
1672 if (Network_game_type == IPX_GAME) {
1673 memcpy( me.player.network.ipx.node, ipx_get_my_local_address(), 6 );
1674 memcpy( me.player.network.ipx.server, ipx_get_my_server_address(), 4 );
1676 send_broadcast_sequence_packet(me);
1679 me.player.network.appletalk.node = appletalk_get_my_node();
1680 me.player.network.appletalk.net = appletalk_get_my_net();
1681 me.player.network.appletalk.socket = appletalk_get_my_socket();
1682 appletalk_send_game_info( (ubyte *)&me, sizeof(sequence_packet), Network_zone_name );
1687 void network_send_all_info_request(char type,int which_security)
1689 // Send a broadcast request for game info
1693 mprintf((0, "Sending all_info request.\n"));
1695 me.Security=which_security;
1697 memcpy( me.player.callsign, Players[Player_num].callsign, CALLSIGN_LEN+1 );
1699 if (Network_game_type == IPX_GAME) {
1700 memcpy( me.player.network.ipx.node, ipx_get_my_local_address(), 6 );
1701 memcpy( me.player.network.ipx.server, ipx_get_my_server_address(), 4 );
1703 send_broadcast_sequence_packet(me);
1706 me.player.network.appletalk.node = appletalk_get_my_node();
1707 me.player.network.appletalk.net = appletalk_get_my_net();
1708 me.player.network.appletalk.socket = appletalk_get_my_socket();
1709 appletalk_send_game_info( (ubyte *)&me, sizeof(sequence_packet), Network_zone_name );
1716 network_update_netgame(void)
1718 // Update the netgame struct with current game variables
1722 Netgame.numconnected=0;
1723 for (i=0;i<N_players;i++)
1724 if (Players[i].connected)
1725 Netgame.numconnected++;
1727 // This is great: D2 1.0 and 1.1 ignore upper part of the game_flags field of
1728 // the lite_info struct when you're sitting on the join netgame screen. We can
1729 // "sneak" Hoard information into this field. This is better than sending
1730 // another packet that could be lost in transit.
1733 if (HoardEquipped())
1735 if (Game_mode & GM_HOARD)
1737 Netgame.game_flags |=NETGAME_FLAG_HOARD;
1738 if (Game_mode & GM_TEAM)
1739 Netgame.game_flags |=NETGAME_FLAG_TEAM_HOARD;
1743 if (Network_status == NETSTAT_STARTING)
1746 Netgame.numplayers = N_players;
1747 Netgame.game_status = Network_status;
1748 Netgame.max_numplayers = MaxNumNetPlayers;
1750 for (i = 0; i < MAX_NUM_NET_PLAYERS; i++)
1752 NetPlayers.players[i].connected = Players[i].connected;
1753 for(j = 0; j < MAX_NUM_NET_PLAYERS; j++)
1754 Netgame.kills[i][j] = kill_matrix[i][j];
1756 Netgame.killed[i] = Players[i].net_killed_total;
1757 Netgame.player_kills[i] = Players[i].net_kills_total;
1758 Netgame.player_score[i] = Players[i].score;
1759 Netgame.player_flags[i] = (Players[i].flags & (PLAYER_FLAGS_BLUE_KEY | PLAYER_FLAGS_RED_KEY | PLAYER_FLAGS_GOLD_KEY));
1761 Netgame.team_kills[0] = team_kills[0];
1762 Netgame.team_kills[1] = team_kills[1];
1763 Netgame.levelnum = Current_level_num;
1769 network_send_endlevel_sub(int player_num)
1774 // Send an endlevel packet for a player
1775 end.type = PID_ENDLEVEL;
1776 end.player_num = player_num;
1777 end.connected = Players[player_num].connected;
1778 end.kills = INTEL_SHORT(Players[player_num].net_kills_total);
1779 end.killed = INTEL_SHORT(Players[player_num].net_killed_total);
1780 memcpy(end.kill_matrix, kill_matrix[player_num], MAX_PLAYERS*sizeof(short));
1781 #ifdef WORDS_BIGENDIAN
1782 for (i = 0; i < MAX_PLAYERS; i++)
1783 for (j = 0; j < MAX_PLAYERS; j++)
1784 end.kill_matrix[i][j] = INTEL_SHORT(end.kill_matrix[i][j]);
1786 j = j; // to satisfy compiler
1789 if (Players[player_num].connected == 1) // Still playing
1791 Assert(Control_center_destroyed);
1792 end.seconds_left = Countdown_seconds_left;
1795 // mprintf((0, "Sending endlevel packet.\n"));
1797 for (i = 0; i < N_players; i++)
1799 if ((i != Player_num) && (i!=player_num) && (Players[i].connected)) {
1800 if (Players[i].connected==1)
1801 network_send_endlevel_short_sub(player_num,i);
1803 if (Network_game_type == IPX_GAME)
1804 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);
1807 appletalk_send_packet_data( (ubyte *)&end, sizeof(endlevel_info), NetPlayers.players[i].network.appletalk.node,
1808 NetPlayers.players[i].network.appletalk.net,
1809 NetPlayers.players[i].network.appletalk.socket);
1816 /* Send an updated endlevel status to other hosts */
1818 network_send_endlevel_packet(void)
1820 network_send_endlevel_sub(Player_num);
1824 /* Send an endlevel packet for a player */
1826 network_send_endlevel_short_sub(int from_player_num,int to_player)
1828 endlevel_info_short end;
1830 end.type = PID_ENDLEVEL_SHORT;
1831 end.player_num = from_player_num;
1832 end.connected = Players[from_player_num].connected;
1833 end.seconds_left = Countdown_seconds_left;
1836 if (Players[from_player_num].connected == 1) // Still playing
1838 Assert(Control_center_destroyed);
1841 if ((to_player != Player_num) && (to_player!=from_player_num) && (Players[to_player].connected))
1843 mprintf((0, "Sending short endlevel packet to %s.\n",Players[to_player].callsign));
1844 if (Network_game_type == IPX_GAME)
1845 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);
1848 appletalk_send_packet_data( (ubyte *)&end, sizeof(endlevel_info_short), NetPlayers.players[to_player].network.appletalk.node,
1849 NetPlayers.players[to_player].network.appletalk.net,
1850 NetPlayers.players[to_player].network.appletalk.socket);
1855 extern fix ThisLevelTime;
1858 network_send_game_info(sequence_packet *their)
1860 // Send game info to someone who requested it
1862 char old_type, old_status;
1866 mprintf((0, "Sending game info.\n"));
1868 network_update_netgame(); // Update the values in the netgame struct
1870 old_type = Netgame.type;
1871 old_status = Netgame.game_status;
1873 Netgame.type = PID_GAME_INFO;
1874 NetPlayers.type = PID_PLAYERSINFO;
1876 NetPlayers.Security=Netgame.Security;
1877 Netgame.version_major=Version_major;
1878 Netgame.version_minor=Version_minor;
1880 if (Endlevel_sequence || Control_center_destroyed)
1881 Netgame.game_status = NETSTAT_ENDLEVEL;
1883 if (Netgame.PlayTimeAllowed)
1885 timevar=i2f (Netgame.PlayTimeAllowed*5*60);
1886 i=f2i(timevar-ThisLevelTime);
1888 Netgame.game_status=NETSTAT_ENDLEVEL;
1892 if (Network_game_type == IPX_GAME) {
1893 send_broadcast_full_netgame_packet();
1894 send_broadcast_netplayers_packet();
1895 } // nothing to do for appletalk games I think....
1897 if (Network_game_type == IPX_GAME) {
1898 send_internetwork_full_netgame_packet(their->player.network.ipx.server, their->player.network.ipx.node);
1899 send_netplayers_packet(their->player.network.ipx.server, their->player.network.ipx.node);
1902 appletalk_send_packet_data( (ubyte *)&Netgame, sizeof(netgame_info), their->player.network.appletalk.node,
1903 their->player.network.appletalk.net, their->player.network.appletalk.socket );
1904 appletalk_send_packet_data( (ubyte *)&NetPlayers, sizeof(AllNetPlayers_info), their->player.network.appletalk.node,
1905 their->player.network.appletalk.net, their->player.network.appletalk.socket );
1910 Netgame.type = old_type;
1911 Netgame.game_status = old_status;
1914 void network_send_lite_info(sequence_packet *their)
1916 // Send game info to someone who requested it
1918 char old_type, old_status,oldstatus;
1920 mprintf((0, "Sending lite game info.\n"));
1922 network_update_netgame(); // Update the values in the netgame struct
1924 old_type = Netgame.type;
1925 old_status = Netgame.game_status;
1927 Netgame.type = PID_LITE_INFO;
1929 if (Endlevel_sequence || Control_center_destroyed)
1930 Netgame.game_status = NETSTAT_ENDLEVEL;
1932 // If hoard mode, make this game look closed even if it isn't
1933 if (HoardEquipped())
1935 if (Game_mode & GM_HOARD)
1937 oldstatus=Netgame.game_status;
1938 Netgame.game_status=NETSTAT_ENDLEVEL;
1939 Netgame.gamemode=NETGAME_CAPTURE_FLAG;
1940 if (oldstatus==NETSTAT_ENDLEVEL)
1941 Netgame.game_flags|=NETGAME_FLAG_REALLY_ENDLEVEL;
1942 if (oldstatus==NETSTAT_STARTING)
1943 Netgame.game_flags|=NETGAME_FLAG_REALLY_FORMING;
1948 if (Network_game_type == IPX_GAME) {
1949 send_broadcast_lite_netgame_packet();
1950 } // nothing to do for appletalk I think....
1952 if (Network_game_type == IPX_GAME) {
1953 send_internetwork_lite_netgame_packet(their->player.network.ipx.server, their->player.network.ipx.node);
1956 appletalk_send_packet_data( (ubyte *)&Netgame, sizeof(lite_info), their->player.network.appletalk.node,
1957 their->player.network.appletalk.net, their->player.network.appletalk.socket );
1962 // Restore the pre-hoard mode
1963 if (HoardEquipped())
1965 if (Game_mode & GM_HOARD)
1967 if (!(Game_mode & GM_TEAM))
1968 Netgame.gamemode=NETGAME_HOARD;
1970 Netgame.gamemode=NETGAME_TEAM_HOARD;
1971 Netgame.game_flags&=~NETGAME_FLAG_REALLY_ENDLEVEL;
1972 Netgame.game_flags&=~NETGAME_FLAG_REALLY_FORMING;
1973 Netgame.game_flags&=~NETGAME_FLAG_TEAM_HOARD;
1977 Netgame.type = old_type;
1978 Netgame.game_status = old_status;
1982 /* Send game info to all players in this game */
1983 void network_send_netgame_update()
1985 char old_type, old_status;
1988 mprintf((0, "Sending updated game info.\n"));
1990 network_update_netgame(); // Update the values in the netgame struct
1992 old_type = Netgame.type;
1993 old_status = Netgame.game_status;
1995 Netgame.type = PID_GAME_UPDATE;
1997 if (Endlevel_sequence || Control_center_destroyed)
1998 Netgame.game_status = NETSTAT_ENDLEVEL;
2000 for (i=0; i<N_players; i++ ) {
2001 if ( (Players[i].connected) && (i!=Player_num ) ) {
2002 if (Network_game_type == IPX_GAME) {
2003 send_lite_netgame_packet(NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node, Players[i].net_address);
2006 appletalk_send_packet_data( (ubyte *)&Netgame, sizeof(lite_info), NetPlayers.players[i].network.appletalk.node,
2007 NetPlayers.players[i].network.appletalk.net, NetPlayers.players[i].network.appletalk.socket );
2013 Netgame.type = old_type;
2014 Netgame.game_status = old_status;
2017 int network_send_request(void)
2019 // Send a request to join a game 'Netgame'. Returns 0 if we can join this
2020 // game, non-zero if there is some problem.
2023 if (Netgame.numplayers < 1)
2026 for (i = 0; i < MAX_NUM_NET_PLAYERS; i++)
2027 if (NetPlayers.players[i].connected)
2030 Assert(i < MAX_NUM_NET_PLAYERS);
2032 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));
2034 // segments_checksum = netmisc_calc_checksum( Segments, sizeof(segment)*(Highest_segment_index+1) );
2036 My_Seq.type = PID_REQUEST;
2037 My_Seq.player.connected = Current_level_num;
2039 if (Network_game_type == IPX_GAME) {
2040 send_internetwork_sequence_packet(My_Seq, NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node);
2043 appletalk_send_packet_data( (ubyte *)&My_Seq, sizeof(sequence_packet), NetPlayers.players[i].network.appletalk.node,
2044 NetPlayers.players[i].network.appletalk.net,
2045 NetPlayers.players[i].network.appletalk.socket);
2052 int SecurityCheck=0;
2054 void network_process_gameinfo(ubyte *data)
2057 netgame_info *new = (netgame_info *)data;
2058 #ifdef WORDS_BIGENDIAN
2059 netgame_info tmp_info;
2061 if (Network_game_type == IPX_GAME) {
2062 receive_netgame_packet(data, &tmp_info, 0); // get correctly aligned structure
2068 WaitingForPlayerInfo=0;
2070 if (new->Security !=TempPlayersInfo->Security)
2072 Int3(); // Get Jason
2073 return; // If this first half doesn't go with the second half
2076 Network_games_changed = 1;
2078 //mprintf((0, "Got game data for game %s.\n", new->game_name));
2080 Assert (TempPlayersInfo!=NULL);
2082 for (i = 0; i < num_active_games; i++)
2084 //mprintf ((0,"GAMEINFO: Game %d is %s!\n",i,Active_games[i].game_name));
2086 if (!stricmp(Active_games[i].game_name, new->game_name) &&
2087 Active_games[i].Security==new->Security)
2091 if (i == MAX_ACTIVE_NETGAMES)
2093 mprintf((0, "Too many netgames.\n"));
2097 // MWA memcpy(&Active_games[i], data, sizeof(netgame_info));
2098 memcpy(&Active_games[i], (ubyte *)new, sizeof(netgame_info));
2099 memcpy (&ActiveNetPlayers[i],TempPlayersInfo,sizeof(AllNetPlayers_info));
2102 if (Active_games[i].Security==SecurityCheck)
2105 //mprintf ((0,"Recieved %d unique games...\n",i));
2107 if (i == num_active_games)
2110 if (Active_games[i].numplayers == 0)
2112 mprintf ((0,"DELETING THIS GAME!!!\n"));
2114 for (j = i; j < num_active_games-1; j++)
2116 memcpy(&Active_games[j], &Active_games[j+1], sizeof(netgame_info));
2117 memcpy (&ActiveNetPlayers[j],&ActiveNetPlayers[j+1],sizeof(AllNetPlayers_info));
2124 void network_process_lite_info(ubyte *data)
2127 lite_info *new = (lite_info *)data;
2128 #ifdef WORDS_BIGENDIAN
2131 if (Network_game_type == IPX_GAME) {
2132 receive_netgame_packet(data, (netgame_info *)&tmp_info, 1);
2137 Network_games_changed = 1;
2139 //mprintf((0, "Got game data for game %s.\n", new->game_name));
2141 for (i = 0; i < num_active_games; i++)
2143 //mprintf ((0,"GAMEINFO: Game %d is %s!\n",i,Active_games[i].game_name));
2145 if ((!stricmp(Active_games[i].game_name, new->game_name)) &&
2146 Active_games[i].Security==new->Security)
2150 if (i == MAX_ACTIVE_NETGAMES)
2152 mprintf((0, "Too many netgames.\n"));
2156 memcpy(&Active_games[i], (ubyte *)new, sizeof(lite_info));
2158 // See if this is really a Hoard game
2159 // If so, adjust all the data accordingly
2161 if (HoardEquipped())
2163 if (Active_games[i].game_flags & NETGAME_FLAG_HOARD)
2165 Active_games[i].gamemode=NETGAME_HOARD;
2166 Active_games[i].game_status=NETSTAT_PLAYING;
2168 if (Active_games[i].game_flags & NETGAME_FLAG_TEAM_HOARD)
2169 Active_games[i].gamemode=NETGAME_TEAM_HOARD;
2170 if (Active_games[i].game_flags & NETGAME_FLAG_REALLY_ENDLEVEL)
2171 Active_games[i].game_status=NETSTAT_ENDLEVEL;
2172 if (Active_games[i].game_flags & NETGAME_FLAG_REALLY_FORMING)
2173 Active_games[i].game_status=NETSTAT_STARTING;
2177 //mprintf ((0,"Recieved %d unique games...\n",i));
2179 if (i == num_active_games)
2182 if (Active_games[i].numplayers == 0)
2184 mprintf ((0,"DELETING THIS GAME!!!\n"));
2186 for (j = i; j < num_active_games-1; j++)
2188 memcpy(&Active_games[j], &Active_games[j+1], sizeof(netgame_info));
2194 void network_process_dump(sequence_packet *their)
2196 // Our request for join was denied. Tell the user why.
2201 mprintf((0, "Dumped by player %s, type %d.\n", their->player.callsign, their->player.connected));
2203 if (their->player.connected!=7)
2204 nm_messagebox(NULL, 1, TXT_OK, NET_DUMP_STRINGS(their->player.connected));
2207 for (i=0;i<N_players;i++)
2208 if (!stricmp (their->player.callsign,Players[i].callsign))
2210 if (i!=network_who_is_master())
2212 HUD_init_message ("%s attempted to kick you out.",their->player.callsign);
2216 sprintf (temp,"%s has kicked you out!",their->player.callsign);
2217 nm_messagebox(NULL, 1, TXT_OK, &temp);
2218 if (Network_status==NETSTAT_PLAYING)
2224 Network_status = NETSTAT_MENU;
2229 void network_process_request(sequence_packet *their)
2231 // Player is ready to receieve a sync packet
2234 mprintf((0, "Player %s ready for sync.\n", their->player.callsign));
2236 for (i = 0; i < N_players; i++) {
2237 if (Network_game_type == IPX_GAME) {
2238 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))) {
2239 Players[i].connected = 1;
2243 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)) ) {
2244 Players[i].connected = 1;
2251 #define REFUSE_INTERVAL F1_0 * 8
2252 extern void multi_reset_object_texture (object *);
2254 void network_process_packet(ubyte *data, int length )
2256 sequence_packet *their = (sequence_packet *)data;
2257 #ifdef WORDS_BIGENDIAN
2258 sequence_packet tmp_packet;
2260 if (Network_game_type == IPX_GAME) {
2261 receive_sequence_packet(data, &tmp_packet);
2262 their = &tmp_packet; // reassign their to point to correctly alinged structure
2266 //mprintf( (0, "Got packet of length %d, type %d\n", length, their->type ));
2268 // if ( length < sizeof(sequence_packet) ) return;
2274 case PID_GAME_INFO: // Jason L. says we can safely ignore this type.
2277 case PID_PLAYERSINFO:
2279 mprintf ((0,"Got a PID_PLAYERSINFO!\n"));
2281 if (Network_status==NETSTAT_WAITING)
2283 if (Network_game_type == IPX_GAME)
2284 receive_netplayers_packet(data, &TempPlayersBase);
2286 memcpy (&TempPlayersBase,data,sizeof(AllNetPlayers_info));
2288 if (TempPlayersBase.Security!=Netgame.Security)
2290 mprintf ((0,"Bad security for PLAYERSINFO\n"));
2294 mprintf ((0,"Got a waiting PID_PLAYERSINFO!\n"));
2295 if (length!=ALLNETPLAYERSINFO_SIZE)
2297 mprintf ((0,"Invalid size for netplayers packet!\n"));
2301 TempPlayersInfo=&TempPlayersBase;
2302 WaitingForPlayerInfo=0;
2303 NetSecurityNum=TempPlayersInfo->Security;
2304 NetSecurityFlag=NETSECURITY_WAIT_FOR_SYNC;
2311 if (length != LITE_INFO_SIZE)
2313 mprintf ((0,"WARNING! Recieved invalid size for PID_LITE_INFO\n"));
2317 if (Network_status == NETSTAT_BROWSING)
2318 network_process_lite_info (data);
2322 // Someone wants a list of games
2324 if (length != SEQUENCE_PACKET_SIZE)
2326 mprintf ((0,"WARNING! Recieved invalid size for PID_GAME_LIST\n"));
2330 mprintf((0, "Got a PID_GAME_LIST!\n"));
2331 if ((Network_status == NETSTAT_PLAYING) || (Network_status == NETSTAT_STARTING) || (Network_status == NETSTAT_ENDLEVEL))
2332 if (network_i_am_master())
2333 network_send_lite_info(their);
2337 case PID_SEND_ALL_GAMEINFO:
2339 if (length != SEQUENCE_PACKET_SIZE)
2341 mprintf ((0,"WARNING! Recieved invalid size for PID_SEND_ALL_GAMEINFO\n"));
2345 if ((Network_status == NETSTAT_PLAYING) || (Network_status == NETSTAT_STARTING) || (Network_status == NETSTAT_ENDLEVEL))
2346 if (network_i_am_master() && their->Security==Netgame.Security)
2347 network_send_game_info(their);
2352 mprintf( (0, "Got NEWPLAYER message from %s.\n", their->player.callsign));
2354 if (length != SEQUENCE_PACKET_SIZE)
2356 mprintf ((0,"WARNING! Recieved invalid size for PID_ADDPLAYER\n"));
2359 mprintf( (0, "Got NEWPLAYER message from %s.\n", their->player.callsign));
2360 network_new_player(their);
2363 if (length != SEQUENCE_PACKET_SIZE)
2365 mprintf ((0,"WARNING! Recieved invalid size for PID_REQUEST\n"));
2369 mprintf( (0, "Got REQUEST from '%s'\n", their->player.callsign ));
2370 if (Network_status == NETSTAT_STARTING)
2372 // Someone wants to join our game!
2373 network_add_player(their);
2375 else if (Network_status == NETSTAT_WAITING)
2377 // Someone is ready to recieve a sync packet
2378 network_process_request(their);
2380 else if (Network_status == NETSTAT_PLAYING)
2382 // Someone wants to join a game in progress!
2383 if (Netgame.RefusePlayers)
2384 DoRefuseStuff (their);
2386 network_welcome_player(their);
2391 if (length != SEQUENCE_PACKET_SIZE)
2393 mprintf ((0,"WARNING! Recieved invalid size for PID_DUMP\n"));
2397 if (Network_status == NETSTAT_WAITING || Network_status==NETSTAT_PLAYING )
2398 network_process_dump(their);
2400 case PID_QUIT_JOINING:
2402 if (length != SEQUENCE_PACKET_SIZE)
2404 mprintf ((0,"WARNING! Recieved invalid size for PID_QUIT_JOINING\n"));
2407 if (Network_status == NETSTAT_STARTING)
2408 network_remove_player( their );
2409 else if ((Network_status == NETSTAT_PLAYING) && (Network_send_objects))
2410 network_stop_resync( their );
2414 mprintf ((0,"Got a sync packet! Network_status=%d\n",NETSTAT_WAITING));
2416 if (Network_status == NETSTAT_WAITING) {
2418 if (Network_game_type == IPX_GAME)
2419 receive_full_netgame_packet(data, &TempNetInfo);
2421 memcpy((ubyte *)&(TempNetInfo), data, sizeof(netgame_info));
2423 if (TempNetInfo.Security!=Netgame.Security)
2425 mprintf ((0,"Bad security on sync packet.\n"));
2429 if (NetSecurityFlag==NETSECURITY_WAIT_FOR_SYNC)
2431 if (TempNetInfo.Security==TempPlayersInfo->Security)
2433 network_read_sync_packet (&TempNetInfo,0);
2440 NetSecurityFlag=NETSECURITY_WAIT_FOR_PLAYERS;
2441 NetSecurityNum=TempNetInfo.Security;
2443 if ( network_wait_for_playerinfo())
2444 network_read_sync_packet((netgame_info *)data,0);
2453 if ((Game_mode&GM_NETWORK) && ((Network_status == NETSTAT_PLAYING)||(Network_status == NETSTAT_ENDLEVEL) || Network_status==NETSTAT_WAITING)) {
2454 network_process_pdata((char *)data);
2457 case PID_NAKED_PDATA:
2458 if ((Game_mode&GM_NETWORK) && ((Network_status == NETSTAT_PLAYING)||(Network_status == NETSTAT_ENDLEVEL) || Network_status==NETSTAT_WAITING))
2459 network_process_naked_pdata((char *)data,length);
2462 case PID_OBJECT_DATA:
2463 if (Network_status == NETSTAT_WAITING)
2464 network_read_object_packet(data);
2467 if ((Network_status == NETSTAT_ENDLEVEL) || (Network_status == NETSTAT_PLAYING))
2468 network_read_endlevel_packet(data);
2470 mprintf((0, "Junked endlevel packet.\n"));
2472 case PID_ENDLEVEL_SHORT:
2473 if ((Network_status == NETSTAT_ENDLEVEL) || (Network_status == NETSTAT_PLAYING))
2474 network_read_endlevel_short_packet(data);
2476 mprintf((0, "Junked short endlevel packet!\n"));
2479 case PID_GAME_UPDATE:
2480 mprintf ((0,"Got a GAME_UPDATE!\n"));
2482 if (Network_status==NETSTAT_PLAYING)
2484 if (Network_game_type == IPX_GAME)
2485 receive_lite_netgame_packet(data, &TempNetInfo);
2487 memcpy((ubyte *)&TempNetInfo, data, sizeof(lite_info) );
2488 if (TempNetInfo.Security==Netgame.Security)
2489 memcpy (&Netgame,(ubyte *)&TempNetInfo,sizeof(lite_info));
2491 if (Game_mode & GM_TEAM)
2495 for (i=0;i<N_players;i++)
2496 if (Players[i].connected)
2497 multi_reset_object_texture (&Objects[Players[i].objnum]);
2502 network_ping (PID_PING_RETURN,data[1]);
2504 case PID_PING_RETURN:
2505 network_handle_ping_return(data[1]); // data[1] is player who told us of their ping time
2507 case PID_NAMES_RETURN:
2508 if (Network_status==NETSTAT_BROWSING && NamesInfoSecurity!=-1)
2509 network_process_names_return (data);
2511 case PID_GAME_PLAYERS:
2512 // Someone wants a list of players in this game
2514 if (length != SEQUENCE_PACKET_SIZE)
2516 mprintf ((0,"WARNING! Recieved invalid size for PID_GAME_PLAYERS\n"));
2520 mprintf((0, "Got a PID_GAME_PLAYERS!\n"));
2521 if ((Network_status == NETSTAT_PLAYING) || (Network_status == NETSTAT_STARTING) || (Network_status == NETSTAT_ENDLEVEL))
2522 if (network_i_am_master() && their->Security==Netgame.Security)
2523 network_send_player_names(their);
2527 mprintf((0, "Ignoring invalid packet type.\n"));
2528 Int3(); // Invalid network packet type, see ROB
2534 void dump_segments()
2538 fp = fopen( "TEST.DMP", "wb" );
2539 fwrite( Segments, sizeof(segment)*(Highest_segment_index+1),1, fp );
2541 mprintf( (0, "SS=%d\n", sizeof(segment) ));
2547 network_read_endlevel_packet( ubyte *data )
2549 // Special packet for end of level syncing
2551 endlevel_info *end = (endlevel_info *)data;
2552 #ifdef WORDS_BIGENDIAN
2555 for (i = 0; i < MAX_PLAYERS; i++)
2556 for (j = 0; j < MAX_PLAYERS; j++)
2557 end->kill_matrix[i][j] = INTEL_SHORT(end->kill_matrix[i][j]);
2558 end->kills = INTEL_SHORT(end->kills);
2559 end->killed = INTEL_SHORT(end->killed);
2562 playernum = end->player_num;
2564 Assert(playernum != Player_num);
2566 if (playernum>=N_players)
2568 Int3(); // weird, but it an happen in a coop restore game
2569 return; // if it happens in a coop restore, don't worry about it
2572 if ((Network_status == NETSTAT_PLAYING) && (end->connected != 0))
2573 return; // Only accept disconnect packets if we're not out of the level yet
2575 Players[playernum].connected = end->connected;
2576 memcpy(&kill_matrix[playernum][0], end->kill_matrix, MAX_PLAYERS*sizeof(short));
2577 Players[playernum].net_kills_total = end->kills;
2578 Players[playernum].net_killed_total = end->killed;
2580 if ((Players[playernum].connected == 1) && (end->seconds_left < Countdown_seconds_left))
2581 Countdown_seconds_left = end->seconds_left;
2583 LastPacketTime[playernum] = timer_get_approx_seconds();
2585 // mprintf((0, "Got endlevel packet from player %d.\n", playernum));
2589 network_read_endlevel_short_packet( ubyte *data )
2591 // Special packet for end of level syncing
2594 endlevel_info_short *end;
2596 end = (endlevel_info_short *)data;
2598 playernum = end->player_num;
2600 Assert(playernum != Player_num);
2602 if (playernum>=N_players)
2604 Int3(); // weird, but it can happen in a coop restore game
2605 return; // if it happens in a coop restore, don't worry about it
2608 if ((Network_status == NETSTAT_PLAYING) && (end->connected != 0))
2610 //mprintf ((0,"Returning early for short_endlevel\n"));
2611 return; // Only accept disconnect packets if we're not out of the level yet
2614 Players[playernum].connected = end->connected;
2616 if ((Players[playernum].connected == 1) && (end->seconds_left < Countdown_seconds_left))
2617 Countdown_seconds_left = end->seconds_left;
2619 LastPacketTime[playernum] = timer_get_approx_seconds();
2624 network_pack_objects(void)
2626 // Switching modes, pack the object array
2628 special_reset_objects();
2632 network_verify_objects(int remote, int local)
2635 int nplayers, got_controlcen=0;
2637 mprintf ((0,"NETWORK:remote=%d local=%d\n",remote,local));
2639 if ((remote-local) > 10)
2642 if (Game_mode & GM_MULTI_ROBOTS)
2647 for (i = 0; i <= Highest_object_index; i++)
2649 if ((Objects[i].type == OBJ_PLAYER) || (Objects[i].type == OBJ_GHOST))
2651 if (Objects[i].type == OBJ_CNTRLCEN)
2655 if (got_controlcen && (MaxNumNetPlayers<=nplayers))
2662 network_read_object_packet( ubyte *data )
2664 // Object from another net player we need to sync with
2666 short objnum, remote_objnum;
2671 static int my_pnum = 0;
2672 static int mode = 0;
2673 static int object_count = 0;
2674 static int frame_num = 0;
2677 int remote_frame_num = data[2];
2681 // mprintf((0, "Object packet %d (remote #%d) contains %d objects.\n", frame_num, remote_frame_num, nobj));
2683 for (i = 0; i < nobj; i++)
2685 objnum = INTEL_SHORT( *(short *)(data+loc) ); loc += 2;
2686 obj_owner = data[loc]; loc += 1;
2687 remote_objnum = INTEL_SHORT( *(short *)(data+loc) ); loc += 2;
2691 // Clear object array
2692 mprintf((0, "Clearing object array.\n"));
2695 Network_rejoined = 1;
2696 my_pnum = obj_owner;
2697 change_playernum_to(my_pnum);
2702 else if (objnum == -2)
2704 // Special debug checksum marker for entire send
2707 network_pack_objects();
2710 mprintf((0, "Objnum -2 found in frame local %d remote %d.\n", frame_num, remote_frame_num));
2711 mprintf((0, "Got %d objects, expected %d.\n", object_count, remote_objnum));
2712 if (remote_objnum != object_count) {
2715 if (network_verify_objects(remote_objnum, object_count))
2717 // Failed to sync up
2718 nm_messagebox(NULL, 1, TXT_OK, TXT_NET_SYNC_FAILED);
2719 Network_status = NETSTAT_MENU;
2726 if (frame_num != remote_frame_num)
2728 mprintf ((0,"Got a type 3 object packet!\n"));
2730 if ((obj_owner == my_pnum) || (obj_owner == -1))
2734 objnum = remote_objnum;
2735 //if (objnum > Highest_object_index)
2737 // Highest_object_index = objnum;
2738 // num_objects = Highest_object_index+1;
2744 network_pack_objects();
2747 objnum = obj_allocate();
2750 obj = &Objects[objnum];
2751 if (obj->segnum != -1)
2753 Assert(obj->segnum == -1);
2754 Assert(objnum < MAX_OBJECTS);
2755 memcpy(obj, &data[loc], sizeof(object));
2756 if (Network_game_type == IPX_GAME)
2758 loc += sizeof(object);
2759 segnum = obj->segnum;
2760 obj->next = obj->prev = obj->segnum = -1;
2761 obj->attached_obj = -1;
2763 obj_link(obj-Objects,segnum);
2764 if (obj_owner == my_pnum)
2765 map_objnum_local_to_local(objnum);
2766 else if (obj_owner != -1)
2767 map_objnum_local_to_remote(objnum, remote_objnum, obj_owner);
2769 object_owner[objnum] = -1;
2771 } // For a standard onbject
2772 } // For each object in packet
2775 /* Polling loop waiting for sync packet to start game
2776 * after having sent request
2778 void network_sync_poll( int nitems, newmenu_item * menus, int * key, int citem )
2789 if (Network_status != NETSTAT_WAITING) // Status changed to playing, exit the menu
2792 if (!Network_rejoined && (timer_get_approx_seconds() > t1+F1_0*2))
2796 // Poll time expired, re-send request
2798 t1 = timer_get_approx_seconds();
2800 mprintf((0, "Re-sending join request.\n"));
2801 i = network_send_request();
2807 void network_start_poll( int nitems, newmenu_item * menus, int * key, int citem )
2814 Assert(Network_status == NETSTAT_STARTING);
2816 if (!menus[0].value) {
2818 menus[0].redraw = 1;
2821 for (i=1; i<nitems; i++ ) {
2822 if ( (i>= N_players) && (menus[i].value) ) {
2824 menus[i].redraw = 1;
2829 for (i=0; i<nitems; i++ ) {
2830 if ( menus[i].value ) {
2832 if ( nm > N_players ) {
2834 menus[i].redraw = 1;
2839 if ( nm > MaxNumNetPlayers ) {
2840 nm_messagebox( TXT_ERROR, 1, TXT_OK, "%s %d %s", TXT_SORRY_ONLY, MaxNumNetPlayers, TXT_NETPLAYERS_IN );
2841 // Turn off the last player highlighted
2842 for (i = N_players; i > 0; i--)
2843 if (menus[i].value == 1)
2846 menus[i].redraw = 1;
2851 // if (nitems > MAX_PLAYERS ) return;
2853 n = Netgame.numplayers;
2856 if (n < Netgame.numplayers )
2858 digi_play_sample (SOUND_HUD_MESSAGE,F1_0);
2860 mprintf ((0,"More players are printed!"));
2861 if (FindArg("-norankings"))
2862 sprintf( menus[N_players-1].text, "%d. %-20s", N_players,NetPlayers.players[N_players-1].callsign );
2864 sprintf( menus[N_players-1].text, "%d. %s%-20s", N_players, RankStrings[NetPlayers.players[N_players-1].rank],NetPlayers.players[N_players-1].callsign );
2866 menus[N_players-1].redraw = 1;
2867 if (N_players <= MaxNumNetPlayers)
2869 menus[N_players-1].value = 1;
2872 else if ( n > Netgame.numplayers )
2874 // One got removed...
2876 digi_play_sample (SOUND_HUD_KILL,F1_0);
2878 for (i=0; i<N_players; i++ )
2881 if (FindArg("-norankings"))
2882 sprintf( menus[i].text, "%d. %-20s", i+1, NetPlayers.players[i].callsign );
2884 sprintf( menus[i].text, "%d. %s%-20s", i+1, RankStrings[NetPlayers.players[i].rank],NetPlayers.players[i].callsign );
2885 if (i < MaxNumNetPlayers)
2889 menus[i].redraw = 1;
2891 for (i=N_players; i<n; i++ )
2893 sprintf( menus[i].text, "%d. ", i+1 ); // Clear out the deleted entries...
2895 menus[i].redraw = 1;
2900 int opt_cinvul, opt_team_anarchy, opt_coop, opt_show_on_map, opt_closed,opt_maxnet;
2901 int last_cinvul=0,last_maxnet,opt_team_hoard;
2902 int opt_refuse,opt_capture;
2904 void network_game_param_poll( int nitems, newmenu_item * menus, int * key, int citem )
2906 static int oldmaxnet=0;
2908 if (((HoardEquipped() && menus[opt_team_hoard].value) || (menus[opt_team_anarchy].value || menus[opt_capture].value)) && !menus[opt_closed].value && !menus[opt_refuse].value) {
2909 menus[opt_refuse].value = 1;
2910 menus[opt_refuse].redraw = 1;
2911 menus[opt_refuse-1].value = 0;
2912 menus[opt_refuse-1].redraw = 1;
2913 menus[opt_refuse-2].value = 0;
2914 menus[opt_refuse-2].redraw = 1;
2918 if (menus[opt_coop].value)
2920 if ( (menus[opt_coop].value) || ((Network_game_type == APPLETALK_GAME) && (Network_appletalk_type == LOCALTALK_TYPE) && (menus[opt_coop-1].value)) )
2925 if (menus[opt_maxnet].value>2)
2927 menus[opt_maxnet].value=2;
2928 menus[opt_maxnet].redraw=1;
2931 if (menus[opt_maxnet].max_value>2)
2933 menus[opt_maxnet].max_value=2;
2934 menus[opt_maxnet].redraw=1;
2938 if ( (Network_game_type == APPLETALK_GAME) && (Network_appletalk_type == LOCALTALK_TYPE) ) {
2939 if (menus[opt_maxnet].value > 0) {
2940 menus[opt_maxnet].value=0;
2941 menus[opt_maxnet].redraw=1;
2943 if (menus[opt_maxnet].max_value > 0) {
2944 menus[opt_maxnet].max_value=0;
2945 menus[opt_maxnet].redraw=1;
2950 if (!Netgame.game_flags & NETGAME_FLAG_SHOW_MAP)
2951 Netgame.game_flags |= NETGAME_FLAG_SHOW_MAP;
2953 if (Netgame.PlayTimeAllowed || Netgame.KillGoal)
2955 Netgame.PlayTimeAllowed=0;
2960 else // if !Coop game
2965 menus[opt_maxnet].value=6;
2966 menus[opt_maxnet].max_value=6;
2969 if ( (Network_game_type == APPLETALK_GAME) && (Network_appletalk_type == LOCALTALK_TYPE) ) {
2970 menus[opt_maxnet].value=1;
2971 menus[opt_maxnet].max_value=1;
2978 if ( last_maxnet != menus[opt_maxnet].value )
2980 sprintf( menus[opt_maxnet].text, "Maximum players: %d", menus[opt_maxnet].value+2 );
2981 last_maxnet = menus[opt_maxnet].value;
2982 menus[opt_maxnet].redraw = 1;
2986 int netgame_difficulty;
2988 int network_get_game_params( char * game_name, int *mode, int *game_flags, int *level )
2991 int opt, opt_name, opt_level, opt_mode,opt_moreopts;
2993 char name[NETGAME_NAME_LEN+1];
2995 char level_text[32];
2998 int new_mission_num;
3001 *game_flags=*game_flags;
3003 SetAllAllowablesTo (1);
3004 NamesInfoSecurity=-1;
3006 for (i=0;i<MAX_PLAYERS;i++)
3008 Players[i].callsign[0]=0;
3010 MaxNumNetPlayers = MAX_NUM_NET_PLAYERS;
3012 Netgame.PlayTimeAllowed=0;
3013 Netgame.Allow_marker_view=1;
3014 netgame_difficulty=Player_default_difficulty;
3016 new_mission_num = multi_choose_mission(&anarchy_only);
3018 if (new_mission_num < 0)
3021 if (!(FindArg ("-packets") && FindArg ("-shortpackets")))
3022 if (!network_choose_connect ())
3026 if ( (Network_game_type == APPLETALK_GAME) && (Network_appletalk_type == LOCALTALK_TYPE) )
3027 MaxNumNetPlayers = 3;
3030 strcpy(Netgame.mission_name, Mission_list[new_mission_num].filename);
3031 strcpy(Netgame.mission_title, Mission_list[new_mission_num].mission_name);
3032 Netgame.control_invul_time = control_invul_time;
3034 sprintf( name, "%s%s", Players[Player_num].callsign, TXT_S_GAME );
3035 sprintf( slevel, "1" );
3038 m[opt].type = NM_TYPE_TEXT; m[opt].text = TXT_DESCRIPTION; opt++;
3041 m[opt].type = NM_TYPE_INPUT; m[opt].text = name; m[opt].text_len = NETGAME_NAME_LEN; opt++;
3043 sprintf(level_text, "%s (1-%d)", TXT_LEVEL_, Last_level);
3045 // if (Last_secret_level < -1)
3046 // sprintf(level_text+strlen(level_text)-1, ", S1-S%d)", -Last_secret_level);
3047 // else if (Last_secret_level == -1)
3048 // sprintf(level_text+strlen(level_text)-1, ", S1)");
3050 Assert(strlen(level_text) < 32);
3052 m[opt].type = NM_TYPE_TEXT; m[opt].text = level_text; opt++;
3055 m[opt].type = NM_TYPE_INPUT; m[opt].text = slevel; m[opt].text_len=4; opt++;
3056 // m[opt].type = NM_TYPE_TEXT; m[opt].text = TXT_OPTIONS; opt++;
3059 m[opt].type = NM_TYPE_RADIO; m[opt].text = TXT_ANARCHY; m[opt].value=1; m[opt].group=0; opt++;
3060 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++;
3061 m[opt].type = NM_TYPE_RADIO; m[opt].text = TXT_ANARCHY_W_ROBOTS; m[opt].value=0; m[opt].group=0; opt++;
3062 m[opt].type = NM_TYPE_RADIO; m[opt].text = TXT_COOPERATIVE; m[opt].value=0; m[opt].group=0; opt_coop=opt; opt++;
3063 m[opt].type = NM_TYPE_RADIO; m[opt].text = "Capture the flag"; m[opt].value=0; m[opt].group=0; opt_capture=opt; opt++;
3065 if (HoardEquipped())
3067 m[opt].type = NM_TYPE_RADIO; m[opt].text = "Hoard"; m[opt].value=0; m[opt].group=0; opt++;
3068 m[opt].type = NM_TYPE_RADIO; m[opt].text = "Team Hoard"; m[opt].value=0; m[opt].group=0; opt_team_hoard=opt; opt++;
3069 m[opt].type = NM_TYPE_TEXT; m[opt].text = ""; opt++;
3072 { m[opt].type = NM_TYPE_TEXT; m[opt].text = ""; opt++; }
3074 m[opt].type = NM_TYPE_RADIO; m[opt].text = "Open game"; m[opt].group=1; m[opt].value=0; opt++;
3076 m[opt].type = NM_TYPE_RADIO; m[opt].text = TXT_CLOSED_GAME; m[opt].group=1; m[opt].value=0; opt++;
3078 m[opt].type = NM_TYPE_RADIO; m[opt].text = "Restricted Game "; m[opt].group=1; m[opt].value=Netgame.RefusePlayers; opt++;
3080 // m[opt].type = NM_TYPE_CHECK; m[opt].text = TXT_SHOW_IDS; m[opt].value=0; opt++;
3083 sprintf( srmaxnet, "Maximum players: %d", MaxNumNetPlayers);
3084 m[opt].type = NM_TYPE_SLIDER; m[opt].value=MaxNumNetPlayers-2; m[opt].text= srmaxnet; m[opt].min_value=0;
3085 m[opt].max_value=MaxNumNetPlayers-2; opt++;
3086 last_maxnet=MaxNumNetPlayers-2;
3089 m[opt].type = NM_TYPE_MENU; m[opt].text = "More options..."; opt++;
3094 ExtGameStatus=GAMESTAT_NETGAME_OPTIONS;
3095 i = newmenu_do1( NULL, NULL, opt, m, network_game_param_poll, 1 );
3097 if (i==opt_moreopts)
3099 if ( m[opt_mode+3].value )
3100 Game_mode=GM_MULTI_COOP;
3101 network_more_game_options();
3105 Netgame.RefusePlayers=m[opt_refuse].value;
3111 MaxNumNetPlayers = m[opt_maxnet].value+2;
3112 Netgame.max_numplayers=MaxNumNetPlayers;
3114 for (j = 0; j < num_active_games; j++)
3115 if (!stricmp(Active_games[j].game_name, name))
3117 nm_messagebox(TXT_ERROR, 1, TXT_OK, TXT_DUPLICATE_NAME);
3121 strcpy( game_name, name );
3124 *level = atoi(slevel);
3126 if ((*level < 1) || (*level > Last_level))
3128 nm_messagebox(TXT_ERROR, 1, TXT_OK, TXT_LEVEL_OUT_RANGE );
3129 sprintf(slevel, "1");
3132 if ( m[opt_mode].value )
3133 *mode = NETGAME_ANARCHY;
3138 nm_messagebox(TXT_SORRY, 1, TXT_OK, TXT_REGISTERED_ONLY );
3139 m[opt_mode+1].value = 0;
3140 m[opt_mode+2].value = 0;
3141 m[opt_mode+3].value = 0;
3142 if (HoardEquipped())
3143 m[opt_mode+4].value = 0;
3145 m[opt_mode].value = 1;
3149 else if (m[opt_mode+1].value) {
3150 *mode = NETGAME_TEAM_ANARCHY;
3152 else if (m[opt_capture].value)
3153 *mode = NETGAME_CAPTURE_FLAG;
3154 else if (HoardEquipped() && m[opt_capture+1].value)
3155 *mode = NETGAME_HOARD;
3156 else if (HoardEquipped() && m[opt_capture+2].value)
3157 *mode = NETGAME_TEAM_HOARD;
3158 else if (anarchy_only) {
3159 nm_messagebox(NULL, 1, TXT_OK, TXT_ANARCHY_ONLY_MISSION);
3160 m[opt_mode+2].value = 0;
3161 m[opt_mode+3].value = 0;
3162 m[opt_mode].value = 1;
3165 else if ( m[opt_mode+2].value )
3166 *mode = NETGAME_ROBOT_ANARCHY;
3167 else if ( m[opt_mode+3].value )
3168 *mode = NETGAME_COOPERATIVE;
3169 else Int3(); // Invalid mode -- see Rob
3171 if (m[opt_closed].value)
3172 Netgame.game_flags |= NETGAME_FLAG_CLOSED;
3180 network_set_game_mode(int gamemode)
3184 if ( gamemode == NETGAME_ANARCHY )
3185 Game_mode = GM_NETWORK;
3186 else if ( gamemode == NETGAME_ROBOT_ANARCHY )
3187 Game_mode = GM_NETWORK | GM_MULTI_ROBOTS;
3188 else if ( gamemode == NETGAME_COOPERATIVE )
3189 Game_mode = GM_NETWORK | GM_MULTI_COOP | GM_MULTI_ROBOTS;
3190 else if (gamemode == NETGAME_CAPTURE_FLAG)
3192 Game_mode = GM_NETWORK | GM_TEAM | GM_CAPTURE;
3196 else if (HoardEquipped() && gamemode == NETGAME_HOARD)
3197 Game_mode = GM_NETWORK | GM_HOARD;
3198 else if (HoardEquipped() && gamemode == NETGAME_TEAM_HOARD)
3200 Game_mode = GM_NETWORK | GM_HOARD | GM_TEAM;
3203 else if ( gamemode == NETGAME_TEAM_ANARCHY )
3205 Game_mode = GM_NETWORK | GM_TEAM;
3212 #ifdef MACINTOSH // minimize players on localtalk games
3213 if ( (Network_game_type == APPLETALK_GAME) && (Network_appletalk_type == LOCALTALK_TYPE) ) {
3214 if (Game_mode & GM_MULTI_ROBOTS)
3215 MaxNumNetPlayers = 2;
3217 MaxNumNetPlayers = 3;
3219 if (Game_mode & GM_MULTI_COOP)
3220 MaxNumNetPlayers = 4;
3222 MaxNumNetPlayers = 8;
3230 network_find_game(void)
3232 // Find out whether or not there is space left on this socket
3236 Network_status = NETSTAT_BROWSING;
3238 num_active_games = 0;
3240 show_boxed_message(TXT_WAIT);
3242 network_send_game_list_request();
3243 t1 = timer_get_approx_seconds() + F1_0*3;
3245 while (timer_get_approx_seconds() < t1) // Wait 3 seconds for replies
3248 clear_boxed_message();
3250 // mprintf((0, "%s %d %s\n", TXT_FOUND, num_active_games, TXT_ACTIVE_GAMES));
3252 if (num_active_games < MAX_ACTIVE_NETGAMES)
3257 void network_read_sync_packet( netgame_info * sp, int rsinit)
3260 char temp_callsign[CALLSIGN_LEN+1];
3261 #ifdef WORDS_BIGENDIAN
3262 netgame_info tmp_info;
3264 if ( (Network_game_type == IPX_GAME) && (sp != &Netgame) ) { // for macintosh -- get the values unpacked to our structure format
3265 receive_full_netgame_packet((ubyte *)sp, &tmp_info);
3271 TempPlayersInfo=&NetPlayers;
3273 // This function is now called by all people entering the netgame.
3275 // mprintf( (0, "%s %d\n", TXT_STARTING_NETGAME, sp->levelnum ));
3279 memcpy( &Netgame, sp, sizeof(netgame_info) );
3280 memcpy (&NetPlayers,TempPlayersInfo,sizeof (AllNetPlayers_info));
3283 N_players = sp->numplayers;
3284 Difficulty_level = sp->difficulty;
3285 Network_status = sp->game_status;
3287 //Assert(Function_mode != FMODE_GAME);
3291 mprintf((1, "Netgame.checksum = %d, calculated checksum = %d.\n", Netgame.segments_checksum, my_segments_checksum));
3293 if (Netgame.segments_checksum != my_segments_checksum)
3295 Network_status = NETSTAT_MENU;
3296 nm_messagebox(TXT_ERROR, 1, TXT_OK, TXT_NETLEVEL_NMATCH);
3302 // Discover my player number
3304 memcpy(temp_callsign, Players[Player_num].callsign, CALLSIGN_LEN+1);
3308 for (i=0; i<MAX_NUM_NET_PLAYERS; i++ ) {
3309 Players[i].net_kills_total = 0;
3310 // Players[i].net_killed_total = 0;
3313 for (i=0; i<N_players; i++ ) {
3314 if (Network_game_type == IPX_GAME) {
3315 if ( (!memcmp( TempPlayersInfo->players[i].network.ipx.node, My_Seq.player.network.ipx.node, 6 )) && (!stricmp( TempPlayersInfo->players[i].callsign, temp_callsign)) ) {
3316 if (Player_num!=-1) {
3317 Int3(); // Hey, we've found ourselves twice
3318 mprintf ((0,"Hey, we've found ourselves twice!\n"));
3319 Network_status = NETSTAT_MENU;
3322 change_playernum_to(i);
3325 if ( (TempPlayersInfo->players[i].network.appletalk.node == My_Seq.player.network.appletalk.node) && (!stricmp( TempPlayersInfo->players[i].callsign, temp_callsign)) ) {
3326 if (Player_num!=-1) {
3327 Int3(); // Hey, we've found ourselves twice
3328 Network_status = NETSTAT_MENU;
3331 change_playernum_to(i);
3334 memcpy( Players[i].callsign, TempPlayersInfo->players[i].callsign, CALLSIGN_LEN+1 );
3336 if (Network_game_type == IPX_GAME) {
3337 #ifdef WORDS_NEED_ALIGNMENT
3339 memcpy(&server, TempPlayersInfo->players[i].network.ipx.server, 4);
3341 ipx_get_local_target((ubyte *)&server, TempPlayersInfo->players[i].network.ipx.node, Players[i].net_address);
3342 #else // WORDS_NEED_ALIGNMENT
3343 if ((*(uint *)TempPlayersInfo->players[i].network.ipx.server) != 0)
3344 ipx_get_local_target(TempPlayersInfo->players[i].network.ipx.server, TempPlayersInfo->players[i].network.ipx.node, Players[i].net_address);
3345 #endif // WORDS_NEED_ALIGNMENT
3347 memcpy( Players[i].net_address, TempPlayersInfo->players[i].network.ipx.node, 6 );
3350 Players[i].n_packets_got=0; // How many packets we got from them
3351 Players[i].n_packets_sent=0; // How many packets we sent to them
3352 Players[i].connected = TempPlayersInfo->players[i].connected;
3353 Players[i].net_kills_total = sp->player_kills[i];
3354 Players[i].net_killed_total = sp->killed[i];
3355 if ((Network_rejoined) || (i != Player_num))
3356 Players[i].score = sp->player_score[i];
3357 for (j = 0; j < MAX_NUM_NET_PLAYERS; j++)
3359 kill_matrix[i][j] = sp->kills[i][j];
3363 if ( Player_num < 0 ) {
3364 mprintf ((0,"Bad Player_num, resetting to NETSTAT_MENU!\n"));
3365 Network_status = NETSTAT_MENU;
3369 if (Network_rejoined)
3370 for (i=0; i<N_players;i++)
3371 Players[i].net_killed_total = sp->killed[i];
3373 if (Network_rejoined) {
3374 network_process_monitor_vector(sp->monitor_vector);
3375 Players[Player_num].time_level = sp->level_time;
3378 team_kills[0] = sp->team_kills[0];
3379 team_kills[1] = sp->team_kills[1];
3381 Players[Player_num].connected = 1;
3382 NetPlayers.players[Player_num].connected = 1;
3383 NetPlayers.players[Player_num].rank=GetMyNetRanking();
3385 if (!Network_rejoined)
3386 for (i=0; i<NumNetPlayerPositions; i++) {
3387 Objects[Players[i].objnum].pos = Player_init[Netgame.locations[i]].pos;
3388 Objects[Players[i].objnum].orient = Player_init[Netgame.locations[i]].orient;
3389 obj_relink(Players[i].objnum,Player_init[Netgame.locations[i]].segnum);
3392 Objects[Players[Player_num].objnum].type = OBJ_PLAYER;
3394 mprintf ((0,"Changing to NETSTAT_PLAYING!\n"));
3395 Network_status = NETSTAT_PLAYING;
3396 Function_mode = FMODE_GAME;
3397 multi_sort_kill_list();
3402 network_send_sync(void)
3406 // Randomize their starting locations...
3408 d_srand( timer_get_fixed_seconds() );
3409 for (i=0; i<NumNetPlayerPositions; i++ )
3411 if (Players[i].connected)
3412 Players[i].connected = 1; // Get rid of endlevel connect statuses
3413 if (Game_mode & GM_MULTI_COOP)
3414 Netgame.locations[i] = i;
3418 np = d_rand() % NumNetPlayerPositions;
3419 for (j=0; j<i; j++ )
3421 if (Netgame.locations[j]==np)
3428 // np is a location that is not used anywhere else..
3429 Netgame.locations[i]=np;
3430 // mprintf((0, "Player %d starting in location %d\n" ,i ,np ));
3434 // Push current data into the sync packet
3436 network_update_netgame();
3437 Netgame.game_status = NETSTAT_PLAYING;
3438 Netgame.type = PID_SYNC;
3439 Netgame.segments_checksum = my_segments_checksum;
3441 for (i=0; i<N_players; i++ ) {
3442 if ((!Players[i].connected) || (i == Player_num))
3445 if (Network_game_type == IPX_GAME) {
3446 // Send several times, extras will be ignored
3447 send_internetwork_full_netgame_packet(NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node);
3448 send_netplayers_packet(NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node);
3451 appletalk_send_packet_data( (ubyte *)&Netgame, sizeof(netgame_info), NetPlayers.players[i].network.appletalk.node,
3452 NetPlayers.players[i].network.appletalk.net,
3453 NetPlayers.players[i].network.appletalk.socket);
3454 appletalk_send_packet_data( (ubyte *)&NetPlayers, sizeof(AllNetPlayers_info), NetPlayers.players[i].network.appletalk.node,
3455 NetPlayers.players[i].network.appletalk.net,
3456 NetPlayers.players[i].network.appletalk.socket);
3462 network_read_sync_packet(&Netgame,1); // Read it myself, as if I had sent it
3466 network_select_teams(void)
3469 newmenu_item m[MAX_PLAYERS+4];
3470 int choice, opt, opt_team_b;
3471 ubyte team_vector = 0;
3472 char team_names[2][CALLSIGN_LEN+1];
3474 int pnums[MAX_PLAYERS+2];
3476 // One-time initialization
3478 for (i = N_players/2; i < N_players; i++) // Put first half of players on team A
3480 team_vector |= (1 << i);
3483 sprintf(team_names[0], "%s", TXT_BLUE);
3484 sprintf(team_names[1], "%s", TXT_RED);
3486 // Here comes da menu
3488 m[0].type = NM_TYPE_INPUT; m[0].text = team_names[0]; m[0].text_len = CALLSIGN_LEN;
3491 for (i = 0; i < N_players; i++)
3493 if (!(team_vector & (1 << i)))
3495 m[opt].type = NM_TYPE_MENU; m[opt].text = NetPlayers.players[i].callsign; pnums[opt] = i; opt++;
3499 m[opt].type = NM_TYPE_INPUT; m[opt].text = team_names[1]; m[opt].text_len = CALLSIGN_LEN; opt++;
3500 for (i = 0; i < N_players; i++)
3502 if (team_vector & (1 << i))
3504 m[opt].type = NM_TYPE_MENU; m[opt].text = NetPlayers.players[i].callsign; pnums[opt] = i; opt++;
3507 m[opt].type = NM_TYPE_TEXT; m[opt].text = ""; opt++;
3508 m[opt].type = NM_TYPE_MENU; m[opt].text = TXT_ACCEPT; opt++;
3510 Assert(opt <= MAX_PLAYERS+4);
3512 choice = newmenu_do(NULL, TXT_TEAM_SELECTION, opt, m, NULL);
3514 if (choice == opt-1)
3516 if ((opt-2-opt_team_b < 2) || (opt_team_b == 1))
3518 nm_messagebox(NULL, 1, TXT_OK, TXT_TEAM_MUST_ONE);
3524 Netgame.team_vector = team_vector;
3525 strcpy(Netgame.team_name[0], team_names[0]);
3526 strcpy(Netgame.team_name[1], team_names[1]);
3530 else if ((choice > 0) && (choice < opt_team_b)) {
3531 team_vector |= (1 << pnums[choice]);
3533 else if ((choice > opt_team_b) && (choice < opt-2)) {
3534 team_vector &= ~(1 << pnums[choice]);
3536 else if (choice == -1)
3545 network_select_players(void)
3548 newmenu_item m[MAX_PLAYERS+4];
3549 char text[MAX_PLAYERS+4][45];
3551 int save_nplayers; //how may people would like to join
3553 network_add_player( &My_Seq );
3555 for (i=0; i< MAX_PLAYERS+4; i++ ) {
3556 sprintf( text[i], "%d. %-20s", i+1, "" );
3557 m[i].type = NM_TYPE_CHECK; m[i].text = text[i]; m[i].value = 0;
3560 m[0].value = 1; // Assume server will play...
3562 if (FindArg("-norankings"))
3563 sprintf( text[0], "%d. %-20s", 1, Players[Player_num].callsign );
3565 sprintf( text[0], "%d. %s%-20s", 1, RankStrings[NetPlayers.players[Player_num].rank],Players[Player_num].callsign );
3567 sprintf( title, "%s %d %s", TXT_TEAM_SELECT, MaxNumNetPlayers, TXT_TEAM_PRESS_ENTER );
3570 ExtGameStatus=GAMESTAT_NETGAME_PLAYER_SELECT;
3571 j=newmenu_do1( NULL, title, MAX_PLAYERS+4, m, network_start_poll, 1 );
3573 save_nplayers = N_players;
3578 // Dump all players and go back to menu mode
3581 for (i=1; i<save_nplayers; i++) {
3582 if (Network_game_type == IPX_GAME)
3583 network_dump_player(NetPlayers.players[i].network.ipx.server,NetPlayers.players[i].network.ipx.node, DUMP_ABORTED);
3586 network_dump_appletalk_player(NetPlayers.players[i].network.appletalk.node,NetPlayers.players[i].network.appletalk.net, NetPlayers.players[i].network.appletalk.socket, DUMP_ABORTED);
3591 Netgame.numplayers = 0;
3592 network_send_game_info(0); // Tell everyone we're bailing
3593 ipx_handle_leave_game(); // Tell the network driver we're bailing too
3595 Network_status = NETSTAT_MENU;
3599 // Count number of players chosen
3602 for (i=0; i<save_nplayers; i++ )
3608 if ( N_players > Netgame.max_numplayers) {
3610 nm_messagebox( TXT_ERROR, 1, TXT_OK, "%s %d %s", TXT_SORRY_ONLY, MaxNumNetPlayers, TXT_NETPLAYERS_IN );
3612 nm_messagebox( TXT_ERROR, 1, TXT_OK, "%s %d netplayers for this game.", TXT_SORRY_ONLY, MaxNumNetPlayers );
3614 N_players = save_nplayers;
3615 goto GetPlayersAgain;
3619 if ( N_players < 2 ) {
3620 nm_messagebox( TXT_ERROR, 1, TXT_OK, TXT_TEAM_ATLEAST_TWO );
3621 N_players = save_nplayers;
3622 goto GetPlayersAgain;
3627 if ( (Netgame.gamemode == NETGAME_TEAM_ANARCHY ||
3628 Netgame.gamemode == NETGAME_CAPTURE_FLAG || Netgame.gamemode == NETGAME_TEAM_HOARD) && (N_players < 2) ) {
3629 nm_messagebox(TXT_ERROR, 1, TXT_OK, "You must select at least two\nplayers to start a team game" );
3630 N_players = save_nplayers;
3631 goto GetPlayersAgain;
3635 // Remove players that aren't marked.
3637 for (i=0; i<save_nplayers; i++ ) {
3642 if (Network_game_type == IPX_GAME) {
3643 memcpy(NetPlayers.players[N_players].network.ipx.node, NetPlayers.players[i].network.ipx.node, 6);
3644 memcpy(NetPlayers.players[N_players].network.ipx.server, NetPlayers.players[i].network.ipx.server, 4);
3646 NetPlayers.players[N_players].network.appletalk.node = NetPlayers.players[i].network.appletalk.node;
3647 NetPlayers.players[N_players].network.appletalk.net = NetPlayers.players[i].network.appletalk.net;
3648 NetPlayers.players[N_players].network.appletalk.socket = NetPlayers.players[i].network.appletalk.socket;
3650 memcpy(NetPlayers.players[N_players].callsign, NetPlayers.players[i].callsign, CALLSIGN_LEN+1);
3651 NetPlayers.players[N_players].version_major=NetPlayers.players[i].version_major;
3652 NetPlayers.players[N_players].version_minor=NetPlayers.players[i].version_minor;
3653 NetPlayers.players[N_players].rank=NetPlayers.players[i].rank;
3654 ClipRank (&NetPlayers.players[N_players].rank);
3655 network_check_for_old_version(i);
3657 Players[N_players].connected = 1;
3662 if (Network_game_type == IPX_GAME)
3663 network_dump_player(NetPlayers.players[i].network.ipx.server,NetPlayers.players[i].network.ipx.node, DUMP_DORK);
3666 network_dump_appletalk_player(NetPlayers.players[i].network.appletalk.node,NetPlayers.players[i].network.appletalk.net, NetPlayers.players[i].network.appletalk.socket, DUMP_DORK);
3671 for (i = N_players; i < MAX_NUM_NET_PLAYERS; i++) {
3672 if (Network_game_type == IPX_GAME) {
3673 memset(NetPlayers.players[i].network.ipx.node, 0, 6);
3674 memset(NetPlayers.players[i].network.ipx.server, 0, 4);
3676 NetPlayers.players[i].network.appletalk.node = 0;
3677 NetPlayers.players[i].network.appletalk.net = 0;
3678 NetPlayers.players[i].network.appletalk.socket = 0;
3680 memset(NetPlayers.players[i].callsign, 0, CALLSIGN_LEN+1);
3681 NetPlayers.players[i].version_major=0;
3682 NetPlayers.players[i].version_minor=0;
3683 NetPlayers.players[i].rank=0;
3686 mprintf ((0,"Select teams: Game mode is %d\n",Netgame.gamemode));
3688 if (Netgame.gamemode == NETGAME_TEAM_ANARCHY ||
3689 Netgame.gamemode == NETGAME_CAPTURE_FLAG ||
3690 Netgame.gamemode == NETGAME_TEAM_HOARD)
3691 if (!network_select_teams())
3698 network_start_game()
3701 char game_name[NETGAME_NAME_LEN+1];
3702 int chosen_game_mode, game_flags, level;
3704 if (Network_game_type == IPX_GAME) {
3706 Assert( FRAME_INFO_SIZE < IPX_MAX_DATA_SIZE );
3707 mprintf((0, "Using frame_info len %d, max %d.\n", FRAME_INFO_SIZE, IPX_MAX_DATA_SIZE));
3709 if ( !Network_active )
3711 nm_messagebox(NULL, 1, TXT_OK, TXT_IPX_NOT_FOUND );
3719 Assert( FRAME_INFO_SIZE < APPLETALK_MAX_DATA_SIZE );
3720 mprintf((0, "Using frame_info len %d, max %d.\n", sizeof(frame_info), APPLETALK_MAX_DATA_SIZE));
3721 if (Appletalk_active <= 0) {
3722 switch (Appletalk_active) {
3723 case APPLETALK_NOT_OPEN:
3724 sprintf(buf, "Appletalk is not currently active.\nPlease enable AppleTalk from the\nChooser and restart Descent.");
3726 case APPLETALK_BAD_LISTENER:
3727 sprintf(buf, "The Resource Fork of Descent appears damaged.\nPlease re-install Descent or contact\nMacPlay technical support.");
3729 case APPLETALK_NO_LOCAL_ADDR:
3730 sprintf(buf, "Wow! Strange!\n\nNo Local Address.");
3732 case APPLETALK_NO_SOCKET:
3733 sprintf(buf, "All AppleTalk sockets are in use.\nTry shutting down other network\napplications and restarting Descent.\n");
3736 nm_messagebox(NULL, 1, TXT_OK, buf);
3739 strcpy(Network_zone_name, DEFAULT_ZONE_NAME);
3744 change_playernum_to(0);
3746 if (network_find_game())
3748 nm_messagebox(NULL, 1, TXT_OK, TXT_NET_FULL);
3753 i = network_get_game_params( game_name, &chosen_game_mode, &game_flags, &level );
3759 // LoadLevel(level); Old, no longer used.
3761 Netgame.difficulty = Difficulty_level;
3762 Netgame.gamemode = chosen_game_mode;
3763 Netgame.game_status = NETSTAT_STARTING;
3764 Netgame.numplayers = 0;
3765 Netgame.max_numplayers = MaxNumNetPlayers;
3766 Netgame.levelnum = level;
3767 Netgame.protocol_version = MULTI_PROTO_VERSION;
3769 strcpy(Netgame.game_name, game_name);
3771 Network_status = NETSTAT_STARTING;
3772 // Have the network driver initialize whatever data it wants to
3773 // store for this netgame.
3774 // For mcast4, this randomly chooses a multicast session and port.
3775 // Clients subscribe to this address when they call
3776 // ipx_handle_netgame_aux_data.
3777 ipx_init_netgame_aux_data(Netgame.AuxData);
3780 if (Network_game_type == APPLETALK_GAME) {
3785 show_boxed_message("Registering Netgame");
3787 err = appletalk_register_netgame( game_name, TickCount() );
3788 t1 = timer_get_fixed_seconds() + F1_0;
3789 while (timer_get_fixed_seconds() < t1) ;
3791 } while ( (err == nbpDuplicate) && (count != MAX_REGISTER_TRIES) );
3792 clear_boxed_message();
3793 if ( (err == tooManyReqs) || (count == MAX_REGISTER_TRIES) ) {
3794 nm_messagebox(NULL, 1, TXT_OK, "AppleTalk Network is too busy.\nPlease try again shortly.");
3795 Game_mode = GM_GAME_OVER;
3801 network_set_game_mode(Netgame.gamemode);
3803 d_srand( timer_get_fixed_seconds() );
3804 Netgame.Security=d_rand(); // For syncing Netgames with player packets
3806 if(network_select_players())
3808 StartNewLevel(Netgame.levelnum, 0);
3811 Game_mode = GM_GAME_OVER;
3815 void restart_net_searching(newmenu_item * m)
3819 num_active_games = 0;
3821 memset(Active_games, 0, sizeof(netgame_info)*MAX_ACTIVE_NETGAMES);
3823 for (i = 0; i < MAX_ACTIVE_NETGAMES; i++)
3825 sprintf(m[i+2].text, "%d. ",i+1);
3829 NamesInfoSecurity=-1;
3830 Network_games_changed = 1;
3833 char *ModeLetters[]={"ANRCHY","TEAM","ROBO","COOP","FLAG","HOARD","TMHOARD"};
3835 int NumActiveNetgames=0;
3837 void network_join_poll( int nitems, newmenu_item * menus, int * key, int citem )
3839 // Polling loop for Join Game menu
3841 int i, osocket,join_status,temp;
3848 if ( (Network_game_type == IPX_GAME) && Network_allow_socket_changes ) {
3849 osocket = Network_socket;
3851 if ( *key==KEY_PAGEDOWN ) { Network_socket--; *key = 0; }
3852 if ( *key==KEY_PAGEUP ) { Network_socket++; *key = 0; }
3854 if (Network_socket>99)
3856 if (Network_socket<-99)
3859 if ( Network_socket+IPX_DEFAULT_SOCKET > 0x8000 )
3860 Network_socket = 0x8000 - IPX_DEFAULT_SOCKET;
3862 if ( Network_socket+IPX_DEFAULT_SOCKET < 0 )
3863 Network_socket = IPX_DEFAULT_SOCKET;
3865 if (Network_socket != osocket ) {
3866 sprintf( menus[0].text, "\t%s %+d (PgUp/PgDn to change)", TXT_CURRENT_IPX_SOCKET, Network_socket );
3867 menus[0].redraw = 1;
3868 mprintf(( 0, "Changing to socket %d\n", Network_socket ));
3870 mprintf ((0,"netgood 1!\n"));
3871 ipx_change_default_socket( IPX_DEFAULT_SOCKET + Network_socket );
3872 mprintf ((0,"netgood 2!\n"));
3873 restart_net_searching(menus);
3874 mprintf ((0,"netgood 3!\n"));
3875 network_send_game_list_request();
3876 mprintf ((0,"netgood 4!\n"));
3881 // send a request for game info every 3 seconds
3883 if (Network_game_type == IPX_GAME) {
3884 if (timer_get_approx_seconds() > t1+F1_0*3) {
3885 t1 = timer_get_approx_seconds();
3886 network_send_game_list_request();
3889 } else if (timer_get_approx_seconds() > t1+F1_0*20) {
3891 t1 = timer_get_approx_seconds();
3892 restart_net_searching(menus);
3893 show_boxed_message("Requesting list of Netgames");
3894 network_send_game_list_request();
3895 clear_boxed_message();
3900 temp=num_active_games;
3904 NumActiveNetgames=num_active_games;
3906 if (!Network_games_changed)
3909 if (temp!=num_active_games)
3910 digi_play_sample (SOUND_HUD_MESSAGE,F1_0);
3912 Network_games_changed = 0;
3913 mprintf ((0,"JOIN POLL: I'm looking at %d games!\n",num_active_games));
3915 // Copy the active games data into the menu options
3916 for (i = 0; i < num_active_games; i++)
3918 int game_status = Active_games[i].game_status;
3919 int j,x, k,tx,ty,ta,nplayers = 0;
3920 char levelname[8],MissName[25],GameName[25],thold[2];
3923 // These next two loops protect against menu skewing
3924 // if missiontitle or gamename contain a tab
3926 for (x=0,tx=0,k=0,j=0;j<15;j++)
3928 if (Active_games[i].mission_title[j]=='\t')
3930 thold[0]=Active_games[i].mission_title[j];
3931 gr_get_string_size (thold,&tx,&ty,&ta);
3933 if ((x+=tx)>=LHX(55))
3935 MissName[k]=MissName[k+1]=MissName[k+2]='.';
3940 MissName[k++]=Active_games[i].mission_title[j];
3944 for (x=0,tx=0,k=0,j=0;j<15;j++)
3946 if (Active_games[i].game_name[j]=='\t')
3948 thold[0]=Active_games[i].game_name[j];
3949 gr_get_string_size (thold,&tx,&ty,&ta);
3951 if ((x+=tx)>=LHX(55))
3953 GameName[k]=GameName[k+1]=GameName[k+2]='.';
3957 GameName[k++]=Active_games[i].game_name[j];
3962 nplayers=Active_games[i].numconnected;
3964 if (Active_games[i].levelnum < 0)
3965 sprintf(levelname, "S%d", -Active_games[i].levelnum);
3967 sprintf(levelname, "%d", Active_games[i].levelnum);
3969 if (game_status == NETSTAT_STARTING)
3971 sprintf (menus[i+2].text,"%d.\t%s \t%s \t %d/%d \t%s \t %s \t%s",
3972 i+1,GameName,ModeLetters[Active_games[i].gamemode],nplayers,
3973 Active_games[i].max_numplayers,MissName,levelname,"Forming");
3975 else if (game_status == NETSTAT_PLAYING)
3977 join_status=can_join_netgame(&Active_games[i],NULL);
3978 // mprintf ((0,"Joinstatus=%d\n",join_status));
3981 sprintf (menus[i+2].text,"%d.\t%s \t%s \t %d/%d \t%s \t %s \t%s",
3982 i+1,GameName,ModeLetters[Active_games[i].gamemode],nplayers,
3983 Active_games[i].max_numplayers,MissName,levelname,"Open");
3984 else if (join_status==2)
3985 sprintf (menus[i+2].text,"%d.\t%s \t%s \t %d/%d \t%s \t %s \t%s",
3986 i+1,GameName,ModeLetters[Active_games[i].gamemode],nplayers,
3987 Active_games[i].max_numplayers,MissName,levelname,"Full");
3988 else if (join_status==3)
3989 sprintf (menus[i+2].text,"%d.\t%s \t%s \t %d/%d \t%s \t %s \t%s",
3990 i+1,GameName,ModeLetters[Active_games[i].gamemode],nplayers,
3991 Active_games[i].max_numplayers,MissName,levelname,"Restrict");
3993 sprintf (menus[i+2].text,"%d.\t%s \t%s \t %d/%d \t%s \t %s \t%s",
3994 i+1,GameName,ModeLetters[Active_games[i].gamemode],nplayers,
3995 Active_games[i].max_numplayers,MissName,levelname,"Closed");
3999 sprintf (menus[i+2].text,"%d.\t%s \t%s \t %d/%d \t%s \t %s \t%s",
4000 i+1,GameName,ModeLetters[Active_games[i].gamemode],nplayers,
4001 Active_games[i].max_numplayers,MissName,levelname,"Between");
4004 Assert(strlen(menus[i+2].text) < 100);
4005 menus[i+2].redraw = 1;
4008 for (i = num_active_games; i < MAX_ACTIVE_NETGAMES; i++)
4010 sprintf(menus[i+2].text, "%d. ",i+1);
4011 menus[i+2].redraw = 1;
4016 network_wait_for_sync(void)
4022 Network_status = NETSTAT_WAITING;
4024 m[0].type=NM_TYPE_TEXT; m[0].text = text;
4025 m[1].type=NM_TYPE_TEXT; m[1].text = TXT_NET_LEAVE;
4027 i = network_send_request();
4032 sprintf( m[0].text, "%s\n'%s' %s", TXT_NET_WAITING, NetPlayers.players[i].callsign, TXT_NET_TO_ENTER );
4035 choice=newmenu_do( NULL, TXT_WAIT, 2, m, network_sync_poll );
4040 if (Network_status != NETSTAT_PLAYING)
4044 // if (Network_status == NETSTAT_ENDLEVEL)
4046 // network_send_endlevel_packet(0);
4047 // longjmp(LeaveGame, 0);
4050 mprintf((0, "Aborting join.\n"));
4051 me.type = PID_QUIT_JOINING;
4052 memcpy( me.player.callsign, Players[Player_num].callsign, CALLSIGN_LEN+1 );
4053 if (Network_game_type == IPX_GAME) {
4054 memcpy( me.player.network.ipx.node, ipx_get_my_local_address(), 6 );
4055 memcpy( me.player.network.ipx.server, ipx_get_my_server_address(), 4 );
4056 send_internetwork_sequence_packet(me, NetPlayers.players[0].network.ipx.server, NetPlayers.players[0].network.ipx.node);
4059 me.player.network.appletalk.node = appletalk_get_my_node();
4060 me.player.network.appletalk.net = appletalk_get_my_net();
4061 me.player.network.appletalk.socket = appletalk_get_my_socket();
4065 Function_mode = FMODE_MENU;
4066 Game_mode = GM_GAME_OVER;
4067 return(-1); // they cancelled
4073 network_request_poll( int nitems, newmenu_item * menus, int * key, int citem )
4075 // Polling loop for waiting-for-requests menu
4085 // Send our endlevel packet at regular intervals
4087 // if (timer_get_approx_seconds() > t1+ENDLEVEL_SEND_INTERVAL)
4089 // network_send_endlevel_packet();
4090 // t1 = timer_get_approx_seconds();
4095 for (i = 0; i < N_players; i++)
4097 if ((Players[i].connected == 1) || (Players[i].connected == 0))
4101 if (num_ready == N_players) // All players have checked in or are disconnected
4108 network_wait_for_requests(void)
4110 // Wait for other players to load the level before we send the sync
4114 Network_status = NETSTAT_WAITING;
4116 m[0].type=NM_TYPE_TEXT; m[0].text = TXT_NET_LEAVE;
4118 mprintf((0, "Entered wait_for_requests : N_players = %d.\n", N_players));
4120 for (choice = 0; choice < N_players; choice++)
4121 mprintf((0, "Players[%d].connected = %d.\n", choice, Players[choice].connected));
4123 Network_status = NETSTAT_WAITING;
4126 Players[Player_num].connected = 1;
4129 choice = newmenu_do(NULL, TXT_WAIT, 1, m, network_request_poll);
4134 choice = nm_messagebox(NULL, 3, TXT_YES, TXT_NO, TXT_START_NOWAIT, TXT_QUITTING_NOW);
4140 // User confirmed abort
4142 for (i=0; i < N_players; i++) {
4143 if ((Players[i].connected != 0) && (i != Player_num)) {
4144 if (Network_game_type == IPX_GAME)
4145 network_dump_player(NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node, DUMP_ABORTED);
4148 network_dump_appletalk_player(NetPlayers.players[i].network.appletalk.node, NetPlayers.players[i].network.appletalk.net, NetPlayers.players[i].network.appletalk.socket, DUMP_ABORTED);
4154 if (Network_game_type == APPLETALK_GAME)
4155 network_release_registered_game();
4157 longjmp(LeaveGame, 0);
4159 else if (choice != -2)
4163 /* Do required syncing after each level, before starting new one */
4165 network_level_sync(void)
4169 mprintf((0, "Player %d entering network_level_sync.\n", Player_num));
4171 MySyncPackInitialized = 0;
4173 // my_segments_checksum = netmisc_calc_checksum(Segments, sizeof(segment)*(Highest_segment_index+1));
4175 network_flush(); // Flush any old packets
4178 result = network_wait_for_sync();
4179 else if (network_i_am_master())
4181 network_wait_for_requests();
4182 network_send_sync();
4186 result = network_wait_for_sync();
4188 network_count_powerups_in_mine();
4192 Players[Player_num].connected = 0;
4193 network_send_endlevel_packet();
4195 if (Network_game_type == APPLETALK_GAME)
4196 network_release_registered_game();
4198 longjmp(LeaveGame, 0);
4203 void network_count_powerups_in_mine(void)
4207 for (i=0;i<MAX_POWERUP_TYPES;i++)
4208 PowerupsInMine[i]=0;
4210 for (i=0;i<=Highest_object_index;i++)
4212 if (Objects[i].type==OBJ_POWERUP)
4214 PowerupsInMine[Objects[i].id]++;
4215 if (multi_powerup_is_4pack(Objects[i].id))
4216 PowerupsInMine[Objects[i].id-1]+=4;
4224 // code to release the NBP binding of an appletalk game
4226 void network_release_registered_game()
4228 if (Network_game_type == APPLETALK_GAME)
4229 appletalk_remove_netgame();
4232 // code to sort zone lists....
4234 int zone_sort_func(const char **e0, const char **e1)
4236 return strcmp(*e0, *e1);
4239 void network_get_appletalk_zone()
4241 int num_zones, i, item, default_item;
4243 char default_zone[MAX_ZONE_LENGTH]; // my zone
4245 Network_zone_name[0] = '\0';
4247 show_boxed_message("Looking for AppleTalk Zones");
4248 num_zones = appletalk_get_zone_names(&zone_list);
4249 clear_boxed_message();
4251 if (num_zones < 0) { // error in getting zone list...maybe no router available....
4252 if ( (num_zones == tooManyReqs) || (num_zones == noDataArea) ){
4253 nm_messagebox(NULL, 1, TXT_OK, "AppleTalk Network is too busy.\nPlease try again shortly.");
4254 longjmp(LeaveGame,0);
4259 if (num_zones == 0) {
4260 strcpy(Network_zone_name, DEFAULT_ZONE_NAME);
4264 if (num_zones == 1) {
4265 Network_zone_name[0] = (char)(strlen(zone_list[0]));
4266 memcpy( &(Network_zone_name[1]), zone_list[0], strlen(zone_list[0]) );
4270 // sort the zone names
4272 for (i = 0; i < num_zones; i++)
4273 strlwr(zone_list[i]);
4275 qsort(zone_list, num_zones, sizeof(char *), zone_sort_func);
4277 // get my current zone so we can highlight that one first
4279 if (appletalk_get_my_zone(default_zone))
4282 for (i = 0; i < num_zones; i++) {
4283 if ( !stricmp(zone_list[i], default_zone) ) {
4291 item = newmenu_listbox1("AppleTalk Zones", num_zones, zone_list, 0, default_item, NULL);
4296 Network_zone_name[0] = (char)(strlen(zone_list[item]));
4297 memcpy( &(Network_zone_name[1]), zone_list[item], strlen(zone_list[item]) );
4300 for (i = 0; i < num_zones; i++)
4301 d_free(zone_list[i]);
4306 void nm_draw_background1(char * filename);
4308 void network_join_game()
4311 char menu_text[MAX_ACTIVE_NETGAMES+2][200];
4313 newmenu_item m[MAX_ACTIVE_NETGAMES+2];
4315 if (Network_game_type == IPX_GAME) {
4316 if ( !Network_active )
4318 nm_messagebox(NULL, 1, TXT_OK, TXT_IPX_NOT_FOUND);
4322 } else if (Appletalk_active <= 0) {
4325 switch (Appletalk_active) {
4326 case APPLETALK_NOT_OPEN:
4327 sprintf(buf, "Appletalk is not currently active.\nPlease enable AppleTalk from the\nChooser and restart Descent.");
4329 case APPLETALK_BAD_LISTENER:
4330 sprintf(buf, "The Resource Fork of Descent appears damaged.\nPlease re-install Descent or contact\nMacPlay technical support.");
4332 case APPLETALK_NO_LOCAL_ADDR:
4333 sprintf(buf, "Wow! Strange!\n\nNo Local Address.");
4335 case APPLETALK_NO_SOCKET:
4336 sprintf(buf, "All AppleTalk sockets are in use.\nTry shutting down other network\napplications and restarting Descent.\n");
4339 nm_messagebox(NULL, 1, TXT_OK, buf);
4351 if (Network_game_type == APPLETALK_GAME)
4352 network_get_appletalk_zone();
4355 Network_send_objects = 0;
4356 Network_sending_extras=0;
4359 Network_status = NETSTAT_BROWSING; // We are looking at a game menu
4362 network_listen(); // Throw out old info
4365 if (Network_game_type == IPX_GAME)
4366 #endif // note link to if
4367 network_send_game_list_request(); // broadcast a request for lists
4369 num_active_games = 0;
4371 memset(m, 0, sizeof(newmenu_item)*MAX_ACTIVE_NETGAMES);
4372 memset(Active_games, 0, sizeof(netgame_info)*MAX_ACTIVE_NETGAMES);
4373 memset(ActiveNetPlayers,0,sizeof(AllNetPlayers_info)*MAX_ACTIVE_NETGAMES);
4375 gr_set_fontcolor(BM_XRGB(15,15,23),-1);
4377 m[0].text = menu_text[0];
4378 m[0].type = NM_TYPE_TEXT;
4379 if (Network_game_type == IPX_GAME) {
4380 if (Network_allow_socket_changes)
4381 sprintf( m[0].text, "\tCurrent IPX Socket is default %+d (PgUp/PgDn to change)", Network_socket );
4383 strcpy( m[0].text, "" ); //sprintf( m[0].text, "" );
4386 p2cstr(Network_zone_name);
4387 if (strcmp(Network_zone_name, "*")) // only print if there is a zone name
4388 sprintf(m[0].text, "\tCurrent Zone is %s", Network_zone_name); // is Network_zone_name a pascal string????
4389 c2pstr(Network_zone_name);
4393 m[1].text=menu_text[1];
4394 m[1].type=NM_TYPE_TEXT;
4395 sprintf (m[1].text,"\tGAME \tMODE \t#PLYRS \tMISSION \tLEV \tSTATUS");
4397 for (i = 0; i < MAX_ACTIVE_NETGAMES; i++) {
4398 m[i+2].text = menu_text[i+2];
4399 m[i+2].type = NM_TYPE_MENU;
4400 sprintf(m[i+2].text, "%d. ", i+1);
4404 Network_games_changed = 1;
4407 nm_draw_background1(Menu_pcx_name); //load this here so if we abort after loading level, we restore the palette
4408 gr_palette_load(gr_palette);
4409 ExtGameStatus=GAMESTAT_JOIN_NETGAME;
4410 choice=newmenu_dotiny("NETGAMES", NULL,MAX_ACTIVE_NETGAMES+2, m, network_join_poll);
4414 Network_status = NETSTAT_MENU;
4415 return; // they cancelled
4419 if (choice >=num_active_games)
4421 nm_messagebox(TXT_SORRY, 1, TXT_OK, TXT_INVALID_CHOICE);
4425 // Choice has been made and looks legit
4426 if (Active_games[choice].game_status == NETSTAT_ENDLEVEL)
4428 nm_messagebox(TXT_SORRY, 1, TXT_OK, TXT_NET_GAME_BETWEEN2);
4432 if (Active_games[choice].protocol_version != MULTI_PROTO_VERSION)
4434 if (Active_games[choice].protocol_version == 3) {
4436 nm_messagebox(TXT_SORRY, 1, TXT_OK, "Your version of Descent 2\nis incompatible with the\nDemo version");
4439 else if (Active_games[choice].protocol_version == 4) {
4441 nm_messagebox(TXT_SORRY, 1, TXT_OK, "This Demo version of\nDescent 2 is incompatible\nwith the full commercial version");
4445 nm_messagebox(TXT_SORRY, 1, TXT_OK, TXT_VERSION_MISMATCH);
4452 // Check for valid mission name
4453 mprintf((0, "Loading mission:%s.\n", Active_games[choice].mission_name));
4454 if (!load_mission_by_name(Active_games[choice].mission_name))
4456 nm_messagebox(NULL, 1, TXT_OK, TXT_MISSION_NOT_FOUND);
4464 if (Active_games[choice].levelnum>8)
4466 nm_messagebox(NULL, 1, TXT_OK, "This OEM version only supports\nthe first 8 levels!");
4473 if (Active_games[choice].levelnum > 4)
4475 nm_messagebox(NULL, 1, TXT_OK, "This SHAREWARE version only supports\nthe first 4 levels!");
4480 if (!network_wait_for_all_info (choice))
4482 nm_messagebox (TXT_SORRY,1,TXT_OK,"There was a join error!");
4483 Network_status = NETSTAT_BROWSING; // We are looking at a game menu
4487 Network_status = NETSTAT_BROWSING; // We are looking at a game menu
4489 if (!can_join_netgame(&Active_games[choice],&ActiveNetPlayers[choice]))
4491 if (Active_games[choice].numplayers == Active_games[choice].max_numplayers)
4492 nm_messagebox(TXT_SORRY, 1, TXT_OK, TXT_GAME_FULL);
4494 nm_messagebox(TXT_SORRY, 1, TXT_OK, TXT_IN_PROGRESS);
4498 // Choice is valid, prepare to join in
4500 memcpy(&Netgame, &Active_games[choice], sizeof(netgame_info));
4501 memcpy (&NetPlayers,&ActiveNetPlayers[choice],sizeof(AllNetPlayers_info));
4503 Difficulty_level = Netgame.difficulty;
4504 MaxNumNetPlayers = Netgame.max_numplayers;
4505 change_playernum_to(1);
4507 // Handle the extra data for the network driver
4508 // For the mcast4 driver, this is the game's multicast address, to
4509 // which the driver subscribes.
4510 if(ipx_handle_netgame_aux_data(Netgame.AuxData) < 0)
4512 Network_status = NETSTAT_BROWSING;
4518 // register the joining player with NBP. This will have the nice effect of a player wanting to
4519 // join to be able to see the netgame if this player were to become the master.
4521 if (Network_game_type == APPLETALK_GAME) {
4526 show_boxed_message("Registering Netgame");
4528 err = appletalk_register_netgame( Active_games[choice].game_name, TickCount() );
4529 t1 = timer_get_fixed_seconds() + F1_0;
4530 while ( timer_get_fixed_seconds() < t1 ) ;
4532 } while ( (err == nbpDuplicate) && (count != MAX_REGISTER_TRIES) );
4533 clear_boxed_message();
4534 if ( (err == tooManyReqs) || (count == MAX_REGISTER_TRIES) ) {
4535 nm_messagebox(NULL, 1, TXT_OK, "AppleTalk Network is too busy.\nPlease try again shortly.");
4541 network_set_game_mode(Netgame.gamemode);
4543 network_AdjustMaxDataSize ();
4545 StartNewLevel(Netgame.levelnum, 0);
4547 return; // look ma, we're in a game!!!
4550 void network_AdjustMaxDataSize ()
4553 if (Netgame.ShortPackets)
4554 MaxXDataSize=NET_XDATA_SIZE;
4556 MaxXDataSize=NET_XDATA_SIZE;
4560 fix StartWaitAllTime=0;
4561 int WaitAllChoice=0;
4562 #define ALL_INFO_REQUEST_INTERVAL F1_0*3
4564 void network_wait_all_poll( int nitems, newmenu_item * menus, int * key, int citem )
4572 if (timer_get_approx_seconds() > t1+ALL_INFO_REQUEST_INTERVAL)
4574 network_send_all_info_request(PID_SEND_ALL_GAMEINFO,SecurityCheck);
4575 t1 = timer_get_approx_seconds();
4578 network_do_big_wait(WaitAllChoice);
4580 if(SecurityCheck==-1)
4584 int network_wait_for_all_info (int choice)
4590 m[0].type=NM_TYPE_TEXT; m[0].text = "Press Escape to cancel";
4592 WaitAllChoice=choice;
4593 StartWaitAllTime=timer_get_approx_seconds();
4594 SecurityCheck=Active_games[choice].Security;
4598 pick=newmenu_do( NULL, "Connecting...", 1, m, network_wait_all_poll );
4600 if (pick>-1 && SecurityCheck!=-1)
4603 if (SecurityCheck==-1)
4612 void network_do_big_wait(int choice)
4615 ubyte packet[IPX_MAX_DATA_SIZE],*data;
4616 AllNetPlayers_info *temp_info;
4617 #ifdef WORDS_BIGENDIAN
4618 AllNetPlayers_info info_struct;
4621 ubyte apacket[APPLETALK_MAX_DATA_SIZE];
4625 if (Network_game_type == APPLETALK_GAME)
4626 size=appletalk_get_packet_data( apacket );
4629 size=ipx_get_packet_data( packet );
4634 if (Network_game_type == APPLETALK_GAME)
4644 if (Network_game_type == IPX_GAME) {
4645 receive_full_netgame_packet(data, &TempNetInfo);
4647 memcpy((ubyte *)&TempNetInfo, data, sizeof(netgame_info));
4649 mprintf ((0,"This is %s game with a security of %d\n",TempNetInfo.game_name,TempNetInfo.Security));
4651 if (TempNetInfo.Security !=SecurityCheck)
4653 mprintf ((0,"Bad security on big_wait...rejecting.\n"));
4657 if (NetSecurityFlag==NETSECURITY_WAIT_FOR_GAMEINFO)
4659 if (TempPlayersInfo->Security==TempNetInfo.Security)
4661 mprintf ((0,"EQUAL !: Game=%d Players=%d ",TempPlayersInfo->Security,TempNetInfo.Security));
4662 if (TempPlayersInfo->Security==SecurityCheck)
4664 memcpy (&Active_games[choice],(ubyte *)&TempNetInfo,sizeof(netgame_info));
4665 memcpy (&ActiveNetPlayers[choice],TempPlayersInfo,sizeof(AllNetPlayers_info));
4672 NetSecurityFlag=NETSECURITY_WAIT_FOR_PLAYERS;
4673 NetSecurityNum=TempNetInfo.Security;
4675 if (network_wait_for_playerinfo())
4677 mprintf ((0,"HUH? Game=%d Player=%d\n",NetSecurityNum,TempPlayersInfo->Security));
4678 memcpy (&Active_games[choice],(ubyte *)&TempNetInfo,sizeof(netgame_info));
4679 memcpy (&ActiveNetPlayers[choice],TempPlayersInfo,sizeof(AllNetPlayers_info));
4686 case PID_PLAYERSINFO:
4687 mprintf ((0,"Got a PID_PLAYERSINFO!\n"));
4689 if (Network_game_type == IPX_GAME) {
4690 #ifndef WORDS_BIGENDIAN
4691 temp_info=(AllNetPlayers_info *)data;
4693 receive_netplayers_packet(data, &info_struct);
4694 temp_info = &info_struct;
4697 temp_info = (AllNetPlayers_info *)data;
4699 if (temp_info->Security!=SecurityCheck)
4700 break; // If this isn't the guy we're looking for, move on
4702 memcpy (&TempPlayersBase,(ubyte *)&temp_info,sizeof(AllNetPlayers_info));
4703 TempPlayersInfo=&TempPlayersBase;
4704 WaitingForPlayerInfo=0;
4705 NetSecurityNum=TempPlayersInfo->Security;
4706 NetSecurityFlag=NETSECURITY_WAIT_FOR_GAMEINFO;
4712 void network_leave_game()
4716 network_do_frame(1, 1);
4719 fclose (SendLogFile);
4720 fclose (RecieveLogFile);
4723 if ((network_i_am_master()))
4725 while (Network_sending_extras>1 && Player_joining_extras!=-1)
4726 network_send_extras();
4728 Netgame.numplayers = 0;
4731 network_send_game_info(NULL);
4734 mprintf ((0,"HEY! I'm master and I've left.\n"));
4737 Players[Player_num].connected = 0;
4738 network_send_endlevel_packet();
4739 change_playernum_to(0);
4740 Game_mode = GM_GAME_OVER;
4741 write_player_file();
4743 // WIN(ipx_destroy_read_thread());
4745 // Tell the network driver we're done with the game.
4746 // This is used by ipx_mcast4.c to unsubscribe from the game's
4747 // multicast session
4748 ipx_handle_leave_game();
4753 void network_flush()
4756 ubyte apacket[APPLETALK_MAX_DATA_SIZE];
4758 ubyte packet[IPX_MAX_DATA_SIZE];
4761 if ( (Network_game_type == APPLETALK_GAME) && (Appletalk_active <= 0) )
4765 if ( Network_game_type == IPX_GAME )
4766 if (!Network_active) return;
4769 if (Network_game_type == APPLETALK_GAME)
4770 while (appletalk_get_packet_data(apacket) > 0) ;
4773 while (ipx_get_packet_data(packet) > 0) ;
4776 void network_listen()
4779 ubyte apacket[APPLETALK_MAX_DATA_SIZE];
4782 ubyte packet[IPX_MAX_DATA_SIZE];
4785 if (Network_status==NETSTAT_PLAYING && Netgame.ShortPackets && !Network_send_objects)
4787 loopmax=N_players*Netgame.PacketsPerSec;
4791 if ( (Network_game_type == APPLETALK_GAME) && (Appletalk_active <= 0) )
4795 if (Network_game_type == IPX_GAME)
4796 if (!Network_active) return;
4798 if (!(Game_mode & GM_NETWORK) && (Function_mode == FMODE_GAME))
4799 mprintf((0, "Calling network_listen() when not in net game.\n"));
4801 WaitingForPlayerInfo=1;
4802 NetSecurityFlag=NETSECURITY_OFF;
4805 if (Network_game_type == IPX_GAME) {
4806 size = ipx_get_packet_data( packet );
4808 network_process_packet( packet, size );
4811 size = ipx_get_packet_data( packet );
4815 size = appletalk_get_packet_data( apacket );
4817 network_process_packet( apacket, size );
4820 size = appletalk_get_packet_data( apacket );
4826 int network_wait_for_playerinfo()
4829 ubyte packet[IPX_MAX_DATA_SIZE];
4830 struct AllNetPlayers_info *TempInfo;
4833 #ifdef WORDS_BIGENDIAN
4834 AllNetPlayers_info info_struct;
4837 ubyte apacket[APPLETALK_MAX_DATA_SIZE];
4841 if ( (Network_game_type == APPLETALK_GAME) && (Appletalk_active <= 0) )
4845 if ( Network_game_type == IPX_GAME)
4846 if (!Network_active) return(0);
4848 // if (!WaitingForPlayerInfo)
4851 if (!(Game_mode & GM_NETWORK) && (Function_mode == FMODE_GAME))
4853 mprintf((0, "Calling network_wait_for_playerinfo() when not in net game.\n"));
4855 if (Network_status==NETSTAT_PLAYING)
4857 Int3(); //MY GOD! Get Jason...this is the source of many problems
4860 basetime=timer_get_approx_seconds();
4862 while (WaitingForPlayerInfo && retries<50 && (timer_get_approx_seconds()<(basetime+(F1_0*5))))
4864 if (Network_game_type == IPX_GAME) {
4865 size = ipx_get_packet_data( packet );
4869 size = appletalk_get_packet_data( apacket );
4874 if (size>0 && id==PID_PLAYERSINFO)
4876 #ifdef WORDS_BIGENDIAN
4878 if (Network_game_type == APPLETALK_GAME) {
4879 TempInfo = (AllNetPlayers_info *)apacket;
4883 receive_netplayers_packet(packet, &info_struct);
4884 TempInfo = &info_struct;
4887 TempInfo=(AllNetPlayers_info *)packet;
4892 if (NetSecurityFlag==NETSECURITY_WAIT_FOR_PLAYERS)
4894 if (NetSecurityNum==TempInfo->Security)
4896 mprintf ((0,"HEYEQUAL: Player=%d Game=%d\n",TempInfo->Security,NetSecurityNum));
4897 memcpy (&TempPlayersBase,(ubyte *)TempInfo,sizeof(AllNetPlayers_info));
4898 TempPlayersInfo=&TempPlayersBase;
4899 NetSecurityFlag=NETSECURITY_OFF;
4901 WaitingForPlayerInfo=0;
4909 mprintf ((0,"I'm original!\n"));
4911 NetSecurityNum=TempInfo->Security;
4912 NetSecurityFlag=NETSECURITY_WAIT_FOR_GAMEINFO;
4914 memcpy (&TempPlayersBase,(ubyte *)TempInfo,sizeof(AllNetPlayers_info));
4915 TempPlayersInfo=&TempPlayersBase;
4916 WaitingForPlayerInfo=0;
4925 void network_send_data( ubyte * ptr, int len, int urgent )
4931 fprintf (SendLogFile,"Packet type: %d Len:%d Urgent:%d TT=%d\n",ptr[0],len,urgent,TTSent[ptr[0]]);
4932 fflush (SendLogFile);
4935 if (Endlevel_sequence)
4938 if (!MySyncPackInitialized) {
4939 MySyncPackInitialized = 1;
4940 memset( &MySyncPack, 0, sizeof(frame_info) );
4946 if ((MySyncPack.data_size+len) > MaxXDataSize ) {
4948 network_do_frame(1, 0);
4949 if (MySyncPack.data_size != 0) {
4950 mprintf((0, "%d bytes were added to data by network_do_frame!\n", MySyncPack.data_size));
4953 // Int3(); // Trying to send too much!
4955 mprintf((0, "Packet overflow, sending additional packet, type %d len %d.\n", ptr[0], len));
4956 Assert(check == ptr[0]);
4959 Assert(MySyncPack.data_size+len <= MaxXDataSize);
4961 memcpy( &MySyncPack.data[MySyncPack.data_size], ptr, len );
4962 MySyncPack.data_size += len;
4965 void network_timeout_player(int playernum)
4967 // Remove a player from the game if we haven't heard from them in
4971 Assert(playernum < N_players);
4972 Assert(playernum > -1);
4974 network_disconnect_player(playernum);
4975 create_player_appearance_effect(&Objects[Players[playernum].objnum]);
4977 digi_play_sample(SOUND_HUD_MESSAGE, F1_0);
4979 HUD_init_message("%s %s", Players[playernum].callsign, TXT_DISCONNECTING);
4980 for (i = 0; i < N_players; i++)
4981 if (Players[i].connected)
4986 nm_messagebox(NULL, 1, TXT_OK, TXT_YOU_ARE_ONLY);
4990 fix last_send_time = 0;
4991 fix last_timeout_check = 0;
4993 #ifdef WORDS_BIGENDIAN
4994 void squish_short_frame_info(short_frame_info old_info, ubyte *data)
5000 data[0] = old_info.type; loc++;
5001 /* skip three for pad byte */ loc += 3;
5002 tmpi = INTEL_INT(old_info.numpackets);
5003 memcpy(&(data[loc]), &tmpi, 4); loc += 4;
5005 memcpy(&(data[loc]), old_info.thepos.bytemat, 9); loc += 9;
5006 tmps = INTEL_SHORT(old_info.thepos.xo);
5007 memcpy(&(data[loc]), &tmps, 2); loc += 2;
5008 tmps = INTEL_SHORT(old_info.thepos.yo);
5009 memcpy(&(data[loc]), &tmps, 2); loc += 2;
5010 tmps = INTEL_SHORT(old_info.thepos.zo);
5011 memcpy(&(data[loc]), &tmps, 2); loc += 2;
5012 tmps = INTEL_SHORT(old_info.thepos.segment);
5013 memcpy(&(data[loc]), &tmps, 2); loc += 2;
5014 tmps = INTEL_SHORT(old_info.thepos.velx);
5015 memcpy(&(data[loc]), &tmps, 2); loc += 2;
5016 tmps = INTEL_SHORT(old_info.thepos.vely);
5017 memcpy(&(data[loc]), &tmps, 2); loc += 2;
5018 tmps = INTEL_SHORT(old_info.thepos.velz);
5019 memcpy(&(data[loc]), &tmps, 2); loc += 2;
5021 tmps = INTEL_SHORT(old_info.data_size);
5022 memcpy(&(data[loc]), &tmps, 2); loc += 2;
5024 data[loc] = old_info.playernum; loc++;
5025 data[loc] = old_info.obj_render_type; loc++;
5026 data[loc] = old_info.level_num; loc++;
5027 memcpy(&(data[loc]), old_info.data, old_info.data_size);
5031 char NakedBuf[NET_XDATA_SIZE+4];
5032 int NakedPacketLen=0;
5033 int NakedPacketDestPlayer=-1;
5035 void network_do_frame(int force, int listen)
5038 short_frame_info ShortSyncPack;
5039 static fix LastEndlevel=0;
5041 if (!(Game_mode&GM_NETWORK)) return;
5043 if ((Network_status != NETSTAT_PLAYING) || (Endlevel_sequence)) // Don't send postion during escape sequence...
5048 Assert (NakedPacketDestPlayer>-1);
5049 // mprintf ((0,"Sending a naked packet to %s (%d bytes)!\n",Players[NakedPacketDestPlayer].callsign,NakedPacketLen));
5050 if (Network_game_type == IPX_GAME)
5051 ipx_send_packet_data( (ubyte *)NakedBuf, NakedPacketLen, NetPlayers.players[NakedPacketDestPlayer].network.ipx.server, NetPlayers.players[NakedPacketDestPlayer].network.ipx.node,Players[NakedPacketDestPlayer].net_address );
5054 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 );
5057 NakedPacketDestPlayer=-1;
5060 if (WaitForRefuseAnswer && timer_get_approx_seconds()>(RefuseTimeLimit+(F1_0*12)))
5061 WaitForRefuseAnswer=0;
5063 last_send_time += FrameTime;
5064 last_timeout_check += FrameTime;
5066 // Send out packet PacksPerSec times per second maximum... unless they fire, then send more often...
5067 if ( (last_send_time>F1_0/Netgame.PacketsPerSec) || (Network_laser_fired) || force || PacketUrgent ) {
5068 if ( Players[Player_num].connected ) {
5069 int objnum = Players[Player_num].objnum;
5073 multi_send_robot_frame(0);
5074 multi_send_fire(); // Do firing if needed..
5079 if (Netgame.ShortPackets)
5081 #ifdef WORDS_BIGENDIAN
5082 ubyte send_data[IPX_MAX_DATA_SIZE];
5083 //int squished_size;
5085 create_shortpos(&ShortSyncPack.thepos, Objects+objnum, 0);
5086 ShortSyncPack.type = PID_PDATA;
5087 ShortSyncPack.playernum = Player_num;
5088 ShortSyncPack.obj_render_type = Objects[objnum].render_type;
5089 ShortSyncPack.level_num = Current_level_num;
5090 ShortSyncPack.data_size = MySyncPack.data_size;
5091 memcpy (&ShortSyncPack.data[0],&MySyncPack.data[0],MySyncPack.data_size);
5093 // -- killed -- 2003-10-11 by Aaron
5094 // Use ipx_send_game_packet instead to send packets to everyone in the game.
5095 // Define in arch/*/*net.c
5097 for (i=0; i<N_players; i++ ) {
5098 if ( (Players[i].connected) && (i!=Player_num ) ) {
5099 MySyncPack.numpackets = Players[i].n_packets_sent++;
5100 ShortSyncPack.numpackets=MySyncPack.numpackets;
5101 if (Network_game_type == IPX_GAME) {
5102 #ifndef WORDS_BIGENDIAN
5103 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 );
5105 squish_short_frame_info(ShortSyncPack, send_data);
5106 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 );
5110 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 );
5116 MySyncPack.numpackets = INTEL_INT(Players[0].n_packets_sent++);
5117 ShortSyncPack.numpackets = MySyncPack.numpackets;
5118 #ifndef WORDS_BIGENDIAN
5119 ipx_send_game_packet((ubyte*)&ShortSyncPack, sizeof(short_frame_info) - MaxXDataSize + MySyncPack.data_size);
5121 squish_short_frame_info(ShortSyncPack, send_data);
5122 ipx_send_game_packet((ubyte*)send_data, IPX_SHORT_INFO_SIZE-MaxXDataSize+MySyncPack.data_size);
5127 else // If long packets
5131 MySyncPack.type = PID_PDATA;
5132 MySyncPack.playernum = Player_num;
5133 MySyncPack.obj_render_type = Objects[objnum].render_type;
5134 MySyncPack.level_num = Current_level_num;
5135 MySyncPack.obj_segnum = Objects[objnum].segnum;
5136 MySyncPack.obj_pos = Objects[objnum].pos;
5137 MySyncPack.obj_orient = Objects[objnum].orient;
5138 MySyncPack.phys_velocity = Objects[objnum].mtype.phys_info.velocity;
5139 MySyncPack.phys_rotvel = Objects[objnum].mtype.phys_info.rotvel;
5141 send_data_size = MySyncPack.data_size; // do this so correct size data is sent
5143 #ifdef WORDS_BIGENDIAN // do the swap stuff
5144 if (Network_game_type == IPX_GAME) {
5145 MySyncPack.obj_segnum = INTEL_SHORT(MySyncPack.obj_segnum);
5146 MySyncPack.obj_pos.x = INTEL_INT((int)MySyncPack.obj_pos.x);
5147 MySyncPack.obj_pos.y = INTEL_INT((int)MySyncPack.obj_pos.y);
5148 MySyncPack.obj_pos.z = INTEL_INT((int)MySyncPack.obj_pos.z);
5150 MySyncPack.obj_orient.rvec.x = INTEL_INT((int)MySyncPack.obj_orient.rvec.x);
5151 MySyncPack.obj_orient.rvec.y = INTEL_INT((int)MySyncPack.obj_orient.rvec.y);
5152 MySyncPack.obj_orient.rvec.z = INTEL_INT((int)MySyncPack.obj_orient.rvec.z);
5153 MySyncPack.obj_orient.uvec.x = INTEL_INT((int)MySyncPack.obj_orient.uvec.x);
5154 MySyncPack.obj_orient.uvec.y = INTEL_INT((int)MySyncPack.obj_orient.uvec.y);
5155 MySyncPack.obj_orient.uvec.z = INTEL_INT((int)MySyncPack.obj_orient.uvec.z);
5156 MySyncPack.obj_orient.fvec.x = INTEL_INT((int)MySyncPack.obj_orient.fvec.x);
5157 MySyncPack.obj_orient.fvec.y = INTEL_INT((int)MySyncPack.obj_orient.fvec.y);
5158 MySyncPack.obj_orient.fvec.z = INTEL_INT((int)MySyncPack.obj_orient.fvec.z);
5160 MySyncPack.phys_velocity.x = INTEL_INT((int)MySyncPack.phys_velocity.x);
5161 MySyncPack.phys_velocity.y = INTEL_INT((int)MySyncPack.phys_velocity.y);
5162 MySyncPack.phys_velocity.z = INTEL_INT((int)MySyncPack.phys_velocity.z);
5164 MySyncPack.phys_rotvel.x = INTEL_INT((int)MySyncPack.phys_rotvel.x);
5165 MySyncPack.phys_rotvel.y = INTEL_INT((int)MySyncPack.phys_rotvel.y);
5166 MySyncPack.phys_rotvel.z = INTEL_INT((int)MySyncPack.phys_rotvel.z);
5168 MySyncPack.data_size = INTEL_SHORT(MySyncPack.data_size);
5173 for (i=0; i<N_players; i++ ) {
5174 if ( (Players[i].connected) && (i!=Player_num ) ) {
5175 if (Network_game_type == IPX_GAME)
5176 MySyncPack.numpackets = INTEL_INT(Players[i].n_packets_sent);
5178 MySyncPack.numpackets = Players[i].n_packets_sent;
5180 Players[i].n_packets_sent++;
5181 if (Network_game_type == IPX_GAME)
5182 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 );
5185 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);
5190 MySyncPack.numpackets = INTEL_INT(Players[0].n_packets_sent++);
5191 ipx_send_game_packet((ubyte*)&MySyncPack, sizeof(frame_info) - MaxXDataSize + send_data_size);
5195 MySyncPack.data_size = 0; // Start data over at 0 length.
5196 if (Control_center_destroyed)
5199 Players[Player_num].connected=3;
5200 if (timer_get_approx_seconds() > (LastEndlevel+(F1_0/2)))
5202 network_send_endlevel_packet();
5203 LastEndlevel=timer_get_approx_seconds();
5206 //mprintf( (0, "Packet has %d bytes appended (TS=%d)\n", MySyncPack.data_size, sizeof(frame_info)-MaxXDataSize+MySyncPack.data_size ));
5213 if ((last_timeout_check > F1_0) && !(Control_center_destroyed))
5215 fix approx_time = timer_get_approx_seconds();
5216 // Check for player timeouts
5217 for (i = 0; i < N_players; i++)
5219 if ((i != Player_num) && (Players[i].connected == 1))
5221 if ((LastPacketTime[i] == 0) || (LastPacketTime[i] > approx_time))
5223 LastPacketTime[i] = approx_time;
5226 if ((approx_time - LastPacketTime[i]) > (15*F1_0))
5227 network_timeout_player(i);
5230 last_timeout_check = 0;
5236 MySyncPack.data_size = 0;
5241 if (VerifyPlayerJoined!=-1 && !(FrameCount & 63))
5242 resend_sync_due_to_packet_loss_for_allender(); // This will resend to network_player_rejoining
5244 if (Network_send_objects)
5245 network_send_objects();
5247 if (Network_sending_extras && VerifyPlayerJoined==-1)
5249 network_send_extras();
5254 int missed_packets = 0;
5256 int ConsistencyCount = 0;
5258 void network_consistency_error(void)
5260 if (++ConsistencyCount < 10)
5263 Function_mode = FMODE_MENU;
5265 nm_messagebox(NULL, 1, TXT_OK, TXT_CONSISTENCY_ERROR);
5267 nm_messagebox(NULL, 1, TXT_OK, "Failed to join the netgame.\nYou are missing packets. Check\nyour network connection and\ntry again.");
5269 Function_mode = FMODE_GAME;
5270 ConsistencyCount = 0;
5271 multi_quit_game = 1;
5272 multi_leave_menu = 1;
5273 multi_reset_stuff();
5274 Function_mode = FMODE_MENU;
5277 void network_process_pdata (char *data)
5279 Assert (Game_mode & GM_NETWORK);
5281 if (Netgame.ShortPackets)
5282 network_read_pdata_short_packet ((short_frame_info *)data);
5284 network_read_pdata_packet ((frame_info *)data);
5287 void network_read_pdata_packet(frame_info *pd )
5291 object * TheirObj = NULL;
5293 // frame_info should be aligned...for mac, make the necessary adjustments
5294 #ifdef WORDS_BIGENDIAN
5295 if (Network_game_type == IPX_GAME) {
5296 pd->numpackets = INTEL_INT(pd->numpackets);
5297 pd->obj_pos.x = INTEL_INT(pd->obj_pos.x);
5298 pd->obj_pos.y = INTEL_INT(pd->obj_pos.y);
5299 pd->obj_pos.z = INTEL_INT(pd->obj_pos.z);
5301 pd->obj_orient.rvec.x = (fix)INTEL_INT((int)pd->obj_orient.rvec.x);
5302 pd->obj_orient.rvec.y = (fix)INTEL_INT((int)pd->obj_orient.rvec.y);
5303 pd->obj_orient.rvec.z = (fix)INTEL_INT((int)pd->obj_orient.rvec.z);
5304 pd->obj_orient.uvec.x = (fix)INTEL_INT((int)pd->obj_orient.uvec.x);
5305 pd->obj_orient.uvec.y = (fix)INTEL_INT((int)pd->obj_orient.uvec.y);
5306 pd->obj_orient.uvec.z = (fix)INTEL_INT((int)pd->obj_orient.uvec.z);
5307 pd->obj_orient.fvec.x = (fix)INTEL_INT((int)pd->obj_orient.fvec.x);
5308 pd->obj_orient.fvec.y = (fix)INTEL_INT((int)pd->obj_orient.fvec.y);
5309 pd->obj_orient.fvec.z = (fix)INTEL_INT((int)pd->obj_orient.fvec.z);
5311 pd->phys_velocity.x = (fix)INTEL_INT((int)pd->phys_velocity.x);
5312 pd->phys_velocity.y = (fix)INTEL_INT((int)pd->phys_velocity.y);
5313 pd->phys_velocity.z = (fix)INTEL_INT((int)pd->phys_velocity.z);
5315 pd->phys_rotvel.x = (fix)INTEL_INT((int)pd->phys_rotvel.x);
5316 pd->phys_rotvel.y = (fix)INTEL_INT((int)pd->phys_rotvel.y);
5317 pd->phys_rotvel.z = (fix)INTEL_INT((int)pd->phys_rotvel.z);
5319 pd->obj_segnum = INTEL_SHORT(pd->obj_segnum);
5320 pd->data_size = INTEL_SHORT(pd->data_size);
5324 TheirPlayernum = pd->playernum;
5325 TheirObjnum = Players[pd->playernum].objnum;
5327 if (TheirPlayernum < 0) {
5328 Int3(); // This packet is bogus!!
5332 if (VerifyPlayerJoined!=-1 && TheirPlayernum==VerifyPlayerJoined)
5334 // Hurray! Someone really really got in the game (I think).
5335 mprintf ((0,"Hurray! VPJ (%d) reset!\n",VerifyPlayerJoined));
5336 VerifyPlayerJoined=-1;
5339 if (!multi_quit_game && (TheirPlayernum >= N_players)) {
5340 if (Network_status!=NETSTAT_WAITING)
5342 Int3(); // We missed an important packet!
5343 network_consistency_error();
5349 if (Endlevel_sequence || (Network_status == NETSTAT_ENDLEVEL) ) {
5350 int old_Endlevel_sequence = Endlevel_sequence;
5351 Endlevel_sequence = 1;
5352 if ( pd->data_size>0 ) {
5353 // pass pd->data to some parser function....
5354 multi_process_bigdata( pd->data, pd->data_size );
5356 Endlevel_sequence = old_Endlevel_sequence;
5359 // mprintf((0, "Gametime = %d, Frametime = %d.\n", GameTime, FrameTime));
5361 if ((sbyte)pd->level_num != Current_level_num)
5363 mprintf((0, "Got frame packet from player %d wrong level %d!\n", pd->playernum, pd->level_num));
5367 TheirObj = &Objects[TheirObjnum];
5369 //------------- Keep track of missed packets -----------------
5370 Players[TheirPlayernum].n_packets_got++;
5372 LastPacketTime[TheirPlayernum] = timer_get_approx_seconds();
5374 if ( pd->numpackets != Players[TheirPlayernum].n_packets_got ) {
5377 missed_packets = pd->numpackets-Players[TheirPlayernum].n_packets_got;
5378 if ((pd->numpackets-Players[TheirPlayernum].n_packets_got)>0)
5379 TotalMissedPackets += pd->numpackets-Players[TheirPlayernum].n_packets_got;
5381 if ( missed_packets > 0 )
5382 mprintf(( 0, "Missed %d packets from player #%d (%d total)\n", pd->numpackets-Players[TheirPlayernum].n_packets_got, TheirPlayernum, missed_packets ));
5384 mprintf( (0, "Got %d late packets from player #%d (%d total)\n", Players[TheirPlayernum].n_packets_got-pd->numpackets, TheirPlayernum, missed_packets ));
5387 #ifdef APPLETALK_DEBUG
5388 if (Network_game_type == APPLETALK_GAME) {
5389 if ( missed_packets > 0 )
5390 fprintf( at_fp, "Missed %d packets from player #%d (%d total)\n", pd->numpackets-Players[TheirPlayernum].n_packets_got, TheirPlayernum, missed_packets );
5392 fprintf( at_fp, "Got %d late packets from player #%d (%d total)\n", Players[TheirPlayernum].n_packets_got-pd->numpackets, TheirPlayernum, missed_packets );
5397 if (Network_game_type == IPX_GAME) {
5398 if ( missed_packets > 0 )
5399 fprintf( ipx_fp, "Missed %d packets from player #%d (%d total)\n", pd->numpackets-Players[TheirPlayernum].n_packets_got, TheirPlayernum, missed_packets );
5401 fprintf( ipx_fp, "Got %d late packets from player #%d (%d total)\n", Players[TheirPlayernum].n_packets_got-pd->numpackets, TheirPlayernum, missed_packets );
5406 Players[TheirPlayernum].n_packets_got = pd->numpackets;
5409 //------------ Read the player's ship's object info ----------------------
5410 TheirObj->pos = pd->obj_pos;
5411 TheirObj->orient = pd->obj_orient;
5412 TheirObj->mtype.phys_info.velocity = pd->phys_velocity;
5413 TheirObj->mtype.phys_info.rotvel = pd->phys_rotvel;
5415 if ((TheirObj->render_type != pd->obj_render_type) && (pd->obj_render_type == RT_POLYOBJ))
5416 multi_make_ghost_player(TheirPlayernum);
5418 obj_relink(TheirObjnum,pd->obj_segnum);
5420 if (TheirObj->movement_type == MT_PHYSICS)
5421 set_thrust_from_velocity(TheirObj);
5423 //------------ Welcome them back if reconnecting --------------
5424 if (!Players[TheirPlayernum].connected) {
5425 Players[TheirPlayernum].connected = 1;
5427 if (Newdemo_state == ND_STATE_RECORDING)
5428 newdemo_record_multi_reconnect(TheirPlayernum);
5430 multi_make_ghost_player(TheirPlayernum);
5432 create_player_appearance_effect(&Objects[TheirObjnum]);
5434 digi_play_sample( SOUND_HUD_MESSAGE, F1_0);
5436 ClipRank (&NetPlayers.players[TheirPlayernum].rank);
5438 if (FindArg("-norankings"))
5439 HUD_init_message( "'%s' %s", Players[TheirPlayernum].callsign, TXT_REJOIN );
5441 HUD_init_message( "%s'%s' %s", RankStrings[NetPlayers.players[TheirPlayernum].rank],Players[TheirPlayernum].callsign, TXT_REJOIN );
5447 //------------ Parse the extra data at the end ---------------
5449 if ( pd->data_size>0 ) {
5450 // pass pd->data to some parser function....
5451 multi_process_bigdata( pd->data, pd->data_size );
5456 #ifdef WORDS_BIGENDIAN
5457 void get_short_frame_info(ubyte *old_info, short_frame_info *new_info)
5461 new_info->type = old_info[loc]; loc++;
5462 /* skip three for pad byte */ loc += 3;
5463 memcpy(&(new_info->numpackets), &(old_info[loc]), 4); loc += 4;
5464 new_info->numpackets = INTEL_INT(new_info->numpackets);
5465 memcpy(new_info->thepos.bytemat, &(old_info[loc]), 9); loc += 9;
5466 memcpy(&(new_info->thepos.xo), &(old_info[loc]), 2); loc += 2;
5467 memcpy(&(new_info->thepos.yo), &(old_info[loc]), 2); loc += 2;
5468 memcpy(&(new_info->thepos.zo), &(old_info[loc]), 2); loc += 2;
5469 memcpy(&(new_info->thepos.segment), &(old_info[loc]), 2); loc += 2;
5470 memcpy(&(new_info->thepos.velx), &(old_info[loc]), 2); loc += 2;
5471 memcpy(&(new_info->thepos.vely), &(old_info[loc]), 2); loc += 2;
5472 memcpy(&(new_info->thepos.velz), &(old_info[loc]), 2); loc += 2;
5473 new_info->thepos.xo = INTEL_SHORT(new_info->thepos.xo);
5474 new_info->thepos.yo = INTEL_SHORT(new_info->thepos.yo);
5475 new_info->thepos.zo = INTEL_SHORT(new_info->thepos.zo);
5476 new_info->thepos.segment = INTEL_SHORT(new_info->thepos.segment);
5477 new_info->thepos.velx = INTEL_SHORT(new_info->thepos.velx);
5478 new_info->thepos.vely = INTEL_SHORT(new_info->thepos.vely);
5479 new_info->thepos.velz = INTEL_SHORT(new_info->thepos.velz);
5481 memcpy(&(new_info->data_size), &(old_info[loc]), 2); loc += 2;
5482 new_info->data_size = INTEL_SHORT(new_info->data_size);
5483 new_info->playernum = old_info[loc]; loc++;
5484 new_info->obj_render_type = old_info[loc]; loc++;
5485 new_info->level_num = old_info[loc]; loc++;
5486 memcpy(new_info->data, &(old_info[loc]), new_info->data_size);
5489 #define get_short_frame_info(old_info, new_info) \
5490 memcpy(new_info, old_info, sizeof(short_frame_info))
5493 void network_read_pdata_short_packet(short_frame_info *pd )
5497 object * TheirObj = NULL;
5498 short_frame_info new_pd;
5500 // short frame info is not aligned because of shortpos. The mac
5501 // will call totally hacked and gross function to fix this up.
5503 if (Network_game_type == IPX_GAME) {
5504 get_short_frame_info((ubyte *)pd, &new_pd);
5506 memcpy(&new_pd, (ubyte *)pd, sizeof(short_frame_info));
5509 TheirPlayernum = new_pd.playernum;
5510 TheirObjnum = Players[new_pd.playernum].objnum;
5512 if (TheirPlayernum < 0) {
5513 Int3(); // This packet is bogus!!
5516 if (!multi_quit_game && (TheirPlayernum >= N_players)) {
5517 if (Network_status!=NETSTAT_WAITING)
5519 Int3(); // We missed an important packet!
5520 network_consistency_error();
5527 if (VerifyPlayerJoined!=-1 && TheirPlayernum==VerifyPlayerJoined)
5529 // Hurray! Someone really really got in the game (I think).
5530 mprintf ((0,"Hurray! VPJ (%d) reset!\n",VerifyPlayerJoined));
5531 VerifyPlayerJoined=-1;
5534 if (Endlevel_sequence || (Network_status == NETSTAT_ENDLEVEL) ) {
5535 int old_Endlevel_sequence = Endlevel_sequence;
5536 Endlevel_sequence = 1;
5537 if ( new_pd.data_size>0 ) {
5538 // pass pd->data to some parser function....
5539 multi_process_bigdata( new_pd.data, new_pd.data_size );
5541 Endlevel_sequence = old_Endlevel_sequence;
5544 // mprintf((0, "Gametime = %d, Frametime = %d.\n", GameTime, FrameTime));
5546 if ((sbyte)new_pd.level_num != Current_level_num)
5548 mprintf((0, "Got frame packet from player %d wrong level %d!\n", new_pd.playernum, new_pd.level_num));
5552 TheirObj = &Objects[TheirObjnum];
5554 //------------- Keep track of missed packets -----------------
5555 Players[TheirPlayernum].n_packets_got++;
5557 LastPacketTime[TheirPlayernum] = timer_get_approx_seconds();
5559 if ( new_pd.numpackets != Players[TheirPlayernum].n_packets_got ) {
5562 missed_packets = new_pd.numpackets-Players[TheirPlayernum].n_packets_got;
5563 if ((new_pd.numpackets-Players[TheirPlayernum].n_packets_got)>0)
5564 TotalMissedPackets += new_pd.numpackets-Players[TheirPlayernum].n_packets_got;
5566 if ( missed_packets > 0 )
5567 mprintf( (0, "Missed %d packets from player #%d (%d total)\n", new_pd.numpackets-Players[TheirPlayernum].n_packets_got, TheirPlayernum, missed_packets ));
5569 mprintf( (0, "Got %d late packets from player #%d (%d total)\n", Players[TheirPlayernum].n_packets_got-new_pd.numpackets, TheirPlayernum, missed_packets ));
5571 Players[TheirPlayernum].n_packets_got = new_pd.numpackets;
5574 //------------ Read the player's ship's object info ----------------------
5576 extract_shortpos(TheirObj, &new_pd.thepos, 0);
5578 if ((TheirObj->render_type != new_pd.obj_render_type) && (new_pd.obj_render_type == RT_POLYOBJ))
5579 multi_make_ghost_player(TheirPlayernum);
5581 if (TheirObj->movement_type == MT_PHYSICS)
5582 set_thrust_from_velocity(TheirObj);
5584 //------------ Welcome them back if reconnecting --------------
5585 if (!Players[TheirPlayernum].connected) {
5586 Players[TheirPlayernum].connected = 1;
5588 if (Newdemo_state == ND_STATE_RECORDING)
5589 newdemo_record_multi_reconnect(TheirPlayernum);
5591 multi_make_ghost_player(TheirPlayernum);
5593 create_player_appearance_effect(&Objects[TheirObjnum]);
5595 digi_play_sample( SOUND_HUD_MESSAGE, F1_0);
5596 ClipRank (&NetPlayers.players[TheirPlayernum].rank);
5598 if (FindArg("-norankings"))
5599 HUD_init_message( "'%s' %s", Players[TheirPlayernum].callsign, TXT_REJOIN );
5601 HUD_init_message( "%s'%s' %s", RankStrings[NetPlayers.players[TheirPlayernum].rank],Players[TheirPlayernum].callsign, TXT_REJOIN );
5607 //------------ Parse the extra data at the end ---------------
5609 if ( new_pd.data_size>0 ) {
5610 // pass pd->data to some parser function....
5611 multi_process_bigdata( new_pd.data, new_pd.data_size );
5617 void network_set_power (void)
5619 int opt=0,choice,opt_primary,opt_second,opt_power;
5623 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Laser upgrade"; m[opt].value=Netgame.DoLaserUpgrade; opt++;
5624 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Super lasers"; m[opt].value=Netgame.DoSuperLaser; opt++;
5625 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Quad Lasers"; m[opt].value=Netgame.DoQuadLasers; opt++;
5626 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Vulcan cannon"; m[opt].value=Netgame.DoVulcan; opt++;
5627 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Spreadfire cannon"; m[opt].value=Netgame.DoSpread; opt++;
5628 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Plasma cannon"; m[opt].value=Netgame.DoPlasma; opt++;
5629 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Fusion cannon"; m[opt].value=Netgame.DoFusions; opt++;
5630 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Gauss cannon"; m[opt].value=Netgame.DoGauss; opt++;
5631 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Helix cannon"; m[opt].value=Netgame.DoHelix; opt++;
5632 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Phoenix cannon"; m[opt].value=Netgame.DoPhoenix; opt++;
5633 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Omega cannon"; m[opt].value=Netgame.DoOmega; opt++;
5636 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Homing Missiles"; m[opt].value=Netgame.DoHoming; opt++;
5637 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Proximity Bombs"; m[opt].value=Netgame.DoProximity; opt++;
5638 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Smart Missiles"; m[opt].value=Netgame.DoSmarts; opt++;
5639 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Mega Missiles"; m[opt].value=Netgame.DoMegas; opt++;
5640 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Flash Missiles"; m[opt].value=Netgame.DoFlash; opt++;
5641 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Guided Missiles"; m[opt].value=Netgame.DoGuided; opt++;
5642 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Smart Mines"; m[opt].value=Netgame.DoSmartMine; opt++;
5643 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Mercury Missiles"; m[opt].value=Netgame.DoMercury; opt++;
5644 m[opt].type = NM_TYPE_CHECK; m[opt].text = "EarthShaker Missiles"; m[opt].value=Netgame.DoEarthShaker; opt++;
5647 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Invulnerability"; m[opt].value=Netgame.DoInvulnerability; opt++;
5648 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Cloaking"; m[opt].value=Netgame.DoCloak; opt++;
5649 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Afterburners"; m[opt].value=Netgame.DoAfterburner; opt++;
5650 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Ammo rack"; m[opt].value=Netgame.DoAmmoRack; opt++;
5651 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Energy Converter"; m[opt].value=Netgame.DoConverter; opt++;
5652 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Headlight"; m[opt].value=Netgame.DoHeadlight; opt++;
5654 choice = newmenu_do(NULL, "Objects to allow", opt, m, NULL);
5656 Netgame.DoLaserUpgrade=m[opt_primary].value;
5657 Netgame.DoSuperLaser=m[opt_primary+1].value;
5658 Netgame.DoQuadLasers=m[opt_primary+2].value;
5659 Netgame.DoVulcan=m[opt_primary+3].value;
5660 Netgame.DoSpread=m[opt_primary+4].value;
5661 Netgame.DoPlasma=m[opt_primary+5].value;
5662 Netgame.DoFusions=m[opt_primary+6].value;
5663 Netgame.DoGauss=m[opt_primary+7].value;
5664 Netgame.DoHelix=m[opt_primary+8].value;
5665 Netgame.DoPhoenix=m[opt_primary+9].value;
5666 Netgame.DoOmega=m[opt_primary+10].value;
5668 Netgame.DoHoming=m[opt_second].value;
5669 Netgame.DoProximity=m[opt_second+1].value;
5670 Netgame.DoSmarts=m[opt_second+2].value;
5671 Netgame.DoMegas=m[opt_second+3].value;
5672 Netgame.DoFlash=m[opt_second+4].value;
5673 Netgame.DoGuided=m[opt_second+5].value;
5674 Netgame.DoSmartMine=m[opt_second+6].value;
5675 Netgame.DoMercury=m[opt_second+7].value;
5676 Netgame.DoEarthShaker=m[opt_second+8].value;
5678 Netgame.DoInvulnerability=m[opt_power].value;
5679 Netgame.DoCloak=m[opt_power+1].value;
5680 Netgame.DoAfterburner=m[opt_power+2].value;
5681 Netgame.DoAmmoRack=m[opt_power+3].value;
5682 Netgame.DoConverter=m[opt_power+4].value;
5683 Netgame.DoHeadlight=m[opt_power+5].value;
5687 void SetAllAllowablesTo (int on)
5689 last_cinvul = control_invul_time = 0; //default to zero
5691 Netgame.DoMegas=Netgame.DoSmarts=Netgame.DoFusions=Netgame.DoHelix=\
5692 Netgame.DoPhoenix=Netgame.DoCloak=Netgame.DoInvulnerability=\
5693 Netgame.DoAfterburner=Netgame.DoGauss=Netgame.DoVulcan=Netgame.DoPlasma=on;
5695 Netgame.DoOmega=Netgame.DoSuperLaser=Netgame.DoProximity=\
5696 Netgame.DoSpread=Netgame.DoMercury=Netgame.DoSmartMine=Netgame.DoFlash=\
5697 Netgame.DoGuided=Netgame.DoEarthShaker=on;
5699 Netgame.DoConverter=Netgame.DoAmmoRack=Netgame.DoHeadlight=on;
5700 Netgame.DoHoming=Netgame.DoLaserUpgrade=Netgame.DoQuadLasers=on;
5701 Netgame.BrightPlayers=Netgame.invul=on;
5707 // Jeez -- mac compiler can't handle all of these on the same decl line.
5708 int opt_setpower,opt_playtime,opt_killgoal,opt_socket,opt_marker_view,opt_light,opt_show_on_map;
5709 int opt_difficulty,opt_packets,opt_short_packets, opt_bright,opt_start_invul;
5712 void network_more_options_poll( int nitems, newmenu_item * menus, int * key, int citem );
5714 void network_more_game_options ()
5717 char PlayText[80],KillText[80],srinvul[50],socket_string[5],packstring[5];
5720 sprintf (socket_string,"%d",Network_socket);
5721 sprintf (packstring,"%d",Netgame.PacketsPerSec);
5723 opt_difficulty = opt;
5724 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++;
5727 sprintf( srinvul, "%s: %d %s", TXT_REACTOR_LIFE, control_invul_time*5, TXT_MINUTES_ABBREV );
5728 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++;
5731 sprintf( PlayText, "Max time: %d %s", Netgame.PlayTimeAllowed*5, TXT_MINUTES_ABBREV );
5732 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++;
5735 sprintf( KillText, "Kill Goal: %d kills", Netgame.KillGoal*5);
5736 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++;
5738 opt_start_invul=opt;
5739 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Invulnerable when reappearing"; m[opt].value=Netgame.invul; opt++;
5741 opt_marker_view = opt;
5742 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Allow camera views from Markers"; m[opt].value=Netgame.Allow_marker_view; opt++;
5744 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Indestructible lights"; m[opt].value=Netgame.AlwaysLighting; opt++;
5747 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Bright player ships"; m[opt].value=Netgame.BrightPlayers; opt++;
5750 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Show enemy names on HUD"; m[opt].value=Netgame.ShowAllNames; opt++;
5752 opt_show_on_map=opt;
5753 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++;
5755 opt_short_packets=opt;
5756 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Short packets"; m[opt].value=Netgame.ShortPackets; opt++;
5759 m[opt].type = NM_TYPE_MENU; m[opt].text = "Set Objects allowed..."; opt++;
5761 if (Network_game_type == IPX_GAME) {
5762 m[opt].type = NM_TYPE_TEXT; m[opt].text = "Network socket"; opt++;
5764 m[opt].type = NM_TYPE_INPUT; m[opt].text = socket_string; m[opt].text_len=4; opt++;
5767 m[opt].type = NM_TYPE_TEXT; m[opt].text = "Packets per second (2 - 20)"; opt++;
5769 m[opt].type = NM_TYPE_INPUT; m[opt].text=packstring; m[opt].text_len=2; opt++;
5771 LastKillGoal=Netgame.KillGoal;
5772 LastPTA=Netgame.PlayTimeAllowed;
5776 ExtGameStatus=GAMESTAT_MORE_NETGAME_OPTIONS;
5777 i = newmenu_do1( NULL, "Additional netgame options", opt, m, network_more_options_poll, 0 );
5779 //control_invul_time = atoi( srinvul )*60*F1_0;
5780 control_invul_time = m[opt_cinvul].value;
5781 Netgame.control_invul_time = control_invul_time*5*F1_0*60;
5783 if (i==opt_setpower)
5785 network_set_power ();
5789 Netgame.PacketsPerSec=atoi(packstring);
5791 if (Netgame.PacketsPerSec>20)
5793 Netgame.PacketsPerSec=20;
5794 nm_messagebox(TXT_ERROR, 1, TXT_OK, "Packet value out of range\nSetting value to 20");
5796 if (Netgame.PacketsPerSec<2)
5798 nm_messagebox(TXT_ERROR, 1, TXT_OK, "Packet value out of range\nSetting value to 2");
5799 Netgame.PacketsPerSec=2;
5802 mprintf ((0,"Hey! Sending out %d packets per second\n",Netgame.PacketsPerSec));
5804 if (Network_game_type == IPX_GAME) {
5805 if ((atoi(socket_string))!=Network_socket) {
5806 Network_socket=atoi(socket_string);
5807 ipx_change_default_socket( IPX_DEFAULT_SOCKET + Network_socket );
5811 Netgame.invul=m[opt_start_invul].value;
5812 Netgame.BrightPlayers=m[opt_bright].value;
5813 Netgame.ShortPackets=m[opt_short_packets].value;
5814 Netgame.ShowAllNames=m[opt_show_names].value;
5815 network_AdjustMaxDataSize();
5817 Netgame.Allow_marker_view=m[opt_marker_view].value;
5818 Netgame.AlwaysLighting=m[opt_light].value;
5819 netgame_difficulty=Difficulty_level = m[opt_difficulty].value;
5820 if (m[opt_show_on_map].value)
5821 Netgame.game_flags |= NETGAME_FLAG_SHOW_MAP;
5826 void network_more_options_poll( int nitems, newmenu_item * menus, int * key, int citem )
5829 citem = citem; // kills compile warnings
5833 if ( last_cinvul != menus[opt_cinvul].value ) {
5834 sprintf( menus[opt_cinvul].text, "%s: %d %s", TXT_REACTOR_LIFE, menus[opt_cinvul].value*5, TXT_MINUTES_ABBREV );
5835 last_cinvul = menus[opt_cinvul].value;
5836 menus[opt_cinvul].redraw = 1;
5839 if (menus[opt_playtime].value!=LastPTA)
5843 nm_messagebox ("Sorry",1,TXT_OK,"Registered version only!");
5844 menus[opt_playtime].value=0;
5845 menus[opt_playtime].redraw=1;
5849 if (Game_mode & GM_MULTI_COOP)
5852 nm_messagebox ("Sorry",1,TXT_OK,"You can't change those for coop!");
5853 menus[opt_playtime].value=0;
5854 menus[opt_playtime].redraw=1;
5858 Netgame.PlayTimeAllowed=menus[opt_playtime].value;
5859 sprintf( menus[opt_playtime].text, "Max Time: %d %s", Netgame.PlayTimeAllowed*5, TXT_MINUTES_ABBREV );
5860 LastPTA=Netgame.PlayTimeAllowed;
5861 menus[opt_playtime].redraw=1;
5863 if (menus[opt_killgoal].value!=LastKillGoal)
5866 nm_messagebox ("Sorry",1,TXT_OK,"Registered version only!");
5867 menus[opt_killgoal].value=0;
5868 menus[opt_killgoal].redraw=1;
5874 if (Game_mode & GM_MULTI_COOP)
5876 nm_messagebox ("Sorry",1,TXT_OK,"You can't change those for coop!");
5877 menus[opt_killgoal].value=0;
5878 menus[opt_killgoal].redraw=1;
5884 Netgame.KillGoal=menus[opt_killgoal].value;
5885 sprintf( menus[opt_killgoal].text, "Kill Goal: %d kills", Netgame.KillGoal*5);
5886 LastKillGoal=Netgame.KillGoal;
5887 menus[opt_killgoal].redraw=1;
5891 extern void multi_send_light (int,ubyte);
5892 extern void multi_send_light_specific (int,int,ubyte);
5894 void network_send_smash_lights (int pnum)
5896 // send the lights that have been blown out
5902 for (i=0;i<=Highest_segment_index;i++)
5903 if (Light_subtracted[i])
5904 multi_send_light_specific(pnum,i,Light_subtracted[i]);
5907 extern int Num_triggers;
5908 extern void multi_send_trigger_specific (char pnum,char);
5910 void network_send_fly_thru_triggers (int pnum)
5912 // send the fly thru triggers that have been disabled
5916 for (i=0;i<Num_triggers;i++)
5917 if (Triggers[i].flags & TF_DISABLED)
5918 multi_send_trigger_specific(pnum,i);
5921 void network_send_player_flags()
5925 for (i=0;i<N_players;i++)
5926 multi_send_flags(i);
5929 void network_ping (ubyte flag,int pnum)
5934 mybuf[1]=Player_num;
5936 if (Network_game_type == IPX_GAME)
5937 ipx_send_packet_data( (ubyte *)mybuf, 2, NetPlayers.players[pnum].network.ipx.server, NetPlayers.players[pnum].network.ipx.node,Players[pnum].net_address );
5940 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);
5944 extern fix PingLaunchTime,PingReturnTime;
5946 void network_handle_ping_return (ubyte pnum)
5948 if (PingLaunchTime==0 || pnum>=N_players)
5950 mprintf ((0,"Got invalid PING RETURN from %s!\n",Players[pnum].callsign));
5954 PingReturnTime=timer_get_fixed_seconds();
5956 HUD_init_message ("Ping time for %s is %d ms!",Players[pnum].callsign,
5957 f2i(fixmul(PingReturnTime-PingLaunchTime,i2f(1000))));
5961 void network_send_ping (ubyte pnum)
5963 network_ping (PID_PING_SEND,pnum);
5966 void DoRefuseStuff (sequence_packet *their)
5968 int i,new_player_num;
5970 ClipRank (&their->player.rank);
5972 for (i=0;i<MAX_PLAYERS;i++)
5973 if (!strcmp (their->player.callsign,Players[i].callsign))
5975 network_welcome_player(their);
5979 if (!WaitForRefuseAnswer)
5981 for (i=0;i<MAX_PLAYERS;i++)
5982 if (!strcmp (their->player.callsign,Players[i].callsign))
5984 network_welcome_player(their);
5988 digi_play_sample (SOUND_HUD_JOIN_REQUEST,F1_0*2);
5990 if (Game_mode & GM_TEAM)
5994 if (!FindArg("-norankings"))
5995 HUD_init_message ("%s %s wants to join",RankStrings[their->player.rank],their->player.callsign);
5997 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]);
5999 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]);
6001 // HUD_init_message ("Alt-1 to place on team %s!",Netgame.team_name[0]);
6002 // HUD_init_message ("Alt-2 to place on team %s!",Netgame.team_name[1]);
6005 HUD_init_message ("%s wants to join...press F6 to connect",their->player.callsign);
6007 strcpy (RefusePlayerName,their->player.callsign);
6008 RefuseTimeLimit=timer_get_approx_seconds();
6010 WaitForRefuseAnswer=1;
6014 for (i=0;i<MAX_PLAYERS;i++)
6015 if (!strcmp (their->player.callsign,Players[i].callsign))
6017 network_welcome_player(their);
6021 if (strcmp(their->player.callsign,RefusePlayerName))
6024 if (RefuseThisPlayer)
6028 WaitForRefuseAnswer=0;
6029 if (Game_mode & GM_TEAM)
6031 new_player_num=GetNewPlayerNumber (their);
6032 mprintf ((0,"Newplayernum=%d\n",new_player_num));
6034 Assert (RefuseTeam==1 || RefuseTeam==2);
6037 Netgame.team_vector &=(~(1<<new_player_num));
6039 Netgame.team_vector |=(1<<new_player_num);
6040 network_welcome_player(their);
6041 network_send_netgame_update ();
6044 network_welcome_player(their);
6048 if ((timer_get_approx_seconds()) > RefuseTimeLimit+REFUSE_INTERVAL)
6052 WaitForRefuseAnswer=0;
6053 if (!strcmp (their->player.callsign,RefusePlayerName)) {
6054 if (Network_game_type == IPX_GAME)
6055 network_dump_player(their->player.network.ipx.server,their->player.network.ipx.node, DUMP_DORK);
6058 network_dump_appletalk_player(their->player.network.appletalk.node,their->player.network.appletalk.net, their->player.network.appletalk.socket, DUMP_DORK);
6067 int GetNewPlayerNumber (sequence_packet *their)
6073 if ( N_players < MaxNumNetPlayers)
6078 // Slots are full but game is open, see if anyone is
6079 // disconnected and replace the oldest player with this new one
6081 int oldest_player = -1;
6082 fix oldest_time = timer_get_approx_seconds();
6084 Assert(N_players == MaxNumNetPlayers);
6086 for (i = 0; i < N_players; i++)
6088 if ( (!Players[i].connected) && (LastPacketTime[i] < oldest_time))
6090 oldest_time = LastPacketTime[i];
6094 return (oldest_player);
6098 void network_send_extras ()
6100 Assert (Player_joining_extras>-1);
6102 if (!network_i_am_master())
6104 mprintf ((0,"Hey! I'm not the master and I was gonna send info!\n"));
6106 // Network_sending_extras=0;
6111 if (Network_sending_extras==40)
6112 network_send_fly_thru_triggers(Player_joining_extras);
6113 if (Network_sending_extras==38)
6114 network_send_door_updates(Player_joining_extras);
6115 if (Network_sending_extras==35)
6116 network_send_markers();
6117 if (Network_sending_extras==30 && (Game_mode & GM_MULTI_ROBOTS))
6118 multi_send_stolen_items();
6119 if (Network_sending_extras==25 && (Netgame.PlayTimeAllowed || Netgame.KillGoal))
6120 multi_send_kill_goal_counts();
6121 if (Network_sending_extras==20)
6122 network_send_smash_lights(Player_joining_extras);
6123 if (Network_sending_extras==15)
6124 network_send_player_flags();
6125 if (Network_sending_extras==10)
6126 multi_send_powerup_update();
6127 // if (Network_sending_extras==5)
6128 // network_send_door_updates(Player_joining_extras); // twice!
6130 Network_sending_extras--;
6131 if (!Network_sending_extras)
6132 Player_joining_extras=-1;
6136 void network_send_naked_packet(char *buf, short len, int who)
6138 if (!(Game_mode&GM_NETWORK)) return;
6140 if (NakedPacketLen==0)
6142 NakedBuf[0]=PID_NAKED_PDATA;
6143 NakedBuf[1]=Player_num;
6147 if (len+NakedPacketLen>MaxXDataSize)
6149 // mprintf ((0,"Sending a naked packet of %d bytes.\n",NakedPacketLen));
6150 if (Network_game_type == IPX_GAME)
6151 ipx_send_packet_data( (ubyte *)NakedBuf, NakedPacketLen, NetPlayers.players[who].network.ipx.server, NetPlayers.players[who].network.ipx.node,Players[who].net_address );
6154 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 );
6157 memcpy (&NakedBuf[NakedPacketLen],buf,len);
6158 NakedPacketLen+=len;
6159 NakedPacketDestPlayer=who;
6163 memcpy (&NakedBuf[NakedPacketLen],buf,len);
6164 NakedPacketLen+=len;
6165 NakedPacketDestPlayer=who;
6170 void network_process_naked_pdata (char *data,int len)
6173 Assert (data[0]=PID_NAKED_PDATA);
6175 // mprintf ((0,"Processing a naked packet of %d length.\n",len));
6178 mprintf ((0,"Naked packet is bad!\n"));
6179 Int3(); // This packet is bogus!!
6183 if (!multi_quit_game && (pnum >= N_players)) {
6184 if (Network_status!=NETSTAT_WAITING)
6186 Int3(); // We missed an important packet!
6187 network_consistency_error();
6194 if (Endlevel_sequence || (Network_status == NETSTAT_ENDLEVEL) ) {
6195 int old_Endlevel_sequence = Endlevel_sequence;
6196 Endlevel_sequence = 1;
6197 multi_process_bigdata( data+2, len-2);
6198 Endlevel_sequence = old_Endlevel_sequence;
6202 multi_process_bigdata( data+2, len-2 );
6205 int ConnectionPacketLevel[]={0,1,1,1};
6206 int ConnectionSecLevel[]={12,3,5,7};
6208 int AppletalkConnectionPacketLevel[]={0,1,0};
6209 int AppletalkConnectionSecLevel[]={10,3,8};
6211 #if defined(RELEASE) && !defined(MACINTOSH) // use the code below for mac appletalk games
6212 int network_choose_connect ()
6217 int network_choose_connect ()
6224 if (Network_game_type == IPX_GAME) {
6226 m[opt].type = NM_TYPE_MENU; m[opt].text = "Local Subnet"; opt++;
6227 m[opt].type = NM_TYPE_MENU; m[opt].text = "14.4 modem over Internet"; opt++;
6228 m[opt].type = NM_TYPE_MENU; m[opt].text = "28.8 modem over Internet"; opt++;
6229 m[opt].type = NM_TYPE_MENU; m[opt].text = "ISDN or T1 over Internet"; opt++;
6231 choice = newmenu_do1( NULL, "Choose connection type", opt, m, NULL, 0 );
6236 Assert (choice>=0 && choice<=3);
6238 Netgame.ShortPackets=ConnectionPacketLevel[choice];
6239 Netgame.PacketsPerSec=ConnectionSecLevel[choice];
6244 m[opt].type = NM_TYPE_MENU; m[opt].text = "EtherTalk"; opt++;
6245 m[opt].type = NM_TYPE_MENU; m[opt].text = "LocalTalk"; opt++;
6246 m[opt].type = NM_TYPE_MENU; m[opt].text = "Other"; opt++;
6248 choice = newmenu_do1( NULL, "Choose connection type", opt, m, NULL, 0 );
6253 Network_appletalk_type = choice;
6255 Assert (choice>=0 && choice<=2);
6257 Netgame.ShortPackets=AppletalkConnectionPacketLevel[choice];
6258 Netgame.PacketsPerSec=AppletalkConnectionSecLevel[choice];
6272 SendLogFile=(FILE *)fopen ("sendlog.net","w");
6276 void OpenRecieveLog ()
6279 RecieveLogFile=(FILE *)fopen ("recvlog.net","w");
6285 int GetMyNetRanking ()
6290 if (Netlife_kills+Netlife_killed==0)
6293 rank=(int) (((float)Netlife_kills/3000.0)*8.0);
6295 eff=(int)((float)((float)Netlife_kills/((float)Netlife_killed+(float)Netlife_kills))*100.0);
6304 rank-=((59-eff)/10);
6311 mprintf ((0,"Rank is %d (%s)\n",rank+1,RankStrings[rank+1]));
6315 void ClipRank (signed char *rank)
6317 // This function insures no crashes when dealing with D2 1.0
6320 if (*rank<0 || *rank>9)
6323 void network_check_for_old_version (char pnum)
6325 if (NetPlayers.players[(int)pnum].version_major==1 && (NetPlayers.players[(int)pnum].version_minor & 0x0F)==0)
6326 NetPlayers.players[(int)pnum].rank=0;
6329 void network_request_player_names (int n)
6331 network_send_all_info_request (PID_GAME_PLAYERS,Active_games[n].Security);
6332 NamesInfoSecurity=Active_games[n].Security;
6335 extern char already_showing_info;
6336 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));
6338 void network_process_names_return (char *data)
6341 char mtext[15][50],temp[50];
6342 int i,t,l,gnum,num=0,count=5,numplayers;
6344 if (NamesInfoSecurity!=(*(int *)(data+1)))
6346 mprintf ((0,"Bad security on names return!\n"));
6347 mprintf ((0,"NIS=%d data=%d\n",NamesInfoSecurity,(*(int *)(data+1))));
6351 numplayers=data[count]; count++;
6353 if (numplayers==255)
6356 NamesInfoSecurity=-1;
6357 nm_messagebox(NULL, 1, "OK", "That game is refusing\nname requests.\n");
6362 Assert (numplayers>0 && numplayers<MAX_NUM_NET_PLAYERS);
6366 m[i].text=(char *)&mtext[i];
6367 m[i].type=NM_TYPE_TEXT;
6370 for (gnum=-1,i=0;i<num_active_games;i++)
6372 if (NamesInfoSecurity==Active_games[i].Security)
6382 NamesInfoSecurity=-1;
6383 nm_messagebox(NULL, 1, "OK", "The game you have requested\nnames from is gone.\n");
6388 sprintf (mtext[num],"Players of game '%s':",Active_games[gnum].game_name); num++;
6389 for (i=0;i<numplayers;i++)
6393 mprintf ((0,"%s\n",data+count));
6395 for (t=0;t<CALLSIGN_LEN+1;t++)
6396 temp[t]=data[count++];
6397 if (FindArg("-norankings"))
6398 sprintf (mtext[num],"%s",temp);
6400 sprintf (mtext[num],"%s%s",RankStrings[l],temp);
6405 if (data[count]==99)
6407 sprintf (mtext[num++]," ");
6408 sprintf (mtext[num++],"Short packets: %s",data[count+1]?"On":"Off");
6409 sprintf (mtext[num++],"Packets Per Second: %d",data[count+2]);
6412 already_showing_info=1;
6413 newmenu_dotiny2( NULL, NULL, num, m, NULL);
6414 already_showing_info=0;
6417 char NameReturning=1;
6419 void network_send_player_names (sequence_packet *their)
6421 int numconnected=0,count=0,i,t;
6426 mprintf ((0,"Got a player name without a return address! Get Jason\n"));
6430 buf[0]=PID_NAMES_RETURN; count++;
6431 (*(int *)(buf+1))=Netgame.Security; count+=4;
6435 buf[count]=255; count++;
6439 mprintf ((0,"RealSec=%d DS=%d\n",Netgame.Security,*(int *)(buf+1)));
6441 for (i=0;i<N_players;i++)
6442 if (Players[i].connected)
6445 buf[count]=numconnected; count++;
6446 for (i=0;i<N_players;i++)
6447 if (Players[i].connected)
6449 buf[count++]=NetPlayers.players[i].rank;
6451 for (t=0;t<CALLSIGN_LEN+1;t++)
6453 buf[count]=NetPlayers.players[i].callsign[t];
6459 buf[count++]=Netgame.ShortPackets;
6460 buf[count++]=Netgame.PacketsPerSec;
6463 ; // empty statement allows compilation on mac which does not have the
6464 // statement below and kills the compiler when there is no
6465 // statement following the label "sendit"
6468 ipx_send_internetwork_packet_data((ubyte *)buf, count, their->player.network.ipx.server, their->player.network.ipx.node);
6475 static int checked=-1;
6483 if (cfexist("hoard.ham"))