Badge cards posted to Telegram: hangar unlocks, chapter milestones (1,3,5,10,15,20), refuel milestones (5,25,100), payouts; neon artwork + ffmpeg-stamped name/earnings; trial wording (coming soon, would have earned) until the admin flips it; admin announce route
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@@ -1,5 +1,7 @@
|
||||
FROM node:22-alpine
|
||||
WORKDIR /app
|
||||
# badge cards: the player's name and earnings are stamped onto the artwork with ffmpeg
|
||||
RUN apk add --no-cache ffmpeg
|
||||
COPY package.json ./
|
||||
RUN npm install --omit=dev --no-audit --no-fund
|
||||
COPY . .
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
// Badge cards for Telegram (Marty, 2026-09-30: "unlocks posted on Telegram with some catchy-looking badges,
|
||||
// along with how much they earned"). The artwork is pre-rendered (public/badges/<id>.png, 1080x1080,
|
||||
// tools/render-badges.mjs) with a blank plate at the bottom; ffmpeg stamps the player's name and the
|
||||
// earnings line onto the plate when a card is posted. Cached on the volume: DATA_DIR/badges/.
|
||||
'use strict';
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const crypto = require('crypto');
|
||||
const { spawn } = require('child_process');
|
||||
|
||||
const BADGES = {
|
||||
magnet: 'Drip Magnet', ship: 'Courier Mk II', shield: 'Shield Core', slow: 'Slow Field',
|
||||
ch1: 'First Chapter', ch3: 'Chapter 3', ch5: 'Chapter 5', ch10: 'Chapter 10', ch15: 'Chapter 15', ch20: 'Chapter 20',
|
||||
refuel5: 'Five Refuels', refuel25: '25 Refuels', refuel100: '100 Refuels', paid: 'Paid in POL'
|
||||
};
|
||||
const CHAPTER_BADGES = { 1: 'ch1', 3: 'ch3', 5: 'ch5', 10: 'ch10', 15: 'ch15', 20: 'ch20' };
|
||||
const REFUEL_BADGES = { 5: 'refuel5', 25: 'refuel25', 100: 'refuel100' };
|
||||
let PUBLIC_DIR = null, CACHE_DIR = null;
|
||||
function init(opts) { PUBLIC_DIR = opts.publicDir; CACHE_DIR = path.join(opts.dataDir, 'badges'); try { fs.mkdirSync(CACHE_DIR, { recursive: true }); } catch (e) {} }
|
||||
const art = id => path.join(PUBLIC_DIR, 'badges', id + '.png');
|
||||
function font(name) { const f = path.join(PUBLIC_DIR, 'fonts', name); if (fs.existsSync(f)) return f; for (const d of ['/usr/share/fonts/truetype/dejavu', '/usr/share/fonts/dejavu', '/usr/share/fonts/TTF']) { const g = path.join(d, 'DejaVuSans-Bold.ttf'); if (fs.existsSync(g)) return g; } return null; }
|
||||
const ffText = t => String(t).replace(/\\/g, '\\\\').replace(/'/g, "\u2019").replace(/:/g, '\\:').replace(/%/g, '%%').replace(/,/g, '\\,');
|
||||
// ffmpeg filter paths: forward slashes, drive colon escaped
|
||||
const ffPath = p => String(p).replace(/\\/g, '/').replace(/:/g, '\\:');
|
||||
|
||||
// the card: name on the plate's upper line, the earnings line under it
|
||||
function render(id, who, line2, tag) {
|
||||
return new Promise(resolve => {
|
||||
if (!BADGES[id] || !fs.existsSync(art(id))) return resolve(null);
|
||||
const f1 = font('Orbitron-Bold.ttf'), f2 = font('Manrope-Bold.ttf'); if (!f1 || !f2) return resolve(null);
|
||||
const name = String(who || '').slice(0, 24), sub = String(line2 || '').slice(0, 70), tg = String(tag || '').slice(0, 40);
|
||||
const out = path.join(CACHE_DIR, id + '-' + crypto.createHash('sha1').update(name + '|' + sub + '|' + tg).digest('hex').slice(0, 12) + '.jpg');
|
||||
if (fs.existsSync(out)) return resolve(out);
|
||||
const vf = "drawtext=fontfile='" + ffPath(f1) + "':text='" + ffText(name) + "':fontcolor=#FFFFFF:fontsize=62:borderw=3:bordercolor=#22D3EE@0.9:shadowcolor=#000000@0.6:shadowx=0:shadowy=4:x=(w-text_w)/2:y=808"
|
||||
+ ",drawtext=fontfile='" + ffPath(f2) + "':text='" + ffText(sub) + "':fontcolor=#FFC24B:fontsize=36:x=(w-text_w)/2:y=910"
|
||||
+ (tg ? ",drawtext=fontfile='" + ffPath(f2) + "':text='" + ffText(tg) + "':fontcolor=#FF6A1A:fontsize=24:x=(w-text_w)/2:y=771" : ''); // Manrope: Orbitron has no middle dot
|
||||
const p = spawn('ffmpeg', ['-v', 'error', '-y', '-i', art(id), '-vf', vf, '-frames:v', '1', '-q:v', '3', out], { stdio: ['ignore', 'ignore', 'pipe'] });
|
||||
let err = ''; p.stderr.on('data', c => { err += c; });
|
||||
p.on('error', () => resolve(null));
|
||||
p.on('close', code => { if (code === 0 && fs.existsSync(out)) resolve(out); else { console.error('badge render failed', code, err.slice(0, 300)); resolve(null); } });
|
||||
});
|
||||
}
|
||||
module.exports = { BADGES, CHAPTER_BADGES, REFUEL_BADGES, init, render };
|
||||
@@ -25,6 +25,7 @@ const DEFAULTS = {
|
||||
itemPol: { shield: 0.05, slow: 0.03 }, // hangar items paid from the POL balance (the sink)
|
||||
itemDrips: { magnet: 250, ship: 600 }, // hangar items paid in drips (never money)
|
||||
testers: [], // emails or member ids allowed through the hand-off while signups = 'testers'
|
||||
trial: true, // posts say 'coming soon, in testing' and 'would have earned' until Marty flips it
|
||||
signups: 'testers' // 'testers' | 'key' (tester list or the curtain pass) | 'open' | 'closed'
|
||||
};
|
||||
function settings() { return Object.assign({}, DEFAULTS, store.read('settings', {})); }
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
<div><label>USD per credit</label><input name="usdPerCredit" type="number" step="0.001" min="0"></div>
|
||||
<div><label>USD per POL fallback</label><input name="usdPerPolFallback" type="number" step="0.001" min="0"></div>
|
||||
<div><label>Low balance alert (POL)</label><input name="lowBalancePol" type="number" step="0.1" min="0"></div>
|
||||
<div><label>Posts say</label><select name="trial"><option value="on">coming soon, in testing (would have earned)</option><option value="off">live (earned)</option></select></div>
|
||||
<div><label>Who may sign in</label><select name="signups"><option value="key">anyone who opened the key link</option><option value="testers">testers list only</option><option value="open">any IAP member</option><option value="closed">nobody</option></select></div>
|
||||
<div><label>Shield core (POL)</label><input name="item_shield" type="number" step="0.001" min="0"></div>
|
||||
<div><label>Slow field (POL)</label><input name="item_slow" type="number" step="0.001" min="0"></div>
|
||||
|
||||
@@ -22,7 +22,7 @@ function load() {
|
||||
var s = d.settings, form = $('settings');
|
||||
['dripPol', 'dailyCapPol', 'thresholdPol', 'seedPol', 'poolSharePct', 'creditsPerVisit', 'usdPerCredit', 'usdPerPolFallback', 'lowBalancePol', 'signups'].forEach(function (k) { form.elements[k].value = s[k]; });
|
||||
form.elements.item_shield.value = s.itemPol.shield; form.elements.item_slow.value = s.itemPol.slow; form.elements.item_magnet.value = s.itemDrips.magnet; form.elements.item_ship.value = s.itemDrips.ship;
|
||||
form.elements.testers.value = (s.testers || []).join('\n');
|
||||
form.elements.testers.value = (s.testers || []).join('\n'); form.elements.trial.value = s.trial === false ? 'off' : 'on';
|
||||
table('players', [['Member', function (r) { return '#' + r.memberId + (r.username ? ' @' + esc(r.username) : '') + '<br><span class="muted">' + esc(r.email || '') + '</span>'; }], ['Wallet', function (r) { return r.wallet ? r.wallet.slice(0, 6) + '…' + r.wallet.slice(-4) : '<span style="color:var(--sig)">none</span>'; }], ['Chapter', 'chapter', 1], ['Drips', 'bank', 1], ['Best', 'best', 1], ['Runs', 'runs', 1], ['Armed', function (r) { return Object.keys(r.items || {}).join(', '); }], ['Last seen', function (r) { return ct(r.lastSeen); }]], d.players);
|
||||
table('refuels', [['When', function (r) { return ct(r.ts); }], ['Member', function (r) { return '#' + r.memberId + (r.username ? ' @' + esc(r.username) : ''); }], ['Campaign', 'campaignId'], ['Credits', 'credits', 1], ['Ad $', function (r) { return f4(r.usd); }, 1], ['Share $', function (r) { return f4(r.share); }, 1], ['POL to pool', function (r) { return f4(r.pol); }, 1], ['Via', 'via']], d.refuels);
|
||||
table('drips', [['When', function (r) { return ct(r.ts); }], ['Member', function (r) { return '#' + r.memberId + (r.username ? ' @' + esc(r.username) : ''); }], ['Chapter', 'chapter', 1], ['POL', function (r) { return f4(r.pol); }, 1]], d.drips);
|
||||
@@ -35,7 +35,7 @@ $('settings').addEventListener('submit', function (e) {
|
||||
e.preventDefault(); var f = e.target.elements; var body = {};
|
||||
['dripPol', 'dailyCapPol', 'thresholdPol', 'seedPol', 'poolSharePct', 'creditsPerVisit', 'usdPerCredit', 'usdPerPolFallback', 'lowBalancePol', 'signups'].forEach(function (k) { body[k] = f[k].value; });
|
||||
body.itemPol = { shield: Number(f.item_shield.value), slow: Number(f.item_slow.value) }; body.itemDrips = { magnet: Number(f.item_magnet.value), ship: Number(f.item_ship.value) };
|
||||
body.testers = f.testers.value.split(/\r?\n/).map(function (x) { return x.trim(); }).filter(Boolean);
|
||||
body.trial = f.trial.value; body.testers = f.testers.value.split(/\r?\n/).map(function (x) { return x.trim(); }).filter(Boolean);
|
||||
api('/api/admin/settings', body).then(function (r) { $('saveOut').textContent = r.ok ? 'Saved.' : (r.error || 'Failed'); load(); });
|
||||
});
|
||||
$('tick').addEventListener('click', function () { $('tickOut').textContent = 'running…'; api('/api/admin/faucet/tick', {}).then(function (r) { $('tickOut').textContent = JSON.stringify(r); load(); }); });
|
||||
|
||||
|
After Width: | Height: | Size: 421 KiB |
|
After Width: | Height: | Size: 411 KiB |
|
After Width: | Height: | Size: 408 KiB |
|
After Width: | Height: | Size: 409 KiB |
|
After Width: | Height: | Size: 406 KiB |
|
After Width: | Height: | Size: 410 KiB |
|
After Width: | Height: | Size: 487 KiB |
|
After Width: | Height: | Size: 467 KiB |
|
After Width: | Height: | Size: 439 KiB |
|
After Width: | Height: | Size: 433 KiB |
|
After Width: | Height: | Size: 436 KiB |
|
After Width: | Height: | Size: 458 KiB |
|
After Width: | Height: | Size: 446 KiB |
|
After Width: | Height: | Size: 460 KiB |
@@ -22,6 +22,7 @@ const game = require('./lib/game');
|
||||
const ledger = require('./lib/ledger');
|
||||
const faucet = require('./lib/faucet');
|
||||
const spawn = require('./lib/spawn');
|
||||
const badge = require('./lib/badge');
|
||||
|
||||
const PORT = Number(process.env.PORT || 3000);
|
||||
const DATA_DIR = process.env.DATA_DIR || path.join(__dirname, 'data');
|
||||
@@ -35,6 +36,7 @@ const outbound = () => process.env.OUTBOUND === 'on';
|
||||
const IS_PROD = process.env.NODE_ENV === 'production';
|
||||
|
||||
store.init(DATA_DIR);
|
||||
badge.init({ publicDir: PUBLIC_DIR, dataDir: DATA_DIR });
|
||||
const faucetOn = faucet.init();
|
||||
|
||||
// ---- Telegram to Marty (outward: gated) -------------------------------------------------------
|
||||
@@ -44,10 +46,49 @@ async function telegram(text) {
|
||||
try { const r = await fetch('https://api.telegram.org/bot' + tok + '/sendMessage', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ chat_id: chat, text, parse_mode: 'HTML', disable_web_page_preview: true }) }); return r.ok; } catch (e) { return false; }
|
||||
}
|
||||
const fmt = n => Number(n).toLocaleString('en-US', { maximumFractionDigits: 4 });
|
||||
// ---- public badge posts (Marty, 2026-09-30): unlocks, chapter and refuel milestones, payouts, as photo cards ----
|
||||
// DR_TG_PUBLIC_CHAT / DR_TG_PUBLIC_TOPIC = the room (PolHunter's), DR_TG_PUBLIC_GENERAL=on also posts the photo to the general channel.
|
||||
async function telegramPhoto(file, caption, general) {
|
||||
if (!outbound()) return false;
|
||||
const tok = process.env.DR_TG_TOKEN, chat = process.env.DR_TG_PUBLIC_CHAT || process.env.DR_TG_CHAT, topic = process.env.DR_TG_PUBLIC_CHAT ? process.env.DR_TG_PUBLIC_TOPIC : null;
|
||||
if (!tok || !chat || !file) return false;
|
||||
try {
|
||||
const fd = new FormData(); fd.append('chat_id', chat); fd.append('caption', caption); fd.append('parse_mode', 'HTML'); if (topic && !general) fd.append('message_thread_id', String(topic));
|
||||
fd.append('photo', new Blob([fs.readFileSync(file)], { type: 'image/jpeg' }), 'badge.jpg');
|
||||
const r = await fetch('https://api.telegram.org/bot' + tok + '/sendPhoto', { method: 'POST', body: fd }); return r.ok;
|
||||
} catch (e) { return false; }
|
||||
}
|
||||
const nameOf = me => me.username ? '@' + me.username : '#' + me.memberId;
|
||||
const trial = () => ledger.settings().trial !== false; // Marty, 2026-09-30: while testing, say so, and show what they WOULD have earned once live
|
||||
function earningsLine(memberId) {
|
||||
const a = ledger.account(memberId); const p = game.player(memberId) || {}; const refuels = store.read('refuels', []).filter(r => r.memberId === Number(memberId)).length;
|
||||
return (trial() ? 'would have earned ' : 'earned ') + fmt(a.earnedTotal || 0) + ' POL so far \u00b7 ' + refuels + ' refuel' + (refuels === 1 ? '' : 's') + ' \u00b7 chapter ' + (p.chapter || 1);
|
||||
}
|
||||
// one post per (member, badge); a payout card is one per payout row
|
||||
async function announce(id, me, opts) {
|
||||
opts = opts || {}; const key = opts.key || id;
|
||||
const posted = store.read('posted', {}); const mine = new Set(posted[String(me.memberId)] || []);
|
||||
if (mine.has(key)) return false;
|
||||
store.update('posted', {}, all => { all[String(me.memberId)] = [...mine, key]; return all; });
|
||||
const line2 = opts.line2 || earningsLine(me.memberId);
|
||||
const file = await badge.render(id, nameOf(me), line2, trial() ? 'COMING SOON \u00b7 NOW IN TESTING' : '');
|
||||
const head = trial() ? opts.caption.replace('<b>Drip Runner</b>', '<b>Drip Runner</b> <i>(coming soon \u00b7 now in testing)</i>') : opts.caption;
|
||||
const foot = trial() ? '<i>Testers are playing a preview. When Drip Runner goes live, amounts like this pay out in POL to the wallet on your InstantAdPay account.</i>' : '<i>Play from your InstantAdPay dashboard.</i>';
|
||||
const cap = head + '\n' + line2 + '\n' + foot;
|
||||
if (!file) return telegram(cap);
|
||||
const ok = await telegramPhoto(file, cap);
|
||||
if (ok && String(process.env.DR_TG_PUBLIC_GENERAL || 'off') === 'on') await telegramPhoto(file, cap, true);
|
||||
return ok;
|
||||
}
|
||||
const ITEM_NAMES = { magnet: 'Drip Magnet', ship: 'Courier Mk II', shield: 'Shield Core', slow: 'Slow Field' };
|
||||
function announceUnlock(me, item, paid) { if (!badge.BADGES[item]) return; announce(item, me, { caption: '\u{1F3AE} <b>Drip Runner</b> \u00b7 <b>' + nameOf(me) + '</b> unlocked the <b>' + ITEM_NAMES[item] + '</b> (' + paid + ')' }).catch(() => {}); }
|
||||
function announceChapter(me, ch, pol) { const id = badge.CHAPTER_BADGES[ch]; if (!id) return; announce(id, me, { caption: '\u{1F3C1} <b>Drip Runner</b> \u00b7 <b>' + nameOf(me) + '</b> cleared <b>Chapter ' + ch + '</b>' + (pol ? ' \u00b7 <b>+' + fmt(pol) + ' POL</b>' : '') }).catch(() => {}); }
|
||||
function announceRefuels(me) { const n = store.read('refuels', []).filter(r => r.memberId === Number(me.memberId)).length; const id = badge.REFUEL_BADGES[n]; if (!id) return; announce(id, me, { caption: '\u26FD <b>Drip Runner</b> \u00b7 <b>' + nameOf(me) + '</b> has refuelled <b>' + n + ' times</b>. Every refuel is a verified visit to a member\u2019s page on InstantAdPay.' }).catch(() => {}); }
|
||||
function announcePaid(p) { announce('paid', { memberId: p.memberId, username: p.username }, { key: 'paid:' + p.id, caption: '\u{1F4B8} <b>Drip Runner</b> \u00b7 <b>' + nameOf(p) + '</b> was paid <b>' + fmt(p.pol) + ' POL</b> \u00b7 <a href="' + explorer() + '/tx/' + p.tx + '">verify</a>', line2: 'paid ' + fmt(p.pol) + ' POL to their wallet \u00b7 ' + earningsLine(p.memberId).replace(/^earned [^\u00b7]+\u00b7 /, '') }).catch(() => {}); }
|
||||
const explorer = () => Number(process.env.DR_CHAIN_ID) === 80002 ? 'https://amoy.polygonscan.com' : 'https://polygonscan.com';
|
||||
async function notify(kind, p) {
|
||||
const who = p && (p.username ? '@' + p.username : '#' + p.memberId);
|
||||
if (kind === 'paid') return telegram('\u{1F3AE} <b>Drip Runner</b> · paid ' + who + ' <b>' + fmt(p.pol) + ' POL</b> · <a href="' + explorer() + '/tx/' + p.tx + '">verify</a>');
|
||||
if (kind === 'paid') { announcePaid(p); return telegram('\u{1F3AE} <b>Drip Runner</b> · paid ' + who + ' <b>' + fmt(p.pol) + ' POL</b> · <a href="' + explorer() + '/tx/' + p.tx + '">verify</a>'); }
|
||||
if (kind === 'failed') return telegram('❌ <b>Drip Runner</b> · payout to ' + who + ' failed: ' + p.error);
|
||||
if (kind === 'low') return telegram('⚠️ <b>Drip Runner wallet is low</b>: ' + fmt(p.balance) + ' POL in ' + p.address + ' (needs ' + fmt(p.threshold) + ').');
|
||||
if (kind === 'refused') return telegram('\u{1F6AB} <b>Drip Runner</b> \u00b7 ' + who + ' (' + p.email + ') tried to sign in but is not on the tester list. Add them under Admin > Settings > Testers: ' + SITE + '/admin');
|
||||
@@ -169,12 +210,22 @@ const server = http.createServer(async (req, res) => {
|
||||
const { body } = await readBody(req); const patch = {};
|
||||
for (const k of ['usdPerCredit', 'creditsPerVisit', 'poolSharePct', 'usdPerPolFallback', 'dripPol', 'dailyCapPol', 'thresholdPol', 'seedPol', 'lowBalancePol']) if (body[k] != null && body[k] !== '') patch[k] = Number(body[k]);
|
||||
if (body.signups && ['testers', 'key', 'open', 'closed'].includes(body.signups)) patch.signups = body.signups;
|
||||
if (body.trial === 'on' || body.trial === 'off') patch.trial = body.trial === 'on';
|
||||
if (Array.isArray(body.testers)) patch.testers = body.testers.map(x => String(x).trim().toLowerCase()).filter(Boolean).slice(0, 500);
|
||||
if (body.itemPol && typeof body.itemPol === 'object') patch.itemPol = Object.assign({}, ledger.settings().itemPol, body.itemPol);
|
||||
if (body.itemDrips && typeof body.itemDrips === 'object') patch.itemDrips = Object.assign({}, ledger.settings().itemDrips, body.itemDrips);
|
||||
return json(res, 200, { ok: true, settings: ledger.setSettings(patch) });
|
||||
}
|
||||
if (p === '/api/admin/faucet/tick' && req.method === 'POST') return json(res, 200, await faucet.tick(notify));
|
||||
if (p === '/api/admin/announce' && req.method === 'POST') { // post (or re-post with force) a badge for a member: {memberId, id}
|
||||
const { body } = await readBody(req); const pl = game.player(Number(body.memberId)); if (!pl) return json(res, 404, { error: 'no such player' });
|
||||
const me = { memberId: pl.memberId, username: pl.username }; const id = String(body.id || '');
|
||||
if (body.force) store.update('posted', {}, all => { all[String(pl.memberId)] = (all[String(pl.memberId)] || []).filter(k => k !== id); return all; });
|
||||
const ch = Object.keys(badge.CHAPTER_BADGES).find(k => badge.CHAPTER_BADGES[k] === id);
|
||||
if (ch) { announceChapter(me, Number(ch), 0); return json(res, 200, { ok: true, kind: 'chapter' }); }
|
||||
if (ITEM_NAMES[id]) { announceUnlock(me, id, 'hangar'); return json(res, 200, { ok: true, kind: 'unlock' }); }
|
||||
return json(res, 400, { error: 'unknown badge id' });
|
||||
}
|
||||
if (p === '/api/admin/handoff' && req.method === 'POST') { // a test token for a synthetic member (local checks only)
|
||||
const { body } = await readBody(req); return json(res, 200, { url: SITE + '/auth?t=' + sso.mint({ memberId: Number(body.memberId) || 999001, email: body.email || 'tester@example.com', wallet: body.wallet || null, username: body.username || 'tester' }) });
|
||||
}
|
||||
@@ -187,7 +238,7 @@ const server = http.createServer(async (req, res) => {
|
||||
}
|
||||
if (p === '/api/balance' && req.method === 'GET') return json(res, 200, ledger.balance(me.memberId));
|
||||
if (p === '/api/run/start' && req.method === 'POST') { const { body } = await readBody(req); const r = game.start(me, body.W, body.H); return json(res, 200, { runId: r.id, seed: r.seed, W: r.W, H: r.H, speed: r.speed, chapter: r.chapter, goal: r.goal, armed: r.armed, ship: r.ship }); }
|
||||
if (p === '/api/run/events' && req.method === 'POST') { const { body } = await readBody(req); const r = game.events(me, String(body.runId || ''), body.t, body.events, !!body.goal); if (r.cleared) r.pool = ledger.pool().available; return json(res, r.error ? 400 : 200, r); }
|
||||
if (p === '/api/run/events' && req.method === 'POST') { const { body } = await readBody(req); const r = game.events(me, String(body.runId || ''), body.t, body.events, !!body.goal); if (r.cleared) { r.pool = ledger.pool().available; if (r.cleared.first) announceChapter(me, r.cleared.chapter, r.cleared.pol); } return json(res, r.error ? 400 : 200, r); }
|
||||
if (p === '/api/run/end' && req.method === 'POST') { const { body } = await readBody(req); return json(res, 200, game.end(me, String(body.runId || ''))); }
|
||||
// refuel: hand the player to IAP for a verified visit; the run resumes when IAP confirms
|
||||
if (p === '/api/refuel/start' && req.method === 'POST') {
|
||||
@@ -205,10 +256,10 @@ const server = http.createServer(async (req, res) => {
|
||||
// the browser may carry IAP's signed receipt: it counts even when the server callback was slow
|
||||
if (!it.done && body.receipt) { const rc = sso.open(body.receipt); if (rc.ok && rc.claims.kind === 'refuel-receipt' && rc.claims.nonce === nonce) it = await creditRefuel(it, nonce, { campaignId: rc.claims.campaignId, credits: rc.claims.credits, via: 'receipt' }); }
|
||||
if (!it.done) return json(res, 200, { ok: false, reason: body.none ? 'none' : 'unverified' });
|
||||
intents.upd(nonce, x => { x.consumed = true; }); game.refuelled(me, it.runId);
|
||||
intents.upd(nonce, x => { x.consumed = true; }); game.refuelled(me, it.runId); announceRefuels(me);
|
||||
return json(res, 200, { ok: true, pool: ledger.pool().available });
|
||||
}
|
||||
if (p === '/api/hangar/buy' && req.method === 'POST') { const { body } = await readBody(req); const r = game.buy(me, String(body.item || '')); if (!r.error) { r.player = game.view(me); r.balance = ledger.balance(me.memberId); } return json(res, r.error ? 400 : 200, r); }
|
||||
if (p === '/api/hangar/buy' && req.method === 'POST') { const { body } = await readBody(req); const item = String(body.item || ''); const r = game.buy(me, item); if (!r.error) { r.player = game.view(me); r.balance = ledger.balance(me.memberId); announceUnlock(me, item, r.paid); } return json(res, r.error ? 400 : 200, r); }
|
||||
return json(res, 404, { error: 'no such route' });
|
||||
}
|
||||
res.writeHead(404, Object.assign({ 'Content-Type': 'text/plain' }, SEC)); res.end('Not found');
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
// Renders the badge card artwork (public/badges/<id>.png, 1080x1080) with Playwright, in the game's own
|
||||
// neon style. The bottom plate is left blank: lib/badge.js stamps the player's name and earnings there
|
||||
// with ffmpeg when a card is posted. Run locally: node tools/render-badges.mjs
|
||||
import pkg from 'file:///D:/Projects/MarketingAgent/qa-tester/node_modules/playwright/index.js';
|
||||
import fs from 'fs'; import path from 'path'; import { fileURLToPath } from 'url';
|
||||
const { chromium } = pkg;
|
||||
const OUT = path.join(path.dirname(fileURLToPath(import.meta.url)), '..', 'public', 'badges');
|
||||
fs.mkdirSync(OUT, { recursive: true });
|
||||
|
||||
export const BADGES = {
|
||||
magnet: { title: 'Drip Magnet', sub: 'Hangar unlock', kind: 'item', color: '#FFC24B', glyph: 'orb' },
|
||||
ship: { title: 'Courier Mk II', sub: 'Hangar unlock', kind: 'item', color: '#8FF0FF', glyph: 'ship' },
|
||||
shield: { title: 'Shield Core', sub: 'Hangar unlock · paid in POL', kind: 'item', color: '#FF6A1A', glyph: 'diamond' },
|
||||
slow: { title: 'Slow Field', sub: 'Hangar unlock · paid in POL', kind: 'item', color: '#A78BFA', glyph: 'dome' },
|
||||
ch1: { title: 'First Chapter', sub: 'Chapter 1 cleared', kind: 'chapter', color: '#8FF0FF', glyph: 'hex', n: 1 },
|
||||
ch3: { title: 'Chapter 3', sub: 'Three chapters deep', kind: 'chapter', color: '#8FF0FF', glyph: 'hex', n: 3 },
|
||||
ch5: { title: 'Chapter 5', sub: 'Halfway to double digits', kind: 'chapter', color: '#FFC24B', glyph: 'hex', n: 5 },
|
||||
ch10: { title: 'Chapter 10', sub: 'Double digits', kind: 'chapter', color: '#FFC24B', glyph: 'hex', n: 10 },
|
||||
ch15: { title: 'Chapter 15', sub: 'Deep in the network', kind: 'chapter', color: '#FF6A1A', glyph: 'hex', n: 15 },
|
||||
ch20: { title: 'Chapter 20', sub: 'Network legend', kind: 'chapter', color: '#FF6A1A', glyph: 'hex', n: 20 },
|
||||
refuel5: { title: 'Five Refuels', sub: 'Keeps the run alive', kind: 'refuel', color: '#FF6A1A', glyph: 'fuel' },
|
||||
refuel25: { title: '25 Refuels', sub: 'Runs on sponsor pages', kind: 'refuel', color: '#FF6A1A', glyph: 'fuel' },
|
||||
refuel100: { title: '100 Refuels', sub: 'Never restarts', kind: 'refuel', color: '#FFC24B', glyph: 'fuel' },
|
||||
paid: { title: 'Paid in POL', sub: 'Sent to their wallet', kind: 'paid', color: '#34D399', glyph: 'coin' },
|
||||
};
|
||||
|
||||
function glyph(g, color, n) {
|
||||
const c = color;
|
||||
if (g === 'orb') return `<div class="orb" style="--c:${c}"></div><div class="ring" style="--c:${c}"></div><div class="ring r2" style="--c:${c}"></div>`;
|
||||
if (g === 'ship') return `<div class="ship" style="--c:${c}"><i></i></div>`;
|
||||
if (g === 'diamond') return `<div class="diamond" style="--c:${c}"></div>`;
|
||||
if (g === 'dome') return `<div class="dome" style="--c:${c}"></div>`;
|
||||
if (g === 'hex') return `<div class="hex" style="--c:${c}"><span>${n}</span></div>`;
|
||||
if (g === 'fuel') return `<div class="fuel" style="--c:${c}"><i></i></div>`;
|
||||
if (g === 'coin') return `<div class="coin" style="--c:${c}"><span>POL</span></div>`;
|
||||
return '';
|
||||
}
|
||||
function html(id, b) {
|
||||
return `<!doctype html><html><head><meta charset="utf-8">
|
||||
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Orbitron:wght@700;900&family=Manrope:wght@600;800&display=swap">
|
||||
<style>
|
||||
*{box-sizing:border-box}html,body{margin:0;width:1080px;height:1080px;overflow:hidden}
|
||||
body{background:#050912;color:#EEF3FA;font-family:Manrope,sans-serif;position:relative}
|
||||
.bg{position:absolute;inset:0;background:radial-gradient(ellipse 70% 50% at 50% 30%,rgba(34,211,238,.18),transparent 60%),radial-gradient(ellipse 50% 40% at 50% 100%,rgba(255,106,26,.16),transparent 60%),linear-gradient(180deg,#03060E,#0A1327 60%,#101C3C)}
|
||||
.grid{position:absolute;inset:0;background-image:linear-gradient(rgba(34,211,238,.09) 1px,transparent 1px),linear-gradient(90deg,rgba(34,211,238,.09) 1px,transparent 1px);background-size:60px 60px;mask-image:radial-gradient(ellipse 70% 70% at 50% 45%,#000 30%,transparent 75%);-webkit-mask-image:radial-gradient(ellipse 70% 70% at 50% 45%,#000 30%,transparent 75%)}
|
||||
.stars{position:absolute;inset:0;background-image:radial-gradient(1.5px 1.5px at 20% 15%,#CFE3FF 50%,transparent 60%),radial-gradient(1.5px 1.5px at 80% 25%,#CFE3FF 50%,transparent 60%),radial-gradient(2px 2px at 65% 8%,#fff 50%,transparent 60%),radial-gradient(1.5px 1.5px at 35% 30%,#CFE3FF 50%,transparent 60%),radial-gradient(1.5px 1.5px at 90% 60%,#CFE3FF 50%,transparent 60%),radial-gradient(1.5px 1.5px at 10% 55%,#CFE3FF 50%,transparent 60%),radial-gradient(2px 2px at 50% 3%,#fff 50%,transparent 60%),radial-gradient(1.5px 1.5px at 72% 42%,#CFE3FF 50%,transparent 60%)}
|
||||
.rail{position:absolute;left:0;right:0;top:700px;height:3px;background:linear-gradient(90deg,transparent,rgba(143,240,255,.9),transparent);box-shadow:0 0 30px rgba(34,211,238,.8)}
|
||||
.logo{position:absolute;top:56px;left:0;right:0;text-align:center;font-family:Orbitron,sans-serif;font-weight:900;font-size:44px;letter-spacing:.12em;text-transform:uppercase;background:linear-gradient(180deg,#fff,#8FF0FF 45%,#22D3EE 60%,#0EA5C9);-webkit-background-clip:text;background-clip:text;color:transparent;filter:drop-shadow(0 0 18px rgba(34,211,238,.6))}
|
||||
.logo b{background:linear-gradient(180deg,#FFE9A8,#FFC24B 55%,#E08A00);-webkit-background-clip:text;background-clip:text;color:transparent}
|
||||
.eyebrow{position:absolute;top:122px;left:0;right:0;text-align:center;font-family:Orbitron,sans-serif;font-weight:700;font-size:26px;letter-spacing:.34em;text-transform:uppercase;color:#22D3EE}
|
||||
.emblem{position:absolute;top:190px;left:0;right:0;height:380px;display:grid;place-items:center}
|
||||
.emblem>*{grid-area:1/1}
|
||||
.orb{width:220px;height:220px;border-radius:50%;background:radial-gradient(circle at 35% 30%,#fff8dc,var(--c) 40%,#B45309 100%);box-shadow:0 0 60px var(--c),0 0 140px color-mix(in srgb,var(--c) 50%,transparent)}
|
||||
.ring{width:320px;height:320px;border-radius:50%;border:4px dashed color-mix(in srgb,var(--c) 70%,transparent);opacity:.8}.ring.r2{width:390px;height:390px;border-style:dotted;opacity:.45}
|
||||
.ship{width:330px;height:150px;border-radius:80px;background:linear-gradient(180deg,#fff,#DCE6F5 50%,#8FA3C4);box-shadow:0 0 60px var(--c),0 0 140px color-mix(in srgb,var(--c) 45%,transparent);position:relative}
|
||||
.ship i{position:absolute;right:60px;top:50%;width:46px;height:46px;margin-top:-23px;border-radius:50%;background:var(--c);box-shadow:0 0 30px var(--c)}
|
||||
.ship:before{content:"";position:absolute;left:-90px;top:50%;width:120px;height:36px;margin-top:-18px;border-radius:18px;background:linear-gradient(90deg,transparent,var(--c));filter:blur(6px)}
|
||||
.diamond{width:230px;height:230px;transform:rotate(45deg);border-radius:36px;background:linear-gradient(135deg,#FFD1B3,var(--c) 50%,#B23A00);box-shadow:0 0 60px var(--c),0 0 140px color-mix(in srgb,var(--c) 45%,transparent);outline:6px solid rgba(255,255,255,.35);outline-offset:18px}
|
||||
.dome{width:300px;height:170px;border-radius:150px 150px 24px 24px;background:radial-gradient(ellipse at 50% 100%,var(--c),#4C1D95 70%);box-shadow:0 0 60px var(--c),0 0 140px color-mix(in srgb,var(--c) 45%,transparent);border-top:6px solid rgba(255,255,255,.5)}
|
||||
.hex{width:300px;height:300px;clip-path:polygon(50% 0,93% 25%,93% 75%,50% 100%,7% 75%,7% 25%);background:linear-gradient(160deg,color-mix(in srgb,var(--c) 85%,#fff),var(--c) 45%,#0B1D3A);display:grid;place-items:center;filter:drop-shadow(0 0 40px var(--c))}
|
||||
.hex span{font-family:Orbitron,sans-serif;font-weight:900;font-size:150px;color:#050912;letter-spacing:-.02em}
|
||||
.fuel{width:230px;height:290px;border-radius:40px 40px 30px 30px;background:linear-gradient(180deg,#0E1730,#0E1730 40%,var(--c) 40%,#B23A00);border:8px solid rgba(255,255,255,.4);box-shadow:0 0 60px var(--c),0 0 140px color-mix(in srgb,var(--c) 45%,transparent);position:relative}
|
||||
.fuel i{position:absolute;top:-40px;left:50%;width:90px;height:50px;margin-left:-45px;border-radius:16px 16px 0 0;background:#DCE6F5}
|
||||
.coin{width:260px;height:260px;border-radius:50%;background:radial-gradient(circle at 35% 30%,#d9fff0,var(--c) 45%,#047857 100%);box-shadow:0 0 60px var(--c),0 0 140px color-mix(in srgb,var(--c) 45%,transparent);display:grid;place-items:center;border:10px solid rgba(255,255,255,.35)}
|
||||
.coin span{font-family:Orbitron,sans-serif;font-weight:900;font-size:70px;color:#052e1c;letter-spacing:.06em}
|
||||
.title{position:absolute;top:590px;left:0;right:0;text-align:center;font-family:Orbitron,sans-serif;font-weight:900;font-size:66px;letter-spacing:.06em;text-transform:uppercase;color:#fff;text-shadow:0 0 30px var(--c),0 4px 0 rgba(0,0,0,.4)}
|
||||
.sub{position:absolute;top:668px;left:0;right:0;text-align:center;font-weight:800;font-size:30px;letter-spacing:.14em;text-transform:uppercase;color:#AFC0D8}
|
||||
.plate{position:absolute;left:90px;right:90px;top:760px;height:250px;border-radius:32px;background:linear-gradient(180deg,rgba(20,31,58,.95),rgba(14,23,45,.98));border:2px solid #24365F;box-shadow:0 30px 60px -20px rgba(0,0,0,.9)}
|
||||
.plate:before{content:"";position:absolute;left:0;right:0;top:0;height:3px;border-radius:32px 32px 0 0;background:linear-gradient(90deg,transparent,#22D3EE,#FFC24B,transparent)}
|
||||
.foot{position:absolute;bottom:26px;left:0;right:0;text-align:center;font-weight:800;font-size:22px;letter-spacing:.2em;text-transform:uppercase;color:#6E82A3}
|
||||
</style></head><body>
|
||||
<div class="bg"></div><div class="grid"></div><div class="stars"></div><div class="rail"></div>
|
||||
<div class="logo">Drip <b>Runner</b></div>
|
||||
<div class="eyebrow">${b.kind === 'paid' ? 'Payout sent' : 'Achievement unlocked'}</div>
|
||||
<div class="emblem">${glyph(b.glyph, b.color, b.n)}</div>
|
||||
<div class="title" style="--c:${b.color}">${b.title}</div>
|
||||
<div class="sub">${b.sub}</div>
|
||||
<div class="plate"></div>
|
||||
<div class="foot">InstantAdPay members · paid in POL</div>
|
||||
</body></html>`;
|
||||
}
|
||||
const browser = await chromium.launch(); const page = await browser.newPage({ viewport: { width: 1080, height: 1080 }, deviceScaleFactor: 1 });
|
||||
for (const [id, b] of Object.entries(BADGES)) {
|
||||
await page.setContent(html(id, b), { waitUntil: 'networkidle' }); await page.evaluate(() => document.fonts.ready); await page.waitForTimeout(300);
|
||||
await page.screenshot({ path: path.join(OUT, id + '.png'), type: 'png' }); console.log('rendered', id);
|
||||
}
|
||||
await browser.close();
|
||||