Allow server owner to force soccer time / goal limits

This commit is contained in:
Benau 2018-11-17 00:48:48 +08:00
parent eb6b930b6a
commit e77eb2ccf6
5 changed files with 59 additions and 31 deletions

View File

@ -75,7 +75,7 @@ ClientLobby::ClientLobby(const TransportAddress& a, std::shared_ptr<Server> 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();

View File

@ -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();
};

View File

@ -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<std::string> 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()

View File

@ -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",

View File

@ -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<ClientLobby>();
assert(cl);
if (UserConfigParams::m_num_laps == 0 ||
UserConfigParams::m_num_laps > 20)
UserConfigParams::m_num_laps = 1;
@ -296,6 +298,14 @@ void TracksScreen::init()
m_reversed->setVisible(false);
}
else if (race_manager->getMinorMode() == RaceManager::MINOR_MODE_SOCCER)
{
if (cl->isServerAutoGameTime())
{
getWidget("lap-text")->setVisible(false);
m_laps->setVisible(false);
m_laps->setValue(0);
}
else
{
m_laps->setVisible(true);
getWidget("lap-text")->setVisible(true);
@ -317,6 +327,7 @@ void TracksScreen::init()
m_laps->setMin(1);
m_laps->setMax(15);
}
}
getWidget("reverse-text")->setVisible(true);
//I18N: In track screen
getWidget<LabelWidget>("reverse-text")->setText(_("Random item location"), false);
@ -325,9 +336,7 @@ void TracksScreen::init()
}
else
{
auto cl = LobbyProtocol::get<ClientLobby>();
assert(cl);
if (cl->isServerAutoLap())
if (cl->isServerAutoGameTime())
{
getWidget("lap-text")->setVisible(false);
m_laps->setVisible(false);