Make getinfo responses consistent, whether actual getinfos or the broker equivelent.

This commit is contained in:
Shpoike 2025-01-26 02:24:28 +00:00
parent e5e7dde336
commit ad5366ae54
4 changed files with 44 additions and 110 deletions

View file

@ -5372,59 +5372,8 @@ static void FTENET_ICE_Heartbeat(ftenet_ice_connection_t *b)
#ifdef HAVE_SERVER
if (b->generic.islisten)
{
extern cvar_t maxclients;
char info[2048];
int i;
client_t *cl;
int numclients = 0;
for (i=0 ; i<svs.allocated_client_slots ; i++)
{
cl = &svs.clients[i];
if ((cl->state == cs_connected || cl->state == cs_spawned || cl->name[0]) && !cl->spectator)
numclients++;
}
*info = 0;
//first line contains the serverinfo, or some form of it
{
char *resp = info;
const char *ignorekeys[] = {
"maxclients", "map", "*gamedir", "*z_ext", //this is a DP protocol query, so some QW fields are not needed
"gamename", "modname", "protocol", "clients", "sv_maxclients", "mapname", "qcstatus", "challenge", NULL}; //and we need to add some
const char *prioritykeys[] = {"hostname", NULL}; //make sure we include these before we start overflowing
char protocolname[64];
const char *gamestatus;
COM_ParseOut(com_protocolname.string, protocolname, sizeof(protocolname)); //we can only report one, so report the first.
if (svprogfuncs)
{
eval_t *v = PR_FindGlobal(svprogfuncs, "worldstatus", PR_ANY, NULL);
if (v)
gamestatus = PR_GetString(svprogfuncs, v->string);
else
gamestatus = "";
}
else
gamestatus = "";
Info_SetValueForKey(resp, "gamename", protocolname, sizeof(info) - (resp-info));//distinguishes it from other types of games
Info_SetValueForKey(resp, "protocol", SV_GetProtocolVersionString(), sizeof(info) - (resp-info));
Info_SetValueForKey(resp, "modname", FS_GetGamedir(true), sizeof(info) - (resp-info));
Info_SetValueForKey(resp, "clients", va("%d", numclients), sizeof(info) - (resp-info));
Info_SetValueForKey(resp, "sv_maxclients", maxclients.string, sizeof(info) - (resp-info));
Info_SetValueForKey(resp, "mapname", InfoBuf_ValueForKey(&svs.info, "map"), sizeof(info) - (resp-info));
resp += strlen(resp);
//now include the full/regular serverinfo
resp += InfoBuf_ToString(&svs.info, resp, sizeof(info) - (resp-info), prioritykeys, ignorekeys, NULL, NULL, NULL);
*resp = 0;
//and any possibly-long qc status string
if (*gamestatus)
Info_SetValueForKey(resp, "qcstatus", gamestatus, sizeof(info) - (resp-info));
resp += strlen(resp);
*resp++ = 0;
}
SV_GeneratePublicServerinfo(info, info+sizeof(info));
FTENET_ICE_SplurgeCmd(b, ICEMSG_SERVERINFO, -1, info);
}
#endif

View file

@ -8831,30 +8831,11 @@ static void FTENET_WebRTC_Heartbeat(ftenet_websocket_connection_t *b)
#ifdef HAVE_SERVER
if (b->generic.islisten)
{
extern cvar_t maxclients;
char info[2048];
int i;
client_t *cl;
int numclients = 0;
for (i=0 ; i<svs.allocated_client_slots ; i++)
{
cl = &svs.clients[i];
if ((cl->state == cs_connected || cl->state == cs_spawned || cl->name[0]) && !cl->spectator)
numclients++;
}
info[0] = ICEMSG_SERVERINFO;
info[1] =
info[2] = 0xff; //to the broker rather than any actual client
info[3] = 0;
Info_SetValueForKey(info+3, "protocol", SV_GetProtocolVersionString(), sizeof(info)-3);
Info_SetValueForKey(info+3, "maxclients", maxclients.string, sizeof(info)-3);
Info_SetValueForKey(info+3, "clients", va("%i", numclients), sizeof(info)-3);
Info_SetValueForKey(info+3, "hostname", hostname.string, sizeof(info)-3);
Info_SetValueForKey(info+3, "modname", FS_GetGamedir(true), sizeof(info)-3);
Info_SetValueForKey(info+3, "mapname", InfoBuf_ValueForKey(&svs.info, "map"), sizeof(info)-3);
Info_SetValueForKey(info+3, "needpass", InfoBuf_ValueForKey(&svs.info, "needpass"), sizeof(info)-3);
SV_GeneratePublicServerinfo(info+3, info+sizeof(info));
if (emscriptenfte_ws_send(b->brokersock, info, 3+strlen(info+3)) <= 0)
return;
}

View file

@ -1173,6 +1173,7 @@ int SV_CalcPing (client_t *cl, qboolean forcecalc);
void SV_FullClientUpdate (client_t *client, client_t *to);
char *SV_PlayerPublicAddress(client_t *cl);
void SV_GeneratePublicServerinfo(char *info, const char *endinfo);
const char *SV_GetProtocolVersionString(void); //decorate the protocol version field of server queries with extra features...
qboolean SVC_GetChallenge (qboolean respond_dp);
int SV_NewChallenge (void);

View file

@ -1328,19 +1328,21 @@ const char *SV_GetProtocolVersionString(void)
}
return ret;
}
static void SVC_GetInfo (const char *challenge, int fullstatus)
void SV_GeneratePublicServerinfo(char *info, const char *endinfo)
{
//dpmaster support
char response[MAX_UDP_PACKET];
char protocolname[MAX_QPATH];
client_t *cl;
int numclients = 0;
int i;
char *resp;
char *resp = info;
const char *ignorekeys[] = {
"maxclients", "map", "*gamedir", "*z_ext", //this is a DP protocol query, so some QW fields are not needed
"gamename", "modname", "protocol", "clients", "sv_maxclients", "mapname", "qcstatus", "challenge", NULL}; //and we need to add some
const char *prioritykeys[] = {"hostname", NULL}; //make sure we include these before we start overflowing
char protocolname[64];
const char *gamestatus;
eval_t *v;
extern cvar_t maxclients;
int i;
client_t *cl;
int numclients = 0;
for (i=0 ; i<svs.allocated_client_slots ; i++)
{
cl = &svs.clients[i];
@ -1348,9 +1350,11 @@ static void SVC_GetInfo (const char *challenge, int fullstatus)
numclients++;
}
//first line contains the serverinfo, or some form of it
COM_ParseOut(com_protocolname.string, protocolname, sizeof(protocolname)); //we can only report one, so report the first.
if (svprogfuncs)
{
v = PR_FindGlobal(svprogfuncs, "worldstatus", PR_ANY, NULL);
eval_t *v = PR_FindGlobal(svprogfuncs, "worldstatus", PR_ANY, NULL);
if (v)
gamestatus = PR_GetString(svprogfuncs, v->string);
else
@ -1359,7 +1363,30 @@ static void SVC_GetInfo (const char *challenge, int fullstatus)
else
gamestatus = "";
COM_ParseOut(com_protocolname.string, protocolname, sizeof(protocolname)); //we can only report one, so report the first.
*resp = 0;
Info_SetValueForKey(resp, "gamename", protocolname, endinfo - resp);//distinguishes it from other types of games
Info_SetValueForKey(resp, "protocol", SV_GetProtocolVersionString(), endinfo - resp);
Info_SetValueForKey(resp, "modname", FS_GetGamedir(true), endinfo - resp);
Info_SetValueForKey(resp, "clients", va("%d", numclients), endinfo - resp);
Info_SetValueForKey(resp, "sv_maxclients", maxclients.string, endinfo - resp);
Info_SetValueForKey(resp, "mapname", InfoBuf_ValueForKey(&svs.info, "map"), endinfo - resp);
resp += strlen(resp);
//now include the full/regular serverinfo
resp += InfoBuf_ToString(&svs.info, resp, endinfo - resp, prioritykeys, ignorekeys, NULL, NULL, NULL);
*resp = 0;
//and any possibly-long qc status string
if (*gamestatus)
Info_SetValueForKey(resp, "qcstatus", gamestatus, endinfo - resp);
resp += strlen(resp);
*resp++ = 0;
}
static void SVC_GetInfo (const char *challenge, int fullstatus)
{
//dpmaster support
char response[MAX_UDP_PACKET];
int i;
char *resp;
resp = response;
@ -1375,31 +1402,7 @@ static void SVC_GetInfo (const char *challenge, int fullstatus)
resp += strlen(resp);
*resp++ = '\n';
//first line contains the serverinfo, or some form of it
{
const char *ignorekeys[] = {
"maxclients", "map", "*gamedir", "*z_ext", //this is a DP protocol query, so some QW fields are not needed
"gamename", "modname", "protocol", "clients", "sv_maxclients", "mapname", "qcstatus", "challenge", NULL}; //and we need to add some
const char *prioritykeys[] = {"hostname", NULL}; //make sure we include these before we start overflowing
*resp = 0;
Info_SetValueForKey(resp, "challenge", challenge, sizeof(response) - (resp-response)); //the challenge can be important for the master protocol to prevent poisoning
Info_SetValueForKey(resp, "gamename", protocolname, sizeof(response) - (resp-response));//distinguishes it from other types of games
Info_SetValueForKey(resp, "protocol", SV_GetProtocolVersionString(), sizeof(response) - (resp-response));
Info_SetValueForKey(resp, "modname", FS_GetGamedir(true), sizeof(response) - (resp-response));
Info_SetValueForKey(resp, "clients", va("%d", numclients), sizeof(response) - (resp-response));
Info_SetValueForKey(resp, "sv_maxclients", maxclients.string, sizeof(response) - (resp-response));
Info_SetValueForKey(resp, "mapname", InfoBuf_ValueForKey(&svs.info, "map"), sizeof(response) - (resp-response));
resp += strlen(resp);
//now include the full/regular serverinfo
resp += InfoBuf_ToString(&svs.info, resp, sizeof(response) - (resp-response), prioritykeys, ignorekeys, NULL, NULL, NULL);
*resp = 0;
//and any possibly-long qc status string
if (*gamestatus)
Info_SetValueForKey(resp, "qcstatus", gamestatus, sizeof(response) - (resp-response));
resp += strlen(resp);
}
*resp++ = 0;
SV_GeneratePublicServerinfo(resp, response+sizeof(response));
if (fullstatus)
{
@ -1574,7 +1577,7 @@ SVC_Ping
Just responds with an acknowledgement
================
*/
void SVC_Ping (void)
static void SVC_Ping (void)
{
char data;