Allow to specify minimum number of players in command line

This commit is contained in:
Deve
2018-07-22 22:48:45 +02:00
parent a22fde85ec
commit ea13d97f6b
3 changed files with 25 additions and 8 deletions

View File

@@ -603,6 +603,7 @@ void cmdLineHelp()
" --disable-lan Disable LAN detection (connect using WAN).\n"
" --auto-connect Automatically connect to fist server and start race\n"
" --max-players=n Maximum number of clients (server only).\n"
" --min-players=n Minimum number of clients (server only).\n"
" --motd Message showing in all lobby of clients, can specify a .txt file.\n"
" --auto-end Automatically end network game after 1st player finished\n"
" for some time (currently his finished time * 0.25 + 15.0). \n"
@@ -1140,12 +1141,28 @@ int handleCmdLine()
NetworkConfig::get()->setServerIdFile(
file_manager->getUserConfigFile(s));
}
if(CommandLine::has("--disable-polling"))
if (CommandLine::has("--disable-polling"))
{
Online::RequestManager::m_disable_polling = true;
if(CommandLine::has("--max-players", &n))
UserConfigParams::m_server_max_players=n;
NetworkConfig::get()->
setMaxPlayers(UserConfigParams::m_server_max_players);
}
if (CommandLine::has("--max-players", &n))
{
UserConfigParams::m_server_max_players = n;
}
if (UserConfigParams::m_server_max_players < 1)
{
UserConfigParams::m_server_max_players = 1;
}
NetworkConfig::get()->setMaxPlayers(UserConfigParams::m_server_max_players);
if (CommandLine::has("--min-players", &n))
{
float threshold = ((float)(n) - 0.5f) /
UserConfigParams::m_server_max_players;
threshold = std::max(std::min(threshold, 1.0f), 0.0f);
UserConfigParams::m_start_game_threshold = threshold;
}
if (CommandLine::has("--port", &n))
{
// We don't know if this instance is going to be a client

View File

@@ -381,7 +381,7 @@ void ServerLobby::asynchronousUpdate()
if (NetworkConfig::get()->isOwnerLess())
{
auto players = m_game_setup->getPlayers();
if (((float)players.size() >
if (((float)players.size() >=
(float)NetworkConfig::get()->getMaxPlayers() *
UserConfigParams::m_start_game_threshold ||
m_game_setup->isGrandPrixStarted()) &&

View File

@@ -213,7 +213,7 @@ void NetworkingLobby::onUpdate(float delta)
if (m_timeout_message->isVisible() && m_player_list)
{
float cur_player = (float)(m_player_list->getItemCount());
if (cur_player > m_server_max_player * m_start_threshold &&
if (cur_player >= m_server_max_player * m_start_threshold &&
m_cur_starting_timer == std::numeric_limits<float>::max())
{
m_cur_starting_timer = m_start_timeout;
@@ -226,7 +226,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)floor(m_server_max_player * m_start_threshold));
(int)ceil(m_server_max_player * m_start_threshold) - 1);
m_timeout_message->setText(msg, true);
}