From 4e3652f3379edf991c8804f4bfc20c4a9d9e3c4d Mon Sep 17 00:00:00 2001 From: rubidium Date: Thu, 8 Feb 2007 10:19:03 +0000 Subject: [PATCH] (svn r8625) [0.5] -Backport from trunk (8253, 8273, 8497, 8520 + 8542): -Codechange: Be more strict about language generation and fail any languages not having the mandatory ##name, ##ownname and ##isocode pragma's. -Fix: return value from clamp was ignored -Codechange: Increase the size of the sound/video/music-drivers to 32 bytes (instead of 16) so their actual parameters can be passed. Sound has for example 'bufsize' and 'hz'. -Fix/Feature: requery gameservers that did not respond to their first query. --- misc_gui.c | 2 +- network.c | 1 + network.h | 1 + network_gamelist.c | 39 +++++++++++++++++++++++++++++++++++++++ network_gamelist.h | 1 + openttd.c | 14 +++++++------- strgen/strgen.c | 8 ++++++-- variables.h | 2 +- 8 files changed, 57 insertions(+), 11 deletions(-) diff --git a/misc_gui.c b/misc_gui.c index 0e5e503e20..93ee8fa200 100644 --- a/misc_gui.c +++ b/misc_gui.c @@ -1822,7 +1822,7 @@ static void CheatsWndProc(Window *w, WindowEvent *e) /* Increase or decrease the value and clamp it to extremes */ value += (x >= 30) ? step : -step; - clamp(value, ce->min, ce->max); + value = clamp(value, ce->min, ce->max); // take whatever the function returns value = ce->proc(value, (x >= 30) ? 1 : -1); diff --git a/network.c b/network.c index a41b3a2cea..d8bf3c233f 100644 --- a/network.c +++ b/network.c @@ -1267,6 +1267,7 @@ void NetworkUDPGameLoop(void) } else if (_udp_client_socket != INVALID_SOCKET) { NetworkUDPReceive(_udp_client_socket); if (_network_udp_broadcast > 0) _network_udp_broadcast--; + NetworkGameListRequery(); } } diff --git a/network.h b/network.h index 5453658e42..893bbe3b53 100644 --- a/network.h +++ b/network.h @@ -130,6 +130,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/network_gamelist.c b/network_gamelist.c index bcc75ad7e4..5265f08d4b 100644 --- a/network_gamelist.c +++ b/network_gamelist.c @@ -6,6 +6,10 @@ #include "debug.h" #include "network_data.h" #include "newgrf_config.h" +#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 @@ -39,6 +43,7 @@ NetworkGameList *NetworkGameListAddItem(uint32 ip, uint16 port) DEBUG(net, 4) ("[NET][GameList] Added server to list"); UpdateNetworkGameWindow(false); + _stop_requerying = false; return item; } @@ -71,4 +76,38 @@ void NetworkGameListRemoveItem(NetworkGameList *remove) } } +enum { + MAX_GAME_LIST_REQUERY_COUNT = 5, + REQUERY_EVERY_X_GAMELOOPS = 60, +}; + +/** Requeries the (game) servers we have not gotten a reply from */ +void NetworkGameListRequery(void) +{ + static uint8 requery_cnt = 0; + struct in_addr ip; + NetworkGameList *item; + + if (_stop_requerying || ++requery_cnt < REQUERY_EVERY_X_GAMELOOPS) return; + + requery_cnt = 0; + _stop_requerying = true; + + for (item = _network_game_list; item != NULL; item = item->next) { + uint8 retries; + + if (item->online || item->retries >= MAX_GAME_LIST_REQUERY_COUNT) continue; + + ip.s_addr = item->ip; + + /* item gets mostly zeroed by NetworkUDPQueryServer */ + retries = item->retries; + NetworkUDPQueryServer(inet_ntoa(ip), item->port); + item->retries = retries + 1; + + _stop_requerying = false; + } + +} + #endif /* ENABLE_NETWORK */ diff --git a/network_gamelist.h b/network_gamelist.h index c1a1a09042..7914f05cd7 100644 --- a/network_gamelist.h +++ b/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 */ diff --git a/openttd.c b/openttd.c index f4804dee99..10dc031cef 100644 --- a/openttd.c +++ b/openttd.c @@ -141,7 +141,7 @@ static void showhelp(void) "\n" "Command line options:\n" " -v drv = Set video driver (see below)\n" - " -s drv = Set sound driver (see below)\n" + " -s drv = Set sound driver (see below) (param bufsize,hz)\n" " -m drv = Set music driver (see below)\n" " -r res = Set resolution (for instance 800x600)\n" " -h = Display this help text\n" @@ -326,7 +326,7 @@ int ttd_main(int argc, char *argv[]) MyGetOptData mgo; int i; const char *optformat; - char musicdriver[16], sounddriver[16], videodriver[16]; + char musicdriver[32], sounddriver[32], videodriver[32]; int resolution[2] = {0,0}; Year startyear = INVALID_YEAR; uint generation_seed = GENERATE_NEW_SEED; @@ -334,7 +334,7 @@ int ttd_main(int argc, char *argv[]) bool network = false; char *network_conn = NULL; - musicdriver[0] = sounddriver[0] = videodriver[0] = 0; + musicdriver[0] = sounddriver[0] = videodriver[0] = '\0'; _game_mode = GM_MENU; _switch_mode = SM_MENU; @@ -410,10 +410,10 @@ int ttd_main(int argc, char *argv[]) LoadFromHighScore(); // override config? - if (musicdriver[0]) ttd_strlcpy(_ini_musicdriver, musicdriver, sizeof(_ini_musicdriver)); - if (sounddriver[0]) ttd_strlcpy(_ini_sounddriver, sounddriver, sizeof(_ini_sounddriver)); - if (videodriver[0]) ttd_strlcpy(_ini_videodriver, videodriver, sizeof(_ini_videodriver)); - if (resolution[0]) { _cur_resolution[0] = resolution[0]; _cur_resolution[1] = resolution[1]; } + if (musicdriver[0] != '\0') ttd_strlcpy(_ini_musicdriver, musicdriver, sizeof(_ini_musicdriver)); + if (sounddriver[0] != '\0') ttd_strlcpy(_ini_sounddriver, sounddriver, sizeof(_ini_sounddriver)); + if (videodriver[0] != '\0') ttd_strlcpy(_ini_videodriver, videodriver, sizeof(_ini_videodriver)); + if (resolution[0] != 0) { _cur_resolution[0] = resolution[0]; _cur_resolution[1] = resolution[1]; } if (startyear != INVALID_YEAR) _patches_newgame.starting_year = startyear; if (generation_seed != GENERATE_NEW_SEED) _patches_newgame.generation_seed = generation_seed; diff --git a/strgen/strgen.c b/strgen/strgen.c index baa348e4f6..bc11c0576f 100644 --- a/strgen/strgen.c +++ b/strgen/strgen.c @@ -910,12 +910,12 @@ static void ParseFile(const char *file, bool english) _file = file; - // For each new file we parse, reset the genders. + /* For each new file we parse, reset the genders, and language codes */ _numgenders = 0; + _lang_name[0] = _lang_ownname[0] = _lang_isocode[0] = '\0'; // TODO:!! We can't reset the cases. In case the translated strings // derive some strings from english.... - in = fopen(file, "r"); if (in == NULL) fatal("Cannot open file"); _cur_line = 1; @@ -925,6 +925,10 @@ static void ParseFile(const char *file, bool english) _cur_line++; } fclose(in); + + if (_lang_name[0] == '\0' || _lang_ownname[0] == '\0' || _lang_isocode[0] == '\0') { + fatal("Language must include ##name, ##ownname and ##isocode"); + } } diff --git a/variables.h b/variables.h index 02f9e8913d..36316ddc01 100644 --- a/variables.h +++ b/variables.h @@ -319,7 +319,7 @@ VARDEF byte _get_z_hint; // used as a hint to getslopez to return the right heig VARDEF Vehicle *_place_clicked_vehicle; -VARDEF char _ini_videodriver[16], _ini_musicdriver[16], _ini_sounddriver[16]; +VARDEF char _ini_videodriver[32], _ini_musicdriver[32], _ini_sounddriver[32]; // Used for dynamic language support typedef struct {