Changeset - r25924:31e3cdb1821b
[Not reviewed]
master
0 1 0
Patric Stout - 3 years ago 2021-08-23 17:38:02
truebrain@openttd.org
Fix #9490: [Network] a full server couldn't be queried either (#9508)

You can now still query a full server, as long as the maximum
amount of allowed connections isn't reached. This means that as
long as there are not 255 clients connected to a server, you can
always connect to query.
1 file changed with 6 insertions and 1 deletions:
0 comments (0 inline, 0 general)
src/network/network_server.cpp
Show inline comments
 
@@ -284,49 +284,49 @@ NetworkRecvStatus ServerNetworkGameSocke
 
	Debug(net, 3, "Closed client connection {}", this->client_id);
 

	
 
	/* We just lost one client :( */
 
	if (this->status >= STATUS_AUTHORIZED) _network_game_info.clients_on--;
 
	extern byte _network_clients_connected;
 
	_network_clients_connected--;
 

	
 
	this->SendPackets(true);
 

	
 
	delete this->GetInfo();
 
	delete this;
 

	
 
	InvalidateWindowData(WC_CLIENT_LIST, 0);
 

	
 
	return status;
 
}
 

	
 
/**
 
 * Whether an connection is allowed or not at this moment.
 
 * @return true if the connection is allowed.
 
 */
 
/* static */ bool ServerNetworkGameSocketHandler::AllowConnection()
 
{
 
	extern byte _network_clients_connected;
 
	bool accept = _network_clients_connected < MAX_CLIENTS && _network_game_info.clients_on < _settings_client.network.max_clients;
 
	bool accept = _network_clients_connected < MAX_CLIENTS;
 

	
 
	/* We can't go over the MAX_CLIENTS limit here. However, the
 
	 * pool must have place for all clients and ourself. */
 
	static_assert(NetworkClientSocketPool::MAX_SIZE == MAX_CLIENTS + 1);
 
	assert(!accept || ServerNetworkGameSocketHandler::CanAllocateItem());
 
	return accept;
 
}
 

	
 
/** Send the packets for the server sockets. */
 
/* static */ void ServerNetworkGameSocketHandler::Send()
 
{
 
	for (NetworkClientSocket *cs : NetworkClientSocket::Iterate()) {
 
		if (cs->writable) {
 
			if (cs->SendPackets() != SPS_CLOSED && cs->status == STATUS_MAP) {
 
				/* This client is in the middle of a map-send, call the function for that */
 
				cs->SendMap();
 
			}
 
		}
 
	}
 
}
 

	
 
static void NetworkHandleCommandQueue(NetworkClientSocket *cs);
 

	
 
/***********
 
@@ -784,48 +784,53 @@ NetworkRecvStatus ServerNetworkGameSocke
 
		return this->SendError(NETWORK_ERROR_NOT_EXPECTED);
 
	}
 

	
 
	NetworkClientInfo *ci = this->GetInfo();
 

	
 
	/* We now want a password from the client else we do not allow them in! */
 
	if (!_settings_client.network.server_password.empty()) {
 
		return this->SendNeedGamePassword();
 
	}
 

	
 
	if (Company::IsValidID(ci->client_playas) && !_network_company_states[ci->client_playas].password.empty()) {
 
		return this->SendNeedCompanyPassword();
 
	}
 

	
 
	return this->SendWelcome();
 
}
 

	
 
NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_JOIN(Packet *p)
 
{
 
	if (this->status != STATUS_INACTIVE) {
 
		/* Illegal call, return error and ignore the packet */
 
		return this->SendError(NETWORK_ERROR_NOT_EXPECTED);
 
	}
 

	
 
	if (_network_game_info.clients_on >= _settings_client.network.max_clients) {
 
		/* Turns out we are full. Inform the user about this. */
 
		return this->SendError(NETWORK_ERROR_FULL);
 
	}
 

	
 
	std::string client_revision = p->Recv_string(NETWORK_REVISION_LENGTH);
 
	uint32 newgrf_version = p->Recv_uint32();
 

	
 
	/* Check if the client has revision control enabled */
 
	if (!IsNetworkCompatibleVersion(client_revision) || _openttd_newgrf_version != newgrf_version) {
 
		/* Different revisions!! */
 
		return this->SendError(NETWORK_ERROR_WRONG_REVISION);
 
	}
 

	
 
	std::string client_name = p->Recv_string(NETWORK_CLIENT_NAME_LENGTH);
 
	CompanyID playas = (Owner)p->Recv_uint8();
 

	
 
	if (this->HasClientQuit()) return NETWORK_RECV_STATUS_CLIENT_QUIT;
 

	
 
	/* join another company does not affect these values */
 
	switch (playas) {
 
		case COMPANY_NEW_COMPANY: // New company
 
			if (Company::GetNumItems() >= _settings_client.network.max_companies) {
 
				return this->SendError(NETWORK_ERROR_FULL);
 
			}
 
			break;
 
		case COMPANY_SPECTATOR: // Spectator
 
			break;
 
		default: // Join another company (companies 1-8 (index 0-7))
0 comments (0 inline, 0 general)