From 11d6f469508a0b252973f11a6e0be03708299c28 Mon Sep 17 00:00:00 2001 From: martbost Date: Mon, 5 Oct 2026 07:25:22 -0500 Subject: [PATCH] Invite friends card in the lobby + ?ref attribution on every entry page Marty: members could not find their referral link. A signed-in player now sees an "Invite friends" card right under Play: their /r/ link (previews with their own card), Copy (clipboard API, select+copy fallback, prompt last) with a Copied! confirmation, and Share where the phone has a share sheet. Link stats and the how-it-works line moved into the card. No username yet: the card says how to get one. Attribution: ?ref= on /, /play and /signin (and ?r= on the landing, where framed /r/ lands) now sets the same dr.ref sponsor cookie as /r/, last touch wins. /r/ for a name the game does not know keeps it as /?ref= instead of dropping it. signin.js also reads ?ref straight from the URL. Tests cover each path. Co-Authored-By: Claude Opus 5.5 --- public/play.html | 28 ++++++++++++++++++++++++++-- public/play.js | 23 ++++++++++++++++++++--- public/signin.html | 2 +- public/signin.js | 3 ++- server.js | 17 ++++++++++++++--- test/run.js | 9 ++++++++- 6 files changed, 71 insertions(+), 11 deletions(-) diff --git a/public/play.html b/public/play.html index 31d24ad..cf4d27b 100644 --- a/public/play.html +++ b/public/play.html @@ -88,6 +88,17 @@ canvas#game{position:absolute;inset:0;width:100%;height:100%;display:block;touch .tip{margin:12px 0 0;padding:10px 12px;border-radius:10px;background:rgba(34,211,238,.07);border:1px solid rgba(34,211,238,.25);font-size:12px;line-height:1.45;color:var(--ink2);text-align:left}.tip b{display:block;font:700 9px var(--body);letter-spacing:.16em;text-transform:uppercase;color:var(--cyan);margin-bottom:3px} .shrHow{margin:6px 0 8px;font-size:11px;line-height:1.45;color:var(--ink2)}.shrHow a{color:inherit} .shr{margin-top:10px;padding:10px 12px;border-radius:10px;border:1px solid var(--line);background:rgba(14,23,45,.6);font-size:11px;color:var(--muted);text-align:center}.shr b{color:var(--gold)}.shr .btn{margin-top:8px} +/* invite friends card (2026-10-05) */ +.inv{margin-top:14px;padding:14px 14px 12px;border-radius:14px;border:1px solid rgba(34,211,238,.5);background:linear-gradient(180deg,rgba(14,40,58,.92),rgba(14,23,45,.96));box-shadow:0 0 34px -14px rgba(34,211,238,.6);text-align:left} +.inv .eyebrow{font:800 13px var(--display);letter-spacing:.14em;text-transform:uppercase;color:var(--cyan2)} +.invLead{margin:6px 0 10px;font-size:13px;line-height:1.45;color:var(--ink)} +.invLbl{display:block;font:700 9px var(--body);letter-spacing:.16em;text-transform:uppercase;color:var(--muted);margin-bottom:4px} +.invLink{display:block;width:100%;padding:10px 11px;border-radius:10px;border:1px solid var(--line);background:rgba(5,9,18,.75);color:var(--gold2);font:700 13px var(--mono);user-select:all;-webkit-user-select:all} +.invLink:focus{outline:2px solid var(--cyan);outline-offset:1px} +.invBtns{display:flex;gap:10px}.invBtns .btn{flex:1 1 0;min-width:0;font-size:13px;padding:12px 8px} +.invBtns .btn.done{background:linear-gradient(180deg,#A7F3D0,var(--ok) 55%,#059669)} +.invNote{margin:8px 0 0;font-size:11px;line-height:1.45;color:var(--muted)}.invNote a{color:var(--cyan2)} +.invStat{margin-top:10px;padding-top:8px;border-top:1px solid var(--line);font-size:11px;color:var(--muted)}.invStat b{color:var(--gold)} .toast{position:absolute;left:50%;bottom:calc(70px + env(safe-area-inset-bottom,0px));transform:translateX(-50%);z-index:20;background:var(--panel2);border:1px solid var(--line);color:var(--ink);font-size:12px;padding:8px 12px;border-radius:10px;opacity:0;transition:opacity .2s;pointer-events:none;max-width:92%;text-align:center} .toast.on{opacity:1} /* member welcome offer (2026-10-05): an extra card under the chapter-clear result, never during a run, never blocking */ @@ -130,9 +141,22 @@ canvas#game{position:absolute;inset:0;width:100%;height:100%;display:block;touch
+ + Level up on InstantAdPay -
connecting…
@@ -181,6 +205,6 @@ canvas#game{position:absolute;inset:0;width:100%;height:100%;display:block;touch - + diff --git a/public/play.js b/public/play.js index 3bf9ac0..59eecec 100644 --- a/public/play.js +++ b/public/play.js @@ -71,9 +71,11 @@ function lobby() { $('lMember').innerHTML = '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; var rf = ME_EXTRA.referrals || {}; - $('lShare').hidden = !ME_EXTRA.share; + // the invite card shows for every signed-in player; without a username there is no link yet, so it says how to get one + $('lShare').hidden = false; $('invHas').hidden = !ME_EXTRA.share; $('invNone').hidden = !!ME_EXTRA.share; $('invNoneGo').href = IAP + '/my'; + $('invLink').value = ME_EXTRA.share || ''; $('bShare').hidden = !navigator.share; $('lShareHow').innerHTML = 'Players whose InstantAdPay sponsor is you are your team. Each time one of them refuels, ' + (rf.pct || 10) + '% of what that refuel adds to the pool is credited to your balance, and it is sent to your wallet with your drips at ' + Number((BAL && BAL.threshold) || 0.25).toFixed(2) + ' POL. How it works'; - $('lShareStat').innerHTML = 'Your link: ' + (rf.clicks || 0) + ' visits · ' + (rf.count || 0) + ' players on your team · ' + f3(rf.earned) + ' POL earned from their refuels (' + (rf.pct || 0) + '% of each)'; + $('lShareStat').innerHTML = 'Your link: ' + (rf.clicks || 0) + ' visit' + (rf.clicks === 1 ? '' : 's') + ' · ' + (rf.count || 0) + ' player' + (rf.count === 1 ? '' : 's') + ' on your team · ' + f3(rf.earned) + ' POL earned from their refuels (' + (rf.pct || 0) + '% of each)'; } show('ovLobby'); } @@ -167,7 +169,22 @@ function starterOffer(o) { $('cOfferNo').addEventListener('click', function () { $('cOffer').hidden = true; }); $('bNext').addEventListener('click', function () { if (!R) return; R.paused = false; R.inv = 1.5; hideAll(); }); $('bShareClear').addEventListener('click', function () { share(this.dataset.text || 'Play Drip Runner with me:'); }); -$('bShare').addEventListener('click', function () { share('I am playing Drip Runner, a game that pays in POL. Hop the network, dodge the bots:'); }); +$('bShare').addEventListener('click', function () { share('Come play Drip Runner with me. Hop the network, dodge the bots:'); }); +// Copy: the clipboard API where the page may use it, else select the field and copy, else a prompt to copy by hand +var copyT = null; +function copied(ok) { + var b = $('bCopy'); clearTimeout(copyT); + if (!ok) { window.prompt('Copy your invite link', ME_EXTRA.share); return; } + b.textContent = 'Copied!'; b.classList.add('done'); toast('Invite link copied. Paste it anywhere.'); + copyT = setTimeout(function () { b.textContent = 'Copy link'; b.classList.remove('done'); }, 2200); +} +function copyFallback() { var f = $('invLink'), ok = false; try { f.focus(); f.select(); f.setSelectionRange(0, f.value.length); ok = document.execCommand('copy'); } catch (e) { ok = false; } f.blur(); copied(ok); } +$('bCopy').addEventListener('click', function () { + var url = ME_EXTRA.share; if (!url) return; + if (navigator.clipboard && navigator.clipboard.writeText && window.isSecureContext !== false) navigator.clipboard.writeText(url).then(function () { copied(true); }, copyFallback); + else copyFallback(); +}); +$('invLink').addEventListener('focus', function () { this.select(); }); $('bRestart').addEventListener('click', function () { endRun().then(newRun); }); function endRun() { var id = R && R.id; R = null; hideAll(); return id ? api('/api/run/end', { runId: id }).catch(function () {}) : Promise.resolve(); } ['bLobby1', 'bLobby2'].forEach(function (id) { $(id).addEventListener('click', function () { endRun().then(loadMe).then(lobby); }); }); diff --git a/public/signin.html b/public/signin.html index 1a00ba1..295bdef 100644 --- a/public/signin.html +++ b/public/signin.html @@ -23,6 +23,6 @@ html{background:#050912}

Keep playing as a guest

- + diff --git a/public/signin.js b/public/signin.js index 2883c8c..999f1b6 100644 --- a/public/signin.js +++ b/public/signin.js @@ -5,5 +5,6 @@ if (!window.IAPSignin) { box.innerHTML = '

Sign-in could not load. Sign in on InstantAdPay instead.

'; return; } var m = /(?:^|;\s*)dr\.ref=([^;]+)/.exec(document.cookie || ''); // the share link a guest arrived on: their sponsor var s = /(?:^|;\s*)dr\.src=([^;]+)/.exec(document.cookie || ''); // paid-traffic source, if any (2026-10-03) - IAPSignin.mount(box, { game: 'driprunner', src: s ? decodeURIComponent(s[1]).split('|')[0] : '', ref: m ? decodeURIComponent(m[1]) : '', title: 'Sign in to run', oneTap: IAPSignin.origin + '/api/my/driprunner' }); + var q = String(new URLSearchParams(location.search).get('ref') || '').replace(/[^A-Za-z0-9_.-]/g, '').slice(0, 40); // /signin?ref= works even where the cookie was refused (2026-10-05) + IAPSignin.mount(box, { game: 'driprunner', src: s ? decodeURIComponent(s[1]).split('|')[0] : '', ref: q || (m ? decodeURIComponent(m[1]) : ''), title: 'Sign in to run', oneTap: IAPSignin.origin + '/api/my/driprunner' }); })(); diff --git a/server.js b/server.js index df4ce34..fc020b0 100644 --- a/server.js +++ b/server.js @@ -229,8 +229,10 @@ const server = http.createServer(async (req, res) => { } { const mr = /^\/r\/([A-Za-z0-9_.-]{1,40})$/.exec(p); if (mr) { const sharer = game.byUsername(mr[1]); - if (!sharer) { res.writeHead(302, { Location: '/', 'Cache-Control': 'no-store' }); return res.end(); } - const ck = ['dr.ref=' + encodeURIComponent(sharer.username.toLowerCase()) + '; Path=/; Max-Age=' + 30 * 86400 + '; SameSite=Lax' + (IS_PROD ? '; Secure' : '')]; + // not a Drip Runner player (yet), but maybe an InstantAdPay member: the landing keeps the name as ?ref (2026-10-05), and + // InstantAdPay decides whether it is a real sponsor when the visitor signs up + if (!sharer) { res.writeHead(302, { Location: '/?ref=' + encodeURIComponent(mr[1].toLowerCase()), 'Cache-Control': 'no-store' }); return res.end(); } + const ck = [refCookieHeader(sharer.username.toLowerCase())]; if (CURTAIN) ck.push('dr.pass=' + encodeURIComponent(CURTAIN) + '; Path=/; Max-Age=2592000; HttpOnly; SameSite=Lax' + (IS_PROD ? '; Secure' : '')); // a player's link is a pass during the trial store.update('share-hits', {}, h => { const k = sharer.username.toLowerCase(); h[k] = (h[k] || 0) + 1; return h; }); res.writeHead(302, { Location: '/play', 'Set-Cookie': ck, 'Cache-Control': 'no-store' }); return res.end(); @@ -250,7 +252,13 @@ const server = http.createServer(async (req, res) => { // ---- static + pages ---- // a paid-traffic landing (?src=adsterra&cid=): remember it (dr.src) and count the visit (2026-10-03) - let srcHdr = null; if (req.method === 'GET' && ['/', '/index.html', '/play', '/signin'].includes(p)) { const t = srctrack.fromQuery(u); if (t) { srcHdr = { 'Set-Cookie': srctrack.cookieHeader(t, IS_PROD) }; srctrack.bump(t.src, 'visits'); } } + let srcHdr = null; if (req.method === 'GET' && ['/', '/index.html', '/play', '/signin'].includes(p)) { + const ck = []; const t = srctrack.fromQuery(u); if (t) { ck.push(srctrack.cookieHeader(t, IS_PROD)); srctrack.bump(t.src, 'visits'); } + // ?ref= on the landing, the game or sign-in (2026-10-05, the IAP viral-link pattern): the same sponsor cookie as /r/, + // last touch wins. ?r= too on the landing only (the framed /r/ lands on /?r=); on /play, r is the refuel receipt. + const rq = queryRef(u, p === '/' || p === '/index.html'); if (rq) ck.push(refCookieHeader(rq)); + if (ck.length) srcHdr = { 'Set-Cookie': ck }; + } if (p === '/' || p === '/index.html') { if (curtained(req, res, u)) return; return sendFile(res, path.join(PUBLIC_DIR, 'index.html'), srcHdr); } 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'), srcHdr); @@ -335,6 +343,9 @@ const server = http.createServer(async (req, res) => { if (!res.headersSent) json(res, 500, { error: 'Something broke on our side. Try again.' }); } }); +// the sponsor cookie (read by signin.js and handed to the InstantAdPay sign-in kit as ref; not HttpOnly on purpose) +function refCookieHeader(ref) { return 'dr.ref=' + encodeURIComponent(ref) + '; Path=/; Max-Age=' + 30 * 86400 + '; SameSite=Lax' + (IS_PROD ? '; Secure' : ''); } +function queryRef(u, allowR) { const r = String(u.searchParams.get('ref') || (allowR ? u.searchParams.get('r') : '') || '').trim().replace(/^@/, ''); return /^[A-Za-z0-9_.-]{1,40}$/.test(r) ? r.toLowerCase() : 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 function signinUrl(req) { return '/signin'; } // in-game sign-in (2026-10-03); the kit carries the dr.ref sponsor itself diff --git a/test/run.js b/test/run.js index 24aa08e..8045093 100644 --- a/test/run.js +++ b/test/run.js @@ -99,7 +99,14 @@ const spawnLib = require('../lib/spawn'); const hit = async (p, opt = {}, ck = '') => { const r = await fetch(B + p, Object.assign({ redirect: 'manual' }, opt, { headers: Object.assign({ Cookie: ck, 'Content-Type': 'application/json' }, opt.headers || {}) })); const set = r.headers.getSetCookie ? r.headers.getSetCookie() : []; let body = null; try { body = await r.json(); } catch (e) {} return { status: r.status, body, set, loc: r.headers.get('location') }; }; const jarAdd = (ck, set) => { const parts = ck ? ck.split('; ') : []; for (const c of set) { const m = /^([^=]+)=([^;]*)/.exec(c); if (!m) continue; const i = parts.findIndex(x => x.startsWith(m[1] + '=')); if (i >= 0) parts.splice(i, 1); if (m[2]) parts.push(m[1] + '=' + m[2]); } return parts.join('; '); }; await admin('/api/admin/settings', { signups: 'open', thresholdPol: 5, refSharePct: 10 }); - eq((await hit('/r/nobody')).loc, '/', 'a share link for an unknown player goes to the landing page'); + eq((await hit('/r/nobody')).loc, '/?ref=nobody', 'a share link for a name the game does not know goes to the landing page with the name kept as ?ref'); + // ?ref= (2026-10-05): the landing, the game and sign-in all set the same sponsor cookie; ?r= only on the landing (on /play it is the refuel receipt) + for (const [path, want] of [['/?ref=Alice', 'alice'], ['/?r=alice', 'alice'], ['/play?ref=alice', 'alice'], ['/signin?ref=@alice', 'alice'], ['/play?r=receipt', null], ['/?ref=bad%20name', null]]) { + const x = await hit(path); const c = x.set.find(s => /^dr\.ref=/.test(s)) || null; + eq([x.status, c ? /^dr\.ref=([^;]*)/.exec(c)[1] : null], [200, want], path + (want ? ' sets dr.ref=' + want : ' sets no sponsor cookie')); + } + { const x = await hit('/?ref=alice&src=adsterra&cid=c1'); eq([x.set.some(s => /^dr\.ref=alice/.test(s)), x.set.some(s => /^dr\.src=/.test(s))], [true, true], 'a paid-traffic landing with ?ref keeps both cookies'); } + { const x = await hit('/r/runner42', { headers: { 'Sec-Fetch-Dest': 'iframe' } }); eq(x.loc, '/?r=runner42', 'a framed share link lands on the landing with ?r'); } const sh = await hit('/r/runner42'); eq([sh.status, sh.loc, sh.set.some(c => /^dr\.ref=runner42/.test(c))], [302, '/play', true], 'a player share link sets the referrer and opens the game'); let g = jarAdd('', sh.set); const me401 = await hit('/api/me', {}, g); eq([me401.status, me401.body.guestOk, me401.body.signin === '/signin'], [401, true, true], 'a newcomer is offered guest play, sign-in stays in the game (/signin; the kit carries the dr.ref sponsor)');