mirror of
https://github.com/burrow-dev/burrow-server.git
synced 2026-11-18 17:27:50 -05:00
feat(account): web item giver with colour pickers, den variants, tints and previews
/account/items, linked from the account page and using its sign-in, gives items to the account signed in: - clothing: the item's own colours, or four colours of your own as a picker, #RRGGBB, or AJ's numbers (palette places, or the whole item's colour id signed or unsigned), converted as you type; hex colours not in the palette become an exact custom colour - den items: the variants their art has (lib/den-variants.json, made by tools/den-variants.sh) and a whole-item tint with a strength, kept in the item's version above the variant and drawn by DenItemHelper (build 83) - a preview of each: clothing icons coloured on the page as the game colours them, den items played by Ruffle in a sandboxed frame through public/item-preview.swf (tools/preview-host) a give with a custom colour id that does not exist is refused.
This commit is contained in:
1 parent
44af83f1c5
commit
7cfef493fa
18 files changed
+1958
-7
No files matched your search
@@ -26,6 +26,8 @@ const recoveryMail = require("./recoverymail.js");
|
||||
const world = require("./world.js");
|
||||
const chatStyles = require("./chatstyles.js");
|
||||
const roles = require("./roles.js");
|
||||
const admin = require("./admin.js");
|
||||
const itemPreview = require("./itempreview.js");
|
||||
|
||||
// the account page at /account: what a player can do about their own
|
||||
// account from a browser. they sign in with the game's username and
|
||||
@@ -566,6 +568,16 @@ const PAGE_HEADERS = {
|
||||
+ "form-action 'none'; frame-ancestors 'none'; base-uri 'none'"),
|
||||
};
|
||||
|
||||
// the web item giver shows den items in frames of public/item-preview.html,
|
||||
// which plays them with Ruffle (a Flash player, from jsDelivr).
|
||||
const ITEMS_PAGE_POLICY = "default-src 'none'; script-src 'unsafe-inline'; style-src 'unsafe-inline'; connect-src 'self'; img-src 'self' data:; font-src 'self'; "
|
||||
+ "frame-src 'self'; form-action 'none'; frame-ancestors 'none'; base-uri 'none'";
|
||||
const RUFFLE = "https://cdn.jsdelivr.net/npm/@ruffle-rs/[email protected]/";
|
||||
const PREVIEW_POLICY = `default-src 'none'; script-src 'unsafe-inline' 'wasm-unsafe-eval' ${RUFFLE}; connect-src 'self' ${RUFFLE}; `
|
||||
+ "style-src 'unsafe-inline'; img-src 'self' data: blob:; media-src 'self' data: blob:; worker-src blob:; "
|
||||
+ "form-action 'none'; frame-ancestors 'self'; base-uri 'none'; sandbox allow-scripts";
|
||||
const artFetches = limits.limiter(600, 600000); // item pictures for the web item giver, per address in ten minutes
|
||||
|
||||
// A request that changes something must come from this server's own page.
|
||||
const sameOrigin = limits.originAllowed;
|
||||
|
||||
@@ -581,6 +593,41 @@ const handle = async (req, res, url, from, web) => {
|
||||
web.send(res, 200, captcha.withScriptVersion(await fs.promises.readFile(path.join(config.publicDir, "account.html"))), "text/html; charset=utf-8");
|
||||
return;
|
||||
}
|
||||
// the item giver on the web (public/items.html), with this page's sign-in.
|
||||
if (route === "GET /account/items") {
|
||||
res.setHeader("Content-Security-Policy", ITEMS_PAGE_POLICY);
|
||||
web.send(res, 200, await fs.promises.readFile(path.join(config.publicDir, "items.html")), "text/html; charset=utf-8");
|
||||
return;
|
||||
}
|
||||
// its den item previews (lib/itempreview.js): a page of their own in a
|
||||
// frame, sandboxed, as they run a Flash player from elsewhere (Ruffle).
|
||||
if (route === "GET /account/item-preview") {
|
||||
res.setHeader("Content-Security-Policy", PREVIEW_POLICY);
|
||||
res.setHeader("X-Frame-Options", "SAMEORIGIN");
|
||||
web.send(res, 200, await fs.promises.readFile(path.join(config.publicDir, "item-preview.html")), "text/html; charset=utf-8");
|
||||
return;
|
||||
}
|
||||
const art = /^GET \/account\/(item-preview\.swf|art\/(clothing|den)\/(\d{1,9}))$/.exec(route);
|
||||
if (art) {
|
||||
// fetched from the preview's sandbox, which has no origin of its own
|
||||
res.setHeader("Access-Control-Allow-Origin", "*");
|
||||
if (art[1] === "item-preview.swf") {
|
||||
web.send(res, 200, await fs.promises.readFile(path.join(config.publicDir, "item-preview.swf")), "application/x-shockwave-flash");
|
||||
return;
|
||||
}
|
||||
if (!artFetches.allow(from.address)) {
|
||||
reply(429, {error: "Too many at once. Try again in a minute."});
|
||||
return;
|
||||
}
|
||||
const found = art[2] === "den" ? await itemPreview.denArt(Number(art[3])) : await itemPreview.clothingIcon(Number(art[3]));
|
||||
if (!found) {
|
||||
reply(404, {error: "No picture."});
|
||||
return;
|
||||
}
|
||||
res.setHeader("Cache-Control", "public, max-age=3600");
|
||||
web.send(res, 200, found, art[2] === "den" ? "application/x-shockwave-flash" : "application/json");
|
||||
return;
|
||||
}
|
||||
if (route === "GET /account/recover") {
|
||||
web.send(res, 200, captcha.withScriptVersion(await fs.promises.readFile(path.join(config.publicDir, "recover.html"))), "text/html; charset=utf-8");
|
||||
return;
|
||||
@@ -854,6 +901,28 @@ const handle = async (req, res, url, from, web) => {
|
||||
case "GET /account/api/me":
|
||||
reply(200, profile(account, from));
|
||||
return;
|
||||
// the item giver (above, and lib/admin.js): for the account signed in
|
||||
// here only, as the in-game one is for the one playing; not while banned.
|
||||
case "GET /account/api/giver":
|
||||
case "GET /account/api/colour":
|
||||
case "POST /account/api/give": {
|
||||
if (banFor(account, from) || account.nameRejected) {
|
||||
reply(403, {error: "Not now."});
|
||||
return;
|
||||
}
|
||||
if (route === "GET /account/api/colour") {
|
||||
const result = await admin.colourLookup(url.searchParams);
|
||||
reply(result.status, result.body);
|
||||
return;
|
||||
}
|
||||
if (req.method === "GET") {
|
||||
reply(200, await admin.searchFor(account, url.searchParams));
|
||||
return;
|
||||
}
|
||||
const result = admin.giveAs(account, body);
|
||||
reply(result.status, result.body);
|
||||
return;
|
||||
}
|
||||
// for the trade offer form: what the player could give, and what
|
||||
// another player has up for trade.
|
||||
case "GET /account/api/tradable": {
|
||||
|
||||
Reference in new issue
Block a user