prevent arena berserk if inc > limit*2

prevents tournament abuse with TC like 1+60
where perf is Classical but berserked games are Hyperbullet.
pull/9829/head
Thibault Duplessis 2021-09-18 12:16:27 +02:00
parent 4be99914b2
commit 53a13fe270
2 changed files with 10 additions and 3 deletions

View File

@ -74,7 +74,7 @@ final class TournamentApi(
password = setup.password,
variant = setup.realVariant,
position = setup.realPosition,
berserkable = setup.berserkable | true,
berserkable = setup.isBerserkable,
streakable = setup.streakable | true,
teamBattle = setup.teamBattleByTeam map TeamBattle.init,
description = setup.description,

View File

@ -203,6 +203,13 @@ private[tournament] case class TournamentSetup(
def isPrivate = password.isDefined || conditions.teamMember.isDefined
// prevent berserk tournament abuse with TC like 1+60,
// where perf is Classical but berserked games are Hyperbullet.
private def timeControlPreventsBerserk =
clockConfig.incrementSeconds > clockConfig.limitInMinutes * 2
def isBerserkable = ~berserkable && !timeControlPreventsBerserk
// update all fields and use default values for missing fields
// meant for HTML form updates
def updateAll(old: Tournament): Tournament = {
@ -220,7 +227,7 @@ private[tournament] case class TournamentSetup(
if (old.isCreated || old.position.isDefined) realPosition
else old.position
},
noBerserk = !(~berserkable),
noBerserk = !isBerserkable,
noStreak = !(~streakable),
teamBattle = old.teamBattle,
description = description,
@ -245,7 +252,7 @@ private[tournament] case class TournamentSetup(
if (position.isDefined && (old.isCreated || old.position.isDefined)) realPosition
else old.position
},
noBerserk = berserkable.fold(old.noBerserk)(!_),
noBerserk = berserkable.fold(old.noBerserk)(!_) || timeControlPreventsBerserk,
noStreak = streakable.fold(old.noStreak)(!_),
teamBattle = old.teamBattle,
description = description.fold(old.description)(_.some.filter(_.nonEmpty)),