(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.
This commit is contained in:
		
							
								
								
									
										3
									
								
								misc.c
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								misc.c
									
									
									
									
									
								
							@@ -82,7 +82,8 @@ void SetDate(uint date)
 | 
				
			|||||||
	_cur_year = ymd.year;
 | 
						_cur_year = ymd.year;
 | 
				
			||||||
	_cur_month = ymd.month;
 | 
						_cur_month = ymd.month;
 | 
				
			||||||
#ifdef ENABLE_NETWORK
 | 
					#ifdef ENABLE_NETWORK
 | 
				
			||||||
	_network_last_advertise_date = 0;
 | 
						_network_last_advertise_frame = 0;
 | 
				
			||||||
 | 
						_network_need_advertise = true;
 | 
				
			||||||
#endif /* ENABLE_NETWORK */
 | 
					#endif /* ENABLE_NETWORK */
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -983,7 +983,8 @@ bool NetworkServerStart(void)
 | 
				
			|||||||
	if (_network_dedicated) IConsoleCmdExec("exec scripts/on_dedicated.scr 0");
 | 
						if (_network_dedicated) IConsoleCmdExec("exec scripts/on_dedicated.scr 0");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Try to register us to the master server */
 | 
						/* Try to register us to the master server */
 | 
				
			||||||
	_network_last_advertise_date = 0;
 | 
						_network_last_advertise_frame = 0;
 | 
				
			||||||
 | 
						_network_need_advertise = true;
 | 
				
			||||||
	NetworkUDPAdvertise();
 | 
						NetworkUDPAdvertise();
 | 
				
			||||||
	return true;
 | 
						return true;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -1321,7 +1322,8 @@ void NetworkStartUp(void)
 | 
				
			|||||||
    // Network is available
 | 
					    // Network is available
 | 
				
			||||||
	_network_available = true;
 | 
						_network_available = true;
 | 
				
			||||||
	_network_dedicated = false;
 | 
						_network_dedicated = false;
 | 
				
			||||||
	_network_last_advertise_date = 0;
 | 
						_network_last_advertise_frame = 0;
 | 
				
			||||||
 | 
						_network_need_advertise = true;
 | 
				
			||||||
	_network_advertise_retries = 0;
 | 
						_network_advertise_retries = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Load the ip from the openttd.cfg */
 | 
						/* Load the ip from the openttd.cfg */
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -197,7 +197,8 @@ VARDEF uint16 _network_udp_broadcast;
 | 
				
			|||||||
VARDEF byte _network_lan_internet;
 | 
					VARDEF byte _network_lan_internet;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
VARDEF bool _network_advertise;
 | 
					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 uint8 _network_advertise_retries;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
VARDEF bool _network_autoclean_companies;
 | 
					VARDEF bool _network_autoclean_companies;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -35,8 +35,8 @@ typedef enum {
 | 
				
			|||||||
} PacketUDPType;
 | 
					} PacketUDPType;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
enum {
 | 
					enum {
 | 
				
			||||||
	ADVERTISE_NORMAL_INTERVAL = 450,	// interval between advertising in days
 | 
						ADVERTISE_NORMAL_INTERVAL = 30000, // interval between advertising in ticks (15 minutes)
 | 
				
			||||||
	ADVERTISE_RETRY_INTERVAL = 5,			// readvertise when no response after this amount of days
 | 
						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
 | 
						ADVERTISE_RETRY_TIMES = 3          // give up readvertising after this much failed retries
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -611,18 +611,23 @@ void NetworkUDPAdvertise(void)
 | 
				
			|||||||
		if (!NetworkUDPListen(&_udp_master_socket, _network_server_bind_ip, 0, false))
 | 
							if (!NetworkUDPListen(&_udp_master_socket, _network_server_bind_ip, 0, false))
 | 
				
			||||||
			return;
 | 
								return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Only send once in the 450 game-days (about 15 minutes) */
 | 
						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_advertise_retries == 0) {
 | 
				
			||||||
		if ( (_network_last_advertise_date + ADVERTISE_NORMAL_INTERVAL) > _date)
 | 
								if ((_network_last_advertise_frame + ADVERTISE_NORMAL_INTERVAL) > _frame_counter)
 | 
				
			||||||
				return;
 | 
									return;
 | 
				
			||||||
			_network_advertise_retries = ADVERTISE_RETRY_TIMES;
 | 
								_network_advertise_retries = ADVERTISE_RETRY_TIMES;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if ( (_network_last_advertise_date + ADVERTISE_RETRY_INTERVAL) > _date)
 | 
							if ((_network_last_advertise_frame + ADVERTISE_RETRY_INTERVAL) > _frame_counter)
 | 
				
			||||||
			return;
 | 
								return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	_network_advertise_retries--;
 | 
						_network_advertise_retries--;
 | 
				
			||||||
	_network_last_advertise_date = _date;
 | 
						_network_last_advertise_frame = _frame_counter;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Find somewhere to send */
 | 
						/* Find somewhere to send */
 | 
				
			||||||
	out_addr.sin_family = AF_INET;
 | 
						out_addr.sin_family = AF_INET;
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user