mirror of
https://github.com/burrow-dev/burrow-server.git
synced 2026-11-18 17:27:50 -05:00
Both panels keep the black and white theme and the game's font, with a new sidebar layout. Moderator panel (public/mod.html) - Dashboard: tiles for players online, open reports, requests and paintings; find a player; recent mod notes; a Restrict Items card for roles that may lock items. - Player page: mod notes, the items the player made with their pictures, "Take picture off" (counts as a strike), and stop/allow picture uploads. - Items tab: make items, change their look, lock and unlock, take from a player, delete. - Review tab (items.approve): approve or turn away new items and pictures. Pictures are blurred until clicked, and each card shows how many of the maker's pictures were turned away before. Lists whose uploads are stopped. - Emoji shown as pictures in chat logs. Admin panel (public/admin.html) - Overview: a Restrict Items card that searches any item by name or id and locks or unlocks it in place, with the count of locked items. - Items page: the same tools as the moderator panel, plus the Item Maker switches (players can make items; new items wait; every picture waits). - Role permission matrix on the Moderators page, and per-account permission grants and denies. - Main's Chat tab added to the sidebar. Account page (public/account.html) - My Items: rename, add or change a picture (converted and shrunk in the browser when needed), sticker or texture, delete. Shows when a picture is waiting for a moderator and when uploads are stopped. Co-Authored-By: Claude Opus 5.5 <[email protected]>
2901 lines
140 KiB
HTML
2901 lines
140 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="en">
|
||
<head>
|
||
<meta charset="utf-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||
<title>Server admin</title>
|
||
<link rel="icon" type="image/png" href="/logo-square.png">
|
||
<style>
|
||
/* the same look as the moderator panel (public/mod.html): a sidebar of
|
||
pages, cards on a slate
|
||
ground. black and white throughout, in the game's own text font: the
|
||
look of the client. Nothing is said by colour: what went wrong is white
|
||
with a "!" before it, and what cannot be undone has a dashed edge. */
|
||
@font-face { font-family: "DigitalDelivery"; font-weight: 400; src: url("/fonts/CCDigitalDelivery-Regular.otf") format("opentype"); }
|
||
@font-face { font-family: "DigitalDelivery"; font-weight: 700; src: url("/fonts/CCDigitalDelivery-Bold.otf") format("opentype"); }
|
||
:root {
|
||
color-scheme: dark;
|
||
--bg: #000;
|
||
--panel: #0d0d0d;
|
||
--raised: #1a1a1a;
|
||
--field: #000;
|
||
--line: #2e2e2e;
|
||
--line-strong: #555;
|
||
--text: #fff;
|
||
--muted: #8c8c8c;
|
||
--accent: #fff;
|
||
--accent-soft: #1a1a1a;
|
||
--radius: 14px;
|
||
--shadow: none;
|
||
}
|
||
* { box-sizing: border-box; }
|
||
[hidden] { display: none !important; }
|
||
::selection { background: #fff; color: #000; }
|
||
::-webkit-scrollbar { width: 10px; height: 10px; }
|
||
::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 5px; border: 3px solid var(--bg); }
|
||
body {
|
||
margin: 0;
|
||
background: var(--bg);
|
||
color: var(--text);
|
||
font: 15px/1.4 "DigitalDelivery", system-ui, "Segoe UI", sans-serif;
|
||
-webkit-font-smoothing: antialiased;
|
||
}
|
||
a { color: inherit; text-underline-offset: 3px; }
|
||
h1, h2, h3 { font-family: "DigitalDelivery", system-ui, sans-serif; }
|
||
h1 { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: 0.01em; }
|
||
h2 { margin: 0 0 10px; font-size: 18px; font-weight: 700; }
|
||
h3 { font-size: 15px; font-weight: 700; }
|
||
p { margin: 0 0 12px; color: var(--muted); }
|
||
label { display: block; margin: 12px 0 5px; color: var(--muted); font-size: 13px; }
|
||
.hint { font-weight: 400; color: var(--muted); font-size: 12.5px; }
|
||
input, select, textarea {
|
||
font: inherit;
|
||
color: var(--text);
|
||
background: var(--field);
|
||
border: 1px solid var(--line);
|
||
border-radius: 10px;
|
||
padding: 8px 12px;
|
||
transition: border-color 0.12s, box-shadow 0.12s;
|
||
}
|
||
input::placeholder, textarea::placeholder { color: #555; }
|
||
input:hover, select:hover, textarea:hover { border-color: var(--line-strong); }
|
||
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--text); }
|
||
input:disabled, select:disabled, textarea:disabled { opacity: 0.45; }
|
||
select:not([multiple]) {
|
||
-webkit-appearance: none;
|
||
appearance: none;
|
||
padding-right: 34px;
|
||
background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
|
||
background-position: calc(100% - 19px) 55%, calc(100% - 14px) 55%;
|
||
background-size: 5px 5px;
|
||
background-repeat: no-repeat;
|
||
}
|
||
input[type="checkbox"] {
|
||
-webkit-appearance: none;
|
||
appearance: none;
|
||
flex: none;
|
||
width: 18px;
|
||
height: 18px;
|
||
margin: 0 6px 0 0;
|
||
padding: 0;
|
||
vertical-align: -4px;
|
||
border: 1px solid var(--line-strong);
|
||
border-radius: 5px;
|
||
background: var(--field);
|
||
cursor: pointer;
|
||
}
|
||
input[type="checkbox"]:checked {
|
||
border-color: var(--text);
|
||
background: var(--text) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 18 18'%3E%3Cpath d='M4.5 9.5l3 3 6-7' fill='none' stroke='%23000' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / 16px no-repeat;
|
||
}
|
||
button {
|
||
font: inherit;
|
||
font-weight: 600;
|
||
color: var(--text);
|
||
background: var(--raised);
|
||
border: 1px solid var(--line);
|
||
border-radius: 10px;
|
||
padding: 7px 14px;
|
||
cursor: pointer;
|
||
white-space: nowrap;
|
||
transition: background 0.12s, border-color 0.12s, color 0.12s, transform 0.06s;
|
||
}
|
||
button:hover { background: #262626; border-color: var(--line-strong); }
|
||
button:active { transform: translateY(1px); }
|
||
button:disabled { opacity: 0.45; cursor: default; transform: none; }
|
||
button:focus-visible, a:focus-visible, input[type="checkbox"]:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
|
||
button.primary { font-weight: 700; color: #000; background: var(--text); border-color: var(--text); }
|
||
button.primary:hover { background: #d9d9d9; border-color: #d9d9d9; }
|
||
button.primary:disabled, button.primary:disabled:hover { background: #3a3a3a; border-color: #3a3a3a; color: #000; }
|
||
button.danger { border-style: dashed; border-color: #666; }
|
||
button.danger:hover { border-style: solid; border-color: var(--text); }
|
||
.status, #status { min-height: 20px; margin: 10px 0 0; font-size: 13px; color: var(--muted); }
|
||
.status.bad, #status.bad { color: var(--text); }
|
||
.status.bad::before, #status.bad::before, .notice::before {
|
||
content: "!";
|
||
display: inline-block;
|
||
width: 17px;
|
||
height: 17px;
|
||
margin-right: 7px;
|
||
border-radius: 50%;
|
||
background: var(--text);
|
||
color: #000;
|
||
font-weight: 700;
|
||
line-height: 17px;
|
||
text-align: center;
|
||
}
|
||
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
|
||
label.check { margin: 0; color: var(--text); font-size: 14px; cursor: pointer; }
|
||
#item-colours { display: flex; gap: 6px 14px; flex-wrap: wrap; margin-top: 8px; }
|
||
#item-colours label.check { display: inline-flex; gap: 5px; align-items: center; }
|
||
ul.plain { list-style: none; padding: 0; margin: 10px 0 0; }
|
||
ul.plain li { padding: 6px 0; border-bottom: 1px solid var(--line); }
|
||
ul.plain li:last-child { border-bottom: 0; }
|
||
img.guarded { filter: blur(14px) grayscale(0.6); cursor: pointer; transition: filter 0.15s; }
|
||
img.guarded.shown { filter: none; cursor: default; }
|
||
.made-items { display: grid; gap: 8px; margin: 8px 0; }
|
||
.made-item { display: flex; gap: 12px; align-items: center; padding: 8px; background: var(--raised); border: 1px solid var(--line); border-radius: 10px; }
|
||
.made-item .art { width: 52px; height: 52px; flex: none; border-radius: 8px; background: var(--field); display: grid; place-items: center; overflow: hidden; color: var(--muted); font-size: 10px; text-align: center; }
|
||
.made-item .art img { max-width: 100%; max-height: 100%; }
|
||
.made-item > div:nth-child(2) { flex: 1; min-width: 0; }
|
||
#quick-lock { margin-top: 18px; }
|
||
.lock-results li { display: flex; gap: 10px; align-items: center; }
|
||
.lock-results .meta { color: var(--muted); font-size: 12px; }
|
||
.lock-results button { margin-left: auto; }
|
||
.lock-results .is-locked { font-size: 11px; padding: 1px 7px; border: 1px solid var(--text); border-radius: 999px; }
|
||
|
||
/* signing in */
|
||
#gate {
|
||
max-width: 400px;
|
||
margin: 10vh auto 0;
|
||
padding: 28px;
|
||
background: var(--panel);
|
||
border: 1px solid var(--line);
|
||
border-radius: 20px;
|
||
box-shadow: var(--shadow);
|
||
}
|
||
#gate h1 { margin-bottom: 4px; }
|
||
#gate input { width: 100%; }
|
||
#gate button { width: 100%; margin-top: 18px; padding: 10px 16px; }
|
||
#captcha { margin-top: 16px; }
|
||
|
||
/* the panel: a sidebar, and the page beside it */
|
||
#panel { display: grid; grid-template-columns: 236px minmax(0, 1fr); min-height: 100vh; }
|
||
#side {
|
||
position: sticky;
|
||
top: 0;
|
||
height: 100vh;
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 18px;
|
||
padding: 20px 14px;
|
||
background: var(--panel);
|
||
border-right: 1px solid var(--line);
|
||
}
|
||
.brand { display: flex; align-items: center; gap: 10px; padding: 0 6px; }
|
||
.brand h1 { font-size: 19px; }
|
||
#who { display: block; margin-top: 1px; }
|
||
nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
|
||
nav button {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 10px;
|
||
width: 100%;
|
||
padding: 9px 10px;
|
||
border: 0;
|
||
background: none;
|
||
color: var(--muted);
|
||
font-weight: 500;
|
||
text-align: left;
|
||
}
|
||
nav button .icon { width: 18px; text-align: center; opacity: 0.85; }
|
||
nav button:hover { background: var(--raised); color: var(--text); }
|
||
nav button[aria-selected="true"] { background: var(--text); color: #000; font-weight: 700; }
|
||
nav button span[id$="-count"]:not(:empty) {
|
||
margin-left: auto;
|
||
padding: 0 8px;
|
||
border-radius: 999px;
|
||
background: var(--text);
|
||
color: #000;
|
||
font-size: 11.5px;
|
||
font-weight: 700;
|
||
line-height: 19px;
|
||
}
|
||
#sign-out { width: 100%; }
|
||
#main { padding: 28px clamp(16px, 3vw, 36px) 48px; max-width: 1240px; width: 100%; }
|
||
.page-title { display: flex; align-items: baseline; gap: 12px; margin-bottom: 18px; }
|
||
.page-title h1 { font-size: 26px; }
|
||
@media (max-width: 860px) {
|
||
#panel { grid-template-columns: 1fr; }
|
||
#side { position: static; height: auto; flex-direction: column; }
|
||
nav { flex-direction: row; flex-wrap: wrap; }
|
||
nav button { width: auto; }
|
||
}
|
||
|
||
section { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 20px; margin-bottom: 18px; box-shadow: var(--shadow); }
|
||
/* the dashboard's numbers: each a card that opens its page */
|
||
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 18px; }
|
||
.tile { padding: 16px 18px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); }
|
||
button.tile { display: block; width: 100%; text-align: left; font-weight: 400; }
|
||
button.tile:hover { border-color: var(--text); background: var(--panel); }
|
||
.tile .value { font-size: 30px; font-weight: 700; line-height: 1.15; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; font-family: "DigitalDelivery", system-ui, sans-serif; }
|
||
.tile .name { margin-top: 4px; font-size: 11.5px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
|
||
.tile.attention { border-color: var(--text); }
|
||
.columns { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 18px; }
|
||
.columns section { margin: 0; }
|
||
dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 18px; margin: 0; }
|
||
dt { color: var(--muted); }
|
||
dd { margin: 0; overflow-wrap: anywhere; }
|
||
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; }
|
||
table { width: 100%; border-collapse: collapse; }
|
||
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
|
||
th { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 600; background: var(--raised); }
|
||
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
|
||
td button { padding: 3px 11px; font-size: 13px; }
|
||
tbody tr:last-child td { border-bottom: 0; }
|
||
tbody tr:hover td { background: #0f0f0f; }
|
||
tbody tr.selected td { background: var(--accent-soft); }
|
||
tbody tr.pick { cursor: pointer; }
|
||
.device-id { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; }
|
||
button.link { background: none; border: 0; padding: 0; color: inherit; text-decoration: underline; cursor: pointer; font: inherit; font-weight: 400; }
|
||
.empty { color: var(--muted); padding: 10px 2px; }
|
||
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
|
||
.toolbar input[type="search"] { flex: 1; min-width: 200px; }
|
||
.tag { display: inline-block; padding: 1px 9px; border: 1px solid var(--line-strong); border-radius: 999px; font-size: 11px; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted); }
|
||
.tag.good { color: #000; background: var(--text); border-color: var(--text); font-weight: 700; }
|
||
.tag.bad { color: var(--text); border-color: var(--text); font-weight: 700; }
|
||
#detail { margin-top: 0; }
|
||
.actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; }
|
||
.action .hint { margin: 8px 0 0; }
|
||
.action { background: var(--raised); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; }
|
||
.action h3 { margin: 0 0 10px; }
|
||
.action .row { display: flex; gap: 8px; flex-wrap: wrap; }
|
||
.action .row input, .action .row select { flex: 1; min-width: 90px; }
|
||
.action .row input[type="checkbox"] { flex: none; min-width: 0; }
|
||
/* the items' buttons wrap in their cell, not out of the table */
|
||
#items td:last-child { white-space: normal; min-width: 300px; }
|
||
#items td:last-child button { margin: 2px 0; }
|
||
.action .buttons { display: flex; gap: 8px; flex-wrap: wrap; }
|
||
#log {
|
||
height: 60vh;
|
||
overflow: auto;
|
||
margin: 0;
|
||
padding: 12px 14px;
|
||
background: var(--field);
|
||
border: 1px solid var(--line);
|
||
border-radius: 12px;
|
||
font: 12px/1.5 ui-monospace, Consolas, monospace;
|
||
color: #bdbdbd;
|
||
white-space: pre-wrap;
|
||
overflow-wrap: anywhere;
|
||
}
|
||
#log .time { color: var(--muted); }
|
||
#log .error { color: var(--text); font-weight: 700; }
|
||
.report { background: var(--raised); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; margin-bottom: 12px; }
|
||
.report h3 { margin: 0 0 4px; }
|
||
.report .typed { margin: 8px 0; padding: 8px 12px; background: var(--field); border: 1px solid var(--line); border-radius: 10px; overflow-wrap: anywhere; }
|
||
.report pre { margin: 8px 0; padding: 8px 12px; background: var(--field); border: 1px solid var(--line); border-radius: 10px; font: 12px/1.5 ui-monospace, Consolas, monospace; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 180px; overflow: auto; }
|
||
.report .buttons { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
|
||
.chat-list { margin: 0; padding: 0; list-style: none; }
|
||
.chat-list li { display: flex; gap: 10px; align-items: baseline; padding: 6px 4px; border-bottom: 1px solid var(--line); }
|
||
.chat-list li:last-child { border-bottom: 0; }
|
||
.chat-list li.this { background: var(--raised); border-radius: 10px; }
|
||
.chat-time { flex: none; width: 128px; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
|
||
.chat-who { flex: none; max-width: 190px; padding: 0; border: 0; font-weight: 700; text-align: left; overflow: hidden; text-overflow: ellipsis; }
|
||
.chat-who:hover { background: none; text-decoration: underline; }
|
||
.chat-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
|
||
.chat-room { display: block; color: var(--muted); font-size: 12px; }
|
||
.chat-more { flex: none; padding: 2px 10px 3px; font-size: 12px; }
|
||
#timeline { margin: 0; padding-left: 18px; font-size: 13px; overflow-wrap: anywhere; }
|
||
.paintings { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
|
||
.painting { background: var(--raised); border: 1px solid var(--line); border-radius: 14px; padding: 14px; }
|
||
.painting img { display: block; width: 100%; height: auto; border-radius: 10px; background: #fff; }
|
||
.painting h3 { margin: 8px 0 2px; }
|
||
.painting .buttons { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
|
||
.painting img { cursor: zoom-in; }
|
||
.preview { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(0, 0, 0, 0.85); cursor: zoom-out; }
|
||
.preview[hidden] { display: none; }
|
||
.preview img { max-width: 100%; max-height: 100%; border-radius: 10px; background: #fff; }
|
||
textarea { width: 100%; resize: vertical; }
|
||
.send-row { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; align-items: center; }
|
||
#owned { margin-top: 16px; }
|
||
#owned ul { margin: 4px 0 12px; padding-left: 18px; columns: 220px; }
|
||
#owned li { break-inside: avoid; }
|
||
#ban-record h3 { margin: 14px 0 4px; }
|
||
#ban-record ul { margin: 0; padding-left: 18px; font-size: 13px; overflow-wrap: anywhere; }
|
||
#ban-record li { margin: 3px 0; }
|
||
#ban-record li button { padding: 2px 10px; font-size: 12px; }
|
||
#password-form { max-width: 360px; }
|
||
#password-form input { width: 100%; }
|
||
#password-form button { margin-top: 16px; }
|
||
.logo { display: block; height: 64px; margin: 0 0 12px; }
|
||
.mark { height: 34px; flex: none; }
|
||
#chat-lines { margin: 0; padding: 0; list-style: none; }
|
||
#chat-lines li, #chat-context li { display: flex; gap: 10px; align-items: baseline; padding: 8px 6px; border-bottom: 1px solid var(--line); }
|
||
#chat-lines li:last-child, #chat-context li:last-child { border-bottom: 0; }
|
||
.chat-time { flex: none; width: 128px; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
|
||
.chat-who { flex: none; max-width: 190px; padding: 0; border: 0; background: none; font-weight: 700; text-align: left; overflow: hidden; text-overflow: ellipsis; }
|
||
.chat-who:hover { background: none; text-decoration: underline; }
|
||
.chat-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
|
||
.chat-room { display: block; color: var(--muted); font-size: 12px; }
|
||
.chat-more { flex: none; padding: 2px 10px; font-size: 12px; }
|
||
#chat-context { margin: 0; padding: 0; list-style: none; }
|
||
#chat-context li.this { background: var(--accent-soft); border-radius: 8px; }
|
||
#player-facts { margin-bottom: 16px; }
|
||
.record-title { margin: 20px 0 6px; }
|
||
#player-history, #player-warnings { margin: 0; padding-left: 18px; font-size: 13px; overflow-wrap: anywhere; }
|
||
/* mod notes: cards, the newest first */
|
||
.notes { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 8px; }
|
||
.notes li { padding: 10px 12px; background: var(--raised); border: 1px solid var(--line); border-left: 3px solid var(--text); border-radius: 10px; overflow-wrap: anywhere; }
|
||
.notes .who { display: flex; gap: 8px; align-items: center; margin-bottom: 3px; color: var(--muted); font-size: 12px; }
|
||
.notes .who button { margin-left: auto; padding: 1px 9px; font-size: 12px; }
|
||
.notes .about { padding: 0; border: 0; background: none; color: var(--text); font-weight: 700; font-size: 12px; text-decoration: underline; }
|
||
.note-row { display: flex; gap: 8px; align-items: flex-start; }
|
||
#note-text { flex: 1; min-width: 0; }
|
||
|
||
/* the admin panel's own */
|
||
/* items waiting for approval: a card each, its picture on the left */
|
||
.review-list { display: grid; gap: 10px; }
|
||
.review-card { display: grid; grid-template-columns: 72px 1fr auto; gap: 14px; align-items: center; padding: 12px; background: var(--raised); border: 1px solid var(--line); border-radius: 14px; }
|
||
.review-card .art { width: 72px; height: 72px; border-radius: 10px; background: var(--field); display: grid; place-items: center; overflow: hidden; color: var(--muted); font-size: 11px; text-align: center; }
|
||
.review-card .art img { max-width: 100%; max-height: 100%; }
|
||
.review-card .buttons { display: flex; gap: 8px; flex-wrap: wrap; }
|
||
.perm-list { display: grid; grid-template-columns: 1fr auto; gap: 6px 14px; align-items: center; margin-top: 8px; }
|
||
.perm-list .on { font-weight: 700; }
|
||
.perm-list .off { color: var(--muted); }
|
||
#role-matrix td:not(:first-child), #role-head th:not(:first-child) { text-align: center; }
|
||
#role-matrix td:first-child { white-space: normal; min-width: 260px; }
|
||
img.item-art { display: block; width: 44px; height: 44px; object-fit: contain; border-radius: 8px; background: var(--raised); }
|
||
#updated { display: block; margin-top: 1px; }
|
||
#owned { margin-top: 16px; }
|
||
</style>
|
||
</head>
|
||
<body>
|
||
<main id="gate" hidden>
|
||
<img class="logo" src="/logo.png" alt="">
|
||
<h1 id="gate-title">Server admin</h1>
|
||
<p id="gate-text"></p>
|
||
<form id="gate-form">
|
||
<div id="code-field" hidden>
|
||
<label for="code">Setup code <span class="hint">[admin] line of the server's output</span></label>
|
||
<input id="code" autocomplete="off" spellcheck="false">
|
||
</div>
|
||
<label for="password" id="password-label">Password</label>
|
||
<input id="password" type="password" autocomplete="current-password" required>
|
||
<div id="confirm-field" hidden>
|
||
<label for="confirm">Password again</label>
|
||
<input id="confirm" type="password" autocomplete="new-password">
|
||
</div>
|
||
<button class="primary" id="gate-button">Sign in</button>
|
||
</form>
|
||
<p class="status" id="gate-status" role="status"></p>
|
||
</main>
|
||
|
||
<div id="panel" hidden>
|
||
<aside id="side">
|
||
<div class="brand">
|
||
<img class="mark" src="/logo.png" alt="">
|
||
<div><h1>Server admin</h1><span class="hint" id="updated"></span></div>
|
||
</div>
|
||
<nav role="tablist" aria-orientation="vertical">
|
||
<button role="tab" data-tab="overview" aria-selected="true"><span class="icon" aria-hidden="true">◉</span>Overview</button>
|
||
<button role="tab" data-tab="accounts" aria-selected="false"><span class="icon" aria-hidden="true">☻</span>Accounts</button>
|
||
<button role="tab" data-tab="chat" aria-selected="false"><span class="icon" aria-hidden="true">✉</span>Chat</button>
|
||
<button role="tab" data-tab="stats" aria-selected="false"><span class="icon" aria-hidden="true">▤</span>Stats</button>
|
||
<button role="tab" data-tab="reports" aria-selected="false"><span class="icon" aria-hidden="true">⚑</span>Reports<span id="report-count"></span></button>
|
||
<button role="tab" data-tab="support" aria-selected="false"><span class="icon" aria-hidden="true">✎</span>Requests<span id="support-count"></span></button>
|
||
<button role="tab" data-tab="masterpieces" aria-selected="false"><span class="icon" aria-hidden="true">▣</span>Masterpieces<span id="masterpiece-count"></span></button>
|
||
<button role="tab" data-tab="items" aria-selected="false"><span class="icon" aria-hidden="true">❖</span>Items</button>
|
||
<button role="tab" data-tab="bans" aria-selected="false"><span class="icon" aria-hidden="true">⊘</span>Bans</button>
|
||
<button role="tab" data-tab="moderators" aria-selected="false"><span class="icon" aria-hidden="true">★</span>Moderators</button>
|
||
<button role="tab" data-tab="messages" aria-selected="false"><span class="icon" aria-hidden="true">✉</span>Messages</button>
|
||
<button role="tab" data-tab="logs" aria-selected="false"><span class="icon" aria-hidden="true">☰</span>Logs</button>
|
||
<button role="tab" data-tab="debug" aria-selected="false"><span class="icon" aria-hidden="true">⚙</span>Debug</button>
|
||
<button role="tab" data-tab="settings" aria-selected="false"><span class="icon" aria-hidden="true">⚿</span>Password</button>
|
||
</nav>
|
||
<button id="sign-out" type="button">Sign out</button>
|
||
</aside>
|
||
<div id="main">
|
||
<div class="page-title"><h1 id="page-name">Overview</h1></div>
|
||
|
||
<div data-view="overview">
|
||
<div class="tiles" id="tiles"></div>
|
||
<div class="columns">
|
||
<section>
|
||
<h2>Playing now</h2>
|
||
<div class="table-wrap"><table>
|
||
<thead><tr><th>Player</th><th>Room</th><th>Address</th></tr></thead>
|
||
<tbody id="players"></tbody>
|
||
</table></div>
|
||
<div class="empty" id="no-players" hidden>Nobody is online.</div>
|
||
</section>
|
||
<section>
|
||
<h2>Server</h2>
|
||
<dl id="server-facts"></dl>
|
||
</section>
|
||
</div>
|
||
<section id="quick-lock">
|
||
<h2>Restrict items</h2>
|
||
<p class="hint">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). <span id="lock-count"></span></p>
|
||
<div class="toolbar">
|
||
<select id="quick-lock-kind" aria-label="Kind">
|
||
<option value="all">All items</option>
|
||
<option value="clothing">Clothing</option>
|
||
<option value="den">Den items</option>
|
||
</select>
|
||
<input id="quick-lock-q" type="search" placeholder="Item name or id" aria-label="Find an item to lock">
|
||
<button type="button" id="quick-lock-all">Every locked item</button>
|
||
</div>
|
||
<ul class="plain lock-results" id="quick-lock-results"></ul>
|
||
<p class="hint" id="quick-lock-more" hidden></p>
|
||
<p class="status" id="quick-lock-status" role="status"></p>
|
||
</section>
|
||
</div>
|
||
|
||
<div data-view="stats" hidden>
|
||
<!--stats-view-->
|
||
</div>
|
||
|
||
<div data-view="accounts" hidden>
|
||
<section>
|
||
<div class="toolbar">
|
||
<select id="account-search-by" aria-label="Search by">
|
||
<option value="name">By name</option>
|
||
<option value="address">By IP address</option>
|
||
<option value="device">By hardware ID</option>
|
||
</select>
|
||
<input id="account-search" type="search" placeholder="Search" aria-label="Search accounts">
|
||
<select id="account-filter" aria-label="Which accounts">
|
||
<option value="all">All</option>
|
||
<option value="online">Online</option>
|
||
<option value="banned">Banned</option>
|
||
</select>
|
||
</div>
|
||
<div id="address-view" hidden>
|
||
<p class="status" id="address-status" role="status"></p>
|
||
<div class="table-wrap"><table>
|
||
<thead><tr><th>Name</th><th>State</th><th id="found-what">Addresses</th><th id="found-when">Last from there</th></tr></thead>
|
||
<tbody id="address-results"></tbody>
|
||
</table></div>
|
||
</div>
|
||
<div class="table-wrap" id="account-list"><table>
|
||
<thead><tr><th>Name</th><th>State</th><th>Created</th><th>Last login</th><th>Last seen</th><th class="num">Logins</th><th class="num">Animals</th><th class="num">Items</th></tr></thead>
|
||
<tbody id="accounts"></tbody>
|
||
</table></div>
|
||
<div class="empty" id="no-accounts" hidden>No accounts match.</div>
|
||
<p class="hint" id="account-more" hidden></p>
|
||
|
||
<div id="detail" hidden>
|
||
<h2 id="detail-name"></h2>
|
||
<p class="status" id="detail-status" role="status"></p>
|
||
<div class="actions">
|
||
<div class="action">
|
||
<h3>Username</h3>
|
||
<div class="row"><input id="new-name" maxlength="100" placeholder="New username" autocomplete="off" spellcheck="false" aria-label="New username">
|
||
<button type="button" data-action="rename">Rename</button></div>
|
||
</div>
|
||
<div class="action">
|
||
<h3>Password</h3>
|
||
<div class="row"><input id="new-password" type="password" placeholder="New password" autocomplete="new-password" aria-label="New password">
|
||
<button type="button" data-action="password">Set</button></div>
|
||
</div>
|
||
<div class="action">
|
||
<h3>Adventure level</h3>
|
||
<div class="row"><input id="quest-level" type="number" min="0" max="100" step="1" aria-label="Adventure level of the animal in use">
|
||
<button type="button" data-action="level">Set</button></div>
|
||
</div>
|
||
<div class="action">
|
||
<h3>Last seen</h3>
|
||
<div class="row"><input id="last-seen" type="datetime-local" aria-label="Last seen, in your local time">
|
||
<button type="button" data-action="lastSeen">Set</button></div>
|
||
<div class="row">
|
||
<button type="button" data-ago="5">5 min ago</button>
|
||
<button type="button" data-ago="180">3 hours ago</button>
|
||
<button type="button" data-ago="2880">2 days ago</button>
|
||
<button type="button" data-ago="86400">60 days ago</button></div>
|
||
</div>
|
||
<div class="action">
|
||
<h3>Bio</h3>
|
||
<textarea id="bio-text" rows="4" maxlength="220" spellcheck="true" aria-label="Bio" style="width:100%"></textarea>
|
||
<div class="row" style="margin-top:8px"><button type="button" data-action="bio">Set</button></div>
|
||
</div>
|
||
<div class="action">
|
||
<h3>Badges</h3>
|
||
<div class="buttons" id="badge-boxes"></div>
|
||
<div class="row" style="margin-top:8px"><button type="button" data-action="badges">Set</button></div>
|
||
<div class="row" style="margin-top:8px"><input id="discord-name" maxlength="33" placeholder="Discord username" autocomplete="off" spellcheck="false" aria-label="Discord username">
|
||
<button type="button" data-action="discord">Set</button></div>
|
||
</div>
|
||
<div class="action">
|
||
<h3>Ban</h3>
|
||
<div class="row"><input id="ban-hours" type="number" min="0" placeholder="Hours (0 = forever)" aria-label="Ban length in hours">
|
||
<input id="ban-reason" maxlength="300" placeholder="Reason" autocomplete="off" aria-label="Reason, shown to the banned player"></div>
|
||
<div class="row" style="margin-top:8px">
|
||
<button type="button" data-action="ban" class="danger">Ban</button>
|
||
<button type="button" data-action="banReason">Save reason</button>
|
||
<button type="button" data-action="unban">Lift</button>
|
||
<button type="button" data-action="banDevices" class="danger">Hardware ban</button>
|
||
<button type="button" data-action="unbanDevices">Lift hardware ban</button></div>
|
||
<div id="ban-record"></div>
|
||
</div>
|
||
<div class="action">
|
||
<h3>Chat</h3>
|
||
<div class="row"><input id="silence-hours" type="number" min="0" placeholder="Hours (0 = until lifted)" aria-label="Silence length in hours">
|
||
<button type="button" data-action="silence">Silence</button>
|
||
<button type="button" data-action="unsilence">Lift</button></div>
|
||
</div>
|
||
<div class="action">
|
||
<h3>Message</h3>
|
||
<div class="row"><input id="message-text" maxlength="200" placeholder="Text" aria-label="Message">
|
||
<button type="button" data-action="message">Send</button></div>
|
||
</div>
|
||
<div class="action">
|
||
<h3>Look into</h3>
|
||
<p class="hint" id="look-facts"></p>
|
||
<div class="buttons">
|
||
<button type="button" id="open-chat">Chat history</button>
|
||
<button type="button" id="open-paintings">Paintings</button>
|
||
</div>
|
||
</div>
|
||
<div class="action">
|
||
<h3>Gems</h3>
|
||
<div class="row"><input id="gems-amount" type="number" placeholder="Amount" aria-label="Gems to add">
|
||
<button type="button" data-action="gems">Add</button></div>
|
||
</div>
|
||
<div class="action">
|
||
<h3>Gift</h3>
|
||
<div class="row">
|
||
<select id="gift-kind" aria-label="What to give">
|
||
<option value="gems">Gems</option>
|
||
<option value="diamonds">Diamonds</option>
|
||
<option value="tickets">Tickets</option>
|
||
<option value="clothing">Clothing</option>
|
||
<option value="den">Den item</option>
|
||
<option value="adopt">Adopt-A-Pet</option>
|
||
<option value="achievement">Achievement</option>
|
||
</select>
|
||
<input id="gift-value" placeholder="Amount" autocomplete="off" aria-label="Amount or id">
|
||
<button type="button" data-action="gift">Give</button></div>
|
||
<div class="row" style="margin-top:8px"><input id="gift-text" maxlength="200" placeholder="Message (optional)" aria-label="Message on the Jam-A-Gram"></div>
|
||
</div>
|
||
<div class="action">
|
||
<h3>Other</h3>
|
||
<div class="buttons">
|
||
<button type="button" data-action="kick">Disconnect</button>
|
||
<button type="button" data-action="unlock">Unlock</button>
|
||
<button type="button" data-action="twoStepOff">Turn off 2FA</button>
|
||
<button type="button" data-action="rejectName">Reject username</button>
|
||
<button type="button" data-action="acceptName">Take rejection back</button>
|
||
<button type="button" data-action="moderator" id="moderator-toggle">Make moderator</button>
|
||
<select id="role-select" aria-label="Staff role">
|
||
<option value="none">No staff role</option>
|
||
<option value="developer">Developer</option>
|
||
<option value="helper">Helper</option>
|
||
<option value="moderator">Moderator</option>
|
||
<option value="admin">Admin</option>
|
||
</select>
|
||
<button type="button" data-action="role">Set role</button>
|
||
<button type="button" data-action="clearDen">Clear den</button>
|
||
<button type="button" data-action="delete" class="danger">Delete</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<h2 style="margin-top:20px">Other accounts</h2>
|
||
<div class="table-wrap"><table>
|
||
<thead><tr><th>Name</th><th>State</th><th>Same hardware</th><th class="num">Same addresses</th></tr></thead>
|
||
<tbody id="alts"></tbody>
|
||
</table></div>
|
||
<div class="empty" id="no-alts" hidden>None found.</div>
|
||
<h2 style="margin-top:20px">Hardware IDs</h2>
|
||
<div class="table-wrap"><table>
|
||
<thead><tr><th>Kind</th><th>Id</th><th>First seen</th><th>Last seen</th><th class="num">Other accounts</th><th>State</th></tr></thead>
|
||
<tbody id="device-ids"></tbody>
|
||
</table></div>
|
||
<div class="empty" id="no-device-ids" hidden>None.</div>
|
||
<h2 style="margin-top:20px">Jam-a-Grams and wall posts</h2>
|
||
<div class="toolbar">
|
||
<select id="mail-kind" aria-label="Which">
|
||
<option value="jamagram">Jam-a-Grams</option>
|
||
<option value="wall">Jammer Wall posts</option>
|
||
</select>
|
||
<select id="mail-direction" aria-label="Sent or received">
|
||
<option value="">Sent and received</option>
|
||
<option value="sent">Sent by them</option>
|
||
<option value="received">Sent to them</option>
|
||
</select>
|
||
</div>
|
||
<ul id="mail-lines" class="chat-list"></ul>
|
||
<div class="empty" id="no-mail" hidden>Nothing kept.</div>
|
||
<button type="button" id="mail-older" hidden>Older</button>
|
||
<h2 style="margin-top:20px">Timeline</h2>
|
||
<ul id="timeline"></ul>
|
||
<div class="empty" id="no-timeline" hidden>Nothing yet.</div>
|
||
<div id="perm-part" hidden>
|
||
<h3 class="record-title">Permissions</h3>
|
||
<p class="hint">Each one as their role has it, or given or taken for them alone. What they may do now is marked.</p>
|
||
<div class="perm-list" id="perm-list"></div>
|
||
<div class="row" style="margin-top:10px"><button type="button" class="primary" data-action="permissions">Save permissions</button></div>
|
||
</div>
|
||
<div id="owned"></div>
|
||
</div>
|
||
</section>
|
||
</div>
|
||
|
||
<div data-view="chat" hidden>
|
||
<section>
|
||
<form id="chat-form" class="toolbar">
|
||
<input id="chat-player" maxlength="100" placeholder="Player" autocomplete="off" spellcheck="false" aria-label="Player">
|
||
<input id="chat-room" maxlength="100" placeholder="Room" autocomplete="off" spellcheck="false" aria-label="Room">
|
||
<input id="chat-text" maxlength="100" placeholder="Words" autocomplete="off" aria-label="Words" style="flex:1">
|
||
<select id="chat-kind" aria-label="What">
|
||
<option value="">Everything</option>
|
||
<option value="chat">Chat</option>
|
||
<option value="whisper">Whispers</option>
|
||
<option value="jamagram">Jam-a-Grams</option>
|
||
<option value="wall">Wall posts</option>
|
||
<option value="notsent">Stopped by the filter</option>
|
||
</select>
|
||
<input id="chat-until" type="datetime-local" aria-label="From this time back">
|
||
<button class="primary" type="submit">Search</button>
|
||
</form>
|
||
<p class="status" id="chat-status" role="status"></p>
|
||
<div id="context-box" hidden>
|
||
<div class="toolbar"><h2 style="margin:0;flex:1" id="context-title"></h2><button type="button" id="context-close">Close</button></div>
|
||
<ul class="chat-list" id="chat-context"></ul>
|
||
</div>
|
||
<ul class="chat-list" id="chat-lines"></ul>
|
||
<div class="empty" id="no-chat" hidden>Nothing here.</div>
|
||
<div class="send-row"><button type="button" id="chat-older" hidden>Older</button></div>
|
||
</section>
|
||
</div>
|
||
|
||
<div data-view="reports" hidden>
|
||
<section>
|
||
<div class="toolbar">
|
||
<h2 style="margin:0;flex:1">Reports</h2>
|
||
<select id="report-filter" aria-label="Which reports">
|
||
<option value="0">Waiting</option>
|
||
<option value="1">Handled</option>
|
||
</select>
|
||
</div>
|
||
<p class="status" id="report-status" role="status"></p>
|
||
<div id="reports"></div>
|
||
<div class="empty" id="no-reports" hidden>Nothing here.</div>
|
||
</section>
|
||
</div>
|
||
|
||
<div data-view="support" hidden>
|
||
<section>
|
||
<div class="toolbar">
|
||
<h2 style="margin:0;flex:1">Requests</h2>
|
||
<select id="support-filter" aria-label="Which requests">
|
||
<option value="0">Waiting</option>
|
||
<option value="1">Answered</option>
|
||
</select>
|
||
</div>
|
||
<p class="status" id="support-status" role="status"></p>
|
||
<h2>Username changes</h2>
|
||
<div id="name-requests"></div>
|
||
<div class="empty" id="no-name-requests" hidden>Nothing here.</div>
|
||
<h2 style="margin-top:20px">Ban appeals</h2>
|
||
<div id="appeals"></div>
|
||
<div class="empty" id="no-appeals" hidden>Nothing here.</div>
|
||
<h2 style="margin-top:20px">Feedback</h2>
|
||
<div id="feedback"></div>
|
||
<div class="empty" id="no-feedback" hidden>Nothing here.</div>
|
||
</section>
|
||
</div>
|
||
|
||
<div data-view="items" hidden>
|
||
<section>
|
||
<h2 id="item-form-title">Make an item</h2>
|
||
<p class="hint">One of the game's items under a new name, price and colours. Players have it at once, with no restart: in the item finder, and first in the hidden shops of oddities.</p>
|
||
<div class="actions">
|
||
<div class="action">
|
||
<h3>Made from</h3>
|
||
<div class="row">
|
||
<select id="item-kind" aria-label="Kind">
|
||
<option value="clothing">Clothing</option>
|
||
<option value="den">Den item</option>
|
||
</select>
|
||
<input id="item-base" type="number" min="1" placeholder="Id of the game's item" aria-label="Id of the item to copy">
|
||
<button type="button" id="item-look">Look up</button></div>
|
||
<p class="hint" id="item-base-name"></p>
|
||
</div>
|
||
<div class="action">
|
||
<h3>The new item</h3>
|
||
<div class="row"><input id="item-name" maxlength="40" placeholder="Name" aria-label="Name"></div>
|
||
<div class="row" style="margin-top:8px"><input id="item-cost" type="number" min="0" placeholder="Price in gems" aria-label="Price in gems">
|
||
<label class="check"><input type="checkbox" id="item-members"> Members only</label></div>
|
||
<div id="item-colours" aria-label="Colours offered"></div>
|
||
<div class="row" style="margin-top:12px">
|
||
<button type="button" class="primary" id="item-save">Make it</button>
|
||
<button type="button" id="item-cancel" hidden>Cancel</button></div>
|
||
</div>
|
||
</div>
|
||
<p class="status" id="item-status" role="status"></p>
|
||
</section>
|
||
<section>
|
||
<h2>Items made</h2>
|
||
<div class="table-wrap"><table>
|
||
<thead><tr><th>Picture</th><th class="num">Id</th><th>Name</th><th>Made from</th><th class="num">Price</th><th>By</th><th></th></tr></thead>
|
||
<tbody id="items"></tbody>
|
||
</table></div>
|
||
<div class="empty" id="no-items" hidden>None yet.</div>
|
||
</section>
|
||
<section>
|
||
<h2>The players' Item Maker</h2>
|
||
<p class="hint">Whether players may make items of their own (Settings, then Item Maker, in the game), and whether what they make waits for a moderator first.</p>
|
||
<label class="check"><input type="checkbox" id="maker-on"> Players can make items</label>
|
||
<label class="check" style="margin-top:8px"><input type="checkbox" id="maker-approval"> New items (and their pictures) wait for a moderator to approve them</label>
|
||
<label class="check" style="margin-top:8px"><input type="checkbox" id="maker-art-approval"> Every new picture a player uploads waits for a moderator (recommended: pictures are seen by everyone who meets the item)</label>
|
||
<div class="row" style="margin-top:10px"><button type="button" class="primary" id="maker-save">Save</button></div>
|
||
<p class="status" id="maker-status" role="status"></p>
|
||
</section>
|
||
<section>
|
||
<h2>Waiting for approval</h2>
|
||
<p class="hint">Items players made while the admin asks for them to be approved first, and every new picture a player gives one (unless the admin says not). Pictures are blurred: click one to see it. An item let in is given to its maker; one turned away is deleted (a picture turned away is only taken off).</p>
|
||
<div class="review-list" id="review-list"></div>
|
||
<div class="empty" id="no-review" hidden>Nothing is waiting.</div>
|
||
<h3 style="margin:18px 0 4px">Picture uploads stopped</h3>
|
||
<p class="hint">A player whose 3 pictures were turned away (or taken off) can upload no more till they are let again, which clears the count. A picture turned away can never be sent again.</p>
|
||
<div class="toolbar"><input id="stop-name" maxlength="20" placeholder="Username" aria-label="Player whose uploads to stop">
|
||
<button type="button" class="danger" id="stop-go">Stop their uploads</button></div>
|
||
<ul class="plain" id="stopped-list"></ul>
|
||
<div class="empty" id="no-stopped" hidden>Nobody.</div>
|
||
<p class="status" id="review-status" role="status"></p>
|
||
</section>
|
||
<section>
|
||
<h2>Item finder and inventories</h2>
|
||
<p class="hint">Any item of the game's or a custom one, by its id. A locked item is kept out of the item finder for players; admins and developers still find it there, marked locked. Taking an item takes every one of it the player has.</p>
|
||
<div class="actions">
|
||
<div class="action">
|
||
<h3>Lock out of the finder</h3>
|
||
<div class="row">
|
||
<select id="lock-kind" aria-label="Kind">
|
||
<option value="clothing">Clothing</option>
|
||
<option value="den">Den item</option>
|
||
</select>
|
||
<input id="lock-id" type="number" min="1" placeholder="Item id" aria-label="Item id">
|
||
<button type="button" id="lock-add">Lock</button></div>
|
||
<ul class="plain" id="locked-items"></ul>
|
||
<div class="empty" id="no-locked">Nothing locked.</div>
|
||
</div>
|
||
<div class="action">
|
||
<h3>Take from a player</h3>
|
||
<div class="row"><input id="take-name" maxlength="20" placeholder="Username" aria-label="Username"></div>
|
||
<div class="row" style="margin-top:8px">
|
||
<select id="take-kind" aria-label="Kind">
|
||
<option value="clothing">Clothing</option>
|
||
<option value="den">Den item</option>
|
||
</select>
|
||
<input id="take-id" type="number" min="1" placeholder="Item id" aria-label="Item id">
|
||
<button type="button" id="take-go">Take</button></div>
|
||
</div>
|
||
</div>
|
||
<p class="status" id="control-status" role="status"></p>
|
||
</section>
|
||
</div>
|
||
|
||
<div data-view="moderators" hidden>
|
||
<section>
|
||
<h2>Moderators</h2>
|
||
<p class="hint">They sign in at <a href="/mod">/mod</a>.</p>
|
||
<div class="table-wrap"><table>
|
||
<thead><tr><th>Name</th><th>2FA</th><th>Last seen</th><th></th></tr></thead>
|
||
<tbody id="moderators"></tbody>
|
||
</table></div>
|
||
<div class="empty" id="no-moderators" hidden>Nobody. Make one from Accounts.</div>
|
||
</section>
|
||
<section>
|
||
<h2>Role permissions</h2>
|
||
<p class="hint">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.</p>
|
||
<div class="table-wrap"><table>
|
||
<thead id="role-head"></thead>
|
||
<tbody id="role-matrix"></tbody>
|
||
</table></div>
|
||
<p class="status" id="role-status" role="status"></p>
|
||
</section>
|
||
<section>
|
||
<h2>What they did</h2>
|
||
<div class="table-wrap"><table>
|
||
<thead><tr><th>When</th><th>Who</th><th>What</th><th>Player</th><th>Detail</th></tr></thead>
|
||
<tbody id="mod-log"></tbody>
|
||
</table></div>
|
||
<div class="empty" id="no-mod-log" hidden>Nothing yet.</div>
|
||
</section>
|
||
</div>
|
||
|
||
<div data-view="bans" hidden>
|
||
<section>
|
||
<h2>Banned and silenced</h2>
|
||
<p class="status" id="ban-status" role="status"></p>
|
||
<div class="table-wrap"><table>
|
||
<thead><tr><th>Name</th><th>Ban</th><th>Reason</th><th>Chat</th><th></th></tr></thead>
|
||
<tbody id="bans"></tbody>
|
||
</table></div>
|
||
<div class="empty" id="no-bans" hidden>Nobody is banned or silenced.</div>
|
||
</section>
|
||
<section>
|
||
<h2>Banned addresses</h2>
|
||
<form id="address-form" class="toolbar">
|
||
<input id="address" maxlength="60" placeholder="IP address" autocomplete="off" spellcheck="false" aria-label="IP address" required>
|
||
<input id="address-reason" maxlength="300" placeholder="Reason" autocomplete="off" aria-label="Reason" style="flex:1">
|
||
<button class="danger" type="submit">Ban</button>
|
||
</form>
|
||
<p class="status" id="address-status" role="status"></p>
|
||
<div class="table-wrap"><table>
|
||
<thead><tr><th>Address</th><th>Reason</th><th>Since</th><th></th></tr></thead>
|
||
<tbody id="addresses"></tbody>
|
||
</table></div>
|
||
<div class="empty" id="no-addresses" hidden>No address is banned.</div>
|
||
</section>
|
||
<section>
|
||
<h2>Hardware bans</h2>
|
||
<p class="status" id="device-status" role="status"></p>
|
||
<div class="table-wrap"><table>
|
||
<thead><tr><th>Banned with</th><th>Reason</th><th>By</th><th>Since</th><th>Accounts</th><th>Ids</th><th></th></tr></thead>
|
||
<tbody id="device-bans"></tbody>
|
||
</table></div>
|
||
<div class="empty" id="no-device-bans" hidden>No hardware bans.</div>
|
||
</section>
|
||
<section>
|
||
<h2>Hardware alerts</h2>
|
||
<div class="table-wrap"><table>
|
||
<thead><tr><th>When</th><th>Player</th><th>What</th><th>Detail</th></tr></thead>
|
||
<tbody id="device-alerts"></tbody>
|
||
</table></div>
|
||
<div class="empty" id="no-device-alerts" hidden>Nothing yet.</div>
|
||
</section>
|
||
<section>
|
||
<h2>Stopped most by the filter</h2>
|
||
<div class="table-wrap"><table>
|
||
<thead><tr><th>Player</th><th class="num">Stopped</th><th>Last</th><th></th></tr></thead>
|
||
<tbody id="filter-hits"></tbody>
|
||
</table></div>
|
||
<div class="empty" id="no-filter-hits" hidden>Nobody.</div>
|
||
</section>
|
||
</div>
|
||
|
||
<div data-view="messages" hidden>
|
||
<div class="columns">
|
||
<section>
|
||
<h2>Message of the day</h2>
|
||
<textarea id="motd-text" rows="4" maxlength="300" aria-label="Message of the day"></textarea>
|
||
<div class="send-row"><button class="primary" type="button" id="motd-save">Save</button></div>
|
||
<p class="status" id="motd-status" role="status"></p>
|
||
</section>
|
||
<section>
|
||
<h2>Announcement</h2>
|
||
<textarea id="announce-text" rows="4" maxlength="300" aria-label="Announcement"></textarea>
|
||
<div class="send-row">
|
||
<select id="announce-room" aria-label="Who sees it"></select>
|
||
<button class="primary" type="button" id="announce-send">Send</button>
|
||
</div>
|
||
<p class="status" id="announce-status" role="status"></p>
|
||
</section>
|
||
</div>
|
||
</div>
|
||
|
||
<div data-view="masterpieces" hidden>
|
||
<section>
|
||
<div class="toolbar">
|
||
<h2 style="margin:0;flex:1">Masterpieces</h2>
|
||
<select id="masterpiece-filter" aria-label="Which masterpieces">
|
||
<option value="waiting">Waiting</option>
|
||
<option value="approved">Approved</option>
|
||
<option value="all">All</option>
|
||
</select>
|
||
<input id="masterpiece-creator" type="search" maxlength="100" placeholder="Maker's username" autocomplete="off" spellcheck="false" aria-label="Maker's username">
|
||
</div>
|
||
<label class="check"><input id="masterpiece-review" type="checkbox"> Review new masterpieces</label>
|
||
<p class="status" id="masterpiece-status" role="status"></p>
|
||
<div class="paintings" id="masterpieces"></div>
|
||
<div class="empty" id="no-masterpieces" hidden>Nothing here.</div>
|
||
<div class="preview" id="preview" hidden><img id="preview-img" alt=""></div>
|
||
</section>
|
||
</div>
|
||
|
||
<div data-view="debug" hidden>
|
||
<div class="columns">
|
||
<section>
|
||
<h2>Teleport</h2>
|
||
<div class="send-row">
|
||
<select id="debug-player" aria-label="Player"></select>
|
||
<input id="debug-room-filter" type="search" placeholder="Filter" aria-label="Filter rooms">
|
||
<label class="check"><input id="debug-noted" type="checkbox"> Unreachable only</label>
|
||
</div>
|
||
<select id="debug-room" size="14" aria-label="Room" style="width:100%;margin-top:8px"></select>
|
||
<div class="send-row"><button class="primary" type="button" id="debug-go">Go</button></div>
|
||
<p class="status" id="debug-status" role="status"></p>
|
||
</section>
|
||
<section>
|
||
<h2>Sale dates</h2>
|
||
<label class="check"><input id="debug-onsale" type="checkbox"> Everything on sale</label>
|
||
<p class="status" id="debug-sale-status" role="status"></p>
|
||
</section>
|
||
</div>
|
||
</div>
|
||
|
||
<div data-view="logs" hidden>
|
||
<section>
|
||
<div class="toolbar">
|
||
<input id="log-filter" type="search" placeholder="Filter" aria-label="Filter log lines">
|
||
<select id="log-preset" aria-label="Common filters">
|
||
<option value="">Everything</option>
|
||
<option value="[client-error]">Client errors</option>
|
||
<option value="[world]">World</option>
|
||
<option value="[admin]">Admin</option>
|
||
<option value="[accounts]">Accounts</option>
|
||
</select>
|
||
<label class="check"><input id="log-follow" type="checkbox" checked> Follow</label>
|
||
</div>
|
||
<pre id="log" tabindex="0" aria-label="Server log"></pre>
|
||
</section>
|
||
</div>
|
||
|
||
<div data-view="settings" hidden>
|
||
<section>
|
||
<h2>Admin password</h2>
|
||
<form id="password-form">
|
||
<label for="current-password">Current</label>
|
||
<input id="current-password" type="password" autocomplete="current-password" required>
|
||
<label for="next-password">New</label>
|
||
<input id="next-password" type="password" autocomplete="new-password" required minlength="8">
|
||
<label for="next-confirm">New again</label>
|
||
<input id="next-confirm" type="password" autocomplete="new-password" required>
|
||
<button class="primary">Change</button>
|
||
</form>
|
||
<p class="status" id="password-status" role="status"></p>
|
||
</section>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<script>
|
||
"use strict";
|
||
|
||
const $ = id => document.getElementById(id);
|
||
const REFRESH_MS = 5000;
|
||
const LOG_REFRESH_MS = 2000;
|
||
const MAX_LOG_LINES = 2000;
|
||
|
||
let state = null; // {needsSetup, needsSetupCode, signedIn}
|
||
let accounts = []; // the rows the search found (at most a page)
|
||
let accountTotal = 0; // how many matched in all
|
||
let current = null; // the open account's row, fetched on its own
|
||
let badges = []; // {id, label}: the badges an account's card can show
|
||
let selected = null; // username whose actions are shown
|
||
let tab = "overview";
|
||
let lastLogId = 0;
|
||
let timer = null;
|
||
|
||
const api = async (path, body) => {
|
||
const response = await fetch(`/admin/api/${path}`, body === undefined ? {} : {
|
||
method: "POST",
|
||
headers: {"Content-Type": "application/json"},
|
||
body: JSON.stringify(body),
|
||
});
|
||
const data = await response.json().catch(() => ({}));
|
||
if (response.status === 401 && state && state.signedIn) {
|
||
// the session ended (the server restarted, or 12 hours passed).
|
||
state.signedIn = false;
|
||
showGate("Your session ended. Sign in again.");
|
||
}
|
||
return {ok: response.ok, status: response.status, data};
|
||
};
|
||
|
||
const setStatus = (element, text, bad = false) => {
|
||
element.textContent = text;
|
||
element.classList.toggle("bad", bad);
|
||
};
|
||
|
||
const el = (tag, text, className) => {
|
||
const node = document.createElement(tag);
|
||
if (text !== undefined) {
|
||
node.textContent = text;
|
||
}
|
||
if (className) {
|
||
node.className = className;
|
||
}
|
||
return node;
|
||
};
|
||
|
||
const when = seconds => (seconds ? new Date(seconds * 1000).toLocaleString([], {dateStyle: "medium", timeStyle: "short"}) : "never");
|
||
const said = result => result.data.ok || result.data.error || "That did not work.";
|
||
// a button that does something, and cannot be pressed again until it is done.
|
||
const btn = (label, onClick, className) => {
|
||
const node = el("button", label, className);
|
||
node.type = "button";
|
||
node.addEventListener("click", async () => {
|
||
node.disabled = true;
|
||
await onClick();
|
||
node.disabled = false;
|
||
});
|
||
return node;
|
||
};
|
||
|
||
const duration = seconds => {
|
||
const units = [[86400, "day"], [3600, "hour"], [60, "minute"]];
|
||
for (const [size, name] of units) {
|
||
if (seconds >= size) {
|
||
const count = Math.floor(seconds / size);
|
||
return `${count} ${name}${count === 1 ? "" : "s"}`;
|
||
}
|
||
}
|
||
return "under a minute";
|
||
};
|
||
|
||
const showGate = message => {
|
||
clearTimeout(timer);
|
||
$("panel").hidden = true;
|
||
$("gate").hidden = false;
|
||
const setup = state.needsSetup;
|
||
$("gate-title").textContent = setup ? "Set admin password" : "Server admin";
|
||
$("gate-text").hidden = true;
|
||
$("password-label").textContent = setup ? "Password (8+ characters)" : "Password";
|
||
$("password").autocomplete = setup ? "new-password" : "current-password";
|
||
$("confirm-field").hidden = !setup;
|
||
$("code-field").hidden = !(setup && state.needsSetupCode);
|
||
$("gate-button").textContent = setup ? "Set password" : "Sign in";
|
||
$("password").value = "";
|
||
$("confirm").value = "";
|
||
setStatus($("gate-status"), message || "");
|
||
($("code-field").hidden ? $("password") : $("code")).focus();
|
||
};
|
||
|
||
$("gate-form").addEventListener("submit", async event => {
|
||
event.preventDefault();
|
||
const password = $("password").value;
|
||
if (state.needsSetup && password !== $("confirm").value) {
|
||
setStatus($("gate-status"), "The two passwords are different.", true);
|
||
return;
|
||
}
|
||
$("gate-button").disabled = true;
|
||
const result = state.needsSetup
|
||
? await api("setup", {password, code: $("code").value})
|
||
: await api("login", {password});
|
||
$("gate-button").disabled = false;
|
||
if (!result.ok) {
|
||
setStatus($("gate-status"), result.data.error || "That did not work.", true);
|
||
return;
|
||
}
|
||
state = {needsSetup: false, needsSetupCode: false, signedIn: true};
|
||
showPanel();
|
||
});
|
||
|
||
$("sign-out").addEventListener("click", async () => {
|
||
await api("logout", {});
|
||
state.signedIn = false;
|
||
showGate("Signed out.");
|
||
});
|
||
|
||
const TILES = [
|
||
["online", "Playing now"],
|
||
["accounts", "Accounts"],
|
||
["activeToday", "Logged in, last 24 hours"],
|
||
["newToday", "Created, last 24 hours"],
|
||
["banned", "Banned"],
|
||
["reports", "Reports waiting"],
|
||
["support", "Requests and feedback waiting"],
|
||
["masterpieces", "Masterpieces waiting"],
|
||
["clientErrors", "Game client errors logged"],
|
||
];
|
||
|
||
const renderOverview = data => {
|
||
$("tiles").replaceChildren(...TILES.map(([key, name]) => {
|
||
const tile = el("div", undefined, "tile");
|
||
tile.append(el("div", data.stats[key].toLocaleString(), "value"), el("div", name, "name"));
|
||
return tile;
|
||
}));
|
||
$("report-count").textContent = data.stats.reports ? String(data.stats.reports) : "";
|
||
$("support-count").textContent = data.stats.support ? String(data.stats.support) : "";
|
||
$("masterpiece-count").textContent = data.stats.masterpieces ? String(data.stats.masterpieces) : "";
|
||
$("players").replaceChildren(...data.players.map(player => {
|
||
const row = el("tr");
|
||
row.append(el("td", player.username), el("td", player.room || "(between rooms)"), el("td", player.address));
|
||
return row;
|
||
}));
|
||
$("no-players").hidden = data.players.length > 0;
|
||
const yesNo = value => (value ? "Yes" : "No");
|
||
const facts = [
|
||
["Address", data.server.address],
|
||
["Running for", duration(data.server.uptimeSeconds)],
|
||
["Memory", `${data.server.memoryMb} MB`],
|
||
["Node", data.server.node],
|
||
["Reachable from other machines", yesNo(data.server.reachableFromOtherMachines)],
|
||
["Encrypted (TLS)", yesNo(data.server.encrypted)],
|
||
["Packet log", data.server.packetLog ? "On" : "Off"],
|
||
["Custom colours", data.server.customColours.toLocaleString()],
|
||
["Busiest rooms", data.rooms.slice(0, 5).map(room => `${room.name} (${room.count})`).join(", ") || "none"],
|
||
];
|
||
$("server-facts").replaceChildren(...facts.flatMap(([name, value]) => [el("dt", name), el("dd", String(value))]));
|
||
};
|
||
|
||
const accountState = account => {
|
||
const tags = [];
|
||
if (account.online) {
|
||
tags.push(el("span", `Online · ${account.room}`, "tag"));
|
||
}
|
||
if (account.banned !== 0) {
|
||
tags.push(el("span", account.banned === -1 ? "Banned" : `Banned ${duration(account.banned)}`, "tag bad"));
|
||
}
|
||
if (account.silenced) {
|
||
tags.push(el("span", "Silenced", "tag bad"));
|
||
}
|
||
if (account.deviceBanned) {
|
||
tags.push(el("span", "Hardware banned", "tag bad"));
|
||
}
|
||
if (account.locked) {
|
||
tags.push(el("span", "Locked", "tag bad"));
|
||
}
|
||
if (account.nameRejected) {
|
||
tags.push(el("span", "Name rejected", "tag bad"));
|
||
}
|
||
if (account.moderator) {
|
||
const label = {developer: "Developer", helper: "Helper", moderator: "Moderator", admin: "Admin"}[account.role] || "Moderator";
|
||
tags.push(el("span", label, "tag good"));
|
||
}
|
||
if (account.twoStep) {
|
||
tags.push(el("span", "2FA", "tag"));
|
||
}
|
||
for (const id of account.badges) {
|
||
tags.push(el("span", (badges.find(badge => badge.id === id) || {label: id}).label, "tag"));
|
||
}
|
||
if (account.featuresOff && account.featuresOff.length) {
|
||
tags.push(el("span", `Off: ${account.featuresOff.join(", ")}`, "tag"));
|
||
}
|
||
return tags.length ? tags : [el("span", "Offline", "hint")];
|
||
};
|
||
|
||
// time played: "3d 4h", "2h 15m", "40m".
|
||
const played = seconds => {
|
||
const days = Math.floor(seconds / 86400);
|
||
const hours = Math.floor(seconds % 86400 / 3600);
|
||
const minutes = Math.floor(seconds % 3600 / 60);
|
||
return days > 0 ? `${days.toLocaleString()}d ${hours}h` : hours > 0 ? `${hours}h ${minutes}m` : `${minutes}m`;
|
||
};
|
||
|
||
// by IP address (the sign-in histories) or hardware ID (lib/devices.js).
|
||
let addressFound = null; // {query, by, players} or null
|
||
const searchByAddress = async () => {
|
||
const by = $("account-search-by").value;
|
||
const query = $("account-search").value.trim();
|
||
if (query === "") {
|
||
addressFound = null;
|
||
setStatus($("address-status"), "");
|
||
renderAccounts();
|
||
return;
|
||
}
|
||
const result = await api(`${by}-search?q=${encodeURIComponent(query)}`);
|
||
if (query !== $("account-search").value.trim() || by !== $("account-search-by").value) {
|
||
return; // typed on meanwhile
|
||
}
|
||
addressFound = result.ok ? {query, by, players: result.data.players} : null;
|
||
setStatus($("address-status"), result.ok ? (result.data.players.length ? "" : "Nobody signed in from there.") : result.data.error || "That did not work.", !result.ok);
|
||
renderAccounts();
|
||
};
|
||
|
||
const renderAddressResults = () => {
|
||
const found = addressFound ? addressFound.players : [];
|
||
$("address-results").replaceChildren(...found.map(entry => {
|
||
const account = accounts.find(one => one.username === entry.username);
|
||
const row = el("tr", undefined, entry.username === selected ? "pick selected" : "pick");
|
||
const nameCell = el("td");
|
||
const pick = el("button", entry.username);
|
||
pick.type = "button";
|
||
nameCell.append(pick);
|
||
const stateCell = el("td");
|
||
if (account) {
|
||
stateCell.append(...accountState(account).flatMap(tag => [tag, " "]));
|
||
}
|
||
row.addEventListener("click", () => select(entry.username));
|
||
if (!account && entry.online) {
|
||
stateCell.append(el("span", "Online", "tag"));
|
||
}
|
||
row.append(nameCell, stateCell, el("td", entry.addresses ? entry.addresses.map(one => one.address).join(", ") : entry.kinds.map(kind => KIND_NAMES[kind] || kind).join(", ")),
|
||
el("td", when(entry.lastAt)));
|
||
return row;
|
||
}));
|
||
};
|
||
|
||
const renderAccounts = () => {
|
||
const searchBy = $("account-search-by").value;
|
||
const byAddress = searchBy !== "name";
|
||
$("address-view").hidden = !byAddress;
|
||
$("found-what").textContent = searchBy === "device" ? "Ids matched" : "Addresses";
|
||
$("found-when").textContent = searchBy === "device" ? "Last used" : "Last from there";
|
||
$("account-list").hidden = byAddress;
|
||
if (byAddress) {
|
||
renderAddressResults();
|
||
$("no-accounts").hidden = true;
|
||
}
|
||
// found and put in order by the server (exact name first).
|
||
const shown = byAddress ? [] : accounts;
|
||
$("account-more").hidden = byAddress || accountTotal <= shown.length;
|
||
$("account-more").textContent = `Showing ${shown.length} of ${accountTotal.toLocaleString()}. Type more of the name to narrow it down.`;
|
||
$("accounts").replaceChildren(...shown.map(account => {
|
||
const row = el("tr", undefined, account.username === selected ? "pick selected" : "pick");
|
||
const stateCell = el("td");
|
||
stateCell.append(...accountState(account).flatMap(tag => [tag, " "]));
|
||
const nameCell = el("td");
|
||
const pick = el("button", account.username);
|
||
pick.type = "button";
|
||
pick.addEventListener("click", event => {
|
||
event.stopPropagation();
|
||
select(account.username);
|
||
});
|
||
nameCell.append(pick);
|
||
row.addEventListener("click", () => select(account.username));
|
||
row.append(nameCell, stateCell, el("td", when(account.createdAt)), el("td", when(account.lastLogin)), el("td", account.online ? "online" : when(account.lastSeen)),
|
||
el("td", account.logins.toLocaleString(), "num"), el("td", account.animals.toLocaleString(), "num"),
|
||
el("td", account.items.toLocaleString(), "num"));
|
||
return row;
|
||
}));
|
||
if (!byAddress) {
|
||
$("no-accounts").hidden = shown.length > 0;
|
||
}
|
||
$("detail").hidden = !current;
|
||
if (current) {
|
||
$("detail-name").textContent = `${current.username} · ${current.gems.toLocaleString()} gems · played ${played(current.playtime || 0)}${current.playtimePublic ? " (public)" : ""}`;
|
||
$("look-facts").textContent = `Stopped by the filter: ${current.stoppedThisWeek} in the last 7 days · Hardware IDs: `
|
||
+ `${current.devicesKnown || "none yet"} · Paintings: ${current.paintings}`;
|
||
}
|
||
};
|
||
|
||
const listOf = (title, entries) => {
|
||
const nodes = [el("h3", `${title} (${entries.length})`)];
|
||
if (entries.length) {
|
||
const list = el("ul");
|
||
list.append(...entries.map(entry => el("li", entry)));
|
||
nodes.push(list);
|
||
}
|
||
return nodes;
|
||
};
|
||
|
||
const loadOwned = async () => {
|
||
const username = selected;
|
||
$("owned").replaceChildren();
|
||
if (!username) {
|
||
return;
|
||
}
|
||
const result = await api(`owned?username=${encodeURIComponent(username)}`);
|
||
if (!result.ok || username !== selected) {
|
||
return;
|
||
}
|
||
const owned = result.data;
|
||
const counted = entries => entries.map(entry => (entry.count > 1 ? `${entry.name} ×${entry.count}` : entry.name));
|
||
const facts = el("dl");
|
||
const pairs = [
|
||
["Gems", owned.currency.gems.toLocaleString()],
|
||
["Diamonds", owned.currency.diamonds.toLocaleString()],
|
||
["Tickets", owned.currency.tickets.toLocaleString()],
|
||
["Dens", owned.dens],
|
||
["Achievements", owned.achievements],
|
||
["Adopt-A-Pets", owned.adoptAPets],
|
||
["Jam-A-Grams in inbox", owned.jamAGrams],
|
||
["Posts on their wall", owned.wallPosts],
|
||
["Hides blocked players", owned.hidesBlockedPlayers ? "Yes" : "No"],
|
||
];
|
||
facts.append(...pairs.flatMap(([name, value]) => [el("dt", name), el("dd", String(value))]));
|
||
const more = (shown, total) => (total > shown ? [el("p", `…and ${total - shown} more.`, "hint")] : []);
|
||
$("owned").append(el("h2", "What they own"), facts,
|
||
...listOf("Animals", owned.animals), ...listOf("Pets", owned.pets),
|
||
...listOf("Clothing, by kind", counted(owned.clothing)), ...more(owned.clothing.reduce((sum, entry) => sum + entry.count, 0), owned.clothingTotal),
|
||
...listOf("Den items, by kind", counted(owned.denItems)), ...more(owned.denItems.reduce((sum, entry) => sum + entry.count, 0), owned.denItemsTotal),
|
||
...listOf("Buddies", owned.buddies), ...listOf("Blocked", owned.blocked),
|
||
...listOf("Saved outfits", owned.outfits), ...listOf("Saved den layouts", owned.denLayouts));
|
||
};
|
||
|
||
// what was done about the selected account's bans, its appeal, and the
|
||
// addresses it signed in from, each with a button to ban that address
|
||
// (for good, with the reason in the box above).
|
||
const BAN_ACTIONS = {ban: "Banned", unban: "Ban lifted", reason: "Reason changed", appeal: "Appealed",
|
||
appeal_approved: "Appeal approved", appeal_denied: "Appeal denied"};
|
||
const loadBanRecord = async () => {
|
||
const username = selected;
|
||
$("ban-record").replaceChildren();
|
||
if (!username) {
|
||
return;
|
||
}
|
||
const result = await api(`banrecord?username=${encodeURIComponent(username)}`);
|
||
if (!result.ok || username !== selected) {
|
||
return;
|
||
}
|
||
const {history, addresses, appeal} = result.data;
|
||
const nodes = [];
|
||
if (addresses.length) {
|
||
const list = el("ul");
|
||
list.append(...addresses.map(entry => {
|
||
const item = el("li", `${entry.address} · ${when(entry.at)} `);
|
||
if (entry.own) {
|
||
return item;
|
||
}
|
||
const node = el("button", entry.banned ? "Unban address" : "Ban address", entry.banned ? "" : "danger");
|
||
node.type = "button";
|
||
node.addEventListener("click", async () => {
|
||
node.disabled = true;
|
||
const answer = await api("address", {action: entry.banned ? "unban" : "ban", address: entry.address, reason: $("ban-reason").value});
|
||
setStatus($("detail-status"), answer.data.ok || answer.data.error || "That did not work.", !answer.ok);
|
||
loadBanRecord();
|
||
});
|
||
item.append(node);
|
||
return item;
|
||
}));
|
||
nodes.push(el("h3", "Addresses"), list);
|
||
}
|
||
if (appeal) {
|
||
nodes.push(el("h3", `Appeal: ${appeal.status}`), el("p", appeal.text, "hint"));
|
||
}
|
||
if (history.length) {
|
||
const list = el("ul");
|
||
list.append(...history.map(entry => el("li", [when(entry.at), BAN_ACTIONS[entry.action] || entry.action,
|
||
entry.action === "ban" ? (entry.seconds === -1 ? "for good" : duration(entry.seconds)) : "", entry.reason, entry.by && `by ${entry.by}`]
|
||
.filter(Boolean).join(" · "))));
|
||
nodes.push(el("h3", "Ban history"), list);
|
||
}
|
||
$("ban-record").replaceChildren(...nodes);
|
||
};
|
||
|
||
// ---- permissions (lib/roles.js): the roles and what each may do
|
||
let roleInfo = null;
|
||
const loadRoles = async () => {
|
||
const result = await api("roles");
|
||
if (result.ok) {
|
||
roleInfo = result.data;
|
||
}
|
||
return roleInfo;
|
||
};
|
||
|
||
// one staff member's: a choice for each permission
|
||
const renderPermissions = current => {
|
||
const shown = Boolean(current && current.role && roleInfo);
|
||
$("perm-part").hidden = !shown;
|
||
if (!shown) {
|
||
return;
|
||
}
|
||
const role = roleInfo.roles.find(entry => entry.id === current.role);
|
||
const fromRole = new Set(role ? role.permissions : []);
|
||
$("perm-list").replaceChildren(...Object.entries(roleInfo.permissions).flatMap(([permission, description]) => {
|
||
const may = current.permissions.includes(permission);
|
||
const label = el("div", `${may ? "✓" : "✗"} ${permission}: ${description}`, may ? "on" : "off");
|
||
const choice = el("select");
|
||
choice.dataset.permission = permission;
|
||
choice.setAttribute("aria-label", permission);
|
||
for (const [value, text] of [["role", fromRole.has(permission) ? "As their role (yes)" : "As their role (no)"], ["grant", "Give them"], ["deny", "Take from them"]]) {
|
||
const option = el("option", text);
|
||
option.value = value;
|
||
choice.append(option);
|
||
}
|
||
choice.value = current.permGrants.includes(permission) ? "grant" : current.permDenies.includes(permission) ? "deny" : "role";
|
||
return [label, choice];
|
||
}));
|
||
};
|
||
|
||
const permissionChoices = () => {
|
||
const chosen = [...$("perm-list").querySelectorAll("select")];
|
||
return {grants: chosen.filter(box => box.value === "grant").map(box => box.dataset.permission),
|
||
denies: chosen.filter(box => box.value === "deny").map(box => box.dataset.permission)};
|
||
};
|
||
|
||
// every role's: a column each, a box for each permission
|
||
const renderRoleMatrix = () => {
|
||
if (!roleInfo) {
|
||
return;
|
||
}
|
||
const head = el("tr");
|
||
head.append(el("th", "Permission"), ...roleInfo.roles.map(role => el("th", `${role.label}${role.changed ? " (changed)" : ""}`)));
|
||
$("role-head").replaceChildren(head);
|
||
const rows = Object.entries(roleInfo.permissions).map(([permission, description]) => {
|
||
const row = el("tr");
|
||
const name = el("td");
|
||
name.append(el("strong", permission), el("div", description, "hint"));
|
||
row.append(name, ...roleInfo.roles.map(role => {
|
||
const cell = el("td");
|
||
const box = el("input");
|
||
box.type = "checkbox";
|
||
box.dataset.role = role.id;
|
||
box.dataset.permission = permission;
|
||
box.checked = role.permissions.includes(permission);
|
||
box.setAttribute("aria-label", `${role.label}: ${permission}`);
|
||
cell.append(box);
|
||
return cell;
|
||
}));
|
||
return row;
|
||
});
|
||
const buttons = el("tr");
|
||
buttons.append(el("td"), ...roleInfo.roles.map(role => {
|
||
const cell = el("td");
|
||
cell.append(button("Save", async () => {
|
||
const permissions = [...$("role-matrix").querySelectorAll(`input[data-role="${role.id}"]`)].filter(box => box.checked).map(box => box.dataset.permission);
|
||
const result = await api("roles", {role: role.id, permissions});
|
||
setStatus($("role-status"), said(result), !result.ok);
|
||
await loadRoles();
|
||
renderRoleMatrix();
|
||
}), " ", button("Reset", async () => {
|
||
const result = await api("roles", {role: role.id, reset: true});
|
||
setStatus($("role-status"), said(result), !result.ok);
|
||
await loadRoles();
|
||
renderRoleMatrix();
|
||
}));
|
||
return cell;
|
||
}));
|
||
$("role-matrix").replaceChildren(...rows, buttons);
|
||
};
|
||
|
||
const fillCard = () => {
|
||
const current = accounts.find(account => account.username === selected);
|
||
if (roleInfo) {
|
||
renderPermissions(current);
|
||
}
|
||
else {
|
||
loadRoles().then(() => renderPermissions(accounts.find(account => account.username === selected)));
|
||
}
|
||
$("badge-boxes").replaceChildren(...badges.map(badge => {
|
||
const label = el("label", undefined, "check");
|
||
const box = el("input");
|
||
box.type = "checkbox";
|
||
box.value = badge.id;
|
||
box.checked = Boolean(current && current.badges.includes(badge.id));
|
||
label.append(box, ` ${badge.label}`);
|
||
return label;
|
||
}));
|
||
$("discord-name").value = current ? current.discord : "";
|
||
$("bio-text").value = current ? current.bio : "";
|
||
$("quest-level").value = current ? current.level : "";
|
||
$("ban-reason").value = current ? current.banReason : "";
|
||
$("moderator-toggle").textContent = current && current.moderator ? "Remove moderator" : "Make moderator";
|
||
$("role-select").value = current && current.role ? current.role : "none";
|
||
};
|
||
|
||
// the open account's own row, whatever the search shows.
|
||
const loadCurrent = async () => {
|
||
const username = selected;
|
||
if (!username) {
|
||
current = null;
|
||
return;
|
||
}
|
||
const result = await api(`account?username=${encodeURIComponent(username)}`);
|
||
if (username !== selected) {
|
||
return;
|
||
}
|
||
current = result.ok ? result.data.account : null;
|
||
badges = result.ok ? result.data.badges : badges;
|
||
if (!current) {
|
||
selected = null;
|
||
}
|
||
};
|
||
|
||
// an account to open, from this page or another: its row, card and records.
|
||
const openAccount = async username => {
|
||
selected = username;
|
||
current = null;
|
||
setStatus($("detail-status"), "");
|
||
for (const id of ["new-name", "new-password", "ban-hours", "silence-hours", "message-text", "gems-amount", "gift-value", "gift-text"]) {
|
||
$(id).value = "";
|
||
}
|
||
hashArg = username;
|
||
setHash();
|
||
await loadCurrent();
|
||
renderAccounts();
|
||
fillCard();
|
||
loadOwned();
|
||
loadBanRecord();
|
||
loadExtras();
|
||
};
|
||
// every account that used a hardware ID: the account list, searched by it.
|
||
const searchDevice = id => {
|
||
$("account-search-by").value = "device";
|
||
$("account-search").placeholder = "Hardware ID, or the start of one";
|
||
$("account-search").value = id;
|
||
showTab("accounts");
|
||
searchByAddress();
|
||
window.scrollTo(0, 0);
|
||
};
|
||
|
||
// from another page.
|
||
const openAccountTab = username => {
|
||
hashArg = username;
|
||
showTab("accounts");
|
||
openAccount(username);
|
||
};
|
||
|
||
// 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.
|
||
let mailLines = [];
|
||
const loadMail = async older => {
|
||
const username = selected;
|
||
if (!username) {
|
||
return;
|
||
}
|
||
const before = older && mailLines.length ? mailLines[mailLines.length - 1].id : 0;
|
||
const result = await api(`chat?username=${encodeURIComponent(username)}&kind=${$("mail-kind").value}`
|
||
+ `&direction=${$("mail-direction").value}&before=${before}`);
|
||
if (username !== selected) {
|
||
return;
|
||
}
|
||
const lines = result.ok ? result.data.lines : [];
|
||
mailLines = older ? [...mailLines, ...lines] : lines;
|
||
$("mail-lines").replaceChildren(...mailLines.map(line => lineNode(line, true)));
|
||
$("no-mail").hidden = mailLines.length > 0;
|
||
$("mail-older").hidden = !(result.ok && result.data.more);
|
||
};
|
||
$("mail-kind").addEventListener("change", () => loadMail(false));
|
||
$("mail-direction").addEventListener("change", () => loadMail(false));
|
||
$("mail-older").addEventListener("click", () => loadMail(true));
|
||
|
||
// other accounts the same person may have, and what happened to them:
|
||
// asked when an account is opened and after an action, not every few
|
||
// seconds (finding alts looks through every account).
|
||
const KIND_NAMES = {os: "system id", board: "board", disk: "disk", install: "client id", mac: "network card"};
|
||
const TIMELINE_NAMES = {ban: "Ban", staff: "Staff", report: "Report", alert: "Alert"};
|
||
const loadExtras = async () => {
|
||
const username = selected;
|
||
$("alts").replaceChildren();
|
||
$("device-ids").replaceChildren();
|
||
$("mail-lines").replaceChildren();
|
||
$("timeline").replaceChildren();
|
||
if (!username) {
|
||
return;
|
||
}
|
||
loadMail(false);
|
||
const [alts, timeline] = await Promise.all([api(`alts?username=${encodeURIComponent(username)}`), api(`timeline?username=${encodeURIComponent(username)}`)]);
|
||
if (username !== selected) {
|
||
return;
|
||
}
|
||
const altList = alts.ok ? alts.data.alts : [];
|
||
$("alts").replaceChildren(...altList.map(alt => {
|
||
const row = el("tr", undefined, "pick");
|
||
const stateCell = el("td");
|
||
if (alt.online) {
|
||
stateCell.append(el("span", "Online", "tag"), " ");
|
||
}
|
||
if (alt.banned !== 0) {
|
||
stateCell.append(el("span", alt.banned === -1 ? "Banned" : `Banned ${duration(alt.banned)}`, "tag bad"), " ");
|
||
}
|
||
if (alt.deviceBanned) {
|
||
stateCell.append(el("span", "Hardware banned", "tag bad"));
|
||
}
|
||
row.append(el("td", alt.username), stateCell,
|
||
el("td", alt.devices.length ? `${alt.devices.map(kind => KIND_NAMES[kind] || kind).join(", ")}${alt.weak ? " (weak)" : ""}` : "—"),
|
||
el("td", alt.addresses ? String(alt.addresses) : "—", "num"));
|
||
row.addEventListener("click", () => openAccount(alt.username));
|
||
return row;
|
||
}));
|
||
$("no-alts").hidden = altList.length > 0;
|
||
const ids = alts.ok ? alts.data.ids : [];
|
||
$("device-ids").replaceChildren(...ids.map(entry => {
|
||
const row = el("tr", undefined, "pick");
|
||
row.title = "Every account that used this id";
|
||
row.append(el("td", KIND_NAMES[entry.kind] || entry.kind), el("td", entry.id, "device-id"), el("td", when(entry.first)), el("td", when(entry.last)),
|
||
el("td", String(entry.others), "num"), el("td", !entry.banned ? "—" : entry.kind === "mac" ? "Banned (alerts only)" : "Banned"));
|
||
row.addEventListener("click", () => searchDevice(entry.id));
|
||
return row;
|
||
}));
|
||
$("no-device-ids").hidden = ids.length > 0;
|
||
const events = timeline.ok ? timeline.data.events : [];
|
||
$("timeline").replaceChildren(...events.map(entry => el("li", [when(entry.at), TIMELINE_NAMES[entry.kind] || entry.kind, entry.text, entry.by && `by ${entry.by}`]
|
||
.filter(Boolean).join(" · "))));
|
||
$("no-timeline").hidden = events.length > 0;
|
||
};
|
||
|
||
const select = username => {
|
||
if (selected === username) {
|
||
selected = null;
|
||
current = null;
|
||
hashArg = "";
|
||
setHash();
|
||
renderAccounts();
|
||
loadOwned();
|
||
loadBanRecord();
|
||
loadExtras();
|
||
return;
|
||
}
|
||
openAccount(username);
|
||
};
|
||
|
||
const GIFT_PLACEHOLDERS = {gems: "Amount", diamonds: "Amount", tickets: "Amount", clothing: "Item id", den: "Item id",
|
||
adopt: "Id, or all", achievement: "Achievement id"};
|
||
$("gift-kind").addEventListener("change", () => {
|
||
$("gift-value").placeholder = GIFT_PLACEHOLDERS[$("gift-kind").value];
|
||
});
|
||
|
||
const giftBody = () => {
|
||
const kind = $("gift-kind").value;
|
||
const value = $("gift-value").value.trim();
|
||
const text = $("gift-text").value;
|
||
if (["gems", "diamonds", "tickets"].includes(kind)) {
|
||
return {kind, text, amount: value === "" ? NaN : Number(value)};
|
||
}
|
||
return {kind, text, id: kind === "adopt" && value.toLowerCase() === "all" ? "all" : Number(value)};
|
||
};
|
||
|
||
const numberFrom = id => ($(id).value.trim() === "" ? NaN : Number($(id).value));
|
||
|
||
const actionBody = action => {
|
||
switch (action) {
|
||
case "rename": return {newName: $("new-name").value};
|
||
case "password": return {password: $("new-password").value};
|
||
case "lastSeen": return {when: Math.floor(new Date($("last-seen").value).getTime() / 1000)};
|
||
case "ban": return {hours: numberFrom("ban-hours"), reason: $("ban-reason").value};
|
||
case "banReason": case "banDevices": return {reason: $("ban-reason").value};
|
||
case "silence": return {hours: numberFrom("silence-hours")};
|
||
case "moderator": return {on: !(current || {}).moderator};
|
||
case "role": return {role: $("role-select").value};
|
||
case "permissions": return permissionChoices();
|
||
case "message": return {text: $("message-text").value};
|
||
case "gems": return {amount: numberFrom("gems-amount")};
|
||
case "gift": return giftBody();
|
||
case "badges": return {badges: [...$("badge-boxes").querySelectorAll("input:checked")].map(box => box.value)};
|
||
case "discord": return {name: $("discord-name").value};
|
||
case "bio": return {text: $("bio-text").value};
|
||
case "level": return {level: numberFrom("quest-level")};
|
||
default: return {};
|
||
}
|
||
};
|
||
|
||
// the "N ago" buttons fill the last-seen box and press Set.
|
||
$("detail").addEventListener("click", event => {
|
||
const quick = event.target.closest("button[data-ago]");
|
||
if (quick) {
|
||
const then = new Date(Date.now() - Number(quick.dataset.ago) * 60000);
|
||
then.setMinutes(then.getMinutes() - then.getTimezoneOffset());
|
||
$("last-seen").value = then.toISOString().slice(0, 16);
|
||
document.querySelector('button[data-action="lastSeen"]').click();
|
||
}
|
||
});
|
||
|
||
$("detail").addEventListener("click", async event => {
|
||
const button = event.target.closest("button[data-action]");
|
||
if (!button || !selected) {
|
||
return;
|
||
}
|
||
const action = button.dataset.action;
|
||
if (action === "delete" && !window.confirm(`Delete ${selected} and everything they own? This cannot be undone.`)) {
|
||
return;
|
||
}
|
||
if (action === "unbanDevices" && !window.confirm(`Lift the hardware bans on ${selected}?`)) {
|
||
return;
|
||
}
|
||
if (action === "banDevices" && !window.confirm(`Hardware ban ${selected}? Everyone on their hardware is put out.`)) {
|
||
return;
|
||
}
|
||
button.disabled = true;
|
||
const result = await api("account", {username: selected, action, ...actionBody(action)});
|
||
button.disabled = false;
|
||
setStatus($("detail-status"), result.data.ok || result.data.error || "That did not work.", !result.ok);
|
||
if (result.ok && action === "delete") {
|
||
selected = null;
|
||
}
|
||
if (result.ok && action === "rename") {
|
||
selected = result.data.username;
|
||
$("new-name").value = "";
|
||
}
|
||
if (result.ok) {
|
||
$("new-password").value = "";
|
||
await refresh();
|
||
fillCard();
|
||
loadOwned();
|
||
loadBanRecord();
|
||
loadExtras();
|
||
}
|
||
});
|
||
|
||
// the server searches, once typing stops for a moment.
|
||
let addressWait = null;
|
||
$("account-search").addEventListener("input", () => {
|
||
clearTimeout(addressWait);
|
||
addressWait = setTimeout($("account-search-by").value !== "name" ? searchByAddress : refresh, $("account-search-by").value !== "name" ? 400 : 250);
|
||
});
|
||
// Enter opens the account of exactly that name, when there is one.
|
||
$("account-search").addEventListener("keydown", async event => {
|
||
if (event.key !== "Enter" || $("account-search-by").value !== "name") {
|
||
return;
|
||
}
|
||
clearTimeout(addressWait);
|
||
await refresh();
|
||
const wanted = $("account-search").value.trim().toLowerCase();
|
||
const exact = accounts.find(account => account.username.toLowerCase() === wanted);
|
||
if (exact && exact.username !== selected) {
|
||
openAccount(exact.username);
|
||
}
|
||
});
|
||
$("account-search-by").addEventListener("change", () => {
|
||
const byAddress = $("account-search-by").value !== "name";
|
||
$("account-search").placeholder = {address: "203.0.113.7, or the start of one", device: "Hardware ID, or the start of one"}[$("account-search-by").value] || "Search";
|
||
if (byAddress) {
|
||
searchByAddress();
|
||
}
|
||
else {
|
||
refresh();
|
||
}
|
||
});
|
||
$("account-filter").addEventListener("change", () => refresh());
|
||
|
||
const act = async (username, action, extra, statusElement) => {
|
||
const result = await api("account", {username, action, ...extra});
|
||
setStatus(statusElement, result.data.ok || result.data.error || "That did not work.", !result.ok);
|
||
return result.ok;
|
||
};
|
||
|
||
// ---- the Chat page: what players typed, sent and posted (lib/chatlog.js).
|
||
let chatQuery = null; // {username, room, text, kind, until}
|
||
let chatLines = [];
|
||
const chatUrl = before => `chat?username=${encodeURIComponent(chatQuery.username)}&room=${encodeURIComponent(chatQuery.room)}`
|
||
+ `&text=${encodeURIComponent(chatQuery.text)}&kind=${chatQuery.kind || ""}&until=${chatQuery.until || 0}&before=${before}`;
|
||
// where a line was said: a room, or who it went to.
|
||
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);
|
||
const lineNode = (line, inContext = false) => {
|
||
const item = el("li", undefined, inContext && line.marked ? "this" : "");
|
||
const who = btn(line.username, () => openAccountTab(line.username), "chat-who");
|
||
const text = el("span", undefined, "chat-text");
|
||
text.append(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(btn("Around", () => showContext(line.id), "chat-more"));
|
||
}
|
||
return item;
|
||
};
|
||
const loadChat = async older => {
|
||
if (!chatQuery) {
|
||
chatQuery = {username: "", room: "", text: "", kind: "", until: 0};
|
||
}
|
||
const before = older && chatLines.length ? chatLines[chatLines.length - 1].id : 0;
|
||
const result = await api(chatUrl(before));
|
||
if (!result.ok) {
|
||
setStatus($("chat-status"), said(result), true);
|
||
return;
|
||
}
|
||
chatLines = older ? [...chatLines, ...result.data.lines] : result.data.lines;
|
||
setStatus($("chat-status"), result.data.days > 0 ? `Kept ${result.data.days} days.` : "Chat is not being kept.");
|
||
$("chat-lines").replaceChildren(...chatLines.map(line => lineNode(line)));
|
||
$("no-chat").hidden = chatLines.length > 0;
|
||
$("chat-older").hidden = !result.data.more;
|
||
};
|
||
const showContext = async id => {
|
||
const result = await api(`chat/around?id=${id}`);
|
||
if (!result.ok) {
|
||
setStatus($("chat-status"), said(result), true);
|
||
return;
|
||
}
|
||
const {line, lines} = result.data;
|
||
$("context-title").textContent = line.kind === "chat" ? line.room : `${line.username} and ${line.to}`;
|
||
$("chat-context").replaceChildren(...lines.map(entry => lineNode({...entry, marked: entry.id === line.id}, true)));
|
||
$("context-box").hidden = false;
|
||
$("context-box").scrollIntoView({block: "nearest"});
|
||
};
|
||
$("context-close").addEventListener("click", () => {
|
||
$("context-box").hidden = true;
|
||
});
|
||
$("chat-form").addEventListener("submit", event => {
|
||
event.preventDefault();
|
||
const until = $("chat-until").value ? Math.floor(new Date($("chat-until").value).getTime() / 1000) : 0;
|
||
chatQuery = {username: $("chat-player").value.trim(), room: $("chat-room").value.trim(), text: $("chat-text").value.trim(), kind: $("chat-kind").value, until};
|
||
$("context-box").hidden = true;
|
||
loadChat(false);
|
||
});
|
||
$("chat-older").addEventListener("click", () => loadChat(true));
|
||
const openChat = (username, kind = "") => {
|
||
$("chat-player").value = username;
|
||
$("chat-room").value = "";
|
||
$("chat-text").value = "";
|
||
$("chat-kind").value = kind;
|
||
$("chat-until").value = "";
|
||
chatQuery = {username, room: "", text: "", kind, until: 0};
|
||
$("context-box").hidden = true;
|
||
hashArg = username;
|
||
showTab("chat");
|
||
};
|
||
|
||
// what the reported player said up to the report, once asked for: report id -> lines.
|
||
const reportChat = new Map();
|
||
let reportsShown = "";
|
||
let lastReports = null;
|
||
|
||
const renderReports = (data, force = false) => {
|
||
const handled = $("report-filter").value === "1";
|
||
$("report-count").textContent = data.open ? String(data.open) : "";
|
||
lastReports = data;
|
||
// drawn again only when the list changed.
|
||
const shown = `${handled} ${data.reports.map(report => report.id).join(",")}`;
|
||
if (shown === reportsShown && !force) {
|
||
return;
|
||
}
|
||
reportsShown = shown;
|
||
$("reports").replaceChildren(...data.reports.map(report => {
|
||
const box = el("div", undefined, "report");
|
||
box.append(el("h3", `${report.target} — ${report.reason}`),
|
||
el("div", `Reported by ${report.reporter} on ${when(report.createdAt)}${report.room ? `, in ${report.room}` : ""}`, "hint"));
|
||
if (report.detail) {
|
||
box.append(el("div", report.detail, "typed"));
|
||
}
|
||
if (report.context) {
|
||
box.append(el("pre", report.context));
|
||
}
|
||
if (reportChat.has(report.id)) {
|
||
const lines = reportChat.get(report.id);
|
||
const list = el("ul", undefined, "chat-list");
|
||
list.append(...lines.map(line => lineNode(line, true)));
|
||
box.append(el("h3", `What ${report.target} said up to the report`), lines.length ? list : el("div", "Nothing kept.", "hint"));
|
||
}
|
||
const chatButton = btn(reportChat.has(report.id) ? "Hide chat" : "Chat at the time", async () => {
|
||
if (reportChat.has(report.id)) {
|
||
reportChat.delete(report.id);
|
||
}
|
||
else {
|
||
const result = await api(`chat?username=${encodeURIComponent(report.target)}&until=${report.createdAt + 60}&before=0`);
|
||
reportChat.set(report.id, result.ok ? result.data.lines.slice(0, 20).reverse() : []);
|
||
}
|
||
renderReports(lastReports, true);
|
||
});
|
||
if (!handled) {
|
||
const buttons = el("div", undefined, "buttons");
|
||
const button = (label, run, className) => {
|
||
const node = el("button", label, className);
|
||
node.type = "button";
|
||
node.addEventListener("click", async () => {
|
||
node.disabled = true;
|
||
await run();
|
||
node.disabled = false;
|
||
refresh();
|
||
});
|
||
return node;
|
||
};
|
||
buttons.append(
|
||
button("Dealt with", async () => {
|
||
const result = await api("report", {id: report.id});
|
||
setStatus($("report-status"), result.data.ok || result.data.error || "That did not work.", !result.ok);
|
||
}, "primary"),
|
||
button("Silence 1 hour", () => act(report.target, "silence", {hours: 1}, $("report-status"))),
|
||
button("Ban 1 day", () => act(report.target, "ban", {hours: 24}, $("report-status")), "danger"),
|
||
chatButton,
|
||
button("Chat history", async () => openChat(report.target)),
|
||
button("Open account", async () => {
|
||
openAccountTab(report.target);
|
||
}));
|
||
box.append(buttons);
|
||
}
|
||
else {
|
||
box.append(el("div", `Dealt with on ${when(report.handledAt)}`, "hint"));
|
||
const buttons = el("div", undefined, "buttons");
|
||
buttons.append(chatButton);
|
||
box.append(buttons);
|
||
}
|
||
return box;
|
||
}));
|
||
$("no-reports").hidden = data.reports.length > 0;
|
||
};
|
||
|
||
$("report-filter").addEventListener("change", () => refresh());
|
||
|
||
const renderSupport = data => {
|
||
const handled = $("support-filter").value === "1";
|
||
$("support-count").textContent = data.open ? String(data.open) : "";
|
||
const button = (label, body, className) => {
|
||
const node = el("button", label, className);
|
||
node.type = "button";
|
||
node.addEventListener("click", async () => {
|
||
node.disabled = true;
|
||
const result = await api("support", body);
|
||
setStatus($("support-status"), result.data.ok || result.data.error || "That did not work.", !result.ok);
|
||
node.disabled = false;
|
||
refresh();
|
||
});
|
||
return node;
|
||
};
|
||
$("name-requests").replaceChildren(...data.names.map(request => {
|
||
const box = el("div", undefined, "report");
|
||
box.append(el("h3", `${request.oldName} → ${request.newName}`), el("div", `Asked on ${when(request.createdAt)}`, "hint"));
|
||
if (request.reason) {
|
||
box.append(el("div", request.reason, "typed"));
|
||
}
|
||
if (handled) {
|
||
box.append(el("div", `${request.status === "approved" ? "Approved" : "Denied"} on ${when(request.handledAt)}`, "hint"));
|
||
}
|
||
else {
|
||
const buttons = el("div", undefined, "buttons");
|
||
buttons.append(button("Approve", {action: "approve", id: request.id}, "primary"), button("Deny", {action: "deny", id: request.id}));
|
||
box.append(buttons);
|
||
}
|
||
return box;
|
||
}));
|
||
$("no-name-requests").hidden = data.names.length > 0;
|
||
$("feedback").replaceChildren(...data.feedback.map(message => {
|
||
const box = el("div", undefined, "report");
|
||
box.append(el("h3", `${message.kind === "bug" ? "Bug report" : "Feedback"} from ${message.username}`),
|
||
el("div", `Sent on ${when(message.createdAt)}`, "hint"), el("pre", message.text));
|
||
if (handled) {
|
||
box.append(el("div", `Read on ${when(message.handledAt)}`, "hint"));
|
||
}
|
||
else {
|
||
const buttons = el("div", undefined, "buttons");
|
||
buttons.append(button("Mark as read", {action: "read", id: message.id}, "primary"));
|
||
box.append(buttons);
|
||
}
|
||
return box;
|
||
}));
|
||
$("no-feedback").hidden = data.feedback.length > 0;
|
||
// typed replies are left alone while one is being written.
|
||
if (!$("appeals").contains(document.activeElement)) {
|
||
$("appeals").replaceChildren(...data.appeals.map(appeal => {
|
||
const box = el("div", undefined, "report");
|
||
box.append(el("h3", appeal.username), el("div", `Sent on ${when(appeal.createdAt)}${appeal.gone ? " · account deleted" : ""}`, "hint"));
|
||
if (appeal.ban) {
|
||
box.append(el("div", `Banned${appeal.ban.seconds === -1 ? " for good" : `, ${duration(appeal.ban.seconds)} left`}${appeal.ban.reason ? ` · ${appeal.ban.reason}` : ""}`, "hint"));
|
||
}
|
||
if (appeal.address) {
|
||
box.append(el("div", `Address ${appeal.address.key} banned${appeal.address.reason ? ` · ${appeal.address.reason}` : ""}`, "hint"));
|
||
}
|
||
box.append(el("div", appeal.text, "typed"));
|
||
if (handled) {
|
||
box.append(el("div", `${appeal.status === "approved" ? "Approved" : "Denied"} on ${when(appeal.handledAt)}${appeal.reply ? ` · ${appeal.reply}` : ""}`, "hint"));
|
||
return box;
|
||
}
|
||
const reply = el("input");
|
||
reply.maxLength = 500;
|
||
reply.placeholder = "Reply (optional)";
|
||
reply.setAttribute("aria-label", `Reply to ${appeal.username}`);
|
||
reply.style.width = "100%";
|
||
const buttons = el("div", undefined, "buttons");
|
||
for (const [label, action, className] of [["Unban", "appealApprove", "primary"], ["Deny", "appealDeny", ""]]) {
|
||
const node = el("button", label, className);
|
||
node.type = "button";
|
||
node.addEventListener("click", async () => {
|
||
node.disabled = true;
|
||
const result = await api("support", {action, id: appeal.accountId, reply: reply.value});
|
||
setStatus($("support-status"), result.data.ok || result.data.error || "That did not work.", !result.ok);
|
||
reply.blur();
|
||
refresh();
|
||
});
|
||
buttons.append(node);
|
||
}
|
||
box.append(reply, buttons);
|
||
return box;
|
||
}));
|
||
}
|
||
$("no-appeals").hidden = data.appeals.length > 0;
|
||
};
|
||
|
||
$("support-filter").addEventListener("change", () => refresh());
|
||
|
||
let paintingsShown = "";
|
||
// the picture full size, over the page; a click puts it away.
|
||
const showPreview = src => {
|
||
$("preview-img").src = src;
|
||
$("preview").hidden = false;
|
||
};
|
||
$("preview").addEventListener("click", () => {
|
||
$("preview").hidden = true;
|
||
});
|
||
document.addEventListener("keydown", event => {
|
||
if (event.key === "Escape") {
|
||
$("preview").hidden = true;
|
||
}
|
||
});
|
||
|
||
const renderMasterpieces = data => {
|
||
const which = $("masterpiece-filter").value;
|
||
const marked = (list, status) => list.map(painting => ({...painting, status}));
|
||
const paintings = which === "all" ? [...marked(data.waiting, "waiting"), ...marked(data.approved, "approved")] : marked(data[which], which);
|
||
$("masterpiece-count").textContent = data.waitingCount ? String(data.waitingCount) : "";
|
||
$("masterpiece-review").checked = data.review;
|
||
$("no-masterpieces").hidden = paintings.length > 0;
|
||
// drawn again only when the list changed, so the pictures do not flicker.
|
||
const shown = `${which} ${paintings.map(painting => `${painting.id}:${painting.likes}:${painting.status}`).join(" ")}`;
|
||
if (shown === paintingsShown) {
|
||
return;
|
||
}
|
||
paintingsShown = shown;
|
||
$("masterpieces").replaceChildren(...paintings.map(painting => {
|
||
const box = el("div", undefined, "painting");
|
||
const picture = el("img");
|
||
picture.src = `/admin/api/masterpiece?id=${encodeURIComponent(painting.id)}`;
|
||
picture.alt = `Painting by ${painting.creator}`;
|
||
picture.loading = "lazy";
|
||
picture.addEventListener("click", () => showPreview(picture.src));
|
||
box.append(picture, el("h3", painting.creator),
|
||
el("div", `${when(painting.createdAt)}${painting.status === "approved" ? `, ${painting.likes} like${painting.likes === 1 ? "" : "s"}` : ""}`
|
||
+ `${which === "all" ? (painting.status === "waiting" ? " · waiting" : " · approved") : ""}`, "hint"));
|
||
const buttons = el("div", undefined, "buttons");
|
||
const button = (label, action, className) => {
|
||
const node = el("button", label, className);
|
||
node.type = "button";
|
||
node.addEventListener("click", async () => {
|
||
node.disabled = true;
|
||
const result = await api("masterpiece", {id: painting.id, action});
|
||
setStatus($("masterpiece-status"), result.data.ok || result.data.error || "That did not work.", !result.ok);
|
||
refresh();
|
||
});
|
||
return node;
|
||
};
|
||
if (painting.status === "waiting") {
|
||
buttons.append(button("Approve", "approve", "primary"), button("Reject", "reject", "danger"));
|
||
}
|
||
else {
|
||
buttons.append(button("Remove", "remove", "danger"));
|
||
}
|
||
const open = el("button", "Open account");
|
||
open.type = "button";
|
||
open.addEventListener("click", () => {
|
||
openAccountTab(painting.creator);
|
||
});
|
||
buttons.append(open);
|
||
box.append(buttons);
|
||
return box;
|
||
}));
|
||
};
|
||
|
||
$("masterpiece-filter").addEventListener("change", () => refresh());
|
||
let creatorWait = null;
|
||
$("masterpiece-creator").addEventListener("input", () => {
|
||
clearTimeout(creatorWait);
|
||
creatorWait = setTimeout(refresh, 250);
|
||
});
|
||
// a player's paintings, waiting and approved.
|
||
const openPaintings = username => {
|
||
$("masterpiece-creator").value = username;
|
||
$("masterpiece-filter").value = "all";
|
||
hashArg = username;
|
||
showTab("masterpieces");
|
||
};
|
||
$("masterpiece-review").addEventListener("change", async () => {
|
||
const result = await api("masterpiece", {action: "review", on: $("masterpiece-review").checked});
|
||
setStatus($("masterpiece-status"), result.data.ok || result.data.error || "That did not work.", !result.ok);
|
||
});
|
||
|
||
// a hardware ban's accounts and ids, each one a link.
|
||
const deviceAccounts = names => {
|
||
const cell = el("td");
|
||
cell.style.whiteSpace = "normal";
|
||
cell.append(...(names.length ? names.flatMap((name, index) => {
|
||
const link = el("button", name, "link");
|
||
link.type = "button";
|
||
link.addEventListener("click", () => openAccountTab(name));
|
||
return index ? [", ", link] : [link];
|
||
}) : ["—"]));
|
||
return cell;
|
||
};
|
||
const openBanIds = new Set();
|
||
const deviceIds = ban => {
|
||
const cell = el("td");
|
||
const shown = openBanIds.has(ban.id);
|
||
const toggle = el("button", shown ? `Hide ${ban.ids.length}` : `Show ${ban.ids.length}`, "link");
|
||
toggle.type = "button";
|
||
toggle.addEventListener("click", () => {
|
||
if (openBanIds.has(ban.id)) {
|
||
openBanIds.delete(ban.id);
|
||
}
|
||
else {
|
||
openBanIds.add(ban.id);
|
||
}
|
||
refresh();
|
||
});
|
||
cell.append(toggle);
|
||
if (shown) {
|
||
for (const entry of ban.ids) {
|
||
const link = el("button", `${KIND_NAMES[entry.kind] || entry.kind} ${entry.id}`, "link device-id");
|
||
link.type = "button";
|
||
link.addEventListener("click", () => searchDevice(entry.id));
|
||
cell.append(el("br"), link);
|
||
}
|
||
}
|
||
return cell;
|
||
};
|
||
|
||
const renderBans = data => {
|
||
const left = seconds => (seconds === -1 ? "Until lifted" : seconds ? `${duration(seconds)} left` : "—");
|
||
$("bans").replaceChildren(...data.accounts.map(account => {
|
||
const row = el("tr");
|
||
const buttons = el("td");
|
||
const button = (label, action) => {
|
||
const node = el("button", label);
|
||
node.type = "button";
|
||
node.addEventListener("click", async () => {
|
||
node.disabled = true;
|
||
await act(account.username, action, {}, $("ban-status"));
|
||
refresh();
|
||
});
|
||
return node;
|
||
};
|
||
if (account.banned !== 0) {
|
||
buttons.append(button("Lift ban", "unban"), " ");
|
||
}
|
||
if (account.silenced !== 0) {
|
||
buttons.append(button("Lift silence", "unsilence"));
|
||
}
|
||
row.append(el("td", account.username), el("td", left(account.banned)), el("td", account.reason || "—"),
|
||
el("td", account.silenced === 0 ? "—" : `Silenced: ${left(account.silenced).toLowerCase()}`), buttons);
|
||
return row;
|
||
}));
|
||
$("no-bans").hidden = data.accounts.length > 0;
|
||
$("addresses").replaceChildren(...data.addresses.map(ban => {
|
||
const row = el("tr");
|
||
const buttons = el("td");
|
||
const node = el("button", "Unban");
|
||
node.type = "button";
|
||
node.addEventListener("click", async () => {
|
||
node.disabled = true;
|
||
const result = await api("address", {action: "unban", address: ban.key});
|
||
setStatus($("address-status"), result.data.ok || result.data.error || "That did not work.", !result.ok);
|
||
refresh();
|
||
});
|
||
buttons.append(node);
|
||
row.append(el("td", ban.key), el("td", ban.reason || "—"), el("td", when(ban.createdAt)), buttons);
|
||
return row;
|
||
}));
|
||
$("no-addresses").hidden = data.addresses.length > 0;
|
||
$("device-bans").replaceChildren(...data.devices.map(ban => {
|
||
const row = el("tr");
|
||
const buttons = el("td");
|
||
buttons.append(btn("Unban", async () => {
|
||
if (!window.confirm(`Lift the hardware ban made with ${ban.username}?`)) {
|
||
return;
|
||
}
|
||
const result = await api("device", {id: ban.id});
|
||
setStatus($("device-status"), said(result), !result.ok);
|
||
refresh();
|
||
}), " ", btn("Open account", async () => openAccountTab(ban.username)));
|
||
row.append(el("td", ban.username || "—"), el("td", ban.reason), el("td", ban.by || "—"), el("td", when(ban.createdAt)),
|
||
deviceAccounts(ban.accounts), deviceIds(ban), buttons);
|
||
return row;
|
||
}));
|
||
$("no-device-bans").hidden = data.devices.length > 0;
|
||
$("device-alerts").replaceChildren(...data.alerts.map(entry => {
|
||
const row = el("tr", undefined, "pick");
|
||
const detail = el("td", entry.detail);
|
||
detail.style.whiteSpace = "normal";
|
||
row.append(el("td", when(entry.at)), el("td", entry.username), el("td", entry.name), detail);
|
||
row.addEventListener("click", () => openAccountTab(entry.username));
|
||
return row;
|
||
}));
|
||
$("no-device-alerts").hidden = data.alerts.length > 0;
|
||
};
|
||
|
||
const renderFilterHits = list => {
|
||
$("filter-hits").replaceChildren(...list.map(entry => {
|
||
const row = el("tr");
|
||
const buttons = el("td");
|
||
buttons.append(btn("Lines", async () => openChat(entry.username, "notsent")), " ", btn("Open account", async () => openAccountTab(entry.username)));
|
||
row.append(el("td", entry.username), el("td", String(entry.count), "num"), el("td", when(entry.last)), buttons);
|
||
return row;
|
||
}));
|
||
$("no-filter-hits").hidden = list.length > 0;
|
||
};
|
||
|
||
$("address-form").addEventListener("submit", async event => {
|
||
event.preventDefault();
|
||
const result = await api("address", {action: "ban", address: $("address").value, reason: $("address-reason").value});
|
||
setStatus($("address-status"), result.data.ok || result.data.error || "That did not work.", !result.ok);
|
||
if (result.ok) {
|
||
event.target.reset();
|
||
}
|
||
refresh();
|
||
});
|
||
|
||
let messagesLoaded = false;
|
||
const renderMessages = data => {
|
||
if (!messagesLoaded) {
|
||
// only once: refreshing must not wipe what is being typed.
|
||
$("motd-text").value = data.motd;
|
||
messagesLoaded = true;
|
||
}
|
||
const chosen = $("announce-room").value;
|
||
const everyone = el("option", "Everyone playing");
|
||
everyone.value = "";
|
||
$("announce-room").replaceChildren(everyone, ...data.rooms.map(room => {
|
||
const option = el("option", `${room.title} (${room.players})`);
|
||
option.value = room.name;
|
||
return option;
|
||
}));
|
||
$("announce-room").value = [...$("announce-room").options].some(option => option.value === chosen) ? chosen : "";
|
||
};
|
||
|
||
$("motd-save").addEventListener("click", async () => {
|
||
const result = await api("motd", {text: $("motd-text").value});
|
||
setStatus($("motd-status"), result.data.ok || result.data.error || "That did not work.", !result.ok);
|
||
});
|
||
|
||
$("announce-send").addEventListener("click", async () => {
|
||
const result = await api("announce", {text: $("announce-text").value, room: $("announce-room").value});
|
||
setStatus($("announce-status"), result.data.ok || result.data.error || "That did not work.", !result.ok);
|
||
if (result.ok) {
|
||
$("announce-text").value = "";
|
||
}
|
||
});
|
||
|
||
let debugRooms = [];
|
||
const renderDebugRooms = () => {
|
||
const wanted = $("debug-room-filter").value.trim().toLowerCase();
|
||
const notedOnly = $("debug-noted").checked;
|
||
const chosen = $("debug-room").value;
|
||
$("debug-room").replaceChildren(...debugRooms
|
||
.filter(room => (!notedOnly || room.note) && (!wanted || `${room.path} ${room.note}`.toLowerCase().includes(wanted)))
|
||
.map(room => {
|
||
const option = el("option", room.note ? `${room.path} (${room.note})` : room.path);
|
||
option.value = room.path;
|
||
return option;
|
||
}));
|
||
$("debug-room").value = chosen;
|
||
};
|
||
const renderDebug = data => {
|
||
const player = $("debug-player").value;
|
||
$("debug-player").replaceChildren(...(data.players.length ? data.players : [""]).map(name => {
|
||
const option = el("option", name || "Nobody is online");
|
||
option.value = name;
|
||
return option;
|
||
}));
|
||
if (data.players.includes(player)) {
|
||
$("debug-player").value = player;
|
||
}
|
||
$("debug-onsale").checked = data.everythingOnSale;
|
||
if (debugRooms.length !== data.rooms.length) {
|
||
debugRooms = data.rooms;
|
||
renderDebugRooms();
|
||
}
|
||
};
|
||
$("debug-room-filter").addEventListener("input", renderDebugRooms);
|
||
$("debug-noted").addEventListener("change", renderDebugRooms);
|
||
$("debug-go").addEventListener("click", async () => {
|
||
const result = await api("debug", {action: "teleport", username: $("debug-player").value, room: $("debug-room").value});
|
||
setStatus($("debug-status"), result.data.ok || result.data.error || "That did not work.", !result.ok);
|
||
});
|
||
$("debug-room").addEventListener("dblclick", () => $("debug-go").click());
|
||
$("debug-onsale").addEventListener("change", async () => {
|
||
const result = await api("debug", {action: "everythingOnSale", on: $("debug-onsale").checked});
|
||
setStatus($("debug-sale-status"), result.data.ok || result.data.error || "That did not work.", !result.ok);
|
||
});
|
||
|
||
const appendLog = lines => {
|
||
const log = $("log");
|
||
for (const line of lines) {
|
||
const row = el("div", undefined, /\[client-error\]|failed|error/i.test(line.text) ? "error" : "");
|
||
row.append(el("span", `${new Date(line.time).toLocaleTimeString()} `, "time"), line.text);
|
||
log.append(row);
|
||
lastLogId = Math.max(lastLogId, line.id);
|
||
}
|
||
while (log.childElementCount > MAX_LOG_LINES) {
|
||
log.firstElementChild.remove();
|
||
}
|
||
if (lines.length && $("log-follow").checked) {
|
||
log.scrollTop = log.scrollHeight;
|
||
}
|
||
};
|
||
|
||
const reloadLog = () => {
|
||
lastLogId = 0;
|
||
$("log").replaceChildren();
|
||
refresh();
|
||
};
|
||
|
||
let filterDelay = null;
|
||
$("log-filter").addEventListener("input", () => {
|
||
clearTimeout(filterDelay);
|
||
filterDelay = setTimeout(reloadLog, 250);
|
||
});
|
||
$("log-preset").addEventListener("change", () => {
|
||
$("log-filter").value = $("log-preset").value;
|
||
reloadLog();
|
||
});
|
||
|
||
$("password-form").addEventListener("submit", async event => {
|
||
event.preventDefault();
|
||
if ($("next-password").value !== $("next-confirm").value) {
|
||
setStatus($("password-status"), "The two new passwords are different.", true);
|
||
return;
|
||
}
|
||
const result = await api("password", {current: $("current-password").value, password: $("next-password").value});
|
||
setStatus($("password-status"), result.ok ? "Password changed." : result.data.error || "That did not work.", !result.ok);
|
||
if (result.ok) {
|
||
event.target.reset();
|
||
}
|
||
});
|
||
|
||
// (as the moderator panel's: public/mod.html)
|
||
const button = (label, onClick, className) => {
|
||
const node = el("button", label, className);
|
||
node.type = "button";
|
||
node.addEventListener("click", async () => {
|
||
node.disabled = true;
|
||
await onClick();
|
||
node.disabled = false;
|
||
});
|
||
return node;
|
||
};
|
||
|
||
// 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 makerSwitchesShown = false;
|
||
$("maker-save").addEventListener("click", async () => {
|
||
const result = await api("item-switches", {enabled: $("maker-on").checked, approval: $("maker-approval").checked, artApproval: $("maker-art-approval").checked});
|
||
setStatus($("maker-status"), said(result), !result.ok);
|
||
makerSwitchesShown = false;
|
||
await refresh();
|
||
});
|
||
|
||
// ---- custom items: the same page as the moderator panel's Items, for
|
||
// the admin (lib/panel.js passes it to the same routes)
|
||
// ---- items (lib/customitems.js)
|
||
let items = [];
|
||
let editing = null; // the item the form is changing, or null to make one
|
||
let baseColours = []; // the colours of the item looked up
|
||
|
||
const showColours = (colours, chosen) => {
|
||
$("item-colours").replaceChildren(...colours.map((colour, index) => {
|
||
const box = el("input");
|
||
box.type = "checkbox";
|
||
box.value = String(colour);
|
||
box.checked = !chosen || chosen.includes(colour);
|
||
const label = el("label", undefined, "check");
|
||
label.append(box, ` Colour ${index + 1}`);
|
||
return label;
|
||
}));
|
||
};
|
||
|
||
const lookUp = async () => {
|
||
const result = await api(`items/base?kind=${$("item-kind").value}&id=${encodeURIComponent($("item-base").value.trim())}`);
|
||
baseColours = result.ok && result.data.colors ? result.data.colors : [];
|
||
if (!result.ok) {
|
||
$("item-base-name").textContent = said(result);
|
||
showColours([]);
|
||
return null;
|
||
}
|
||
if (!editing) {
|
||
$("item-base-name").textContent = `${result.data.name || "(no name)"}: ${result.data.cost} gems in the game.`;
|
||
if (!$("item-name").value.trim()) {
|
||
$("item-name").value = result.data.name || "";
|
||
}
|
||
showColours(baseColours);
|
||
}
|
||
return result.data;
|
||
};
|
||
$("item-look").addEventListener("click", lookUp);
|
||
$("item-kind").addEventListener("change", () => {
|
||
$("item-base-name").textContent = "";
|
||
showColours([]);
|
||
});
|
||
|
||
const itemForm = item => {
|
||
editing = item;
|
||
$("item-form-title").textContent = item ? `Change ${item.name}` : "Make an item";
|
||
$("item-save").textContent = item ? "Save" : "Make it";
|
||
$("item-cancel").hidden = !item;
|
||
for (const field of ["item-kind", "item-base", "item-look"]) {
|
||
$(field).disabled = Boolean(item);
|
||
}
|
||
if (item) {
|
||
$("item-kind").value = item.kind;
|
||
}
|
||
$("item-base").value = item ? item.base : "";
|
||
$("item-name").value = item ? item.name : "";
|
||
$("item-cost").value = item ? item.cost : "";
|
||
$("item-members").checked = Boolean(item && item.members);
|
||
$("item-base-name").textContent = item ? `${item.baseName} (${item.kind === "den" ? "den item" : "clothing"} ${item.base})` : "";
|
||
showColours([]);
|
||
if (item && item.kind === "clothing") {
|
||
// the base's colours, and any of the item's own that are not among them
|
||
lookUp().then(() => showColours([...new Set([...baseColours, ...item.colors])], item.colors));
|
||
}
|
||
};
|
||
$("item-cancel").addEventListener("click", () => itemForm(null));
|
||
|
||
$("item-save").addEventListener("click", async () => {
|
||
const fields = {name: $("item-name").value, cost: $("item-cost").value, members: $("item-members").checked};
|
||
const boxes = [...$("item-colours").querySelectorAll("input")];
|
||
if (boxes.length) {
|
||
fields.colors = boxes.filter(box => box.checked).map(box => Number(box.value));
|
||
if (!fields.colors.length) {
|
||
setStatus($("item-status"), "Leave at least one colour.", true);
|
||
return;
|
||
}
|
||
}
|
||
$("item-save").disabled = true;
|
||
const result = await api("items", editing
|
||
? {action: "update", kind: editing.kind, id: editing.id, ...fields}
|
||
: {action: "create", kind: $("item-kind").value, base: $("item-base").value.trim(), ...fields});
|
||
$("item-save").disabled = false;
|
||
setStatus($("item-status"), said(result), !result.ok);
|
||
if (result.ok) {
|
||
itemForm(null);
|
||
refresh();
|
||
}
|
||
});
|
||
|
||
const renderItems = () => {
|
||
$("items").replaceChildren(...items.map(item => {
|
||
const row = el("tr");
|
||
const buttons = el("td");
|
||
buttons.append(button("Change", () => itemForm(item)), " ",
|
||
button(item.inShop ? "Take off sale" : "Put on sale", async () => {
|
||
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();
|
||
}));
|
||
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;
|
||
}));
|
||
$("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(`/admin/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 overview'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);
|
||
});
|
||
|
||
const refresh = async () => {
|
||
clearTimeout(timer);
|
||
if (!state || !state.signedIn) {
|
||
return;
|
||
}
|
||
// what waits, on the tabs and in the page's title (for when it is in
|
||
// another tab).
|
||
const counts = await api("counts");
|
||
if (counts.ok) {
|
||
$("report-count").textContent = counts.data.reports ? ` (${counts.data.reports})` : "";
|
||
$("support-count").textContent = counts.data.support ? ` (${counts.data.support})` : "";
|
||
$("masterpiece-count").textContent = counts.data.masterpieces ? ` (${counts.data.masterpieces})` : "";
|
||
const waiting = counts.data.reports + counts.data.support + counts.data.masterpieces;
|
||
document.title = waiting ? `(${waiting}) Server admin` : "Server admin";
|
||
}
|
||
// out of sight, only that; the rest when it is back.
|
||
if (document.hidden) {
|
||
timer = setTimeout(refresh, REFRESH_MS);
|
||
return;
|
||
}
|
||
let result = null;
|
||
if (tab === "overview") {
|
||
result = await api("overview");
|
||
if (result.ok) {
|
||
renderOverview(result.data);
|
||
}
|
||
if (!$("quick-lock-q").value.trim()) {
|
||
quickLockFind();
|
||
}
|
||
}
|
||
else if (tab === "accounts") {
|
||
const query = $("account-search-by").value !== "name" ? "" : $("account-search").value.trim();
|
||
result = await api(`accounts?q=${encodeURIComponent(query)}&filter=${$("account-filter").value}`);
|
||
if (result.ok) {
|
||
accounts = result.data.accounts;
|
||
accountTotal = result.data.total;
|
||
badges = result.data.badges || [];
|
||
await loadCurrent();
|
||
renderAccounts();
|
||
}
|
||
}
|
||
else if (tab === "stats") {
|
||
await window.statsView.load(api);
|
||
}
|
||
else if (tab === "reports") {
|
||
result = await api(`reports?handled=${$("report-filter").value}`);
|
||
if (result.ok) {
|
||
renderReports(result.data);
|
||
}
|
||
}
|
||
else if (tab === "support") {
|
||
result = await api(`support?handled=${$("support-filter").value}`);
|
||
if (result.ok) {
|
||
renderSupport(result.data);
|
||
}
|
||
}
|
||
else if (tab === "items") {
|
||
result = await api("items");
|
||
if (result.ok) {
|
||
items = result.data.items;
|
||
lockedItems = result.data.locked;
|
||
renderItems();
|
||
renderLocked();
|
||
}
|
||
const review = await api("review");
|
||
if (review.ok) {
|
||
renderReview(review.data);
|
||
// set from the server once a visit (not over boxes being changed)
|
||
if (!makerSwitchesShown) {
|
||
$("maker-on").checked = review.data.enabled;
|
||
$("maker-approval").checked = review.data.approval;
|
||
$("maker-art-approval").checked = review.data.artApproval;
|
||
makerSwitchesShown = true;
|
||
}
|
||
}
|
||
}
|
||
else if (tab === "masterpieces") {
|
||
result = await api(`masterpieces?creator=${encodeURIComponent($("masterpiece-creator").value.trim())}`);
|
||
if (result.ok) {
|
||
renderMasterpieces(result.data);
|
||
}
|
||
}
|
||
else if (tab === "moderators") {
|
||
// built once a visit, and again on a save: the page's refresh must
|
||
// not undo boxes ticked and not yet saved.
|
||
if (!$("role-matrix").children.length && await loadRoles()) {
|
||
renderRoleMatrix();
|
||
}
|
||
result = await api("moderators");
|
||
if (result.ok) {
|
||
$("moderators").replaceChildren(...result.data.moderators.map(mod => {
|
||
const row = el("tr");
|
||
const open = el("button", "Open account");
|
||
open.type = "button";
|
||
open.addEventListener("click", () => {
|
||
openAccountTab(mod.username);
|
||
});
|
||
const cell = el("td");
|
||
cell.append(open);
|
||
row.append(el("td", mod.username), el("td", mod.twoStep ? "On" : "Off: cannot sign in"), el("td", when(mod.lastSeen)), cell);
|
||
return row;
|
||
}));
|
||
$("no-moderators").hidden = result.data.moderators.length > 0;
|
||
$("mod-log").replaceChildren(...result.data.log.map(entry => {
|
||
const row = el("tr");
|
||
const detail = el("td", entry.detail);
|
||
detail.style.whiteSpace = "normal";
|
||
row.append(el("td", when(entry.at)), el("td", entry.by), el("td", entry.action), el("td", entry.target || "—"), detail);
|
||
return row;
|
||
}));
|
||
$("no-mod-log").hidden = result.data.log.length > 0;
|
||
}
|
||
}
|
||
else if (tab === "bans") {
|
||
const hits = api("filterhits");
|
||
result = await api("bans");
|
||
if (result.ok) {
|
||
renderBans(result.data);
|
||
}
|
||
const hitsResult = await hits;
|
||
if (hitsResult.ok) {
|
||
renderFilterHits(hitsResult.data.players);
|
||
}
|
||
}
|
||
else if (tab === "chat") {
|
||
// only the first page keeps itself up to date: older pages stay as they were read.
|
||
if (!chatQuery || chatLines.length <= 100) {
|
||
await loadChat(false);
|
||
result = {ok: true};
|
||
}
|
||
}
|
||
else if (tab === "messages") {
|
||
result = await api("messages");
|
||
if (result.ok) {
|
||
renderMessages(result.data);
|
||
}
|
||
}
|
||
else if (tab === "debug") {
|
||
result = await api("debug");
|
||
if (result.ok) {
|
||
renderDebug(result.data);
|
||
}
|
||
}
|
||
else if (tab === "logs") {
|
||
result = await api(`logs?after=${lastLogId}&filter=${encodeURIComponent($("log-filter").value)}`);
|
||
if (result.ok) {
|
||
appendLog(result.data.lines);
|
||
}
|
||
}
|
||
if (result && result.ok) {
|
||
$("updated").textContent = `Updated ${new Date().toLocaleTimeString()}`;
|
||
}
|
||
if (state.signedIn && tab !== "settings") {
|
||
timer = setTimeout(refresh, tab === "logs" ? LOG_REFRESH_MS : REFRESH_MS);
|
||
}
|
||
};
|
||
|
||
// the page's address follows what is shown ("#accounts/John",
|
||
// "#chat/John"), for links to paste, and for Back.
|
||
let hashArg = "";
|
||
let applyingHash = false;
|
||
const setHash = () => {
|
||
const wanted = `#${tab}${hashArg ? `/${encodeURIComponent(hashArg)}` : ""}`;
|
||
if (location.hash !== wanted) {
|
||
history[applyingHash ? "replaceState" : "pushState"](null, "", wanted);
|
||
}
|
||
};
|
||
const applyHash = () => {
|
||
const [name, arg] = location.hash.slice(1).split("/");
|
||
if (![...document.querySelectorAll("nav button")].some(button => button.dataset.tab === name)) {
|
||
return false;
|
||
}
|
||
const value = arg ? decodeURIComponent(arg) : "";
|
||
applyingHash = true;
|
||
if (name === "accounts" && value) {
|
||
openAccountTab(value);
|
||
}
|
||
else if (name === "chat" && value) {
|
||
openChat(value);
|
||
}
|
||
else if (name === "masterpieces" && value) {
|
||
openPaintings(value);
|
||
}
|
||
else {
|
||
hashArg = "";
|
||
showTab(name);
|
||
}
|
||
applyingHash = false;
|
||
return true;
|
||
};
|
||
window.addEventListener("popstate", () => {
|
||
if (state && state.signedIn) {
|
||
applyHash();
|
||
}
|
||
});
|
||
|
||
const showTab = name => {
|
||
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() : "";
|
||
tab = name;
|
||
setHash();
|
||
for (const button of document.querySelectorAll("nav button")) {
|
||
button.setAttribute("aria-selected", String(button.dataset.tab === name));
|
||
}
|
||
for (const view of document.querySelectorAll("[data-view]")) {
|
||
view.hidden = view.dataset.view !== name;
|
||
}
|
||
refresh();
|
||
};
|
||
|
||
for (const button of document.querySelectorAll("nav button")) {
|
||
button.addEventListener("click", () => {
|
||
hashArg = "";
|
||
showTab(button.dataset.tab);
|
||
});
|
||
}
|
||
document.addEventListener("visibilitychange", () => {
|
||
if (!document.hidden) {
|
||
refresh();
|
||
}
|
||
});
|
||
|
||
const showPanel = () => {
|
||
$("gate").hidden = true;
|
||
$("panel").hidden = false;
|
||
if (!applyHash()) {
|
||
showTab(tab);
|
||
}
|
||
};
|
||
|
||
const start = async () => {
|
||
try {
|
||
state = (await api("state")).data;
|
||
}
|
||
catch (err) {
|
||
state = {needsSetup: false, needsSetupCode: false, signedIn: false};
|
||
showGate("The server did not answer.");
|
||
return;
|
||
}
|
||
if (state.signedIn) {
|
||
showPanel();
|
||
}
|
||
else {
|
||
showGate();
|
||
}
|
||
};
|
||
|
||
start();
|
||
</script>
|
||
</body>
|
||
</html>
|