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

@ -54,11 +54,44 @@ function peerIp(req) {
return normalizeIp(req.socket && req.socket.remoteAddress) || 'unknown';
}
// Does this request come from a proxy whose X-Forwarded-* headers we believe?
function isTrustedPeer(req, trustProxy) {
// TRUSTED_PROXIES: extra proxy addresses believed under TRUST_PROXY=auto, on top of the private ranges. The built-in
// "private" list misses a proxy that reaches the game over a global IPv6 address, Tailscale / CGNAT (100.64.0.0/10) or
// any other routable address. Accepts an array or a comma separated string of IPs and CIDRs, IPv4 or IPv6
// ("100.64.0.0/10, 2001:db8::6, 2001:db8:1::/48"). Returns null for an empty list, throws on a malformed entry (a
// typo must stop the start-up, not silently leave the proxy untrusted). The result has .has(ip) and .list.
function parseTrustedProxies(v) {
const items = Array.isArray(v) ? v : String(v === undefined || v === null ? '' : v).split(',');
const list = items.map((s) => String(s).trim()).filter(Boolean);
if (!list.length) return null;
const bl = new net.BlockList();
for (const item of list) {
const slash = item.indexOf('/');
const addr = normalizeIp(slash < 0 ? item : item.slice(0, slash));
const type = net.isIPv4(addr) ? 'ipv4' : net.isIPv6(addr) ? 'ipv6' : null;
const max = type === 'ipv4' ? 32 : 128;
const prefixText = slash < 0 ? null : item.slice(slash + 1);
const prefix = prefixText === null ? max : (/^\d{1,3}$/.test(prefixText) ? Number(prefixText) : NaN);
if (!type || !(prefix >= 0 && prefix <= max) ||
(item.startsWith('::ffff:') && slash >= 0)) { // a v4-mapped prefix would need its own arithmetic: write the IPv4 form
throw new Error('invalid TRUSTED_PROXIES entry ' + JSON.stringify(item) + ' (use an IP or CIDR such as 100.64.0.0/10 or 2001:db8::6)');
}
if (prefixText === null) bl.addAddress(addr, type); else bl.addSubnet(addr, prefix, type);
}
return {
list,
has(ip) {
const a = normalizeIp(ip);
return net.isIPv4(a) ? bl.check(a, 'ipv4') : net.isIPv6(a) ? bl.check(a, 'ipv6') : false;
},
};
}
// Does this request come from a proxy whose X-Forwarded-* headers we believe? `trusted` = parseTrustedProxies() result.
function isTrustedPeer(req, trustProxy, trusted) {
if (trustProxy === true) return true;
if (trustProxy === false) return false;
return isPrivateIp(peerIp(req));
const ip = peerIp(req);
return isPrivateIp(ip) || !!(trusted && trusted.has(ip));
}
// One entry of a forwarding header ("203.0.113.9", "[2001:db8::5]:443", "1.2.3.4:5555") -> bare IP or null.
@ -95,17 +128,17 @@ function forwardedClientIp(value) {
}
// The address used for logging and the per-IP socket cap.
function clientIp(req, trustProxy) {
function clientIp(req, trustProxy, trusted) {
const peer = peerIp(req);
if (!isTrustedPeer(req, trustProxy)) return peer;
if (!isTrustedPeer(req, trustProxy, trusted)) return peer;
return forwardedClientIp(req.headers['x-forwarded-for']) ||
firstForwardedIp(req.headers['x-real-ip']) || peer;
}
// ---------------------------------------------------------------- Origin check
// Scheme-less, lower-case "host[:port]" with the default ports 80 / 443 dropped.
// Accepts a bare host ("Game.Example.com:443"), a Host header, or a full origin ("https://x.example").
function normalizeHost(s) {
// Scheme-less, lower-case host name and port of a bare host ("Game.Example.com:443"), a Host header or a full origin
// ("https://x.example"): { name, port }, with port '' for none or for the default ports 80 / 443. null if unusable.
function hostParts(s) {
if (typeof s !== 'string') return null;
let v = s.trim();
if (!v) return null;
@ -117,27 +150,43 @@ function normalizeHost(s) {
try { u = new URL(v); } catch (e) { return null; }
if (!u.hostname) return null;
const port = u.port; // '' for the scheme's own default
const h = u.hostname.toLowerCase(); // IPv6 keeps its brackets
return port && port !== '80' && port !== '443' ? h + ':' + port : h;
return { name: u.hostname.toLowerCase(), port: port && port !== '80' && port !== '443' ? port : '' }; // IPv6 keeps its brackets
}
// "host[:port]" form of hostParts().
function normalizeHost(s) {
const p = hostParts(s);
return p ? (p.port ? p.name + ':' + p.port : p.name) : null;
}
// Returns true when a WebSocket upgrade with this Origin may proceed.
// no Origin header -> true (non-browser clients)
// Origin host == Host -> true
// Origin host == X-Forwarded-Host (first) -> true, only when the peer is a trusted proxy
// Origin host name == Host name, Host without a port -> true, only when the peer is a trusted proxy (see below)
// Origin host in allowedOrigins -> true
// opts: { trustProxy, trustedProxies (parseTrustedProxies() result), allowedOrigins }.
function originAllowed(req, opts) {
const origin = req.headers.origin;
if (origin === undefined) return true;
const o = (typeof origin === 'string' && origin.toLowerCase() !== 'null' && /^[a-z][a-z0-9+.-]*:\/\//i.test(origin))
? normalizeHost(origin) : null;
? hostParts(origin) : null;
if (!o) return false;
if (o === normalizeHost(req.headers.host)) return true;
if (isTrustedPeer(req, opts.trustProxy)) {
const h = hostParts(req.headers.host);
if (h && o.name === h.name && o.port === h.port) return true;
if (isTrustedPeer(req, opts.trustProxy, opts.trustedProxies)) {
const xfh = req.headers['x-forwarded-host'];
if (typeof xfh === 'string' && o === normalizeHost(xfh.split(',')[0])) return true;
if (typeof xfh === 'string' && normalizeHost(xfh.split(',')[0]) === normalizeHost(origin)) return true;
// Published on a port other than 80/443 (https://game.example.com:8443) behind nginx / nginx Proxy Manager: their
// "proxy_set_header Host $host" drops the port, so Host is "game.example.com" while the browser's Origin keeps
// ":8443", and neither the X-Forwarded-Host nor an ALLOWED_ORIGINS entry written without the port helps. A browser that
// talks to this server directly on its port (8080 by default, never 80/443 unless you chose that) puts the port in
// Host, so a Host WITHOUT one from a trusted proxy is what a stripped port looks like: accept the same host name on
// any port. Another name still fails.
if (h && !h.port && o.name === h.name) return true;
}
for (const a of opts.allowedOrigins || []) if (o === normalizeHost(a)) return true;
const on = normalizeHost(origin);
for (const a of opts.allowedOrigins || []) if (on === normalizeHost(a)) return true;
return false;
}
@ -220,6 +269,6 @@ function listUrls(bound, port, ifaces) {
}
module.exports = {
normalizeIp, isPrivateIp, parseTrustProxy, peerIp, isTrustedPeer, firstForwardedIp, forwardedClientIp, clientIp,
normalizeHost, originAllowed, TokenBucket, listenDual, listUrls, fmtUrl,
normalizeIp, isPrivateIp, parseTrustProxy, parseTrustedProxies, peerIp, isTrustedPeer, firstForwardedIp, forwardedClientIp, clientIp,
hostParts, normalizeHost, originAllowed, TokenBucket, listenDual, listUrls, fmtUrl,
};