Skip to content

Commit

Permalink
engine: client: rework NetAPI response parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
a1batross committed Jul 7, 2024
1 parent 1b4427f commit f8b9587
Showing 1 changed file with 42 additions and 32 deletions.
74 changes: 42 additions & 32 deletions engine/client/cl_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1861,54 +1861,64 @@ CL_ParseNETInfoMessage
Handle a reply from a netinfo
=================
*/
static void CL_ParseNETInfoMessage( netadr_t from, sizebuf_t *msg, const char *s )
static void CL_ParseNETInfoMessage( netadr_t from, const char *s )
{
net_request_t *nr;
net_request_t *nr = NULL;
static char infostring[MAX_INFO_STRING+8];
int i, context, type;
int errorBits = 0;
const char *val;

context = Q_atoi( Cmd_Argv( 1 ));
type = Q_atoi( Cmd_Argv( 2 ));
while( *s != '\\' ) s++; // fetching infostring

// check for errors
val = Info_ValueForKey( s, "neterror" );
// find request with specified context and type
for( i = 0; i < MAX_REQUESTS; i++ )
{
if( clgame.net_requests[i].resp.context == context && clgame.net_requests[i].resp.type == type )
{
nr = &clgame.net_requests[i];
break;
}
}

if( !Q_stricmp( val, "protocol" ))
SetBits( errorBits, NET_ERROR_PROTO_UNSUPPORTED );
else if( !Q_stricmp( val, "undefined" ))
SetBits( errorBits, NET_ERROR_UNDEFINED );
else if( !Q_stricmp( val, "forbidden" ))
SetBits( errorBits, NET_ERROR_FORBIDDEN );
// not found, ignore
if( nr == NULL )
return;

CL_FixupColorStringsForInfoString( s, infostring );
// find the infostring
while( *s != '\\' && *s )
s++;

// find a request with specified context
for( i = 0; i < MAX_REQUESTS; i++ )
if( s[0] == '\\' )
{
nr = &clgame.net_requests[i];
// check for errors
val = Info_ValueForKey( s, "neterror" );

if( nr->resp.context == context && nr->resp.type == type )
{
// setup the answer
nr->resp.response = infostring;
nr->resp.remote_address = from;
nr->resp.error = NET_SUCCESS;
nr->resp.ping = host.realtime - nr->timesend;
if( !Q_stricmp( val, "protocol" ))
SetBits( errorBits, NET_ERROR_PROTO_UNSUPPORTED );
else if( !Q_stricmp( val, "undefined" ))
SetBits( errorBits, NET_ERROR_UNDEFINED );
else if( !Q_stricmp( val, "forbidden" ))
SetBits( errorBits, NET_ERROR_FORBIDDEN );

if( nr->timeout <= host.realtime )
SetBits( nr->resp.error, NET_ERROR_TIMEOUT );
SetBits( nr->resp.error, errorBits ); // misc error bits
CL_FixupColorStringsForInfoString( s, infostring );
}

nr->pfnFunc( &nr->resp );
// setup the answer
nr->resp.response = infostring;
nr->resp.remote_address = from;
nr->resp.error = NET_SUCCESS;
nr->resp.ping = host.realtime - nr->timesend;

if( !FBitSet( nr->flags, FNETAPI_MULTIPLE_RESPONSE ))
memset( nr, 0, sizeof( *nr )); // done
return;
}
}
if( nr->timeout <= host.realtime )
SetBits( nr->resp.error, NET_ERROR_TIMEOUT );
SetBits( nr->resp.error, errorBits ); // misc error bits

nr->pfnFunc( &nr->resp );

if( !FBitSet( nr->flags, FNETAPI_MULTIPLE_RESPONSE ))
memset( nr, 0, sizeof( *nr )); // done
}

/*
Expand Down Expand Up @@ -2041,7 +2051,7 @@ static void CL_ConnectionlessPacket( netadr_t from, sizebuf_t *msg )
else if( !Q_strcmp( c, "netinfo" ))
{
// server responding to a status broadcast
CL_ParseNETInfoMessage( from, msg, args );
CL_ParseNETInfoMessage( from, args );
}
else if( !Q_strcmp( c, "cmd" ))
{
Expand Down

0 comments on commit f8b9587

Please sign in to comment.