mirror of
https://github.com/burrow-dev/burrow-server.git
synced 2026-11-18 17:27:50 -05:00
Compare commits
2
Commits
08780d7e69
...
9f69b3511b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9f69b3511b | ||
|
|
8e7b193621 |
No files matched your search
+16
-1
@@ -803,7 +803,10 @@ const storableUsernameProblem = username => {
|
||||
};
|
||||
|
||||
// gives the account a new username, and carries it into everyone's buddy and
|
||||
// block lists. returns "invalid_username" or "username_taken", else null.
|
||||
// block lists. The staff dashboard stores a few human-readable names beside
|
||||
// account ids; keep those labels current too, so a rename does not split a
|
||||
// player's history across two names. Returns "invalid_username" or
|
||||
// "username_taken", else null.
|
||||
// the player must not be online: the game knows them by the old name.
|
||||
// with `anyName` (the admin panel) the sign-up rules about length and
|
||||
// characters do not apply; see storableUsernameProblem.
|
||||
@@ -825,6 +828,18 @@ const rename = (account, username, anyName = false) => {
|
||||
}
|
||||
db.prepare("UPDATE accounts SET username = ?, username_key = ? WHERE id = ?").run(username, newKey, account.id);
|
||||
console.log(`[accounts] renamed "${logText(account.username)}" to "${logText(username)}" (id ${logText(account.id)})`);
|
||||
for (const [table, column] of [
|
||||
["reports", "reporter"], ["reports", "target"], ["feedback", "username"],
|
||||
["chat_log", "username"], ["chat_log", "to_name"], ["appeals", "username"],
|
||||
["ban_log", "username"], ["mod_log", "by"], ["mod_log", "target"],
|
||||
]) {
|
||||
// A few lean unit tests load the account store without every dashboard
|
||||
// module. The tables are present in the actual server, but keep rename
|
||||
// usable in that smaller setup too.
|
||||
if (db.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = ?").get(table)) {
|
||||
db.prepare(`UPDATE ${table} SET ${column} = ? WHERE ${column} = ? COLLATE NOCASE`).run(username, account.username);
|
||||
}
|
||||
}
|
||||
byKey.delete(oldKey);
|
||||
account.username = username;
|
||||
byKey.set(newKey, account);
|
||||
|
||||
@@ -138,6 +138,11 @@ const LANG_ENG = 0;
|
||||
const IDLE_ANIM_LAND = 14;
|
||||
const IDLE_ANIM_OCEAN = 29;
|
||||
const MAX_PATH_POINTS = 12;
|
||||
// Action messages are client-side animation names (":dance:", ":sitNW:",
|
||||
// etc.). Keep the currently playing one only while the avatar is standing
|
||||
// still, so someone who enters the room can see it once their client has
|
||||
// created that avatar.
|
||||
const ACTION_NAME = /^:[A-Za-z][A-Za-z0-9]*:$/;
|
||||
const TYPED_NAME = /^[A-Za-z0-9][A-Za-z0-9 '.-]{0,19}$/; // an animal's or pet's name typed by its owner
|
||||
const MAX_BLOCKED = 1000; // from the account page; the game's own button has no limit
|
||||
const TYPED_CHAT_TYPES = ["0", "9"];
|
||||
@@ -467,6 +472,12 @@ const sendAvatarCreate = (to, target) => {
|
||||
if (target.petPlayerMode) {
|
||||
to.sendXt("uc", room.id, target.id, "on", "13");
|
||||
}
|
||||
// `ac` only creates the avatar. Actions normally travel as live `uc`
|
||||
// type-3 packets, so replay a standing player's current action after `ac`
|
||||
// for a player who has just entered (or reloaded) the room.
|
||||
if (target.activeAction) {
|
||||
to.sendXt("uc", room.id, target.id, target.activeAction.name, "3", target.activeAction.extra);
|
||||
}
|
||||
minigames.showBubble(to, target);
|
||||
};
|
||||
|
||||
@@ -671,6 +682,9 @@ const handlers = {
|
||||
const teleport = params[params.length - 1] === "1" ? 1 : 0;
|
||||
const firstUpdate = !session.pos;
|
||||
session.pos = {x: coords[coords.length - 2], y: coords[coords.length - 1]};
|
||||
// Walking, swimming, or a teleport replaces a looping action on every
|
||||
// client. Do not replay it to somebody entering later.
|
||||
delete session.activeAction;
|
||||
if (!session.greeted) {
|
||||
// the first room has loaded: the client can show a popup now.
|
||||
session.greeted = true;
|
||||
@@ -1302,6 +1316,7 @@ const leaveRoom = session => {
|
||||
room.sessions.delete(session);
|
||||
session.room = null;
|
||||
session.pos = null;
|
||||
delete session.activeAction;
|
||||
minigames.roomLeft(session);
|
||||
for (const other of room.sessions) {
|
||||
// AvatarManager.avatarRemoveResponse
|
||||
@@ -1768,6 +1783,16 @@ module.exports = {
|
||||
}
|
||||
return;
|
||||
}
|
||||
// Type 3 is the action packet. It used to be sent only to people
|
||||
// already in the room, leaving late arrivals with an idle avatar
|
||||
// until the player performed the action again. Save the safe action
|
||||
// name and its mirror marker for the next avatar-create packet.
|
||||
if (fields[1] === "3") {
|
||||
if (!ACTION_NAME.test(fields[0])) {
|
||||
return;
|
||||
}
|
||||
session.activeAction = {name: fields[0], extra: fields[2] || ""};
|
||||
}
|
||||
// Attachment messages carry an emoticon *definition* id from the
|
||||
// sender, while the recipient's avatar view needs that definition's
|
||||
// media id. This is the normal path used by den attachments and
|
||||
|
||||
+41
-9
@@ -215,9 +215,25 @@
|
||||
.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; }
|
||||
#side { position: static; height: auto; gap: 12px; padding: 12px; }
|
||||
nav { flex-direction: row; flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden; padding-bottom: 2px; scrollbar-width: thin; }
|
||||
nav button { flex: 0 0 auto; width: auto; }
|
||||
#main { padding: 16px 12px 32px; }
|
||||
section { padding: 15px; border-radius: 14px; }
|
||||
.page-title { align-items: flex-start; flex-direction: column; gap: 3px; margin-bottom: 14px; }
|
||||
.columns, .actions { grid-template-columns: minmax(0, 1fr); }
|
||||
.toolbar input[type="search"] { flex-basis: 100%; min-width: 0; width: 100%; }
|
||||
.table-wrap { max-width: 100%; }
|
||||
}
|
||||
@media (max-width: 520px) {
|
||||
body { font-size: 14px; overflow-x: hidden; }
|
||||
.brand { padding: 0; }
|
||||
.tiles, .paintings { grid-template-columns: minmax(0, 1fr); }
|
||||
.tile { padding: 14px; }
|
||||
.tile .value { font-size: 26px; }
|
||||
dl { grid-template-columns: 1fr; gap: 2px; }
|
||||
dd { margin-bottom: 9px; }
|
||||
.preview { padding: 8px; }
|
||||
}
|
||||
|
||||
section { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 20px; margin-bottom: 18px; box-shadow: var(--shadow); }
|
||||
@@ -1002,6 +1018,8 @@
|
||||
let tab = "overview";
|
||||
let lastLogId = 0;
|
||||
let timer = null;
|
||||
// Older responses must never overwrite a newer account search.
|
||||
let accountSearchRun = 0;
|
||||
|
||||
const api = async (path, body) => {
|
||||
const response = await fetch(`/dashboard/api/admin/${path}`, body === undefined ? {} : {
|
||||
@@ -1735,6 +1753,7 @@
|
||||
// the server searches, once typing stops for a moment.
|
||||
let addressWait = null;
|
||||
$("account-search").addEventListener("input", () => {
|
||||
accountSearchRun++;
|
||||
clearTimeout(addressWait);
|
||||
addressWait = setTimeout($("account-search-by").value !== "name" ? searchByAddress : refresh, $("account-search-by").value !== "name" ? 400 : 250);
|
||||
});
|
||||
@@ -1752,6 +1771,7 @@
|
||||
}
|
||||
});
|
||||
$("account-search-by").addEventListener("change", () => {
|
||||
accountSearchRun++;
|
||||
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) {
|
||||
@@ -1761,7 +1781,10 @@
|
||||
refresh();
|
||||
}
|
||||
});
|
||||
$("account-filter").addEventListener("change", () => refresh());
|
||||
$("account-filter").addEventListener("change", () => {
|
||||
accountSearchRun++;
|
||||
refresh();
|
||||
});
|
||||
|
||||
const act = async (username, action, extra, statusElement) => {
|
||||
const result = await api("account", {username, action, ...extra});
|
||||
@@ -2041,7 +2064,7 @@
|
||||
$("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.src = `/dashboard/api/admin/masterpiece?id=${encodeURIComponent(painting.id)}`;
|
||||
picture.alt = `Painting by ${painting.creator}`;
|
||||
picture.loading = "lazy";
|
||||
picture.addEventListener("click", () => showPreview(picture.src));
|
||||
@@ -2861,14 +2884,23 @@
|
||||
}
|
||||
}
|
||||
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) {
|
||||
const searchBy = $("account-search-by").value;
|
||||
const query = searchBy !== "name" ? "" : $("account-search").value.trim();
|
||||
const filter = $("account-filter").value;
|
||||
const searchRun = ++accountSearchRun;
|
||||
result = await api(`accounts?q=${encodeURIComponent(query)}&filter=${filter}`);
|
||||
// A slower earlier search must not replace what the person just typed.
|
||||
if (result.ok && searchRun === accountSearchRun && tab === "accounts"
|
||||
&& searchBy === $("account-search-by").value
|
||||
&& query === (searchBy !== "name" ? "" : $("account-search").value.trim())
|
||||
&& filter === $("account-filter").value) {
|
||||
accounts = result.data.accounts;
|
||||
accountTotal = result.data.total;
|
||||
badges = result.data.badges || [];
|
||||
await loadCurrent();
|
||||
renderAccounts();
|
||||
if (searchRun === accountSearchRun && tab === "accounts") {
|
||||
renderAccounts();
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (tab === "stats") {
|
||||
|
||||
+37
-4
@@ -216,9 +216,25 @@
|
||||
.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; }
|
||||
#side { position: static; height: auto; gap: 12px; padding: 12px; }
|
||||
nav { flex-direction: row; flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden; padding-bottom: 2px; scrollbar-width: thin; }
|
||||
nav button { flex: 0 0 auto; width: auto; }
|
||||
#main { padding: 16px 12px 32px; }
|
||||
section { padding: 15px; border-radius: 14px; }
|
||||
.page-title { align-items: flex-start; flex-direction: column; gap: 3px; margin-bottom: 14px; }
|
||||
.columns, .actions { grid-template-columns: minmax(0, 1fr); }
|
||||
.toolbar input[type="search"] { flex-basis: 100%; min-width: 0; width: 100%; }
|
||||
.table-wrap { max-width: 100%; }
|
||||
}
|
||||
@media (max-width: 520px) {
|
||||
body { font-size: 14px; overflow-x: hidden; }
|
||||
.brand { padding: 0; }
|
||||
.tiles, .paintings { grid-template-columns: minmax(0, 1fr); }
|
||||
.tile { padding: 14px; }
|
||||
.tile .value { font-size: 26px; }
|
||||
dl { grid-template-columns: 1fr; gap: 2px; }
|
||||
dd { margin-bottom: 9px; }
|
||||
.preview { padding: 8px; }
|
||||
}
|
||||
|
||||
section { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 20px; margin-bottom: 18px; box-shadow: var(--shadow); }
|
||||
@@ -1020,6 +1036,8 @@
|
||||
let tab = "home";
|
||||
let selected = null; // the username of the player whose box is open
|
||||
let players = [];
|
||||
// Older responses must never overwrite a newer player search.
|
||||
let playerSearchRun = 0;
|
||||
let chatQuery = null; // what the Chat page shows: {username, room, text}
|
||||
let chatLines = [];
|
||||
let timer = null;
|
||||
@@ -1560,6 +1578,7 @@
|
||||
$("player-only").addEventListener("click", event => {
|
||||
const chip = event.target.closest("button[data-only]");
|
||||
if (chip) {
|
||||
playerSearchRun++;
|
||||
setListOnly(chip.dataset.only);
|
||||
refresh();
|
||||
}
|
||||
@@ -1567,6 +1586,7 @@
|
||||
|
||||
// from another page: that player's box, whether or not the search shows them.
|
||||
const openPlayer = username => {
|
||||
playerSearchRun++;
|
||||
$("player-search").value = username;
|
||||
$("player-search-by").value = "name";
|
||||
$("player-search").placeholder = "Search";
|
||||
@@ -1582,6 +1602,7 @@
|
||||
|
||||
// every account that used a hardware ID: the player list, searched by it.
|
||||
const searchDevice = id => {
|
||||
playerSearchRun++;
|
||||
$("player-search-by").value = "device";
|
||||
$("player-search").placeholder = "Hardware ID, or the start of one";
|
||||
$("player-search").value = id;
|
||||
@@ -1664,6 +1685,7 @@
|
||||
// by address, asked once typing stops: each search is written down.
|
||||
let searchWait = null;
|
||||
$("player-search").addEventListener("input", () => {
|
||||
playerSearchRun++;
|
||||
clearTimeout(searchWait);
|
||||
searchWait = setTimeout(refresh, $("player-search-by").value === "name" ? 250 : 700);
|
||||
});
|
||||
@@ -1687,6 +1709,7 @@
|
||||
}
|
||||
});
|
||||
$("player-search-by").addEventListener("change", () => {
|
||||
playerSearchRun++;
|
||||
$("player-search").placeholder = {address: "203.0.113.7, or the start of one", device: "Hardware ID, or the start of one"}[$("player-search-by").value] || "Search";
|
||||
refresh();
|
||||
});
|
||||
@@ -1966,7 +1989,7 @@
|
||||
let recentList = [];
|
||||
let paintingsShown = "";
|
||||
let recentShown = "";
|
||||
const paintingSrc = painting => `/mod/api/masterpiece?id=${encodeURIComponent(painting.id)}`;
|
||||
const paintingSrc = painting => `/dashboard/api/staff/masterpiece?id=${encodeURIComponent(painting.id)}`;
|
||||
const paintingWords = painting => (painting.status === "waiting" ? `Waiting · painted ${ago(painting.createdAt)}`
|
||||
: `Approved${painting.approvedAt ? ` ${ago(painting.approvedAt)}` : ""}${painting.approvedBy ? ` by ${painting.approvedBy === myName ? "you" : painting.approvedBy}` : ""}`
|
||||
+ `${painting.likes ? ` · ${painting.likes} ${painting.likes === 1 ? "like" : "likes"}` : ""}`);
|
||||
@@ -2766,9 +2789,13 @@
|
||||
const searchBy = $("player-search-by").value;
|
||||
const byAddress = searchBy !== "name";
|
||||
const query = $("player-search").value.trim();
|
||||
const searchRun = ++playerSearchRun;
|
||||
$("address-hint").hidden = searchBy !== "address";
|
||||
$("player-only").hidden = byAddress;
|
||||
if (byAddress && query === "") {
|
||||
if (searchRun !== playerSearchRun || tab !== "players") {
|
||||
return;
|
||||
}
|
||||
players = [];
|
||||
renderPlayers();
|
||||
$("players-more").hidden = true;
|
||||
@@ -2777,6 +2804,12 @@
|
||||
else {
|
||||
const only = listOnly();
|
||||
const result = await api(`players?q=${encodeURIComponent(query)}${byAddress ? `&by=${searchBy}` : only ? `&only=${only}` : ""}`);
|
||||
if (searchRun !== playerSearchRun || tab !== "players"
|
||||
|| searchBy !== $("player-search-by").value
|
||||
|| query !== $("player-search").value.trim()
|
||||
|| (!byAddress && only !== listOnly())) {
|
||||
return;
|
||||
}
|
||||
players = result.ok ? result.data.players : [];
|
||||
renderPlayers();
|
||||
const total = result.ok && result.data.total ? result.data.total : players.length;
|
||||
|
||||
@@ -85,6 +85,21 @@ const run = async () => {
|
||||
await a.untilXt("ac");
|
||||
await a.nextXt("il");
|
||||
|
||||
// Actions are normally live type-3 chat packets. A player who enters after
|
||||
// one has started must receive the current action after the avatar itself,
|
||||
// including its mirror marker, rather than seeing an idle animal.
|
||||
say(a, roomId, ":dance:%3%m1");
|
||||
assert.deepStrictEqual((await b.untilXt("uc")).slice(2), [String(annLogin.params.userId), ":dance:", "3", "m1"]);
|
||||
const {client: c} = await arrive("Cat", "KettlePass01");
|
||||
assert.deepStrictEqual((await c.untilXt("uc")).slice(2), [String(annLogin.params.userId), ":dance:", "3", "m1"]);
|
||||
await a.untilXt("ac"); // Cat appearing in the room
|
||||
await a.nextXt("il");
|
||||
await b.untilXt("ac");
|
||||
await b.nextXt("il");
|
||||
c.socket.destroy();
|
||||
await a.untilXt("ar");
|
||||
await b.untilXt("ar");
|
||||
|
||||
// the shop's name and stalls come from its room file (lib/roominfo.js),
|
||||
// read the first time anyone goes in; until then the name is made from its
|
||||
// path. a scout goes in first and comes back until the file has been read,
|
||||
@@ -514,6 +529,7 @@ const run = async () => {
|
||||
a.xt("fr", own[4], "Ben", 2);
|
||||
assert.deepStrictEqual((await a.nextXt("fr")).slice(2), ["1"]);
|
||||
const waiting = (await panel("reports", undefined, admin)).data;
|
||||
const reportId = waiting.reports[0].id;
|
||||
assert.strictEqual(waiting.open, 1);
|
||||
assert.strictEqual(waiting.reports.length, 1);
|
||||
assert.deepStrictEqual([waiting.reports[0].reporter, waiting.reports[0].target, waiting.reports[0].reason, waiting.reports[0].detail, waiting.reports[0].room],
|
||||
@@ -690,6 +706,12 @@ const run = async () => {
|
||||
await panel("debug", {action: "everythingOnSale", on: false}, admin);
|
||||
assert.ok(await dated(1030) > 0);
|
||||
|
||||
// Renames must carry the names shown on existing moderation records.
|
||||
// The admin action disconnects Ben before making this change.
|
||||
assert.strictEqual((await panel("account", {username: "Ben", action: "rename", newName: "Benny"}, admin)).status, 200);
|
||||
const renamedReport = (await panel("reports?handled=1", undefined, admin)).data.reports.find(report => report.id === reportId);
|
||||
assert.strictEqual(renamedReport.target, "Benny");
|
||||
|
||||
a.socket.destroy();
|
||||
b.socket.destroy();
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user