Changeset - r25346:21c8ec239c8f
[Not reviewed]
master
0 3 0
rubidium42 - 3 years ago 2021-05-01 12:21:33
rubidium@openttd.org
Codechange: Move join information into a single structure
3 files changed with 19 insertions and 19 deletions:
0 comments (0 inline, 0 general)
src/network/network.cpp
Show inline comments
 
@@ -762,9 +762,9 @@ bool NetworkClientConnectGame(NetworkAdd
 

	
 
	strecpy(_settings_client.network.last_joined, address.GetAddressAsString(false).c_str(), lastof(_settings_client.network.last_joined));
 

	
 
	_network_join_as = join_as;
 
	_network_join_server_password = join_server_password;
 
	_network_join_company_password = join_company_password;
 
	_network_join.company = join_as;
 
	_network_join.server_password = join_server_password;
 
	_network_join.company_password = join_company_password;
 

	
 
	NetworkDisconnect();
 
	NetworkInitialize();
src/network/network_client.cpp
Show inline comments
 
@@ -326,13 +326,8 @@ static uint8 _network_server_max_compani
 
/** Maximum number of spectators of the currently joined server. */
 
static uint8 _network_server_max_spectators;
 

	
 
/** Who would we like to join as. */
 
CompanyID _network_join_as;
 

	
 
/** Login password from -p argument */
 
const char *_network_join_server_password = nullptr;
 
/** Company password from -P argument */
 
const char *_network_join_company_password = nullptr;
 
/** Information about the game to join to. */
 
NetworkJoinInfo _network_join;
 

	
 
/** Make sure the server ID length is the same as a md5 hash. */
 
static_assert(NETWORK_SERVER_ID_LENGTH == 16 * 2 + 1);
 
@@ -372,7 +367,7 @@ NetworkRecvStatus ClientNetworkGameSocke
 
	p->Send_string(GetNetworkRevisionString());
 
	p->Send_uint32(_openttd_newgrf_version);
 
	p->Send_string(_settings_client.network.client_name); // Client name
 
	p->Send_uint8 (_network_join_as);     // PlayAs
 
	p->Send_uint8 (_network_join.company);     // PlayAs
 
	p->Send_uint8 (0); // Used to be language
 
	my_client->SendPacket(p);
 
	return NETWORK_RECV_STATUS_OKAY;
 
@@ -804,7 +799,7 @@ NetworkRecvStatus ClientNetworkGameSocke
 
	if (this->status < STATUS_JOIN || this->status >= STATUS_AUTH_GAME) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
 
	this->status = STATUS_AUTH_GAME;
 

	
 
	const char *password = _network_join_server_password;
 
	const char *password = _network_join.server_password;
 
	if (!StrEmpty(password)) {
 
		return SendGamePassword(password);
 
	}
 
@@ -823,7 +818,7 @@ NetworkRecvStatus ClientNetworkGameSocke
 
	p->Recv_string(_password_server_id, sizeof(_password_server_id));
 
	if (this->HasClientQuit()) return NETWORK_RECV_STATUS_MALFORMED_PACKET;
 

	
 
	const char *password = _network_join_company_password;
 
	const char *password = _network_join.company_password;
 
	if (!StrEmpty(password)) {
 
		return SendCompanyPassword(password);
 
	}
 
@@ -945,10 +940,10 @@ NetworkRecvStatus ClientNetworkGameSocke
 

	
 
	/* New company/spectator (invalid company) or company we want to join is not active
 
	 * Switch local company to spectator and await the server's judgement */
 
	if (_network_join_as == COMPANY_NEW_COMPANY || !Company::IsValidID(_network_join_as)) {
 
	if (_network_join.company == COMPANY_NEW_COMPANY || !Company::IsValidID(_network_join.company)) {
 
		SetLocalCompany(COMPANY_SPECTATOR);
 

	
 
		if (_network_join_as != COMPANY_SPECTATOR) {
 
		if (_network_join.company != COMPANY_SPECTATOR) {
 
			/* We have arrived and ready to start playing; send a command to make a new company;
 
			 * the server will give us a client-id and let us in */
 
			_network_join_status = NETWORK_JOIN_STATUS_REGISTERING;
 
@@ -957,7 +952,7 @@ NetworkRecvStatus ClientNetworkGameSocke
 
		}
 
	} else {
 
		/* take control over an existing company */
 
		SetLocalCompany(_network_join_as);
 
		SetLocalCompany(_network_join.company);
 
	}
 

	
 
	return NETWORK_RECV_STATUS_OKAY;
src/network/network_client.h
Show inline comments
 
@@ -112,9 +112,14 @@ typedef ClientNetworkGameSocketHandler M
 
void NetworkClient_Connected();
 
void NetworkClientSetCompanyPassword(const char *password);
 

	
 
extern CompanyID _network_join_as;
 
/** Information required to join a server. */
 
struct NetworkJoinInfo {
 
	NetworkJoinInfo() : company(COMPANY_SPECTATOR), server_password(nullptr), company_password(nullptr) {}
 
	CompanyID company;            ///< The company to join.
 
	const char *server_password;  ///< The password of the server to join.
 
	const char *company_password; ///< The password of the company to join.
 
};
 

	
 
extern const char *_network_join_server_password;
 
extern const char *_network_join_company_password;
 
extern NetworkJoinInfo _network_join;
 

	
 
#endif /* NETWORK_CLIENT_H */
0 comments (0 inline, 0 general)