BlueGit

timfa questward

Add editor Restart now and default NPCs to not buy items.

Admins can trigger a graceful server shutdown from the world editor; systemd restarts with a fresh deploy. Humanoid spawner defaults no longer enable buysItems — opt in per NPC in the editor.

timfa Tim Falken · pushed by timfa

Authored 2026-08-28 · 2 months ago

Hash
9a3f48d2636be6ac885afcde77988f7a7073fa14
Parent
0a7756df
9 files changed +99 −14
client/editor.html +10 −7
@@ -7,13 +7,16 @@
7 7 </head>
8 8 <body>
9 9 <header>
10 <h1>Questward — World editor</h1>
11 <p id="who">Connecting…</p>
12 <p id="auth-actions" class="auth-actions">
13 <a id="auth-sign-in" href="/auth/login" hidden>Sign in</a>
14 <a id="auth-sign-out" href="/auth/logout" hidden>Sign out</a>
15 </p>
16 <p id="error" class="error"></p>
10 <div class="editor-header-main">
11 <h1>Questward — World editor</h1>
12 <p id="who">Connecting…</p>
13 <p id="auth-actions" class="auth-actions">
14 <a id="auth-sign-in" href="/auth/login" hidden>Sign in</a>
15 <a id="auth-sign-out" href="/auth/logout" hidden>Sign out</a>
16 </p>
17 <p id="error" class="error"></p>
18 </div>
19 <button id="editor-restart-now" type="button" hidden title="Graceful shutdown; systemd restarts the server">Restart now</button>
17 20 </header>
18 21 <aside>
19 22 <p>Chunk <strong id="coords">0, 0</strong></p>
@@ -7,13 +7,16 @@
7</head>
7</head>
8<body>
8<body>
9 <header>
9 <header>
10 <h1>Questward — World editor</h1>
10 <div class="editor-header-main">
11 <p id="who">Connecting…</p>
11 <h1>Questward — World editor</h1>
12 <p id="auth-actions" class="auth-actions">
12 <p id="who">Connecting…</p>
13 <a id="auth-sign-in" href="/auth/login" hidden>Sign in</a>
13 <p id="auth-actions" class="auth-actions">
14 <a id="auth-sign-out" href="/auth/logout" hidden>Sign out</a>
14 <a id="auth-sign-in" href="/auth/login" hidden>Sign in</a>
15 </p>
15 <a id="auth-sign-out" href="/auth/logout" hidden>Sign out</a>
16 <p id="error" class="error"></p>
16 </p>
17 <p id="error" class="error"></p>
18 </div>
19 <button id="editor-restart-now" type="button" hidden title="Graceful shutdown; systemd restarts the server">Restart now</button>
17 </header>
20 </header>
18 <aside>
21 <aside>
19 <p>Chunk <strong id="coords">0, 0</strong></p>
22 <p>Chunk <strong id="coords">0, 0</strong></p>
client/src/editor/main.js +30 −1
@@ -1076,6 +1076,12 @@ async function main ()
1076 1076 return;
1077 1077 }
1078 1078 $("error").textContent = "";
1079 const restartBtn = document.getElementById("editor-restart-now");
1080 if (restartBtn)
1081 {
1082 restartBtn.hidden = false;
1083 restartBtn.disabled = false;
1084 }
1079 1085 socket.send({ type: MessageType.editorLoadSettings });
1080 1086 socket.send({ type: MessageType.editorLoadGameAdmins });
1081 1087 socket.send({ type: MessageType.editorConsoleSubscribe });
@@ -1131,6 +1137,11 @@ async function main ()
1131 1137 requestDimensions();
1132 1138 requestChunks(neighborhoodCoords(chunkX, chunkY));
1133 1139 }
1140 else if (message.type === MessageType.forceLogout)
1141 {
1142 $("who").textContent = "Server restarting…";
1143 $("error").textContent = message.reason || "Server shutting down.";
1144 }
1134 1145 else if (message.type === MessageType.error)
1135 1146 {
1136 1147 $("error").textContent = message.message;
@@ -1153,7 +1164,8 @@ async function main ()
1153 1164 const reasons = {
1154 1165 4401: "Sign in expired or missing. Use Sign out, then sign in again.",
1155 1166 1011: "Server could not verify your account with auth.timfalken.com.",
1156 1006: "Connection dropped before the editor session started."
1167 1006: "Connection dropped before the editor session started.",
1168 1001: "Server is restarting. Reload this page in a moment."
1157 1169 };
1158 1170 const detail = reasons[event.code] ?? `Connection closed (code ${event.code}).`;
1159 1171 $("who").textContent = "Connection failed";
@@ -1316,6 +1328,23 @@ $("apply").addEventListener("click", () =>
1316 1328 updateRevisionUI();
1317 1329 socket.send({ type: MessageType.editorApplyRevision });
1318 1330 });
1331 document.getElementById("editor-restart-now")?.addEventListener("click", () =>
1332 {
1333 if (!socket)
1334 { return; }
1335 const ok = window.confirm(
1336 "Restart the server now?\n\nAll players and editor sessions will disconnect. "
1337 + "systemd will start a fresh process and pull the latest code from git."
1338 );
1339 if (!ok)
1340 { return; }
1341 const restartBtn = document.getElementById("editor-restart-now");
1342 if (restartBtn)
1343 { restartBtn.disabled = true; }
1344 $("who").textContent = "Restarting server…";
1345 $("error").textContent = "";
1346 socket.send({ type: MessageType.editorRestartNow });
1347 });
1319 1348 $("night").addEventListener("input", () =>
1320 1349 {
1321 1350 view.nightPreview = Number($("night").value);
@@ -1076,6 +1076,12 @@ async function main ()
1076 return;
1076 return;
1077 }
1077 }
1078 $("error").textContent = "";
1078 $("error").textContent = "";
1079 const restartBtn = document.getElementById("editor-restart-now");
1080 if (restartBtn)
1081 {
1082 restartBtn.hidden = false;
1083 restartBtn.disabled = false;
1084 }
1079 socket.send({ type: MessageType.editorLoadSettings });
1085 socket.send({ type: MessageType.editorLoadSettings });
1080 socket.send({ type: MessageType.editorLoadGameAdmins });
1086 socket.send({ type: MessageType.editorLoadGameAdmins });
1081 socket.send({ type: MessageType.editorConsoleSubscribe });
1087 socket.send({ type: MessageType.editorConsoleSubscribe });
@@ -1131,6 +1137,11 @@ async function main ()
1131 requestDimensions();
1137 requestDimensions();
1132 requestChunks(neighborhoodCoords(chunkX, chunkY));
1138 requestChunks(neighborhoodCoords(chunkX, chunkY));
1133 }
1139 }
1140 else if (message.type === MessageType.forceLogout)
1141 {
1142 $("who").textContent = "Server restarting…";
1143 $("error").textContent = message.reason || "Server shutting down.";
1144 }
1134 else if (message.type === MessageType.error)
1145 else if (message.type === MessageType.error)
1135 {
1146 {
1136 $("error").textContent = message.message;
1147 $("error").textContent = message.message;
@@ -1153,7 +1164,8 @@ async function main ()
1153 const reasons = {
1164 const reasons = {
1154 4401: "Sign in expired or missing. Use Sign out, then sign in again.",
1165 4401: "Sign in expired or missing. Use Sign out, then sign in again.",
1155 1011: "Server could not verify your account with auth.timfalken.com.",
1166 1011: "Server could not verify your account with auth.timfalken.com.",
1156 1006: "Connection dropped before the editor session started."
1167 1006: "Connection dropped before the editor session started.",
1168 1001: "Server is restarting. Reload this page in a moment."
1157 };
1169 };
1158 const detail = reasons[event.code] ?? `Connection closed (code ${event.code}).`;
1170 const detail = reasons[event.code] ?? `Connection closed (code ${event.code}).`;
1159 $("who").textContent = "Connection failed";
1171 $("who").textContent = "Connection failed";
@@ -1316,6 +1328,23 @@ $("apply").addEventListener("click", () =>
1316 updateRevisionUI();
1328 updateRevisionUI();
1317 socket.send({ type: MessageType.editorApplyRevision });
1329 socket.send({ type: MessageType.editorApplyRevision });
1318});
1330});
1331document.getElementById("editor-restart-now")?.addEventListener("click", () =>
1332{
1333 if (!socket)
1334 { return; }
1335 const ok = window.confirm(
1336 "Restart the server now?\n\nAll players and editor sessions will disconnect. "
1337 + "systemd will start a fresh process and pull the latest code from git."
1338 );
1339 if (!ok)
1340 { return; }
1341 const restartBtn = document.getElementById("editor-restart-now");
1342 if (restartBtn)
1343 { restartBtn.disabled = true; }
1344 $("who").textContent = "Restarting server…";
1345 $("error").textContent = "";
1346 socket.send({ type: MessageType.editorRestartNow });
1347});
1319$("night").addEventListener("input", () =>
1348$("night").addEventListener("input", () =>
1320{
1349{
1321 view.nightPreview = Number($("night").value);
1350 view.nightPreview = Number($("night").value);
client/ui/editor.css +40 −0
@@ -11,10 +11,50 @@ html, body {
11 11 }
12 12
13 13 body > header {
14 display: flex;
15 align-items: flex-start;
16 justify-content: space-between;
17 gap: 1rem;
14 18 padding: 0.6rem 1rem;
15 19 border-bottom: 1px solid #2c3340;
16 20 }
17 21
22 .editor-header-main {
23 min-width: 0;
24 flex: 1 1 auto;
25 }
26
27 .editor-header-main h1,
28 .editor-header-main p {
29 margin: 0.15rem 0;
30 }
31
32 #editor-restart-now {
33 flex: 0 0 auto;
34 margin-top: 0.15rem;
35 padding: 0.35rem 0.65rem;
36 border: 1px solid #7a4a4a;
37 border-radius: 0.35rem;
38 background: #2a1818;
39 color: #f0c8c8;
40 font: inherit;
41 cursor: pointer;
42 white-space: nowrap;
43 }
44
45 #editor-restart-now:hover:not(:disabled) {
46 background: #3a2020;
47 }
48
49 #editor-restart-now:disabled {
50 opacity: 0.55;
51 cursor: default;
52 }
53
54 #editor-restart-now[hidden] {
55 display: none !important;
56 }
57
18 58 body > aside {
19 59 position: absolute;
20 60 left: 0;
@@ -11,10 +11,50 @@ html, body {
11}
11}
12
12
13body > header {
13body > header {
14 display: flex;
15 align-items: flex-start;
16 justify-content: space-between;
17 gap: 1rem;
14 padding: 0.6rem 1rem;
18 padding: 0.6rem 1rem;
15 border-bottom: 1px solid #2c3340;
19 border-bottom: 1px solid #2c3340;
16}
20}
17
21
22.editor-header-main {
23 min-width: 0;
24 flex: 1 1 auto;
25}
26
27.editor-header-main h1,
28.editor-header-main p {
29 margin: 0.15rem 0;
30}
31
32#editor-restart-now {
33 flex: 0 0 auto;
34 margin-top: 0.15rem;
35 padding: 0.35rem 0.65rem;
36 border: 1px solid #7a4a4a;
37 border-radius: 0.35rem;
38 background: #2a1818;
39 color: #f0c8c8;
40 font: inherit;
41 cursor: pointer;
42 white-space: nowrap;
43}
44
45#editor-restart-now:hover:not(:disabled) {
46 background: #3a2020;
47}
48
49#editor-restart-now:disabled {
50 opacity: 0.55;
51 cursor: default;
52}
53
54#editor-restart-now[hidden] {
55 display: none !important;
56}
57
18body > aside {
58body > aside {
19 position: absolute;
59 position: absolute;
20 left: 0;
60 left: 0;
server/src/gateway/websocket.js +4 −0
@@ -940,6 +940,10 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,
940 940 });
941 941 }
942 942 break;
943 case MessageType.editorRestartNow:
944 requireAdmin(session);
945 deploy?.requestRestartNow?.("admin-editor");
946 break;
943 947 case MessageType.editorLoadQuests:
944 948 requireAdmin(session);
945 949 send(session, { type: MessageType.editorQuests, ...editor.loadQuests() });
@@ -940,6 +940,10 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,
940 });
940 });
941 }
941 }
942 break;
942 break;
943 case MessageType.editorRestartNow:
944 requireAdmin(session);
945 deploy?.requestRestartNow?.("admin-editor");
946 break;
943 case MessageType.editorLoadQuests:
947 case MessageType.editorLoadQuests:
944 requireAdmin(session);
948 requireAdmin(session);
945 send(session, { type: MessageType.editorQuests, ...editor.loadQuests() });
949 send(session, { type: MessageType.editorQuests, ...editor.loadQuests() });
server/src/index.js +8 −0
@@ -35,6 +35,14 @@ const deployBridge = {
35 35 isDraining ()
36 36 {
37 37 return shuttingDown;
38 },
39 requestRestartNow (reason = "admin-editor")
40 {
41 void plannedRestart({
42 reasons: [reason],
43 remoteCommit: null,
44 scheduledAt: Date.now()
45 });
38 46 }
39 47 };
40 48
@@ -35,6 +35,14 @@ const deployBridge = {
35 isDraining ()
35 isDraining ()
36 {
36 {
37 return shuttingDown;
37 return shuttingDown;
38 },
39 requestRestartNow (reason = "admin-editor")
40 {
41 void plannedRestart({
42 reasons: [reason],
43 remoteCommit: null,
44 scheduledAt: Date.now()
45 });
38 }
46 }
39};
47};
40
48
server/tests/shop.test.js +3 −2
@@ -225,7 +225,7 @@ test("humanoid spawner config keeps sex equipment sells quantities and buysItems
225 225 assert.equal(config.maxAlive, 1);
226 226 });
227 227
228 test("shopkeeper with default buysItems accepts paper from the player", () =>
228 test("shopkeeper with buysItems accepts paper from the player", () =>
229 229 {
230 230 const harness = makeSimulation({ workerCount: 1 });
231 231 try
@@ -240,7 +240,8 @@ test("shopkeeper with default buysItems accepts paper from the player", () =>
240 240 maxAlive: 1,
241 241 spawnRangeTiles: 0,
242 242 maxWanderRangeTiles: 0,
243 displayName: "Stationer"
243 displayName: "Stationer",
244 buysItems: true
244 245 }
245 246 }];
246 247 harness.worldDb.saveChunkVersion(0, 0, harness.worldDb.getActiveRevisionId(), true, encodeChunkBlob(data));
@@ -225,7 +225,7 @@ test("humanoid spawner config keeps sex equipment sells quantities and buysItems
225 assert.equal(config.maxAlive, 1);
225 assert.equal(config.maxAlive, 1);
226});
226});
227
227
228test("shopkeeper with default buysItems accepts paper from the player", () =>
228test("shopkeeper with buysItems accepts paper from the player", () =>
229{
229{
230 const harness = makeSimulation({ workerCount: 1 });
230 const harness = makeSimulation({ workerCount: 1 });
231 try
231 try
@@ -240,7 +240,8 @@ test("shopkeeper with default buysItems accepts paper from the player", () =>
240 maxAlive: 1,
240 maxAlive: 1,
241 spawnRangeTiles: 0,
241 spawnRangeTiles: 0,
242 maxWanderRangeTiles: 0,
242 maxWanderRangeTiles: 0,
243 displayName: "Stationer"
243 displayName: "Stationer",
244 buysItems: true
244 }
245 }
245 }];
246 }];
246 harness.worldDb.saveChunkVersion(0, 0, harness.worldDb.getActiveRevisionId(), true, encodeChunkBlob(data));
247 harness.worldDb.saveChunkVersion(0, 0, harness.worldDb.getActiveRevisionId(), true, encodeChunkBlob(data));
server/tests/spawner-bounty.test.js +2 −2
@@ -35,10 +35,10 @@ test("town guard spawner defaults level, bounty, and equipment", () =>
35 35 assert.equal(config.equipment.weapon, 245);
36 36 });
37 37
38 test("shopkeeper spawners buy from players by default", () =>
38 test("humanoid spawners do not buy from players by default", () =>
39 39 {
40 40 const config = normalizeSpawnerConfig({ mobTypeId: MobId.humanoid }, "shop-1");
41 assert.equal(config.buysItems, true);
41 assert.equal(config.buysItems, false);
42 42 const guard = normalizeSpawnerConfig({ mobTypeId: MobId.townGuard }, "guard-1");
43 43 assert.equal(guard.buysItems, false);
44 44 });
@@ -35,10 +35,10 @@ test("town guard spawner defaults level, bounty, and equipment", () =>
35 assert.equal(config.equipment.weapon, 245);
35 assert.equal(config.equipment.weapon, 245);
36});
36});
37
37
38test("shopkeeper spawners buy from players by default", () =>
38test("humanoid spawners do not buy from players by default", () =>
39{
39{
40 const config = normalizeSpawnerConfig({ mobTypeId: MobId.humanoid }, "shop-1");
40 const config = normalizeSpawnerConfig({ mobTypeId: MobId.humanoid }, "shop-1");
41 assert.equal(config.buysItems, true);
41 assert.equal(config.buysItems, false);
42 const guard = normalizeSpawnerConfig({ mobTypeId: MobId.townGuard }, "guard-1");
42 const guard = normalizeSpawnerConfig({ mobTypeId: MobId.townGuard }, "guard-1");
43 assert.equal(guard.buysItems, false);
43 assert.equal(guard.buysItems, false);
44});
44});
shared/definitions/mobs.js +1 −2
@@ -247,7 +247,6 @@ export function defaultSpawnerConfig (spawnerId, mobTypeId = MobId.deer)
247 247 const humanoid = isHumanoidMob(mobTypeId) || mobTypeId === MobId.humanoid;
248 248 const townGuard = mobTypeId === MobId.townGuard;
249 249 const centralExchange = mobTypeId === MobId.centralExchange;
250 const shopkeeper = mobTypeId === MobId.humanoid;
251 250 const bodyNpc = humanoid || townGuard || centralExchange;
252 251 return {
253 252 spawnerId,
@@ -275,7 +274,7 @@ export function defaultSpawnerConfig (spawnerId, mobTypeId = MobId.deer)
275 274 : emptySpawnerEquipment(),
276 275 sells: [],
277 276 spells: [],
278 buysItems: shopkeeper,
277 buysItems: false,
279 278 hiddenDiscount: 0.9,
280 279 centralExchange,
281 280 townGuard,
@@ -247,7 +247,6 @@ export function defaultSpawnerConfig (spawnerId, mobTypeId = MobId.deer)
247 const humanoid = isHumanoidMob(mobTypeId) || mobTypeId === MobId.humanoid;
247 const humanoid = isHumanoidMob(mobTypeId) || mobTypeId === MobId.humanoid;
248 const townGuard = mobTypeId === MobId.townGuard;
248 const townGuard = mobTypeId === MobId.townGuard;
249 const centralExchange = mobTypeId === MobId.centralExchange;
249 const centralExchange = mobTypeId === MobId.centralExchange;
250 const shopkeeper = mobTypeId === MobId.humanoid;
251 const bodyNpc = humanoid || townGuard || centralExchange;
250 const bodyNpc = humanoid || townGuard || centralExchange;
252 return {
251 return {
253 spawnerId,
252 spawnerId,
@@ -275,7 +274,7 @@ export function defaultSpawnerConfig (spawnerId, mobTypeId = MobId.deer)
275 : emptySpawnerEquipment(),
274 : emptySpawnerEquipment(),
276 sells: [],
275 sells: [],
277 spells: [],
276 spells: [],
278 buysItems: shopkeeper,
277 buysItems: false,
279 hiddenDiscount: 0.9,
278 hiddenDiscount: 0.9,
280 centralExchange,
279 centralExchange,
281 townGuard,
280 townGuard,
shared/protocol/constants.js +1 −0
@@ -111,6 +111,7 @@ export const MessageType = Object.freeze({
111 111 editorRevokeGameAdmin: "EDITOR_REVOKE_GAME_ADMIN",
112 112 editorApplyRevision: "EDITOR_APPLY_REVISION",
113 113 editorRevisionApplied: "EDITOR_REVISION_APPLIED",
114 editorRestartNow: "EDITOR_RESTART_NOW",
114 115 friendRequest: "FRIEND_REQUEST",
115 116 friendAccept: "FRIEND_ACCEPT",
116 117 friendDecline: "FRIEND_DECLINE",
@@ -111,6 +111,7 @@ export const MessageType = Object.freeze({
111 editorRevokeGameAdmin: "EDITOR_REVOKE_GAME_ADMIN",
111 editorRevokeGameAdmin: "EDITOR_REVOKE_GAME_ADMIN",
112 editorApplyRevision: "EDITOR_APPLY_REVISION",
112 editorApplyRevision: "EDITOR_APPLY_REVISION",
113 editorRevisionApplied: "EDITOR_REVISION_APPLIED",
113 editorRevisionApplied: "EDITOR_REVISION_APPLIED",
114 editorRestartNow: "EDITOR_RESTART_NOW",
114 friendRequest: "FRIEND_REQUEST",
115 friendRequest: "FRIEND_REQUEST",
115 friendAccept: "FRIEND_ACCEPT",
116 friendAccept: "FRIEND_ACCEPT",
116 friendDecline: "FRIEND_DECLINE",
117 friendDecline: "FRIEND_DECLINE",