diff --git a/engine/common/net_ice.c b/engine/common/net_ice.c index 2947e82d1..bdc15da03 100644 --- a/engine/common/net_ice.c +++ b/engine/common/net_ice.c @@ -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 ; istate == 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 diff --git a/engine/common/net_wins.c b/engine/common/net_wins.c index 61f29b42b..83f975cb4 100644 --- a/engine/common/net_wins.c +++ b/engine/common/net_wins.c @@ -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 ; istate == 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; } diff --git a/engine/server/server.h b/engine/server/server.h index 5f5ce47e1..55a04e849 100644 --- a/engine/server/server.h +++ b/engine/server/server.h @@ -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); diff --git a/engine/server/sv_main.c b/engine/server/sv_main.c index e8febd6c2..54b62dd82 100644 --- a/engine/server/sv_main.c +++ b/engine/server/sv_main.c @@ -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 ; istring); 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;