(svn r15848) -Feature: Add autoclean_novehicles setting which will, when autoclean_companies is true, remove any company with no vehicles and no active client after autoclean_novehciles-months.

This commit is contained in:
peter1138 2009-03-25 16:30:33 +00:00
parent 2052850425
commit 28d3123dfd
3 changed files with 20 additions and 1 deletions

View File

@ -1418,6 +1418,7 @@ static void NetworkAutoCleanCompanies()
const NetworkClientInfo *ci;
const Company *c;
bool clients_in_company[MAX_COMPANIES];
int vehicles_in_company[MAX_COMPANIES];
if (!_settings_client.network.autoclean_companies) return;
@ -1433,6 +1434,16 @@ static void NetworkAutoCleanCompanies()
if (IsValidCompanyID(ci->client_playas)) clients_in_company[ci->client_playas] = true;
}
if (_settings_client.network.autoclean_novehicles != 0) {
memset(vehicles_in_company, 0, sizeof(vehicles_in_company));
const Vehicle *v;
FOR_ALL_VEHICLES(v) {
if (!IsValidCompanyID(v->owner) || !v->IsPrimaryVehicle()) continue;
vehicles_in_company[v->owner]++;
}
}
/* Go through all the comapnies */
FOR_ALL_COMPANIES(c) {
/* Skip the non-active once */
@ -1446,7 +1457,7 @@ static void NetworkAutoCleanCompanies()
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)) {
/* Shut the company down */
DoCommandP(0, 2, c->index, CMD_COMPANY_CTRL);
IConsolePrintF(CC_DEFAULT, "Auto-cleaned company #%d", c->index + 1);
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)) {
@ -1456,6 +1467,12 @@ static void NetworkAutoCleanCompanies()
_network_company_states[c->index].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 && vehicles_in_company[c->index] == 0) {
/* Shut the company down */
DoCommandP(0, 2, c->index, CMD_COMPANY_CTRL);
IConsolePrintF(CC_DEFAULT, "Auto-cleaned company #%d with no vehicles", c->index + 1);
}
} else {
/* It is not empty, reset the date */
_network_company_states[c->index].months_empty = 0;

View File

@ -126,6 +126,7 @@ struct NetworkSettings {
bool autoclean_companies; ///< automatically remove companies that are not in use
uint8 autoclean_unprotected; ///< remove passwordless companies after this many months
uint8 autoclean_protected; ///< remove the password from passworded companies after this many months
uint8 autoclean_novehicles; ///< remove companies with no vehicles after this many months
uint8 max_companies; ///< maximum amount of companies
uint8 max_clients; ///< maximum amount of clients
uint8 max_spectators; ///< maximum amount of spectators

View File

@ -577,6 +577,7 @@ const SettingDesc _settings[] = {
SDTC_BOOL(network.autoclean_companies, S, NO, false, STR_NULL, NULL),
SDTC_VAR(network.autoclean_unprotected, SLE_UINT8, S,D0|NO, 12, 0, 240, 0, STR_NULL, NULL),
SDTC_VAR(network.autoclean_protected, SLE_UINT8, S,D0|NO, 36, 0, 240, 0, STR_NULL, NULL),
SDTC_VAR(network.autoclean_novehicles, SLE_UINT8, S,D0|NO, 0, 0, 240, 0, STR_NULL, NULL),
SDTC_VAR(network.max_companies, SLE_UINT8, S, NO, 8, 1,MAX_COMPANIES,0, STR_NULL, UpdateClientConfigValues),
SDTC_VAR(network.max_clients, SLE_UINT8, S, NO, 16, 2, MAX_CLIENTS, 0, STR_NULL, NULL),
SDTC_VAR(network.max_spectators, SLE_UINT8, S, NO, 8, 0, MAX_CLIENTS, 0, STR_NULL, UpdateClientConfigValues),