Changeset - r662:d42c2c6d320b
[Not reviewed]
master
0 5 0
truelight - 19 years ago 2004-12-15 15:19:51
truelight@openttd.org
(svn r1096) -Fix: [Network] PlayAs is now registered correctly
-Codewise: [Network] Cleaned some code, removed some comment, changed
some wrong comment
5 files changed with 20 insertions and 17 deletions:
0 comments (0 inline, 0 general)
network.c
Show inline comments
 
@@ -401,13 +401,13 @@ static ClientState *AllocClient(SOCKET s
 
	memset(cs, 0, sizeof(*cs));
 
	cs->socket = s;
 
	cs->last_frame = 0;
 
	cs->quited = false;
 

	
 
	if (_network_server) {
 
		ci = &_network_client_info[client_no];
 
		ci = DEREF_CLIENT_INFO(cs);
 
		memset(ci, 0, sizeof(*ci));
 

	
 
		cs->index = _network_client_index++;
 
		ci->client_index = cs->index;
 
		ci->join_date = _date;
 

	
 
@@ -697,12 +697,13 @@ void NetworkInitialize(void)
 
{
 
	ClientState *cs;
 

	
 
	_local_command_queue = NULL;
 

	
 
	// Clean all client-sockets
 
	memset(_clients, 0, sizeof(_clients));
 
	for (cs = _clients; cs != &_clients[MAX_CLIENTS]; cs++) {
 
		cs->socket = INVALID_SOCKET;
 
		cs->status = STATUS_INACTIVE;
 
		cs->command_queue = NULL;
 
	}
 

	
network.h
Show inline comments
 
@@ -24,13 +24,12 @@
 
#define MAX_CLIENTS (MAX_PLAYERS + 3)
 

	
 

	
 
// Do not change this next line. It should _ALWAYS_ be MAX_CLIENTS + 1
 
#define MAX_CLIENT_INFO (MAX_CLIENTS + 1)
 

	
 
#define NETWORK_DISCOVER_PORT 3978
 
#define NETWORK_DEFAULT_PORT 3979
 

	
 
#define MAX_INTERFACES 9
 

	
 

	
 
// How many vehicle/station types we put over the network
network_client.c
Show inline comments
 
@@ -62,13 +62,13 @@ DEF_CLIENT_SEND_COMMAND(PACKET_CLIENT_JO
 
	_network_join_status = NETWORK_JOIN_STATUS_AUTHORIZING;
 
	InvalidateWindow(WC_NETWORK_STATUS_WINDOW, 0);
 

	
 
	p = NetworkSend_Init(PACKET_CLIENT_JOIN);
 
	NetworkSend_string(p, _openttd_revision);
 
	NetworkSend_string(p, _network_player_name); // Player name
 
	NetworkSend_uint8(p, _network_playas); // Password
 
	NetworkSend_uint8(p, _network_playas); // PlayAs
 
	NetworkSend_uint8(p, NETLANG_ANY); // Language
 
	NetworkSend_string(p, _network_unique_id);
 
	NetworkSend_Packet(p, MY_CLIENT);
 
}
 

	
 
DEF_CLIENT_SEND_COMMAND_PARAM(PACKET_CLIENT_PASSWORD)(NetworkPasswordType type, const char *password)
 
@@ -314,41 +314,48 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER
 
//  as client we save this in NetworkClientInfo, linked via 'index'
 
//  which is always an unique number on a server.
 
DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_CLIENT_INFO)
 
{
 
	NetworkClientInfo *ci;
 
	uint16 index = NetworkRecv_uint16(p);
 
	byte playas = NetworkRecv_uint8(p);
 
	char name[NETWORK_NAME_LENGTH];
 
	char unique_id[NETWORK_NAME_LENGTH];
 

	
 
	NetworkRecv_string(p, name, sizeof(name));
 
	NetworkRecv_string(p, unique_id, sizeof(unique_id));
 

	
 
	/* Do we receive a change of data? Most likely we changed playas */
 
	if (index == _network_own_client_index)
 
		_network_playas = playas;
 

	
 
	ci = NetworkFindClientInfoFromIndex(index);
 
	if (ci != NULL) {
 
		byte playas;
 
		char name[NETWORK_NAME_LENGTH];
 

	
 
		playas = NetworkRecv_uint8(p);
 
		NetworkRecv_string(p, name, sizeof(name));
 

	
 
		if (playas == ci->client_playas && strcmp(name, ci->client_name) != 0) {
 
			// Client name changed, display the change
 
			NetworkTextMessage(NETWORK_ACTION_NAME_CHANGE, 1, ci->client_name, name);
 
		} else if (playas != ci->client_playas) {
 
			// The player changed from client-player..
 
			// Do not display that for now
 
		}
 

	
 
		ci->client_playas = playas;
 
		ttd_strlcpy(ci->client_name, name, sizeof(ci->client_name));
 

	
 
		return NETWORK_RECV_STATUS_OKAY;
 
	}
 

	
 
	// We don't have this index yet, find an empty index, and put the data there
 
	ci = NetworkFindClientInfoFromIndex(NETWORK_EMPTY_INDEX);
 
	if (ci != NULL) {
 
		ci->client_index = index;
 
		ci->client_playas = NetworkRecv_uint8(p);
 
		NetworkRecv_string(p, ci->client_name, sizeof(ci->client_name));
 
		NetworkRecv_string(p, ci->unique_id, sizeof(ci->unique_id));
 
		ci->client_playas = playas;
 

	
 
		ttd_strlcpy(ci->client_name, name, sizeof(ci->client_name));
 
		ttd_strlcpy(ci->unique_id, unique_id, sizeof(ci->unique_id));
 

	
 
		return NETWORK_RECV_STATUS_OKAY;
 
	}
 

	
 
	// Here the program should never ever come.....
 
	return NETWORK_RECV_STATUS_MALFORMED_PACKET;
 
}
network_server.c
Show inline comments
 
@@ -775,13 +775,13 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT
 
	if (cp->cmd != CMD_PLAYER_CTRL && ci->client_playas-1 != cp->player) {
 
		// The player did a command with the wrong player_id.. bad!!
 
		SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_PLAYER_MISMATCH);
 
		return;
 
	}
 
	if (cp->cmd == CMD_PLAYER_CTRL) {
 
		// UGLY! p1 is mis-used to get the client-id in CmdPlayerCtrl
 
		// UGLY! p2 is mis-used to get the client-id in CmdPlayerCtrl
 
		cp->p2 = cs - _clients;
 
	}
 

	
 

	
 
	// The frame can be executed in the same frame as the next frame-packet
 
	//  That frame just before that frame is saved in _frame_counter_max
players.c
Show inline comments
 
@@ -659,24 +659,20 @@ int32 CmdPlayerCtrl(int x, int y, uint32
 
				if (ci->client_playas != 0 && ci->client_playas <= MAX_PLAYERS) {
 
					memcpy(_decode_parameters, ci->client_name, 32);
 
					/* XXX - What are the consequents of this? It is needed, but is it bad? */
 
					_docommand_recursive = 0;
 
					DoCommandP(0, ci->client_playas-1, 0, NULL, CMD_CHANGE_PRESIDENT_NAME | CMD_MSG(STR_700D_CAN_T_CHANGE_PRESIDENT));
 
				}
 
			} else {
 
				_network_playas = p->index + 1;
 
			}
 
		} else {
 
			if (_network_server) {
 
				NetworkClientInfo *ci;
 
				// UGLY! p2 is mis-used to fetch the client-id
 
				ci = &_network_client_info[p2];
 
				ci->client_playas = OWNER_SPECTATOR;
 
				NetworkUpdateClientInfo(ci->client_index);
 
			} else {
 
				_network_playas = OWNER_SPECTATOR;
 
			}
 
#endif /* ENABLE_NETWORK */
 
		}
 
		break;
 
	case 1: // make new ai player
 
		DoStartupNewPlayer(true);
0 comments (0 inline, 0 general)