From 53efe6c01ada6a7198eae8e377a38831f6dae766 Mon Sep 17 00:00:00 2001 From: zicodxx <> Date: Fri, 12 Dec 2008 01:36:34 +0000 Subject: [PATCH] Cleaned a frameinfo-packet related code and introduced more of D2X - especially for short packets (which is thankfully covered by Version checking) --- CHANGELOG.txt | 4 + main/netpkt.c | 210 +++++++++++------------------- main/netpkt.h | 13 +- main/network.c | 340 +++++++++++++++++++++++++++++++++++++++++++++---- main/network.h | 18 ++- 5 files changed, 424 insertions(+), 161 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index dc73a2bee..07342e04c 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,5 +1,9 @@ D1X-Rebirth Changelog +20081212 +-------- +main/netpkt.c, main/netpkt.h, main/network.c, main/network.h: Cleaned a frameinfo-packet related code and introduced more of D2X - especially for short packets (which is thankfully covered by Version checking) + 20081208 -------- main/multi.h: Made MULTI_D1X_PROTO use D1X-IVER so no different releases can play together with Version checking enabled diff --git a/main/netpkt.c b/main/netpkt.c index 73df71cb8..c253fb63a 100644 --- a/main/netpkt.c +++ b/main/netpkt.c @@ -532,146 +532,86 @@ void receive_d1x_netgame_packet(ubyte *data, netgame_info *netgame) { } } -void send_frameinfo_packet(ubyte *server, ubyte *node, ubyte *address, int short_packet) +#ifdef WORDS_BIGENDIAN +void send_frameinfo_packet(frame_info *info, ubyte *server, ubyte *node, ubyte *net_address) { - int loc; - ushort tmpus; - object *pl_obj = &Objects[Players[Player_num].objnum]; + int loc = 0; + + out_buffer[loc] = info->type; loc++; + /*3 bytes of padding */ loc += 3; + + PUT_INTEL_INT(&out_buffer[loc], info->numpackets); loc += 4; + PUT_INTEL_INT(&out_buffer[loc], (int)info->obj_pos.x); loc += 4; + PUT_INTEL_INT(&out_buffer[loc], (int)info->obj_pos.y); loc += 4; + PUT_INTEL_INT(&out_buffer[loc], (int)info->obj_pos.z); loc += 4; - loc = 0; - memset(out_buffer, 0, MAX_DATA_SIZE); - if (short_packet == 1) { - loc = 0; - out_buffer[loc] = PID_SHORTPDATA; loc++; - out_buffer[loc] = Player_num; loc++; - out_buffer[loc] = pl_obj->render_type; loc++; - out_buffer[loc] = Current_level_num; loc++; - create_shortpos((shortpos *)(out_buffer + loc), pl_obj,1); - loc += 9+2*3+2+2*3; // go past shortpos structure - PUT_INTEL_SHORT(out_buffer + loc, MySyncPack.data_size); loc += 2; - memcpy(out_buffer + loc, MySyncPack.data, MySyncPack.data_size); - loc += MySyncPack.data_size; - } else if (short_packet == 2) { - loc = 0; - out_buffer[loc] = PID_PDATA_SHORT2; loc++; - out_buffer[loc] = MySyncPack.numpackets & 255; loc++; - create_shortpos((shortpos *)(out_buffer + loc), pl_obj,1); - loc += 9+2*3+2+2*3; // go past shortpos structure - tmpus = MySyncPack.data_size | (Player_num << 12) | (pl_obj->render_type << 15); - PUT_INTEL_SHORT(out_buffer + loc, tmpus); loc += 2; - out_buffer[loc] = Current_level_num; loc++; - memcpy(out_buffer + loc, MySyncPack.data, MySyncPack.data_size); - loc += MySyncPack.data_size; - } else { - out_buffer[0] = PID_PDATA; loc++; loc += 3; // skip three for pad byte - PUT_INTEL_INT(&(out_buffer[loc]), MySyncPack.numpackets); loc += 4; + PUT_INTEL_INT(&out_buffer[loc], (int)info->obj_orient.rvec.x); loc += 4; + PUT_INTEL_INT(&out_buffer[loc], (int)info->obj_orient.rvec.y); loc += 4; + PUT_INTEL_INT(&out_buffer[loc], (int)info->obj_orient.rvec.z); loc += 4; + PUT_INTEL_INT(&out_buffer[loc], (int)info->obj_orient.uvec.x); loc += 4; + PUT_INTEL_INT(&out_buffer[loc], (int)info->obj_orient.uvec.y); loc += 4; + PUT_INTEL_INT(&out_buffer[loc], (int)info->obj_orient.uvec.z); loc += 4; + PUT_INTEL_INT(&out_buffer[loc], (int)info->obj_orient.fvec.x); loc += 4; + PUT_INTEL_INT(&out_buffer[loc], (int)info->obj_orient.fvec.y); loc += 4; + PUT_INTEL_INT(&out_buffer[loc], (int)info->obj_orient.fvec.z); loc += 4; + + PUT_INTEL_INT(&out_buffer[loc], (int)info->phys_velocity.x); loc += 4; + PUT_INTEL_INT(&out_buffer[loc], (int)info->phys_velocity.y); loc += 4; + PUT_INTEL_INT(&out_buffer[loc], (int)info->phys_velocity.z); loc += 4; + + PUT_INTEL_INT(&out_buffer[loc], (int)info->phys_rotvel.x); loc += 4; + PUT_INTEL_INT(&out_buffer[loc], (int)info->phys_rotvel.y); loc += 4; + PUT_INTEL_INT(&out_buffer[loc], (int)info->phys_rotvel.z); loc += 4; + + PUT_INTEL_SHORT(&out_buffer[loc], info->obj_segnum); loc += 2; + PUT_INTEL_SHORT(&out_buffer[loc], info->data_size); loc += 2; + out_buffer[loc] = info->playernum; loc++; + out_buffer[loc] = info->obj_render_type; loc++; + out_buffer[loc] = info->level_num; loc++; + memcpy(&out_buffer[loc], info->data, info->data_size); loc += info->data_size; - PUT_INTEL_INT(&(out_buffer[loc]), (int)pl_obj->pos.x); loc += 4; - PUT_INTEL_INT(&(out_buffer[loc]), (int)pl_obj->pos.y); loc += 4; - PUT_INTEL_INT(&(out_buffer[loc]), (int)pl_obj->pos.z); loc += 4; - - PUT_INTEL_INT(&(out_buffer[loc]), (int)pl_obj->orient.rvec.x); loc += 4; - PUT_INTEL_INT(&(out_buffer[loc]), (int)pl_obj->orient.rvec.y); loc += 4; - PUT_INTEL_INT(&(out_buffer[loc]), (int)pl_obj->orient.rvec.z); loc += 4; - PUT_INTEL_INT(&(out_buffer[loc]), (int)pl_obj->orient.uvec.x); loc += 4; - PUT_INTEL_INT(&(out_buffer[loc]), (int)pl_obj->orient.uvec.y); loc += 4; - PUT_INTEL_INT(&(out_buffer[loc]), (int)pl_obj->orient.uvec.z); loc += 4; - PUT_INTEL_INT(&(out_buffer[loc]), (int)pl_obj->orient.fvec.x); loc += 4; - PUT_INTEL_INT(&(out_buffer[loc]), (int)pl_obj->orient.fvec.y); loc += 4; - PUT_INTEL_INT(&(out_buffer[loc]), (int)pl_obj->orient.fvec.z); loc += 4; - - PUT_INTEL_INT(&(out_buffer[loc]), (int)pl_obj->mtype.phys_info.velocity.x); loc += 4; - PUT_INTEL_INT(&(out_buffer[loc]), (int)pl_obj->mtype.phys_info.velocity.y); loc += 4; - PUT_INTEL_INT(&(out_buffer[loc]), (int)pl_obj->mtype.phys_info.velocity.z); loc += 4; - - PUT_INTEL_INT(&(out_buffer[loc]), (int)pl_obj->mtype.phys_info.rotvel.x); loc += 4; - PUT_INTEL_INT(&(out_buffer[loc]), (int)pl_obj->mtype.phys_info.rotvel.y); loc += 4; - PUT_INTEL_INT(&(out_buffer[loc]), (int)pl_obj->mtype.phys_info.rotvel.z); loc += 4; - - PUT_INTEL_SHORT(&(out_buffer[loc]), pl_obj->segnum); loc += 2; - PUT_INTEL_SHORT(&(out_buffer[loc]), MySyncPack.data_size); loc += 2; + // Always array passed + NetDrvSendPacketData(out_buffer, loc, server, node, net_address); +} - out_buffer[loc] = Player_num; loc++; - out_buffer[loc] = pl_obj->render_type; loc++; - out_buffer[loc] = Current_level_num; loc++; - memcpy(&(out_buffer[loc]), MySyncPack.data, MySyncPack.data_size); - loc += MySyncPack.data_size; - } -#if 0 // adb: not possible (always array passed) - if (address == NULL) - NetDrvSendInternetworkPacketData( out_buffer, loc, server, node ); - else +void receive_frameinfo_packet(ubyte *data, frame_info *info) +{ + int loc = 0; + + info->type = data[loc]; loc++; + /*3 bytes of padding */ loc += 3; + + info->numpackets = GET_INTEL_INT(&data[loc]); loc += 4; + info->obj_pos.x = GET_INTEL_INT(&data[loc]); loc += 4; + info->obj_pos.y = GET_INTEL_INT(&data[loc]); loc += 4; + info->obj_pos.z = GET_INTEL_INT(&data[loc]); loc += 4; + + info->obj_orient.rvec.x = GET_INTEL_INT(&data[loc]); loc += 4; + info->obj_orient.rvec.y = GET_INTEL_INT(&data[loc]); loc += 4; + info->obj_orient.rvec.z = GET_INTEL_INT(&data[loc]); loc += 4; + info->obj_orient.uvec.x = GET_INTEL_INT(&data[loc]); loc += 4; + info->obj_orient.uvec.y = GET_INTEL_INT(&data[loc]); loc += 4; + info->obj_orient.uvec.z = GET_INTEL_INT(&data[loc]); loc += 4; + info->obj_orient.fvec.x = GET_INTEL_INT(&data[loc]); loc += 4; + info->obj_orient.fvec.y = GET_INTEL_INT(&data[loc]); loc += 4; + info->obj_orient.fvec.z = GET_INTEL_INT(&data[loc]); loc += 4; + + info->phys_velocity.x = GET_INTEL_INT(&data[loc]); loc += 4; + info->phys_velocity.y = GET_INTEL_INT(&data[loc]); loc += 4; + info->phys_velocity.z = GET_INTEL_INT(&data[loc]); loc += 4; + + info->phys_rotvel.x = GET_INTEL_INT(&data[loc]); loc += 4; + info->phys_rotvel.y = GET_INTEL_INT(&data[loc]); loc += 4; + info->phys_rotvel.z = GET_INTEL_INT(&data[loc]); loc += 4; + + info->obj_segnum = GET_INTEL_SHORT(&data[loc]); loc += 2; + info->data_size = GET_INTEL_SHORT(&data[loc]); loc += 2; + info->playernum = data[loc]; loc++; + info->obj_render_type = data[loc]; loc++; + info->level_num = data[loc]; loc++; + memcpy(info->data, &data[loc], info->data_size); loc += info->data_size; +} #endif - NetDrvSendPacketData( out_buffer, loc, server, node, address); -} - -void receive_frameinfo_packet(ubyte *data, frame_info *info, int short_packet) -{ - int loc; - - if (short_packet == 1) { - loc = 0; - info->type = data[loc]; loc++; - info->playernum = data[loc]; loc++; - info->obj_render_type = data[loc]; loc++; - info->level_num = data[loc]; loc++; - loc += 9+2*3+2+2*3; // skip shortpos structure - info->data_size = GET_INTEL_SHORT(data + loc); loc+=2; - memcpy(info->data, &(data[loc]), info->data_size); - } else if (short_packet == 2) { - ushort tmpus; - - loc = 0; - info->type = data[loc]; loc++; - info->numpackets = data[loc]; loc++; - loc += 9+2*3+2+2*3; // skip shortpos structure - tmpus = GET_INTEL_SHORT(data + loc); loc+=2; - info->data_size = tmpus & 0xfff; - info->playernum = (tmpus >> 12) & 7; - info->obj_render_type = tmpus >> 15; - info->numpackets |= Players[info->playernum].n_packets_got & (~255); - if (info->numpackets - Players[info->playernum].n_packets_got > 224) - info->numpackets -= 256; - else if (Players[info->playernum].n_packets_got - info->numpackets > 128) - info->numpackets += 256; - info->level_num = data[loc]; loc++; - memcpy(info->data, &(data[loc]), info->data_size); - } else { - loc = 0; - info->type = data[loc]; loc++; loc += 3; // skip three for pad byte - info->numpackets = GET_INTEL_INT(&(data[loc])); loc += 4; - - info->obj_pos.x = GET_INTEL_INT(&(data[loc])); loc += 4; - info->obj_pos.y = GET_INTEL_INT(&(data[loc])); loc += 4; - info->obj_pos.z = GET_INTEL_INT(&(data[loc])); loc += 4; - - info->obj_orient.rvec.x = GET_INTEL_INT(&(data[loc])); loc += 4; - info->obj_orient.rvec.y = GET_INTEL_INT(&(data[loc])); loc += 4; - info->obj_orient.rvec.z = GET_INTEL_INT(&(data[loc])); loc += 4; - info->obj_orient.uvec.x = GET_INTEL_INT(&(data[loc])); loc += 4; - info->obj_orient.uvec.y = GET_INTEL_INT(&(data[loc])); loc += 4; - info->obj_orient.uvec.z = GET_INTEL_INT(&(data[loc])); loc += 4; - info->obj_orient.fvec.x = GET_INTEL_INT(&(data[loc])); loc += 4; - info->obj_orient.fvec.y = GET_INTEL_INT(&(data[loc])); loc += 4; - info->obj_orient.fvec.z = GET_INTEL_INT(&(data[loc])); loc += 4; - - info->phys_velocity.x = GET_INTEL_INT(&(data[loc])); loc += 4; - info->phys_velocity.y = GET_INTEL_INT(&(data[loc])); loc += 4; - info->phys_velocity.z = GET_INTEL_INT(&(data[loc])); loc += 4; - - info->phys_rotvel.x = GET_INTEL_INT(&(data[loc])); loc += 4; - info->phys_rotvel.y = GET_INTEL_INT(&(data[loc])); loc += 4; - info->phys_rotvel.z = GET_INTEL_INT(&(data[loc])); loc += 4; - - info->obj_segnum = GET_INTEL_SHORT(&(data[loc])); loc += 2; - info->data_size = GET_INTEL_SHORT(&(data[loc])); loc += 2; - - info->playernum = data[loc]; loc++; - info->obj_render_type = data[loc]; loc++; - info->level_num = data[loc]; loc++; - memcpy(info->data, &(data[loc]), info->data_size); - } -} void swap_object(object *obj) { diff --git a/main/netpkt.h b/main/netpkt.h index fc7e612f8..7f3f6bbfb 100644 --- a/main/netpkt.h +++ b/main/netpkt.h @@ -18,8 +18,17 @@ void send_sequence_packet(sequence_packet seq, ubyte *server, ubyte *node, ubyte void receive_sequence_packet(ubyte *data, sequence_packet *seq); void send_netgame_packet(ubyte *server, ubyte *node); void receive_netgame_packet(ubyte *data, netgame_info *netgame, int d1x); -void send_frameinfo_packet(ubyte *server, ubyte *node, ubyte *address, int short_packet); -void receive_frameinfo_packet(ubyte *data, frame_info *info, int short_packet); void swap_object(object *obj); +#ifdef WORDS_BIGENDIAN +void send_frameinfo_packet(frame_info *info, ubyte *server, ubyte *node, ubyte *net_address); +void receive_frameinfo_packet(ubyte *data, frame_info *info); +#else // !WORDS_BIGENDIAN +#define send_frameinfo_packet(info, server, node, net_address) \ + NetDrvSendPacketData((ubyte *)info, sizeof(frame_info) - NET_XDATA_SIZE + (info)->data_size, server, node, net_address) +#define receive_frameinfo_packet(data, info) \ + do { memcpy((ubyte *)(info), data, sizeof(frame_info) - NET_XDATA_SIZE); \ + memcpy((info)->data, &data[sizeof(frame_info) - NET_XDATA_SIZE], (info)->data_size); } while(0) +#endif // WORDS_BIGENDIAN + #endif diff --git a/main/network.c b/main/network.c index 2d9f218c5..04319df5a 100644 --- a/main/network.c +++ b/main/network.c @@ -71,7 +71,9 @@ void network_read_sync_packet( ubyte * sp, int d1x ); void network_flush(); void network_listen(); void network_ping(ubyte flag, int pnum); -void network_read_pdata_packet( ubyte *data, int short_pos ); +void network_process_pdata(char *data); +void network_read_pdata_packet(ubyte *data); +void network_read_pdata_short_packet(short_frame_info *pd); int network_compare_players(netplayer_info *pl1, netplayer_info *pl2); void DoRefuseStuff(sequence_packet *their); int show_game_stats(int choice); @@ -1382,18 +1384,11 @@ void network_process_packet(ubyte *data, int length ) if (Network_status == NETSTAT_WAITING) network_read_sync_packet(data, 0); break; - case PID_PDATA: - if ((Game_mode&GM_NETWORK) && ((Network_status == NETSTAT_PLAYING)||(Network_status == NETSTAT_ENDLEVEL) )) { - network_read_pdata_packet(data, 0); - } - break; -//added on 8/4/98 by Matt Mueller - case PID_SHORTPDATA: - if ((Game_mode&GM_NETWORK) && ((Network_status == NETSTAT_PLAYING)||(Network_status == NETSTAT_ENDLEVEL) )) { - network_read_pdata_packet(data, 1); - } - break; -//end modified section - Matt Mueller + case PID_PDATA: + if ((Game_mode&GM_NETWORK) && ((Network_status == NETSTAT_PLAYING)||(Network_status == NETSTAT_ENDLEVEL) || Network_status==NETSTAT_WAITING)) { + network_process_pdata((char *)data); + } + break; case PID_OBJECT_DATA: if (Network_status == NETSTAT_WAITING) network_read_object_packet(data); @@ -1426,10 +1421,6 @@ void network_process_packet(ubyte *data, int length ) if (Network_status == NETSTAT_WAITING) network_read_sync_packet(data, 1); break; - case PID_PDATA_SHORT2: - if ((Game_mode&GM_NETWORK) && ((Network_status == NETSTAT_PLAYING)||(Network_status == NETSTAT_ENDLEVEL) )) { - network_read_pdata_packet(data, 2); - }break; //added 03/04/99 Matt Mueller - new direct data packets.. case PID_DIRECTDATA: if ((Game_mode&GM_NETWORK) && ((Network_status == NETSTAT_PLAYING)||(Network_status == NETSTAT_ENDLEVEL) )) { @@ -3275,6 +3266,7 @@ fix last_timeout_check = 0; void network_do_frame(int force, int listen) { int i; + short_frame_info ShortSyncPack; if (!(Game_mode&GM_NETWORK)) return; @@ -3291,23 +3283,83 @@ void network_do_frame(int force, int listen) if ( (last_send_time > (F1_0 / Network_pps)) || (Network_laser_fired) || force || PacketUrgent ) { if ( Players[Player_num].connected ) { + int objnum = Players[Player_num].objnum; PacketUrgent = 0; if (listen) { #ifndef SHAREWARE multi_send_robot_frame(0); #endif - multi_send_fire(100); // Do firing if needed.. + multi_send_fire(100); // Do firing if needed.. } last_send_time = 0; - for (i=0; iplayernum; + TheirObjnum = Players[pd->playernum].objnum; + + if (TheirPlayernum < 0) { + Int3(); // This packet is bogus!! + return; + } + + if (!multi_quit_game && (TheirPlayernum >= N_players)) + { + if (Network_status!=NETSTAT_WAITING) + { + Int3(); // We missed an important packet! + network_consistency_error(); + return; + } + else + return; + } + + if (Endlevel_sequence || (Network_status == NETSTAT_ENDLEVEL) ) { + int old_Endlevel_sequence = Endlevel_sequence; + Endlevel_sequence = 1; + if ( pd->data_size>0 ) + { + // pass pd->data to some parser function.... + multi_process_bigdata( pd->data, pd->data_size ); + } + Endlevel_sequence = old_Endlevel_sequence; + return; + } + + if ((sbyte)pd->level_num != Current_level_num) + { + return; + } + + TheirObj = &Objects[TheirObjnum]; + + //------------- Keep track of missed packets ----------------- + Players[TheirPlayernum].n_packets_got++; + LastPacketTime[TheirPlayernum] = timer_get_approx_seconds(); + if ( pd->numpackets != Players[TheirPlayernum].n_packets_got ) { + missed_packets += pd->numpackets-Players[TheirPlayernum].n_packets_got; + + Players[TheirPlayernum].n_packets_got = pd->numpackets; + } + + //------------ Read the player's ship's object info ---------------------- + TheirObj->pos = pd->obj_pos; + TheirObj->orient = pd->obj_orient; + TheirObj->mtype.phys_info.velocity = pd->phys_velocity; + TheirObj->mtype.phys_info.rotvel = pd->phys_rotvel; + + if ((TheirObj->render_type != pd->obj_render_type) && (pd->obj_render_type == RT_POLYOBJ)) + multi_make_ghost_player(TheirPlayernum); + + obj_relink(TheirObjnum,pd->obj_segnum); + + if (TheirObj->movement_type == MT_PHYSICS) + set_thrust_from_velocity(TheirObj); + + //------------ Welcome them back if reconnecting -------------- + if (!Players[TheirPlayernum].connected) { + Players[TheirPlayernum].connected = 1; + + if (Newdemo_state == ND_STATE_RECORDING) + newdemo_record_multi_reconnect(TheirPlayernum); + + multi_make_ghost_player(TheirPlayernum); + + create_player_appearance_effect(&Objects[TheirObjnum]); + + digi_play_sample( SOUND_HUD_MESSAGE, F1_0); + + HUD_init_message( "'%s' %s", Players[TheirPlayernum].callsign, TXT_REJOIN ); + + multi_send_score(); + } + + //------------ Parse the extra data at the end --------------- + + if ( pd->data_size>0 ) { + // pass pd->data to some parser function.... + multi_process_bigdata( pd->data, pd->data_size ); + } + +} + +#ifdef WORDS_BIGENDIAN +void get_short_frame_info(ubyte *old_info, short_frame_info *new_info) +{ + int loc = 0; + + new_info->type = old_info[loc]; loc++; + /* skip three for pad byte */ loc += 3; + memcpy(&(new_info->numpackets), &(old_info[loc]), 4); loc += 4; + new_info->numpackets = INTEL_INT(new_info->numpackets); + memcpy(new_info->thepos.bytemat, &(old_info[loc]), 9); loc += 9; + memcpy(&(new_info->thepos.xo), &(old_info[loc]), 2); loc += 2; + memcpy(&(new_info->thepos.yo), &(old_info[loc]), 2); loc += 2; + memcpy(&(new_info->thepos.zo), &(old_info[loc]), 2); loc += 2; + memcpy(&(new_info->thepos.segment), &(old_info[loc]), 2); loc += 2; + memcpy(&(new_info->thepos.velx), &(old_info[loc]), 2); loc += 2; + memcpy(&(new_info->thepos.vely), &(old_info[loc]), 2); loc += 2; + memcpy(&(new_info->thepos.velz), &(old_info[loc]), 2); loc += 2; + new_info->thepos.xo = INTEL_SHORT(new_info->thepos.xo); + new_info->thepos.yo = INTEL_SHORT(new_info->thepos.yo); + new_info->thepos.zo = INTEL_SHORT(new_info->thepos.zo); + new_info->thepos.segment = INTEL_SHORT(new_info->thepos.segment); + new_info->thepos.velx = INTEL_SHORT(new_info->thepos.velx); + new_info->thepos.vely = INTEL_SHORT(new_info->thepos.vely); + new_info->thepos.velz = INTEL_SHORT(new_info->thepos.velz); + + memcpy(&(new_info->data_size), &(old_info[loc]), 2); loc += 2; + new_info->data_size = INTEL_SHORT(new_info->data_size); + new_info->playernum = old_info[loc]; loc++; + new_info->obj_render_type = old_info[loc]; loc++; + new_info->level_num = old_info[loc]; loc++; + memcpy(new_info->data, &(old_info[loc]), new_info->data_size); +} +#else +#define get_short_frame_info(old_info, new_info) \ + memcpy(new_info, old_info, sizeof(short_frame_info)) +#endif + +void network_read_pdata_short_packet(short_frame_info *pd ) +{ + int TheirPlayernum; + int TheirObjnum; + object * TheirObj = NULL; + short_frame_info new_pd; + +// short frame info is not aligned because of shortpos. The mac +// will call totally hacked and gross function to fix this up. + + get_short_frame_info((ubyte *)pd, &new_pd); + + TheirPlayernum = new_pd.playernum; + TheirObjnum = Players[new_pd.playernum].objnum; + + if (TheirPlayernum < 0) { + Int3(); // This packet is bogus!! + return; + } + if (!multi_quit_game && (TheirPlayernum >= N_players)) { + if (Network_status!=NETSTAT_WAITING) + { + Int3(); // We missed an important packet! + network_consistency_error(); + return; + } + else + return; + } + + if (Endlevel_sequence || (Network_status == NETSTAT_ENDLEVEL) ) { + int old_Endlevel_sequence = Endlevel_sequence; + Endlevel_sequence = 1; + if ( new_pd.data_size>0 ) { + // pass pd->data to some parser function.... + multi_process_bigdata( new_pd.data, new_pd.data_size ); + } + Endlevel_sequence = old_Endlevel_sequence; + return; + } + + if ((sbyte)new_pd.level_num != Current_level_num) + { + return; + } + + TheirObj = &Objects[TheirObjnum]; + + //------------- Keep track of missed packets ----------------- + Players[TheirPlayernum].n_packets_got++; + LastPacketTime[TheirPlayernum] = timer_get_approx_seconds(); + if ( pd->numpackets != Players[TheirPlayernum].n_packets_got ) { + missed_packets += pd->numpackets-Players[TheirPlayernum].n_packets_got; + + Players[TheirPlayernum].n_packets_got = pd->numpackets; + } + + //------------ Read the player's ship's object info ---------------------- + + extract_shortpos(TheirObj, &new_pd.thepos, 0); + + if ((TheirObj->render_type != new_pd.obj_render_type) && (new_pd.obj_render_type == RT_POLYOBJ)) + multi_make_ghost_player(TheirPlayernum); + + if (TheirObj->movement_type == MT_PHYSICS) + set_thrust_from_velocity(TheirObj); + + //------------ Welcome them back if reconnecting -------------- + if (!Players[TheirPlayernum].connected) { + Players[TheirPlayernum].connected = 1; + + if (Newdemo_state == ND_STATE_RECORDING) + newdemo_record_multi_reconnect(TheirPlayernum); + + multi_make_ghost_player(TheirPlayernum); + + create_player_appearance_effect(&Objects[TheirObjnum]); + + digi_play_sample( SOUND_HUD_MESSAGE, F1_0); + + HUD_init_message( "'%s' %s", Players[TheirPlayernum].callsign, TXT_REJOIN ); + + multi_send_score(); + } + + //------------ Parse the extra data at the end --------------- + + if ( new_pd.data_size>0 ) { + // pass pd->data to some parser function.... + multi_process_bigdata( new_pd.data, new_pd.data_size ); + } + +} + int network_who_is_master(void) { diff --git a/main/network.h b/main/network.h index 47b23155a..842a32026 100644 --- a/main/network.h +++ b/main/network.h @@ -86,6 +86,22 @@ typedef struct frame_info { } __pack__ frame_info; #endif +// short_frame_info is not aligned -- 01/18/96 -- MWA +// won't align because of shortpos. Shortpos needs +// to stay in current form. + +typedef struct short_frame_info { + ubyte type; // What type of packet + ubyte pad[3]; // Pad out length of frame_info packet + int numpackets; + shortpos thepos; + ushort data_size; // Size of data appended to the net packet + ubyte playernum; + ubyte obj_render_type; + ubyte level_num; + char data[NET_XDATA_SIZE]; // extra data to be tacked on the end +} __pack__ short_frame_info; + void network_start_game(); void network_join_game(); void network_rejoin_game(); @@ -187,13 +203,11 @@ void network_send_game_info(sequence_packet *their, int light); #define PID_GAME_INFO 37 #endif -#define PID_SHORTPDATA 48 #define PID_D1X_GAME_INFO_REQ 65 #define PID_D1X_GAME_INFO 66 #define PID_D1X_GAME_LITE_REQ 67 #define PID_D1X_GAME_LITE 68 #define PID_D1X_SYNC 69 -#define PID_PDATA_SHORT2 70 #define PID_D1X_REQUEST 71 //added 03/04/99 Matt Mueller - send multi data, without extra baggage #define PID_DIRECTDATA 72