(svn r1093) -Fix: Hopefully fixed windows revision issues once and for all. Removed globalness of _openttd_revision and put all such ifdefs into one place. If server has a revision only the same revisions can join; if the server has no revision everyone can join. I reckon this should be a server-side option to allow people to join or not to join.
authordarkvater
Wed, 15 Dec 2004 00:31:08 +0000
changeset 659 a98c731921b4
parent 658 ed6a0ea93a6c
child 660 3d7c7ea950f2
(svn r1093) -Fix: Hopefully fixed windows revision issues once and for all. Removed globalness of _openttd_revision and put all such ifdefs into one place. If server has a revision only the same revisions can join; if the server has no revision everyone can join. I reckon this should be a server-side option to allow people to join or not to join.
console.c
network.c
network_client.c
network_gui.c
network_server.c
strings.c
ttd.c
ttd.h
ttd.vcproj
variables.h
win32.c
--- a/console.c	Tue Dec 14 21:56:01 2004 +0000
+++ b/console.c	Wed Dec 15 00:31:08 2004 +0000
@@ -229,6 +229,8 @@
 	}
 }
 
+extern const char _openttd_revision[];
+
 void IConsoleInit(void)
 {
 	uint i;
@@ -253,11 +255,7 @@
 		_iconsole_cbuffer[i] = 0;
 	}
 	IConsoleStdLibRegister();
-	#if defined(WITH_REV)
 	IConsolePrintF(13, "OpenTTD Game Console Revision 6 - %s", _openttd_revision);
-	#else
-	IConsolePrint(13, "OpenTTD Game Console Revision 6");
-	#endif
 	IConsolePrint(12, "---------------------------------");
 	IConsolePrint(12, "use \"help\" for more info");
 	IConsolePrint(12, "");
--- a/network.c	Tue Dec 14 21:56:01 2004 +0000
+++ b/network.c	Wed Dec 15 00:31:08 2004 +0000
@@ -783,6 +783,8 @@
 	return _networking;
 }
 
+extern const char _openttd_revision[];
+
 void NetworkInitGameInfo(void)
 {
 	NetworkClientInfo *ci;
--- a/network_client.c	Tue Dec 14 21:56:01 2004 +0000
+++ b/network_client.c	Wed Dec 15 00:31:08 2004 +0000
@@ -43,6 +43,8 @@
 	NetworkSend_Packet(p, MY_CLIENT);
 }
 
+extern const char _openttd_revision[];
+
 DEF_CLIENT_SEND_COMMAND(PACKET_CLIENT_JOIN)
 {
 	//
--- a/network_gui.c	Tue Dec 14 21:56:01 2004 +0000
+++ b/network_gui.c	Wed Dec 15 00:31:08 2004 +0000
@@ -68,24 +68,26 @@
 	}
 }
 
+extern const char _openttd_revision[];
+
 static void NetworkGameWindowWndProc(Window *w, WindowEvent *e)
 {
 	switch(e->event) {
 	case WE_PAINT: {
-		if (_selected_item == NULL)
-			w->disabled_state = (1<<17) | (1<<18);
-		else if (!_selected_item->online)
-			w->disabled_state = (1<<17); // Server offline, join button disabled
-		else if (_selected_item->info.clients_on == _selected_item->info.clients_max)
-			w->disabled_state = (1<<17); // Server full, join button disabled
-#ifdef WITH_REV
-		else if (strncmp(_selected_item->info.server_revision, _openttd_revision, NETWORK_REVISION_LENGTH - 1) != 0) {
-			if (strncmp(_selected_item->info.server_revision, "norev000", sizeof(_selected_item->info.server_revision)) != 0)
-				w->disabled_state = (1<<17); // Revision mismatch, join button disabled
+		w->disabled_state = 0;
+
+		if (_selected_item == NULL) {
+			SETBIT(w->disabled_state, 17); SETBIT(w->disabled_state, 18);
+		} else if (!_selected_item->online) {
+			SETBIT(w->disabled_state, 17); // Server offline, join button disabled
+		} else if (_selected_item->info.clients_on == _selected_item->info.clients_max) {
+			SETBIT(w->disabled_state, 17); // Server full, join button disabled
+
+			// revisions don't match, check if server has no revision; then allow connection
+		} else if (strncmp(_selected_item->info.server_revision, _openttd_revision, NETWORK_REVISION_LENGTH - 1) != 0) {
+			if (strncmp(_selected_item->info.server_revision, NOREV_STRING, sizeof(_selected_item->info.server_revision)) != 0)
+				SETBIT(w->disabled_state, 17); // Revision mismatch, join button disabled
 		}
-#endif
-		else
-			w->disabled_state = 0;
 
 		SetDParam(0, 0x00);
 		SetDParam(2, STR_NETWORK_LAN + _network_connection);
@@ -105,12 +107,8 @@
 			char servername[NETWORK_NAME_LENGTH];
 			const NetworkGameList *cur_item = _network_game_list;
 			while (cur_item != NULL) {
-#ifdef WITH_REV
 				bool compatible = (strncmp(cur_item->info.server_revision, _openttd_revision, NETWORK_REVISION_LENGTH - 1) == 0);
-#else
-				bool compatible = true; // We have no idea if we are compatible...
-#endif
-				if (strncmp(cur_item->info.server_revision, "norev000", sizeof(cur_item->info.server_revision)) == 0)
+				if (strncmp(cur_item->info.server_revision, NOREV_STRING, sizeof(cur_item->info.server_revision)) == 0)
 					compatible = true;
 
 				if (cur_item == _selected_item)
@@ -200,17 +198,15 @@
 
 			y+=2;
 
-#ifdef WITH_REV
 			if (strncmp(_selected_item->info.server_revision, _openttd_revision, NETWORK_REVISION_LENGTH - 1) != 0) {
-				if (strncmp(_selected_item->info.server_revision, "norev000", sizeof(_selected_item->info.server_revision)) != 0)
+				if (strncmp(_selected_item->info.server_revision, NOREV_STRING, sizeof(_selected_item->info.server_revision)) != 0)
 					DrawStringMultiCenter(360, y, STR_NETWORK_VERSION_MISMATCH, 2); // server mismatch
-			} else
-#endif
-			if (_selected_item->info.clients_on == _selected_item->info.clients_max)
+			} else if (_selected_item->info.clients_on == _selected_item->info.clients_max) {
 				// Show: server full, when clients_on == clients_max
 				DrawStringMultiCenter(360, y, STR_NETWORK_SERVER_FULL, 2); // server full
-			else if (_selected_item->info.use_password)
+			} else if (_selected_item->info.use_password)
 				DrawStringMultiCenter(360, y, STR_NETWORK_PASSWORD, 2); // password warning
+
 			y+=10;
 		}
 	}	break;
--- a/network_server.c	Tue Dec 14 21:56:01 2004 +0000
+++ b/network_server.c	Wed Dec 15 00:31:08 2004 +0000
@@ -563,6 +563,8 @@
 	SEND_COMMAND(PACKET_SERVER_COMPANY_INFO)(cs);
 }
 
+extern const char _openttd_revision[];
+
 DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_JOIN)
 {
 	char name[NETWORK_NAME_LENGTH];
@@ -576,10 +578,8 @@
 
 	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)
-	// Check if the client has WITH_REV enabled
-	if (strncmp("norev000", client_revision, sizeof(client_revision)) != 0) {
+	// Check if the client has revision control enabled
+	if (strncmp(NOREV_STRING, client_revision, sizeof(client_revision)) != 0) {
 		if (strncmp(_network_game_info.server_revision, client_revision, sizeof(_network_game_info.server_revision) - 1) != 0) {
 			// Different revisions!!
 			SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_WRONG_REVISION);
@@ -587,7 +587,6 @@
 			return;
 		}
 	}
-#endif
 
 	NetworkRecv_string(p, name, sizeof(name));
 	playas = NetworkRecv_uint8(p);
--- a/strings.c	Tue Dec 14 21:56:01 2004 +0000
+++ b/strings.c	Wed Dec 15 00:31:08 2004 +0000
@@ -20,6 +20,14 @@
 static uint _langtab_num[32]; // Offset into langpack offs
 static uint _langtab_start[32]; // Offset into langpack offs
 
+#if defined(WITH_REV)
+	extern const char _openttd_revision[];
+#elif defined(WITH_REV_HACK)
+	const char _openttd_revision[] = WITH_REV_HACK;
+#else
+	const char _openttd_revision[] = NOREV_STRING;
+#endif
+
 typedef byte *PlayerNameGeneratorProc(byte *buffr);
 
 typedef struct {
@@ -433,9 +441,7 @@
 				buff = FormatNoCommaNumber(buff, GetParamInt32());
 				break;
 			case 2: /* {REV} */
-#ifdef WITH_REV
 				buff = str_cat(buff, (const byte*)_openttd_revision);
-#endif
 				break;
 			case 3: { /* {SHORTCARGO} */
 				// Short description of cargotypes. Layout:
--- a/ttd.c	Tue Dec 14 21:56:01 2004 +0000
+++ b/ttd.c	Wed Dec 15 00:31:08 2004 +0000
@@ -28,11 +28,6 @@
 
 #include <stdarg.h>
 
-/* Define the _openttd_revision tag if it is not defined */
-#ifndef WITH_REV
-	const char _openttd_revision[] = "norev000";
-#endif
-
 void GameLoop();
 
 void IncreaseSpriteLRU();
--- a/ttd.h	Tue Dec 14 21:56:01 2004 +0000
+++ b/ttd.h	Wed Dec 15 00:31:08 2004 +0000
@@ -1,6 +1,7 @@
 #ifndef TTD_H
 #define TTD_H
 
+#define NOREV_STRING "norev000"
 // FIXME: Include only where really needed.
 // include sprites
 #include "table/sprites.h"
--- a/ttd.vcproj	Tue Dec 14 21:56:01 2004 +0000
+++ b/ttd.vcproj	Wed Dec 15 00:31:08 2004 +0000
@@ -453,10 +453,9 @@
 						BasicRuntimeChecks="3"/>
 				</FileConfiguration>
 			</File>
-                        <File
-                                RelativePath=".\md5.c">
-                        </File>
-
+			<File
+				RelativePath=".\md5.c">
+			</File>
 			<File
 				RelativePath="minilzo.c">
 				<FileConfiguration
@@ -577,9 +576,6 @@
 				</FileConfiguration>
 			</File>
 			<File
-				RelativePath=".\newgrf.c">
-			</File>
-			<File
 				RelativePath=".\network_client.c">
 			</File>
 			<File
@@ -589,10 +585,13 @@
 				RelativePath=".\network_gamelist.c">
 			</File>
 			<File
+				RelativePath=".\network_server.c">
+			</File>
+			<File
 				RelativePath=".\network_udp.c">
 			</File>
 			<File
-				RelativePath=".\network_server.c">
+				RelativePath=".\newgrf.c">
 			</File>
 			<File
 				RelativePath="oldloader.c">
@@ -1173,9 +1172,6 @@
 				RelativePath=".\network.h">
 			</File>
 			<File
-				RelativePath=".\newgrf.h">
-			</File>
-			<File
 				RelativePath=".\network_client.h">
 			</File>
 			<File
@@ -1188,10 +1184,13 @@
 				RelativePath=".\network_gamelist.h">
 			</File>
 			<File
+				RelativePath=".\network_server.h">
+			</File>
+			<File
 				RelativePath=".\network_udp.h">
 			</File>
 			<File
-				RelativePath=".\network_server.h">
+				RelativePath=".\newgrf.h">
 			</File>
 			<File
 				RelativePath="news.h">
--- a/variables.h	Tue Dec 14 21:56:01 2004 +0000
+++ b/variables.h	Wed Dec 15 00:31:08 2004 +0000
@@ -426,13 +426,6 @@
 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)
--- a/win32.c	Tue Dec 14 21:56:01 2004 +0000
+++ b/win32.c	Wed Dec 15 00:31:08 2004 +0000
@@ -15,11 +15,6 @@
 
 #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;
@@ -446,6 +441,8 @@
 	}
 }
 
+extern const char _openttd_revision[];
+
 static void MakeWindow(bool full_screen)
 {
 	_fullscreen = full_screen;
@@ -504,10 +501,9 @@
 			SetWindowPos(_wnd.main_wnd, 0, x, y, w, h, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
 		} else {
 			char Windowtitle[50] = "OpenTTD ";
-			#ifdef WITH_REV
-				// also show revision number/release in window title
-				strncat(Windowtitle, _openttd_revision, sizeof(Windowtitle)-(strlen(Windowtitle) + 1));
-			#endif
+			// also show revision number/release in window title
+			strncat(Windowtitle, _openttd_revision, sizeof(Windowtitle)-(strlen(Windowtitle) + 1));
+
 			_wnd.main_wnd = CreateWindow("TTD", Windowtitle, style, x, y, w, h, 0, 0, _inst, 0);
 			if (_wnd.main_wnd == NULL)
 				error("CreateWindow failed");