feat: complete human-vs-ESP32 gameplay and cumulative statistics
This commit is contained in:
@@ -299,6 +299,28 @@ bool http_api_handle(http_api_t *api, const http_api_request_t *request, http_ap
|
||||
} else response->status = 200U;
|
||||
return true;
|
||||
}
|
||||
if (request->route == HTTP_API_ROUTE_STATISTICS && request->method == HTTP_API_GET) {
|
||||
role_t viewer = ROLE_SPECTATOR;
|
||||
uint8_t token[kSessionTokenBytes];
|
||||
uint8_t session_index = 0;
|
||||
if (request->session_token != NULL && request->session_token[0] != '\0') {
|
||||
if (!parse_token(request->session_token, token) || !application_session_for_token(api->application, token, &session_index)) {
|
||||
response_error(response, 401U, "UNAUTHORIZED", "Сессия не найдена", version);
|
||||
return true;
|
||||
}
|
||||
viewer = lifecycle->sessions.entries[session_index].role;
|
||||
}
|
||||
const match_statistics_t *match = lifecycle->game.state.statistics;
|
||||
const cumulative_statistics_t *total = lifecycle->cumulative;
|
||||
response_write(response, 200U, "{\"ok\":true,\"viewer\":\"%s\",\"gameId\":%" PRIu32
|
||||
",\"match\":[[%u,%u,%u,%u],[%u,%u,%u,%u]],\"cumulative\":[[%u,%u,%u,%u,%" PRIu32 ",%" PRIu32 ",%" PRIu32
|
||||
"],[%u,%u,%u,%u,%" PRIu32 ",%" PRIu32 ",%" PRIu32 "]]}", role_text(viewer), lifecycle->game.state.game_id,
|
||||
match[0].shots, match[0].hits, match[0].misses, match[0].ships_sunk,
|
||||
match[1].shots, match[1].hits, match[1].misses, match[1].ships_sunk,
|
||||
total[0].games, total[0].wins, total[0].losses, total[0].ships_sunk, total[0].shots, total[0].hits, total[0].misses,
|
||||
total[1].games, total[1].wins, total[1].losses, total[1].ships_sunk, total[1].shots, total[1].hits, total[1].misses);
|
||||
return response->body_length < sizeof(response->body);
|
||||
}
|
||||
if (request->route == HTTP_API_ROUTE_JOIN) {
|
||||
char name[kDisplayNameBytes + 1U] = {0};
|
||||
role_t role = ROLE_SPECTATOR;
|
||||
|
||||
Reference in New Issue
Block a user