From da6d382c471ccaa2273770c712d70a5d85f98cc4 Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Sun, 8 Nov 2015 23:29:52 +0000 Subject: [PATCH] make server heartbeat PUT --- src/network/network.cpp | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/src/network/network.cpp b/src/network/network.cpp index 3b916dda30..7aa795a91a 100644 --- a/src/network/network.cpp +++ b/src/network/network.cpp @@ -898,18 +898,29 @@ void Network::AdvertiseHeartbeat() { #ifndef DISABLE_HTTP // Send the heartbeat request - std::string url = GetMasterServerUrl() - + std::string("?token=") + advertise_token - + std::string("&players=") + std::to_string(network_get_num_players()); + http_json_request request; + request.url = GetMasterServerUrl(); + request.method = HTTP_METHOD_PUT; - // TODO send status data (e.g. players) via JSON body + json_t *body = json_object(); + json_object_set(body, "token", json_string(advertise_token.c_str())); + json_object_set(body, "players", json_integer(network_get_num_players())); + + json_t *gameInfo = json_object(); + json_object_set(gameInfo, "mapSize", json_integer(RCT2_GLOBAL(RCT2_ADDRESS_MAP_SIZE, uint8) - 2)); + json_object_set(gameInfo, "day", json_integer(RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_MONTH_TICKS, uint16))); + json_object_set(gameInfo, "month", json_integer(RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_MONTH_YEAR, uint16))); + json_object_set(gameInfo, "guests", json_integer(RCT2_GLOBAL(RCT2_ADDRESS_GUESTS_IN_PARK, uint16))); + json_object_set(gameInfo, "parkValue", json_integer(RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_PARK_VALUE, money32))); + if (!(RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) & PARK_FLAGS_NO_MONEY)) { + money32 cash = DECRYPT_MONEY(RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_MONEY_ENCRYPTED, money32)); + json_object_set(gameInfo, "cash", json_integer(cash)); + } + + json_object_set(body, "gameInfo", gameInfo); + request.body = body; gNetwork.last_heartbeat_time = SDL_GetTicks(); - - http_json_request request; - request.url = url.c_str(); - request.method = HTTP_METHOD_PUT; - request.body = NULL; http_request_json_async(&request, [](http_json_response *response) -> void { if (response == NULL) { log_warning("Unable to connect to master server"); @@ -928,6 +939,8 @@ void Network::AdvertiseHeartbeat() } http_request_json_dispose(response); }); + + json_decref(body); #endif }