From e5f5a1c04df6f04ea5da1256d514610b8b7b143e Mon Sep 17 00:00:00 2001 From: Benau Date: Sat, 15 Sep 2018 15:10:03 +0800 Subject: [PATCH] Use a more server owner friendly value instead of threshold --- src/main.cpp | 7 +++---- src/network/game_setup.cpp | 5 ++--- src/network/protocols/client_lobby.cpp | 9 ++++----- src/network/protocols/server_lobby.cpp | 10 +++------- src/network/server_config.cpp | 4 ++++ src/network/server_config.hpp | 6 +++--- src/states_screens/networking_lobby.cpp | 17 +++++++++-------- src/states_screens/networking_lobby.hpp | 5 +++-- 8 files changed, 31 insertions(+), 32 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 161d846b8..9a7f73d8e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1228,10 +1228,9 @@ int handleCmdLine(bool has_server_config, bool has_parent_process) if (CommandLine::has("--min-players", &n)) { - float threshold = ((float)(n) - 0.5f) / - ServerConfig::m_server_max_players; - threshold = std::max(std::min(threshold, 1.0f), 0.0f); - ServerConfig::m_start_game_threshold = threshold; + if (n > ServerConfig::m_server_max_players) + n = 1; + ServerConfig::m_min_start_game_players = n; } if (CommandLine::has("--port", &n)) { diff --git a/src/network/game_setup.cpp b/src/network/game_setup.cpp index 8f49b5358..6af5ce125 100644 --- a/src/network/game_setup.cpp +++ b/src/network/game_setup.cpp @@ -216,12 +216,11 @@ void GameSetup::addServerInfo(NetworkString* ns) } if (ServerConfig::m_owner_less) { - ns->addFloat(ServerConfig::m_start_game_threshold) + ns->addUInt8(ServerConfig::m_min_start_game_players) .addFloat(ServerConfig::m_start_game_counter); } else - ns->addFloat(0.0f).addFloat(0.0f); - ns->addUInt8(ServerConfig::m_server_max_players); + ns->addUInt8(0).addFloat(0.0f); ns->encodeString16(m_message_of_today); } // addServerInfo diff --git a/src/network/protocols/client_lobby.cpp b/src/network/protocols/client_lobby.cpp index 9d510bfe0..43f1c198d 100644 --- a/src/network/protocols/client_lobby.cpp +++ b/src/network/protocols/client_lobby.cpp @@ -574,9 +574,9 @@ void ClientLobby::handleServerInfo(Event* event) each_line = _("Difficulty: %s", difficulty_name); NetworkingLobby::getInstance()->addMoreServerInfo(each_line); - u_data = data.getUInt8(); + unsigned max_player = data.getUInt8(); //I18N: In the networking lobby - each_line = _("Max players: %d", (int)u_data); + each_line = _("Max players: %d", (int)max_player); NetworkingLobby::getInstance()->addMoreServerInfo(each_line); u_data = data.getUInt8(); @@ -627,11 +627,10 @@ void ClientLobby::handleServerInfo(Event* event) } } // Auto start info - float start_threshold = data.getFloat(); + unsigned min_players = data.getUInt8(); float start_timeout = data.getFloat(); - unsigned max_player = data.getUInt8(); NetworkingLobby::getInstance()->initAutoStartTimer(grand_prix_started, - start_threshold, start_timeout, max_player); + min_players, start_timeout, max_player); // MOTD core::stringw motd; diff --git a/src/network/protocols/server_lobby.cpp b/src/network/protocols/server_lobby.cpp index d8765e56f..0113ac9bb 100644 --- a/src/network/protocols/server_lobby.cpp +++ b/src/network/protocols/server_lobby.cpp @@ -437,10 +437,8 @@ void ServerLobby::asynchronousUpdate() { if (ServerConfig::m_owner_less) { - float player_size = (float)m_game_setup->getPlayerCount(); - if ((player_size >= - (float)ServerConfig::m_server_max_players * - ServerConfig::m_start_game_threshold || + int player_size = m_game_setup->getPlayerCount(); + if ((player_size >= ServerConfig::m_min_start_game_players || m_game_setup->isGrandPrixStarted()) && m_timeout.load() == std::numeric_limits::max()) { @@ -448,9 +446,7 @@ void ServerLobby::asynchronousUpdate() (int64_t) (ServerConfig::m_start_game_counter * 1000.0f)); } - else if (player_size < - (float)ServerConfig::m_server_max_players* - ServerConfig::m_start_game_threshold && + else if (player_size < ServerConfig::m_min_start_game_players && !m_game_setup->isGrandPrixStarted()) { m_timeout.store(std::numeric_limits::max()); diff --git a/src/network/server_config.cpp b/src/network/server_config.cpp index 2cfea03d0..80cbbea42 100644 --- a/src/network/server_config.cpp +++ b/src/network/server_config.cpp @@ -275,7 +275,11 @@ void loadServerLobbyFromConfig() m_owner_less = true; } if (m_owner_less) + { + if (m_min_start_game_players > m_server_max_players) + m_min_start_game_players = 1; m_team_choosing = false; + } const bool is_soccer = race_manager->getMinorMode() == RaceManager::MINOR_MODE_SOCCER; diff --git a/src/network/server_config.hpp b/src/network/server_config.hpp index 5b38c5c0e..b893005ba 100644 --- a/src/network/server_config.hpp +++ b/src/network/server_config.hpp @@ -176,10 +176,10 @@ namespace ServerConfig "if satisfied start-game-threshold below for owner less or ranked " "server.")); - SERVER_CFG_PREFIX FloatServerConfigParam m_start_game_threshold - SERVER_CFG_DEFAULT(FloatServerConfigParam(0.5f, "start-game-threshold", + SERVER_CFG_PREFIX IntServerConfigParam m_min_start_game_players + SERVER_CFG_DEFAULT(IntServerConfigParam(2, "min-start-game-players", "Only auto start kart selection when number of " - "connected player is larger than max player * this value, for " + "connected player is larger than or equals this value, for " "owner less or ranked server, after start-game-counter.")); SERVER_CFG_PREFIX BoolServerConfigParam m_auto_end diff --git a/src/states_screens/networking_lobby.cpp b/src/states_screens/networking_lobby.cpp index 8499b534b..448781a75 100644 --- a/src/states_screens/networking_lobby.cpp +++ b/src/states_screens/networking_lobby.cpp @@ -143,8 +143,9 @@ void NetworkingLobby::init() m_allow_change_team = false; m_has_auto_start_in_server = false; m_ping_update_timer = 0.0f; - m_cur_starting_timer = m_start_threshold = m_start_timeout = + m_cur_starting_timer = m_start_timeout = m_server_max_player = std::numeric_limits::max(); + m_min_start_game_players = 0; m_timeout_message->setVisible(false); //I18N: In the networking lobby @@ -252,13 +253,13 @@ void NetworkingLobby::onUpdate(float delta) if (m_has_auto_start_in_server && m_player_list) { m_timeout_message->setVisible(true); - float cur_player = (float)(m_player_list->getItemCount()); - if (cur_player >= m_server_max_player * m_start_threshold && + unsigned cur_player = m_player_list->getItemCount(); + if (cur_player >= m_min_start_game_players && m_cur_starting_timer == std::numeric_limits::max()) { m_cur_starting_timer = m_start_timeout; } - else if (cur_player < m_server_max_player * m_start_threshold) + else if (cur_player < m_min_start_game_players) { m_cur_starting_timer = std::numeric_limits::max(); //I18N: In the networking lobby, display the number of players @@ -266,7 +267,7 @@ void NetworkingLobby::onUpdate(float delta) core::stringw msg = _P("Game will start if there is more than %d player.", "Game will start if there are more than %d players.", - (int)ceil(m_server_max_player * m_start_threshold) - 1); + (int)(m_min_start_game_players - 1)); m_timeout_message->setText(msg, true); } @@ -534,15 +535,15 @@ void NetworkingLobby::cleanAddedPlayers() // ---------------------------------------------------------------------------- void NetworkingLobby::initAutoStartTimer(bool grand_prix_started, - float start_threshold, + unsigned min_players, float start_timeout, unsigned server_max_player) { - if (start_threshold == 0.0f || start_timeout == 0.0f) + if (min_players == 0 || start_timeout == 0.0f) return; m_has_auto_start_in_server = true; - m_start_threshold = grand_prix_started ? 0.0f : start_threshold; + m_min_start_game_players = grand_prix_started ? 0 : min_players; m_start_timeout = start_timeout; m_server_max_player = (float)server_max_player; } // initAutoStartTimer diff --git a/src/states_screens/networking_lobby.hpp b/src/states_screens/networking_lobby.hpp index e01c2b3ea..37a00aac6 100644 --- a/src/states_screens/networking_lobby.hpp +++ b/src/states_screens/networking_lobby.hpp @@ -71,8 +71,9 @@ private: std::vector m_server_info; int m_server_info_height; - float m_cur_starting_timer, m_start_threshold, m_start_timeout, + float m_cur_starting_timer, m_start_timeout, m_server_max_player; + unsigned m_min_start_game_players; bool m_allow_change_team, m_has_auto_start_in_server; @@ -137,7 +138,7 @@ public: KartTeam> >& p); void addSplitscreenPlayer(irr::core::stringw name); void cleanAddedPlayers(); - void initAutoStartTimer(bool grand_prix_started, float start_threshold, + void initAutoStartTimer(bool grand_prix_started, unsigned min_players, float start_timeout, unsigned server_max_player); void setStartingTimerTo(float t) { m_cur_starting_timer = t; }