From 6a1a1740c0e5bdb95498a2c387d08e054172ed8c Mon Sep 17 00:00:00 2001 From: Benau Date: Sat, 5 Jan 2019 01:20:25 +0800 Subject: [PATCH] Make live join or spectate a server option --- src/network/game_setup.cpp | 4 +++- src/network/protocols/server_lobby.cpp | 11 +++++++---- src/network/server_config.cpp | 2 ++ src/network/server_config.hpp | 8 ++++++++ 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/network/game_setup.cpp b/src/network/game_setup.cpp index 7d1117ecb..8838dcbad 100644 --- a/src/network/game_setup.cpp +++ b/src/network/game_setup.cpp @@ -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 //----------------------------------------------------------------------------- diff --git a/src/network/protocols/server_lobby.cpp b/src/network/protocols/server_lobby.cpp index bac5832e7..3151bc9f5 100644 --- a/src/network/protocols/server_lobby.cpp +++ b/src/network/protocols/server_lobby.cpp @@ -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 >& 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) { diff --git a/src/network/server_config.cpp b/src/network/server_config.cpp index 9d9ff528b..412bc079c 100644 --- a/src/network/server_config.cpp +++ b/src/network/server_config.cpp @@ -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); diff --git a/src/network/server_config.hpp b/src/network/server_config.hpp index 71bfed32f..32c01ba78 100644 --- a/src/network/server_config.hpp +++ b/src/network/server_config.hpp @@ -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 "