Make live join or spectate a server option

This commit is contained in:
Benau 2019-01-05 01:20:25 +08:00
parent 214272468d
commit 6a1a1740c0
4 changed files with 20 additions and 5 deletions

View File

@ -155,7 +155,9 @@ void GameSetup::addServerInfo(NetworkString* ns)
ns->encodeString16(m_message_of_today);
ns->addUInt8((uint8_t)ServerConfig::m_server_configurable);
ns->addUInt8(race_manager->supportsLiveJoining() ? 1 : 0);
ns->addUInt8(
ServerConfig::m_live_players && race_manager->supportsLiveJoining() ?
1 : 0);
} // addServerInfo
//-----------------------------------------------------------------------------

View File

@ -655,7 +655,8 @@ NetworkString* ServerLobby::getLoadWorldMessage(
//-----------------------------------------------------------------------------
bool ServerLobby::canLiveJoinNow() const
{
return race_manager->supportsLiveJoining() &&
return ServerConfig::m_live_players &&
race_manager->supportsLiveJoining() &&
World::getWorld() && RaceEventManager::getInstance()->isRunning() &&
!RaceEventManager::getInstance()->isRaceOver() &&
(World::getWorld()->getPhase() == WorldStatus::RACE_PHASE ||
@ -2901,7 +2902,7 @@ void ServerLobby::configPeersStartTime()
}
max_ping = std::max(peer->getAveragePing(), max_ping);
}
if (race_manager->supportsLiveJoining())
if (ServerConfig::m_live_players && race_manager->supportsLiveJoining())
{
Log::info("ServerLobby", "Max ping to ServerConfig::m_max_ping for "
"live joining.");
@ -3253,7 +3254,9 @@ void ServerLobby::handlePlayerDisconnection() const
}
}
if (total != 1 && World::getWorld()->hasTeam() &&
// If live players is enabled, don't end the game if unfair team
if (!ServerConfig::m_live_players &&
total != 1 && World::getWorld()->hasTeam() &&
(red_count == 0 || blue_count == 0))
World::getWorld()->setUnfairTeam(true);
@ -3265,7 +3268,7 @@ void ServerLobby::handlePlayerDisconnection() const
void ServerLobby::addLiveJoinPlaceholder(
std::vector<std::shared_ptr<NetworkPlayerProfile> >& players) const
{
if (!race_manager->supportsLiveJoining())
if (!ServerConfig::m_live_players || !race_manager->supportsLiveJoining())
return;
if (race_manager->getMinorMode() == RaceManager::MINOR_MODE_FREE_FOR_ALL)
{

View File

@ -291,6 +291,8 @@ void loadServerLobbyFromConfig()
if (m_official_tracks_threshold > 1.0f)
m_official_tracks_threshold = 1.0f;
if (m_live_players)
m_official_karts_threshold = 1.0f;
auto modes = getLocalGameModeFromConfig();
race_manager->setMinorMode(modes.first);
race_manager->setMajorMode(modes.second);

View File

@ -229,6 +229,14 @@ namespace ServerConfig
"was created using the in-game GUI. The changed difficulty and game "
"mode will not be saved in this config file."));
SERVER_CFG_PREFIX BoolServerConfigParam m_live_players
SERVER_CFG_DEFAULT(BoolServerConfigParam(false, "live-players",
"If true, players can live join or spectate the in-progress game. "
"Currently this feature is only available if the current game mode "
"used in server is FFA, CTF or soccer, also no addon karts will be "
"available for players to choose, and official-karts-threshold will "
"be made 1.0."));
SERVER_CFG_PREFIX FloatServerConfigParam m_flag_return_timemout
SERVER_CFG_DEFAULT(FloatServerConfigParam(20.0f, "flag-return-timemout",
"Time in seconds when a flag is dropped a by player in CTF "