diff options
author | Simon Howard | 2012-02-02 21:59:46 +0000 |
---|---|---|
committer | Simon Howard | 2012-02-02 21:59:46 +0000 |
commit | d0c89e469d1523eae383ff5b2dcf9d3bd758dc16 (patch) | |
tree | 6c8606c222b35957451e076d49a012e0a1f80601 /src | |
parent | 1138de4fb695a3ca5e4d06d75891fadce5cf7679 (diff) | |
download | chocolate-doom-d0c89e469d1523eae383ff5b2dcf9d3bd758dc16.tar.gz chocolate-doom-d0c89e469d1523eae383ff5b2dcf9d3bd758dc16.tar.bz2 chocolate-doom-d0c89e469d1523eae383ff5b2dcf9d3bd758dc16.zip |
Re-resolve the address of the master server every eight hours, to adapt
to changes in DNS configuration.
Subversion-branch: /trunk/chocolate-doom
Subversion-revision: 2486
Diffstat (limited to 'src')
-rw-r--r-- | src/net_server.c | 50 |
1 files changed, 44 insertions, 6 deletions
diff --git a/src/net_server.c b/src/net_server.c index d889c120..77be7a26 100644 --- a/src/net_server.c +++ b/src/net_server.c @@ -49,6 +49,10 @@ #define MASTER_REFRESH_PERIOD 20 * 60 /* 20 minutes */ +// How often to re-resolve the address of the master server? + +#define MASTER_RESOLVE_PERIOD 8 * 60 * 60 /* 8 hours */ + typedef enum { // waiting for the game to start @@ -141,6 +145,7 @@ static net_gamesettings_t sv_settings; static net_addr_t *master_server = NULL; static unsigned int master_refresh_time; +static unsigned int master_resolve_time; // receive window @@ -1561,6 +1566,42 @@ void NET_SV_Init(void) server_initialized = true; } +static void UpdateMasterServer(void) +{ + unsigned int now; + + now = I_GetTimeMS(); + + // The address of the master server can change. Periodically + // re-resolve the master server to update. + + if (now - master_resolve_time > MASTER_RESOLVE_PERIOD * 1000) + { + net_addr_t *new_addr; + printf("Re-resolve master server\n"); + + new_addr = NET_Query_ResolveMaster(server_context); + + // Has the master server changed address? + + if (new_addr != NULL && new_addr != master_server) + { + NET_FreeAddress(master_server); + master_server = new_addr; + } + + master_resolve_time = now; + } + + // Possibly refresh our registration with the master server. + + if (now - master_refresh_time > MASTER_REFRESH_PERIOD * 1000) + { + NET_Query_AddToMaster(master_server); + master_refresh_time = now; + } +} + void NET_SV_RegisterWithMaster(void) { //! @@ -1585,6 +1626,7 @@ void NET_SV_RegisterWithMaster(void) { NET_Query_AddToMaster(master_server); master_refresh_time = I_GetTimeMS(); + master_resolve_time = master_refresh_time; } } @@ -1608,13 +1650,9 @@ void NET_SV_Run(void) NET_FreePacket(packet); } - // Possibly refresh our registration with the master server. - - if (master_server != NULL - && I_GetTimeMS() - master_refresh_time > MASTER_REFRESH_PERIOD * 1000) + if (master_server != NULL) { - NET_Query_AddToMaster(master_server); - master_refresh_time = I_GetTimeMS(); + UpdateMasterServer(); } // "Run" any clients that may have things to do, independent of responses |