mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-20 21:43:06 +01:00
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)
This commit is contained in:
@@ -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)
|
||||
------------------------------------------------------------------------
|
||||
|
||||
@@ -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<uint16_t>(_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)
|
||||
|
||||
@@ -150,6 +150,33 @@ void ServerList::AddRange(const std::vector<ServerListEntry>& entries)
|
||||
Sort();
|
||||
}
|
||||
|
||||
void ServerList::AddOrUpdateRange(const std::vector<ServerListEntry>& 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<ServerListEntry> 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();
|
||||
|
||||
@@ -60,6 +60,7 @@ public:
|
||||
size_t GetCount() const;
|
||||
void Add(const ServerListEntry& entry);
|
||||
void AddRange(const std::vector<ServerListEntry>& entries);
|
||||
void AddOrUpdateRange(const std::vector<ServerListEntry>& entries);
|
||||
void Clear() noexcept;
|
||||
|
||||
void ReadAndAddFavourites();
|
||||
|
||||
Reference in New Issue
Block a user