Skip to content
coko7Public

About

πŸŽ„ Advent-calendar photo game: a new picture unlocks every December day. Guess the local time it was taken, and closer guesses score more points. Built in Rust with axum, askama and SQLite.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

14 Commits

Folders and files

Repository files navigation

πŸŽ„ Advent of Time

An advent-calendar game for December: every day from the 1st to the 25th a new photo unlocks at 06:00 CET, and players guess the local time it was taken (HH:MM). The closer the guess, the more points.

Rust (axum, askama templates, SQLite via sqlx), server-rendered HTML, a few lines of JS for the countdown.

Run locally

cargo run                      # http://localhost:7878, data in ./data
cargo test

Open http://localhost:7878, not 127.0.0.1: POST requests whose Origin differs from AOT_BASE_URL are refused.

To play outside December, debug builds accept a fake clock (it keeps ticking from the given instant). Release builds ignore it:

AOT_FAKE_NOW=2026-12-05T10:00:00Z cargo run

Password accounts work without any setup. OAuth needs the AOT_<PROVIDER>_CLIENT_ID/SECRET variables (see below).

Configuration

All configuration comes from environment variables. See .env.example.

Variable Default
AOT_BASE_URL http://localhost:7878 Public URL. Used for OAuth redirects, the CSRF origin check, and Secure cookies when https
AOT_LISTEN 127.0.0.1:7878
AOT_DATA_DIR data Holds aot.db and pictures/
AOT_STATIC_DIR static
AOT_{DISCORD,GITHUB,MICROSOFT}_CLIENT_ID / _SECRET unset A provider appears on the login page only when both are set
AOT_FAKE_NOW unset Debug builds only

Edition dates and scoring rules are code, in src/game.rs (EDITIONS). Add an entry for each new year, and its name as edition.y<year> in every locales/*.toml.

Deploy (Docker + Traefik)

cp .env.example .env           # fill in domain, Traefik and OAuth values
mkdir -p data import && sudo chown 1000:1000 data
docker compose up -d --build

The container joins the external Traefik network named by TRAEFIK_NETWORK and gets a router for AOT_DOMAIN with TLS from TRAEFIK_CERTRESOLVER.

Update to a new release

docker compose exec aot aot backup /data/backups/pre-deploy-$(date +%F).db
git fetch --tags && git checkout v2.1.0
docker compose up -d --build     # the old container serves until the new image is built
docker compose logs --tail 20 aot

Migrations run at startup and sessions survive the restart. To roll back, check out the previous tag and rebuild. If that release changed the database schema, also restore the backup: stop the container, copy it over data/aot.db, delete aot.db-wal and aot.db-shm, start again. docker image prune clears old images.

OAuth redirect URIs

Register these at each provider (replace the domain):

  • Discord: https://<domain>/auth/oauth2-redirect/discord (scope identify)
  • GitHub: https://<domain>/auth/oauth2-redirect/github (no scope needed)
  • Microsoft: https://<domain>/auth/oauth2-redirect/microsoft (scope User.Read)

Provider tokens are used once at login to read the user id and are never stored.

Admin commands

Every admin task is a subcommand of the same binary. On the server, run it inside the live container with docker compose exec aot aot <command> (locally: cargo run -- <command>). It uses the same database and settings. Files the command reads go in ./import on the server, which the container sees read-only as /import.

Don't use docker compose run: the one-off container inherits the Traefik labels, and Traefik sends it part of the traffic while it runs.

Pictures

# Reads the answer from EXIF DateTimeOriginal, applies the rotation, shrinks to 1600px wide,
# writes a fresh JPEG with no metadata under a random name.
docker compose exec aot aot picture import /import/PXL_20250712_143205123.jpg \
    --day 1 --location "Lisbon, Portugal" --date-hint "July"

# No EXIF time, or the camera clock was wrong? Give the local time yourself:
docker compose exec aot aot picture import /import/x.jpg --day 2 --time 14:30

docker compose exec aot aot picture edit --day 1 --location "Somewhere in Portugal"
docker compose exec aot aot picture list

The import prints the EXIF time, timezone offset and GPS position (with a map link) so you can check them. A day whose picture is not imported yet shows "coming soon" once unlocked. Replacing a picture, or changing an answer, is refused once players have guessed it (picture edit --time ... --force overrides).

Users

docker compose exec aot aot user list
docker compose exec aot aot user hide <name>        # unhide <name>
docker compose exec aot aot user rename <name> <new-name>
docker compose exec aot aot user reset-password <name>   # prints a new random password

Import the 2025 edition (v1 data)

Run once, before the game opens, so returning players log in to their old account and keep their name. Empty the token fields of users.json first.

# with users.json, pictures.json and day-pics/ copied to ./import/v1 on the server
docker compose exec aot aot import-v1 \
    --users /import/v1/users.json --pictures /import/v1/pictures.json --images /import/v1/day-pics

Everything goes in one transaction: players, the 25 pictures (copied under random names) and all guesses. A player who already has a v2 account is reused, not duplicated. A second import is refused.

Backup

docker compose exec aot aot backup /data/backups/aot-$(date +%F).db

Writes a consistent snapshot while the server keeps running; it lands in ./data/backups on the host. From cron, add -T (no terminal) and escape %: docker compose exec -T aot aot backup /data/backups/aot-$(date +\%F).db.

Releases

Players see the version in the footer of every page, and the release notes at /changelog.

  • A PR with a change players can see adds a release at the top of changelog.toml and bumps version in Cargo.toml: minor for features (2.1.0), patch for fixes (2.0.1). A test fails if the two disagree.
  • Internal changes (refactors, logs, CI) get neither.
  • Once merged, CI tags the commit v<version>. Deploy tags, not main.

Until launch the version stays 2.0.0: visible changes add a note to the 2.0.0 release instead of bumping. At launch, move the tag to the deployed commit: git tag -f v2.0.0 <commit> && git push -f origin v2.0.0. The rules above apply from the first change after launch.

Adding a language

  1. Copy locales/en.toml to locales/<lang>.toml and translate it. A test fails if a key is missing.
  2. Add the file to CATALOG_SOURCES in src/i18n.rs.
  3. Add templates/about_<lang>.html and a branch for it in templates/about.html.
  4. Optionally add <lang> = [...] notes to the releases in changelog.toml. Without them, the English notes show.

The language is picked from the browser's Accept-Language header, falling back to English.

License

MIT. The bundled 0xProto Nerd Font has its own license in static/fonts/.

About

πŸŽ„ Advent-calendar photo game: a new picture unlocks every December day. Guess the local time it was taken, and closer guesses score more points. Built in Rust with axum, askama and SQLite.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages