forked from lichess-org/lila
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEnv.scala
110 lines (90 loc) · 3.08 KB
/
Env.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package lila.game
import akka.actor._
import com.typesafe.config.Config
final class Env(
config: Config,
db: lila.db.Env,
mongoCache: lila.memo.MongoCache.Builder,
system: ActorSystem,
hub: lila.hub.Env,
getLightUser: lila.common.LightUser.Getter,
appPath: String,
isProd: Boolean,
asyncCache: lila.memo.AsyncCache.Builder,
settingStore: lila.memo.SettingStore.Builder,
scheduler: lila.common.Scheduler
) {
private val settings = new {
val PaginatorMaxPerPage = config getInt "paginator.max_per_page"
val CaptcherName = config getString "captcher.name"
val CaptcherDuration = config duration "captcher.duration"
val CollectionGame = config getString "collection.game"
val CollectionCrosstable = config getString "collection.crosstable"
val CollectionMatchup = config getString "collection.matchup"
val UciMemoTtl = config duration "uci_memo.ttl"
val netBaseUrl = config getString "net.base_url"
val PngUrl = config getString "png.url"
val PngSize = config getInt "png.size"
}
import settings._
lazy val gameColl = db(CollectionGame)
lazy val pngExport = new PngExport(PngUrl, PngSize)
lazy val divider = new Divider
lazy val cached = new Cached(
coll = gameColl,
asyncCache = asyncCache,
mongoCache = mongoCache
)
lazy val paginator = new PaginatorBuilder(
coll = gameColl,
cached = cached,
maxPerPage = lila.common.MaxPerPage(PaginatorMaxPerPage)
)
lazy val rewind = Rewind
lazy val uciMemo = new UciMemo(UciMemoTtl)
lazy val pgnDump = new PgnDump(
netBaseUrl = netBaseUrl,
getLightUser = getLightUser
)
lazy val crosstableApi = new CrosstableApi(
coll = db(CollectionCrosstable),
matchupColl = db(CollectionMatchup),
gameColl = gameColl,
asyncCache = asyncCache,
system = system
)
lazy val playTime = new PlayTimeApi(gameColl, asyncCache, system)
// load captcher actor
private val captcher = system.actorOf(Props(new Captcher), name = CaptcherName)
scheduler.message(CaptcherDuration) {
captcher -> actorApi.NewCaptcha
}
def onStart(gameId: String) = GameRepo game gameId foreach {
_ foreach { game =>
system.lilaBus.publish(actorApi.StartGame(game), 'startGame)
game.userIds foreach { userId =>
system.lilaBus.publish(
actorApi.UserStartGame(userId, game),
Symbol(s"userStartGame:$userId")
)
}
}
}
lazy val gamesByUsersStream = new GamesByUsersStream(system)
lazy val bestOpponents = new BestOpponents
}
object Env {
lazy val current = "game" boot new Env(
config = lila.common.PlayApp loadConfig "game",
db = lila.db.Env.current,
mongoCache = lila.memo.Env.current.mongoCache,
system = lila.common.PlayApp.system,
hub = lila.hub.Env.current,
getLightUser = lila.user.Env.current.lightUser,
appPath = play.api.Play.current.path.getCanonicalPath,
isProd = lila.common.PlayApp.isProd,
asyncCache = lila.memo.Env.current.asyncCache,
settingStore = lila.memo.Env.current.settingStore,
scheduler = lila.common.PlayApp.scheduler
)
}