Changeset - r785:98d70fb62afe
[Not reviewed]
master
0 6 0
truelight - 19 years ago 2004-12-23 17:37:26
truelight@openttd.org
(svn r1252) -Add: [Network] With 'set restart_game_date' you can set the date for in
which year the server must restart hisself. (0 = disabled, default value)
6 files changed with 50 insertions and 2 deletions:
0 comments (0 inline, 0 general)
console_cmds.c
Show inline comments
 
@@ -828,24 +828,41 @@ DEF_CONSOLE_CMD(ConSet) {
 
			return NULL;
 
		}
 
		if (argc == 3) {
 
			_network_autoclean_unprotected = atoi(argv[2]);
 
			IConsolePrintF(_iconsole_color_warning, "Autoclean-unprotected changed to '%d'", _network_autoclean_unprotected);
 
		} else {
 
			IConsolePrintF(_iconsole_color_default, "Current autoclean-unprotected is '%d'", _network_autoclean_unprotected);
 
			IConsolePrint(_iconsole_color_warning, "Usage: set autoclean_unprotected <months>.");
 
		}
 
		return NULL;
 
	}
 

	
 
	// setting the server auto restart date
 
	if (strcmp(argv[1],"restart_game_date") == 0) {
 
		if (!_network_server) {
 
			IConsolePrintF(_iconsole_color_error, "You are not the server");
 
			return NULL;
 
		}
 
		if (argc == 3) {
 
			_network_restart_game_date = atoi(argv[2]);
 
			IConsolePrintF(_iconsole_color_warning, "Restart Game Date changed to '%d'", _network_restart_game_date);
 
		} else {
 
			IConsolePrintF(_iconsole_color_default, "Current Restart Game Date is '%d'", _network_restart_game_date);
 
			IConsolePrint(_iconsole_color_warning, "Usage: set restart_game_date <year>. '0' means disabled.");
 
			IConsolePrint(_iconsole_color_warning, " Auto-restart the server when 1 jan of this year is reached (e.g.: 2030).");
 
		}
 
		return NULL;
 
	}
 

	
 
#endif /* ENABLE_NETWORK */
 

	
 
	// Patch-options
 
	if (strcmp(argv[1],"patch") == 0) {
 
		if (_networking && !_network_server) {
 
			IConsolePrintF(_iconsole_color_error, "You are not the server");
 
			return NULL;
 
		}
 
		if (argc == 3)
 
			ConsoleGetPatchSetting(argv[2]);
 
		else if (argc == 4)
 
			ConsoleSetPatchSetting(argv[2], argv[3]);
 
@@ -859,24 +876,25 @@ DEF_CONSOLE_CMD(ConSet) {
 
	IConsolePrint(_iconsole_color_error, "Known settings are:");
 
#ifdef ENABLE_NETWORK
 
	IConsolePrint(_iconsole_color_error, " - autoclean_companies on/off");
 
	IConsolePrint(_iconsole_color_error, " - autoclean_protected <months>");
 
	IConsolePrint(_iconsole_color_error, " - autoclean_unprotected <months>");
 
	IConsolePrint(_iconsole_color_error, " - company_pw \"<password>\"");
 
	IConsolePrint(_iconsole_color_error, " - name \"<playername>\"");
 
	IConsolePrint(_iconsole_color_error, " - server_name \"<name>\"");
 
	IConsolePrint(_iconsole_color_error, " - server_advertise on/off");
 
	IConsolePrint(_iconsole_color_error, " - server_bind_ip <ip>");
 
	IConsolePrint(_iconsole_color_error, " - server_port <port>");
 
	IConsolePrint(_iconsole_color_error, " - server_pw \"<password>\"");
 
	IConsolePrint(_iconsole_color_error, " - restart_game_date \"<year>\"");
 
#endif /* ENABLE_NETWORK */
 
	IConsolePrint(_iconsole_color_error, " - patch <patch_name> [<value>]");
 

	
 
	return NULL;
 
}
 

	
 

	
 
#ifdef _DEBUG
 
/* ****************************************** */
 
/*  debug commands and variables */
 
/* ****************************************** */
 

	
misc.c
Show inline comments
 
@@ -120,41 +120,41 @@ void SetDate(uint date)
 
void CSleep(int milliseconds)
 
{
 
	#if defined(WIN32)
 
		Sleep(milliseconds);
 
	#endif
 
	#if defined(UNIX)
 
		#if !defined(__BEOS__) && !defined(__AMIGA__)
 
			usleep(milliseconds * 1000);
 
		#endif
 
		#ifdef __BEOS__
 
			snooze(milliseconds * 1000);
 
		#endif
 
		#if defined(__AMIGA__) 
 
		#if defined(__AMIGA__)
 
		{
 
			ULONG signals;
 
			ULONG TimerSigBit = 1 << TimerPort->mp_SigBit;
 

	
 
			// send IORequest
 
			TimerRequest->tr_node.io_Command = TR_ADDREQUEST;
 
			TimerRequest->tr_time.tv_secs    = (milliseconds * 1000) / 1000000;
 
			TimerRequest->tr_time.tv_micro   = (milliseconds * 1000) % 1000000;
 
			SendIO((struct IORequest *)TimerRequest);
 

	
 
			if (!((signals = Wait(TimerSigBit | SIGBREAKF_CTRL_C)) & TimerSigBit) ) {
 
				AbortIO((struct IORequest *)TimerRequest);
 
			}
 
			WaitIO((struct IORequest *)TimerRequest);
 
		}
 
		#endif // __AMIGA__ 
 
		#endif // __AMIGA__
 
	#endif
 
}
 

	
 
void InitializeClearLand();
 
void InitializeRail();
 
void InitializeRailGui();
 
void InitializeRoad();
 
void InitializeRoadGui();
 
void InitializeAirportGui();
 
void InitializeDock();
 
void InitializeDockGui();
 
void InitializeIndustries();
 
@@ -681,24 +681,28 @@ void IncreaseDate()
 
	/* check if we entered a new year? */
 
	if ((byte)ymd.year == _cur_year)
 
		return;
 
	_cur_year = ymd.year;
 

	
 
	/* yes, call various yearly loops */
 

	
 
	PlayersYearlyLoop();
 
	TrainsYearlyLoop();
 
	RoadVehiclesYearlyLoop();
 
	AircraftYearlyLoop();
 
	ShipsYearlyLoop();
 
#ifdef ENABLE_NETWORK
 
	if (_network_server)
 
		NetworkServerYearlyLoop();
 
#endif /* ENABLE_NETWORK */
 

	
 
	/* check if we reached 2090, that's the maximum year. */
 
	if (_cur_year == 171) {
 
		Vehicle *v;
 
		_cur_year = 170;
 
		_date = 62093;
 
		FOR_ALL_VEHICLES(v) {
 
			v->date_of_last_service -= 365; // 1 year is 365 days long
 
		}
 
	}
 

	
 
	if (_patches.auto_euro)
network.h
Show inline comments
 
@@ -175,24 +175,26 @@ VARDEF bool _network_udp_server;
 
VARDEF uint16 _network_udp_broadcast;
 

	
 
VARDEF byte _network_lan_internet;
 

	
 
VARDEF bool _network_advertise;
 
VARDEF uint16 _network_last_advertise_date;
 
VARDEF uint8 _network_advertise_retries;
 

	
 
VARDEF bool _network_autoclean_companies;
 
VARDEF uint8 _network_autoclean_unprotected; // Remove a company after X months
 
VARDEF uint8 _network_autoclean_protected;   // Unprotect a company after X months
 

	
 
VARDEF uint16 _network_restart_game_date;    // If this year is reached, the server automaticly restarts
 

	
 
NetworkGameList *NetworkQueryServer(const byte* host, unsigned short port, bool game_info);
 

	
 
#endif /* ENABLE_NETWORK */
 

	
 
// Those variables must always be registered!
 
#define MAX_SAVED_SERVERS 10
 
VARDEF char *_network_host_list[MAX_SAVED_SERVERS];
 
VARDEF bool _networking;
 
VARDEF bool _network_available;  // is network mode available?
 
VARDEF bool _network_server; // network-server is active
 
VARDEF bool _network_dedicated; // are we a dedicated server?
 
VARDEF byte _network_playas; // an id to play as..
network_server.c
Show inline comments
 
@@ -1250,24 +1250,41 @@ void NetworkUpdateClientInfo(uint16 clie
 
	NetworkClientInfo *ci;
 

	
 
	ci = NetworkFindClientInfoFromIndex(client_index);
 

	
 
	if (ci == NULL)
 
		return;
 

	
 
	FOR_ALL_CLIENTS(cs) {
 
		SEND_COMMAND(PACKET_SERVER_CLIENT_INFO)(cs, ci);
 
	}
 
}
 

	
 
extern void SwitchMode(int new_mode);
 

	
 
/* Check if we want to restart the map */
 
static void NetworkCheckRestartMap()
 
{
 
	if (_network_restart_game_date != 0 && _cur_year + 1920 >= _network_restart_game_date) {
 
		_docommand_recursive = 0;
 

	
 
		DEBUG(net, 0)("Auto-restarting map. Year %d reached.", _cur_year + 1920);
 

	
 
		_random_seeds[0][0] = Random();
 
		_random_seeds[0][1] = InteractiveRandom();
 

	
 
		SwitchMode(SM_NEWGAME);
 
	}
 
}
 

	
 
/* Check if the server has autoclean_companies activated
 
    Two things happen:
 
      1) If a company is not protected, it is closed after 1 year (for example)
 
      2) If a company is protected, protection is disabled after 3 years (for example)
 
           (and item 1. happens a year later) */
 
static void NetworkAutoCleanCompanies()
 
{
 
	NetworkClientState *cs;
 
	NetworkClientInfo *ci;
 
	Player *p;
 
	bool clients_in_company[MAX_PLAYERS];
 

	
 
@@ -1468,18 +1485,23 @@ void NetworkServer_Tick(void)
 

	
 
#ifndef ENABLE_NETWORK_SYNC_EVERY_FRAME
 
	// Update the last_sync_frame if needed!
 
	if (last_sync_frame + _network_sync_freq < _frame_counter) {
 
		last_sync_frame = _frame_counter;
 
	}
 
#endif
 

	
 
	/* See if we need to advertise */
 
	NetworkUDPAdvertise();
 
}
 

	
 
void NetworkServerYearlyLoop(void)
 
{
 
	NetworkCheckRestartMap();
 
}
 

	
 
void NetworkServerMonthlyLoop(void)
 
{
 
	NetworkAutoCleanCompanies();
 
}
 

	
 
#endif /* ENABLE_NETWORK */
network_server.h
Show inline comments
 
@@ -6,16 +6,17 @@
 
DEF_SERVER_SEND_COMMAND(PACKET_SERVER_MAP);
 
DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_ERROR_QUIT)(NetworkClientState *cs, uint16 client_index, NetworkErrorCode errorno);
 
DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_ERROR)(NetworkClientState *cs, NetworkErrorCode error);
 
DEF_SERVER_SEND_COMMAND(PACKET_SERVER_SHUTDOWN);
 
DEF_SERVER_SEND_COMMAND(PACKET_SERVER_NEWGAME);
 

	
 
bool NetworkFindName(char new_name[NETWORK_NAME_LENGTH]);
 
void NetworkServer_HandleChat(NetworkAction action, DestType desttype, int dest, const char *msg, byte from_index);
 

	
 
bool NetworkServer_ReadPackets(NetworkClientState *cs);
 
void NetworkServer_Tick(void);
 
void NetworkServerMonthlyLoop(void);
 
void NetworkServerYearlyLoop(void);
 

	
 
#endif /* ENABLE_NETWORK */
 

	
 
#endif // NETWORK_SERVER_H
settings.c
Show inline comments
 
@@ -757,24 +757,25 @@ static const SettingDesc network_setting
 
	{"server_bind_ip",	SDT_STRINGBUF | (lengthof(_network_server_bind_ip_host) << 16),	"0.0.0.0",	&_network_server_bind_ip_host,	NULL},
 
	{"server_port",			SDT_UINT,	(void*)NETWORK_DEFAULT_PORT,	&_network_server_port,	NULL},
 
	{"server_advertise",SDT_BOOL, (void*)false, &_network_advertise, NULL},
 
	{"lan_internet",		SDT_UINT8, (void*)0, &_network_lan_internet, NULL},
 
	{"player_name",			SDT_STRINGBUF | (lengthof(_network_player_name) << 16), NULL, &_network_player_name, NULL},
 
	{"server_password",	SDT_STRINGBUF | (lengthof(_network_game_info.server_password) << 16), NULL, &_network_game_info.server_password, NULL},
 
	{"server_name",			SDT_STRINGBUF | (lengthof(_network_server_name) << 16), NULL, &_network_server_name, NULL},
 
	{"connect_to_ip",		SDT_STRINGBUF | (lengthof(_network_default_ip) << 16), NULL, &_network_default_ip, NULL},
 
	{"network_id",			SDT_STRINGBUF | (lengthof(_network_unique_id) << 16), NULL, &_network_unique_id, NULL},
 
	{"autoclean_companies", SDT_BOOL, (void*)false, &_network_autoclean_companies, NULL},
 
	{"autoclean_unprotected", SDT_UINT8, (void*)12, &_network_autoclean_unprotected, NULL},
 
	{"autoclean_protected", SDT_UINT8, (void*)36, &_network_autoclean_protected, NULL},
 
	{"restart_game_date", SDT_UINT16, (void*)0, &_network_restart_game_date, NULL},
 
	{NULL,							0,											NULL,					NULL,										NULL}
 
};
 
#endif /* ENABLE_NETWORK */
 

	
 
static const SettingDesc debug_settings[] = {
 
	{"savedump_path",		SDT_STRINGBUF | (lengthof(_savedump_path)<<16) | SDT_NOSAVE, NULL, _savedump_path, NULL},
 
	{"savedump_first",	SDT_UINT | SDT_NOSAVE,	0,				&_savedump_first, NULL},
 
	{"savedump_freq",		SDT_UINT | SDT_NOSAVE,	(void*)1, &_savedump_freq,	NULL},
 
	{"savedump_last",		SDT_UINT | SDT_NOSAVE,	0,				&_savedump_last,	NULL},
 
	{NULL,							0,											NULL,			NULL,							NULL}
 
};
 

	
0 comments (0 inline, 0 general)