PolyBreak on the network rails (hand-off, in-game sign-in, one-more-paddle refuel receipts, Games card, strip line, return routing) + Promo tools PolyBreak card, 600x300 traffic-exchange size for every game and InstantAdPay's own 600x300 banner
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1376,6 +1376,26 @@ function swOpen(token) {
|
||||
return { ok: true, claims: c };
|
||||
}
|
||||
const swIsGameUrl = u => [SW_URL()].concat(SW_ALT()).some(o => String(u || '').startsWith(o + '/'));
|
||||
// -- PolyBreak (2026-10-13): the brick breaker; its own secret PB_SSO_SECRET (also on the game), same shape as SpellWheel
|
||||
const PB_SECRET = () => String(process.env.PB_SSO_SECRET || '').trim();
|
||||
const PB_URL = () => String(process.env.PB_URL || 'https://polybreak.app').replace(/\/+$/, '');
|
||||
const PB_ALT = () => String(process.env.PB_ALT_URLS || 'https://www.polybreak.app,https://polybreak.saasy.top').split(',').map(x => x.trim().replace(/\/+$/, '')).filter(Boolean);
|
||||
const pbSign = p => drB64u(crypto.createHmac('sha256', PB_SECRET()).update(p).digest());
|
||||
function pbMint(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) + '.' + pbSign(payload); }
|
||||
function pbOpen(token) {
|
||||
if (PB_SECRET().length < 32) return { error: 'PolyBreak is not connected yet.' };
|
||||
const [p, sig] = String(token || '').split('.'); if (!p || !sig) return { error: 'That link is not valid.' };
|
||||
let payload; try { payload = Buffer.from(String(p).replace(/-/g, '+').replace(/_/g, '/'), 'base64').toString('utf8'); } catch (e) { return { error: 'That link is not valid.' }; }
|
||||
const want = pbSign(payload); if (want.length !== sig.length || !crypto.timingSafeEqual(Buffer.from(want), Buffer.from(sig))) return { error: 'That link is not valid.' };
|
||||
let c; try { c = JSON.parse(payload); } catch (e) { return { error: 'That link is not valid.' }; }
|
||||
if (!c.exp || Date.now() > c.exp) return { error: 'That link has expired. Go back to PolyBreak and tap One more paddle again.' };
|
||||
return { ok: true, claims: c };
|
||||
}
|
||||
const pbIsGameUrl = u => [PB_URL()].concat(PB_ALT()).some(o => String(u || '').startsWith(o + '/'));
|
||||
async function pbCallback(cbUrl, receipt) {
|
||||
if (!pbIsGameUrl(cbUrl)) return false;
|
||||
try { const r = await fetch(cbUrl, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ t: receipt }), signal: AbortSignal.timeout(8000) }); return r.ok; } catch (e) { console.warn('polybreak callback', e.message); return false; }
|
||||
}
|
||||
// -- PolyWarriors (2026-10-05): the cyberpunk fighting game at polywarriors.com; its own secret PW_SSO_SECRET (also on the game)
|
||||
const PW_SECRET = () => String(process.env.PW_SSO_SECRET || '').trim();
|
||||
const PW_URL = () => String(process.env.PW_URL || 'https://polywarriors.com').replace(/\/+$/, '');
|
||||
@@ -1568,6 +1588,9 @@ function GAMES() {
|
||||
// PolyWarriors (Marty 2026-10-05: "put Poly Warriors there as well, saying that it's coming next Monday")
|
||||
{ slug: 'polywarriors', name: 'PolyWarriors', tag: 'Cyberpunk fighting', blurb: 'Turn-based fights with collectible low-poly warriors. Recruit fighters born with rare traits, climb the arena, challenge other members, and mint your warriors as NFTs.',
|
||||
art: 'https://coolify-saasytop.nyc3.digitaloceanspaces.com/promo/polywarriors-trailer.jpg', video: 'https://coolify-saasytop.nyc3.digitaloceanspaces.com/promo/polywarriors-trailer.mp4', play: '/api/my/polywarriors', pays: 'POL for first wins over arena rivals', soon: { opens: '2026-10-12', label: 'Opens Monday, Oct 12' } }, // live 10-12: trailer poster + 16:9 trailer on the public games page
|
||||
// PolyBreak (2026-10-13): the brick breaker; first round clears and the purple Polygon gem pay POL
|
||||
{ slug: 'polybreak', name: 'PolyBreak', tag: 'Brick breaker', blurb: 'Break walls of glass jewel bricks with the classic arcade capsules, and catch the purple Polygon gem when it falls. First clears of each round pay POL.',
|
||||
art: 'https://banners.adrotate.xyz/game-banners/polybreak/og-polybreak-clean.jpg', play: '/api/my/polybreak', pays: 'POL for first round clears and gem catches' },
|
||||
]);
|
||||
}
|
||||
// each game's member perk (the $5 welcome offer, 2026-10-05) shown on its card
|
||||
@@ -1580,6 +1603,7 @@ const STRIP = () => ({
|
||||
gemkingdom: { line: 'Match gems, beat the bosses, rebuild your kingdom. First clears pay POL.', open: GK_URL() + '/play', host: GK_URL().replace(/^https?:\/\//, '') },
|
||||
polhunter: { line: 'Find hidden codes on sites across the network. Every find drips POL.', open: 'https://polhunter.com/', host: 'polhunter.com' },
|
||||
clutterhunt: { line: 'Search cozy, cluttered rooms for hidden objects. New rooms every season.', open: SEEK_URL() + '/', host: SEEK_URL().replace(/^https?:\/\//, '') },
|
||||
polybreak: { line: 'Break the glass jewel wall, catch the capsules and the purple Polygon gem. First clears pay POL.', open: PB_URL() + '/', host: PB_URL().replace(/^https?:\/\//, '') },
|
||||
spellwheel: { line: 'Swipe the letter wheel, fill the grid, solve the daily puzzle. Levels and dailies pay POL.', open: SW_URL() + '/', host: SW_URL().replace(/^https?:\/\//, '') },
|
||||
polywarriors: { line: 'Recruit one-of-a-kind warriors, fight the arena, challenge members. First wins pay POL.', open: PW_URL() + '/', host: PW_URL().replace(/^https?:\/\//, '') },
|
||||
});
|
||||
@@ -1644,6 +1668,8 @@ const GAME_AUTH = {
|
||||
sponsorRef: a.sponsorRef || null, joinedRef: a.joinedRef || null, joinedAt: a.created || null }) },
|
||||
seek: { name: 'ClutterHunt', origins: () => [SEEK_URL()].concat(SEEK_ALT()), host: () => SEEK_URL().replace(/^https?:\/\//, ''),
|
||||
mint: (a, memberId) => seekMint({ memberId: Number(memberId) || 0, email: String(a.email).toLowerCase(), username: a.username || null, wallet: a.address || null }) },
|
||||
polybreak: { name: 'PolyBreak', origins: () => [PB_URL()].concat(PB_ALT()), host: () => PB_URL().replace(/^https?:\/\//, ''),
|
||||
mint: (a, memberId) => pbMint({ memberId: Number(memberId) || 0, email: String(a.email).toLowerCase(), username: a.username || null, wallet: a.address || null, sponsorRef: a.sponsorRef || null }) },
|
||||
spellwheel: { name: 'SpellWheel', origins: () => [SW_URL()].concat(SW_ALT()), host: () => SW_URL().replace(/^https?:\/\//, ''),
|
||||
mint: (a, memberId) => swMint({ memberId: Number(memberId) || 0, email: String(a.email).toLowerCase(), username: a.username || null, wallet: a.address || null }) },
|
||||
polywarriors: { name: 'PolyWarriors', origins: () => [PW_URL()].concat(PW_ALT()), host: () => PW_URL().replace(/^https?:\/\//, ''),
|
||||
@@ -2079,7 +2105,7 @@ const server = http.createServer(async (req, res) => {
|
||||
let memberId = 0;
|
||||
if (r.account.address) { try { memberId = await chain.memberIdByAccount(r.account.address); } catch (err) {} }
|
||||
const token = await auth.mintSession({ email: r.account.email, address: r.account.address, memberId });
|
||||
return json(res, 200, { ok: true, account: r.account, created: !!r.created, next: ({ clutterhunt: '/api/my/clutterhunt', spellwheel: '/api/my/spellwheel', polywarriors: '/api/my/polywarriors', driprunner: '/api/my/driprunner', passivedrip: '/api/my/passivedrip', gemkingdom: '/api/my/gemkingdom', gkshop: '/gk/shop/resume', spookydoors: '/api/my/spookydoors', sdshop: '/sd/shop/resume' })[parseCookies(req)['iap.return']] || null }, { 'Set-Cookie': auth.sessionCookie(token) }); // next: Drip Runner sent them here to sign in (2026-09-30)
|
||||
return json(res, 200, { ok: true, account: r.account, created: !!r.created, next: ({ clutterhunt: '/api/my/clutterhunt', spellwheel: '/api/my/spellwheel', polybreak: '/api/my/polybreak', polywarriors: '/api/my/polywarriors', driprunner: '/api/my/driprunner', passivedrip: '/api/my/passivedrip', gemkingdom: '/api/my/gemkingdom', gkshop: '/gk/shop/resume', spookydoors: '/api/my/spookydoors', sdshop: '/sd/shop/resume' })[parseCookies(req)['iap.return']] || null }, { 'Set-Cookie': auth.sessionCookie(token) }); // next: Drip Runner sent them here to sign in (2026-09-30)
|
||||
}
|
||||
|
||||
// -- in-game sign-in (2026-10-03): see GAME_AUTH. Mirrors /api/auth/email/start + verify, minus cookies.
|
||||
@@ -2248,7 +2274,7 @@ const server = http.createServer(async (req, res) => {
|
||||
const _defSpon = Number(siteConfig().defaultSponsorId) || 1;
|
||||
if (!sponsorId && memberId !== _defSpon) sponsorId = _defSpon; // orphan fallback → #1 (never self-sponsor)
|
||||
if (memberId && acct && acct.memberId !== memberId) accounts.setMemberId(acct.email, memberId).catch(() => {});
|
||||
const out = { signedIn: true, gkShop: !!parseCookies(req)['iap.gkshop'], sdShop: !!parseCookies(req)['iap.sdshop'], pwMint: !!parseCookies(req)['iap.pwmint'], returnTo: ['polhunter', 'driprunner', 'passivedrip', 'gemkingdom', 'gkshop', 'spookydoors', 'sdshop', 'pwmint'].includes(parseCookies(req)['iap.return']) ? parseCookies(req)['iap.return'] : null, sponsorBlocked, sponsorRouted, sponsorName: spdMe.name || null, email: s.email || (acct && acct.email) || null,
|
||||
const out = { signedIn: true, gkShop: !!parseCookies(req)['iap.gkshop'], sdShop: !!parseCookies(req)['iap.sdshop'], pwMint: !!parseCookies(req)['iap.pwmint'], returnTo: ['polhunter', 'driprunner', 'passivedrip', 'gemkingdom', 'gkshop', 'spookydoors', 'sdshop', 'pwmint', 'polybreak'].includes(parseCookies(req)['iap.return']) ? parseCookies(req)['iap.return'] : null, sponsorBlocked, sponsorRouted, sponsorName: spdMe.name || null, email: s.email || (acct && acct.email) || null,
|
||||
address: s.address || (acct && acct.address) || null, memberId,
|
||||
username: (acct && acct.username) || null,
|
||||
refCode: (acct && acct.code) || null, sponsorId,
|
||||
@@ -3034,6 +3060,14 @@ const server = http.createServer(async (req, res) => {
|
||||
res.writeHead(302, { Location: PW_URL() + '/auth?t=' + tok, 'Cache-Control': 'no-store', 'Set-Cookie': gkCookie('iap.return', '', 0) }); return res.end();
|
||||
}
|
||||
// -- SpellWheel hand-off (2026-10-04): sign the member across; the game verifies with SW_SSO_SECRET
|
||||
if (p === '/api/my/polybreak' && req.method === 'GET') { gamestats.handoff('polybreak');
|
||||
const s = await auth.fromRequest(req);
|
||||
if (!s || !s.email) { res.writeHead(302, { Location: '/my' + refQ(u), 'Set-Cookie': gkCookie('iap.return', 'polybreak', 1800), 'Cache-Control': 'no-store' }); return res.end(); }
|
||||
if (PB_SECRET().length < 32) return json(res, 503, { error: 'PolyBreak is not connected yet.' });
|
||||
const acct = await accounts.byEmail(s.email);
|
||||
const tok = pbMint({ memberId: Number((acct && acct.memberId) || s.memberId || 0), email: String(s.email).toLowerCase(), username: (acct && acct.username) || null, wallet: (acct && acct.address) || null, sponsorRef: (acct && acct.sponsorRef) || null });
|
||||
res.writeHead(302, { Location: PB_URL() + '/auth?t=' + tok, 'Cache-Control': 'no-store', 'Set-Cookie': gkCookie('iap.return', '', 0) }); return res.end();
|
||||
}
|
||||
if (p === '/api/my/spellwheel' && req.method === 'GET') { gamestats.handoff('spellwheel');
|
||||
const s = await auth.fromRequest(req);
|
||||
if (!s || !s.email) { res.writeHead(302, { Location: '/my' + refQ(u), 'Set-Cookie': gkCookie('iap.return', 'spellwheel', 1800), 'Cache-Control': 'no-store' }); return res.end(); }
|
||||
@@ -3295,12 +3329,14 @@ const server = http.createServer(async (req, res) => {
|
||||
if (r.error) { const g = gkOpen(u.searchParams.get('t')); if (!g.error && g.claims.game === 'gemkingdom') { r = g; game = 'gemkingdom'; } }
|
||||
if (r.error) { const g = seekOpen(u.searchParams.get('t')); if (!g.error && g.claims.game === 'seek') { r = g; game = 'seek'; } }
|
||||
if (r.error) { const g = swOpen(u.searchParams.get('t')); if (!g.error && g.claims.game === 'spellwheel') { r = g; game = 'spellwheel'; } }
|
||||
if (r.error) { const g = pbOpen(u.searchParams.get('t')); if (!g.error && g.claims.game === 'polybreak') { r = g; game = 'polybreak'; } }
|
||||
if (r.error) return json(res, 400, { error: r.error });
|
||||
const c = r.claims; if (c.kind !== 'refuel' || !c.nonce || !c.email || !c.ret) return json(res, 400, { error: 'That is not a refuel link.' });
|
||||
if (game === 'gemkingdom' && !String(c.ret).startsWith(GK_URL() + '/')) return json(res, 400, { error: 'That is not a Gem Kingdom link.' });
|
||||
if (game === 'seek' && !seekIsGameUrl(c.ret)) return json(res, 400, { error: 'That is not a ClutterHunt link.' });
|
||||
if (game === 'spellwheel' && !swIsGameUrl(c.ret)) return json(res, 400, { error: 'That is not a SpellWheel link.' });
|
||||
const G = game === 'gemkingdom' ? { game: 'Gem Kingdom', label: 'continue' } : game === 'seek' ? { game: 'ClutterHunt', label: 'hint' } : game === 'spellwheel' ? { game: 'SpellWheel', label: 'hint' } : { game: 'Drip Runner', label: 'refuel' };
|
||||
if (game === 'polybreak' && !pbIsGameUrl(c.ret)) return json(res, 400, { error: 'That is not a PolyBreak link.' });
|
||||
const G = game === 'polybreak' ? { game: 'PolyBreak', label: 'one more paddle' } : game === 'gemkingdom' ? { game: 'Gem Kingdom', label: 'continue' } : game === 'seek' ? { game: 'ClutterHunt', label: 'hint' } : game === 'spellwheel' ? { game: 'SpellWheel', label: 'hint' } : { game: 'Drip Runner', label: 'refuel' };
|
||||
for (const [n, v] of refuelTokens) if (v.ts + 30 * 60000 < Date.now()) refuelTokens.delete(n);
|
||||
let t = refuelTokens.get(c.nonce);
|
||||
if (t && t.done) return json(res, 200, Object.assign({ done: true, ret: t.doneRet || t.ret }, G));
|
||||
@@ -3343,12 +3379,18 @@ const server = http.createServer(async (req, res) => {
|
||||
if (!tier) return json(res, 400, { error: 'That video just ran out of budget. Go back and try again.' });
|
||||
await ads.markVideoSeen(t.email, t.id); credits = tier.cost;
|
||||
} else {
|
||||
const r = await ads.completeVisit(t.email, t.id, { reward: false, note: t.game === 'gemkingdom' ? 'Gem Kingdom continue' : t.game === 'seek' ? 'ClutterHunt hint' : t.game === 'spellwheel' ? 'SpellWheel hint' : 'Drip Runner refuel' });
|
||||
const r = await ads.completeVisit(t.email, t.id, { reward: false, note: t.game === 'polybreak' ? 'PolyBreak paddle' : t.game === 'gemkingdom' ? 'Gem Kingdom continue' : t.game === 'seek' ? 'ClutterHunt hint' : t.game === 'spellwheel' ? 'SpellWheel hint' : 'Drip Runner refuel' });
|
||||
if (r.error) return json(res, 400, r);
|
||||
credits = ads.rates().visitCostPerVisit || 3;
|
||||
{ const camp = await ads.campaignById(t.id).catch(() => null); if (camp && camp.house) credits = 0; } // a house ad costs nobody anything: no POL pool income (2026-10-03)
|
||||
}
|
||||
t.done = true;
|
||||
if (t.game === 'polybreak') { // PolyBreak one more paddle: signed receipt to the game's callback and on the ret page
|
||||
const receipt = pbMint({ kind: 'pb-paddle', nonce, email: t.email, campaignId: t.id, credits }, 15 * 60000);
|
||||
const posted = await pbCallback(t.cb, receipt);
|
||||
t.doneRet = t.ret + (t.ret.includes('?') ? '&' : '?') + 'ok=1&r=' + encodeURIComponent(receipt);
|
||||
return json(res, 200, { ok: true, posted, ret: t.doneRet, game: 'PolyBreak', label: 'one more paddle' });
|
||||
}
|
||||
if (t.game === 'spellwheel') { // SpellWheel hint: signed receipt to the game's callback and on the ret page
|
||||
const receipt = swMint({ kind: 'sw-hint', nonce, email: t.email, campaignId: t.id, credits }, 15 * 60000);
|
||||
const posted = await swCallback(t.cb, receipt);
|
||||
|
||||
Reference in New Issue
Block a user