Pass tiers: Explorer ($20/30 days) and Champion ($40/30 days) beside the weekly Game Pass, behind sovTiers (default off, admin-only preview)

Islands and looks in Shards of Valor, never power and never more POL: every tier gets exactly the weekly pass caps and polgrant
still answers pass: true. Per-tier expiry side by side (record.tiers, legacy until mirrors weekly, lazy migration); flag() adds
tier (highest active) and tiers; hand-off token gamePass { active, until, tier }; /api/partner/player pass { active, until, tier,
tiers }. Buy { tier } with purchased credits or a waiting order per tier that a big-enough package fulfils (highest price first,
each tx once). No auto-renew, no proration. Admin: per-tier stats (Central week/month), comp per tier, end-a-tier (refund).
Tournament pool keeps weekly sales only unless passTournamentTierSales. Member card shows three tiers; /my#passes opens it.
Tests: qa/sov-passes-store.cjs, qa/sov-passes-local.mjs (bash qa/run.sh sov-passes). Cache tags my.js/admin.js 20261018tiers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-10-18 14:46:51 -05:00
parent 5e8f2c0b6b
commit 0688bdeb72
11 changed files with 590 additions and 59 deletions
+18 -5
View File
@@ -685,7 +685,8 @@ async function polUsdLive() {
const v = (pk.priceCents / 100) / (Number(BigInt(pk.costWei)) / 1e18); if (v > 0) { polUsdCache.v = v; polUsdCache.at = Date.now(); } return v;
}
// the Game Pass flag rides in every sign-in hand-off token (3a: games get it at sign-in and on every polgrant answer)
const gpClaim = c => (c && c.email && (!c.kind || c.kind === 'sso')) ? { gamePass: gamepass.flag(c.email) } : {};
// gamePass: { active, until, tier } (tier = the highest active pass: weekly | explorer | champion | null; a game treats a missing tier as weekly)
const gpClaim = c => { if (!(c && c.email && (!c.kind || c.kind === 'sso'))) return {}; const f = gamepass.flag(c.email); return { gamePass: { active: f.active, until: f.until, tier: f.tier } }; };
function siteConfig() {
let saved = {};
try { saved = JSON.parse(fs.readFileSync(SITE_FILE, 'utf8')); } catch (e) {}
@@ -716,6 +717,11 @@ function siteConfig() {
geoTier2: '', // empty = built-in default (rest of Western/Central Europe, JP, KR, SG, HK, TW, IL, Gulf, ZA, BR, MX, AR, CL, CO ...); tier 3 = everything else
// Game Pass (2026-10-16, docs/GAME-PASS.md): off until Marty flips it; caps apply from capsStartDate (Central), before it polgrant allows everything and only records
gamePassEnabled: '0', gamePassPriceCredits: 500, gamePassDays: 7, capFreeDaily: 0.30, capFreeTotal: 2.0, capPassDaily: 1.50, capPassTotal: 5.0, capsStartDate: '', passTournamentPct: 5,
// Explorer ($20) and Champion ($40) monthly passes beside the weekly one (2026-10-18, ultima-rpg docs/IAP-PASSES-SPEC.md): islands and looks
// in Shards of Valor, never power, never more POL (same caps as the weekly pass). sovTiers = the sale switch for both (off: only ADMIN_EMAIL
// sees and can buy them, for testing; holders keep their pass). gamePass<Tier>Enabled '0' stops one tier alone. passTournamentTierSales '1'
// would add their sales to the Pass Tournament pool (off = the pool exactly as before).
sovTiers: '0', gamePassExplorerEnabled: '1', gamePassExplorerPriceCredits: 2000, gamePassExplorerDays: 30, gamePassChampionEnabled: '1', gamePassChampionPriceCredits: 4000, gamePassChampionDays: 30, passTournamentTierSales: '0',
supportTelegramChat: '1289244227', // help desk pings: Marty's PRIVATE chat only (a positive user id; group/channel ids are refused). Sent with telegramBotToken, Hermes bot as fallback
supportTemplates: '', // help desk saved replies, JSON [{name, body}] (Admin > Support > Saved replies); empty = the built-in set
telegramGamesChatId: '', telegramGamesTopicId: '661565', // Game Achievements topic for the weekly Pass Tournament post (chat blank = the shared echo chat)
@@ -3809,7 +3815,7 @@ const server = http.createServer(async (req, res) => {
const m = Number(u.searchParams.get('m')) || 0, e = String(u.searchParams.get('e') || '').trim().toLowerCase(), ts = String(u.searchParams.get('ts') || ''), sig = String(u.searchParams.get('sig') || '');
if (!/^\d{13}$/.test(ts) || Math.abs(Date.now() - Number(ts)) > 600000) return json(res, 401, { error: 'stale' });
if (!gpSigOk(crypto.createHmac('sha256', chk.secret).update('player:' + (m > 0 ? String(m) : e) + ':' + ts).digest('hex'), sig)) return json(res, 401, { error: 'bad signature' });
const r = await gpResolve(m, e); if (!r) return json(res, 404, { error: 'no such member', pass: { active: false, until: null } });
const r = await gpResolve(m, e); if (!r) return json(res, 404, { error: 'no such member', pass: { active: false, until: null, tier: null, tiers: { weekly: null, explorer: null, champion: null } } });
const now = gpDevNow(u.searchParams.get('devDay'));
return json(res, 200, { ok: true, memberId: r.memberId, username: r.acct.username || null, wallet: r.acct.address || null, suspended: fraud.isSuspended(r.email),
pass: gamepass.flag(r.email, now), caps: gamepass.capsFor(r.email, now, game), gamePassEnabled: gamepass.cfg().enabled });
@@ -3842,7 +3848,7 @@ const server = http.createServer(async (req, res) => {
}
if (p === '/api/my/gamepass' && req.method === 'GET') {
const s = await auth.fromRequest(req); if (!s || !s.email) return json(res, 401, { error: 'Sign in first.' });
return json(res, 200, gamepass.view(s.email, gpDevNow(u.searchParams.get('devDay'))));
return json(res, 200, gamepass.view(s.email, gpDevNow(u.searchParams.get('devDay')), { admin: !!ADMIN_EMAIL && String(s.email).toLowerCase() === ADMIN_EMAIL }));
}
if (p === '/api/my/gamepass/buy' && req.method === 'POST') {
const s = await auth.fromRequest(req); if (!s || !s.email) return json(res, 401, { error: 'Sign in first.' });
@@ -3850,14 +3856,21 @@ const server = http.createServer(async (req, res) => {
const b = await readBody(req); const { ids } = await myMemberIds(s);
// purchased-grade credits only, from a position's package balance (the PolyWarriors mint rule); devPaid = local tests only
const charge = (!IS_PROD && b.devPaid) ? async () => ({ ok: true, campaignId: 0, dev: true }) : (price, label) => ads.gamePurchase(s.email, ids, price, label, 'https://instantadpay.com/my#games', { purchasedOnly: true });
const r = await gamepass.buy(s.email, charge, gpDevNow(b.devDay));
// tier: weekly (missing) | explorer | champion; Explorer/Champion are refused unless sovTiers is on, except for the ADMIN_EMAIL account (testing)
const r = await gamepass.buy(s.email, charge, gpDevNow(b.devDay), b.tier, { admin: !!ADMIN_EMAIL && String(s.email).toLowerCase() === ADMIN_EMAIL });
return json(res, r.error ? 400 : 200, r);
}
if (!IS_PROD && p === '/api/dev/gamepass-purchase' && req.method === 'POST') { const b = await readBody(req); return json(res, 200, { order: await gamepass.onEvent({ type: 'Purchase', priceCents: Number(b.cents) || 500, buyerId: 0, tx: '0x' + crypto.randomBytes(32).toString('hex'), ts: Date.now(), devEmail: b.email }) }); } // local tests only
if (p === '/api/admin/gamepass/stats' && req.method === 'GET') { if (!isAdmin(req)) return json(res, 401, { error: 'auth' }); return json(res, 200, gamepass.adminStats()); }
if (p === '/api/admin/gamepass/comp' && req.method === 'POST') { // support: give an account a pass week without a purchase
if (!isAdmin(req)) return json(res, 401, { error: 'auth' }); const b = await readBody(req); const e = String(b.email || '').trim().toLowerCase(); if (!e) return json(res, 400, { error: 'email required' });
const r = gamepass.comp(e, String(b.why || 'support').slice(0, 80)); console.log('gamepass comp', e, b.why || ''); return json(res, 200, Object.assign({ ok: true, email: e }, r));
const tier = String(b.tier || 'weekly').toLowerCase(); if (!gamepass.TIERS.includes(tier)) return json(res, 400, { error: 'unknown tier' });
const r = gamepass.comp(e, String(b.why || 'support').slice(0, 80), tier); console.log('gamepass comp', tier, e, b.why || ''); return json(res, 200, Object.assign({ ok: true, email: e }, r));
}
if (p === '/api/admin/gamepass/revoke' && req.method === 'POST') { // support refund only: ends one tier now (never automatic); the record keeps what it was
if (!isAdmin(req)) return json(res, 401, { error: 'auth' }); const b = await readBody(req); const e = String(b.email || '').trim().toLowerCase(); if (!e) return json(res, 400, { error: 'email required' });
const r = gamepass.revoke(e, String(b.tier || '').toLowerCase(), String(b.why || 'support').slice(0, 80)); if (!r.error) console.log('gamepass revoke', r.tier, e, b.why || '');
return json(res, r.error ? 400 : 200, Object.assign({ email: e }, r));
}
if (p === '/api/admin/gamepass/tournament/run' && req.method === 'POST') { // settle a week by hand (the Monday job normally does this)
if (!isAdmin(req)) return json(res, 401, { error: 'auth' }); const b = await readBody(req);