dredless 1.3.0 → 1.4.0
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/dist/browser/dredless.global.js +919 -483
- package/dist/browser/dredless.global.js.map +4 -4
- package/docs/CLIENT.md +1 -1
- package/docs/MACHINES.md +97 -14
- package/docs/MANAGEMENT.md +1 -1
- package/docs/NODE_API.md +2 -0
- package/docs/PROTOCOL.md +27 -0
- package/docs/WORLD_STATE.md +11 -0
- package/package.json +1 -1
- package/src/browser.d.ts +20 -0
- package/src/browser.js +12 -0
- package/src/client/core.js +71 -6
- package/src/client/domains/index.js +69 -13
- package/src/client/domains/tips.js +0 -15
- package/src/index.d.ts +90 -13
- package/src/index.js +12 -0
- package/src/network/bundle-metadata.js +191 -0
- package/src/network/servers.js +48 -23
- package/src/protocol/outbound/machine-config.d.ts +19 -0
- package/src/protocol/outbound/machine-config.js +112 -0
- package/src/protocol/outbound/ui-config.d.ts +25 -0
- package/src/protocol/outbound/ui-config.js +6 -0
- package/src/state/model/decoder.js +39 -18
- package/src/state/model/state.js +4 -3
package/src/index.d.ts
CHANGED
|
@@ -376,6 +376,11 @@ export const LoaderPriority: {
|
|
|
376
376
|
export type LoaderPriority = typeof LoaderPriority[keyof typeof LoaderPriority];
|
|
377
377
|
export type ClipboardTarget =
|
|
378
378
|
number
|
|
379
|
+
| "launcher"
|
|
380
|
+
| "door"
|
|
381
|
+
| "spawn"
|
|
382
|
+
| "spawn-point"
|
|
383
|
+
| "spawnPoint"
|
|
379
384
|
| "loader"
|
|
380
385
|
| "loader-config"
|
|
381
386
|
| "loaderConfig"
|
|
@@ -424,6 +429,28 @@ export interface LoaderConfig {
|
|
|
424
429
|
waitForStack?: boolean;
|
|
425
430
|
}
|
|
426
431
|
|
|
432
|
+
export type AllowedRank = "guest" | "crew" | "captain";
|
|
433
|
+
export type AllowedRanks = readonly AllowedRank[] | "all";
|
|
434
|
+
|
|
435
|
+
export interface RankFilterConfig {
|
|
436
|
+
/** Specify allowedRanks or rankMask, not both. Empty disables all ranks. */
|
|
437
|
+
allowedRanks?: AllowedRanks;
|
|
438
|
+
/** 0–7, or 0xffffffff for all current and future ranks. */
|
|
439
|
+
rankMask?: number;
|
|
440
|
+
}
|
|
441
|
+
export interface LauncherConfig {
|
|
442
|
+
/** Degrees, 0–360. */
|
|
443
|
+
angle?: number;
|
|
444
|
+
/** 0–30; fractional values are supported. */
|
|
445
|
+
power?: number;
|
|
446
|
+
}
|
|
447
|
+
export interface DoorConfig extends RankFilterConfig {}
|
|
448
|
+
export interface DoorClipboardConfig extends DoorConfig {
|
|
449
|
+
/** Placement orientation; does not rotate an existing door. */
|
|
450
|
+
orientation?: "vertical" | "horizontal";
|
|
451
|
+
}
|
|
452
|
+
export interface SpawnPointConfig extends RankFilterConfig {}
|
|
453
|
+
|
|
427
454
|
export interface LoaderFullConfig extends LoaderConfig {
|
|
428
455
|
filterMode?: LoaderFilterMode;
|
|
429
456
|
filterSlots?: Array<number | null | undefined>;
|
|
@@ -631,6 +658,18 @@ export class DredlessClient {
|
|
|
631
658
|
|
|
632
659
|
whenReady(): Promise<this>;
|
|
633
660
|
|
|
661
|
+
sendLauncherConfig(entity: number, config?: LauncherConfig): DredlessClient;
|
|
662
|
+
setLauncherAngle(entity: number, angle: number, config?: LauncherConfig): DredlessClient;
|
|
663
|
+
setLauncherPower(entity: number, power: number, config?: LauncherConfig): DredlessClient;
|
|
664
|
+
copyLauncherConfig(entity: number, config?: LauncherConfig): DredlessClient;
|
|
665
|
+
pasteLauncherConfig(entity: number, config?: LauncherConfig): DredlessClient;
|
|
666
|
+
sendDoorConfig(entity: number, config?: DoorConfig): DredlessClient;
|
|
667
|
+
copyDoorConfig(entity: number, config?: DoorClipboardConfig): DredlessClient;
|
|
668
|
+
pasteDoorConfig(entity: number, config?: DoorClipboardConfig): DredlessClient;
|
|
669
|
+
sendSpawnPointConfig(entity: number, config?: SpawnPointConfig): DredlessClient;
|
|
670
|
+
copySpawnPointConfig(entity: number, config?: SpawnPointConfig): DredlessClient;
|
|
671
|
+
pasteSpawnPointConfig(entity: number, config?: SpawnPointConfig): DredlessClient;
|
|
672
|
+
|
|
634
673
|
close(code?: number, reason?: string): this;
|
|
635
674
|
|
|
636
675
|
disconnect(code?: number, reason?: string): this;
|
|
@@ -1340,9 +1379,13 @@ export interface PusherHandle extends MachineHandle {
|
|
|
1340
1379
|
export interface LauncherHandle extends MachineHandle {
|
|
1341
1380
|
state: LauncherSummary | null;
|
|
1342
1381
|
|
|
1343
|
-
|
|
1382
|
+
configure(config?: LauncherConfig): DredlessClient;
|
|
1383
|
+
copy(config?: LauncherConfig): DredlessClient;
|
|
1384
|
+
paste(config?: LauncherConfig): DredlessClient;
|
|
1385
|
+
setAngle(angle: number, config?: LauncherConfig): DredlessClient;
|
|
1344
1386
|
|
|
1345
|
-
setPower(power: number): DredlessClient;
|
|
1387
|
+
setPower(power: number, config?: LauncherConfig): DredlessClient;
|
|
1388
|
+
power: number | null | undefined;
|
|
1346
1389
|
|
|
1347
1390
|
angleDegrees: number | undefined;
|
|
1348
1391
|
angleRadians: number | undefined;
|
|
@@ -1448,15 +1491,25 @@ export interface HelmHandle extends MachineHandle {
|
|
|
1448
1491
|
|
|
1449
1492
|
export interface DoorHandle extends EntityHandle {
|
|
1450
1493
|
state: DoorSummary | null;
|
|
1451
|
-
|
|
1494
|
+
rankMask: number | null | undefined;
|
|
1495
|
+
allowedRanks: ("guest" | "crew" | "captain")[] | null | undefined;
|
|
1452
1496
|
open: boolean | undefined;
|
|
1453
|
-
|
|
1497
|
+
configure(config?: DoorConfig): DredlessClient;
|
|
1498
|
+
copy(config?: DoorClipboardConfig): DredlessClient;
|
|
1499
|
+
paste(config?: DoorClipboardConfig): DredlessClient;
|
|
1500
|
+
setAllowedRanks(allowedRanks: AllowedRanks): DredlessClient;
|
|
1501
|
+
setRankMask(rankMask: number): DredlessClient;
|
|
1454
1502
|
}
|
|
1455
1503
|
|
|
1456
1504
|
export interface SpawnPointHandle extends MachineHandle {
|
|
1457
1505
|
state: SpawnPointSummary | null;
|
|
1458
|
-
|
|
1459
|
-
|
|
1506
|
+
rankMask: number | null | undefined;
|
|
1507
|
+
allowedRanks: ("guest" | "crew" | "captain")[] | null | undefined;
|
|
1508
|
+
configure(config?: SpawnPointConfig): DredlessClient;
|
|
1509
|
+
copy(config?: SpawnPointConfig): DredlessClient;
|
|
1510
|
+
paste(config?: SpawnPointConfig): DredlessClient;
|
|
1511
|
+
setAllowedRanks(allowedRanks: AllowedRanks): DredlessClient;
|
|
1512
|
+
setRankMask(rankMask: number): DredlessClient;
|
|
1460
1513
|
}
|
|
1461
1514
|
|
|
1462
1515
|
export interface ShieldProjectorHandle extends MachineHandle {
|
|
@@ -2044,6 +2097,8 @@ export interface ItemCrateSummary {
|
|
|
2044
2097
|
itemId: number | null;
|
|
2045
2098
|
itemName: string | null;
|
|
2046
2099
|
count: number | null;
|
|
2100
|
+
/** Use the box sprite instead of the item's normal sprite. */
|
|
2101
|
+
boxSprite: boolean;
|
|
2047
2102
|
width: number | null;
|
|
2048
2103
|
height: number | null;
|
|
2049
2104
|
itemState: ModelRecord;
|
|
@@ -2123,6 +2178,10 @@ export interface HealthSummary {
|
|
|
2123
2178
|
hp: number | null;
|
|
2124
2179
|
maxHp: number | null;
|
|
2125
2180
|
ratio: number | null;
|
|
2181
|
+
/** Full width of the rendered health bar, in world units. */
|
|
2182
|
+
barWidth: number;
|
|
2183
|
+
/** Vertical displacement from the entity position, in world units. */
|
|
2184
|
+
barOffsetY: number;
|
|
2126
2185
|
state: ModelRecord;
|
|
2127
2186
|
}
|
|
2128
2187
|
|
|
@@ -2297,6 +2356,9 @@ export interface LauncherSummary {
|
|
|
2297
2356
|
angleRaw: number | null;
|
|
2298
2357
|
angleRadians: number | null;
|
|
2299
2358
|
angleDegrees: number | null;
|
|
2359
|
+
/** Replicated launcher power; null on legacy servers. */
|
|
2360
|
+
power: number | null;
|
|
2361
|
+
configState: ModelRecord | null;
|
|
2300
2362
|
state: ModelRecord;
|
|
2301
2363
|
}
|
|
2302
2364
|
|
|
@@ -2353,19 +2415,23 @@ export interface SignSummary {
|
|
|
2353
2415
|
state: ModelRecord;
|
|
2354
2416
|
}
|
|
2355
2417
|
|
|
2356
|
-
export interface
|
|
2418
|
+
export interface RankFilterSummary {
|
|
2419
|
+
/** Unsigned rank bits: guest=1, crew=2, captain=4; null if unavailable. */
|
|
2420
|
+
rankMask: number | null;
|
|
2421
|
+
allowedRanks: ("guest" | "crew" | "captain")[] | null;
|
|
2422
|
+
/** True for the all-ranks mask, including future ranks. */
|
|
2423
|
+
allRanks: boolean;
|
|
2424
|
+
rankState: ModelRecord;
|
|
2425
|
+
}
|
|
2426
|
+
|
|
2427
|
+
export interface SpawnPointSummary extends RankFilterSummary {
|
|
2357
2428
|
entity: number;
|
|
2358
|
-
rank: number;
|
|
2359
|
-
rankName: string | null;
|
|
2360
2429
|
state: ModelRecord;
|
|
2361
2430
|
}
|
|
2362
2431
|
|
|
2363
|
-
export interface DoorSummary {
|
|
2432
|
+
export interface DoorSummary extends RankFilterSummary {
|
|
2364
2433
|
entity: number;
|
|
2365
|
-
rank: number;
|
|
2366
|
-
rankName: string | null;
|
|
2367
2434
|
open: boolean;
|
|
2368
|
-
rankState: ModelRecord;
|
|
2369
2435
|
state: ModelRecord;
|
|
2370
2436
|
}
|
|
2371
2437
|
|
|
@@ -2769,6 +2835,17 @@ export function buildLoaderFullConfigData(entity: number, config?: LoaderFullCon
|
|
|
2769
2835
|
|
|
2770
2836
|
export function buildPusherConfigData(entity: number, config?: PusherConfig): Uint8Array;
|
|
2771
2837
|
|
|
2838
|
+
export function normalizeRankMask(config?: RankFilterConfig): number;
|
|
2839
|
+
export function buildLauncherConfigData(entity: number, config?: LauncherConfig): Uint8Array;
|
|
2840
|
+
export function buildLauncherCopyConfigData(config?: LauncherConfig): Uint8Array;
|
|
2841
|
+
export function buildLauncherPasteConfigData(entity: number, config?: LauncherConfig): Uint8Array;
|
|
2842
|
+
export function buildDoorConfigData(entity: number, config?: DoorConfig): Uint8Array;
|
|
2843
|
+
export function buildDoorCopyConfigData(config?: DoorClipboardConfig): Uint8Array;
|
|
2844
|
+
export function buildDoorPasteConfigData(entity: number, config?: DoorClipboardConfig): Uint8Array;
|
|
2845
|
+
export function buildSpawnPointConfigData(entity: number, config?: SpawnPointConfig): Uint8Array;
|
|
2846
|
+
export function buildSpawnPointCopyConfigData(config?: SpawnPointConfig): Uint8Array;
|
|
2847
|
+
export function buildSpawnPointPasteConfigData(entity: number, config?: SpawnPointConfig): Uint8Array;
|
|
2848
|
+
|
|
2772
2849
|
export function buildPusherFilterItemsData(entity: number, filterSlots?: Array<number | null | undefined>): Uint8Array;
|
|
2773
2850
|
|
|
2774
2851
|
export function generateGeneratorMaze(seed: number): GeneratorMaze;
|
package/src/index.js
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
export {
|
|
2
|
+
buildLauncherConfigData,
|
|
3
|
+
buildLauncherCopyConfigData,
|
|
4
|
+
buildLauncherPasteConfigData,
|
|
5
|
+
buildDoorConfigData,
|
|
6
|
+
buildDoorCopyConfigData,
|
|
7
|
+
buildDoorPasteConfigData,
|
|
8
|
+
buildSpawnPointConfigData,
|
|
9
|
+
buildSpawnPointCopyConfigData,
|
|
10
|
+
buildSpawnPointPasteConfigData,
|
|
11
|
+
normalizeRankMask,
|
|
12
|
+
} from "./protocol/outbound/machine-config.js";
|
|
1
13
|
export {Session, AnonSession} from "./network/session.js";
|
|
2
14
|
export {Connection} from "./network/connection.js";
|
|
3
15
|
export {DropReason, DisconnectError, normalizeDisconnect} from "./network/disconnect.js";
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
// A deliberately limited reader, not a JavaScript evaluator. Only constant
|
|
2
|
+
// strings, booleans, and arrays of strings may back the requested exports.
|
|
3
|
+
const identifier = /^[A-Za-z_$][\w$]*$/;
|
|
4
|
+
const regexPrefix = new Set(['(', '[', '{', '=', ':', ',', ';', '!', '?', '&', '|', '=>', 'return', 'throw', 'case', 'typeof', 'void', 'delete']);
|
|
5
|
+
|
|
6
|
+
function quoted(source, start) {
|
|
7
|
+
const quote = source[start];
|
|
8
|
+
let value = '', valid = true, i = start + 1;
|
|
9
|
+
for (; i < source.length; i++) {
|
|
10
|
+
const c = source[i];
|
|
11
|
+
if (c === quote) return {value, valid, end: i + 1};
|
|
12
|
+
if (c !== '\\') { value += c; if (c === '\n' || c === '\r') valid = false; continue; }
|
|
13
|
+
const escape = source[++i];
|
|
14
|
+
const simple = {n: '\n', r: '\r', t: '\t', b: '\b', f: '\f', v: '\v', '0': '\0'};
|
|
15
|
+
if (escape === '\n') continue;
|
|
16
|
+
if (escape === '\r') { if (source[i + 1] === '\n') i++; continue; }
|
|
17
|
+
if (escape === 'x' || escape === 'u') {
|
|
18
|
+
const braced = escape === 'u' && source[i + 1] === '{';
|
|
19
|
+
const first = i + (braced ? 2 : 1);
|
|
20
|
+
const end = braced ? source.indexOf('}', first) : first + (escape === 'x' ? 2 : 4);
|
|
21
|
+
const digits = source.slice(first, end);
|
|
22
|
+
if (end < first) return {value, valid: false, end: source.length};
|
|
23
|
+
if (!/^[\da-f]+$/i.test(digits) || Number.parseInt(digits, 16) > 0x10ffff) valid = false;
|
|
24
|
+
else value += String.fromCodePoint(Number.parseInt(digits, 16));
|
|
25
|
+
i = braced ? end : end - 1;
|
|
26
|
+
} else if (escape === '0' && /\d/.test(source[i + 1] || '')) valid = false;
|
|
27
|
+
else if (escape in simple) value += simple[escape];
|
|
28
|
+
else if (escape && !/[1-9]/.test(escape)) value += escape;
|
|
29
|
+
else valid = false;
|
|
30
|
+
}
|
|
31
|
+
return {value, valid: false, end: i};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function skipRegex(source, start) {
|
|
35
|
+
let inClass = false, i = start + 1;
|
|
36
|
+
for (; i < source.length; i++) {
|
|
37
|
+
if (source[i] === '\\') { i++; continue; }
|
|
38
|
+
if (source[i] === '[') inClass = true;
|
|
39
|
+
if (source[i] === ']') inClass = false;
|
|
40
|
+
if (source[i] === '/' && !inClass) {
|
|
41
|
+
while (/[a-z]/i.test(source[i + 1] || '')) i++;
|
|
42
|
+
return i + 1;
|
|
43
|
+
}
|
|
44
|
+
if (source[i] === '\n') break;
|
|
45
|
+
}
|
|
46
|
+
return i;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function skipTemplate(source, start) {
|
|
50
|
+
let i = start + 1;
|
|
51
|
+
while (i < source.length) {
|
|
52
|
+
if (source[i] === '\\') { i += 2; continue; }
|
|
53
|
+
if (source[i] === '`') return i + 1;
|
|
54
|
+
if (source[i] === '$' && source[i + 1] === '{') {
|
|
55
|
+
const expression = lex(source, i + 2, true);
|
|
56
|
+
i = expression.end;
|
|
57
|
+
} else i++;
|
|
58
|
+
}
|
|
59
|
+
return i;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function lex(source, start = 0, interpolation = false) {
|
|
63
|
+
const tokens = [];
|
|
64
|
+
let i = start, depth = 0;
|
|
65
|
+
while (i < source.length) {
|
|
66
|
+
const c = source[i];
|
|
67
|
+
if (/\s/.test(c)) { i++; continue; }
|
|
68
|
+
if (source.startsWith('//', i)) { const end = source.indexOf('\n', i); i = end < 0 ? source.length : end; continue; }
|
|
69
|
+
if (source.startsWith('/*', i)) { const end = source.indexOf('*/', i + 2); i = end < 0 ? source.length : end + 2; continue; }
|
|
70
|
+
let token;
|
|
71
|
+
if (c === '"' || c === "'") {
|
|
72
|
+
const string = quoted(source, i);
|
|
73
|
+
token = {kind: 'string', value: string.value, valid: string.valid}; i = string.end;
|
|
74
|
+
} else if (c === '`') { i = skipTemplate(source, i); token = {kind: 'opaque', value: 'template'}; }
|
|
75
|
+
else if (c === '/' && (!tokens.length || regexPrefix.has(tokens.at(-1).value))) {
|
|
76
|
+
i = skipRegex(source, i); token = {kind: 'opaque', value: 'regex'};
|
|
77
|
+
} else if (/[A-Za-z_$]/.test(c)) {
|
|
78
|
+
const first = i++;
|
|
79
|
+
while (/[\w$]/.test(source[i] || '')) i++;
|
|
80
|
+
token = {kind: 'identifier', value: source.slice(first, i)};
|
|
81
|
+
} else {
|
|
82
|
+
token = {kind: 'punctuation', value: source.startsWith('=>', i) ? '=>' : c};
|
|
83
|
+
i += token.value.length;
|
|
84
|
+
}
|
|
85
|
+
if (interpolation && token.kind === 'punctuation' && token.value === '}' && depth === 0) return {tokens, end: i};
|
|
86
|
+
if (token.value === '{' && token.kind === 'punctuation') depth++;
|
|
87
|
+
if (token.value === '}' && token.kind === 'punctuation') depth--;
|
|
88
|
+
tokens.push(token);
|
|
89
|
+
}
|
|
90
|
+
return {tokens, end: i};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function literal(tokens, start) {
|
|
94
|
+
const token = tokens[start];
|
|
95
|
+
if (token?.kind === 'string' && token.valid) return {value: token.value, end: start + 1};
|
|
96
|
+
if (token?.kind === 'identifier' && ['true', 'false'].includes(token.value)) return {value: token.value === 'true', end: start + 1};
|
|
97
|
+
if (token?.kind !== 'punctuation' || token.value !== '[') return null;
|
|
98
|
+
const value = [];
|
|
99
|
+
let i = start + 1;
|
|
100
|
+
while (!(tokens[i]?.kind === 'punctuation' && tokens[i].value === ']')) {
|
|
101
|
+
if (tokens[i]?.kind !== 'string' || !tokens[i].valid) return null;
|
|
102
|
+
value.push(tokens[i++].value);
|
|
103
|
+
if (tokens[i]?.kind === 'punctuation' && tokens[i].value === ']') break;
|
|
104
|
+
if (tokens[i++]?.value !== ',') return null;
|
|
105
|
+
}
|
|
106
|
+
return tokens[i]?.value === ']' ? {value, end: i + 1} : null;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function getter(tokens, start) {
|
|
110
|
+
let i = start;
|
|
111
|
+
if (tokens[i++]?.value !== '(' || tokens[i++]?.value !== ')' || tokens[i++]?.value !== '=>') return null;
|
|
112
|
+
if (tokens[i]?.kind === 'identifier' && identifier.test(tokens[i].value) && [',', '}'].includes(tokens[i + 1]?.value)) return tokens[i].value;
|
|
113
|
+
if (tokens[i++]?.value !== '{' || tokens[i++]?.value !== 'return') return null;
|
|
114
|
+
const name = tokens[i++];
|
|
115
|
+
if (tokens[i]?.value === ';') i++;
|
|
116
|
+
return name?.kind === 'identifier' && tokens[i]?.value === '}' ? name.value : null;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export function readBundleExports(text, names) {
|
|
120
|
+
const wanted = new Set(names), found = new Map();
|
|
121
|
+
// HTML and raw JS are both accepted. Never scan markup as JavaScript.
|
|
122
|
+
const scripts = /^\s*</.test(text) ? [...text.matchAll(/<script\b[^>]*>([\s\S]*?)<\/script\s*>/gi)].map((match) => match[1]) : [];
|
|
123
|
+
for (const source of scripts.length ? scripts : [text]) {
|
|
124
|
+
const {tokens} = lex(source);
|
|
125
|
+
const root = new Map(), scopes = [root];
|
|
126
|
+
const brackets = [];
|
|
127
|
+
for (const [index, token] of tokens.entries()) {
|
|
128
|
+
token.scope = scopes.at(-1);
|
|
129
|
+
if (token.kind !== 'punctuation') continue;
|
|
130
|
+
if (['(', '[', '{'].includes(token.value)) brackets.push(index);
|
|
131
|
+
if ([')', ']', '}'].includes(token.value)) {
|
|
132
|
+
const opening = brackets.pop();
|
|
133
|
+
if (opening !== undefined) tokens[opening].close = index;
|
|
134
|
+
}
|
|
135
|
+
if (token.value === '{') { token.child = new Map(); scopes.push(token.child); }
|
|
136
|
+
if (token.value === '}' && scopes.length > 1) scopes.pop();
|
|
137
|
+
}
|
|
138
|
+
// Resolve after scanning declarations, so export/definition order is irrelevant.
|
|
139
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
140
|
+
if (tokens[i].kind !== 'identifier' || tokens[i].value !== 'const') continue;
|
|
141
|
+
const scope = tokens[i].scope;
|
|
142
|
+
let j = i + 1;
|
|
143
|
+
while (tokens[j]?.kind === 'identifier' && tokens[j + 1]?.value === '=') {
|
|
144
|
+
const name = tokens[j].value, result = literal(tokens, j + 2);
|
|
145
|
+
let end = j + 2;
|
|
146
|
+
while (end < tokens.length) {
|
|
147
|
+
const token = tokens[end];
|
|
148
|
+
if (token.scope === scope && token.kind === 'punctuation' && [';', ',', '}'].includes(token.value)) break;
|
|
149
|
+
end = token.close !== undefined ? token.close + 1 : end + 1;
|
|
150
|
+
}
|
|
151
|
+
const valid = result && result.end === end;
|
|
152
|
+
scope.set(name, scope.has(name) ? null : valid ? result.value : null);
|
|
153
|
+
if (tokens[end]?.value !== ',') break;
|
|
154
|
+
j = end + 1;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
const record = (name, binding, scope) => {
|
|
158
|
+
if (!wanted.has(name)) return;
|
|
159
|
+
const value = binding ? scope.get(binding) : undefined;
|
|
160
|
+
if (value == null) throw new Error(`Unable to resolve bundle export ${name}: expected a constant literal in the same module`);
|
|
161
|
+
if (found.has(name) && JSON.stringify(found.get(name)) !== JSON.stringify(value)) throw new Error(`Ambiguous bundle export ${name}`);
|
|
162
|
+
found.set(name, value);
|
|
163
|
+
};
|
|
164
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
165
|
+
if (tokens[i].kind !== 'identifier') continue;
|
|
166
|
+
const method = tokens[i].value === 'Object' && tokens[i + 1]?.value === '.' ? tokens[i + 2]?.value : null;
|
|
167
|
+
// The game also uses a minified helper: helper(exports,{NAME:()=>x}).
|
|
168
|
+
const call = ['defineProperties', 'defineProperty'].includes(method) ? i + 3 : i + 1;
|
|
169
|
+
if (tokens[call]?.value !== '(' || tokens[call + 1]?.kind !== 'identifier' || tokens[call + 2]?.value !== ',') continue;
|
|
170
|
+
let j = call + 3;
|
|
171
|
+
if (method === 'defineProperty') {
|
|
172
|
+
const name = tokens[j++];
|
|
173
|
+
if (name?.kind !== 'string' || !wanted.has(name.value) || tokens[j++]?.value !== ',') continue;
|
|
174
|
+
const object = tokens[j++];
|
|
175
|
+
if (object?.value !== '{' || !object.child) continue;
|
|
176
|
+
for (; j < tokens.length && tokens[j].scope !== object.scope; j++) {
|
|
177
|
+
if (tokens[j].scope === object.child && tokens[j].value === 'get' && tokens[j + 1]?.value === ':') record(name.value, getter(tokens, j + 2), tokens[i].scope);
|
|
178
|
+
}
|
|
179
|
+
} else {
|
|
180
|
+
const object = tokens[j++];
|
|
181
|
+
if (object?.value !== '{' || !object.child) continue;
|
|
182
|
+
for (; j < tokens.length && tokens[j].scope !== object.scope; j++) {
|
|
183
|
+
const key = tokens[j];
|
|
184
|
+
if (key.scope === object.child && ['identifier', 'string'].includes(key.kind) && wanted.has(key.value) && tokens[j + 1]?.value === ':') record(key.value, getter(tokens, j + 2), tokens[i].scope);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
for (const name of wanted) if (!found.has(name)) throw new Error(`Missing bundle export ${name}`);
|
|
190
|
+
return Object.fromEntries(found);
|
|
191
|
+
}
|
package/src/network/servers.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {DEFAULT_BASE_URL} from "../constants.js";
|
|
2
2
|
import {getWebSocket, hostName, normalizeBaseUrl} from "../runtime.js";
|
|
3
3
|
import {HttpClient} from "./http.js";
|
|
4
|
+
import {readBundleExports} from "./bundle-metadata.js";
|
|
4
5
|
|
|
5
6
|
const cache = new Map();
|
|
6
7
|
|
|
@@ -11,20 +12,26 @@ class ServerDirectory {
|
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
async load() {
|
|
14
|
-
if (cache.has(this.baseUrl))
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
if (!cache.has(this.baseUrl)) cache.set(this.baseUrl, this.#fetchMeta());
|
|
16
|
+
const pending = cache.get(this.baseUrl);
|
|
17
|
+
try {
|
|
18
|
+
this.meta = await pending;
|
|
19
|
+
} catch (error) {
|
|
20
|
+
if (cache.get(this.baseUrl) === pending) cache.delete(this.baseUrl);
|
|
21
|
+
throw error;
|
|
17
22
|
}
|
|
18
|
-
const promise = this.#fetchMeta();
|
|
19
|
-
cache.set(this.baseUrl, promise);
|
|
20
|
-
this.meta = await promise;
|
|
21
23
|
return this;
|
|
22
24
|
}
|
|
23
25
|
|
|
24
26
|
async version() {
|
|
25
27
|
await this.load();
|
|
26
|
-
|
|
27
|
-
|
|
28
|
+
try {
|
|
29
|
+
this.meta.version ??= parseGameVersion(this.meta.text);
|
|
30
|
+
return this.meta.version;
|
|
31
|
+
} catch (error) {
|
|
32
|
+
cache.delete(this.baseUrl);
|
|
33
|
+
throw error;
|
|
34
|
+
}
|
|
28
35
|
}
|
|
29
36
|
|
|
30
37
|
async list() {
|
|
@@ -33,8 +40,13 @@ class ServerDirectory {
|
|
|
33
40
|
|
|
34
41
|
async servers() {
|
|
35
42
|
await this.load();
|
|
36
|
-
|
|
37
|
-
|
|
43
|
+
try {
|
|
44
|
+
this.meta.serverInfo ??= parseServerInfo(this.meta.text, this.baseUrl);
|
|
45
|
+
return this.meta.serverInfo.servers;
|
|
46
|
+
} catch (error) {
|
|
47
|
+
cache.delete(this.baseUrl);
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
38
50
|
}
|
|
39
51
|
|
|
40
52
|
async get(id = null) {
|
|
@@ -50,7 +62,7 @@ class ServerDirectory {
|
|
|
50
62
|
const response = await new HttpClient({baseUrl: this.baseUrl}).request("index.html");
|
|
51
63
|
if (!response.ok) throw new Error(`Failed to fetch bundle: ${response.status} ${response.statusText}`);
|
|
52
64
|
const text = await response.text();
|
|
53
|
-
return {text
|
|
65
|
+
return {text};
|
|
54
66
|
}
|
|
55
67
|
}
|
|
56
68
|
|
|
@@ -132,7 +144,9 @@ export function serverId(server) {
|
|
|
132
144
|
}
|
|
133
145
|
|
|
134
146
|
function parseGameVersion(text) {
|
|
135
|
-
|
|
147
|
+
const {GAME_VERSION} = readBundleExports(text, ["GAME_VERSION"]);
|
|
148
|
+
if (typeof GAME_VERSION !== "string" || !GAME_VERSION.trim()) throw new Error("Invalid bundle export GAME_VERSION: expected a nonempty string");
|
|
149
|
+
return GAME_VERSION;
|
|
136
150
|
}
|
|
137
151
|
|
|
138
152
|
function parseNoticeVersion(text) {
|
|
@@ -159,18 +173,29 @@ function parseNoticeVersion(text) {
|
|
|
159
173
|
|
|
160
174
|
function parseServerInfo(text, baseUrl) {
|
|
161
175
|
const host = hostName(baseUrl);
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
const
|
|
165
|
-
|
|
166
|
-
|
|
176
|
+
const config = readBundleExports(text, ["LOCAL_DOMAIN", "BASE_DOMAIN", "TEST_DOMAIN", "TEST_GAME_DOMAIN",
|
|
177
|
+
"GAME_DOMAINS", "GAME_SERVER_NAMES", "MASTER_DOMAIN", "TEST_MASTER_DOMAIN"]);
|
|
178
|
+
const domain = (value, name) => {
|
|
179
|
+
if (typeof value !== "string" || value.length > 253 || !/^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)*[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/i.test(value)) {
|
|
180
|
+
throw new Error(`Invalid bundle export ${name}: expected a hostname`);
|
|
181
|
+
}
|
|
182
|
+
return value;
|
|
183
|
+
};
|
|
184
|
+
const localDomain = domain(config.LOCAL_DOMAIN, "LOCAL_DOMAIN");
|
|
185
|
+
const baseDomain = domain(config.BASE_DOMAIN, "BASE_DOMAIN");
|
|
186
|
+
const testDomain = domain(config.TEST_DOMAIN, "TEST_DOMAIN");
|
|
187
|
+
const testGameDomain = domain(config.TEST_GAME_DOMAIN, "TEST_GAME_DOMAIN");
|
|
188
|
+
const domains = config.GAME_DOMAINS;
|
|
189
|
+
const names = config.GAME_SERVER_NAMES;
|
|
190
|
+
if (!Array.isArray(domains) || !domains.length) throw new Error("Invalid bundle export GAME_DOMAINS: expected nonempty hostname array");
|
|
191
|
+
domains.forEach((value) => domain(value, "GAME_DOMAINS"));
|
|
192
|
+
if (!Array.isArray(names) || names.length !== domains.length || names.some((name) => typeof name !== "string")) {
|
|
193
|
+
throw new Error("Invalid bundle export GAME_SERVER_NAMES: expected one string per game domain");
|
|
194
|
+
}
|
|
167
195
|
const meta = {
|
|
168
|
-
localDomain,
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
testGameDomain,
|
|
172
|
-
masterDomain: match[8],
|
|
173
|
-
testMasterDomain: match[9]
|
|
196
|
+
localDomain, baseDomain, testDomain, testGameDomain,
|
|
197
|
+
masterDomain: domain(config.MASTER_DOMAIN, "MASTER_DOMAIN"),
|
|
198
|
+
testMasterDomain: domain(config.TEST_MASTER_DOMAIN, "TEST_MASTER_DOMAIN")
|
|
174
199
|
};
|
|
175
200
|
if (host === localDomain) return {mode: "local", servers: [server(0, localDomain, "Local Test 1")], meta};
|
|
176
201
|
if (host === testDomain) return {mode: "test", servers: [server(0, testGameDomain, "Public Test")], meta};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export {
|
|
2
|
+
buildLauncherConfigData,
|
|
3
|
+
buildLauncherCopyConfigData,
|
|
4
|
+
buildLauncherPasteConfigData,
|
|
5
|
+
buildDoorConfigData,
|
|
6
|
+
buildDoorCopyConfigData,
|
|
7
|
+
buildDoorPasteConfigData,
|
|
8
|
+
buildSpawnPointConfigData,
|
|
9
|
+
buildSpawnPointCopyConfigData,
|
|
10
|
+
buildSpawnPointPasteConfigData,
|
|
11
|
+
normalizeRankMask,
|
|
12
|
+
type AllowedRank,
|
|
13
|
+
type AllowedRanks,
|
|
14
|
+
type RankFilterConfig,
|
|
15
|
+
type LauncherConfig,
|
|
16
|
+
type DoorConfig,
|
|
17
|
+
type DoorClipboardConfig,
|
|
18
|
+
type SpawnPointConfig,
|
|
19
|
+
} from "../../index.js";
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import {encoder} from "../../constants.js";
|
|
2
|
+
|
|
3
|
+
function uint32(value, name) {
|
|
4
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value < 0 || value > 0xffffffff) {
|
|
5
|
+
throw new RangeError(`${name} must be an unsigned 32-bit integer`);
|
|
6
|
+
}
|
|
7
|
+
return value;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function encodeUnsigned(value) {
|
|
11
|
+
if (value < 64) return [value];
|
|
12
|
+
if (value < 256) return [0x80, value];
|
|
13
|
+
if (value < 65536) return [0x81, value & 255, value >>> 8];
|
|
14
|
+
return [0x82, value & 255, value >>> 8 & 255, value >>> 16 & 255, value >>> 24];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function encodeFloat(value, name, max) {
|
|
18
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value < 0 || value > max) {
|
|
19
|
+
throw new RangeError(`${name} must be a finite number between 0 and ${max}`);
|
|
20
|
+
}
|
|
21
|
+
const number = Math.fround(value);
|
|
22
|
+
if (Number.isInteger(number)) {
|
|
23
|
+
if (number < 64) return [number];
|
|
24
|
+
if (number < 128) return [0x84, number];
|
|
25
|
+
return [0x85, number & 255, number >>> 8];
|
|
26
|
+
}
|
|
27
|
+
const bytes = new Uint8Array(5);
|
|
28
|
+
bytes[0] = 0x88;
|
|
29
|
+
new DataView(bytes.buffer).setFloat32(1, number, true);
|
|
30
|
+
return [...bytes];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function section(name, values) {
|
|
34
|
+
const bytes = encoder.encode(name);
|
|
35
|
+
return [0x8a, bytes.length, ...bytes, 0, 0x90, ...values, 0x91];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function message(target, action, sections) {
|
|
39
|
+
return Uint8Array.from([0x90, action, ...encodeUnsigned(uint32(target, "target")), ...sections.flat(), 0x91]);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function normalizeRankMask({allowedRanks, rankMask} = {}) {
|
|
43
|
+
if (allowedRanks !== undefined && rankMask !== undefined) {
|
|
44
|
+
throw new TypeError("provide allowedRanks or rankMask, not both");
|
|
45
|
+
}
|
|
46
|
+
if (rankMask !== undefined) {
|
|
47
|
+
const value = uint32(rankMask, "rankMask");
|
|
48
|
+
if (value > 7 && value !== 0xffffffff) throw new RangeError("rankMask must be 0–7 or 0xffffffff");
|
|
49
|
+
return value;
|
|
50
|
+
}
|
|
51
|
+
if (allowedRanks === undefined) return 4;
|
|
52
|
+
if (allowedRanks === "all") return 0xffffffff;
|
|
53
|
+
if (!Array.isArray(allowedRanks)) throw new TypeError('allowedRanks must be an array of rank names or "all"');
|
|
54
|
+
let mask = 0;
|
|
55
|
+
for (const rank of allowedRanks) {
|
|
56
|
+
const bit = {guest: 1, crew: 2, captain: 4}[rank];
|
|
57
|
+
if (typeof rank !== "string" || !["guest", "crew", "captain"].includes(rank)) throw new RangeError(`unsupported rank: ${rank}`);
|
|
58
|
+
mask |= bit;
|
|
59
|
+
}
|
|
60
|
+
return mask;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function rankSection(config) {
|
|
64
|
+
return section("filter_ranks", encodeUnsigned(normalizeRankMask(config)));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function launcherSection({angle = 0, power = 30} = {}) {
|
|
68
|
+
return section("config_item_launcher", [...encodeFloat(angle, "angle", 360), ...encodeFloat(power, "power", 30)]);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function doorSections(config = {}, clipboard = false) {
|
|
72
|
+
if (!clipboard && config.orientation !== undefined) {
|
|
73
|
+
throw new TypeError("door orientation is only available for placement/clipboard configuration");
|
|
74
|
+
}
|
|
75
|
+
const sections = [rankSection(config)];
|
|
76
|
+
if (clipboard) {
|
|
77
|
+
const orientation = config.orientation ?? "vertical";
|
|
78
|
+
if (orientation !== "vertical" && orientation !== "horizontal") {
|
|
79
|
+
throw new RangeError('orientation must be "vertical" or "horizontal"');
|
|
80
|
+
}
|
|
81
|
+
sections.unshift(section("angle_symmetric", [orientation === "horizontal" ? 1 : 0]));
|
|
82
|
+
}
|
|
83
|
+
return sections;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function buildLauncherConfigData(entity, config = {}) {
|
|
87
|
+
return message(entity, 0, [launcherSection(config)]);
|
|
88
|
+
}
|
|
89
|
+
export function buildLauncherCopyConfigData(config = {}) {
|
|
90
|
+
return message(8, 1, [launcherSection(config)]);
|
|
91
|
+
}
|
|
92
|
+
export function buildLauncherPasteConfigData(entity, config = {}) {
|
|
93
|
+
return message(entity, 2, [launcherSection(config)]);
|
|
94
|
+
}
|
|
95
|
+
export function buildDoorConfigData(entity, config = {}) {
|
|
96
|
+
return message(entity, 0, doorSections(config));
|
|
97
|
+
}
|
|
98
|
+
export function buildDoorCopyConfigData(config = {}) {
|
|
99
|
+
return message(10, 1, doorSections(config, true));
|
|
100
|
+
}
|
|
101
|
+
export function buildDoorPasteConfigData(entity, config = {}) {
|
|
102
|
+
return message(entity, 2, doorSections(config, true));
|
|
103
|
+
}
|
|
104
|
+
export function buildSpawnPointConfigData(entity, config = {}) {
|
|
105
|
+
return message(entity, 0, [rankSection(config)]);
|
|
106
|
+
}
|
|
107
|
+
export function buildSpawnPointCopyConfigData(config = {}) {
|
|
108
|
+
return message(9, 1, [rankSection(config)]);
|
|
109
|
+
}
|
|
110
|
+
export function buildSpawnPointPasteConfigData(entity, config = {}) {
|
|
111
|
+
return message(entity, 2, [rankSection(config)]);
|
|
112
|
+
}
|