lila/app/Env.scala

230 lines
7.7 KiB
Scala
Raw Normal View History

2013-04-10 04:17:58 -06:00
package lila.app
2013-04-10 18:38:38 -06:00
import akka.actor._
import com.typesafe.config.Config
2016-02-24 01:15:37 -07:00
import scala.concurrent.duration._
2013-04-10 18:38:38 -06:00
2013-05-24 07:49:02 -06:00
final class Env(
2013-06-04 08:27:07 -06:00
config: Config,
val scheduler: lila.common.Scheduler,
val system: ActorSystem,
appPath: String
) {
2013-04-10 18:38:38 -06:00
val CliUsername = config getString "cli.username"
2013-04-12 17:47:03 -06:00
2013-04-10 18:38:38 -06:00
private val RendererName = config getString "app.renderer.name"
2013-05-08 15:34:37 -06:00
lazy val preloader = new mashup.Preload(
2015-06-16 10:46:30 -06:00
tv = Env.tv.tv,
leaderboard = Env.user.cached.topWeek,
2016-10-17 09:35:24 -06:00
tourneyWinners = Env.tournament.winners.all.map(_.top),
2017-08-05 02:37:36 -06:00
timelineEntries = Env.timeline.entryApi.userEntries _,
dailyPuzzle = tryDailyPuzzle,
2018-01-06 06:31:51 -07:00
liveStreams = () => Env.streamer.liveStreamApi.all,
countRounds = Env.round.count,
2015-03-22 03:01:40 -06:00
lobbyApi = Env.api.lobbyApi,
getPlayban = Env.playban.api.currentBan _,
lightUserApi = Env.user.lightUserApi
)
2013-05-08 15:34:37 -06:00
2017-07-23 04:15:00 -06:00
lazy val socialInfo = mashup.UserInfo.Social(
relationApi = Env.relation.api,
noteApi = Env.user.noteApi,
prefApi = Env.pref.api
) _
lazy val userNbGames = mashup.UserInfo.NbGames(
crosstableApi = Env.game.crosstableApi,
2013-05-23 12:03:43 -06:00
bookmarkApi = Env.bookmark.api,
2017-07-23 04:15:00 -06:00
gameCached = Env.game.cached
) _
lazy val userInfo = mashup.UserInfo(
2013-05-23 15:09:12 -06:00
relationApi = Env.relation.api,
2015-06-04 13:46:12 -06:00
trophyApi = Env.user.trophyApi,
2017-11-27 16:01:41 -07:00
shieldApi = Env.tournament.shieldApi,
2018-03-08 18:07:16 -07:00
revolutionApi = Env.tournament.revolutionApi,
2013-06-04 04:05:41 -06:00
postApi = Env.forum.postApi,
2016-05-11 10:21:03 -06:00
studyRepo = Env.study.studyRepo,
getRatingChart = Env.history.ratingChartApi.apply,
getRanks = Env.user.cached.ranking.getAll,
isHostingSimul = Env.simul.isHosting,
2017-12-30 22:08:01 -07:00
fetchIsStreamer = Env.streamer.api.isStreamer,
2017-02-05 04:19:53 -07:00
fetchTeamIds = Env.team.cached.teamIdsList,
2016-09-01 12:02:08 -06:00
fetchIsCoach = Env.coach.api.isListedCoach,
2016-04-02 02:19:34 -06:00
insightShare = Env.insight.share,
getPlayTime = Env.game.playTime.apply,
completionRate = Env.playban.api.completionRate
) _
2013-05-23 12:03:43 -06:00
lazy val teamInfo = new mashup.TeamInfoApi(
api = Env.team.api,
getForumNbPosts = Env.forum.categApi.teamNbPosts _,
getForumPosts = Env.forum.recent.team _,
asyncCache = Env.memo.asyncCache
)
private val tryDailyPuzzle: lila.puzzle.Daily.Try = () =>
scala.concurrent.Future {
Env.puzzle.daily.get
}.flatMap(identity).withTimeoutDefault(50 millis, none)(system) recover {
case e: Exception =>
lila.log("preloader").warn("daily puzzle", e)
none
}
2018-03-10 06:10:46 -07:00
def closeAccount(userId: lila.user.User.ID, self: Boolean): Funit = for {
user <- lila.user.UserRepo byId userId flatten s"No such user $userId"
goodUser <- !user.lameOrTroll ?? { !Env.playban.api.hasCurrentBan(user.id) }
2017-12-10 13:06:51 -07:00
_ <- lila.user.UserRepo.disable(user, keepEmail = !goodUser)
_ = Env.user.onlineUserIdMemo.remove(user.id)
following <- Env.relation.api fetchFollowing user.id
_ <- !goodUser ?? Env.activity.write.unfollowAll(user, following)
_ <- Env.relation.api.unfollowAll(user.id)
_ <- Env.user.rankingApi.remove(user.id)
_ <- Env.team.api.quitAll(user.id)
_ = Env.challenge.api.removeByUserId(user.id)
_ = Env.tournament.api.withdrawAll(user)
_ <- Env.plan.api.cancel(user).nevermind
_ <- Env.lobby.seekApi.removeByUser(user)
_ <- Env.security.store.disconnect(user.id)
_ <- Env.streamer.api.demote(user.id)
reports <- Env.report.api.processAndGetBySuspect(lila.report.Suspect(user))
2018-03-10 06:10:46 -07:00
_ <- self ?? Env.mod.logApi.selfCloseAccount(user.id, reports)
} yield {
system.lilaBus.publish(lila.hub.actorApi.security.CloseAccount(user.id), 'accountClose)
}
2017-11-11 20:20:49 -07:00
system.lilaBus.subscribe(system.actorOf(Props(new Actor {
def receive = {
2017-11-13 15:39:23 -07:00
case lila.hub.actorApi.security.GarbageCollect(userId, _) =>
system.scheduler.scheduleOnce(1 second) {
2018-03-10 06:10:46 -07:00
closeAccount(userId, self = false)
2017-11-13 15:39:23 -07:00
}
2017-11-11 20:20:49 -07:00
}
})), 'garbageCollect)
2013-04-10 18:38:38 -06:00
system.actorOf(Props(new actor.Renderer), name = RendererName)
2017-10-10 16:35:37 -06:00
lila.log.boot.info(s"Java version ${System.getProperty("java.version")}")
2016-03-20 03:31:09 -06:00
lila.log.boot.info("Preloading modules")
lila.common.Chronometer.syncEffect(List(
Env.socket,
Env.site,
Env.tournament,
Env.lobby,
Env.game,
Env.setup,
Env.round,
Env.team,
Env.message,
Env.timeline,
Env.gameSearch,
Env.teamSearch,
Env.forumSearch,
Env.relation,
Env.report,
Env.bookmark,
Env.pref,
Env.chat,
Env.puzzle,
Env.tv,
Env.blog,
Env.video,
Env.playban, // required to load the actor
Env.shutup, // required to load the actor
Env.insight, // required to load the actor
Env.push, // required to load the actor
Env.perfStat, // required to load the actor
Env.slack, // required to load the actor
Env.challenge, // required to load the actor
Env.explorer, // required to load the actor
Env.fishnet, // required to schedule the cleaner
2016-07-14 04:03:04 -06:00
Env.notifyModule, // required to load the actor
2016-07-25 14:34:15 -06:00
Env.plan, // required to load the actor
2016-08-22 16:05:10 -06:00
Env.studySearch, // required to load the actor
2017-07-18 05:35:59 -06:00
Env.event, // required to load the actor
2017-09-19 20:24:59 -06:00
Env.activity, // required to load the actor
Env.relay // you know the drill by now
2016-03-28 22:50:31 -06:00
)) { lap =>
2017-10-10 21:25:24 -06:00
lila.log.boot.info(s"${lap.millis}ms Preloading complete")
2013-06-04 08:27:07 -06:00
}
2013-04-12 17:47:03 -06:00
scheduler.once(5 seconds) {
2016-05-31 04:01:50 -06:00
Env.slack.api.publishRestart
2013-06-04 08:27:07 -06:00
}
2013-04-10 18:38:38 -06:00
}
2013-04-10 04:17:58 -06:00
object Env {
2015-08-31 18:36:08 -06:00
lazy val current = "app" boot new Env(
2013-04-10 18:38:38 -06:00
config = lila.common.PlayApp.loadConfig,
scheduler = lila.common.PlayApp.scheduler,
system = lila.common.PlayApp.system,
appPath = lila.common.PlayApp withApp (_.path.getCanonicalPath)
)
2013-04-10 18:38:38 -06:00
2013-04-10 04:17:58 -06:00
def api = lila.api.Env.current
def db = lila.db.Env.current
def user = lila.user.Env.current
def security = lila.security.Env.current
def hub = lila.hub.Env.current
def socket = lila.socket.Env.current
2017-01-26 14:18:14 -07:00
def memo = lila.memo.Env.current
2013-04-10 04:17:58 -06:00
def message = lila.message.Env.current
def i18n = lila.i18n.Env.current
def game = lila.game.Env.current
def bookmark = lila.bookmark.Env.current
def search = lila.search.Env.current
def gameSearch = lila.gameSearch.Env.current
def timeline = lila.timeline.Env.current
def forum = lila.forum.Env.current
def forumSearch = lila.forumSearch.Env.current
def team = lila.team.Env.current
def teamSearch = lila.teamSearch.Env.current
def analyse = lila.analyse.Env.current
def mod = lila.mod.Env.current
2016-05-31 07:19:12 -06:00
def notifyModule = lila.notify.Env.current
2013-04-10 04:17:58 -06:00
def site = lila.site.Env.current
def round = lila.round.Env.current
def lobby = lila.lobby.Env.current
def setup = lila.setup.Env.current
def importer = lila.importer.Env.current
2013-05-12 05:51:33 -06:00
def tournament = lila.tournament.Env.current
2015-03-30 16:40:26 -06:00
def simul = lila.simul.Env.current
2013-05-23 07:38:55 -06:00
def relation = lila.relation.Env.current
def report = lila.report.Env.current
2013-10-20 01:59:47 -06:00
def pref = lila.pref.Env.current
2014-01-31 15:54:34 -07:00
def chat = lila.chat.Env.current
2014-02-03 11:53:10 -07:00
def puzzle = lila.puzzle.Env.current
2014-05-03 17:45:14 -06:00
def coordinate = lila.coordinate.Env.current
def tv = lila.tv.Env.current
2014-05-31 13:03:04 -06:00
def blog = lila.blog.Env.current
2014-07-03 12:57:37 -06:00
def qa = lila.qa.Env.current
def history = lila.history.Env.current
2015-03-22 03:34:35 -06:00
def video = lila.video.Env.current
2015-04-25 16:08:07 -06:00
def playban = lila.playban.Env.current
2015-04-29 09:04:55 -06:00
def shutup = lila.shutup.Env.current
2015-11-26 21:05:59 -07:00
def insight = lila.insight.Env.current
2015-12-08 05:03:11 -07:00
def push = lila.push.Env.current
2015-12-23 20:41:28 -07:00
def perfStat = lila.perfStat.Env.current
def slack = lila.slack.Env.current
2016-01-26 20:49:02 -07:00
def challenge = lila.challenge.Env.current
def explorer = lila.explorer.Env.current
2016-03-11 08:23:06 -07:00
def fishnet = lila.fishnet.Env.current
2016-02-26 05:08:11 -07:00
def study = lila.study.Env.current
2016-07-25 03:11:39 -06:00
def studySearch = lila.studySearch.Env.current
2016-06-22 09:57:45 -06:00
def learn = lila.learn.Env.current
2016-07-12 11:19:30 -06:00
def plan = lila.plan.Env.current
2016-08-22 16:05:10 -06:00
def event = lila.event.Env.current
2016-08-20 08:39:42 -06:00
def coach = lila.coach.Env.current
2016-11-29 18:07:23 -07:00
def pool = lila.pool.Env.current
def practice = lila.practice.Env.current
def irwin = lila.irwin.Env.current
2017-07-18 04:05:22 -06:00
def activity = lila.activity.Env.current
2017-09-19 20:24:59 -06:00
def relay = lila.relay.Env.current
2017-12-27 21:56:36 -07:00
def streamer = lila.streamer.Env.current
2018-03-09 14:55:11 -07:00
def oAuth = lila.oauth.Env.current
2013-04-10 04:17:58 -06:00
}