Phone UI and touch precision overhaul, proxy fixes, Orbital Uplink, four new maps

Phone panels (reviewed + QA'd, matrix of 22 layouts with real taps/bounding boxes):
- selected-tower action bar over the board (Upgrade/Sell/Target/close), info panel
  updated in place so taps are never lost, scrollable palette for 7+ towers,
  overlays with pinned footers (Help "Got it", Play solo, Join always visible),
  tappable room chip to invite, reduced-motion/contrast/forced-colors fixes,
  paused state, partner cursor labels, bigger level pips and owner flags
- touch input rewritten around "pointerdown commits nothing": pinch never builds,
  10px tap slop, palm-proof pinch, long-press pings with any tool armed, nudge
  arrows for precise placement, hotkey repeat guard, proportional wheel zoom
- new e2e: select/sell, info-panel stability, UI states, touch precision;
  camera unit tests

Proxy/server (reproduced against real nginx 1.26 with NPM v2.16 config):
- Origin check works when the proxy drops a non-default port, TRUSTED_PROXIES for
  proxies on global IPv6/CGNAT addresses, service worker no longer serves nginx's
  502 page, DEPLOY.md corrected (NPM default read timeout is 90 s, Advanced-tab
  limits, path-prefix, cookie size, per-IP cap behaviour)

Content:
- Orbital Uplink: 4-level endgame tower (450 + 500/800/1200 credits): piercing
  armour-ignoring beam, blast and lingering slow, ground+air, range 11-14;
  glyph, beam effect, sound, help text, unit tests
- Maps: The Canyon, Archipelago, Fortress, Pinwheel (7 maps total)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tb8pW2KAN4oFkh1aK1BfD8
This commit is contained in:
Claude 2026-10-10 18:03:24 +00:00
parent dad0382e10
commit a5bd09d505
22 changed files with 2423 additions and 405 deletions

View file

@ -31,19 +31,50 @@ room and send the invite link (or the 4-letter code) to a friend.
Solo only: you can also just open `public/index.html` in a browser (the built-in synth music plays; your own tracks
need the server, because browsers block loading the track list from a `file://` page).
Environment variables: `PORT` (8080), `HOST` (`::`, dual-stack IPv4 + IPv6), `TRUST_PROXY`, `ALLOWED_ORIGINS`,
`MAX_CONN_PER_IP`, `GRACE_MS`. Full reference and troubleshooting: [docs/DEPLOY.md](docs/DEPLOY.md).
Environment variables: `PORT` (8080), `HOST` (`::`, dual-stack IPv4 + IPv6), `TRUST_PROXY`, `TRUSTED_PROXIES`,
`ALLOWED_ORIGINS`, `MAX_CONN_PER_IP`, `GRACE_MS`. Full reference and troubleshooting: [docs/DEPLOY.md](docs/DEPLOY.md).
## Setup guide: Debian 13 LXC behind nginx Proxy Manager
The game is one small Node process (static files + a WebSocket at `/ws`), so the proxy only has to forward HTTP and
WebSockets. Nothing is stored on disk; a restart ends running games.
What was tested and what was not: the proxy side was run against a real nginx 1.26.3 loaded with the configuration that
nginx Proxy Manager (NPM) v2.16.0 generates, not against the NPM application itself, Let's Encrypt, a Proxmox LXC or a
phone. The details and the observations behind every statement below are in [docs/DEPLOY.md](docs/DEPLOY.md).
**You need first**
* A Debian 13 LXC (any Linux with Node 18+ works) with an IP address that NPM can reach, for example `192.168.1.50`
(`ip -br a` inside the container shows it).
* NPM already running, and a DNS name for the game (here `game.example.com`) that points at it. NPM's Let's Encrypt
request needs the name to resolve to your public address and ports 80 and 443 forwarded to NPM; that part is NPM's
own setup, see its documentation.
### 1. Install it in the LXC (as root)
```bash
apt update && apt install -y nodejs npm git # Debian 13 ships Node 20, which is plenty (18+ works)
apt update && apt install -y nodejs npm git rsync # Debian 13 ships Node 20, which is plenty (18+ works)
```
Get the code into `/opt/netwall`, either **(a)** copied from your own computer (no keys needed on the LXC; run this in
the repository folder; `rsync` is needed on both sides):
```bash
rsync -a --exclude node_modules --exclude test --exclude .git ./ root@192.168.1.50:/opt/netwall/
```
or **(b)** cloned inside the LXC. That only works if the LXC may read the repository: for a private one create a key in
the LXC (`ssh-keygen -t ed25519`) and add the public key (`~/.ssh/id_ed25519.pub`) to the repository as a read-only
deploy key on your git server first (not tested here):
```bash
git clone ssh://forgejo@int.git.vanvikinternet.no/jvanvik/towerdef.git /opt/netwall
```
Then, in the LXC:
```bash
cd /opt/netwall && npm install --omit=dev # only "ws"
useradd --system --home-dir /opt/netwall --shell /usr/sbin/nologin netwall
@ -56,28 +87,46 @@ journalctl -u netwall -f # live log
```
The service listens on `[::]:8080` (dual stack) and runs as the unprivileged `netwall` user. Change `PORT`, `HOST`,
`TRUST_PROXY` or `ALLOWED_ORIGINS` in the unit's `Environment=` lines (or `systemctl edit netwall`) and
`TRUST_PROXY`, `TRUSTED_PROXIES` or `ALLOWED_ORIGINS` in the unit's `Environment=` lines (or `systemctl edit netwall`) and
`systemctl restart netwall`. If the unit fails with a sandboxing error inside an unprivileged Proxmox container,
comment out the line it names (see the notes in `deploy/netwall.service`).
comment out the line it names (see the notes in `deploy/netwall.service`). Before going on, check from the NPM host that
it can reach the game: `curl http://192.168.1.50:8080/healthz` must print `ok`.
### 2. Add a Proxy Host in nginx Proxy Manager
**Hosts > Proxy Hosts > Add Proxy Host**
**Hosts > Proxy Hosts > Add Proxy Host** (labels as in NPM v2.16.0)
| Tab / field | Value |
|---|---|
| Details: Domain Names | `game.example.com` (your name for it) |
| Details: Scheme | `http` |
| Details: Forward Hostname / IP | the LXC's IP address |
| Details: Forward Hostname / IP | the LXC's IP address (`192.168.1.50`), not `127.0.0.1` |
| Details: Forward Port | `8080` |
| Details: Cache Assets | **off** |
| Details: **Websockets Support** | **on** (without it the page loads but co-op cannot connect) |
| Details: **Websockets Support** | **on** (without it the page loads but co-op cannot connect: HTTP 426 on `/ws`) |
| Custom Locations | leave empty |
| SSL: Certificate | Request a new SSL Certificate (Let's Encrypt), **Force SSL** on, **HTTP/2** on |
| Advanced (optional) | `proxy_read_timeout 3600s;` and `proxy_send_timeout 3600s;` for very long idle games |
| Advanced (the gear icon) | nothing needed (NPM's default 90 s timeouts are fine: a joined game streams data all the time) |
NPM passes the original `Host` header through, which is what the server's WebSocket origin check expects, so no
extra configuration is needed. If the server log ever shows `refused websocket ... does not match Host` (HTTP 403 on
the upgrade), set `ALLOWED_ORIGINS=https://game.example.com` in the unit and restart.
On the standard ports (80/443) that is all: NPM sends the public name as `Host`, which is what the server's WebSocket
origin check expects. **If you publish NPM on another port** (for example `https://game.example.com:8443`): NPM drops the
port from `Host`; the server accepts that from a proxy on a private address. If co-op still answers 403 (the log says
`refused websocket ... Origin "https://game.example.com:8443" does not match Host`), the proxy reaches the game from a
non-private address (global IPv6, Tailscale): set `TRUSTED_PROXIES=<that address>`, or
`ALLOWED_ORIGINS=https://game.example.com:8443` (**with the port**) in the unit and restart. The Advanced tab cannot
add `X-Forwarded-Host` (NPM ignores it there), so do not follow advice that says it can.
**If something does not work.** The lobby only ever says "Could not reach the game server."; the real reason is the
HTTP status of the `/ws` request in the browser's developer tools (Network or Console) and the server log
(`journalctl -u netwall -f`):
| Status of `/ws` | Meaning |
|---|---|
| 426 | Websockets Support is off in the Proxy Host |
| 403 | Origin check, see the paragraph above and `docs/DEPLOY.md` section 9 |
| 429 | too many sockets from one address; usually the proxy is not recognised as a proxy (`TRUSTED_PROXIES`) |
| 400 `Request Header Or Cookie Too Large` | big cookies from another app on the same domain; Advanced box: `large_client_header_buffers 4 16k;` |
| 502 | NPM cannot reach `192.168.1.50:8080`: service down, wrong IP or port, or a firewall |
### 3. IPv6 (optional)
@ -98,35 +147,38 @@ Lock the LXC down so that only the proxy can reach port 8080 (firewall example i
### 5. Update
```bash
cd /opt/netwall && git pull && npm install --omit=dev && systemctl restart netwall
```
If you cloned it: `cd /opt/netwall && git pull && npm install --omit=dev && systemctl restart netwall`. If you copied it
with rsync: run the same `rsync` again, then `cd /opt/netwall && npm install --omit=dev && systemctl restart netwall`.
Running games end with the restart (players see the room is gone and can create a new one).
Under a path prefix such as `https://example.com/netwall/`, the proxy must strip the prefix; see section 7 of
[docs/DEPLOY.md](docs/DEPLOY.md). A dedicated sub-domain is simpler.
[docs/DEPLOY.md](docs/DEPLOY.md) (in NPM: a Custom Location `/netwall/` with Forward Hostname `192.168.1.50/`, both with
the trailing slash). A dedicated sub-domain is simpler.
## How to play
| | |
|---|---|
| **Goal** | Survive 30 waves (then keep going in endless mode). Every packet that reaches the server costs integrity. |
| **Goal** | Survive 30 waves (then keep going in endless mode) on one of seven maps. Every packet that reaches the server costs integrity. |
| **Firewall** (5) | A wall. Packets path-find around it; the route preview shows how much longer it makes their trip. |
| **Packet Filter** | Fast and cheap. Weak against armour. |
| **IDS Sniper** | Long range, hits hard, slow. The answer to armour and bosses. |
| **Flood Mortar** | Splash damage on ground swarms. Cannot hit flyers. |
| **Rate Limiter** | Slows everything in range. Rootkits resist it. |
| **Router Arc** | Chain lightning between nearby packets. |
| **Orbital Uplink** | The endgame weapon: a piercing beam that ignores armour, hits ground and air, blasts and slows around the target and reaches across most of the map. Very expensive to buy and to upgrade (4 levels). |
| **Spoofed packets** | Fly straight over your maze: keep some anti-air. |
| **Credits** | From kills and cleared waves. Upgrade turrets to level 3; selling returns 70% (walls 100%). |
| **Credits** | From kills and cleared waves. Upgrade turrets (3 levels, 4 for the Uplink); selling returns 70% (walls 100%). |
Controls, desktop: click to build, drag to paint walls, right-click cancels, `1`-`6` pick a tower, `Space` next wave,
Controls, desktop: click to build, drag to paint walls, right-click cancels, `1`-`7` pick a tower, `Space` next wave,
`U` upgrade, `X` sell, `T` change targeting, `P` pause, `F` speed, `A` auto-waves, `M` mute, wheel zoom, Alt+click pings.
Controls, touch: tap a tower type, tap the map to preview (the new route is drawn), tap the check mark (or the same cell
again) to build. Walls paint as you drag. Two fingers pan and zoom; long-press pings your partner. In portrait the board
turns 90 degrees so the cells stay big.
Controls, touch: tap a tower type, tap the map to preview (the new route is drawn), nudge the preview with the arrow
buttons if you missed the cell, then tap the check mark to build. A tap only ever acts when the finger lifts, so a pinch
never builds by accident. Walls paint as you drag. Two fingers pan and zoom; long-press pings your partner with any tool
armed. Tap a tower to get an action bar over the board (Upgrade, Sell, Target). In portrait the board turns 90 degrees
when that makes the cells bigger.
## Music
@ -170,7 +222,7 @@ reconnects automatically and resumes the same seat for a minute.
npm test # rules + server: placement validation, route sealing, corner cutting, targeting, waves, economy,
# protocol, rooms, reconnects, security checks, static files, dual stack
npm run e2e # real browsers: desktop, phone touch (tap-to-build, drag-paint, pinch, long-press), end screens,
# two-browser co-op incl. reconnect, and a 14-size layout matrix
# two-browser co-op incl. reconnect, and a 22-layout matrix (phones, tablets, desktop, thumb reach of every control)
```
`npm run e2e` drives Chromium through Playwright (a devDependency). Install the browser once with