From f599108c164735ec1e43a564aadf1c8a7f53ed9e Mon Sep 17 00:00:00 2001 From: Rubidium Date: Sat, 23 Mar 2024 09:35:28 +0100 Subject: [PATCH] Codechange: move 'months_empty' to CompanyProperties --- src/company_base.h | 1 + src/network/network_server.cpp | 18 +++++++++--------- src/network/network_type.h | 1 - 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/company_base.h b/src/company_base.h index ea4565a808..356a5fe058 100644 --- a/src/company_base.h +++ b/src/company_base.h @@ -91,6 +91,7 @@ struct CompanyProperties { TimerGameEconomy::Year inaugurated_year; ///< Economy year of starting the company. + uint8_t months_empty = 0; ///< NOSAVE: Number of months this company has not had a client in multiplayer. uint8_t months_of_bankruptcy; ///< Number of months that the company is unable to pay its debts CompanyMask bankrupt_asked; ///< which companies were asked about buying it? int16_t bankrupt_timeout; ///< If bigger than \c 0, amount of time to wait for an answer on an offer to buy this company. diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp index 39bd2aa540..f63c79bd65 100644 --- a/src/network/network_server.cpp +++ b/src/network/network_server.cpp @@ -961,7 +961,8 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_IDENTIFY(Packet Debug(desync, 1, "client: {:08x}; {:02x}; {:02x}; {:02x}", TimerGameEconomy::date, TimerGameEconomy::date_fract, (int)ci->client_playas, (int)ci->index); /* Make sure companies to which people try to join are not autocleaned */ - if (Company::IsValidID(playas)) _network_company_states[playas].months_empty = 0; + Company *c = Company::GetIfValid(playas); + if (c != nullptr) c->months_empty = 0; return this->SendNewGRFCheck(); } @@ -1643,37 +1644,37 @@ static void NetworkAutoCleanCompanies() } /* Go through all the companies */ - for (const Company *c : Company::Iterate()) { + for (Company *c : Company::Iterate()) { /* Skip the non-active once */ if (c->is_ai) continue; if (!HasBit(has_clients, c->index)) { /* The company is empty for one month more */ - _network_company_states[c->index].months_empty++; + if (c->months_empty != std::numeric_limitsmonths_empty)>::max()) c->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 && _network_company_states[c->index].password.empty()) { + if (_settings_client.network.autoclean_unprotected != 0 && c->months_empty > _settings_client.network.autoclean_unprotected && _network_company_states[c->index].password.empty()) { /* Shut the company down */ Command::Post(CCA_DELETE, c->index, CRR_AUTOCLEAN, INVALID_CLIENT_ID); IConsolePrint(CC_INFO, "Auto-cleaned company #{} 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 && !_network_company_states[c->index].password.empty()) { + if (_settings_client.network.autoclean_protected != 0 && c->months_empty > _settings_client.network.autoclean_protected && !_network_company_states[c->index].password.empty()) { /* Unprotect the company */ _network_company_states[c->index].password.clear(); IConsolePrint(CC_INFO, "Auto-removed protection from company #{}.", c->index + 1); - _network_company_states[c->index].months_empty = 0; + c->months_empty = 0; NetworkServerUpdateCompanyPassworded(c->index, false); } /* Is the company empty for autoclean_novehicles-months, and has no vehicles? */ - if (_settings_client.network.autoclean_novehicles != 0 && _network_company_states[c->index].months_empty > _settings_client.network.autoclean_novehicles && !HasBit(has_vehicles, c->index)) { + if (_settings_client.network.autoclean_novehicles != 0 && c->months_empty > _settings_client.network.autoclean_novehicles && !HasBit(has_vehicles, c->index)) { /* Shut the company down */ Command::Post(CCA_DELETE, c->index, CRR_AUTOCLEAN, INVALID_CLIENT_ID); IConsolePrint(CC_INFO, "Auto-cleaned company #{} with no vehicles.", c->index + 1); } } else { /* It is not empty, reset the date */ - _network_company_states[c->index].months_empty = 0; + c->months_empty = 0; } } } @@ -2266,7 +2267,6 @@ void NetworkServerNewCompany(const Company *c, NetworkClientInfo *ci) if (!_network_server) return; - _network_company_states[c->index].months_empty = 0; _network_company_states[c->index].password.clear(); NetworkServerUpdateCompanyPassworded(c->index, false); diff --git a/src/network/network_type.h b/src/network/network_type.h index a3c0f47e74..4f8617ff37 100644 --- a/src/network/network_type.h +++ b/src/network/network_type.h @@ -73,7 +73,6 @@ struct NetworkCompanyStats { /** Some state information of a company, especially for servers */ struct NetworkCompanyState { std::string password; ///< The password for the company - uint16_t months_empty; ///< How many months the company is empty }; struct NetworkClientInfo;