Compare commits

..
2 Commits
4 changed files with 25 additions and 11 deletions

No files matched your search

+11 -6
View File
@@ -14,25 +14,30 @@ Needs Go 1.25+ and Podman or Docker. Put a `.env` in the repo root (variables in
podman-compose up -d db # or: docker compose up -d db podman-compose up -d db # or: docker compose up -d db
cd server cd server
make migrate make migrate
make dev # admin at http://localhost:3000/utils make dev # http://localhost:3000: the game (once built, below); /utils: the admin
``` ```
After pulling changes, run `make migrate` again before starting the server: it applies new After pulling changes or editing `server/config/game.json`, run `make migrate` again before
migrations and syncs the tools with `config/game.json` (the server alone doesn't). starting the server: it applies new migrations and syncs the tools and prices with the
config (the server alone doesn't).
## Defold client ## Defold client
Needs Java 21+. The Makefile downloads Defold's command-line builder (`bob.jar`). The editor Needs Java 21+. The Makefile downloads Defold's command-line builder (`bob.jar`). The editor
is optional: https://defold.com/download/ is optional: https://defold.com/download/
With the server running:
```bash ```bash
cd client cd client
make run # desktop build, plays against http://localhost:3000 make run # desktop build, plays against http://localhost:3000
make web && make serve-web # browser build: open http://localhost:8080 make web # browser build into dist/web/MoonMiners/
``` ```
The server serves the browser build at http://localhost:3000 (from
`client/dist/web/MoonMiners`, or `MM_WEB_DIR`). It looks for the build when it starts:
after the first `make web`, restart the server; later builds only need a page reload.
Without a build, `/` goes to the admin. The desktop and browser games keep separate saved
players.
## Deploy ## Deploy
Dokploy, Docker Compose with `docker-compose.prod.yml`. Details in `server/README.md`. Dokploy, Docker Compose with `docker-compose.prod.yml`. Details in `server/README.md`.
+2 -1
View File
@@ -31,7 +31,8 @@ build: $(BOB) .internal/lib/dependencies.json
# Web build (WebAssembly) into dist/web/MoonMiners/ (index.html + engine + archive). Release # Web build (WebAssembly) into dist/web/MoonMiners/ (index.html + engine + archive). Release
# by default; WEB_VARIANT=debug keeps logs and the test hook (window.mmTestQueue). # by default; WEB_VARIANT=debug keeps logs and the test hook (window.mmTestQueue).
# `make serve-web` serves it on :8080 with /api and /static proxied to UPSTREAM. # The game server serves it at / (server.go, MM_WEB_DIR); `make serve-web` serves it on :8080
# with /api and /static proxied to UPSTREAM (a test server).
WEB_VARIANT ?= release WEB_VARIANT ?= release
UPSTREAM ?= http://localhost:3000 UPSTREAM ?= http://localhost:3000
WEB_PORT ?= 8080 WEB_PORT ?= 8080
+5 -3
View File
@@ -43,7 +43,8 @@ every interface), `DB_SSLMODE` (default `disable`), `ADMIN_PASSWORD` (the
password of the admin pages, `/utils`; unset: they're locked), `ADMIN_USER_IDS` password of the admin pages, `/utils`; unset: they're locked), `ADMIN_USER_IDS`
(comma-separated player ids that are admins in the game API: `state.admin`, `admin-grant`, (comma-separated player ids that are admins in the game API: `state.admin`, `admin-grant`,
saving moon settings), `MM_DEV=1` (reload templates and static files from disk; no admin saving moon settings), `MM_DEV=1` (reload templates and static files from disk; no admin
login, and every player is an admin), `TRUST_PROXY=1` (behind a reverse proxy: rate-limit by login, and every player is an admin), `MM_WEB_DIR` (the browser build served at `/`; default `../client/dist/web/MoonMiners`,
none there: `/` redirects to `/utils`), `TRUST_PROXY=1` (behind a reverse proxy: rate-limit by
the last `X-Forwarded-For` address instead of the connection's, and mark the admin cookie the last `X-Forwarded-For` address instead of the connection's, and mark the admin cookie
Secure on HTTPS; new players are limited to 10 a minute per IP). Secure on HTTPS; new players are limited to 10 a minute per IP).
@@ -58,8 +59,9 @@ Secure on HTTPS; new players are limited to 10 a minute per IP).
make migrate make migrate
``` ```
3. Run the server (`MM_DEV=1`: no admin login) and open the admin at 3. Run the server (`MM_DEV=1`: no admin login). The admin is at
http://localhost:3000/utils, or point the Defold client at it: http://localhost:3000/utils; the game at http://localhost:3000 once the client's
`make web` has built it (then restart the server), or run the desktop client against it:
```bash ```bash
make dev make dev
+7 -1
View File
@@ -68,10 +68,16 @@ func serve(ctx context.Context) error {
mux.HandleFunc("GET /favicon.ico", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("GET /favicon.ico", func(w http.ResponseWriter, r *http.Request) {
http.ServeFileFS(w, r, s.static, "favicon.ico") http.ServeFileFS(w, r, s.static, "favicon.ico")
}) })
// A Defold web build will be served here later; for now the admin. // The game's web build (client: make web) at /, from MM_WEB_DIR (default: the client's
// dist/web/MoonMiners beside this checkout); without one, / goes to the admin.
webDir := env("MM_WEB_DIR", "../client/dist/web/MoonMiners")
if st, err := os.Stat(webDir + "/index.html"); err == nil && !st.IsDir() {
mux.Handle("GET /", http.FileServerFS(os.DirFS(webDir)))
} else {
mux.HandleFunc("GET /{$}", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("GET /{$}", func(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/utils", http.StatusSeeOther) http.Redirect(w, r, "/utils", http.StatusSeeOther)
}) })
}
mux.HandleFunc("GET /utils/login", s.handleLoginPage) mux.HandleFunc("GET /utils/login", s.handleLoginPage)
mux.HandleFunc("POST /utils/login", s.handleLogin) mux.HandleFunc("POST /utils/login", s.handleLogin)
mux.HandleFunc("POST /utils/logout", s.handleLogout) mux.HandleFunc("POST /utils/logout", s.handleLogout)