1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-31 02:35:46 +01:00

Add status messages to server list window

This commit is contained in:
Christian F. Coors
2017-10-05 17:54:26 +02:00
committed by Michael Steenbeek
parent 34685b07a0
commit e737b3108c
3 changed files with 24 additions and 6 deletions

View File

@@ -4456,7 +4456,11 @@ STR_6144 :Show dirty visuals
STR_6145 :{SMALLFONT}{BLACK}Set speed limit for boosters
STR_6146 :Enable all drawable track pieces
STR_6147 :{SMALLFONT}{BLACK}Enables all track pieces the ride type is capable of in the construction window, regardless of whether the vehicle supports them.
STR_6148 :Connecting to master server...
STR_6149 :Unable to connect to master server
STR_6150 :Invalid response from master server (no JSON number)
STR_6151 :Master server failed to return servers
STR_6152 :Invalid response from master server (no JSON array)
#############
# Scenarios #

View File

@@ -40,6 +40,7 @@ static server_entry *_serverEntries = nullptr;
static sint32 _numServerEntries = 0;
static std::mutex _mutex;
static uint32 _numPlayersOnline = 0;
static rct_string_id status_text = STR_SERVER_LIST_CONNECTING;
enum {
WIDX_BACKGROUND,
@@ -396,7 +397,7 @@ static void window_server_list_paint(rct_window *w, rct_drawpixelinfo *dpi)
const char * version = NETWORK_STREAM_ID;
gfx_draw_string_left(dpi, STR_NETWORK_VERSION, (void*)&version, COLOUR_WHITE, w->x + 324, w->y + w->widgets[WIDX_START_SERVER].top);
gfx_draw_string_left(dpi, STR_X_PLAYERS_ONLINE, (void*)&_numPlayersOnline, COLOUR_WHITE, w->x + 8, w->y + w->height - 15);
gfx_draw_string_left(dpi, status_text, (void *)&_numPlayersOnline, COLOUR_WHITE, w->x + 8, w->y + w->height - 15);
}
static void window_server_list_scrollpaint(rct_window *w, rct_drawpixelinfo *dpi, sint32 scrollIndex)
@@ -687,6 +688,7 @@ static void fetch_servers()
request.method = HTTP_METHOD_GET;
request.body = nullptr;
request.type = HTTP_DATA_JSON;
status_text = STR_SERVER_LIST_CONNECTING;
http_request_async(&request, fetch_servers_callback);
#endif
}
@@ -695,6 +697,8 @@ static void fetch_servers()
static void fetch_servers_callback(http_response_t* response)
{
if (response == nullptr) {
status_text = STR_SERVER_LIST_NO_CONNECTION;
window_invalidate_by_class(WC_SERVER_LIST);
log_warning("Unable to connect to master server");
return;
}
@@ -702,6 +706,8 @@ static void fetch_servers_callback(http_response_t* response)
json_t *jsonStatus = json_object_get(response->root, "status");
if (!json_is_number(jsonStatus)) {
http_request_dispose(response);
status_text = STR_SERVER_LIST_INVALID_RESPONSE_JSON_NUMBER;
window_invalidate_by_class(WC_SERVER_LIST);
log_warning("Invalid response from master server");
return;
}
@@ -709,6 +715,8 @@ static void fetch_servers_callback(http_response_t* response)
sint32 status = (sint32)json_integer_value(jsonStatus);
if (status != 200) {
http_request_dispose(response);
status_text = STR_SERVER_LIST_MASTER_SERVER_FAILED;
window_invalidate_by_class(WC_SERVER_LIST);
log_warning("Master server failed to return servers");
return;
}
@@ -716,6 +724,8 @@ static void fetch_servers_callback(http_response_t* response)
json_t *jsonServers = json_object_get(response->root, "servers");
if (!json_is_array(jsonServers)) {
http_request_dispose(response);
status_text = STR_SERVER_LIST_INVALID_RESPONSE_JSON_ARRAY;
window_invalidate_by_class(WC_SERVER_LIST);
log_warning("Invalid response from master server");
return;
}
@@ -766,9 +776,7 @@ static void fetch_servers_callback(http_response_t* response)
sort_servers();
_numPlayersOnline = get_total_player_count();
rct_window *window = window_find_by_class(WC_SERVER_LIST);
if (window != nullptr) {
window_invalidate(window);
}
status_text = STR_X_PLAYERS_ONLINE;
window_invalidate_by_class(WC_SERVER_LIST);
}
#endif

View File

@@ -3798,6 +3798,12 @@ enum {
STR_CHEAT_ENABLE_ALL_DRAWABLE_TRACK_PIECES = 6146,
STR_CHEAT_ENABLE_ALL_DRAWABLE_TRACK_PIECES_TIP = 6147,
STR_SERVER_LIST_CONNECTING = 6148,
STR_SERVER_LIST_NO_CONNECTION = 6149,
STR_SERVER_LIST_INVALID_RESPONSE_JSON_NUMBER = 6150,
STR_SERVER_LIST_MASTER_SERVER_FAILED = 6151,
STR_SERVER_LIST_INVALID_RESPONSE_JSON_ARRAY = 6152,
// Have to include resource strings (from scenarios and objects) for the time being now that language is partially working
STR_COUNT = 32768
};