disallow rated variant games with total time < 30s
parent
c5e1130afb
commit
78a12bd83d
|
@ -142,6 +142,10 @@ object Challenge {
|
|||
case "black" => ColorChoice.Black -> chess.Black
|
||||
case _ => ColorChoice.Random -> chess.Color(scala.util.Random.nextBoolean)
|
||||
}
|
||||
val finalMode = timeControl match {
|
||||
case TimeControl.Clock(clock) if !lila.game.Game.allowRated(variant, clock) => Mode.Casual
|
||||
case _ => mode
|
||||
}
|
||||
new Challenge(
|
||||
_id = randomId,
|
||||
status = Status.Created,
|
||||
|
@ -151,7 +155,7 @@ object Challenge {
|
|||
Some(variant.initialFen).ifFalse(variant.standardInitialPosition)
|
||||
),
|
||||
timeControl = timeControl,
|
||||
mode = mode,
|
||||
mode = finalMode,
|
||||
colorChoice = colorChoice,
|
||||
finalColor = finalColor,
|
||||
challenger = challenger.fold[EitherChallenger](
|
||||
|
|
|
@ -596,6 +596,9 @@ object Game {
|
|||
game.variant == chess.variant.Horde &&
|
||||
game.createdAt.isBefore(Game.hordeWhitePawnsSince)
|
||||
|
||||
def allowRated(variant: Variant, clock: Clock.Config) =
|
||||
variant.standard || clock.estimateTotalTime >= 30
|
||||
|
||||
val gameIdSize = 8
|
||||
val playerIdSize = 4
|
||||
val fullIdSize = 12
|
||||
|
|
|
@ -38,17 +38,19 @@ case class HookConfig(
|
|||
sid: Option[String],
|
||||
blocking: Set[String]
|
||||
): Either[Hook, Option[Seek]] = timeMode match {
|
||||
case TimeMode.RealTime => Left(Hook.make(
|
||||
uid = uid,
|
||||
variant = variant,
|
||||
clock = justMakeClock,
|
||||
mode = mode,
|
||||
color = color.name,
|
||||
user = user,
|
||||
blocking = blocking,
|
||||
sid = sid,
|
||||
ratingRange = ratingRange
|
||||
))
|
||||
case TimeMode.RealTime =>
|
||||
val clock = justMakeClock
|
||||
Left(Hook.make(
|
||||
uid = uid,
|
||||
variant = variant,
|
||||
clock = clock,
|
||||
mode = lila.game.Game.allowRated(variant, clock).fold(mode, Mode.Casual),
|
||||
color = color.name,
|
||||
user = user,
|
||||
blocking = blocking,
|
||||
sid = sid,
|
||||
ratingRange = ratingRange
|
||||
))
|
||||
case _ => Right(user map { u =>
|
||||
Seek.make(
|
||||
variant = variant,
|
||||
|
|
|
@ -209,13 +209,25 @@ module.exports = function(cfg, element) {
|
|||
var $ratings = $form.find('.ratings > div');
|
||||
var randomColorVariants = $form.data('random-color-variants').split(',');
|
||||
var toggleButtons = function() {
|
||||
var variantId = $variantSelect.val();
|
||||
var timeMode = $timeModeSelect.val();
|
||||
var rated = $rated.prop('checked');
|
||||
var timeOk = timeMode != '1' || $timeInput.val() > 0 || $incrementInput.val() > 0;
|
||||
var limit = $timeInput.val();
|
||||
var inc = $incrementInput.val();
|
||||
// no rated variants with less than 30s on the clock
|
||||
var cantBeRated = variantId != '1' && limit < 0.5 && inc == 0;
|
||||
if (cantBeRated) {
|
||||
if (rated) {
|
||||
$casual.click();
|
||||
return toggleButtons();
|
||||
}
|
||||
}
|
||||
$rated.attr('disabled', cantBeRated);
|
||||
var timeOk = timeMode != '1' || limit > 0 || inc > 0;
|
||||
var ratedOk = !isHook || !rated || timeMode != '0';
|
||||
if (timeOk && ratedOk) {
|
||||
$form.find('.color_submits button').toggleClass('nope', false);
|
||||
$form.find('.color_submits button:not(.random)').toggle(!rated || randomColorVariants.indexOf($variantSelect.val()) === -1);
|
||||
$form.find('.color_submits button:not(.random)').toggle(!rated || randomColorVariants.indexOf(variantId) === -1);
|
||||
} else
|
||||
$form.find('.color_submits button').toggleClass('nope', true);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue