Files
instantadpay/tools/patch_game_strip.py
T

48 lines
4.2 KiB
Python

# Cross-promo strip (Marty, 2026-10-03: "cross-promote the other games from inside each game", Spooky Doors included now).
# /api/public/games = the live list (CORS *), /g/<slug>?from=<game> = counted hop (Traffic tab: host = the sending game,
# path g/<slug>) that lands a signed-in member straight in the game through the usual hand-off, else on the game's own page.
ROOT = 'D:/Projects/HighRisk/onchain-ad-membership/site/'
def edit(path, pairs):
b = open(ROOT + path, 'rb').read(); crlf = b.count(b'\r\n') > b.count(b'\n') // 2
s = b.decode('utf-8').replace('\r\n', '\n')
for a, r in pairs:
if s.count(a) != 1: raise SystemExit('%s anchor %d: %s' % (path, s.count(a), a[:70]))
s = s.replace(a, r)
if crlf: s = s.replace('\n', '\r\n')
open(ROOT + path, 'wb').write(s.encode('utf-8')); print('patched', path)
HELP = r"""// -- cross-promo strip (2026-10-03): one short line per game and where a signed-out player lands (the game's own page)
const STRIP = () => ({
spookydoors: { line: 'Halloween only. Run the graveyard, knock on doors, climb the candy ladder to POL.', open: SD_URL() + '/play', host: SD_URL().replace(/^https?:\/\//, '') },
driprunner: { line: 'Hop, dodge the bots, clear chapters. Every first clear drips POL.', open: DR_URL() + '/play', host: DR_URL().replace(/^https?:\/\//, '') },
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' },
});
// live for the strip: in gamesLive, and a seasonal game until its season ends (Marty 2026-10-03: Spooky Doors may show before
// its formal announcement; "if someone manages to see it and play it, that's fine")
function stripGames() {
const sc = siteConfig(); const live = new Set(String(sc.gamesLive == null ? 'polhunter' : sc.gamesLive).split(',').map(x => x.trim().toLowerCase()).filter(Boolean));
const day = todayCT(), S = STRIP(); const lbl = d => { const t = new Date(d + 'T12:00:00Z'); t.setUTCDate(t.getUTCDate() - 1); return t.toLocaleDateString('en-US', { month: 'short', day: 'numeric', timeZone: 'UTC' }); };
return GAMES().filter(g => live.has(g.slug) && S[g.slug] && !(g.season && day >= g.season.end))
.map(g => ({ slug: g.slug, name: g.name, tag: g.season ? 'Limited time \u00b7 ends ' + lbl(g.season.end) : g.tag, line: S[g.slug].line, art: g.art, artPos: g.artPos || 'center', seasonal: !!g.season }));
}
"""
ROUTES = r""" // -- cross-promo strip (2026-10-03): the list every game reads, and the counted hop between games
if (p === '/api/public/games' && req.method === 'GET') return json(res, 200, { games: stripGames() }, { 'Access-Control-Allow-Origin': '*', 'Cache-Control': 'public, max-age=300' });
{ const mg = /^\/g\/([a-z]{3,20})$/.exec(p); if (mg && req.method === 'GET') {
const g = GAMES().find(x => x.slug === mg[1]); const S = STRIP()[mg[1]];
if (!g || !S) { res.writeHead(302, { Location: '/my#games', 'Cache-Control': 'no-store' }); return res.end(); }
const from = String(u.searchParams.get('from') || '').toLowerCase().replace(/[^a-z]/g, '').slice(0, 20); const src = STRIP()[from];
traffic.hit('/g/' + g.slug, req.headers.referer || (src ? 'https://' + src.host + '/' : ''), req.headers['user-agent']); // Traffic tab: host = sending game, path g/<slug>
const s = await auth.fromRequest(req);
res.writeHead(302, { Location: (s && s.email) ? g.play : S.open, 'Cache-Control': 'no-store' }); return res.end(); // signed in here: straight into the game, signed in
} }
"""
edit('server.js', [
("// -- PassiveDrip hand-off (2026-10-01): same token shape as Drip Runner", HELP + "// -- PassiveDrip hand-off (2026-10-01): same token shape as Drip Runner"),
(" // -- Games hub (2026-10-01): the registry is here, the live list is site config (gamesLive)\n", ROUTES + " // -- Games hub (2026-10-01): the registry is here, the live list is site config (gamesLive)\n"),
("pays: 'POL to your wallet at 0.25', progress: drProgress }", "pays: 'POL to your wallet at 0.10', progress: drProgress }"),
])
print('ok')