Skip to content

Commit

Permalink
allow challenge API to ignore moreTime rules and preferences
Browse files Browse the repository at this point in the history
TD needs to adjust time, while TD does not want players to add/adjust
time by themselves. Use case:Armageddon games2.Make correction to
Individual boardCase for no.2. We sent out links, we started the time
too early, TD made mistake. We need to adjust time.Case for no2. Player
said, it was opponent turn, but actually it was his turn. (Bug that I
see sometimes, rare but happened, could be internet problem). TD checked
evidences, and approved it, so we need to adjust time.Case for no.2. One
player violated small regulations, but not enough to make him lose the
game. Usually we take time from his side, but if that is not possible we
can add time to his opponent.The problem with current setting is that
"allow add time" is bind to the player capability and we do not have
setting "player allow add time" and "admin allow add time". Admin in
this case is the account (Auth) that created the board.
  • Loading branch information
ornicar committed Oct 14, 2024
1 parent bce53c8 commit 3539837
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/controllers/Round.scala
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ final class Round(
.flatMap:
_.flatMap { Pov(_, me) }.so: pov =>
env.round.moretimer
.isAllowedIn(pov.game, Preload.none)
.isAllowedIn(pov.game, Preload.none, byAdmin = true)
.map:
if _ then
env.round.roundApi.tell(pov.gameId, Moretime(pov.playerId, seconds.seconds))
Expand Down
2 changes: 1 addition & 1 deletion modules/round/src/main/JsonView.scala
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ final class JsonView(
flags: ExportOptions
): Fu[JsObject] = for
takebackable <- takebacker.isAllowedIn(pov.game, Preload(prefs))
moretimeable <- moretimer.isAllowedIn(pov.game, Preload(prefs))
moretimeable <- moretimer.isAllowedIn(pov.game, Preload(prefs), byAdmin = false)
socket <- getSocketStatus(pov.game)
pref = prefs(pov.color)
yield
Expand Down
7 changes: 4 additions & 3 deletions modules/round/src/main/Moretimer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ final class Moretimer(
val p = correspondenceGiveTime(pov.game)
p.game.correspondenceClock.map(Event.CorrespondenceClock.apply).fold(p)(p + _)

def isAllowedIn(game: Game, prefs: Preload[ByColor[Pref]]): Fu[Boolean] =
(game.canTakebackOrAddTime && game.playable && !game.metadata.hasRule(_.noGiveTime))
.so(isAllowedByPrefs(game, prefs))
def isAllowedIn(game: Game, prefs: Preload[ByColor[Pref]], byAdmin: Boolean): Fu[Boolean] =
(game.canTakebackOrAddTime && game.playable).so:
if byAdmin then fuccess(true)
else (!game.metadata.hasRule(_.noGiveTime)).so(isAllowedByPrefs(game, prefs))

private def correspondenceGiveTime(g: Game) = Progress(g, g.copy(movedAt = nowInstant))

Expand Down
2 changes: 1 addition & 1 deletion modules/round/src/main/RoundMobile.scala
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ final class RoundMobile(
users <- game.userIdPair.traverse(_.so(lightUserGet))
prefs <- prefApi.byId(game.userIdPair)
takebackable <- takebacker.isAllowedIn(game, Preload(prefs))
moretimeable <- moretimer.isAllowedIn(game, Preload(prefs))
moretimeable <- moretimer.isAllowedIn(game, Preload(prefs), byAdmin = false)
chat <- use.chat.so(getPlayerChat(game, myPlayer.exists(_.hasUser)))
chatLines <- chat.map(_.chat).soFu(lila.chat.JsonView.asyncLines)
bookmarked <- use.bookmark.so(bookmarkExists(game, myPlayer.flatMap(_.userId)))
Expand Down

0 comments on commit 3539837

Please sign in to comment.