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/<username> 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=<name> on /, /play and /signin (and ?r= on the landing, where framed /r/<name> lands) now sets the same dr.ref sponsor cookie as /r/<name>, last touch wins. /r/<name> for a name the game does not know keeps it as /?ref=<name> instead of dropping it. signin.js also reads ?ref straight from the URL. Tests cover each path. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -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=<click id>): 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=<username> on the landing, the game or sign-in (2026-10-05, the IAP viral-link pattern): the same sponsor cookie as /r/<name>,
|
||||
// last touch wins. ?r= too on the landing only (the framed /r/<name> lands on /?r=<name>); 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
|
||||
|
||||
Reference in New Issue
Block a user