engine: client: rework NetAPI response parsing

This commit is contained in:
Alibek Omarov 2024-07-07 03:30:34 +03:00
parent 1b4427f13f
commit f8b958738a

View file

@ -1861,9 +1861,9 @@ 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;
@ -1871,8 +1871,27 @@ static void CL_ParseNETInfoMessage( netadr_t from, sizebuf_t *msg, const char *s
context = Q_atoi( Cmd_Argv( 1 ));
type = Q_atoi( Cmd_Argv( 2 ));
while( *s != '\\' ) s++; // fetching infostring
// 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;
}
}
// not found, ignore
if( nr == NULL )
return;
// find the infostring
while( *s != '\\' && *s )
s++;
if( s[0] == '\\' )
{
// check for errors
val = Info_ValueForKey( s, "neterror" );
@ -1884,14 +1903,8 @@ static void CL_ParseNETInfoMessage( netadr_t from, sizebuf_t *msg, const char *s
SetBits( errorBits, NET_ERROR_FORBIDDEN );
CL_FixupColorStringsForInfoString( s, infostring );
}
// find a request with specified context
for( i = 0; i < MAX_REQUESTS; i++ )
{
nr = &clgame.net_requests[i];
if( nr->resp.context == context && nr->resp.type == type )
{
// setup the answer
nr->resp.response = infostring;
nr->resp.remote_address = from;
@ -1906,9 +1919,6 @@ static void CL_ParseNETInfoMessage( netadr_t from, sizebuf_t *msg, const char *s
if( !FBitSet( nr->flags, FNETAPI_MULTIPLE_RESPONSE ))
memset( nr, 0, sizeof( *nr )); // done
return;
}
}
}
/*
@ -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" ))
{