Changeset - r2861:2a5e8951e185
[Not reviewed]
master
0 4 0
peter1138 - 18 years ago 2006-01-19 17:50:40
peter1138@openttd.org
(svn r3409) - Change the server advertisement interval to use the frame counter instead
of game days. This allows a paused server to continue to advertise itself.
This also fixes advertising for games that start before 1922.
4 files changed with 24 insertions and 15 deletions:
0 comments (0 inline, 0 general)
misc.c
Show inline comments
 
@@ -79,13 +79,14 @@ void SetDate(uint date)
 
{
 
	YearMonthDay ymd;
 
	ConvertDayToYMD(&ymd, _date = date);
 
	_cur_year = ymd.year;
 
	_cur_month = ymd.month;
 
#ifdef ENABLE_NETWORK
 
	_network_last_advertise_date = 0;
 
	_network_last_advertise_frame = 0;
 
	_network_need_advertise = true;
 
#endif /* ENABLE_NETWORK */
 
}
 

	
 
void InitializeVehicles(void);
 
void InitializeWaypoints(void);
 
void InitializeDepot(void);
network.c
Show inline comments
 
@@ -980,13 +980,14 @@ bool NetworkServerStart(void)
 
	// execute server initialization script
 
	IConsoleCmdExec("exec scripts/on_server.scr 0");
 
	// if the server is dedicated ... add some other script
 
	if (_network_dedicated) IConsoleCmdExec("exec scripts/on_dedicated.scr 0");
 

	
 
	/* Try to register us to the master server */
 
	_network_last_advertise_date = 0;
 
	_network_last_advertise_frame = 0;
 
	_network_need_advertise = true;
 
	NetworkUDPAdvertise();
 
	return true;
 
}
 

	
 
// The server is rebooting...
 
// The only difference with NetworkDisconnect, is the packets that is sent
 
@@ -1318,13 +1319,14 @@ void NetworkStartUp(void)
 
	}
 
	#endif // __MORPHOS__ / __AMIGA__
 

	
 
    // Network is available
 
	_network_available = true;
 
	_network_dedicated = false;
 
	_network_last_advertise_date = 0;
 
	_network_last_advertise_frame = 0;
 
	_network_need_advertise = true;
 
	_network_advertise_retries = 0;
 

	
 
	/* Load the ip from the openttd.cfg */
 
	_network_server_bind_ip = inet_addr(_network_server_bind_ip_host);
 
	/* And put the data back in it in case it was an invalid ip */
 
	snprintf(_network_server_bind_ip_host, sizeof(_network_server_bind_ip_host), "%s", inet_ntoa(*(struct in_addr *)&_network_server_bind_ip));
network.h
Show inline comments
 
@@ -194,13 +194,14 @@ VARDEF uint8 _network_reconnect;
 
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 bool _network_need_advertise;
 
VARDEF uint32 _network_last_advertise_frame;
 
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
 

	
network_udp.c
Show inline comments
 
@@ -32,15 +32,15 @@ typedef enum {
 
	PACKET_UDP_MASTER_RESPONSE_LIST, // Response from master server with server ip's + port's
 
	PACKET_UDP_SERVER_UNREGISTER, // Request to be removed from the server-list
 
	PACKET_UDP_END
 
} PacketUDPType;
 

	
 
enum {
 
	ADVERTISE_NORMAL_INTERVAL = 450,	// interval between advertising in days
 
	ADVERTISE_RETRY_INTERVAL = 5,			// readvertise when no response after this amount of days
 
	ADVERTISE_RETRY_TIMES = 3					// give up readvertising after this much failed retries
 
	ADVERTISE_NORMAL_INTERVAL = 30000, // interval between advertising in ticks (15 minutes)
 
	ADVERTISE_RETRY_INTERVAL = 300,    // readvertise when no response after this many ticks (9 seconds)
 
	ADVERTISE_RETRY_TIMES = 3          // give up readvertising after this much failed retries
 
};
 

	
 
#define DEF_UDP_RECEIVE_COMMAND(type) void NetworkPacketReceive_ ## type ## _command(Packet *p, struct sockaddr_in *client_addr)
 
static void NetworkSendUDP_Packet(SOCKET udp, Packet* p, struct sockaddr_in* recv);
 

	
 
static NetworkClientState _udp_cs;
 
@@ -608,24 +608,29 @@ void NetworkUDPAdvertise(void)
 

	
 
	/* check for socket */
 
	if (_udp_master_socket == INVALID_SOCKET)
 
		if (!NetworkUDPListen(&_udp_master_socket, _network_server_bind_ip, 0, false))
 
			return;
 

	
 
	/* Only send once in the 450 game-days (about 15 minutes) */
 
	if (_network_advertise_retries == 0) {
 
		if ( (_network_last_advertise_date + ADVERTISE_NORMAL_INTERVAL) > _date)
 
	if (_network_need_advertise) {
 
		_network_need_advertise = false;
 
		_network_advertise_retries = ADVERTISE_RETRY_TIMES;
 
	} else {
 
		/* Only send once every ADVERTISE_NORMAL_INTERVAL ticks */
 
		if (_network_advertise_retries == 0) {
 
			if ((_network_last_advertise_frame + ADVERTISE_NORMAL_INTERVAL) > _frame_counter)
 
				return;
 
			_network_advertise_retries = ADVERTISE_RETRY_TIMES;
 
		}
 

	
 
		if ((_network_last_advertise_frame + ADVERTISE_RETRY_INTERVAL) > _frame_counter)
 
			return;
 
		_network_advertise_retries = ADVERTISE_RETRY_TIMES;
 
	}
 

	
 
	if ( (_network_last_advertise_date + ADVERTISE_RETRY_INTERVAL) > _date)
 
		return;
 

	
 
	_network_advertise_retries--;
 
	_network_last_advertise_date = _date;
 
	_network_last_advertise_frame = _frame_counter;
 

	
 
	/* Find somewhere to send */
 
	out_addr.sin_family = AF_INET;
 
	out_addr.sin_port = htons(NETWORK_MASTER_SERVER_PORT);
 
	out_addr.sin_addr.s_addr = NetworkResolveHost(NETWORK_MASTER_SERVER_HOST);
 

	
0 comments (0 inline, 0 general)