start integrating pools to lobby
This commit is contained in:
parent
97c4ed86de
commit
bba0830674
|
@ -154,6 +154,6 @@ object Env {
|
|||
gameCache = lila.game.Env.current.cached,
|
||||
system = lila.common.PlayApp.system,
|
||||
scheduler = lila.common.PlayApp.scheduler,
|
||||
pools = lila.pool.Env.current.pools.configs,
|
||||
pools = lila.pool.Env.current.api.configs,
|
||||
isProd = lila.common.PlayApp.isProd)
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ final class Env(
|
|||
blocking: String => Fu[Set[String]],
|
||||
playban: String => Fu[Option[lila.playban.TempBan]],
|
||||
gameCache: lila.game.Cached,
|
||||
poolApi: lila.pool.PoolApi,
|
||||
system: ActorSystem,
|
||||
scheduler: lila.common.Scheduler) {
|
||||
|
||||
|
@ -51,6 +52,7 @@ final class Env(
|
|||
maxPlaying = MaxPlaying,
|
||||
blocking = blocking,
|
||||
playban = playban,
|
||||
poolApi = poolApi,
|
||||
onStart = onStart,
|
||||
hideHooks = () => disableHooks.get)
|
||||
}
|
||||
|
@ -59,6 +61,7 @@ final class Env(
|
|||
hub = hub,
|
||||
lobby = lobby,
|
||||
socket = socket,
|
||||
poolApi = poolApi,
|
||||
blocking = blocking)
|
||||
|
||||
object disableHooks {
|
||||
|
@ -96,6 +99,7 @@ object Env {
|
|||
blocking = lila.relation.Env.current.api.fetchBlocking,
|
||||
playban = lila.playban.Env.current.api.currentBan _,
|
||||
gameCache = lila.game.Env.current.cached,
|
||||
poolApi = lila.pool.Env.current.api,
|
||||
system = lila.common.PlayApp.system,
|
||||
scheduler = lila.common.PlayApp.scheduler)
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ private[lobby] final class Lobby(
|
|||
maxPlaying: Int,
|
||||
blocking: String => Fu[Set[String]],
|
||||
playban: String => Fu[Option[lila.playban.TempBan]],
|
||||
poolApi: lila.pool.PoolApi,
|
||||
onStart: String => Unit,
|
||||
hideHooks: () => Boolean) extends Actor {
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ import scala.concurrent.duration._
|
|||
import actorApi._
|
||||
import lila.common.PimpedJson._
|
||||
import lila.hub.actorApi.lobby._
|
||||
import lila.pool.{PoolApi,PoolConfig}
|
||||
import lila.socket.actorApi.{ Connected => _, _ }
|
||||
import lila.socket.Handler
|
||||
import lila.user.User
|
||||
|
@ -18,6 +19,7 @@ private[lobby] final class SocketHandler(
|
|||
hub: lila.hub.Env,
|
||||
lobby: ActorRef,
|
||||
socket: ActorRef,
|
||||
poolApi: PoolApi,
|
||||
blocking: String => Fu[Set[String]]) {
|
||||
|
||||
private def controller(
|
||||
|
@ -38,6 +40,14 @@ private[lobby] final class SocketHandler(
|
|||
user <- member.user
|
||||
} lobby ! CancelSeek(id, user)
|
||||
case ("idle", o) => socket ! SetIdle(uid, ~(o boolean "d"))
|
||||
case ("poolIn", o) => for {
|
||||
id <- o str "d"
|
||||
user <- member.user
|
||||
} poolApi.join(PoolConfig.Id(id), PoolApi.Joiner(user.id, user.ratingMap))
|
||||
case ("poolOut", o) => for {
|
||||
id <- o str "d"
|
||||
user <- member.user
|
||||
} poolApi.leave(PoolConfig.Id(id), user.id)
|
||||
}
|
||||
|
||||
def apply(uid: String, user: Option[User], mobile: Boolean): Fu[JsSocketHandler] =
|
||||
|
|
|
@ -13,7 +13,7 @@ final class Env(
|
|||
|
||||
private val PoolList = (config getStringList "list").toList flatMap PoolConfig.parse
|
||||
|
||||
val pools = new Pools(PoolList, system)
|
||||
lazy val api = new PoolApi(PoolList, system)
|
||||
}
|
||||
|
||||
object Env {
|
||||
|
|
|
@ -13,8 +13,8 @@ private final class PoolActor(config: PoolConfig) extends Actor {
|
|||
|
||||
def receive = {
|
||||
|
||||
case Join(user) =>
|
||||
members = members.filter(_.userId != user.id) :+ PoolMember(user, config)
|
||||
case Join(joiner) =>
|
||||
members = members.filter(_.userId != joiner.userId) :+ PoolMember(joiner, config)
|
||||
|
||||
case Leave(userId) =>
|
||||
members = members.filter(_.userId != userId)
|
||||
|
@ -28,7 +28,7 @@ private final class PoolActor(config: PoolConfig) extends Actor {
|
|||
|
||||
private object PoolActor {
|
||||
|
||||
case class Join(user: User) extends AnyVal
|
||||
case class Join(joiner: PoolApi.Joiner) extends AnyVal
|
||||
case class Leave(userId: User.ID) extends AnyVal
|
||||
|
||||
case object MakePairings
|
||||
|
|
|
@ -4,10 +4,11 @@ import akka.actor._
|
|||
|
||||
import lila.user.User
|
||||
|
||||
final class Pools(
|
||||
final class PoolApi(
|
||||
val configs: List[PoolConfig],
|
||||
system: ActorSystem) {
|
||||
|
||||
import PoolApi._
|
||||
import PoolActor._
|
||||
|
||||
private val actors: Map[PoolConfig.Id, ActorRef] = configs.map { config =>
|
||||
|
@ -16,9 +17,9 @@ final class Pools(
|
|||
name = s"pool-${config.id.value}")
|
||||
}.toMap
|
||||
|
||||
def join(poolId: PoolConfig.Id, user: User) = actors foreach {
|
||||
case (id, actor) if id == poolId => actor ! Join(user)
|
||||
case (_, actor) => actor ! Leave(user.id)
|
||||
def join(poolId: PoolConfig.Id, joiner: Joiner) = actors foreach {
|
||||
case (id, actor) if id == poolId => actor ! Join(joiner)
|
||||
case (_, actor) => actor ! Leave(joiner.userId)
|
||||
}
|
||||
|
||||
def leave(poolId: PoolConfig.Id, userId: User.ID) = sendTo(poolId, Leave(userId))
|
||||
|
@ -26,3 +27,8 @@ final class Pools(
|
|||
private def sendTo(poolId: PoolConfig.Id, msg: Any) =
|
||||
actors get poolId foreach { _ ! msg }
|
||||
}
|
||||
|
||||
object PoolApi {
|
||||
|
||||
case class Joiner(userId: User.ID, ratingMap: Map[String, Int])
|
||||
}
|
|
@ -11,8 +11,9 @@ case class PoolMember(
|
|||
|
||||
object PoolMember {
|
||||
|
||||
def apply(user: User, config: PoolConfig): PoolMember = PoolMember(
|
||||
user.id,
|
||||
user.perfs(config.perfType).intRating,
|
||||
DateTime.now)
|
||||
def apply(joiner: PoolApi.Joiner, config: PoolConfig): PoolMember =
|
||||
PoolMember(
|
||||
joiner.userId,
|
||||
joiner.ratingMap.getOrElse(config.perfType.key, 1500),
|
||||
DateTime.now)
|
||||
}
|
||||
|
|
|
@ -192,7 +192,8 @@ object ApplicationBuild extends Build {
|
|||
)
|
||||
|
||||
lazy val lobby = project("lobby", Seq(
|
||||
common, db, memo, hub, socket, chess, game, user, round, timeline, relation, playban, security)).settings(
|
||||
common, db, memo, hub, socket, chess, game, user,
|
||||
round, timeline, relation, playban, security, pool)).settings(
|
||||
libraryDependencies ++= provided(play.api, reactivemongo.driver)
|
||||
)
|
||||
|
||||
|
@ -205,16 +206,19 @@ object ApplicationBuild extends Build {
|
|||
libraryDependencies ++= provided(play.api, reactivemongo.driver)
|
||||
)
|
||||
|
||||
lazy val insight = project("insight",
|
||||
lazy val insight = project(
|
||||
"insight",
|
||||
Seq(common, chess, game, user, analyse, relation, pref, socket, round, security)
|
||||
).settings(
|
||||
libraryDependencies ++= provided(play.api,
|
||||
reactivemongo.driver, reactivemongo.iteratees)
|
||||
libraryDependencies ++= provided(
|
||||
play.api,
|
||||
reactivemongo.driver, reactivemongo.iteratees)
|
||||
)
|
||||
|
||||
lazy val tournament = project("tournament", Seq(
|
||||
common, hub, socket, chess, game, round, security, chat, memo, quote, history, notifyModule)).settings(
|
||||
libraryDependencies ++= provided(play.api,
|
||||
libraryDependencies ++= provided(
|
||||
play.api,
|
||||
reactivemongo.driver, reactivemongo.iteratees)
|
||||
)
|
||||
|
||||
|
@ -244,7 +248,8 @@ object ApplicationBuild extends Build {
|
|||
)
|
||||
|
||||
lazy val studySearch = project("studySearch", Seq(common, hub, study, search)).settings(
|
||||
libraryDependencies ++= provided(play.api,
|
||||
libraryDependencies ++= provided(
|
||||
play.api,
|
||||
reactivemongo.driver, reactivemongo.iteratees)
|
||||
)
|
||||
|
||||
|
@ -285,7 +290,8 @@ object ApplicationBuild extends Build {
|
|||
)
|
||||
|
||||
lazy val forumSearch = project("forumSearch", Seq(common, hub, forum, search)).settings(
|
||||
libraryDependencies ++= provided(play.api,
|
||||
libraryDependencies ++= provided(
|
||||
play.api,
|
||||
reactivemongo.driver, reactivemongo.iteratees)
|
||||
)
|
||||
|
||||
|
@ -294,7 +300,8 @@ object ApplicationBuild extends Build {
|
|||
)
|
||||
|
||||
lazy val teamSearch = project("teamSearch", Seq(common, hub, team, search)).settings(
|
||||
libraryDependencies ++= provided(play.api,
|
||||
libraryDependencies ++= provided(
|
||||
play.api,
|
||||
reactivemongo.driver, reactivemongo.iteratees)
|
||||
)
|
||||
|
||||
|
@ -319,7 +326,8 @@ object ApplicationBuild extends Build {
|
|||
)
|
||||
|
||||
lazy val explorer = project("explorer", Seq(common, db, game)).settings(
|
||||
libraryDependencies ++= provided(play.api,
|
||||
libraryDependencies ++= provided(
|
||||
play.api,
|
||||
reactivemongo.driver, reactivemongo.iteratees)
|
||||
)
|
||||
|
||||
|
|
|
@ -31,11 +31,11 @@ module.exports = function(send, ctrl) {
|
|||
};
|
||||
|
||||
this.poolIn = function(id) {
|
||||
send('pool_in', id);
|
||||
send('poolIn', id);
|
||||
}.bind(this);
|
||||
|
||||
this.poolOut = function(id) {
|
||||
send('pool_out', id);
|
||||
send('poolOut', id);
|
||||
}.bind(this);
|
||||
|
||||
this.receive = function(type, data) {
|
||||
|
|
Loading…
Reference in a new issue