(svn r13669) [NoAI] -Fix: allow clients only to join non-AI controlled companies in multiplayer noai
authortruebrain
Mon, 30 Jun 2008 21:31:23 +0000
branchnoai
changeset 11111 1b984dab8cec
parent 11110 8e553098ad05
child 11126 72d4c9314c72
(svn r13669) [NoAI] -Fix: allow clients only to join non-AI controlled companies in multiplayer
src/network/core/config.h
src/network/network_client.cpp
src/network/network_gui.cpp
src/network/network_server.cpp
src/network/network_type.h
--- a/src/network/core/config.h	Mon Jun 30 21:27:53 2008 +0000
+++ b/src/network/core/config.h	Mon Jun 30 21:31:23 2008 +0000
@@ -20,7 +20,7 @@
 	SEND_MTU                      = 1460, ///< Number of bytes we can pack in a single packet
 
 	NETWORK_GAME_INFO_VERSION     =    4, ///< What version of game-info do we use?
-	NETWORK_COMPANY_INFO_VERSION  =    4, ///< What version of company info is this?
+	NETWORK_COMPANY_INFO_VERSION  =    5, ///< What version of company info is this?
 	NETWORK_MASTER_SERVER_VERSION =    1, ///< What version of master-server-protocol do we use?
 
 	NETWORK_NAME_LENGTH           =   80, ///< The maximum length of the server name and map name, in bytes including '\0'
--- a/src/network/network_client.cpp	Mon Jun 30 21:27:53 2008 +0000
+++ b/src/network/network_client.cpp	Mon Jun 30 21:31:23 2008 +0000
@@ -376,6 +376,7 @@
 		_network_player_info[current].income           = p->Recv_uint64();
 		_network_player_info[current].performance      = p->Recv_uint16();
 		_network_player_info[current].use_password     = p->Recv_bool();
+		_network_player_info[current].ai               = p->Recv_bool();
 		for (i = 0; i < NETWORK_VEHICLE_TYPES; i++)
 			_network_player_info[current].num_vehicle[i] = p->Recv_uint16();
 		for (i = 0; i < NETWORK_STATION_TYPES; i++)
--- a/src/network/network_gui.cpp	Mon Jun 30 21:27:53 2008 +0000
+++ b/src/network/network_gui.cpp	Mon Jun 30 21:31:23 2008 +0000
@@ -988,7 +988,7 @@
 		int y = NET_PRC__OFFSET_TOP_WIDGET_COMPANY, pos;
 
 		/* Join button is disabled when no company is selected */
-		this->SetWidgetDisabledState(NLWW_JOIN, this->company == INVALID_PLAYER);
+		this->SetWidgetDisabledState(NLWW_JOIN, this->company == INVALID_PLAYER || _network_player_info[company].ai);
 		/* Cannot start new company if there are too many */
 		this->SetWidgetDisabledState(NLWW_NEW, gi->companies_on >= gi->companies_max);
 		/* Cannot spectate if there are too many spectators */
--- a/src/network/network_server.cpp	Mon Jun 30 21:27:53 2008 +0000
+++ b/src/network/network_server.cpp	Mon Jun 30 21:31:23 2008 +0000
@@ -108,6 +108,7 @@
 
 		/* Send 1 if there is a passord for the company else send 0 */
 		p->Send_bool(!StrEmpty(_network_player_info[player->index].password));
+		p->Send_bool(_network_player_info[player->index].ai);
 
 		for (i = 0; i < NETWORK_VEHICLE_TYPES; i++) {
 			p->Send_uint16(_network_player_info[player->index].num_vehicle[i]);
@@ -679,7 +680,7 @@
 			}
 			break;
 		default: /* Join another company (companies 1-8 (index 0-7)) */
-			if (!IsValidPlayer(playas)) {
+			if (!IsValidPlayer(playas) || !IsHumanPlayer(playas)) {
 				SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_PLAYER_MISMATCH);
 				return;
 			}
@@ -1335,6 +1336,7 @@
 		_network_player_info[p->index].company_value = p->old_economy[0].company_value;
 		_network_player_info[p->index].money = p->player_money;
 		_network_player_info[p->index].performance = p->old_economy[0].performance_history;
+		_network_player_info[p->index].ai = p->is_ai;
 	}
 
 	// Go through all vehicles and count the type of vehicles
--- a/src/network/network_type.h	Mon Jun 30 21:27:53 2008 +0000
+++ b/src/network/network_type.h	Mon Jun 30 21:31:23 2008 +0000
@@ -47,6 +47,7 @@
 	uint16 num_station[NETWORK_STATION_TYPES];      ///< How many stations are there of this type?
 	char players[NETWORK_PLAYERS_LENGTH];           ///< The players that control this company (Name1, name2, ..)
 	uint16 months_empty;                            ///< How many months the company is empty
+	bool ai;                                        ///< Is this company an AI
 };
 
 struct NetworkClientInfo {