Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,14 @@ jobs:
cat > "$RUNNER_TEMP/notes.md" <<EOF
## Host the bitmap game

With Docker or Podman, on linux/amd64 or linux/arm64:
With Docker or Podman, on linux/amd64 or linux/arm64, one command downloads and starts it:

docker run -d --name rylween -p 127.0.0.1:8081:8081 -v rylween-data:/data -e RYLWEEN_AUTH_SECURE_COOKIES=false $IMAGE:$RELEASE
docker run --rm -it --name rylween -p 127.0.0.1:8081:8081 -v rylween-data:/data -e RYLWEEN_AUTH_SECURE_COOKIES=false $IMAGE:$RELEASE

Then open http://127.0.0.1:8081/ and register an account. The sysop account's generated password is in
\`/data/auth/admin-password.txt\`: \`docker exec rylween cat /data/auth/admin-password.txt\`. Saves,
accounts, and logs live on the \`/data\` volume. Behind an HTTPS proxy, leave out the secure cookies setting.
Once it is up it prints the link to open, http://localhost:8081/login, where you register an account.
Ctrl-C stops it. The sysop account's generated password is in \`/data/auth/admin-password.txt\`:
\`docker exec rylween cat /data/auth/admin-password.txt\`. Saves, accounts, and logs live on the
\`/data\` volume. Behind an HTTPS proxy, leave out the secure cookies setting.

Or download \`compose.yaml\` and run \`docker compose up -d\` next to it. Its header lists the settings.

Expand Down
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,32 @@ from [`game/src/main/resources/bitmap/assets`](game/src/main/resources/bitmap/as

## Running The Game

### With Only Docker or Podman

Each release is published as an image, so a machine with Docker or Podman and
internet access needs nothing else: no checkout, no git, no JDK. One command
downloads the latest release and starts the bitmap game:

```sh
docker run --rm -it --pull always --name rylween -p 127.0.0.1:8081:8081 -v rylween-data:/data -e RYLWEEN_AUTH_SECURE_COOKIES=false ghcr.io/lagergren/rylween
```

With Podman, write `podman` for `docker`. Once the server is up it prints the
link to open, `http://localhost:8081/login`, where you register an account.
Ctrl-C stops it. Saves and accounts stay on the `rylween-data` volume, and the
next run picks up any newer release. The image expects HTTPS by default;
`RYLWEEN_AUTH_SECURE_COOKIES=false` lets logins work over plain HTTP on this
machine. On another port, say 9000, publish `-p 127.0.0.1:9000:8081` and add
`-e RYLWEEN_PUBLIC_URL=http://localhost:9000` so the printed link matches.

On a Mac, Homebrew installs either one. `brew install docker` alone installs
only the client, without the engine that runs the containers:

```sh
brew install podman && podman machine init --now # Podman, and the Linux VM it runs containers in
brew install --cask docker # or Docker Desktop; start it once from Applications
```

### On Your Network: `./deploy.sh`

```sh
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ private data class BitmapWebConfig(
val debugSecrets: Boolean,
val mapTiles: Int,
val tileSize: Int,
/** Where players reach the server, ending in `/`: what a link to it starts with. */
val publicUrl: String,
) {
val saveDir: File get() = dataDir.resolve("saves")
val logDir: File get() = dataDir.resolve("logs/runtime-bitmap-web")
Expand All @@ -165,6 +167,9 @@ private data class BitmapWebConfig(
val worldSaveFile: File get() = saveFile ?: saveDir.resolve("world.rsave")
val authRequired: Boolean get() = userId == null

/** The link to play: the login page, or the game itself in a --user session, which needs no login. */
val entryUrl: String get() = publicUrl + if (authRequired) "login" else ""

fun ensureDataDirectories() {
Files.createDirectories(saveDir.toPath())
Files.createDirectories(logDir.toPath())
Expand Down Expand Up @@ -192,6 +197,7 @@ private data class BitmapWebConfig(
var debugSecrets = optionalEnv("RYLWEEN_BITMAP_DEBUG_SECRETS") == "true"
var mapTiles = envOrDefault("RYLWEEN_BITMAP_MAP_TILES", DEFAULT_BITMAP_VIEWPORT_TILES.toString()).toInt()
var tileSize = envOrDefault("RYLWEEN_BITMAP_TILE_SIZE", DEFAULT_BITMAP_TILE_SIZE.toString()).toInt()
var publicUrl = optionalEnv("RYLWEEN_PUBLIC_URL")
var index = 0
while (index < args.size) {
when (val arg = args[index]) {
Expand Down Expand Up @@ -259,6 +265,10 @@ private data class BitmapWebConfig(
index += 1
tileSize = requiredValue(args, index, arg).toInt()
}
"--public-url" -> {
index += 1
publicUrl = requiredValue(args, index, arg)
}
"--help", "-h" -> {
printUsage()
exitProcess(0)
Expand All @@ -283,9 +293,27 @@ private data class BitmapWebConfig(
debugSecrets,
mapTiles,
tileSize,
publicUrl?.let { url -> url.trimEnd('/') + "/" } ?: defaultPublicUrl(host, port),
)
}

/**
* The address to advertise when none is given: the bind address, where a wildcard means this machine. In a
* container that is localhost with the same port, as the documented `docker run -p 127.0.0.1:8081:8081` maps it.
*/
private fun defaultPublicUrl(
host: String,
port: Int,
): String {
val reachableHost =
when {
host == "0.0.0.0" || host == "::" -> "localhost"
':' in host -> "[$host]"
else -> host
}
return "http://$reachableHost:$port/"
}

private fun envOrDefault(
key: String,
defaultValue: String,
Expand Down Expand Up @@ -318,14 +346,16 @@ private data class BitmapWebConfig(
private fun printUsage() {
println(
"""
Usage: rylween-bitmap-web [--host HOST] [--port PORT] [--data DIR] [--state SLUG] [--bundle FILE] [--user ID] [--load FILE] [--save FILE] [--account NAME --password PASSWORD [--email EMAIL]] [--secure-cookies] [--title|--no-title] [--debug-secrets] [--map-tiles N] [--tile-size PX]
Usage: rylween-bitmap-web [--host HOST] [--port PORT] [--data DIR] [--state SLUG] [--bundle FILE] [--user ID] [--load FILE] [--save FILE] [--account NAME --password PASSWORD [--email EMAIL]] [--secure-cookies] [--title|--no-title] [--debug-secrets] [--map-tiles N] [--tile-size PX] [--public-url URL]

The bitmap runtime uses the embedded :game bundle by default. --bundle can point
at build/compiled/rylween-bundle.json to exercise an emitted artifact instead.
Authenticated saves and logs live under --data. --user keeps the local dev bypass.
--account/--password ensures an auth account exists before the server starts.
--secure-cookies adds the Secure cookie attribute for HTTPS deployments.
--debug-secrets enables hidden manual-test wilderness commands, including M for the annotated full map.
--public-url (RYLWEEN_PUBLIC_URL) is the address players open, which the server prints once it is up.
It defaults to the bind address, with a wildcard read as localhost.
Map defaults: ${DEFAULT_BITMAP_VIEWPORT_TILES}x${DEFAULT_BITMAP_VIEWPORT_TILES} tiles at ${DEFAULT_BITMAP_TILE_SIZE}px.
""".trimIndent(),
)
Expand Down Expand Up @@ -399,8 +429,9 @@ private class BitmapWebServer(
"devUser=${config.userId.orEmpty()} load=${config.loadFile?.path.orEmpty()} " +
"save=${config.worldSaveFile.path} title=${config.showTitleMenu} " +
"debugSecrets=${config.debugSecrets} mapTiles=${config.mapTiles} tileSize=${config.tileSize} " +
"bundle=${game.source}",
"bundle=${game.source} url=${config.entryUrl}",
)
announceEntry(game.bundle.content.let { content -> content.strings.value(content.universe.nameString) }, config.entryUrl)
while (!serverSocket.isClosed) {
val socket = serverSocket.accept()
executor.execute { handleClient(socket) }
Expand Down Expand Up @@ -1108,6 +1139,25 @@ private fun streamServerLog(line: String) {
println("[rylween-bitmap] $line")
}

/**
* Tells whoever started the server where to play, once it accepts connections. The link has a line of its own, so
* terminals make all of it, and nothing more, clickable.
*/
private fun announceEntry(
gameName: String,
url: String,
) {
println(
"""
|
|$gameName $rylweenVersion is up. To play, open:
|
| $url
|
""".trimMargin(),
)
}

private fun serverLogValue(value: String): String = "\"" + value.replace("\\", "\\\\").replace("\"", "\\\"") + "\""

private fun String?.toBitmapFacingOrDefault(): BitmapWildernessFacing =
Expand Down
Loading