Changeset - r4858:dff82c94b2ec
[Not reviewed]
master
0 1 0
Darkvater - 18 years ago 2006-10-15 23:35:26
darkvater@openttd.org
(svn r6784) -Codechange: Change invalid PlayerID type into ClientID which it is in CmdPlayerCtrl
1 file changed with 6 insertions and 4 deletions:
0 comments (0 inline, 0 general)
players.c
Show inline comments
 
@@ -812,27 +812,29 @@ int32 CmdSetAutoReplace(TileIndex tile, 
 
 * on the server itself. First of all this is unbelievably ugly; second of all, well,
 
 * it IS ugly! <b>Someone fix this up :)</b> So where to fix?@n
 
 * @arg - network_server.c:838 DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND)@n
 
 * @arg - network_client.c:536 DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_MAP) from where the map has been received
 
 */
 
int32 CmdPlayerCtrl(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 
{
 
	if (flags & DC_EXEC) _current_player = OWNER_NONE;
 

	
 
	switch (p1) {
 
	case 0: { /* Create a new player */
 
		Player *p;
 
		PlayerID pid = p2;
 
		uint16 cid = p2; // ClientID
 

	
 
		if (!(flags & DC_EXEC) || !IsValidPlayer(pid)) return 0;
 
		/* ClientID would be valid up to MAX_CLIENT_INFO, but as it has to be a
 
		 * new player, its valid range is restricted to that of players */
 
		if (!(flags & DC_EXEC) || !IsValidPlayer((PlayerID)cid)) return 0;
 

	
 
		p = DoStartupNewPlayer(false);
 

	
 
#ifdef ENABLE_NETWORK
 
		if (_networking && !_network_server && _local_player == PLAYER_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 == PLAYER_SPECTATOR) {
 
@@ -842,25 +844,25 @@ int32 CmdPlayerCtrl(TileIndex tile, uint
 
						_network_playas != PLAYER_SPECTATOR) {
 
						_local_player = p->index;
 
					MarkWholeScreenDirty();
 
				}
 
			} else if (p->index == _local_player) {
 
				DoCommandP(0, (_patches.autorenew << 15 ) | (_patches.autorenew_months << 16) | 4, _patches.autorenew_money, NULL, 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[pid];
 
				NetworkClientInfo *ci = &_network_client_info[cid];
 
				ci->client_playas = p->index + 1;
 
				NetworkUpdateClientInfo(ci->client_index);
 

	
 
				if (ci->client_playas != 0 && ci->client_playas <= MAX_PLAYERS) {
 
					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
 
@@ -872,25 +874,25 @@ int32 CmdPlayerCtrl(TileIndex tile, uint
 
					 * For example in network_client.c:534? */
 
					_cmd_text = ci->client_name;
 
					_local_player = ci->client_playas - 1;
 
					NetworkSend_Command(0, 0, 0, CMD_CHANGE_PRESIDENT_NAME, NULL);
 
					_local_player = player_backup;
 
				}
 
			}
 
		} else if (_network_server) {
 
			// Creating player failed, defer client to spectator
 
			/* 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[pid];
 
			NetworkClientInfo *ci = &_network_client_info[cid];
 
			ci->client_playas = PLAYER_SPECTATOR;
 
			NetworkUpdateClientInfo(ci->client_index);
 
#endif /* ENABLE_NETWORK */
 
		}
 
	} break;
 

	
 
	case 1: /* Make a new AI player */
 
		if (!(flags & DC_EXEC)) return 0;
 

	
 
		DoStartupNewPlayer(true);
 
		break;
 

	
0 comments (0 inline, 0 general)