From d6ca1a3da939df4a714ffdef4a32833e1ce6b58e Mon Sep 17 00:00:00 2001 From: Meehoi Date: Sat, 24 Sep 2022 03:51:05 +0700 Subject: [PATCH] Fix #18035: Favourited servers don't get their online status updated From fetching flow, list will always have favourited servers but no code to update those entries, only append. This code updates those favourited servers in the list with new data from internet by matching address. This will fix list having 2 duplicate servers too. (one favourited and one not) --- distribution/changelog.txt | 1 + src/openrct2-ui/windows/ServerList.cpp | 4 ++-- src/openrct2/network/ServerList.cpp | 27 ++++++++++++++++++++++++++ src/openrct2/network/ServerList.h | 1 + 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index a4e38beda0..b0837635b3 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -73,6 +73,7 @@ - Fix: [#18026] Park rating drops to 0 with more than 32k guests, total ride excitement or intensity. - Fix: [#18051] Visual glitch with Mine Ride's large unbanked turn. - Fix: [#18032] All non-interactive widgets (labels, groupboxes) produce sound when clicked. +- Fix: [#18035] Favourited servers don’t get their online status updated. 0.4.1 (2022-07-04) ------------------------------------------------------------------------ diff --git a/src/openrct2-ui/windows/ServerList.cpp b/src/openrct2-ui/windows/ServerList.cpp index 711b3180c2..f7e9b0b232 100644 --- a/src/openrct2-ui/windows/ServerList.cpp +++ b/src/openrct2-ui/windows/ServerList.cpp @@ -146,7 +146,6 @@ rct_window* WindowServerListOpen() safe_strcpy(_playerName, gConfigNetwork.player_name.c_str(), sizeof(_playerName)); - _serverList.ReadAndAddFavourites(); window->no_list_items = static_cast(_serverList.GetCount()); ServerListFetchServersBegin(); @@ -581,7 +580,8 @@ static void ServerListFetchServersCheck(rct_window* w) try { auto [entries, statusText] = _fetchFuture.get(); - _serverList.AddRange(entries); + _serverList.AddOrUpdateRange(entries); + _serverList.WriteFavourites(); // Update favourites in case favourited server info changes _numPlayersOnline = _serverList.GetTotalPlayerCount(); _statusText = STR_X_PLAYERS_ONLINE; if (statusText != STR_NONE) diff --git a/src/openrct2/network/ServerList.cpp b/src/openrct2/network/ServerList.cpp index 4881d52f5a..0c04d27229 100644 --- a/src/openrct2/network/ServerList.cpp +++ b/src/openrct2/network/ServerList.cpp @@ -150,6 +150,33 @@ void ServerList::AddRange(const std::vector& entries) Sort(); } +void ServerList::AddOrUpdateRange(const std::vector& entries) +{ + for (auto& existsEntry : _serverEntries) + { + auto match = std::find_if( + entries.begin(), entries.end(), [&](const ServerListEntry& entry) { return existsEntry.Address == entry.Address; }); + if (match != entries.end()) + { + // Keep favourites + auto fav = existsEntry.Favourite; + + existsEntry = *match; + existsEntry.Favourite = fav; + } + } + + std::vector newServers; + std::copy_if(entries.begin(), entries.end(), std::back_inserter(newServers), [this](const ServerListEntry& entry) { + return std::find_if( + _serverEntries.begin(), _serverEntries.end(), + [&](const ServerListEntry& existsEntry) { return existsEntry.Address == entry.Address; }) + == _serverEntries.end(); + }); + + AddRange(newServers); +} + void ServerList::Clear() noexcept { _serverEntries.clear(); diff --git a/src/openrct2/network/ServerList.h b/src/openrct2/network/ServerList.h index be30ffe15a..4d007a7512 100644 --- a/src/openrct2/network/ServerList.h +++ b/src/openrct2/network/ServerList.h @@ -60,6 +60,7 @@ public: size_t GetCount() const; void Add(const ServerListEntry& entry); void AddRange(const std::vector& entries); + void AddOrUpdateRange(const std::vector& entries); void Clear() noexcept; void ReadAndAddFavourites();