Start sync implementation

This commit is contained in:
Thibault Duplessis 2012-03-16 23:18:06 +01:00
parent f21d6aa1d4
commit ef73f21eed
3 changed files with 39 additions and 3 deletions

View file

@ -5,11 +5,16 @@ import DataForm._
import play.api._
import play.api.mvc._
import play.api.libs.json._
object Application extends Controller {
val env = new HttpEnv(Play.unsafeApplication.configuration.underlying)
def sync(id: String, color: String, version: Int, fullId: String) = Action {
Ok(toJson(env.syncer.sync(id, color, version, fullId)))
}
def move(fullId: String) = Action { implicit request
(moveForm.bindFromRequest.value toValid "Invalid move" flatMap { move =>
env.server.play(fullId, move._1, move._2, move._3).unsafePerformIO

View file

@ -3,8 +3,9 @@
# ~~~~
# Home page
GET / controllers.Application.index
POST /move/:fullId controllers.Application.move(fullId: String)
GET / controllers.Application.index
POST /move/:fullId controllers.Application.move(fullId: String)
POST /sync/:id/:color/:version/:fullId controllers.Application.sync(id: String, color: String, version: Int, fullId: String)
# Map static resources from the /public folder to the /assets URL path
GET /assets/*file controllers.Assets.at(path="/public", file)
GET /assets/*file controllers.Assets.at(path="/public", file)

View file

@ -0,0 +1,30 @@
package lila.system
import lila.chess.Color
import model._
import scalaz.effects._
final class Syncer(repo: GameRepo) {
def sync(
id: String,
colorString: String,
version: Int,
fullId: String): IO[Map[String, Any]] = {
for {
color io { Color(colorString) err "Invalid color" }
gameAndPlayer repo.player(id, color)
(g, p) = gameAndPlayer
//events io { eventsSince(p, version) }
} yield Map(
"v" -> p.eventStack.version,
//"e" -> events map (_.toMap),
"p" -> g.player,
"t" -> g.turns
)
} except (e io(Map("reload" -> true)))
def eventsSince(player: DbPlayer, version: Int): List[Event] =
player.eventStack.eventsSince(version) | Nil
}