Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
b3d1e18
Wallet server: generated catalogue and captains list for functions/, …
claude Nov 19, 2026
fda9cf0
Wallet server: /api/wallet (balance, buy, chest, gift, seen), emerald…
claude Nov 19, 2026
65e1869
Wallet client: wallet.js and cosmetics.js use /api/wallet when the se…
claude Nov 19, 2026
8373c98
Shop: emerald Buy buttons carry their pack id; Playwright tests for t…
claude Nov 19, 2026
e5be2e6
Merge branch 'upmain' into wallet-server
claude Nov 19, 2026
a38d9f9
Wallet server: filter gift notes and names with a server copy of name…
claude Nov 19, 2026
1c0c850
Wallet server tests: the two-buys race test now forces both buys to r…
claude Nov 19, 2026
18ae96a
Wallet hardening: webhook mode/Payment Link checks, refunds and charg…
claude Nov 19, 2026
4a25ee4
Owned check: public GET /api/owned?uids= (edge-cached, limited) and e…
claude Nov 19, 2026
e273871
README: wallet hardening (Payment Links, mode, refunds and chargeback…
claude Nov 19, 2026
ffeb4fb
Wallet: chest count must be a number and a gift recipient a string; t…
claude Nov 19, 2026
8685bd0
Checkout: 'All sales are final. No refunds.' on Stripe's page (custom…
claude Nov 19, 2026
0c6c8fd
Shop: "All sales are final. No refunds." under each emerald Buy butto…
claude Nov 19, 2026
985d590
README: all sales final, Payment help form (where requests land, limi…
claude Nov 19, 2026
a86d670
Merge branch 'upmain' into wallet-server
claude Nov 19, 2026
8db098b
Merge branch 'wallet-server' into wallet-hardening
claude Nov 19, 2026
b740778
Server catalogue regenerated after merging main (Carbon Star is in th…
claude Nov 19, 2026
0ce28c1
Merge branch 'wallet-server' into wallet-hardening
claude Nov 19, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions README.md

Large diffs are not rendered by default.

75 changes: 69 additions & 6 deletions e63334287a3deaa3/cosmetics.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,16 @@
* Set it to true to open everything. For testing only, ?cosmetics=1 in the page address turns it on, and only when the
* page is on localhost or driven by an automated browser (navigator.webdriver): that check is captains.js's, the one
* file every hidden cosmetic asks (without it on the page the address does nothing).
* The site's captains are NOT let in here early. captains.js lets them see the games' own screens (Driftfall's Locker,
* THE REAL SWITCH is wallet.js's PAYMENTS.enabled: true opens the shop for everyone with the server wallet (server()
* below; functions/_wallet.js): balance, locker and every purchase, chest and gift come from and go to the server. The
* browser-only locker and wallet (the old local mode) are kept only for the ?cosmetics=1 test switch. ENABLED, if set,
* also opens the shop with the server wallet.
* CAPTAINS' PREVIEW (CAPTAIN_PREVIEW, below): while PAYMENTS.enabled is false, a captain who opens the shop page gets the
* real shop with the server wallet in that browser tab (sessionStorage 'cosmetics:preview', set by shop/ once
* captains.js confirms the captain), so the owners can try the whole flow on the live site; everyone else still sees
* "not open yet", and the server refuses everyone but captains until PAYMENTS.enabled is true. Turn the preview off
* by setting CAPTAIN_PREVIEW to false (?preview=0 on the shop page also ends it for that tab).
* Apart from that preview, the site's captains are NOT let in here early. captains.js lets them see the games' own screens (Driftfall's Locker,
* Boostball's garage and Kit, Slipstream's Garage), where every item is free to wear while this file is off; the
* shop, the wallet, earning and buying stay shut for them like everyone else, so on() asks captains.js's open(), which
* leaves captains out, not may().
Expand Down Expand Up @@ -67,7 +76,9 @@
'use strict';
if (window.BackRoomCosmetics) return;

var ENABLED = false; // THE SWITCH: false keeps every part of the cosmetics hidden; true opens the shop for everyone.
var ENABLED = false; // false keeps every part of the cosmetics hidden (see THE REAL SWITCH above: wallet.js PAYMENTS.enabled)
var CAPTAIN_PREVIEW = true; // the captains' preview of the real shop (see above); false turns it off for everyone
var PREVIEW_KEY = 'cosmetics:preview';

var me0 = document.currentScript;
var HUB = !!(me0 && me0.hasAttribute('data-hub'));
Expand Down Expand Up @@ -97,7 +108,22 @@

var SHARED = window.BackRoomCaptains || null; // captains.js: the test switch lives there, with the others
var FLAG = !!(SHARED && SHARED.open(false, 'cosmetics'));
function on() { return !!(api.ENABLED || FLAG); }
function on() { return server() || FLAG; }
// The server wallet is in use: PAYMENTS.enabled (wallet.js), ENABLED, or the captains' preview on the shop page.
// Otherwise, with the test switch alone, the old browser-only mode.
function payments() { try { var w = window.BackRoomWallet; return !!(w && w.PAYMENTS && w.PAYMENTS.enabled); } catch (e) { return false; } }
function shopPage() { try { return /^\/e63334287a3deaa3\/shop(\/(index\.html)?)?$/.test(location.pathname); } catch (e) { return false; } }
function previewOn() { if (!CAPTAIN_PREVIEW || !shopPage()) return false; try { return sessionStorage.getItem(PREVIEW_KEY) === '1'; } catch (e) { return false; } }
function server() { return !!(api.ENABLED || payments() || previewOn()); }
// shop/ calls these: start the preview once captains.js has confirmed a captain; stop it when that changes.
function previewAllowed() { return CAPTAIN_PREVIEW && shopPage() && !payments() && !api.ENABLED; }
function startPreview() {
if (!previewAllowed() || !(SHARED && SHARED.captain && SHARED.captain())) return false;
try { sessionStorage.setItem(PREVIEW_KEY, '1'); } catch (e) { return false; }
return previewOn();
}
function stopPreview() { try { sessionStorage.removeItem(PREVIEW_KEY); } catch (e) {} }
try { if (/[?&]preview=0(&|$)/.test(location.search)) stopPreview(); } catch (e) {}

// ---------------- Skins ----------------
// look: bg / bg2 background colours, bgp background pattern, outfit, head (piece on the head), tone (skin colour, optional),
Expand Down Expand Up @@ -1134,14 +1160,25 @@
// lists every skin, accessory and game item as owned, and save() writes back only what they really own (L.raw), so
// nothing they didn't buy is ever saved, mirrored into their account or kept after they sign out. load(true) is the
// real locker alone (the account mirror and buying use it).
function cap() { try { return !!(on() && SHARED && SHARED.captain && SHARED.captain()); } catch (e) { return false; } }
function cap() {
try { if (on() && server() && window.BackRoomWallet && window.BackRoomWallet.unlimited && window.BackRoomWallet.unlimited()) return true; } catch (e) {}
try { return !!(on() && SHARED && SHARED.captain && SHARED.captain()); } catch (e) { return false; }
}
function load(raw) {
var o = json(ls(KEY)), L = { v: 1, s: [], a: [], g: [], e: { skin: '' }, ge: {} };
SLOTS.forEach(function (k) { L.e[k] = ''; });
if (!obj(o) || o.v !== 1) o = {};
if (server()) {
// The server wallet: what's owned is the server's answer (wallet.js), plus the game items a game hands over
// itself (give: free to everyone, so kept in this browser). Only what is worn (e, ge) is read from here.
var w = window.BackRoomWallet, mine = w && w._owned ? w._owned() : [];
mine.forEach(function (id) { if (SKINS_BY_ID[id]) L.s.push(id); else if (ACC_BY_ID[id]) L.a.push(id); else if (ITEM_BY_ID[id]) L.g.push(id); });
if (Array.isArray(o.g)) o.g.forEach(function (id) { var it = ITEM_BY_ID[id]; if (it && it.give && L.g.indexOf(id) < 0) L.g.push(id); });
} else {
if (Array.isArray(o.s)) o.s.forEach(function (id) { if (SKINS_BY_ID[id] && L.s.indexOf(id) < 0) L.s.push(id); });
if (Array.isArray(o.a)) o.a.forEach(function (id) { if (ACC_BY_ID[id] && L.a.indexOf(id) < 0) L.a.push(id); });
if (Array.isArray(o.g)) o.g.forEach(function (id) { if (ITEM_BY_ID[id] && L.g.indexOf(id) < 0) L.g.push(id); });
}
if (!raw && cap()) {
Object.defineProperty(L, 'raw', { value: { s: L.s, a: L.a, g: L.g }, enumerable: false });
L.s = SKINS.map(function (x) { return x.id; }); L.a = ACCESSORIES.map(function (x) { return x.id; }); L.g = GAME_ITEMS.map(function (x) { return x.id; });
Expand All @@ -1155,6 +1192,14 @@
}
function save(L) {
if (L.raw) { var r = L.raw; L = { v: 1, s: r.s, a: r.a, g: r.g, e: L.e, ge: L.ge }; } // a captain: only what they really own
if (server()) {
// The server wallet: ownership is never saved here (the server holds it). What was saved before is left as it
// was; only what is worn and the game-given items change.
var o = json(ls(KEY)); o = obj(o) && o.v === 1 ? o : {};
var keep = Array.isArray(o.g) ? o.g.filter(function (id) { return ITEM_BY_ID[id]; }) : [];
L.g.forEach(function (id) { if (ITEM_BY_ID[id] && ITEM_BY_ID[id].give && keep.indexOf(id) < 0) keep.push(id); });
L = { v: 1, s: Array.isArray(o.s) ? o.s : [], a: Array.isArray(o.a) ? o.a : [], g: keep, e: L.e, ge: L.ge };
}
if (!L.g.length && !Object.keys(L.ge || {}).length) { delete L.g; delete L.ge; } // no game items: the saved locker is exactly what it was before they existed
ls(KEY, JSON.stringify(L)); try { document.dispatchEvent(new CustomEvent('backroom:cosmetics', { detail: { equipped: equipped() } })); } catch (e) {} }
function equip(id) {
Expand Down Expand Up @@ -1265,9 +1310,12 @@
// unknown, money (emerald packs: wallet.js EMERALD_PACKS and PAYMENTS), owned (you already own everything in it),
// wallet (no wallet.js), funds (not enough mangos).
function emeraldPack(id) { var w = W(); return w && w.EMERALD_PACKS ? w.EMERALD_PACKS.filter(function (e) { return e.id === id; })[0] : null; }
// With the server wallet buy() returns a PROMISE of the same answer (the server buys, rolls and fills the locker;
// extra reasons: signin, closed, server, duplicate, with a message). Callers: Promise.resolve(buy(id)).then(...).
function buy(packId, opts) {
var p = pack(packId);
if (!on()) return { ok: false, reason: 'off' };
if (server()) return serverBuy(p, packId);
if (!p && emeraldPack(packId)) return { ok: false, reason: 'money', checkout: W().PAYMENTS.checkout(packId) };
if (!p) return { ok: false, reason: 'unknown' };
var pv = preview(packId);
Expand All @@ -1280,6 +1328,20 @@
if (f.refund) w.earn(f.refund, f.dups === 1 ? 'Back for a duplicate' : 'Back for ' + f.dups + ' duplicates');
return { ok: true, pack: p.id, spent: free ? 0 : p.price, got: f.got, refund: f.refund, balance: w.balance() };
}
function serverBuy(p, packId) {
if (!p && emeraldPack(packId)) return Promise.resolve({ ok: false, reason: 'money' });
if (!p) return Promise.resolve({ ok: false, reason: 'unknown' });
if (preview(packId).all) return Promise.resolve({ ok: false, reason: 'owned' });
var w = W(); if (!w || !w._buy) return Promise.resolve({ ok: false, reason: 'wallet' });
var dm = /^draw-(\d+)$/.exec(p.id);
return (dm ? w._chest(+dm[1]) : w._buy(p.id)).then(function (r) {
if (!r || !r.ok) return r || { ok: false, reason: 'server' };
var got = { skins: (r.got && r.got.skins) || [], acc: (r.got && r.got.acc) || [], items: (r.got && r.got.items) || [], draws: (r.got && r.got.draws) || [] };
var L = load(), first = got.skins[0] || (got.draws[0] && got.draws[0].skin);
if (!L.e.skin && first && L.s.indexOf(first) >= 0) { L.e.skin = first; save(L); }
return { ok: true, pack: p.id, spent: r.spent, got: got, refund: r.refund || 0, balance: r.balance };
});
}
// Put what a pack (or one item, or chests) holds into the real locker, opening chests here. Pays nothing: the caller
// pays the refund for duplicates (buy() above, or wallet.js's grant() for a gift). -> { got, dups, refund }
function fill(p, opts) {
Expand All @@ -1297,7 +1359,7 @@
return { got: got, dups: dups, refund: dups * DUP_REFUND };
}
// A gift arriving (wallet.js's grant('gift'), the only caller): fill the locker with what packId holds, free.
function receive(packId, opts) { var p = pack(packId); if (!on() || !p) return null; var f = fill(p, opts); f.pack = p; return f; }
function receive(packId, opts) { var p = pack(packId); if (!on() || server() || !p) return null; var f = fill(p, opts); f.pack = p; return f; }

// ---------------- Drawing (64 × 64 units, avatar.js's grid) ----------------
var INK = '#1B1513', WH = '#FFFFFF';
Expand Down Expand Up @@ -1527,7 +1589,8 @@
// ---------------- API ----------------
var api = {
ENABLED: ENABLED,
on: on,
on: on, server: server, previewAllowed: previewAllowed, startPreview: startPreview, stopPreview: stopPreview,
previewing: function () { return previewOn() && !payments() && !api.ENABLED; },
SKINS: SKINS, ACCESSORIES: ACCESSORIES, SKINS_BY_ID: SKINS_BY_ID, ACCESSORIES_BY_ID: ACC_BY_ID, SLOTS: SLOTS, SLOT_NAMES: SLOT_NAMES,
RARITY: RARITY, RARITY_BY_ID: RARITY_BY_ID, RARITY_TOTAL: RARITY_TOTAL, PACKS: PACKS, PACKS_BY_ID: PACKS_BY_ID,
PRICE: PRICE, CHEST_PRICE: CHEST_PRICE, DUP_REFUND: DUP_REFUND, pack: pack,
Expand Down
82 changes: 82 additions & 0 deletions e63334287a3deaa3/owned.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* BackRoomOwned: may ANOTHER player be drawn wearing this item? Asks the server (GET /api/owned?uids=…, public and
* edge-cached), because each player's own page can be edited to wear anything, and other players' pages would then
* draw it. Games call this before drawing someone else's skin, accessory or game item once the shop is public.
*
* BackRoomOwned.check(uid, itemId) → true (owns it, or a captain, or a give item anyone may wear),
* false (doesn't own it: draw the default look),
* undefined (not known yet, or the server can't be reached: draw the default
* look for now; onChange fires when the answer arrives)
* BackRoomOwned.want(uids) ask ahead for a list of uids (e.g. everyone in the room as they join)
* BackRoomOwned.onChange(fn) fn(uids) after answers arrive, so the game can redraw those players
* BackRoomOwned.active() true once the shop is public (wallet.js PAYMENTS.enabled): until then games
* needn't check at all
*
* Calls are batched (up to 24 uids a request, sent 50 ms after the first ask) and answers kept for 60 seconds. It
* never throws and never blocks a frame: a failure only means "not known yet" (retried after 30 seconds).
* It can't stop a player seeing an item on their OWN screen: that page is theirs to edit.
*/
(function () {
'use strict';
if (window.BackRoomOwned) return;
var API = /(^|\.)ascoding11\.com$/.test(location.hostname) ? '/api/' : 'https://ascoding11.com/api/';
var MAX = 24, KEEP = 60000, RETRY = 30000, UID = /^[A-Za-z0-9_-]{6,128}$/;
var known = {}; // uid -> { t: time, all: bool, set: { id: 1 } } or { t, failed: true }
var give = {}; // item ids anyone may wear (free or earned in a game), from the server
var queue = [], timer = 0, inflight = {}, listeners = [];

function now() { return Date.now(); }
function fresh(k) { return k && now() - k.t < (k.failed ? RETRY : KEEP); }
function want(uids) {
(uids || []).forEach(function (u) {
u = String(u || '');
if (!UID.test(u) || fresh(known[u]) || inflight[u] || queue.indexOf(u) >= 0) return;
queue.push(u);
});
if (queue.length && !timer) timer = setTimeout(flush, 50);
}
function flush() {
timer = 0;
while (queue.length) send(queue.splice(0, MAX));
}
function send(batch) {
batch.forEach(function (u) { inflight[u] = 1; });
var done = function (players) {
var t = now();
batch.forEach(function (u) {
delete inflight[u];
var p = players && players[u];
if (p === '*') known[u] = { t: t, all: true, set: {} };
else if (Array.isArray(p)) { var s = {}; p.forEach(function (id) { s[id] = 1; }); known[u] = { t: t, all: false, set: s }; }
else known[u] = { t: t, failed: true };
});
listeners.forEach(function (fn) { try { fn(batch.slice()); } catch (e) {} });
};
try {
fetch(API + 'owned?uids=' + batch.map(encodeURIComponent).join(','), { credentials: 'omit' })
.then(function (r) { return r.ok ? r.json() : null; })
.then(function (d) {
if (d && d.give && Array.isArray(d.give)) d.give.forEach(function (id) { give[id] = 1; });
done(d && d.v === 1 && d.players);
}, function () { done(null); });
} catch (e) { done(null); }
}
function check(uid, itemId) {
uid = String(uid || ''); itemId = String(itemId || '');
if (!itemId) return true;
if (give[itemId]) return true;
var k = known[uid];
if (!fresh(k)) want([uid]);
if (!k || k.failed) return undefined;
return k.all || !!k.set[itemId];
}
function active() {
try { var W = window.BackRoomWallet || (window.parent && window.parent.BackRoomWallet); return !!(W && W.PAYMENTS && W.PAYMENTS.enabled); }
catch (e) { return false; }
}
window.BackRoomOwned = {
check: check, want: want, active: active,
onChange: function (fn) { if (typeof fn === 'function') listeners.push(fn); },
_reset: function () { known = {}; give = {}; queue = []; inflight = {}; if (timer) clearTimeout(timer); timer = 0; }
};
})();
Loading
Loading