1 /* $Id: network.c,v 1.19 2003-07-25 05:08:08 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.
20 static char rcsid[] = "$Id: network.c,v 1.19 2003-07-25 05:08:08 btb Exp $";
73 #include <Errors.h> // for appletalk networking errors
77 #define LHX(x) ((x)*(MenuHires?2:1))
78 #define LHY(y) ((y)*(MenuHires?2.4:1))
80 /* the following are the possible packet identificators.
81 * they are stored in the "type" field of the packet structs.
82 * they are offset 4 bytes from the beginning of the raw IPX data
83 * because of the "driver's" ipx_packetnum (see linuxnet.c).
85 #define PID_LITE_INFO 43 // 0x2B lite game info
86 #define PID_SEND_ALL_GAMEINFO 44 // 0x2C plz send more than lite only
87 #define PID_PLAYERSINFO 45 // 0x2D here's my name & personal data
88 #define PID_REQUEST 46 // 0x2E may i join, plz send sync
89 #define PID_SYNC 47 // 0x2F master says: enter mine now!
90 #define PID_PDATA 48 // 0x30
91 #define PID_ADDPLAYER 49
93 #define PID_DUMP 51 // 0x33 you can't join this game
94 #define PID_ENDLEVEL 52
96 #define PID_QUIT_JOINING 54
97 #define PID_OBJECT_DATA 55 // array of bots, players, powerups, ...
98 #define PID_GAME_LIST 56 // 0x38 give me the list of your games
99 #define PID_GAME_INFO 57 // 0x39 here's a game i've started
100 #define PID_PING_SEND 58
101 #define PID_PING_RETURN 59
102 #define PID_GAME_UPDATE 60 // inform about new player/team change
103 #define PID_ENDLEVEL_SHORT 61
104 #define PID_NAKED_PDATA 62
105 #define PID_GAME_PLAYERS 63
106 #define PID_NAMES_RETURN 64 // 0x40
109 #define NETGAME_ANARCHY 0
110 #define NETGAME_TEAM_ANARCHY 1
111 #define NETGAME_ROBOT_ANARCHY 2
112 #define NETGAME_COOPERATIVE 3
113 #define NETGAME_CAPTURE_FLAG 4
114 #define NETGAME_HOARD 5
115 #define NETGAME_TEAM_HOARD 6
117 /* The following are values for NetSecurityFlag */
118 #define NETSECURITY_OFF 0
119 #define NETSECURITY_WAIT_FOR_PLAYERS 1
120 #define NETSECURITY_WAIT_FOR_GAMEINFO 2
121 #define NETSECURITY_WAIT_FOR_SYNC 3
122 /* The NetSecurityNum and the "Security" field of the network structs
123 * identifies a netgame. It is a random number chosen by the network master
124 * (the one that did "start netgame").
127 // MWA -- these structures are aligned -- please save me sanity and
128 // headaches by keeping alignment if these are changed!!!! Contact
131 typedef struct endlevel_info {
136 short kill_matrix[MAX_PLAYERS][MAX_PLAYERS];
141 typedef struct endlevel_info_short {
146 } endlevel_info_short;
148 // WARNING!!! This is the top part of netgame_info...if that struct changes,
149 // this struct much change as well. ie...they are aligned and the join system will
150 // not work without it.
152 // MWA if this structure changes -- please make appropriate changes to receive_netgame_info
153 // code for macintosh in netmisc.c
155 typedef struct lite_info {
158 char game_name[NETGAME_NAME_LEN+1];
159 char mission_title[MISSION_NAME_LEN+1];
160 char mission_name[9];
167 ubyte max_numplayers;
170 ubyte protocol_version;
174 } __pack__ lite_info;
176 // IF YOU CHANGE THE SIZE OF ANY OF THE FOLLOWING STRUCTURES
177 // MAKE THE MACINTOSH DEFINES BE THE SAME SIZE AS THE PC OR
178 // I WILL HAVE TO HURT YOU VERY BADLY!!! -- MWA
181 #define NETGAME_INFO_SIZE ( Network_game_type == IPX_GAME?355:sizeof(netgame_info) )
182 #define ALLNETPLAYERSINFO_SIZE ( Network_game_type == IPX_GAME?317:sizeof(AllNetPlayers_info) )
183 #define LITE_INFO_SIZE ( Network_game_type == IPX_GAME?72:sizeof(lite_info) )
184 #define SEQUENCE_PACKET_SIZE ( Network_game_type == IPX_GAME?34:sizeof(sequence_packet) )
185 #define FRAME_INFO_SIZE ( Network_game_type == IPX_GAME?541:sizeof(frame_info) )
186 #define IPX_SHORT_INFO_SIZE ( 490 )
188 #define NETGAME_INFO_SIZE sizeof(netgame_info)
189 #define ALLNETPLAYERSINFO_SIZE sizeof(AllNetPlayers_info)
190 #define LITE_INFO_SIZE sizeof(lite_info)
191 #define SEQUENCE_PACKET_SIZE sizeof(sequence_packet)
192 #define FRAME_INFO_SIZE sizeof(frame_info)
193 #define IPX_SHORT_INFO_SIZE sizeof(short_frame_info)
196 #define MAX_ACTIVE_NETGAMES 12
198 netgame_info Active_games[MAX_ACTIVE_NETGAMES];
199 AllNetPlayers_info ActiveNetPlayers[MAX_ACTIVE_NETGAMES];
200 AllNetPlayers_info *TempPlayersInfo,TempPlayersBase;
201 int NamesInfoSecurity=-1;
203 // MWAnetgame_info *TempNetInfo;
204 netgame_info TempNetInfo;
206 extern void multi_send_drop_marker (int player,vms_vector position,char messagenum,char text[]);
207 extern void multi_send_kill_goal_counts();
208 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) );
210 void network_process_naked_pdata (char *,int);
211 extern void multi_send_robot_controls(char);
213 void network_flush();
214 void network_listen();
215 void network_update_netgame();
216 void network_check_for_old_version(char pnum);
217 void network_send_objects();
218 void network_send_rejoin_sync(int player_num);
219 void network_send_game_info(sequence_packet *their);
220 void network_send_endlevel_short_sub(int from_player_num, int to_player);
221 void network_read_sync_packet(netgame_info * sp, int rsinit);
222 int network_wait_for_playerinfo();
223 void network_process_pdata(char *data);
224 void network_read_object_packet(ubyte *data );
225 void network_read_endlevel_packet(ubyte *data );
226 void network_read_endlevel_short_packet(ubyte *data );
227 void network_ping(ubyte flat, int pnum);
228 void network_handle_ping_return(ubyte pnum);
229 void network_process_names_return(char *data);
230 void network_send_player_names(sequence_packet *their);
231 int network_choose_connect();
232 void network_more_game_options();
233 void network_count_powerups_in_mine();
234 int network_wait_for_all_info(int choice);
235 void network_AdjustMaxDataSize();
236 void network_do_big_wait(int choice);
237 void network_send_extras();
238 void network_read_pdata_packet(frame_info *pd);
239 void network_read_pdata_short_packet(short_frame_info *pd);
241 void ClipRank(signed char *rank);
242 void DoRefuseStuff(sequence_packet *their);
243 int GetNewPlayerNumber(sequence_packet *their);
244 void SetAllAllowablesTo(int on);
246 int num_active_games = 0;
247 int PacketsPerSec=10;
248 int MaxXDataSize=NET_XDATA_SIZE;
250 int Netlife_kills=0, Netlife_killed=0;
253 int Network_active=0;
255 int Network_status = 0;
256 int Network_games_changed = 0;
258 int Network_socket = 0;
259 int Network_allow_socket_changes = 1;
261 int NetSecurityFlag=NETSECURITY_OFF;
262 int NetSecurityNum=0;
263 int Network_sending_extras=0;
264 int VerifyPlayerJoined=-1;
265 int Player_joining_extras=-1; // This is so we know who to send 'latecomer' packets to.
266 // We could just send updates to everyone but that kills the sender!
268 // For rejoin object syncing
270 int Network_rejoined = 0; // Did WE rejoin this game?
271 int Network_new_game = 0; // Is this the first level of a new game?
272 int Network_send_objects = 0; // Are we in the process of sending objects to a player?
273 int Network_send_objnum = -1; // What object are we sending next?
274 int Network_player_added = 0; // Is this a new player or a returning player?
275 int Network_send_object_mode = 0; // What type of objects are we sending, static or dynamic?
276 sequence_packet Network_player_rejoining; // Who is rejoining now?
278 fix LastPacketTime[MAX_PLAYERS]; // For timeouts of idle/crashed players
280 int PacketUrgent = 0;
282 int TotalMissedPackets=0,TotalPacketsGot=0;
284 frame_info MySyncPack,UrgentSyncPack;
285 ubyte MySyncPackInitialized = 0; // Set to 1 if the MySyncPack is zeroed.
286 ushort my_segments_checksum = 0;
288 sequence_packet My_Seq;
289 char WantPlayersInfo=0;
290 char WaitingForPlayerInfo=0;
292 char *RankStrings[]={"(unpatched) ","Cadet ","Ensign ","Lieutenant ","Lt.Commander ",
293 "Commander ","Captain ","Vice Admiral ","Admiral ","Demigod "};
295 extern obj_position Player_init[MAX_PLAYERS];
297 extern int force_cockpit_redraw;
299 // reasons for a packet with type PID_DUMP
300 #define DUMP_CLOSED 0 // no new players allowed after game started
301 #define DUMP_FULL 1 // player cound maxed out
302 #define DUMP_ENDLEVEL 2
304 #define DUMP_ABORTED 4
305 #define DUMP_CONNECTED 5 // never used
307 #define DUMP_KICKED 7 // never used
309 extern ubyte Version_major,Version_minor;
310 extern ubyte SurfingNet;
311 extern char MaxPowerupsAllowed[MAX_POWERUP_TYPES];
312 extern char PowerupsInMine[MAX_POWERUP_TYPES];
314 extern void multi_send_stolen_items();
316 int network_wait_for_snyc();
317 extern void multi_send_wall_status (int,ubyte,ubyte,ubyte);
318 extern void multi_send_wall_status_specific (int,int,ubyte,ubyte,ubyte);
320 extern void game_disable_cheats();
324 FILE *SendLogFile,*RecieveLogFile;
325 int TTSent[100],TTRecv[100];
328 extern int Final_boss_is_dead;
330 // following is network stuff for appletalk
332 void network_dump_appletalk_player(ubyte node, ushort net, ubyte socket, int why);
334 #define NETWORK_OEM 0x10
338 int Network_game_type; // used to tell IPX vs. appletalk games
340 #define MAX_ZONES 255
341 #define MAX_ZONE_LENGTH 33
342 #define DEFAULT_ZONE_NAME "\p*"
343 #define MAX_REGISTER_TRIES 5 // maximum time we will try and register a netgame
344 char Network_zone_name[MAX_ZONE_LENGTH]; // zone name game being played in for appletalk
345 char Zone_names[MAX_ZONES][MAX_ZONE_LENGTH]; // total list of zones that we can see
346 ubyte appletalk_use_broadcast = 0;
347 ubyte Network_game_validated = 0; // validates a game before being able to join
348 ubyte Network_game_validate_choice = 0;
349 ubyte Network_appletalk_type = 0; // type of appletalk network game is being played on
351 #define ETHERTALK_TYPE 0
352 #define LOCALTALK_TYPE 1
353 #define OTHERTALK_TYPE 2
356 void network_release_registered_game(void);
364 // So you want to play a netgame, eh? Let's a get a few things
368 int save_pnum = Player_num;
370 game_disable_cheats();
372 Final_boss_is_dead=0;
373 NamesInfoSecurity=-1;
381 for (t=0;t<MAX_POWERUP_TYPES;t++)
383 MaxPowerupsAllowed[t]=0;
387 TotalMissedPackets=0; TotalPacketsGot=0;
389 memset(&Netgame, 0, sizeof(netgame_info));
390 memset(&NetPlayers,0,sizeof(AllNetPlayers_info));
391 memset(&My_Seq, 0, sizeof(sequence_packet));
392 My_Seq.type = PID_REQUEST;
393 memcpy(My_Seq.player.callsign, Players[Player_num].callsign, CALLSIGN_LEN+1);
396 Version_minor|=NETWORK_OEM;
399 My_Seq.player.version_major=Version_major;
400 My_Seq.player.version_minor=Version_minor;
401 My_Seq.player.rank=GetMyNetRanking();
403 if (Network_game_type == IPX_GAME) {
404 memcpy(My_Seq.player.network.ipx.node, ipx_get_my_local_address(), 6);
405 memcpy(My_Seq.player.network.ipx.server, ipx_get_my_server_address(), 4 );
408 My_Seq.player.network.appletalk.node = appletalk_get_my_node();
409 My_Seq.player.network.appletalk.net = appletalk_get_my_net();
410 My_Seq.player.network.appletalk.socket = appletalk_get_my_socket();
414 My_Seq.player.computer_type = MAC;
416 My_Seq.player.computer_type = DOS;
419 for (Player_num = 0; Player_num < MAX_NUM_NET_PLAYERS; Player_num++)
420 init_player_stats_game();
422 Player_num = save_pnum;
424 Network_new_game = 1;
425 Control_center_destroyed = 0;
428 Netgame.PacketsPerSec=10;
430 if ((t=FindArg("-packets")))
432 Netgame.PacketsPerSec=atoi(Args[t+1]);
433 if (Netgame.PacketsPerSec<1)
434 Netgame.PacketsPerSec=1;
435 else if (Netgame.PacketsPerSec>20)
436 Netgame.PacketsPerSec=20;
437 mprintf ((0,"Will send %d packets per second",Netgame.PacketsPerSec));
439 if (FindArg("-shortpackets"))
441 Netgame.ShortPackets=1;
442 mprintf ((0,"Will send short packets.\n"));
447 network_i_am_master(void)
449 // I am the lowest numbered player in this game?
453 if (!(Game_mode & GM_NETWORK))
454 return (Player_num == 0);
456 for (i = 0; i < Player_num; i++)
457 if (Players[i].connected)
462 int network_who_is_master(void)
464 // Who is the master of this game?
468 if (!(Game_mode & GM_NETWORK))
469 return (Player_num == 0);
471 for (i = 0; i < N_players; i++)
472 if (Players[i].connected)
476 int network_how_many_connected()
480 for (i = 0; i < N_players; i++)
481 if (Players[i].connected)
486 #define ENDLEVEL_SEND_INTERVAL (F1_0*2)
487 #define ENDLEVEL_IDLE_TIME (F1_0*20)
490 network_endlevel_poll( int nitems, newmenu_item * menus, int * key, int citem )
492 // Polling loop for End-of-level menu
500 int previous_state[MAX_NUM_NET_PLAYERS];
501 int previous_seconds_left;
508 // Send our endlevel packet at regular intervals
510 if (timer_get_approx_seconds() > (t1+ENDLEVEL_SEND_INTERVAL))
512 network_send_endlevel_packet();
513 t1 = timer_get_approx_seconds();
516 for (i = 0; i < N_players; i++)
517 previous_state[i] = Players[i].connected;
519 previous_seconds_left = Countdown_seconds_left;
523 for (i = 0; i < N_players; i++)
525 if (Players[i].connected == 1)
527 // Check timeout for idle players
528 if (timer_get_approx_seconds() > LastPacketTime[i]+ENDLEVEL_IDLE_TIME)
530 mprintf((0, "idle timeout for player %d.\n", i));
531 Players[i].connected = 0;
532 network_send_endlevel_sub(i);
536 if ((Players[i].connected != 1) && (Players[i].connected != 5) && (Players[i].connected != 6))
538 if (Players[i].connected != 1)
540 if (Players[i].connected == 4)
544 if (num_escaped == N_players) // All players are out of the mine
546 Countdown_seconds_left = -1;
550 if (num_ready == N_players) // All players have checked in or are disconnected
560 network_endlevel_poll2( int nitems, newmenu_item * menus, int * key, int citem )
562 // Polling loop for End-of-level menu
574 // Send our endlevel packet at regular intervals
576 if (timer_get_approx_seconds() > (t1+ENDLEVEL_SEND_INTERVAL))
578 network_send_endlevel_packet();
579 t1 = timer_get_approx_seconds();
582 // mprintf ((0,"Trying to listen!\n"));
585 for (i = 0; i < N_players; i++)
587 if ((Players[i].connected != 1) && (Players[i].connected != 5) && (Players[i].connected != 6))
589 if (Players[i].connected == 4)
593 if (num_ready == N_players) // All players have checked in or are disconnected
603 extern fix StartAbortMenuTime;
606 network_endlevel_poll3( int nitems, newmenu_item * menus, int * key, int citem )
608 // Polling loop for End-of-level menu
617 if (timer_get_approx_seconds() > (StartAbortMenuTime+(F1_0 * 8)))
624 for (i = 0; i < N_players; i++)
625 if ((Players[i].connected != 1) && (Players[i].connected != 5) && (Players[i].connected != 6))
628 if (num_ready == N_players) // All players have checked in or are disconnected
635 network_endlevel(int *secret)
637 // Do whatever needs to be done between levels
645 Network_status = NETSTAT_ENDLEVEL; // We are between levels
649 network_send_endlevel_packet();
651 for (i=0; i<N_players; i++)
653 LastPacketTime[i] = timer_get_approx_seconds();
656 network_send_endlevel_packet();
657 network_send_endlevel_packet();
658 MySyncPackInitialized = 0;
660 network_update_netgame();
666 can_join_netgame(netgame_info *game,AllNetPlayers_info *people)
668 // Can this player rejoin a netgame in progress?
672 if (game->game_status == NETSTAT_STARTING)
675 if (game->game_status != NETSTAT_PLAYING)
677 mprintf ((0,"Error: Can't join because game_status !=NETSTAT_PLAYING\n"));
681 if (game->version_major==0 && Version_major>0)
683 mprintf ((0,"Error:Can't join because version majors don't match!\n"));
687 if (game->version_major>0 && Version_major==0)
689 mprintf ((0,"Error:Can't join because version majors2 don't match!\n"));
693 // Game is in progress, figure out if this guy can re-join it
695 num_players = game->numplayers;
697 if (!(game->game_flags & NETGAME_FLAG_CLOSED)) {
698 // Look for player that is not connected
700 if (game->numconnected==game->max_numplayers)
703 // mprintf ((0,"Refuse = %d\n",game->RefusePlayers));
705 if (game->RefusePlayers)
708 if (game->numplayers < game->max_numplayers)
711 if (game->numconnected<num_players)
718 mprintf ((0,"Error! Can't join because people==NULL!\n"));
722 // Search to see if we were already in this closed netgame in progress
724 for (i = 0; i < num_players; i++) {
725 if (Network_game_type == IPX_GAME) {
726 if ( (!stricmp(Players[Player_num].callsign, people->players[i].callsign)) &&
727 (!memcmp(My_Seq.player.network.ipx.node, people->players[i].network.ipx.node, 6)) &&
728 (!memcmp(My_Seq.player.network.ipx.server, people->players[i].network.ipx.server, 4)) )
731 if ( (!stricmp(Players[Player_num].callsign, people->players[i].callsign)) &&
732 (My_Seq.player.network.appletalk.node == people->players[i].network.appletalk.node) &&
733 (My_Seq.player.network.appletalk.net == people->players[i].network.appletalk.net) )
738 if (i != num_players)
741 mprintf ((0,"Error: Can't join because at end of list!\n"));
746 network_disconnect_player(int playernum)
748 // A player has disconnected from the net game, take whatever steps are
751 if (playernum == Player_num)
753 Int3(); // Weird, see Rob
757 Players[playernum].connected = 0;
758 NetPlayers.players[playernum].connected = 0;
759 if (VerifyPlayerJoined==playernum)
760 VerifyPlayerJoined=-1;
762 // create_player_appearance_effect(&Objects[Players[playernum].objnum]);
763 multi_make_player_ghost(playernum);
765 if (Newdemo_state == ND_STATE_RECORDING)
766 newdemo_record_multi_disconnect(playernum);
768 multi_strip_robots(playernum);
772 network_new_player(sequence_packet *their)
777 pnum = their->player.connected;
780 Assert(pnum < MaxNumNetPlayers);
782 objnum = Players[pnum].objnum;
784 if (Newdemo_state == ND_STATE_RECORDING) {
787 if (pnum == N_players)
791 newdemo_record_multi_connect(pnum, new_player, their->player.callsign);
794 memcpy(Players[pnum].callsign, their->player.callsign, CALLSIGN_LEN+1);
795 memcpy(NetPlayers.players[pnum].callsign, their->player.callsign, CALLSIGN_LEN+1);
798 ClipRank (&their->player.rank);
799 NetPlayers.players[pnum].rank=their->player.rank;
800 NetPlayers.players[pnum].version_major=their->player.version_major;
801 NetPlayers.players[pnum].version_minor=their->player.version_minor;
802 network_check_for_old_version(pnum);
804 if (Network_game_type == IPX_GAME) {
805 if ( (*(uint *)their->player.network.ipx.server) != 0 )
806 ipx_get_local_target( their->player.network.ipx.server, their->player.network.ipx.node, Players[pnum].net_address );
808 memcpy(Players[pnum].net_address, their->player.network.ipx.node, 6);
810 memcpy(NetPlayers.players[pnum].network.ipx.node, their->player.network.ipx.node, 6);
811 memcpy(NetPlayers.players[pnum].network.ipx.server, their->player.network.ipx.server, 4);
813 NetPlayers.players[pnum].network.appletalk.node = their->player.network.appletalk.node;
814 NetPlayers.players[pnum].network.appletalk.net = their->player.network.appletalk.net;
815 NetPlayers.players[pnum].network.appletalk.socket = their->player.network.appletalk.socket;
818 Players[pnum].n_packets_got = 0;
819 Players[pnum].connected = 1;
820 Players[pnum].net_kills_total = 0;
821 Players[pnum].net_killed_total = 0;
822 memset(kill_matrix[pnum], 0, MAX_PLAYERS*sizeof(short));
823 Players[pnum].score = 0;
824 Players[pnum].flags = 0;
825 Players[pnum].KillGoalCount=0;
827 if (pnum == N_players)
830 Netgame.numplayers = N_players;
833 digi_play_sample(SOUND_HUD_MESSAGE, F1_0);
835 ClipRank (&their->player.rank);
837 if (FindArg("-norankings"))
838 HUD_init_message("'%s' %s\n",their->player.callsign, TXT_JOINING);
840 HUD_init_message("%s'%s' %s\n",RankStrings[their->player.rank],their->player.callsign, TXT_JOINING);
842 multi_make_ghost_player(pnum);
845 multi_sort_kill_list();
847 // create_player_appearance_effect(&Objects[objnum]);
850 char RefuseThisPlayer=0,WaitForRefuseAnswer=0,RefuseTeam;
851 char RefusePlayerName[12];
852 fix RefuseTimeLimit=0;
854 void network_welcome_player(sequence_packet *their)
856 // Add a player to a game already in progress
857 ubyte local_address[6];
861 WaitForRefuseAnswer=0;
863 if (FindArg("-NoMatrixCheat"))
865 if ((their->player.version_minor & 0x0F) < 3)
867 network_dump_player(their->player.network.ipx.server, their->player.network.ipx.node, DUMP_DORK);
874 // If hoard game, and this guy isn't D2 Christmas (v1.2), dump him
876 if ((Game_mode & GM_HOARD) && ((their->player.version_minor & 0x0F)<2))
878 if (Network_game_type == IPX_GAME)
879 network_dump_player(their->player.network.ipx.server, their->player.network.ipx.node, DUMP_DORK);
882 network_dump_appletalk_player(their->player.network.appletalk.node, their->player.network.appletalk.net, their->player.network.appletalk.socket, DUMP_DORK);
888 // Don't accept new players if we're ending this level. Its safe to
889 // ignore since they'll request again later
891 if ((Endlevel_sequence) || (Control_center_destroyed))
893 mprintf((0, "Ignored request from new player to join during endgame.\n"));
894 if (Network_game_type == IPX_GAME)
895 network_dump_player(their->player.network.ipx.server,their->player.network.ipx.node, DUMP_ENDLEVEL);
898 network_dump_appletalk_player(their->player.network.appletalk.node, their->player.network.appletalk.net, their->player.network.appletalk.socket, DUMP_ENDLEVEL);
903 if (Network_send_objects || Network_sending_extras)
905 // Ignore silently, we're already responding to someone and we can't
906 // do more than one person at a time. If we don't dump them they will
907 // re-request in a few seconds.
911 if (their->player.connected != Current_level_num)
913 mprintf((0, "Dumping player due to old level number.\n"));
914 if (Network_game_type == IPX_GAME)
915 network_dump_player(their->player.network.ipx.server, their->player.network.ipx.node, DUMP_LEVEL);
918 network_dump_appletalk_player(their->player.network.appletalk.node, their->player.network.appletalk.net, their->player.network.appletalk.socket, DUMP_LEVEL);
924 memset(&Network_player_rejoining, 0, sizeof(sequence_packet));
925 Network_player_added = 0;
927 if (Network_game_type == IPX_GAME) {
928 if ( (*(uint *)their->player.network.ipx.server) != 0 )
929 ipx_get_local_target( their->player.network.ipx.server, their->player.network.ipx.node, local_address );
931 memcpy(local_address, their->player.network.ipx.node, 6);
934 for (i = 0; i < N_players; i++)
936 if ( (Network_game_type == IPX_GAME) && (!stricmp(Players[i].callsign, their->player.callsign )) && (!memcmp(Players[i].net_address,local_address, 6)) )
941 #ifdef MACINTOSH // note link to above if
942 else if ( (!stricmp(Players[i].callsign, their->player.callsign)) &&
943 (NetPlayers.players[i].network.appletalk.node == their->player.network.appletalk.node) &&
944 (NetPlayers.players[i].network.appletalk.net == their->player.network.appletalk.net)) {
951 if (player_num == -1)
953 // Player is new to this game
955 if ( !(Netgame.game_flags & NETGAME_FLAG_CLOSED) && (N_players < MaxNumNetPlayers))
957 // Add player in an open slot, game not full yet
959 player_num = N_players;
960 Network_player_added = 1;
962 else if (Netgame.game_flags & NETGAME_FLAG_CLOSED)
964 // Slots are open but game is closed
966 if (Network_game_type == IPX_GAME)
967 network_dump_player(their->player.network.ipx.server, their->player.network.ipx.node, DUMP_CLOSED);
970 network_dump_appletalk_player(their->player.network.appletalk.node, their->player.network.appletalk.net, their->player.network.appletalk.socket, DUMP_CLOSED);
976 // Slots are full but game is open, see if anyone is
977 // disconnected and replace the oldest player with this new one
979 int oldest_player = -1;
980 fix oldest_time = timer_get_approx_seconds();
982 Assert(N_players == MaxNumNetPlayers);
984 for (i = 0; i < N_players; i++)
986 if ( (!Players[i].connected) && (LastPacketTime[i] < oldest_time))
988 oldest_time = LastPacketTime[i];
993 if (oldest_player == -1)
995 // Everyone is still connected
997 if (Network_game_type == IPX_GAME)
998 network_dump_player(their->player.network.ipx.server, their->player.network.ipx.node, DUMP_FULL);
1001 network_dump_appletalk_player(their->player.network.appletalk.node, their->player.network.appletalk.net, their->player.network.appletalk.socket, DUMP_FULL);
1009 player_num = oldest_player;
1010 Network_player_added = 1;
1016 // Player is reconnecting
1018 if (Players[player_num].connected)
1020 mprintf((0, "Extra REQUEST from player ignored.\n"));
1024 if (Newdemo_state == ND_STATE_RECORDING)
1025 newdemo_record_multi_reconnect(player_num);
1027 Network_player_added = 0;
1029 digi_play_sample(SOUND_HUD_MESSAGE, F1_0);
1031 if (FindArg("-norankings"))
1032 HUD_init_message("'%s' %s", Players[player_num].callsign, TXT_REJOIN);
1034 HUD_init_message("%s'%s' %s", RankStrings[NetPlayers.players[player_num].rank],Players[player_num].callsign, TXT_REJOIN);
1037 Players[player_num].KillGoalCount=0;
1039 // Send updated Objects data to the new/returning player
1042 Network_player_rejoining = *their;
1043 Network_player_rejoining.player.connected = player_num;
1044 Network_send_objects = 1;
1045 Network_send_objnum = -1;
1047 network_send_objects();
1050 int network_objnum_is_past(int objnum)
1052 // determine whether or not a given object number has already been sent
1053 // to a re-joining player.
1055 int player_num = Network_player_rejoining.player.connected;
1056 int obj_mode = !((object_owner[objnum] == -1) || (object_owner[objnum] == player_num));
1058 if (!Network_send_objects)
1059 return 0; // We're not sending objects to a new player
1061 if (obj_mode > Network_send_object_mode)
1063 else if (obj_mode < Network_send_object_mode)
1065 else if (objnum < Network_send_objnum)
1071 #define OBJ_PACKETS_PER_FRAME 1
1072 extern void multi_send_active_door(char);
1073 extern void multi_send_door_open_specific(int,int,int,ubyte);
1076 void network_send_door_updates(int pnum)
1078 // Send door status when new player joins
1084 // Assert (pnum>-1 && pnum<N_players);
1086 for (i = 0; i < Num_walls; i++)
1088 if ((Walls[i].type == WALL_DOOR) && ((Walls[i].state == WALL_DOOR_OPENING) || (Walls[i].state == WALL_DOOR_WAITING) || (Walls[i].state == WALL_DOOR_OPEN)))
1089 multi_send_door_open_specific(pnum,Walls[i].segnum, Walls[i].sidenum,Walls[i].flags);
1090 else if ((Walls[i].type == WALL_BLASTABLE) && (Walls[i].flags & WALL_BLASTED))
1091 multi_send_door_open_specific(pnum,Walls[i].segnum, Walls[i].sidenum,Walls[i].flags);
1092 else if ((Walls[i].type == WALL_BLASTABLE) && (Walls[i].hps != WALL_HPS))
1093 multi_send_hostage_door_status(i);
1095 multi_send_wall_status_specific(pnum,i,Walls[i].type,Walls[i].flags,Walls[i].state);
1099 extern vms_vector MarkerPoint[];
1100 void network_send_markers()
1102 // send marker positions/text to new player
1109 if (MarkerObject[(i*2)]!=-1)
1110 multi_send_drop_marker (i,MarkerPoint[(i*2)],0,MarkerMessage[i*2]);
1111 if (MarkerObject[(i*2)+1]!=-1)
1112 multi_send_drop_marker (i,MarkerPoint[(i*2)+1],1,MarkerMessage[(i*2)+1]);
1116 void network_process_monitor_vector(int vector)
1122 for (i=0; i <= Highest_segment_index; i++)
1126 for (j = 0; j < 6; j++)
1128 if ( ((tm = seg->sides[j].tmap_num2) != 0) &&
1129 ((ec = TmapInfo[tm&0x3fff].eclip_num) != -1) &&
1130 ((bm = Effects[ec].dest_bm_num) != -1) )
1132 if (vector & (1 << count))
1134 seg->sides[j].tmap_num2 = bm | (tm&0xc000);
1135 // mprintf((0, "Monitor %d blown up.\n", count));
1138 // mprintf((0, "Monitor %d intact.\n", count));
1146 int network_create_monitor_vector(void)
1149 int num_blown_bitmaps = 0;
1150 int monitor_num = 0;
1151 #define NUM_BLOWN_BITMAPS 20
1152 int blown_bitmaps[NUM_BLOWN_BITMAPS];
1156 for (i=0; i < Num_effects; i++)
1158 if (Effects[i].dest_bm_num > 0) {
1159 for (j = 0; j < num_blown_bitmaps; j++)
1160 if (blown_bitmaps[j] == Effects[i].dest_bm_num)
1162 if (j == num_blown_bitmaps) {
1163 blown_bitmaps[num_blown_bitmaps++] = Effects[i].dest_bm_num;
1164 Assert(num_blown_bitmaps < NUM_BLOWN_BITMAPS);
1169 // for (i = 0; i < num_blown_bitmaps; i++)
1170 // mprintf((0, "Blown bitmap #%d = %d.\n", i, blown_bitmaps[i]));
1172 for (i=0; i <= Highest_segment_index; i++)
1176 for (j = 0; j < 6; j++)
1178 if ((tm = seg->sides[j].tmap_num2) != 0)
1180 if ( ((ec = TmapInfo[tm&0x3fff].eclip_num) != -1) &&
1181 (Effects[ec].dest_bm_num != -1) )
1183 // mprintf((0, "Monitor %d intact.\n", monitor_num));
1185 Assert(monitor_num < 32);
1189 for (k = 0; k < num_blown_bitmaps; k++)
1191 if ((tm&0x3fff) == blown_bitmaps[k])
1193 //mprintf((0, "Monitor %d destroyed.\n", monitor_num));
1194 vector |= (1 << monitor_num);
1196 Assert(monitor_num < 32);
1204 // mprintf((0, "Final monitor vector %x.\n", vector));
1208 void network_stop_resync(sequence_packet *their)
1210 if (Network_game_type == IPX_GAME) {
1211 if ( (!memcmp(Network_player_rejoining.player.network.ipx.node, their->player.network.ipx.node, 6)) &&
1212 (!memcmp(Network_player_rejoining.player.network.ipx.server, their->player.network.ipx.server, 4)) &&
1213 (!stricmp(Network_player_rejoining.player.callsign, their->player.callsign)) )
1215 mprintf((0, "Aborting resync for player %s.\n", their->player.callsign));
1216 Network_send_objects = 0;
1217 Network_sending_extras=0;
1219 Player_joining_extras=-1;
1220 Network_send_objnum = -1;
1223 if ( (Network_player_rejoining.player.network.appletalk.node == their->player.network.appletalk.node) &&
1224 (Network_player_rejoining.player.network.appletalk.net == their->player.network.appletalk.net) &&
1225 (!stricmp(Network_player_rejoining.player.callsign, their->player.callsign)) )
1227 mprintf((0, "Aborting resync for player %s.\n", their->player.callsign));
1228 Network_send_objects = 0;
1229 Network_sending_extras=0;
1231 Player_joining_extras=-1;
1232 Network_send_objnum = -1;
1237 byte object_buffer[IPX_MAX_DATA_SIZE];
1239 void network_send_objects(void)
1241 short remote_objnum;
1245 static int obj_count = 0;
1246 static int frame_num = 0;
1248 int obj_count_frame = 0;
1249 int player_num = Network_player_rejoining.player.connected;
1251 // Send clear objects array trigger and send player num
1253 Assert(Network_send_objects != 0);
1254 Assert(player_num >= 0);
1255 Assert(player_num < MaxNumNetPlayers);
1257 if (Endlevel_sequence || Control_center_destroyed)
1259 // Endlevel started before we finished sending the goods, we'll
1260 // have to stop and try again after the level.
1262 if (Network_game_type == IPX_GAME)
1263 network_dump_player(Network_player_rejoining.player.network.ipx.server,Network_player_rejoining.player.network.ipx.node, DUMP_ENDLEVEL);
1266 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);
1268 Network_send_objects = 0;
1272 for (h = 0; h < OBJ_PACKETS_PER_FRAME; h++) // Do more than 1 per frame, try to speed it up without
1273 // over-stressing the receiver.
1275 obj_count_frame = 0;
1276 memset(object_buffer, 0, IPX_MAX_DATA_SIZE);
1277 object_buffer[0] = PID_OBJECT_DATA;
1280 if (Network_send_objnum == -1)
1283 Network_send_object_mode = 0;
1284 // mprintf((0, "Sending object array to player %d.\n", player_num));
1285 *(short *)(object_buffer+loc) = INTEL_SHORT(-1); loc += 2;
1286 object_buffer[loc] = player_num; loc += 1;
1287 /* Placeholder for remote_objnum, not used here */ loc += 2;
1288 Network_send_objnum = 0;
1289 obj_count_frame = 1;
1293 for (i = Network_send_objnum; i <= Highest_object_index; i++)
1295 if ((Objects[i].type != OBJ_POWERUP) && (Objects[i].type != OBJ_PLAYER) &&
1296 (Objects[i].type != OBJ_CNTRLCEN) && (Objects[i].type != OBJ_GHOST) &&
1297 (Objects[i].type != OBJ_ROBOT) && (Objects[i].type != OBJ_HOSTAGE) &&
1298 !(Objects[i].type==OBJ_WEAPON && Objects[i].id==PMINE_ID))
1300 if ((Network_send_object_mode == 0) && ((object_owner[i] != -1) && (object_owner[i] != player_num)))
1302 if ((Network_send_object_mode == 1) && ((object_owner[i] == -1) || (object_owner[i] == player_num)))
1305 if ( ((IPX_MAX_DATA_SIZE-1) - loc) < (sizeof(object)+5) )
1306 break; // Not enough room for another object
1311 remote_objnum = objnum_local_to_remote((short)i, &owner);
1312 Assert(owner == object_owner[i]);
1314 *(short *)(object_buffer+loc) = INTEL_SHORT((short)i); loc += 2;
1315 object_buffer[loc] = owner; loc += 1;
1316 *(short *)(object_buffer+loc) = INTEL_SHORT(remote_objnum); loc += 2;
1317 memcpy(&object_buffer[loc], &Objects[i], sizeof(object));
1318 if (Network_game_type == IPX_GAME)
1319 swap_object((object *)&object_buffer[loc]);
1320 loc += sizeof(object);
1321 // mprintf((0, "..packing object %d, remote %d\n", i, remote_objnum));
1324 if (obj_count_frame) // Send any objects we've buffered
1328 Network_send_objnum = i;
1329 object_buffer[1] = obj_count_frame; object_buffer[2] = frame_num;
1330 // mprintf((0, "Object packet %d contains %d objects.\n", frame_num, obj_count_frame));
1332 Assert(loc <= IPX_MAX_DATA_SIZE);
1334 if (Network_game_type == IPX_GAME)
1335 ipx_send_internetwork_packet_data( object_buffer, loc, Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node );
1338 appletalk_send_packet_data( object_buffer, loc, Network_player_rejoining.player.network.appletalk.node,
1339 Network_player_rejoining.player.network.appletalk.net,
1340 Network_player_rejoining.player.network.appletalk.socket);
1343 // OLD ipx_send_packet_data(object_buffer, loc, &Network_player_rejoining.player.node);
1346 if (i > Highest_object_index)
1348 if (Network_send_object_mode == 0)
1350 Network_send_objnum = 0;
1351 Network_send_object_mode = 1; // go to next mode
1355 Assert(Network_send_object_mode == 1);
1358 // Send count so other side can make sure he got them all
1359 // mprintf((0, "Sending end marker in packet #%d.\n", frame_num));
1360 mprintf((0, "Sent %d objects.\n", obj_count));
1361 object_buffer[0] = PID_OBJECT_DATA;
1362 object_buffer[1] = 1;
1363 object_buffer[2] = frame_num;
1364 *(short *)(object_buffer+3) = INTEL_SHORT(-2);
1365 *(short *)(object_buffer+6) = INTEL_SHORT(obj_count);
1366 //OLD ipx_send_packet_data(object_buffer, 8, &Network_player_rejoining.player.node);
1367 if (Network_game_type == IPX_GAME)
1368 ipx_send_internetwork_packet_data(object_buffer, 8, Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node);
1371 appletalk_send_packet_data( object_buffer, 8, Network_player_rejoining.player.network.appletalk.node,
1372 Network_player_rejoining.player.network.appletalk.net,
1373 Network_player_rejoining.player.network.appletalk.socket);
1377 // Send sync packet which tells the player who he is and to start!
1378 network_send_rejoin_sync(player_num);
1379 mprintf ((0,"VerfiyPlayerJoined is now set to %d\n",player_num));
1380 VerifyPlayerJoined=player_num;
1382 // Turn off send object mode
1383 Network_send_objnum = -1;
1384 Network_send_objects = 0;
1387 //if (!network_i_am_master ())
1388 // Int3(); // Bad!! Get Jason. Someone goofy is trying to get ahold of the game!
1390 Network_sending_extras=40; // start to send extras
1391 Player_joining_extras=player_num;
1395 } // i > Highest_object_index
1396 } // For PACKETS_PER_FRAME
1399 extern void multi_send_powerup_update();
1401 void network_send_rejoin_sync(int player_num)
1405 Players[player_num].connected = 1; // connect the new guy
1406 LastPacketTime[player_num] = timer_get_approx_seconds();
1408 if (Endlevel_sequence || Control_center_destroyed)
1410 // Endlevel started before we finished sending the goods, we'll
1411 // have to stop and try again after the level.
1413 if (Network_game_type == IPX_GAME)
1414 network_dump_player(Network_player_rejoining.player.network.ipx.server,Network_player_rejoining.player.network.ipx.node, DUMP_ENDLEVEL);
1417 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);
1419 Network_send_objects = 0;
1420 Network_sending_extras=0;
1424 if (Network_player_added)
1426 Network_player_rejoining.type = PID_ADDPLAYER;
1427 Network_player_rejoining.player.connected = player_num;
1428 network_new_player(&Network_player_rejoining);
1430 for (i = 0; i < N_players; i++)
1432 if ((i != player_num) && (i != Player_num) && (Players[i].connected))
1433 if (Network_game_type == IPX_GAME) {
1434 send_sequence_packet( Network_player_rejoining, NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node, Players[i].net_address);
1437 appletalk_send_packet_data( (ubyte *)&Network_player_rejoining, sizeof(sequence_packet), NetPlayers.players[i].network.appletalk.node,
1438 NetPlayers.players[i].network.appletalk.net, NetPlayers.players[i].network.appletalk.socket);
1444 // Send sync packet to the new guy
1446 network_update_netgame();
1448 // Fill in the kill list
1449 for (j=0; j<MAX_PLAYERS; j++)
1451 for (i=0; i<MAX_PLAYERS;i++)
1452 Netgame.kills[j][i] = kill_matrix[j][i];
1453 Netgame.killed[j] = Players[j].net_killed_total;
1454 Netgame.player_kills[j] = Players[j].net_kills_total;
1455 Netgame.player_score[j] = Players[j].score;
1458 Netgame.level_time = Players[Player_num].time_level;
1459 Netgame.monitor_vector = network_create_monitor_vector();
1461 mprintf((0, "Sending rejoin sync packet!!!\n"));
1463 if (Network_game_type == IPX_GAME) {
1464 send_internetwork_full_netgame_packet(Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node);
1465 send_netplayers_packet(Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node);
1468 appletalk_send_packet_data( (ubyte *)&Netgame, sizeof(netgame_info), Network_player_rejoining.player.network.appletalk.node,
1469 Network_player_rejoining.player.network.appletalk.net,
1470 Network_player_rejoining.player.network.appletalk.socket);
1471 appletalk_send_packet_data( (ubyte *)&NetPlayers, sizeof(AllNetPlayers_info), Network_player_rejoining.player.network.appletalk.node,
1472 Network_player_rejoining.player.network.appletalk.net,
1473 Network_player_rejoining.player.network.appletalk.socket);
1478 void resend_sync_due_to_packet_loss_for_allender ()
1482 mprintf ((0,"I'm resending a sync packet! VPJ=%d\n",VerifyPlayerJoined));
1484 network_update_netgame();
1486 // Fill in the kill list
1487 for (j=0; j<MAX_PLAYERS; j++)
1489 for (i=0; i<MAX_PLAYERS;i++)
1490 Netgame.kills[j][i] = kill_matrix[j][i];
1491 Netgame.killed[j] = Players[j].net_killed_total;
1492 Netgame.player_kills[j] = Players[j].net_kills_total;
1493 Netgame.player_score[j] = Players[j].score;
1496 Netgame.level_time = Players[Player_num].time_level;
1497 Netgame.monitor_vector = network_create_monitor_vector();
1499 if (Network_game_type == IPX_GAME) {
1500 send_internetwork_full_netgame_packet(Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node);
1501 send_netplayers_packet(Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node);
1504 appletalk_send_packet_data( (ubyte *)&Netgame, sizeof(netgame_info), Network_player_rejoining.player.network.appletalk.node,
1505 Network_player_rejoining.player.network.appletalk.net,
1506 Network_player_rejoining.player.network.appletalk.socket);
1507 appletalk_send_packet_data( (ubyte *)&NetPlayers, sizeof(AllNetPlayers_info), Network_player_rejoining.player.network.appletalk.node,
1508 Network_player_rejoining.player.network.appletalk.net,
1509 Network_player_rejoining.player.network.appletalk.socket);
1515 char * network_get_player_name( int objnum )
1517 if ( objnum < 0 ) return NULL;
1518 if ( Objects[objnum].type != OBJ_PLAYER ) return NULL;
1519 if ( Objects[objnum].id >= MAX_PLAYERS ) return NULL;
1520 if ( Objects[objnum].id >= N_players ) return NULL;
1522 return Players[Objects[objnum].id].callsign;
1526 void network_add_player(sequence_packet *p)
1530 mprintf((0, "Got add player request!\n"));
1532 for (i=0; i<N_players; i++ ) {
1533 if (Network_game_type == IPX_GAME) {
1534 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))
1535 return; // already got them
1537 if ( (NetPlayers.players[i].network.appletalk.node == p->player.network.appletalk.node) &&
1538 (NetPlayers.players[i].network.appletalk.net == p->player.network.appletalk.net))
1543 if (Network_game_type == IPX_GAME) {
1544 memcpy( NetPlayers.players[N_players].network.ipx.node, p->player.network.ipx.node, 6 );
1545 memcpy( NetPlayers.players[N_players].network.ipx.server, p->player.network.ipx.server, 4 );
1547 NetPlayers.players[N_players].network.appletalk.node = p->player.network.appletalk.node;
1548 NetPlayers.players[N_players].network.appletalk.net = p->player.network.appletalk.net;
1549 NetPlayers.players[N_players].network.appletalk.socket = p->player.network.appletalk.socket;
1552 ClipRank (&p->player.rank);
1554 memcpy( NetPlayers.players[N_players].callsign, p->player.callsign, CALLSIGN_LEN+1 );
1555 NetPlayers.players[N_players].version_major=p->player.version_major;
1556 NetPlayers.players[N_players].version_minor=p->player.version_minor;
1557 NetPlayers.players[N_players].rank=p->player.rank;
1558 NetPlayers.players[N_players].connected = 1;
1559 network_check_for_old_version (N_players);
1561 Players[N_players].KillGoalCount=0;
1562 Players[N_players].connected = 1;
1563 LastPacketTime[N_players] = timer_get_approx_seconds();
1565 Netgame.numplayers = N_players;
1567 // Broadcast updated info
1569 mprintf ((0,"sending_game_info!\n"));
1570 network_send_game_info(NULL);
1573 // One of the players decided not to join the game
1575 void network_remove_player(sequence_packet *p)
1580 for (i=0; i<N_players; i++ ) {
1581 if (Network_game_type == IPX_GAME) {
1582 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)) {
1587 if ( (NetPlayers.players[i].network.appletalk.node == p->player.network.appletalk.node) && (NetPlayers.players[i].network.appletalk.net == p->player.network.appletalk.net) ) {
1594 if (pn < 0 ) return;
1596 for (i=pn; i<N_players-1; i++ ) {
1597 if (Network_game_type == IPX_GAME) {
1598 memcpy( NetPlayers.players[i].network.ipx.node, NetPlayers.players[i+1].network.ipx.node, 6 );
1599 memcpy( NetPlayers.players[i].network.ipx.server, NetPlayers.players[i+1].network.ipx.server, 4 );
1601 NetPlayers.players[i].network.appletalk.node = NetPlayers.players[i+1].network.appletalk.node;
1602 NetPlayers.players[i].network.appletalk.net = NetPlayers.players[i+1].network.appletalk.net;
1603 NetPlayers.players[i].network.appletalk.socket = NetPlayers.players[i+1].network.appletalk.socket;
1605 memcpy( NetPlayers.players[i].callsign, NetPlayers.players[i+1].callsign, CALLSIGN_LEN+1 );
1606 NetPlayers.players[i].version_major=NetPlayers.players[i+1].version_major;
1607 NetPlayers.players[i].version_minor=NetPlayers.players[i+1].version_minor;
1609 NetPlayers.players[i].rank=NetPlayers.players[i+1].rank;
1610 ClipRank (&NetPlayers.players[i].rank);
1611 network_check_for_old_version(i);
1615 Netgame.numplayers = N_players;
1617 // Broadcast new info
1619 network_send_game_info(NULL);
1624 network_dump_player(ubyte * server, ubyte *node, int why)
1626 // Inform player that he was not chosen for the netgame
1628 sequence_packet temp;
1630 temp.type = PID_DUMP;
1631 memcpy(temp.player.callsign, Players[Player_num].callsign, CALLSIGN_LEN+1);
1632 temp.player.connected = why;
1633 if (Network_game_type == IPX_GAME) {
1634 send_internetwork_sequence_packet(temp, server, node);
1641 void network_dump_appletalk_player(ubyte node, ushort net, ubyte socket, int why)
1643 sequence_packet temp;
1645 temp.type = PID_DUMP;
1646 memcpy(temp.player.callsign, Players[Player_num].callsign, CALLSIGN_LEN+1);
1647 temp.player.connected = why;
1648 if (Network_game_type == APPLETALK_GAME) {
1649 appletalk_send_packet_data( (ubyte *)&temp, sizeof(sequence_packet), node, net, socket );
1657 network_send_game_list_request()
1659 // Send a broadcast request for game info
1663 mprintf((0, "Sending game_list request.\n"));
1664 me.type = PID_GAME_LIST;
1665 memcpy( me.player.callsign, Players[Player_num].callsign, CALLSIGN_LEN+1 );
1667 if (Network_game_type == IPX_GAME) {
1668 memcpy( me.player.network.ipx.node, ipx_get_my_local_address(), 6 );
1669 memcpy( me.player.network.ipx.server, ipx_get_my_server_address(), 4 );
1671 send_broadcast_sequence_packet(me);
1674 me.player.network.appletalk.node = appletalk_get_my_node();
1675 me.player.network.appletalk.net = appletalk_get_my_net();
1676 me.player.network.appletalk.socket = appletalk_get_my_socket();
1677 appletalk_send_game_info( (ubyte *)&me, sizeof(sequence_packet), Network_zone_name );
1682 void network_send_all_info_request(char type,int which_security)
1684 // Send a broadcast request for game info
1688 mprintf((0, "Sending all_info request.\n"));
1690 me.Security=which_security;
1692 memcpy( me.player.callsign, Players[Player_num].callsign, CALLSIGN_LEN+1 );
1694 if (Network_game_type == IPX_GAME) {
1695 memcpy( me.player.network.ipx.node, ipx_get_my_local_address(), 6 );
1696 memcpy( me.player.network.ipx.server, ipx_get_my_server_address(), 4 );
1698 send_broadcast_sequence_packet(me);
1701 me.player.network.appletalk.node = appletalk_get_my_node();
1702 me.player.network.appletalk.net = appletalk_get_my_net();
1703 me.player.network.appletalk.socket = appletalk_get_my_socket();
1704 appletalk_send_game_info( (ubyte *)&me, sizeof(sequence_packet), Network_zone_name );
1711 network_update_netgame(void)
1713 // Update the netgame struct with current game variables
1717 Netgame.numconnected=0;
1718 for (i=0;i<N_players;i++)
1719 if (Players[i].connected)
1720 Netgame.numconnected++;
1722 // This is great: D2 1.0 and 1.1 ignore upper part of the game_flags field of
1723 // the lite_info struct when you're sitting on the join netgame screen. We can
1724 // "sneak" Hoard information into this field. This is better than sending
1725 // another packet that could be lost in transit.
1728 if (HoardEquipped())
1730 if (Game_mode & GM_HOARD)
1732 Netgame.game_flags |=NETGAME_FLAG_HOARD;
1733 if (Game_mode & GM_TEAM)
1734 Netgame.game_flags |=NETGAME_FLAG_TEAM_HOARD;
1738 if (Network_status == NETSTAT_STARTING)
1741 Netgame.numplayers = N_players;
1742 Netgame.game_status = Network_status;
1743 Netgame.max_numplayers = MaxNumNetPlayers;
1745 for (i = 0; i < MAX_NUM_NET_PLAYERS; i++)
1747 NetPlayers.players[i].connected = Players[i].connected;
1748 for(j = 0; j < MAX_NUM_NET_PLAYERS; j++)
1749 Netgame.kills[i][j] = kill_matrix[i][j];
1751 Netgame.killed[i] = Players[i].net_killed_total;
1752 Netgame.player_kills[i] = Players[i].net_kills_total;
1753 Netgame.player_score[i] = Players[i].score;
1754 Netgame.player_flags[i] = (Players[i].flags & (PLAYER_FLAGS_BLUE_KEY | PLAYER_FLAGS_RED_KEY | PLAYER_FLAGS_GOLD_KEY));
1756 Netgame.team_kills[0] = team_kills[0];
1757 Netgame.team_kills[1] = team_kills[1];
1758 Netgame.levelnum = Current_level_num;
1764 network_send_endlevel_sub(int player_num)
1769 // Send an endlevel packet for a player
1770 end.type = PID_ENDLEVEL;
1771 end.player_num = player_num;
1772 end.connected = Players[player_num].connected;
1773 end.kills = INTEL_SHORT(Players[player_num].net_kills_total);
1774 end.killed = INTEL_SHORT(Players[player_num].net_killed_total);
1775 memcpy(end.kill_matrix, kill_matrix[player_num], MAX_PLAYERS*sizeof(short));
1776 #ifdef WORDS_BIGENDIAN
1777 for (i = 0; i < MAX_PLAYERS; i++)
1778 for (j = 0; j < MAX_PLAYERS; j++)
1779 end.kill_matrix[i][j] = INTEL_SHORT(end.kill_matrix[i][j]);
1781 j = j; // to satisfy compiler
1784 if (Players[player_num].connected == 1) // Still playing
1786 Assert(Control_center_destroyed);
1787 end.seconds_left = Countdown_seconds_left;
1790 // mprintf((0, "Sending endlevel packet.\n"));
1792 for (i = 0; i < N_players; i++)
1794 if ((i != Player_num) && (i!=player_num) && (Players[i].connected)) {
1795 if (Players[i].connected==1)
1796 network_send_endlevel_short_sub(player_num,i);
1798 if (Network_game_type == IPX_GAME)
1799 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);
1802 appletalk_send_packet_data( (ubyte *)&end, sizeof(endlevel_info), NetPlayers.players[i].network.appletalk.node,
1803 NetPlayers.players[i].network.appletalk.net,
1804 NetPlayers.players[i].network.appletalk.socket);
1811 /* Send an updated endlevel status to other hosts */
1813 network_send_endlevel_packet(void)
1815 network_send_endlevel_sub(Player_num);
1819 /* Send an endlevel packet for a player */
1821 network_send_endlevel_short_sub(int from_player_num,int to_player)
1823 endlevel_info_short end;
1825 end.type = PID_ENDLEVEL_SHORT;
1826 end.player_num = from_player_num;
1827 end.connected = Players[from_player_num].connected;
1828 end.seconds_left = Countdown_seconds_left;
1831 if (Players[from_player_num].connected == 1) // Still playing
1833 Assert(Control_center_destroyed);
1836 if ((to_player != Player_num) && (to_player!=from_player_num) && (Players[to_player].connected))
1838 mprintf((0, "Sending short endlevel packet to %s.\n",Players[to_player].callsign));
1839 if (Network_game_type == IPX_GAME)
1840 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);
1843 appletalk_send_packet_data( (ubyte *)&end, sizeof(endlevel_info_short), NetPlayers.players[to_player].network.appletalk.node,
1844 NetPlayers.players[to_player].network.appletalk.net,
1845 NetPlayers.players[to_player].network.appletalk.socket);
1850 extern fix ThisLevelTime;
1853 network_send_game_info(sequence_packet *their)
1855 // Send game info to someone who requested it
1857 char old_type, old_status;
1861 mprintf((0, "Sending game info.\n"));
1863 network_update_netgame(); // Update the values in the netgame struct
1865 old_type = Netgame.type;
1866 old_status = Netgame.game_status;
1868 Netgame.type = PID_GAME_INFO;
1869 NetPlayers.type = PID_PLAYERSINFO;
1871 NetPlayers.Security=Netgame.Security;
1872 Netgame.version_major=Version_major;
1873 Netgame.version_minor=Version_minor;
1875 if (Endlevel_sequence || Control_center_destroyed)
1876 Netgame.game_status = NETSTAT_ENDLEVEL;
1878 if (Netgame.PlayTimeAllowed)
1880 timevar=i2f (Netgame.PlayTimeAllowed*5*60);
1881 i=f2i(timevar-ThisLevelTime);
1883 Netgame.game_status=NETSTAT_ENDLEVEL;
1887 if (Network_game_type == IPX_GAME) {
1888 send_broadcast_full_netgame_packet();
1889 send_broadcast_netplayers_packet();
1890 } // nothing to do for appletalk games I think....
1892 if (Network_game_type == IPX_GAME) {
1893 send_internetwork_full_netgame_packet(their->player.network.ipx.server, their->player.network.ipx.node);
1894 send_netplayers_packet(their->player.network.ipx.server, their->player.network.ipx.node);
1897 appletalk_send_packet_data( (ubyte *)&Netgame, sizeof(netgame_info), their->player.network.appletalk.node,
1898 their->player.network.appletalk.net, their->player.network.appletalk.socket );
1899 appletalk_send_packet_data( (ubyte *)&NetPlayers, sizeof(AllNetPlayers_info), their->player.network.appletalk.node,
1900 their->player.network.appletalk.net, their->player.network.appletalk.socket );
1905 Netgame.type = old_type;
1906 Netgame.game_status = old_status;
1909 void network_send_lite_info(sequence_packet *their)
1911 // Send game info to someone who requested it
1913 char old_type, old_status,oldstatus;
1915 mprintf((0, "Sending lite game info.\n"));
1917 network_update_netgame(); // Update the values in the netgame struct
1919 old_type = Netgame.type;
1920 old_status = Netgame.game_status;
1922 Netgame.type = PID_LITE_INFO;
1924 if (Endlevel_sequence || Control_center_destroyed)
1925 Netgame.game_status = NETSTAT_ENDLEVEL;
1927 // If hoard mode, make this game look closed even if it isn't
1928 if (HoardEquipped())
1930 if (Game_mode & GM_HOARD)
1932 oldstatus=Netgame.game_status;
1933 Netgame.game_status=NETSTAT_ENDLEVEL;
1934 Netgame.gamemode=NETGAME_CAPTURE_FLAG;
1935 if (oldstatus==NETSTAT_ENDLEVEL)
1936 Netgame.game_flags|=NETGAME_FLAG_REALLY_ENDLEVEL;
1937 if (oldstatus==NETSTAT_STARTING)
1938 Netgame.game_flags|=NETGAME_FLAG_REALLY_FORMING;
1943 if (Network_game_type == IPX_GAME) {
1944 send_broadcast_lite_netgame_packet();
1945 } // nothing to do for appletalk I think....
1947 if (Network_game_type == IPX_GAME) {
1948 send_internetwork_lite_netgame_packet(their->player.network.ipx.server, their->player.network.ipx.node);
1951 appletalk_send_packet_data( (ubyte *)&Netgame, sizeof(lite_info), their->player.network.appletalk.node,
1952 their->player.network.appletalk.net, their->player.network.appletalk.socket );
1957 // Restore the pre-hoard mode
1958 if (HoardEquipped())
1960 if (Game_mode & GM_HOARD)
1962 if (!(Game_mode & GM_TEAM))
1963 Netgame.gamemode=NETGAME_HOARD;
1965 Netgame.gamemode=NETGAME_TEAM_HOARD;
1966 Netgame.game_flags&=~NETGAME_FLAG_REALLY_ENDLEVEL;
1967 Netgame.game_flags&=~NETGAME_FLAG_REALLY_FORMING;
1968 Netgame.game_flags&=~NETGAME_FLAG_TEAM_HOARD;
1972 Netgame.type = old_type;
1973 Netgame.game_status = old_status;
1977 /* Send game info to all players in this game */
1978 void network_send_netgame_update()
1980 char old_type, old_status;
1983 mprintf((0, "Sending updated game info.\n"));
1985 network_update_netgame(); // Update the values in the netgame struct
1987 old_type = Netgame.type;
1988 old_status = Netgame.game_status;
1990 Netgame.type = PID_GAME_UPDATE;
1992 if (Endlevel_sequence || Control_center_destroyed)
1993 Netgame.game_status = NETSTAT_ENDLEVEL;
1995 for (i=0; i<N_players; i++ ) {
1996 if ( (Players[i].connected) && (i!=Player_num ) ) {
1997 if (Network_game_type == IPX_GAME) {
1998 send_lite_netgame_packet(NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node, Players[i].net_address);
2001 appletalk_send_packet_data( (ubyte *)&Netgame, sizeof(lite_info), NetPlayers.players[i].network.appletalk.node,
2002 NetPlayers.players[i].network.appletalk.net, NetPlayers.players[i].network.appletalk.socket );
2008 Netgame.type = old_type;
2009 Netgame.game_status = old_status;
2012 int network_send_request(void)
2014 // Send a request to join a game 'Netgame'. Returns 0 if we can join this
2015 // game, non-zero if there is some problem.
2018 if (Netgame.numplayers < 1)
2021 for (i = 0; i < MAX_NUM_NET_PLAYERS; i++)
2022 if (NetPlayers.players[i].connected)
2025 Assert(i < MAX_NUM_NET_PLAYERS);
2027 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));
2029 // segments_checksum = netmisc_calc_checksum( Segments, sizeof(segment)*(Highest_segment_index+1) );
2031 My_Seq.type = PID_REQUEST;
2032 My_Seq.player.connected = Current_level_num;
2034 if (Network_game_type == IPX_GAME) {
2035 send_internetwork_sequence_packet(My_Seq, NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node);
2038 appletalk_send_packet_data( (ubyte *)&My_Seq, sizeof(sequence_packet), NetPlayers.players[i].network.appletalk.node,
2039 NetPlayers.players[i].network.appletalk.net,
2040 NetPlayers.players[i].network.appletalk.socket);
2047 int SecurityCheck=0;
2049 void network_process_gameinfo(ubyte *data)
2052 netgame_info *new = (netgame_info *)data;
2053 #ifdef WORDS_BIGENDIAN
2054 netgame_info tmp_info;
2056 if (Network_game_type == IPX_GAME) {
2057 receive_netgame_packet(data, &tmp_info, 0); // get correctly aligned structure
2063 WaitingForPlayerInfo=0;
2065 if (new->Security !=TempPlayersInfo->Security)
2067 Int3(); // Get Jason
2068 return; // If this first half doesn't go with the second half
2071 Network_games_changed = 1;
2073 //mprintf((0, "Got game data for game %s.\n", new->game_name));
2075 Assert (TempPlayersInfo!=NULL);
2077 for (i = 0; i < num_active_games; i++)
2079 //mprintf ((0,"GAMEINFO: Game %d is %s!\n",i,Active_games[i].game_name));
2081 if (!stricmp(Active_games[i].game_name, new->game_name) &&
2082 Active_games[i].Security==new->Security)
2086 if (i == MAX_ACTIVE_NETGAMES)
2088 mprintf((0, "Too many netgames.\n"));
2092 // MWA memcpy(&Active_games[i], data, sizeof(netgame_info));
2093 memcpy(&Active_games[i], (ubyte *)new, sizeof(netgame_info));
2094 memcpy (&ActiveNetPlayers[i],TempPlayersInfo,sizeof(AllNetPlayers_info));
2097 if (Active_games[i].Security==SecurityCheck)
2100 //mprintf ((0,"Recieved %d unique games...\n",i));
2102 if (i == num_active_games)
2105 if (Active_games[i].numplayers == 0)
2107 mprintf ((0,"DELETING THIS GAME!!!\n"));
2109 for (j = i; j < num_active_games-1; j++)
2111 memcpy(&Active_games[j], &Active_games[j+1], sizeof(netgame_info));
2112 memcpy (&ActiveNetPlayers[j],&ActiveNetPlayers[j+1],sizeof(AllNetPlayers_info));
2119 void network_process_lite_info(ubyte *data)
2122 lite_info *new = (lite_info *)data;
2123 #ifdef WORDS_BIGENDIAN
2126 if (Network_game_type == IPX_GAME) {
2127 receive_netgame_packet(data, (netgame_info *)&tmp_info, 1);
2132 Network_games_changed = 1;
2134 //mprintf((0, "Got game data for game %s.\n", new->game_name));
2136 for (i = 0; i < num_active_games; i++)
2138 //mprintf ((0,"GAMEINFO: Game %d is %s!\n",i,Active_games[i].game_name));
2140 if ((!stricmp(Active_games[i].game_name, new->game_name)) &&
2141 Active_games[i].Security==new->Security)
2145 if (i == MAX_ACTIVE_NETGAMES)
2147 mprintf((0, "Too many netgames.\n"));
2151 memcpy(&Active_games[i], (ubyte *)new, sizeof(lite_info));
2153 // See if this is really a Hoard game
2154 // If so, adjust all the data accordingly
2156 if (HoardEquipped())
2158 if (Active_games[i].game_flags & NETGAME_FLAG_HOARD)
2160 Active_games[i].gamemode=NETGAME_HOARD;
2161 Active_games[i].game_status=NETSTAT_PLAYING;
2163 if (Active_games[i].game_flags & NETGAME_FLAG_TEAM_HOARD)
2164 Active_games[i].gamemode=NETGAME_TEAM_HOARD;
2165 if (Active_games[i].game_flags & NETGAME_FLAG_REALLY_ENDLEVEL)
2166 Active_games[i].game_status=NETSTAT_ENDLEVEL;
2167 if (Active_games[i].game_flags & NETGAME_FLAG_REALLY_FORMING)
2168 Active_games[i].game_status=NETSTAT_STARTING;
2172 //mprintf ((0,"Recieved %d unique games...\n",i));
2174 if (i == num_active_games)
2177 if (Active_games[i].numplayers == 0)
2179 mprintf ((0,"DELETING THIS GAME!!!\n"));
2181 for (j = i; j < num_active_games-1; j++)
2183 memcpy(&Active_games[j], &Active_games[j+1], sizeof(netgame_info));
2189 void network_process_dump(sequence_packet *their)
2191 // Our request for join was denied. Tell the user why.
2196 mprintf((0, "Dumped by player %s, type %d.\n", their->player.callsign, their->player.connected));
2198 if (their->player.connected!=7)
2199 nm_messagebox(NULL, 1, TXT_OK, NET_DUMP_STRINGS(their->player.connected));
2202 for (i=0;i<N_players;i++)
2203 if (!stricmp (their->player.callsign,Players[i].callsign))
2205 if (i!=network_who_is_master())
2207 HUD_init_message ("%s attempted to kick you out.",their->player.callsign);
2211 sprintf (temp,"%s has kicked you out!",their->player.callsign);
2212 nm_messagebox(NULL, 1, TXT_OK, &temp);
2213 if (Network_status==NETSTAT_PLAYING)
2219 Network_status = NETSTAT_MENU;
2224 void network_process_request(sequence_packet *their)
2226 // Player is ready to receieve a sync packet
2229 mprintf((0, "Player %s ready for sync.\n", their->player.callsign));
2231 for (i = 0; i < N_players; i++) {
2232 if (Network_game_type == IPX_GAME) {
2233 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))) {
2234 Players[i].connected = 1;
2238 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)) ) {
2239 Players[i].connected = 1;
2246 #define REFUSE_INTERVAL F1_0 * 8
2247 extern void multi_reset_object_texture (object *);
2249 void network_process_packet(ubyte *data, int length )
2251 sequence_packet *their = (sequence_packet *)data;
2252 #ifdef WORDS_BIGENDIAN
2253 sequence_packet tmp_packet;
2255 if (Network_game_type == IPX_GAME) {
2256 receive_sequence_packet(data, &tmp_packet);
2257 their = &tmp_packet; // reassign their to point to correctly alinged structure
2261 //mprintf( (0, "Got packet of length %d, type %d\n", length, their->type ));
2263 // if ( length < sizeof(sequence_packet) ) return;
2269 case PID_GAME_INFO: // Jason L. says we can safely ignore this type.
2272 case PID_PLAYERSINFO:
2274 mprintf ((0,"Got a PID_PLAYERSINFO!\n"));
2276 if (Network_status==NETSTAT_WAITING)
2278 if (Network_game_type == IPX_GAME)
2279 receive_netplayers_packet(data, &TempPlayersBase);
2281 memcpy (&TempPlayersBase,data,sizeof(AllNetPlayers_info));
2283 if (TempPlayersBase.Security!=Netgame.Security)
2285 mprintf ((0,"Bad security for PLAYERSINFO\n"));
2289 mprintf ((0,"Got a waiting PID_PLAYERSINFO!\n"));
2290 if (length!=ALLNETPLAYERSINFO_SIZE)
2292 mprintf ((0,"Invalid size for netplayers packet!\n"));
2296 TempPlayersInfo=&TempPlayersBase;
2297 WaitingForPlayerInfo=0;
2298 NetSecurityNum=TempPlayersInfo->Security;
2299 NetSecurityFlag=NETSECURITY_WAIT_FOR_SYNC;
2306 if (length != LITE_INFO_SIZE)
2308 mprintf ((0,"WARNING! Recieved invalid size for PID_LITE_INFO\n"));
2312 if (Network_status == NETSTAT_BROWSING)
2313 network_process_lite_info (data);
2317 // Someone wants a list of games
2319 if (length != SEQUENCE_PACKET_SIZE)
2321 mprintf ((0,"WARNING! Recieved invalid size for PID_GAME_LIST\n"));
2325 mprintf((0, "Got a PID_GAME_LIST!\n"));
2326 if ((Network_status == NETSTAT_PLAYING) || (Network_status == NETSTAT_STARTING) || (Network_status == NETSTAT_ENDLEVEL))
2327 if (network_i_am_master())
2328 network_send_lite_info(their);
2332 case PID_SEND_ALL_GAMEINFO:
2334 if (length != SEQUENCE_PACKET_SIZE)
2336 mprintf ((0,"WARNING! Recieved invalid size for PID_SEND_ALL_GAMEINFO\n"));
2340 if ((Network_status == NETSTAT_PLAYING) || (Network_status == NETSTAT_STARTING) || (Network_status == NETSTAT_ENDLEVEL))
2341 if (network_i_am_master() && their->Security==Netgame.Security)
2342 network_send_game_info(their);
2347 mprintf( (0, "Got NEWPLAYER message from %s.\n", their->player.callsign));
2349 if (length != SEQUENCE_PACKET_SIZE)
2351 mprintf ((0,"WARNING! Recieved invalid size for PID_ADDPLAYER\n"));
2354 mprintf( (0, "Got NEWPLAYER message from %s.\n", their->player.callsign));
2355 network_new_player(their);
2358 if (length != SEQUENCE_PACKET_SIZE)
2360 mprintf ((0,"WARNING! Recieved invalid size for PID_REQUEST\n"));
2364 mprintf( (0, "Got REQUEST from '%s'\n", their->player.callsign ));
2365 if (Network_status == NETSTAT_STARTING)
2367 // Someone wants to join our game!
2368 network_add_player(their);
2370 else if (Network_status == NETSTAT_WAITING)
2372 // Someone is ready to recieve a sync packet
2373 network_process_request(their);
2375 else if (Network_status == NETSTAT_PLAYING)
2377 // Someone wants to join a game in progress!
2378 if (Netgame.RefusePlayers)
2379 DoRefuseStuff (their);
2381 network_welcome_player(their);
2386 if (length != SEQUENCE_PACKET_SIZE)
2388 mprintf ((0,"WARNING! Recieved invalid size for PID_DUMP\n"));
2392 if (Network_status == NETSTAT_WAITING || Network_status==NETSTAT_PLAYING )
2393 network_process_dump(their);
2395 case PID_QUIT_JOINING:
2397 if (length != SEQUENCE_PACKET_SIZE)
2399 mprintf ((0,"WARNING! Recieved invalid size for PID_QUIT_JOINING\n"));
2402 if (Network_status == NETSTAT_STARTING)
2403 network_remove_player( their );
2404 else if ((Network_status == NETSTAT_PLAYING) && (Network_send_objects))
2405 network_stop_resync( their );
2409 mprintf ((0,"Got a sync packet! Network_status=%d\n",NETSTAT_WAITING));
2411 if (Network_status == NETSTAT_WAITING) {
2413 if (Network_game_type == IPX_GAME)
2414 receive_full_netgame_packet(data, &TempNetInfo);
2416 memcpy((ubyte *)&(TempNetInfo), data, sizeof(netgame_info));
2418 if (TempNetInfo.Security!=Netgame.Security)
2420 mprintf ((0,"Bad security on sync packet.\n"));
2424 if (NetSecurityFlag==NETSECURITY_WAIT_FOR_SYNC)
2426 if (TempNetInfo.Security==TempPlayersInfo->Security)
2428 network_read_sync_packet (&TempNetInfo,0);
2435 NetSecurityFlag=NETSECURITY_WAIT_FOR_PLAYERS;
2436 NetSecurityNum=TempNetInfo.Security;
2438 if ( network_wait_for_playerinfo())
2439 network_read_sync_packet((netgame_info *)data,0);
2448 if ((Game_mode&GM_NETWORK) && ((Network_status == NETSTAT_PLAYING)||(Network_status == NETSTAT_ENDLEVEL) || Network_status==NETSTAT_WAITING)) {
2449 network_process_pdata((char *)data);
2452 case PID_NAKED_PDATA:
2453 if ((Game_mode&GM_NETWORK) && ((Network_status == NETSTAT_PLAYING)||(Network_status == NETSTAT_ENDLEVEL) || Network_status==NETSTAT_WAITING))
2454 network_process_naked_pdata((char *)data,length);
2457 case PID_OBJECT_DATA:
2458 if (Network_status == NETSTAT_WAITING)
2459 network_read_object_packet(data);
2462 if ((Network_status == NETSTAT_ENDLEVEL) || (Network_status == NETSTAT_PLAYING))
2463 network_read_endlevel_packet(data);
2465 mprintf((0, "Junked endlevel packet.\n"));
2467 case PID_ENDLEVEL_SHORT:
2468 if ((Network_status == NETSTAT_ENDLEVEL) || (Network_status == NETSTAT_PLAYING))
2469 network_read_endlevel_short_packet(data);
2471 mprintf((0, "Junked short endlevel packet!\n"));
2474 case PID_GAME_UPDATE:
2475 mprintf ((0,"Got a GAME_UPDATE!\n"));
2477 if (Network_status==NETSTAT_PLAYING)
2479 if (Network_game_type == IPX_GAME)
2480 receive_lite_netgame_packet(data, &TempNetInfo);
2482 memcpy((ubyte *)&TempNetInfo, data, sizeof(lite_info) );
2483 if (TempNetInfo.Security==Netgame.Security)
2484 memcpy (&Netgame,(ubyte *)&TempNetInfo,sizeof(lite_info));
2486 if (Game_mode & GM_TEAM)
2490 for (i=0;i<N_players;i++)
2491 if (Players[i].connected)
2492 multi_reset_object_texture (&Objects[Players[i].objnum]);
2497 network_ping (PID_PING_RETURN,data[1]);
2499 case PID_PING_RETURN:
2500 network_handle_ping_return(data[1]); // data[1] is player who told us of their ping time
2502 case PID_NAMES_RETURN:
2503 if (Network_status==NETSTAT_BROWSING && NamesInfoSecurity!=-1)
2504 network_process_names_return (data);
2506 case PID_GAME_PLAYERS:
2507 // Someone wants a list of players in this game
2509 if (length != SEQUENCE_PACKET_SIZE)
2511 mprintf ((0,"WARNING! Recieved invalid size for PID_GAME_PLAYERS\n"));
2515 mprintf((0, "Got a PID_GAME_PLAYERS!\n"));
2516 if ((Network_status == NETSTAT_PLAYING) || (Network_status == NETSTAT_STARTING) || (Network_status == NETSTAT_ENDLEVEL))
2517 if (network_i_am_master() && their->Security==Netgame.Security)
2518 network_send_player_names(their);
2522 mprintf((0, "Ignoring invalid packet type.\n"));
2523 Int3(); // Invalid network packet type, see ROB
2529 void dump_segments()
2533 fp = fopen( "TEST.DMP", "wb" );
2534 fwrite( Segments, sizeof(segment)*(Highest_segment_index+1),1, fp );
2536 mprintf( (0, "SS=%d\n", sizeof(segment) ));
2542 network_read_endlevel_packet( ubyte *data )
2544 // Special packet for end of level syncing
2546 endlevel_info *end = (endlevel_info *)data;
2547 #ifdef WORDS_BIGENDIAN
2550 for (i = 0; i < MAX_PLAYERS; i++)
2551 for (j = 0; j < MAX_PLAYERS; j++)
2552 end->kill_matrix[i][j] = INTEL_SHORT(end->kill_matrix[i][j]);
2553 end->kills = INTEL_SHORT(end->kills);
2554 end->killed = INTEL_SHORT(end->killed);
2557 playernum = end->player_num;
2559 Assert(playernum != Player_num);
2561 if (playernum>=N_players)
2563 Int3(); // weird, but it an happen in a coop restore game
2564 return; // if it happens in a coop restore, don't worry about it
2567 if ((Network_status == NETSTAT_PLAYING) && (end->connected != 0))
2568 return; // Only accept disconnect packets if we're not out of the level yet
2570 Players[playernum].connected = end->connected;
2571 memcpy(&kill_matrix[playernum][0], end->kill_matrix, MAX_PLAYERS*sizeof(short));
2572 Players[playernum].net_kills_total = end->kills;
2573 Players[playernum].net_killed_total = end->killed;
2575 if ((Players[playernum].connected == 1) && (end->seconds_left < Countdown_seconds_left))
2576 Countdown_seconds_left = end->seconds_left;
2578 LastPacketTime[playernum] = timer_get_approx_seconds();
2580 // mprintf((0, "Got endlevel packet from player %d.\n", playernum));
2584 network_read_endlevel_short_packet( ubyte *data )
2586 // Special packet for end of level syncing
2589 endlevel_info_short *end;
2591 end = (endlevel_info_short *)data;
2593 playernum = end->player_num;
2595 Assert(playernum != Player_num);
2597 if (playernum>=N_players)
2599 Int3(); // weird, but it can happen in a coop restore game
2600 return; // if it happens in a coop restore, don't worry about it
2603 if ((Network_status == NETSTAT_PLAYING) && (end->connected != 0))
2605 //mprintf ((0,"Returning early for short_endlevel\n"));
2606 return; // Only accept disconnect packets if we're not out of the level yet
2609 Players[playernum].connected = end->connected;
2611 if ((Players[playernum].connected == 1) && (end->seconds_left < Countdown_seconds_left))
2612 Countdown_seconds_left = end->seconds_left;
2614 LastPacketTime[playernum] = timer_get_approx_seconds();
2619 network_pack_objects(void)
2621 // Switching modes, pack the object array
2623 special_reset_objects();
2627 network_verify_objects(int remote, int local)
2630 int nplayers, got_controlcen=0;
2632 mprintf ((0,"NETWORK:remote=%d local=%d\n",remote,local));
2634 if ((remote-local) > 10)
2637 if (Game_mode & GM_MULTI_ROBOTS)
2642 for (i = 0; i <= Highest_object_index; i++)
2644 if ((Objects[i].type == OBJ_PLAYER) || (Objects[i].type == OBJ_GHOST))
2646 if (Objects[i].type == OBJ_CNTRLCEN)
2650 if (got_controlcen && (MaxNumNetPlayers<=nplayers))
2657 network_read_object_packet( ubyte *data )
2659 // Object from another net player we need to sync with
2661 short objnum, remote_objnum;
2666 static int my_pnum = 0;
2667 static int mode = 0;
2668 static int object_count = 0;
2669 static int frame_num = 0;
2672 int remote_frame_num = data[2];
2676 // mprintf((0, "Object packet %d (remote #%d) contains %d objects.\n", frame_num, remote_frame_num, nobj));
2678 for (i = 0; i < nobj; i++)
2680 objnum = INTEL_SHORT( *(short *)(data+loc) ); loc += 2;
2681 obj_owner = data[loc]; loc += 1;
2682 remote_objnum = INTEL_SHORT( *(short *)(data+loc) ); loc += 2;
2686 // Clear object array
2687 mprintf((0, "Clearing object array.\n"));
2690 Network_rejoined = 1;
2691 my_pnum = obj_owner;
2692 change_playernum_to(my_pnum);
2697 else if (objnum == -2)
2699 // Special debug checksum marker for entire send
2702 network_pack_objects();
2705 mprintf((0, "Objnum -2 found in frame local %d remote %d.\n", frame_num, remote_frame_num));
2706 mprintf((0, "Got %d objects, expected %d.\n", object_count, remote_objnum));
2707 if (remote_objnum != object_count) {
2710 if (network_verify_objects(remote_objnum, object_count))
2712 // Failed to sync up
2713 nm_messagebox(NULL, 1, TXT_OK, TXT_NET_SYNC_FAILED);
2714 Network_status = NETSTAT_MENU;
2721 if (frame_num != remote_frame_num)
2723 mprintf ((0,"Got a type 3 object packet!\n"));
2725 if ((obj_owner == my_pnum) || (obj_owner == -1))
2729 objnum = remote_objnum;
2730 //if (objnum > Highest_object_index)
2732 // Highest_object_index = objnum;
2733 // num_objects = Highest_object_index+1;
2739 network_pack_objects();
2742 objnum = obj_allocate();
2745 obj = &Objects[objnum];
2746 if (obj->segnum != -1)
2748 Assert(obj->segnum == -1);
2749 Assert(objnum < MAX_OBJECTS);
2750 memcpy(obj, &data[loc], sizeof(object));
2751 if (Network_game_type == IPX_GAME)
2753 loc += sizeof(object);
2754 segnum = obj->segnum;
2755 obj->next = obj->prev = obj->segnum = -1;
2756 obj->attached_obj = -1;
2758 obj_link(obj-Objects,segnum);
2759 if (obj_owner == my_pnum)
2760 map_objnum_local_to_local(objnum);
2761 else if (obj_owner != -1)
2762 map_objnum_local_to_remote(objnum, remote_objnum, obj_owner);
2764 object_owner[objnum] = -1;
2766 } // For a standard onbject
2767 } // For each object in packet
2770 /* Polling loop waiting for sync packet to start game
2771 * after having sent request
2773 void network_sync_poll( int nitems, newmenu_item * menus, int * key, int citem )
2784 if (Network_status != NETSTAT_WAITING) // Status changed to playing, exit the menu
2787 if (!Network_rejoined && (timer_get_approx_seconds() > t1+F1_0*2))
2791 // Poll time expired, re-send request
2793 t1 = timer_get_approx_seconds();
2795 mprintf((0, "Re-sending join request.\n"));
2796 i = network_send_request();
2802 void network_start_poll( int nitems, newmenu_item * menus, int * key, int citem )
2809 Assert(Network_status == NETSTAT_STARTING);
2811 if (!menus[0].value) {
2813 menus[0].redraw = 1;
2816 for (i=1; i<nitems; i++ ) {
2817 if ( (i>= N_players) && (menus[i].value) ) {
2819 menus[i].redraw = 1;
2824 for (i=0; i<nitems; i++ ) {
2825 if ( menus[i].value ) {
2827 if ( nm > N_players ) {
2829 menus[i].redraw = 1;
2834 if ( nm > MaxNumNetPlayers ) {
2835 nm_messagebox( TXT_ERROR, 1, TXT_OK, "%s %d %s", TXT_SORRY_ONLY, MaxNumNetPlayers, TXT_NETPLAYERS_IN );
2836 // Turn off the last player highlighted
2837 for (i = N_players; i > 0; i--)
2838 if (menus[i].value == 1)
2841 menus[i].redraw = 1;
2846 // if (nitems > MAX_PLAYERS ) return;
2848 n = Netgame.numplayers;
2851 if (n < Netgame.numplayers )
2853 digi_play_sample (SOUND_HUD_MESSAGE,F1_0);
2855 mprintf ((0,"More players are printed!"));
2856 if (FindArg("-norankings"))
2857 sprintf( menus[N_players-1].text, "%d. %-20s", N_players,NetPlayers.players[N_players-1].callsign );
2859 sprintf( menus[N_players-1].text, "%d. %s%-20s", N_players, RankStrings[NetPlayers.players[N_players-1].rank],NetPlayers.players[N_players-1].callsign );
2861 menus[N_players-1].redraw = 1;
2862 if (N_players <= MaxNumNetPlayers)
2864 menus[N_players-1].value = 1;
2867 else if ( n > Netgame.numplayers )
2869 // One got removed...
2871 digi_play_sample (SOUND_HUD_KILL,F1_0);
2873 for (i=0; i<N_players; i++ )
2876 if (FindArg("-norankings"))
2877 sprintf( menus[i].text, "%d. %-20s", i+1, NetPlayers.players[i].callsign );
2879 sprintf( menus[i].text, "%d. %s%-20s", i+1, RankStrings[NetPlayers.players[i].rank],NetPlayers.players[i].callsign );
2880 if (i < MaxNumNetPlayers)
2884 menus[i].redraw = 1;
2886 for (i=N_players; i<n; i++ )
2888 sprintf( menus[i].text, "%d. ", i+1 ); // Clear out the deleted entries...
2890 menus[i].redraw = 1;
2895 int opt_cinvul, opt_team_anarchy, opt_coop, opt_show_on_map, opt_closed,opt_maxnet;
2896 int last_cinvul=0,last_maxnet,opt_team_hoard;
2897 int opt_refuse,opt_capture;
2899 void network_game_param_poll( int nitems, newmenu_item * menus, int * key, int citem )
2901 static int oldmaxnet=0;
2903 if (((HoardEquipped() && menus[opt_team_hoard].value) || (menus[opt_team_anarchy].value || menus[opt_capture].value)) && !menus[opt_closed].value && !menus[opt_refuse].value) {
2904 menus[opt_refuse].value = 1;
2905 menus[opt_refuse].redraw = 1;
2906 menus[opt_refuse-1].value = 0;
2907 menus[opt_refuse-1].redraw = 1;
2908 menus[opt_refuse-2].value = 0;
2909 menus[opt_refuse-2].redraw = 1;
2913 if (menus[opt_coop].value)
2915 if ( (menus[opt_coop].value) || ((Network_game_type == APPLETALK_GAME) && (Network_appletalk_type == LOCALTALK_TYPE) && (menus[opt_coop-1].value)) )
2920 if (menus[opt_maxnet].value>2)
2922 menus[opt_maxnet].value=2;
2923 menus[opt_maxnet].redraw=1;
2926 if (menus[opt_maxnet].max_value>2)
2928 menus[opt_maxnet].max_value=2;
2929 menus[opt_maxnet].redraw=1;
2933 if ( (Network_game_type == APPLETALK_GAME) && (Network_appletalk_type == LOCALTALK_TYPE) ) {
2934 if (menus[opt_maxnet].value > 0) {
2935 menus[opt_maxnet].value=0;
2936 menus[opt_maxnet].redraw=1;
2938 if (menus[opt_maxnet].max_value > 0) {
2939 menus[opt_maxnet].max_value=0;
2940 menus[opt_maxnet].redraw=1;
2945 if (!Netgame.game_flags & NETGAME_FLAG_SHOW_MAP)
2946 Netgame.game_flags |= NETGAME_FLAG_SHOW_MAP;
2948 if (Netgame.PlayTimeAllowed || Netgame.KillGoal)
2950 Netgame.PlayTimeAllowed=0;
2955 else // if !Coop game
2960 menus[opt_maxnet].value=6;
2961 menus[opt_maxnet].max_value=6;
2964 if ( (Network_game_type == APPLETALK_GAME) && (Network_appletalk_type == LOCALTALK_TYPE) ) {
2965 menus[opt_maxnet].value=1;
2966 menus[opt_maxnet].max_value=1;
2973 if ( last_maxnet != menus[opt_maxnet].value )
2975 sprintf( menus[opt_maxnet].text, "Maximum players: %d", menus[opt_maxnet].value+2 );
2976 last_maxnet = menus[opt_maxnet].value;
2977 menus[opt_maxnet].redraw = 1;
2981 int netgame_difficulty;
2983 int network_get_game_params( char * game_name, int *mode, int *game_flags, int *level )
2986 int opt, opt_name, opt_level, opt_mode,opt_moreopts;
2988 char name[NETGAME_NAME_LEN+1];
2990 char level_text[32];
2993 int new_mission_num;
2996 *game_flags=*game_flags;
2998 SetAllAllowablesTo (1);
2999 NamesInfoSecurity=-1;
3001 for (i=0;i<MAX_PLAYERS;i++)
3003 Players[i].callsign[0]=0;
3007 Netgame.PlayTimeAllowed=0;
3008 Netgame.Allow_marker_view=1;
3009 netgame_difficulty=Player_default_difficulty;
3011 new_mission_num = multi_choose_mission(&anarchy_only);
3013 if (new_mission_num < 0)
3016 if (!(FindArg ("-packets") && FindArg ("-shortpackets")))
3017 if (!network_choose_connect ())
3021 if ( (Network_game_type == APPLETALK_GAME) && (Network_appletalk_type == LOCALTALK_TYPE) )
3022 MaxNumNetPlayers = 3;
3025 strcpy(Netgame.mission_name, Mission_list[new_mission_num].filename);
3026 strcpy(Netgame.mission_title, Mission_list[new_mission_num].mission_name);
3027 Netgame.control_invul_time = control_invul_time;
3029 sprintf( name, "%s%s", Players[Player_num].callsign, TXT_S_GAME );
3030 sprintf( slevel, "1" );
3033 m[opt].type = NM_TYPE_TEXT; m[opt].text = TXT_DESCRIPTION; opt++;
3036 m[opt].type = NM_TYPE_INPUT; m[opt].text = name; m[opt].text_len = NETGAME_NAME_LEN; opt++;
3038 sprintf(level_text, "%s (1-%d)", TXT_LEVEL_, Last_level);
3040 // if (Last_secret_level < -1)
3041 // sprintf(level_text+strlen(level_text)-1, ", S1-S%d)", -Last_secret_level);
3042 // else if (Last_secret_level == -1)
3043 // sprintf(level_text+strlen(level_text)-1, ", S1)");
3045 Assert(strlen(level_text) < 32);
3047 m[opt].type = NM_TYPE_TEXT; m[opt].text = level_text; opt++;
3050 m[opt].type = NM_TYPE_INPUT; m[opt].text = slevel; m[opt].text_len=4; opt++;
3051 // m[opt].type = NM_TYPE_TEXT; m[opt].text = TXT_OPTIONS; opt++;
3054 m[opt].type = NM_TYPE_RADIO; m[opt].text = TXT_ANARCHY; m[opt].value=1; m[opt].group=0; opt++;
3055 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++;
3056 m[opt].type = NM_TYPE_RADIO; m[opt].text = TXT_ANARCHY_W_ROBOTS; m[opt].value=0; m[opt].group=0; opt++;
3057 m[opt].type = NM_TYPE_RADIO; m[opt].text = TXT_COOPERATIVE; m[opt].value=0; m[opt].group=0; opt_coop=opt; opt++;
3058 m[opt].type = NM_TYPE_RADIO; m[opt].text = "Capture the flag"; m[opt].value=0; m[opt].group=0; opt_capture=opt; opt++;
3060 if (HoardEquipped())
3062 m[opt].type = NM_TYPE_RADIO; m[opt].text = "Hoard"; m[opt].value=0; m[opt].group=0; opt++;
3063 m[opt].type = NM_TYPE_RADIO; m[opt].text = "Team Hoard"; m[opt].value=0; m[opt].group=0; opt_team_hoard=opt; opt++;
3064 m[opt].type = NM_TYPE_TEXT; m[opt].text = ""; opt++;
3067 { m[opt].type = NM_TYPE_TEXT; m[opt].text = ""; opt++; }
3069 m[opt].type = NM_TYPE_RADIO; m[opt].text = "Open game"; m[opt].group=1; m[opt].value=0; opt++;
3071 m[opt].type = NM_TYPE_RADIO; m[opt].text = TXT_CLOSED_GAME; m[opt].group=1; m[opt].value=0; opt++;
3073 m[opt].type = NM_TYPE_RADIO; m[opt].text = "Restricted Game "; m[opt].group=1; m[opt].value=Netgame.RefusePlayers; opt++;
3075 // m[opt].type = NM_TYPE_CHECK; m[opt].text = TXT_SHOW_IDS; m[opt].value=0; opt++;
3078 sprintf( srmaxnet, "Maximum players: %d", MaxNumNetPlayers);
3079 m[opt].type = NM_TYPE_SLIDER; m[opt].value=MaxNumNetPlayers-2; m[opt].text= srmaxnet; m[opt].min_value=0;
3080 m[opt].max_value=MaxNumNetPlayers-2; opt++;
3081 last_maxnet=MaxNumNetPlayers-2;
3084 m[opt].type = NM_TYPE_MENU; m[opt].text = "More options..."; opt++;
3089 ExtGameStatus=GAMESTAT_NETGAME_OPTIONS;
3090 i = newmenu_do1( NULL, NULL, opt, m, network_game_param_poll, 1 );
3092 if (i==opt_moreopts)
3094 if ( m[opt_mode+3].value )
3095 Game_mode=GM_MULTI_COOP;
3096 network_more_game_options();
3100 Netgame.RefusePlayers=m[opt_refuse].value;
3106 MaxNumNetPlayers = m[opt_maxnet].value+2;
3107 Netgame.max_numplayers=MaxNumNetPlayers;
3109 for (j = 0; j < num_active_games; j++)
3110 if (!stricmp(Active_games[j].game_name, name))
3112 nm_messagebox(TXT_ERROR, 1, TXT_OK, TXT_DUPLICATE_NAME);
3116 strcpy( game_name, name );
3119 *level = atoi(slevel);
3121 if ((*level < 1) || (*level > Last_level))
3123 nm_messagebox(TXT_ERROR, 1, TXT_OK, TXT_LEVEL_OUT_RANGE );
3124 sprintf(slevel, "1");
3127 if ( m[opt_mode].value )
3128 *mode = NETGAME_ANARCHY;
3133 nm_messagebox(TXT_SORRY, 1, TXT_OK, TXT_REGISTERED_ONLY );
3134 m[opt_mode+1].value = 0;
3135 m[opt_mode+2].value = 0;
3136 m[opt_mode+3].value = 0;
3137 if (HoardEquipped())
3138 m[opt_mode+4].value = 0;
3140 m[opt_mode].value = 1;
3144 else if (m[opt_mode+1].value) {
3145 *mode = NETGAME_TEAM_ANARCHY;
3147 else if (m[opt_capture].value)
3148 *mode = NETGAME_CAPTURE_FLAG;
3149 else if (HoardEquipped() && m[opt_capture+1].value)
3150 *mode = NETGAME_HOARD;
3151 else if (HoardEquipped() && m[opt_capture+2].value)
3152 *mode = NETGAME_TEAM_HOARD;
3153 else if (anarchy_only) {
3154 nm_messagebox(NULL, 1, TXT_OK, TXT_ANARCHY_ONLY_MISSION);
3155 m[opt_mode+2].value = 0;
3156 m[opt_mode+3].value = 0;
3157 m[opt_mode].value = 1;
3160 else if ( m[opt_mode+2].value )
3161 *mode = NETGAME_ROBOT_ANARCHY;
3162 else if ( m[opt_mode+3].value )
3163 *mode = NETGAME_COOPERATIVE;
3164 else Int3(); // Invalid mode -- see Rob
3166 if (m[opt_closed].value)
3167 Netgame.game_flags |= NETGAME_FLAG_CLOSED;
3175 network_set_game_mode(int gamemode)
3179 if ( gamemode == NETGAME_ANARCHY )
3180 Game_mode = GM_NETWORK;
3181 else if ( gamemode == NETGAME_ROBOT_ANARCHY )
3182 Game_mode = GM_NETWORK | GM_MULTI_ROBOTS;
3183 else if ( gamemode == NETGAME_COOPERATIVE )
3184 Game_mode = GM_NETWORK | GM_MULTI_COOP | GM_MULTI_ROBOTS;
3185 else if (gamemode == NETGAME_CAPTURE_FLAG)
3187 Game_mode = GM_NETWORK | GM_TEAM | GM_CAPTURE;
3191 else if (HoardEquipped() && gamemode == NETGAME_HOARD)
3192 Game_mode = GM_NETWORK | GM_HOARD;
3193 else if (HoardEquipped() && gamemode == NETGAME_TEAM_HOARD)
3195 Game_mode = GM_NETWORK | GM_HOARD | GM_TEAM;
3198 else if ( gamemode == NETGAME_TEAM_ANARCHY )
3200 Game_mode = GM_NETWORK | GM_TEAM;
3207 #ifdef MACINTOSH // minimize players on localtalk games
3208 if ( (Network_game_type == APPLETALK_GAME) && (Network_appletalk_type == LOCALTALK_TYPE) ) {
3209 if (Game_mode & GM_MULTI_ROBOTS)
3210 MaxNumNetPlayers = 2;
3212 MaxNumNetPlayers = 3;
3214 if (Game_mode & GM_MULTI_COOP)
3215 MaxNumNetPlayers = 4;
3217 MaxNumNetPlayers = 8;
3225 network_find_game(void)
3227 // Find out whether or not there is space left on this socket
3231 Network_status = NETSTAT_BROWSING;
3233 num_active_games = 0;
3235 show_boxed_message(TXT_WAIT);
3237 network_send_game_list_request();
3238 t1 = timer_get_approx_seconds() + F1_0*3;
3240 while (timer_get_approx_seconds() < t1) // Wait 3 seconds for replies
3243 clear_boxed_message();
3245 // mprintf((0, "%s %d %s\n", TXT_FOUND, num_active_games, TXT_ACTIVE_GAMES));
3247 if (num_active_games < MAX_ACTIVE_NETGAMES)
3252 void network_read_sync_packet( netgame_info * sp, int rsinit)
3255 char temp_callsign[CALLSIGN_LEN+1];
3256 #ifdef WORDS_BIGENDIAN
3257 netgame_info tmp_info;
3259 if ( (Network_game_type == IPX_GAME) && (sp != &Netgame) ) { // for macintosh -- get the values unpacked to our structure format
3260 receive_full_netgame_packet((ubyte *)sp, &tmp_info);
3266 TempPlayersInfo=&NetPlayers;
3268 // This function is now called by all people entering the netgame.
3270 // mprintf( (0, "%s %d\n", TXT_STARTING_NETGAME, sp->levelnum ));
3274 memcpy( &Netgame, sp, sizeof(netgame_info) );
3275 memcpy (&NetPlayers,TempPlayersInfo,sizeof (AllNetPlayers_info));
3278 N_players = sp->numplayers;
3279 Difficulty_level = sp->difficulty;
3280 Network_status = sp->game_status;
3282 //Assert(Function_mode != FMODE_GAME);
3286 mprintf((1, "Netgame.checksum = %d, calculated checksum = %d.\n", Netgame.segments_checksum, my_segments_checksum));
3288 if (Netgame.segments_checksum != my_segments_checksum)
3290 Network_status = NETSTAT_MENU;
3291 nm_messagebox(TXT_ERROR, 1, TXT_OK, TXT_NETLEVEL_NMATCH);
3297 // Discover my player number
3299 memcpy(temp_callsign, Players[Player_num].callsign, CALLSIGN_LEN+1);
3303 for (i=0; i<MAX_NUM_NET_PLAYERS; i++ ) {
3304 Players[i].net_kills_total = 0;
3305 // Players[i].net_killed_total = 0;
3308 for (i=0; i<N_players; i++ ) {
3309 if (Network_game_type == IPX_GAME) {
3310 if ( (!memcmp( TempPlayersInfo->players[i].network.ipx.node, My_Seq.player.network.ipx.node, 6 )) && (!stricmp( TempPlayersInfo->players[i].callsign, temp_callsign)) ) {
3311 if (Player_num!=-1) {
3312 Int3(); // Hey, we've found ourselves twice
3313 mprintf ((0,"Hey, we've found ourselves twice!\n"));
3314 Network_status = NETSTAT_MENU;
3317 change_playernum_to(i);
3320 if ( (TempPlayersInfo->players[i].network.appletalk.node == My_Seq.player.network.appletalk.node) && (!stricmp( TempPlayersInfo->players[i].callsign, temp_callsign)) ) {
3321 if (Player_num!=-1) {
3322 Int3(); // Hey, we've found ourselves twice
3323 Network_status = NETSTAT_MENU;
3326 change_playernum_to(i);
3329 memcpy( Players[i].callsign, TempPlayersInfo->players[i].callsign, CALLSIGN_LEN+1 );
3331 if (Network_game_type == IPX_GAME) {
3332 if ( (*(uint *)TempPlayersInfo->players[i].network.ipx.server) != 0 )
3333 ipx_get_local_target( TempPlayersInfo->players[i].network.ipx.server, TempPlayersInfo->players[i].network.ipx.node, Players[i].net_address );
3335 memcpy( Players[i].net_address, TempPlayersInfo->players[i].network.ipx.node, 6 );
3338 Players[i].n_packets_got=0; // How many packets we got from them
3339 Players[i].n_packets_sent=0; // How many packets we sent to them
3340 Players[i].connected = TempPlayersInfo->players[i].connected;
3341 Players[i].net_kills_total = sp->player_kills[i];
3342 Players[i].net_killed_total = sp->killed[i];
3343 if ((Network_rejoined) || (i != Player_num))
3344 Players[i].score = sp->player_score[i];
3345 for (j = 0; j < MAX_NUM_NET_PLAYERS; j++)
3347 kill_matrix[i][j] = sp->kills[i][j];
3351 if ( Player_num < 0 ) {
3352 mprintf ((0,"Bad Player_num, resetting to NETSTAT_MENU!\n"));
3353 Network_status = NETSTAT_MENU;
3357 if (Network_rejoined)
3358 for (i=0; i<N_players;i++)
3359 Players[i].net_killed_total = sp->killed[i];
3361 if (Network_rejoined) {
3362 network_process_monitor_vector(sp->monitor_vector);
3363 Players[Player_num].time_level = sp->level_time;
3366 team_kills[0] = sp->team_kills[0];
3367 team_kills[1] = sp->team_kills[1];
3369 Players[Player_num].connected = 1;
3370 NetPlayers.players[Player_num].connected = 1;
3371 NetPlayers.players[Player_num].rank=GetMyNetRanking();
3373 if (!Network_rejoined)
3374 for (i=0; i<NumNetPlayerPositions; i++) {
3375 Objects[Players[i].objnum].pos = Player_init[Netgame.locations[i]].pos;
3376 Objects[Players[i].objnum].orient = Player_init[Netgame.locations[i]].orient;
3377 obj_relink(Players[i].objnum,Player_init[Netgame.locations[i]].segnum);
3380 Objects[Players[Player_num].objnum].type = OBJ_PLAYER;
3382 mprintf ((0,"Changing to NETSTAT_PLAYING!\n"));
3383 Network_status = NETSTAT_PLAYING;
3384 Function_mode = FMODE_GAME;
3385 multi_sort_kill_list();
3390 network_send_sync(void)
3394 // Randomize their starting locations...
3396 d_srand( timer_get_fixed_seconds() );
3397 for (i=0; i<NumNetPlayerPositions; i++ )
3399 if (Players[i].connected)
3400 Players[i].connected = 1; // Get rid of endlevel connect statuses
3401 if (Game_mode & GM_MULTI_COOP)
3402 Netgame.locations[i] = i;
3406 np = d_rand() % NumNetPlayerPositions;
3407 for (j=0; j<i; j++ )
3409 if (Netgame.locations[j]==np)
3416 // np is a location that is not used anywhere else..
3417 Netgame.locations[i]=np;
3418 // mprintf((0, "Player %d starting in location %d\n" ,i ,np ));
3422 // Push current data into the sync packet
3424 network_update_netgame();
3425 Netgame.game_status = NETSTAT_PLAYING;
3426 Netgame.type = PID_SYNC;
3427 Netgame.segments_checksum = my_segments_checksum;
3429 for (i=0; i<N_players; i++ ) {
3430 if ((!Players[i].connected) || (i == Player_num))
3433 if (Network_game_type == IPX_GAME) {
3434 // Send several times, extras will be ignored
3435 send_internetwork_full_netgame_packet(NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node);
3436 send_netplayers_packet(NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node);
3439 appletalk_send_packet_data( (ubyte *)&Netgame, sizeof(netgame_info), NetPlayers.players[i].network.appletalk.node,
3440 NetPlayers.players[i].network.appletalk.net,
3441 NetPlayers.players[i].network.appletalk.socket);
3442 appletalk_send_packet_data( (ubyte *)&NetPlayers, sizeof(AllNetPlayers_info), NetPlayers.players[i].network.appletalk.node,
3443 NetPlayers.players[i].network.appletalk.net,
3444 NetPlayers.players[i].network.appletalk.socket);
3449 network_read_sync_packet(&Netgame,1); // Read it myself, as if I had sent it
3453 network_select_teams(void)
3456 newmenu_item m[MAX_PLAYERS+4];
3457 int choice, opt, opt_team_b;
3458 ubyte team_vector = 0;
3459 char team_names[2][CALLSIGN_LEN+1];
3461 int pnums[MAX_PLAYERS+2];
3463 // One-time initialization
3465 for (i = N_players/2; i < N_players; i++) // Put first half of players on team A
3467 team_vector |= (1 << i);
3470 sprintf(team_names[0], "%s", TXT_BLUE);
3471 sprintf(team_names[1], "%s", TXT_RED);
3473 // Here comes da menu
3475 m[0].type = NM_TYPE_INPUT; m[0].text = team_names[0]; m[0].text_len = CALLSIGN_LEN;
3478 for (i = 0; i < N_players; i++)
3480 if (!(team_vector & (1 << i)))
3482 m[opt].type = NM_TYPE_MENU; m[opt].text = NetPlayers.players[i].callsign; pnums[opt] = i; opt++;
3486 m[opt].type = NM_TYPE_INPUT; m[opt].text = team_names[1]; m[opt].text_len = CALLSIGN_LEN; opt++;
3487 for (i = 0; i < N_players; i++)
3489 if (team_vector & (1 << i))
3491 m[opt].type = NM_TYPE_MENU; m[opt].text = NetPlayers.players[i].callsign; pnums[opt] = i; opt++;
3494 m[opt].type = NM_TYPE_TEXT; m[opt].text = ""; opt++;
3495 m[opt].type = NM_TYPE_MENU; m[opt].text = TXT_ACCEPT; opt++;
3497 Assert(opt <= MAX_PLAYERS+4);
3499 choice = newmenu_do(NULL, TXT_TEAM_SELECTION, opt, m, NULL);
3501 if (choice == opt-1)
3503 if ((opt-2-opt_team_b < 2) || (opt_team_b == 1))
3505 nm_messagebox(NULL, 1, TXT_OK, TXT_TEAM_MUST_ONE);
3511 Netgame.team_vector = team_vector;
3512 strcpy(Netgame.team_name[0], team_names[0]);
3513 strcpy(Netgame.team_name[1], team_names[1]);
3517 else if ((choice > 0) && (choice < opt_team_b)) {
3518 team_vector |= (1 << pnums[choice]);
3520 else if ((choice > opt_team_b) && (choice < opt-2)) {
3521 team_vector &= ~(1 << pnums[choice]);
3523 else if (choice == -1)
3532 network_select_players(void)
3535 newmenu_item m[MAX_PLAYERS+4];
3536 char text[MAX_PLAYERS+4][45];
3538 int save_nplayers; //how may people would like to join
3540 network_add_player( &My_Seq );
3542 for (i=0; i< MAX_PLAYERS+4; i++ ) {
3543 sprintf( text[i], "%d. %-20s", i+1, "" );
3544 m[i].type = NM_TYPE_CHECK; m[i].text = text[i]; m[i].value = 0;
3547 m[0].value = 1; // Assume server will play...
3549 if (FindArg("-norankings"))
3550 sprintf( text[0], "%d. %-20s", 1, Players[Player_num].callsign );
3552 sprintf( text[0], "%d. %s%-20s", 1, RankStrings[NetPlayers.players[Player_num].rank],Players[Player_num].callsign );
3554 sprintf( title, "%s %d %s", TXT_TEAM_SELECT, MaxNumNetPlayers, TXT_TEAM_PRESS_ENTER );
3557 ExtGameStatus=GAMESTAT_NETGAME_PLAYER_SELECT;
3558 j=newmenu_do1( NULL, title, MAX_PLAYERS+4, m, network_start_poll, 1 );
3560 save_nplayers = N_players;
3565 // Dump all players and go back to menu mode
3568 for (i=1; i<save_nplayers; i++) {
3569 if (Network_game_type == IPX_GAME)
3570 network_dump_player(NetPlayers.players[i].network.ipx.server,NetPlayers.players[i].network.ipx.node, DUMP_ABORTED);
3573 network_dump_appletalk_player(NetPlayers.players[i].network.appletalk.node,NetPlayers.players[i].network.appletalk.net, NetPlayers.players[i].network.appletalk.socket, DUMP_ABORTED);
3578 Netgame.numplayers = 0;
3579 network_send_game_info(0); // Tell everyone we're bailing
3581 Network_status = NETSTAT_MENU;
3585 // Count number of players chosen
3588 for (i=0; i<save_nplayers; i++ )
3594 if ( N_players > Netgame.max_numplayers) {
3596 nm_messagebox( TXT_ERROR, 1, TXT_OK, "%s %d %s", TXT_SORRY_ONLY, MaxNumNetPlayers, TXT_NETPLAYERS_IN );
3598 nm_messagebox( TXT_ERROR, 1, TXT_OK, "%s %d netplayers for this game.", TXT_SORRY_ONLY, MaxNumNetPlayers );
3600 N_players = save_nplayers;
3601 goto GetPlayersAgain;
3605 if ( N_players < 2 ) {
3606 nm_messagebox( TXT_ERROR, 1, TXT_OK, TXT_TEAM_ATLEAST_TWO );
3607 N_players = save_nplayers;
3608 goto GetPlayersAgain;
3613 if ( (Netgame.gamemode == NETGAME_TEAM_ANARCHY ||
3614 Netgame.gamemode == NETGAME_CAPTURE_FLAG || Netgame.gamemode == NETGAME_TEAM_HOARD) && (N_players < 2) ) {
3615 nm_messagebox(TXT_ERROR, 1, TXT_OK, "You must select at least two\nplayers to start a team game" );
3616 N_players = save_nplayers;
3617 goto GetPlayersAgain;
3621 // Remove players that aren't marked.
3623 for (i=0; i<save_nplayers; i++ ) {
3628 if (Network_game_type == IPX_GAME) {
3629 memcpy(NetPlayers.players[N_players].network.ipx.node, NetPlayers.players[i].network.ipx.node, 6);
3630 memcpy(NetPlayers.players[N_players].network.ipx.server, NetPlayers.players[i].network.ipx.server, 4);
3632 NetPlayers.players[N_players].network.appletalk.node = NetPlayers.players[i].network.appletalk.node;
3633 NetPlayers.players[N_players].network.appletalk.net = NetPlayers.players[i].network.appletalk.net;
3634 NetPlayers.players[N_players].network.appletalk.socket = NetPlayers.players[i].network.appletalk.socket;
3636 memcpy(NetPlayers.players[N_players].callsign, NetPlayers.players[i].callsign, CALLSIGN_LEN+1);
3637 NetPlayers.players[N_players].version_major=NetPlayers.players[i].version_major;
3638 NetPlayers.players[N_players].version_minor=NetPlayers.players[i].version_minor;
3639 NetPlayers.players[N_players].rank=NetPlayers.players[i].rank;
3640 ClipRank (&NetPlayers.players[N_players].rank);
3641 network_check_for_old_version(i);
3643 Players[N_players].connected = 1;
3648 if (Network_game_type == IPX_GAME)
3649 network_dump_player(NetPlayers.players[i].network.ipx.server,NetPlayers.players[i].network.ipx.node, DUMP_DORK);
3652 network_dump_appletalk_player(NetPlayers.players[i].network.appletalk.node,NetPlayers.players[i].network.appletalk.net, NetPlayers.players[i].network.appletalk.socket, DUMP_DORK);
3657 for (i = N_players; i < MAX_NUM_NET_PLAYERS; i++) {
3658 if (Network_game_type == IPX_GAME) {
3659 memset(NetPlayers.players[i].network.ipx.node, 0, 6);
3660 memset(NetPlayers.players[i].network.ipx.server, 0, 4);
3662 NetPlayers.players[i].network.appletalk.node = 0;
3663 NetPlayers.players[i].network.appletalk.net = 0;
3664 NetPlayers.players[i].network.appletalk.socket = 0;
3666 memset(NetPlayers.players[i].callsign, 0, CALLSIGN_LEN+1);
3667 NetPlayers.players[i].version_major=0;
3668 NetPlayers.players[i].version_minor=0;
3669 NetPlayers.players[i].rank=0;
3672 mprintf ((0,"Select teams: Game mode is %d\n",Netgame.gamemode));
3674 if (Netgame.gamemode == NETGAME_TEAM_ANARCHY ||
3675 Netgame.gamemode == NETGAME_CAPTURE_FLAG ||
3676 Netgame.gamemode == NETGAME_TEAM_HOARD)
3677 if (!network_select_teams())
3684 network_start_game()
3687 char game_name[NETGAME_NAME_LEN+1];
3688 int chosen_game_mode, game_flags, level;
3690 if (Network_game_type == IPX_GAME) {
3692 Assert( FRAME_INFO_SIZE < IPX_MAX_DATA_SIZE );
3693 mprintf((0, "Using frame_info len %d, max %d.\n", FRAME_INFO_SIZE, IPX_MAX_DATA_SIZE));
3695 if ( !Network_active )
3697 nm_messagebox(NULL, 1, TXT_OK, TXT_IPX_NOT_FOUND );
3705 Assert( FRAME_INFO_SIZE < APPLETALK_MAX_DATA_SIZE );
3706 mprintf((0, "Using frame_info len %d, max %d.\n", sizeof(frame_info), APPLETALK_MAX_DATA_SIZE));
3707 if (Appletalk_active <= 0) {
3708 switch (Appletalk_active) {
3709 case APPLETALK_NOT_OPEN:
3710 sprintf(buf, "Appletalk is not currently active.\nPlease enable AppleTalk from the\nChooser and restart Descent.");
3712 case APPLETALK_BAD_LISTENER:
3713 sprintf(buf, "The Resource Fork of Descent appears damaged.\nPlease re-install Descent or contact\nMacPlay technical support.");
3715 case APPLETALK_NO_LOCAL_ADDR:
3716 sprintf(buf, "Wow! Strange!\n\nNo Local Address.");
3718 case APPLETALK_NO_SOCKET:
3719 sprintf(buf, "All AppleTalk sockets are in use.\nTry shutting down other network\napplications and restarting Descent.\n");
3722 nm_messagebox(NULL, 1, TXT_OK, buf);
3725 strcpy(Network_zone_name, DEFAULT_ZONE_NAME);
3730 change_playernum_to(0);
3732 if (network_find_game())
3734 nm_messagebox(NULL, 1, TXT_OK, TXT_NET_FULL);
3739 i = network_get_game_params( game_name, &chosen_game_mode, &game_flags, &level );
3745 // LoadLevel(level); Old, no longer used.
3747 Netgame.difficulty = Difficulty_level;
3748 Netgame.gamemode = chosen_game_mode;
3749 Netgame.game_status = NETSTAT_STARTING;
3750 Netgame.numplayers = 0;
3751 Netgame.max_numplayers = MaxNumNetPlayers;
3752 Netgame.levelnum = level;
3753 Netgame.protocol_version = MULTI_PROTO_VERSION;
3755 strcpy(Netgame.game_name, game_name);
3757 Network_status = NETSTAT_STARTING;
3760 if (Network_game_type == APPLETALK_GAME) {
3765 show_boxed_message("Registering Netgame");
3767 err = appletalk_register_netgame( game_name, TickCount() );
3768 t1 = timer_get_fixed_seconds() + F1_0;
3769 while (timer_get_fixed_seconds() < t1) ;
3771 } while ( (err == nbpDuplicate) && (count != MAX_REGISTER_TRIES) );
3772 clear_boxed_message();
3773 if ( (err == tooManyReqs) || (count == MAX_REGISTER_TRIES) ) {
3774 nm_messagebox(NULL, 1, TXT_OK, "AppleTalk Network is too busy.\nPlease try again shortly.");
3775 Game_mode = GM_GAME_OVER;
3781 network_set_game_mode(Netgame.gamemode);
3783 d_srand( timer_get_fixed_seconds() );
3784 Netgame.Security=d_rand(); // For syncing Netgames with player packets
3786 if(network_select_players())
3788 StartNewLevel(Netgame.levelnum, 0);
3791 Game_mode = GM_GAME_OVER;
3795 void restart_net_searching(newmenu_item * m)
3799 num_active_games = 0;
3801 memset(Active_games, 0, sizeof(netgame_info)*MAX_ACTIVE_NETGAMES);
3803 for (i = 0; i < MAX_ACTIVE_NETGAMES; i++)
3805 sprintf(m[i+2].text, "%d. ",i+1);
3809 NamesInfoSecurity=-1;
3810 Network_games_changed = 1;
3813 char *ModeLetters[]={"ANRCHY","TEAM","ROBO","COOP","FLAG","HOARD","TMHOARD"};
3815 int NumActiveNetgames=0;
3817 void network_join_poll( int nitems, newmenu_item * menus, int * key, int citem )
3819 // Polling loop for Join Game menu
3821 int i, osocket,join_status,temp;
3828 if ( (Network_game_type == IPX_GAME) && Network_allow_socket_changes ) {
3829 osocket = Network_socket;
3831 if ( *key==KEY_PAGEDOWN ) { Network_socket--; *key = 0; }
3832 if ( *key==KEY_PAGEUP ) { Network_socket++; *key = 0; }
3834 if (Network_socket>99)
3836 if (Network_socket<-99)
3839 if ( Network_socket+IPX_DEFAULT_SOCKET > 0x8000 )
3840 Network_socket = 0x8000 - IPX_DEFAULT_SOCKET;
3842 if ( Network_socket+IPX_DEFAULT_SOCKET < 0 )
3843 Network_socket = IPX_DEFAULT_SOCKET;
3845 if (Network_socket != osocket ) {
3846 sprintf( menus[0].text, "\t%s %+d (PgUp/PgDn to change)", TXT_CURRENT_IPX_SOCKET, Network_socket );
3847 menus[0].redraw = 1;
3848 mprintf(( 0, "Changing to socket %d\n", Network_socket ));
3850 mprintf ((0,"netgood 1!\n"));
3851 ipx_change_default_socket( IPX_DEFAULT_SOCKET + Network_socket );
3852 mprintf ((0,"netgood 2!\n"));
3853 restart_net_searching(menus);
3854 mprintf ((0,"netgood 3!\n"));
3855 network_send_game_list_request();
3856 mprintf ((0,"netgood 4!\n"));
3861 // send a request for game info every 3 seconds
3863 if (Network_game_type == IPX_GAME) {
3864 if (timer_get_approx_seconds() > t1+F1_0*3) {
3865 t1 = timer_get_approx_seconds();
3866 network_send_game_list_request();
3869 } else if (timer_get_approx_seconds() > t1+F1_0*20) {
3871 t1 = timer_get_approx_seconds();
3872 restart_net_searching(menus);
3873 show_boxed_message("Requesting list of Netgames");
3874 network_send_game_list_request();
3875 clear_boxed_message();
3880 temp=num_active_games;
3884 NumActiveNetgames=num_active_games;
3886 if (!Network_games_changed)
3889 if (temp!=num_active_games)
3890 digi_play_sample (SOUND_HUD_MESSAGE,F1_0);
3892 Network_games_changed = 0;
3893 mprintf ((0,"JOIN POLL: I'm looking at %d games!\n",num_active_games));
3895 // Copy the active games data into the menu options
3896 for (i = 0; i < num_active_games; i++)
3898 int game_status = Active_games[i].game_status;
3899 int j,x, k,tx,ty,ta,nplayers = 0;
3900 char levelname[8],MissName[25],GameName[25],thold[2];
3903 // These next two loops protect against menu skewing
3904 // if missiontitle or gamename contain a tab
3906 for (x=0,tx=0,k=0,j=0;j<15;j++)
3908 if (Active_games[i].mission_title[j]=='\t')
3910 thold[0]=Active_games[i].mission_title[j];
3911 gr_get_string_size (thold,&tx,&ty,&ta);
3913 if ((x+=tx)>=LHX(55))
3915 MissName[k]=MissName[k+1]=MissName[k+2]='.';
3920 MissName[k++]=Active_games[i].mission_title[j];
3924 for (x=0,tx=0,k=0,j=0;j<15;j++)
3926 if (Active_games[i].game_name[j]=='\t')
3928 thold[0]=Active_games[i].game_name[j];
3929 gr_get_string_size (thold,&tx,&ty,&ta);
3931 if ((x+=tx)>=LHX(55))
3933 GameName[k]=GameName[k+1]=GameName[k+2]='.';
3937 GameName[k++]=Active_games[i].game_name[j];
3942 nplayers=Active_games[i].numconnected;
3944 if (Active_games[i].levelnum < 0)
3945 sprintf(levelname, "S%d", -Active_games[i].levelnum);
3947 sprintf(levelname, "%d", Active_games[i].levelnum);
3949 if (game_status == NETSTAT_STARTING)
3951 sprintf (menus[i+2].text,"%d.\t%s \t%s \t %d/%d \t%s \t %s \t%s",
3952 i+1,GameName,ModeLetters[Active_games[i].gamemode],nplayers,
3953 Active_games[i].max_numplayers,MissName,levelname,"Forming");
3955 else if (game_status == NETSTAT_PLAYING)
3957 join_status=can_join_netgame(&Active_games[i],NULL);
3958 // mprintf ((0,"Joinstatus=%d\n",join_status));
3961 sprintf (menus[i+2].text,"%d.\t%s \t%s \t %d/%d \t%s \t %s \t%s",
3962 i+1,GameName,ModeLetters[Active_games[i].gamemode],nplayers,
3963 Active_games[i].max_numplayers,MissName,levelname,"Open");
3964 else if (join_status==2)
3965 sprintf (menus[i+2].text,"%d.\t%s \t%s \t %d/%d \t%s \t %s \t%s",
3966 i+1,GameName,ModeLetters[Active_games[i].gamemode],nplayers,
3967 Active_games[i].max_numplayers,MissName,levelname,"Full");
3968 else if (join_status==3)
3969 sprintf (menus[i+2].text,"%d.\t%s \t%s \t %d/%d \t%s \t %s \t%s",
3970 i+1,GameName,ModeLetters[Active_games[i].gamemode],nplayers,
3971 Active_games[i].max_numplayers,MissName,levelname,"Restrict");
3973 sprintf (menus[i+2].text,"%d.\t%s \t%s \t %d/%d \t%s \t %s \t%s",
3974 i+1,GameName,ModeLetters[Active_games[i].gamemode],nplayers,
3975 Active_games[i].max_numplayers,MissName,levelname,"Closed");
3979 sprintf (menus[i+2].text,"%d.\t%s \t%s \t %d/%d \t%s \t %s \t%s",
3980 i+1,GameName,ModeLetters[Active_games[i].gamemode],nplayers,
3981 Active_games[i].max_numplayers,MissName,levelname,"Between");
3984 Assert(strlen(menus[i+2].text) < 100);
3985 menus[i+2].redraw = 1;
3988 for (i = num_active_games; i < MAX_ACTIVE_NETGAMES; i++)
3990 sprintf(menus[i+2].text, "%d. ",i+1);
3991 menus[i+2].redraw = 1;
3996 network_wait_for_sync(void)
4002 Network_status = NETSTAT_WAITING;
4004 m[0].type=NM_TYPE_TEXT; m[0].text = text;
4005 m[1].type=NM_TYPE_TEXT; m[1].text = TXT_NET_LEAVE;
4007 i = network_send_request();
4012 sprintf( m[0].text, "%s\n'%s' %s", TXT_NET_WAITING, NetPlayers.players[i].callsign, TXT_NET_TO_ENTER );
4015 choice=newmenu_do( NULL, TXT_WAIT, 2, m, network_sync_poll );
4020 if (Network_status != NETSTAT_PLAYING)
4024 // if (Network_status == NETSTAT_ENDLEVEL)
4026 // network_send_endlevel_packet(0);
4027 // longjmp(LeaveGame, 0);
4030 mprintf((0, "Aborting join.\n"));
4031 me.type = PID_QUIT_JOINING;
4032 memcpy( me.player.callsign, Players[Player_num].callsign, CALLSIGN_LEN+1 );
4033 if (Network_game_type == IPX_GAME) {
4034 memcpy( me.player.network.ipx.node, ipx_get_my_local_address(), 6 );
4035 memcpy( me.player.network.ipx.server, ipx_get_my_server_address(), 4 );
4036 send_internetwork_sequence_packet(me, NetPlayers.players[0].network.ipx.server, NetPlayers.players[0].network.ipx.node);
4039 me.player.network.appletalk.node = appletalk_get_my_node();
4040 me.player.network.appletalk.net = appletalk_get_my_net();
4041 me.player.network.appletalk.socket = appletalk_get_my_socket();
4045 Function_mode = FMODE_MENU;
4046 Game_mode = GM_GAME_OVER;
4047 return(-1); // they cancelled
4053 network_request_poll( int nitems, newmenu_item * menus, int * key, int citem )
4055 // Polling loop for waiting-for-requests menu
4065 // Send our endlevel packet at regular intervals
4067 // if (timer_get_approx_seconds() > t1+ENDLEVEL_SEND_INTERVAL)
4069 // network_send_endlevel_packet();
4070 // t1 = timer_get_approx_seconds();
4075 for (i = 0; i < N_players; i++)
4077 if ((Players[i].connected == 1) || (Players[i].connected == 0))
4081 if (num_ready == N_players) // All players have checked in or are disconnected
4088 network_wait_for_requests(void)
4090 // Wait for other players to load the level before we send the sync
4094 Network_status = NETSTAT_WAITING;
4096 m[0].type=NM_TYPE_TEXT; m[0].text = TXT_NET_LEAVE;
4098 mprintf((0, "Entered wait_for_requests : N_players = %d.\n", N_players));
4100 for (choice = 0; choice < N_players; choice++)
4101 mprintf((0, "Players[%d].connected = %d.\n", choice, Players[choice].connected));
4103 Network_status = NETSTAT_WAITING;
4106 Players[Player_num].connected = 1;
4109 choice = newmenu_do(NULL, TXT_WAIT, 1, m, network_request_poll);
4114 choice = nm_messagebox(NULL, 3, TXT_YES, TXT_NO, TXT_START_NOWAIT, TXT_QUITTING_NOW);
4120 // User confirmed abort
4122 for (i=0; i < N_players; i++) {
4123 if ((Players[i].connected != 0) && (i != Player_num)) {
4124 if (Network_game_type == IPX_GAME)
4125 network_dump_player(NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node, DUMP_ABORTED);
4128 network_dump_appletalk_player(NetPlayers.players[i].network.appletalk.node, NetPlayers.players[i].network.appletalk.net, NetPlayers.players[i].network.appletalk.socket, DUMP_ABORTED);
4134 if (Network_game_type == APPLETALK_GAME)
4135 network_release_registered_game();
4137 longjmp(LeaveGame, 0);
4139 else if (choice != -2)
4143 /* Do required syncing after each level, before starting new one */
4145 network_level_sync(void)
4149 mprintf((0, "Player %d entering network_level_sync.\n", Player_num));
4151 MySyncPackInitialized = 0;
4153 // my_segments_checksum = netmisc_calc_checksum(Segments, sizeof(segment)*(Highest_segment_index+1));
4155 network_flush(); // Flush any old packets
4158 result = network_wait_for_sync();
4159 else if (network_i_am_master())
4161 network_wait_for_requests();
4162 network_send_sync();
4166 result = network_wait_for_sync();
4168 network_count_powerups_in_mine();
4172 Players[Player_num].connected = 0;
4173 network_send_endlevel_packet();
4175 if (Network_game_type == APPLETALK_GAME)
4176 network_release_registered_game();
4178 longjmp(LeaveGame, 0);
4183 void network_count_powerups_in_mine(void)
4187 for (i=0;i<MAX_POWERUP_TYPES;i++)
4188 PowerupsInMine[i]=0;
4190 for (i=0;i<=Highest_object_index;i++)
4192 if (Objects[i].type==OBJ_POWERUP)
4194 PowerupsInMine[Objects[i].id]++;
4195 if (multi_powerup_is_4pack(Objects[i].id))
4196 PowerupsInMine[Objects[i].id-1]+=4;
4204 // code to release the NBP binding of an appletalk game
4206 void network_release_registered_game()
4208 if (Network_game_type == APPLETALK_GAME)
4209 appletalk_remove_netgame();
4212 // code to sort zone lists....
4214 int zone_sort_func(const char **e0, const char **e1)
4216 return strcmp(*e0, *e1);
4219 void network_get_appletalk_zone()
4221 int num_zones, i, item, default_item;
4223 char default_zone[MAX_ZONE_LENGTH]; // my zone
4225 Network_zone_name[0] = '\0';
4227 show_boxed_message("Looking for AppleTalk Zones");
4228 num_zones = appletalk_get_zone_names(&zone_list);
4229 clear_boxed_message();
4231 if (num_zones < 0) { // error in getting zone list...maybe no router available....
4232 if ( (num_zones == tooManyReqs) || (num_zones == noDataArea) ){
4233 nm_messagebox(NULL, 1, TXT_OK, "AppleTalk Network is too busy.\nPlease try again shortly.");
4234 longjmp(LeaveGame,0);
4239 if (num_zones == 0) {
4240 strcpy(Network_zone_name, DEFAULT_ZONE_NAME);
4244 if (num_zones == 1) {
4245 Network_zone_name[0] = (char)(strlen(zone_list[0]));
4246 memcpy( &(Network_zone_name[1]), zone_list[0], strlen(zone_list[0]) );
4250 // sort the zone names
4252 for (i = 0; i < num_zones; i++)
4253 strlwr(zone_list[i]);
4255 qsort(zone_list, num_zones, sizeof(char *), zone_sort_func);
4257 // get my current zone so we can highlight that one first
4259 if (appletalk_get_my_zone(default_zone))
4262 for (i = 0; i < num_zones; i++) {
4263 if ( !stricmp(zone_list[i], default_zone) ) {
4271 item = newmenu_listbox1("AppleTalk Zones", num_zones, zone_list, 0, default_item, NULL);
4276 Network_zone_name[0] = (char)(strlen(zone_list[item]));
4277 memcpy( &(Network_zone_name[1]), zone_list[item], strlen(zone_list[item]) );
4280 for (i = 0; i < num_zones; i++)
4281 d_free(zone_list[i]);
4286 void nm_draw_background1(char * filename);
4288 void network_join_game()
4291 char menu_text[MAX_ACTIVE_NETGAMES+2][200];
4293 newmenu_item m[MAX_ACTIVE_NETGAMES+2];
4295 if (Network_game_type == IPX_GAME) {
4296 if ( !Network_active )
4298 nm_messagebox(NULL, 1, TXT_OK, TXT_IPX_NOT_FOUND);
4302 } else if (Appletalk_active <= 0) {
4305 switch (Appletalk_active) {
4306 case APPLETALK_NOT_OPEN:
4307 sprintf(buf, "Appletalk is not currently active.\nPlease enable AppleTalk from the\nChooser and restart Descent.");
4309 case APPLETALK_BAD_LISTENER:
4310 sprintf(buf, "The Resource Fork of Descent appears damaged.\nPlease re-install Descent or contact\nMacPlay technical support.");
4312 case APPLETALK_NO_LOCAL_ADDR:
4313 sprintf(buf, "Wow! Strange!\n\nNo Local Address.");
4315 case APPLETALK_NO_SOCKET:
4316 sprintf(buf, "All AppleTalk sockets are in use.\nTry shutting down other network\napplications and restarting Descent.\n");
4319 nm_messagebox(NULL, 1, TXT_OK, buf);
4331 if (Network_game_type == APPLETALK_GAME)
4332 network_get_appletalk_zone();
4335 Network_send_objects = 0;
4336 Network_sending_extras=0;
4339 Network_status = NETSTAT_BROWSING; // We are looking at a game menu
4342 network_listen(); // Throw out old info
4345 if (Network_game_type == IPX_GAME)
4346 #endif // note link to if
4347 network_send_game_list_request(); // broadcast a request for lists
4349 num_active_games = 0;
4351 memset(m, 0, sizeof(newmenu_item)*MAX_ACTIVE_NETGAMES);
4352 memset(Active_games, 0, sizeof(netgame_info)*MAX_ACTIVE_NETGAMES);
4353 memset(ActiveNetPlayers,0,sizeof(AllNetPlayers_info)*MAX_ACTIVE_NETGAMES);
4355 gr_set_fontcolor(BM_XRGB(15,15,23),-1);
4357 m[0].text = menu_text[0];
4358 m[0].type = NM_TYPE_TEXT;
4359 if (Network_game_type == IPX_GAME) {
4360 if (Network_allow_socket_changes)
4361 sprintf( m[0].text, "\tCurrent IPX Socket is default %+d (PgUp/PgDn to change)", Network_socket );
4363 strcpy( m[0].text, "" ); //sprintf( m[0].text, "" );
4366 p2cstr(Network_zone_name);
4367 if (strcmp(Network_zone_name, "*")) // only print if there is a zone name
4368 sprintf(m[0].text, "\tCurrent Zone is %s", Network_zone_name); // is Network_zone_name a pascal string????
4369 c2pstr(Network_zone_name);
4373 m[1].text=menu_text[1];
4374 m[1].type=NM_TYPE_TEXT;
4375 sprintf (m[1].text,"\tGAME \tMODE \t#PLYRS \tMISSION \tLEV \tSTATUS");
4377 for (i = 0; i < MAX_ACTIVE_NETGAMES; i++) {
4378 m[i+2].text = menu_text[i+2];
4379 m[i+2].type = NM_TYPE_MENU;
4380 sprintf(m[i+2].text, "%d. ", i+1);
4384 Network_games_changed = 1;
4387 nm_draw_background1(Menu_pcx_name); //load this here so if we abort after loading level, we restore the palette
4388 gr_palette_load(gr_palette);
4389 ExtGameStatus=GAMESTAT_JOIN_NETGAME;
4390 choice=newmenu_dotiny("NETGAMES", NULL,MAX_ACTIVE_NETGAMES+2, m, network_join_poll);
4394 Network_status = NETSTAT_MENU;
4395 return; // they cancelled
4399 if (choice >=num_active_games)
4401 nm_messagebox(TXT_SORRY, 1, TXT_OK, TXT_INVALID_CHOICE);
4405 // Choice has been made and looks legit
4406 if (Active_games[choice].game_status == NETSTAT_ENDLEVEL)
4408 nm_messagebox(TXT_SORRY, 1, TXT_OK, TXT_NET_GAME_BETWEEN2);
4412 if (Active_games[choice].protocol_version != MULTI_PROTO_VERSION)
4414 if (Active_games[choice].protocol_version == 3) {
4416 nm_messagebox(TXT_SORRY, 1, TXT_OK, "Your version of Descent 2\nis incompatible with the\nDemo version");
4419 else if (Active_games[choice].protocol_version == 4) {
4421 nm_messagebox(TXT_SORRY, 1, TXT_OK, "This Demo version of\nDescent 2 is incompatible\nwith the full commercial version");
4425 nm_messagebox(TXT_SORRY, 1, TXT_OK, TXT_VERSION_MISMATCH);
4432 // Check for valid mission name
4433 mprintf((0, "Loading mission:%s.\n", Active_games[choice].mission_name));
4434 if (!load_mission_by_name(Active_games[choice].mission_name))
4436 nm_messagebox(NULL, 1, TXT_OK, TXT_MISSION_NOT_FOUND);
4442 #if defined (D2_OEM)
4444 if (Active_games[choice].levelnum>8)
4446 nm_messagebox(NULL, 1, TXT_OK, "This OEM version only supports\nthe first 8 levels!");
4452 if (!network_wait_for_all_info (choice))
4454 nm_messagebox (TXT_SORRY,1,TXT_OK,"There was a join error!");
4455 Network_status = NETSTAT_BROWSING; // We are looking at a game menu
4459 Network_status = NETSTAT_BROWSING; // We are looking at a game menu
4461 if (!can_join_netgame(&Active_games[choice],&ActiveNetPlayers[choice]))
4463 if (Active_games[choice].numplayers == Active_games[choice].max_numplayers)
4464 nm_messagebox(TXT_SORRY, 1, TXT_OK, TXT_GAME_FULL);
4466 nm_messagebox(TXT_SORRY, 1, TXT_OK, TXT_IN_PROGRESS);
4470 // Choice is valid, prepare to join in
4472 memcpy(&Netgame, &Active_games[choice], sizeof(netgame_info));
4473 memcpy (&NetPlayers,&ActiveNetPlayers[choice],sizeof(AllNetPlayers_info));
4475 Difficulty_level = Netgame.difficulty;
4476 MaxNumNetPlayers = Netgame.max_numplayers;
4477 change_playernum_to(1);
4481 // register the joining player with NBP. This will have the nice effect of a player wanting to
4482 // join to be able to see the netgame if this player were to become the master.
4484 if (Network_game_type == APPLETALK_GAME) {
4489 show_boxed_message("Registering Netgame");
4491 err = appletalk_register_netgame( Active_games[choice].game_name, TickCount() );
4492 t1 = timer_get_fixed_seconds() + F1_0;
4493 while ( timer_get_fixed_seconds() < t1 ) ;
4495 } while ( (err == nbpDuplicate) && (count != MAX_REGISTER_TRIES) );
4496 clear_boxed_message();
4497 if ( (err == tooManyReqs) || (count == MAX_REGISTER_TRIES) ) {
4498 nm_messagebox(NULL, 1, TXT_OK, "AppleTalk Network is too busy.\nPlease try again shortly.");
4504 network_set_game_mode(Netgame.gamemode);
4506 network_AdjustMaxDataSize ();
4508 StartNewLevel(Netgame.levelnum, 0);
4510 return; // look ma, we're in a game!!!
4513 void network_AdjustMaxDataSize ()
4516 if (Netgame.ShortPackets)
4517 MaxXDataSize=NET_XDATA_SIZE;
4519 MaxXDataSize=NET_XDATA_SIZE;
4523 fix StartWaitAllTime=0;
4524 int WaitAllChoice=0;
4525 #define ALL_INFO_REQUEST_INTERVAL F1_0*3
4527 void network_wait_all_poll( int nitems, newmenu_item * menus, int * key, int citem )
4535 if (timer_get_approx_seconds() > t1+ALL_INFO_REQUEST_INTERVAL)
4537 network_send_all_info_request(PID_SEND_ALL_GAMEINFO,SecurityCheck);
4538 t1 = timer_get_approx_seconds();
4541 network_do_big_wait(WaitAllChoice);
4543 if(SecurityCheck==-1)
4547 int network_wait_for_all_info (int choice)
4553 m[0].type=NM_TYPE_TEXT; m[0].text = "Press Escape to cancel";
4555 WaitAllChoice=choice;
4556 StartWaitAllTime=timer_get_approx_seconds();
4557 SecurityCheck=Active_games[choice].Security;
4561 pick=newmenu_do( NULL, "Connecting...", 1, m, network_wait_all_poll );
4563 if (pick>-1 && SecurityCheck!=-1)
4566 if (SecurityCheck==-1)
4575 void network_do_big_wait(int choice)
4578 ubyte packet[IPX_MAX_DATA_SIZE],*data;
4579 AllNetPlayers_info *temp_info;
4580 #ifdef WORDS_BIGENDIAN
4581 AllNetPlayers_info info_struct;
4584 ubyte apacket[APPLETALK_MAX_DATA_SIZE];
4588 if (Network_game_type == APPLETALK_GAME)
4589 size=appletalk_get_packet_data( apacket );
4592 size=ipx_get_packet_data( packet );
4597 if (Network_game_type == APPLETALK_GAME)
4607 if (Network_game_type == IPX_GAME) {
4608 receive_full_netgame_packet(data, &TempNetInfo);
4610 memcpy((ubyte *)&TempNetInfo, data, sizeof(netgame_info));
4612 mprintf ((0,"This is %s game with a security of %d\n",TempNetInfo.game_name,TempNetInfo.Security));
4614 if (TempNetInfo.Security !=SecurityCheck)
4616 mprintf ((0,"Bad security on big_wait...rejecting.\n"));
4620 if (NetSecurityFlag==NETSECURITY_WAIT_FOR_GAMEINFO)
4622 if (TempPlayersInfo->Security==TempNetInfo.Security)
4624 mprintf ((0,"EQUAL !: Game=%d Players=%d ",TempPlayersInfo->Security,TempNetInfo.Security));
4625 if (TempPlayersInfo->Security==SecurityCheck)
4627 memcpy (&Active_games[choice],(ubyte *)&TempNetInfo,sizeof(netgame_info));
4628 memcpy (&ActiveNetPlayers[choice],TempPlayersInfo,sizeof(AllNetPlayers_info));
4635 NetSecurityFlag=NETSECURITY_WAIT_FOR_PLAYERS;
4636 NetSecurityNum=TempNetInfo.Security;
4638 if (network_wait_for_playerinfo())
4640 mprintf ((0,"HUH? Game=%d Player=%d\n",NetSecurityNum,TempPlayersInfo->Security));
4641 memcpy (&Active_games[choice],(ubyte *)&TempNetInfo,sizeof(netgame_info));
4642 memcpy (&ActiveNetPlayers[choice],TempPlayersInfo,sizeof(AllNetPlayers_info));
4649 case PID_PLAYERSINFO:
4650 mprintf ((0,"Got a PID_PLAYERSINFO!\n"));
4652 if (Network_game_type == IPX_GAME) {
4653 #ifndef WORDS_BIGENDIAN
4654 temp_info=(AllNetPlayers_info *)data;
4656 receive_netplayers_packet(data, &info_struct);
4657 temp_info = &info_struct;
4660 temp_info = (AllNetPlayers_info *)data;
4662 if (temp_info->Security!=SecurityCheck)
4663 break; // If this isn't the guy we're looking for, move on
4665 memcpy (&TempPlayersBase,(ubyte *)&temp_info,sizeof(AllNetPlayers_info));
4666 TempPlayersInfo=&TempPlayersBase;
4667 WaitingForPlayerInfo=0;
4668 NetSecurityNum=TempPlayersInfo->Security;
4669 NetSecurityFlag=NETSECURITY_WAIT_FOR_GAMEINFO;
4675 void network_leave_game()
4679 network_do_frame(1, 1);
4682 fclose (SendLogFile);
4683 fclose (RecieveLogFile);
4686 if ((network_i_am_master()))
4688 while (Network_sending_extras>1 && Player_joining_extras!=-1)
4689 network_send_extras();
4691 Netgame.numplayers = 0;
4694 network_send_game_info(NULL);
4697 mprintf ((0,"HEY! I'm master and I've left.\n"));
4700 Players[Player_num].connected = 0;
4701 network_send_endlevel_packet();
4702 change_playernum_to(0);
4703 Game_mode = GM_GAME_OVER;
4704 write_player_file();
4706 // WIN(ipx_destroy_read_thread());
4711 void network_flush()
4714 ubyte apacket[APPLETALK_MAX_DATA_SIZE];
4716 ubyte packet[IPX_MAX_DATA_SIZE];
4719 if ( (Network_game_type == APPLETALK_GAME) && (Appletalk_active <= 0) )
4723 if ( Network_game_type == IPX_GAME )
4724 if (!Network_active) return;
4727 if (Network_game_type == APPLETALK_GAME)
4728 while (appletalk_get_packet_data(apacket) > 0) ;
4731 while (ipx_get_packet_data(packet) > 0) ;
4734 void network_listen()
4737 ubyte apacket[APPLETALK_MAX_DATA_SIZE];
4740 ubyte packet[IPX_MAX_DATA_SIZE];
4743 if (Network_status==NETSTAT_PLAYING && Netgame.ShortPackets && !Network_send_objects)
4745 loopmax=N_players*Netgame.PacketsPerSec;
4749 if ( (Network_game_type == APPLETALK_GAME) && (Appletalk_active <= 0) )
4753 if (Network_game_type == IPX_GAME)
4754 if (!Network_active) return;
4756 if (!(Game_mode & GM_NETWORK) && (Function_mode == FMODE_GAME))
4757 mprintf((0, "Calling network_listen() when not in net game.\n"));
4759 WaitingForPlayerInfo=1;
4760 NetSecurityFlag=NETSECURITY_OFF;
4763 if (Network_game_type == IPX_GAME) {
4764 size = ipx_get_packet_data( packet );
4766 network_process_packet( packet, size );
4769 size = ipx_get_packet_data( packet );
4773 size = appletalk_get_packet_data( apacket );
4775 network_process_packet( apacket, size );
4778 size = appletalk_get_packet_data( apacket );
4784 int network_wait_for_playerinfo()
4787 ubyte packet[IPX_MAX_DATA_SIZE];
4788 struct AllNetPlayers_info *TempInfo;
4791 #ifdef WORDS_BIGENDIAN
4792 AllNetPlayers_info info_struct;
4795 ubyte apacket[APPLETALK_MAX_DATA_SIZE];
4799 if ( (Network_game_type == APPLETALK_GAME) && (Appletalk_active <= 0) )
4803 if ( Network_game_type == IPX_GAME)
4804 if (!Network_active) return(0);
4806 // if (!WaitingForPlayerInfo)
4809 if (!(Game_mode & GM_NETWORK) && (Function_mode == FMODE_GAME))
4811 mprintf((0, "Calling network_wait_for_playerinfo() when not in net game.\n"));
4813 if (Network_status==NETSTAT_PLAYING)
4815 Int3(); //MY GOD! Get Jason...this is the source of many problems
4818 basetime=timer_get_approx_seconds();
4820 while (WaitingForPlayerInfo && retries<50 && (timer_get_approx_seconds()<(basetime+(F1_0*5))))
4822 if (Network_game_type == IPX_GAME) {
4823 size = ipx_get_packet_data( packet );
4827 size = appletalk_get_packet_data( apacket );
4832 if (size>0 && id==PID_PLAYERSINFO)
4834 #ifdef WORDS_BIGENDIAN
4836 if (Network_game_type == APPLETALK_GAME) {
4837 TempInfo = (AllNetPlayers_info *)apacket;
4841 receive_netplayers_packet(packet, &info_struct);
4842 TempInfo = &info_struct;
4845 TempInfo=(AllNetPlayers_info *)packet;
4850 if (NetSecurityFlag==NETSECURITY_WAIT_FOR_PLAYERS)
4852 if (NetSecurityNum==TempInfo->Security)
4854 mprintf ((0,"HEYEQUAL: Player=%d Game=%d\n",TempInfo->Security,NetSecurityNum));
4855 memcpy (&TempPlayersBase,(ubyte *)TempInfo,sizeof(AllNetPlayers_info));
4856 TempPlayersInfo=&TempPlayersBase;
4857 NetSecurityFlag=NETSECURITY_OFF;
4859 WaitingForPlayerInfo=0;
4867 mprintf ((0,"I'm original!\n"));
4869 NetSecurityNum=TempInfo->Security;
4870 NetSecurityFlag=NETSECURITY_WAIT_FOR_GAMEINFO;
4872 memcpy (&TempPlayersBase,(ubyte *)TempInfo,sizeof(AllNetPlayers_info));
4873 TempPlayersInfo=&TempPlayersBase;
4874 WaitingForPlayerInfo=0;
4883 void network_send_data( ubyte * ptr, int len, int urgent )
4889 fprintf (SendLogFile,"Packet type: %d Len:%d Urgent:%d TT=%d\n",ptr[0],len,urgent,TTSent[ptr[0]]);
4890 fflush (SendLogFile);
4893 if (Endlevel_sequence)
4896 if (!MySyncPackInitialized) {
4897 MySyncPackInitialized = 1;
4898 memset( &MySyncPack, 0, sizeof(frame_info) );
4904 if ((MySyncPack.data_size+len) > MaxXDataSize ) {
4906 network_do_frame(1, 0);
4907 if (MySyncPack.data_size != 0) {
4908 mprintf((0, "%d bytes were added to data by network_do_frame!\n", MySyncPack.data_size));
4911 // Int3(); // Trying to send too much!
4913 mprintf((0, "Packet overflow, sending additional packet, type %d len %d.\n", ptr[0], len));
4914 Assert(check == ptr[0]);
4917 Assert(MySyncPack.data_size+len <= MaxXDataSize);
4919 memcpy( &MySyncPack.data[MySyncPack.data_size], ptr, len );
4920 MySyncPack.data_size += len;
4923 void network_timeout_player(int playernum)
4925 // Remove a player from the game if we haven't heard from them in
4929 Assert(playernum < N_players);
4930 Assert(playernum > -1);
4932 network_disconnect_player(playernum);
4933 create_player_appearance_effect(&Objects[Players[playernum].objnum]);
4935 digi_play_sample(SOUND_HUD_MESSAGE, F1_0);
4937 HUD_init_message("%s %s", Players[playernum].callsign, TXT_DISCONNECTING);
4938 for (i = 0; i < N_players; i++)
4939 if (Players[i].connected)
4944 nm_messagebox(NULL, 1, TXT_OK, TXT_YOU_ARE_ONLY);
4948 fix last_send_time = 0;
4949 fix last_timeout_check = 0;
4951 #ifdef WORDS_BIGENDIAN
4952 void squish_short_frame_info(short_frame_info old_info, ubyte *data)
4958 data[0] = old_info.type; loc++;
4959 /* skip three for pad byte */ loc += 3;
4960 tmpi = INTEL_INT(old_info.numpackets);
4961 memcpy(&(data[loc]), &tmpi, 4); loc += 4;
4963 memcpy(&(data[loc]), old_info.thepos.bytemat, 9); loc += 9;
4964 tmps = INTEL_SHORT(old_info.thepos.xo);
4965 memcpy(&(data[loc]), &tmps, 2); loc += 2;
4966 tmps = INTEL_SHORT(old_info.thepos.yo);
4967 memcpy(&(data[loc]), &tmps, 2); loc += 2;
4968 tmps = INTEL_SHORT(old_info.thepos.zo);
4969 memcpy(&(data[loc]), &tmps, 2); loc += 2;
4970 tmps = INTEL_SHORT(old_info.thepos.segment);
4971 memcpy(&(data[loc]), &tmps, 2); loc += 2;
4972 tmps = INTEL_SHORT(old_info.thepos.velx);
4973 memcpy(&(data[loc]), &tmps, 2); loc += 2;
4974 tmps = INTEL_SHORT(old_info.thepos.vely);
4975 memcpy(&(data[loc]), &tmps, 2); loc += 2;
4976 tmps = INTEL_SHORT(old_info.thepos.velz);
4977 memcpy(&(data[loc]), &tmps, 2); loc += 2;
4979 tmps = INTEL_SHORT(old_info.data_size);
4980 memcpy(&(data[loc]), &tmps, 2); loc += 2;
4982 data[loc] = old_info.playernum; loc++;
4983 data[loc] = old_info.obj_render_type; loc++;
4984 data[loc] = old_info.level_num; loc++;
4985 memcpy(&(data[loc]), old_info.data, old_info.data_size);
4989 char NakedBuf[NET_XDATA_SIZE+4];
4990 int NakedPacketLen=0;
4991 int NakedPacketDestPlayer=-1;
4993 void network_do_frame(int force, int listen)
4996 short_frame_info ShortSyncPack;
4997 static fix LastEndlevel=0;
4999 if (!(Game_mode&GM_NETWORK)) return;
5001 if ((Network_status != NETSTAT_PLAYING) || (Endlevel_sequence)) // Don't send postion during escape sequence...
5006 Assert (NakedPacketDestPlayer>-1);
5007 // mprintf ((0,"Sending a naked packet to %s (%d bytes)!\n",Players[NakedPacketDestPlayer].callsign,NakedPacketLen));
5008 if (Network_game_type == IPX_GAME)
5009 ipx_send_packet_data( (ubyte *)NakedBuf, NakedPacketLen, NetPlayers.players[NakedPacketDestPlayer].network.ipx.server, NetPlayers.players[NakedPacketDestPlayer].network.ipx.node,Players[NakedPacketDestPlayer].net_address );
5012 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 );
5015 NakedPacketDestPlayer=-1;
5018 if (WaitForRefuseAnswer && timer_get_approx_seconds()>(RefuseTimeLimit+(F1_0*12)))
5019 WaitForRefuseAnswer=0;
5021 last_send_time += FrameTime;
5022 last_timeout_check += FrameTime;
5024 // Send out packet PacksPerSec times per second maximum... unless they fire, then send more often...
5025 if ( (last_send_time>F1_0/Netgame.PacketsPerSec) || (Network_laser_fired) || force || PacketUrgent ) {
5026 if ( Players[Player_num].connected ) {
5027 int objnum = Players[Player_num].objnum;
5031 multi_send_robot_frame(0);
5032 multi_send_fire(); // Do firing if needed..
5037 if (Netgame.ShortPackets)
5039 #ifdef WORDS_BIGENDIAN
5040 ubyte send_data[IPX_MAX_DATA_SIZE];
5041 //int squished_size;
5043 create_shortpos(&ShortSyncPack.thepos, Objects+objnum, 0);
5044 ShortSyncPack.type = PID_PDATA;
5045 ShortSyncPack.playernum = Player_num;
5046 ShortSyncPack.obj_render_type = Objects[objnum].render_type;
5047 ShortSyncPack.level_num = Current_level_num;
5048 ShortSyncPack.data_size = MySyncPack.data_size;
5049 memcpy (&ShortSyncPack.data[0],&MySyncPack.data[0],MySyncPack.data_size);
5051 for (i=0; i<N_players; i++ ) {
5052 if ( (Players[i].connected) && (i!=Player_num ) ) {
5053 MySyncPack.numpackets = Players[i].n_packets_sent++;
5054 ShortSyncPack.numpackets=MySyncPack.numpackets;
5055 if (Network_game_type == IPX_GAME) {
5056 #ifndef WORDS_BIGENDIAN
5057 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 );
5059 squish_short_frame_info(ShortSyncPack, send_data);
5060 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 );
5064 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 );
5070 else // If long packets
5074 MySyncPack.type = PID_PDATA;
5075 MySyncPack.playernum = Player_num;
5076 MySyncPack.obj_render_type = Objects[objnum].render_type;
5077 MySyncPack.level_num = Current_level_num;
5078 MySyncPack.obj_segnum = Objects[objnum].segnum;
5079 MySyncPack.obj_pos = Objects[objnum].pos;
5080 MySyncPack.obj_orient = Objects[objnum].orient;
5081 MySyncPack.phys_velocity = Objects[objnum].mtype.phys_info.velocity;
5082 MySyncPack.phys_rotvel = Objects[objnum].mtype.phys_info.rotvel;
5084 send_data_size = MySyncPack.data_size; // do this so correct size data is sent
5086 #ifdef WORDS_BIGENDIAN // do the swap stuff
5087 if (Network_game_type == IPX_GAME) {
5088 MySyncPack.obj_segnum = INTEL_SHORT(MySyncPack.obj_segnum);
5089 MySyncPack.obj_pos.x = INTEL_INT((int)MySyncPack.obj_pos.x);
5090 MySyncPack.obj_pos.y = INTEL_INT((int)MySyncPack.obj_pos.y);
5091 MySyncPack.obj_pos.z = INTEL_INT((int)MySyncPack.obj_pos.z);
5093 MySyncPack.obj_orient.rvec.x = INTEL_INT((int)MySyncPack.obj_orient.rvec.x);
5094 MySyncPack.obj_orient.rvec.y = INTEL_INT((int)MySyncPack.obj_orient.rvec.y);
5095 MySyncPack.obj_orient.rvec.z = INTEL_INT((int)MySyncPack.obj_orient.rvec.z);
5096 MySyncPack.obj_orient.uvec.x = INTEL_INT((int)MySyncPack.obj_orient.uvec.x);
5097 MySyncPack.obj_orient.uvec.y = INTEL_INT((int)MySyncPack.obj_orient.uvec.y);
5098 MySyncPack.obj_orient.uvec.z = INTEL_INT((int)MySyncPack.obj_orient.uvec.z);
5099 MySyncPack.obj_orient.fvec.x = INTEL_INT((int)MySyncPack.obj_orient.fvec.x);
5100 MySyncPack.obj_orient.fvec.y = INTEL_INT((int)MySyncPack.obj_orient.fvec.y);
5101 MySyncPack.obj_orient.fvec.z = INTEL_INT((int)MySyncPack.obj_orient.fvec.z);
5103 MySyncPack.phys_velocity.x = INTEL_INT((int)MySyncPack.phys_velocity.x);
5104 MySyncPack.phys_velocity.y = INTEL_INT((int)MySyncPack.phys_velocity.y);
5105 MySyncPack.phys_velocity.z = INTEL_INT((int)MySyncPack.phys_velocity.z);
5107 MySyncPack.phys_rotvel.x = INTEL_INT((int)MySyncPack.phys_rotvel.x);
5108 MySyncPack.phys_rotvel.y = INTEL_INT((int)MySyncPack.phys_rotvel.y);
5109 MySyncPack.phys_rotvel.z = INTEL_INT((int)MySyncPack.phys_rotvel.z);
5111 MySyncPack.data_size = INTEL_SHORT(MySyncPack.data_size);
5115 for (i=0; i<N_players; i++ ) {
5116 if ( (Players[i].connected) && (i!=Player_num ) ) {
5117 if (Network_game_type == IPX_GAME)
5118 MySyncPack.numpackets = INTEL_INT(Players[i].n_packets_sent);
5120 MySyncPack.numpackets = Players[i].n_packets_sent;
5122 Players[i].n_packets_sent++;
5123 if (Network_game_type == IPX_GAME)
5124 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 );
5127 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);
5133 MySyncPack.data_size = 0; // Start data over at 0 length.
5134 if (Control_center_destroyed)
5137 Players[Player_num].connected=3;
5138 if (timer_get_approx_seconds() > (LastEndlevel+(F1_0/2)))
5140 network_send_endlevel_packet();
5141 LastEndlevel=timer_get_approx_seconds();
5144 //mprintf( (0, "Packet has %d bytes appended (TS=%d)\n", MySyncPack.data_size, sizeof(frame_info)-MaxXDataSize+MySyncPack.data_size ));
5151 if ((last_timeout_check > F1_0) && !(Control_center_destroyed))
5153 fix approx_time = timer_get_approx_seconds();
5154 // Check for player timeouts
5155 for (i = 0; i < N_players; i++)
5157 if ((i != Player_num) && (Players[i].connected == 1))
5159 if ((LastPacketTime[i] == 0) || (LastPacketTime[i] > approx_time))
5161 LastPacketTime[i] = approx_time;
5164 if ((approx_time - LastPacketTime[i]) > (15*F1_0))
5165 network_timeout_player(i);
5168 last_timeout_check = 0;
5174 MySyncPack.data_size = 0;
5179 if (VerifyPlayerJoined!=-1 && !(FrameCount & 63))
5180 resend_sync_due_to_packet_loss_for_allender(); // This will resend to network_player_rejoining
5182 if (Network_send_objects)
5183 network_send_objects();
5185 if (Network_sending_extras && VerifyPlayerJoined==-1)
5187 network_send_extras();
5192 int missed_packets = 0;
5194 int ConsistencyCount = 0;
5196 void network_consistency_error(void)
5198 if (++ConsistencyCount < 10)
5201 Function_mode = FMODE_MENU;
5203 nm_messagebox(NULL, 1, TXT_OK, TXT_CONSISTENCY_ERROR);
5205 nm_messagebox(NULL, 1, TXT_OK, "Failed to join the netgame.\nYou are missing packets. Check\nyour network connection and\ntry again.");
5207 Function_mode = FMODE_GAME;
5208 ConsistencyCount = 0;
5209 multi_quit_game = 1;
5210 multi_leave_menu = 1;
5211 multi_reset_stuff();
5212 Function_mode = FMODE_MENU;
5215 void network_process_pdata (char *data)
5217 Assert (Game_mode & GM_NETWORK);
5219 if (Netgame.ShortPackets)
5220 network_read_pdata_short_packet ((short_frame_info *)data);
5222 network_read_pdata_packet ((frame_info *)data);
5225 void network_read_pdata_packet(frame_info *pd )
5229 object * TheirObj = NULL;
5231 // frame_info should be aligned...for mac, make the necessary adjustments
5232 #ifdef WORDS_BIGENDIAN
5233 if (Network_game_type == IPX_GAME) {
5234 pd->numpackets = INTEL_INT(pd->numpackets);
5235 pd->obj_pos.x = INTEL_INT(pd->obj_pos.x);
5236 pd->obj_pos.y = INTEL_INT(pd->obj_pos.y);
5237 pd->obj_pos.z = INTEL_INT(pd->obj_pos.z);
5239 pd->obj_orient.rvec.x = (fix)INTEL_INT((int)pd->obj_orient.rvec.x);
5240 pd->obj_orient.rvec.y = (fix)INTEL_INT((int)pd->obj_orient.rvec.y);
5241 pd->obj_orient.rvec.z = (fix)INTEL_INT((int)pd->obj_orient.rvec.z);
5242 pd->obj_orient.uvec.x = (fix)INTEL_INT((int)pd->obj_orient.uvec.x);
5243 pd->obj_orient.uvec.y = (fix)INTEL_INT((int)pd->obj_orient.uvec.y);
5244 pd->obj_orient.uvec.z = (fix)INTEL_INT((int)pd->obj_orient.uvec.z);
5245 pd->obj_orient.fvec.x = (fix)INTEL_INT((int)pd->obj_orient.fvec.x);
5246 pd->obj_orient.fvec.y = (fix)INTEL_INT((int)pd->obj_orient.fvec.y);
5247 pd->obj_orient.fvec.z = (fix)INTEL_INT((int)pd->obj_orient.fvec.z);
5249 pd->phys_velocity.x = (fix)INTEL_INT((int)pd->phys_velocity.x);
5250 pd->phys_velocity.y = (fix)INTEL_INT((int)pd->phys_velocity.y);
5251 pd->phys_velocity.z = (fix)INTEL_INT((int)pd->phys_velocity.z);
5253 pd->phys_rotvel.x = (fix)INTEL_INT((int)pd->phys_rotvel.x);
5254 pd->phys_rotvel.y = (fix)INTEL_INT((int)pd->phys_rotvel.y);
5255 pd->phys_rotvel.z = (fix)INTEL_INT((int)pd->phys_rotvel.z);
5257 pd->obj_segnum = INTEL_SHORT(pd->obj_segnum);
5258 pd->data_size = INTEL_SHORT(pd->data_size);
5262 TheirPlayernum = pd->playernum;
5263 TheirObjnum = Players[pd->playernum].objnum;
5265 if (TheirPlayernum < 0) {
5266 Int3(); // This packet is bogus!!
5270 if (VerifyPlayerJoined!=-1 && TheirPlayernum==VerifyPlayerJoined)
5272 // Hurray! Someone really really got in the game (I think).
5273 mprintf ((0,"Hurray! VPJ (%d) reset!\n",VerifyPlayerJoined));
5274 VerifyPlayerJoined=-1;
5277 if (!multi_quit_game && (TheirPlayernum >= N_players)) {
5278 if (Network_status!=NETSTAT_WAITING)
5280 Int3(); // We missed an important packet!
5281 network_consistency_error();
5287 if (Endlevel_sequence || (Network_status == NETSTAT_ENDLEVEL) ) {
5288 int old_Endlevel_sequence = Endlevel_sequence;
5289 Endlevel_sequence = 1;
5290 if ( pd->data_size>0 ) {
5291 // pass pd->data to some parser function....
5292 multi_process_bigdata( pd->data, pd->data_size );
5294 Endlevel_sequence = old_Endlevel_sequence;
5297 // mprintf((0, "Gametime = %d, Frametime = %d.\n", GameTime, FrameTime));
5299 if ((byte)pd->level_num != Current_level_num)
5301 mprintf((0, "Got frame packet from player %d wrong level %d!\n", pd->playernum, pd->level_num));
5305 TheirObj = &Objects[TheirObjnum];
5307 //------------- Keep track of missed packets -----------------
5308 Players[TheirPlayernum].n_packets_got++;
5310 LastPacketTime[TheirPlayernum] = timer_get_approx_seconds();
5312 if ( pd->numpackets != Players[TheirPlayernum].n_packets_got ) {
5315 missed_packets = pd->numpackets-Players[TheirPlayernum].n_packets_got;
5316 if ((pd->numpackets-Players[TheirPlayernum].n_packets_got)>0)
5317 TotalMissedPackets += pd->numpackets-Players[TheirPlayernum].n_packets_got;
5319 if ( missed_packets > 0 )
5320 mprintf(( 0, "Missed %d packets from player #%d (%d total)\n", pd->numpackets-Players[TheirPlayernum].n_packets_got, TheirPlayernum, missed_packets ));
5322 mprintf( (0, "Got %d late packets from player #%d (%d total)\n", Players[TheirPlayernum].n_packets_got-pd->numpackets, TheirPlayernum, missed_packets ));
5325 #ifdef APPLETALK_DEBUG
5326 if (Network_game_type == APPLETALK_GAME) {
5327 if ( missed_packets > 0 )
5328 fprintf( at_fp, "Missed %d packets from player #%d (%d total)\n", pd->numpackets-Players[TheirPlayernum].n_packets_got, TheirPlayernum, missed_packets );
5330 fprintf( at_fp, "Got %d late packets from player #%d (%d total)\n", Players[TheirPlayernum].n_packets_got-pd->numpackets, TheirPlayernum, missed_packets );
5335 if (Network_game_type == IPX_GAME) {
5336 if ( missed_packets > 0 )
5337 fprintf( ipx_fp, "Missed %d packets from player #%d (%d total)\n", pd->numpackets-Players[TheirPlayernum].n_packets_got, TheirPlayernum, missed_packets );
5339 fprintf( ipx_fp, "Got %d late packets from player #%d (%d total)\n", Players[TheirPlayernum].n_packets_got-pd->numpackets, TheirPlayernum, missed_packets );
5344 Players[TheirPlayernum].n_packets_got = pd->numpackets;
5347 //------------ Read the player's ship's object info ----------------------
5348 TheirObj->pos = pd->obj_pos;
5349 TheirObj->orient = pd->obj_orient;
5350 TheirObj->mtype.phys_info.velocity = pd->phys_velocity;
5351 TheirObj->mtype.phys_info.rotvel = pd->phys_rotvel;
5353 if ((TheirObj->render_type != pd->obj_render_type) && (pd->obj_render_type == RT_POLYOBJ))
5354 multi_make_ghost_player(TheirPlayernum);
5356 obj_relink(TheirObjnum,pd->obj_segnum);
5358 if (TheirObj->movement_type == MT_PHYSICS)
5359 set_thrust_from_velocity(TheirObj);
5361 //------------ Welcome them back if reconnecting --------------
5362 if (!Players[TheirPlayernum].connected) {
5363 Players[TheirPlayernum].connected = 1;
5365 if (Newdemo_state == ND_STATE_RECORDING)
5366 newdemo_record_multi_reconnect(TheirPlayernum);
5368 multi_make_ghost_player(TheirPlayernum);
5370 create_player_appearance_effect(&Objects[TheirObjnum]);
5372 digi_play_sample( SOUND_HUD_MESSAGE, F1_0);
5374 ClipRank (&NetPlayers.players[TheirPlayernum].rank);
5376 if (FindArg("-norankings"))
5377 HUD_init_message( "'%s' %s", Players[TheirPlayernum].callsign, TXT_REJOIN );
5379 HUD_init_message( "%s'%s' %s", RankStrings[NetPlayers.players[TheirPlayernum].rank],Players[TheirPlayernum].callsign, TXT_REJOIN );
5385 //------------ Parse the extra data at the end ---------------
5387 if ( pd->data_size>0 ) {
5388 // pass pd->data to some parser function....
5389 multi_process_bigdata( pd->data, pd->data_size );
5394 #ifdef WORDS_BIGENDIAN
5395 void get_short_frame_info(ubyte *old_info, short_frame_info *new_info)
5399 new_info->type = old_info[loc]; loc++;
5400 /* skip three for pad byte */ loc += 3;
5401 memcpy(&(new_info->numpackets), &(old_info[loc]), 4); loc += 4;
5402 new_info->numpackets = INTEL_INT(new_info->numpackets);
5403 memcpy(new_info->thepos.bytemat, &(old_info[loc]), 9); loc += 9;
5404 memcpy(&(new_info->thepos.xo), &(old_info[loc]), 2); loc += 2;
5405 memcpy(&(new_info->thepos.yo), &(old_info[loc]), 2); loc += 2;
5406 memcpy(&(new_info->thepos.zo), &(old_info[loc]), 2); loc += 2;
5407 memcpy(&(new_info->thepos.segment), &(old_info[loc]), 2); loc += 2;
5408 memcpy(&(new_info->thepos.velx), &(old_info[loc]), 2); loc += 2;
5409 memcpy(&(new_info->thepos.vely), &(old_info[loc]), 2); loc += 2;
5410 memcpy(&(new_info->thepos.velz), &(old_info[loc]), 2); loc += 2;
5411 new_info->thepos.xo = INTEL_SHORT(new_info->thepos.xo);
5412 new_info->thepos.yo = INTEL_SHORT(new_info->thepos.yo);
5413 new_info->thepos.zo = INTEL_SHORT(new_info->thepos.zo);
5414 new_info->thepos.segment = INTEL_SHORT(new_info->thepos.segment);
5415 new_info->thepos.velx = INTEL_SHORT(new_info->thepos.velx);
5416 new_info->thepos.vely = INTEL_SHORT(new_info->thepos.vely);
5417 new_info->thepos.velz = INTEL_SHORT(new_info->thepos.velz);
5419 memcpy(&(new_info->data_size), &(old_info[loc]), 2); loc += 2;
5420 new_info->data_size = INTEL_SHORT(new_info->data_size);
5421 new_info->playernum = old_info[loc]; loc++;
5422 new_info->obj_render_type = old_info[loc]; loc++;
5423 new_info->level_num = old_info[loc]; loc++;
5424 memcpy(new_info->data, &(old_info[loc]), new_info->data_size);
5427 #define get_short_frame_info(old_info, new_info) \
5428 memcpy(new_info, old_info, sizeof(short_frame_info))
5431 void network_read_pdata_short_packet(short_frame_info *pd )
5435 object * TheirObj = NULL;
5436 short_frame_info new_pd;
5438 // short frame info is not aligned because of shortpos. The mac
5439 // will call totally hacked and gross function to fix this up.
5441 if (Network_game_type == IPX_GAME) {
5442 get_short_frame_info((ubyte *)pd, &new_pd);
5444 memcpy(&new_pd, (ubyte *)pd, sizeof(short_frame_info));
5447 TheirPlayernum = new_pd.playernum;
5448 TheirObjnum = Players[new_pd.playernum].objnum;
5450 if (TheirPlayernum < 0) {
5451 Int3(); // This packet is bogus!!
5454 if (!multi_quit_game && (TheirPlayernum >= N_players)) {
5455 if (Network_status!=NETSTAT_WAITING)
5457 Int3(); // We missed an important packet!
5458 network_consistency_error();
5465 if (VerifyPlayerJoined!=-1 && TheirPlayernum==VerifyPlayerJoined)
5467 // Hurray! Someone really really got in the game (I think).
5468 mprintf ((0,"Hurray! VPJ (%d) reset!\n",VerifyPlayerJoined));
5469 VerifyPlayerJoined=-1;
5472 if (Endlevel_sequence || (Network_status == NETSTAT_ENDLEVEL) ) {
5473 int old_Endlevel_sequence = Endlevel_sequence;
5474 Endlevel_sequence = 1;
5475 if ( new_pd.data_size>0 ) {
5476 // pass pd->data to some parser function....
5477 multi_process_bigdata( new_pd.data, new_pd.data_size );
5479 Endlevel_sequence = old_Endlevel_sequence;
5482 // mprintf((0, "Gametime = %d, Frametime = %d.\n", GameTime, FrameTime));
5484 if ((byte)new_pd.level_num != Current_level_num)
5486 mprintf((0, "Got frame packet from player %d wrong level %d!\n", new_pd.playernum, new_pd.level_num));
5490 TheirObj = &Objects[TheirObjnum];
5492 //------------- Keep track of missed packets -----------------
5493 Players[TheirPlayernum].n_packets_got++;
5495 LastPacketTime[TheirPlayernum] = timer_get_approx_seconds();
5497 if ( new_pd.numpackets != Players[TheirPlayernum].n_packets_got ) {
5500 missed_packets = new_pd.numpackets-Players[TheirPlayernum].n_packets_got;
5501 if ((new_pd.numpackets-Players[TheirPlayernum].n_packets_got)>0)
5502 TotalMissedPackets += new_pd.numpackets-Players[TheirPlayernum].n_packets_got;
5504 if ( missed_packets > 0 )
5505 mprintf( (0, "Missed %d packets from player #%d (%d total)\n", new_pd.numpackets-Players[TheirPlayernum].n_packets_got, TheirPlayernum, missed_packets ));
5507 mprintf( (0, "Got %d late packets from player #%d (%d total)\n", Players[TheirPlayernum].n_packets_got-new_pd.numpackets, TheirPlayernum, missed_packets ));
5509 Players[TheirPlayernum].n_packets_got = new_pd.numpackets;
5512 //------------ Read the player's ship's object info ----------------------
5514 extract_shortpos(TheirObj, &new_pd.thepos, 0);
5516 if ((TheirObj->render_type != new_pd.obj_render_type) && (new_pd.obj_render_type == RT_POLYOBJ))
5517 multi_make_ghost_player(TheirPlayernum);
5519 if (TheirObj->movement_type == MT_PHYSICS)
5520 set_thrust_from_velocity(TheirObj);
5522 //------------ Welcome them back if reconnecting --------------
5523 if (!Players[TheirPlayernum].connected) {
5524 Players[TheirPlayernum].connected = 1;
5526 if (Newdemo_state == ND_STATE_RECORDING)
5527 newdemo_record_multi_reconnect(TheirPlayernum);
5529 multi_make_ghost_player(TheirPlayernum);
5531 create_player_appearance_effect(&Objects[TheirObjnum]);
5533 digi_play_sample( SOUND_HUD_MESSAGE, F1_0);
5534 ClipRank (&NetPlayers.players[TheirPlayernum].rank);
5536 if (FindArg("-norankings"))
5537 HUD_init_message( "'%s' %s", Players[TheirPlayernum].callsign, TXT_REJOIN );
5539 HUD_init_message( "%s'%s' %s", RankStrings[NetPlayers.players[TheirPlayernum].rank],Players[TheirPlayernum].callsign, TXT_REJOIN );
5545 //------------ Parse the extra data at the end ---------------
5547 if ( new_pd.data_size>0 ) {
5548 // pass pd->data to some parser function....
5549 multi_process_bigdata( new_pd.data, new_pd.data_size );
5555 void network_set_power (void)
5557 int opt=0,choice,opt_primary,opt_second,opt_power;
5561 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Laser upgrade"; m[opt].value=Netgame.DoLaserUpgrade; opt++;
5562 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Super lasers"; m[opt].value=Netgame.DoSuperLaser; opt++;
5563 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Quad Lasers"; m[opt].value=Netgame.DoQuadLasers; opt++;
5564 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Vulcan cannon"; m[opt].value=Netgame.DoVulcan; opt++;
5565 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Spreadfire cannon"; m[opt].value=Netgame.DoSpread; opt++;
5566 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Plasma cannon"; m[opt].value=Netgame.DoPlasma; opt++;
5567 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Fusion cannon"; m[opt].value=Netgame.DoFusions; opt++;
5568 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Gauss cannon"; m[opt].value=Netgame.DoGauss; opt++;
5569 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Helix cannon"; m[opt].value=Netgame.DoHelix; opt++;
5570 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Phoenix cannon"; m[opt].value=Netgame.DoPhoenix; opt++;
5571 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Omega cannon"; m[opt].value=Netgame.DoOmega; opt++;
5574 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Homing Missiles"; m[opt].value=Netgame.DoHoming; opt++;
5575 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Proximity Bombs"; m[opt].value=Netgame.DoProximity; opt++;
5576 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Smart Missiles"; m[opt].value=Netgame.DoSmarts; opt++;
5577 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Mega Missiles"; m[opt].value=Netgame.DoMegas; opt++;
5578 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Flash Missiles"; m[opt].value=Netgame.DoFlash; opt++;
5579 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Guided Missiles"; m[opt].value=Netgame.DoGuided; opt++;
5580 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Smart Mines"; m[opt].value=Netgame.DoSmartMine; opt++;
5581 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Mercury Missiles"; m[opt].value=Netgame.DoMercury; opt++;
5582 m[opt].type = NM_TYPE_CHECK; m[opt].text = "EarthShaker Missiles"; m[opt].value=Netgame.DoEarthShaker; opt++;
5585 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Invulnerability"; m[opt].value=Netgame.DoInvulnerability; opt++;
5586 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Cloaking"; m[opt].value=Netgame.DoCloak; opt++;
5587 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Afterburners"; m[opt].value=Netgame.DoAfterburner; opt++;
5588 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Ammo rack"; m[opt].value=Netgame.DoAmmoRack; opt++;
5589 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Energy Converter"; m[opt].value=Netgame.DoConverter; opt++;
5590 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Headlight"; m[opt].value=Netgame.DoHeadlight; opt++;
5592 choice = newmenu_do(NULL, "Objects to allow", opt, m, NULL);
5594 Netgame.DoLaserUpgrade=m[opt_primary].value;
5595 Netgame.DoSuperLaser=m[opt_primary+1].value;
5596 Netgame.DoQuadLasers=m[opt_primary+2].value;
5597 Netgame.DoVulcan=m[opt_primary+3].value;
5598 Netgame.DoSpread=m[opt_primary+4].value;
5599 Netgame.DoPlasma=m[opt_primary+5].value;
5600 Netgame.DoFusions=m[opt_primary+6].value;
5601 Netgame.DoGauss=m[opt_primary+7].value;
5602 Netgame.DoHelix=m[opt_primary+8].value;
5603 Netgame.DoPhoenix=m[opt_primary+9].value;
5604 Netgame.DoOmega=m[opt_primary+10].value;
5606 Netgame.DoHoming=m[opt_second].value;
5607 Netgame.DoProximity=m[opt_second+1].value;
5608 Netgame.DoSmarts=m[opt_second+2].value;
5609 Netgame.DoMegas=m[opt_second+3].value;
5610 Netgame.DoFlash=m[opt_second+4].value;
5611 Netgame.DoGuided=m[opt_second+5].value;
5612 Netgame.DoSmartMine=m[opt_second+6].value;
5613 Netgame.DoMercury=m[opt_second+7].value;
5614 Netgame.DoEarthShaker=m[opt_second+8].value;
5616 Netgame.DoInvulnerability=m[opt_power].value;
5617 Netgame.DoCloak=m[opt_power+1].value;
5618 Netgame.DoAfterburner=m[opt_power+2].value;
5619 Netgame.DoAmmoRack=m[opt_power+3].value;
5620 Netgame.DoConverter=m[opt_power+4].value;
5621 Netgame.DoHeadlight=m[opt_power+5].value;
5625 void SetAllAllowablesTo (int on)
5627 last_cinvul = control_invul_time = 0; //default to zero
5629 Netgame.DoMegas=Netgame.DoSmarts=Netgame.DoFusions=Netgame.DoHelix=\
5630 Netgame.DoPhoenix=Netgame.DoCloak=Netgame.DoInvulnerability=\
5631 Netgame.DoAfterburner=Netgame.DoGauss=Netgame.DoVulcan=Netgame.DoPlasma=on;
5633 Netgame.DoOmega=Netgame.DoSuperLaser=Netgame.DoProximity=\
5634 Netgame.DoSpread=Netgame.DoMercury=Netgame.DoSmartMine=Netgame.DoFlash=\
5635 Netgame.DoGuided=Netgame.DoEarthShaker=on;
5637 Netgame.DoConverter=Netgame.DoAmmoRack=Netgame.DoHeadlight=on;
5638 Netgame.DoHoming=Netgame.DoLaserUpgrade=Netgame.DoQuadLasers=on;
5639 Netgame.BrightPlayers=Netgame.invul=on;
5645 // Jeez -- mac compiler can't handle all of these on the same decl line.
5646 int opt_setpower,opt_playtime,opt_killgoal,opt_socket,opt_marker_view,opt_light,opt_show_on_map;
5647 int opt_difficulty,opt_packets,opt_short_packets, opt_bright,opt_start_invul;
5650 void network_more_options_poll( int nitems, newmenu_item * menus, int * key, int citem );
5652 void network_more_game_options ()
5655 char PlayText[80],KillText[80],srinvul[50],socket_string[5],packstring[5];
5658 sprintf (socket_string,"%d",Network_socket);
5659 sprintf (packstring,"%d",Netgame.PacketsPerSec);
5661 opt_difficulty = opt;
5662 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++;
5665 sprintf( srinvul, "%s: %d %s", TXT_REACTOR_LIFE, control_invul_time*5, TXT_MINUTES_ABBREV );
5666 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++;
5669 sprintf( PlayText, "Max time: %d %s", Netgame.PlayTimeAllowed*5, TXT_MINUTES_ABBREV );
5670 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++;
5673 sprintf( KillText, "Kill Goal: %d kills", Netgame.KillGoal*5);
5674 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++;
5676 opt_start_invul=opt;
5677 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Invulnerable when reappearing"; m[opt].value=Netgame.invul; opt++;
5679 opt_marker_view = opt;
5680 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Allow camera views from Markers"; m[opt].value=Netgame.Allow_marker_view; opt++;
5682 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Indestructible lights"; m[opt].value=Netgame.AlwaysLighting; opt++;
5685 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Bright player ships"; m[opt].value=Netgame.BrightPlayers; opt++;
5688 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Show enemy names on HUD"; m[opt].value=Netgame.ShowAllNames; opt++;
5690 opt_show_on_map=opt;
5691 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++;
5693 opt_short_packets=opt;
5694 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Short packets"; m[opt].value=Netgame.ShortPackets; opt++;
5697 m[opt].type = NM_TYPE_MENU; m[opt].text = "Set Objects allowed..."; opt++;
5699 if (Network_game_type == IPX_GAME) {
5700 m[opt].type = NM_TYPE_TEXT; m[opt].text = "Network socket"; opt++;
5702 m[opt].type = NM_TYPE_INPUT; m[opt].text = socket_string; m[opt].text_len=4; opt++;
5705 m[opt].type = NM_TYPE_TEXT; m[opt].text = "Packets per second (2 - 20)"; opt++;
5707 m[opt].type = NM_TYPE_INPUT; m[opt].text=packstring; m[opt].text_len=2; opt++;
5709 LastKillGoal=Netgame.KillGoal;
5710 LastPTA=Netgame.PlayTimeAllowed;
5714 ExtGameStatus=GAMESTAT_MORE_NETGAME_OPTIONS;
5715 i = newmenu_do1( NULL, "Additional netgame options", opt, m, network_more_options_poll, 0 );
5717 //control_invul_time = atoi( srinvul )*60*F1_0;
5718 control_invul_time = m[opt_cinvul].value;
5719 Netgame.control_invul_time = control_invul_time*5*F1_0*60;
5721 if (i==opt_setpower)
5723 network_set_power ();
5727 Netgame.PacketsPerSec=atoi(packstring);
5729 if (Netgame.PacketsPerSec>20)
5731 Netgame.PacketsPerSec=20;
5732 nm_messagebox(TXT_ERROR, 1, TXT_OK, "Packet value out of range\nSetting value to 20");
5734 if (Netgame.PacketsPerSec<2)
5736 nm_messagebox(TXT_ERROR, 1, TXT_OK, "Packet value out of range\nSetting value to 2");
5737 Netgame.PacketsPerSec=2;
5740 mprintf ((0,"Hey! Sending out %d packets per second\n",Netgame.PacketsPerSec));
5742 if (Network_game_type == IPX_GAME) {
5743 if ((atoi(socket_string))!=Network_socket) {
5744 Network_socket=atoi(socket_string);
5745 ipx_change_default_socket( IPX_DEFAULT_SOCKET + Network_socket );
5749 Netgame.invul=m[opt_start_invul].value;
5750 Netgame.BrightPlayers=m[opt_bright].value;
5751 Netgame.ShortPackets=m[opt_short_packets].value;
5752 Netgame.ShowAllNames=m[opt_show_names].value;
5753 network_AdjustMaxDataSize();
5755 Netgame.Allow_marker_view=m[opt_marker_view].value;
5756 Netgame.AlwaysLighting=m[opt_light].value;
5757 netgame_difficulty=Difficulty_level = m[opt_difficulty].value;
5758 if (m[opt_show_on_map].value)
5759 Netgame.game_flags |= NETGAME_FLAG_SHOW_MAP;
5764 void network_more_options_poll( int nitems, newmenu_item * menus, int * key, int citem )
5767 citem = citem; // kills compile warnings
5771 if ( last_cinvul != menus[opt_cinvul].value ) {
5772 sprintf( menus[opt_cinvul].text, "%s: %d %s", TXT_REACTOR_LIFE, menus[opt_cinvul].value*5, TXT_MINUTES_ABBREV );
5773 last_cinvul = menus[opt_cinvul].value;
5774 menus[opt_cinvul].redraw = 1;
5777 if (menus[opt_playtime].value!=LastPTA)
5781 nm_messagebox ("Sorry",1,TXT_OK,"Registered version only!");
5782 menus[opt_playtime].value=0;
5783 menus[opt_playtime].redraw=1;
5787 if (Game_mode & GM_MULTI_COOP)
5790 nm_messagebox ("Sorry",1,TXT_OK,"You can't change those for coop!");
5791 menus[opt_playtime].value=0;
5792 menus[opt_playtime].redraw=1;
5796 Netgame.PlayTimeAllowed=menus[opt_playtime].value;
5797 sprintf( menus[opt_playtime].text, "Max Time: %d %s", Netgame.PlayTimeAllowed*5, TXT_MINUTES_ABBREV );
5798 LastPTA=Netgame.PlayTimeAllowed;
5799 menus[opt_playtime].redraw=1;
5801 if (menus[opt_killgoal].value!=LastKillGoal)
5804 nm_messagebox ("Sorry",1,TXT_OK,"Registered version only!");
5805 menus[opt_killgoal].value=0;
5806 menus[opt_killgoal].redraw=1;
5812 if (Game_mode & GM_MULTI_COOP)
5814 nm_messagebox ("Sorry",1,TXT_OK,"You can't change those for coop!");
5815 menus[opt_killgoal].value=0;
5816 menus[opt_killgoal].redraw=1;
5822 Netgame.KillGoal=menus[opt_killgoal].value;
5823 sprintf( menus[opt_killgoal].text, "Kill Goal: %d kills", Netgame.KillGoal*5);
5824 LastKillGoal=Netgame.KillGoal;
5825 menus[opt_killgoal].redraw=1;
5829 extern void multi_send_light (int,ubyte);
5830 extern void multi_send_light_specific (int,int,ubyte);
5832 void network_send_smash_lights (int pnum)
5834 // send the lights that have been blown out
5840 for (i=0;i<=Highest_segment_index;i++)
5841 if (Light_subtracted[i])
5842 multi_send_light_specific(pnum,i,Light_subtracted[i]);
5845 extern int Num_triggers;
5846 extern void multi_send_trigger_specific (char pnum,char);
5848 void network_send_fly_thru_triggers (int pnum)
5850 // send the fly thru triggers that have been disabled
5854 for (i=0;i<Num_triggers;i++)
5855 if (Triggers[i].flags & TF_DISABLED)
5856 multi_send_trigger_specific(pnum,i);
5859 void network_send_player_flags()
5863 for (i=0;i<N_players;i++)
5864 multi_send_flags(i);
5867 void network_ping (ubyte flag,int pnum)
5872 mybuf[1]=Player_num;
5874 if (Network_game_type == IPX_GAME)
5875 ipx_send_packet_data( (ubyte *)mybuf, 2, NetPlayers.players[pnum].network.ipx.server, NetPlayers.players[pnum].network.ipx.node,Players[pnum].net_address );
5878 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);
5882 extern fix PingLaunchTime,PingReturnTime;
5884 void network_handle_ping_return (ubyte pnum)
5886 if (PingLaunchTime==0 || pnum>=N_players)
5888 mprintf ((0,"Got invalid PING RETURN from %s!\n",Players[pnum].callsign));
5892 PingReturnTime=timer_get_fixed_seconds();
5894 HUD_init_message ("Ping time for %s is %d ms!",Players[pnum].callsign,
5895 f2i(fixmul(PingReturnTime-PingLaunchTime,i2f(1000))));
5899 void network_send_ping (ubyte pnum)
5901 network_ping (PID_PING_SEND,pnum);
5904 void DoRefuseStuff (sequence_packet *their)
5906 int i,new_player_num;
5908 ClipRank (&their->player.rank);
5910 for (i=0;i<MAX_PLAYERS;i++)
5911 if (!strcmp (their->player.callsign,Players[i].callsign))
5913 network_welcome_player(their);
5917 if (!WaitForRefuseAnswer)
5919 for (i=0;i<MAX_PLAYERS;i++)
5920 if (!strcmp (their->player.callsign,Players[i].callsign))
5922 network_welcome_player(their);
5926 digi_play_sample (SOUND_HUD_JOIN_REQUEST,F1_0*2);
5928 if (Game_mode & GM_TEAM)
5932 if (!FindArg("-norankings"))
5933 HUD_init_message ("%s %s wants to join",RankStrings[their->player.rank],their->player.callsign);
5935 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]);
5937 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]);
5939 // HUD_init_message ("Alt-1 to place on team %s!",Netgame.team_name[0]);
5940 // HUD_init_message ("Alt-2 to place on team %s!",Netgame.team_name[1]);
5943 HUD_init_message ("%s wants to join...press F6 to connect",their->player.callsign);
5945 strcpy (RefusePlayerName,their->player.callsign);
5946 RefuseTimeLimit=timer_get_approx_seconds();
5948 WaitForRefuseAnswer=1;
5952 for (i=0;i<MAX_PLAYERS;i++)
5953 if (!strcmp (their->player.callsign,Players[i].callsign))
5955 network_welcome_player(their);
5959 if (strcmp(their->player.callsign,RefusePlayerName))
5962 if (RefuseThisPlayer)
5966 WaitForRefuseAnswer=0;
5967 if (Game_mode & GM_TEAM)
5969 new_player_num=GetNewPlayerNumber (their);
5970 mprintf ((0,"Newplayernum=%d\n",new_player_num));
5972 Assert (RefuseTeam==1 || RefuseTeam==2);
5975 Netgame.team_vector &=(~(1<<new_player_num));
5977 Netgame.team_vector |=(1<<new_player_num);
5978 network_welcome_player(their);
5979 network_send_netgame_update ();
5982 network_welcome_player(their);
5986 if ((timer_get_approx_seconds()) > RefuseTimeLimit+REFUSE_INTERVAL)
5990 WaitForRefuseAnswer=0;
5991 if (!strcmp (their->player.callsign,RefusePlayerName)) {
5992 if (Network_game_type == IPX_GAME)
5993 network_dump_player(their->player.network.ipx.server,their->player.network.ipx.node, DUMP_DORK);
5996 network_dump_appletalk_player(their->player.network.appletalk.node,their->player.network.appletalk.net, their->player.network.appletalk.socket, DUMP_DORK);
6005 int GetNewPlayerNumber (sequence_packet *their)
6011 if ( N_players < MaxNumNetPlayers)
6016 // Slots are full but game is open, see if anyone is
6017 // disconnected and replace the oldest player with this new one
6019 int oldest_player = -1;
6020 fix oldest_time = timer_get_approx_seconds();
6022 Assert(N_players == MaxNumNetPlayers);
6024 for (i = 0; i < N_players; i++)
6026 if ( (!Players[i].connected) && (LastPacketTime[i] < oldest_time))
6028 oldest_time = LastPacketTime[i];
6032 return (oldest_player);
6036 void network_send_extras ()
6038 Assert (Player_joining_extras>-1);
6040 if (!network_i_am_master())
6042 mprintf ((0,"Hey! I'm not the master and I was gonna send info!\n"));
6044 // Network_sending_extras=0;
6049 if (Network_sending_extras==40)
6050 network_send_fly_thru_triggers(Player_joining_extras);
6051 if (Network_sending_extras==38)
6052 network_send_door_updates(Player_joining_extras);
6053 if (Network_sending_extras==35)
6054 network_send_markers();
6055 if (Network_sending_extras==30 && (Game_mode & GM_MULTI_ROBOTS))
6056 multi_send_stolen_items();
6057 if (Network_sending_extras==25 && (Netgame.PlayTimeAllowed || Netgame.KillGoal))
6058 multi_send_kill_goal_counts();
6059 if (Network_sending_extras==20)
6060 network_send_smash_lights(Player_joining_extras);
6061 if (Network_sending_extras==15)
6062 network_send_player_flags();
6063 if (Network_sending_extras==10)
6064 multi_send_powerup_update();
6065 // if (Network_sending_extras==5)
6066 // network_send_door_updates(Player_joining_extras); // twice!
6068 Network_sending_extras--;
6069 if (!Network_sending_extras)
6070 Player_joining_extras=-1;
6074 void network_send_naked_packet(char *buf, short len, int who)
6076 if (!(Game_mode&GM_NETWORK)) return;
6078 if (NakedPacketLen==0)
6080 NakedBuf[0]=PID_NAKED_PDATA;
6081 NakedBuf[1]=Player_num;
6085 if (len+NakedPacketLen>MaxXDataSize)
6087 // mprintf ((0,"Sending a naked packet of %d bytes.\n",NakedPacketLen));
6088 if (Network_game_type == IPX_GAME)
6089 ipx_send_packet_data( (ubyte *)NakedBuf, NakedPacketLen, NetPlayers.players[who].network.ipx.server, NetPlayers.players[who].network.ipx.node,Players[who].net_address );
6092 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 );
6095 memcpy (&NakedBuf[NakedPacketLen],buf,len);
6096 NakedPacketLen+=len;
6097 NakedPacketDestPlayer=who;
6101 memcpy (&NakedBuf[NakedPacketLen],buf,len);
6102 NakedPacketLen+=len;
6103 NakedPacketDestPlayer=who;
6108 void network_process_naked_pdata (char *data,int len)
6111 Assert (data[0]=PID_NAKED_PDATA);
6113 // mprintf ((0,"Processing a naked packet of %d length.\n",len));
6116 mprintf ((0,"Naked packet is bad!\n"));
6117 Int3(); // This packet is bogus!!
6121 if (!multi_quit_game && (pnum >= N_players)) {
6122 if (Network_status!=NETSTAT_WAITING)
6124 Int3(); // We missed an important packet!
6125 network_consistency_error();
6132 if (Endlevel_sequence || (Network_status == NETSTAT_ENDLEVEL) ) {
6133 int old_Endlevel_sequence = Endlevel_sequence;
6134 Endlevel_sequence = 1;
6135 multi_process_bigdata( data+2, len-2);
6136 Endlevel_sequence = old_Endlevel_sequence;
6140 multi_process_bigdata( data+2, len-2 );
6143 int ConnectionPacketLevel[]={0,1,1,1};
6144 int ConnectionSecLevel[]={12,3,5,7};
6146 int AppletalkConnectionPacketLevel[]={0,1,0};
6147 int AppletalkConnectionSecLevel[]={10,3,8};
6149 #if defined(RELEASE) && !defined(MACINTOSH) // use the code below for mac appletalk games
6150 int network_choose_connect ()
6155 int network_choose_connect ()
6162 if (Network_game_type == IPX_GAME) {
6164 m[opt].type = NM_TYPE_MENU; m[opt].text = "Local Subnet"; opt++;
6165 m[opt].type = NM_TYPE_MENU; m[opt].text = "14.4 modem over Internet"; opt++;
6166 m[opt].type = NM_TYPE_MENU; m[opt].text = "28.8 modem over Internet"; opt++;
6167 m[opt].type = NM_TYPE_MENU; m[opt].text = "ISDN or T1 over Internet"; opt++;
6169 choice = newmenu_do1( NULL, "Choose connection type", opt, m, NULL, 0 );
6174 Assert (choice>=0 && choice<=3);
6176 Netgame.ShortPackets=ConnectionPacketLevel[choice];
6177 Netgame.PacketsPerSec=ConnectionSecLevel[choice];
6182 m[opt].type = NM_TYPE_MENU; m[opt].text = "EtherTalk"; opt++;
6183 m[opt].type = NM_TYPE_MENU; m[opt].text = "LocalTalk"; opt++;
6184 m[opt].type = NM_TYPE_MENU; m[opt].text = "Other"; opt++;
6186 choice = newmenu_do1( NULL, "Choose connection type", opt, m, NULL, 0 );
6191 Network_appletalk_type = choice;
6193 Assert (choice>=0 && choice<=2);
6195 Netgame.ShortPackets=AppletalkConnectionPacketLevel[choice];
6196 Netgame.PacketsPerSec=AppletalkConnectionSecLevel[choice];
6210 SendLogFile=(FILE *)fopen ("sendlog.net","w");
6214 void OpenRecieveLog ()
6217 RecieveLogFile=(FILE *)fopen ("recvlog.net","w");
6223 int GetMyNetRanking ()
6228 if (Netlife_kills+Netlife_killed==0)
6231 rank=(int) (((float)Netlife_kills/3000.0)*8.0);
6233 eff=(int)((float)((float)Netlife_kills/((float)Netlife_killed+(float)Netlife_kills))*100.0);
6242 rank-=((59-eff)/10);
6249 mprintf ((0,"Rank is %d (%s)\n",rank+1,RankStrings[rank+1]));
6253 void ClipRank (signed char *rank)
6255 // This function insures no crashes when dealing with D2 1.0
6258 if (*rank<0 || *rank>9)
6261 void network_check_for_old_version (char pnum)
6263 if (NetPlayers.players[(int)pnum].version_major==1 && (NetPlayers.players[(int)pnum].version_minor & 0x0F)==0)
6264 NetPlayers.players[(int)pnum].rank=0;
6267 void network_request_player_names (int n)
6269 network_send_all_info_request (PID_GAME_PLAYERS,Active_games[n].Security);
6270 NamesInfoSecurity=Active_games[n].Security;
6273 extern char already_showing_info;
6274 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));
6276 void network_process_names_return (char *data)
6279 char mtext[15][50],temp[50];
6280 int i,t,l,gnum,num=0,count=5,numplayers;
6282 if (NamesInfoSecurity!=(*(int *)(data+1)))
6284 mprintf ((0,"Bad security on names return!\n"));
6285 mprintf ((0,"NIS=%d data=%d\n",NamesInfoSecurity,(*(int *)(data+1))));
6289 numplayers=data[count]; count++;
6291 if (numplayers==255)
6294 NamesInfoSecurity=-1;
6295 nm_messagebox(NULL, 1, "OK", "That game is refusing\nname requests.\n");
6300 Assert (numplayers>0 && numplayers<MAX_NUM_NET_PLAYERS);
6304 m[i].text=(char *)&mtext[i];
6305 m[i].type=NM_TYPE_TEXT;
6308 for (gnum=-1,i=0;i<num_active_games;i++)
6310 if (NamesInfoSecurity==Active_games[i].Security)
6320 NamesInfoSecurity=-1;
6321 nm_messagebox(NULL, 1, "OK", "The game you have requested\nnames from is gone.\n");
6326 sprintf (mtext[num],"Players of game '%s':",Active_games[gnum].game_name); num++;
6327 for (i=0;i<numplayers;i++)
6331 mprintf ((0,"%s\n",data+count));
6333 for (t=0;t<CALLSIGN_LEN+1;t++)
6334 temp[t]=data[count++];
6335 if (FindArg("-norankings"))
6336 sprintf (mtext[num],"%s",temp);
6338 sprintf (mtext[num],"%s%s",RankStrings[l],temp);
6343 if (data[count]==99)
6345 sprintf (mtext[num++]," ");
6346 sprintf (mtext[num++],"Short packets: %s",data[count+1]?"On":"Off");
6347 sprintf (mtext[num++],"Packets Per Second: %d",data[count+2]);
6350 already_showing_info=1;
6351 newmenu_dotiny2( NULL, NULL, num, m, NULL);
6352 already_showing_info=0;
6355 char NameReturning=1;
6357 void network_send_player_names (sequence_packet *their)
6359 int numconnected=0,count=0,i,t;
6364 mprintf ((0,"Got a player name without a return address! Get Jason\n"));
6368 buf[0]=PID_NAMES_RETURN; count++;
6369 (*(int *)(buf+1))=Netgame.Security; count+=4;
6373 buf[count]=255; count++;
6377 mprintf ((0,"RealSec=%d DS=%d\n",Netgame.Security,*(int *)(buf+1)));
6379 for (i=0;i<N_players;i++)
6380 if (Players[i].connected)
6383 buf[count]=numconnected; count++;
6384 for (i=0;i<N_players;i++)
6385 if (Players[i].connected)
6387 buf[count++]=NetPlayers.players[i].rank;
6389 for (t=0;t<CALLSIGN_LEN+1;t++)
6391 buf[count]=NetPlayers.players[i].callsign[t];
6397 buf[count++]=Netgame.ShortPackets;
6398 buf[count++]=Netgame.PacketsPerSec;
6401 ; // empty statement allows compilation on mac which does not have the
6402 // statement below and kills the compiler when there is no
6403 // statement following the label "sendit"
6406 ipx_send_internetwork_packet_data((ubyte *)buf, count, their->player.network.ipx.server, their->player.network.ipx.node);
6413 static int checked=-1;
6421 if (cfexist("hoard.ham"))