Mercurial > hg > openttd
changeset 13533:5ab8386b02bc draft
(svn r18054) -Change/Fix [FS#3310]: make pause on join pause during the whole joining (including download) phase
author | rubidium <rubidium@openttd.org> |
---|---|
date | Thu, 12 Nov 2009 20:52:14 +0000 |
parents | 6386a541e470 |
children | 84977eed16e4 |
files | src/network/network.cpp src/network/network_server.cpp |
diffstat | 2 files changed, 48 insertions(+), 23 deletions(-) [+] |
line wrap: on
line diff
--- a/src/network/network.cpp +++ b/src/network/network.cpp @@ -396,6 +396,21 @@ /** + * Helper function for the pause checkers. If pause is true and the + * current pause mode isn't set the game will be paused, if it it false + * and the pause mode is set the game will be unpaused. In the other + * cases nothing happens to the pause state. + * @param pause whether we'd like to pause + * @param pm the mode which we would like to pause with + */ +static void CheckPauseHelper(bool pause, PauseMode pm) +{ + if (pause == ((_pause_mode & pm) != PM_UNPAUSED)) return; + + DoCommandP(0, pm, pause ? 1 : 0, CMD_PAUSE); +} + +/** * Counts the number of active clients connected. * It has to be in STATUS_ACTIVE and not a spectator * @return number of active clients @@ -414,20 +429,43 @@ return count; } -/* Check if the minimum number of active clients has been reached and pause or unpause the game as appropriate */ +/** + * Check if the minimum number of active clients has been reached and pause or unpause the game as appropriate + */ static void CheckMinActiveClients() { - if (!_network_dedicated || _settings_client.network.min_active_clients == 0 || (_pause_mode & PM_PAUSED_ERROR) != 0) return; - - if (NetworkCountActiveClients() < _settings_client.network.min_active_clients) { - if ((_pause_mode & PM_PAUSED_ACTIVE_CLIENTS) != 0) return; + if ((_pause_mode & PM_PAUSED_ERROR) != PM_UNPAUSED || + !_network_dedicated || + (_settings_client.network.min_active_clients == 0 && (_pause_mode & PM_PAUSED_ACTIVE_CLIENTS) == PM_UNPAUSED)) { + return; + } + CheckPauseHelper(NetworkCountActiveClients() < _settings_client.network.min_active_clients, PM_PAUSED_ACTIVE_CLIENTS); +} - DoCommandP(0, PM_PAUSED_ACTIVE_CLIENTS, 1, CMD_PAUSE); - } else { - if ((_pause_mode & PM_PAUSED_ACTIVE_CLIENTS) == 0) return; +/** + * Checks whether there is a joining client + * @return true iff one client is joining (but not authorizing) + */ +static bool NetworkHasJoiningClient() +{ + const NetworkClientSocket *cs; + FOR_ALL_CLIENT_SOCKETS(cs) { + if (cs->status >= STATUS_AUTH && cs->status < STATUS_ACTIVE) return true; + } - DoCommandP(0, PM_PAUSED_ACTIVE_CLIENTS, 0, CMD_PAUSE); + return false; +} + +/** + * Check whether we should pause on join + */ +static void CheckPauseOnJoin() +{ + if ((_pause_mode & PM_PAUSED_ERROR) != PM_UNPAUSED || + (!_settings_client.network.pause_on_join && (_pause_mode & PM_PAUSED_JOIN) == PM_UNPAUSED)) { + return; } + CheckPauseHelper(NetworkHasJoiningClient(), PM_PAUSED_JOIN); } /** Converts a string to ip/port/company @@ -526,11 +564,6 @@ DEBUG(net, 1, "Closed client connection %d", cs->client_id); - /* When the client was PRE_ACTIVE, the server was in pause mode, so unpause */ - if (cs->status == STATUS_PRE_ACTIVE && (_pause_mode & PM_PAUSED_JOIN)) { - DoCommandP(0, PM_PAUSED_JOIN, 0, CMD_PAUSE); - } - if (_network_server) { /* We just lost one client :( */ if (cs->status >= STATUS_AUTH) _network_game_info.clients_on--; @@ -1070,6 +1103,7 @@ /* Only check for active clients just before we're going to send out * the commands so we don't send multiple pause/unpause commands when * the frame_freq is more than 1 tick. */ + CheckPauseOnJoin(); CheckMinActiveClients(); }
--- a/src/network/network_server.cpp +++ b/src/network/network_server.cpp @@ -829,11 +829,6 @@ } } - if (_settings_client.network.pause_on_join) { - /* Now pause the game till the client is in sync */ - DoCommandP(0, PM_PAUSED_JOIN, 1, CMD_PAUSE); - } - /* also update the new client with our max values */ SEND_COMMAND(PACKET_SERVER_CONFIG_UPDATE)(cs); @@ -1022,10 +1017,6 @@ /* Now he is! Unpause the game */ cs->status = STATUS_ACTIVE; - if (_pause_mode & PM_PAUSED_JOIN) { - DoCommandP(0, PM_PAUSED_JOIN, 0, CMD_PAUSE); - } - /* Execute script for, e.g. MOTD */ IConsoleCmdExec("exec scripts/on_server_connect.scr 0"); }