many fixes

This commit is contained in:
Thibault Duplessis 2013-05-09 15:55:33 -03:00
parent 6c38438d28
commit 2768fb8457
8 changed files with 35 additions and 45 deletions

View file

@ -8,6 +8,7 @@ import controllers.{ routes ⇒ R }
import akka.actor._
import akka.pattern.{ ask, pipe }
// returns String urls, not Call objects
private[app] final class Router(
baseUrl: String,
protocol: String,
@ -25,9 +26,9 @@ private[app] final class Router(
case route: String noLangBaseUrl + route
} pipeTo sender
case TeamShow(id) sender ! R.Team.show(id)
case TeamShow(id) sender ! R.Team.show(id).url
case Player(fullId) sender ! R.Round.player(fullId)
case Player(fullId) sender ! R.Round.player(fullId).url
}
private lazy val noLangBaseUrl = protocol + I18nDomain(domain).commonDomain

View file

@ -17,7 +17,6 @@ import play.api.templates.Html
object Round extends LilaController with TheftPrevention with RoundEventPerformer {
private def env = Env.round
// private def rematcher = Env.setup.rematcher
private def bookmarkApi = Env.bookmark.api
private def analyser = Env.analyse.analyser
// private def tournamentRepo = Env.tournament.repo
@ -67,8 +66,7 @@ object Round extends LilaController with TheftPrevention with RoundEventPerforme
tour = tour))
}
},
Ok("TODO").fuccess
// TODO Redirect(routes.Setup.await(fullId)).fuccess
Redirect(routes.Setup.await(fullId)).fuccess
)
}
}
@ -81,10 +79,9 @@ object Round extends LilaController with TheftPrevention with RoundEventPerforme
private def join(pov: Pov)(implicit ctx: Context): Fu[Result] =
GameRepo initialFen pov.gameId zip env.version(pov.gameId) map {
case (fen, version) Ok("TODO") // TODO
// Ok(html.setup.join(
// pov, version, env.setup.friendConfigMemo get pov.game.id, fen
// ))
case (fen, version) Ok(html.setup.join(
pov, version, Env.setup.friendConfigMemo get pov.game.id, fen
))
}
private def watch(pov: Pov)(implicit ctx: Context): Fu[Result] =
@ -111,20 +108,19 @@ object Round extends LilaController with TheftPrevention with RoundEventPerforme
def drawCancel(fullId: String) = performAndRedirect(fullId, hand.drawCancel)
def drawDecline(fullId: String) = performAndRedirect(fullId, hand.drawDecline)
def rematch(fullId: String) = TODO
// Action {
// rematcher offerOrAccept fullId flatMap { validResult
// validResult.fold(
// err putFailures(err) map { _
// Redirect(routes.Round.player(fullId))
// }, {
// case (nextFullId, events) performEvents(fullId)(events) map { _
// Redirect(routes.Round.player(nextFullId))
// }
// }
// )
// }
// }
def rematch(fullId: String) = Open { implicit ctx
Env.setup.rematcher offerOrAccept fullId fold (
err {
logwarn(err.getMessage)
Redirect(routes.Round.player(fullId))
}, {
case (nextFullId, events) {
performEvents(fullId)(events)
Redirect(routes.Round.player(nextFullId))
}
}
)
}
def rematchCancel(fullId: String) = performAndRedirect(fullId, hand.rematchCancel)
def rematchDecline(fullId: String) = performAndRedirect(fullId, hand.rematchDecline)

View file

@ -68,10 +68,10 @@ object GameRepo {
$update($select(id), $set("p.0.ed" -> white, "p.1.ed" -> black))
def setUser(id: ID, color: Color, user: User) = {
val pn = "p" + color.fold(0, 1)
val pn = "p." + color.fold(0, 1) + "."
$update($select(id), $set(
pn + ".uid" -> Json.toJson(user.id),
pn + ".elo" -> Json.toJson(user.elo))
(pn + "uid") -> Json.toJson(user.id),
(pn + "elo") -> Json.toJson(user.elo))
)
}

View file

@ -24,8 +24,8 @@ private[round] final class History(ttl: Duration) extends Actor {
else ((v + 1 to version).toList map get).flatten.some
)
case AddEvents(events) sender ! {
events map { e
case AddEvents(xs) sender ! {
xs map { e
version = version + 1
VersionedEvent(
version = version,

View file

@ -139,9 +139,7 @@ private[round] final class Socket(
def ownerOf(uid: String): Option[Member] =
members get uid filter (_.owner)
def playerTime(color: Color): Double = color.fold(
whiteTime,
blackTime)
def playerTime(color: Color): Double = color.fold(whiteTime, blackTime)
def playerTime(color: Color, time: Double) {
color.fold(whiteTime = time, blackTime = time)

View file

@ -1,9 +1,8 @@
package lila.round
import akka.actor._
import akka.pattern.ask
import akka.pattern.{ ask, pipe }
import play.api.libs.json.JsObject
import scalaz.{ Success, Failure }
import actorApi._
import lila.game.{ Pov, PovRef, GameRepo }
@ -34,7 +33,7 @@ private[round] final class SocketHandler(
txt o str "d"
if member.canChat
if flood.allowMessage(uid, txt)
} messenger.playerMessage(povRef, txt) foreach socket.!
} messenger.playerMessage(povRef, txt) pipeTo socket
case ("move", o) parseMove(o) foreach {
case (orig, dest, prom, blur, lag) {
socket ! Ack(uid)
@ -50,12 +49,8 @@ private[round] final class SocketHandler(
})
}
}
case ("moretime", o) hand moretime povRef foreach {
_ foreach { events socket ! events }
}
case ("outoftime", o) hand outoftime povRef foreach {
_ foreach socket.!
}
case ("moretime", o) hand moretime povRef pipeTo socket
case ("outoftime", o) hand outoftime povRef pipeTo socket
}
else {
case ("p", o) o int "v" foreach { v socket ! PingVersion(uid, v) }
@ -66,7 +61,7 @@ private[round] final class SocketHandler(
} messenger.watcherMessage(
povRef.gameId,
member.userId,
txt) foreach socket.!
txt) pipeTo socket
}
def watcher(

View file

@ -6,7 +6,7 @@ import tube.{ anonConfigTube, filterConfigTube }
import lila.game.Game
import lila.db.Implicits._
import lila.db.api._
import lila.common.LilaCookie
import lila.common.{ LilaCookie, LilaException }
import play.api.libs.json._
import play.api.mvc._
@ -28,7 +28,7 @@ private[setup] object AnonConfigRepo {
def config(sid: String): Fu[UserConfig] =
$find byId sid recover {
case e: lila.db.DbException {
case e: LilaException {
logwarn("Can't load config: " + e.getMessage)
none[UserConfig]
}

View file

@ -1,11 +1,11 @@
package lila.setup
import lila.user.User
import tube.{ userConfigTube, filterConfigTube }
import lila.game.Game
import lila.db.Implicits._
import lila.db.api._
import lila.common.LilaException
import play.api.libs.json._
@ -19,7 +19,7 @@ private[setup] object UserConfigRepo {
def config(user: User): Fu[UserConfig] =
$find byId user.id recover {
case e: lila.db.DbException {
case e: LilaException {
logwarn("Can't load config: " + e.getMessage)
none[UserConfig]
}