summaryrefslogtreecommitdiff
path: root/src/network
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2009-03-25 16:30:33 +0000
committerpeter1138 <peter1138@openttd.org>2009-03-25 16:30:33 +0000
commit28d3123dfd7c8a981496e81fb1dc5996015563d9 (patch)
treeda8d06cfc31e2312725d33bcd53743b1d3048879 /src/network
parent20528504256660d75eba2240706cf47b15c5bd10 (diff)
downloadopenttd-28d3123dfd7c8a981496e81fb1dc5996015563d9.tar.xz
(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.
Diffstat (limited to 'src/network')
-rw-r--r--src/network/network_server.cpp19
1 files changed, 18 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;