Skip to content

Commit

Permalink
abort games that timed out while lichess is down
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Mar 28, 2016
1 parent 6008330 commit 8b19b47
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 17 deletions.
2 changes: 1 addition & 1 deletion modules/explorer/src/main/Env.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ final class Env(

if (IndexFlow) system.lilaBus.subscribe(system.actorOf(Props(new Actor {
def receive = {
case lila.game.actorApi.FinishGame(game, _, _) => indexer(game)
case lila.game.actorApi.FinishGame(game, _, _) if !game.aborted => indexer(game)
}
})), 'finishGame)
}
Expand Down
4 changes: 2 additions & 2 deletions modules/gameSearch/src/main/Env.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ final class Env(
system.lilaBus.subscribe(system.actorOf(Props(new Actor {
import lila.game.actorApi.{ InsertGame, FinishGame }
def receive = {
case FinishGame(game, _, _) => self ! InsertGame(game)
case InsertGame(game) => api store game
case FinishGame(game, _, _) if !game.aborted => self ! InsertGame(game)
case InsertGame(game) => api store game
}
}), name = ActorName), 'finishGame)

Expand Down
2 changes: 1 addition & 1 deletion modules/mod/src/main/Env.scala
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ final class Env(
case lila.hub.actorApi.mod.MarkCheater(userId) => api autoAdjust userId
case lila.analyse.actorApi.AnalysisReady(game, analysis) =>
assessApi.onAnalysisReady(game, analysis)
case lila.game.actorApi.FinishGame(game, whiteUserOption, blackUserOption) =>
case lila.game.actorApi.FinishGame(game, whiteUserOption, blackUserOption) if !game.aborted =>
(whiteUserOption |@| blackUserOption) apply {
case (whiteUser, blackUser) => boosting.check(game, whiteUser, blackUser) >>
assessApi.onGameReady(game, whiteUser, blackUser)
Expand Down
2 changes: 1 addition & 1 deletion modules/perfStat/src/main/Env.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ final class Env(

system.lilaBus.subscribe(system.actorOf(Props(new Actor {
def receive = {
case lila.game.actorApi.FinishGame(game, _, _) => indexer addGame game
case lila.game.actorApi.FinishGame(game, _, _) if !game.aborted => indexer addGame game
}
})), 'finishGame)
}
Expand Down
16 changes: 15 additions & 1 deletion modules/round/src/main/Finisher.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ private[round] final class Finisher(
def rageQuit(game: Game, winner: Option[Color])(implicit proxy: GameProxy): Fu[Events] =
apply(game, _.Timeout, winner) >>- winner.?? { color => playban.rageQuit(game, !color) }

def outOfTime(game: Game)(implicit proxy: GameProxy): Fu[Events] = {
import lila.common.PlayApp
if (!PlayApp.startedSinceSeconds(120) && game.updatedAt.exists(_ isBefore PlayApp.startedAt)) {
logger.info(s"Aborting game last played before JVM boot: ${game.id}")
other(game, _.Aborted, none)
}
else {
val winner = Some(!game.player.color) filterNot { color =>
game.toChess.board.variant.insufficientWinningMaterial(game.toChess.situation.board, color)
}
other(game, _.Outoftime, winner)
}
}

def other(
game: Game,
status: Status.type => Status,
Expand Down Expand Up @@ -71,7 +85,7 @@ private[round] final class Finisher(
}
}
}
} >>- proxy.invalidate
} >>- proxy.invalidate

private def notifyTimeline(game: Game)(color: Color) = {
import lila.hub.actorApi.timeline.{ Propagate, GameEnd }
Expand Down
7 changes: 2 additions & 5 deletions modules/round/src/main/Round.scala
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ private[round] final class Round(
}

case Outoftime => handle { game =>
game.outoftime(lags.get) ?? outOfTime(game)
game.outoftime(lags.get) ?? outOfTime(game).thenPp
}

// exceptionally we don't block nor publish events
Expand Down Expand Up @@ -209,10 +209,7 @@ private[round] final class Round(
if (lag > 0) lila.mon.round.move.networkLag(lag)
}

private def outOfTime(game: Game) =
finisher.other(game, _.Outoftime, Some(!game.player.color) filterNot { color =>
game.toChess.board.variant.insufficientWinningMaterial(game.toChess.situation.board, color)
})
private def outOfTime(game: Game) = finisher.outOfTime(game)

protected def handle[A](op: Game => Fu[Events]): Funit =
handleGame(proxy.game)(op)
Expand Down
14 changes: 8 additions & 6 deletions modules/tournament/src/main/PairingRepo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,14 @@ object PairingRepo {
pairingHandler.write(pairing) ++ BSONDocument("d" -> DateTime.now)
}.void

def finish(g: lila.game.Game) = coll.update(
selectId(g.id),
BSONDocument("$set" -> BSONDocument(
"s" -> g.status.id,
"w" -> g.winnerColor.map(_.white),
"t" -> g.turns))).void
def finish(g: lila.game.Game) =
if (g.aborted) coll.remove(selectId(g.id))
else coll.update(
selectId(g.id),
BSONDocument("$set" -> BSONDocument(
"s" -> g.status.id,
"w" -> g.winnerColor.map(_.white),
"t" -> g.turns))).void

def setBerserk(pairing: Pairing, userId: String, value: Int) = (userId match {
case uid if pairing.user1 == uid => "b1".some
Expand Down

0 comments on commit 8b19b47

Please sign in to comment.