Games hub: one Games menu entry and pane with a card per game (registry in server.js, live list = site config gamesLive, default polhunter; admin sees unlaunched games as previews), Drip Runner card with the player's own progress via a signed read; chatbot knows Games + Drip Runner (KNOWLEDGE_DATE 2026-10-01); QA walk covers the pane
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1248,6 +1248,24 @@ async function drCallback(body) {
|
||||
catch (e) { console.warn('driprunner callback', e.message); return false; }
|
||||
}
|
||||
|
||||
// -- the games registry (2026-10-01). Add a game here; launch it by adding its slug to site config gamesLive.
|
||||
function GAMES() {
|
||||
return [
|
||||
{ slug: 'driprunner', name: 'Drip Runner', tag: 'Arcade runner', blurb: 'Hop the network, dodge the bots, clear chapters. Each first clear drips POL into your game balance, and a refuel on a member\u2019s page keeps your run alive.',
|
||||
art: DR_URL() + '/badges/ch5.jpg', play: '/api/my/driprunner', pays: 'POL to your wallet at 0.25', progress: drProgress },
|
||||
{ slug: 'polhunter', name: 'PolHunter', tag: 'Scavenger hunt', blurb: 'Hunt hidden codes on sites across the network. Every find drips POL straight to your wallet.',
|
||||
art: 'https://polhunter.com/img/hero-800.webp', play: '/api/my/polhunter', pays: 'POL per find' },
|
||||
];
|
||||
}
|
||||
// the player's own line on the Drip Runner card, read from the game with a signed request
|
||||
async function drProgress(memberId) {
|
||||
if (DR_SECRET().length < 32) return null;
|
||||
const ts = String(Date.now()); const sig = crypto.createHmac('sha256', DR_SECRET()).update('player:' + memberId + ':' + ts).digest('hex');
|
||||
const r = await fetch(DR_URL() + '/api/partner/player?m=' + Number(memberId) + '&ts=' + ts + '&sig=' + sig, { signal: AbortSignal.timeout(2500) });
|
||||
if (!r.ok) return null; const j = await r.json(); if (!j || !j.played) return { line: 'Not played yet' };
|
||||
return { line: 'Chapter ' + j.chapter + ' \u00b7 ' + Number(j.unpaid).toFixed(3) + ' POL in your game balance' + (j.paidTotal ? ' \u00b7 ' + Number(j.paidTotal).toFixed(3) + ' POL paid out' : '') };
|
||||
}
|
||||
|
||||
const server = http.createServer(async (req, res) => {
|
||||
try {
|
||||
const u = new URL(req.url, 'http://x');
|
||||
@@ -2492,6 +2510,22 @@ const server = http.createServer(async (req, res) => {
|
||||
t.doneRet = t.ret + '&ok=1&r=' + encodeURIComponent(receipt);
|
||||
return json(res, 200, { ok: true, posted, ret: t.doneRet });
|
||||
}
|
||||
// -- Games hub (2026-10-01): the registry is here, the live list is site config (gamesLive)
|
||||
if (p === '/api/my/games' && req.method === 'GET') {
|
||||
const s = await auth.fromRequest(req);
|
||||
if (!s || !s.email) return json(res, 401, { error: 'Sign in first.' });
|
||||
const sc = siteConfig(); const live = new Set(String(sc.gamesLive == null ? 'polhunter' : sc.gamesLive).split(',').map(x => x.trim().toLowerCase()).filter(Boolean));
|
||||
const admin = !!(ADMIN_EMAIL && String(s.email).toLowerCase() === ADMIN_EMAIL);
|
||||
const acct = await accounts.byEmail(s.email); const memberId = (acct && acct.memberId) || s.memberId || 0;
|
||||
const out = [];
|
||||
for (const g of GAMES()) {
|
||||
const isLive = live.has(g.slug); if (!isLive && !admin) continue;
|
||||
const card = Object.assign({}, g, { live: isLive, preview: !isLive });
|
||||
if (g.progress && memberId) { try { card.progress = await g.progress(memberId); } catch (e) {} }
|
||||
out.push(card);
|
||||
}
|
||||
return json(res, 200, { games: out.map(g => { const c = Object.assign({}, g); if (typeof c.progress === 'function') delete c.progress; return c; }) });
|
||||
}
|
||||
if (p === '/api/my/claim' && req.method === 'POST') {
|
||||
const s = await auth.fromRequest(req);
|
||||
if (!s || !s.email) return json(res, 401, { error: 'Sign in first.' });
|
||||
|
||||
Reference in New Issue
Block a user