engine: client: simplify server message parsing by moving common code out of protocol-specific parsing funcs
This commit is contained in:
parent
33a1416199
commit
3717e5c2e0
5 changed files with 67 additions and 105 deletions
|
@ -2303,6 +2303,32 @@ static int CL_GetMessage( byte *data, size_t *length )
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void CL_ParseNetMessage( sizebuf_t *msg, void (*parsefn)( sizebuf_t * ))
|
||||||
|
{
|
||||||
|
cls.starting_count = MSG_GetNumBytesRead( msg ); // updates each frame
|
||||||
|
CL_Parse_Debug( true ); // begin parsing
|
||||||
|
|
||||||
|
parsefn( msg );
|
||||||
|
|
||||||
|
cl.frames[cl.parsecountmod].graphdata.msgbytes += MSG_GetNumBytesRead( msg ) - cls.starting_count;
|
||||||
|
CL_Parse_Debug( false ); // done
|
||||||
|
|
||||||
|
// we don't know if it is ok to save a demo message until
|
||||||
|
// after we have parsed the frame
|
||||||
|
if( !cls.demoplayback )
|
||||||
|
{
|
||||||
|
if( cls.demorecording && !cls.demowaiting )
|
||||||
|
{
|
||||||
|
CL_WriteDemoMessage( false, cls.starting_count, msg );
|
||||||
|
}
|
||||||
|
else if( cls.state != ca_active )
|
||||||
|
{
|
||||||
|
CL_WriteDemoMessage( true, cls.starting_count, msg );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
=================
|
=================
|
||||||
CL_ReadNetMessage
|
CL_ReadNetMessage
|
||||||
|
@ -2311,11 +2337,29 @@ CL_ReadNetMessage
|
||||||
static void CL_ReadNetMessage( void )
|
static void CL_ReadNetMessage( void )
|
||||||
{
|
{
|
||||||
size_t curSize;
|
size_t curSize;
|
||||||
|
void (*parsefn)( sizebuf_t *msg );
|
||||||
|
|
||||||
|
switch( cls.legacymode )
|
||||||
|
{
|
||||||
|
case PROTO_CURRENT:
|
||||||
|
parsefn = CL_ParseServerMessage;
|
||||||
|
break;
|
||||||
|
case PROTO_LEGACY:
|
||||||
|
parsefn = CL_ParseLegacyServerMessage;
|
||||||
|
break;
|
||||||
|
case PROTO_QUAKE:
|
||||||
|
parsefn = CL_ParseQuakeMessage;
|
||||||
|
break;
|
||||||
|
case PROTO_GOLDSRC:
|
||||||
|
default:
|
||||||
|
ASSERT( 0 );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
while( CL_GetMessage( net_message_buffer, &curSize ))
|
while( CL_GetMessage( net_message_buffer, &curSize ))
|
||||||
{
|
{
|
||||||
const int split_header = LittleLong( 0xFFFFFFFE );
|
const int split_header = LittleLong( 0xFFFFFFFE );
|
||||||
if( cls.legacymode && !memcmp( &split_header, net_message_buffer, sizeof( split_header )))
|
if( cls.legacymode == PROTO_LEGACY && !memcmp( &split_header, net_message_buffer, sizeof( split_header )))
|
||||||
{
|
{
|
||||||
// Will rewrite existing packet by merged
|
// Will rewrite existing packet by merged
|
||||||
if( !NetSplit_GetLong( &cls.netchan.netsplit, &net_from, net_message_buffer, &curSize ) )
|
if( !NetSplit_GetLong( &cls.netchan.netsplit, &net_from, net_message_buffer, &curSize ) )
|
||||||
|
@ -2350,11 +2394,17 @@ static void CL_ReadNetMessage( void )
|
||||||
if( !cls.demoplayback && !Netchan_Process( &cls.netchan, &net_message ))
|
if( !cls.demoplayback && !Netchan_Process( &cls.netchan, &net_message ))
|
||||||
continue; // wasn't accepted for some reason
|
continue; // wasn't accepted for some reason
|
||||||
|
|
||||||
// run special handler for quake demos
|
if( cls.state == ca_active )
|
||||||
if( cls.demoplayback == DEMO_QUAKE1 )
|
{
|
||||||
CL_ParseQuakeMessage( &net_message, true );
|
cl.frames[cls.netchan.incoming_sequence & CL_UPDATE_MASK].valid = false;
|
||||||
else if( cls.legacymode ) CL_ParseLegacyServerMessage( &net_message, true );
|
cl.frames[cls.netchan.incoming_sequence & CL_UPDATE_MASK].choked = false;
|
||||||
else CL_ParseServerMessage( &net_message, true );
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CL_ResetFrame( &cl.frames[cls.netchan.incoming_sequence & CL_UPDATE_MASK] );
|
||||||
|
}
|
||||||
|
|
||||||
|
CL_ParseNetMessage( &net_message, parsefn );
|
||||||
cl.send_reply = true;
|
cl.send_reply = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2368,7 +2418,7 @@ static void CL_ReadNetMessage( void )
|
||||||
if( Netchan_CopyNormalFragments( &cls.netchan, &net_message, &curSize ))
|
if( Netchan_CopyNormalFragments( &cls.netchan, &net_message, &curSize ))
|
||||||
{
|
{
|
||||||
MSG_Init( &net_message, "ServerData", net_message_buffer, curSize );
|
MSG_Init( &net_message, "ServerData", net_message_buffer, curSize );
|
||||||
CL_ParseServerMessage( &net_message, false );
|
CL_ParseNetMessage( &net_message, parsefn );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( Netchan_CopyFileFragments( &cls.netchan, &net_message ))
|
if( Netchan_CopyFileFragments( &cls.netchan, &net_message ))
|
||||||
|
|
|
@ -188,7 +188,7 @@ void CL_ParseServerTime( sizebuf_t *msg )
|
||||||
cl.mtime[1] = cl.mtime[0];
|
cl.mtime[1] = cl.mtime[0];
|
||||||
cl.mtime[0] = MSG_ReadFloat( msg );
|
cl.mtime[0] = MSG_ReadFloat( msg );
|
||||||
|
|
||||||
if( cls.demoplayback == DEMO_QUAKE1 )
|
if( cls.legacymode == PROTO_QUAKE )
|
||||||
return; // don't mess the time
|
return; // don't mess the time
|
||||||
|
|
||||||
if( cl.maxclients == 1 )
|
if( cl.maxclients == 1 )
|
||||||
|
@ -2219,36 +2219,19 @@ CL_ParseServerMessage
|
||||||
dispatch messages
|
dispatch messages
|
||||||
=====================
|
=====================
|
||||||
*/
|
*/
|
||||||
void CL_ParseServerMessage( sizebuf_t *msg, qboolean normal_message )
|
void CL_ParseServerMessage( sizebuf_t *msg )
|
||||||
{
|
{
|
||||||
size_t bufStart, playerbytes;
|
size_t bufStart, playerbytes;
|
||||||
int cmd, param1, param2;
|
int cmd, param1, param2;
|
||||||
int old_background;
|
int old_background;
|
||||||
const char *s;
|
const char *s;
|
||||||
|
|
||||||
cls.starting_count = MSG_GetNumBytesRead( msg ); // updates each frame
|
|
||||||
CL_Parse_Debug( true ); // begin parsing
|
|
||||||
|
|
||||||
if( normal_message )
|
|
||||||
{
|
|
||||||
// assume no entity/player update this packet
|
|
||||||
if( cls.state == ca_active )
|
|
||||||
{
|
|
||||||
cl.frames[cls.netchan.incoming_sequence & CL_UPDATE_MASK].valid = false;
|
|
||||||
cl.frames[cls.netchan.incoming_sequence & CL_UPDATE_MASK].choked = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
CL_ResetFrame( &cl.frames[cls.netchan.incoming_sequence & CL_UPDATE_MASK] );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// parse the message
|
// parse the message
|
||||||
while( 1 )
|
while( 1 )
|
||||||
{
|
{
|
||||||
if( MSG_CheckOverflow( msg ))
|
if( MSG_CheckOverflow( msg ))
|
||||||
{
|
{
|
||||||
Host_Error( "CL_ParseServerMessage: overflow!\n" );
|
Host_Error( "%s: overflow!\n", __func__ );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2507,21 +2490,4 @@ void CL_ParseServerMessage( sizebuf_t *msg, qboolean normal_message )
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cl.frames[cl.parsecountmod].graphdata.msgbytes += MSG_GetNumBytesRead( msg ) - cls.starting_count;
|
|
||||||
CL_Parse_Debug( false ); // done
|
|
||||||
|
|
||||||
// we don't know if it is ok to save a demo message until
|
|
||||||
// after we have parsed the frame
|
|
||||||
if( !cls.demoplayback )
|
|
||||||
{
|
|
||||||
if( cls.demorecording && !cls.demowaiting )
|
|
||||||
{
|
|
||||||
CL_WriteDemoMessage( false, cls.starting_count, msg );
|
|
||||||
}
|
|
||||||
else if( cls.state != ca_active )
|
|
||||||
{
|
|
||||||
CL_WriteDemoMessage( true, cls.starting_count, msg );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -317,36 +317,19 @@ CL_ParseLegacyServerMessage
|
||||||
dispatch messages
|
dispatch messages
|
||||||
=====================
|
=====================
|
||||||
*/
|
*/
|
||||||
void CL_ParseLegacyServerMessage( sizebuf_t *msg, qboolean normal_message )
|
void CL_ParseLegacyServerMessage( sizebuf_t *msg )
|
||||||
{
|
{
|
||||||
size_t bufStart, playerbytes;
|
size_t bufStart, playerbytes;
|
||||||
int cmd, param1, param2;
|
int cmd, param1, param2;
|
||||||
int old_background;
|
int old_background;
|
||||||
const char *s;
|
const char *s;
|
||||||
|
|
||||||
cls.starting_count = MSG_GetNumBytesRead( msg ); // updates each frame
|
|
||||||
CL_Parse_Debug( true ); // begin parsing
|
|
||||||
|
|
||||||
if( normal_message )
|
|
||||||
{
|
|
||||||
// assume no entity/player update this packet
|
|
||||||
if( cls.state == ca_active )
|
|
||||||
{
|
|
||||||
cl.frames[cls.netchan.incoming_sequence & CL_UPDATE_MASK].valid = false;
|
|
||||||
cl.frames[cls.netchan.incoming_sequence & CL_UPDATE_MASK].choked = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
CL_ResetFrame( &cl.frames[cls.netchan.incoming_sequence & CL_UPDATE_MASK] );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// parse the message
|
// parse the message
|
||||||
while( 1 )
|
while( 1 )
|
||||||
{
|
{
|
||||||
if( MSG_CheckOverflow( msg ))
|
if( MSG_CheckOverflow( msg ))
|
||||||
{
|
{
|
||||||
Host_Error( "CL_ParseServerMessage: overflow!\n" );
|
Host_Error( "%s: overflow!\n", __func__ );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -623,23 +606,6 @@ void CL_ParseLegacyServerMessage( sizebuf_t *msg, qboolean normal_message )
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cl.frames[cl.parsecountmod].graphdata.msgbytes += MSG_GetNumBytesRead( msg ) - cls.starting_count;
|
|
||||||
CL_Parse_Debug( false ); // done
|
|
||||||
|
|
||||||
// we don't know if it is ok to save a demo message until
|
|
||||||
// after we have parsed the frame
|
|
||||||
if( !cls.demoplayback )
|
|
||||||
{
|
|
||||||
if( cls.demorecording && !cls.demowaiting )
|
|
||||||
{
|
|
||||||
CL_WriteDemoMessage( false, cls.starting_count, msg );
|
|
||||||
}
|
|
||||||
else if( cls.state != ca_active )
|
|
||||||
{
|
|
||||||
CL_WriteDemoMessage( true, cls.starting_count, msg );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CL_LegacyPrecache_f( void )
|
void CL_LegacyPrecache_f( void )
|
||||||
|
|
|
@ -886,38 +886,21 @@ CL_ParseQuakeMessage
|
||||||
|
|
||||||
==================
|
==================
|
||||||
*/
|
*/
|
||||||
void CL_ParseQuakeMessage( sizebuf_t *msg, qboolean normal_message )
|
void CL_ParseQuakeMessage( sizebuf_t *msg )
|
||||||
{
|
{
|
||||||
int cmd, param1, param2;
|
int cmd, param1, param2;
|
||||||
size_t bufStart;
|
size_t bufStart;
|
||||||
const char *str;
|
const char *str;
|
||||||
|
|
||||||
cls.starting_count = MSG_GetNumBytesRead( msg ); // updates each frame
|
|
||||||
CL_Parse_Debug( true ); // begin parsing
|
|
||||||
|
|
||||||
// init excise buffer
|
// init excise buffer
|
||||||
MSG_Init( &msg_demo, "UserMsg", msg_buf, sizeof( msg_buf ));
|
MSG_Init( &msg_demo, "UserMsg", msg_buf, sizeof( msg_buf ));
|
||||||
|
|
||||||
if( normal_message )
|
|
||||||
{
|
|
||||||
// assume no entity/player update this packet
|
|
||||||
if( cls.state == ca_active )
|
|
||||||
{
|
|
||||||
cl.frames[cls.netchan.incoming_sequence & CL_UPDATE_MASK].valid = false;
|
|
||||||
cl.frames[cls.netchan.incoming_sequence & CL_UPDATE_MASK].choked = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
CL_ResetFrame( &cl.frames[cls.netchan.incoming_sequence & CL_UPDATE_MASK] );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// parse the message
|
// parse the message
|
||||||
while( 1 )
|
while( 1 )
|
||||||
{
|
{
|
||||||
if( MSG_CheckOverflow( msg ))
|
if( MSG_CheckOverflow( msg ))
|
||||||
{
|
{
|
||||||
Host_Error( "CL_ParseServerMessage: overflow!\n" );
|
Host_Error( "%s: overflow!\n", __func__ );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1113,9 +1096,6 @@ void CL_ParseQuakeMessage( sizebuf_t *msg, qboolean normal_message )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cl.frames[cl.parsecountmod].graphdata.msgbytes += MSG_GetNumBytesRead( msg ) - cls.starting_count;
|
|
||||||
CL_Parse_Debug( false ); // done
|
|
||||||
|
|
||||||
// now process packet.
|
// now process packet.
|
||||||
CL_ProcessPacket( &cl.frames[cl.parsecountmod] );
|
CL_ProcessPacket( &cl.frames[cl.parsecountmod] );
|
||||||
|
|
||||||
|
|
|
@ -891,7 +891,7 @@ void CL_ParseHLTV( sizebuf_t *msg );
|
||||||
void CL_ParseDirector( sizebuf_t *msg );
|
void CL_ParseDirector( sizebuf_t *msg );
|
||||||
void CL_ParseResLocation( sizebuf_t *msg );
|
void CL_ParseResLocation( sizebuf_t *msg );
|
||||||
void CL_ParseCvarValue( sizebuf_t *msg, const qboolean ext );
|
void CL_ParseCvarValue( sizebuf_t *msg, const qboolean ext );
|
||||||
void CL_ParseServerMessage( sizebuf_t *msg, qboolean normal_message );
|
void CL_ParseServerMessage( sizebuf_t *msg );
|
||||||
void CL_ParseTempEntity( sizebuf_t *msg );
|
void CL_ParseTempEntity( sizebuf_t *msg );
|
||||||
qboolean CL_DispatchUserMessage( const char *pszName, int iSize, void *pbuf );
|
qboolean CL_DispatchUserMessage( const char *pszName, int iSize, void *pbuf );
|
||||||
qboolean CL_RequestMissingResources( void );
|
qboolean CL_RequestMissingResources( void );
|
||||||
|
@ -907,7 +907,7 @@ int CL_EstimateNeededResources( void );
|
||||||
//
|
//
|
||||||
// cl_parse_48.c
|
// cl_parse_48.c
|
||||||
//
|
//
|
||||||
void CL_ParseLegacyServerMessage( sizebuf_t *msg, qboolean normal_message );
|
void CL_ParseLegacyServerMessage( sizebuf_t *msg );
|
||||||
void CL_LegacyPrecache_f( void );
|
void CL_LegacyPrecache_f( void );
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -966,7 +966,7 @@ void CL_SetIdealPitch( void );
|
||||||
//
|
//
|
||||||
// cl_qparse.c
|
// cl_qparse.c
|
||||||
//
|
//
|
||||||
void CL_ParseQuakeMessage( sizebuf_t *msg, qboolean normal_message );
|
void CL_ParseQuakeMessage( sizebuf_t *msg );
|
||||||
|
|
||||||
//
|
//
|
||||||
// cl_frame.c
|
// cl_frame.c
|
||||||
|
|
Loading…
Add table
Reference in a new issue