[Download]: Add field to JSON endpoint (#846)

This commit is contained in:
Edo 2023-03-18 12:01:26 +00:00 committed by GitHub
parent b550438cd8
commit 237959e442
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 4 deletions

View File

@ -432,23 +432,27 @@ namespace Components
for (auto i = 0; i < Game::MAX_CLIENTS; ++i)
{
std::unordered_map<std::string, nlohmann::json> playerInfo;
// Insert default values
playerInfo["score"] = 0;
playerInfo["ping"] = 0;
playerInfo["name"] = "";
playerInfo["test_client"] = 0;
if (Dedicated::IsRunning())
{
if (Game::svs_clients[i].header.state < Game::CS_CONNECTED) continue;
if (Game::svs_clients[i].header.state < Game::CS_ACTIVE) continue;
if (!Game::svs_clients[i].gentity || !Game::svs_clients[i].gentity->client) continue;
playerInfo["score"] = Game::SV_GameClientNum_Score(i);
playerInfo["ping"] = Game::svs_clients[i].ping;
playerInfo["name"] = Game::svs_clients[i].name;
playerInfo["test_client"] = Game::svs_clients[i].bIsTestClient;
}
else
{
// Score and ping are irrelevant
const auto* name = Game::PartyHost_GetMemberName(Game::g_lobbyData, i);
if (name == nullptr || *name == '\0') continue;
if (!name || !*name) continue;
playerInfo["name"] = name;
}

View File

@ -220,7 +220,7 @@ namespace Components
const auto* client = Game::svs_clients[i].gentity->client;
const auto team = client->sess.cs.team;
if (team == Game::TEAM_SPECTATOR)
if (Game::svs_clients[i].bIsTestClient || team == Game::TEAM_SPECTATOR)
{
continue;
}
@ -233,7 +233,7 @@ namespace Components
{
// Score and ping are irrelevant
const auto* namePtr = Game::PartyHost_GetMemberName(reinterpret_cast<Game::PartyData*>(0x1081C00), i);
if (!namePtr || !namePtr[0]) continue;
if (!namePtr || !*namePtr) continue;
name = namePtr;
}