fix race conditions when premoving with high geolag

pull/388/head
Thibault Duplessis 2015-03-31 15:59:44 +02:00
parent d9ad8bfec7
commit 60b5cf9f8f
3 changed files with 25 additions and 14 deletions

View File

@ -4,7 +4,7 @@ import lila.common.PimpedJson._
import play.api.libs.json._
import chess.Pos.{ piotr, allPiotrs }
import chess.{ PromotableRole, Pos, Color, Situation, Move => ChessMove, Clock => ChessClock }
import chess.{ PromotableRole, Pos, Color, Situation, Move => ChessMove, Clock => ChessClock, Status }
import lila.chat.{ Line, UserLine, PlayerLine }
sealed trait Event {
@ -176,12 +176,22 @@ object Event {
)
}
case class State(color: Color, turns: Int) extends Event {
case class State(
color: Color,
turns: Int,
status: Status,
whiteOffersDraw: Boolean,
blackOffersDraw: Boolean) extends Event {
def typ = "state"
def data = Json.obj(
"color" -> color.name,
"turns" -> turns
)
"turns" -> turns,
"status" -> Json.obj(
"id" -> status.id,
"name" -> status.name),
"wDraw" -> whiteOffersDraw.option(true),
"bDraw" -> blackOffersDraw.option(true)
).noNull
}
case class Crowd(

View File

@ -141,9 +141,14 @@ case class Game(
val events = (players collect {
case p if p.isHuman => Event.possibleMoves(situation, p.color)
}) :::
Event.State(situation.color, game.turns) ::
(Event fromMove move) :::
(Event fromSituation situation)
Event.State(
situation.color,
game.turns,
status,
whiteOffersDraw = whitePlayer.isOfferingDraw,
blackOffersDraw = blackPlayer.isOfferingDraw) ::
(Event fromMove move) :::
(Event fromSituation situation)
def copyPlayer(player: Player) = player.copy(
blurs = math.min(
@ -176,12 +181,6 @@ case class Game(
}
val finalEvents = events ::: clockEvent.toList ::: {
(updated.playable && (
abortable != updated.abortable || (Color.all exists { color =>
playerCanOfferDraw(color) != updated.playerCanOfferDraw(color)
})
)) ?? List(Event.Reload)
} ::: {
// abstraction leak, I know.
(updated.variant.threeCheck && situation.check) ?? List(Event.CheckCount(
white = updated.checkCount.white,
@ -426,7 +425,6 @@ object Game {
chess.variant.ThreeCheck,
chess.variant.KingOfTheHill)
val analysableVariants: Set[Variant] = Set(
chess.variant.Standard,
chess.variant.Chess960,

View File

@ -23,6 +23,9 @@ module.exports = function(send, ctrl) {
});
ctrl.data.game.player = o.color;
ctrl.data.game.turns = o.turns;
ctrl.data.game.status = o.status;
ctrl.data[ctrl.data.player.color === 'white' ? 'player' : 'opponent'].offeringDraw = o.wDraw;
ctrl.data[ctrl.data.player.color === 'black' ? 'player' : 'opponent'].offeringDraw = o.bDraw;
m.redraw();
ctrl.setTitle();
},