Changeset - r25474:d9d75ddfaa02
[Not reviewed]
master
0 4 0
rubidium42 - 3 years ago 2021-05-02 06:27:06
rubidium@openttd.org
Codechange: [Network] Make company state password std::string
4 files changed with 18 insertions and 18 deletions:
0 comments (0 inline, 0 general)
src/console_cmds.cpp
Show inline comments
 
@@ -1635,7 +1635,7 @@ DEF_CONSOLE_CMD(ConCompanies)
 
		if (c->is_ai) {
 
			password_state = "AI";
 
		} else if (_network_server) {
 
				password_state = StrEmpty(_network_company_states[c->index].password) ? "unprotected" : "protected";
 
			password_state = _network_company_states[c->index].password.empty() ? "unprotected" : "protected";
 
		}
 

	
 
		char colour[512];
src/network/network.cpp
Show inline comments
 
@@ -601,7 +601,7 @@ void NetworkClose(bool close_admins)
 

	
 
	NetworkFreeLocalCommandQueue();
 

	
 
	free(_network_company_states);
 
	delete[] _network_company_states;
 
	_network_company_states = nullptr;
 

	
 
	InitializeNetworkPools(close_admins);
 
@@ -896,7 +896,7 @@ bool NetworkServerStart()
 
	DEBUG(net, 5, "Starting listeners for incoming server queries");
 
	NetworkUDPServerListen();
 

	
 
	_network_company_states = CallocT<NetworkCompanyState>(MAX_COMPANIES);
 
	_network_company_states = new NetworkCompanyState[MAX_COMPANIES];
 
	_network_server = true;
 
	_networking = true;
 
	_frame_counter = 0;
src/network/network_server.cpp
Show inline comments
 
@@ -863,7 +863,7 @@ NetworkRecvStatus ServerNetworkGameSocke
 
		return this->SendNeedGamePassword();
 
	}
 

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

	
 
@@ -964,7 +964,7 @@ NetworkRecvStatus ServerNetworkGameSocke
 
	}
 

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

	
 
@@ -985,8 +985,8 @@ NetworkRecvStatus ServerNetworkGameSocke
 
	 * Also, check the company is still valid - client could be moved to spectators
 
	 * in the middle of the authorization process */
 
	CompanyID playas = this->GetInfo()->client_playas;
 
	if (Company::IsValidID(playas) && !StrEmpty(_network_company_states[playas].password) &&
 
			strcmp(password, _network_company_states[playas].password) != 0) {
 
	if (Company::IsValidID(playas) && !_network_company_states[playas].password.empty() &&
 
			_network_company_states[playas].password.compare(password) != 0) {
 
		/* Password is invalid */
 
		return this->SendError(NETWORK_ERROR_WRONG_PASSWORD);
 
	}
 
@@ -1467,13 +1467,13 @@ NetworkRecvStatus ServerNetworkGameSocke
 
	if (company_id != COMPANY_SPECTATOR && !Company::IsValidHumanID(company_id)) return NETWORK_RECV_STATUS_OKAY;
 

	
 
	/* Check if we require a password for this company */
 
	if (company_id != COMPANY_SPECTATOR && !StrEmpty(_network_company_states[company_id].password)) {
 
	if (company_id != COMPANY_SPECTATOR && !_network_company_states[company_id].password.empty()) {
 
		/* we need a password from the client - should be in this packet */
 
		char password[NETWORK_PASSWORD_LENGTH];
 
		p->Recv_string(password, sizeof(password));
 

	
 
		/* Incorrect password sent, return! */
 
		if (strcmp(password, _network_company_states[company_id].password) != 0) {
 
		if (_network_company_states[company_id].password.compare(password) != 0) {
 
			DEBUG(net, 2, "Wrong password from client-id #%d for company #%d", this->client_id, company_id + 1);
 
			return NETWORK_RECV_STATUS_OKAY;
 
		}
 
@@ -1523,7 +1523,7 @@ void NetworkSocketHandler::SendCompanyIn
 
	p->Send_uint16(c->old_economy[0].performance_history);
 

	
 
	/* Send 1 if there is a password for the company else send 0 */
 
	p->Send_bool  (!StrEmpty(_network_company_states[c->index].password));
 
	p->Send_bool  (!_network_company_states[c->index].password.empty());
 

	
 
	for (uint i = 0; i < NETWORK_VEH_END; i++) {
 
		p->Send_uint16(stats->num_vehicle[i]);
 
@@ -1660,15 +1660,15 @@ static void NetworkAutoCleanCompanies()
 
			_network_company_states[c->index].months_empty++;
 

	
 
			/* Is the company empty for autoclean_unprotected-months, and is there no protection? */
 
			if (_settings_client.network.autoclean_unprotected != 0 && _network_company_states[c->index].months_empty > _settings_client.network.autoclean_unprotected && StrEmpty(_network_company_states[c->index].password)) {
 
			if (_settings_client.network.autoclean_unprotected != 0 && _network_company_states[c->index].months_empty > _settings_client.network.autoclean_unprotected && _network_company_states[c->index].password.empty()) {
 
				/* Shut the company down */
 
				DoCommandP(0, CCA_DELETE | c->index << 16 | CRR_AUTOCLEAN << 24, 0, CMD_COMPANY_CTRL);
 
				IConsolePrintF(CC_DEFAULT, "Auto-cleaned company #%d with no password", c->index + 1);
 
			}
 
			/* Is the company empty for autoclean_protected-months, and there is a protection? */
 
			if (_settings_client.network.autoclean_protected != 0 && _network_company_states[c->index].months_empty > _settings_client.network.autoclean_protected && !StrEmpty(_network_company_states[c->index].password)) {
 
			if (_settings_client.network.autoclean_protected != 0 && _network_company_states[c->index].months_empty > _settings_client.network.autoclean_protected && !_network_company_states[c->index].password.empty()) {
 
				/* Unprotect the company */
 
				_network_company_states[c->index].password[0] = '\0';
 
				_network_company_states[c->index].password.clear();
 
				IConsolePrintF(CC_DEFAULT, "Auto-removed protection from company #%d", c->index + 1);
 
				_network_company_states[c->index].months_empty = 0;
 
				NetworkServerUpdateCompanyPassworded(c->index, false);
 
@@ -1765,8 +1765,8 @@ void NetworkServerSetCompanyPassword(Com
 
		password = GenerateCompanyPasswordHash(password, _settings_client.network.network_id.c_str(), _settings_game.game_creation.generation_seed);
 
	}
 

	
 
	strecpy(_network_company_states[company_id].password, password, lastof(_network_company_states[company_id].password));
 
	NetworkServerUpdateCompanyPassworded(company_id, !StrEmpty(_network_company_states[company_id].password));
 
	_network_company_states[company_id].password = password;
 
	NetworkServerUpdateCompanyPassworded(company_id, !_network_company_states[company_id].password.empty());
 
}
 

	
 
/**
 
@@ -2188,7 +2188,7 @@ void NetworkServerNewCompany(const Compa
 
	if (!_network_server) return;
 

	
 
	_network_company_states[c->index].months_empty = 0;
 
	_network_company_states[c->index].password[0] = '\0';
 
	_network_company_states[c->index].password.clear();
 
	NetworkServerUpdateCompanyPassworded(c->index, false);
 

	
 
	if (ci != nullptr) {
src/network/network_type.h
Show inline comments
 
@@ -62,8 +62,8 @@ struct NetworkCompanyStats {
 

	
 
/** Some state information of a company, especially for servers */
 
struct NetworkCompanyState {
 
	char password[NETWORK_PASSWORD_LENGTH];         ///< The password for the company
 
	uint16 months_empty;                            ///< How many months the company is empty
 
	std::string password; ///< The password for the company
 
	uint16 months_empty;  ///< How many months the company is empty
 
};
 

	
 
struct NetworkClientInfo;
0 comments (0 inline, 0 general)