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,
|
2015-12-06 03:40:34 -07:00
|
|
|
val scheduler: lila.common.Scheduler,
|
2017-01-26 14:00:51 -07:00
|
|
|
val system: ActorSystem,
|
2017-02-14 08:34:07 -07:00
|
|
|
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,
|
2016-02-23 20:03:22 -07:00
|
|
|
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 _,
|
2017-09-09 09:01:35 -06:00
|
|
|
dailyPuzzle = tryDailyPuzzle,
|
2018-01-06 06:31:51 -07:00
|
|
|
liveStreams = () => Env.streamer.liveStreamApi.all,
|
2017-09-09 09:01:35 -06:00
|
|
|
countRounds = Env.round.count,
|
2015-03-22 03:01:40 -06:00
|
|
|
lobbyApi = Env.api.lobbyApi,
|
2015-08-15 14:25:49 -06:00
|
|
|
getPlayban = Env.playban.api.currentBan _,
|
2017-02-14 08:34:07 -07:00
|
|
|
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,
|
2014-07-26 13:22:21 -06:00
|
|
|
getRatingChart = Env.history.ratingChartApi.apply,
|
2014-08-03 14:03:17 -06:00
|
|
|
getRanks = Env.user.cached.ranking.getAll,
|
2015-09-30 09:26:53 -06:00
|
|
|
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,
|
2017-03-18 05:48:33 -06:00
|
|
|
getPlayTime = Env.game.playTime.apply,
|
2017-02-14 08:34:07 -07:00
|
|
|
completionRate = Env.playban.api.completionRate
|
|
|
|
) _
|
2013-05-23 12:03:43 -06:00
|
|
|
|
2016-11-27 22:42:37 -07:00
|
|
|
lazy val teamInfo = new mashup.TeamInfoApi(
|
|
|
|
api = Env.team.api,
|
|
|
|
getForumNbPosts = Env.forum.categApi.teamNbPosts _,
|
2017-01-26 14:46:26 -07:00
|
|
|
getForumPosts = Env.forum.recent.team _,
|
2017-02-14 08:34:07 -07:00
|
|
|
asyncCache = Env.memo.asyncCache
|
|
|
|
)
|
2016-11-27 22:42:37 -07:00
|
|
|
|
2018-02-14 07:49:08 -07:00
|
|
|
private val tryDailyPuzzle: lila.puzzle.Daily.Try = () =>
|
2017-01-29 03:53:44 -07:00
|
|
|
scala.concurrent.Future {
|
|
|
|
Env.puzzle.daily.get
|
|
|
|
}.flatMap(identity).withTimeoutDefault(50 millis, none)(system) recover {
|
2016-07-29 08:02:44 -06:00
|
|
|
case e: Exception =>
|
|
|
|
lila.log("preloader").warn("daily puzzle", e)
|
|
|
|
none
|
|
|
|
}
|
2016-07-29 07:55:49 -06:00
|
|
|
|
2018-03-10 06:10:46 -07:00
|
|
|
def closeAccount(userId: lila.user.User.ID, self: Boolean): Funit = for {
|
2017-12-10 10:12:30 -07:00
|
|
|
user <- lila.user.UserRepo byId userId flatten s"No such user $userId"
|
2017-12-10 14:17:25 -07:00
|
|
|
goodUser <- !user.lameOrTroll ?? { !Env.playban.api.hasCurrentBan(user.id) }
|
2017-12-10 13:06:51 -07:00
|
|
|
_ <- lila.user.UserRepo.disable(user, keepEmail = !goodUser)
|
2017-12-10 10:12:30 -07:00
|
|
|
_ = Env.user.onlineUserIdMemo.remove(user.id)
|
2017-12-11 09:40:05 -07:00
|
|
|
following <- Env.relation.api fetchFollowing user.id
|
2018-01-03 15:39:55 -07:00
|
|
|
_ <- !goodUser ?? Env.activity.write.unfollowAll(user, following)
|
2017-12-10 10:12:30 -07:00
|
|
|
_ <- 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)
|
2018-04-04 15:15:28 -06:00
|
|
|
_ <- Env.streamer.api.demote(user.id)
|
2018-03-06 13:19:41 -07:00
|
|
|
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)
|
2017-12-10 10:12:30 -07:00
|
|
|
} 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")
|
2017-01-29 03:48:03 -07:00
|
|
|
lila.common.Chronometer.syncEffect(List(
|
|
|
|
Env.socket,
|
2016-03-12 05:56:44 -07:00
|
|
|
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,
|
2016-07-18 02:22:13 -06:00
|
|
|
Env.playban, // required to load the actor
|
2016-03-12 05:56:44 -07:00
|
|
|
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
|
2016-06-02 12:42:53 -06:00
|
|
|
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
|
|
|
|
2016-03-12 05:56:44 -07: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,
|
2015-12-06 03:40:34 -07:00
|
|
|
scheduler = lila.common.PlayApp.scheduler,
|
2017-09-09 09:01:35 -06:00
|
|
|
system = lila.common.PlayApp.system,
|
2017-02-14 08:34:07 -07:00
|
|
|
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
|
2013-07-27 09:39:19 -06:00
|
|
|
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
|
2014-05-03 10:11:24 -06:00
|
|
|
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
|
2014-07-26 13:22:21 -06:00
|
|
|
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
|
2016-01-04 20:40:42 -07:00
|
|
|
def slack = lila.slack.Env.current
|
2016-01-26 20:49:02 -07:00
|
|
|
def challenge = lila.challenge.Env.current
|
2016-02-08 22:00:49 -07:00
|
|
|
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
|
2017-01-21 05:34:20 -07:00
|
|
|
def practice = lila.practice.Env.current
|
2017-04-22 05:20:04 -06:00
|
|
|
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
|
|
|
}
|