diff options
Diffstat (limited to 'source/mvd_parse.c')
-rw-r--r-- | source/mvd_parse.c | 818 |
1 files changed, 423 insertions, 395 deletions
diff --git a/source/mvd_parse.c b/source/mvd_parse.c index a0f9070..2f6dd83 100644 --- a/source/mvd_parse.c +++ b/source/mvd_parse.c @@ -22,11 +22,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // mvd_parse.c // -#include "sv_local.h" #include "mvd_local.h" +#if USE_CLIENT + #define MVD_ShowSVC( cmd ) \ - Com_Printf( "%3"PRIz":%s\n", msg_read.readcount - 1, \ + Com_Printf( "%3"PRIz":%s\n", msg_read.readcount - 1, \ MVD_ServerCommandString( cmd ) ) static const char mvd_strings[mvd_num_types][20] = { @@ -38,14 +39,14 @@ static const char mvd_strings[mvd_num_types][20] = { "mvd_configstring", "mvd_frame", "mvd_frame_nodelta", - "mvd_unicast", + "mvd_unicast", "mvd_unicast_r", - "mvd_multicast_all", - "mvd_multicast_pvs", - "mvd_multicast_phs", - "mvd_multicast_all_r", - "mvd_multicast_pvs_r", - "mvd_multicast_phs_r", + "mvd_multicast_all", + "mvd_multicast_pvs", + "mvd_multicast_phs", + "mvd_multicast_all_r", + "mvd_multicast_pvs_r", + "mvd_multicast_phs_r", "mvd_sound", "mvd_print", "mvd_stufftext" @@ -59,214 +60,216 @@ static const char *MVD_ServerCommandString( int cmd ) { } else if( cmd >= 0 && cmd < mvd_num_types ) { s = mvd_strings[cmd]; } else { - s = "UNKNOWN COMMAND"; - } + s = "UNKNOWN COMMAND"; + } return s; } +#endif // USE_CLIENT + static void MVD_LinkEdict( mvd_t *mvd, edict_t *ent ) { - int index; - mmodel_t *cm; - int x, zd, zu; - bsp_t *cache = mvd->cm.cache; + int index; + mmodel_t *cm; + int x, zd, zu; + bsp_t *cache = mvd->cm.cache; - if( !cache ) { - return; - } + if( !cache ) { + return; + } - if( ent->s.solid == 31 ) { - index = ent->s.modelindex; - if( index < 1 || index > cache->nummodels ) { - Com_WPrintf( "%s: entity %d: bad inline model index: %d\n", - __func__, ent->s.number, index ); - return; - } - cm = &cache->models[ index - 1 ]; - VectorCopy( cm->mins, ent->mins ); - VectorCopy( cm->maxs, ent->maxs ); + if( ent->s.solid == 31 ) { + index = ent->s.modelindex; + if( index < 1 || index > cache->nummodels ) { + Com_WPrintf( "%s: entity %d: bad inline model index: %d\n", + __func__, ent->s.number, index ); + return; + } + cm = &cache->models[ index - 1 ]; + VectorCopy( cm->mins, ent->mins ); + VectorCopy( cm->maxs, ent->maxs ); ent->solid = SOLID_BSP; - } else if( ent->s.solid ) { - x = 8 * ( ent->s.solid & 31 ); - zd = 8 * ( ( ent->s.solid >> 5 ) & 31 ); - zu = 8 * ( ( ent->s.solid >> 10 ) & 63 ) - 32; - - ent->mins[0] = ent->mins[1] = -x; - ent->maxs[0] = ent->maxs[1] = x; - ent->mins[2] = -zd; - ent->maxs[2] = zu; + } else if( ent->s.solid ) { + x = 8 * ( ent->s.solid & 31 ); + zd = 8 * ( ( ent->s.solid >> 5 ) & 31 ); + zu = 8 * ( ( ent->s.solid >> 10 ) & 63 ) - 32; + + ent->mins[0] = ent->mins[1] = -x; + ent->maxs[0] = ent->maxs[1] = x; + ent->mins[2] = -zd; + ent->maxs[2] = zu; ent->solid = SOLID_BBOX; - } else { - VectorClear( ent->mins ); - VectorClear( ent->maxs ); + } else { + VectorClear( ent->mins ); + VectorClear( ent->maxs ); ent->solid = SOLID_NOT; - } + } SV_LinkEdict( &mvd->cm, ent ); } void MVD_ParseEntityString( mvd_t *mvd, const char *data ) { - const char *p; - char key[MAX_STRING_CHARS]; - char value[MAX_STRING_CHARS]; - char classname[MAX_QPATH]; - vec3_t origin; - vec3_t angles; - - while( data ) { - p = COM_Parse( &data ); - if( !p[0] ) { - break; - } - if( p[0] != '{' ) { - Com_Error( ERR_DROP, "expected '{', found '%s'", p ); - } - - classname[0] = 0; - VectorClear( origin ); - VectorClear( angles ); - while( 1 ) { - p = COM_Parse( &data ); - if( p[0] == '}' ) { - break; - } - if( p[0] == '{' ) { - Com_Error( ERR_DROP, "expected key, found '{'" ); - } - - Q_strlcpy( key, p, sizeof( key ) ); - - p = COM_Parse( &data ); - if( !data ) { - Com_Error( ERR_DROP, "expected key/value pair, found EOF" ); - } - if( p[0] == '}' || p[0] == '{' ) { - Com_Error( ERR_DROP, "expected value, found '%s'", p ); - } - - if( !strcmp( key, "classname" ) ) { - Q_strlcpy( classname, p, sizeof( classname ) ); - continue; - } - - Q_strlcpy( value, p, sizeof( value ) ); - - p = value; - if( !strcmp( key, "origin" ) ) { - origin[0] = atof( COM_Parse( &p ) ); - origin[1] = atof( COM_Parse( &p ) ); - origin[2] = atof( COM_Parse( &p ) ); - } else if( !strncmp( key, "angle", 5 ) ) { - if( key[5] == 0 ) { - angles[0] = 0; - angles[1] = atof( COM_Parse( &p ) ); - angles[2] = 0; - } else if( key[5] == 's' && key[6] == 0 ) { - angles[0] = atof( COM_Parse( &p ) ); - angles[1] = atof( COM_Parse( &p ) ); - angles[2] = atof( COM_Parse( &p ) ); - } - } - } - - if( !classname[0] ) { - Com_Error( ERR_DROP, "entity with no classname" ); - } - - if( strncmp( classname, "info_player_", 12 ) ) { - continue; - } - - if( !strcmp( classname + 12, "intermission" ) ) { - VectorCopy( origin, mvd->spawnOrigin ); - VectorCopy( angles, mvd->spawnAngles ); + const char *p; + char key[MAX_STRING_CHARS]; + char value[MAX_STRING_CHARS]; + char classname[MAX_QPATH]; + vec3_t origin; + vec3_t angles; + + while( data ) { + p = COM_Parse( &data ); + if( !p[0] ) { + break; + } + if( p[0] != '{' ) { + Com_Error( ERR_DROP, "expected '{', found '%s'", p ); + } + + classname[0] = 0; + VectorClear( origin ); + VectorClear( angles ); + while( 1 ) { + p = COM_Parse( &data ); + if( p[0] == '}' ) { + break; + } + if( p[0] == '{' ) { + Com_Error( ERR_DROP, "expected key, found '{'" ); + } + + Q_strlcpy( key, p, sizeof( key ) ); + + p = COM_Parse( &data ); + if( !data ) { + Com_Error( ERR_DROP, "expected key/value pair, found EOF" ); + } + if( p[0] == '}' || p[0] == '{' ) { + Com_Error( ERR_DROP, "expected value, found '%s'", p ); + } + + if( !strcmp( key, "classname" ) ) { + Q_strlcpy( classname, p, sizeof( classname ) ); + continue; + } + + Q_strlcpy( value, p, sizeof( value ) ); + + p = value; + if( !strcmp( key, "origin" ) ) { + origin[0] = atof( COM_Parse( &p ) ); + origin[1] = atof( COM_Parse( &p ) ); + origin[2] = atof( COM_Parse( &p ) ); + } else if( !strncmp( key, "angle", 5 ) ) { + if( key[5] == 0 ) { + angles[0] = 0; + angles[1] = atof( COM_Parse( &p ) ); + angles[2] = 0; + } else if( key[5] == 's' && key[6] == 0 ) { + angles[0] = atof( COM_Parse( &p ) ); + angles[1] = atof( COM_Parse( &p ) ); + angles[2] = atof( COM_Parse( &p ) ); + } + } + } + + if( !classname[0] ) { + Com_Error( ERR_DROP, "entity with no classname" ); + } + + if( strncmp( classname, "info_player_", 12 ) ) { + continue; + } + + if( !strcmp( classname + 12, "intermission" ) ) { + VectorCopy( origin, mvd->spawnOrigin ); + VectorCopy( angles, mvd->spawnAngles ); break; - } - - if( !strcmp( classname + 12, "start" ) || + } + + if( !strcmp( classname + 12, "start" ) || !strcmp( classname + 12, "deathmatch" ) ) { - VectorCopy( origin, mvd->spawnOrigin ); - VectorCopy( angles, mvd->spawnAngles ); - } + VectorCopy( origin, mvd->spawnOrigin ); + VectorCopy( angles, mvd->spawnAngles ); + } - } + } } static void MVD_ParseMulticast( mvd_t *mvd, mvd_ops_t op, int extrabits ) { - mvd_client_t *client; + mvd_client_t *client; client_t *cl; - byte mask[MAX_MAP_VIS]; - mleaf_t *leaf1, *leaf2; - vec3_t org; + byte mask[MAX_MAP_VIS]; + mleaf_t *leaf1, *leaf2; + vec3_t org; qboolean reliable = qfalse; - player_state_t *ps; + player_state_t *ps; byte *data; - int length, leafnum; + int length, leafnum; - length = MSG_ReadByte(); + length = MSG_ReadByte(); length |= extrabits << 8; - switch( op ) { - case mvd_multicast_all_r: - reliable = qtrue; + switch( op ) { + case mvd_multicast_all_r: + reliable = qtrue; // intentional fallthrough - case mvd_multicast_all: - leaf1 = NULL; - break; - case mvd_multicast_phs_r: - reliable = qtrue; + case mvd_multicast_all: + leaf1 = NULL; + break; + case mvd_multicast_phs_r: + reliable = qtrue; // intentional fallthrough - case mvd_multicast_phs: + case mvd_multicast_phs: leafnum = MSG_ReadShort(); - leaf1 = CM_LeafNum( &mvd->cm, leafnum ); - BSP_ClusterVis( mvd->cm.cache, mask, leaf1->cluster, DVIS_PHS ); - break; - case mvd_multicast_pvs_r: - reliable = qtrue; + leaf1 = CM_LeafNum( &mvd->cm, leafnum ); + BSP_ClusterVis( mvd->cm.cache, mask, leaf1->cluster, DVIS_PHS ); + break; + case mvd_multicast_pvs_r: + reliable = qtrue; // intentional fallthrough - case mvd_multicast_pvs: + case mvd_multicast_pvs: leafnum = MSG_ReadShort(); - leaf1 = CM_LeafNum( &mvd->cm, leafnum ); - BSP_ClusterVis( mvd->cm.cache, mask, leaf1->cluster, DVIS_PVS ); - break; - default: - MVD_Destroyf( mvd, "bad op" ); - } + leaf1 = CM_LeafNum( &mvd->cm, leafnum ); + BSP_ClusterVis( mvd->cm.cache, mask, leaf1->cluster, DVIS_PVS ); + break; + default: + MVD_Destroyf( mvd, "bad op" ); + } // skip data payload - data = msg_read.data + msg_read.readcount; - msg_read.readcount += length; - if( msg_read.readcount > msg_read.cursize ) { - MVD_Destroyf( mvd, "read past end of message" ); - } + data = msg_read.data + msg_read.readcount; + msg_read.readcount += length; + if( msg_read.readcount > msg_read.cursize ) { + MVD_Destroyf( mvd, "read past end of message" ); + } - // send the data to all relevent clients + // send the data to all relevent clients LIST_FOR_EACH( mvd_client_t, client, &mvd->clients, entry ) { cl = client->cl; if( cl->state < cs_primed ) { continue; } - // do not send unreliables to connecting clients - if( !reliable && ( cl->state != cs_spawned || cl->download || ( cl->flags & CF_NODATA ) ) ) { - continue; - } - - if( leaf1 ) { - // find the client's PVS - ps = &client->ps; - VectorMA( ps->viewoffset, 0.125f, ps->pmove.origin, org ); - leaf2 = CM_PointLeaf( &mvd->cm, org ); - if( !CM_AreasConnected( &mvd->cm, leaf1->area, leaf2->area ) ) - continue; - if( !Q_IsBitSet( mask, leaf2->cluster ) ) { - continue; - } - } - - cl->AddMessage( cl, data, length, reliable ); - } + // do not send unreliables to connecting clients + if( !reliable && ( cl->state != cs_spawned || cl->download || ( cl->flags & CF_NODATA ) ) ) { + continue; + } + + if( leaf1 ) { + // find the client's PVS + ps = &client->ps; + VectorMA( ps->viewoffset, 0.125f, ps->pmove.origin, org ); + leaf2 = CM_PointLeaf( &mvd->cm, org ); + if( !CM_AreasConnected( &mvd->cm, leaf1->area, leaf2->area ) ) + continue; + if( !Q_IsBitSet( mask, leaf2->cluster ) ) { + continue; + } + } + + cl->AddMessage( cl, data, length, reliable ); + } } static void MVD_UnicastSend( mvd_t *mvd, qboolean reliable, byte *data, size_t length, mvd_player_t *player ) { @@ -274,17 +277,17 @@ static void MVD_UnicastSend( mvd_t *mvd, qboolean reliable, byte *data, size_t l mvd_client_t *client; client_t *cl; - // send to all relevant clients + // send to all relevant clients LIST_FOR_EACH( mvd_client_t, client, &mvd->clients, entry ) { cl = client->cl; if( cl->state < cs_spawned ) { continue; } target = client->target ? client->target : mvd->dummy; - if( target == player ) { - cl->AddMessage( cl, data, length, reliable ); - } - } + if( target == player ) { + cl->AddMessage( cl, data, length, reliable ); + } + } } static void MVD_UnicastLayout( mvd_t *mvd, qboolean reliable, mvd_player_t *player ) { @@ -297,15 +300,15 @@ static void MVD_UnicastLayout( mvd_t *mvd, qboolean reliable, mvd_player_t *play MSG_ReadString( mvd->layout, sizeof( mvd->layout ) ); - // force an update to all relevant clients + // force an update to all relevant clients LIST_FOR_EACH( mvd_client_t, client, &mvd->clients, entry ) { if( client->cl->state < cs_spawned ) { continue; } - if( client->layout_type == LAYOUT_SCORES ) { + if( client->layout_type == LAYOUT_SCORES ) { client->layout_time = 0; - } - } + } + } } static void MVD_UnicastString( mvd_t *mvd, qboolean reliable, mvd_player_t *player ) { @@ -315,7 +318,7 @@ static void MVD_UnicastString( mvd_t *mvd, qboolean reliable, mvd_player_t *play byte *data; size_t readcount, length; - data = msg_read.data + msg_read.readcount - 1; + data = msg_read.data + msg_read.readcount - 1; readcount = msg_read.readcount - 1; index = MSG_ReadShort(); @@ -359,7 +362,7 @@ static void MVD_UnicastPrint( mvd_t *mvd, qboolean reliable, mvd_player_t *playe client_t *cl; mvd_player_t *target; - data = msg_read.data + msg_read.readcount - 1; + data = msg_read.data + msg_read.readcount - 1; readcount = msg_read.readcount - 1; level = MSG_ReadByte(); @@ -367,14 +370,14 @@ static void MVD_UnicastPrint( mvd_t *mvd, qboolean reliable, mvd_player_t *playe length = msg_read.readcount - readcount; - // send to all relevant clients + // send to all relevant clients LIST_FOR_EACH( mvd_client_t, client, &mvd->clients, entry ) { cl = client->cl; if( cl->state < cs_spawned ) { continue; } - if( level < cl->messagelevel ) { - continue; + if( level < cl->messagelevel ) { + continue; } if( level == PRINT_CHAT && ( client->uf & UF_MUTE_PLAYERS ) ) { continue; @@ -382,10 +385,10 @@ static void MVD_UnicastPrint( mvd_t *mvd, qboolean reliable, mvd_player_t *playe // decide if message should be routed or not target = ( mvd->flags & MVF_NOMSGS ) ? mvd->dummy : client->target ? client->target : mvd->dummy; - if( target == player ) { - cl->AddMessage( cl, data, length, reliable ); - } - } + if( target == player ) { + cl->AddMessage( cl, data, length, reliable ); + } + } } static void MVD_UnicastStuff( mvd_t *mvd, qboolean reliable, mvd_player_t *player ) { @@ -393,7 +396,7 @@ static void MVD_UnicastStuff( mvd_t *mvd, qboolean reliable, mvd_player_t *playe byte *data; size_t readcount, length; - data = msg_read.data + msg_read.readcount - 1; + data = msg_read.data + msg_read.readcount - 1; readcount = msg_read.readcount - 1; MSG_ReadString( string, sizeof( string ) ); @@ -412,64 +415,70 @@ Attempt to parse the datagram and find custom configstrings, layouts, etc. Give up as soon as unknown command byte is encountered. */ static void MVD_ParseUnicast( mvd_t *mvd, mvd_ops_t op, int extrabits ) { - int clientNum; - size_t length, last; - mvd_player_t *player; + int clientNum; + size_t length, last; + mvd_player_t *player; byte *data; qboolean reliable; - int cmd; + int cmd; - length = MSG_ReadByte(); + length = MSG_ReadByte(); length |= extrabits << 8; - clientNum = MSG_ReadByte(); + clientNum = MSG_ReadByte(); - if( clientNum < 0 || clientNum >= mvd->maxclients ) { - MVD_Destroyf( mvd, "%s: bad number: %d", __func__, clientNum ); - } + if( clientNum < 0 || clientNum >= mvd->maxclients ) { + MVD_Destroyf( mvd, "%s: bad number: %d", __func__, clientNum ); + } - last = msg_read.readcount + length; - if( last > msg_read.cursize ) { - MVD_Destroyf( mvd, "%s: read past end of message", __func__ ); - } + last = msg_read.readcount + length; + if( last > msg_read.cursize ) { + MVD_Destroyf( mvd, "%s: read past end of message", __func__ ); + } - player = &mvd->players[clientNum]; + player = &mvd->players[clientNum]; reliable = op == mvd_unicast_r ? qtrue : qfalse; - while( msg_read.readcount < last ) { + while( msg_read.readcount < last ) { cmd = MSG_ReadByte(); - if( mvd_shownet->integer > 1 ) { - MSG_ShowSVC( cmd ); - } - switch( cmd ) { - case svc_layout: +#if USE_CLIENT + if( mvd_shownet->integer > 1 ) { + MSG_ShowSVC( cmd ); + } +#endif + switch( cmd ) { + case svc_layout: MVD_UnicastLayout( mvd, reliable, player ); - break; - case svc_configstring: + break; + case svc_configstring: MVD_UnicastString( mvd, reliable, player ); - break; - case svc_print: + break; + case svc_print: MVD_UnicastPrint( mvd, reliable, player ); - break; - case svc_stufftext: + break; + case svc_stufftext: MVD_UnicastStuff( mvd, reliable, player ); - break; - default: + break; + default: +#if USE_CLIENT if( mvd_shownet->integer > 1 ) { Com_Printf( "%"PRIz":SKIPPING UNICAST\n", msg_read.readcount - 1 ); } - // send remaining data and return +#endif + // send remaining data and return data = msg_read.data + msg_read.readcount - 1; length = last - msg_read.readcount + 1; MVD_UnicastSend( mvd, reliable, data, length, player ); - msg_read.readcount = last; - return; - } - } + msg_read.readcount = last; + return; + } + } - if( mvd_shownet->integer > 1 ) { - Com_Printf( "%"PRIz":END OF UNICAST\n", msg_read.readcount - 1 ); - } +#if USE_CLIENT + if( mvd_shownet->integer > 1 ) { + Com_Printf( "%"PRIz":END OF UNICAST\n", msg_read.readcount - 1 ); + } +#endif if( msg_read.readcount > last ) { MVD_Destroyf( mvd, "%s: read past end of unicast", __func__ ); @@ -486,36 +495,36 @@ are able to postition sounds on BSP models properly. FIXME: this duplicates code in sv_game.c */ static void MVD_ParseSound( mvd_t *mvd, int extrabits ) { - int flags, index; - int volume, attenuation, offset, sendchan; - int entnum; - vec3_t origin; - mvd_client_t *client; - client_t *cl; - byte mask[MAX_MAP_VIS]; - mleaf_t *leaf; - int area; - player_state_t *ps; - message_packet_t *msg; + int flags, index; + int volume, attenuation, offset, sendchan; + int entnum; + vec3_t origin; + mvd_client_t *client; + client_t *cl; + byte mask[MAX_MAP_VIS]; + mleaf_t *leaf; + int area; + player_state_t *ps; + message_packet_t *msg; edict_t *entity; int i; - flags = MSG_ReadByte(); - index = MSG_ReadByte(); + flags = MSG_ReadByte(); + index = MSG_ReadByte(); volume = attenuation = offset = 0; if( flags & SND_VOLUME ) - volume = MSG_ReadByte(); + volume = MSG_ReadByte(); if( flags & SND_ATTENUATION ) - attenuation = MSG_ReadByte(); + attenuation = MSG_ReadByte(); if( flags & SND_OFFSET ) - offset = MSG_ReadByte(); + offset = MSG_ReadByte(); - // entity relative - sendchan = MSG_ReadShort(); + // entity relative + sendchan = MSG_ReadShort(); entnum = sendchan >> 3; if( entnum < 0 || entnum >= MAX_EDICTS ) { - MVD_Destroyf( mvd, "%s: bad entnum: %d", __func__, entnum ); + MVD_Destroyf( mvd, "%s: bad entnum: %d", __func__, entnum ); } entity = &mvd->edicts[entnum]; @@ -527,10 +536,10 @@ static void MVD_ParseSound( mvd_t *mvd, int extrabits ) { LIST_FOR_EACH( mvd_client_t, client, &mvd->clients, entry ) { cl = client->cl; - // do not send unreliables to connecting clients - if( cl->state != cs_spawned || cl->download || ( cl->flags & CF_NODATA ) ) { - continue; - } + // do not send unreliables to connecting clients + if( cl->state != cs_spawned || cl->download || ( cl->flags & CF_NODATA ) ) { + continue; + } // PHS cull this sound if( !( extrabits & 1 ) ) { @@ -543,10 +552,10 @@ static void MVD_ParseSound( mvd_t *mvd, int extrabits ) { // doors can legally straddle two areas, so // we may need to check another one if( !entity->areanum2 || !CM_AreasConnected( &mvd->cm, area, entity->areanum2 ) ) { - continue; // blocked by a door + continue; // blocked by a door } } - BSP_ClusterVis( mvd->cm.cache, mask, leaf->cluster, DVIS_PHS ); + BSP_ClusterVis( mvd->cm.cache, mask, leaf->cluster, DVIS_PHS ); if( !SV_EdictPV( &mvd->cm, entity, mask ) ) { continue; // not in PHS } @@ -608,7 +617,7 @@ static void MVD_ParseSound( mvd_t *mvd, int extrabits ) { List_Remove( &msg->entry ); List_Append( &cl->msg_used[0], &msg->entry ); cl->msg_bytes += MAX_SOUND_PACKET; - } + } } void MVD_FreePlayer( mvd_player_t *player ) { @@ -631,27 +640,27 @@ static void set_player_name( mvd_player_t *player, const char *string ) { } static void MVD_ParseConfigstring( mvd_t *mvd ) { - int index; - size_t len, maxlen; - char *string; - mvd_client_t *client; + int index; + size_t len, maxlen; + char *string; + mvd_client_t *client; mvd_player_t *player; mvd_cs_t *cs, **pcs; int i; - index = MSG_ReadShort(); - if( index < 0 || index >= MAX_CONFIGSTRINGS ) { - MVD_Destroyf( mvd, "%s: bad index: %d", __func__, index ); - } + index = MSG_ReadShort(); + if( index < 0 || index >= MAX_CONFIGSTRINGS ) { + MVD_Destroyf( mvd, "%s: bad index: %d", __func__, index ); + } string = mvd->configstrings[index]; maxlen = CS_SIZE( index ); len = MSG_ReadString( string, maxlen ); if( len >= maxlen ) { - MVD_Destroyf( mvd, "%s: index %d overflowed", __func__, index ); + MVD_Destroyf( mvd, "%s: index %d overflowed", __func__, index ); } - if( index >= CS_PLAYERSKINS && index < CS_PLAYERSKINS + mvd->maxclients ) { + if( index >= CS_PLAYERSKINS && index < CS_PLAYERSKINS + mvd->maxclients ) { // update player name player = &mvd->players[ index - CS_PLAYERSKINS ]; set_player_name( player, string ); @@ -680,19 +689,19 @@ static void MVD_ParseConfigstring( mvd_t *mvd ) { } } - MSG_WriteByte( svc_configstring ); - MSG_WriteShort( index ); - MSG_WriteData( string, len + 1 ); - + MSG_WriteByte( svc_configstring ); + MSG_WriteShort( index ); + MSG_WriteData( string, len + 1 ); + // broadcast configstring change LIST_FOR_EACH( mvd_client_t, client, &mvd->clients, entry ) { if( client->cl->state < cs_primed ) { continue; } - SV_ClientAddMessage( client->cl, MSG_RELIABLE ); - } + SV_ClientAddMessage( client->cl, MSG_RELIABLE ); + } - SZ_Clear( &msg_write ); + SZ_Clear( &msg_write ); } static void MVD_ParsePrint( mvd_t *mvd ) { @@ -713,7 +722,7 @@ extracting data from player state. static void MVD_PlayerToEntityStates( mvd_t *mvd ) { mvd_player_t *player; edict_t *edict; - int i; + int i; mvd->numplayers = 0; for( i = 1, player = mvd->players; i <= mvd->maxclients; i++, player++ ) { @@ -732,7 +741,7 @@ static void MVD_PlayerToEntityStates( mvd_t *mvd ) { continue; // not present in this frame } - VectorCopy( edict->s.origin, edict->s.old_origin ); + VectorCopy( edict->s.origin, edict->s.old_origin ); VectorScale( player->ps.pmove.origin, 0.125f, edict->s.origin ); VectorCopy( player->ps.viewangles, edict->s.angles ); @@ -747,8 +756,7 @@ static void MVD_PlayerToEntityStates( mvd_t *mvd ) { } } -#define RELINK_MASK (U_MODEL|U_ORIGIN1|U_ORIGIN2|U_ORIGIN3|U_SOLID) - +#define RELINK_MASK (U_MODEL|U_ORIGIN1|U_ORIGIN2|U_ORIGIN3|U_SOLID) /* ================== @@ -756,32 +764,34 @@ MVD_ParsePacketEntities ================== */ static void MVD_ParsePacketEntities( mvd_t *mvd ) { - int number; - int bits; - edict_t *ent; + int number; + int bits; + edict_t *ent; - while( 1 ) { - if( msg_read.readcount > msg_read.cursize ) { - MVD_Destroyf( mvd, "%s: read past end of message", __func__ ); - } + while( 1 ) { + if( msg_read.readcount > msg_read.cursize ) { + MVD_Destroyf( mvd, "%s: read past end of message", __func__ ); + } - number = MSG_ParseEntityBits( &bits ); - if( number < 0 || number >= MAX_EDICTS ) { - MVD_Destroyf( mvd, "%s: bad number: %d", __func__, number ); - } + number = MSG_ParseEntityBits( &bits ); + if( number < 0 || number >= MAX_EDICTS ) { + MVD_Destroyf( mvd, "%s: bad number: %d", __func__, number ); + } - if( !number ) { - break; - } + if( !number ) { + break; + } ent = &mvd->edicts[number]; +#if USE_CLIENT if( mvd_shownet->integer > 2 ) { - Com_Printf( " %s: %d ", ent->inuse ? + Com_Printf( " %s: %d ", ent->inuse ? "delta" : "baseline", number ); MSG_ShowDeltaEntityBits( bits ); Com_Printf( "\n" ); } +#endif MSG_ParseDeltaEntity( &ent->s, &ent->s, number, bits ); @@ -790,19 +800,21 @@ static void MVD_ParsePacketEntities( mvd_t *mvd ) { MVD_LinkEdict( mvd, ent ); } - if( bits & U_REMOVE ) { - if( mvd_shownet->integer > 2 ) { - Com_Printf( " remove: %d\n", number ); - } + if( bits & U_REMOVE ) { +#if USE_CLIENT + if( mvd_shownet->integer > 2 ) { + Com_Printf( " remove: %d\n", number ); + } +#endif ent->inuse = qfalse; - continue; - } + continue; + } ent->inuse = qtrue; if( number >= mvd->pool.num_edicts ) { mvd->pool.num_edicts = number + 1; } - } + } } /* @@ -811,44 +823,48 @@ MVD_ParsePacketPlayers ================== */ static void MVD_ParsePacketPlayers( mvd_t *mvd ) { - int number; - int bits; + int number; + int bits; mvd_player_t *player; - while( 1 ) { - if( msg_read.readcount > msg_read.cursize ) { - MVD_Destroyf( mvd, "%s: read past end of message", __func__ ); - } + while( 1 ) { + if( msg_read.readcount > msg_read.cursize ) { + MVD_Destroyf( mvd, "%s: read past end of message", __func__ ); + } - number = MSG_ReadByte(); - if( number == CLIENTNUM_NONE ) { - break; - } + number = MSG_ReadByte(); + if( number == CLIENTNUM_NONE ) { + break; + } - if( number < 0 || number >= mvd->maxclients ) { - MVD_Destroyf( mvd, "%s: bad number: %d", __func__, number ); - } + if( number < 0 || number >= mvd->maxclients ) { + MVD_Destroyf( mvd, "%s: bad number: %d", __func__, number ); + } player = &mvd->players[number]; - bits = MSG_ReadShort(); + bits = MSG_ReadShort(); +#if USE_CLIENT if( mvd_shownet->integer > 2 ) { - Com_Printf( " %s: %d ", player->inuse ? + Com_Printf( " %s: %d ", player->inuse ? "delta" : "baseline", number ); MSG_ShowDeltaPlayerstateBits_Packet( bits ); Com_Printf( "\n" ); } +#endif MSG_ParseDeltaPlayerstate_Packet( &player->ps, &player->ps, bits ); - if( bits & PPS_REMOVE ) { - if( mvd_shownet->integer > 2 ) { - Com_Printf( " remove: %d\n", number ); - } + if( bits & PPS_REMOVE ) { +#if USE_CLIENT + if( mvd_shownet->integer > 2 ) { + Com_Printf( " remove: %d\n", number ); + } +#endif player->inuse = qfalse; - continue; - } + continue; + } player->inuse = qtrue; } @@ -860,41 +876,47 @@ MVD_ParseFrame ================ */ static void MVD_ParseFrame( mvd_t *mvd ) { - int length; + int length; - // read portalbits - length = MSG_ReadByte(); - if( length ) { - if( length < 0 || msg_read.readcount + length > msg_read.cursize ) { + // read portalbits + length = MSG_ReadByte(); + if( length ) { + if( length < 0 || msg_read.readcount + length > msg_read.cursize ) { MVD_Destroyf( mvd, "%s: read past end of message", __func__ ); - } - if( length > MAX_MAP_AREAS/8 ) { + } + if( length > MAX_MAP_AREAS/8 ) { MVD_Destroyf( mvd, "%s: bad portalbits length: %d", __func__, length ); - } + } CM_SetPortalStates( &mvd->cm, msg_read.data + msg_read.readcount, length ); msg_read.readcount += length; - } else { + } else { CM_SetPortalStates( &mvd->cm, NULL, 0 ); - } + } - if( mvd_shownet->integer > 1 ) { - Com_Printf( "%3"PRIz":playerinfo\n", msg_read.readcount - 1 ); - } +#if USE_CLIENT + if( mvd_shownet->integer > 1 ) { + Com_Printf( "%3"PRIz":playerinfo\n", msg_read.readcount - 1 ); + } +#endif - MVD_ParsePacketPlayers( mvd ); + MVD_ParsePacketPlayers( mvd ); - if( mvd_shownet->integer > 1 ) { - Com_Printf( "%3"PRIz":packetentities\n", msg_read.readcount - 1 ); - } +#if USE_CLIENT + if( mvd_shownet->integer > 1 ) { + Com_Printf( "%3"PRIz":packetentities\n", msg_read.readcount - 1 ); + } +#endif - MVD_ParsePacketEntities( mvd ); + MVD_ParsePacketEntities( mvd ); - if( mvd_shownet->integer > 1 ) { - Com_Printf( "%3"PRIz":frame:%u\n", msg_read.readcount - 1, mvd->framenum ); - } +#if USE_CLIENT + if( mvd_shownet->integer > 1 ) { + Com_Printf( "%3"PRIz":frame:%u\n", msg_read.readcount - 1, mvd->framenum ); + } +#endif - MVD_PlayerToEntityStates( mvd ); + MVD_PlayerToEntityStates( mvd ); mvd->framenum++; } @@ -962,18 +984,18 @@ static void MVD_ChangeLevel( mvd_t *mvd ) { } static void MVD_ParseServerData( mvd_t *mvd, int extrabits ) { - int protocol; + int protocol; size_t len, maxlen; - char *string; + char *string; int i, index; mvd_player_t *player; // clear the leftover from previous level MVD_ClearState( mvd ); - // parse major protocol version - protocol = MSG_ReadLong(); - if( protocol != PROTOCOL_VERSION_MVD ) { + // parse major protocol version + protocol = MSG_ReadLong(); + if( protocol != PROTOCOL_VERSION_MVD ) { MVD_Destroyf( mvd, "Unsupported protocol: %d", protocol ); } @@ -984,7 +1006,7 @@ static void MVD_ParseServerData( mvd_t *mvd, int extrabits ) { "Current version is %d.\n", protocol, PROTOCOL_VERSION_MVD_CURRENT ); } - mvd->servercount = MSG_ReadLong(); + mvd->servercount = MSG_ReadLong(); len = MSG_ReadString( mvd->gamedir, sizeof( mvd->gamedir ) ); if( len >= sizeof( mvd->gamedir ) ) { MVD_Destroyf( mvd, "Oversize gamedir string" ); @@ -993,7 +1015,7 @@ static void MVD_ParseServerData( mvd_t *mvd, int extrabits ) { mvd->flags = extrabits; #if 0 - // change gamedir unless playing a demo + // change gamedir unless playing a demo Cvar_UserSet( "game", mvd->gamedir ); if( FS_NeedRestart() ) { FS_Restart(); @@ -1061,7 +1083,7 @@ static void MVD_ParseServerData( mvd_t *mvd, int extrabits ) { memcpy( mvd->mapname, string + 5, len - 9 ); // skip "maps/" mvd->mapname[len - 9] = 0; // cut off ".bsp" - // load the world model (we are only interesed in visibility info) + // load the world model (we are only interesed in visibility info) Com_Printf( "[%s] -=- Loading %s...\n", mvd->name, string ); if( !CM_LoadMap( &mvd->cm, string ) ) { MVD_Destroyf( mvd, "Couldn't load %s: %s", string, BSP_GetError() ); @@ -1108,70 +1130,76 @@ static void MVD_ParseServerData( mvd_t *mvd, int extrabits ) { } void MVD_ParseMessage( mvd_t *mvd ) { - int cmd, extrabits; + int cmd, extrabits; - if( mvd_shownet->integer == 1 ) { - Com_Printf( "%"PRIz" ", msg_read.cursize ); - } else if( mvd_shownet->integer > 1 ) { - Com_Printf( "------------------\n" ); - } +#if USE_CLIENT + if( mvd_shownet->integer == 1 ) { + Com_Printf( "%"PRIz" ", msg_read.cursize ); + } else if( mvd_shownet->integer > 1 ) { + Com_Printf( "------------------\n" ); + } +#endif // // parse the message // - while( 1 ) { - if( msg_read.readcount > msg_read.cursize ) { + while( 1 ) { + if( msg_read.readcount > msg_read.cursize ) { MVD_Destroyf( mvd, "Read past end of message" ); - } - if( msg_read.readcount == msg_read.cursize ) { - if( mvd_shownet->integer > 1 ) { - Com_Printf( "%3"PRIz":END OF MESSAGE\n", msg_read.readcount - 1 ); - } - break; - } - - cmd = MSG_ReadByte(); + } + if( msg_read.readcount == msg_read.cursize ) { +#if USE_CLIENT + if( mvd_shownet->integer > 1 ) { + Com_Printf( "%3"PRIz":END OF MESSAGE\n", msg_read.readcount - 1 ); + } +#endif + break; + } + + cmd = MSG_ReadByte(); extrabits = cmd >> SVCMD_BITS; cmd &= SVCMD_MASK; - if( mvd_shownet->integer > 1 ) { - MVD_ShowSVC( cmd ); - } +#if USE_CLIENT + if( mvd_shownet->integer > 1 ) { + MVD_ShowSVC( cmd ); + } +#endif - switch( cmd ) { - case mvd_serverdata: - MVD_ParseServerData( mvd, extrabits ); - break; - case mvd_multicast_all: - case mvd_multicast_pvs: + switch( cmd ) { + case mvd_serverdata: + MVD_ParseServerData( mvd, extrabits ); + break; + case mvd_multicast_all: + case mvd_multicast_pvs: case mvd_multicast_phs: - case mvd_multicast_all_r: + case mvd_multicast_all_r: case mvd_multicast_pvs_r: case mvd_multicast_phs_r: - MVD_ParseMulticast( mvd, cmd, extrabits ); - break; - case mvd_unicast: - case mvd_unicast_r: - MVD_ParseUnicast( mvd, cmd, extrabits ); - break; - case mvd_configstring: - MVD_ParseConfigstring( mvd ); - break; - case mvd_frame: - MVD_ParseFrame( mvd ); - break; - case mvd_sound: - MVD_ParseSound( mvd, extrabits ); - break; + MVD_ParseMulticast( mvd, cmd, extrabits ); + break; + case mvd_unicast: + case mvd_unicast_r: + MVD_ParseUnicast( mvd, cmd, extrabits ); + break; + case mvd_configstring: + MVD_ParseConfigstring( mvd ); + break; + case mvd_frame: + MVD_ParseFrame( mvd ); + break; + case mvd_sound: + MVD_ParseSound( mvd, extrabits ); + break; case mvd_print: MVD_ParsePrint( mvd ); break; case mvd_nop: break; - default: + default: MVD_Destroyf( mvd, "Illegible command at %"PRIz": %d", msg_read.readcount - 1, cmd ); - } - } + } + } } |