diff --git a/ads.js b/ads.js index 28b0259..895058f 100644 Binary files a/ads.js and b/ads.js differ diff --git a/public/assets/refuel.js b/public/assets/refuel.js new file mode 100644 index 0000000..b553ca8 --- /dev/null +++ b/public/assets/refuel.js @@ -0,0 +1,46 @@ +/* Drip Runner refuel: one verified visit, then back to the game with a signed receipt. */ +(function () { + 'use strict'; + var $ = function (id) { return document.getElementById(id); }; + var q = new URLSearchParams(location.search); var tok = q.get('t') || ''; + var nonce = ''; try { nonce = JSON.parse(atob(tok.split('.')[0].replace(/-/g, '+').replace(/_/g, '/'))).nonce || ''; } catch (e) {} + var ret = null, dwell = 8, left = 8, timer = null, done = false; + function msg(title, text, backUrl) { $('rfFrame').innerHTML = '

' + title + '

' + text + '

'; $('rfDone').hidden = true; $('rfCheck').hidden = true; if (backUrl) { var b = $('rfBack'); b.hidden = false; b.onclick = function () { location.href = backUrl; }; } } + function esc(s) { return String(s == null ? '' : s).replace(/[&<>"']/g, function (c) { return { '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]; }); } + function api(p, body) { return fetch(p, body ? { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body) } : {}).then(function (r) { return r.json(); }); } + function ring() { $('rfN').textContent = left; $('rfRing').style.setProperty('--p', ((dwell - left) / dwell * 100) + '%'); } + function tick() { + if (document.hidden) return; // the timer only runs while the page is in front + left--; if (left > 0) return ring(); + clearInterval(timer); ring(); $('rfHint').textContent = 'One quick check to count the visit:'; + challenge(); + } + function challenge() { + api('/api/refuel/challenge?n=' + encodeURIComponent(nonce)).then(function (c) { + if (c.early) { setTimeout(challenge, (c.wait || 1) * 1000 + 300); return; } + if (c.error) { $('rfHint').textContent = c.error; return; } + $('rfPrompt').textContent = 'Tap the ' + c.prompt + ':'; var w = $('rfOpts'); w.innerHTML = ''; + c.options.forEach(function (em, i) { var b = document.createElement('button'); b.type = 'button'; b.textContent = em; b.addEventListener('click', function () { answer(i); }); w.appendChild(b); }); + $('rfCheck').hidden = false; + }); + } + function answer(i) { + api('/api/refuel/done', { n: nonce, answer: i }).then(function (r) { + if (r.error) { if (r.retry) return challenge(); $('rfHint').textContent = r.error; $('rfCheck').hidden = true; return; } + done = true; $('rfCheck').hidden = true; $('rfHint').textContent = 'Visit counted. Your tank is full.'; + var b = $('rfDone'); b.disabled = false; b.textContent = 'Back to the run'; b.onclick = function () { location.href = r.ret; }; + setTimeout(function () { location.href = r.ret; }, 1200); + }); + } + if (!tok) return msg('No refuel link', 'Open this page from the game’s Refuel button.'); + api('/api/refuel/open?t=' + encodeURIComponent(tok)).then(function (r) { + if (r.error) return msg('Refuel link problem', esc(r.error)); + if (r.done) { location.href = r.ret; return; } + if (r.none) return msg('No sponsor pages right now', r.why === 'cap' ? 'You have done today’s verified visits on InstantAdPay. Refuels reopen tomorrow.' : 'No verified-visit packs are running at the moment. Try again in a while.', r.ret + '&none=1'); + ret = r.ret; dwell = r.dwell || 8; left = Math.max(1, dwell - (r.elapsed || 0)); + $('rfTitle').textContent = r.title || 'Member site'; try { $('rfUrl').textContent = new URL(r.target).hostname; } catch (e) {} + var f = document.createElement('iframe'); f.src = r.target; f.setAttribute('referrerpolicy', 'no-referrer'); f.setAttribute('sandbox', 'allow-scripts allow-same-origin allow-forms allow-popups'); $('rfFrame').innerHTML = ''; $('rfFrame').appendChild(f); + var o = $('rfOpen'); o.href = r.target; o.hidden = false; + ring(); timer = setInterval(tick, 1000); + }).catch(function () { msg('Could not load the visit', 'Check your connection and go back to the game.'); }); +})(); diff --git a/public/refuel.html b/public/refuel.html new file mode 100644 index 0000000..a114c2d --- /dev/null +++ b/public/refuel.html @@ -0,0 +1,42 @@ + + + + + + +Refuel · InstantAdPay verified visit + + + + +
InstantAdPay · verified visit · refuel for Drip Runner
+
+
+
…

Loading the sponsor page…

Stay on this page. The timer only runs while it is in front.

+ + + +
+ + + diff --git a/server.js b/server.js index bb0435b..1ab82ca 100644 --- a/server.js +++ b/server.js @@ -1224,6 +1224,30 @@ function pushFeed(ev) { } // ---- server ---- +// -- Drip Runner (2026-09-30): the hand-off, refuel visits and the signed callback to the game. +// Tokens share PolHunter's shape (base64url payload . base64url HMAC) under a separate secret. +const DR_SECRET = () => String(process.env.DR_SSO_SECRET || '').trim(); +const DR_URL = () => String(process.env.DR_URL || 'https://driprunner.saasy.top').replace(/\/+$/, ''); +const drB64u = b => Buffer.from(b).toString('base64').replace(/=+$/, '').replace(/\+/g, '-').replace(/\//g, '_'); +const drSign = payload => drB64u(crypto.createHmac('sha256', DR_SECRET()).update(payload).digest()); +function drMint(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) + '.' + drSign(payload); } +function drOpen(token) { + if (DR_SECRET().length < 32) return { error: 'Drip Runner 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 = drSign(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 refuel link has expired. Go back to the game and tap Refuel again.' }; + return { ok: true, claims: c }; +} +const refuelTokens = new Map(); // nonce -> { email, memberId, id, title, target, ts, ret, challenge, done } +async function drCallback(body) { + const raw = JSON.stringify(body); const ts = String(Date.now()); + const sig = crypto.createHmac('sha256', DR_SECRET()).update(ts + '\n' + raw).digest('hex'); + try { const r = await fetch(DR_URL() + '/api/refuel/callback', { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-DR-Ts': ts, 'X-DR-Sig': sig }, body: raw, signal: AbortSignal.timeout(8000) }); return r.ok; } + catch (e) { console.warn('driprunner callback', e.message); return false; } +} + const server = http.createServer(async (req, res) => { try { const u = new URL(req.url, 'http://x'); @@ -2401,6 +2425,57 @@ const server = http.createServer(async (req, res) => { const tok = b64u(payload) + '.' + b64u(crypto.createHmac('sha256', secret).update(payload).digest()); res.writeHead(302, { Location: huntUrl + '/auth?t=' + tok, 'Cache-Control': 'no-store', 'Set-Cookie': 'iap.return=; Path=/; SameSite=Lax; Max-Age=0' + (IS_PROD ? '; Secure' : '') }); return res.end(); // the loop is closed } + // -- Drip Runner hand-off (2026-09-30): sign the member across, the game verifies with the shared secret + if (p === '/api/my/driprunner' && req.method === 'GET') { + const s = await auth.fromRequest(req); + if (!s || !s.email) { res.writeHead(302, { Location: '/my' }); return res.end(); } + if (DR_SECRET().length < 32) return json(res, 503, { error: 'Drip Runner is not connected yet.' }); + const acct = await accounts.byEmail(s.email); + const memberId = (acct && acct.memberId) || s.memberId || 0; + const tok = drMint({ memberId: Number(memberId), email: s.email, wallet: (acct && acct.address) || s.address || null, username: (acct && acct.username) || null }); + res.writeHead(302, { Location: DR_URL() + '/auth?t=' + tok, 'Cache-Control': 'no-store' }); return res.end(); + } + // -- Drip Runner refuel: a real verified visit (advertiser charged as usual); the player gets fuel, not credits + if (p === '/api/refuel/open' && req.method === 'GET') { + const r = drOpen(u.searchParams.get('t')); 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.' }); + 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, { done: true, ret: t.doneRet || t.ret }); + if (!t) { + const email = String(c.email).toLowerCase(); + const status = await ads.visitStatus(email); + if (status.count >= status.cap) return json(res, 200, { none: true, why: 'cap', ret: c.ret }); + const ad = await ads.serveVisit(email, viewerGeo(req)); + if (!ad) return json(res, 200, { none: true, why: 'empty', ret: c.ret }); + t = { email, memberId: Number(c.memberId), id: ad.id, title: ad.title, target: ad.target, ts: Date.now(), ret: c.ret, challenge: null, done: false }; + refuelTokens.set(c.nonce, t); + } + return json(res, 200, { title: t.title, target: t.target, dwell: ads.rates().visitDwellSeconds || 8, ret: t.ret, elapsed: Math.floor((Date.now() - t.ts) / 1000) }); + } + if (p === '/api/refuel/challenge' && req.method === 'GET') { + const t = refuelTokens.get(String(u.searchParams.get('n') || '')); + if (!t || t.done) return json(res, 400, { error: 'That refuel is no longer open.' }); + const dwellMs = (ads.rates().visitDwellSeconds || 8) * 1000; const age = Date.now() - t.ts; + if (age < dwellMs - 400) return json(res, 200, { early: true, wait: Math.ceil((dwellMs - age) / 1000) }); + const pick = CAPTCHA.slice().sort(() => Math.random() - 0.5).slice(0, 5); const answer = Math.floor(Math.random() * pick.length); + t.challenge = { answer }; + return json(res, 200, { prompt: pick[answer][1], options: pick.map(x => x[0]) }); + } + if (p === '/api/refuel/done' && req.method === 'POST') { + const b = await readBody(req); const nonce = String(b.n || ''); const t = refuelTokens.get(nonce); + if (!t || t.done) return json(res, 400, { error: 'That refuel is no longer open.' }); + if (!t.challenge) return json(res, 400, { error: 'Finish the quick check first.', retry: true }); + if (Number(b.answer) !== t.challenge.answer) { t.challenge = null; return json(res, 400, { error: 'Wrong pick.', retry: true }); } + const r = await ads.completeVisit(t.email, t.id, { reward: false, note: 'Drip Runner refuel' }); + if (r.error) return json(res, 400, r); + t.done = true; + const credits = ads.rates().visitCostPerVisit || 3; + const posted = await drCallback({ nonce, memberId: t.memberId, campaignId: t.id, credits }); + const receipt = drMint({ kind: 'refuel-receipt', nonce, campaignId: t.id, credits }, 15 * 60000); + t.doneRet = t.ret + '&ok=1&r=' + encodeURIComponent(receipt); + return json(res, 200, { ok: true, posted, ret: t.doneRet }); + } if (p === '/api/my/claim' && req.method === 'POST') { const s = await auth.fromRequest(req); if (!s || !s.email) return json(res, 401, { error: 'Sign in first.' }); @@ -3502,6 +3577,7 @@ const server = http.createServer(async (req, res) => { if (p === '/wallets') return sendFile(res, path.join(PUBLIC_DIR, 'wallets.html')); if (p === '/friday') return sendFile(res, path.join(PUBLIC_DIR, 'friday.html')); if (p === '/wednesday') return sendFile(res, path.join(PUBLIC_DIR, 'wednesday.html')); + if (p === '/refuel') return sendFile(res, path.join(PUBLIC_DIR, 'refuel.html')); // Drip Runner refuel visit (2026-09-30) // per-partner kit pages (Marty, 2026-09-29): /partners/ serves public/kits/.html, one file per reviewer or site owner { const mk = p.match(/^\/partners\/([a-z0-9-]{2,40})$/); if (mk) { const f = path.join(PUBLIC_DIR, 'kits', mk[1] + '.html'); if (fs.existsSync(f)) return sendFile(res, f); } } if (p === '/plan-lab') return sendFile(res, path.join(PUBLIC_DIR, 'plan-lab.html')); // Reach Ladder simulator for Marty's planning group: unlisted, shared by link (2026-09-27)