Spooky Doors launch pack (IAP side): door packs + Golden Doors, Promo tools card, season from Oct 4
- Visit packs get a placement: 'all' (as before), 'doors' (Behind Spooky Doors, doorPackCost 4/door) or
'golden' (Golden Spooky Door, goldenDoorCost 6/door). campaigns.placement column (alterSafe) + JSON store.
- Doors serve golden packs first, then door packs, then the existing chain; each pack at most once per
player per Central day. Door-only packs never reach the Earn tab, refuels or the PassiveDrip listing
until rates.sdSeasonEnd ('2026-11-01'); from then on they behave as 'all'.
- Door payloads: credits = per-door price actually charged (3/4/6); Golden Doors add golden: true and
bonus: goldenBonusCandy (2) to /api/door/open, done, callback and receipt. Gold variant of /door.
- Campaign list: Spooky Doors / Golden Door chip, doors opened + unique players, Buy more doors at the
door price. Composer: placement choice with live cost. Admin rates labels + house pack placement.
- Promo tools: Spooky Doors card (spookydoors.com/r/<username>, copy, share image, two posts) on the same
season window as the Games card (seasonState helper).
- Season start moved up to 2026-10-04 (Games card + promo card + chatbot).
- qa/door.mjs covers all of the above.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1295,7 +1295,8 @@ async function gkCallback(cbUrl, receipt) {
|
||||
// lands first. Costumes are bought with ad credits through ads.gamePurchase, exactly like Gem Kingdom Crowns.
|
||||
const SD_SECRET = () => String(process.env.SD_SSO_SECRET || '').trim();
|
||||
const SD_URL = () => String(process.env.SD_URL || 'https://spookydoors.com').replace(/\/+$/, '');
|
||||
const SD_SEASON = { start: '2026-10-17', end: '2026-11-01' }; // Central days, end exclusive (through Halloween night)
|
||||
const SD_SEASON = { start: '2026-10-04', end: '2026-11-01' }; // Central days, end exclusive (through Halloween night); start moved up from 10-17 (Marty, 2026-10-02)
|
||||
const sdGoldenBonus = () => { const n = Number(ads.rates().goldenBonusCandy); return Number.isFinite(n) && n >= 0 ? Math.round(n) : 2; }; // extra candy on a Golden Door
|
||||
const sdSign = p => drB64u(crypto.createHmac('sha256', SD_SECRET()).update(p).digest());
|
||||
function sdMint(claims, ttlMs) { const payload = JSON.stringify(Object.assign({ iat: Date.now(), exp: Date.now() + (ttlMs || 300000), nonce: crypto.randomBytes(12).toString('hex') }, claims)); return drB64u(payload) + '.' + sdSign(payload); }
|
||||
function sdOpen(token, expiredMsg) {
|
||||
@@ -1358,10 +1359,18 @@ function sdPage(res, code, title, inner) {
|
||||
}
|
||||
|
||||
|
||||
// the generic season window (2026-10-02), shared by the Games card and the Promo tools card: 'live' while today (Central) is in
|
||||
// [start, end), 'preview' before start for the admin only, 'hidden' otherwise (and for everyone from end on)
|
||||
function seasonState(season, day, admin) {
|
||||
if (!season) return 'live';
|
||||
if (day >= season.end) return 'hidden';
|
||||
if (day < season.start) return admin ? 'preview' : 'hidden';
|
||||
return 'live';
|
||||
}
|
||||
// -- the games registry (2026-10-01). Add a game here; launch it by adding its slug to site config gamesLive.
|
||||
function GAMES() {
|
||||
return [
|
||||
{ slug: 'spookydoors', name: 'Spooky Doors', tag: 'Halloween \u00b7 Oct 17 to 31', blurb: 'Trick or treat! Walk the street, knock on doors and fill your candy bucket. Every door is a short visit to a member\u2019s page or ad, and candy climbs a ladder with POL at set levels. Gone after Halloween night.',
|
||||
{ slug: 'spookydoors', name: 'Spooky Doors', tag: 'Halloween \u00b7 Oct 4 to 31', blurb: 'Trick or treat! Walk the street, knock on doors and fill your candy bucket. Every door is a short visit to a member\u2019s page or ad, and candy climbs a ladder with POL at set levels. Gone after Halloween night.',
|
||||
art: SD_URL() + '/og-spookydoors.jpg', play: '/api/my/spookydoors', pays: 'POL at set candy levels', season: { start: SD_SEASON.start, end: SD_SEASON.end }, progress: sdProgress },
|
||||
{ slug: 'driprunner', name: 'Drip Runner', tag: 'Arcade runner', blurb: 'Hop the network, dodge the bots, clear chapters. Each first clear drips POL into your game balance, and a refuel on a member\u2019s page keeps your run alive.',
|
||||
art: DR_URL() + '/og-driprunner.jpg?v=20261002', artPos: 'left', play: '/api/my/driprunner', pays: 'POL to your wallet at 0.25', progress: drProgress },
|
||||
@@ -2660,6 +2669,16 @@ const server = http.createServer(async (req, res) => {
|
||||
return gkPage(res, 200, 'Crowns added', '<meta http-equiv="refresh" content="1;url=' + back + '"><p class="sub">Gem Kingdom · Crown Shop</p><h1>Paid!</h1><div class="big">+' + Number(c.crowns).toLocaleString('en-US') + ' Crowns</div><p class="sub">Taking you back to your kingdom...</p><a class="btn" href="' + back + '">Back to Gem Kingdom</a>');
|
||||
}
|
||||
// -- Spooky Doors hand-off (2026-10-02): sign the member across; the game verifies with SD_SSO_SECRET
|
||||
// -- Spooky Doors promo card in Promo tools (2026-10-02): shown on the same season window as the Games card (admin preview
|
||||
// before the start). The member's link is SD_URL/r/<username>, built in the page from their own username.
|
||||
if (p === '/api/my/spookydoors/promo' && req.method === 'GET') {
|
||||
const s = await auth.fromRequest(req);
|
||||
if (!s || !s.email) return json(res, 401, { error: 'Sign in first.' });
|
||||
const admin = !!(ADMIN_EMAIL && String(s.email).toLowerCase() === ADMIN_EMAIL);
|
||||
const ss = seasonState(SD_SEASON, todayCT(), admin);
|
||||
if (ss === 'hidden') return json(res, 200, { show: false });
|
||||
return json(res, 200, { show: true, preview: ss === 'preview', base: SD_URL(), image: SD_URL() + '/og-spookydoors.jpg', season: { start: SD_SEASON.start, end: SD_SEASON.end } });
|
||||
}
|
||||
if (p === '/api/my/spookydoors' && req.method === 'GET') {
|
||||
const s = await auth.fromRequest(req);
|
||||
// a newcomer from a Spooky Doors post carries the poster's ?ref through to /my, where the viral-link rule sets the sponsor
|
||||
@@ -2821,8 +2840,11 @@ const server = http.createServer(async (req, res) => {
|
||||
const status = await ads.visitStatus(email, 'door'); // doors have their own daily allowance
|
||||
if (!t) {
|
||||
if (status.count >= status.cap) return json(res, 200, { none: true, why: 'cap', ret: sdJoin(c.ret, 'cap=1') });
|
||||
const ad = await ads.serveVisit(email, viewerGeo(req), { kind: 'door' }); // doors may repeat a campaign after doorRepeatDays
|
||||
if (ad) t = { kind: 'visit', email, memberId: Number(c.memberId) || 0, id: ad.id, title: ad.title, target: ad.target, ts: Date.now(), ret: c.ret, challenge: null, done: false };
|
||||
// door packs + Golden Doors first (golden, then doors; once per player per Central day), then the existing chain
|
||||
const pack = await ads.serveDoorPack(email, viewerGeo(req));
|
||||
const ad = pack || await ads.serveVisit(email, viewerGeo(req), { kind: 'door' }); // doors may repeat a campaign after doorRepeatDays
|
||||
if (ad) t = { kind: 'visit', email, memberId: Number(c.memberId) || 0, id: ad.id, title: ad.title, target: ad.target, ts: Date.now(), ret: c.ret, challenge: null, done: false,
|
||||
credits: pack ? pack.credits : (ads.rates().visitCostPerVisit || 3), golden: !!(pack && pack.golden), bonus: (pack && pack.golden) ? sdGoldenBonus() : 0 };
|
||||
else { // every visit pack already visited: a member video ad instead, one door per video per person
|
||||
const v = await ads.serveVideo(Object.assign({ excludeEmail: email, refuel: true }, viewerGeo(req)));
|
||||
if (v) t = { kind: 'video', email, memberId: Number(c.memberId) || 0, id: v.id, title: v.title, videoUrl: v.videoUrl, secs: v.watchSecs, width: v.width, height: v.height, ts: Date.now(), ret: c.ret, challenge: null, done: false };
|
||||
@@ -2838,7 +2860,7 @@ const server = http.createServer(async (req, res) => {
|
||||
const doors = { used: status.count, cap: status.cap };
|
||||
if (t.kind === 'video') return json(res, 200, { mode: 'video', title: t.title, host: t.host || null, doors, video: { url: t.videoUrl, width: t.width, height: t.height }, dwell: t.secs, ret: t.ret, elapsed: Math.floor((Date.now() - t.ts) / 1000) });
|
||||
if (t.kind === 'house') return json(res, 200, { mode: 'visit', house: true, program: t.program, title: t.title, host: null, doors, target: t.target, dwell: ads.rates().visitDwellSeconds || 8, ret: t.ret, elapsed: Math.floor((Date.now() - t.ts) / 1000) });
|
||||
return json(res, 200, { mode: 'visit', title: t.title, host: t.host || null, doors, target: t.target, dwell: ads.rates().visitDwellSeconds || 8, ret: t.ret, elapsed: Math.floor((Date.now() - t.ts) / 1000) });
|
||||
return json(res, 200, Object.assign({ mode: 'visit', title: t.title, host: t.host || null, doors, target: t.target, dwell: ads.rates().visitDwellSeconds || 8, ret: t.ret, elapsed: Math.floor((Date.now() - t.ts) / 1000), credits: t.credits || (ads.rates().visitCostPerVisit || 3) }, t.golden ? { golden: true, bonus: t.bonus } : {}));
|
||||
}
|
||||
if (p === '/api/door/challenge' && req.method === 'GET') {
|
||||
const n = String(u.searchParams.get('n') || ''); const t = doorTokens.get(n);
|
||||
@@ -2869,16 +2891,18 @@ const server = http.createServer(async (req, res) => {
|
||||
} else {
|
||||
const r = await ads.completeVisit(t.email, t.id, { reward: false, kind: 'door', note: 'Spooky Doors door' });
|
||||
if (r.error) return json(res, 400, r);
|
||||
credits = ads.rates().visitCostPerVisit || 3;
|
||||
credits = r.unit || ads.rates().visitCostPerVisit || 3; // the per-door price actually charged (door pack 4, Golden Door 6, a visit pack 3)
|
||||
if (t.golden && r.golden === false) t.golden = false; // the season closed between open and done: an ordinary door
|
||||
}
|
||||
t.done = true;
|
||||
const host = t.host || null;
|
||||
const house = t.kind === 'house' ? { house: true, program: t.program } : {}; // a house ad: credits 0, host null, campaignId 0
|
||||
const posted = await sdCallback(Object.assign({ nonce, memberId: t.memberId, campaignId: t.id, credits, host }, house));
|
||||
const receipt = sdMint(Object.assign({ kind: 'door-receipt', nonce, memberId: t.memberId, campaignId: t.id, credits, host }, house), 24 * 3600000);
|
||||
const gold = (t.kind === 'visit' && t.golden) ? { golden: true, bonus: t.bonus } : {}; // a Golden Door: the game adds `bonus` candy
|
||||
const posted = await sdCallback(Object.assign({ nonce, memberId: t.memberId, campaignId: t.id, credits, host }, house, gold));
|
||||
const receipt = sdMint(Object.assign({ kind: 'door-receipt', nonce, memberId: t.memberId, campaignId: t.id, credits, host }, house, gold), 24 * 3600000);
|
||||
t.doneRet = sdJoin(t.ret, 'ok=1&r=' + encodeURIComponent(receipt));
|
||||
doorTokens.set(nonce, t);
|
||||
return json(res, 200, Object.assign({ ok: true, posted, host, ret: t.doneRet }, house));
|
||||
return json(res, 200, Object.assign({ ok: true, posted, host, credits, ret: t.doneRet }, house, gold));
|
||||
}
|
||||
// -- Games hub (2026-10-01): the registry is here, the live list is site config (gamesLive)
|
||||
if (p === '/api/my/games' && req.method === 'GET') {
|
||||
@@ -2891,8 +2915,8 @@ const server = http.createServer(async (req, res) => {
|
||||
const dayLabel = (d, back) => { const t = new Date(d + 'T12:00:00Z'); if (back) t.setUTCDate(t.getUTCDate() - 1); return t.toLocaleDateString('en-US', { month: 'short', day: 'numeric', timeZone: 'UTC' }); };
|
||||
for (const g of GAMES()) {
|
||||
// a seasonal game (2026-10-02) shows only while today (Central) is in [start, end); before start the admin sees a preview, after end nobody
|
||||
let seasonPreview = false;
|
||||
if (g.season) { if (day >= g.season.end) continue; if (day < g.season.start) { if (!admin) continue; seasonPreview = true; } }
|
||||
const ss = seasonState(g.season, day, admin); if (ss === 'hidden') continue;
|
||||
const seasonPreview = ss === 'preview';
|
||||
const isLive = live.has(g.slug); if (!isLive && !admin) continue;
|
||||
const card = Object.assign({}, g, { live: isLive, preview: !isLive || seasonPreview });
|
||||
if (g.season) { card.season = Object.assign({}, g.season, { opens: dayLabel(g.season.start), ends: dayLabel(g.season.end, true) }); if (seasonPreview) card.previewNote = 'preview, opens ' + card.season.opens; }
|
||||
@@ -3516,6 +3540,7 @@ const server = http.createServer(async (req, res) => {
|
||||
out.clickSources = await coach.clickSources(ids);
|
||||
out.hours = await ads.hoursFor(ids); // on-site views per UTC hour, last 7 days
|
||||
out.geo = await ads.geoFor(ids); // on-site serves per viewer country
|
||||
out.doorStats = await ads.doorStats(all.filter(c => c.type === 'visits').map(c => c.id)); // Spooky Doors: doors opened + unique players per pack
|
||||
{ const t = geo.tierLists(siteConfig()); out.tiers = { t1: [...t.t1], t2: [...t.t2] }; out.geoReady = geo.status().loaded; }
|
||||
const pool = await ads.balances((await myMemberIds(s)).ids, s.email);
|
||||
out.purchasedCredits = pool.total;
|
||||
|
||||
Reference in New Issue
Block a user