diff --git a/gamepass.js b/gamepass.js index 0ce0514..16ecc7a 100644 --- a/gamepass.js +++ b/gamepass.js @@ -278,6 +278,15 @@ function buyStackPro(email, now) { } function cancelStackOrder(email) { const e = String(email || '').toLowerCase(); const w = stackOrders(e)[0]; if (!w) return { ok: true }; orders.set(w.order, Object.assign({}, orders.get(w.order), { status: 'cancelled', cancelledAt: Date.now() })); return { ok: true, order: w.order }; } function compStackPro(email, on, note) { const e = String(email || '').toLowerCase(); if (on) stackpro.set(e, { ts: Date.now(), via: 'comp', note: String(note || '').slice(0, 120) }); else stackpro.delete(e); return { ok: true, pro: !!on }; } +// a package bought WITHOUT a Pro order first, granted by the admin (Marty 2026-11-09, Orlando's $10 package): recorded as a +// package sale with its tx so it counts as new money, and the tx is marked used like any fulfilment +function grantStackProForPackage(email, tx, cents, buyerId, note) { + const e = String(email || '').toLowerCase(); if (!e) return { error: 'No account.' }; + if (stackpro.get(e)) return { ok: true, already: true }; + stackpro.set(e, { ts: Date.now(), via: 'package', tx, cents, buyerId, note: String(note || 'admin grant: package bought without a Pro order').slice(0, 120) }); + console.log('stack pro granted for package', e, tx, cents, 'cents'); + return { ok: true, pro: true }; +} function stackProOwners() { return [...stackpro.keys()]; } // A package purchase landing on chain fulfils one of this account's waiting orders: the highest-priced one the package covers. @@ -672,5 +681,5 @@ function prune(now) { return n; } -module.exports = { STACK_PRO_CENTS, stackPro, stackProView, buyStackPro, cancelStackOrder, compStackPro, stackProOwners, init, cfg, GAMES, NAMES, TIERS, TIER_NAMES, TIER_DEFS, HERO_DEFS, HERO_KEYS, heroesOwned, heroClaim, heroView, buyHero, cancelHeroOrder, compHero, revokeHero, heroStats, flag, activity, view, buy, cancelOrder, comp, revoke, onEvent, capsFor, grant, voidGrant, tournamentTick, runTournament, pending, markPaid, adminStats, prune, weekStart, dayKey, +module.exports = { STACK_PRO_CENTS, stackPro, stackProView, buyStackPro, cancelStackOrder, compStackPro, stackProOwners, grantStackProForPackage, init, cfg, GAMES, NAMES, TIERS, TIER_NAMES, TIER_DEFS, HERO_DEFS, HERO_KEYS, heroesOwned, heroClaim, heroView, buyHero, cancelHeroOrder, compHero, revokeHero, heroStats, flag, activity, view, buy, cancelOrder, comp, revoke, onEvent, capsFor, grant, voidGrant, tournamentTick, runTournament, pending, markPaid, adminStats, prune, weekStart, dayKey, _ledger: () => L }; diff --git a/server.js b/server.js index 6029e38..b8af5f7 100644 --- a/server.js +++ b/server.js @@ -4530,6 +4530,19 @@ const server = http.createServer(async (req, res) => { if (!r.error) console.log('bonus heroes admin test', p.split('/').pop(), hero, me); return json(res, r.error ? 400 : 200, Object.assign({ email: me, test: true, heroes: gamepass.heroView(me, Date.now(), { preview: true }) }, r)); } + // Admin: give Stack POL Pro for a package that was bought without a Pro order first (Marty 2026-11-09). The tx must be an on-chain + // Purchase of $10 or more by that member id; then the badge posts like any unlock. + if (p === '/api/admin/stackpro/grant' && req.method === 'POST') { + if (!isAdmin(req)) return json(res, 401, { error: 'auth' }); + const b = await readBody(req); const id = Number(b.memberId), tx = String(b.tx || '').toLowerCase(); + let ev = null; try { ev = (JSON.parse(fs.readFileSync(path.join(DATA_DIR, 'chain-index.json'), 'utf8')).events || []).find(e => e.type === 'Purchase' && String(e.tx || '').toLowerCase() === tx); } catch (e) {} + if (!ev || Number(ev.buyerId) !== id || Number(ev.priceCents) < gamepass.STACK_PRO_CENTS) return json(res, 400, { error: 'That tx is not a $10+ package bought by member #' + id + '.', ev }); + const a = await accounts.byMemberId(id); if (!a || !a.email) return json(res, 404, { error: 'No account for member #' + id }); + const r = gamepass.grantStackProForPackage(a.email, tx, Number(ev.priceCents), id, b.note); + try { await stackProMark(a.email); } catch (e) {} + let posted = 0; try { posted = await postBadgeOnce(a.email, 'stackpro'); } catch (e) { console.error('stackpro badge', e.message); } + return json(res, 200, Object.assign({ username: a.username, posted }, r)); + } if (p === '/api/admin/heroes/stats' && req.method === 'GET') { if (!isAdmin(req)) return json(res, 401, { error: 'auth' }); return json(res, 200, gamepass.heroStats()); } // Admin > Game Pass tier test (2026-10-25, Marty): every tier as members will see it, with the admin's OWN account's state, and a // test buy of a tier that is not on sale yet (opens the same waiting order a member gets; a fresh package on /my fulfils it).