diff --git a/app/controllers/LilaController.scala b/app/controllers/LilaController.scala index 91c4682374..0a85905a7f 100644 --- a/app/controllers/LilaController.scala +++ b/app/controllers/LilaController.scala @@ -51,11 +51,6 @@ private[controllers] trait LilaController protected def SocketEither[A: FrameFormatter](f: Context => Fu[Either[Result, (Iteratee[A, _], Enumerator[A])]]) = WebSocket.tryAccept[A] { req => reqToCtx(req) flatMap f } - protected def SocketEitherLimited[A: FrameFormatter](consumer: TokenBucket.Consumer, name: String)(f: Context => Fu[Either[Result, (Iteratee[A, _], Enumerator[A])]]) = - LilaSocket.rateLimited[A](consumer, name) { req => - reqToCtx(req) flatMap f - } - protected def SocketOption[A: FrameFormatter](f: Context => Fu[Option[(Iteratee[A, _], Enumerator[A])]]) = WebSocket.tryAccept[A] { req => reqToCtx(req) flatMap f map { diff --git a/app/controllers/Round.scala b/app/controllers/Round.scala index 088d56a0a4..3e69d0b1e1 100644 --- a/app/controllers/Round.scala +++ b/app/controllers/Round.scala @@ -23,40 +23,31 @@ object Round extends LilaController with TheftPrevention { private def bookmarkApi = Env.bookmark.api private def analyser = Env.analyse.analyser - private val socketConsumer = lila.api.TokenBucket.create( - system = lila.common.PlayApp.system, - size = 10, - rate = 6) - - def websocketWatcher(gameId: String, color: String) = SocketOptionLimited[JsValue]( - consumer = socketConsumer, - name = "watcher") { implicit ctx => - get("sri") ?? { uid => - env.socketHandler.watcher( - gameId = gameId, - colorName = color, - uid = uid, - user = ctx.me, - ip = ctx.ip, - userTv = get("userTv")) - } + def websocketWatcher(gameId: String, color: String) = SocketOption[JsValue] { implicit ctx => + get("sri") ?? { uid => + env.socketHandler.watcher( + gameId = gameId, + colorName = color, + uid = uid, + user = ctx.me, + ip = ctx.ip, + userTv = get("userTv")) } + } - def websocketPlayer(fullId: String, apiVersion: Int) = SocketEitherLimited[JsValue]( - consumer = socketConsumer, - name = "player") { implicit ctx => - GameRepo pov fullId flatMap { - case Some(pov) => - if (isTheft(pov)) fuccess(Left(theftResponse)) - else get("sri") match { - case Some(uid) => requestAiMove(pov) >> env.socketHandler.player( - pov, uid, ~get("ran"), ctx.me, ctx.ip - ) map Right.apply - case None => fuccess(Left(NotFound)) - } - case None => fuccess(Left(NotFound)) - } + def websocketPlayer(fullId: String, apiVersion: Int) = SocketEither[JsValue] { implicit ctx => + GameRepo pov fullId flatMap { + case Some(pov) => + if (isTheft(pov)) fuccess(Left(theftResponse)) + else get("sri") match { + case Some(uid) => requestAiMove(pov) >> env.socketHandler.player( + pov, uid, ~get("ran"), ctx.me, ctx.ip + ) map Right.apply + case None => fuccess(Left(NotFound)) + } + case None => fuccess(Left(NotFound)) } + } private def requestAiMove(pov: Pov) = pov.game.playableByAi ?? Env.fishnet.player(pov.game)