summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/network/network_server.cpp19
-rw-r--r--src/settings_type.h1
-rw-r--r--src/table/settings.h1
3 files changed, 20 insertions, 1 deletions
diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp
index 85fa2b3a7..16695c46b 100644
--- a/src/network/network_server.cpp
+++ b/src/network/network_server.cpp
@@ -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;
diff --git a/src/settings_type.h b/src/settings_type.h
index e96a25802..e3f52600d 100644
--- a/src/settings_type.h
+++ b/src/settings_type.h
@@ -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
diff --git a/src/table/settings.h b/src/table/settings.h
index 677e25c84..7a422d6d2 100644
--- a/src/table/settings.h
+++ b/src/table/settings.h
@@ -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),