upgrade to scalachess 7.1 to support partial import of illegal PGN

pull/3761/head
Thibault Duplessis 2017-10-30 17:42:33 -05:00
parent 2404af109d
commit f2a5c65ee3
5 changed files with 18 additions and 6 deletions

View File

@ -1,6 +1,7 @@
package lila.fishnet
import org.joda.time.DateTime
import scalaz.Validation.FlatMap._
import chess.format.Uci
import JsonApi.Request.Evaluation
@ -34,7 +35,7 @@ private object AnalysisBuilder {
case Some(game) =>
GameRepo.initialFen(game) flatMap { initialFen =>
def debug = s"${game.variant.key} analysis for ${game.id} by ${client.fullId}"
chess.Replay(game.pgnMoves, initialFen, game.variant).fold(
chess.Replay(game.pgnMoves, initialFen, game.variant).flatMap(_.valid).fold(
fufail(_),
replay => UciToPgn(replay, uciAnalysis) match {
case (analysis, errors) =>

View File

@ -4,10 +4,11 @@ import scala.concurrent.Future
import akka.actor._
import akka.pattern.pipe
import chess.format.{ Forsyth, pgn }
import chess.format.pgn.{ Tags, Sans }
import chess.format.{ Forsyth, pgn }
import chess.{ Game => ChessGame }
import scalaz.{ NonEmptyList, OptionT }
import scalaz.Validation.FlatMap._
import lila.common.Captcha
import lila.hub.actorApi.captcha._
@ -90,7 +91,11 @@ private final class Captcher extends Actor {
} toNel
private def rewind(game: Game, moves: PgnMoves): Option[ChessGame] =
pgn.Reader.movesWithSans(moves, sans => Sans(safeInit(sans.value)), tags = Tags.empty) map (_.state) toOption
pgn.Reader.movesWithSans(
moves,
sans => Sans(safeInit(sans.value)),
tags = Tags.empty
).flatMap(_.valid) map (_.state) toOption
private def safeInit[A](list: List[A]): List[A] = list match {
case x :: Nil => Nil

View File

@ -1,6 +1,7 @@
package lila.game
import org.joda.time.DateTime
import scalaz.Validation.FlatMap._
import chess.format.{ pgn => chessPgn }
@ -17,7 +18,7 @@ object Rewind {
moveStrs = game.pgnMoves,
op = sans => chessPgn.Sans(sans.value.dropRight(1)),
tags = createTags(initialFen, game)
) map { replay =>
).flatMap(_.valid) map { replay =>
val rewindedGame = replay.state
val rewindedHistory = rewindedGame.board.history
val rewindedSituation = rewindedGame.situation

View File

@ -35,9 +35,14 @@ case class ImportData(pgn: String, analyse: Option[String]) {
private val maxPlies = 600
private def evenIncomplete(result: Reader.Result): Replay = result match {
case Reader.Result.Complete(replay) => replay
case Reader.Result.Incomplete(replay, _) => replay
}
def preprocess(user: Option[String]): Valid[Preprocessed] = Parser.full(pgn) flatMap {
case ParsedPgn(_, _, sans) if sans.value.size > maxPlies => !!("Replay is too long")
case parsed @ ParsedPgn(_, tags, sans) => Reader.full(pgn) map {
case parsed @ ParsedPgn(_, tags, sans) => Reader.full(pgn) map evenIncomplete map {
case replay @ Replay(setup, _, game) =>
val initBoard = parsed.tags.fen.map(_.value) flatMap Forsyth.<< map (_.board)
val fromPosition = initBoard.nonEmpty && !parsed.tags.fen.contains(FEN(Forsyth.initial))

View File

@ -28,7 +28,7 @@ object Dependencies {
val findbugs = "com.google.code.findbugs" % "jsr305" % "3.0.1"
val hasher = "com.roundeights" %% "hasher" % "1.2.0"
val jodaTime = "joda-time" % "joda-time" % "2.9.9"
val chess = "org.lichess" %% "scalachess" % "6.27"
val chess = "org.lichess" %% "scalachess" % "7.1"
val maxmind = "com.sanoma.cda" %% "maxmind-geoip2-scala" % "1.2.3-THIB"
val prismic = "io.prismic" %% "scala-kit" % "1.2.11-THIB"
val java8compat = "org.scala-lang.modules" %% "scala-java8-compat" % "0.8.0"