From b6c74c1c2077ce0c4dcd525890ea739a807f1508 Mon Sep 17 00:00:00 2001 From: truelight Date: Tue, 14 Dec 2004 20:27:00 +0000 Subject: [PATCH] (svn r1090) -Fix: Made the _openttd_revision variable global, and with that hopefully killed the windows-revision problem. If WITH_REV is defined, for both Windows as *nix system _openttd_revision is filled with normal info, else _openttd_revision is set to 'norev000' -Fix: Small possible server-crash --- console.c | 14 +++----------- network.c | 10 ---------- network_client.c | 10 ---------- network_gui.c | 9 --------- network_server.c | 5 ++++- strings.c | 9 --------- ttd.c | 7 ++++++- variables.h | 7 +++++++ win32.c | 8 ++++++-- 9 files changed, 26 insertions(+), 53 deletions(-) diff --git a/console.c b/console.c index 211fb27b96..57f7c25bc6 100644 --- a/console.c +++ b/console.c @@ -232,14 +232,6 @@ static void IConsoleWndProc(Window* w, WindowEvent* e) void IConsoleInit(void) { uint i; -#ifdef WITH_REV_HACK - #define WITH_REV - const char _openttd_revision[] = WITH_REV_HACK; -#else - #if defined(WITH_REV) - extern char _openttd_revision[]; - #endif -#endif _iconsole_output_file = NULL; _iconsole_color_default = 1; _iconsole_color_error = 3; @@ -604,7 +596,7 @@ void IConsoleAliasExec(const char* cmdline, char* tokens[20], byte tokentypes[20 if (cmdline[i] == '+') { // all params seperated: "[param 1]" "[param 2]" t=1; - while ((tokens[t]!=NULL) && (t<20) && + while ((tokens[t]!=NULL) && (t<20) && ((tokentypes[t] == ICONSOLE_VAR_STRING) || (tokentypes[t] == ICONSOLE_VAR_UNKNOWN))) { int l2 = strlen(tokens[t]); *linestream = '"'; @@ -623,7 +615,7 @@ void IConsoleAliasExec(const char* cmdline, char* tokens[20], byte tokentypes[20 t=1; *linestream = '"'; linestream++; - while ((tokens[t]!=NULL) && (t<20) && + while ((tokens[t]!=NULL) && (t<20) && ((tokentypes[t] == ICONSOLE_VAR_STRING) || (tokentypes[t] == ICONSOLE_VAR_UNKNOWN))) { int l2 = strlen(tokens[t]); memcpy(linestream,tokens[t],l2); @@ -640,7 +632,7 @@ void IConsoleAliasExec(const char* cmdline, char* tokens[20], byte tokentypes[20 // one specific parameter: %A = [param 1] %B = [param 2] ... int l2; t = ((byte)cmdline[i]) - 64; - if ((t<20) && (tokens[t]!=NULL) && + if ((t<20) && (tokens[t]!=NULL) && ((tokentypes[t] == ICONSOLE_VAR_STRING) || (tokentypes[t] == ICONSOLE_VAR_UNKNOWN))) { l2 = strlen(tokens[t]); *linestream = '"'; diff --git a/network.c b/network.c index 836ccb6e01..c031051b6a 100644 --- a/network.c +++ b/network.c @@ -785,16 +785,6 @@ bool NetworkClientConnectGame(const byte* host, unsigned short port) void NetworkInitGameInfo(void) { -#ifdef WITH_REV_HACK - #define WITH_REV - const char _openttd_revision[] = WITH_REV_HACK; -#else - #if defined(WITH_REV) - extern char _openttd_revision[]; - #else - const char _openttd_revision[] = "norev000"; - #endif -#endif NetworkClientInfo *ci; ttd_strlcpy(_network_game_info.server_name, _network_server_name, sizeof(_network_game_info.server_name)); diff --git a/network_client.c b/network_client.c index dc512c545c..747464425d 100644 --- a/network_client.c +++ b/network_client.c @@ -56,16 +56,6 @@ DEF_CLIENT_SEND_COMMAND(PACKET_CLIENT_JOIN) // String: Unique id to find the player back in server-listing // -#ifdef WITH_REV_HACK - #define WITH_REV - const char _openttd_revision[] = WITH_REV_HACK; -#else - #if defined(WITH_REV) - extern char _openttd_revision[]; - #else - const char _openttd_revision[] = "norev000"; - #endif -#endif Packet *p; _network_join_status = NETWORK_JOIN_STATUS_AUTHORIZING; InvalidateWindow(WC_NETWORK_STATUS_WINDOW, 0); diff --git a/network_gui.c b/network_gui.c index 839e227ab6..2d39bcbf07 100644 --- a/network_gui.c +++ b/network_gui.c @@ -47,15 +47,6 @@ enum { static NetworkGameList *_selected_item = NULL; static int8 _selected_company_item = -1; -#ifdef WITH_REV_HACK - #define WITH_REV - const char _openttd_revision[] = WITH_REV_HACK; -#else - #ifdef WITH_REV - extern char _openttd_revision[]; - #endif -#endif - // Truncates a string to max_width (via GetStringWidth) and adds 3 dots // at the end of the name. static void NetworkTruncateString(char *name, const int max_width) diff --git a/network_server.c b/network_server.c index 35abd9ae11..cc0b6b4529 100644 --- a/network_server.c +++ b/network_server.c @@ -577,7 +577,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_JOIN) NetworkRecv_string(p, client_revision, sizeof(client_revision)); // Too bad, when WITH_REV is disabled, we can not compare the version. -#if defined(WITH_REV) || defined (WITH_REV_HACK) +#if defined(WITH_REV) // Check if the client has WITH_REV enabled if (strncmp("norev000", client_revision, sizeof(client_revision)) != 0) { if (strncmp(_network_game_info.server_revision, client_revision, sizeof(_network_game_info.server_revision) - 1) != 0) { @@ -1215,6 +1215,9 @@ void NetworkUpdateClientInfo(uint16 client_index) ci = NetworkFindClientInfoFromIndex(client_index); + if (ci == NULL) + return; + FOR_ALL_CLIENTS(cs) { SEND_COMMAND(PACKET_SERVER_CLIENT_INFO)(cs, ci); } diff --git a/strings.c b/strings.c index 3bc54dd715..14ed34ff04 100644 --- a/strings.c +++ b/strings.c @@ -20,15 +20,6 @@ static byte *_langpack; static uint _langtab_num[32]; // Offset into langpack offs static uint _langtab_start[32]; // Offset into langpack offs -#ifdef WITH_REV_HACK - #define WITH_REV - const char _openttd_revision[] = WITH_REV_HACK; -#else - #ifdef WITH_REV - extern const char _openttd_revision[]; - #endif -#endif - typedef byte *PlayerNameGeneratorProc(byte *buffr); typedef struct { diff --git a/ttd.c b/ttd.c index ea2bffc338..2339337d6d 100644 --- a/ttd.c +++ b/ttd.c @@ -28,6 +28,11 @@ #include +/* Define the _openttd_revision tag if it is not defined */ +#ifndef WITH_REV + const char _openttd_revision[] = "norev000"; +#endif + void GameLoop(); void IncreaseSpriteLRU(); @@ -645,7 +650,7 @@ int ttd_main(int argc, char* argv[]) // initialize the ingame console IConsoleInit(); IConsoleCmdExec("exec scripts/autoexec.scr 0"); - + InitPlayerRandoms(); #ifdef ENABLE_NETWORK diff --git a/variables.h b/variables.h index 667bd4a834..ad69bc3752 100644 --- a/variables.h +++ b/variables.h @@ -426,6 +426,13 @@ VARDEF int _debug_grf_level; VARDEF int _debug_ai_level; VARDEF int _debug_net_level; +/* Make the revision tag global */ +extern const char _openttd_revision[]; +#ifdef WITH_REV_HACK + /* Special rules for Windows */ + #define WITH_REV +#endif + void CDECL debug(const char *s, ...); #ifdef NO_DEBUG_MESSAGES #define DEBUG(name, level) diff --git a/win32.c b/win32.c index 2f82559a04..7177d72a8a 100644 --- a/win32.c +++ b/win32.c @@ -15,6 +15,11 @@ #define SMART_PALETTE_ANIM +/* Declare the revision tag for Windows */ +#ifdef WITH_REV_HACK + const char _openttd_revision[] = WITH_REV_HACK; +#endif + static struct { HWND main_wnd; HBITMAP dib_sect; @@ -499,9 +504,8 @@ static void MakeWindow(bool full_screen) SetWindowPos(_wnd.main_wnd, 0, x, y, w, h, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER); } else { char Windowtitle[50] = "OpenTTD "; - #ifdef WITH_REV_HACK + #ifdef WITH_REV // also show revision number/release in window title - extern const char _openttd_revision[]; strncat(Windowtitle, _openttd_revision, sizeof(Windowtitle)-(strlen(Windowtitle) + 1)); #endif _wnd.main_wnd = CreateWindow("TTD", Windowtitle, style, x, y, w, h, 0, 0, _inst, 0);