Skip to content

Commit

Permalink
Merge branch 'master' into report-reason-no-store
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Sep 23, 2024
2 parents 889bfde + 8c09ce1 commit 9837dd5
Show file tree
Hide file tree
Showing 151 changed files with 1,175 additions and 831 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
- 'project/**'
- 'translation/**'
- 'build.sbt'
- 'lila'
- 'lila.sh'
- 'conf/application.conf.default'
- '.sbtopts.default'
branches-ignore:
Expand All @@ -24,7 +24,7 @@ on:
- 'project/**'
- 'translation/source/**'
- 'build.sbt'
- 'lila'
- 'lila.sh'
- 'conf/application.conf.default'
- '.sbtopts.default'
env:
Expand All @@ -41,7 +41,7 @@ jobs:
java-version: 21
cache: sbt
- run: TZ=UTC git log -1 --date=iso-strict-local --pretty='format:app.version.commit = "%H"%napp.version.date = "%ad"%napp.version.message = """%s"""%n' | tee conf/version.conf
- run: ./lila -Depoll=true "test;stage"
- run: ./lila.sh -Depoll=true "test;stage"
- run: cp LICENSE COPYING.md README.md target/universal/stage && git log -n 1 --pretty=oneline > target/universal/stage/commit.txt
- run: cd target/universal/stage && tar --zstd -cvpf ../../../lila-3.0.tar.zst . && cd -
env:
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ RUNNING_PID
# VSCode auto-generated files
.vscode/

# VSCode workspaces
*.code-workspace

# IntelliJ auto-generated files
.idea

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Use [GitHub issues](https://github.com/lichess-org/lila/issues) for bug reports
## Installation

```
./lila # thin wrapper around sbt
./lila.sh # thin wrapper around sbt
run
```

Expand Down
1 change: 1 addition & 0 deletions app/Env.scala
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ given ConfigLoader[NetConfig] = ConfigLoader(config =>
siteName = get[String]("site.name"),
socketDomains = get[List[String]]("socket.domains"),
socketAlts = get[List[String]]("socket.alts"),
socketTest = get[Boolean]("socket.test"),
crawlable = get[Boolean]("crawlable"),
rateLimit = get[RateLimit]("ratelimit"),
email = get[EmailAddress]("email"),
Expand Down
13 changes: 13 additions & 0 deletions app/controllers/Dev.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package controllers

import lila.app.*
import play.api.libs.json.*

final class Dev(env: Env) extends LilaController(env):

Expand Down Expand Up @@ -76,3 +77,15 @@ final class Dev(env: Env) extends LilaController(env):
private def runCommand(command: String)(using Me): Fu[String] =
env.mod.logApi.cli(command) >>
env.api.cli(command.split(" ").toList)

def socketTestResult = AuthBody(parse.json) { ctx ?=> me ?=>
ctx.body.body
.validate[JsArray]
.fold(
err => BadRequest(Json.obj("error" -> err.toString)),
results =>
env.api.socketTestResult
.put(Json.obj(me.userId.toString -> results))
.inject(jsonOkResult)
)
}
34 changes: 14 additions & 20 deletions app/controllers/Game.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,20 @@ final class Game(env: Env, apiC: => Api) extends LilaController(env):
exportGame(id.gameId)

private[controllers] def exportGame(gameId: GameId)(using Context): Fu[Result] =
env.round.proxyRepo.gameIfPresent(gameId).orElse(env.game.gameRepo.game(gameId)).flatMap {
case None => NotFound
case Some(game) =>
val config = GameApiV2.OneConfig(
format = if HTTPRequest.acceptsJson(req) then GameApiV2.Format.JSON else GameApiV2.Format.PGN,
imported = getBool("imported"),
flags = requestPgnFlags(extended = true),
playerFile = get("players")
)
env.api.gameApiV2
.exportOne(game, config)
.flatMap: content =>
env.api.gameApiV2
.filename(game, config.format)
.map: filename =>
Ok(content)
.pipe(asAttachment(filename))
.withHeaders(headersForApiOrApp*)
.as(gameContentType(config))
}
Found(env.round.proxyRepo.gameIfPresent(gameId).orElse(env.game.gameRepo.game(gameId))): game =>
val config = GameApiV2.OneConfig(
format = if HTTPRequest.acceptsJson(req) then GameApiV2.Format.JSON else GameApiV2.Format.PGN,
imported = getBool("imported"),
flags = requestPgnFlags(extended = true),
playerFile = get("players")
)
for
content <- env.api.gameApiV2.exportOne(game, config)
filename <- env.api.gameApiV2.filename(game, config.format)
yield Ok(content)
.pipe(asAttachment(filename))
.withHeaders(headersForApiOrApp*)
.as(gameContentType(config))

def exportByUser(username: UserStr) = OpenOrScoped()(handleExport(username))
def apiExportByUser(username: UserStr) = AnonOrScoped()(handleExport(username))
Expand Down
10 changes: 6 additions & 4 deletions app/views/base/page.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import scalalib.StringUtils.escapeHtmlRaw
import lila.app.UiEnv.{ *, given }
import lila.common.String.html.safeJsonValue
import lila.ui.RenderedPage
import lila.api.SocketTest

object page:

Expand Down Expand Up @@ -110,10 +111,11 @@ object page:
dataDev,
dataVapid := (ctx.isAuth && env.security.lilaCookie.isRememberMe(ctx.req))
.option(env.push.vapidPublicKey),
dataUser := ctx.userId,
dataSoundSet := pref.currentSoundSet.toString,
dataSocketDomains,
pref.isUsingAltSocket.option(dataSocketAlts),
dataUser := ctx.userId,
dataSoundSet := pref.currentSoundSet.toString,
attr("data-socket-domains") := SocketTest.socketEndpoints(netConfig).mkString(","),
attr("data-socket-test-user") := SocketTest.isUserInTestBucket(netConfig),
attr("data-socket-test-running") := netConfig.socketTest,
dataAssetUrl,
dataAssetVersion := assetVersion,
dataNonce := ctx.nonce.ifTrue(sameAssetDomain).map(_.value),
Expand Down
17 changes: 16 additions & 1 deletion bin/git-hooks/pre-commit
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
#!/bin/sh

pnpm lint-staged
# Short circuit lint-staged to avoid waiting on node when not needed. Even
# when no files match, and we execute lint-stage directly, it still delays
# the commit by .15s or so, which is annoying.
if \git --no-pager diff-index -z --name-only --no-renames --cached HEAD | \
\grep -qzE '\.(json|scss|ts)$'; then
# NOTE! grep must be kept in sync with lint-staged in package.json!

LINT_STAGED="$(dirname -- "$0")/../../node_modules/.bin/lint-staged"

# pnpm or npx adds .25s overhead. exec further reduces overhead.
if [ -x "$LINT_STAGED" ]; then
exec "$LINT_STAGED"
else
exec pnpm lint-staged
fi
fi
2 changes: 1 addition & 1 deletion bin/trans-dump.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function keyListFrom(name: string): KeyList {
};
}

const dbCode = (obj: KeyList) => ` object ${obj.name}:\n${obj.code}`
const dbCode = (obj: KeyList) => ` object ${obj.name}:\n${obj.code}`;

Promise.all(dbs.map(keyListFrom)).then(objs => {
const code = `// Generated with bin/trans-dump.ts
Expand Down
1 change: 1 addition & 0 deletions conf/base.conf
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ net {
domain = "localhost:9663"
socket.domains = ["localhost:9664"]
socket.alts = []
socket.test = false
asset.domain = ${net.domain}
asset.base_url = "http://"${net.asset.domain}
asset.base_url_internal = ${net.asset.base_url}
Expand Down
2 changes: 2 additions & 0 deletions conf/routes
Original file line number Diff line number Diff line change
Expand Up @@ -871,6 +871,8 @@ POST /dev/cli controllers.Dev.cliPost
GET /dev/settings controllers.Dev.settings
POST /dev/settings/:id controllers.Dev.settingsPost(id)

POST /dev/socket-test controllers.Dev.socketTestResult

# Push
POST /mobile/register/:platform/:deviceId controllers.Push.mobileRegister(platform, deviceId)
POST /mobile/unregister controllers.Push.mobileUnregister
Expand Down
File renamed without changes.
7 changes: 6 additions & 1 deletion modules/api/src/main/Env.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package lila.api

import akka.actor.*
import com.softwaremill.macwire.*
import com.softwaremill.tagging.*
import play.api.Mode

import lila.chat.{ GetLinkCheck, IsChatFresh }
Expand Down Expand Up @@ -58,7 +59,8 @@ final class Env(
webConfig: lila.web.WebConfig,
realPlayerApi: lila.web.RealPlayerApi,
bookmarkExists: lila.core.bookmark.BookmarkExists,
manifest: lila.web.AssetManifest
manifest: lila.web.AssetManifest,
yoloDb: lila.db.AsyncDb @@ lila.db.YoloDb // for socket test results
)(using val mode: Mode, scheduler: Scheduler)(using
Executor,
ActorSystem,
Expand Down Expand Up @@ -93,6 +95,9 @@ final class Env(

lazy val cli = wire[Cli]

lazy val socketTestResult =
SocketTestResult(yoloDb(lila.core.config.CollName("socket_test")).failingSilently())

private lazy val linkCheck = wire[LinkCheck]
lazy val chatFreshness = wire[ChatFreshness]

Expand Down
6 changes: 4 additions & 2 deletions modules/api/src/main/GameApiV2.scala
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ final class GameApiV2(
(game, initialFen, analysis) <- enrich(config.flags)(game)
formatted <- config.format match
case Format.JSON =>
toJson(game, initialFen, analysis, config, realPlayers = realPlayers).dmap(Json.stringify)
toJson(game, initialFen, analysis, config, realPlayers = realPlayers).map(Json.stringify)
case Format.PGN =>
PgnStr.raw(
pgnDump(
Expand All @@ -61,7 +61,7 @@ final class GameApiV2(
analysis,
config.flags,
realPlayers = realPlayers
).dmap(annotator.toPgnString)
).map(annotator.toPgnString)
)
yield formatted

Expand Down Expand Up @@ -345,6 +345,8 @@ final class GameApiV2(
.add("lastMove" -> flags.lastFen.option(g.lastMoveKeys))
.add("division" -> flags.division.option(division(g, initialFen)))
.add("bookmarked" -> bookmarked)
.add("import" -> g.pgnImport.map: i =>
Json.obj().add("date" -> i.date))

private def gameLightUsers(game: Game): Future[ByColor[(lila.core.game.Player, Option[LightUser])]] =
game.players.traverse(_.userId.so(getLightUser)).dmap(game.players.zip(_))
Expand Down
22 changes: 22 additions & 0 deletions modules/api/src/main/SocketTestResult.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package lila.api

import play.api.libs.json.*

import lila.db.JSON
import lila.core.config.NetConfig

final class SocketTestResult(resultsDb: lila.db.AsyncCollFailingSilently)(using Executor):
def put(results: JsObject) = resultsDb: coll =>
coll.insert.one(JSON.bdoc(results)).void

object SocketTest:

def isUserInTestBucket(net: NetConfig)(using ctx: Context) =
net.socketTest && ctx.pref.usingAltSocket.isEmpty && ctx.userId.exists(_.value.toList.sum % 128 == 0)

def socketEndpoints(net: NetConfig)(using ctx: Context): List[String] =
ctx.pref.usingAltSocket.match
case Some(true) => net.socketAlts
case Some(false) => net.socketDomains
case _ if isUserInTestBucket(net) => net.socketDomains.head :: net.socketAlts.headOption.toList
case _ => net.socketDomains
2 changes: 2 additions & 0 deletions modules/appeal/src/main/ui/AppealUi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ final class AppealUi(helpers: Helpers):
else if suspect.marks.boost || query.contains("boost") then trans.appeal.boosterMarked()
else if suspect.marks.troll || query.contains("shadowban") then trans.appeal.accountMuted()
else if suspect.marks.rankban || query.contains("rankban") then trans.appeal.excludedFromLeaderboards()
else if suspect.marks.arenaBan || query.contains("arenaban") then trans.appeal.arenaBanned()
else if suspect.marks.prizeban || query.contains("prizeban") then trans.appeal.prizeBanned()
else trans.appeal.cleanAllGood()

def renderUser(appeal: Appeal, userId: UserId, asMod: Boolean)(using Context) =
Expand Down
1 change: 1 addition & 0 deletions modules/core/src/main/config.scala
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ object config:
siteName: String,
socketDomains: List[String],
socketAlts: List[String],
socketTest: Boolean,
crawlable: Boolean,
rateLimit: RateLimit,
email: EmailAddress,
Expand Down
Loading

0 comments on commit 9837dd5

Please sign in to comment.