onlinemodus fix failed

This commit is contained in:
2026-11-19 00:55:39 +01:00
parent 64c5b65543
commit 347701d66f
10 changed files with 414 additions and 53 deletions

View File

@@ -72,7 +72,14 @@ app.delete(/^\/db\/(.*)\.json$/, (req, res) => {
});
// --- static game (same origin: no CORS, no mixed content) ------------------------------------------
app.use(express.static(path.join(__dirname, '..', 'game')));
app.use(express.static(path.join(__dirname, '..', 'game'), {
etag: true,
setHeaders(res, p) {
// images / fonts / audio rarely change -> cache hard (fast re-renders, no re-fetch flicker)
if (/\.(png|jpe?g|webp|gif|svg|woff2?|ttf|otf|mp3|ogg|wav|m4a)$/i.test(p)) res.setHeader('Cache-Control', 'public, max-age=31536000, immutable');
else res.setHeader('Cache-Control', 'no-cache'); // code/html: revalidate so deploys show up
},
}));
const PORT = process.env.PORT || 8080;
app.listen(PORT, () => console.log('Robot Clash server on :' + PORT));

View File

@@ -29,13 +29,26 @@ function resolveSV(v) {
}
// --- RTDB-like tree over the nodes table ---------------------------------------------------------
// objects are stored as ONE json node, so a deep path (e.g. matches/<id>/meta/seed) has no own row -
// read it from the nearest ancestor blob by descending into its parsed json (Firebase-like deep reads)
function readInside(p) {
const seg = p.split('/');
for (let i = seg.length - 1; i >= 1; i--) {
const row = db.prepare('SELECT data FROM nodes WHERE path = ?').get(seg.slice(0, i).join('/'));
if (!row) continue;
let v = parse(row.data);
for (let j = i; j < seg.length; j++) { if (v && typeof v === 'object' && !Array.isArray(v)) v = v[seg[j]]; else { v = undefined; break; } }
return v === undefined ? null : v;
}
return null;
}
function getTree(p) {
p = norm(p);
const like = p ? p + '/%' : '%';
const rows = p
? db.prepare('SELECT path, data FROM nodes WHERE path = ? OR path LIKE ?').all(p, like)
: db.prepare('SELECT path, data FROM nodes').all();
if (!rows.length) return null;
if (!rows.length) return p ? readInside(p) : null;
let result;
rows.sort((a, b) => a.path.length - b.path.length);
for (const row of rows) {