2013-03-18 17:36:22 -06:00
|
|
|
package controllers
|
|
|
|
|
2014-12-18 16:25:37 -07:00
|
|
|
import play.api.libs.json._
|
2013-05-24 08:37:24 -06:00
|
|
|
import play.api.mvc._
|
2016-09-22 17:29:39 -06:00
|
|
|
import play.twirl.api.Html
|
|
|
|
import scala.concurrent.duration._
|
2013-05-24 08:37:24 -06:00
|
|
|
|
2013-12-29 02:51:40 -07:00
|
|
|
import lila.api.Context
|
2013-05-08 15:34:37 -06:00
|
|
|
import lila.app._
|
2017-05-09 15:18:32 -06:00
|
|
|
import lila.common.IpAddress
|
2013-05-08 15:34:37 -06:00
|
|
|
import views._
|
2013-03-18 17:36:22 -06:00
|
|
|
|
2013-10-28 12:23:37 -06:00
|
|
|
object Lobby extends LilaController {
|
2013-03-18 17:36:22 -06:00
|
|
|
|
2016-11-29 16:05:42 -07:00
|
|
|
private val lobbyJson = Json.obj(
|
2016-12-10 04:47:03 -07:00
|
|
|
"lobby" -> Json.obj(
|
|
|
|
"version" -> 0,
|
2016-12-10 04:58:29 -07:00
|
|
|
"pools" -> Env.api.lobbyApi.poolsJson
|
2016-12-10 04:47:03 -07:00
|
|
|
)
|
2016-11-29 16:05:42 -07:00
|
|
|
)
|
|
|
|
|
2014-02-17 02:12:19 -07:00
|
|
|
def home = Open { implicit ctx =>
|
2014-12-26 03:09:52 -07:00
|
|
|
negotiate(
|
2015-06-19 09:36:31 -06:00
|
|
|
html = renderHome(Results.Ok).map(NoCache),
|
2016-11-29 16:05:42 -07:00
|
|
|
api = _ => fuccess(Ok(lobbyJson))
|
2014-12-26 03:09:52 -07:00
|
|
|
)
|
2013-05-08 15:34:37 -06:00
|
|
|
}
|
2013-03-20 10:34:38 -06:00
|
|
|
|
2016-03-08 22:15:53 -07:00
|
|
|
def handleStatus(req: RequestHeader, status: Results.Status): Fu[Result] = {
|
2014-02-17 02:12:19 -07:00
|
|
|
reqToCtx(req) flatMap { ctx => renderHome(status)(ctx) }
|
2016-03-08 22:15:53 -07:00
|
|
|
}
|
2013-03-20 10:34:38 -06:00
|
|
|
|
2016-03-09 05:59:54 -07:00
|
|
|
def renderHome(status: Results.Status)(implicit ctx: Context): Fu[Result] = {
|
2017-05-09 15:18:32 -06:00
|
|
|
Env.current.preloader(
|
|
|
|
posts = Env.forum.recent(ctx.me, Env.team.cached.teamIdsList).nevermind,
|
|
|
|
tours = Env.tournament.cached.promotable.get.nevermind,
|
|
|
|
events = Env.event.api.promotable.get.nevermind,
|
|
|
|
simuls = Env.simul.allCreatedFeaturable.get.nevermind
|
|
|
|
) dmap (html.lobby.home.apply _).tupled dmap { html =>
|
|
|
|
ensureSessionId(ctx.req)(status(html))
|
|
|
|
}
|
2016-03-10 20:08:34 -07:00
|
|
|
}.mon(_.http.response.home)
|
2013-05-08 15:34:37 -06:00
|
|
|
|
2014-12-17 17:02:59 -07:00
|
|
|
def seeks = Open { implicit ctx =>
|
2014-12-28 16:15:42 -07:00
|
|
|
negotiate(
|
|
|
|
html = fuccess(NotFound),
|
|
|
|
api = _ => ctx.me.fold(Env.lobby.seekApi.forAnon)(Env.lobby.seekApi.forUser) map { seeks =>
|
|
|
|
Ok(JsArray(seeks.map(_.render)))
|
|
|
|
}
|
|
|
|
)
|
2014-12-17 17:02:59 -07:00
|
|
|
}
|
|
|
|
|
2017-02-15 17:53:15 -07:00
|
|
|
private val MessageLimitPerIP = new lila.memo.RateLimit[IpAddress](
|
2016-12-20 12:37:14 -07:00
|
|
|
credits = 40,
|
2016-12-08 03:15:37 -07:00
|
|
|
duration = 10 seconds,
|
|
|
|
name = "lobby socket message per IP",
|
2017-02-14 08:34:07 -07:00
|
|
|
key = "lobby_socket.message.ip"
|
|
|
|
)
|
2016-03-06 21:48:59 -07:00
|
|
|
|
2016-12-08 03:15:37 -07:00
|
|
|
def socket(apiVersion: Int) = SocketOptionLimited[JsValue](MessageLimitPerIP, "lobby") { implicit ctx =>
|
2017-02-01 07:31:22 -07:00
|
|
|
getSocketUid("sri") ?? { uid =>
|
|
|
|
Env.lobby.socketHandler(uid, user = ctx.me, mobile = getBool("mobile")) map some
|
2013-05-08 15:34:37 -06:00
|
|
|
}
|
|
|
|
}
|
2013-05-24 08:37:24 -06:00
|
|
|
|
2016-09-22 17:29:39 -06:00
|
|
|
def timeline = Auth { implicit ctx => me =>
|
2017-08-05 02:37:36 -06:00
|
|
|
Env.timeline.entryApi.userEntries(me.id) map { html.timeline.entries(_) }
|
2016-09-22 17:29:39 -06:00
|
|
|
}
|
2013-03-18 17:36:22 -06:00
|
|
|
}
|