Changeset - r14988:e84b1f39bc47
[Not reviewed]
master
0 3 0
smatz - 14 years ago 2010-04-11 17:32:14
smatz@openttd.org
(svn r19610) -Codechange: rename STATUS_AUTH to STATUS_AUTHORIZED
3 files changed with 26 insertions and 26 deletions:
0 comments (0 inline, 0 general)
src/network/core/tcp_game.h
Show inline comments
 
@@ -73,21 +73,21 @@ enum {
 

	
 
/** Packet that wraps a command */
 
struct CommandPacket;
 

	
 
/** Status of a client */
 
enum ClientStatus {
 
	STATUS_INACTIVE,   ///< The client is not connected nor active
 
	STATUS_AUTH_GAME,  ///< The client is authorizing with game (server) password
 
	STATUS_INACTIVE,     ///< The client is not connected nor active
 
	STATUS_AUTH_GAME,    ///< The client is authorizing with game (server) password
 
	STATUS_AUTH_COMPANY, ///< The client is authorizing with company password
 
	STATUS_AUTH,       ///< The client is authorized
 
	STATUS_MAP_WAIT,   ///< The client is waiting as someone else is downloading the map
 
	STATUS_MAP,        ///< The client is downloading the map
 
	STATUS_DONE_MAP,   ///< The client has downloaded the map
 
	STATUS_PRE_ACTIVE, ///< The client is catching up the delayed frames
 
	STATUS_ACTIVE,     ///< The client is active within in the game
 
	STATUS_AUTHORIZED,   ///< The client is authorized
 
	STATUS_MAP_WAIT,     ///< The client is waiting as someone else is downloading the map
 
	STATUS_MAP,          ///< The client is downloading the map
 
	STATUS_DONE_MAP,     ///< The client has downloaded the map
 
	STATUS_PRE_ACTIVE,   ///< The client is catching up the delayed frames
 
	STATUS_ACTIVE,       ///< The client is active within in the game
 
};
 

	
 
class NetworkClientSocket;
 
typedef Pool<NetworkClientSocket, ClientIndex, 8, MAX_CLIENT_SLOTS> NetworkClientSocketPool;
 
extern NetworkClientSocketPool _networkclientsocket_pool;
 

	
src/network/network.cpp
Show inline comments
 
@@ -449,13 +449,13 @@ static void CheckMinActiveClients()
 
 * @return true iff one client is joining (but not authorizing)
 
 */
 
static bool NetworkHasJoiningClient()
 
{
 
	const NetworkClientSocket *cs;
 
	FOR_ALL_CLIENT_SOCKETS(cs) {
 
		if (cs->status >= STATUS_AUTH && cs->status < STATUS_ACTIVE) return true;
 
		if (cs->status >= STATUS_AUTHORIZED && cs->status < STATUS_ACTIVE) return true;
 
	}
 

	
 
	return false;
 
}
 

	
 
/**
 
@@ -545,34 +545,34 @@ NetworkRecvStatus NetworkCloseClient(Net
 
	 * connection after cs->Send_Packets we will close an already closed
 
	 * connection. This handles that case gracefully without having to make
 
	 * that code any more complex or more aware of the validity of the socket.
 
	 */
 
	if (cs->sock == INVALID_SOCKET) return status;
 

	
 
	if (status != NETWORK_RECV_STATUS_CONN_LOST && !cs->HasClientQuit() && _network_server && cs->status >= STATUS_AUTH) {
 
	if (status != NETWORK_RECV_STATUS_CONN_LOST && !cs->HasClientQuit() && _network_server && cs->status >= STATUS_AUTHORIZED) {
 
		/* We did not receive a leave message from this client... */
 
		char client_name[NETWORK_CLIENT_NAME_LENGTH];
 
		NetworkClientSocket *new_cs;
 

	
 
		NetworkGetClientName(client_name, sizeof(client_name), cs);
 

	
 
		NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, client_name, NULL, STR_NETWORK_ERROR_CLIENT_CONNECTION_LOST);
 

	
 
		/* Inform other clients of this... strange leaving ;) */
 
		FOR_ALL_CLIENT_SOCKETS(new_cs) {
 
			if (new_cs->status > STATUS_AUTH && cs != new_cs) {
 
			if (new_cs->status > STATUS_AUTHORIZED && cs != new_cs) {
 
				SEND_COMMAND(PACKET_SERVER_ERROR_QUIT)(new_cs, cs->client_id, NETWORK_ERROR_CONNECTION_LOST);
 
			}
 
		}
 
	}
 

	
 
	DEBUG(net, 1, "Closed client connection %d", cs->client_id);
 

	
 
	if (_network_server) {
 
		/* We just lost one client :( */
 
		if (cs->status >= STATUS_AUTH) _network_game_info.clients_on--;
 
		if (cs->status >= STATUS_AUTHORIZED) _network_game_info.clients_on--;
 
		_network_clients_connected--;
 

	
 
		SetWindowDirty(WC_CLIENT_LIST, 0);
 
	}
 

	
 
	cs->Send_Packets(true);
src/network/network_server.cpp
Show inline comments
 
@@ -149,24 +149,24 @@ DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SER
 
	cs->Send_Packet(p);
 

	
 
	StringID strid = GetNetworkErrorMsg(error);
 
	GetString(str, strid, lastof(str));
 

	
 
	/* Only send when the current client was in game */
 
	if (cs->status > STATUS_AUTH) {
 
	if (cs->status > STATUS_AUTHORIZED) {
 
		NetworkClientSocket *new_cs;
 
		char client_name[NETWORK_CLIENT_NAME_LENGTH];
 

	
 
		NetworkGetClientName(client_name, sizeof(client_name), cs);
 

	
 
		DEBUG(net, 1, "'%s' made an error and has been disconnected. Reason: '%s'", client_name, str);
 

	
 
		NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, client_name, NULL, strid);
 

	
 
		FOR_ALL_CLIENT_SOCKETS(new_cs) {
 
			if (new_cs->status > STATUS_AUTH && new_cs != cs) {
 
			if (new_cs->status > STATUS_AUTHORIZED && new_cs != cs) {
 
				/* Some errors we filter to a more general error. Clients don't have to know the real
 
				 *  reason a joining failed. */
 
				if (error == NETWORK_ERROR_NOT_AUTHORIZED || error == NETWORK_ERROR_NOT_EXPECTED || error == NETWORK_ERROR_WRONG_REVISION)
 
					error = NETWORK_ERROR_ILLEGAL_PACKET;
 

	
 
				SEND_COMMAND(PACKET_SERVER_ERROR_QUIT)(new_cs, cs->client_id, error);
 
@@ -258,26 +258,26 @@ DEF_SERVER_SEND_COMMAND(PACKET_SERVER_WE
 
	 */
 

	
 
	Packet *p;
 
	NetworkClientSocket *new_cs;
 

	
 
	/* Invalid packet when status is AUTH or higher */
 
	if (cs->status >= STATUS_AUTH) return NetworkCloseClient(cs, NETWORK_RECV_STATUS_MALFORMED_PACKET);
 
	if (cs->status >= STATUS_AUTHORIZED) return NetworkCloseClient(cs, NETWORK_RECV_STATUS_MALFORMED_PACKET);
 

	
 
	cs->status = STATUS_AUTH;
 
	cs->status = STATUS_AUTHORIZED;
 
	_network_game_info.clients_on++;
 

	
 
	p = new Packet(PACKET_SERVER_WELCOME);
 
	p->Send_uint32(cs->client_id);
 
	p->Send_uint32(_settings_game.game_creation.generation_seed);
 
	p->Send_string(_settings_client.network.network_id);
 
	cs->Send_Packet(p);
 

	
 
		/* Transmit info about all the active clients */
 
	FOR_ALL_CLIENT_SOCKETS(new_cs) {
 
		if (new_cs != cs && new_cs->status > STATUS_AUTH)
 
		if (new_cs != cs && new_cs->status > STATUS_AUTHORIZED)
 
			SEND_COMMAND(PACKET_SERVER_CLIENT_INFO)(cs, new_cs->GetInfo());
 
	}
 
	/* Also send the info of the server */
 
	return SEND_COMMAND(PACKET_SERVER_CLIENT_INFO)(cs, NetworkFindClientInfoFromClientID(CLIENT_ID_SERVER));
 
}
 

	
 
@@ -322,18 +322,18 @@ DEF_SERVER_SEND_COMMAND(PACKET_SERVER_MA
 
	 *    nothing
 
	 */
 

	
 
	static FILE *file_pointer;
 
	static uint sent_packets; // How many packets we did send succecfully last time
 

	
 
	if (cs->status < STATUS_AUTH) {
 
	if (cs->status < STATUS_AUTHORIZED) {
 
		/* Illegal call, return error and ignore the packet */
 
		return SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_NOT_AUTHORIZED);
 
	}
 

	
 
	if (cs->status == STATUS_AUTH) {
 
	if (cs->status == STATUS_AUTHORIZED) {
 
		const char *filename = "network_server.tmp";
 
		Packet *p;
 

	
 
		/* Make a dump of the current game */
 
		if (SaveOrLoad(filename, SL_SAVE, AUTOSAVE_DIR) != SL_OK) usererror("network savedump failed");
 

	
 
@@ -388,13 +388,13 @@ DEF_SERVER_SEND_COMMAND(PACKET_SERVER_MA
 
				 *  and start sending him the map */
 
				FOR_ALL_CLIENT_SOCKETS(new_cs) {
 
					if (new_cs->status == STATUS_MAP_WAIT) {
 
						/* Check if we already have a new client to send the map to */
 
						if (!new_map_client) {
 
							/* If not, this client will get the map */
 
							new_cs->status = STATUS_AUTH;
 
							new_cs->status = STATUS_AUTHORIZED;
 
							new_map_client = true;
 
							SEND_COMMAND(PACKET_SERVER_MAP)(new_cs);
 
						} else {
 
							/* Else, send the other clients how many clients are in front of them */
 
							SEND_COMMAND(PACKET_SERVER_WAIT)(new_cs);
 
						}
 
@@ -812,13 +812,13 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT
 
		 * That shouldn't happen. The client must be wrong. */
 
		return SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_NOT_EXPECTED);
 
	}
 

	
 
	/* The client was never joined.. so this is impossible, right?
 
	 *  Ignore the packet, give the client a warning, and close his connection */
 
	if (cs->status < STATUS_AUTH || cs->HasClientQuit()) {
 
	if (cs->status < STATUS_AUTHORIZED || cs->HasClientQuit()) {
 
		return SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_NOT_AUTHORIZED);
 
	}
 

	
 
	/* Check if someone else is receiving the map */
 
	FOR_ALL_CLIENT_SOCKETS(new_cs) {
 
		if (new_cs->status == STATUS_MAP) {
 
@@ -853,13 +853,13 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT
 
		/* This is the frame the client receives
 
		 *  we need it later on to make sure the client is not too slow */
 
		cs->last_frame = _frame_counter;
 
		cs->last_frame_server = _frame_counter;
 

	
 
		FOR_ALL_CLIENT_SOCKETS(new_cs) {
 
			if (new_cs->status > STATUS_AUTH) {
 
			if (new_cs->status > STATUS_AUTHORIZED) {
 
				SEND_COMMAND(PACKET_SERVER_CLIENT_INFO)(new_cs, cs->GetInfo());
 
				SEND_COMMAND(PACKET_SERVER_JOIN)(new_cs, cs->client_id);
 
			}
 
		}
 

	
 
		/* also update the new client with our max values */
 
@@ -986,13 +986,13 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT
 

	
 
	DEBUG(net, 2, "'%s' reported an error and is closing its connection (%s)", client_name, str);
 

	
 
	NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, client_name, NULL, strid);
 

	
 
	FOR_ALL_CLIENT_SOCKETS(new_cs) {
 
		if (new_cs->status > STATUS_AUTH) {
 
		if (new_cs->status > STATUS_AUTHORIZED) {
 
			SEND_COMMAND(PACKET_SERVER_ERROR_QUIT)(new_cs, cs->client_id, errorno);
 
		}
 
	}
 

	
 
	cs->CloseConnection(false);
 
	return NETWORK_RECV_STATUS_CONN_LOST;
 
@@ -1013,24 +1013,24 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT
 

	
 
	NetworkGetClientName(client_name, sizeof(client_name), cs);
 

	
 
	NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, client_name, NULL, STR_NETWORK_MESSAGE_CLIENT_LEAVING);
 

	
 
	FOR_ALL_CLIENT_SOCKETS(new_cs) {
 
		if (new_cs->status > STATUS_AUTH) {
 
		if (new_cs->status > STATUS_AUTHORIZED) {
 
			SEND_COMMAND(PACKET_SERVER_QUIT)(new_cs, cs->client_id);
 
		}
 
	}
 

	
 
	cs->CloseConnection(false);
 
	return NETWORK_RECV_STATUS_CONN_LOST;
 
}
 

	
 
DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_ACK)
 
{
 
	if (cs->status < STATUS_AUTH) {
 
	if (cs->status < STATUS_AUTHORIZED) {
 
		/* Illegal call, return error and ignore the packet */
 
		return SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_NOT_AUTHORIZED);
 
	}
 

	
 
	uint32 frame = p->Recv_uint32();
 

	
 
@@ -1151,13 +1151,13 @@ void NetworkServerSendChat(NetworkAction
 
		break;
 
	}
 
}
 

	
 
DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_CHAT)
 
{
 
	if (cs->status < STATUS_AUTH) {
 
	if (cs->status < STATUS_AUTHORIZED) {
 
		/* Illegal call, return error and ignore the packet */
 
		return SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_NOT_AUTHORIZED);
 
	}
 

	
 
	NetworkAction action = (NetworkAction)p->Recv_uint8();
 
	DestType desttype = (DestType)p->Recv_uint8();
0 comments (0 inline, 0 general)