diff --git a/public/account.html b/public/account.html index 5b4e4a7..3346a0e 100644 --- a/public/account.html +++ b/public/account.html @@ -136,6 +136,14 @@ input:not([type="checkbox"]), textarea { width: 100%; } textarea { min-height: 110px; resize: vertical; } .row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 12px; } + /* their own custom items: a card each, its picture on the left */ + .my-items { display: grid; gap: 10px; margin-top: 10px; } + .my-item { display: grid; grid-template-columns: 72px 1fr; gap: 12px; align-items: center; padding: 10px; border: 1px solid var(--line); border-radius: 14px; } + .my-item .art { width: 72px; height: 72px; border-radius: 10px; background: var(--raised, #1a1a1a); display: grid; place-items: center; overflow: hidden; color: var(--muted); font-size: 11px; text-align: center; } + .my-item .art img { max-width: 100%; max-height: 100%; image-rendering: auto; } + .my-item .row { margin-top: 6px; } + .my-item input[type="text"] { flex: 1; min-width: 140px; } + .my-item input[type="file"] { display: none; } .captcha { margin-top: 12px; } .tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; } .tile { padding: 12px 14px 11px; border: 1px solid var(--line); border-radius: 18px; } @@ -303,6 +311,14 @@ +
+

My items

+

+
+ +

+
+ +
+

Restrict items

+

Find any item, the game's or a custom one, by name or id, and lock it out of the item finder: players can no longer find it or take it there (staff still can).

+
+ + + +
+ + +

+
@@ -541,6 +686,97 @@ + + +
+

Role permissions

+

What each role may do. A change counts at once, for staff playing too. Each staff member can also be given more, or less, on their account.

+
+ + +
+

+

What they did

@@ -704,6 +949,7 @@

+ @@ -557,7 +753,7 @@ const REFRESH_MS = 8000; let signedIn = false; - let tab = "players"; + let tab = "home"; let selected = null; // the username of the player whose box is open let players = []; let chatQuery = null; // what the Chat page shows: {username, room, text} @@ -723,8 +919,52 @@ if (document.activeElement !== $("ban-reason")) { $("ban-reason").value = player.banned === 0 ? "" : player.banReason; } + renderNotes(player.notes || []); + renderMade(player); }; + // what they made in the Item Maker, for a report about one of its pictures + let uploadsStopped = false; + const renderMade = player => { + $("made-block").hidden = !permissions.has("items.approve"); + const made = player.madeItems || []; + $("no-made-items").hidden = made.length > 0; + $("made-items").replaceChildren(...made.map(item => { + const row = el("div", undefined, "made-item"); + const art = el("div", item.artUrl ? undefined : "No picture", "art"); + if (item.artUrl) { + art.append(guardedPicture(item.artUrl)); + } + const about = el("div"); + about.append(el("strong", item.name), el("div", `${item.kind === "den" ? "den item" : "clothing"} ${item.id}${item.artWaiting ? " · picture waiting for approval" : ""}`, "hint")); + row.append(art, about); + if (item.artUrl) { + row.append(button("Take picture off", async () => { + if (!confirm(`Take the picture off ${item.name}? It counts against ${player.username}.`)) { + return; + } + const result = await api("review", {action: "takePicture", kind: item.kind, id: item.id}); + setStatus($("detail-status"), said(result), !result.ok); + await loadDetail(); + }, "danger")); + } + return row; + })); + uploadsStopped = player.picturesStopped; + $("uploads-state").textContent = player.picturesStopped ? "Picture uploads: stopped." + : `Picture uploads: allowed (${player.pictureStrikes || 0} of 3 turned away).`; + $("uploads-toggle").textContent = player.picturesStopped ? "Let them upload again" : "Stop their picture uploads"; + $("uploads-toggle").className = player.picturesStopped ? "" : "danger"; + }; + $("uploads-toggle").addEventListener("click", async () => { + if (!selected) { + return; + } + const result = await api("review", {action: "uploads", username: selected, blocked: !uploadsStopped}); + setStatus($("detail-status"), said(result), !result.ok); + await loadDetail(); + }); + // the player's Jam-a-Grams or wall posts, sent and received // (lib/chatlog.js): asked with the rest of the extras, and a page more // with Older. "(not sent)" in front is one the filter stopped. @@ -794,12 +1034,45 @@ $("no-timeline").hidden = events.length > 0; }; + // mod notes (lib/modnotes.js): the newest first, each removable by its + // writer (or an admin). + const renderNotes = notes => { + $("player-notes").replaceChildren(...notes.map(note => { + const row = el("li"); + const head = el("div", `${when(note.at)} · ${note.by}`, "who"); + row.append(head, note.text); + head.append(button("Remove", async () => { + if (!confirm("Remove this note?")) { + return; + } + const result = await api("act", {username: selected, action: "deleteNote", id: note.id}); + setStatus($("detail-status"), said(result), !result.ok); + refresh(); + })); + return row; + })); + }; + $("note-add").addEventListener("click", async () => { + const text = $("note-text").value.trim(); + if (!text || !selected) { + return; + } + $("note-add").disabled = true; + const result = await api("act", {username: selected, action: "note", text}); + $("note-add").disabled = false; + setStatus($("detail-status"), said(result), !result.ok); + if (result.ok) { + $("note-text").value = ""; + refresh(); + } + }); + const select = username => { selected = username; hashArg = username || ""; setHash(); setStatus($("detail-status"), ""); - for (const id of ["ban-hours", "ban-reason", "silence-hours", "message-text", "warn-note"]) { + for (const id of ["ban-hours", "ban-reason", "silence-hours", "message-text", "warn-note", "note-text"]) { $(id).value = ""; } renderPlayers(); @@ -898,11 +1171,15 @@ const placeOf = line => (line.kind === "whisper" ? `Whisper to ${line.to}` : line.kind === "jamagram" ? `Jam-a-Gram to ${line.to}` : line.kind === "wall" ? `On ${line.to}'s wall` : line.room); + // a line as typed, its emoji ("\{1f600}", as the game sends them) as themselves + const withEmoji = text => String(text).replace(/\\\{([0-9a-f]{2,6}(?:-[0-9a-f]{2,6}){0,9})\}/g, + (whole, hex) => String.fromCodePoint(...hex.split("-").map(part => parseInt(part, 16)))); + const lineNode = (line, inContext = false) => { const item = el("li", undefined, inContext && line.marked ? "this" : ""); const who = button(line.username, () => openPlayer(line.username), "chat-who"); const text = el("span", undefined, "chat-text"); - text.append(line.text || "(no words)", el("span", placeOf(line), "chat-room")); + text.append(withEmoji(line.text || "(no words)"), el("span", placeOf(line), "chat-room")); item.append(el("span", when(line.at), "chat-time"), who, text); if (!inContext) { item.append(button("Around", () => showContext(line.id), "chat-more")); @@ -1362,8 +1639,38 @@ const result = await api("items", {action: "update", kind: item.kind, id: item.id, inShop: !item.inShop}); setStatus($("item-status"), said(result), !result.ok); await refresh(); + }), " ", + button(item.locked ? "Unlock" : "Lock", async () => { + const result = await api("items", {action: item.locked ? "unlock" : "lock", kind: item.kind, id: item.id}); + setStatus($("item-status"), said(result), !result.ok); + await refresh(); + }), " ", + button("Picture", () => pickPicture(item)), " ", + ...(item.artUrl && item.kind === "clothing" ? [button(item.artMode === "texture" ? "Worn: texture" : "Worn: sticker", async () => { + const result = await api("items", {action: "look", kind: item.kind, id: item.id, look: item.artMode === "texture" ? "sticker" : "texture"}); + setStatus($("item-status"), said(result), !result.ok); + await refresh(); + }), " "] : []), + ...(item.artUrl ? [button("Remove picture", () => sendPicture(item, null)), " "] : []), + button("Delete", async () => { + if (!confirm(`Delete ${item.name}? It goes from the game and from every player who has it. This cannot be undone.`)) { + return; + } + const result = await api("items", {action: "delete", kind: item.kind, id: item.id}); + setStatus($("item-status"), said(result), !result.ok); + await refresh(); })); - row.append(el("td", String(item.id), "num"), el("td", `${item.name}${item.members ? " (members)" : ""}${item.inShop ? "" : " (off sale)"}`), + const art = el("td"); + if (item.artUrl) { + const picture = el("img", undefined, "item-art"); + picture.src = item.artUrl; + picture.alt = ""; + art.append(picture); + } + else { + art.append(el("span", "—", "hint")); + } + row.append(art, el("td", String(item.id), "num"), el("td", `${item.name}${item.members ? " (members)" : ""}${item.ownerId ? " (a player's own)" : item.inShop ? "" : " (off sale)"}${item.locked ? " (locked)" : ""}`), el("td", `${item.baseName} (${item.kind === "den" ? "den item" : "clothing"} ${item.base})`), el("td", String(item.cost), "num"), el("td", item.createdBy), buttons); return row; @@ -1371,6 +1678,204 @@ $("no-items").hidden = items.length > 0; }; + // an item's own picture (lib/itemart.js): chosen here, sent as it is + // a picture made ready to send (lib/itemart.js): as it is when the + // server takes it as it is (a PNG, JPEG or GIF small enough: a GIF keeps + // moving), else drawn into a PNG that fits, smaller until it is small + // enough. any picture this browser can open will do (WebP, AVIF, BMP...). + // null when it cannot be read at all. + const PICTURE_SIDE = 512; + const PICTURE_BYTES = 300 * 1024; + const preparePicture = async file => { + const kept = ["image/png", "image/jpeg", "image/gif"].includes(file.type); + let image = null; + try { + image = await createImageBitmap(file); + } + catch (err) { + return kept ? file : null; + } + if (kept && file.size <= PICTURE_BYTES && image.width <= PICTURE_SIDE && image.height <= PICTURE_SIDE) { + image.close(); + return file; + } + for (const side of [PICTURE_SIDE, 384, 256, 128]) { + const scale = Math.min(1, side / image.width, side / image.height); + const canvas = document.createElement("canvas"); + canvas.width = Math.max(1, Math.round(image.width * scale)); + canvas.height = Math.max(1, Math.round(image.height * scale)); + canvas.getContext("2d").drawImage(image, 0, 0, canvas.width, canvas.height); + const blob = await new Promise(resolve => canvas.toBlob(resolve, "image/png")); + if (blob && blob.size <= PICTURE_BYTES) { + image.close(); + return blob; + } + } + image.close(); + return null; + }; + + const sendPicture = async (item, chosen) => { + const file = chosen ? await preparePicture(chosen) : null; + if (chosen && !file) { + setStatus($("item-status"), "That picture could not be read. Try a PNG, JPEG or GIF.", true); + return; + } + setStatus($("item-status"), file ? "Sending the picture..." : "Taking the picture away..."); + try { + const response = await fetch(`/mod/api/itemart?kind=${encodeURIComponent(item.kind)}&id=${encodeURIComponent(item.id)}${file ? "" : "&remove=1"}`, + {method: "POST", headers: {"Content-Type": "application/octet-stream"}, body: file || new Uint8Array(0)}); + const data = await response.json().catch(() => ({})); + setStatus($("item-status"), data.ok || data.error || "That did not work.", !data.ok); + } + catch (err) { + setStatus($("item-status"), "The server did not answer.", true); + } + refresh(); + }; + const pickPicture = item => { + const file = el("input"); + file.type = "file"; + file.accept = "image/*"; + file.addEventListener("change", () => file.files[0] && sendPicture(item, file.files[0])); + file.click(); + }; + + // ---- the dashboard's item lock: any item by name or id, locked or + // unlocked where it is found (the Items page lists every locked one). + let quickLockTimer = null; + let quickLockAsked = 0; + const quickLockFind = async () => { + const query = $("quick-lock-q").value.trim(); + const asked = ++quickLockAsked; + const result = await api(`items/find?q=${encodeURIComponent(query)}&kind=${$("quick-lock-kind").value}`); + if (asked !== quickLockAsked || !result.ok) { + return; + } + const {results, total, lockedCount} = result.data; + $("lock-count").textContent = lockedCount === 1 ? "1 item is locked now." : `${lockedCount} items are locked now.`; + const shown = query ? results : []; + $("quick-lock-results").replaceChildren(...shown.map(item => { + const row = el("li"); + row.append(el("span", item.name || "(no name)"), + el("span", `${item.kind === "den" ? "den item" : "clothing"} ${item.id}${item.custom ? ", custom" : ""}`, "meta")); + if (item.locked) { + row.append(el("span", "locked", "is-locked")); + } + row.append(button(item.locked ? "Unlock" : "Lock", async () => { + const changed = await api("items", {action: item.locked ? "unlock" : "lock", kind: item.kind, id: item.id}); + setStatus($("quick-lock-status"), said(changed), !changed.ok); + await quickLockFind(); + }, item.locked ? undefined : "primary")); + return row; + })); + $("quick-lock-more").hidden = !query || (results.length > 0 && total <= results.length); + $("quick-lock-more").textContent = results.length === 0 ? "No item matches." + : `${total} items match; these are the first ${results.length}. Type more of the name.`; + }; + $("quick-lock-q").addEventListener("input", () => { + clearTimeout(quickLockTimer); + quickLockTimer = setTimeout(quickLockFind, 250); + }); + $("quick-lock-kind").addEventListener("change", quickLockFind); + $("quick-lock-all").addEventListener("click", () => showTab("items")); + + // ---- locks and taking items (lib/itemcontrol.js) + let lockedItems = []; + const renderLocked = () => { + $("locked-items").replaceChildren(...lockedItems.map(entry => { + const row = el("li", `${entry.name || "(no name)"} (${entry.kind === "den" ? "den item" : "clothing"} ${entry.id}) `); + row.append(button("Unlock", async () => { + const result = await api("items", {action: "unlock", kind: entry.kind, id: entry.id}); + setStatus($("control-status"), said(result), !result.ok); + await refresh(); + })); + return row; + })); + $("no-locked").hidden = lockedItems.length > 0; + }; + $("lock-add").addEventListener("click", async () => { + const result = await api("items", {action: "lock", kind: $("lock-kind").value, id: $("lock-id").value.trim()}); + setStatus($("control-status"), said(result), !result.ok); + if (result.ok) { + $("lock-id").value = ""; + await refresh(); + } + }); + $("take-go").addEventListener("click", async () => { + const name = $("take-name").value.trim(); + const id = $("take-id").value.trim(); + if (!name || !id || !confirm(`Take every ${$("take-kind").value === "den" ? "den item" : "clothing item"} ${id} from ${name}?`)) { + return; + } + const result = await api("items", {action: "take", username: name, kind: $("take-kind").value, id}); + setStatus($("control-status"), said(result), !result.ok); + }); + + // pictures players upload are blurred till a moderator chooses to look: + // one that is gore need not be seen whole to be turned away. + const revealed = new Set(); // pictures shown, by address (kept over refreshes) + const guardedPicture = src => { + const picture = el("img", undefined, revealed.has(src) ? "guarded shown" : "guarded"); + picture.src = src; + picture.alt = ""; + picture.title = revealed.has(src) ? "" : "Click to show"; + picture.addEventListener("click", () => { + revealed.add(src); + picture.classList.add("shown"); + picture.title = ""; + }); + return picture; + }; + + // ---- what players made that waits for approval (lib/playeritems.js) + const renderReview = data => { + const waiting = data.waiting || []; + $("no-review").hidden = waiting.length > 0; + $("review-list").replaceChildren(...waiting.map(entry => { + const card = el("div", undefined, "review-card"); + const art = el("div", entry.artUrl ? undefined : "No picture", "art"); + if (entry.artUrl) { + art.append(guardedPicture(entry.artUrl)); + } + const about = el("div"); + about.append(el("strong", entry.name), el("div", `${entry.waiting === "item" ? "A new item" : "A new picture"} · ${entry.kind === "den" ? "den item" : "clothing"} from ${entry.baseName}`, "hint"), + el("div", `by ${entry.maker} · ${when(entry.createdAt)}${entry.makerStrikes ? ` · ${entry.makerStrikes} of ${data.strikes} pictures turned away before` : ""}`, "hint")); + const buttons = el("div", undefined, "buttons"); + const decide = approve => async () => { + const result = await api("review", {kind: entry.kind, id: entry.id, approve}); + setStatus($("review-status"), said(result), !result.ok); + await refresh(); + }; + buttons.append(button("Approve", decide(true), "primary"), button("Turn away", decide(false), "danger")); + card.append(art, about, buttons); + return card; + })); + const stopped = data.stopped || []; + $("no-stopped").hidden = stopped.length > 0; + $("stopped-list").replaceChildren(...stopped.map(username => { + const row = el("li", `${username} `); + row.append(button("Let them upload again", async () => { + const result = await api("review", {action: "uploads", username, blocked: false}); + setStatus($("review-status"), said(result), !result.ok); + await refresh(); + })); + return row; + })); + }; + $("stop-go").addEventListener("click", async () => { + const username = $("stop-name").value.trim(); + if (!username) { + return; + } + const result = await api("review", {action: "uploads", username, blocked: true}); + setStatus($("review-status"), said(result), !result.ok); + if (result.ok) { + $("stop-name").value = ""; + } + await refresh(); + }); + let permissions = new Set(); // what the signed-in role may do (GET /mod/api/me) const refresh = async () => { @@ -1381,14 +1886,39 @@ const shown = tab; const counts = permissions.has("player.view") ? await api("overview") : {ok: false}; if (counts.ok) { - $("report-count").textContent = counts.data.reports ? ` (${counts.data.reports})` : ""; - $("request-count").textContent = counts.data.requests ? ` (${counts.data.requests})` : ""; - $("masterpiece-count").textContent = counts.data.paintings ? ` (${counts.data.paintings})` : ""; + $("report-count").textContent = counts.data.reports ? String(counts.data.reports) : ""; + $("request-count").textContent = counts.data.requests ? String(counts.data.requests) : ""; + $("masterpiece-count").textContent = counts.data.paintings ? String(counts.data.paintings) : ""; $("online-count").textContent = `${counts.data.online} playing`; + $("home-online").textContent = String(counts.data.online); + $("home-reports").textContent = String(counts.data.reports); + $("home-requests").textContent = String(counts.data.requests); + $("home-paintings").textContent = String(counts.data.paintings); + for (const [id, count] of [["home-reports", counts.data.reports], ["home-requests", counts.data.requests], ["home-paintings", counts.data.paintings]]) { + $(id).closest(".tile").classList.toggle("attention", count > 0); + } // what waits, in the page's title too, for when it is in another tab. const waiting = counts.data.reports + counts.data.requests + counts.data.paintings; document.title = waiting ? `(${waiting}) Moderators` : "Moderators"; } + if (shown === "home") { + if (permissions.has("items.create") && !$("quick-lock-q").value.trim()) { + quickLockFind(); + } + const result = await api("notes"); + const notes = result.ok ? result.data.notes : []; + $("home-notes").replaceChildren(...notes.map(note => { + const row = el("li"); + const head = el("div", undefined, "who"); + const about = el("button", note.about, "about"); + about.type = "button"; + about.addEventListener("click", () => openPlayer(note.about)); + head.append(about, `${when(note.at)} · by ${note.by}`); + row.append(head, note.text); + return row; + })); + $("no-home-notes").hidden = notes.length > 0; + } // out of sight, only the counts (for the title); the rest when it is back. if (document.hidden) { timer = setTimeout(refresh, REFRESH_MS); @@ -1455,11 +1985,19 @@ renderFilterHits(hits.data.players); } } + else if (shown === "review") { + const result = await api("review"); + if (result.ok) { + renderReview(result.data); + } + } else if (shown === "items") { const result = await api("items"); if (result.ok) { items = result.data.items; + lockedItems = result.data.locked; renderItems(); + renderLocked(); } } if (signedIn) { @@ -1511,6 +2049,9 @@ const showTab = name => { tab = name; setHash(); + const named = document.querySelector(`nav button[data-tab="${name}"]`); + // the tab's own words: not its icon, nor its count + $("page-name").textContent = named ? [...named.childNodes].filter(node => node.nodeType === 3).map(node => node.textContent).join("").trim() : ""; for (const one of document.querySelectorAll("nav button")) { one.setAttribute("aria-selected", String(one.dataset.tab === name)); } @@ -1525,6 +2066,22 @@ showTab(one.dataset.tab); }); } + // the dashboard: each number opens its page; the search opens a player + for (const tile of document.querySelectorAll("[data-goto]")) { + tile.addEventListener("click", () => showTab(tile.dataset.goto)); + } + const homeFind = () => { + const name = $("home-search").value.trim(); + if (name) { + openPlayer(name); + } + }; + $("home-search-go").addEventListener("click", homeFind); + $("home-search").addEventListener("keydown", event => { + if (event.key === "Enter") { + homeFind(); + } + }); document.addEventListener("visibilitychange", () => { if (!document.hidden) { refresh(); @@ -1562,6 +2119,7 @@ if (byAddress.disabled && $("player-search-by").value === "address") { $("player-search-by").value = "name"; } + $("quick-lock").hidden = !allowed.has("items.create"); const open = pages.find(page => page.dataset.tab === tab && !page.hidden) || pages.find(page => !page.hidden); if (open) { tab = open.dataset.tab; diff --git a/public/register.html b/public/register.html index 1572d5d..a104179 100644 --- a/public/register.html +++ b/public/register.html @@ -234,6 +234,7 @@ username_taken: "That username is already taken.", name_not_allowed: "That username is not allowed.", invalid_password: "Passwords need 10 characters or more, with a capital letter, a small letter and a digit.", + weak_password: "That password is too easy to guess: it is a common one, or has your username in it.", choose_animal: "Choose an animal first.", too_many_registrations: "Too many accounts were created from your address. Try again in an hour.", address_banned: "Your address is banned.",