summaryrefslogtreecommitdiff
path: root/src/network/network_gamelist.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/network/network_gamelist.cpp')
-rw-r--r--src/network/network_gamelist.cpp31
1 files changed, 30 insertions, 1 deletions
diff --git a/src/network/network_gamelist.cpp b/src/network/network_gamelist.cpp
index ae716070c..b4f34983f 100644
--- a/src/network/network_gamelist.cpp
+++ b/src/network/network_gamelist.cpp
@@ -20,7 +20,8 @@
#include "../safeguards.h"
-NetworkGameList *_network_game_list = nullptr;
+NetworkGameList *_network_game_list = nullptr; ///< Game list of this client.
+int _network_game_list_version = 0; ///< Current version of all items in the list.
/** The games to insert when the GUI thread has time for us. */
static std::atomic<NetworkGameList *> _network_game_delayed_insertion_list(nullptr);
@@ -81,6 +82,7 @@ NetworkGameList *NetworkGameListAddItem(const std::string &connection_string)
}
item = new NetworkGameList(resolved_connection_string);
+ item->version = _network_game_list_version;
if (prev_item == nullptr) {
_network_game_list = item;
@@ -120,6 +122,33 @@ void NetworkGameListRemoveItem(NetworkGameList *remove)
}
}
+/**
+ * Remove all servers that have not recently been updated.
+ * Call this after you received all the servers from the Game Coordinator, so
+ * the ones that are no longer listed are removed.
+ */
+void NetworkGameListRemoveExpired()
+{
+ NetworkGameList **prev_item = &_network_game_list;
+
+ for (NetworkGameList *item = _network_game_list; item != nullptr;) {
+ if (!item->manually && item->version < _network_game_list_version) {
+ NetworkGameList *remove = item;
+ item = item->next;
+ *prev_item = item;
+
+ /* Remove GRFConfig information */
+ ClearGRFConfigList(&remove->info.grfconfig);
+ delete remove;
+ } else {
+ prev_item = &item->next;
+ item = item->next;
+ }
+ }
+
+ UpdateNetworkGameWindow();
+}
+
static const uint MAX_GAME_LIST_REQUERY_COUNT = 10; ///< How often do we requery in number of times per server?
static const uint REQUERY_EVERY_X_GAMELOOPS = 60; ///< How often do we requery in time?
static const uint REFRESH_GAMEINFO_X_REQUERIES = 50; ///< Refresh the game info itself after REFRESH_GAMEINFO_X_REQUERIES * REQUERY_EVERY_X_GAMELOOPS game loops