2013-04-10 04:17:58 -06:00
|
|
|
package lila.app
|
|
|
|
|
2013-04-10 18:38:38 -06:00
|
|
|
import akka.actor._
|
2019-12-04 08:02:49 -07:00
|
|
|
import com.softwaremill.macwire._
|
2020-05-08 09:31:27 -06:00
|
|
|
import lila.memo.SettingStore.Strings._
|
2020-07-24 01:55:29 -06:00
|
|
|
import lila.memo.SettingStore.UserIds._
|
2020-08-07 08:22:26 -06:00
|
|
|
import play.api.libs.ws.StandaloneWSClient
|
2019-12-13 07:30:20 -07:00
|
|
|
import play.api.mvc.{ ControllerComponents, SessionCookieBaker }
|
2019-12-08 01:02:12 -07:00
|
|
|
import play.api.{ Configuration, Environment, Mode }
|
2019-12-05 08:46:00 -07:00
|
|
|
import scala.concurrent.duration._
|
2019-12-13 18:17:43 -07:00
|
|
|
import scala.concurrent.{ ExecutionContext, Future }
|
2013-04-10 18:38:38 -06:00
|
|
|
|
2019-12-04 21:32:03 -07:00
|
|
|
import lila.common.config._
|
2020-05-08 09:31:27 -06:00
|
|
|
import lila.common.{ Bus, Lilakka, Strings }
|
2020-07-24 01:55:29 -06:00
|
|
|
import lila.common.UserIds
|
2019-08-24 07:21:20 -06:00
|
|
|
|
2013-05-24 07:49:02 -06:00
|
|
|
final class Env(
|
2019-12-04 08:02:49 -07:00
|
|
|
val config: Configuration,
|
2019-12-04 21:32:03 -07:00
|
|
|
val common: lila.common.Env,
|
2019-12-06 20:37:15 -07:00
|
|
|
val imageRepo: lila.db.ImageRepo,
|
2019-12-04 08:02:49 -07:00
|
|
|
val api: lila.api.Env,
|
|
|
|
val user: lila.user.Env,
|
|
|
|
val security: lila.security.Env,
|
|
|
|
val hub: lila.hub.Env,
|
|
|
|
val socket: lila.socket.Env,
|
|
|
|
val memo: lila.memo.Env,
|
2020-01-24 15:48:23 -07:00
|
|
|
val msg: lila.msg.Env,
|
2019-12-04 08:02:49 -07:00
|
|
|
val game: lila.game.Env,
|
|
|
|
val bookmark: lila.bookmark.Env,
|
|
|
|
val search: lila.search.Env,
|
|
|
|
val gameSearch: lila.gameSearch.Env,
|
|
|
|
val timeline: lila.timeline.Env,
|
|
|
|
val forum: lila.forum.Env,
|
|
|
|
val forumSearch: lila.forumSearch.Env,
|
|
|
|
val team: lila.team.Env,
|
|
|
|
val teamSearch: lila.teamSearch.Env,
|
|
|
|
val analyse: lila.analyse.Env,
|
|
|
|
val mod: lila.mod.Env,
|
2019-12-05 08:46:00 -07:00
|
|
|
val notifyM: lila.notify.Env,
|
2019-12-04 08:02:49 -07:00
|
|
|
val round: lila.round.Env,
|
|
|
|
val lobby: lila.lobby.Env,
|
|
|
|
val setup: lila.setup.Env,
|
|
|
|
val importer: lila.importer.Env,
|
|
|
|
val tournament: lila.tournament.Env,
|
|
|
|
val simul: lila.simul.Env,
|
|
|
|
val relation: lila.relation.Env,
|
|
|
|
val report: lila.report.Env,
|
2020-07-25 06:40:51 -06:00
|
|
|
val appeal: lila.appeal.Env,
|
2019-12-04 08:02:49 -07:00
|
|
|
val pref: lila.pref.Env,
|
|
|
|
val chat: lila.chat.Env,
|
|
|
|
val puzzle: lila.puzzle.Env,
|
|
|
|
val coordinate: lila.coordinate.Env,
|
|
|
|
val tv: lila.tv.Env,
|
|
|
|
val blog: lila.blog.Env,
|
|
|
|
val history: lila.history.Env,
|
|
|
|
val video: lila.video.Env,
|
|
|
|
val playban: lila.playban.Env,
|
|
|
|
val shutup: lila.shutup.Env,
|
|
|
|
val insight: lila.insight.Env,
|
|
|
|
val push: lila.push.Env,
|
|
|
|
val perfStat: lila.perfStat.Env,
|
|
|
|
val slack: lila.slack.Env,
|
|
|
|
val challenge: lila.challenge.Env,
|
|
|
|
val explorer: lila.explorer.Env,
|
|
|
|
val fishnet: lila.fishnet.Env,
|
|
|
|
val study: lila.study.Env,
|
|
|
|
val studySearch: lila.studySearch.Env,
|
|
|
|
val learn: lila.learn.Env,
|
|
|
|
val plan: lila.plan.Env,
|
|
|
|
val event: lila.event.Env,
|
|
|
|
val coach: lila.coach.Env,
|
2020-01-16 07:40:33 -07:00
|
|
|
val clas: lila.clas.Env,
|
2019-12-04 08:02:49 -07:00
|
|
|
val pool: lila.pool.Env,
|
|
|
|
val practice: lila.practice.Env,
|
|
|
|
val irwin: lila.irwin.Env,
|
|
|
|
val activity: lila.activity.Env,
|
|
|
|
val relay: lila.relay.Env,
|
|
|
|
val streamer: lila.streamer.Env,
|
|
|
|
val oAuth: lila.oauth.Env,
|
|
|
|
val bot: lila.bot.Env,
|
|
|
|
val evalCache: lila.evalCache.Env,
|
2019-12-05 08:46:00 -07:00
|
|
|
val rating: lila.rating.Env,
|
2020-04-29 10:31:34 -06:00
|
|
|
val swiss: lila.swiss.Env,
|
2019-12-06 20:37:15 -07:00
|
|
|
val lilaCookie: lila.common.LilaCookie,
|
|
|
|
val controllerComponents: ControllerComponents
|
2020-06-24 03:37:18 -06:00
|
|
|
)(implicit
|
|
|
|
val system: ActorSystem,
|
|
|
|
val executionContext: ExecutionContext,
|
|
|
|
val mode: play.api.Mode
|
|
|
|
) {
|
2019-12-04 08:02:49 -07:00
|
|
|
|
2020-05-05 20:53:16 -06:00
|
|
|
def net = common.netConfig
|
|
|
|
|
2019-12-13 07:30:20 -07:00
|
|
|
val explorerEndpoint = config.get[String]("explorer.endpoint")
|
2019-12-04 23:52:53 -07:00
|
|
|
val tablebaseEndpoint = config.get[String]("explorer.tablebase.endpoint")
|
2020-04-30 09:18:20 -06:00
|
|
|
|
|
|
|
val appVersionDate = config.getOptional[String]("app.version.date")
|
|
|
|
val appVersionCommit = config.getOptional[String]("app.version.commit")
|
|
|
|
val appVersionMessage = config.getOptional[String]("app.version.message")
|
2019-12-04 16:39:16 -07:00
|
|
|
|
2019-12-22 10:45:14 -07:00
|
|
|
lazy val apiTimelineSetting = memo.settingStore[Int](
|
|
|
|
"apiTimelineEntries",
|
|
|
|
default = 10,
|
|
|
|
text = "API timeline entries to serve".some
|
|
|
|
)
|
2020-05-08 09:31:27 -06:00
|
|
|
lazy val noDelaySecretSetting = memo.settingStore[Strings](
|
|
|
|
"noDelaySecrets",
|
|
|
|
default = Strings(Nil),
|
|
|
|
text =
|
|
|
|
"Secret tokens that allows fetching ongoing games without the 3-moves delay. Separated by commas.".some
|
|
|
|
)
|
2020-06-01 11:51:39 -06:00
|
|
|
lazy val featuredTeamsSetting = memo.settingStore[Strings](
|
|
|
|
"featuredTeams",
|
|
|
|
default = Strings(Nil),
|
2020-07-24 01:55:29 -06:00
|
|
|
text = "Team IDs that always get their tournaments visible on /tournament. Separated by commas.".some
|
|
|
|
)
|
|
|
|
lazy val prizeTournamentMakers = memo.settingStore[UserIds](
|
|
|
|
"prizeTournamentMakers ",
|
|
|
|
default = UserIds(Nil),
|
2020-07-30 02:44:05 -06:00
|
|
|
text =
|
|
|
|
"User IDs who can make prize tournaments (arena & swiss) without a warning. Separated by commas.".some
|
2020-06-01 11:51:39 -06:00
|
|
|
)
|
2019-12-22 10:45:14 -07:00
|
|
|
|
2019-12-13 07:30:20 -07:00
|
|
|
lazy val preloader = wire[mashup.Preload]
|
|
|
|
lazy val socialInfo = wire[mashup.UserInfo.SocialApi]
|
|
|
|
lazy val userNbGames = wire[mashup.UserInfo.NbGamesApi]
|
|
|
|
lazy val userInfo = wire[mashup.UserInfo.UserInfoApi]
|
|
|
|
lazy val teamInfo = wire[mashup.TeamInfoApi]
|
2019-12-04 23:52:53 -07:00
|
|
|
lazy val gamePaginator = wire[mashup.GameFilterMenu.PaginatorBuilder]
|
2020-05-24 09:28:10 -06:00
|
|
|
lazy val pageCache = wire[http.PageCache]
|
2019-12-04 16:39:16 -07:00
|
|
|
|
2018-02-14 07:49:08 -07:00
|
|
|
private val tryDailyPuzzle: lila.puzzle.Daily.Try = () =>
|
2019-12-13 07:30:20 -07:00
|
|
|
Future {
|
2019-12-04 08:02:49 -07:00
|
|
|
puzzle.daily.get
|
2019-12-13 07:30:20 -07:00
|
|
|
}.flatMap(identity)
|
2020-04-29 08:58:36 -06:00
|
|
|
.withTimeoutDefault(50.millis, none) 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
|
|
|
|
2019-12-04 23:52:53 -07:00
|
|
|
def scheduler = system.scheduler
|
|
|
|
|
2019-12-13 07:30:20 -07:00
|
|
|
def closeAccount(userId: lila.user.User.ID, self: Boolean): Funit =
|
|
|
|
for {
|
2019-12-31 11:17:47 -07:00
|
|
|
u <- user.repo byId userId orFail s"No such user $userId"
|
2019-12-31 11:31:26 -07:00
|
|
|
badApple = u.lameOrTrollOrAlt
|
2019-12-31 11:17:47 -07:00
|
|
|
playbanned <- playban.api.hasCurrentBan(u.id)
|
|
|
|
_ <- user.repo.disable(u, keepEmail = badApple || playbanned)
|
|
|
|
_ <- relation.api.unfollowAll(u.id)
|
|
|
|
_ <- user.rankingApi.remove(u.id)
|
2020-07-23 07:31:00 -06:00
|
|
|
teamIds <- team.api.quitAll(u.id)
|
2019-12-31 11:17:47 -07:00
|
|
|
_ <- challenge.api.removeByUserId(u.id)
|
|
|
|
_ <- tournament.api.withdrawAll(u)
|
2020-07-23 07:31:00 -06:00
|
|
|
_ <- swiss.api.withdrawAll(u, teamIds)
|
2019-12-31 11:17:47 -07:00
|
|
|
_ <- plan.api.cancel(u).nevermind
|
|
|
|
_ <- lobby.seekApi.removeByUser(u)
|
2020-05-30 19:53:40 -06:00
|
|
|
_ <- security.store.closeAllSessionsOf(u.id)
|
2019-12-31 11:17:47 -07:00
|
|
|
_ <- push.webSubscriptionApi.unsubscribeByUser(u)
|
|
|
|
_ <- streamer.api.demote(u.id)
|
|
|
|
_ <- coach.api.remove(u.id)
|
|
|
|
reports <- report.api.processAndGetBySuspect(lila.report.Suspect(u))
|
|
|
|
_ <- self ?? mod.logApi.selfCloseAccount(u.id, reports)
|
|
|
|
_ <- u.marks.troll ?? relation.api.fetchFollowing(u.id) flatMap {
|
2019-12-13 07:30:20 -07:00
|
|
|
activity.write.unfollowAll(u, _)
|
|
|
|
}
|
2019-12-31 10:44:30 -07:00
|
|
|
} yield Bus.publish(lila.hub.actorApi.security.CloseAccount(u.id), "accountClose")
|
2017-11-11 20:20:49 -07:00
|
|
|
|
2019-12-04 08:02:49 -07:00
|
|
|
Bus.subscribeFun("garbageCollect") {
|
2020-06-03 21:11:50 -06:00
|
|
|
case lila.hub.actorApi.security.GarbageCollect(userId) =>
|
2019-12-31 11:31:26 -07:00
|
|
|
// GC can be aborted by reverting the initial SB mark
|
2019-12-04 18:47:46 -07:00
|
|
|
user.repo.isTroll(userId) foreach { troll =>
|
2020-04-29 08:58:36 -06:00
|
|
|
if (troll) scheduler.scheduleOnce(1.second) {
|
2019-12-31 11:31:26 -07:00
|
|
|
closeAccount(userId, self = false)
|
|
|
|
}
|
2019-10-16 01:17:31 -06:00
|
|
|
}
|
2019-08-24 04:39:42 -06:00
|
|
|
}
|
|
|
|
|
2019-12-28 08:16:14 -07:00
|
|
|
system.actorOf(Props(new actor.Renderer), name = config.get[String]("app.renderer.name"))
|
2019-12-04 16:39:16 -07:00
|
|
|
}
|
|
|
|
|
2019-12-05 08:46:00 -07:00
|
|
|
final class EnvBoot(
|
|
|
|
config: Configuration,
|
|
|
|
environment: Environment,
|
|
|
|
controllerComponents: ControllerComponents,
|
2019-12-26 18:28:17 -07:00
|
|
|
cookieBacker: SessionCookieBaker,
|
|
|
|
shutdown: CoordinatedShutdown
|
2020-06-24 03:37:18 -06:00
|
|
|
)(implicit
|
|
|
|
ec: ExecutionContext,
|
|
|
|
system: ActorSystem,
|
2020-08-07 08:22:26 -06:00
|
|
|
ws: StandaloneWSClient
|
2020-06-24 03:37:18 -06:00
|
|
|
) {
|
2019-12-04 21:46:58 -07:00
|
|
|
|
2019-12-13 07:30:20 -07:00
|
|
|
implicit def scheduler = system.scheduler
|
2019-12-27 12:49:59 -07:00
|
|
|
implicit def mode = environment.mode
|
2019-12-13 07:30:20 -07:00
|
|
|
def appPath = AppPath(environment.rootPath)
|
2019-12-20 09:53:21 -07:00
|
|
|
def baseUrl = common.netConfig.baseUrl
|
2019-12-04 21:46:58 -07:00
|
|
|
implicit def idGenerator = game.idGenerator
|
|
|
|
|
2020-07-05 11:09:49 -06:00
|
|
|
lazy val mainDb: lila.db.Db = mongo.blockingDb("main", config.get[String]("mongodb.uri"))
|
2019-12-13 07:30:20 -07:00
|
|
|
lazy val imageRepo = new lila.db.ImageRepo(mainDb(CollName("image")))
|
2019-12-06 20:37:15 -07:00
|
|
|
|
2019-12-04 21:46:58 -07:00
|
|
|
// wire all the lila modules
|
2019-12-13 07:30:20 -07:00
|
|
|
lazy val common: lila.common.Env = wire[lila.common.Env]
|
|
|
|
lazy val memo: lila.memo.Env = wire[lila.memo.Env]
|
|
|
|
lazy val mongo: lila.db.Env = wire[lila.db.Env]
|
|
|
|
lazy val user: lila.user.Env = wire[lila.user.Env]
|
|
|
|
lazy val security: lila.security.Env = wire[lila.security.Env]
|
|
|
|
lazy val hub: lila.hub.Env = wire[lila.hub.Env]
|
|
|
|
lazy val socket: lila.socket.Env = wire[lila.socket.Env]
|
2020-01-24 15:48:23 -07:00
|
|
|
lazy val msg: lila.msg.Env = wire[lila.msg.Env]
|
2019-12-13 07:30:20 -07:00
|
|
|
lazy val game: lila.game.Env = wire[lila.game.Env]
|
|
|
|
lazy val bookmark: lila.bookmark.Env = wire[lila.bookmark.Env]
|
|
|
|
lazy val search: lila.search.Env = wire[lila.search.Env]
|
|
|
|
lazy val gameSearch: lila.gameSearch.Env = wire[lila.gameSearch.Env]
|
|
|
|
lazy val timeline: lila.timeline.Env = wire[lila.timeline.Env]
|
|
|
|
lazy val forum: lila.forum.Env = wire[lila.forum.Env]
|
2019-12-04 21:32:03 -07:00
|
|
|
lazy val forumSearch: lila.forumSearch.Env = wire[lila.forumSearch.Env]
|
2019-12-13 07:30:20 -07:00
|
|
|
lazy val team: lila.team.Env = wire[lila.team.Env]
|
|
|
|
lazy val teamSearch: lila.teamSearch.Env = wire[lila.teamSearch.Env]
|
|
|
|
lazy val analyse: lila.analyse.Env = wire[lila.analyse.Env]
|
|
|
|
lazy val mod: lila.mod.Env = wire[lila.mod.Env]
|
|
|
|
lazy val notifyM: lila.notify.Env = wire[lila.notify.Env]
|
|
|
|
lazy val round: lila.round.Env = wire[lila.round.Env]
|
|
|
|
lazy val lobby: lila.lobby.Env = wire[lila.lobby.Env]
|
|
|
|
lazy val setup: lila.setup.Env = wire[lila.setup.Env]
|
|
|
|
lazy val importer: lila.importer.Env = wire[lila.importer.Env]
|
|
|
|
lazy val tournament: lila.tournament.Env = wire[lila.tournament.Env]
|
|
|
|
lazy val simul: lila.simul.Env = wire[lila.simul.Env]
|
|
|
|
lazy val relation: lila.relation.Env = wire[lila.relation.Env]
|
|
|
|
lazy val report: lila.report.Env = wire[lila.report.Env]
|
2020-07-25 06:40:51 -06:00
|
|
|
lazy val appeal: lila.appeal.Env = wire[lila.appeal.Env]
|
2019-12-13 07:30:20 -07:00
|
|
|
lazy val pref: lila.pref.Env = wire[lila.pref.Env]
|
|
|
|
lazy val chat: lila.chat.Env = wire[lila.chat.Env]
|
|
|
|
lazy val puzzle: lila.puzzle.Env = wire[lila.puzzle.Env]
|
|
|
|
lazy val coordinate: lila.coordinate.Env = wire[lila.coordinate.Env]
|
|
|
|
lazy val tv: lila.tv.Env = wire[lila.tv.Env]
|
|
|
|
lazy val blog: lila.blog.Env = wire[lila.blog.Env]
|
|
|
|
lazy val history: lila.history.Env = wire[lila.history.Env]
|
|
|
|
lazy val video: lila.video.Env = wire[lila.video.Env]
|
|
|
|
lazy val playban: lila.playban.Env = wire[lila.playban.Env]
|
|
|
|
lazy val shutup: lila.shutup.Env = wire[lila.shutup.Env]
|
|
|
|
lazy val insight: lila.insight.Env = wire[lila.insight.Env]
|
|
|
|
lazy val push: lila.push.Env = wire[lila.push.Env]
|
|
|
|
lazy val perfStat: lila.perfStat.Env = wire[lila.perfStat.Env]
|
|
|
|
lazy val slack: lila.slack.Env = wire[lila.slack.Env]
|
|
|
|
lazy val challenge: lila.challenge.Env = wire[lila.challenge.Env]
|
|
|
|
lazy val explorer: lila.explorer.Env = wire[lila.explorer.Env]
|
|
|
|
lazy val fishnet: lila.fishnet.Env = wire[lila.fishnet.Env]
|
|
|
|
lazy val study: lila.study.Env = wire[lila.study.Env]
|
2019-12-04 21:32:03 -07:00
|
|
|
lazy val studySearch: lila.studySearch.Env = wire[lila.studySearch.Env]
|
2019-12-13 07:30:20 -07:00
|
|
|
lazy val learn: lila.learn.Env = wire[lila.learn.Env]
|
|
|
|
lazy val plan: lila.plan.Env = wire[lila.plan.Env]
|
|
|
|
lazy val event: lila.event.Env = wire[lila.event.Env]
|
|
|
|
lazy val coach: lila.coach.Env = wire[lila.coach.Env]
|
2020-01-16 07:40:33 -07:00
|
|
|
lazy val clas: lila.clas.Env = wire[lila.clas.Env]
|
2019-12-13 07:30:20 -07:00
|
|
|
lazy val pool: lila.pool.Env = wire[lila.pool.Env]
|
|
|
|
lazy val practice: lila.practice.Env = wire[lila.practice.Env]
|
|
|
|
lazy val irwin: lila.irwin.Env = wire[lila.irwin.Env]
|
|
|
|
lazy val activity: lila.activity.Env = wire[lila.activity.Env]
|
|
|
|
lazy val relay: lila.relay.Env = wire[lila.relay.Env]
|
|
|
|
lazy val streamer: lila.streamer.Env = wire[lila.streamer.Env]
|
|
|
|
lazy val oAuth: lila.oauth.Env = wire[lila.oauth.Env]
|
|
|
|
lazy val bot: lila.bot.Env = wire[lila.bot.Env]
|
|
|
|
lazy val evalCache: lila.evalCache.Env = wire[lila.evalCache.Env]
|
|
|
|
lazy val rating: lila.rating.Env = wire[lila.rating.Env]
|
2020-04-29 10:31:34 -06:00
|
|
|
lazy val swiss: lila.swiss.Env = wire[lila.swiss.Env]
|
2019-12-13 07:30:20 -07:00
|
|
|
lazy val api: lila.api.Env = wire[lila.api.Env]
|
|
|
|
lazy val lilaCookie = wire[lila.common.LilaCookie]
|
2019-12-04 21:32:03 -07:00
|
|
|
|
2019-12-20 09:53:21 -07:00
|
|
|
val env: lila.app.Env = {
|
2019-12-05 19:31:59 -07:00
|
|
|
val c = lila.common.Chronometer.sync(wire[lila.app.Env])
|
|
|
|
lila.log("boot").info(s"Loaded lila modules in ${c.showDuration}")
|
|
|
|
c.result
|
|
|
|
}
|
2019-12-04 21:46:58 -07:00
|
|
|
|
2019-12-20 09:53:29 -07:00
|
|
|
templating.Environment setEnv env
|
|
|
|
|
|
|
|
// free memory for reload workflow
|
2020-08-01 02:15:00 -06:00
|
|
|
if (mode == Mode.Dev)
|
2019-12-27 11:31:06 -07:00
|
|
|
Lilakka.shutdown(shutdown, _.PhaseServiceStop, "Freeing dev memory") { () =>
|
|
|
|
Future {
|
|
|
|
templating.Environment.destroy()
|
|
|
|
lila.common.Bus.destroy()
|
|
|
|
lila.mon.destroy()
|
|
|
|
}
|
2019-12-26 18:28:17 -07:00
|
|
|
}
|
2013-04-10 04:17:58 -06:00
|
|
|
}
|