diff options
author | rubidium <rubidium@openttd.org> | 2007-02-01 21:04:40 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2007-02-01 21:04:40 +0000 |
commit | 15980fc023c9fffa1af1ab71a446d0154d7962ca (patch) | |
tree | 455c66fea8606601015929a491e75466741e09f6 /src | |
parent | 5678febfe22b9cee3ae90d8335c7969c76c4a6fb (diff) | |
download | openttd-15980fc023c9fffa1af1ab71a446d0154d7962ca.tar.xz |
(svn r8520) -Fix/Feature: requery gameservers that did not respond to their first query.
Diffstat (limited to 'src')
-rw-r--r-- | src/network/network.cpp | 1 | ||||
-rw-r--r-- | src/network/network.h | 1 | ||||
-rw-r--r-- | src/network/network_gamelist.cpp | 38 | ||||
-rw-r--r-- | src/network/network_gamelist.h | 1 |
4 files changed, 41 insertions, 0 deletions
diff --git a/src/network/network.cpp b/src/network/network.cpp index a181f9055..91855589a 100644 --- a/src/network/network.cpp +++ b/src/network/network.cpp @@ -1275,6 +1275,7 @@ void NetworkUDPGameLoop(void) } else { _udp_client_socket->ReceivePackets(); if (_network_udp_broadcast > 0) _network_udp_broadcast--; + NetworkGameListRequery(); } } diff --git a/src/network/network.h b/src/network/network.h index a72e404a1..58af8e304 100644 --- a/src/network/network.h +++ b/src/network/network.h @@ -71,6 +71,7 @@ typedef struct NetworkGameList { uint16 port; bool online; // False if the server did not respond (default status) bool manually; // True if the server was added manually + uint8 retries; struct NetworkGameList *next; } NetworkGameList; diff --git a/src/network/network_gamelist.cpp b/src/network/network_gamelist.cpp index a202769e0..e5c1d9b9a 100644 --- a/src/network/network_gamelist.cpp +++ b/src/network/network_gamelist.cpp @@ -7,6 +7,10 @@ #include "network_data.h" #include "../newgrf_config.h" #include "../helpers.hpp" +#include "network_udp.h" + +/** Should we stop/contiue requerying of offline servers? */ +static bool _stop_requerying = false; // This file handles the GameList // Also, it handles the request to a server for data about the server @@ -40,6 +44,7 @@ NetworkGameList *NetworkGameListAddItem(uint32 ip, uint16 port) DEBUG(net, 4, "[gamelist] added server to list"); UpdateNetworkGameWindow(false); + _stop_requerying = false; return item; } @@ -72,4 +77,37 @@ void NetworkGameListRemoveItem(NetworkGameList *remove) } } +enum { + MAX_GAME_LIST_REQUERY_COUNT = 5, + REQUERY_EVERY_X_GAMELOOPS = 30, +}; + +/** Requeries the (game) servers we have not gotten a reply from */ +void NetworkGameListRequery(void) +{ + static uint8 requery_cnt = 0; + + if (_stop_requerying || ++requery_cnt < REQUERY_EVERY_X_GAMELOOPS) return; + + requery_cnt = 0; + _stop_requerying = true; + + struct in_addr ip; + NetworkGameList *item; + + for (item = _network_game_list; item != NULL; item = item->next) { + if (item->online || item->retries >= MAX_GAME_LIST_REQUERY_COUNT) continue; + + ip.s_addr = item->ip; + + /* item gets mostly zeroed by NetworkUDPQueryServer */ + uint8 retries = item->retries; + NetworkUDPQueryServer(inet_ntoa(ip), item->port); + item->retries = retries + 1; + + _stop_requerying = false; + } + +} + #endif /* ENABLE_NETWORK */ diff --git a/src/network/network_gamelist.h b/src/network/network_gamelist.h index c1a1a0904..7914f05cd 100644 --- a/src/network/network_gamelist.h +++ b/src/network/network_gamelist.h @@ -7,5 +7,6 @@ void NetworkGameListClear(void); NetworkGameList *NetworkGameListAddItem(uint32 ip, uint16 port); void NetworkGameListRemoveItem(NetworkGameList *remove); void NetworkGameListAddQueriedItem(const NetworkGameInfo *info, bool server_online); +void NetworkGameListRequery(void); #endif /* NETWORK_GAMELIST_H */ |