Changeset - r28685:54f1f97dad9a
[Not reviewed]
master
0 1 0
Rubidium - 3 months ago 2024-02-03 19:27:25
rubidium@openttd.org
Codechange: cascade through SendNeedGame/CompanyPassword functions, instead of duplicating logic for determining whether to call these functions
1 file changed with 14 insertions and 21 deletions:
0 comments (0 inline, 0 general)
src/network/network_server.cpp
Show inline comments
 
@@ -423,6 +423,11 @@ NetworkRecvStatus ServerNetworkGameSocke
 
/** Request the game password. */
 
NetworkRecvStatus ServerNetworkGameSocketHandler::SendNeedGamePassword()
 
{
 
	if (_settings_client.network.server_password.empty()) {
 
		/* Do not actually need a game password, continue with the company password. */
 
		return this->SendNeedCompanyPassword();
 
	}
 

	
 
	Debug(net, 9, "client[{}] SendNeedGamePassword()", this->client_id);
 

	
 
	/* Invalid packet when status is STATUS_AUTH_GAME or higher */
 
@@ -441,6 +446,11 @@ NetworkRecvStatus ServerNetworkGameSocke
 
/** Request the company password. */
 
NetworkRecvStatus ServerNetworkGameSocketHandler::SendNeedCompanyPassword()
 
{
 
	NetworkClientInfo *ci = this->GetInfo();
 
	if (!Company::IsValidID(ci->client_playas) || _network_company_states[ci->client_playas].password.empty()) {
 
		return this->SendWelcome();
 
	}
 

	
 
	Debug(net, 9, "client[{}] SendNeedCompanyPassword()", this->client_id);
 

	
 
	/* Invalid packet when status is STATUS_AUTH_COMPANY or higher */
 
@@ -845,18 +855,7 @@ NetworkRecvStatus ServerNetworkGameSocke
 

	
 
	Debug(net, 9, "client[{}] Receive_CLIENT_NEWGRFS_CHECKED()", this->client_id);
 

	
 
	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();
 
	return this->SendNeedGamePassword();
 
}
 

	
 
NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_JOIN(Packet *p)
 
@@ -930,8 +929,8 @@ NetworkRecvStatus ServerNetworkGameSocke
 
	this->status = STATUS_NEWGRFS_CHECK;
 

	
 
	if (_grfconfig == nullptr) {
 
		/* Behave as if we received PACKET_CLIENT_NEWGRFS_CHECKED */
 
		return this->Receive_CLIENT_NEWGRFS_CHECKED(nullptr);
 
		/* Continue asking for the game password. */
 
		return this->SendNeedGamePassword();
 
	}
 

	
 
	return this->SendNewGRFCheck();
 
@@ -954,13 +953,7 @@ NetworkRecvStatus ServerNetworkGameSocke
 
		return this->SendError(NETWORK_ERROR_WRONG_PASSWORD);
 
	}
 

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

	
 
	/* Valid password, allow user */
 
	return this->SendWelcome();
 
	return this->SendNeedCompanyPassword();
 
}
 

	
 
NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_COMPANY_PASSWORD(Packet *p)
0 comments (0 inline, 0 general)