Allow using fixed laps in server with --laps option

This commit is contained in:
Benau 2022-11-21 12:30:17 +08:00
parent 96f01d54ce
commit 0fbbd7bbaa
3 changed files with 19 additions and 4 deletions

View File

@ -568,7 +568,7 @@ void cmdLineHelp()
" --kart=NAME Use kart NAME.\n"
" --ai=a,b,... Use the karts a, b, ... for the AI, and additional player kart.\n"
" --aiNP=a,b,... Use the karts a, b, ... for the AI, no additional player kart.\n"
" --laps=N Define number of laps to N.\n"
" --laps=N Define number of laps to N, if used in a server all races will use this value.\n"
" --mode=N N=0 Normal, N=1 Time trial, N=2 Battle, N=3 Soccer,\n"
" N=4 Follow The Leader, N=5 Capture The Flag. In configure server use --battle-mode=n\n"
" for battle server and --soccer-timed / goals for soccer server\n"
@ -1685,7 +1685,10 @@ int handleCmdLine(bool has_server_config, bool has_parent_process)
else
{
Log::verbose("main", "You chose to have %d laps.", laps);
RaceManager::get()->setNumLaps(laps);
if (NetworkConfig::get()->isServer())
ServerLobby::m_fixed_laps = laps;
else
RaceManager::get()->setNumLaps(laps);
}
} // --laps

View File

@ -64,7 +64,7 @@
#include <iostream>
#include <iterator>
int ServerLobby::m_fixed_laps = -1;
// ========================================================================
class SubmitRankingRequest : public Online::XMLRequest
{
@ -2618,6 +2618,14 @@ void ServerLobby::startSelection(const Event *event)
Track* t = track_manager->getTrack(*it);
assert(t);
m_default_vote->m_num_laps = t->getDefaultNumberOfLaps();
if (ServerConfig::m_auto_game_time_ratio > 0.0f)
{
m_default_vote->m_num_laps =
(uint8_t)(fmaxf(1.0f, (float)t->getDefaultNumberOfLaps() *
ServerConfig::m_auto_game_time_ratio));
}
else if (m_fixed_laps != -1)
m_default_vote->m_num_laps = m_fixed_laps;
m_default_vote->m_reverse = rg.get(2) == 0;
break;
}
@ -2675,7 +2683,8 @@ void ServerLobby::startSelection(const Event *event)
ns->addUInt8(LE_START_SELECTION)
.addFloat(ServerConfig::m_voting_timeout)
.addUInt8(m_game_setup->isGrandPrixStarted() ? 1 : 0)
.addUInt8(ServerConfig::m_auto_game_time_ratio > 0.0f ? 1 : 0)
.addUInt8((ServerConfig::m_auto_game_time_ratio > 0.0f ||
m_fixed_laps != -1) ? 1 : 0)
.addUInt8(ServerConfig::m_track_voting ? 1 : 0);
const auto& all_k = m_available_kts.first;
@ -4185,6 +4194,8 @@ void ServerLobby::handlePlayerVote(Event* event)
(uint8_t)(fmaxf(1.0f, (float)t->getDefaultNumberOfLaps() *
ServerConfig::m_auto_game_time_ratio));
}
else if (m_fixed_laps != -1)
vote.m_num_laps = m_fixed_laps;
else if (vote.m_num_laps == 0 || vote.m_num_laps > 20)
vote.m_num_laps = (uint8_t)3;
if (!t->reverseAvailable() && vote.m_reverse)

View File

@ -413,6 +413,7 @@ public:
}
uint32_t getServerIdOnline() const { return m_server_id_online; }
void setClientServerHostId(uint32_t id) { m_client_server_host_id = id; }
static int m_fixed_laps;
}; // class ServerLobby
#endif // SERVER_LOBBY_HPP