1 /* $Id: network.c,v 1.17 2003-02-28 03:54:55 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.17 2003-02-28 03:54:55 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 #define PID_LITE_INFO 43
81 #define PID_SEND_ALL_GAMEINFO 44
82 #define PID_PLAYERSINFO 45
83 #define PID_REQUEST 46
86 #define PID_ADDPLAYER 49
88 #define PID_ENDLEVEL 52
89 #define PID_QUIT_JOINING 54
90 #define PID_OBJECT_DATA 55
91 #define PID_GAME_LIST 56
92 #define PID_GAME_INFO 57
93 #define PID_PING_SEND 58
94 #define PID_PING_RETURN 59
95 #define PID_GAME_UPDATE 60
96 #define PID_ENDLEVEL_SHORT 61
97 #define PID_NAKED_PDATA 62
98 #define PID_GAME_PLAYERS 63
99 #define PID_NAMES_RETURN 64
101 #define NETGAME_ANARCHY 0
102 #define NETGAME_TEAM_ANARCHY 1
103 #define NETGAME_ROBOT_ANARCHY 2
104 #define NETGAME_COOPERATIVE 3
105 #define NETGAME_CAPTURE_FLAG 4
106 #define NETGAME_HOARD 5
107 #define NETGAME_TEAM_HOARD 6
109 #define NETSECURITY_OFF 0
110 #define NETSECURITY_WAIT_FOR_PLAYERS 1
111 #define NETSECURITY_WAIT_FOR_GAMEINFO 2
112 #define NETSECURITY_WAIT_FOR_SYNC 3
114 // MWA -- these structures are aligned -- please save me sanity and
115 // headaches by keeping alignment if these are changed!!!! Contact
118 typedef struct endlevel_info {
123 short kill_matrix[MAX_PLAYERS][MAX_PLAYERS];
128 typedef struct endlevel_info_short {
133 } endlevel_info_short;
135 // WARNING!!! This is the top part of netgame_info...if that struct changes,
136 // this struct much change as well. ie...they are aligned and the join system will
137 // not work without it.
139 // MWA if this structure changes -- please make appropriate changes to receive_netgame_info
140 // code for macintosh in netmisc.c
142 typedef struct lite_info {
145 char game_name[NETGAME_NAME_LEN+1];
146 char mission_title[MISSION_NAME_LEN+1];
147 char mission_name[9];
154 ubyte max_numplayers;
157 ubyte protocol_version;
161 } __pack__ lite_info;
163 // IF YOU CHANGE THE SIZE OF ANY OF THE FOLLOWING STRUCTURES
164 // MAKE THE MACINTOSH DEFINES BE THE SAME SIZE AS THE PC OR
165 // I WILL HAVE TO HURT YOU VERY BADLY!!! -- MWA
168 #define NETGAME_INFO_SIZE ( Network_game_type == IPX_GAME?355:sizeof(netgame_info) )
169 #define ALLNETPLAYERSINFO_SIZE ( Network_game_type == IPX_GAME?317:sizeof(AllNetPlayers_info) )
170 #define LITE_INFO_SIZE ( Network_game_type == IPX_GAME?72:sizeof(lite_info) )
171 #define SEQUENCE_PACKET_SIZE ( Network_game_type == IPX_GAME?34:sizeof(sequence_packet) )
172 #define FRAME_INFO_SIZE ( Network_game_type == IPX_GAME?541:sizeof(frame_info) )
173 #define IPX_SHORT_INFO_SIZE ( 490 )
175 #define NETGAME_INFO_SIZE sizeof(netgame_info)
176 #define ALLNETPLAYERSINFO_SIZE sizeof(AllNetPlayers_info)
177 #define LITE_INFO_SIZE sizeof(lite_info)
178 #define SEQUENCE_PACKET_SIZE sizeof(sequence_packet)
179 #define FRAME_INFO_SIZE sizeof(frame_info)
180 #define IPX_SHORT_INFO_SIZE sizeof(short_frame_info)
183 #define MAX_ACTIVE_NETGAMES 12
185 netgame_info Active_games[MAX_ACTIVE_NETGAMES];
186 AllNetPlayers_info ActiveNetPlayers[MAX_ACTIVE_NETGAMES];
187 AllNetPlayers_info *TempPlayersInfo,TempPlayersBase;
188 int NamesInfoSecurity=-1;
190 // MWAnetgame_info *TempNetInfo;
191 netgame_info TempNetInfo;
193 extern void multi_send_drop_marker (int player,vms_vector position,char messagenum,char text[]);
194 extern void multi_send_kill_goal_counts();
195 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) );
197 void network_process_naked_pdata (char *,int);
198 extern void multi_send_robot_controls(char);
200 void network_flush();
201 void network_listen();
202 void network_update_netgame();
203 void network_check_for_old_version(char pnum);
204 void network_send_objects();
205 void network_send_rejoin_sync(int player_num);
206 void network_send_game_info(sequence_packet *their);
207 void network_send_endlevel_short_sub(int from_player_num, int to_player);
208 void network_read_sync_packet(netgame_info * sp, int rsinit);
209 int network_wait_for_playerinfo();
210 void network_process_pdata(char *data);
211 void network_read_object_packet(ubyte *data );
212 void network_read_endlevel_packet(ubyte *data );
213 void network_read_endlevel_short_packet(ubyte *data );
214 void network_ping(ubyte flat, int pnum);
215 void network_handle_ping_return(ubyte pnum);
216 void network_process_names_return(char *data);
217 void network_send_player_names(sequence_packet *their);
218 int network_choose_connect();
219 void network_more_game_options();
220 void network_count_powerups_in_mine();
221 int network_wait_for_all_info(int choice);
222 void network_AdjustMaxDataSize();
223 void network_do_big_wait(int choice);
224 void network_send_extras();
225 void network_read_pdata_packet(frame_info *pd);
226 void network_read_pdata_short_packet(short_frame_info *pd);
228 void ClipRank(signed char *rank);
229 void DoRefuseStuff(sequence_packet *their);
230 int GetNewPlayerNumber(sequence_packet *their);
231 void SetAllAllowablesTo(int on);
233 int num_active_games = 0;
234 int PacketsPerSec=10;
235 int MaxXDataSize=NET_XDATA_SIZE;
237 int Netlife_kills=0, Netlife_killed=0;
240 int Network_active=0;
242 int Network_status = 0;
243 int Network_games_changed = 0;
245 int Network_socket = 0;
246 int Network_allow_socket_changes = 1;
248 int NetSecurityFlag=NETSECURITY_OFF;
249 int NetSecurityNum=0;
250 int Network_sending_extras=0;
251 int VerifyPlayerJoined=-1;
252 int Player_joining_extras=-1; // This is so we know who to send 'latecomer' packets to.
253 // We could just send updates to everyone but that kills the sender!
255 // For rejoin object syncing
257 int Network_rejoined = 0; // Did WE rejoin this game?
258 int Network_new_game = 0; // Is this the first level of a new game?
259 int Network_send_objects = 0; // Are we in the process of sending objects to a player?
260 int Network_send_objnum = -1; // What object are we sending next?
261 int Network_player_added = 0; // Is this a new player or a returning player?
262 int Network_send_object_mode = 0; // What type of objects are we sending, static or dynamic?
263 sequence_packet Network_player_rejoining; // Who is rejoining now?
265 fix LastPacketTime[MAX_PLAYERS]; // For timeouts of idle/crashed players
267 int PacketUrgent = 0;
269 int TotalMissedPackets=0,TotalPacketsGot=0;
271 frame_info MySyncPack,UrgentSyncPack;
272 ubyte MySyncPackInitialized = 0; // Set to 1 if the MySyncPack is zeroed.
273 ushort my_segments_checksum = 0;
275 sequence_packet My_Seq;
276 char WantPlayersInfo=0;
277 char WaitingForPlayerInfo=0;
279 char *RankStrings[]={"(unpatched) ","Cadet ","Ensign ","Lieutenant ","Lt.Commander ",
280 "Commander ","Captain ","Vice Admiral ","Admiral ","Demigod "};
282 extern obj_position Player_init[MAX_PLAYERS];
284 extern int force_cockpit_redraw;
286 #define DUMP_CLOSED 0
288 #define DUMP_ENDLEVEL 2
290 #define DUMP_ABORTED 4
291 #define DUMP_CONNECTED 5
293 #define DUMP_KICKED 7
295 extern ubyte Version_major,Version_minor;
296 extern ubyte SurfingNet;
297 extern char MaxPowerupsAllowed[MAX_POWERUP_TYPES];
298 extern char PowerupsInMine[MAX_POWERUP_TYPES];
300 extern void multi_send_stolen_items();
302 int network_wait_for_snyc();
303 extern void multi_send_wall_status (int,ubyte,ubyte,ubyte);
304 extern void multi_send_wall_status_specific (int,int,ubyte,ubyte,ubyte);
306 extern void game_disable_cheats();
309 FILE *SendLogFile,*RecieveLogFile;
310 int TTSent[100],TTRecv[100];
312 extern int Final_boss_is_dead;
314 // following is network stuff for appletalk
316 void network_dump_appletalk_player(ubyte node, ushort net, ubyte socket, int why);
318 #define NETWORK_OEM 0x10
322 int Network_game_type; // used to tell IPX vs. appletalk games
324 #define MAX_ZONES 255
325 #define MAX_ZONE_LENGTH 33
326 #define DEFAULT_ZONE_NAME "\p*"
327 #define MAX_REGISTER_TRIES 5 // maximum time we will try and register a netgame
328 char Network_zone_name[MAX_ZONE_LENGTH]; // zone name game being played in for appletalk
329 char Zone_names[MAX_ZONES][MAX_ZONE_LENGTH]; // total list of zones that we can see
330 ubyte appletalk_use_broadcast = 0;
331 ubyte Network_game_validated = 0; // validates a game before being able to join
332 ubyte Network_game_validate_choice = 0;
333 ubyte Network_appletalk_type = 0; // type of appletalk network game is being played on
335 #define ETHERTALK_TYPE 0
336 #define LOCALTALK_TYPE 1
337 #define OTHERTALK_TYPE 2
340 void network_release_registered_game(void);
348 // So you want to play a netgame, eh? Let's a get a few things
352 int save_pnum = Player_num;
354 game_disable_cheats();
356 Final_boss_is_dead=0;
357 NamesInfoSecurity=-1;
365 for (t=0;t<MAX_POWERUP_TYPES;t++)
367 MaxPowerupsAllowed[t]=0;
371 TotalMissedPackets=0; TotalPacketsGot=0;
373 memset(&Netgame, 0, sizeof(netgame_info));
374 memset(&NetPlayers,0,sizeof(AllNetPlayers_info));
375 memset(&My_Seq, 0, sizeof(sequence_packet));
376 My_Seq.type = PID_REQUEST;
377 memcpy(My_Seq.player.callsign, Players[Player_num].callsign, CALLSIGN_LEN+1);
380 Version_minor|=NETWORK_OEM;
383 My_Seq.player.version_major=Version_major;
384 My_Seq.player.version_minor=Version_minor;
385 My_Seq.player.rank=GetMyNetRanking();
387 if (Network_game_type == IPX_GAME) {
388 memcpy(My_Seq.player.network.ipx.node, ipx_get_my_local_address(), 6);
389 memcpy(My_Seq.player.network.ipx.server, ipx_get_my_server_address(), 4 );
392 My_Seq.player.network.appletalk.node = appletalk_get_my_node();
393 My_Seq.player.network.appletalk.net = appletalk_get_my_net();
394 My_Seq.player.network.appletalk.socket = appletalk_get_my_socket();
398 My_Seq.player.computer_type = MAC;
400 My_Seq.player.computer_type = DOS;
403 for (Player_num = 0; Player_num < MAX_NUM_NET_PLAYERS; Player_num++)
404 init_player_stats_game();
406 Player_num = save_pnum;
408 Network_new_game = 1;
409 Control_center_destroyed = 0;
412 Netgame.PacketsPerSec=10;
414 if ((t=FindArg("-packets")))
416 Netgame.PacketsPerSec=atoi(Args[t+1]);
417 if (Netgame.PacketsPerSec<1)
418 Netgame.PacketsPerSec=1;
419 else if (Netgame.PacketsPerSec>20)
420 Netgame.PacketsPerSec=20;
421 mprintf ((0,"Will send %d packets per second",Netgame.PacketsPerSec));
423 if (FindArg("-shortpackets"))
425 Netgame.ShortPackets=1;
426 mprintf ((0,"Will send short packets.\n"));
431 network_i_am_master(void)
433 // I am the lowest numbered player in this game?
437 if (!(Game_mode & GM_NETWORK))
438 return (Player_num == 0);
440 for (i = 0; i < Player_num; i++)
441 if (Players[i].connected)
446 network_who_is_master(void)
448 // Who is the master of this game?
452 if (!(Game_mode & GM_NETWORK))
453 return (Player_num == 0);
455 for (i = 0; i < N_players; i++)
456 if (Players[i].connected)
460 int network_how_many_connected()
464 for (i = 0; i < N_players; i++)
465 if (Players[i].connected)
470 #define ENDLEVEL_SEND_INTERVAL (F1_0*2)
471 #define ENDLEVEL_IDLE_TIME (F1_0*20)
474 network_endlevel_poll( int nitems, newmenu_item * menus, int * key, int citem )
476 // Polling loop for End-of-level menu
484 int previous_state[MAX_NUM_NET_PLAYERS];
485 int previous_seconds_left;
492 // Send our endlevel packet at regular intervals
494 if (timer_get_approx_seconds() > (t1+ENDLEVEL_SEND_INTERVAL))
496 network_send_endlevel_packet();
497 t1 = timer_get_approx_seconds();
500 for (i = 0; i < N_players; i++)
501 previous_state[i] = Players[i].connected;
503 previous_seconds_left = Countdown_seconds_left;
507 for (i = 0; i < N_players; i++)
509 if (Players[i].connected == 1)
511 // Check timeout for idle players
512 if (timer_get_approx_seconds() > LastPacketTime[i]+ENDLEVEL_IDLE_TIME)
514 mprintf((0, "idle timeout for player %d.\n", i));
515 Players[i].connected = 0;
516 network_send_endlevel_sub(i);
520 if ((Players[i].connected != 1) && (Players[i].connected != 5) && (Players[i].connected != 6))
522 if (Players[i].connected != 1)
524 if (Players[i].connected == 4)
528 if (num_escaped == N_players) // All players are out of the mine
530 Countdown_seconds_left = -1;
534 if (num_ready == N_players) // All players have checked in or are disconnected
544 network_endlevel_poll2( int nitems, newmenu_item * menus, int * key, int citem )
546 // Polling loop for End-of-level menu
558 // Send our endlevel packet at regular intervals
560 if (timer_get_approx_seconds() > (t1+ENDLEVEL_SEND_INTERVAL))
562 network_send_endlevel_packet();
563 t1 = timer_get_approx_seconds();
566 // mprintf ((0,"Trying to listen!\n"));
569 for (i = 0; i < N_players; i++)
571 if ((Players[i].connected != 1) && (Players[i].connected != 5) && (Players[i].connected != 6))
573 if (Players[i].connected == 4)
577 if (num_ready == N_players) // All players have checked in or are disconnected
587 extern fix StartAbortMenuTime;
590 network_endlevel_poll3( int nitems, newmenu_item * menus, int * key, int citem )
592 // Polling loop for End-of-level menu
601 if (timer_get_approx_seconds() > (StartAbortMenuTime+(F1_0 * 8)))
608 for (i = 0; i < N_players; i++)
609 if ((Players[i].connected != 1) && (Players[i].connected != 5) && (Players[i].connected != 6))
612 if (num_ready == N_players) // All players have checked in or are disconnected
619 network_endlevel(int *secret)
621 // Do whatever needs to be done between levels
629 Network_status = NETSTAT_ENDLEVEL; // We are between levels
633 network_send_endlevel_packet();
635 for (i=0; i<N_players; i++)
637 LastPacketTime[i] = timer_get_approx_seconds();
640 network_send_endlevel_packet();
641 network_send_endlevel_packet();
642 MySyncPackInitialized = 0;
644 network_update_netgame();
650 can_join_netgame(netgame_info *game,AllNetPlayers_info *people)
652 // Can this player rejoin a netgame in progress?
656 if (game->game_status == NETSTAT_STARTING)
659 if (game->game_status != NETSTAT_PLAYING)
661 mprintf ((0,"Error: Can't join because game_status !=NETSTAT_PLAYING\n"));
665 if (game->version_major==0 && Version_major>0)
667 mprintf ((0,"Error:Can't join because version majors don't match!\n"));
671 if (game->version_major>0 && Version_major==0)
673 mprintf ((0,"Error:Can't join because version majors2 don't match!\n"));
677 // Game is in progress, figure out if this guy can re-join it
679 num_players = game->numplayers;
681 if (!(game->game_flags & NETGAME_FLAG_CLOSED)) {
682 // Look for player that is not connected
684 if (game->numconnected==game->max_numplayers)
687 // mprintf ((0,"Refuse = %d\n",game->RefusePlayers));
689 if (game->RefusePlayers)
692 if (game->numplayers < game->max_numplayers)
695 if (game->numconnected<num_players)
702 mprintf ((0,"Error! Can't join because people==NULL!\n"));
706 // Search to see if we were already in this closed netgame in progress
708 for (i = 0; i < num_players; i++) {
709 if (Network_game_type == IPX_GAME) {
710 if ( (!stricmp(Players[Player_num].callsign, people->players[i].callsign)) &&
711 (!memcmp(My_Seq.player.network.ipx.node, people->players[i].network.ipx.node, 6)) &&
712 (!memcmp(My_Seq.player.network.ipx.server, people->players[i].network.ipx.server, 4)) )
715 if ( (!stricmp(Players[Player_num].callsign, people->players[i].callsign)) &&
716 (My_Seq.player.network.appletalk.node == people->players[i].network.appletalk.node) &&
717 (My_Seq.player.network.appletalk.net == people->players[i].network.appletalk.net) )
722 if (i != num_players)
725 mprintf ((0,"Error: Can't join because at end of list!\n"));
730 network_disconnect_player(int playernum)
732 // A player has disconnected from the net game, take whatever steps are
735 if (playernum == Player_num)
737 Int3(); // Weird, see Rob
741 Players[playernum].connected = 0;
742 NetPlayers.players[playernum].connected = 0;
743 if (VerifyPlayerJoined==playernum)
744 VerifyPlayerJoined=-1;
746 // create_player_appearance_effect(&Objects[Players[playernum].objnum]);
747 multi_make_player_ghost(playernum);
749 if (Newdemo_state == ND_STATE_RECORDING)
750 newdemo_record_multi_disconnect(playernum);
752 multi_strip_robots(playernum);
756 network_new_player(sequence_packet *their)
761 pnum = their->player.connected;
764 Assert(pnum < MaxNumNetPlayers);
766 objnum = Players[pnum].objnum;
768 if (Newdemo_state == ND_STATE_RECORDING) {
771 if (pnum == N_players)
775 newdemo_record_multi_connect(pnum, new_player, their->player.callsign);
778 memcpy(Players[pnum].callsign, their->player.callsign, CALLSIGN_LEN+1);
779 memcpy(NetPlayers.players[pnum].callsign, their->player.callsign, CALLSIGN_LEN+1);
782 ClipRank (&their->player.rank);
783 NetPlayers.players[pnum].rank=their->player.rank;
784 NetPlayers.players[pnum].version_major=their->player.version_major;
785 NetPlayers.players[pnum].version_minor=their->player.version_minor;
786 network_check_for_old_version(pnum);
788 if (Network_game_type == IPX_GAME) {
789 if ( (*(uint *)their->player.network.ipx.server) != 0 )
790 ipx_get_local_target( their->player.network.ipx.server, their->player.network.ipx.node, Players[pnum].net_address );
792 memcpy(Players[pnum].net_address, their->player.network.ipx.node, 6);
794 memcpy(NetPlayers.players[pnum].network.ipx.node, their->player.network.ipx.node, 6);
795 memcpy(NetPlayers.players[pnum].network.ipx.server, their->player.network.ipx.server, 4);
797 NetPlayers.players[pnum].network.appletalk.node = their->player.network.appletalk.node;
798 NetPlayers.players[pnum].network.appletalk.net = their->player.network.appletalk.net;
799 NetPlayers.players[pnum].network.appletalk.socket = their->player.network.appletalk.socket;
802 Players[pnum].n_packets_got = 0;
803 Players[pnum].connected = 1;
804 Players[pnum].net_kills_total = 0;
805 Players[pnum].net_killed_total = 0;
806 memset(kill_matrix[pnum], 0, MAX_PLAYERS*sizeof(short));
807 Players[pnum].score = 0;
808 Players[pnum].flags = 0;
809 Players[pnum].KillGoalCount=0;
811 if (pnum == N_players)
814 Netgame.numplayers = N_players;
817 digi_play_sample(SOUND_HUD_MESSAGE, F1_0);
819 ClipRank (&their->player.rank);
821 if (FindArg("-norankings"))
822 HUD_init_message("'%s' %s\n",their->player.callsign, TXT_JOINING);
824 HUD_init_message("%s'%s' %s\n",RankStrings[their->player.rank],their->player.callsign, TXT_JOINING);
826 multi_make_ghost_player(pnum);
829 multi_sort_kill_list();
831 // create_player_appearance_effect(&Objects[objnum]);
834 char RefuseThisPlayer=0,WaitForRefuseAnswer=0,RefuseTeam;
835 char RefusePlayerName[12];
836 fix RefuseTimeLimit=0;
838 void network_welcome_player(sequence_packet *their)
840 // Add a player to a game already in progress
841 ubyte local_address[6];
845 WaitForRefuseAnswer=0;
847 if (FindArg("-NoMatrixCheat"))
849 if ((their->player.version_minor & 0x0F) < 3)
851 network_dump_player(their->player.network.ipx.server, their->player.network.ipx.node, DUMP_DORK);
858 // If hoard game, and this guy isn't D2 Christmas (v1.2), dump him
860 if ((Game_mode & GM_HOARD) && ((their->player.version_minor & 0x0F)<2))
862 if (Network_game_type == IPX_GAME)
863 network_dump_player(their->player.network.ipx.server, their->player.network.ipx.node, DUMP_DORK);
866 network_dump_appletalk_player(their->player.network.appletalk.node, their->player.network.appletalk.net, their->player.network.appletalk.socket, DUMP_DORK);
872 // Don't accept new players if we're ending this level. Its safe to
873 // ignore since they'll request again later
875 if ((Endlevel_sequence) || (Control_center_destroyed))
877 mprintf((0, "Ignored request from new player to join during endgame.\n"));
878 if (Network_game_type == IPX_GAME)
879 network_dump_player(their->player.network.ipx.server,their->player.network.ipx.node, DUMP_ENDLEVEL);
882 network_dump_appletalk_player(their->player.network.appletalk.node, their->player.network.appletalk.net, their->player.network.appletalk.socket, DUMP_ENDLEVEL);
887 if (Network_send_objects || Network_sending_extras)
889 // Ignore silently, we're already responding to someone and we can't
890 // do more than one person at a time. If we don't dump them they will
891 // re-request in a few seconds.
895 if (their->player.connected != Current_level_num)
897 mprintf((0, "Dumping player due to old level number.\n"));
898 if (Network_game_type == IPX_GAME)
899 network_dump_player(their->player.network.ipx.server, their->player.network.ipx.node, DUMP_LEVEL);
902 network_dump_appletalk_player(their->player.network.appletalk.node, their->player.network.appletalk.net, their->player.network.appletalk.socket, DUMP_LEVEL);
908 memset(&Network_player_rejoining, 0, sizeof(sequence_packet));
909 Network_player_added = 0;
911 if (Network_game_type == IPX_GAME) {
912 if ( (*(uint *)their->player.network.ipx.server) != 0 )
913 ipx_get_local_target( their->player.network.ipx.server, their->player.network.ipx.node, local_address );
915 memcpy(local_address, their->player.network.ipx.node, 6);
918 for (i = 0; i < N_players; i++)
920 if ( (Network_game_type == IPX_GAME) && (!stricmp(Players[i].callsign, their->player.callsign )) && (!memcmp(Players[i].net_address,local_address, 6)) )
925 #ifdef MACINTOSH // note link to above if
926 else if ( (!stricmp(Players[i].callsign, their->player.callsign)) &&
927 (NetPlayers.players[i].network.appletalk.node == their->player.network.appletalk.node) &&
928 (NetPlayers.players[i].network.appletalk.net == their->player.network.appletalk.net)) {
935 if (player_num == -1)
937 // Player is new to this game
939 if ( !(Netgame.game_flags & NETGAME_FLAG_CLOSED) && (N_players < MaxNumNetPlayers))
941 // Add player in an open slot, game not full yet
943 player_num = N_players;
944 Network_player_added = 1;
946 else if (Netgame.game_flags & NETGAME_FLAG_CLOSED)
948 // Slots are open but game is closed
950 if (Network_game_type == IPX_GAME)
951 network_dump_player(their->player.network.ipx.server, their->player.network.ipx.node, DUMP_CLOSED);
954 network_dump_appletalk_player(their->player.network.appletalk.node, their->player.network.appletalk.net, their->player.network.appletalk.socket, DUMP_CLOSED);
960 // Slots are full but game is open, see if anyone is
961 // disconnected and replace the oldest player with this new one
963 int oldest_player = -1;
964 fix oldest_time = timer_get_approx_seconds();
966 Assert(N_players == MaxNumNetPlayers);
968 for (i = 0; i < N_players; i++)
970 if ( (!Players[i].connected) && (LastPacketTime[i] < oldest_time))
972 oldest_time = LastPacketTime[i];
977 if (oldest_player == -1)
979 // Everyone is still connected
981 if (Network_game_type == IPX_GAME)
982 network_dump_player(their->player.network.ipx.server, their->player.network.ipx.node, DUMP_FULL);
985 network_dump_appletalk_player(their->player.network.appletalk.node, their->player.network.appletalk.net, their->player.network.appletalk.socket, DUMP_FULL);
993 player_num = oldest_player;
994 Network_player_added = 1;
1000 // Player is reconnecting
1002 if (Players[player_num].connected)
1004 mprintf((0, "Extra REQUEST from player ignored.\n"));
1008 if (Newdemo_state == ND_STATE_RECORDING)
1009 newdemo_record_multi_reconnect(player_num);
1011 Network_player_added = 0;
1013 digi_play_sample(SOUND_HUD_MESSAGE, F1_0);
1015 if (FindArg("-norankings"))
1016 HUD_init_message("'%s' %s", Players[player_num].callsign, TXT_REJOIN);
1018 HUD_init_message("%s'%s' %s", RankStrings[NetPlayers.players[player_num].rank],Players[player_num].callsign, TXT_REJOIN);
1021 Players[player_num].KillGoalCount=0;
1023 // Send updated Objects data to the new/returning player
1026 Network_player_rejoining = *their;
1027 Network_player_rejoining.player.connected = player_num;
1028 Network_send_objects = 1;
1029 Network_send_objnum = -1;
1031 network_send_objects();
1034 int network_objnum_is_past(int objnum)
1036 // determine whether or not a given object number has already been sent
1037 // to a re-joining player.
1039 int player_num = Network_player_rejoining.player.connected;
1040 int obj_mode = !((object_owner[objnum] == -1) || (object_owner[objnum] == player_num));
1042 if (!Network_send_objects)
1043 return 0; // We're not sending objects to a new player
1045 if (obj_mode > Network_send_object_mode)
1047 else if (obj_mode < Network_send_object_mode)
1049 else if (objnum < Network_send_objnum)
1055 #define OBJ_PACKETS_PER_FRAME 1
1056 extern void multi_send_active_door(char);
1057 extern void multi_send_door_open_specific(int,int,int,ubyte);
1060 void network_send_door_updates(int pnum)
1062 // Send door status when new player joins
1068 // Assert (pnum>-1 && pnum<N_players);
1070 for (i = 0; i < Num_walls; i++)
1072 if ((Walls[i].type == WALL_DOOR) && ((Walls[i].state == WALL_DOOR_OPENING) || (Walls[i].state == WALL_DOOR_WAITING) || (Walls[i].state == WALL_DOOR_OPEN)))
1073 multi_send_door_open_specific(pnum,Walls[i].segnum, Walls[i].sidenum,Walls[i].flags);
1074 else if ((Walls[i].type == WALL_BLASTABLE) && (Walls[i].flags & WALL_BLASTED))
1075 multi_send_door_open_specific(pnum,Walls[i].segnum, Walls[i].sidenum,Walls[i].flags);
1076 else if ((Walls[i].type == WALL_BLASTABLE) && (Walls[i].hps != WALL_HPS))
1077 multi_send_hostage_door_status(i);
1079 multi_send_wall_status_specific(pnum,i,Walls[i].type,Walls[i].flags,Walls[i].state);
1083 extern vms_vector MarkerPoint[];
1084 void network_send_markers()
1086 // send marker positions/text to new player
1093 if (MarkerObject[(i*2)]!=-1)
1094 multi_send_drop_marker (i,MarkerPoint[(i*2)],0,MarkerMessage[i*2]);
1095 if (MarkerObject[(i*2)+1]!=-1)
1096 multi_send_drop_marker (i,MarkerPoint[(i*2)+1],1,MarkerMessage[(i*2)+1]);
1100 void network_process_monitor_vector(int vector)
1106 for (i=0; i <= Highest_segment_index; i++)
1110 for (j = 0; j < 6; j++)
1112 if ( ((tm = seg->sides[j].tmap_num2) != 0) &&
1113 ((ec = TmapInfo[tm&0x3fff].eclip_num) != -1) &&
1114 ((bm = Effects[ec].dest_bm_num) != -1) )
1116 if (vector & (1 << count))
1118 seg->sides[j].tmap_num2 = bm | (tm&0xc000);
1119 // mprintf((0, "Monitor %d blown up.\n", count));
1122 // mprintf((0, "Monitor %d intact.\n", count));
1130 int network_create_monitor_vector(void)
1133 int num_blown_bitmaps = 0;
1134 int monitor_num = 0;
1135 #define NUM_BLOWN_BITMAPS 20
1136 int blown_bitmaps[NUM_BLOWN_BITMAPS];
1140 for (i=0; i < Num_effects; i++)
1142 if (Effects[i].dest_bm_num > 0) {
1143 for (j = 0; j < num_blown_bitmaps; j++)
1144 if (blown_bitmaps[j] == Effects[i].dest_bm_num)
1146 if (j == num_blown_bitmaps) {
1147 blown_bitmaps[num_blown_bitmaps++] = Effects[i].dest_bm_num;
1148 Assert(num_blown_bitmaps < NUM_BLOWN_BITMAPS);
1153 // for (i = 0; i < num_blown_bitmaps; i++)
1154 // mprintf((0, "Blown bitmap #%d = %d.\n", i, blown_bitmaps[i]));
1156 for (i=0; i <= Highest_segment_index; i++)
1160 for (j = 0; j < 6; j++)
1162 if ((tm = seg->sides[j].tmap_num2) != 0)
1164 if ( ((ec = TmapInfo[tm&0x3fff].eclip_num) != -1) &&
1165 (Effects[ec].dest_bm_num != -1) )
1167 // mprintf((0, "Monitor %d intact.\n", monitor_num));
1169 Assert(monitor_num < 32);
1173 for (k = 0; k < num_blown_bitmaps; k++)
1175 if ((tm&0x3fff) == blown_bitmaps[k])
1177 //mprintf((0, "Monitor %d destroyed.\n", monitor_num));
1178 vector |= (1 << monitor_num);
1180 Assert(monitor_num < 32);
1188 // mprintf((0, "Final monitor vector %x.\n", vector));
1192 void network_stop_resync(sequence_packet *their)
1194 if (Network_game_type == IPX_GAME) {
1195 if ( (!memcmp(Network_player_rejoining.player.network.ipx.node, their->player.network.ipx.node, 6)) &&
1196 (!memcmp(Network_player_rejoining.player.network.ipx.server, their->player.network.ipx.server, 4)) &&
1197 (!stricmp(Network_player_rejoining.player.callsign, their->player.callsign)) )
1199 mprintf((0, "Aborting resync for player %s.\n", their->player.callsign));
1200 Network_send_objects = 0;
1201 Network_sending_extras=0;
1203 Player_joining_extras=-1;
1204 Network_send_objnum = -1;
1207 if ( (Network_player_rejoining.player.network.appletalk.node == their->player.network.appletalk.node) &&
1208 (Network_player_rejoining.player.network.appletalk.net == their->player.network.appletalk.net) &&
1209 (!stricmp(Network_player_rejoining.player.callsign, their->player.callsign)) )
1211 mprintf((0, "Aborting resync for player %s.\n", their->player.callsign));
1212 Network_send_objects = 0;
1213 Network_sending_extras=0;
1215 Player_joining_extras=-1;
1216 Network_send_objnum = -1;
1221 byte object_buffer[IPX_MAX_DATA_SIZE];
1223 void network_send_objects(void)
1225 short remote_objnum;
1229 static int obj_count = 0;
1230 static int frame_num = 0;
1232 int obj_count_frame = 0;
1233 int player_num = Network_player_rejoining.player.connected;
1235 // Send clear objects array trigger and send player num
1237 Assert(Network_send_objects != 0);
1238 Assert(player_num >= 0);
1239 Assert(player_num < MaxNumNetPlayers);
1241 if (Endlevel_sequence || Control_center_destroyed)
1243 // Endlevel started before we finished sending the goods, we'll
1244 // have to stop and try again after the level.
1246 if (Network_game_type == IPX_GAME)
1247 network_dump_player(Network_player_rejoining.player.network.ipx.server,Network_player_rejoining.player.network.ipx.node, DUMP_ENDLEVEL);
1250 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);
1252 Network_send_objects = 0;
1256 for (h = 0; h < OBJ_PACKETS_PER_FRAME; h++) // Do more than 1 per frame, try to speed it up without
1257 // over-stressing the receiver.
1259 obj_count_frame = 0;
1260 memset(object_buffer, 0, IPX_MAX_DATA_SIZE);
1261 object_buffer[0] = PID_OBJECT_DATA;
1264 if (Network_send_objnum == -1)
1267 Network_send_object_mode = 0;
1268 // mprintf((0, "Sending object array to player %d.\n", player_num));
1269 *(short *)(object_buffer+loc) = INTEL_SHORT(-1); loc += 2;
1270 object_buffer[loc] = player_num; loc += 1;
1271 /* Placeholder for remote_objnum, not used here */ loc += 2;
1272 Network_send_objnum = 0;
1273 obj_count_frame = 1;
1277 for (i = Network_send_objnum; i <= Highest_object_index; i++)
1279 if ((Objects[i].type != OBJ_POWERUP) && (Objects[i].type != OBJ_PLAYER) &&
1280 (Objects[i].type != OBJ_CNTRLCEN) && (Objects[i].type != OBJ_GHOST) &&
1281 (Objects[i].type != OBJ_ROBOT) && (Objects[i].type != OBJ_HOSTAGE) &&
1282 !(Objects[i].type==OBJ_WEAPON && Objects[i].id==PMINE_ID))
1284 if ((Network_send_object_mode == 0) && ((object_owner[i] != -1) && (object_owner[i] != player_num)))
1286 if ((Network_send_object_mode == 1) && ((object_owner[i] == -1) || (object_owner[i] == player_num)))
1289 if ( ((IPX_MAX_DATA_SIZE-1) - loc) < (sizeof(object)+5) )
1290 break; // Not enough room for another object
1295 remote_objnum = objnum_local_to_remote((short)i, &owner);
1296 Assert(owner == object_owner[i]);
1298 *(short *)(object_buffer+loc) = INTEL_SHORT((short)i); loc += 2;
1299 object_buffer[loc] = owner; loc += 1;
1300 *(short *)(object_buffer+loc) = INTEL_SHORT(remote_objnum); loc += 2;
1301 memcpy(&object_buffer[loc], &Objects[i], sizeof(object));
1302 if (Network_game_type == IPX_GAME)
1303 swap_object((object *)&object_buffer[loc]);
1304 loc += sizeof(object);
1305 // mprintf((0, "..packing object %d, remote %d\n", i, remote_objnum));
1308 if (obj_count_frame) // Send any objects we've buffered
1312 Network_send_objnum = i;
1313 object_buffer[1] = obj_count_frame; object_buffer[2] = frame_num;
1314 // mprintf((0, "Object packet %d contains %d objects.\n", frame_num, obj_count_frame));
1316 Assert(loc <= IPX_MAX_DATA_SIZE);
1318 if (Network_game_type == IPX_GAME)
1319 ipx_send_internetwork_packet_data( object_buffer, loc, Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node );
1322 appletalk_send_packet_data( object_buffer, loc, Network_player_rejoining.player.network.appletalk.node,
1323 Network_player_rejoining.player.network.appletalk.net,
1324 Network_player_rejoining.player.network.appletalk.socket);
1327 // OLD ipx_send_packet_data(object_buffer, loc, &Network_player_rejoining.player.node);
1330 if (i > Highest_object_index)
1332 if (Network_send_object_mode == 0)
1334 Network_send_objnum = 0;
1335 Network_send_object_mode = 1; // go to next mode
1339 Assert(Network_send_object_mode == 1);
1342 // Send count so other side can make sure he got them all
1343 // mprintf((0, "Sending end marker in packet #%d.\n", frame_num));
1344 mprintf((0, "Sent %d objects.\n", obj_count));
1345 object_buffer[0] = PID_OBJECT_DATA;
1346 object_buffer[1] = 1;
1347 object_buffer[2] = frame_num;
1348 *(short *)(object_buffer+3) = INTEL_SHORT(-2);
1349 *(short *)(object_buffer+6) = INTEL_SHORT(obj_count);
1350 //OLD ipx_send_packet_data(object_buffer, 8, &Network_player_rejoining.player.node);
1351 if (Network_game_type == IPX_GAME)
1352 ipx_send_internetwork_packet_data(object_buffer, 8, Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node);
1355 appletalk_send_packet_data( object_buffer, 8, Network_player_rejoining.player.network.appletalk.node,
1356 Network_player_rejoining.player.network.appletalk.net,
1357 Network_player_rejoining.player.network.appletalk.socket);
1361 // Send sync packet which tells the player who he is and to start!
1362 network_send_rejoin_sync(player_num);
1363 mprintf ((0,"VerfiyPlayerJoined is now set to %d\n",player_num));
1364 VerifyPlayerJoined=player_num;
1366 // Turn off send object mode
1367 Network_send_objnum = -1;
1368 Network_send_objects = 0;
1371 //if (!network_i_am_master ())
1372 // Int3(); // Bad!! Get Jason. Someone goofy is trying to get ahold of the game!
1374 Network_sending_extras=40; // start to send extras
1375 Player_joining_extras=player_num;
1379 } // i > Highest_object_index
1380 } // For PACKETS_PER_FRAME
1383 extern void multi_send_powerup_update();
1385 void network_send_rejoin_sync(int player_num)
1389 Players[player_num].connected = 1; // connect the new guy
1390 LastPacketTime[player_num] = timer_get_approx_seconds();
1392 if (Endlevel_sequence || Control_center_destroyed)
1394 // Endlevel started before we finished sending the goods, we'll
1395 // have to stop and try again after the level.
1397 if (Network_game_type == IPX_GAME)
1398 network_dump_player(Network_player_rejoining.player.network.ipx.server,Network_player_rejoining.player.network.ipx.node, DUMP_ENDLEVEL);
1401 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);
1403 Network_send_objects = 0;
1404 Network_sending_extras=0;
1408 if (Network_player_added)
1410 Network_player_rejoining.type = PID_ADDPLAYER;
1411 Network_player_rejoining.player.connected = player_num;
1412 network_new_player(&Network_player_rejoining);
1414 for (i = 0; i < N_players; i++)
1416 if ((i != player_num) && (i != Player_num) && (Players[i].connected))
1417 if (Network_game_type == IPX_GAME) {
1418 send_sequence_packet( Network_player_rejoining, NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node, Players[i].net_address);
1421 appletalk_send_packet_data( (ubyte *)&Network_player_rejoining, sizeof(sequence_packet), NetPlayers.players[i].network.appletalk.node,
1422 NetPlayers.players[i].network.appletalk.net, NetPlayers.players[i].network.appletalk.socket);
1428 // Send sync packet to the new guy
1430 network_update_netgame();
1432 // Fill in the kill list
1433 for (j=0; j<MAX_PLAYERS; j++)
1435 for (i=0; i<MAX_PLAYERS;i++)
1436 Netgame.kills[j][i] = kill_matrix[j][i];
1437 Netgame.killed[j] = Players[j].net_killed_total;
1438 Netgame.player_kills[j] = Players[j].net_kills_total;
1439 Netgame.player_score[j] = Players[j].score;
1442 Netgame.level_time = Players[Player_num].time_level;
1443 Netgame.monitor_vector = network_create_monitor_vector();
1445 mprintf((0, "Sending rejoin sync packet!!!\n"));
1447 if (Network_game_type == IPX_GAME) {
1448 send_internetwork_full_netgame_packet(Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node);
1449 send_netplayers_packet(Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node);
1452 appletalk_send_packet_data( (ubyte *)&Netgame, sizeof(netgame_info), Network_player_rejoining.player.network.appletalk.node,
1453 Network_player_rejoining.player.network.appletalk.net,
1454 Network_player_rejoining.player.network.appletalk.socket);
1455 appletalk_send_packet_data( (ubyte *)&NetPlayers, sizeof(AllNetPlayers_info), Network_player_rejoining.player.network.appletalk.node,
1456 Network_player_rejoining.player.network.appletalk.net,
1457 Network_player_rejoining.player.network.appletalk.socket);
1462 void resend_sync_due_to_packet_loss_for_allender ()
1466 mprintf ((0,"I'm resending a sync packet! VPJ=%d\n",VerifyPlayerJoined));
1468 network_update_netgame();
1470 // Fill in the kill list
1471 for (j=0; j<MAX_PLAYERS; j++)
1473 for (i=0; i<MAX_PLAYERS;i++)
1474 Netgame.kills[j][i] = kill_matrix[j][i];
1475 Netgame.killed[j] = Players[j].net_killed_total;
1476 Netgame.player_kills[j] = Players[j].net_kills_total;
1477 Netgame.player_score[j] = Players[j].score;
1480 Netgame.level_time = Players[Player_num].time_level;
1481 Netgame.monitor_vector = network_create_monitor_vector();
1483 if (Network_game_type == IPX_GAME) {
1484 send_internetwork_full_netgame_packet(Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node);
1485 send_netplayers_packet(Network_player_rejoining.player.network.ipx.server, Network_player_rejoining.player.network.ipx.node);
1488 appletalk_send_packet_data( (ubyte *)&Netgame, sizeof(netgame_info), Network_player_rejoining.player.network.appletalk.node,
1489 Network_player_rejoining.player.network.appletalk.net,
1490 Network_player_rejoining.player.network.appletalk.socket);
1491 appletalk_send_packet_data( (ubyte *)&NetPlayers, sizeof(AllNetPlayers_info), Network_player_rejoining.player.network.appletalk.node,
1492 Network_player_rejoining.player.network.appletalk.net,
1493 Network_player_rejoining.player.network.appletalk.socket);
1499 char * network_get_player_name( int objnum )
1501 if ( objnum < 0 ) return NULL;
1502 if ( Objects[objnum].type != OBJ_PLAYER ) return NULL;
1503 if ( Objects[objnum].id >= MAX_PLAYERS ) return NULL;
1504 if ( Objects[objnum].id >= N_players ) return NULL;
1506 return Players[Objects[objnum].id].callsign;
1510 void network_add_player(sequence_packet *p)
1514 mprintf((0, "Got add player request!\n"));
1516 for (i=0; i<N_players; i++ ) {
1517 if (Network_game_type == IPX_GAME) {
1518 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))
1519 return; // already got them
1521 if ( (NetPlayers.players[i].network.appletalk.node == p->player.network.appletalk.node) &&
1522 (NetPlayers.players[i].network.appletalk.net == p->player.network.appletalk.net))
1527 if (Network_game_type == IPX_GAME) {
1528 memcpy( NetPlayers.players[N_players].network.ipx.node, p->player.network.ipx.node, 6 );
1529 memcpy( NetPlayers.players[N_players].network.ipx.server, p->player.network.ipx.server, 4 );
1531 NetPlayers.players[N_players].network.appletalk.node = p->player.network.appletalk.node;
1532 NetPlayers.players[N_players].network.appletalk.net = p->player.network.appletalk.net;
1533 NetPlayers.players[N_players].network.appletalk.socket = p->player.network.appletalk.socket;
1536 ClipRank (&p->player.rank);
1538 memcpy( NetPlayers.players[N_players].callsign, p->player.callsign, CALLSIGN_LEN+1 );
1539 NetPlayers.players[N_players].version_major=p->player.version_major;
1540 NetPlayers.players[N_players].version_minor=p->player.version_minor;
1541 NetPlayers.players[N_players].rank=p->player.rank;
1542 NetPlayers.players[N_players].connected = 1;
1543 network_check_for_old_version (N_players);
1545 Players[N_players].KillGoalCount=0;
1546 Players[N_players].connected = 1;
1547 LastPacketTime[N_players] = timer_get_approx_seconds();
1549 Netgame.numplayers = N_players;
1551 // Broadcast updated info
1553 mprintf ((0,"sending_game_info!\n"));
1554 network_send_game_info(NULL);
1557 // One of the players decided not to join the game
1559 void network_remove_player(sequence_packet *p)
1564 for (i=0; i<N_players; i++ ) {
1565 if (Network_game_type == IPX_GAME) {
1566 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)) {
1571 if ( (NetPlayers.players[i].network.appletalk.node == p->player.network.appletalk.node) && (NetPlayers.players[i].network.appletalk.net == p->player.network.appletalk.net) ) {
1578 if (pn < 0 ) return;
1580 for (i=pn; i<N_players-1; i++ ) {
1581 if (Network_game_type == IPX_GAME) {
1582 memcpy( NetPlayers.players[i].network.ipx.node, NetPlayers.players[i+1].network.ipx.node, 6 );
1583 memcpy( NetPlayers.players[i].network.ipx.server, NetPlayers.players[i+1].network.ipx.server, 4 );
1585 NetPlayers.players[i].network.appletalk.node = NetPlayers.players[i+1].network.appletalk.node;
1586 NetPlayers.players[i].network.appletalk.net = NetPlayers.players[i+1].network.appletalk.net;
1587 NetPlayers.players[i].network.appletalk.socket = NetPlayers.players[i+1].network.appletalk.socket;
1589 memcpy( NetPlayers.players[i].callsign, NetPlayers.players[i+1].callsign, CALLSIGN_LEN+1 );
1590 NetPlayers.players[i].version_major=NetPlayers.players[i+1].version_major;
1591 NetPlayers.players[i].version_minor=NetPlayers.players[i+1].version_minor;
1593 NetPlayers.players[i].rank=NetPlayers.players[i+1].rank;
1594 ClipRank (&NetPlayers.players[i].rank);
1595 network_check_for_old_version(i);
1599 Netgame.numplayers = N_players;
1601 // Broadcast new info
1603 network_send_game_info(NULL);
1608 network_dump_player(ubyte * server, ubyte *node, int why)
1610 // Inform player that he was not chosen for the netgame
1612 sequence_packet temp;
1614 temp.type = PID_DUMP;
1615 memcpy(temp.player.callsign, Players[Player_num].callsign, CALLSIGN_LEN+1);
1616 temp.player.connected = why;
1617 if (Network_game_type == IPX_GAME) {
1618 send_internetwork_sequence_packet(temp, server, node);
1625 void network_dump_appletalk_player(ubyte node, ushort net, ubyte socket, int why)
1627 sequence_packet temp;
1629 temp.type = PID_DUMP;
1630 memcpy(temp.player.callsign, Players[Player_num].callsign, CALLSIGN_LEN+1);
1631 temp.player.connected = why;
1632 if (Network_game_type == APPLETALK_GAME) {
1633 appletalk_send_packet_data( (ubyte *)&temp, sizeof(sequence_packet), node, net, socket );
1641 network_send_game_list_request()
1643 // Send a broadcast request for game info
1647 mprintf((0, "Sending game_list request.\n"));
1648 me.type = PID_GAME_LIST;
1649 memcpy( me.player.callsign, Players[Player_num].callsign, CALLSIGN_LEN+1 );
1651 if (Network_game_type == IPX_GAME) {
1652 memcpy( me.player.network.ipx.node, ipx_get_my_local_address(), 6 );
1653 memcpy( me.player.network.ipx.server, ipx_get_my_server_address(), 4 );
1655 send_broadcast_sequence_packet(me);
1658 me.player.network.appletalk.node = appletalk_get_my_node();
1659 me.player.network.appletalk.net = appletalk_get_my_net();
1660 me.player.network.appletalk.socket = appletalk_get_my_socket();
1661 appletalk_send_game_info( (ubyte *)&me, sizeof(sequence_packet), Network_zone_name );
1666 void network_send_all_info_request(char type,int which_security)
1668 // Send a broadcast request for game info
1672 mprintf((0, "Sending all_info request.\n"));
1674 me.Security=which_security;
1676 memcpy( me.player.callsign, Players[Player_num].callsign, CALLSIGN_LEN+1 );
1678 if (Network_game_type == IPX_GAME) {
1679 memcpy( me.player.network.ipx.node, ipx_get_my_local_address(), 6 );
1680 memcpy( me.player.network.ipx.server, ipx_get_my_server_address(), 4 );
1682 send_broadcast_sequence_packet(me);
1685 me.player.network.appletalk.node = appletalk_get_my_node();
1686 me.player.network.appletalk.net = appletalk_get_my_net();
1687 me.player.network.appletalk.socket = appletalk_get_my_socket();
1688 appletalk_send_game_info( (ubyte *)&me, sizeof(sequence_packet), Network_zone_name );
1695 network_update_netgame(void)
1697 // Update the netgame struct with current game variables
1701 Netgame.numconnected=0;
1702 for (i=0;i<N_players;i++)
1703 if (Players[i].connected)
1704 Netgame.numconnected++;
1706 // This is great: D2 1.0 and 1.1 ignore upper part of the game_flags field of
1707 // the lite_info struct when you're sitting on the join netgame screen. We can
1708 // "sneak" Hoard information into this field. This is better than sending
1709 // another packet that could be lost in transit.
1712 if (HoardEquipped())
1714 if (Game_mode & GM_HOARD)
1716 Netgame.game_flags |=NETGAME_FLAG_HOARD;
1717 if (Game_mode & GM_TEAM)
1718 Netgame.game_flags |=NETGAME_FLAG_TEAM_HOARD;
1722 if (Network_status == NETSTAT_STARTING)
1725 Netgame.numplayers = N_players;
1726 Netgame.game_status = Network_status;
1727 Netgame.max_numplayers = MaxNumNetPlayers;
1729 for (i = 0; i < MAX_NUM_NET_PLAYERS; i++)
1731 NetPlayers.players[i].connected = Players[i].connected;
1732 for(j = 0; j < MAX_NUM_NET_PLAYERS; j++)
1733 Netgame.kills[i][j] = kill_matrix[i][j];
1735 Netgame.killed[i] = Players[i].net_killed_total;
1736 Netgame.player_kills[i] = Players[i].net_kills_total;
1737 Netgame.player_score[i] = Players[i].score;
1738 Netgame.player_flags[i] = (Players[i].flags & (PLAYER_FLAGS_BLUE_KEY | PLAYER_FLAGS_RED_KEY | PLAYER_FLAGS_GOLD_KEY));
1740 Netgame.team_kills[0] = team_kills[0];
1741 Netgame.team_kills[1] = team_kills[1];
1742 Netgame.levelnum = Current_level_num;
1748 network_send_endlevel_sub(int player_num)
1753 // Send an endlevel packet for a player
1754 end.type = PID_ENDLEVEL;
1755 end.player_num = player_num;
1756 end.connected = Players[player_num].connected;
1757 end.kills = INTEL_SHORT(Players[player_num].net_kills_total);
1758 end.killed = INTEL_SHORT(Players[player_num].net_killed_total);
1759 memcpy(end.kill_matrix, kill_matrix[player_num], MAX_PLAYERS*sizeof(short));
1760 #ifdef WORDS_BIGENDIAN
1761 for (i = 0; i < MAX_PLAYERS; i++)
1762 for (j = 0; j < MAX_PLAYERS; j++)
1763 end.kill_matrix[i][j] = INTEL_SHORT(end.kill_matrix[i][j]);
1765 j = j; // to satisfy compiler
1768 if (Players[player_num].connected == 1) // Still playing
1770 Assert(Control_center_destroyed);
1771 end.seconds_left = Countdown_seconds_left;
1774 // mprintf((0, "Sending endlevel packet.\n"));
1776 for (i = 0; i < N_players; i++)
1778 if ((i != Player_num) && (i!=player_num) && (Players[i].connected)) {
1779 if (Players[i].connected==1)
1780 network_send_endlevel_short_sub(player_num,i);
1782 if (Network_game_type == IPX_GAME)
1783 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);
1786 appletalk_send_packet_data( (ubyte *)&end, sizeof(endlevel_info), NetPlayers.players[i].network.appletalk.node,
1787 NetPlayers.players[i].network.appletalk.net,
1788 NetPlayers.players[i].network.appletalk.socket);
1796 network_send_endlevel_packet(void)
1798 // Send an updated endlevel status to other hosts
1800 network_send_endlevel_sub(Player_num);
1805 network_send_endlevel_short_sub(int from_player_num,int to_player)
1807 endlevel_info_short end;
1809 // Send an endlevel packet for a player
1810 end.type = PID_ENDLEVEL_SHORT;
1811 end.player_num = from_player_num;
1812 end.connected = Players[from_player_num].connected;
1813 end.seconds_left = Countdown_seconds_left;
1816 if (Players[from_player_num].connected == 1) // Still playing
1818 Assert(Control_center_destroyed);
1821 if ((to_player != Player_num) && (to_player!=from_player_num) && (Players[to_player].connected))
1823 mprintf((0, "Sending short endlevel packet to %s.\n",Players[to_player].callsign));
1824 if (Network_game_type == IPX_GAME)
1825 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);
1828 appletalk_send_packet_data( (ubyte *)&end, sizeof(endlevel_info_short), NetPlayers.players[to_player].network.appletalk.node,
1829 NetPlayers.players[to_player].network.appletalk.net,
1830 NetPlayers.players[to_player].network.appletalk.socket);
1835 extern fix ThisLevelTime;
1838 network_send_game_info(sequence_packet *their)
1840 // Send game info to someone who requested it
1842 char old_type, old_status;
1846 mprintf((0, "Sending game info.\n"));
1848 network_update_netgame(); // Update the values in the netgame struct
1850 old_type = Netgame.type;
1851 old_status = Netgame.game_status;
1853 Netgame.type = PID_GAME_INFO;
1854 NetPlayers.type = PID_PLAYERSINFO;
1856 NetPlayers.Security=Netgame.Security;
1857 Netgame.version_major=Version_major;
1858 Netgame.version_minor=Version_minor;
1860 if (Endlevel_sequence || Control_center_destroyed)
1861 Netgame.game_status = NETSTAT_ENDLEVEL;
1863 if (Netgame.PlayTimeAllowed)
1865 timevar=i2f (Netgame.PlayTimeAllowed*5*60);
1866 i=f2i(timevar-ThisLevelTime);
1868 Netgame.game_status=NETSTAT_ENDLEVEL;
1872 if (Network_game_type == IPX_GAME) {
1873 send_broadcast_full_netgame_packet();
1874 send_broadcast_netplayers_packet();
1875 } // nothing to do for appletalk games I think....
1877 if (Network_game_type == IPX_GAME) {
1878 send_internetwork_full_netgame_packet(their->player.network.ipx.server, their->player.network.ipx.node);
1879 send_netplayers_packet(their->player.network.ipx.server, their->player.network.ipx.node);
1882 appletalk_send_packet_data( (ubyte *)&Netgame, sizeof(netgame_info), their->player.network.appletalk.node,
1883 their->player.network.appletalk.net, their->player.network.appletalk.socket );
1884 appletalk_send_packet_data( (ubyte *)&NetPlayers, sizeof(AllNetPlayers_info), their->player.network.appletalk.node,
1885 their->player.network.appletalk.net, their->player.network.appletalk.socket );
1890 Netgame.type = old_type;
1891 Netgame.game_status = old_status;
1894 void network_send_lite_info(sequence_packet *their)
1896 // Send game info to someone who requested it
1898 char old_type, old_status,oldstatus;
1900 mprintf((0, "Sending lite game info.\n"));
1902 network_update_netgame(); // Update the values in the netgame struct
1904 old_type = Netgame.type;
1905 old_status = Netgame.game_status;
1907 Netgame.type = PID_LITE_INFO;
1909 if (Endlevel_sequence || Control_center_destroyed)
1910 Netgame.game_status = NETSTAT_ENDLEVEL;
1912 // If hoard mode, make this game look closed even if it isn't
1913 if (HoardEquipped())
1915 if (Game_mode & GM_HOARD)
1917 oldstatus=Netgame.game_status;
1918 Netgame.game_status=NETSTAT_ENDLEVEL;
1919 Netgame.gamemode=NETGAME_CAPTURE_FLAG;
1920 if (oldstatus==NETSTAT_ENDLEVEL)
1921 Netgame.game_flags|=NETGAME_FLAG_REALLY_ENDLEVEL;
1922 if (oldstatus==NETSTAT_STARTING)
1923 Netgame.game_flags|=NETGAME_FLAG_REALLY_FORMING;
1928 if (Network_game_type == IPX_GAME) {
1929 send_broadcast_lite_netgame_packet();
1930 } // nothing to do for appletalk I think....
1932 if (Network_game_type == IPX_GAME) {
1933 send_internetwork_lite_netgame_packet(their->player.network.ipx.server, their->player.network.ipx.node);
1936 appletalk_send_packet_data( (ubyte *)&Netgame, sizeof(lite_info), their->player.network.appletalk.node,
1937 their->player.network.appletalk.net, their->player.network.appletalk.socket );
1942 // Restore the pre-hoard mode
1943 if (HoardEquipped())
1945 if (Game_mode & GM_HOARD)
1947 if (!(Game_mode & GM_TEAM))
1948 Netgame.gamemode=NETGAME_HOARD;
1950 Netgame.gamemode=NETGAME_TEAM_HOARD;
1951 Netgame.game_flags&=~NETGAME_FLAG_REALLY_ENDLEVEL;
1952 Netgame.game_flags&=~NETGAME_FLAG_REALLY_FORMING;
1953 Netgame.game_flags&=~NETGAME_FLAG_TEAM_HOARD;
1957 Netgame.type = old_type;
1958 Netgame.game_status = old_status;
1962 void network_send_netgame_update()
1964 // Send game info to someone who requested it
1966 char old_type, old_status;
1969 mprintf((0, "Sending updated game info.\n"));
1971 network_update_netgame(); // Update the values in the netgame struct
1973 old_type = Netgame.type;
1974 old_status = Netgame.game_status;
1976 Netgame.type = PID_GAME_UPDATE;
1978 if (Endlevel_sequence || Control_center_destroyed)
1979 Netgame.game_status = NETSTAT_ENDLEVEL;
1981 for (i=0; i<N_players; i++ ) {
1982 if ( (Players[i].connected) && (i!=Player_num ) ) {
1983 if (Network_game_type == IPX_GAME) {
1984 send_lite_netgame_packet(NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node, Players[i].net_address);
1987 appletalk_send_packet_data( (ubyte *)&Netgame, sizeof(lite_info), NetPlayers.players[i].network.appletalk.node,
1988 NetPlayers.players[i].network.appletalk.net, NetPlayers.players[i].network.appletalk.socket );
1994 Netgame.type = old_type;
1995 Netgame.game_status = old_status;
1998 int network_send_request(void)
2000 // Send a request to join a game 'Netgame'. Returns 0 if we can join this
2001 // game, non-zero if there is some problem.
2004 if (Netgame.numplayers < 1)
2007 for (i = 0; i < MAX_NUM_NET_PLAYERS; i++)
2008 if (NetPlayers.players[i].connected)
2011 Assert(i < MAX_NUM_NET_PLAYERS);
2013 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));
2015 // segments_checksum = netmisc_calc_checksum( Segments, sizeof(segment)*(Highest_segment_index+1) );
2017 My_Seq.type = PID_REQUEST;
2018 My_Seq.player.connected = Current_level_num;
2020 if (Network_game_type == IPX_GAME) {
2021 send_internetwork_sequence_packet(My_Seq, NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node);
2024 appletalk_send_packet_data( (ubyte *)&My_Seq, sizeof(sequence_packet), NetPlayers.players[i].network.appletalk.node,
2025 NetPlayers.players[i].network.appletalk.net,
2026 NetPlayers.players[i].network.appletalk.socket);
2033 int SecurityCheck=0;
2035 void network_process_gameinfo(ubyte *data)
2038 netgame_info *new = (netgame_info *)data;
2039 #ifdef WORDS_BIGENDIAN
2040 netgame_info tmp_info;
2042 if (Network_game_type == IPX_GAME) {
2043 receive_netgame_packet(data, &tmp_info, 0); // get correctly aligned structure
2049 WaitingForPlayerInfo=0;
2051 if (new->Security !=TempPlayersInfo->Security)
2053 Int3(); // Get Jason
2054 return; // If this first half doesn't go with the second half
2057 Network_games_changed = 1;
2059 //mprintf((0, "Got game data for game %s.\n", new->game_name));
2061 Assert (TempPlayersInfo!=NULL);
2063 for (i = 0; i < num_active_games; i++)
2065 //mprintf ((0,"GAMEINFO: Game %d is %s!\n",i,Active_games[i].game_name));
2067 if (!stricmp(Active_games[i].game_name, new->game_name) &&
2068 Active_games[i].Security==new->Security)
2072 if (i == MAX_ACTIVE_NETGAMES)
2074 mprintf((0, "Too many netgames.\n"));
2078 // MWA memcpy(&Active_games[i], data, sizeof(netgame_info));
2079 memcpy(&Active_games[i], (ubyte *)new, sizeof(netgame_info));
2080 memcpy (&ActiveNetPlayers[i],TempPlayersInfo,sizeof(AllNetPlayers_info));
2083 if (Active_games[i].Security==SecurityCheck)
2086 //mprintf ((0,"Recieved %d unique games...\n",i));
2088 if (i == num_active_games)
2091 if (Active_games[i].numplayers == 0)
2093 mprintf ((0,"DELETING THIS GAME!!!\n"));
2095 for (j = i; j < num_active_games-1; j++)
2097 memcpy(&Active_games[j], &Active_games[j+1], sizeof(netgame_info));
2098 memcpy (&ActiveNetPlayers[j],&ActiveNetPlayers[j+1],sizeof(AllNetPlayers_info));
2105 void network_process_lite_info(ubyte *data)
2108 lite_info *new = (lite_info *)data;
2109 #ifdef WORDS_BIGENDIAN
2112 if (Network_game_type == IPX_GAME) {
2113 receive_netgame_packet(data, (netgame_info *)&tmp_info, 1);
2118 Network_games_changed = 1;
2120 //mprintf((0, "Got game data for game %s.\n", new->game_name));
2122 for (i = 0; i < num_active_games; i++)
2124 //mprintf ((0,"GAMEINFO: Game %d is %s!\n",i,Active_games[i].game_name));
2126 if ((!stricmp(Active_games[i].game_name, new->game_name)) &&
2127 Active_games[i].Security==new->Security)
2131 if (i == MAX_ACTIVE_NETGAMES)
2133 mprintf((0, "Too many netgames.\n"));
2137 memcpy(&Active_games[i], (ubyte *)new, sizeof(lite_info));
2139 // See if this is really a Hoard game
2140 // If so, adjust all the data accordingly
2142 if (HoardEquipped())
2144 if (Active_games[i].game_flags & NETGAME_FLAG_HOARD)
2146 Active_games[i].gamemode=NETGAME_HOARD;
2147 Active_games[i].game_status=NETSTAT_PLAYING;
2149 if (Active_games[i].game_flags & NETGAME_FLAG_TEAM_HOARD)
2150 Active_games[i].gamemode=NETGAME_TEAM_HOARD;
2151 if (Active_games[i].game_flags & NETGAME_FLAG_REALLY_ENDLEVEL)
2152 Active_games[i].game_status=NETSTAT_ENDLEVEL;
2153 if (Active_games[i].game_flags & NETGAME_FLAG_REALLY_FORMING)
2154 Active_games[i].game_status=NETSTAT_STARTING;
2158 //mprintf ((0,"Recieved %d unique games...\n",i));
2160 if (i == num_active_games)
2163 if (Active_games[i].numplayers == 0)
2165 mprintf ((0,"DELETING THIS GAME!!!\n"));
2167 for (j = i; j < num_active_games-1; j++)
2169 memcpy(&Active_games[j], &Active_games[j+1], sizeof(netgame_info));
2175 void network_process_dump(sequence_packet *their)
2177 // Our request for join was denied. Tell the user why.
2182 mprintf((0, "Dumped by player %s, type %d.\n", their->player.callsign, their->player.connected));
2184 if (their->player.connected!=7)
2185 nm_messagebox(NULL, 1, TXT_OK, NET_DUMP_STRINGS(their->player.connected));
2188 for (i=0;i<N_players;i++)
2189 if (!stricmp (their->player.callsign,Players[i].callsign))
2191 if (i!=network_who_is_master())
2193 HUD_init_message ("%s attempted to kick you out.",their->player.callsign);
2197 sprintf (temp,"%s has kicked you out!",their->player.callsign);
2198 nm_messagebox(NULL, 1, TXT_OK, &temp);
2199 if (Network_status==NETSTAT_PLAYING)
2205 Network_status = NETSTAT_MENU;
2210 void network_process_request(sequence_packet *their)
2212 // Player is ready to receieve a sync packet
2215 mprintf((0, "Player %s ready for sync.\n", their->player.callsign));
2217 for (i = 0; i < N_players; i++) {
2218 if (Network_game_type == IPX_GAME) {
2219 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))) {
2220 Players[i].connected = 1;
2224 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)) ) {
2225 Players[i].connected = 1;
2232 #define REFUSE_INTERVAL F1_0 * 8
2233 extern void multi_reset_object_texture (object *);
2235 void network_process_packet(ubyte *data, int length )
2237 sequence_packet *their = (sequence_packet *)data;
2238 #ifdef WORDS_BIGENDIAN
2239 sequence_packet tmp_packet;
2241 if (Network_game_type == IPX_GAME) {
2242 receive_sequence_packet(data, &tmp_packet);
2243 their = &tmp_packet; // reassign their to point to correctly alinged structure
2247 //mprintf( (0, "Got packet of length %d, type %d\n", length, their->type ));
2249 // if ( length < sizeof(sequence_packet) ) return;
2255 case PID_GAME_INFO: // Jason L. says we can safely ignore this type.
2258 case PID_PLAYERSINFO:
2260 mprintf ((0,"Got a PID_PLAYERSINFO!\n"));
2262 if (Network_status==NETSTAT_WAITING)
2264 if (Network_game_type == IPX_GAME)
2265 receive_netplayers_packet(data, &TempPlayersBase);
2267 memcpy (&TempPlayersBase,data,sizeof(AllNetPlayers_info));
2269 if (TempPlayersBase.Security!=Netgame.Security)
2271 mprintf ((0,"Bad security for PLAYERSINFO\n"));
2275 mprintf ((0,"Got a waiting PID_PLAYERSINFO!\n"));
2276 if (length!=ALLNETPLAYERSINFO_SIZE)
2278 mprintf ((0,"Invalid size for netplayers packet!\n"));
2282 TempPlayersInfo=&TempPlayersBase;
2283 WaitingForPlayerInfo=0;
2284 NetSecurityNum=TempPlayersInfo->Security;
2285 NetSecurityFlag=NETSECURITY_WAIT_FOR_SYNC;
2292 if (length != LITE_INFO_SIZE)
2294 mprintf ((0,"WARNING! Recieved invalid size for PID_LITE_INFO\n"));
2298 if (Network_status == NETSTAT_BROWSING)
2299 network_process_lite_info (data);
2303 // Someone wants a list of games
2305 if (length != SEQUENCE_PACKET_SIZE)
2307 mprintf ((0,"WARNING! Recieved invalid size for PID_GAME_LIST\n"));
2311 mprintf((0, "Got a PID_GAME_LIST!\n"));
2312 if ((Network_status == NETSTAT_PLAYING) || (Network_status == NETSTAT_STARTING) || (Network_status == NETSTAT_ENDLEVEL))
2313 if (network_i_am_master())
2314 network_send_lite_info(their);
2318 case PID_SEND_ALL_GAMEINFO:
2320 if (length != SEQUENCE_PACKET_SIZE)
2322 mprintf ((0,"WARNING! Recieved invalid size for PID_SEND_ALL_GAMEINFO\n"));
2326 if ((Network_status == NETSTAT_PLAYING) || (Network_status == NETSTAT_STARTING) || (Network_status == NETSTAT_ENDLEVEL))
2327 if (network_i_am_master() && their->Security==Netgame.Security)
2328 network_send_game_info(their);
2333 mprintf( (0, "Got NEWPLAYER message from %s.\n", their->player.callsign));
2335 if (length != SEQUENCE_PACKET_SIZE)
2337 mprintf ((0,"WARNING! Recieved invalid size for PID_ADDPLAYER\n"));
2340 mprintf( (0, "Got NEWPLAYER message from %s.\n", their->player.callsign));
2341 network_new_player(their);
2344 if (length != SEQUENCE_PACKET_SIZE)
2346 mprintf ((0,"WARNING! Recieved invalid size for PID_REQUEST\n"));
2350 mprintf( (0, "Got REQUEST from '%s'\n", their->player.callsign ));
2351 if (Network_status == NETSTAT_STARTING)
2353 // Someone wants to join our game!
2354 network_add_player(their);
2356 else if (Network_status == NETSTAT_WAITING)
2358 // Someone is ready to recieve a sync packet
2359 network_process_request(their);
2361 else if (Network_status == NETSTAT_PLAYING)
2363 // Someone wants to join a game in progress!
2364 if (Netgame.RefusePlayers)
2365 DoRefuseStuff (their);
2367 network_welcome_player(their);
2372 if (length != SEQUENCE_PACKET_SIZE)
2374 mprintf ((0,"WARNING! Recieved invalid size for PID_DUMP\n"));
2378 if (Network_status == NETSTAT_WAITING || Network_status==NETSTAT_PLAYING )
2379 network_process_dump(their);
2381 case PID_QUIT_JOINING:
2383 if (length != SEQUENCE_PACKET_SIZE)
2385 mprintf ((0,"WARNING! Recieved invalid size for PID_QUIT_JOINING\n"));
2388 if (Network_status == NETSTAT_STARTING)
2389 network_remove_player( their );
2390 else if ((Network_status == NETSTAT_PLAYING) && (Network_send_objects))
2391 network_stop_resync( their );
2395 mprintf ((0,"Got a sync packet! Network_status=%d\n",NETSTAT_WAITING));
2397 if (Network_status == NETSTAT_WAITING) {
2399 if (Network_game_type == IPX_GAME)
2400 receive_full_netgame_packet(data, &TempNetInfo);
2402 memcpy((ubyte *)&(TempNetInfo), data, sizeof(netgame_info));
2404 if (TempNetInfo.Security!=Netgame.Security)
2406 mprintf ((0,"Bad security on sync packet.\n"));
2410 if (NetSecurityFlag==NETSECURITY_WAIT_FOR_SYNC)
2412 if (TempNetInfo.Security==TempPlayersInfo->Security)
2414 network_read_sync_packet (&TempNetInfo,0);
2421 NetSecurityFlag=NETSECURITY_WAIT_FOR_PLAYERS;
2422 NetSecurityNum=TempNetInfo.Security;
2424 if ( network_wait_for_playerinfo())
2425 network_read_sync_packet((netgame_info *)data,0);
2434 if ((Game_mode&GM_NETWORK) && ((Network_status == NETSTAT_PLAYING)||(Network_status == NETSTAT_ENDLEVEL) || Network_status==NETSTAT_WAITING)) {
2435 network_process_pdata((char *)data);
2438 case PID_NAKED_PDATA:
2439 if ((Game_mode&GM_NETWORK) && ((Network_status == NETSTAT_PLAYING)||(Network_status == NETSTAT_ENDLEVEL) || Network_status==NETSTAT_WAITING))
2440 network_process_naked_pdata((char *)data,length);
2443 case PID_OBJECT_DATA:
2444 if (Network_status == NETSTAT_WAITING)
2445 network_read_object_packet(data);
2448 if ((Network_status == NETSTAT_ENDLEVEL) || (Network_status == NETSTAT_PLAYING))
2449 network_read_endlevel_packet(data);
2451 mprintf((0, "Junked endlevel packet.\n"));
2453 case PID_ENDLEVEL_SHORT:
2454 if ((Network_status == NETSTAT_ENDLEVEL) || (Network_status == NETSTAT_PLAYING))
2455 network_read_endlevel_short_packet(data);
2457 mprintf((0, "Junked short endlevel packet!\n"));
2460 case PID_GAME_UPDATE:
2461 mprintf ((0,"Got a GAME_UPDATE!\n"));
2463 if (Network_status==NETSTAT_PLAYING)
2465 if (Network_game_type == IPX_GAME)
2466 receive_lite_netgame_packet(data, &TempNetInfo);
2468 memcpy((ubyte *)&TempNetInfo, data, sizeof(lite_info) );
2469 if (TempNetInfo.Security==Netgame.Security)
2470 memcpy (&Netgame,(ubyte *)&TempNetInfo,sizeof(lite_info));
2472 if (Game_mode & GM_TEAM)
2476 for (i=0;i<N_players;i++)
2477 if (Players[i].connected)
2478 multi_reset_object_texture (&Objects[Players[i].objnum]);
2483 network_ping (PID_PING_RETURN,data[1]);
2485 case PID_PING_RETURN:
2486 network_handle_ping_return(data[1]); // data[1] is player who told us of their ping time
2488 case PID_NAMES_RETURN:
2489 if (Network_status==NETSTAT_BROWSING && NamesInfoSecurity!=-1)
2490 network_process_names_return (data);
2492 case PID_GAME_PLAYERS:
2493 // Someone wants a list of players in this game
2495 if (length != SEQUENCE_PACKET_SIZE)
2497 mprintf ((0,"WARNING! Recieved invalid size for PID_GAME_PLAYERS\n"));
2501 mprintf((0, "Got a PID_GAME_PLAYERS!\n"));
2502 if ((Network_status == NETSTAT_PLAYING) || (Network_status == NETSTAT_STARTING) || (Network_status == NETSTAT_ENDLEVEL))
2503 if (network_i_am_master() && their->Security==Netgame.Security)
2504 network_send_player_names(their);
2508 mprintf((0, "Ignoring invalid packet type.\n"));
2509 Int3(); // Invalid network packet type, see ROB
2515 void dump_segments()
2519 fp = fopen( "TEST.DMP", "wb" );
2520 fwrite( Segments, sizeof(segment)*(Highest_segment_index+1),1, fp );
2522 mprintf( (0, "SS=%d\n", sizeof(segment) ));
2528 network_read_endlevel_packet( ubyte *data )
2530 // Special packet for end of level syncing
2532 endlevel_info *end = (endlevel_info *)data;
2533 #ifdef WORDS_BIGENDIAN
2536 for (i = 0; i < MAX_PLAYERS; i++)
2537 for (j = 0; j < MAX_PLAYERS; j++)
2538 end->kill_matrix[i][j] = INTEL_SHORT(end->kill_matrix[i][j]);
2539 end->kills = INTEL_SHORT(end->kills);
2540 end->killed = INTEL_SHORT(end->killed);
2543 playernum = end->player_num;
2545 Assert(playernum != Player_num);
2547 if (playernum>=N_players)
2549 Int3(); // weird, but it an happen in a coop restore game
2550 return; // if it happens in a coop restore, don't worry about it
2553 if ((Network_status == NETSTAT_PLAYING) && (end->connected != 0))
2554 return; // Only accept disconnect packets if we're not out of the level yet
2556 Players[playernum].connected = end->connected;
2557 memcpy(&kill_matrix[playernum][0], end->kill_matrix, MAX_PLAYERS*sizeof(short));
2558 Players[playernum].net_kills_total = end->kills;
2559 Players[playernum].net_killed_total = end->killed;
2561 if ((Players[playernum].connected == 1) && (end->seconds_left < Countdown_seconds_left))
2562 Countdown_seconds_left = end->seconds_left;
2564 LastPacketTime[playernum] = timer_get_approx_seconds();
2566 // mprintf((0, "Got endlevel packet from player %d.\n", playernum));
2570 network_read_endlevel_short_packet( ubyte *data )
2572 // Special packet for end of level syncing
2575 endlevel_info_short *end;
2577 end = (endlevel_info_short *)data;
2579 playernum = end->player_num;
2581 Assert(playernum != Player_num);
2583 if (playernum>=N_players)
2585 Int3(); // weird, but it can happen in a coop restore game
2586 return; // if it happens in a coop restore, don't worry about it
2589 if ((Network_status == NETSTAT_PLAYING) && (end->connected != 0))
2591 //mprintf ((0,"Returning early for short_endlevel\n"));
2592 return; // Only accept disconnect packets if we're not out of the level yet
2595 Players[playernum].connected = end->connected;
2597 if ((Players[playernum].connected == 1) && (end->seconds_left < Countdown_seconds_left))
2598 Countdown_seconds_left = end->seconds_left;
2600 LastPacketTime[playernum] = timer_get_approx_seconds();
2605 network_pack_objects(void)
2607 // Switching modes, pack the object array
2609 special_reset_objects();
2613 network_verify_objects(int remote, int local)
2616 int nplayers, got_controlcen=0;
2618 mprintf ((0,"NETWORK:remote=%d local=%d\n",remote,local));
2620 if ((remote-local) > 10)
2623 if (Game_mode & GM_MULTI_ROBOTS)
2628 for (i = 0; i <= Highest_object_index; i++)
2630 if ((Objects[i].type == OBJ_PLAYER) || (Objects[i].type == OBJ_GHOST))
2632 if (Objects[i].type == OBJ_CNTRLCEN)
2636 if (got_controlcen && (MaxNumNetPlayers<=nplayers))
2643 network_read_object_packet( ubyte *data )
2645 // Object from another net player we need to sync with
2647 short objnum, remote_objnum;
2652 static int my_pnum = 0;
2653 static int mode = 0;
2654 static int object_count = 0;
2655 static int frame_num = 0;
2658 int remote_frame_num = data[2];
2662 // mprintf((0, "Object packet %d (remote #%d) contains %d objects.\n", frame_num, remote_frame_num, nobj));
2664 for (i = 0; i < nobj; i++)
2666 objnum = INTEL_SHORT( *(short *)(data+loc) ); loc += 2;
2667 obj_owner = data[loc]; loc += 1;
2668 remote_objnum = INTEL_SHORT( *(short *)(data+loc) ); loc += 2;
2672 // Clear object array
2673 mprintf((0, "Clearing object array.\n"));
2676 Network_rejoined = 1;
2677 my_pnum = obj_owner;
2678 change_playernum_to(my_pnum);
2683 else if (objnum == -2)
2685 // Special debug checksum marker for entire send
2688 network_pack_objects();
2691 mprintf((0, "Objnum -2 found in frame local %d remote %d.\n", frame_num, remote_frame_num));
2692 mprintf((0, "Got %d objects, expected %d.\n", object_count, remote_objnum));
2693 if (remote_objnum != object_count) {
2696 if (network_verify_objects(remote_objnum, object_count))
2698 // Failed to sync up
2699 nm_messagebox(NULL, 1, TXT_OK, TXT_NET_SYNC_FAILED);
2700 Network_status = NETSTAT_MENU;
2707 if (frame_num != remote_frame_num)
2709 mprintf ((0,"Got a type 3 object packet!\n"));
2711 if ((obj_owner == my_pnum) || (obj_owner == -1))
2715 objnum = remote_objnum;
2716 //if (objnum > Highest_object_index)
2718 // Highest_object_index = objnum;
2719 // num_objects = Highest_object_index+1;
2725 network_pack_objects();
2728 objnum = obj_allocate();
2731 obj = &Objects[objnum];
2732 if (obj->segnum != -1)
2734 Assert(obj->segnum == -1);
2735 Assert(objnum < MAX_OBJECTS);
2736 memcpy(obj, &data[loc], sizeof(object));
2737 if (Network_game_type == IPX_GAME)
2739 loc += sizeof(object);
2740 segnum = obj->segnum;
2741 obj->next = obj->prev = obj->segnum = -1;
2742 obj->attached_obj = -1;
2744 obj_link(obj-Objects,segnum);
2745 if (obj_owner == my_pnum)
2746 map_objnum_local_to_local(objnum);
2747 else if (obj_owner != -1)
2748 map_objnum_local_to_remote(objnum, remote_objnum, obj_owner);
2750 object_owner[objnum] = -1;
2752 } // For a standard onbject
2753 } // For each object in packet
2756 void network_sync_poll( int nitems, newmenu_item * menus, int * key, int citem )
2758 // Polling loop waiting for sync packet to start game
2768 if (Network_status != NETSTAT_WAITING) // Status changed to playing, exit the menu
2771 if (!Network_rejoined && (timer_get_approx_seconds() > t1+F1_0*2))
2775 // Poll time expired, re-send request
2777 t1 = timer_get_approx_seconds();
2779 mprintf((0, "Re-sending join request.\n"));
2780 i = network_send_request();
2786 void network_start_poll( int nitems, newmenu_item * menus, int * key, int citem )
2793 Assert(Network_status == NETSTAT_STARTING);
2795 if (!menus[0].value) {
2797 menus[0].redraw = 1;
2800 for (i=1; i<nitems; i++ ) {
2801 if ( (i>= N_players) && (menus[i].value) ) {
2803 menus[i].redraw = 1;
2808 for (i=0; i<nitems; i++ ) {
2809 if ( menus[i].value ) {
2811 if ( nm > N_players ) {
2813 menus[i].redraw = 1;
2818 if ( nm > MaxNumNetPlayers ) {
2819 nm_messagebox( TXT_ERROR, 1, TXT_OK, "%s %d %s", TXT_SORRY_ONLY, MaxNumNetPlayers, TXT_NETPLAYERS_IN );
2820 // Turn off the last player highlighted
2821 for (i = N_players; i > 0; i--)
2822 if (menus[i].value == 1)
2825 menus[i].redraw = 1;
2830 // if (nitems > MAX_PLAYERS ) return;
2832 n = Netgame.numplayers;
2835 if (n < Netgame.numplayers )
2837 digi_play_sample (SOUND_HUD_MESSAGE,F1_0);
2839 mprintf ((0,"More players are printed!"));
2840 if (FindArg("-norankings"))
2841 sprintf( menus[N_players-1].text, "%d. %-20s", N_players,NetPlayers.players[N_players-1].callsign );
2843 sprintf( menus[N_players-1].text, "%d. %s%-20s", N_players, RankStrings[NetPlayers.players[N_players-1].rank],NetPlayers.players[N_players-1].callsign );
2845 menus[N_players-1].redraw = 1;
2846 if (N_players <= MaxNumNetPlayers)
2848 menus[N_players-1].value = 1;
2851 else if ( n > Netgame.numplayers )
2853 // One got removed...
2855 digi_play_sample (SOUND_HUD_KILL,F1_0);
2857 for (i=0; i<N_players; i++ )
2860 if (FindArg("-norankings"))
2861 sprintf( menus[i].text, "%d. %-20s", i+1, NetPlayers.players[i].callsign );
2863 sprintf( menus[i].text, "%d. %s%-20s", i+1, RankStrings[NetPlayers.players[i].rank],NetPlayers.players[i].callsign );
2864 if (i < MaxNumNetPlayers)
2868 menus[i].redraw = 1;
2870 for (i=N_players; i<n; i++ )
2872 sprintf( menus[i].text, "%d. ", i+1 ); // Clear out the deleted entries...
2874 menus[i].redraw = 1;
2879 int opt_cinvul, opt_team_anarchy, opt_coop, opt_show_on_map, opt_closed,opt_maxnet;
2880 int last_cinvul=0,last_maxnet,opt_team_hoard;
2881 int opt_refuse,opt_capture;
2883 void network_game_param_poll( int nitems, newmenu_item * menus, int * key, int citem )
2885 static int oldmaxnet=0;
2887 if (((HoardEquipped() && menus[opt_team_hoard].value) || (menus[opt_team_anarchy].value || menus[opt_capture].value)) && !menus[opt_closed].value && !menus[opt_refuse].value) {
2888 menus[opt_refuse].value = 1;
2889 menus[opt_refuse].redraw = 1;
2890 menus[opt_refuse-1].value = 0;
2891 menus[opt_refuse-1].redraw = 1;
2892 menus[opt_refuse-2].value = 0;
2893 menus[opt_refuse-2].redraw = 1;
2897 if (menus[opt_coop].value)
2899 if ( (menus[opt_coop].value) || ((Network_game_type == APPLETALK_GAME) && (Network_appletalk_type == LOCALTALK_TYPE) && (menus[opt_coop-1].value)) )
2904 if (menus[opt_maxnet].value>2)
2906 menus[opt_maxnet].value=2;
2907 menus[opt_maxnet].redraw=1;
2910 if (menus[opt_maxnet].max_value>2)
2912 menus[opt_maxnet].max_value=2;
2913 menus[opt_maxnet].redraw=1;
2917 if ( (Network_game_type == APPLETALK_GAME) && (Network_appletalk_type == LOCALTALK_TYPE) ) {
2918 if (menus[opt_maxnet].value > 0) {
2919 menus[opt_maxnet].value=0;
2920 menus[opt_maxnet].redraw=1;
2922 if (menus[opt_maxnet].max_value > 0) {
2923 menus[opt_maxnet].max_value=0;
2924 menus[opt_maxnet].redraw=1;
2929 if (!Netgame.game_flags & NETGAME_FLAG_SHOW_MAP)
2930 Netgame.game_flags |= NETGAME_FLAG_SHOW_MAP;
2932 if (Netgame.PlayTimeAllowed || Netgame.KillGoal)
2934 Netgame.PlayTimeAllowed=0;
2939 else // if !Coop game
2944 menus[opt_maxnet].value=6;
2945 menus[opt_maxnet].max_value=6;
2948 if ( (Network_game_type == APPLETALK_GAME) && (Network_appletalk_type == LOCALTALK_TYPE) ) {
2949 menus[opt_maxnet].value=1;
2950 menus[opt_maxnet].max_value=1;
2957 if ( last_maxnet != menus[opt_maxnet].value )
2959 sprintf( menus[opt_maxnet].text, "Maximum players: %d", menus[opt_maxnet].value+2 );
2960 last_maxnet = menus[opt_maxnet].value;
2961 menus[opt_maxnet].redraw = 1;
2965 int netgame_difficulty;
2967 int network_get_game_params( char * game_name, int *mode, int *game_flags, int *level )
2970 int opt, opt_name, opt_level, opt_mode,opt_moreopts;
2972 char name[NETGAME_NAME_LEN+1];
2974 char level_text[32];
2977 int new_mission_num;
2980 *game_flags=*game_flags;
2982 SetAllAllowablesTo (1);
2983 NamesInfoSecurity=-1;
2985 for (i=0;i<MAX_PLAYERS;i++)
2987 Players[i].callsign[0]=0;
2991 Netgame.PlayTimeAllowed=0;
2992 Netgame.Allow_marker_view=1;
2993 netgame_difficulty=Player_default_difficulty;
2995 new_mission_num = multi_choose_mission(&anarchy_only);
2997 if (new_mission_num < 0)
3000 if (!(FindArg ("-packets") && FindArg ("-shortpackets")))
3001 if (!network_choose_connect ())
3005 if ( (Network_game_type == APPLETALK_GAME) && (Network_appletalk_type == LOCALTALK_TYPE) )
3006 MaxNumNetPlayers = 3;
3009 strcpy(Netgame.mission_name, Mission_list[new_mission_num].filename);
3010 strcpy(Netgame.mission_title, Mission_list[new_mission_num].mission_name);
3011 Netgame.control_invul_time = control_invul_time;
3013 sprintf( name, "%s%s", Players[Player_num].callsign, TXT_S_GAME );
3014 sprintf( slevel, "1" );
3017 m[opt].type = NM_TYPE_TEXT; m[opt].text = TXT_DESCRIPTION; opt++;
3020 m[opt].type = NM_TYPE_INPUT; m[opt].text = name; m[opt].text_len = NETGAME_NAME_LEN; opt++;
3022 sprintf(level_text, "%s (1-%d)", TXT_LEVEL_, Last_level);
3024 // if (Last_secret_level < -1)
3025 // sprintf(level_text+strlen(level_text)-1, ", S1-S%d)", -Last_secret_level);
3026 // else if (Last_secret_level == -1)
3027 // sprintf(level_text+strlen(level_text)-1, ", S1)");
3029 Assert(strlen(level_text) < 32);
3031 m[opt].type = NM_TYPE_TEXT; m[opt].text = level_text; opt++;
3034 m[opt].type = NM_TYPE_INPUT; m[opt].text = slevel; m[opt].text_len=4; opt++;
3035 // m[opt].type = NM_TYPE_TEXT; m[opt].text = TXT_OPTIONS; opt++;
3038 m[opt].type = NM_TYPE_RADIO; m[opt].text = TXT_ANARCHY; m[opt].value=1; m[opt].group=0; opt++;
3039 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++;
3040 m[opt].type = NM_TYPE_RADIO; m[opt].text = TXT_ANARCHY_W_ROBOTS; m[opt].value=0; m[opt].group=0; opt++;
3041 m[opt].type = NM_TYPE_RADIO; m[opt].text = TXT_COOPERATIVE; m[opt].value=0; m[opt].group=0; opt_coop=opt; opt++;
3042 m[opt].type = NM_TYPE_RADIO; m[opt].text = "Capture the flag"; m[opt].value=0; m[opt].group=0; opt_capture=opt; opt++;
3044 if (HoardEquipped())
3046 m[opt].type = NM_TYPE_RADIO; m[opt].text = "Hoard"; m[opt].value=0; m[opt].group=0; opt++;
3047 m[opt].type = NM_TYPE_RADIO; m[opt].text = "Team Hoard"; m[opt].value=0; m[opt].group=0; opt_team_hoard=opt; opt++;
3048 m[opt].type = NM_TYPE_TEXT; m[opt].text = ""; opt++;
3051 { m[opt].type = NM_TYPE_TEXT; m[opt].text = ""; opt++; }
3053 m[opt].type = NM_TYPE_RADIO; m[opt].text = "Open game"; m[opt].group=1; m[opt].value=0; opt++;
3055 m[opt].type = NM_TYPE_RADIO; m[opt].text = TXT_CLOSED_GAME; m[opt].group=1; m[opt].value=0; opt++;
3057 m[opt].type = NM_TYPE_RADIO; m[opt].text = "Restricted Game "; m[opt].group=1; m[opt].value=Netgame.RefusePlayers; opt++;
3059 // m[opt].type = NM_TYPE_CHECK; m[opt].text = TXT_SHOW_IDS; m[opt].value=0; opt++;
3062 sprintf( srmaxnet, "Maximum players: %d", MaxNumNetPlayers);
3063 m[opt].type = NM_TYPE_SLIDER; m[opt].value=MaxNumNetPlayers-2; m[opt].text= srmaxnet; m[opt].min_value=0;
3064 m[opt].max_value=MaxNumNetPlayers-2; opt++;
3065 last_maxnet=MaxNumNetPlayers-2;
3068 m[opt].type = NM_TYPE_MENU; m[opt].text = "More options..."; opt++;
3073 ExtGameStatus=GAMESTAT_NETGAME_OPTIONS;
3074 i = newmenu_do1( NULL, NULL, opt, m, network_game_param_poll, 1 );
3076 if (i==opt_moreopts)
3078 if ( m[opt_mode+3].value )
3079 Game_mode=GM_MULTI_COOP;
3080 network_more_game_options();
3084 Netgame.RefusePlayers=m[opt_refuse].value;
3090 MaxNumNetPlayers = m[opt_maxnet].value+2;
3091 Netgame.max_numplayers=MaxNumNetPlayers;
3093 for (j = 0; j < num_active_games; j++)
3094 if (!stricmp(Active_games[j].game_name, name))
3096 nm_messagebox(TXT_ERROR, 1, TXT_OK, TXT_DUPLICATE_NAME);
3100 strcpy( game_name, name );
3103 *level = atoi(slevel);
3105 if ((*level < 1) || (*level > Last_level))
3107 nm_messagebox(TXT_ERROR, 1, TXT_OK, TXT_LEVEL_OUT_RANGE );
3108 sprintf(slevel, "1");
3111 if ( m[opt_mode].value )
3112 *mode = NETGAME_ANARCHY;
3117 nm_messagebox(TXT_SORRY, 1, TXT_OK, TXT_REGISTERED_ONLY );
3118 m[opt_mode+1].value = 0;
3119 m[opt_mode+2].value = 0;
3120 m[opt_mode+3].value = 0;
3121 if (HoardEquipped())
3122 m[opt_mode+4].value = 0;
3124 m[opt_mode].value = 1;
3128 else if (m[opt_mode+1].value) {
3129 *mode = NETGAME_TEAM_ANARCHY;
3131 else if (m[opt_capture].value)
3132 *mode = NETGAME_CAPTURE_FLAG;
3133 else if (HoardEquipped() && m[opt_capture+1].value)
3134 *mode = NETGAME_HOARD;
3135 else if (HoardEquipped() && m[opt_capture+2].value)
3136 *mode = NETGAME_TEAM_HOARD;
3137 else if (anarchy_only) {
3138 nm_messagebox(NULL, 1, TXT_OK, TXT_ANARCHY_ONLY_MISSION);
3139 m[opt_mode+2].value = 0;
3140 m[opt_mode+3].value = 0;
3141 m[opt_mode].value = 1;
3144 else if ( m[opt_mode+2].value )
3145 *mode = NETGAME_ROBOT_ANARCHY;
3146 else if ( m[opt_mode+3].value )
3147 *mode = NETGAME_COOPERATIVE;
3148 else Int3(); // Invalid mode -- see Rob
3150 if (m[opt_closed].value)
3151 Netgame.game_flags |= NETGAME_FLAG_CLOSED;
3159 network_set_game_mode(int gamemode)
3163 if ( gamemode == NETGAME_ANARCHY )
3164 Game_mode = GM_NETWORK;
3165 else if ( gamemode == NETGAME_ROBOT_ANARCHY )
3166 Game_mode = GM_NETWORK | GM_MULTI_ROBOTS;
3167 else if ( gamemode == NETGAME_COOPERATIVE )
3168 Game_mode = GM_NETWORK | GM_MULTI_COOP | GM_MULTI_ROBOTS;
3169 else if (gamemode == NETGAME_CAPTURE_FLAG)
3171 Game_mode = GM_NETWORK | GM_TEAM | GM_CAPTURE;
3175 else if (HoardEquipped() && gamemode == NETGAME_HOARD)
3176 Game_mode = GM_NETWORK | GM_HOARD;
3177 else if (HoardEquipped() && gamemode == NETGAME_TEAM_HOARD)
3179 Game_mode = GM_NETWORK | GM_HOARD | GM_TEAM;
3182 else if ( gamemode == NETGAME_TEAM_ANARCHY )
3184 Game_mode = GM_NETWORK | GM_TEAM;
3191 #ifdef MACINTOSH // minimize players on localtalk games
3192 if ( (Network_game_type == APPLETALK_GAME) && (Network_appletalk_type == LOCALTALK_TYPE) ) {
3193 if (Game_mode & GM_MULTI_ROBOTS)
3194 MaxNumNetPlayers = 2;
3196 MaxNumNetPlayers = 3;
3198 if (Game_mode & GM_MULTI_COOP)
3199 MaxNumNetPlayers = 4;
3201 MaxNumNetPlayers = 8;
3209 network_find_game(void)
3211 // Find out whether or not there is space left on this socket
3215 Network_status = NETSTAT_BROWSING;
3217 num_active_games = 0;
3219 show_boxed_message(TXT_WAIT);
3221 network_send_game_list_request();
3222 t1 = timer_get_approx_seconds() + F1_0*3;
3224 while (timer_get_approx_seconds() < t1) // Wait 3 seconds for replies
3227 clear_boxed_message();
3229 // mprintf((0, "%s %d %s\n", TXT_FOUND, num_active_games, TXT_ACTIVE_GAMES));
3231 if (num_active_games < MAX_ACTIVE_NETGAMES)
3236 void network_read_sync_packet( netgame_info * sp, int rsinit)
3239 char temp_callsign[CALLSIGN_LEN+1];
3240 #ifdef WORDS_BIGENDIAN
3241 netgame_info tmp_info;
3243 if ( (Network_game_type == IPX_GAME) && (sp != &Netgame) ) { // for macintosh -- get the values unpacked to our structure format
3244 receive_full_netgame_packet((ubyte *)sp, &tmp_info);
3250 TempPlayersInfo=&NetPlayers;
3252 // This function is now called by all people entering the netgame.
3254 // mprintf( (0, "%s %d\n", TXT_STARTING_NETGAME, sp->levelnum ));
3258 memcpy( &Netgame, sp, sizeof(netgame_info) );
3259 memcpy (&NetPlayers,TempPlayersInfo,sizeof (AllNetPlayers_info));
3262 N_players = sp->numplayers;
3263 Difficulty_level = sp->difficulty;
3264 Network_status = sp->game_status;
3266 //Assert(Function_mode != FMODE_GAME);
3270 mprintf((1, "Netgame.checksum = %d, calculated checksum = %d.\n", Netgame.segments_checksum, my_segments_checksum));
3272 if (Netgame.segments_checksum != my_segments_checksum)
3274 Network_status = NETSTAT_MENU;
3275 nm_messagebox(TXT_ERROR, 1, TXT_OK, TXT_NETLEVEL_NMATCH);
3281 // Discover my player number
3283 memcpy(temp_callsign, Players[Player_num].callsign, CALLSIGN_LEN+1);
3287 for (i=0; i<MAX_NUM_NET_PLAYERS; i++ ) {
3288 Players[i].net_kills_total = 0;
3289 // Players[i].net_killed_total = 0;
3292 for (i=0; i<N_players; i++ ) {
3293 if (Network_game_type == IPX_GAME) {
3294 if ( (!memcmp( TempPlayersInfo->players[i].network.ipx.node, My_Seq.player.network.ipx.node, 6 )) && (!stricmp( TempPlayersInfo->players[i].callsign, temp_callsign)) ) {
3295 if (Player_num!=-1) {
3296 Int3(); // Hey, we've found ourselves twice
3297 mprintf ((0,"Hey, we've found ourselves twice!\n"));
3298 Network_status = NETSTAT_MENU;
3301 change_playernum_to(i);
3304 if ( (TempPlayersInfo->players[i].network.appletalk.node == My_Seq.player.network.appletalk.node) && (!stricmp( TempPlayersInfo->players[i].callsign, temp_callsign)) ) {
3305 if (Player_num!=-1) {
3306 Int3(); // Hey, we've found ourselves twice
3307 Network_status = NETSTAT_MENU;
3310 change_playernum_to(i);
3313 memcpy( Players[i].callsign, TempPlayersInfo->players[i].callsign, CALLSIGN_LEN+1 );
3315 if (Network_game_type == IPX_GAME) {
3316 if ( (*(uint *)TempPlayersInfo->players[i].network.ipx.server) != 0 )
3317 ipx_get_local_target( TempPlayersInfo->players[i].network.ipx.server, TempPlayersInfo->players[i].network.ipx.node, Players[i].net_address );
3319 memcpy( Players[i].net_address, TempPlayersInfo->players[i].network.ipx.node, 6 );
3322 Players[i].n_packets_got=0; // How many packets we got from them
3323 Players[i].n_packets_sent=0; // How many packets we sent to them
3324 Players[i].connected = TempPlayersInfo->players[i].connected;
3325 Players[i].net_kills_total = sp->player_kills[i];
3326 Players[i].net_killed_total = sp->killed[i];
3327 if ((Network_rejoined) || (i != Player_num))
3328 Players[i].score = sp->player_score[i];
3329 for (j = 0; j < MAX_NUM_NET_PLAYERS; j++)
3331 kill_matrix[i][j] = sp->kills[i][j];
3335 if ( Player_num < 0 ) {
3336 mprintf ((0,"Bad Player_num, resetting to NETSTAT_MENU!\n"));
3337 Network_status = NETSTAT_MENU;
3341 if (Network_rejoined)
3342 for (i=0; i<N_players;i++)
3343 Players[i].net_killed_total = sp->killed[i];
3345 if (Network_rejoined) {
3346 network_process_monitor_vector(sp->monitor_vector);
3347 Players[Player_num].time_level = sp->level_time;
3350 team_kills[0] = sp->team_kills[0];
3351 team_kills[1] = sp->team_kills[1];
3353 Players[Player_num].connected = 1;
3354 NetPlayers.players[Player_num].connected = 1;
3355 NetPlayers.players[Player_num].rank=GetMyNetRanking();
3357 if (!Network_rejoined)
3358 for (i=0; i<NumNetPlayerPositions; i++) {
3359 Objects[Players[i].objnum].pos = Player_init[Netgame.locations[i]].pos;
3360 Objects[Players[i].objnum].orient = Player_init[Netgame.locations[i]].orient;
3361 obj_relink(Players[i].objnum,Player_init[Netgame.locations[i]].segnum);
3364 Objects[Players[Player_num].objnum].type = OBJ_PLAYER;
3366 mprintf ((0,"Changing to NETSTAT_PLAYING!\n"));
3367 Network_status = NETSTAT_PLAYING;
3368 Function_mode = FMODE_GAME;
3369 multi_sort_kill_list();
3374 network_send_sync(void)
3378 // Randomize their starting locations...
3380 d_srand( timer_get_fixed_seconds() );
3381 for (i=0; i<NumNetPlayerPositions; i++ )
3383 if (Players[i].connected)
3384 Players[i].connected = 1; // Get rid of endlevel connect statuses
3385 if (Game_mode & GM_MULTI_COOP)
3386 Netgame.locations[i] = i;
3390 np = d_rand() % NumNetPlayerPositions;
3391 for (j=0; j<i; j++ )
3393 if (Netgame.locations[j]==np)
3400 // np is a location that is not used anywhere else..
3401 Netgame.locations[i]=np;
3402 // mprintf((0, "Player %d starting in location %d\n" ,i ,np ));
3406 // Push current data into the sync packet
3408 network_update_netgame();
3409 Netgame.game_status = NETSTAT_PLAYING;
3410 Netgame.type = PID_SYNC;
3411 Netgame.segments_checksum = my_segments_checksum;
3413 for (i=0; i<N_players; i++ ) {
3414 if ((!Players[i].connected) || (i == Player_num))
3417 if (Network_game_type == IPX_GAME) {
3418 // Send several times, extras will be ignored
3419 send_internetwork_full_netgame_packet(NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node);
3420 send_netplayers_packet(NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node);
3423 appletalk_send_packet_data( (ubyte *)&Netgame, sizeof(netgame_info), NetPlayers.players[i].network.appletalk.node,
3424 NetPlayers.players[i].network.appletalk.net,
3425 NetPlayers.players[i].network.appletalk.socket);
3426 appletalk_send_packet_data( (ubyte *)&NetPlayers, sizeof(AllNetPlayers_info), NetPlayers.players[i].network.appletalk.node,
3427 NetPlayers.players[i].network.appletalk.net,
3428 NetPlayers.players[i].network.appletalk.socket);
3433 network_read_sync_packet(&Netgame,1); // Read it myself, as if I had sent it
3437 network_select_teams(void)
3440 newmenu_item m[MAX_PLAYERS+4];
3441 int choice, opt, opt_team_b;
3442 ubyte team_vector = 0;
3443 char team_names[2][CALLSIGN_LEN+1];
3445 int pnums[MAX_PLAYERS+2];
3447 // One-time initialization
3449 for (i = N_players/2; i < N_players; i++) // Put first half of players on team A
3451 team_vector |= (1 << i);
3454 sprintf(team_names[0], "%s", TXT_BLUE);
3455 sprintf(team_names[1], "%s", TXT_RED);
3457 // Here comes da menu
3459 m[0].type = NM_TYPE_INPUT; m[0].text = team_names[0]; m[0].text_len = CALLSIGN_LEN;
3462 for (i = 0; i < N_players; i++)
3464 if (!(team_vector & (1 << i)))
3466 m[opt].type = NM_TYPE_MENU; m[opt].text = NetPlayers.players[i].callsign; pnums[opt] = i; opt++;
3470 m[opt].type = NM_TYPE_INPUT; m[opt].text = team_names[1]; m[opt].text_len = CALLSIGN_LEN; opt++;
3471 for (i = 0; i < N_players; i++)
3473 if (team_vector & (1 << i))
3475 m[opt].type = NM_TYPE_MENU; m[opt].text = NetPlayers.players[i].callsign; pnums[opt] = i; opt++;
3478 m[opt].type = NM_TYPE_TEXT; m[opt].text = ""; opt++;
3479 m[opt].type = NM_TYPE_MENU; m[opt].text = TXT_ACCEPT; opt++;
3481 Assert(opt <= MAX_PLAYERS+4);
3483 choice = newmenu_do(NULL, TXT_TEAM_SELECTION, opt, m, NULL);
3485 if (choice == opt-1)
3487 if ((opt-2-opt_team_b < 2) || (opt_team_b == 1))
3489 nm_messagebox(NULL, 1, TXT_OK, TXT_TEAM_MUST_ONE);
3495 Netgame.team_vector = team_vector;
3496 strcpy(Netgame.team_name[0], team_names[0]);
3497 strcpy(Netgame.team_name[1], team_names[1]);
3501 else if ((choice > 0) && (choice < opt_team_b)) {
3502 team_vector |= (1 << pnums[choice]);
3504 else if ((choice > opt_team_b) && (choice < opt-2)) {
3505 team_vector &= ~(1 << pnums[choice]);
3507 else if (choice == -1)
3516 network_select_players(void)
3519 newmenu_item m[MAX_PLAYERS+4];
3520 char text[MAX_PLAYERS+4][45];
3522 int save_nplayers; //how may people would like to join
3524 network_add_player( &My_Seq );
3526 for (i=0; i< MAX_PLAYERS+4; i++ ) {
3527 sprintf( text[i], "%d. %-20s", i+1, "" );
3528 m[i].type = NM_TYPE_CHECK; m[i].text = text[i]; m[i].value = 0;
3531 m[0].value = 1; // Assume server will play...
3533 if (FindArg("-norankings"))
3534 sprintf( text[0], "%d. %-20s", 1, Players[Player_num].callsign );
3536 sprintf( text[0], "%d. %s%-20s", 1, RankStrings[NetPlayers.players[Player_num].rank],Players[Player_num].callsign );
3538 sprintf( title, "%s %d %s", TXT_TEAM_SELECT, MaxNumNetPlayers, TXT_TEAM_PRESS_ENTER );
3541 ExtGameStatus=GAMESTAT_NETGAME_PLAYER_SELECT;
3542 j=newmenu_do1( NULL, title, MAX_PLAYERS+4, m, network_start_poll, 1 );
3544 save_nplayers = N_players;
3549 // Dump all players and go back to menu mode
3552 for (i=1; i<save_nplayers; i++) {
3553 if (Network_game_type == IPX_GAME)
3554 network_dump_player(NetPlayers.players[i].network.ipx.server,NetPlayers.players[i].network.ipx.node, DUMP_ABORTED);
3557 network_dump_appletalk_player(NetPlayers.players[i].network.appletalk.node,NetPlayers.players[i].network.appletalk.net, NetPlayers.players[i].network.appletalk.socket, DUMP_ABORTED);
3562 Netgame.numplayers = 0;
3563 network_send_game_info(0); // Tell everyone we're bailing
3565 Network_status = NETSTAT_MENU;
3569 // Count number of players chosen
3572 for (i=0; i<save_nplayers; i++ )
3578 if ( N_players > Netgame.max_numplayers) {
3580 nm_messagebox( TXT_ERROR, 1, TXT_OK, "%s %d %s", TXT_SORRY_ONLY, MaxNumNetPlayers, TXT_NETPLAYERS_IN );
3582 nm_messagebox( TXT_ERROR, 1, TXT_OK, "%s %d netplayers for this game.", TXT_SORRY_ONLY, MaxNumNetPlayers );
3584 N_players = save_nplayers;
3585 goto GetPlayersAgain;
3589 if ( N_players < 2 ) {
3590 nm_messagebox( TXT_ERROR, 1, TXT_OK, TXT_TEAM_ATLEAST_TWO );
3591 N_players = save_nplayers;
3592 goto GetPlayersAgain;
3597 if ( (Netgame.gamemode == NETGAME_TEAM_ANARCHY ||
3598 Netgame.gamemode == NETGAME_CAPTURE_FLAG || Netgame.gamemode == NETGAME_TEAM_HOARD) && (N_players < 2) ) {
3599 nm_messagebox(TXT_ERROR, 1, TXT_OK, "You must select at least two\nplayers to start a team game" );
3600 N_players = save_nplayers;
3601 goto GetPlayersAgain;
3605 // Remove players that aren't marked.
3607 for (i=0; i<save_nplayers; i++ ) {
3612 if (Network_game_type == IPX_GAME) {
3613 memcpy(NetPlayers.players[N_players].network.ipx.node, NetPlayers.players[i].network.ipx.node, 6);
3614 memcpy(NetPlayers.players[N_players].network.ipx.server, NetPlayers.players[i].network.ipx.server, 4);
3616 NetPlayers.players[N_players].network.appletalk.node = NetPlayers.players[i].network.appletalk.node;
3617 NetPlayers.players[N_players].network.appletalk.net = NetPlayers.players[i].network.appletalk.net;
3618 NetPlayers.players[N_players].network.appletalk.socket = NetPlayers.players[i].network.appletalk.socket;
3620 memcpy(NetPlayers.players[N_players].callsign, NetPlayers.players[i].callsign, CALLSIGN_LEN+1);
3621 NetPlayers.players[N_players].version_major=NetPlayers.players[i].version_major;
3622 NetPlayers.players[N_players].version_minor=NetPlayers.players[i].version_minor;
3623 NetPlayers.players[N_players].rank=NetPlayers.players[i].rank;
3624 ClipRank (&NetPlayers.players[N_players].rank);
3625 network_check_for_old_version(i);
3627 Players[N_players].connected = 1;
3632 if (Network_game_type == IPX_GAME)
3633 network_dump_player(NetPlayers.players[i].network.ipx.server,NetPlayers.players[i].network.ipx.node, DUMP_DORK);
3636 network_dump_appletalk_player(NetPlayers.players[i].network.appletalk.node,NetPlayers.players[i].network.appletalk.net, NetPlayers.players[i].network.appletalk.socket, DUMP_DORK);
3641 for (i = N_players; i < MAX_NUM_NET_PLAYERS; i++) {
3642 if (Network_game_type == IPX_GAME) {
3643 memset(NetPlayers.players[i].network.ipx.node, 0, 6);
3644 memset(NetPlayers.players[i].network.ipx.server, 0, 4);
3646 NetPlayers.players[i].network.appletalk.node = 0;
3647 NetPlayers.players[i].network.appletalk.net = 0;
3648 NetPlayers.players[i].network.appletalk.socket = 0;
3650 memset(NetPlayers.players[i].callsign, 0, CALLSIGN_LEN+1);
3651 NetPlayers.players[i].version_major=0;
3652 NetPlayers.players[i].version_minor=0;
3653 NetPlayers.players[i].rank=0;
3656 mprintf ((0,"Select teams: Game mode is %d\n",Netgame.gamemode));
3658 if (Netgame.gamemode == NETGAME_TEAM_ANARCHY ||
3659 Netgame.gamemode == NETGAME_CAPTURE_FLAG ||
3660 Netgame.gamemode == NETGAME_TEAM_HOARD)
3661 if (!network_select_teams())
3668 network_start_game()
3671 char game_name[NETGAME_NAME_LEN+1];
3672 int chosen_game_mode, game_flags, level;
3674 if (Network_game_type == IPX_GAME) {
3676 Assert( FRAME_INFO_SIZE < IPX_MAX_DATA_SIZE );
3677 mprintf((0, "Using frame_info len %d, max %d.\n", FRAME_INFO_SIZE, IPX_MAX_DATA_SIZE));
3679 if ( !Network_active )
3681 nm_messagebox(NULL, 1, TXT_OK, TXT_IPX_NOT_FOUND );
3689 Assert( FRAME_INFO_SIZE < APPLETALK_MAX_DATA_SIZE );
3690 mprintf((0, "Using frame_info len %d, max %d.\n", sizeof(frame_info), APPLETALK_MAX_DATA_SIZE));
3691 if (Appletalk_active <= 0) {
3692 switch (Appletalk_active) {
3693 case APPLETALK_NOT_OPEN:
3694 sprintf(buf, "Appletalk is not currently active.\nPlease enable AppleTalk from the\nChooser and restart Descent.");
3696 case APPLETALK_BAD_LISTENER:
3697 sprintf(buf, "The Resource Fork of Descent appears damaged.\nPlease re-install Descent or contact\nMacPlay technical support.");
3699 case APPLETALK_NO_LOCAL_ADDR:
3700 sprintf(buf, "Wow! Strange!\n\nNo Local Address.");
3702 case APPLETALK_NO_SOCKET:
3703 sprintf(buf, "All AppleTalk sockets are in use.\nTry shutting down other network\napplications and restarting Descent.\n");
3706 nm_messagebox(NULL, 1, TXT_OK, buf);
3709 strcpy(Network_zone_name, DEFAULT_ZONE_NAME);
3714 change_playernum_to(0);
3716 if (network_find_game())
3718 nm_messagebox(NULL, 1, TXT_OK, TXT_NET_FULL);
3723 i = network_get_game_params( game_name, &chosen_game_mode, &game_flags, &level );
3729 // LoadLevel(level); Old, no longer used.
3731 Netgame.difficulty = Difficulty_level;
3732 Netgame.gamemode = chosen_game_mode;
3733 Netgame.game_status = NETSTAT_STARTING;
3734 Netgame.numplayers = 0;
3735 Netgame.max_numplayers = MaxNumNetPlayers;
3736 Netgame.levelnum = level;
3737 Netgame.protocol_version = MULTI_PROTO_VERSION;
3739 strcpy(Netgame.game_name, game_name);
3741 Network_status = NETSTAT_STARTING;
3744 if (Network_game_type == APPLETALK_GAME) {
3749 show_boxed_message("Registering Netgame");
3751 err = appletalk_register_netgame( game_name, TickCount() );
3752 t1 = timer_get_fixed_seconds() + F1_0;
3753 while (timer_get_fixed_seconds() < t1) ;
3755 } while ( (err == nbpDuplicate) && (count != MAX_REGISTER_TRIES) );
3756 clear_boxed_message();
3757 if ( (err == tooManyReqs) || (count == MAX_REGISTER_TRIES) ) {
3758 nm_messagebox(NULL, 1, TXT_OK, "AppleTalk Network is too busy.\nPlease try again shortly.");
3759 Game_mode = GM_GAME_OVER;
3765 network_set_game_mode(Netgame.gamemode);
3767 d_srand( timer_get_fixed_seconds() );
3768 Netgame.Security=d_rand(); // For syncing Netgames with player packets
3770 if(network_select_players())
3772 StartNewLevel(Netgame.levelnum, 0);
3775 Game_mode = GM_GAME_OVER;
3779 void restart_net_searching(newmenu_item * m)
3783 num_active_games = 0;
3785 memset(Active_games, 0, sizeof(netgame_info)*MAX_ACTIVE_NETGAMES);
3787 for (i = 0; i < MAX_ACTIVE_NETGAMES; i++)
3789 sprintf(m[i+2].text, "%d. ",i+1);
3793 NamesInfoSecurity=-1;
3794 Network_games_changed = 1;
3797 char *ModeLetters[]={"ANRCHY","TEAM","ROBO","COOP","FLAG","HOARD","TMHOARD"};
3799 int NumActiveNetgames=0;
3801 void network_join_poll( int nitems, newmenu_item * menus, int * key, int citem )
3803 // Polling loop for Join Game menu
3805 int i, osocket,join_status,temp;
3812 if ( (Network_game_type == IPX_GAME) && Network_allow_socket_changes ) {
3813 osocket = Network_socket;
3815 if ( *key==KEY_PAGEDOWN ) { Network_socket--; *key = 0; }
3816 if ( *key==KEY_PAGEUP ) { Network_socket++; *key = 0; }
3818 if (Network_socket>99)
3820 if (Network_socket<-99)
3823 if ( Network_socket+IPX_DEFAULT_SOCKET > 0x8000 )
3824 Network_socket = 0x8000 - IPX_DEFAULT_SOCKET;
3826 if ( Network_socket+IPX_DEFAULT_SOCKET < 0 )
3827 Network_socket = IPX_DEFAULT_SOCKET;
3829 if (Network_socket != osocket ) {
3830 sprintf( menus[0].text, "\t%s %+d (PgUp/PgDn to change)", TXT_CURRENT_IPX_SOCKET, Network_socket );
3831 menus[0].redraw = 1;
3832 mprintf(( 0, "Changing to socket %d\n", Network_socket ));
3834 mprintf ((0,"netgood 1!\n"));
3835 ipx_change_default_socket( IPX_DEFAULT_SOCKET + Network_socket );
3836 mprintf ((0,"netgood 2!\n"));
3837 restart_net_searching(menus);
3838 mprintf ((0,"netgood 3!\n"));
3839 network_send_game_list_request();
3840 mprintf ((0,"netgood 4!\n"));
3845 // send a request for game info every 3 seconds
3847 if (Network_game_type == IPX_GAME) {
3848 if (timer_get_approx_seconds() > t1+F1_0*3) {
3849 t1 = timer_get_approx_seconds();
3850 network_send_game_list_request();
3853 } else if (timer_get_approx_seconds() > t1+F1_0*20) {
3855 t1 = timer_get_approx_seconds();
3856 restart_net_searching(menus);
3857 show_boxed_message("Requesting list of Netgames");
3858 network_send_game_list_request();
3859 clear_boxed_message();
3864 temp=num_active_games;
3868 NumActiveNetgames=num_active_games;
3870 if (!Network_games_changed)
3873 if (temp!=num_active_games)
3874 digi_play_sample (SOUND_HUD_MESSAGE,F1_0);
3876 Network_games_changed = 0;
3877 mprintf ((0,"JOIN POLL: I'm looking at %d games!\n",num_active_games));
3879 // Copy the active games data into the menu options
3880 for (i = 0; i < num_active_games; i++)
3882 int game_status = Active_games[i].game_status;
3883 int j,x, k,tx,ty,ta,nplayers = 0;
3884 char levelname[8],MissName[25],GameName[25],thold[2];
3887 // These next two loops protect against menu skewing
3888 // if missiontitle or gamename contain a tab
3890 for (x=0,tx=0,k=0,j=0;j<15;j++)
3892 if (Active_games[i].mission_title[j]=='\t')
3894 thold[0]=Active_games[i].mission_title[j];
3895 gr_get_string_size (thold,&tx,&ty,&ta);
3897 if ((x+=tx)>=LHX(55))
3899 MissName[k]=MissName[k+1]=MissName[k+2]='.';
3904 MissName[k++]=Active_games[i].mission_title[j];
3908 for (x=0,tx=0,k=0,j=0;j<15;j++)
3910 if (Active_games[i].game_name[j]=='\t')
3912 thold[0]=Active_games[i].game_name[j];
3913 gr_get_string_size (thold,&tx,&ty,&ta);
3915 if ((x+=tx)>=LHX(55))
3917 GameName[k]=GameName[k+1]=GameName[k+2]='.';
3921 GameName[k++]=Active_games[i].game_name[j];
3926 nplayers=Active_games[i].numconnected;
3928 if (Active_games[i].levelnum < 0)
3929 sprintf(levelname, "S%d", -Active_games[i].levelnum);
3931 sprintf(levelname, "%d", Active_games[i].levelnum);
3933 if (game_status == NETSTAT_STARTING)
3935 sprintf (menus[i+2].text,"%d.\t%s \t%s \t %d/%d \t%s \t %s \t%s",
3936 i+1,GameName,ModeLetters[Active_games[i].gamemode],nplayers,
3937 Active_games[i].max_numplayers,MissName,levelname,"Forming");
3939 else if (game_status == NETSTAT_PLAYING)
3941 join_status=can_join_netgame(&Active_games[i],NULL);
3942 // mprintf ((0,"Joinstatus=%d\n",join_status));
3945 sprintf (menus[i+2].text,"%d.\t%s \t%s \t %d/%d \t%s \t %s \t%s",
3946 i+1,GameName,ModeLetters[Active_games[i].gamemode],nplayers,
3947 Active_games[i].max_numplayers,MissName,levelname,"Open");
3948 else if (join_status==2)
3949 sprintf (menus[i+2].text,"%d.\t%s \t%s \t %d/%d \t%s \t %s \t%s",
3950 i+1,GameName,ModeLetters[Active_games[i].gamemode],nplayers,
3951 Active_games[i].max_numplayers,MissName,levelname,"Full");
3952 else if (join_status==3)
3953 sprintf (menus[i+2].text,"%d.\t%s \t%s \t %d/%d \t%s \t %s \t%s",
3954 i+1,GameName,ModeLetters[Active_games[i].gamemode],nplayers,
3955 Active_games[i].max_numplayers,MissName,levelname,"Restrict");
3957 sprintf (menus[i+2].text,"%d.\t%s \t%s \t %d/%d \t%s \t %s \t%s",
3958 i+1,GameName,ModeLetters[Active_games[i].gamemode],nplayers,
3959 Active_games[i].max_numplayers,MissName,levelname,"Closed");
3963 sprintf (menus[i+2].text,"%d.\t%s \t%s \t %d/%d \t%s \t %s \t%s",
3964 i+1,GameName,ModeLetters[Active_games[i].gamemode],nplayers,
3965 Active_games[i].max_numplayers,MissName,levelname,"Between");
3968 Assert(strlen(menus[i+2].text) < 100);
3969 menus[i+2].redraw = 1;
3972 for (i = num_active_games; i < MAX_ACTIVE_NETGAMES; i++)
3974 sprintf(menus[i+2].text, "%d. ",i+1);
3975 menus[i+2].redraw = 1;
3980 network_wait_for_sync(void)
3986 Network_status = NETSTAT_WAITING;
3988 m[0].type=NM_TYPE_TEXT; m[0].text = text;
3989 m[1].type=NM_TYPE_TEXT; m[1].text = TXT_NET_LEAVE;
3991 i = network_send_request();
3996 sprintf( m[0].text, "%s\n'%s' %s", TXT_NET_WAITING, NetPlayers.players[i].callsign, TXT_NET_TO_ENTER );
3999 choice=newmenu_do( NULL, TXT_WAIT, 2, m, network_sync_poll );
4004 if (Network_status != NETSTAT_PLAYING)
4008 // if (Network_status == NETSTAT_ENDLEVEL)
4010 // network_send_endlevel_packet(0);
4011 // longjmp(LeaveGame, 0);
4014 mprintf((0, "Aborting join.\n"));
4015 me.type = PID_QUIT_JOINING;
4016 memcpy( me.player.callsign, Players[Player_num].callsign, CALLSIGN_LEN+1 );
4017 if (Network_game_type == IPX_GAME) {
4018 memcpy( me.player.network.ipx.node, ipx_get_my_local_address(), 6 );
4019 memcpy( me.player.network.ipx.server, ipx_get_my_server_address(), 4 );
4020 send_internetwork_sequence_packet(me, NetPlayers.players[0].network.ipx.server, NetPlayers.players[0].network.ipx.node);
4023 me.player.network.appletalk.node = appletalk_get_my_node();
4024 me.player.network.appletalk.net = appletalk_get_my_net();
4025 me.player.network.appletalk.socket = appletalk_get_my_socket();
4029 Function_mode = FMODE_MENU;
4030 Game_mode = GM_GAME_OVER;
4031 return(-1); // they cancelled
4037 network_request_poll( int nitems, newmenu_item * menus, int * key, int citem )
4039 // Polling loop for waiting-for-requests menu
4049 // Send our endlevel packet at regular intervals
4051 // if (timer_get_approx_seconds() > t1+ENDLEVEL_SEND_INTERVAL)
4053 // network_send_endlevel_packet();
4054 // t1 = timer_get_approx_seconds();
4059 for (i = 0; i < N_players; i++)
4061 if ((Players[i].connected == 1) || (Players[i].connected == 0))
4065 if (num_ready == N_players) // All players have checked in or are disconnected
4072 network_wait_for_requests(void)
4074 // Wait for other players to load the level before we send the sync
4078 Network_status = NETSTAT_WAITING;
4080 m[0].type=NM_TYPE_TEXT; m[0].text = TXT_NET_LEAVE;
4082 mprintf((0, "Entered wait_for_requests : N_players = %d.\n", N_players));
4084 for (choice = 0; choice < N_players; choice++)
4085 mprintf((0, "Players[%d].connected = %d.\n", choice, Players[choice].connected));
4087 Network_status = NETSTAT_WAITING;
4090 Players[Player_num].connected = 1;
4093 choice = newmenu_do(NULL, TXT_WAIT, 1, m, network_request_poll);
4098 choice = nm_messagebox(NULL, 3, TXT_YES, TXT_NO, TXT_START_NOWAIT, TXT_QUITTING_NOW);
4104 // User confirmed abort
4106 for (i=0; i < N_players; i++) {
4107 if ((Players[i].connected != 0) && (i != Player_num)) {
4108 if (Network_game_type == IPX_GAME)
4109 network_dump_player(NetPlayers.players[i].network.ipx.server, NetPlayers.players[i].network.ipx.node, DUMP_ABORTED);
4112 network_dump_appletalk_player(NetPlayers.players[i].network.appletalk.node, NetPlayers.players[i].network.appletalk.net, NetPlayers.players[i].network.appletalk.socket, DUMP_ABORTED);
4118 if (Network_game_type == APPLETALK_GAME)
4119 network_release_registered_game();
4121 longjmp(LeaveGame, 0);
4123 else if (choice != -2)
4128 network_level_sync(void)
4130 // Do required syncing between (before) levels
4134 mprintf((0, "Player %d entering network_level_sync.\n", Player_num));
4136 MySyncPackInitialized = 0;
4138 // my_segments_checksum = netmisc_calc_checksum(Segments, sizeof(segment)*(Highest_segment_index+1));
4140 network_flush(); // Flush any old packets
4143 result = network_wait_for_sync();
4144 else if (network_i_am_master())
4146 network_wait_for_requests();
4147 network_send_sync();
4151 result = network_wait_for_sync();
4153 network_count_powerups_in_mine();
4157 Players[Player_num].connected = 0;
4158 network_send_endlevel_packet();
4160 if (Network_game_type == APPLETALK_GAME)
4161 network_release_registered_game();
4163 longjmp(LeaveGame, 0);
4168 void network_count_powerups_in_mine(void)
4172 for (i=0;i<MAX_POWERUP_TYPES;i++)
4173 PowerupsInMine[i]=0;
4175 for (i=0;i<=Highest_object_index;i++)
4177 if (Objects[i].type==OBJ_POWERUP)
4179 PowerupsInMine[Objects[i].id]++;
4180 if (multi_powerup_is_4pack(Objects[i].id))
4181 PowerupsInMine[Objects[i].id-1]+=4;
4189 // code to release the NBP binding of an appletalk game
4191 void network_release_registered_game()
4193 if (Network_game_type == APPLETALK_GAME)
4194 appletalk_remove_netgame();
4197 // code to sort zone lists....
4199 int zone_sort_func(const char **e0, const char **e1)
4201 return strcmp(*e0, *e1);
4204 void network_get_appletalk_zone()
4206 int num_zones, i, item, default_item;
4208 char default_zone[MAX_ZONE_LENGTH]; // my zone
4210 Network_zone_name[0] = '\0';
4212 show_boxed_message("Looking for AppleTalk Zones");
4213 num_zones = appletalk_get_zone_names(&zone_list);
4214 clear_boxed_message();
4216 if (num_zones < 0) { // error in getting zone list...maybe no router available....
4217 if ( (num_zones == tooManyReqs) || (num_zones == noDataArea) ){
4218 nm_messagebox(NULL, 1, TXT_OK, "AppleTalk Network is too busy.\nPlease try again shortly.");
4219 longjmp(LeaveGame,0);
4224 if (num_zones == 0) {
4225 strcpy(Network_zone_name, DEFAULT_ZONE_NAME);
4229 if (num_zones == 1) {
4230 Network_zone_name[0] = (char)(strlen(zone_list[0]));
4231 memcpy( &(Network_zone_name[1]), zone_list[0], strlen(zone_list[0]) );
4235 // sort the zone names
4237 for (i = 0; i < num_zones; i++)
4238 strlwr(zone_list[i]);
4240 qsort(zone_list, num_zones, sizeof(char *), zone_sort_func);
4242 // get my current zone so we can highlight that one first
4244 if (appletalk_get_my_zone(default_zone))
4247 for (i = 0; i < num_zones; i++) {
4248 if ( !stricmp(zone_list[i], default_zone) ) {
4256 item = newmenu_listbox1("AppleTalk Zones", num_zones, zone_list, 0, default_item, NULL);
4261 Network_zone_name[0] = (char)(strlen(zone_list[item]));
4262 memcpy( &(Network_zone_name[1]), zone_list[item], strlen(zone_list[item]) );
4265 for (i = 0; i < num_zones; i++)
4266 d_free(zone_list[i]);
4271 void nm_draw_background1(char * filename);
4273 void network_join_game()
4276 char menu_text[MAX_ACTIVE_NETGAMES+2][200];
4278 newmenu_item m[MAX_ACTIVE_NETGAMES+2];
4280 if (Network_game_type == IPX_GAME) {
4281 if ( !Network_active )
4283 nm_messagebox(NULL, 1, TXT_OK, TXT_IPX_NOT_FOUND);
4287 } else if (Appletalk_active <= 0) {
4290 switch (Appletalk_active) {
4291 case APPLETALK_NOT_OPEN:
4292 sprintf(buf, "Appletalk is not currently active.\nPlease enable AppleTalk from the\nChooser and restart Descent.");
4294 case APPLETALK_BAD_LISTENER:
4295 sprintf(buf, "The Resource Fork of Descent appears damaged.\nPlease re-install Descent or contact\nMacPlay technical support.");
4297 case APPLETALK_NO_LOCAL_ADDR:
4298 sprintf(buf, "Wow! Strange!\n\nNo Local Address.");
4300 case APPLETALK_NO_SOCKET:
4301 sprintf(buf, "All AppleTalk sockets are in use.\nTry shutting down other network\napplications and restarting Descent.\n");
4304 nm_messagebox(NULL, 1, TXT_OK, buf);
4316 if (Network_game_type == APPLETALK_GAME)
4317 network_get_appletalk_zone();
4320 Network_send_objects = 0;
4321 Network_sending_extras=0;
4324 Network_status = NETSTAT_BROWSING; // We are looking at a game menu
4327 network_listen(); // Throw out old info
4330 if (Network_game_type == IPX_GAME)
4331 #endif // note link to if
4332 network_send_game_list_request(); // broadcast a request for lists
4334 num_active_games = 0;
4336 memset(m, 0, sizeof(newmenu_item)*MAX_ACTIVE_NETGAMES);
4337 memset(Active_games, 0, sizeof(netgame_info)*MAX_ACTIVE_NETGAMES);
4338 memset(ActiveNetPlayers,0,sizeof(AllNetPlayers_info)*MAX_ACTIVE_NETGAMES);
4340 gr_set_fontcolor(BM_XRGB(15,15,23),-1);
4342 m[0].text = menu_text[0];
4343 m[0].type = NM_TYPE_TEXT;
4344 if (Network_game_type == IPX_GAME) {
4345 if (Network_allow_socket_changes)
4346 sprintf( m[0].text, "\tCurrent IPX Socket is default %+d (PgUp/PgDn to change)", Network_socket );
4348 strcpy( m[0].text, "" ); //sprintf( m[0].text, "" );
4351 p2cstr(Network_zone_name);
4352 if (strcmp(Network_zone_name, "*")) // only print if there is a zone name
4353 sprintf(m[0].text, "\tCurrent Zone is %s", Network_zone_name); // is Network_zone_name a pascal string????
4354 c2pstr(Network_zone_name);
4358 m[1].text=menu_text[1];
4359 m[1].type=NM_TYPE_TEXT;
4360 sprintf (m[1].text,"\tGAME \tMODE \t#PLYRS \tMISSION \tLEV \tSTATUS");
4362 for (i = 0; i < MAX_ACTIVE_NETGAMES; i++) {
4363 m[i+2].text = menu_text[i+2];
4364 m[i+2].type = NM_TYPE_MENU;
4365 sprintf(m[i+2].text, "%d. ", i+1);
4369 Network_games_changed = 1;
4372 nm_draw_background1(Menu_pcx_name); //load this here so if we abort after loading level, we restore the palette
4373 gr_palette_load(gr_palette);
4374 ExtGameStatus=GAMESTAT_JOIN_NETGAME;
4375 choice=newmenu_dotiny("NETGAMES", NULL,MAX_ACTIVE_NETGAMES+2, m, network_join_poll);
4379 Network_status = NETSTAT_MENU;
4380 return; // they cancelled
4384 if (choice >=num_active_games)
4386 nm_messagebox(TXT_SORRY, 1, TXT_OK, TXT_INVALID_CHOICE);
4390 // Choice has been made and looks legit
4391 if (Active_games[choice].game_status == NETSTAT_ENDLEVEL)
4393 nm_messagebox(TXT_SORRY, 1, TXT_OK, TXT_NET_GAME_BETWEEN2);
4397 if (Active_games[choice].protocol_version != MULTI_PROTO_VERSION)
4399 if (Active_games[choice].protocol_version == 3) {
4401 nm_messagebox(TXT_SORRY, 1, TXT_OK, "Your version of Descent 2\nis incompatible with the\nDemo version");
4404 else if (Active_games[choice].protocol_version == 4) {
4406 nm_messagebox(TXT_SORRY, 1, TXT_OK, "This Demo version of\nDescent 2 is incompatible\nwith the full commercial version");
4410 nm_messagebox(TXT_SORRY, 1, TXT_OK, TXT_VERSION_MISMATCH);
4417 // Check for valid mission name
4418 mprintf((0, "Loading mission:%s.\n", Active_games[choice].mission_name));
4419 if (!load_mission_by_name(Active_games[choice].mission_name))
4421 nm_messagebox(NULL, 1, TXT_OK, TXT_MISSION_NOT_FOUND);
4427 #if defined (D2_OEM)
4429 if (Active_games[choice].levelnum>8)
4431 nm_messagebox(NULL, 1, TXT_OK, "This OEM version only supports\nthe first 8 levels!");
4437 if (!network_wait_for_all_info (choice))
4439 nm_messagebox (TXT_SORRY,1,TXT_OK,"There was a join error!");
4440 Network_status = NETSTAT_BROWSING; // We are looking at a game menu
4444 Network_status = NETSTAT_BROWSING; // We are looking at a game menu
4446 if (!can_join_netgame(&Active_games[choice],&ActiveNetPlayers[choice]))
4448 if (Active_games[choice].numplayers == Active_games[choice].max_numplayers)
4449 nm_messagebox(TXT_SORRY, 1, TXT_OK, TXT_GAME_FULL);
4451 nm_messagebox(TXT_SORRY, 1, TXT_OK, TXT_IN_PROGRESS);
4455 // Choice is valid, prepare to join in
4457 memcpy(&Netgame, &Active_games[choice], sizeof(netgame_info));
4458 memcpy (&NetPlayers,&ActiveNetPlayers[choice],sizeof(AllNetPlayers_info));
4460 Difficulty_level = Netgame.difficulty;
4461 MaxNumNetPlayers = Netgame.max_numplayers;
4462 change_playernum_to(1);
4466 // register the joining player with NBP. This will have the nice effect of a player wanting to
4467 // join to be able to see the netgame if this player were to become the master.
4469 if (Network_game_type == APPLETALK_GAME) {
4474 show_boxed_message("Registering Netgame");
4476 err = appletalk_register_netgame( Active_games[choice].game_name, TickCount() );
4477 t1 = timer_get_fixed_seconds() + F1_0;
4478 while ( timer_get_fixed_seconds() < t1 ) ;
4480 } while ( (err == nbpDuplicate) && (count != MAX_REGISTER_TRIES) );
4481 clear_boxed_message();
4482 if ( (err == tooManyReqs) || (count == MAX_REGISTER_TRIES) ) {
4483 nm_messagebox(NULL, 1, TXT_OK, "AppleTalk Network is too busy.\nPlease try again shortly.");
4489 network_set_game_mode(Netgame.gamemode);
4491 network_AdjustMaxDataSize ();
4493 StartNewLevel(Netgame.levelnum, 0);
4495 return; // look ma, we're in a game!!!
4498 void network_AdjustMaxDataSize ()
4501 if (Netgame.ShortPackets)
4502 MaxXDataSize=NET_XDATA_SIZE;
4504 MaxXDataSize=NET_XDATA_SIZE;
4508 fix StartWaitAllTime=0;
4509 int WaitAllChoice=0;
4510 #define ALL_INFO_REQUEST_INTERVAL F1_0*3
4512 void network_wait_all_poll( int nitems, newmenu_item * menus, int * key, int citem )
4520 if (timer_get_approx_seconds() > t1+ALL_INFO_REQUEST_INTERVAL)
4522 network_send_all_info_request(PID_SEND_ALL_GAMEINFO,SecurityCheck);
4523 t1 = timer_get_approx_seconds();
4526 network_do_big_wait(WaitAllChoice);
4528 if(SecurityCheck==-1)
4532 int network_wait_for_all_info (int choice)
4538 m[0].type=NM_TYPE_TEXT; m[0].text = "Press Escape to cancel";
4540 WaitAllChoice=choice;
4541 StartWaitAllTime=timer_get_approx_seconds();
4542 SecurityCheck=Active_games[choice].Security;
4546 pick=newmenu_do( NULL, "Connecting...", 1, m, network_wait_all_poll );
4548 if (pick>-1 && SecurityCheck!=-1)
4551 if (SecurityCheck==-1)
4560 void network_do_big_wait(int choice)
4563 ubyte packet[IPX_MAX_DATA_SIZE],*data;
4564 AllNetPlayers_info *temp_info;
4565 #ifdef WORDS_BIGENDIAN
4566 AllNetPlayers_info info_struct;
4569 ubyte apacket[APPLETALK_MAX_DATA_SIZE];
4573 if (Network_game_type == APPLETALK_GAME)
4574 size=appletalk_get_packet_data( apacket );
4577 size=ipx_get_packet_data( packet );
4582 if (Network_game_type == APPLETALK_GAME)
4592 if (Network_game_type == IPX_GAME) {
4593 receive_full_netgame_packet(data, &TempNetInfo);
4595 memcpy((ubyte *)&TempNetInfo, data, sizeof(netgame_info));
4597 mprintf ((0,"This is %s game with a security of %d\n",TempNetInfo.game_name,TempNetInfo.Security));
4599 if (TempNetInfo.Security !=SecurityCheck)
4601 mprintf ((0,"Bad security on big_wait...rejecting.\n"));
4605 if (NetSecurityFlag==NETSECURITY_WAIT_FOR_GAMEINFO)
4607 if (TempPlayersInfo->Security==TempNetInfo.Security)
4609 mprintf ((0,"EQUAL !: Game=%d Players=%d ",TempPlayersInfo->Security,TempNetInfo.Security));
4610 if (TempPlayersInfo->Security==SecurityCheck)
4612 memcpy (&Active_games[choice],(ubyte *)&TempNetInfo,sizeof(netgame_info));
4613 memcpy (&ActiveNetPlayers[choice],TempPlayersInfo,sizeof(AllNetPlayers_info));
4620 NetSecurityFlag=NETSECURITY_WAIT_FOR_PLAYERS;
4621 NetSecurityNum=TempNetInfo.Security;
4623 if (network_wait_for_playerinfo())
4625 mprintf ((0,"HUH? Game=%d Player=%d\n",NetSecurityNum,TempPlayersInfo->Security));
4626 memcpy (&Active_games[choice],(ubyte *)&TempNetInfo,sizeof(netgame_info));
4627 memcpy (&ActiveNetPlayers[choice],TempPlayersInfo,sizeof(AllNetPlayers_info));
4634 case PID_PLAYERSINFO:
4635 mprintf ((0,"Got a PID_PLAYERSINFO!\n"));
4637 if (Network_game_type == IPX_GAME) {
4638 #ifndef WORDS_BIGENDIAN
4639 temp_info=(AllNetPlayers_info *)data;
4641 receive_netplayers_packet(data, &info_struct);
4642 temp_info = &info_struct;
4645 temp_info = (AllNetPlayers_info *)data;
4647 if (temp_info->Security!=SecurityCheck)
4648 break; // If this isn't the guy we're looking for, move on
4650 memcpy (&TempPlayersBase,(ubyte *)&temp_info,sizeof(AllNetPlayers_info));
4651 TempPlayersInfo=&TempPlayersBase;
4652 WaitingForPlayerInfo=0;
4653 NetSecurityNum=TempPlayersInfo->Security;
4654 NetSecurityFlag=NETSECURITY_WAIT_FOR_GAMEINFO;
4660 void network_leave_game()
4664 network_do_frame(1, 1);
4667 fclose (SendLogFile);
4668 fclose (RecieveLogFile);
4671 if ((network_i_am_master()))
4673 while (Network_sending_extras>1 && Player_joining_extras!=-1)
4674 network_send_extras();
4676 Netgame.numplayers = 0;
4679 network_send_game_info(NULL);
4682 mprintf ((0,"HEY! I'm master and I've left.\n"));
4685 Players[Player_num].connected = 0;
4686 network_send_endlevel_packet();
4687 change_playernum_to(0);
4688 Game_mode = GM_GAME_OVER;
4689 write_player_file();
4691 // WIN(ipx_destroy_read_thread());
4696 void network_flush()
4699 ubyte apacket[APPLETALK_MAX_DATA_SIZE];
4701 ubyte packet[IPX_MAX_DATA_SIZE];
4704 if ( (Network_game_type == APPLETALK_GAME) && (Appletalk_active <= 0) )
4708 if ( Network_game_type == IPX_GAME )
4709 if (!Network_active) return;
4712 if (Network_game_type == APPLETALK_GAME)
4713 while (appletalk_get_packet_data(apacket) > 0) ;
4716 while (ipx_get_packet_data(packet) > 0) ;
4719 void network_listen()
4722 ubyte apacket[APPLETALK_MAX_DATA_SIZE];
4725 ubyte packet[IPX_MAX_DATA_SIZE];
4728 if (Network_status==NETSTAT_PLAYING && Netgame.ShortPackets && !Network_send_objects)
4730 loopmax=N_players*Netgame.PacketsPerSec;
4734 if ( (Network_game_type == APPLETALK_GAME) && (Appletalk_active <= 0) )
4738 if (Network_game_type == IPX_GAME)
4739 if (!Network_active) return;
4741 if (!(Game_mode & GM_NETWORK) && (Function_mode == FMODE_GAME))
4742 mprintf((0, "Calling network_listen() when not in net game.\n"));
4744 WaitingForPlayerInfo=1;
4745 NetSecurityFlag=NETSECURITY_OFF;
4748 if (Network_game_type == IPX_GAME) {
4749 size = ipx_get_packet_data( packet );
4751 network_process_packet( packet, size );
4754 size = ipx_get_packet_data( packet );
4758 size = appletalk_get_packet_data( apacket );
4760 network_process_packet( apacket, size );
4763 size = appletalk_get_packet_data( apacket );
4769 int network_wait_for_playerinfo()
4772 ubyte packet[IPX_MAX_DATA_SIZE];
4773 struct AllNetPlayers_info *TempInfo;
4776 #ifdef WORDS_BIGENDIAN
4777 AllNetPlayers_info info_struct;
4780 ubyte apacket[APPLETALK_MAX_DATA_SIZE];
4784 if ( (Network_game_type == APPLETALK_GAME) && (Appletalk_active <= 0) )
4788 if ( Network_game_type == IPX_GAME)
4789 if (!Network_active) return(0);
4791 // if (!WaitingForPlayerInfo)
4794 if (!(Game_mode & GM_NETWORK) && (Function_mode == FMODE_GAME))
4796 mprintf((0, "Calling network_wait_for_playerinfo() when not in net game.\n"));
4798 if (Network_status==NETSTAT_PLAYING)
4800 Int3(); //MY GOD! Get Jason...this is the source of many problems
4803 basetime=timer_get_approx_seconds();
4805 while (WaitingForPlayerInfo && retries<50 && (timer_get_approx_seconds()<(basetime+(F1_0*5))))
4807 if (Network_game_type == IPX_GAME) {
4808 size = ipx_get_packet_data( packet );
4812 size = appletalk_get_packet_data( apacket );
4817 if (size>0 && id==PID_PLAYERSINFO)
4819 #ifdef WORDS_BIGENDIAN
4821 if (Network_game_type == APPLETALK_GAME) {
4822 TempInfo = (AllNetPlayers_info *)apacket;
4826 receive_netplayers_packet(packet, &info_struct);
4827 TempInfo = &info_struct;
4830 TempInfo=(AllNetPlayers_info *)packet;
4835 if (NetSecurityFlag==NETSECURITY_WAIT_FOR_PLAYERS)
4837 if (NetSecurityNum==TempInfo->Security)
4839 mprintf ((0,"HEYEQUAL: Player=%d Game=%d\n",TempInfo->Security,NetSecurityNum));
4840 memcpy (&TempPlayersBase,(ubyte *)TempInfo,sizeof(AllNetPlayers_info));
4841 TempPlayersInfo=&TempPlayersBase;
4842 NetSecurityFlag=NETSECURITY_OFF;
4844 WaitingForPlayerInfo=0;
4852 mprintf ((0,"I'm original!\n"));
4854 NetSecurityNum=TempInfo->Security;
4855 NetSecurityFlag=NETSECURITY_WAIT_FOR_GAMEINFO;
4857 memcpy (&TempPlayersBase,(ubyte *)TempInfo,sizeof(AllNetPlayers_info));
4858 TempPlayersInfo=&TempPlayersBase;
4859 WaitingForPlayerInfo=0;
4868 void network_send_data( ubyte * ptr, int len, int urgent )
4874 fprintf (SendLogFile,"Packet type: %d Len:%d Urgent:%d TT=%d\n",ptr[0],len,urgent,TTSent[ptr[0]]);
4875 fflush (SendLogFile);
4878 if (Endlevel_sequence)
4881 if (!MySyncPackInitialized) {
4882 MySyncPackInitialized = 1;
4883 memset( &MySyncPack, 0, sizeof(frame_info) );
4889 if ((MySyncPack.data_size+len) > MaxXDataSize ) {
4891 network_do_frame(1, 0);
4892 if (MySyncPack.data_size != 0) {
4893 mprintf((0, "%d bytes were added to data by network_do_frame!\n", MySyncPack.data_size));
4896 // Int3(); // Trying to send too much!
4898 mprintf((0, "Packet overflow, sending additional packet, type %d len %d.\n", ptr[0], len));
4899 Assert(check == ptr[0]);
4902 Assert(MySyncPack.data_size+len <= MaxXDataSize);
4904 memcpy( &MySyncPack.data[MySyncPack.data_size], ptr, len );
4905 MySyncPack.data_size += len;
4908 void network_timeout_player(int playernum)
4910 // Remove a player from the game if we haven't heard from them in
4914 Assert(playernum < N_players);
4915 Assert(playernum > -1);
4917 network_disconnect_player(playernum);
4918 create_player_appearance_effect(&Objects[Players[playernum].objnum]);
4920 digi_play_sample(SOUND_HUD_MESSAGE, F1_0);
4922 HUD_init_message("%s %s", Players[playernum].callsign, TXT_DISCONNECTING);
4923 for (i = 0; i < N_players; i++)
4924 if (Players[i].connected)
4929 nm_messagebox(NULL, 1, TXT_OK, TXT_YOU_ARE_ONLY);
4933 fix last_send_time = 0;
4934 fix last_timeout_check = 0;
4936 #ifdef WORDS_BIGENDIAN
4937 void squish_short_frame_info(short_frame_info old_info, ubyte *data)
4943 data[0] = old_info.type; loc++;
4944 /* skip three for pad byte */ loc += 3;
4945 tmpi = INTEL_INT(old_info.numpackets);
4946 memcpy(&(data[loc]), &tmpi, 4); loc += 4;
4948 memcpy(&(data[loc]), old_info.thepos.bytemat, 9); loc += 9;
4949 tmps = INTEL_SHORT(old_info.thepos.xo);
4950 memcpy(&(data[loc]), &tmps, 2); loc += 2;
4951 tmps = INTEL_SHORT(old_info.thepos.yo);
4952 memcpy(&(data[loc]), &tmps, 2); loc += 2;
4953 tmps = INTEL_SHORT(old_info.thepos.zo);
4954 memcpy(&(data[loc]), &tmps, 2); loc += 2;
4955 tmps = INTEL_SHORT(old_info.thepos.segment);
4956 memcpy(&(data[loc]), &tmps, 2); loc += 2;
4957 tmps = INTEL_SHORT(old_info.thepos.velx);
4958 memcpy(&(data[loc]), &tmps, 2); loc += 2;
4959 tmps = INTEL_SHORT(old_info.thepos.vely);
4960 memcpy(&(data[loc]), &tmps, 2); loc += 2;
4961 tmps = INTEL_SHORT(old_info.thepos.velz);
4962 memcpy(&(data[loc]), &tmps, 2); loc += 2;
4964 tmps = INTEL_SHORT(old_info.data_size);
4965 memcpy(&(data[loc]), &tmps, 2); loc += 2;
4967 data[loc] = old_info.playernum; loc++;
4968 data[loc] = old_info.obj_render_type; loc++;
4969 data[loc] = old_info.level_num; loc++;
4970 memcpy(&(data[loc]), old_info.data, old_info.data_size);
4974 char NakedBuf[NET_XDATA_SIZE+4];
4975 int NakedPacketLen=0;
4976 int NakedPacketDestPlayer=-1;
4978 void network_do_frame(int force, int listen)
4981 short_frame_info ShortSyncPack;
4982 static fix LastEndlevel=0;
4984 if (!(Game_mode&GM_NETWORK)) return;
4986 if ((Network_status != NETSTAT_PLAYING) || (Endlevel_sequence)) // Don't send postion during escape sequence...
4991 Assert (NakedPacketDestPlayer>-1);
4992 // mprintf ((0,"Sending a naked packet to %s (%d bytes)!\n",Players[NakedPacketDestPlayer].callsign,NakedPacketLen));
4993 if (Network_game_type == IPX_GAME)
4994 ipx_send_packet_data( (ubyte *)NakedBuf, NakedPacketLen, NetPlayers.players[NakedPacketDestPlayer].network.ipx.server, NetPlayers.players[NakedPacketDestPlayer].network.ipx.node,Players[NakedPacketDestPlayer].net_address );
4997 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 );
5000 NakedPacketDestPlayer=-1;
5003 if (WaitForRefuseAnswer && timer_get_approx_seconds()>(RefuseTimeLimit+(F1_0*12)))
5004 WaitForRefuseAnswer=0;
5006 last_send_time += FrameTime;
5007 last_timeout_check += FrameTime;
5009 // Send out packet PacksPerSec times per second maximum... unless they fire, then send more often...
5010 if ( (last_send_time>F1_0/Netgame.PacketsPerSec) || (Network_laser_fired) || force || PacketUrgent ) {
5011 if ( Players[Player_num].connected ) {
5012 int objnum = Players[Player_num].objnum;
5016 multi_send_robot_frame(0);
5017 multi_send_fire(); // Do firing if needed..
5022 if (Netgame.ShortPackets)
5024 #ifdef WORDS_BIGENDIAN
5025 ubyte send_data[IPX_MAX_DATA_SIZE];
5026 //int squished_size;
5028 create_shortpos(&ShortSyncPack.thepos, Objects+objnum, 0);
5029 ShortSyncPack.type = PID_PDATA;
5030 ShortSyncPack.playernum = Player_num;
5031 ShortSyncPack.obj_render_type = Objects[objnum].render_type;
5032 ShortSyncPack.level_num = Current_level_num;
5033 ShortSyncPack.data_size = MySyncPack.data_size;
5034 memcpy (&ShortSyncPack.data[0],&MySyncPack.data[0],MySyncPack.data_size);
5036 for (i=0; i<N_players; i++ ) {
5037 if ( (Players[i].connected) && (i!=Player_num ) ) {
5038 MySyncPack.numpackets = Players[i].n_packets_sent++;
5039 ShortSyncPack.numpackets=MySyncPack.numpackets;
5040 if (Network_game_type == IPX_GAME) {
5041 #ifndef WORDS_BIGENDIAN
5042 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 );
5044 squish_short_frame_info(ShortSyncPack, send_data);
5045 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 );
5049 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 );
5055 else // If long packets
5059 MySyncPack.type = PID_PDATA;
5060 MySyncPack.playernum = Player_num;
5061 MySyncPack.obj_render_type = Objects[objnum].render_type;
5062 MySyncPack.level_num = Current_level_num;
5063 MySyncPack.obj_segnum = Objects[objnum].segnum;
5064 MySyncPack.obj_pos = Objects[objnum].pos;
5065 MySyncPack.obj_orient = Objects[objnum].orient;
5066 MySyncPack.phys_velocity = Objects[objnum].mtype.phys_info.velocity;
5067 MySyncPack.phys_rotvel = Objects[objnum].mtype.phys_info.rotvel;
5069 send_data_size = MySyncPack.data_size; // do this so correct size data is sent
5071 #ifdef WORDS_BIGENDIAN // do the swap stuff
5072 if (Network_game_type == IPX_GAME) {
5073 MySyncPack.obj_segnum = INTEL_SHORT(MySyncPack.obj_segnum);
5074 MySyncPack.obj_pos.x = INTEL_INT((int)MySyncPack.obj_pos.x);
5075 MySyncPack.obj_pos.y = INTEL_INT((int)MySyncPack.obj_pos.y);
5076 MySyncPack.obj_pos.z = INTEL_INT((int)MySyncPack.obj_pos.z);
5078 MySyncPack.obj_orient.rvec.x = INTEL_INT((int)MySyncPack.obj_orient.rvec.x);
5079 MySyncPack.obj_orient.rvec.y = INTEL_INT((int)MySyncPack.obj_orient.rvec.y);
5080 MySyncPack.obj_orient.rvec.z = INTEL_INT((int)MySyncPack.obj_orient.rvec.z);
5081 MySyncPack.obj_orient.uvec.x = INTEL_INT((int)MySyncPack.obj_orient.uvec.x);
5082 MySyncPack.obj_orient.uvec.y = INTEL_INT((int)MySyncPack.obj_orient.uvec.y);
5083 MySyncPack.obj_orient.uvec.z = INTEL_INT((int)MySyncPack.obj_orient.uvec.z);
5084 MySyncPack.obj_orient.fvec.x = INTEL_INT((int)MySyncPack.obj_orient.fvec.x);
5085 MySyncPack.obj_orient.fvec.y = INTEL_INT((int)MySyncPack.obj_orient.fvec.y);
5086 MySyncPack.obj_orient.fvec.z = INTEL_INT((int)MySyncPack.obj_orient.fvec.z);
5088 MySyncPack.phys_velocity.x = INTEL_INT((int)MySyncPack.phys_velocity.x);
5089 MySyncPack.phys_velocity.y = INTEL_INT((int)MySyncPack.phys_velocity.y);
5090 MySyncPack.phys_velocity.z = INTEL_INT((int)MySyncPack.phys_velocity.z);
5092 MySyncPack.phys_rotvel.x = INTEL_INT((int)MySyncPack.phys_rotvel.x);
5093 MySyncPack.phys_rotvel.y = INTEL_INT((int)MySyncPack.phys_rotvel.y);
5094 MySyncPack.phys_rotvel.z = INTEL_INT((int)MySyncPack.phys_rotvel.z);
5096 MySyncPack.data_size = INTEL_SHORT(MySyncPack.data_size);
5100 for (i=0; i<N_players; i++ ) {
5101 if ( (Players[i].connected) && (i!=Player_num ) ) {
5102 if (Network_game_type == IPX_GAME)
5103 MySyncPack.numpackets = INTEL_INT(Players[i].n_packets_sent);
5105 MySyncPack.numpackets = Players[i].n_packets_sent;
5107 Players[i].n_packets_sent++;
5108 if (Network_game_type == IPX_GAME)
5109 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 );
5112 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);
5118 MySyncPack.data_size = 0; // Start data over at 0 length.
5119 if (Control_center_destroyed)
5122 Players[Player_num].connected=3;
5123 if (timer_get_approx_seconds() > (LastEndlevel+(F1_0/2)))
5125 network_send_endlevel_packet();
5126 LastEndlevel=timer_get_approx_seconds();
5129 //mprintf( (0, "Packet has %d bytes appended (TS=%d)\n", MySyncPack.data_size, sizeof(frame_info)-MaxXDataSize+MySyncPack.data_size ));
5136 if ((last_timeout_check > F1_0) && !(Control_center_destroyed))
5138 fix approx_time = timer_get_approx_seconds();
5139 // Check for player timeouts
5140 for (i = 0; i < N_players; i++)
5142 if ((i != Player_num) && (Players[i].connected == 1))
5144 if ((LastPacketTime[i] == 0) || (LastPacketTime[i] > approx_time))
5146 LastPacketTime[i] = approx_time;
5149 if ((approx_time - LastPacketTime[i]) > (15*F1_0))
5150 network_timeout_player(i);
5153 last_timeout_check = 0;
5159 MySyncPack.data_size = 0;
5164 if (VerifyPlayerJoined!=-1 && !(FrameCount & 63))
5165 resend_sync_due_to_packet_loss_for_allender(); // This will resend to network_player_rejoining
5167 if (Network_send_objects)
5168 network_send_objects();
5170 if (Network_sending_extras && VerifyPlayerJoined==-1)
5172 network_send_extras();
5177 int missed_packets = 0;
5179 int ConsistencyCount = 0;
5181 void network_consistency_error(void)
5183 if (++ConsistencyCount < 10)
5186 Function_mode = FMODE_MENU;
5188 nm_messagebox(NULL, 1, TXT_OK, TXT_CONSISTENCY_ERROR);
5190 nm_messagebox(NULL, 1, TXT_OK, "Failed to join the netgame.\nYou are missing packets. Check\nyour network connection and\ntry again.");
5192 Function_mode = FMODE_GAME;
5193 ConsistencyCount = 0;
5194 multi_quit_game = 1;
5195 multi_leave_menu = 1;
5196 multi_reset_stuff();
5197 Function_mode = FMODE_MENU;
5200 void network_process_pdata (char *data)
5202 Assert (Game_mode & GM_NETWORK);
5204 if (Netgame.ShortPackets)
5205 network_read_pdata_short_packet ((short_frame_info *)data);
5207 network_read_pdata_packet ((frame_info *)data);
5210 void network_read_pdata_packet(frame_info *pd )
5214 object * TheirObj = NULL;
5216 // frame_info should be aligned...for mac, make the necessary adjustments
5217 #ifdef WORDS_BIGENDIAN
5218 if (Network_game_type == IPX_GAME) {
5219 pd->numpackets = INTEL_INT(pd->numpackets);
5220 pd->obj_pos.x = INTEL_INT(pd->obj_pos.x);
5221 pd->obj_pos.y = INTEL_INT(pd->obj_pos.y);
5222 pd->obj_pos.z = INTEL_INT(pd->obj_pos.z);
5224 pd->obj_orient.rvec.x = (fix)INTEL_INT((int)pd->obj_orient.rvec.x);
5225 pd->obj_orient.rvec.y = (fix)INTEL_INT((int)pd->obj_orient.rvec.y);
5226 pd->obj_orient.rvec.z = (fix)INTEL_INT((int)pd->obj_orient.rvec.z);
5227 pd->obj_orient.uvec.x = (fix)INTEL_INT((int)pd->obj_orient.uvec.x);
5228 pd->obj_orient.uvec.y = (fix)INTEL_INT((int)pd->obj_orient.uvec.y);
5229 pd->obj_orient.uvec.z = (fix)INTEL_INT((int)pd->obj_orient.uvec.z);
5230 pd->obj_orient.fvec.x = (fix)INTEL_INT((int)pd->obj_orient.fvec.x);
5231 pd->obj_orient.fvec.y = (fix)INTEL_INT((int)pd->obj_orient.fvec.y);
5232 pd->obj_orient.fvec.z = (fix)INTEL_INT((int)pd->obj_orient.fvec.z);
5234 pd->phys_velocity.x = (fix)INTEL_INT((int)pd->phys_velocity.x);
5235 pd->phys_velocity.y = (fix)INTEL_INT((int)pd->phys_velocity.y);
5236 pd->phys_velocity.z = (fix)INTEL_INT((int)pd->phys_velocity.z);
5238 pd->phys_rotvel.x = (fix)INTEL_INT((int)pd->phys_rotvel.x);
5239 pd->phys_rotvel.y = (fix)INTEL_INT((int)pd->phys_rotvel.y);
5240 pd->phys_rotvel.z = (fix)INTEL_INT((int)pd->phys_rotvel.z);
5242 pd->obj_segnum = INTEL_SHORT(pd->obj_segnum);
5243 pd->data_size = INTEL_SHORT(pd->data_size);
5247 TheirPlayernum = pd->playernum;
5248 TheirObjnum = Players[pd->playernum].objnum;
5250 if (TheirPlayernum < 0) {
5251 Int3(); // This packet is bogus!!
5255 if (VerifyPlayerJoined!=-1 && TheirPlayernum==VerifyPlayerJoined)
5257 // Hurray! Someone really really got in the game (I think).
5258 mprintf ((0,"Hurray! VPJ (%d) reset!\n",VerifyPlayerJoined));
5259 VerifyPlayerJoined=-1;
5262 if (!multi_quit_game && (TheirPlayernum >= N_players)) {
5263 if (Network_status!=NETSTAT_WAITING)
5265 Int3(); // We missed an important packet!
5266 network_consistency_error();
5272 if (Endlevel_sequence || (Network_status == NETSTAT_ENDLEVEL) ) {
5273 int old_Endlevel_sequence = Endlevel_sequence;
5274 Endlevel_sequence = 1;
5275 if ( pd->data_size>0 ) {
5276 // pass pd->data to some parser function....
5277 multi_process_bigdata( pd->data, pd->data_size );
5279 Endlevel_sequence = old_Endlevel_sequence;
5282 // mprintf((0, "Gametime = %d, Frametime = %d.\n", GameTime, FrameTime));
5284 if ((byte)pd->level_num != Current_level_num)
5286 mprintf((0, "Got frame packet from player %d wrong level %d!\n", pd->playernum, pd->level_num));
5290 TheirObj = &Objects[TheirObjnum];
5292 //------------- Keep track of missed packets -----------------
5293 Players[TheirPlayernum].n_packets_got++;
5295 LastPacketTime[TheirPlayernum] = timer_get_approx_seconds();
5297 if ( pd->numpackets != Players[TheirPlayernum].n_packets_got ) {
5300 missed_packets = pd->numpackets-Players[TheirPlayernum].n_packets_got;
5301 if ((pd->numpackets-Players[TheirPlayernum].n_packets_got)>0)
5302 TotalMissedPackets += pd->numpackets-Players[TheirPlayernum].n_packets_got;
5304 if ( missed_packets > 0 )
5305 mprintf(( 0, "Missed %d packets from player #%d (%d total)\n", pd->numpackets-Players[TheirPlayernum].n_packets_got, TheirPlayernum, missed_packets ));
5307 mprintf( (0, "Got %d late packets from player #%d (%d total)\n", Players[TheirPlayernum].n_packets_got-pd->numpackets, TheirPlayernum, missed_packets ));
5310 #ifdef APPLETALK_DEBUG
5311 if (Network_game_type == APPLETALK_GAME) {
5312 if ( missed_packets > 0 )
5313 fprintf( at_fp, "Missed %d packets from player #%d (%d total)\n", pd->numpackets-Players[TheirPlayernum].n_packets_got, TheirPlayernum, missed_packets );
5315 fprintf( at_fp, "Got %d late packets from player #%d (%d total)\n", Players[TheirPlayernum].n_packets_got-pd->numpackets, TheirPlayernum, missed_packets );
5320 if (Network_game_type == IPX_GAME) {
5321 if ( missed_packets > 0 )
5322 fprintf( ipx_fp, "Missed %d packets from player #%d (%d total)\n", pd->numpackets-Players[TheirPlayernum].n_packets_got, TheirPlayernum, missed_packets );
5324 fprintf( ipx_fp, "Got %d late packets from player #%d (%d total)\n", Players[TheirPlayernum].n_packets_got-pd->numpackets, TheirPlayernum, missed_packets );
5329 Players[TheirPlayernum].n_packets_got = pd->numpackets;
5332 //------------ Read the player's ship's object info ----------------------
5333 TheirObj->pos = pd->obj_pos;
5334 TheirObj->orient = pd->obj_orient;
5335 TheirObj->mtype.phys_info.velocity = pd->phys_velocity;
5336 TheirObj->mtype.phys_info.rotvel = pd->phys_rotvel;
5338 if ((TheirObj->render_type != pd->obj_render_type) && (pd->obj_render_type == RT_POLYOBJ))
5339 multi_make_ghost_player(TheirPlayernum);
5341 obj_relink(TheirObjnum,pd->obj_segnum);
5343 if (TheirObj->movement_type == MT_PHYSICS)
5344 set_thrust_from_velocity(TheirObj);
5346 //------------ Welcome them back if reconnecting --------------
5347 if (!Players[TheirPlayernum].connected) {
5348 Players[TheirPlayernum].connected = 1;
5350 if (Newdemo_state == ND_STATE_RECORDING)
5351 newdemo_record_multi_reconnect(TheirPlayernum);
5353 multi_make_ghost_player(TheirPlayernum);
5355 create_player_appearance_effect(&Objects[TheirObjnum]);
5357 digi_play_sample( SOUND_HUD_MESSAGE, F1_0);
5359 ClipRank (&NetPlayers.players[TheirPlayernum].rank);
5361 if (FindArg("-norankings"))
5362 HUD_init_message( "'%s' %s", Players[TheirPlayernum].callsign, TXT_REJOIN );
5364 HUD_init_message( "%s'%s' %s", RankStrings[NetPlayers.players[TheirPlayernum].rank],Players[TheirPlayernum].callsign, TXT_REJOIN );
5370 //------------ Parse the extra data at the end ---------------
5372 if ( pd->data_size>0 ) {
5373 // pass pd->data to some parser function....
5374 multi_process_bigdata( pd->data, pd->data_size );
5379 #ifdef WORDS_BIGENDIAN
5380 void get_short_frame_info(ubyte *old_info, short_frame_info *new_info)
5384 new_info->type = old_info[loc]; loc++;
5385 /* skip three for pad byte */ loc += 3;
5386 memcpy(&(new_info->numpackets), &(old_info[loc]), 4); loc += 4;
5387 new_info->numpackets = INTEL_INT(new_info->numpackets);
5388 memcpy(new_info->thepos.bytemat, &(old_info[loc]), 9); loc += 9;
5389 memcpy(&(new_info->thepos.xo), &(old_info[loc]), 2); loc += 2;
5390 memcpy(&(new_info->thepos.yo), &(old_info[loc]), 2); loc += 2;
5391 memcpy(&(new_info->thepos.zo), &(old_info[loc]), 2); loc += 2;
5392 memcpy(&(new_info->thepos.segment), &(old_info[loc]), 2); loc += 2;
5393 memcpy(&(new_info->thepos.velx), &(old_info[loc]), 2); loc += 2;
5394 memcpy(&(new_info->thepos.vely), &(old_info[loc]), 2); loc += 2;
5395 memcpy(&(new_info->thepos.velz), &(old_info[loc]), 2); loc += 2;
5396 new_info->thepos.xo = INTEL_SHORT(new_info->thepos.xo);
5397 new_info->thepos.yo = INTEL_SHORT(new_info->thepos.yo);
5398 new_info->thepos.zo = INTEL_SHORT(new_info->thepos.zo);
5399 new_info->thepos.segment = INTEL_SHORT(new_info->thepos.segment);
5400 new_info->thepos.velx = INTEL_SHORT(new_info->thepos.velx);
5401 new_info->thepos.vely = INTEL_SHORT(new_info->thepos.vely);
5402 new_info->thepos.velz = INTEL_SHORT(new_info->thepos.velz);
5404 memcpy(&(new_info->data_size), &(old_info[loc]), 2); loc += 2;
5405 new_info->data_size = INTEL_SHORT(new_info->data_size);
5406 new_info->playernum = old_info[loc]; loc++;
5407 new_info->obj_render_type = old_info[loc]; loc++;
5408 new_info->level_num = old_info[loc]; loc++;
5409 memcpy(new_info->data, &(old_info[loc]), new_info->data_size);
5412 #define get_short_frame_info(old_info, new_info) \
5413 memcpy(new_info, old_info, sizeof(short_frame_info))
5416 void network_read_pdata_short_packet(short_frame_info *pd )
5420 object * TheirObj = NULL;
5421 short_frame_info new_pd;
5423 // short frame info is not aligned because of shortpos. The mac
5424 // will call totally hacked and gross function to fix this up.
5426 if (Network_game_type == IPX_GAME) {
5427 get_short_frame_info((ubyte *)pd, &new_pd);
5429 memcpy(&new_pd, (ubyte *)pd, sizeof(short_frame_info));
5432 TheirPlayernum = new_pd.playernum;
5433 TheirObjnum = Players[new_pd.playernum].objnum;
5435 if (TheirPlayernum < 0) {
5436 Int3(); // This packet is bogus!!
5439 if (!multi_quit_game && (TheirPlayernum >= N_players)) {
5440 if (Network_status!=NETSTAT_WAITING)
5442 Int3(); // We missed an important packet!
5443 network_consistency_error();
5450 if (VerifyPlayerJoined!=-1 && TheirPlayernum==VerifyPlayerJoined)
5452 // Hurray! Someone really really got in the game (I think).
5453 mprintf ((0,"Hurray! VPJ (%d) reset!\n",VerifyPlayerJoined));
5454 VerifyPlayerJoined=-1;
5457 if (Endlevel_sequence || (Network_status == NETSTAT_ENDLEVEL) ) {
5458 int old_Endlevel_sequence = Endlevel_sequence;
5459 Endlevel_sequence = 1;
5460 if ( new_pd.data_size>0 ) {
5461 // pass pd->data to some parser function....
5462 multi_process_bigdata( new_pd.data, new_pd.data_size );
5464 Endlevel_sequence = old_Endlevel_sequence;
5467 // mprintf((0, "Gametime = %d, Frametime = %d.\n", GameTime, FrameTime));
5469 if ((byte)new_pd.level_num != Current_level_num)
5471 mprintf((0, "Got frame packet from player %d wrong level %d!\n", new_pd.playernum, new_pd.level_num));
5475 TheirObj = &Objects[TheirObjnum];
5477 //------------- Keep track of missed packets -----------------
5478 Players[TheirPlayernum].n_packets_got++;
5480 LastPacketTime[TheirPlayernum] = timer_get_approx_seconds();
5482 if ( new_pd.numpackets != Players[TheirPlayernum].n_packets_got ) {
5485 missed_packets = new_pd.numpackets-Players[TheirPlayernum].n_packets_got;
5486 if ((new_pd.numpackets-Players[TheirPlayernum].n_packets_got)>0)
5487 TotalMissedPackets += new_pd.numpackets-Players[TheirPlayernum].n_packets_got;
5489 if ( missed_packets > 0 )
5490 mprintf( (0, "Missed %d packets from player #%d (%d total)\n", new_pd.numpackets-Players[TheirPlayernum].n_packets_got, TheirPlayernum, missed_packets ));
5492 mprintf( (0, "Got %d late packets from player #%d (%d total)\n", Players[TheirPlayernum].n_packets_got-new_pd.numpackets, TheirPlayernum, missed_packets ));
5494 Players[TheirPlayernum].n_packets_got = new_pd.numpackets;
5497 //------------ Read the player's ship's object info ----------------------
5499 extract_shortpos(TheirObj, &new_pd.thepos, 0);
5501 if ((TheirObj->render_type != new_pd.obj_render_type) && (new_pd.obj_render_type == RT_POLYOBJ))
5502 multi_make_ghost_player(TheirPlayernum);
5504 if (TheirObj->movement_type == MT_PHYSICS)
5505 set_thrust_from_velocity(TheirObj);
5507 //------------ Welcome them back if reconnecting --------------
5508 if (!Players[TheirPlayernum].connected) {
5509 Players[TheirPlayernum].connected = 1;
5511 if (Newdemo_state == ND_STATE_RECORDING)
5512 newdemo_record_multi_reconnect(TheirPlayernum);
5514 multi_make_ghost_player(TheirPlayernum);
5516 create_player_appearance_effect(&Objects[TheirObjnum]);
5518 digi_play_sample( SOUND_HUD_MESSAGE, F1_0);
5519 ClipRank (&NetPlayers.players[TheirPlayernum].rank);
5521 if (FindArg("-norankings"))
5522 HUD_init_message( "'%s' %s", Players[TheirPlayernum].callsign, TXT_REJOIN );
5524 HUD_init_message( "%s'%s' %s", RankStrings[NetPlayers.players[TheirPlayernum].rank],Players[TheirPlayernum].callsign, TXT_REJOIN );
5530 //------------ Parse the extra data at the end ---------------
5532 if ( new_pd.data_size>0 ) {
5533 // pass pd->data to some parser function....
5534 multi_process_bigdata( new_pd.data, new_pd.data_size );
5540 void network_set_power (void)
5542 int opt=0,choice,opt_primary,opt_second,opt_power;
5546 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Laser upgrade"; m[opt].value=Netgame.DoLaserUpgrade; opt++;
5547 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Super lasers"; m[opt].value=Netgame.DoSuperLaser; opt++;
5548 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Quad Lasers"; m[opt].value=Netgame.DoQuadLasers; opt++;
5549 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Vulcan cannon"; m[opt].value=Netgame.DoVulcan; opt++;
5550 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Spreadfire cannon"; m[opt].value=Netgame.DoSpread; opt++;
5551 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Plasma cannon"; m[opt].value=Netgame.DoPlasma; opt++;
5552 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Fusion cannon"; m[opt].value=Netgame.DoFusions; opt++;
5553 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Gauss cannon"; m[opt].value=Netgame.DoGauss; opt++;
5554 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Helix cannon"; m[opt].value=Netgame.DoHelix; opt++;
5555 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Phoenix cannon"; m[opt].value=Netgame.DoPhoenix; opt++;
5556 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Omega cannon"; m[opt].value=Netgame.DoOmega; opt++;
5559 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Homing Missiles"; m[opt].value=Netgame.DoHoming; opt++;
5560 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Proximity Bombs"; m[opt].value=Netgame.DoProximity; opt++;
5561 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Smart Missiles"; m[opt].value=Netgame.DoSmarts; opt++;
5562 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Mega Missiles"; m[opt].value=Netgame.DoMegas; opt++;
5563 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Flash Missiles"; m[opt].value=Netgame.DoFlash; opt++;
5564 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Guided Missiles"; m[opt].value=Netgame.DoGuided; opt++;
5565 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Smart Mines"; m[opt].value=Netgame.DoSmartMine; opt++;
5566 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Mercury Missiles"; m[opt].value=Netgame.DoMercury; opt++;
5567 m[opt].type = NM_TYPE_CHECK; m[opt].text = "EarthShaker Missiles"; m[opt].value=Netgame.DoEarthShaker; opt++;
5570 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Invulnerability"; m[opt].value=Netgame.DoInvulnerability; opt++;
5571 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Cloaking"; m[opt].value=Netgame.DoCloak; opt++;
5572 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Afterburners"; m[opt].value=Netgame.DoAfterburner; opt++;
5573 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Ammo rack"; m[opt].value=Netgame.DoAmmoRack; opt++;
5574 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Energy Converter"; m[opt].value=Netgame.DoConverter; opt++;
5575 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Headlight"; m[opt].value=Netgame.DoHeadlight; opt++;
5577 choice = newmenu_do(NULL, "Objects to allow", opt, m, NULL);
5579 Netgame.DoLaserUpgrade=m[opt_primary].value;
5580 Netgame.DoSuperLaser=m[opt_primary+1].value;
5581 Netgame.DoQuadLasers=m[opt_primary+2].value;
5582 Netgame.DoVulcan=m[opt_primary+3].value;
5583 Netgame.DoSpread=m[opt_primary+4].value;
5584 Netgame.DoPlasma=m[opt_primary+5].value;
5585 Netgame.DoFusions=m[opt_primary+6].value;
5586 Netgame.DoGauss=m[opt_primary+7].value;
5587 Netgame.DoHelix=m[opt_primary+8].value;
5588 Netgame.DoPhoenix=m[opt_primary+9].value;
5589 Netgame.DoOmega=m[opt_primary+10].value;
5591 Netgame.DoHoming=m[opt_second].value;
5592 Netgame.DoProximity=m[opt_second+1].value;
5593 Netgame.DoSmarts=m[opt_second+2].value;
5594 Netgame.DoMegas=m[opt_second+3].value;
5595 Netgame.DoFlash=m[opt_second+4].value;
5596 Netgame.DoGuided=m[opt_second+5].value;
5597 Netgame.DoSmartMine=m[opt_second+6].value;
5598 Netgame.DoMercury=m[opt_second+7].value;
5599 Netgame.DoEarthShaker=m[opt_second+8].value;
5601 Netgame.DoInvulnerability=m[opt_power].value;
5602 Netgame.DoCloak=m[opt_power+1].value;
5603 Netgame.DoAfterburner=m[opt_power+2].value;
5604 Netgame.DoAmmoRack=m[opt_power+3].value;
5605 Netgame.DoConverter=m[opt_power+4].value;
5606 Netgame.DoHeadlight=m[opt_power+5].value;
5610 void SetAllAllowablesTo (int on)
5612 last_cinvul = control_invul_time = 0; //default to zero
5614 Netgame.DoMegas=Netgame.DoSmarts=Netgame.DoFusions=Netgame.DoHelix=\
5615 Netgame.DoPhoenix=Netgame.DoCloak=Netgame.DoInvulnerability=\
5616 Netgame.DoAfterburner=Netgame.DoGauss=Netgame.DoVulcan=Netgame.DoPlasma=on;
5618 Netgame.DoOmega=Netgame.DoSuperLaser=Netgame.DoProximity=\
5619 Netgame.DoSpread=Netgame.DoMercury=Netgame.DoSmartMine=Netgame.DoFlash=\
5620 Netgame.DoGuided=Netgame.DoEarthShaker=on;
5622 Netgame.DoConverter=Netgame.DoAmmoRack=Netgame.DoHeadlight=on;
5623 Netgame.DoHoming=Netgame.DoLaserUpgrade=Netgame.DoQuadLasers=on;
5624 Netgame.BrightPlayers=Netgame.invul=on;
5630 // Jeez -- mac compiler can't handle all of these on the same decl line.
5631 int opt_setpower,opt_playtime,opt_killgoal,opt_socket,opt_marker_view,opt_light,opt_show_on_map;
5632 int opt_difficulty,opt_packets,opt_short_packets, opt_bright,opt_start_invul;
5635 void network_more_options_poll( int nitems, newmenu_item * menus, int * key, int citem );
5637 void network_more_game_options ()
5640 char PlayText[80],KillText[80],srinvul[50],socket_string[5],packstring[5];
5643 sprintf (socket_string,"%d",Network_socket);
5644 sprintf (packstring,"%d",Netgame.PacketsPerSec);
5646 opt_difficulty = opt;
5647 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++;
5650 sprintf( srinvul, "%s: %d %s", TXT_REACTOR_LIFE, control_invul_time*5, TXT_MINUTES_ABBREV );
5651 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++;
5654 sprintf( PlayText, "Max time: %d %s", Netgame.PlayTimeAllowed*5, TXT_MINUTES_ABBREV );
5655 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++;
5658 sprintf( KillText, "Kill Goal: %d kills", Netgame.KillGoal*5);
5659 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++;
5661 opt_start_invul=opt;
5662 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Invulnerable when reappearing"; m[opt].value=Netgame.invul; opt++;
5664 opt_marker_view = opt;
5665 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Allow camera views from Markers"; m[opt].value=Netgame.Allow_marker_view; opt++;
5667 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Indestructible lights"; m[opt].value=Netgame.AlwaysLighting; opt++;
5670 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Bright player ships"; m[opt].value=Netgame.BrightPlayers; opt++;
5673 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Show enemy names on HUD"; m[opt].value=Netgame.ShowAllNames; opt++;
5675 opt_show_on_map=opt;
5676 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++;
5678 opt_short_packets=opt;
5679 m[opt].type = NM_TYPE_CHECK; m[opt].text = "Short packets"; m[opt].value=Netgame.ShortPackets; opt++;
5682 m[opt].type = NM_TYPE_MENU; m[opt].text = "Set Objects allowed..."; opt++;
5684 if (Network_game_type == IPX_GAME) {
5685 m[opt].type = NM_TYPE_TEXT; m[opt].text = "Network socket"; opt++;
5687 m[opt].type = NM_TYPE_INPUT; m[opt].text = socket_string; m[opt].text_len=4; opt++;
5690 m[opt].type = NM_TYPE_TEXT; m[opt].text = "Packets per second (2 - 20)"; opt++;
5692 m[opt].type = NM_TYPE_INPUT; m[opt].text=packstring; m[opt].text_len=2; opt++;
5694 LastKillGoal=Netgame.KillGoal;
5695 LastPTA=Netgame.PlayTimeAllowed;
5699 ExtGameStatus=GAMESTAT_MORE_NETGAME_OPTIONS;
5700 i = newmenu_do1( NULL, "Additional netgame options", opt, m, network_more_options_poll, 0 );
5702 //control_invul_time = atoi( srinvul )*60*F1_0;
5703 control_invul_time = m[opt_cinvul].value;
5704 Netgame.control_invul_time = control_invul_time*5*F1_0*60;
5706 if (i==opt_setpower)
5708 network_set_power ();
5712 Netgame.PacketsPerSec=atoi(packstring);
5714 if (Netgame.PacketsPerSec>20)
5716 Netgame.PacketsPerSec=20;
5717 nm_messagebox(TXT_ERROR, 1, TXT_OK, "Packet value out of range\nSetting value to 20");
5719 if (Netgame.PacketsPerSec<2)
5721 nm_messagebox(TXT_ERROR, 1, TXT_OK, "Packet value out of range\nSetting value to 2");
5722 Netgame.PacketsPerSec=2;
5725 mprintf ((0,"Hey! Sending out %d packets per second\n",Netgame.PacketsPerSec));
5727 if (Network_game_type == IPX_GAME) {
5728 if ((atoi(socket_string))!=Network_socket) {
5729 Network_socket=atoi(socket_string);
5730 ipx_change_default_socket( IPX_DEFAULT_SOCKET + Network_socket );
5734 Netgame.invul=m[opt_start_invul].value;
5735 Netgame.BrightPlayers=m[opt_bright].value;
5736 Netgame.ShortPackets=m[opt_short_packets].value;
5737 Netgame.ShowAllNames=m[opt_show_names].value;
5738 network_AdjustMaxDataSize();
5740 Netgame.Allow_marker_view=m[opt_marker_view].value;
5741 Netgame.AlwaysLighting=m[opt_light].value;
5742 netgame_difficulty=Difficulty_level = m[opt_difficulty].value;
5743 if (m[opt_show_on_map].value)
5744 Netgame.game_flags |= NETGAME_FLAG_SHOW_MAP;
5749 void network_more_options_poll( int nitems, newmenu_item * menus, int * key, int citem )
5752 citem = citem; // kills compile warnings
5756 if ( last_cinvul != menus[opt_cinvul].value ) {
5757 sprintf( menus[opt_cinvul].text, "%s: %d %s", TXT_REACTOR_LIFE, menus[opt_cinvul].value*5, TXT_MINUTES_ABBREV );
5758 last_cinvul = menus[opt_cinvul].value;
5759 menus[opt_cinvul].redraw = 1;
5762 if (menus[opt_playtime].value!=LastPTA)
5766 nm_messagebox ("Sorry",1,TXT_OK,"Registered version only!");
5767 menus[opt_playtime].value=0;
5768 menus[opt_playtime].redraw=1;
5772 if (Game_mode & GM_MULTI_COOP)
5775 nm_messagebox ("Sorry",1,TXT_OK,"You can't change those for coop!");
5776 menus[opt_playtime].value=0;
5777 menus[opt_playtime].redraw=1;
5781 Netgame.PlayTimeAllowed=menus[opt_playtime].value;
5782 sprintf( menus[opt_playtime].text, "Max Time: %d %s", Netgame.PlayTimeAllowed*5, TXT_MINUTES_ABBREV );
5783 LastPTA=Netgame.PlayTimeAllowed;
5784 menus[opt_playtime].redraw=1;
5786 if (menus[opt_killgoal].value!=LastKillGoal)
5789 nm_messagebox ("Sorry",1,TXT_OK,"Registered version only!");
5790 menus[opt_killgoal].value=0;
5791 menus[opt_killgoal].redraw=1;
5797 if (Game_mode & GM_MULTI_COOP)
5799 nm_messagebox ("Sorry",1,TXT_OK,"You can't change those for coop!");
5800 menus[opt_killgoal].value=0;
5801 menus[opt_killgoal].redraw=1;
5807 Netgame.KillGoal=menus[opt_killgoal].value;
5808 sprintf( menus[opt_killgoal].text, "Kill Goal: %d kills", Netgame.KillGoal*5);
5809 LastKillGoal=Netgame.KillGoal;
5810 menus[opt_killgoal].redraw=1;
5814 extern void multi_send_light (int,ubyte);
5815 extern void multi_send_light_specific (int,int,ubyte);
5817 void network_send_smash_lights (int pnum)
5819 // send the lights that have been blown out
5825 for (i=0;i<=Highest_segment_index;i++)
5826 if (Light_subtracted[i])
5827 multi_send_light_specific(pnum,i,Light_subtracted[i]);
5830 extern int Num_triggers;
5831 extern void multi_send_trigger_specific (char pnum,char);
5833 void network_send_fly_thru_triggers (int pnum)
5835 // send the fly thru triggers that have been disabled
5839 for (i=0;i<Num_triggers;i++)
5840 if (Triggers[i].flags & TF_DISABLED)
5841 multi_send_trigger_specific(pnum,i);
5844 void network_send_player_flags()
5848 for (i=0;i<N_players;i++)
5849 multi_send_flags(i);
5852 void network_ping (ubyte flag,int pnum)
5857 mybuf[1]=Player_num;
5859 if (Network_game_type == IPX_GAME)
5860 ipx_send_packet_data( (ubyte *)mybuf, 2, NetPlayers.players[pnum].network.ipx.server, NetPlayers.players[pnum].network.ipx.node,Players[pnum].net_address );
5863 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);
5867 extern fix PingLaunchTime,PingReturnTime;
5869 void network_handle_ping_return (ubyte pnum)
5871 if (PingLaunchTime==0 || pnum>=N_players)
5873 mprintf ((0,"Got invalid PING RETURN from %s!\n",Players[pnum].callsign));
5877 PingReturnTime=timer_get_fixed_seconds();
5879 HUD_init_message ("Ping time for %s is %d ms!",Players[pnum].callsign,
5880 f2i(fixmul(PingReturnTime-PingLaunchTime,i2f(1000))));
5884 void network_send_ping (ubyte pnum)
5886 network_ping (PID_PING_SEND,pnum);
5889 void DoRefuseStuff (sequence_packet *their)
5891 int i,new_player_num;
5893 ClipRank (&their->player.rank);
5895 for (i=0;i<MAX_PLAYERS;i++)
5896 if (!strcmp (their->player.callsign,Players[i].callsign))
5898 network_welcome_player(their);
5902 if (!WaitForRefuseAnswer)
5904 for (i=0;i<MAX_PLAYERS;i++)
5905 if (!strcmp (their->player.callsign,Players[i].callsign))
5907 network_welcome_player(their);
5911 digi_play_sample (SOUND_HUD_JOIN_REQUEST,F1_0*2);
5913 if (Game_mode & GM_TEAM)
5917 if (!FindArg("-norankings"))
5918 HUD_init_message ("%s %s wants to join",RankStrings[their->player.rank],their->player.callsign);
5920 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]);
5922 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]);
5924 // HUD_init_message ("Alt-1 to place on team %s!",Netgame.team_name[0]);
5925 // HUD_init_message ("Alt-2 to place on team %s!",Netgame.team_name[1]);
5928 HUD_init_message ("%s wants to join...press F6 to connect",their->player.callsign);
5930 strcpy (RefusePlayerName,their->player.callsign);
5931 RefuseTimeLimit=timer_get_approx_seconds();
5933 WaitForRefuseAnswer=1;
5937 for (i=0;i<MAX_PLAYERS;i++)
5938 if (!strcmp (their->player.callsign,Players[i].callsign))
5940 network_welcome_player(their);
5944 if (strcmp(their->player.callsign,RefusePlayerName))
5947 if (RefuseThisPlayer)
5951 WaitForRefuseAnswer=0;
5952 if (Game_mode & GM_TEAM)
5954 new_player_num=GetNewPlayerNumber (their);
5955 mprintf ((0,"Newplayernum=%d\n",new_player_num));
5957 Assert (RefuseTeam==1 || RefuseTeam==2);
5960 Netgame.team_vector &=(~(1<<new_player_num));
5962 Netgame.team_vector |=(1<<new_player_num);
5963 network_welcome_player(their);
5964 network_send_netgame_update ();
5967 network_welcome_player(their);
5971 if ((timer_get_approx_seconds()) > RefuseTimeLimit+REFUSE_INTERVAL)
5975 WaitForRefuseAnswer=0;
5976 if (!strcmp (their->player.callsign,RefusePlayerName)) {
5977 if (Network_game_type == IPX_GAME)
5978 network_dump_player(their->player.network.ipx.server,their->player.network.ipx.node, DUMP_DORK);
5981 network_dump_appletalk_player(their->player.network.appletalk.node,their->player.network.appletalk.net, their->player.network.appletalk.socket, DUMP_DORK);
5990 int GetNewPlayerNumber (sequence_packet *their)
5996 if ( N_players < MaxNumNetPlayers)
6001 // Slots are full but game is open, see if anyone is
6002 // disconnected and replace the oldest player with this new one
6004 int oldest_player = -1;
6005 fix oldest_time = timer_get_approx_seconds();
6007 Assert(N_players == MaxNumNetPlayers);
6009 for (i = 0; i < N_players; i++)
6011 if ( (!Players[i].connected) && (LastPacketTime[i] < oldest_time))
6013 oldest_time = LastPacketTime[i];
6017 return (oldest_player);
6021 void network_send_extras ()
6023 Assert (Player_joining_extras>-1);
6025 if (!network_i_am_master())
6027 mprintf ((0,"Hey! I'm not the master and I was gonna send info!\n"));
6029 // Network_sending_extras=0;
6034 if (Network_sending_extras==40)
6035 network_send_fly_thru_triggers(Player_joining_extras);
6036 if (Network_sending_extras==38)
6037 network_send_door_updates(Player_joining_extras);
6038 if (Network_sending_extras==35)
6039 network_send_markers();
6040 if (Network_sending_extras==30 && (Game_mode & GM_MULTI_ROBOTS))
6041 multi_send_stolen_items();
6042 if (Network_sending_extras==25 && (Netgame.PlayTimeAllowed || Netgame.KillGoal))
6043 multi_send_kill_goal_counts();
6044 if (Network_sending_extras==20)
6045 network_send_smash_lights(Player_joining_extras);
6046 if (Network_sending_extras==15)
6047 network_send_player_flags();
6048 if (Network_sending_extras==10)
6049 multi_send_powerup_update();
6050 // if (Network_sending_extras==5)
6051 // network_send_door_updates(Player_joining_extras); // twice!
6053 Network_sending_extras--;
6054 if (!Network_sending_extras)
6055 Player_joining_extras=-1;
6059 void network_send_naked_packet(char *buf, short len, int who)
6061 if (!(Game_mode&GM_NETWORK)) return;
6063 if (NakedPacketLen==0)
6065 NakedBuf[0]=PID_NAKED_PDATA;
6066 NakedBuf[1]=Player_num;
6070 if (len+NakedPacketLen>MaxXDataSize)
6072 // mprintf ((0,"Sending a naked packet of %d bytes.\n",NakedPacketLen));
6073 if (Network_game_type == IPX_GAME)
6074 ipx_send_packet_data( (ubyte *)NakedBuf, NakedPacketLen, NetPlayers.players[who].network.ipx.server, NetPlayers.players[who].network.ipx.node,Players[who].net_address );
6077 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 );
6080 memcpy (&NakedBuf[NakedPacketLen],buf,len);
6081 NakedPacketLen+=len;
6082 NakedPacketDestPlayer=who;
6086 memcpy (&NakedBuf[NakedPacketLen],buf,len);
6087 NakedPacketLen+=len;
6088 NakedPacketDestPlayer=who;
6093 void network_process_naked_pdata (char *data,int len)
6096 Assert (data[0]=PID_NAKED_PDATA);
6098 // mprintf ((0,"Processing a naked packet of %d length.\n",len));
6101 mprintf ((0,"Naked packet is bad!\n"));
6102 Int3(); // This packet is bogus!!
6106 if (!multi_quit_game && (pnum >= N_players)) {
6107 if (Network_status!=NETSTAT_WAITING)
6109 Int3(); // We missed an important packet!
6110 network_consistency_error();
6117 if (Endlevel_sequence || (Network_status == NETSTAT_ENDLEVEL) ) {
6118 int old_Endlevel_sequence = Endlevel_sequence;
6119 Endlevel_sequence = 1;
6120 multi_process_bigdata( data+2, len-2);
6121 Endlevel_sequence = old_Endlevel_sequence;
6125 multi_process_bigdata( data+2, len-2 );
6128 int ConnectionPacketLevel[]={0,1,1,1};
6129 int ConnectionSecLevel[]={12,3,5,7};
6131 int AppletalkConnectionPacketLevel[]={0,1,0};
6132 int AppletalkConnectionSecLevel[]={10,3,8};
6134 #if defined(RELEASE) && !defined(MACINTOSH) // use the code below for mac appletalk games
6135 int network_choose_connect ()
6140 int network_choose_connect ()
6147 if (Network_game_type == IPX_GAME) {
6149 m[opt].type = NM_TYPE_MENU; m[opt].text = "Local Subnet"; opt++;
6150 m[opt].type = NM_TYPE_MENU; m[opt].text = "14.4 modem over Internet"; opt++;
6151 m[opt].type = NM_TYPE_MENU; m[opt].text = "28.8 modem over Internet"; opt++;
6152 m[opt].type = NM_TYPE_MENU; m[opt].text = "ISDN or T1 over Internet"; opt++;
6154 choice = newmenu_do1( NULL, "Choose connection type", opt, m, NULL, 0 );
6159 Assert (choice>=0 && choice<=3);
6161 Netgame.ShortPackets=ConnectionPacketLevel[choice];
6162 Netgame.PacketsPerSec=ConnectionSecLevel[choice];
6167 m[opt].type = NM_TYPE_MENU; m[opt].text = "EtherTalk"; opt++;
6168 m[opt].type = NM_TYPE_MENU; m[opt].text = "LocalTalk"; opt++;
6169 m[opt].type = NM_TYPE_MENU; m[opt].text = "Other"; opt++;
6171 choice = newmenu_do1( NULL, "Choose connection type", opt, m, NULL, 0 );
6176 Network_appletalk_type = choice;
6178 Assert (choice>=0 && choice<=2);
6180 Netgame.ShortPackets=AppletalkConnectionPacketLevel[choice];
6181 Netgame.PacketsPerSec=AppletalkConnectionSecLevel[choice];
6195 SendLogFile=(FILE *)fopen ("sendlog.net","w");
6199 void OpenRecieveLog ()
6202 RecieveLogFile=(FILE *)fopen ("recvlog.net","w");
6208 int GetMyNetRanking ()
6213 if (Netlife_kills+Netlife_killed==0)
6216 rank=(int) (((float)Netlife_kills/3000.0)*8.0);
6218 eff=(int)((float)((float)Netlife_kills/((float)Netlife_killed+(float)Netlife_kills))*100.0);
6227 rank-=((59-eff)/10);
6234 mprintf ((0,"Rank is %d (%s)\n",rank+1,RankStrings[rank+1]));
6238 void ClipRank (signed char *rank)
6240 // This function insures no crashes when dealing with D2 1.0
6243 if (*rank<0 || *rank>9)
6246 void network_check_for_old_version (char pnum)
6248 if (NetPlayers.players[(int)pnum].version_major==1 && (NetPlayers.players[(int)pnum].version_minor & 0x0F)==0)
6249 NetPlayers.players[(int)pnum].rank=0;
6252 void network_request_player_names (int n)
6254 network_send_all_info_request (PID_GAME_PLAYERS,Active_games[n].Security);
6255 NamesInfoSecurity=Active_games[n].Security;
6258 extern char already_showing_info;
6259 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));
6261 void network_process_names_return (char *data)
6264 char mtext[15][50],temp[50];
6265 int i,t,l,gnum,num=0,count=5,numplayers;
6267 if (NamesInfoSecurity!=(*(int *)(data+1)))
6269 mprintf ((0,"Bad security on names return!\n"));
6270 mprintf ((0,"NIS=%d data=%d\n",NamesInfoSecurity,(*(int *)(data+1))));
6274 numplayers=data[count]; count++;
6276 if (numplayers==255)
6279 NamesInfoSecurity=-1;
6280 nm_messagebox(NULL, 1, "OK", "That game is refusing\nname requests.\n");
6285 Assert (numplayers>0 && numplayers<MAX_NUM_NET_PLAYERS);
6289 m[i].text=(char *)&mtext[i];
6290 m[i].type=NM_TYPE_TEXT;
6293 for (gnum=-1,i=0;i<num_active_games;i++)
6295 if (NamesInfoSecurity==Active_games[i].Security)
6305 NamesInfoSecurity=-1;
6306 nm_messagebox(NULL, 1, "OK", "The game you have requested\nnames from is gone.\n");
6311 sprintf (mtext[num],"Players of game '%s':",Active_games[gnum].game_name); num++;
6312 for (i=0;i<numplayers;i++)
6316 mprintf ((0,"%s\n",data+count));
6318 for (t=0;t<CALLSIGN_LEN+1;t++)
6319 temp[t]=data[count++];
6320 if (FindArg("-norankings"))
6321 sprintf (mtext[num],"%s",temp);
6323 sprintf (mtext[num],"%s%s",RankStrings[l],temp);
6328 if (data[count]==99)
6330 sprintf (mtext[num++]," ");
6331 sprintf (mtext[num++],"Short packets: %s",data[count+1]?"On":"Off");
6332 sprintf (mtext[num++],"Packets Per Second: %d",data[count+2]);
6335 already_showing_info=1;
6336 newmenu_dotiny2( NULL, NULL, num, m, NULL);
6337 already_showing_info=0;
6340 char NameReturning=1;
6342 void network_send_player_names (sequence_packet *their)
6344 int numconnected=0,count=0,i,t;
6349 mprintf ((0,"Got a player name without a return address! Get Jason\n"));
6353 buf[0]=PID_NAMES_RETURN; count++;
6354 (*(int *)(buf+1))=Netgame.Security; count+=4;
6358 buf[count]=255; count++;
6362 mprintf ((0,"RealSec=%d DS=%d\n",Netgame.Security,*(int *)(buf+1)));
6364 for (i=0;i<N_players;i++)
6365 if (Players[i].connected)
6368 buf[count]=numconnected; count++;
6369 for (i=0;i<N_players;i++)
6370 if (Players[i].connected)
6372 buf[count++]=NetPlayers.players[i].rank;
6374 for (t=0;t<CALLSIGN_LEN+1;t++)
6376 buf[count]=NetPlayers.players[i].callsign[t];
6382 buf[count++]=Netgame.ShortPackets;
6383 buf[count++]=Netgame.PacketsPerSec;
6386 ; // empty statement allows compilation on mac which does not have the
6387 // statement below and kills the compiler when there is no
6388 // statement following the label "sendit"
6391 ipx_send_internetwork_packet_data((ubyte *)buf, count, their->player.network.ipx.server, their->player.network.ipx.node);
6398 static int checked=-1;
6406 if (cfexist("hoard.ham"))