mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-22 22:34:33 +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:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user