15 #include "network_udp.h" |
15 #include "network_udp.h" |
16 #include "network_gamelist.h" |
16 #include "network_gamelist.h" |
17 #include "network_gui.h" |
17 #include "network_gui.h" |
18 |
18 |
19 NetworkGameList *_network_game_list = NULL; |
19 NetworkGameList *_network_game_list = NULL; |
20 |
|
21 /** Should we stop/contiue requerying of offline servers? */ |
|
22 static bool _stop_requerying = false; |
|
23 |
20 |
24 /** Add a new item to the linked gamelist. If the IP and Port match |
21 /** Add a new item to the linked gamelist. If the IP and Port match |
25 * return the existing item instead of adding it again |
22 * return the existing item instead of adding it again |
26 * @param ip the IP-address (inet_addr) of the to-be added item |
23 * @param ip the IP-address (inet_addr) of the to-be added item |
27 * @param port the port the server is running on |
24 * @param port the port the server is running on |
48 prev_item->next = item; |
45 prev_item->next = item; |
49 } |
46 } |
50 DEBUG(net, 4, "[gamelist] added server to list"); |
47 DEBUG(net, 4, "[gamelist] added server to list"); |
51 |
48 |
52 UpdateNetworkGameWindow(false); |
49 UpdateNetworkGameWindow(false); |
53 _stop_requerying = false; |
|
54 |
50 |
55 return item; |
51 return item; |
56 } |
52 } |
57 |
53 |
58 /** Remove an item from the gamelist linked list |
54 /** Remove an item from the gamelist linked list |
82 prev_item = item; |
78 prev_item = item; |
83 } |
79 } |
84 } |
80 } |
85 |
81 |
86 enum { |
82 enum { |
87 MAX_GAME_LIST_REQUERY_COUNT = 5, |
83 MAX_GAME_LIST_REQUERY_COUNT = 5, ///< How often do we requery in number of times per server? |
88 REQUERY_EVERY_X_GAMELOOPS = 60, |
84 REQUERY_EVERY_X_GAMELOOPS = 60, ///< How often do we requery in time? |
|
85 REFRESH_GAMEINFO_X_REQUERIES = 50, ///< Refresh the game info itself after REFRESH_GAMEINFO_X_REQUERIES * REQUERY_EVERY_X_GAMELOOPS game loops |
89 }; |
86 }; |
90 |
87 |
91 /** Requeries the (game) servers we have not gotten a reply from */ |
88 /** Requeries the (game) servers we have not gotten a reply from */ |
92 void NetworkGameListRequery() |
89 void NetworkGameListRequery() |
93 { |
90 { |
94 static uint8 requery_cnt = 0; |
91 static uint8 requery_cnt = 0; |
95 |
92 |
96 if (_stop_requerying || ++requery_cnt < REQUERY_EVERY_X_GAMELOOPS) return; |
93 if (++requery_cnt < REQUERY_EVERY_X_GAMELOOPS) return; |
97 |
|
98 requery_cnt = 0; |
94 requery_cnt = 0; |
99 _stop_requerying = true; |
|
100 |
95 |
101 struct in_addr ip; |
96 struct in_addr ip; |
102 NetworkGameList *item; |
97 NetworkGameList *item; |
103 |
98 |
104 for (item = _network_game_list; item != NULL; item = item->next) { |
99 for (item = _network_game_list; item != NULL; item = item->next) { |
105 if (item->online || item->retries >= MAX_GAME_LIST_REQUERY_COUNT) continue; |
100 item->retries++; |
|
101 if (item->retries < REFRESH_GAMEINFO_X_REQUERIES && (item->online || item->retries >= MAX_GAME_LIST_REQUERY_COUNT)) continue; |
106 |
102 |
107 ip.s_addr = item->ip; |
103 ip.s_addr = item->ip; |
108 |
104 |
109 /* item gets mostly zeroed by NetworkUDPQueryServer */ |
105 /* item gets mostly zeroed by NetworkUDPQueryServer */ |
110 uint8 retries = item->retries; |
106 uint8 retries = item->retries; |
111 NetworkUDPQueryServer(inet_ntoa(ip), item->port); |
107 NetworkUDPQueryServer(inet_ntoa(ip), item->port); |
112 item->retries = retries + 1; |
108 item->retries = (retries >= REFRESH_GAMEINFO_X_REQUERIES) ? 0 : retries; |
113 |
|
114 _stop_requerying = false; |
|
115 } |
109 } |
116 |
|
117 } |
110 } |
118 |
111 |
119 #endif /* ENABLE_NETWORK */ |
112 #endif /* ENABLE_NETWORK */ |