Implement lobby preload

pull/1/merge
Thibault Duplessis 2012-03-22 00:47:08 +01:00
parent ab96898741
commit 6d14a39884
6 changed files with 20 additions and 15 deletions

View File

@ -17,7 +17,6 @@ object LobbyXhrC extends LilaController {
private def sync(hookId: Option[String]) = Action { implicit request =>
JsonOk(xhr.sync(
getIntOr("auth", 0) == 1,
getOr("l", "en"),
getIntOr("state", 0)
).unsafePerformIO)
}

View File

@ -6,8 +6,8 @@
POST /move/:fullId controllers.AppXhrC.move(fullId: String)
GET /sync/:gameId/:color/:version controllers.AppXhrC.syncPublic(gameId: String, color: String, version: Int)
GET /sync/:gameId/:color/:version/:fullId controllers.AppXhrC.sync(gameId: String, color: String, version: Int, fullId: String)
GET /ping controllers.AppXhrC.ping()
GET /how-many-players-now controllers.AppXhrC.nbPlayers()
GET /ping controllers.AppXhrC.ping
GET /how-many-players-now controllers.AppXhrC.nbPlayers
# App Private API
POST /api/update-version/:gameId controllers.AppApiC.updateVersion(gameId: String)
@ -20,14 +20,16 @@ POST /api/alive/:gameId/:color controllers.AppApiC.alive(gameId: String, col
POST /api/draw/:gameId/:color controllers.AppApiC.draw(gameId: String, color: String)
POST /api/draw-accept/:gameId/:color controllers.AppApiC.drawAccept(gameId: String, color: String)
GET /api/activity/:gameId/:color controllers.AppApiC.activity(gameId: String, color: String)
GET /api/nb-players controllers.AppXhrC.nbPlayers()
GET /api/nb-players controllers.AppXhrC.nbPlayers
# Lobby XHR
GET /lobby/sync/:hookId controllers.LobbyXhrC.syncWithHook(hookId: String)
GET /lobby/sync controllers.LobbyXhrC.syncWithoutHook()
GET /lobby/sync controllers.LobbyXhrC.syncWithoutHook
# Lobby Private API
POST /api/lobby/join/:gameId/:color controllers.LobbyApiC.join(gameId: String, color: String)
GET /api/lobby/preload/:hookId controllers.LobbyXhrC.syncWithHook(hookId: String)
GET /api/lobby/preload controllers.LobbyXhrC.syncWithoutHook
# Useless, but play2 needs it
GET /assets/*file controllers.Assets.at(path="/public", file)

View File

@ -2,13 +2,14 @@ package lila.system
import model._
import memo._
import db.GameRepo
import lila.chess.{ Color, White, Black }
import db.{ GameRepo, HookRepo }
import scalaz.effects._
case class LobbyApi(
gameRepo: GameRepo,
hookRepo: HookRepo,
lobbyMemo: LobbyMemo,
versionMemo: VersionMemo,
gameRepo: GameRepo,
aliveMemo: AliveMemo) extends IOTools {
def join(gameId: String, colorName: String): IO[Unit] = for {

View File

@ -15,14 +15,13 @@ final class LobbyXhr(
def sync(
auth: Boolean,
lang: String,
version: Int): IO[Map[String, Any]] = for {
newVersion versionWait(version)
hooks if (auth) hookRepo.allOpen else hookRepo.allOpenCasual
} yield Map(
"state" -> newVersion,
"pool" -> {
if (hooks.nonEmpty) Map("hooks" -> renderHooks(hooks, None))
if (hooks.nonEmpty) Map("hooks" -> renderHooks(hooks, None).toMap)
else Map("message" -> "No game available right now, create one!")
},
"chat" -> null,
@ -31,9 +30,11 @@ final class LobbyXhr(
private def renderHooks(hooks: List[Hook], myHookId: Option[String]) = for {
hook hooks
} yield hook.render ++ {
if (myHookId == hook.ownerId) Map("action" -> "cancel", "id" -> myHookId)
else Map("action" -> "join", "id" -> hook.id)
} yield hook.id -> {
hook.render ++ {
if (myHookId == hook.ownerId) Map("action" -> "cancel", "id" -> myHookId)
else Map("action" -> "join", "id" -> hook.id)
}
}
private def versionWait(version: Int): IO[Int] = io {

View File

@ -27,8 +27,10 @@ final class SystemEnv(config: Config) {
sleep = getMilliseconds("lobby.poll.sleep"))
lazy val lobbyApi = new LobbyApi(
gameRepo = gameRepo,
hookRepo = hookRepo,
versionMemo = versionMemo,
lobbyMemo = lobbyMemo,
gameRepo = gameRepo,
aliveMemo = aliveMemo)
lazy val syncer = new Syncer(

View File

@ -3,5 +3,5 @@ package memo
final class LobbyMemo {
val version: Int = 0
val version: Int = 1
}