changeset 11487:55dcf738620d draft

(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.
author peter1138 <peter1138@openttd.org>
date Wed, 25 Mar 2009 16:30:33 +0000
parents 6eecc878334e
children 0395660bac3b
files src/network/network_server.cpp src/settings_type.h src/table/settings.h
diffstat 3 files changed, 20 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/network/network_server.cpp
+++ b/src/network/network_server.cpp
@@ -1418,6 +1418,7 @@
 	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 @@
 		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 @@
 			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 @@
 				_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;
--- a/src/settings_type.h
+++ b/src/settings_type.h
@@ -126,6 +126,7 @@
 	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
--- a/src/table/settings.h
+++ b/src/table/settings.h
@@ -577,6 +577,7 @@
 	 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),