diff options
author | Patric Stout <truebrain@openttd.org> | 2021-07-03 11:12:28 +0200 |
---|---|---|
committer | Patric Stout <github@truebrain.nl> | 2021-07-10 20:17:07 +0200 |
commit | aa93d76223f0411b54f5150adbe2c83c33fd61af (patch) | |
tree | 481a29b60241d08b549b2477e836c3b186276c4d /src/network/network_gui.cpp | |
parent | b1280fd17ebaf9e4df086b63074d0bd8b8c9155d (diff) | |
download | openttd-aa93d76223f0411b54f5150adbe2c83c33fd61af.tar.xz |
Add: use Game Coordinator to get latest public server listing
Diffstat (limited to 'src/network/network_gui.cpp')
-rw-r--r-- | src/network/network_gui.cpp | 40 |
1 files changed, 28 insertions, 12 deletions
diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp index 6f48bf022..24884ed16 100644 --- a/src/network/network_gui.cpp +++ b/src/network/network_gui.cpp @@ -18,6 +18,7 @@ #include "network_base.h" #include "network_content.h" #include "network_server.h" +#include "network_coordinator.h" #include "../gui.h" #include "network_udp.h" #include "../window_func.h" @@ -54,6 +55,8 @@ static void ShowNetworkStartServerWindow(); static void ShowNetworkLobbyWindow(NetworkGameList *ngl); +static const int NETWORK_LIST_REFRESH_DELAY = 30; ///< Time, in seconds, between updates of the network list. + static ClientID _admin_client_id = INVALID_CLIENT_ID; ///< For what client a confirmation window is open. static CompanyID _admin_company_id = INVALID_COMPANY; ///< For what company a confirmation window is open. @@ -219,14 +222,15 @@ protected: static GUIGameServerList::SortFunction * const sorter_funcs[]; static GUIGameServerList::FilterFunction * const filter_funcs[]; - NetworkGameList *server; ///< selected server - NetworkGameList *last_joined; ///< the last joined server - GUIGameServerList servers; ///< list with game servers. - ServerListPosition list_pos; ///< position of the selected server - Scrollbar *vscroll; ///< vertical scrollbar of the list of servers - QueryString name_editbox; ///< Client name editbox. - QueryString filter_editbox; ///< Editbox for filter on servers - GUITimer requery_timer; ///< Timer for network requery + NetworkGameList *server; ///< Selected server. + NetworkGameList *last_joined; ///< The last joined server. + GUIGameServerList servers; ///< List with game servers. + ServerListPosition list_pos; ///< Position of the selected server. + Scrollbar *vscroll; ///< Vertical scrollbar of the list of servers. + QueryString name_editbox; ///< Client name editbox. + QueryString filter_editbox; ///< Editbox for filter on servers. + GUITimer requery_timer; ///< Timer for network requery. + bool searched_internet = false; ///< Did we ever press "Search Internet" button? int lock_offset; ///< Left offset for lock icon. int blot_offset; ///< Left offset for green/yellow/red compatibility icon. @@ -244,8 +248,18 @@ protected: /* Create temporary array of games to use for listing */ this->servers.clear(); + bool found_current_server = false; for (NetworkGameList *ngl = _network_game_list; ngl != nullptr; ngl = ngl->next) { this->servers.push_back(ngl); + if (ngl == this->server) { + found_current_server = true; + } + } + /* A refresh can cause the current server to be delete; so unselect. */ + if (!found_current_server) { + if (this->server == this->last_joined) this->last_joined = nullptr; + this->server = nullptr; + this->list_pos = SLP_INVALID; } /* Apply the filter condition immediately, if a search string has been provided. */ @@ -479,7 +493,7 @@ public: this->last_joined = NetworkAddServer(_settings_client.network.last_joined, false); this->server = this->last_joined; - this->requery_timer.SetInterval(MILLISECONDS_PER_TICK); + this->requery_timer.SetInterval(NETWORK_LIST_REFRESH_DELAY * 1000); this->servers.SetListing(this->last_sorting); this->servers.SetSortFuncs(this->sorter_funcs); @@ -725,7 +739,8 @@ public: } case WID_NG_SEARCH_INTERNET: - NetworkUDPQueryMasterServer(); + _network_coordinator_client.GetListing(); + this->searched_internet = true; break; case WID_NG_SEARCH_LAN: @@ -841,10 +856,11 @@ public: void OnRealtimeTick(uint delta_ms) override { + if (!this->searched_internet) return; if (!this->requery_timer.Elapsed(delta_ms)) return; - this->requery_timer.SetInterval(MILLISECONDS_PER_TICK); + this->requery_timer.SetInterval(NETWORK_LIST_REFRESH_DELAY * 1000); - NetworkGameListRequery(); + _network_coordinator_client.GetListing(); } }; |