diff options
author | rubidium <rubidium@openttd.org> | 2009-11-12 20:52:14 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2009-11-12 20:52:14 +0000 |
commit | b0f18a27fb2afed8b5c4149cffc5de11a5ca78e8 (patch) | |
tree | 3ad09ab3b24c201e323cfbc8b2fef38e82b3e24b /src/network | |
parent | 64ecceadda07d6c40d21f4a6c8911c2fdf86b921 (diff) | |
download | openttd-b0f18a27fb2afed8b5c4149cffc5de11a5ca78e8.tar.xz |
(svn r18054) -Change/Fix [FS#3310]: make pause on join pause during the whole joining (including download) phase
Diffstat (limited to 'src/network')
-rw-r--r-- | src/network/network.cpp | 60 | ||||
-rw-r--r-- | src/network/network_server.cpp | 9 |
2 files changed, 47 insertions, 22 deletions
diff --git a/src/network/network.cpp b/src/network/network.cpp index b8d79d327..04624648c 100644 --- a/src/network/network.cpp +++ b/src/network/network.cpp @@ -396,6 +396,21 @@ void NetworkHandlePauseChange(PauseMode prev_mode, PauseMode changed_mode) /** + * 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 @@ static uint NetworkCountActiveClients() 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 ((_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); +} - if (NetworkCountActiveClients() < _settings_client.network.min_active_clients) { - 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, 1, CMD_PAUSE); - } else { - if ((_pause_mode & PM_PAUSED_ACTIVE_CLIENTS) == 0) return; + return false; +} - DoCommandP(0, PM_PAUSED_ACTIVE_CLIENTS, 0, CMD_PAUSE); +/** + * 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 @@ void NetworkCloseClient(NetworkClientSocket *cs, bool error) 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 @@ void NetworkGameLoop() /* 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(); } diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp index efb005935..898e471ee 100644 --- a/src/network/network_server.cpp +++ b/src/network/network_server.cpp @@ -829,11 +829,6 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_MAP_OK) } } - 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 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_ACK) /* 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"); } |