PolyWarriors weekly season prizes: signed game claim -> earned credits (setting pwWeeklyPrize 1000,500,250), once per week+place
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1353,6 +1353,7 @@ function pwOpen(token) {
|
||||
const pwPasses = persistedMap('pwpasses'); // email -> { n, earned, used, log: [{ at, d, why }] }
|
||||
const pwPassN = e => ((pwPasses.get(e) || {}).n || 0);
|
||||
function pwPassAdd(e, d, why) { const c = pwPasses.get(e) || { n: 0, earned: 0, used: 0, log: [] }; const v = { n: Math.max(0, c.n + d), earned: c.earned + Math.max(0, d), used: c.used + Math.max(0, -d), log: [{ at: Date.now(), d, why }].concat(c.log || []).slice(0, 50) }; pwPasses.set(e, v); return v.n; }
|
||||
const pwPrizes = persistedMap('pwprizes'); // 'YYYY-MM-DD:place' -> { email, credits, at }
|
||||
const pwOrders = persistedMap('pworders'); // order -> { status: 'waiting'|'paid', email, serial, ret, cb, ts, tx, cents, delivered }
|
||||
const pwIsGameUrl = x => [PW_URL()].concat(PW_ALT()).some(o => String(x || '').startsWith(o + '/'));
|
||||
async function pwCallback(cbUrl, receipt) {
|
||||
@@ -2888,6 +2889,23 @@ const server = http.createServer(async (req, res) => {
|
||||
res.writeHead(302, { Location: DR_URL() + '/auth?t=' + tok, 'Cache-Control': 'no-store', 'Set-Cookie': 'iap.return=; Path=/; SameSite=Lax; Max-Age=0' + (IS_PROD ? '; Secure' : '') }); return res.end();
|
||||
}
|
||||
// -- PolyWarriors hand-off (2026-10-05): sign the member across; the game verifies with PW_SSO_SECRET
|
||||
// PolyWarriors weekly member-fight season prizes (Marty 2026-10-05): the game signs one claim per week and place; InstantAdPay
|
||||
// decides the amount (setting pwWeeklyPrize, default '1000,500,250' earned credits) and pays each week+place once.
|
||||
if (p === '/api/game/pw/prize' && req.method === 'POST') {
|
||||
const b = await readBody(req); const r = pwOpen(b.t);
|
||||
if (r.error) return json(res, 400, { error: r.error });
|
||||
const c = r.claims, place = Number(c.place), week = String(c.week || '');
|
||||
if (c.kind !== 'pw-prize' || !(place >= 1 && place <= 3) || !/^\d{4}-\d{2}-\d{2}$/.test(week) || !c.email) return json(res, 400, { error: 'bad claim' });
|
||||
if (Math.abs(Date.now() - new Date(week + 'T12:00:00Z').getTime()) > 14 * 86400000) return json(res, 400, { error: 'stale week' });
|
||||
const k = week + ':' + place; if (pwPrizes.get(k)) return json(res, 200, { ok: true, already: true });
|
||||
const acct = await accounts.byEmail(String(c.email).toLowerCase()); if (!acct) return json(res, 404, { error: 'no account' });
|
||||
const amts = String(siteConfig().pwWeeklyPrize || '1000,500,250').split(',').map(x => Math.max(0, Math.round(Number(x) || 0)));
|
||||
const credits = Math.min(amts[place - 1] || 0, 5000); if (!credits) return json(res, 200, { ok: true, credits: 0 });
|
||||
pwPrizes.set(k, { email: acct.email, credits, at: Date.now() });
|
||||
await ads.addEarned(acct.email, credits, { log: { kind: 'bonus', note: 'PolyWarriors weekly season: #' + place + ' (week of ' + week + ')', ref: 'pwprize:' + k } });
|
||||
console.log('polywarriors weekly prize', k, acct.email, credits);
|
||||
return json(res, 200, { ok: true, credits });
|
||||
}
|
||||
if (p === '/api/my/polywarriors' && req.method === 'GET') {
|
||||
const s = await auth.fromRequest(req);
|
||||
if (!s || !s.email) { res.writeHead(302, { Location: '/my' + refQ(u), 'Set-Cookie': gkCookie('iap.return', 'polywarriors', 1800), 'Cache-Control': 'no-store' }); return res.end(); }
|
||||
|
||||
Reference in New Issue
Block a user