Merge branch 'master' into star
* master: minor UI tweaks compensate clock with the player lag Display ping lag add missing dependency on hasherpull/1/merge
commit
2a9a4a5ed8
|
@ -12,6 +12,7 @@ import chess.Role.forsyth
|
|||
import org.joda.time.DateTime
|
||||
import org.scala_tools.time.Imports._
|
||||
import com.novus.salat.annotations.Key
|
||||
import scala.math.min
|
||||
|
||||
case class DbGame(
|
||||
id: String,
|
||||
|
@ -51,7 +52,7 @@ case class DbGame(
|
|||
def player(user: User): Option[DbPlayer] =
|
||||
players find (_ isUser user)
|
||||
|
||||
def player(c: Color.type => Color): DbPlayer = player(c(Color))
|
||||
def player(c: Color.type ⇒ Color): DbPlayer = player(c(Color))
|
||||
|
||||
def isPlayerFullId(player: DbPlayer, fullId: String): Boolean =
|
||||
(fullId.size == DbGame.fullIdSize) && player.id == (fullId drop 8)
|
||||
|
@ -107,7 +108,11 @@ case class DbGame(
|
|||
castles = castles,
|
||||
positionHashes = positionHashes)
|
||||
|
||||
def update(game: Game, move: Move, blur: Boolean = false): Progress = {
|
||||
def update(
|
||||
game: Game,
|
||||
move: Move,
|
||||
blur: Boolean = false,
|
||||
lag: Int = 0): Progress = {
|
||||
val (history, situation) = (game.board.history, game.situation)
|
||||
val events =
|
||||
Event.possibleMoves(game.situation, White) ::
|
||||
|
@ -145,7 +150,11 @@ case class DbGame(
|
|||
else if (situation.staleMate) Status.Stalemate
|
||||
else if (situation.autoDraw) Status.Draw
|
||||
else status,
|
||||
clock = game.clock,
|
||||
clock = game.clock map { c ⇒
|
||||
c.giveTime(
|
||||
move.color,
|
||||
min(lag, DbGame.maxLagToCompensate) / 1000f)
|
||||
},
|
||||
check = if (situation.check) situation.kingPos else None,
|
||||
lastMoveTime = nowSeconds.some
|
||||
)
|
||||
|
@ -242,7 +251,7 @@ case class DbGame(
|
|||
player(color).lastDrawOffer.fold(_ >= turns - 1, false)
|
||||
|
||||
def playerCanRematch(color: Color) =
|
||||
finishedOrAborted && opponent(color).isHuman
|
||||
finishedOrAborted && opponent(color).isHuman
|
||||
|
||||
def playerCanProposeTakeback(color: Color) =
|
||||
started && playable &&
|
||||
|
@ -342,6 +351,7 @@ object DbGame {
|
|||
val gameIdSize = 8
|
||||
val playerIdSize = 4
|
||||
val fullIdSize = 12
|
||||
val maxLagToCompensate = 1000
|
||||
|
||||
def takeGameId(fullId: String) = fullId take gameIdSize
|
||||
|
||||
|
|
|
@ -30,7 +30,8 @@ final class Hand(
|
|||
origString: String,
|
||||
destString: String,
|
||||
promString: Option[String] = None,
|
||||
blur: Boolean = false): IOValidEvents = fromPov(povRef) {
|
||||
blur: Boolean = false,
|
||||
lag: Int = 0): IOValidEvents = fromPov(povRef) {
|
||||
case Pov(g1, color) ⇒ (for {
|
||||
g2 ← (g1.playable).fold(success(g1), failure("Game not playable" wrapNel))
|
||||
orig ← posAt(origString) toValid "Wrong orig " + origString
|
||||
|
@ -38,7 +39,7 @@ final class Hand(
|
|||
promotion = Role promotable promString
|
||||
newChessGameAndMove ← g2.toChess(orig, dest, promotion)
|
||||
(newChessGame, move) = newChessGameAndMove
|
||||
} yield g2.update(newChessGame, move, blur)).fold(
|
||||
} yield g2.update(newChessGame, move, blur, lag)).fold(
|
||||
e ⇒ io(failure(e)),
|
||||
progress ⇒ for {
|
||||
events ← if (progress.game.finished) for {
|
||||
|
|
|
@ -52,8 +52,8 @@ final class Socket(
|
|||
hub ! Events(events)
|
||||
}
|
||||
case Some("move") ⇒ parseMove(e) foreach {
|
||||
case (orig, dest, prom, blur) ⇒
|
||||
hand.play(povRef, orig, dest, prom, blur) flatMap { events ⇒
|
||||
case (orig, dest, prom, blur, lag) ⇒
|
||||
hand.play(povRef, orig, dest, prom, blur, lag) flatMap { events ⇒
|
||||
events.fold(putFailures, send(povRef.gameId, _))
|
||||
} unsafePerformIO
|
||||
}
|
||||
|
@ -99,7 +99,8 @@ final class Socket(
|
|||
dest ← d str "to"
|
||||
prom = d str "promotion"
|
||||
blur = (d int "b") == Some(1)
|
||||
} yield (orig, dest, prom, blur)
|
||||
lag = d int "lag"
|
||||
} yield (orig, dest, prom, blur, lag | 0)
|
||||
|
||||
private def join(
|
||||
povOption: Option[Pov],
|
||||
|
|
|
@ -7,7 +7,7 @@ import play.api.templates.Html
|
|||
|
||||
trait AssetHelper {
|
||||
|
||||
val assetVersion = 21
|
||||
val assetVersion = 22
|
||||
|
||||
def cssTag(name: String) = css("stylesheets/" + name)
|
||||
|
||||
|
|
|
@ -82,6 +82,8 @@
|
|||
<a href="http://github.com/ornicar/lila" target="_blank" title="See what's inside, fork and contribute">Source Code</a><br />
|
||||
<a href="@routes.Monitor.index">Monitor</a> |
|
||||
<a href="@routes.I18n.contribute">Translate Lichess</a>
|
||||
<br />
|
||||
Ping: <span id="connection_lag">?</span>
|
||||
</div>
|
||||
</div>
|
||||
@jsTag("deps.min.js")
|
||||
|
|
|
@ -28,6 +28,7 @@ trait Dependencies {
|
|||
val paginator = "com.github.ornicar" %% "paginator-core" % "1.5"
|
||||
val paginatorSalat = "com.github.ornicar" %% "paginator-salat-adapter" % "1.4"
|
||||
val csv = "com.github.tototoshi" %% "scala-csv" % "0.3"
|
||||
val hasher = "com.roundeights" % "hasher" % "0.3" from "http://cloud.github.com/downloads/Nycto/Hasher/hasher_2.9.1-0.3.jar"
|
||||
}
|
||||
|
||||
object ApplicationBuild extends Build with Resolvers with Dependencies {
|
||||
|
@ -37,7 +38,7 @@ object ApplicationBuild extends Build with Resolvers with Dependencies {
|
|||
version := "0.1",
|
||||
scalaVersion := "2.9.1",
|
||||
resolvers := Seq(iliaz, codahale, sonatype, typesafe, t2v, guice),
|
||||
libraryDependencies := Seq(scalaz, scalalib),
|
||||
libraryDependencies := Seq(scalaz, scalalib, hasher),
|
||||
libraryDependencies in test := Seq(specs2),
|
||||
shellPrompt := {
|
||||
(state: State) ⇒ "%s> ".format(Project.extract(state).currentProject.id)
|
||||
|
|
|
@ -22,7 +22,8 @@ var lichess = {
|
|||
},
|
||||
options: {
|
||||
name: "site",
|
||||
offlineTag: $('#connection_lost')
|
||||
offlineTag: $('#connection_lost'),
|
||||
lagTag: $('#connection_lag')
|
||||
}
|
||||
},
|
||||
onProduction: /.+\.lichess\.org/.test(document.domain),
|
||||
|
|
|
@ -349,8 +349,10 @@ $.widget("lichess.game", {
|
|||
self.options.possible_moves = null;
|
||||
self.movePiece($oldSquare.attr("id"), squareId, null, true);
|
||||
|
||||
// TODO send moveData here
|
||||
function sendMoveRequest(moveData) {
|
||||
if (self.canRunClock()) {
|
||||
moveData.lag = parseInt(lichess.socket.averageLag);
|
||||
}
|
||||
lichess.socket.send("move", moveData);
|
||||
}
|
||||
|
||||
|
@ -582,7 +584,7 @@ $.widget("lichess.game", {
|
|||
}
|
||||
},
|
||||
canRunClock: function() {
|
||||
return this.options.game.clock && this.options.game.started && ! this.options.game.finished;
|
||||
return this.options.game.clock && this.options.game.started && !this.options.game.finished;
|
||||
},
|
||||
getPieceColor: function($piece) {
|
||||
return $piece.hasClass('white') ? 'white': 'black';
|
||||
|
|
|
@ -11,7 +11,8 @@ $.websocket = function(url, version, settings) {
|
|||
offlineDelay: 5000, // time before showing offlineTag
|
||||
offlineTag: false, // jQuery object showing connection error
|
||||
pingMaxLag: 5000, // time to wait for pong before reseting the connection
|
||||
pingDelay: 1500 // time between pong and ping
|
||||
pingDelay: 1500, // time between pong and ping
|
||||
lagTag: false // jQuery object showing ping lag
|
||||
}
|
||||
};
|
||||
$.extend(true, self.settings, settings);
|
||||
|
@ -22,6 +23,8 @@ $.websocket = function(url, version, settings) {
|
|||
self.fullUrl = null;
|
||||
self.pingSchedule = null;
|
||||
self.connectSchedule = null;
|
||||
self.lastPingTime = self.now();
|
||||
self.averageLag = 0;
|
||||
self.connect();
|
||||
$(window).unload(function() {
|
||||
self.destroy();
|
||||
|
@ -87,6 +90,7 @@ $.websocket.prototype = {
|
|||
try {
|
||||
self.debug("ping " + self.pingData());
|
||||
self.ws.send(self.pingData());
|
||||
self.lastPingTime = self.now();
|
||||
} catch (e) {
|
||||
self.debug(e);
|
||||
}
|
||||
|
@ -97,6 +101,11 @@ $.websocket.prototype = {
|
|||
//self.debug("pong");
|
||||
clearTimeout(self.connectSchedule);
|
||||
self.schedulePing(self.options.pingDelay);
|
||||
var lag = self.now() - self.lastPingTime;
|
||||
if (self.options.lagTag) {
|
||||
self.options.lagTag.text(lag + " ms");
|
||||
}
|
||||
self.averageLag = self.averageLag * 0.8 + lag * 0.2;
|
||||
},
|
||||
pingData: function() {
|
||||
return JSON.stringify({t: "p", v: this.version});
|
||||
|
@ -120,6 +129,7 @@ $.websocket.prototype = {
|
|||
else self.debug(m.t + " not supported");
|
||||
}
|
||||
},
|
||||
now: function() { return new Date().getTime(); },
|
||||
debug: function(msg) { if (this.options.debug) console.debug("[" + this.options.name + "]", msg); },
|
||||
destroy: function() {
|
||||
var self = this;
|
||||
|
|
|
@ -469,7 +469,7 @@ div.locale_adjust {
|
|||
}
|
||||
|
||||
div.lichess_social {
|
||||
height: 25px;
|
||||
height: 0px;
|
||||
text-align: center;
|
||||
}
|
||||
div.lichess_social div.addtochrome {
|
||||
|
|
Loading…
Reference in New Issue