In-game sign-in: /signin runs the InstantAdPay kit (no trip to InstantAdPay), CSP admits instantadpay.com, dashboard and Level up links open InstantAdPay signed in

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-10-03 10:02:47 -05:00
parent dd00cb1b57
commit 9c693fcf63
7 changed files with 95 additions and 10 deletions
+2 -2
View File
@@ -47,7 +47,7 @@
<h1>Hop the network.<br><em>Get paid in POL.</em></h1> <h1>Hop the network.<br><em>Get paid in POL.</em></h1>
<p class="lead">A fast little runner game for InstantAdPay members. Grab gold drips, dodge the bots, clear chapters. Your first clear of every chapter drips POL into your game balance, and it pays out to the wallet on your InstantAdPay account.</p> <p class="lead">A fast little runner game for InstantAdPay members. Grab gold drips, dodge the bots, clear chapters. Your first clear of every chapter drips POL into your game balance, and it pays out to the wallet on your InstantAdPay account.</p>
<div class="cta"> <div class="cta">
<a class="btn" href="https://instantadpay.com/api/my/driprunner">Play with InstantAdPay</a> <a class="btn" href="/signin">Play with InstantAdPay</a>
<a class="btn ghost" href="/play">Try a run first</a> <a class="btn ghost" href="/play">Try a run first</a>
</div> </div>
<p class="muted">New to InstantAdPay? The first button signs you up free with just your email, then drops you straight into the game.</p> <p class="muted">New to InstantAdPay? The first button signs you up free with just your email, then drops you straight into the game.</p>
@@ -90,7 +90,7 @@
</div> </div>
<div class="cta" style="margin-top:26px"> <div class="cta" style="margin-top:26px">
<a class="btn" href="https://instantadpay.com/api/my/driprunner">Play with InstantAdPay</a> <a class="btn" href="/signin">Play with InstantAdPay</a>
<a class="btn ghost" href="/play">Try a run first</a> <a class="btn ghost" href="/play">Try a run first</a>
</div> </div>
<p class="fine">Drip Runner pays small amounts of POL for play that the game can verify. Amounts depend on the pool, which is funded by the ad visits players make, and can change. Nothing here is a promise of income. One account per person. Part of the Crypto Team Build Network, alongside InstantAdPay and PolHunter.</p> <p class="fine">Drip Runner pays small amounts of POL for play that the game can verify. Amounts depend on the pool, which is funded by the ad visits players make, and can change. Nothing here is a promise of income. One account per person. Part of the Crypto Team Build Network, alongside InstantAdPay and PolHunter.</p>
+1
View File
@@ -162,6 +162,7 @@ canvas#game{position:absolute;inset:0;width:100%;height:100%;display:block;touch
<button class="btn ghost" id="bLobby4" type="button">Back</button> <button class="btn ghost" id="bLobby4" type="button">Back</button>
</div></div> </div></div>
</div></div> </div></div>
<script src="https://instantadpay.com/assets/game-signin.js?v=20261003a" async></script>
<script src="/spawn.js"></script> <script src="/spawn.js"></script>
<script src="/play.js"></script> <script src="/play.js"></script>
</body> </body>
+6 -4
View File
@@ -59,9 +59,11 @@ function lobby() {
$('lChap').textContent = P.chapter; $('lDrips').textContent = P.bank.toLocaleString(); $('lPol').textContent = f3(BAL.unpaid); $('lChap').textContent = P.chapter; $('lDrips').textContent = P.bank.toLocaleString(); $('lPol').textContent = f3(BAL.unpaid);
$('lPool').innerHTML = 'POL pool <b>' + f3(POOL.available) + '</b> · today’s cap left <b>' + f3(POOL.capLeft) + '</b> · a chapter drip is <b>' + f3(POOL.dripPol) + '</b>'; $('lPool').innerHTML = 'POL pool <b>' + f3(POOL.available) + '</b> · today’s cap left <b>' + f3(POOL.capLeft) + '</b> · a chapter drip is <b>' + f3(POOL.dripPol) + '</b>';
$('lIap').href = IAP + '/my'; $('bLevel').href = IAP + '/my#buy'; tip('lTip'); $('lIap').href = IAP + '/my'; $('bLevel').href = IAP + '/my#buy'; tip('lTip');
// signed in through the game: these open InstantAdPay already signed in (in-game sign-in pass, 2026-10-03)
[['lIap', 'overview'], ['bLevel', 'buy']].forEach(function (x) { var a = $(x[0]); if (a && !a.dataset.pass) { a.dataset.pass = 1; a.addEventListener('click', function (ev) { if (window.IAPSignin && IAPSignin.hasPass()) { ev.preventDefault(); IAPSignin.enter(x[1]); } }); } });
if (ME.guest) { if (ME.guest) {
$('lMember').innerHTML = '<i class="no"></i>Playing as a guest · sign in to keep your progress and collect POL'; $('lMember').innerHTML = '<i class="no"></i>Playing as a guest · sign in to keep your progress and collect POL';
$('bSignin').hidden = false; $('bSignin').href = ME_EXTRA.signin || (IAP + '/api/my/driprunner'); $('lShare').hidden = true; $('bSignin').hidden = false; $('bSignin').href = ME_EXTRA.signin || '/signin'; $('lShare').hidden = true;
} else { } else {
$('lMember').innerHTML = '<i class="' + (ME.wallet ? '' : 'no') + '"></i>InstantAdPay · ' + (ME.username ? '@' + ME.username : '#' + ME.memberId) + ' · ' + (ME.wallet ? ME.wallet.slice(0, 6) + '…' + ME.wallet.slice(-4) : 'no wallet on file'); $('lMember').innerHTML = '<i class="' + (ME.wallet ? '' : 'no') + '"></i>InstantAdPay · ' + (ME.username ? '@' + ME.username : '#' + ME.memberId) + ' · ' + (ME.wallet ? ME.wallet.slice(0, 6) + '…' + ME.wallet.slice(-4) : 'no wallet on file');
$('bSignin').hidden = true; $('bSignin').hidden = true;
@@ -143,7 +145,7 @@ function cleared() {
$('cBig').innerHTML = '+' + f3(c.pol) + '<small>POL</small>'; $('cBig').classList.toggle('dim', !c.pol); $('cBig').innerHTML = '+' + f3(c.pol) + '<small>POL</small>'; $('cBig').classList.toggle('dim', !c.pol);
var why = { paid: 'First clear, verified. Added to your game balance.', replay: c.first ? 'Verified.' : 'You cleared this one before. Only the first clear pays.', pool: 'The POL pool is empty right now. Refuel visits fill it, so this clear counts but pays nothing.', cap: 'Today’s pool cap is spent. Chapter counts, no POL today.', flagged: 'This run was flagged by the server check, so it pays nothing.', guest: 'You are playing as a guest. Sign in with InstantAdPay and this clear pays ' + f3(POOL.dripPol) + ' POL into your balance. Your progress comes with you.' }; var why = { paid: 'First clear, verified. Added to your game balance.', replay: c.first ? 'Verified.' : 'You cleared this one before. Only the first clear pays.', pool: 'The POL pool is empty right now. Refuel visits fill it, so this clear counts but pays nothing.', cap: 'Today’s pool cap is spent. Chapter counts, no POL today.', flagged: 'This run was flagged by the server check, so it pays nothing.', guest: 'You are playing as a guest. Sign in with InstantAdPay and this clear pays ' + f3(POOL.dripPol) + ' POL into your balance. Your progress comes with you.' };
$('bShareClear').hidden = !!ME.guest || !ME_EXTRA.share; $('bShareClear').dataset.text = 'I just cleared Chapter ' + c.chapter + ' in Drip Runner' + (c.pol ? ' and it paid ' + f3(c.pol) + ' POL' : '') + '. Hop the network, dodge the bots:'; $('bShareClear').hidden = !!ME.guest || !ME_EXTRA.share; $('bShareClear').dataset.text = 'I just cleared Chapter ' + c.chapter + ' in Drip Runner' + (c.pol ? ' and it paid ' + f3(c.pol) + ' POL' : '') + '. Hop the network, dodge the bots:';
$('bClearSignin').hidden = !ME.guest; if (ME.guest) $('bClearSignin').href = ME_EXTRA.signin || (IAP + '/api/my/driprunner'); $('bClearSignin').hidden = !ME.guest; if (ME.guest) $('bClearSignin').href = ME_EXTRA.signin || '/signin';
$('cText').textContent = why[c.reason] || ''; $('cChip').className = 'chip ' + (c.pol ? 'ok' : 'sig'); $('cChip').textContent = (c.pol ? 'verified' : c.reason) + ' · ' + tm + ' play time'; $('cText').textContent = why[c.reason] || ''; $('cChip').className = 'chip ' + (c.pol ? 'ok' : 'sig'); $('cChip').textContent = (c.pol ? 'verified' : c.reason) + ' · ' + tm + ' play time';
R.chapter = c.next; R.goal = c.nextGoal; R.chapDrips = 0; if (r.pool != null) POOL.available = r.pool; R.chapter = c.next; R.goal = c.nextGoal; R.chapDrips = 0; if (r.pool != null) POOL.available = r.pool;
tip('cTip'); setTimeout(function () { show('ovClear'); }, 500); tip('cTip'); setTimeout(function () { show('ovClear'); }, 500);
@@ -165,7 +167,7 @@ function snapshot(nonce) {
} }
$('bRefuel').addEventListener('click', function () { $('bRefuel').addEventListener('click', function () {
if (!R) return; if (!R) return;
if (ME.guest) { location.href = ME_EXTRA.signin || (IAP + '/api/my/driprunner'); return; } // guests sign in first; their progress follows them if (ME.guest) { location.href = ME_EXTRA.signin || '/signin'; return; } // guests sign in first; their progress follows them
$('bRefuel').disabled = true; $('bRefuel').disabled = true;
api('/api/refuel/start', { runId: R.id }).then(function (r) { api('/api/refuel/start', { runId: R.id }).then(function (r) {
$('bRefuel').disabled = false; $('bRefuel').disabled = false;
@@ -252,7 +254,7 @@ loadMe().then(function () {
if (q.get('collected')) { history.replaceState(null, '', '/play'); setTimeout(function () { toast('Signed in. Your guest clears paid ' + q.get('collected') + ' drip' + (q.get('collected') === '1' ? '' : 's') + ' into your balance.'); }, 600); } if (q.get('collected')) { history.replaceState(null, '', '/play'); setTimeout(function () { toast('Signed in. Your guest clears paid ' + q.get('collected') + ' drip' + (q.get('collected') === '1' ? '' : 's') + ' into your balance.'); }, 600); }
lobby(); lobby();
}).catch(function (r) { }).catch(function (r) {
var b = $('loadBtn'); b.hidden = false; b.href = (r && (r.signin || r.iap)) || IAP + '/api/my/driprunner'; var b = $('loadBtn'); b.hidden = false; b.href = (r && (r.signin || r.iap)) || '/signin';
if (r && r.guestOk) { // came through a share or tester link: play first, sign in later if (r && r.guestOk) { // came through a share or tester link: play first, sign in later
$('loadTitle').textContent = 'Ready to run'; $('loadText').textContent = 'Play a run right now, no sign-in. Sign in with InstantAdPay when you want to keep your progress, refuel, and collect POL.'; $('loadTitle').textContent = 'Ready to run'; $('loadText').textContent = 'Play a run right now, no sign-in. Sign in with InstantAdPay when you want to keep your progress, refuel, and collect POL.';
b.textContent = 'Sign in with InstantAdPay'; b.className = 'btn ghost'; var g = $('loadGuest'); g.hidden = false; b.textContent = 'Sign in with InstantAdPay'; b.className = 'btn ghost'; var g = $('loadGuest'); g.hidden = false;
+28
View File
@@ -0,0 +1,28 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover">
<meta name="robots" content="noindex,nofollow">
<title>Sign in · Drip Runner</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Orbitron:wght@600;800;900&family=Manrope:wght@400;600;800&display=swap">
<link rel="stylesheet" href="/site.css">
<style>
html{background:#050912}
.si{max-width:420px;margin:0 auto;padding-top:36px;display:grid;gap:18px}
.si .logo{font-size:30px;text-align:center}
.si .card{--si-accent:var(--cyan);--si-accent-ink:#04121a;--si-ink:var(--ink);--si-muted:var(--ink2);--si-field:rgba(5,9,18,.6);--si-line:var(--line);--si-font:var(--body);--si-bad:#ff7a9c}
.si .card h2{margin:0}
.si .back{text-align:center;font-size:14px}.si .back a{color:var(--muted)}
</style>
</head>
<body>
<main class="si">
<a href="/" style="text-decoration:none"><p class="logo">Drip <span>Runner</span></p></a>
<section class="card" id="iapSignin"><p>Loading sign-in…</p></section>
<p class="back"><a href="/play">Keep playing as a guest</a></p>
</main>
<script src="https://instantadpay.com/assets/game-signin.js?v=20261003a"></script>
<script src="/signin.js"></script>
</body>
</html>
+8
View File
@@ -0,0 +1,8 @@
// In-game sign-in (2026-10-03): the InstantAdPay kit runs on this page, so a player signs in (or opens a free
// InstantAdPay account) without leaving Drip Runner. The kit hands back the game token; /auth opens it as before.
(function () {
var box = document.getElementById('iapSignin');
if (!window.IAPSignin) { box.innerHTML = '<p>Sign-in could not load. <a href="https://instantadpay.com/api/my/driprunner" style="color:var(--cyan)">Sign in on InstantAdPay instead</a>.</p>'; return; }
var m = /(?:^|;\s*)dr\.ref=([^;]+)/.exec(document.cookie || ''); // the share link a guest arrived on: their sponsor
IAPSignin.mount(box, { game: 'driprunner', ref: m ? decodeURIComponent(m[1]) : '', title: 'Sign in to run', oneTap: IAPSignin.origin + '/api/my/driprunner' });
})();
+6 -4
View File
@@ -102,7 +102,8 @@ async function notify(kind, p) {
// ---- helpers --------------------------------------------------------------------------------- // ---- helpers ---------------------------------------------------------------------------------
const TYPES = { '.html': 'text/html; charset=utf-8', '.css': 'text/css', '.js': 'application/javascript', '.png': 'image/png', '.jpg': 'image/jpeg', '.svg': 'image/svg+xml', '.ico': 'image/x-icon', '.json': 'application/json', '.webp': 'image/webp', '.mp4': 'video/mp4' }; const TYPES = { '.html': 'text/html; charset=utf-8', '.css': 'text/css', '.js': 'application/javascript', '.png': 'image/png', '.jpg': 'image/jpeg', '.svg': 'image/svg+xml', '.ico': 'image/x-icon', '.json': 'application/json', '.webp': 'image/webp', '.mp4': 'video/mp4' };
const CSP = "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; font-src 'self' https://fonts.gstatic.com; img-src 'self' data:; connect-src 'self'; frame-ancestors 'none'; form-action 'self'"; // instantadpay.com: the in-game sign-in kit (script), its API (connect) and the signed-in nudge form (form-action), 2026-10-03
const CSP = "default-src 'self'; script-src 'self' " + IAP + "; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; font-src 'self' https://fonts.gstatic.com; img-src 'self' data:; connect-src 'self' " + IAP + "; frame-ancestors 'none'; form-action 'self' " + IAP;
const SEC = { 'X-Content-Type-Options': 'nosniff', 'Referrer-Policy': 'strict-origin-when-cross-origin', 'X-Frame-Options': 'DENY', 'Content-Security-Policy': CSP }; const SEC = { 'X-Content-Type-Options': 'nosniff', 'Referrer-Policy': 'strict-origin-when-cross-origin', 'X-Frame-Options': 'DENY', 'Content-Security-Policy': CSP };
function json(res, code, body, extra) { res.writeHead(code, Object.assign({ 'Content-Type': 'application/json', 'Cache-Control': 'no-store' }, SEC, extra || {})); res.end(JSON.stringify(body)); } function json(res, code, body, extra) { res.writeHead(code, Object.assign({ 'Content-Type': 'application/json', 'Cache-Control': 'no-store' }, SEC, extra || {})); res.end(JSON.stringify(body)); }
function sendFile(res, file, extra) { function sendFile(res, file, extra) {
@@ -173,7 +174,7 @@ const server = http.createServer(async (req, res) => {
// ---- sign-in by hand-off (passes the curtain: the member already came through IAP) ---- // ---- sign-in by hand-off (passes the curtain: the member already came through IAP) ----
if (p === '/auth') { if (p === '/auth') {
const r = sso.verify(u.searchParams.get('t')); const r = sso.verify(u.searchParams.get('t'));
if (r.error) return page(res, 400, 'Sign-in did not work', '<p>' + esc(r.error) + '</p><p><a class="btn" href="' + IAP + '/api/my/driprunner">Try again from InstantAdPay</a></p>'); if (r.error) return page(res, 400, 'Sign-in did not work', '<p>' + esc(r.error) + '</p><p><a class="btn" href="/signin">Try again</a></p>');
if (!allowed(r.claims, req)) { console.log('hand-off refused: not a tester', r.claims.memberId, r.claims.username || '', String(r.claims.email || '').replace(/^(.).*(@.*)$/, '$1***$2')); notify('refused', { memberId: r.claims.memberId, username: r.claims.username, email: r.claims.email }).catch(() => {}); } if (!allowed(r.claims, req)) { console.log('hand-off refused: not a tester', r.claims.memberId, r.claims.username || '', String(r.claims.email || '').replace(/^(.).*(@.*)$/, '$1***$2')); notify('refused', { memberId: r.claims.memberId, username: r.claims.username, email: r.claims.email }).catch(() => {}); }
if (!allowed(r.claims, req)) { const keyMode = String(process.env.DR_SIGNUPS || ledger.settings().signups) === 'key'; return page(res, 403, keyMode ? 'Open the tester link first' : 'Not on the tester list yet', keyMode ? '<p>Drip Runner is in a closed trial. Open the tester link Marty sent you (the one with the key) in this same browser, then tap Open Drip Runner again. Your InstantAdPay account is ' + esc(r.claims.username ? '@' + r.claims.username : '#' + r.claims.memberId) + '.</p>' : '<p>Drip Runner is in a closed trial. Your InstantAdPay account (' + esc(r.claims.username ? '@' + r.claims.username : '#' + r.claims.memberId) + ') is not on the tester list. Ask Marty to add you.</p>'); } if (!allowed(r.claims, req)) { const keyMode = String(process.env.DR_SIGNUPS || ledger.settings().signups) === 'key'; return page(res, 403, keyMode ? 'Open the tester link first' : 'Not on the tester list yet', keyMode ? '<p>Drip Runner is in a closed trial. Open the tester link Marty sent you (the one with the key) in this same browser, then tap Open Drip Runner again. Your InstantAdPay account is ' + esc(r.claims.username ? '@' + r.claims.username : '#' + r.claims.memberId) + '.</p>' : '<p>Drip Runner is in a closed trial. Your InstantAdPay account (' + esc(r.claims.username ? '@' + r.claims.username : '#' + r.claims.memberId) + ') is not on the tester list. Ask Marty to add you.</p>'); }
const existing = sso.fromRequest(req); const existing = sso.fromRequest(req);
@@ -220,6 +221,7 @@ const server = http.createServer(async (req, res) => {
if (p === '/' || p === '/index.html') { if (curtained(req, res, u)) return; return sendFile(res, path.join(PUBLIC_DIR, 'index.html')); } if (p === '/' || p === '/index.html') { if (curtained(req, res, u)) return; return sendFile(res, path.join(PUBLIC_DIR, 'index.html')); }
if (p === '/testers') { if (curtained(req, res, u)) return; return sendFile(res, path.join(PUBLIC_DIR, 'testers.html')); } // the pre-launch briefing if (p === '/testers') { if (curtained(req, res, u)) return; return sendFile(res, path.join(PUBLIC_DIR, 'testers.html')); } // the pre-launch briefing
if (p === '/play') return sendFile(res, path.join(PUBLIC_DIR, 'play.html')); if (p === '/play') return sendFile(res, path.join(PUBLIC_DIR, 'play.html'));
if (p === '/signin') return sendFile(res, path.join(PUBLIC_DIR, 'signin.html')); // in-game sign-in (InstantAdPay kit)
if (p === '/admin') return sendFile(res, path.join(PUBLIC_DIR, 'admin.html')); // the page asks for the key; every /api/admin call checks it if (p === '/admin') return sendFile(res, path.join(PUBLIC_DIR, 'admin.html')); // the page asks for the key; every /api/admin call checks it
if (p === '/spawn.js') return sendFile(res, path.join(__dirname, 'lib', 'spawn.js')); if (p === '/spawn.js') return sendFile(res, path.join(__dirname, 'lib', 'spawn.js'));
if (/^\/(badges\/)?[a-z0-9._-]+\.(css|js|png|jpg|svg|ico|webp|mp4)$/i.test(p) && !p.includes('..')) return sendFile(res, path.join(PUBLIC_DIR, p.slice(1)), p.startsWith('/badges/') ? { 'Cache-Control': 'public, max-age=86400', 'Access-Control-Allow-Origin': '*' } : undefined); // badge art is also shown on InstantAdPay and in link previews if (/^\/(badges\/)?[a-z0-9._-]+\.(css|js|png|jpg|svg|ico|webp|mp4)$/i.test(p) && !p.includes('..')) return sendFile(res, path.join(PUBLIC_DIR, p.slice(1)), p.startsWith('/badges/') ? { 'Cache-Control': 'public, max-age=86400', 'Access-Control-Allow-Origin': '*' } : undefined); // badge art is also shown on InstantAdPay and in link previews
@@ -290,7 +292,7 @@ const server = http.createServer(async (req, res) => {
const g = sso.startGuest(refCookie(req)); return json(res, 200, { ok: true }, { 'Set-Cookie': sso.guestCookie(g.gid) }); const g = sso.startGuest(refCookie(req)); return json(res, 200, { ok: true }, { 'Set-Cookie': sso.guestCookie(g.gid) });
} }
const who = me || sso.guestFrom(req); const who = me || sso.guestFrom(req);
if (!who) return json(res, 401, { error: 'Sign in through InstantAdPay first.', iap: IAP + '/api/my/driprunner', guestOk: !CURTAIN || hasPass(req), signin: signinUrl(req) }); if (!who) return json(res, 401, { error: 'Sign in with your InstantAdPay account first.', iap: '/signin', guestOk: !CURTAIN || hasPass(req), signin: signinUrl(req) });
return memberApi(req, res, u, p, who); return memberApi(req, res, u, p, who);
} }
res.writeHead(404, Object.assign({ 'Content-Type': 'text/plain' }, SEC)); res.end('Not found'); res.writeHead(404, Object.assign({ 'Content-Type': 'text/plain' }, SEC)); res.end('Not found');
@@ -301,7 +303,7 @@ const server = http.createServer(async (req, res) => {
}); });
function refCookie(req) { const m = /(?:^|;\s*)dr\.ref=([^;]+)/.exec(req.headers.cookie || ''); const r = m ? decodeURIComponent(m[1]) : ''; return /^[a-z0-9_.-]{1,40}$/.test(r) ? r : null; } function refCookie(req) { const m = /(?:^|;\s*)dr\.ref=([^;]+)/.exec(req.headers.cookie || ''); const r = m ? decodeURIComponent(m[1]) : ''; return /^[a-z0-9_.-]{1,40}$/.test(r) ? r : null; }
// where a guest signs in: through the sharer's InstantAdPay join link when they came from one (new people land under the sharer), else the plain hand-off // where a guest signs in: through the sharer's InstantAdPay join link when they came from one (new people land under the sharer), else the plain hand-off
function signinUrl(req) { const r = refCookie(req); return r ? IAP + '/join/' + encodeURIComponent(r) + '?from=driprunner' : IAP + '/api/my/driprunner'; } function signinUrl(req) { return '/signin'; } // in-game sign-in (2026-10-03); the kit carries the dr.ref sponsor itself
async function memberApi(req, res, u, p, me) { async function memberApi(req, res, u, p, me) {
try { try {
{ {
+44
View File
@@ -0,0 +1,44 @@
# In-game sign-in (Marty, 2026-10-03): /signin is our own page running the InstantAdPay kit; every sign-in link
# points there; the CSP admits instantadpay.com for the kit script, its API calls and the nudge form.
ROOT = 'D:/Projects/HighRisk/drip-runner/'
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)
edit('server.js', [
("const CSP = \"default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; font-src 'self' https://fonts.gstatic.com; img-src 'self' data:; connect-src 'self'; frame-ancestors 'none'; form-action 'self'\";",
"// instantadpay.com: the in-game sign-in kit (script), its API (connect) and the signed-in nudge form (form-action), 2026-10-03\n"
"const CSP = \"default-src 'self'; script-src 'self' \" + IAP + \"; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; font-src 'self' https://fonts.gstatic.com; img-src 'self' data:; connect-src 'self' \" + IAP + \"; frame-ancestors 'none'; form-action 'self' \" + IAP;"),
("function signinUrl(req) { const r = refCookie(req); return r ? IAP + '/join/' + encodeURIComponent(r) + '?from=driprunner' : IAP + '/api/my/driprunner'; }",
"function signinUrl(req) { return '/signin'; } // in-game sign-in (2026-10-03); the kit carries the dr.ref sponsor itself"),
(" if (p === '/play') return sendFile(res, path.join(PUBLIC_DIR, 'play.html'));\n",
" if (p === '/play') return sendFile(res, path.join(PUBLIC_DIR, 'play.html'));\n"
" if (p === '/signin') return sendFile(res, path.join(PUBLIC_DIR, 'signin.html')); // in-game sign-in (InstantAdPay kit)\n"),
("res, 400, 'Sign-in did not work', '<p>' + esc(r.error) + '</p><p><a class=\"btn\" href=\"' + IAP + '/api/my/driprunner\">Try again from InstantAdPay</a></p>');",
"res, 400, 'Sign-in did not work', '<p>' + esc(r.error) + '</p><p><a class=\"btn\" href=\"/signin\">Try again</a></p>');"),
("return json(res, 401, { error: 'Sign in through InstantAdPay first.', iap: IAP + '/api/my/driprunner',",
"return json(res, 401, { error: 'Sign in with your InstantAdPay account first.', iap: '/signin',"),
])
edit('public/play.js', [
(" $('lIap').href = IAP + '/my'; $('bLevel').href = IAP + '/my#buy'; tip('lTip');",
" $('lIap').href = IAP + '/my'; $('bLevel').href = IAP + '/my#buy'; tip('lTip');\n"
" // signed in through the game: these open InstantAdPay already signed in (in-game sign-in pass, 2026-10-03)\n"
" [['lIap', 'overview'], ['bLevel', 'buy']].forEach(function (x) { var a = $(x[0]); if (a && !a.dataset.pass) { a.dataset.pass = 1; a.addEventListener('click', function (ev) { if (window.IAPSignin && IAPSignin.hasPass()) { ev.preventDefault(); IAPSignin.enter(x[1]); } }); } });"),
("$('bSignin').href = ME_EXTRA.signin || (IAP + '/api/my/driprunner');", "$('bSignin').href = ME_EXTRA.signin || '/signin';"),
("$('bClearSignin').href = ME_EXTRA.signin || (IAP + '/api/my/driprunner');", "$('bClearSignin').href = ME_EXTRA.signin || '/signin';"),
("location.href = ME_EXTRA.signin || (IAP + '/api/my/driprunner'); return; }", "location.href = ME_EXTRA.signin || '/signin'; return; }"),
("b.href = (r && (r.signin || r.iap)) || IAP + '/api/my/driprunner';", "b.href = (r && (r.signin || r.iap)) || '/signin';"),
])
edit('public/play.html', [
('<script src="/spawn.js"></script>', '<script src="https://instantadpay.com/assets/game-signin.js?v=20261003a" async></script>\n<script src="/spawn.js"></script>'),
])
b =open(ROOT + 'public/index.html', 'rb').read().decode('utf-8')
n = b.count('href="https://instantadpay.com/api/my/driprunner">Play with InstantAdPay</a>')
if n != 2: raise SystemExit('index anchors %d' % n)
open(ROOT + 'public/index.html', 'wb').write(b.replace('href="https://instantadpay.com/api/my/driprunner">Play with InstantAdPay</a>', 'href="/signin">Play with InstantAdPay</a>').encode('utf-8')); print('patched public/index.html')
print('ok')