(svn r1108) -Fix: [Network] Fixed problem around slow clients:
authortruelight
Wed, 15 Dec 2004 21:13:52 +0000
changeset 670 d164965bb35a
parent 669 2d332f6e59f0
child 671 6f1d8c908156
(svn r1108) -Fix: [Network] Fixed problem around slow clients:
They joined, they got the map, but it took some time before the new
player was created. In this time a player could do stuff, causing a
player-id-mismatch, and the player was kicked out. Now a player get's a
nice GUI which says: registering.. When that is gone, the player is
joined and can play safely. Tnx to Moriarty for bugging me with this bug ;)
lang/english.txt
main_gui.c
network.h
network_client.c
network_gui.c
players.c
--- a/lang/english.txt	Wed Dec 15 20:24:26 2004 +0000
+++ b/lang/english.txt	Wed Dec 15 21:13:52 2004 +0000
@@ -1303,6 +1303,7 @@
 STR_NETWORK_CONNECTING_3					:{BLACK}(3/6) Waiting..
 STR_NETWORK_CONNECTING_4					:{BLACK}(4/6) Downloading map..
 STR_NETWORK_CONNECTING_5					:{BLACK}(5/6) Processing data..
+STR_NETWORK_CONNECTING_6					:{BLACK}(6/6) Registering..
 
 STR_NETWORK_CONNECTING_SPECIAL_1				:{BLACK}Fetching game info..
 STR_NETWORK_CONNECTING_SPECIAL_2				:{BLACK}Fetching company info..
--- a/main_gui.c	Wed Dec 15 20:24:26 2004 +0000
+++ b/main_gui.c	Wed Dec 15 21:13:52 2004 +0000
@@ -2229,7 +2229,7 @@
 			DrawSprite(SPR_OTTD_T, off_x +  34, 50);
 			DrawSprite(SPR_OTTD_T, off_x +  65, 50);
 			DrawSprite(SPR_OTTD_D, off_x +  96, 50);
-			
+
 			/*
 			DrawSprite(SPR_OTTD_R, off_x + 119, 50);
 			DrawSprite(SPR_OTTD_A, off_x + 148, 50);
@@ -2323,8 +2323,8 @@
 			ShowBuildRailToolbar(_last_built_railtype, 4);
 			break;
 
-		case 'L': 
-			ShowTerraformToolbar(); 
+		case 'L':
+			ShowTerraformToolbar();
 			break;
 
 		case 'X':
@@ -2332,9 +2332,9 @@
 			MarkWholeScreenDirty();
 			break;
 
-		case WKC_BACKQUOTE: 
-			IConsoleSwitch(); 
-			e->keypress.cont=false; 
+		case WKC_BACKQUOTE:
+			IConsoleSwitch();
+			e->keypress.cont=false;
 			break;
 
 #ifdef ENABLE_NETWORK
@@ -2356,6 +2356,7 @@
 
 
 void ShowSelectGameWindow();
+extern void ShowJoinStatusWindowAfterJoin();
 
 void SetupColorsAndInitialWindow()
 {
@@ -2405,6 +2406,10 @@
 
 		WP(w,def_d).data_1 = -1280;
 
+		/* Bring joining GUI to front till the client is really joined */
+		if (_networking && !_network_server)
+			ShowJoinStatusWindowAfterJoin();
+
 		break;
 	case GM_EDITOR:
 		w = AllocateWindow(0, 0, width, height, MainWindowWndProc, 0, NULL);
--- a/network.h	Wed Dec 15 20:24:26 2004 +0000
+++ b/network.h	Wed Dec 15 21:13:52 2004 +0000
@@ -109,6 +109,7 @@
 	NETWORK_JOIN_STATUS_WAITING,
 	NETWORK_JOIN_STATUS_DOWNLOADING,
 	NETWORK_JOIN_STATUS_PROCESSING,
+	NETWORK_JOIN_STATUS_REGISTERING,
 
 	NETWORK_JOIN_STATUS_GETTING_COMPANY_INFO,
 } NetworkJoinStatus;
--- a/network_client.c	Wed Dec 15 20:24:26 2004 +0000
+++ b/network_client.c	Wed Dec 15 21:13:52 2004 +0000
@@ -487,8 +487,6 @@
 		}
 		_opt_mod_ptr = &_opt;
 
-		DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0);
-
 		// Say we received the map and loaded it correctly!
 		SEND_COMMAND(PACKET_CLIENT_MAP_OK)();
 
@@ -498,6 +496,7 @@
 			if (_network_playas == OWNER_SPECTATOR) {
 				// The client wants to be a spectator..
 				_local_player = OWNER_SPECTATOR;
+				DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0);
 			} else {
 				// send a command to make a new player
 				_local_player = 0;
--- a/network_gui.c	Wed Dec 15 20:24:26 2004 +0000
+++ b/network_gui.c	Wed Dec 15 21:13:52 2004 +0000
@@ -1271,6 +1271,15 @@
 	AllocateWindowDesc(&_network_join_status_window_desc);
 }
 
+void ShowJoinStatusWindowAfterJoin()
+{
+	/* This is a special instant of ShowJoinStatusWindow, because
+	    it is opened after the map is loaded, but the client maybe is not
+	    done registering itself to the server */
+	DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0);
+	_network_join_status = NETWORK_JOIN_STATUS_REGISTERING;
+	AllocateWindowDesc(&_network_join_status_window_desc);
+}
 
 
 
--- a/players.c	Wed Dec 15 20:24:26 2004 +0000
+++ b/players.c	Wed Dec 15 21:13:52 2004 +0000
@@ -643,6 +643,13 @@
 	switch(p1 & 0xff) {
 	case 0: // make new player
 		p = DoStartupNewPlayer(false);
+
+#ifdef ENABLE_NETWORK
+		if (_networking && !_network_server && _local_player == OWNER_SPECTATOR)
+			/* In case we are a client joining a server... */
+			DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0);
+#endif /* ENABLE_NETWORK */
+
 		if (p != NULL) {
 			if (_local_player == OWNER_SPECTATOR) {
 				_local_player = p->index;