From e77eb2ccf6df3dfdc6e1406dfe6d986eab287640 Mon Sep 17 00:00:00 2001 From: Benau Date: Sat, 17 Nov 2018 00:48:48 +0800 Subject: [PATCH] Allow server owner to force soccer time / goal limits --- src/network/protocols/client_lobby.cpp | 4 +- src/network/protocols/client_lobby.hpp | 4 +- src/network/protocols/server_lobby.cpp | 20 +++++++-- src/network/server_config.hpp | 17 +++++--- src/states_screens/online/tracks_screen.cpp | 45 ++++++++++++--------- 5 files changed, 59 insertions(+), 31 deletions(-) diff --git a/src/network/protocols/client_lobby.cpp b/src/network/protocols/client_lobby.cpp index 66ec4ec4f..973e7dc12 100644 --- a/src/network/protocols/client_lobby.cpp +++ b/src/network/protocols/client_lobby.cpp @@ -75,7 +75,7 @@ ClientLobby::ClientLobby(const TransportAddress& a, std::shared_ptr s) : LobbyProtocol(NULL) { m_waiting_for_game = false; - m_server_auto_lap = false; + m_server_auto_game_time = false; m_received_server_result = false; m_state.store(NONE); m_server_address = a; @@ -844,7 +844,7 @@ void ClientLobby::startSelection(Event* event) SFXManager::get()->quickSound("wee"); const NetworkString& data = event->data(); bool skip_kart_screen = data.getUInt8() == 1; - m_server_auto_lap = data.getUInt8() == 1; + m_server_auto_game_time = data.getUInt8() == 1; const unsigned kart_num = data.getUInt16(); const unsigned track_num = data.getUInt16(); m_available_karts.clear(); diff --git a/src/network/protocols/client_lobby.hpp b/src/network/protocols/client_lobby.hpp index 3d5a034a6..2c20de476 100644 --- a/src/network/protocols/client_lobby.hpp +++ b/src/network/protocols/client_lobby.hpp @@ -71,7 +71,7 @@ private: bool m_waiting_for_game; - bool m_server_auto_lap; + bool m_server_auto_game_time; bool m_received_server_result; @@ -111,7 +111,7 @@ public: { return m_state.load() == REQUESTING_CONNECTION; } bool isLobbyReady() const { return m_state.load() == CONNECTED; } bool isWaitingForGame() const { return m_waiting_for_game; } - bool isServerAutoLap() const { return m_server_auto_lap; } + bool isServerAutoGameTime() const { return m_server_auto_game_time; } virtual bool isRacing() const OVERRIDE { return m_state.load() == RACING; } void clearPlayers(); }; diff --git a/src/network/protocols/server_lobby.cpp b/src/network/protocols/server_lobby.cpp index da2be275c..977a2de95 100644 --- a/src/network/protocols/server_lobby.cpp +++ b/src/network/protocols/server_lobby.cpp @@ -883,7 +883,7 @@ void ServerLobby::startSelection(const Event *event) ns->setSynchronous(true); ns->addUInt8(LE_START_SELECTION).addUInt8( m_game_setup->isGrandPrixStarted() ? 1 : 0) - .addUInt8(ServerConfig::m_auto_lap_ratio > 0.0f ? 1 : 0); + .addUInt8(ServerConfig::m_auto_game_time_ratio > 0.0f ? 1 : 0); // Remove karts / tracks from server that are not supported on all clients std::set karts_erase, tracks_erase; @@ -1885,14 +1885,14 @@ void ServerLobby::playerVote(Event* event) if (race_manager->modeHasLaps()) { - if (ServerConfig::m_auto_lap_ratio > 0.0f) + if (ServerConfig::m_auto_game_time_ratio > 0.0f) { Track* t = track_manager->getTrack(track_name); if (t) { lap = (uint8_t)(fmaxf(1.0f, (float)t->getDefaultNumberOfLaps() * - ServerConfig::m_auto_lap_ratio)); + ServerConfig::m_auto_game_time_ratio)); } else { @@ -1904,6 +1904,20 @@ void ServerLobby::playerVote(Event* event) else if (lap == 0) lap = (uint8_t)3; } + else if (race_manager->getMinorMode() == RaceManager::MINOR_MODE_SOCCER && + ServerConfig::m_auto_game_time_ratio > 0.0f) + { + if (m_game_setup->isSoccerGoalTarget()) + { + lap = (uint8_t)(ServerConfig::m_auto_game_time_ratio * + UserConfigParams::m_num_goals); + } + else + { + lap = (uint8_t)(ServerConfig::m_auto_game_time_ratio * + UserConfigParams::m_soccer_time_limit); + } + } NetworkString other = NetworkString(PROTOCOL_LOBBY_ROOM); std::string name = StringUtils::wideToUtf8(event->getPeer() diff --git a/src/network/server_config.hpp b/src/network/server_config.hpp index 15eff8fc7..739ddd1e9 100644 --- a/src/network/server_config.hpp +++ b/src/network/server_config.hpp @@ -238,12 +238,17 @@ namespace ServerConfig "(time-limit-threshold-ctf + flag-return-timemout / 60.0)) * 60.0," " negative value to disable time limit.")); - SERVER_CFG_PREFIX FloatServerConfigParam m_auto_lap_ratio - SERVER_CFG_DEFAULT(FloatServerConfigParam(-1.0f, "auto-lap-ratio", - "Value used by server to automatically calculate " - "lap of each race in network game, if more than 0.0f, the number of " - "lap of each track vote in linear race will be determined by " - "max(1.0f, auto-lap-ratio * default lap of that track).")); + SERVER_CFG_PREFIX FloatServerConfigParam m_auto_game_time_ratio + SERVER_CFG_DEFAULT(FloatServerConfigParam(-1.0f, "auto-game-time-ratio", + "Value used by server to automatically estimate each game time. " + "For races, it decides the lap of each race in network game, " + "if more than 0.0f, the number of lap of each track vote in " + "linear race will be determined by " + "max(1.0f, auto-game-time-ratio * default lap of that track). " + "For soccer if more than 0.0f, for time limit game it will be " + "auto-game-time-ratio * soccer-time-limit in UserConfig, for goal " + "limit game it will be auto-game-time-ratio * numgoals " + "in UserConfig, -1 to disable for all.")); SERVER_CFG_PREFIX IntServerConfigParam m_max_ping SERVER_CFG_DEFAULT(IntServerConfigParam(300, "max-ping", diff --git a/src/states_screens/online/tracks_screen.cpp b/src/states_screens/online/tracks_screen.cpp index ab2f5d3e4..9e546c92e 100644 --- a/src/states_screens/online/tracks_screen.cpp +++ b/src/states_screens/online/tracks_screen.cpp @@ -273,6 +273,8 @@ void TracksScreen::init() { // Notice: for arena (battle / soccer) lap and reverse will be mapped to // goals / time limit and random item location + auto cl = LobbyProtocol::get(); + assert(cl); if (UserConfigParams::m_num_laps == 0 || UserConfigParams::m_num_laps > 20) UserConfigParams::m_num_laps = 1; @@ -297,25 +299,34 @@ void TracksScreen::init() } else if (race_manager->getMinorMode() == RaceManager::MINOR_MODE_SOCCER) { - m_laps->setVisible(true); - getWidget("lap-text")->setVisible(true); - auto cl = LobbyProtocol::get(); - assert(cl); - if (cl->getGameSetup()->isSoccerGoalTarget()) + if (cl->isServerAutoGameTime()) { - //I18N: In track screen - getWidget("lap-text")->setText(_("Number of goals to win"), false); - m_laps->setValue(UserConfigParams::m_num_goals); - m_laps->setMin(1); - m_laps->setMax(10); + getWidget("lap-text")->setVisible(false); + m_laps->setVisible(false); + m_laps->setValue(0); } else { - //I18N: In track screen - getWidget("lap-text")->setText(_("Maximum time (min.)"), false); - m_laps->setValue(UserConfigParams::m_soccer_time_limit); - m_laps->setMin(1); - m_laps->setMax(15); + m_laps->setVisible(true); + getWidget("lap-text")->setVisible(true); + auto cl = LobbyProtocol::get(); + assert(cl); + if (cl->getGameSetup()->isSoccerGoalTarget()) + { + //I18N: In track screen + getWidget("lap-text")->setText(_("Number of goals to win"), false); + m_laps->setValue(UserConfigParams::m_num_goals); + m_laps->setMin(1); + m_laps->setMax(10); + } + else + { + //I18N: In track screen + getWidget("lap-text")->setText(_("Maximum time (min.)"), false); + m_laps->setValue(UserConfigParams::m_soccer_time_limit); + m_laps->setMin(1); + m_laps->setMax(15); + } } getWidget("reverse-text")->setVisible(true); //I18N: In track screen @@ -325,9 +336,7 @@ void TracksScreen::init() } else { - auto cl = LobbyProtocol::get(); - assert(cl); - if (cl->isServerAutoLap()) + if (cl->isServerAutoGameTime()) { getWidget("lap-text")->setVisible(false); m_laps->setVisible(false);