various fixes / improvements
This commit is contained in:
parent
1414f47afa
commit
e2228f26ab
|
@ -31,7 +31,7 @@ object Round extends LilaController with TheftPrevention with RoundEventPerforme
|
|||
|
||||
def websocketPlayer(fullId: String) = WebSocket.async[JsValue] { implicit req ⇒
|
||||
reqToCtx(req) flatMap { implicit ctx ⇒
|
||||
(get("sri") |@| getInt("version") |@| get("token")).tupled zmap {
|
||||
(get("sri") |@| getInt("version") |@| get("tk2")).tupled zmap {
|
||||
case (uid, version, token) ⇒ env.socketHandler.player(fullId, version, uid, token, ctx)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,11 +8,12 @@ import Pos._
|
|||
object Board {
|
||||
|
||||
def render(pov: Pov) = {
|
||||
val check = ~pov.game.check.map(_.key)
|
||||
val check = pov.game.check.zmap(_.key)
|
||||
val board = pov.game.toChess.board
|
||||
val moved: Pos ⇒ Boolean = pov.game.toChessHistory.lastMove.fold((_: Pos) ⇒ false) { last ⇒
|
||||
pos ⇒ last._1 == pos || last._2 == pos
|
||||
}
|
||||
val moved: Pos ⇒ Boolean =
|
||||
pov.game.toChessHistory.lastMove.fold((_: Pos) ⇒ false) { last ⇒
|
||||
pos ⇒ last._1 == pos || last._2 == pos
|
||||
}
|
||||
pov.color.fold(white, black) map { s ⇒
|
||||
"""<div class="lcs %s%s%s" id="%s" style="top:%dpx;left:%dpx;">""".format(
|
||||
s.color,
|
||||
|
@ -22,7 +23,7 @@ object Board {
|
|||
s.top,
|
||||
s.left) ++
|
||||
"""<div class="lcsi"></div>""" ++ {
|
||||
~board(s.pos).map(piece ⇒
|
||||
board(s.pos).zmap(piece ⇒
|
||||
"""<div class="lichess_piece %s %s"></div>""".format(
|
||||
piece.role.name, piece.color.name)
|
||||
)
|
||||
|
|
|
@ -14,25 +14,23 @@ final class LobbyMenu(i18nKeys: I18nKeys) {
|
|||
val name: I18nKeys#Key,
|
||||
val title: I18nKeys#Key)
|
||||
|
||||
// TODO
|
||||
// val hook = new Elem(
|
||||
// "hook",
|
||||
// routes.Setup.hookForm,
|
||||
// i18nKeys.createAGame,
|
||||
// i18nKeys.createAGame)
|
||||
val hook = new Elem(
|
||||
"hook",
|
||||
routes.Setup.hookForm,
|
||||
i18nKeys.createAGame,
|
||||
i18nKeys.createAGame)
|
||||
|
||||
// val friend = new Elem(
|
||||
// "friend",
|
||||
// routes.Setup.friendForm,
|
||||
// i18nKeys.playWithAFriend,
|
||||
// i18nKeys.inviteAFriendToPlayWithYou)
|
||||
val friend = new Elem(
|
||||
"friend",
|
||||
routes.Setup.friendForm,
|
||||
i18nKeys.playWithAFriend,
|
||||
i18nKeys.inviteAFriendToPlayWithYou)
|
||||
|
||||
// val ai = new Elem(
|
||||
// "ai",
|
||||
// routes.Setup.aiForm,
|
||||
// i18nKeys.playWithTheMachine,
|
||||
// i18nKeys.challengeTheArtificialIntelligence)
|
||||
val ai = new Elem(
|
||||
"ai",
|
||||
routes.Setup.aiForm,
|
||||
i18nKeys.playWithTheMachine,
|
||||
i18nKeys.challengeTheArtificialIntelligence)
|
||||
|
||||
// val all = List(hook, friend, ai)
|
||||
val all = List[Elem]()
|
||||
val all = List(hook, friend, ai)
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ final class Env(config: Config, system: ActorSystem) {
|
|||
val site = socketFor("site")
|
||||
val round = socketFor("round")
|
||||
val hub = system.actorOf(Props(new Broadcast(List(
|
||||
socket.lobby, socket.site
|
||||
lobby, site, round
|
||||
))(makeTimeout(SocketHubTimeout))), name = SocketHubName)
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ object Message {
|
|||
import Tube.Helpers._
|
||||
|
||||
private[lobby] lazy val tube = Tube[Message](
|
||||
reader = Json.reads[Message],
|
||||
writer = Json.writes[Message],
|
||||
(__.json update readDate('date)) andThen Json.reads[Message],
|
||||
Json.writes[Message] andThen (__.json update writeDate('date)),
|
||||
flags = Seq(_.NoId))
|
||||
}
|
||||
|
|
|
@ -76,7 +76,7 @@ private[round] final class Socket(
|
|||
case GameEvents(_, events) ⇒ notify(events)
|
||||
|
||||
case msg @ AnalysisAvailable(_) ⇒ {
|
||||
notifyAll("analysisAvailable", JsNull)
|
||||
notifyAll("analysisAvailable", true)
|
||||
}
|
||||
|
||||
case Quit(uid) ⇒ {
|
||||
|
@ -116,24 +116,24 @@ private[round] final class Socket(
|
|||
|
||||
def batch(member: Member, vevents: List[VersionedEvent]) {
|
||||
if (vevents.nonEmpty) {
|
||||
member.channel push makeEvent("b", JsArray(vevents map (_ jsFor member)))
|
||||
member.channel push makeEvent("b", List(vevents map (_ jsFor member)))
|
||||
}
|
||||
}
|
||||
|
||||
def notifyOwner(color: Color, t: String, data: JsValue) {
|
||||
def notifyOwner[A : Writes](color: Color, t: String, data: A) {
|
||||
ownerOf(color) foreach { m ⇒
|
||||
m.channel push makeEvent(t, data)
|
||||
}
|
||||
}
|
||||
|
||||
def notifyGone(color: Color, gone: Boolean) {
|
||||
notifyOwner(!color, "gone", JsBoolean(gone))
|
||||
notifyOwner(!color, "gone", gone)
|
||||
}
|
||||
|
||||
def makeEvent(t: String, data: JsValue): JsObject =
|
||||
JsObject(Seq("t" -> JsString(t), "d" -> data))
|
||||
def makeEvent[A : Writes](t: String, data: A): JsObject =
|
||||
Json.obj("t" -> t, "d" -> data)
|
||||
|
||||
lazy val ackEvent = makeEvent("ack", JsNull)
|
||||
lazy val ackEvent = Json.obj("t" -> "ack")
|
||||
|
||||
def ownerOf(color: Color): Option[Member] =
|
||||
members.values find { m ⇒ m.owner && m.color == color }
|
||||
|
|
|
@ -44,10 +44,11 @@ object Handler {
|
|||
}
|
||||
}
|
||||
|
||||
def errorHandler(err: String): JsSocketHandler =
|
||||
def errorHandler(err: String): JsSocketHandler = {
|
||||
logwarn("[socket] " + err)
|
||||
Iteratee.skipToEof[JsValue] ->
|
||||
Enumerator[JsValue](Json.obj(
|
||||
"error" -> "Socket handler error: %s".format(err)
|
||||
)).andThen(Enumerator.eof)
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue