Partner credits for PolHunter tour stops (Marty 2026-11-17): POST /api/partner/credits
Signed like polgrant (X-Game-Ts + X-Game-Sig = HMAC(HUNT_SSO_SECRET, ts + newline + body)), polhunter only. Grants earned-grade ad credits (ads.addEarned, kind earn, credit-activity line "PolHunter tour stop: <site>") once per ref across instances (marks.claim pcred:<game>:<ref>); a repeat answers repeat: true. Ceiling per call siteConfig partnerCreditsMax (default 25); suspended accounts refused. qa/partnercredits.test.mjs: 9 checks on a local copy (bad sig, unknown member, ceiling, bad ref, grant, repeat, one log line, earned grade, other game). iap-qa member walk: 0 bugs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -4806,7 +4806,7 @@ const server = http.createServer(async (req, res) => {
|
||||
return json(res, 200, Object.assign({ 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 }, game === 'shardsofvalor' ? gamepass.heroClaim(r.email) : {}));
|
||||
}
|
||||
if ((p === '/api/partner/polgrant' || p === '/api/partner/polgrant/void' || p === '/api/partner/tournament/paid') && req.method === 'POST') {
|
||||
if ((p === '/api/partner/polgrant' || p === '/api/partner/polgrant/void' || p === '/api/partner/tournament/paid' || p === '/api/partner/credits') && req.method === 'POST') {
|
||||
let raw; try { raw = (await readRaw(req, 16384)).toString('utf8'); } catch (e) { return json(res, 413, { error: 'too big' }); }
|
||||
let b; try { b = JSON.parse(raw || '{}'); } catch (e) { return json(res, 400, { error: 'bad json' }); }
|
||||
const game = String(b.game || '').toLowerCase(); const chk = gpPartnerCheck(game); if (chk.error) return json(res, chk.code, { error: chk.error });
|
||||
@@ -4816,6 +4816,22 @@ const server = http.createServer(async (req, res) => {
|
||||
if (p === '/api/partner/tournament/paid') { const r = gamepass.markPaid(b.week, b.place, b.tx, game); if (!r.error) console.log('gamepass prize paid', b.week, '#' + b.place, 'by', game, String(b.tx || '').slice(0, 14)); return json(res, r.error ? 400 : 200, r); }
|
||||
const r = await gpResolve(b.memberId, b.email); if (!r) return json(res, 404, { error: 'no such member' });
|
||||
const now = gpDevNow(b.devDay);
|
||||
// PolHunter tour stops (Marty 2026-11-17): a free member's repeat find pays a few earned-grade ad credits instead of POL. PolHunter
|
||||
// decides the amount (its settings tourStopCredits / tourStopCreditsDailyMax); here a hard ceiling per call (siteConfig partnerCreditsMax,
|
||||
// default 25), once per ref across every instance (marks), with a credit-activity line. A retry of the same ref answers repeat: true.
|
||||
if (p === '/api/partner/credits') {
|
||||
if (game !== 'polhunter') return json(res, 400, { error: 'not enabled for ' + game });
|
||||
const n = Math.round(Number(b.credits) || 0), max = Math.max(0, Math.round(Number(siteConfig().partnerCreditsMax) || 25)), ref = String(b.ref || '');
|
||||
if (!(n > 0) || n > max) return json(res, 400, { error: 'credits must be 1 to ' + max });
|
||||
if (!/^[A-Za-z0-9:_-]{3,60}$/.test(ref)) return json(res, 400, { error: 'bad ref' });
|
||||
const who = await gpResolve(b.memberId, b.email); if (!who) return json(res, 404, { error: 'no such member' });
|
||||
if (fraud.isSuspended(who.email)) return json(res, 403, { error: 'suspended' });
|
||||
if (!(await marks.claim('pcred:' + game + ':' + ref))) return json(res, 200, { ok: true, repeat: true, credits: n });
|
||||
try { await ads.addEarned(who.email, n, { log: { kind: 'earn', note: String(b.note || 'PolHunter tour stop').replace(/[<>]/g, '').slice(0, 120), ref: ('ph' + ref).slice(0, 40) } }); }
|
||||
catch (e) { console.error('partner credits', ref, e.message); return json(res, 500, { error: 'grant failed' }); }
|
||||
console.log('partner credits', game, ref, n, who.email.replace(/^(.).*(@.*)$/, '$1***$2'));
|
||||
return json(res, 200, { ok: true, credits: n });
|
||||
}
|
||||
if (p.endsWith('/void')) return json(res, 200, gamepass.voidGrant({ game, ref: b.ref }));
|
||||
if (fraud.isSuspended(r.email)) return json(res, 200, { allowed: 0, deferred: 0, pass: false, day: gamepass.dayKey(now), suspended: true }); // nothing is recorded: a cleared account replays the ref later
|
||||
const out = gamepass.grant({ email: r.email, game, kind: b.kind, pol: b.pol, ref: b.ref, now });
|
||||
|
||||
Reference in New Issue
Block a user