Network Tour (Marty 2026-11-17): mission rotation per hunter + free-tier tour stops

- lib/rotation.js: a round = every active house mission; the board offers only missions not found this
  round, never-visited first, then least recently found; mid-round additions join as not found, paused
  missions are skipped; the start gate refuses a mission found earlier this round. State per member in
  rotation.json (start, rounds); everyone starts at 0 so round 1 = their whole history. Paid missions
  keep their rules; daily limits, draws, pool and tiers unchanged. Setting rotationOn (default 1).
- Board: "Network tour: X of Y sites this round" with a progress bar and the sites left; New to you tag.
- Badge sweep renamed Full Network Tour (art unchanged), earned by the old rule or a closed round;
  celebrated on the board every round, round count on the card, Telegram posts it once.
- Free tier: POL only for discovery (first find of a mission). A repeat find is a tour stop: counts as
  the day's hunt and for the tour, 0 POL, ad credits through a signed call to InstantAdPay
  (polgrant.credits -> POST /api/partner/credits, idempotent on ref tour:<row id>); settings
  tourStopCredits 10 / tourStopCreditsDailyMax 10; unconfirmed stops stay owed and retry every 2 min.
  Game Pass holders unchanged. Toured free members see the Game Pass line on the board.
- Admin: Network Tour section (settings, rounds per hunter, credits sent/owed), GET /api/admin/rotation.
- Board daily line now passes the tier (a Pass holder saw 3, not 5).
- fridaybank: http for a local stub IAP (tests). Tests: test/rotation.js (27 checks), run.js waits for
  /health instead of a fixed 1.2 s. Guides: how-a-hunt-works, faq, free-account explain the tour.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-11-17 09:20:42 -06:00
parent 408a30cf31
commit 654cd7b408
15 changed files with 352 additions and 26 deletions
+32 -7
View File
@@ -57,6 +57,9 @@ const passExtra = me => passActive(me) ? 2 : 0; // the perk: 5 missions a day in
// a free account gets the free tier (lib/rewards.js freeMissionsPerDay / freeMinPol / freeMaxPol). With GAMEPASS off there is no
// pass to buy, so everyone stays on the full tier as before.
const fullTier = me => !gp.on() || passActive(me);
// the Network Tour (Marty 2026-11-17, lib/rotation.js): rounds per hunter; a free member's repeat find is a tour stop (ad credits, no POL)
const rotation = require('./lib/rotation');
const isTourStop = (me, m) => !fullTier(me) && !m.paid && rotation.everFound(me.memberId, me.wallet, m.id);
// one reward through IAP: ask(pol, ref) -> IAP's answer (+ the player-facing note), wait(rowId, pol, ref) -> queue the ref (fail closed)
const gpGate = me => ({
ask: async (pol, ref) => { const r = await gp.grant({ memberId: me.memberId, email: me.email, kind: 'daily', pol, ref }); r.note = gp.note(r, 'daily', pol); return r; },
@@ -269,7 +272,7 @@ const server = http.createServer(async (req, res) => {
if (p === '/api/badges') return json(res, 200, { badges: social.BADGES.map(b => Object.assign({ art: '/badges/badge-' + b.id + '.jpg' }, b)) });
if (p === '/api/prizes') return json(res, 200, social.prizes(), { 'Cache-Control': 'public, max-age=60' });
if (p === '/leaders') return sendFile(res, path.join(PUBLIC_DIR, 'leaders.html'));
if (p === '/promo') return sendFile(res, path.join(PUBLIC_DIR, 'promo.html'));
if (p === '/promo') return sendFile(res, path.join(PUBLIC_DIR, 'promo.html'));
if (p === '/terms' || p === '/privacy' || p === '/disclaimer') return sendFile(res, path.join(PUBLIC_DIR, p.slice(1) + '.html')); // legal pages (2026-11-17)
// evergreen Guides (Marty 2026-11-17): /guides and four pages, static files in public/guides
const GUIDES = ['how-a-hunt-works', 'is-polhunter-legit', 'free-account', 'faq'];
@@ -291,9 +294,14 @@ const server = http.createServer(async (req, res) => {
const fbank = await fbFor(me);
if (gp.on()) gp.fetchPass(me.memberId, me.email).catch(() => {}); // keep the Game Pass flag fresh (display + perks; grant answers carry the truth)
referrals.seen(me); // hunters already signed in never pass through /auth again, so keep the directory fresh here too
const done = rewards.doneToday(me.memberId, me.wallet); const wdone = done; // today's finds, by member id or wallet
return json(res, 200, { me: { memberId: me.memberId, username: me.username, wallet: me.wallet }, missions: missions.forMember(me.memberId).map(m => Object.assign(pubMission(m), { done: done.has(m.id) || wdone.has(m.id) })), drips: rewards.mine(me.memberId).slice(0, 20), faucet: { on: faucetOn }, pool: rewards.pool(), daily: rewards.daily(me.memberId, rewards.doneToday(me.memberId, me.wallet), fbank.bonus, passExtra(me)), fridayBank: fbank, gamepass: gp.view(me.memberId, me.email),
badges: social.badgesFor(me.memberId), badgeCards: (() => { const got = new Set(social.badgesFor(me.memberId).map(b => b.id)); const who = social.nameOf(me); return social.BADGES.map(b => ({ id: b.id, name: b.name, icon: b.icon, why: b.why, art: '/badges/badge-' + b.id + '.jpg', earned: got.has(b.id), page: got.has(b.id) ? SITE + '/b/' + who + '/' + b.id : null, image: got.has(b.id) ? SITE + '/badge-img/' + who + '/' + b.id + '.jpg' : null })); })(), rank: { week: social.rankOf(me.memberId, 'week'), month: social.rankOf(me.memberId, 'month'), all: social.rankOf(me.memberId, 'all') },
const done = rewards.doneToday(me.memberId, me.wallet); // today's finds, by member id or wallet
// the Network Tour: open this round first (never visited, then least recently found), then today's finds marked done
const rot = rotation.state(me), free = !fullTier(me), rc = rotation.cfg();
const offered = rotation.order(me, rot).filter(m => !done.has(m.id)), doneList = missions.forMember(me.memberId).filter(m => done.has(m.id));
const boardMissions = offered.concat(doneList).map(m => Object.assign(pubMission(m), { done: done.has(m.id), fresh: !m.paid && !rot.last.has(m.id), tourStop: free && !m.paid && rot.last.has(m.id) ? { credits: rc.credits } : undefined }));
const tour = { on: rot.on, round: rot.round, rounds: rot.rounds, done: rot.done, total: rot.total, left: [...new Set(rot.left.map(m => m.site))], toured: rot.toured, free, tourStopCredits: rc.credits };
return json(res, 200, { me: { memberId: me.memberId, username: me.username, wallet: me.wallet }, missions: boardMissions, tour, drips: rewards.mine(me.memberId).slice(0, 20), faucet: { on: faucetOn }, pool: rewards.pool(), daily: rewards.daily(me.memberId, rewards.doneToday(me.memberId, me.wallet), fbank.bonus, passExtra(me), fullTier(me)), /* the tier, as start/submit pass it (the board showed a Pass holder 3, not 5) */ fridayBank: fbank, gamepass: gp.view(me.memberId, me.email),
badges: social.badgesFor(me.memberId), badgeCards: (() => { const got = new Set(social.badgesFor(me.memberId).map(b => b.id)); const who = social.nameOf(me); return social.BADGES.map(b => ({ id: b.id, name: b.name, icon: b.icon, why: b.why, count: b.id === 'sweep' && rot.rounds > 1 ? rot.rounds : undefined, art: '/badges/badge-' + b.id + '.jpg', earned: got.has(b.id), page: got.has(b.id) ? SITE + '/b/' + who + '/' + b.id : null, image: got.has(b.id) ? SITE + '/badge-img/' + who + '/' + b.id + '.jpg' : null })); })(), rank: { week: social.rankOf(me.memberId, 'week'), month: social.rankOf(me.memberId, 'month'), all: social.rankOf(me.memberId, 'all') },
share: { link: social.shareLink(SITE, me), joinUrl: 'https://instantadpay.com/join/' + encodeURIComponent(String(me.username || me.memberId)) + '?from=polhunter' },
referral: referrals.state(me), box: detective.view(me, fullTier(me)) });
}
@@ -301,6 +309,7 @@ const server = http.createServer(async (req, res) => {
const b = await readBody(req); const m = missions.get(String(b.missionId || '')); if (!m || !m.active) return json(res, 404, { error: 'That mission is not open.' });
if (!me.wallet) return json(res, 400, { error: 'Link a wallet on InstantAdPay first so the drip has somewhere to land, then open PolHunter again.' });
if (rewards.completed(me.memberId, m.id, me.wallet)) return json(res, 400, { error: 'You already completed this one.' });
if (rotation.blocked(me, m)) return json(res, 400, { error: 'You found this one already this round. The rest of the network tour comes first.', tour: true });
{ const pool = rewards.pool(); if (pool.spent) return json(res, 400, { error: SPENT_MSG, spent: true, resetsAt: pool.resetsAt }); }
{ const fb = await fbFor(me); const d = rewards.daily(me.memberId, rewards.doneToday(me.memberId, me.wallet), fb.bonus, passExtra(me), fullTier(me)); if (!d.left) return json(res, 400, { error: dailyMsg(d), dailyDone: true, resetsAt: rewards.pool().resetsAt }); }
if (limited('start:' + me.memberId, 20, 3600000)) return json(res, 429, { error: 'Easy. Twenty starts an hour is plenty.' });
@@ -319,7 +328,18 @@ const server = http.createServer(async (req, res) => {
if (rewards.completed(me.memberId, m.id, me.wallet)) return json(res, 400, { error: 'You already completed this one.' });
{ const pool = rewards.pool(); if (pool.spent) return json(res, 400, { error: SPENT_MSG, spent: true, resetsAt: pool.resetsAt }); }
{ const fb = await fbFor(me); const d = rewards.daily(me.memberId, rewards.doneToday(me.memberId, me.wallet), fb.bonus, passExtra(me), fullTier(me)); if (!d.left) return json(res, 400, { error: dailyMsg(d), dailyDone: true, resetsAt: rewards.pool().resetsAt }); }
const before = new Set(social.badgesFor(me.memberId).map(b => b.id));
const before = new Set(social.badgesFor(me.memberId).map(b => b.id)); const roundsBefore = rotation.state(me).rounds;
// a free member's repeat find (Marty 2026-11-17): a tour stop, ad credits instead of POL; counts as the day's hunt and for the tour
if (isTourStop(me, m)) {
const row = rotation.tourStop(me, m); const roundsNow = rotation.state(me).rounds;
const unlocked = social.badgesFor(me.memberId).filter(b => !before.has(b.id));
for (const b of unlocked) notify('badge', { me, id: b.id }).catch(() => {});
const show = unlocked.map(b => b.id); if (roundsNow > roundsBefore && !show.includes('sweep')) show.push('sweep'); // a new round closed: celebrate again
rotation.deliver(row, gp).catch(e => console.error('tour stop', e.message)); // signed call to InstantAdPay; owed and retried if it fails
const cr = row.tourStop.credits;
return json(res, 200, { ok: true, pol: 0, tourStop: { credits: cr }, unlocked: show, round: roundsNow > roundsBefore ? roundsNow : null, gamepass: gp.view(me.memberId, me.email),
message: 'Tour stop logged. ' + (cr > 0 ? '+' + cr + ' ad credits are on their way to your InstantAdPay account.' : 'Today\u2019s tour-stop ad credits are already yours.') + ' New sites pay POL on your first find, and the Game Pass pays POL on every hunt.' });
}
let g, note = null;
if (gp.on() && !m.paid) { // the Game Pass: IAP's account-wide daily cap first (a paid mission is the advertiser's money, not gated)
const quote = rewards.quote(m, fullTier(me)), ref = 'find:' + m.id + ':' + missions.ctDay(), r = await gpGate(me).ask(quote, ref); note = r.note;
@@ -332,9 +352,11 @@ const server = http.createServer(async (req, res) => {
try { refDrips = referrals.onFind(me, g.rec); } catch (e) { console.error('referral', e.message); }
for (const d of refDrips) if (d.ref.kind === 'bounty' || d.ref.kind === 'first-bonus') notify(d.ref.kind === 'bounty' ? 'referral' : 'firstbonus', { drip: d }).catch(() => {});
// achievements unlocked by this find: told to the board, posted to Telegram (gated)
const roundsNow = rotation.state(me).rounds;
const unlocked = social.badgesFor(me.memberId).filter(b => !before.has(b.id));
for (const b of unlocked) notify('badge', { me, id: b.id }).catch(() => {});
return json(res, 200, { ok: true, pol: g.waiting ? 0 : g.rec.pol, nominal: g.rec.nominal, queued: g.queued, capped: g.capped, waiting: g.waiting, note, unlocked: unlocked.map(b => b.id), gamepass: gp.view(me.memberId, me.email),
const show = unlocked.map(b => b.id); if (roundsNow > roundsBefore && !show.includes('sweep')) show.push('sweep'); // Full Network Tour again: board only, Telegram posts a badge once
return json(res, 200, { ok: true, pol: g.waiting ? 0 : g.rec.pol, nominal: g.rec.nominal, queued: g.queued, capped: g.capped, waiting: g.waiting, note, unlocked: show, round: roundsNow > roundsBefore ? roundsNow : null, gamepass: gp.view(me.memberId, me.email),
message: g.waiting ? 'Found it. ' + note : g.capped ? 'Found it. ' + note : g.queued ? 'Found it. Today’s POL is spoken for, so yours is queued and pays out next.' : 'Found it. ' + fmt(g.rec.pol) + ' POL is on its way to your wallet.' + (note ? ' ' + note : '') });
}
// ---- Mystery Hunt Box + Ad Detective
@@ -371,10 +393,11 @@ const server = http.createServer(async (req, res) => {
return json(res, 200, { ok: true, missions: missions.list() });
}
if (p === '/api/admin/mission' && req.method === 'DELETE') { const b = await readBody(req); missions.remove(String(b.id || '')); return json(res, 200, { ok: true, missions: missions.list() }); }
if (p === '/api/admin/settings' && req.method === 'POST') { const b = await readBody(req); const patch = {}; for (const k of ['minPol', 'maxPol', 'dailyCapPol', 'lowBalancePol', 'weeklyMinFinds', 'drawSkew', 'missionsPerDay', 'freeMissionsPerDay', 'freeMinPol', 'freeMaxPol', 'detectiveOn', 'detectivePol', 'refEnabled', 'refBountyPol', 'refMatchPct', 'refMatchDays', 'refNewDays', 'refCapPol', 'refMatchMinPol']) if (b[k] != null && Number(b[k]) >= 0) patch[k] = Number(b[k]); for (const k of ['weeklyPrizes', 'leaderboardExclude']) if (Array.isArray(b[k])) patch[k] = b[k].map(Number).filter(n => n >= 0); return json(res, 200, { ok: true, settings: rewards.setSettings(patch) }); }
if (p === '/api/admin/settings' && req.method === 'POST') { const b = await readBody(req); const patch = {}; for (const k of ['minPol', 'maxPol', 'dailyCapPol', 'lowBalancePol', 'weeklyMinFinds', 'drawSkew', 'missionsPerDay', 'freeMissionsPerDay', 'freeMinPol', 'freeMaxPol', 'detectiveOn', 'detectivePol', 'refEnabled', 'refBountyPol', 'refMatchPct', 'refMatchDays', 'refNewDays', 'refCapPol', 'refMatchMinPol', 'rotationOn', 'tourStopCredits', 'tourStopCreditsDailyMax']) if (b[k] != null && Number(b[k]) >= 0) patch[k] = Number(b[k]); for (const k of ['weeklyPrizes', 'leaderboardExclude']) if (Array.isArray(b[k])) patch[k] = b[k].map(Number).filter(n => n >= 0); return json(res, 200, { ok: true, settings: rewards.setSettings(patch) }); }
// award a week by hand (its Monday key); already-awarded weeks are skipped
if (p === '/api/admin/prizes/award' && req.method === 'POST') { const b = await readBody(req); const r = social.awardWeek(String(b.week || '')); if (r && r.winners && r.winners.length) notify('prize', r).catch(() => {}); return json(res, r && r.error ? 400 : 200, r); }
// Ad Detective question bank: stats per question, add or edit one, retire or restore one
if (p === '/api/admin/rotation') return json(res, 200, rotation.adminView()); // the Network Tour: rounds per hunter, tour-stop credits sent / owed
if (p === '/api/admin/detective') return json(res, 200, detective.stats());
if (p === '/api/admin/detective/question' && req.method === 'POST') { const b = await readBody(req); if (b.id && b.active != null && !b.q) return json(res, detective.setActive(String(b.id), !!b.active) ? 200 : 404, { ok: true }); const r = detective.saveQuestion(b); return json(res, r.error ? 400 : 200, r); }
if (p === '/api/admin/drip/retry' && req.method === 'POST') { const b = await readBody(req); rewards.mark(String(b.id || ''), { status: 'due', error: null }); return json(res, 200, { ok: true }); }
@@ -401,6 +424,8 @@ if (faucetOn) setInterval(() => faucet.tick(notify).catch(e => console.error('fa
// Game Pass: refs that could not reach InstantAdPay retry every 5 minutes (lib/polgrant.js); the weekly Pass Tournament prizes are
// paid from this faucet every 10 minutes (lib/tournament.js). Both are inert unless GAMEPASS=on; prizes need the faucet wallet too.
gp.startRetry(payQueued); if (faucetOn) tournament.start();
// tour-stop ad credits InstantAdPay has not confirmed yet are retried every two minutes (owed until then)
setInterval(() => { if (gp.on()) rotation.retryDue(gp).catch(e => console.error('tour stops', e.message)); }, 2 * 60000);
// Every completed mission reaches Telegram (Marty, 2026-09-21): a find is posted when its drip is paid, and
// this sweep posts any paid find that is not marked posted yet (the pre-live gate, Telegram down, a restart).
// Only finds made after HUNT_POST_SINCE count, so rehearsal drips from before the doors opened stay quiet.