dredless 1.5.0 → 1.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/docs/MANAGEMENT.md
CHANGED
|
@@ -79,8 +79,11 @@ client.management.canSave(): boolean;
|
|
|
79
79
|
client.management.save(options?: {timeout?: number}): Promise<DisconnectInfo>;
|
|
80
80
|
```
|
|
81
81
|
|
|
82
|
-
`canSave()` requires a connected/ready client
|
|
83
|
-
|
|
82
|
+
`canSave()` requires a connected/ready client and a current ship with a parent-world ID.
|
|
83
|
+
It permits attempts when the parent's `danger_level` is `0` or unknown (including missing parent metadata).
|
|
84
|
+
Mosaic (world `66`) is explicitly whitelisted regardless of its reported danger level. Other known unsafe
|
|
85
|
+
zones return `false`. Partial metadata updates retain the last known danger level.
|
|
86
|
+
This is permission to attempt a save, not a guarantee of success; server permissions still apply.
|
|
84
87
|
|
|
85
88
|
**Fragment:** this saves the ship and ejects its players:
|
|
86
89
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dredless",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.2",
|
|
4
4
|
"description": "A fully-featured and from-scratch headless drednot.io client implementation written in pure js.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://github.com/certainhuman/dredless#readme",
|
package/src/client/core.js
CHANGED
|
@@ -117,6 +117,9 @@ function normalizeHistoryLimit(value, fallback) {
|
|
|
117
117
|
return Math.floor(limit);
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
+
// Mosaic accepts save attempts independently of its reported danger level.
|
|
121
|
+
const SAVE_ALLOWED_PARENT_WORLD_IDS = new Set([66]);
|
|
122
|
+
|
|
120
123
|
export class DredlessClient extends EventBus {
|
|
121
124
|
constructor(connection, {
|
|
122
125
|
connect = true,
|
|
@@ -273,8 +276,12 @@ export class DredlessClient extends EventBus {
|
|
|
273
276
|
if (!this.connected || !this.ready) return false;
|
|
274
277
|
const ship = this.worlds.shipWorld();
|
|
275
278
|
if (!ship || ship.isOverworld !== false || ship.parentWorld == null) return false;
|
|
276
|
-
const
|
|
277
|
-
|
|
279
|
+
const parentId = Number(ship.parentWorld);
|
|
280
|
+
if (SAVE_ALLOWED_PARENT_WORLD_IDS.has(parentId)) return true;
|
|
281
|
+
const danger = this.worlds.worlds.get(parentId)?.meta?.danger_level;
|
|
282
|
+
// Missing metadata is not proof that saving is forbidden. The server
|
|
283
|
+
// remains authoritative, and saveShip waits for its Saved close code.
|
|
284
|
+
return danger == null || danger === 0;
|
|
278
285
|
}
|
|
279
286
|
|
|
280
287
|
async saveShip({timeout = 10000} = {}) {
|
|
@@ -283,7 +290,7 @@ export class DredlessClient extends EventBus {
|
|
|
283
290
|
throw new RangeError("timeout must be positive milliseconds no greater than 2147483647");
|
|
284
291
|
}
|
|
285
292
|
if (this.#savePending) throw new Error("A ship save is already in progress");
|
|
286
|
-
if (!this.canSaveShip()) throw new Error("Saving requires a connected, ready client with
|
|
293
|
+
if (!this.canSaveShip()) throw new Error("Saving requires a connected, ready client with a current ship outside a known unsafe zone (Mosaic is allowed)");
|
|
287
294
|
this.#savePending = true;
|
|
288
295
|
try {
|
|
289
296
|
return await new Promise((resolve, reject) => {
|
package/src/constants.js
CHANGED
|
@@ -44,7 +44,11 @@ export const COMMAND_FIELDS = [
|
|
|
44
44
|
|
|
45
45
|
export const COMMAND_DEFAULT_FORMATS = {
|
|
46
46
|
type: "positive-fixint",
|
|
47
|
-
|
|
47
|
+
// The official client counts commands in a u32 and writes the smallest
|
|
48
|
+
// unsigned format (fixint, then uint8, uint16, uint32). A fixed uint16
|
|
49
|
+
// wrapped the 65,536th command to 0, and the server drops a connection
|
|
50
|
+
// whose command number goes backwards (ProtocolError).
|
|
51
|
+
n: "uint",
|
|
48
52
|
x: "float32",
|
|
49
53
|
y: "float32",
|
|
50
54
|
mx: "float32",
|
package/src/index.d.ts
CHANGED
|
@@ -697,7 +697,7 @@ export class DredlessClient {
|
|
|
697
697
|
disconnect(code?: number, reason?: string): this;
|
|
698
698
|
sendChatMessage(message?: string): this;
|
|
699
699
|
sendCommsMessage(message?: string): this;
|
|
700
|
-
/** Whether
|
|
700
|
+
/** Whether a connected, ready client may attempt saving: safe or unknown parent danger, or Mosaic (66). */
|
|
701
701
|
canSaveShip(): boolean;
|
|
702
702
|
/** Save and await the server's Saved close code; reject on ineligibility, timeout, or any other disconnect. */
|
|
703
703
|
saveShip(options?: SaveShipOptions): Promise<DisconnectInfo>;
|
|
@@ -872,7 +872,7 @@ export interface PlayerDomain {
|
|
|
872
872
|
}
|
|
873
873
|
|
|
874
874
|
export interface ShipManagementDomain {
|
|
875
|
-
/**
|
|
875
|
+
/** Allows safe/unknown parent danger or Mosaic (66); requires a connected, ready client. Server confirmation still applies. */
|
|
876
876
|
canSave(): boolean;
|
|
877
877
|
|
|
878
878
|
/** Save and await the server's Saved close code; reject on ineligibility, timeout, or any other disconnect. */
|
|
@@ -90,6 +90,13 @@ function encodeValue(key, value, entry) {
|
|
|
90
90
|
if (typeof value === "number") {
|
|
91
91
|
const schemaFormat = COMMAND_DEFAULT_FORMATS[key];
|
|
92
92
|
let format = schemaFormat && schemaFormat !== "nil" ? schemaFormat : null;
|
|
93
|
+
if (format === "uint") {
|
|
94
|
+
// A narrower format would silently wrap the value.
|
|
95
|
+
if (!Number.isInteger(value) || value < 0 || value > 0xffffffff) {
|
|
96
|
+
throw new RangeError(`Command field ${key} must be an integer from 0 to 4294967295, got ${value}`);
|
|
97
|
+
}
|
|
98
|
+
format = value <= 0x7f ? "positive-fixint" : value <= 0xff ? "uint8" : value <= 0xffff ? "uint16" : "uint32";
|
|
99
|
+
}
|
|
93
100
|
if (!format) {
|
|
94
101
|
if (!Number.isInteger(value)) format = "float32";
|
|
95
102
|
else if (value >= 0) {
|