Merge branch 'house_placing' into jgrpp

This commit is contained in:
Jonathan G Rennison
2015-09-21 22:17:37 +01:00
13 changed files with 202 additions and 140 deletions

View File

@@ -63,7 +63,6 @@ NetworkCompanyState *_network_company_states = NULL; ///< Statistics about some
ClientID _network_own_client_id; ///< Our client identifier.
ClientID _redirect_console_to_client; ///< If not invalid, redirect the console output to a client.
bool _network_need_advertise; ///< Whether we need to advertise.
uint32 _network_last_advertise_frame; ///< Last time we did advertise.
uint8 _network_reconnect; ///< Reconnect timeout
StringList _network_bind_list; ///< The addresses to bind on.
StringList _network_host_list; ///< The servers we know.
@@ -762,7 +761,6 @@ bool NetworkServerStart()
if (_network_dedicated) IConsoleCmdExec("exec scripts/on_dedicated.scr 0");
/* Try to register us to the master server */
_network_last_advertise_frame = 0;
_network_need_advertise = true;
NetworkUDPAdvertise();
@@ -1079,7 +1077,6 @@ void NetworkStartUp()
/* Network is available */
_network_available = NetworkCoreInitialize();
_network_dedicated = false;
_network_last_advertise_frame = 0;
_network_need_advertise = true;
_network_advertise_retries = 0;

View File

@@ -34,7 +34,6 @@ extern NetworkCompanyState *_network_company_states;
extern ClientID _network_own_client_id;
extern ClientID _redirect_console_to_client;
extern bool _network_need_advertise;
extern uint32 _network_last_advertise_frame;
extern uint8 _network_reconnect;
extern StringList _network_bind_list;
extern StringList _network_host_list;

View File

@@ -42,9 +42,9 @@ static ThreadMutex *_network_udp_mutex = ThreadMutex::New();
/** Session key to register ourselves to the master server */
static uint64 _session_key = 0;
static const uint ADVERTISE_NORMAL_INTERVAL = 30000; ///< interval between advertising in ticks (15 minutes)
static const uint ADVERTISE_RETRY_INTERVAL = 300; ///< re-advertise when no response after this many ticks (9 seconds)
static const uint ADVERTISE_RETRY_TIMES = 3; ///< give up re-advertising after this much failed retries
static const uint32 ADVERTISE_NORMAL_INTERVAL = 15 * 60 * 1000; ///< interval between advertising in ms (15 minutes)
static const uint32 ADVERTISE_RETRY_INTERVAL = 10 * 1000; ///< re-advertise when no response after this many ms (10 seconds)
static const uint32 ADVERTISE_RETRY_TIMES = 3; ///< give up re-advertising after this much failed retries
NetworkUDPSocketHandler *_udp_client_socket = NULL; ///< udp client socket
NetworkUDPSocketHandler *_udp_server_socket = NULL; ///< udp server socket
@@ -616,25 +616,37 @@ static void NetworkUDPAdvertiseThread(void *pntr)
*/
void NetworkUDPAdvertise()
{
static uint32 _last_advertisement = 0; ///< The time of the last advertisement (used to check for wrapping of time)
static uint32 _next_advertisement = 0; ///< The next time we should perform a normal advertisement.
static uint32 _next_retry = 0; ///< The next time we should perform a retry of an advertisement.
/* Check if we should send an advertise */
if (!_networking || !_network_server || !_network_udp_server || !_settings_client.network.server_advertise) return;
if (_network_need_advertise) {
if (_network_need_advertise || _realtime_tick < _last_advertisement) {
/* Forced advertisement, or a wrapping of time in which case we determine the advertisement/retry times again. */
_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;
if (_realtime_tick <= _next_advertisement) return;
_network_advertise_retries = ADVERTISE_RETRY_TIMES;
} else {
/* An actual retry. */
if (_realtime_tick <= _next_retry) return;
}
if ((_network_last_advertise_frame + ADVERTISE_RETRY_INTERVAL) > _frame_counter) return;
}
_network_advertise_retries--;
_network_last_advertise_frame = _frame_counter;
_last_advertisement = _realtime_tick;
_next_advertisement = _realtime_tick + ADVERTISE_NORMAL_INTERVAL;
_next_retry = _realtime_tick + ADVERTISE_RETRY_INTERVAL;
/* Make sure we do not have an overflow when checking these; when time wraps, we simply force an advertisement. */
if (_next_advertisement < _last_advertisement) _next_advertisement = UINT32_MAX;
if (_next_retry < _last_advertisement) _next_retry = UINT32_MAX;
if (!ThreadObject::New(NetworkUDPAdvertiseThread, NULL)) {
NetworkUDPAdvertiseThread(NULL);