File diff r5072:39de6c66b72d → r5073:59dc96582bd4
players.c
Show inline comments
 
@@ -839,53 +839,60 @@ int32 CmdPlayerCtrl(TileIndex tile, uint
 
		/* Delete multiplayer progress bar */
 
		DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0);
 

	
 
		p = DoStartupNewPlayer(false);
 

	
 
		/* A new player could not be created, revert to being a spectator */
 
		if (p == NULL) {
 
#ifdef ENABLE_NETWORK
 
			if (_network_server) {
 
				NetworkClientInfo *ci = &_network_client_info[cid];
 
				ci->client_playas = PLAYER_SPECTATOR;
 
				NetworkUpdateClientInfo(ci->client_index);
 
			} else
 
#endif /* ENABLE_NETWORK */
 
			{
 
				_local_player = _network_playas = PLAYER_SPECTATOR;
 
			}
 
			break;
 
		}
 

	
 
		/* This is the joining client who wants a new company */
 
		if (_local_player != _network_playas) {
 
			assert(_local_player == PLAYER_SPECTATOR && _network_playas == p->index);
 
			_local_player = p->index;
 
			DoCommandP(0, (_patches.autorenew << 15 ) | (_patches.autorenew_months << 16) | 4, _patches.autorenew_money, NULL, CMD_SET_AUTOREPLACE);
 

	
 
			MarkWholeScreenDirty();
 
		}
 

	
 
		/* Now that we have a new player, broadcast its autorenew settings to
 
		 * all clients so everything is in sync */
 
		DoCommand(0,
 
			(_patches.autorenew << 15 ) | (_patches.autorenew_months << 16) | 4,
 
			_patches.autorenew_money,
 
			DC_EXEC,
 
			CMD_SET_AUTOREPLACE
 
		);
 

	
 
#ifdef ENABLE_NETWORK
 
		if (_network_server) {
 
			/* XXX - UGLY! p2 (pid) is mis-used to fetch the client-id, done at
 
			 * server-side in network_server.c:838, function
 
			 * DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND) */
 
			NetworkClientInfo *ci = &_network_client_info[cid];
 
			ci->client_playas = p->index;
 
			NetworkUpdateClientInfo(ci->client_index);
 

	
 
			if (IsValidPlayer(ci->client_playas)) {
 
				PlayerID player_backup = _local_player;
 
				_network_player_info[p->index].months_empty = 0;
 

	
 
				/* XXX - When a client joins, we automatically set its name to the
 
				 * player's name (for some reason). As it stands now only the server
 
				 * knows the client's name, so it needs to send out a "broadcast" to
 
				 * do this. To achieve this we send a network command. However, it
 
				 * uses _local_player to execute the command as.  To prevent abuse
 
				 * (eg. only yourself can change your name/company), we 'cheat' by
 
				 * impersonation _local_player as the server. Not the best solution;
 
				 * but it works.
 
				 * TODO: Perhaps this could be improved by when the client is ready
 
				 * with joining to let it send itself the command, and not the server?
 
				 * For example in network_client.c:534? */