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
|
@@ -341,6 +341,223 @@
|
|
|
341
341
|
}
|
|
342
342
|
});
|
|
343
343
|
|
|
344
|
+
// src/network/bundle-metadata.js
|
|
345
|
+
function quoted(source, start) {
|
|
346
|
+
const quote = source[start];
|
|
347
|
+
let value = "", valid = true, i = start + 1;
|
|
348
|
+
for (; i < source.length; i++) {
|
|
349
|
+
const c = source[i];
|
|
350
|
+
if (c === quote) return { value, valid, end: i + 1 };
|
|
351
|
+
if (c !== "\\") {
|
|
352
|
+
value += c;
|
|
353
|
+
if (c === "\n" || c === "\r") valid = false;
|
|
354
|
+
continue;
|
|
355
|
+
}
|
|
356
|
+
const escape = source[++i];
|
|
357
|
+
const simple = { n: "\n", r: "\r", t: " ", b: "\b", f: "\f", v: "\v", "0": "\0" };
|
|
358
|
+
if (escape === "\n") continue;
|
|
359
|
+
if (escape === "\r") {
|
|
360
|
+
if (source[i + 1] === "\n") i++;
|
|
361
|
+
continue;
|
|
362
|
+
}
|
|
363
|
+
if (escape === "x" || escape === "u") {
|
|
364
|
+
const braced = escape === "u" && source[i + 1] === "{";
|
|
365
|
+
const first = i + (braced ? 2 : 1);
|
|
366
|
+
const end = braced ? source.indexOf("}", first) : first + (escape === "x" ? 2 : 4);
|
|
367
|
+
const digits = source.slice(first, end);
|
|
368
|
+
if (end < first) return { value, valid: false, end: source.length };
|
|
369
|
+
if (!/^[\da-f]+$/i.test(digits) || Number.parseInt(digits, 16) > 1114111) valid = false;
|
|
370
|
+
else value += String.fromCodePoint(Number.parseInt(digits, 16));
|
|
371
|
+
i = braced ? end : end - 1;
|
|
372
|
+
} else if (escape === "0" && /\d/.test(source[i + 1] || "")) valid = false;
|
|
373
|
+
else if (escape in simple) value += simple[escape];
|
|
374
|
+
else if (escape && !/[1-9]/.test(escape)) value += escape;
|
|
375
|
+
else valid = false;
|
|
376
|
+
}
|
|
377
|
+
return { value, valid: false, end: i };
|
|
378
|
+
}
|
|
379
|
+
function skipRegex(source, start) {
|
|
380
|
+
let inClass = false, i = start + 1;
|
|
381
|
+
for (; i < source.length; i++) {
|
|
382
|
+
if (source[i] === "\\") {
|
|
383
|
+
i++;
|
|
384
|
+
continue;
|
|
385
|
+
}
|
|
386
|
+
if (source[i] === "[") inClass = true;
|
|
387
|
+
if (source[i] === "]") inClass = false;
|
|
388
|
+
if (source[i] === "/" && !inClass) {
|
|
389
|
+
while (/[a-z]/i.test(source[i + 1] || "")) i++;
|
|
390
|
+
return i + 1;
|
|
391
|
+
}
|
|
392
|
+
if (source[i] === "\n") break;
|
|
393
|
+
}
|
|
394
|
+
return i;
|
|
395
|
+
}
|
|
396
|
+
function skipTemplate(source, start) {
|
|
397
|
+
let i = start + 1;
|
|
398
|
+
while (i < source.length) {
|
|
399
|
+
if (source[i] === "\\") {
|
|
400
|
+
i += 2;
|
|
401
|
+
continue;
|
|
402
|
+
}
|
|
403
|
+
if (source[i] === "`") return i + 1;
|
|
404
|
+
if (source[i] === "$" && source[i + 1] === "{") {
|
|
405
|
+
const expression = lex(source, i + 2, true);
|
|
406
|
+
i = expression.end;
|
|
407
|
+
} else i++;
|
|
408
|
+
}
|
|
409
|
+
return i;
|
|
410
|
+
}
|
|
411
|
+
function lex(source, start = 0, interpolation = false) {
|
|
412
|
+
const tokens = [];
|
|
413
|
+
let i = start, depth = 0;
|
|
414
|
+
while (i < source.length) {
|
|
415
|
+
const c = source[i];
|
|
416
|
+
if (/\s/.test(c)) {
|
|
417
|
+
i++;
|
|
418
|
+
continue;
|
|
419
|
+
}
|
|
420
|
+
if (source.startsWith("//", i)) {
|
|
421
|
+
const end = source.indexOf("\n", i);
|
|
422
|
+
i = end < 0 ? source.length : end;
|
|
423
|
+
continue;
|
|
424
|
+
}
|
|
425
|
+
if (source.startsWith("/*", i)) {
|
|
426
|
+
const end = source.indexOf("*/", i + 2);
|
|
427
|
+
i = end < 0 ? source.length : end + 2;
|
|
428
|
+
continue;
|
|
429
|
+
}
|
|
430
|
+
let token;
|
|
431
|
+
if (c === '"' || c === "'") {
|
|
432
|
+
const string = quoted(source, i);
|
|
433
|
+
token = { kind: "string", value: string.value, valid: string.valid };
|
|
434
|
+
i = string.end;
|
|
435
|
+
} else if (c === "`") {
|
|
436
|
+
i = skipTemplate(source, i);
|
|
437
|
+
token = { kind: "opaque", value: "template" };
|
|
438
|
+
} else if (c === "/" && (!tokens.length || regexPrefix.has(tokens.at(-1).value))) {
|
|
439
|
+
i = skipRegex(source, i);
|
|
440
|
+
token = { kind: "opaque", value: "regex" };
|
|
441
|
+
} else if (/[A-Za-z_$]/.test(c)) {
|
|
442
|
+
const first = i++;
|
|
443
|
+
while (/[\w$]/.test(source[i] || "")) i++;
|
|
444
|
+
token = { kind: "identifier", value: source.slice(first, i) };
|
|
445
|
+
} else {
|
|
446
|
+
token = { kind: "punctuation", value: source.startsWith("=>", i) ? "=>" : c };
|
|
447
|
+
i += token.value.length;
|
|
448
|
+
}
|
|
449
|
+
if (interpolation && token.kind === "punctuation" && token.value === "}" && depth === 0) return { tokens, end: i };
|
|
450
|
+
if (token.value === "{" && token.kind === "punctuation") depth++;
|
|
451
|
+
if (token.value === "}" && token.kind === "punctuation") depth--;
|
|
452
|
+
tokens.push(token);
|
|
453
|
+
}
|
|
454
|
+
return { tokens, end: i };
|
|
455
|
+
}
|
|
456
|
+
function literal(tokens, start) {
|
|
457
|
+
const token = tokens[start];
|
|
458
|
+
if (token?.kind === "string" && token.valid) return { value: token.value, end: start + 1 };
|
|
459
|
+
if (token?.kind === "identifier" && ["true", "false"].includes(token.value)) return { value: token.value === "true", end: start + 1 };
|
|
460
|
+
if (token?.kind !== "punctuation" || token.value !== "[") return null;
|
|
461
|
+
const value = [];
|
|
462
|
+
let i = start + 1;
|
|
463
|
+
while (!(tokens[i]?.kind === "punctuation" && tokens[i].value === "]")) {
|
|
464
|
+
if (tokens[i]?.kind !== "string" || !tokens[i].valid) return null;
|
|
465
|
+
value.push(tokens[i++].value);
|
|
466
|
+
if (tokens[i]?.kind === "punctuation" && tokens[i].value === "]") break;
|
|
467
|
+
if (tokens[i++]?.value !== ",") return null;
|
|
468
|
+
}
|
|
469
|
+
return tokens[i]?.value === "]" ? { value, end: i + 1 } : null;
|
|
470
|
+
}
|
|
471
|
+
function getter(tokens, start) {
|
|
472
|
+
let i = start;
|
|
473
|
+
if (tokens[i++]?.value !== "(" || tokens[i++]?.value !== ")" || tokens[i++]?.value !== "=>") return null;
|
|
474
|
+
if (tokens[i]?.kind === "identifier" && identifier.test(tokens[i].value) && [",", "}"].includes(tokens[i + 1]?.value)) return tokens[i].value;
|
|
475
|
+
if (tokens[i++]?.value !== "{" || tokens[i++]?.value !== "return") return null;
|
|
476
|
+
const name = tokens[i++];
|
|
477
|
+
if (tokens[i]?.value === ";") i++;
|
|
478
|
+
return name?.kind === "identifier" && tokens[i]?.value === "}" ? name.value : null;
|
|
479
|
+
}
|
|
480
|
+
function readBundleExports(text2, names) {
|
|
481
|
+
const wanted = new Set(names), found = /* @__PURE__ */ new Map();
|
|
482
|
+
const scripts = /^\s*</.test(text2) ? [...text2.matchAll(/<script\b[^>]*>([\s\S]*?)<\/script\s*>/gi)].map((match) => match[1]) : [];
|
|
483
|
+
for (const source of scripts.length ? scripts : [text2]) {
|
|
484
|
+
const { tokens } = lex(source);
|
|
485
|
+
const root = /* @__PURE__ */ new Map(), scopes = [root];
|
|
486
|
+
const brackets = [];
|
|
487
|
+
for (const [index, token] of tokens.entries()) {
|
|
488
|
+
token.scope = scopes.at(-1);
|
|
489
|
+
if (token.kind !== "punctuation") continue;
|
|
490
|
+
if (["(", "[", "{"].includes(token.value)) brackets.push(index);
|
|
491
|
+
if ([")", "]", "}"].includes(token.value)) {
|
|
492
|
+
const opening = brackets.pop();
|
|
493
|
+
if (opening !== void 0) tokens[opening].close = index;
|
|
494
|
+
}
|
|
495
|
+
if (token.value === "{") {
|
|
496
|
+
token.child = /* @__PURE__ */ new Map();
|
|
497
|
+
scopes.push(token.child);
|
|
498
|
+
}
|
|
499
|
+
if (token.value === "}" && scopes.length > 1) scopes.pop();
|
|
500
|
+
}
|
|
501
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
502
|
+
if (tokens[i].kind !== "identifier" || tokens[i].value !== "const") continue;
|
|
503
|
+
const scope = tokens[i].scope;
|
|
504
|
+
let j = i + 1;
|
|
505
|
+
while (tokens[j]?.kind === "identifier" && tokens[j + 1]?.value === "=") {
|
|
506
|
+
const name = tokens[j].value, result = literal(tokens, j + 2);
|
|
507
|
+
let end = j + 2;
|
|
508
|
+
while (end < tokens.length) {
|
|
509
|
+
const token = tokens[end];
|
|
510
|
+
if (token.scope === scope && token.kind === "punctuation" && [";", ",", "}"].includes(token.value)) break;
|
|
511
|
+
end = token.close !== void 0 ? token.close + 1 : end + 1;
|
|
512
|
+
}
|
|
513
|
+
const valid = result && result.end === end;
|
|
514
|
+
scope.set(name, scope.has(name) ? null : valid ? result.value : null);
|
|
515
|
+
if (tokens[end]?.value !== ",") break;
|
|
516
|
+
j = end + 1;
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
const record = (name, binding, scope) => {
|
|
520
|
+
if (!wanted.has(name)) return;
|
|
521
|
+
const value = binding ? scope.get(binding) : void 0;
|
|
522
|
+
if (value == null) throw new Error(`Unable to resolve bundle export ${name}: expected a constant literal in the same module`);
|
|
523
|
+
if (found.has(name) && JSON.stringify(found.get(name)) !== JSON.stringify(value)) throw new Error(`Ambiguous bundle export ${name}`);
|
|
524
|
+
found.set(name, value);
|
|
525
|
+
};
|
|
526
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
527
|
+
if (tokens[i].kind !== "identifier") continue;
|
|
528
|
+
const method = tokens[i].value === "Object" && tokens[i + 1]?.value === "." ? tokens[i + 2]?.value : null;
|
|
529
|
+
const call = ["defineProperties", "defineProperty"].includes(method) ? i + 3 : i + 1;
|
|
530
|
+
if (tokens[call]?.value !== "(" || tokens[call + 1]?.kind !== "identifier" || tokens[call + 2]?.value !== ",") continue;
|
|
531
|
+
let j = call + 3;
|
|
532
|
+
if (method === "defineProperty") {
|
|
533
|
+
const name = tokens[j++];
|
|
534
|
+
if (name?.kind !== "string" || !wanted.has(name.value) || tokens[j++]?.value !== ",") continue;
|
|
535
|
+
const object = tokens[j++];
|
|
536
|
+
if (object?.value !== "{" || !object.child) continue;
|
|
537
|
+
for (; j < tokens.length && tokens[j].scope !== object.scope; j++) {
|
|
538
|
+
if (tokens[j].scope === object.child && tokens[j].value === "get" && tokens[j + 1]?.value === ":") record(name.value, getter(tokens, j + 2), tokens[i].scope);
|
|
539
|
+
}
|
|
540
|
+
} else {
|
|
541
|
+
const object = tokens[j++];
|
|
542
|
+
if (object?.value !== "{" || !object.child) continue;
|
|
543
|
+
for (; j < tokens.length && tokens[j].scope !== object.scope; j++) {
|
|
544
|
+
const key = tokens[j];
|
|
545
|
+
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);
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
for (const name of wanted) if (!found.has(name)) throw new Error(`Missing bundle export ${name}`);
|
|
551
|
+
return Object.fromEntries(found);
|
|
552
|
+
}
|
|
553
|
+
var identifier, regexPrefix;
|
|
554
|
+
var init_bundle_metadata = __esm({
|
|
555
|
+
"src/network/bundle-metadata.js"() {
|
|
556
|
+
identifier = /^[A-Za-z_$][\w$]*$/;
|
|
557
|
+
regexPrefix = /* @__PURE__ */ new Set(["(", "[", "{", "=", ":", ",", ";", "!", "?", "&", "|", "=>", "return", "throw", "case", "typeof", "void", "delete"]);
|
|
558
|
+
}
|
|
559
|
+
});
|
|
560
|
+
|
|
344
561
|
// src/network/servers.js
|
|
345
562
|
async function fetchServerStatus(server2, baseUrl = DEFAULT_BASE_URL) {
|
|
346
563
|
const resolved = await resolveServer(server2, baseUrl);
|
|
@@ -412,7 +629,9 @@
|
|
|
412
629
|
return Number(server2);
|
|
413
630
|
}
|
|
414
631
|
function parseGameVersion(text2) {
|
|
415
|
-
|
|
632
|
+
const { GAME_VERSION } = readBundleExports(text2, ["GAME_VERSION"]);
|
|
633
|
+
if (typeof GAME_VERSION !== "string" || !GAME_VERSION.trim()) throw new Error("Invalid bundle export GAME_VERSION: expected a nonempty string");
|
|
634
|
+
return GAME_VERSION;
|
|
416
635
|
}
|
|
417
636
|
function parseNoticeVersion(text2) {
|
|
418
637
|
const moduleMatch = text2.match(/Object\.defineProperty\(exports,"checkNotice"[\s\S]{0,8000}?setCookie\)\("notice_version",([A-Za-z_$][\w$]*)\)/);
|
|
@@ -436,24 +655,46 @@
|
|
|
436
655
|
}
|
|
437
656
|
function parseServerInfo(text2, baseUrl) {
|
|
438
657
|
const host = hostName(baseUrl);
|
|
439
|
-
const
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
658
|
+
const config = readBundleExports(text2, [
|
|
659
|
+
"LOCAL_DOMAIN",
|
|
660
|
+
"BASE_DOMAIN",
|
|
661
|
+
"TEST_DOMAIN",
|
|
662
|
+
"TEST_GAME_DOMAIN",
|
|
663
|
+
"GAME_DOMAINS",
|
|
664
|
+
"GAME_SERVER_NAMES",
|
|
665
|
+
"MASTER_DOMAIN",
|
|
666
|
+
"TEST_MASTER_DOMAIN"
|
|
667
|
+
]);
|
|
668
|
+
const domain = (value, name) => {
|
|
669
|
+
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)) {
|
|
670
|
+
throw new Error(`Invalid bundle export ${name}: expected a hostname`);
|
|
671
|
+
}
|
|
672
|
+
return value;
|
|
673
|
+
};
|
|
674
|
+
const localDomain = domain(config.LOCAL_DOMAIN, "LOCAL_DOMAIN");
|
|
675
|
+
const baseDomain = domain(config.BASE_DOMAIN, "BASE_DOMAIN");
|
|
676
|
+
const testDomain = domain(config.TEST_DOMAIN, "TEST_DOMAIN");
|
|
677
|
+
const testGameDomain = domain(config.TEST_GAME_DOMAIN, "TEST_GAME_DOMAIN");
|
|
678
|
+
const domains = config.GAME_DOMAINS;
|
|
679
|
+
const names = config.GAME_SERVER_NAMES;
|
|
680
|
+
if (!Array.isArray(domains) || !domains.length) throw new Error("Invalid bundle export GAME_DOMAINS: expected nonempty hostname array");
|
|
681
|
+
domains.forEach((value) => domain(value, "GAME_DOMAINS"));
|
|
682
|
+
if (!Array.isArray(names) || names.length !== domains.length || names.some((name) => typeof name !== "string")) {
|
|
683
|
+
throw new Error("Invalid bundle export GAME_SERVER_NAMES: expected one string per game domain");
|
|
684
|
+
}
|
|
444
685
|
const meta = {
|
|
445
686
|
localDomain,
|
|
446
687
|
baseDomain,
|
|
447
688
|
testDomain,
|
|
448
689
|
testGameDomain,
|
|
449
|
-
masterDomain:
|
|
450
|
-
testMasterDomain:
|
|
690
|
+
masterDomain: domain(config.MASTER_DOMAIN, "MASTER_DOMAIN"),
|
|
691
|
+
testMasterDomain: domain(config.TEST_MASTER_DOMAIN, "TEST_MASTER_DOMAIN")
|
|
451
692
|
};
|
|
452
693
|
if (host === localDomain) return { mode: "local", servers: [server(0, localDomain, "Local Test 1")], meta };
|
|
453
694
|
if (host === testDomain) return { mode: "test", servers: [server(0, testGameDomain, "Public Test")], meta };
|
|
454
695
|
return {
|
|
455
696
|
mode: "production",
|
|
456
|
-
servers: domains.map((
|
|
697
|
+
servers: domains.map((domain2, index) => server(index, domain2, names[index] || `Server ${index + 1}`)),
|
|
457
698
|
meta
|
|
458
699
|
};
|
|
459
700
|
}
|
|
@@ -473,6 +714,7 @@
|
|
|
473
714
|
init_constants();
|
|
474
715
|
init_runtime();
|
|
475
716
|
init_http();
|
|
717
|
+
init_bundle_metadata();
|
|
476
718
|
cache = /* @__PURE__ */ new Map();
|
|
477
719
|
ServerDirectory = class {
|
|
478
720
|
constructor(baseUrl = DEFAULT_BASE_URL) {
|
|
@@ -480,27 +722,38 @@
|
|
|
480
722
|
this.meta = null;
|
|
481
723
|
}
|
|
482
724
|
async load() {
|
|
483
|
-
if (cache.has(this.baseUrl))
|
|
484
|
-
|
|
485
|
-
|
|
725
|
+
if (!cache.has(this.baseUrl)) cache.set(this.baseUrl, this.#fetchMeta());
|
|
726
|
+
const pending = cache.get(this.baseUrl);
|
|
727
|
+
try {
|
|
728
|
+
this.meta = await pending;
|
|
729
|
+
} catch (error) {
|
|
730
|
+
if (cache.get(this.baseUrl) === pending) cache.delete(this.baseUrl);
|
|
731
|
+
throw error;
|
|
486
732
|
}
|
|
487
|
-
const promise = this.#fetchMeta();
|
|
488
|
-
cache.set(this.baseUrl, promise);
|
|
489
|
-
this.meta = await promise;
|
|
490
733
|
return this;
|
|
491
734
|
}
|
|
492
735
|
async version() {
|
|
493
736
|
await this.load();
|
|
494
|
-
|
|
495
|
-
|
|
737
|
+
try {
|
|
738
|
+
this.meta.version ??= parseGameVersion(this.meta.text);
|
|
739
|
+
return this.meta.version;
|
|
740
|
+
} catch (error) {
|
|
741
|
+
cache.delete(this.baseUrl);
|
|
742
|
+
throw error;
|
|
743
|
+
}
|
|
496
744
|
}
|
|
497
745
|
async list() {
|
|
498
746
|
return this.servers();
|
|
499
747
|
}
|
|
500
748
|
async servers() {
|
|
501
749
|
await this.load();
|
|
502
|
-
|
|
503
|
-
|
|
750
|
+
try {
|
|
751
|
+
this.meta.serverInfo ??= parseServerInfo(this.meta.text, this.baseUrl);
|
|
752
|
+
return this.meta.serverInfo.servers;
|
|
753
|
+
} catch (error) {
|
|
754
|
+
cache.delete(this.baseUrl);
|
|
755
|
+
throw error;
|
|
756
|
+
}
|
|
504
757
|
}
|
|
505
758
|
async get(id = null) {
|
|
506
759
|
return this.pick(id);
|
|
@@ -513,7 +766,7 @@
|
|
|
513
766
|
const response = await new HttpClient({ baseUrl: this.baseUrl }).request("index.html");
|
|
514
767
|
if (!response.ok) throw new Error(`Failed to fetch bundle: ${response.status} ${response.statusText}`);
|
|
515
768
|
const text2 = await response.text();
|
|
516
|
-
return { text: text2
|
|
769
|
+
return { text: text2 };
|
|
517
770
|
}
|
|
518
771
|
};
|
|
519
772
|
fetchGameVersion = (baseUrl = DEFAULT_BASE_URL) => new ServerDirectory(baseUrl).version();
|
|
@@ -521,6 +774,110 @@
|
|
|
521
774
|
}
|
|
522
775
|
});
|
|
523
776
|
|
|
777
|
+
// src/protocol/outbound/machine-config.js
|
|
778
|
+
init_constants();
|
|
779
|
+
function uint32(value, name) {
|
|
780
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value < 0 || value > 4294967295) {
|
|
781
|
+
throw new RangeError(`${name} must be an unsigned 32-bit integer`);
|
|
782
|
+
}
|
|
783
|
+
return value;
|
|
784
|
+
}
|
|
785
|
+
function encodeUnsigned(value) {
|
|
786
|
+
if (value < 64) return [value];
|
|
787
|
+
if (value < 256) return [128, value];
|
|
788
|
+
if (value < 65536) return [129, value & 255, value >>> 8];
|
|
789
|
+
return [130, value & 255, value >>> 8 & 255, value >>> 16 & 255, value >>> 24];
|
|
790
|
+
}
|
|
791
|
+
function encodeFloat(value, name, max) {
|
|
792
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value < 0 || value > max) {
|
|
793
|
+
throw new RangeError(`${name} must be a finite number between 0 and ${max}`);
|
|
794
|
+
}
|
|
795
|
+
const number = Math.fround(value);
|
|
796
|
+
if (Number.isInteger(number)) {
|
|
797
|
+
if (number < 64) return [number];
|
|
798
|
+
if (number < 128) return [132, number];
|
|
799
|
+
return [133, number & 255, number >>> 8];
|
|
800
|
+
}
|
|
801
|
+
const bytes = new Uint8Array(5);
|
|
802
|
+
bytes[0] = 136;
|
|
803
|
+
new DataView(bytes.buffer).setFloat32(1, number, true);
|
|
804
|
+
return [...bytes];
|
|
805
|
+
}
|
|
806
|
+
function section(name, values) {
|
|
807
|
+
const bytes = encoder.encode(name);
|
|
808
|
+
return [138, bytes.length, ...bytes, 0, 144, ...values, 145];
|
|
809
|
+
}
|
|
810
|
+
function message(target, action, sections) {
|
|
811
|
+
return Uint8Array.from([144, action, ...encodeUnsigned(uint32(target, "target")), ...sections.flat(), 145]);
|
|
812
|
+
}
|
|
813
|
+
function normalizeRankMask({ allowedRanks, rankMask } = {}) {
|
|
814
|
+
if (allowedRanks !== void 0 && rankMask !== void 0) {
|
|
815
|
+
throw new TypeError("provide allowedRanks or rankMask, not both");
|
|
816
|
+
}
|
|
817
|
+
if (rankMask !== void 0) {
|
|
818
|
+
const value = uint32(rankMask, "rankMask");
|
|
819
|
+
if (value > 7 && value !== 4294967295) throw new RangeError("rankMask must be 0\u20137 or 0xffffffff");
|
|
820
|
+
return value;
|
|
821
|
+
}
|
|
822
|
+
if (allowedRanks === void 0) return 4;
|
|
823
|
+
if (allowedRanks === "all") return 4294967295;
|
|
824
|
+
if (!Array.isArray(allowedRanks)) throw new TypeError('allowedRanks must be an array of rank names or "all"');
|
|
825
|
+
let mask = 0;
|
|
826
|
+
for (const rank of allowedRanks) {
|
|
827
|
+
const bit = { guest: 1, crew: 2, captain: 4 }[rank];
|
|
828
|
+
if (typeof rank !== "string" || !["guest", "crew", "captain"].includes(rank)) throw new RangeError(`unsupported rank: ${rank}`);
|
|
829
|
+
mask |= bit;
|
|
830
|
+
}
|
|
831
|
+
return mask;
|
|
832
|
+
}
|
|
833
|
+
function rankSection(config) {
|
|
834
|
+
return section("filter_ranks", encodeUnsigned(normalizeRankMask(config)));
|
|
835
|
+
}
|
|
836
|
+
function launcherSection({ angle = 0, power = 30 } = {}) {
|
|
837
|
+
return section("config_item_launcher", [...encodeFloat(angle, "angle", 360), ...encodeFloat(power, "power", 30)]);
|
|
838
|
+
}
|
|
839
|
+
function doorSections(config = {}, clipboard = false) {
|
|
840
|
+
if (!clipboard && config.orientation !== void 0) {
|
|
841
|
+
throw new TypeError("door orientation is only available for placement/clipboard configuration");
|
|
842
|
+
}
|
|
843
|
+
const sections = [rankSection(config)];
|
|
844
|
+
if (clipboard) {
|
|
845
|
+
const orientation = config.orientation ?? "vertical";
|
|
846
|
+
if (orientation !== "vertical" && orientation !== "horizontal") {
|
|
847
|
+
throw new RangeError('orientation must be "vertical" or "horizontal"');
|
|
848
|
+
}
|
|
849
|
+
sections.unshift(section("angle_symmetric", [orientation === "horizontal" ? 1 : 0]));
|
|
850
|
+
}
|
|
851
|
+
return sections;
|
|
852
|
+
}
|
|
853
|
+
function buildLauncherConfigData(entity, config = {}) {
|
|
854
|
+
return message(entity, 0, [launcherSection(config)]);
|
|
855
|
+
}
|
|
856
|
+
function buildLauncherCopyConfigData(config = {}) {
|
|
857
|
+
return message(8, 1, [launcherSection(config)]);
|
|
858
|
+
}
|
|
859
|
+
function buildLauncherPasteConfigData(entity, config = {}) {
|
|
860
|
+
return message(entity, 2, [launcherSection(config)]);
|
|
861
|
+
}
|
|
862
|
+
function buildDoorConfigData(entity, config = {}) {
|
|
863
|
+
return message(entity, 0, doorSections(config));
|
|
864
|
+
}
|
|
865
|
+
function buildDoorCopyConfigData(config = {}) {
|
|
866
|
+
return message(10, 1, doorSections(config, true));
|
|
867
|
+
}
|
|
868
|
+
function buildDoorPasteConfigData(entity, config = {}) {
|
|
869
|
+
return message(entity, 2, doorSections(config, true));
|
|
870
|
+
}
|
|
871
|
+
function buildSpawnPointConfigData(entity, config = {}) {
|
|
872
|
+
return message(entity, 0, [rankSection(config)]);
|
|
873
|
+
}
|
|
874
|
+
function buildSpawnPointCopyConfigData(config = {}) {
|
|
875
|
+
return message(9, 1, [rankSection(config)]);
|
|
876
|
+
}
|
|
877
|
+
function buildSpawnPointPasteConfigData(entity, config = {}) {
|
|
878
|
+
return message(entity, 2, [rankSection(config)]);
|
|
879
|
+
}
|
|
880
|
+
|
|
524
881
|
// src/network/connection.js
|
|
525
882
|
init_constants();
|
|
526
883
|
init_runtime();
|
|
@@ -594,8 +951,8 @@
|
|
|
594
951
|
});
|
|
595
952
|
}
|
|
596
953
|
var DisconnectError = class extends Error {
|
|
597
|
-
constructor(disconnect,
|
|
598
|
-
super(`${
|
|
954
|
+
constructor(disconnect, message2 = "Disconnected") {
|
|
955
|
+
super(`${message2}: ${disconnect.name ?? "Unknown"} (${disconnect.code})${disconnect.reason ? ` \u2014 ${disconnect.reason}` : ""}`);
|
|
599
956
|
this.name = "DisconnectError";
|
|
600
957
|
this.disconnect = disconnect;
|
|
601
958
|
}
|
|
@@ -629,290 +986,15 @@
|
|
|
629
986
|
const listeners = this.#listeners.get(type);
|
|
630
987
|
if (!listeners || listeners.size === 0) return;
|
|
631
988
|
for (const callback of listeners.size === 1 ? listeners : [...listeners]) {
|
|
632
|
-
try {
|
|
633
|
-
callback(...args);
|
|
634
|
-
} catch (error) {
|
|
635
|
-
if (type === "error" || !this.#listeners.has("error")) throw error;
|
|
636
|
-
this.emit("error", error);
|
|
637
|
-
}
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
|
-
};
|
|
641
|
-
|
|
642
|
-
// src/protocol/outbound/comms.js
|
|
643
|
-
var COMMS_MESSAGE_TYPE = 3;
|
|
644
|
-
function buildCommsMessage(message = "") {
|
|
645
|
-
return {
|
|
646
|
-
type: COMMS_MESSAGE_TYPE,
|
|
647
|
-
msg: String(message)
|
|
648
|
-
};
|
|
649
|
-
}
|
|
650
|
-
function normalizeCommsEvent(event) {
|
|
651
|
-
const rawMessages = Array.isArray(event?.msgs_text) ? event.msgs_text : [];
|
|
652
|
-
return {
|
|
653
|
-
...event,
|
|
654
|
-
entity: event?.ent_id != null && Number.isFinite(Number(event.ent_id)) ? Number(event.ent_id) : null,
|
|
655
|
-
rawMessages,
|
|
656
|
-
messages: rawMessages.map((message) => ({
|
|
657
|
-
raw: message,
|
|
658
|
-
text: flattenRichText(message)
|
|
659
|
-
}))
|
|
660
|
-
};
|
|
661
|
-
}
|
|
662
|
-
function flattenRichText(value) {
|
|
663
|
-
if (value == null) return "";
|
|
664
|
-
if (typeof value === "string") return value;
|
|
665
|
-
if (typeof value === "number" || typeof value === "boolean") return String(value);
|
|
666
|
-
if (Array.isArray(value)) return value.map(flattenRichText).join("");
|
|
667
|
-
if (typeof value === "object") {
|
|
668
|
-
if (Object.hasOwn(value, "c")) return flattenRichText(value.c);
|
|
669
|
-
if (Object.hasOwn(value, "text")) return flattenRichText(value.text);
|
|
670
|
-
}
|
|
671
|
-
return "";
|
|
672
|
-
}
|
|
673
|
-
|
|
674
|
-
// src/protocol/outbound/ship-management.js
|
|
675
|
-
var SHIP_MANAGEMENT_TYPE = 4;
|
|
676
|
-
var CREW_LOG_LENGTH = 500;
|
|
677
|
-
var SET_PRIVACY_ACTION = "set_privacy";
|
|
678
|
-
var GRAVITY_ACTION = "gravity";
|
|
679
|
-
var SET_PATRON_PERKS_ACTION = "set_patron_perks";
|
|
680
|
-
var STARTER_RECOVERY_ACTION = "starter_recovery";
|
|
681
|
-
var PLAYER_LIST_ACTION = "player_list";
|
|
682
|
-
var INVITE_RESET_ACTION = "invite_reset";
|
|
683
|
-
var SET_RANK_ACTION = "set_rank";
|
|
684
|
-
var KICK_ACTION = "kick";
|
|
685
|
-
var BAN_ACTION = "ban";
|
|
686
|
-
var UNBAN_ACTION = "unban";
|
|
687
|
-
var DEMOTE_SELF_ACTION = "demote_self";
|
|
688
|
-
var SAVE_SHIP_ACTION = "save_team";
|
|
689
|
-
var RENAME_REQUEST_ACTION = "rename_request";
|
|
690
|
-
var RENAME_COMMIT_ACTION = "rename_commit";
|
|
691
|
-
var GravityDirection = Object.freeze({
|
|
692
|
-
Down: "down",
|
|
693
|
-
Up: "up",
|
|
694
|
-
Left: "left",
|
|
695
|
-
Right: "right"
|
|
696
|
-
});
|
|
697
|
-
function normalizeGravityDirection(value) {
|
|
698
|
-
if (value === GravityDirection.Down || value === 0) return 0;
|
|
699
|
-
if (value === GravityDirection.Up || value === 1) return 1;
|
|
700
|
-
if (value === GravityDirection.Left || value === 2) return 2;
|
|
701
|
-
if (value === GravityDirection.Right || value === 3) return 3;
|
|
702
|
-
throw new RangeError('direction must be "down", "up", "left", "right", or an integer from 0 to 3');
|
|
703
|
-
}
|
|
704
|
-
function requireNonNegativeInteger(value, name) {
|
|
705
|
-
const number = Number(value);
|
|
706
|
-
if (!Number.isInteger(number) || number < 0) throw new RangeError(`${name} must be a non-negative integer`);
|
|
707
|
-
return number;
|
|
708
|
-
}
|
|
709
|
-
function normalizePrivacy(value) {
|
|
710
|
-
if (value === true || value === 1 || value === "private") return 1;
|
|
711
|
-
if (value === false || value === 0 || value === "public") return 0;
|
|
712
|
-
throw new RangeError(`privacy must be 0, 1, true, false, "public", or "private"`);
|
|
713
|
-
}
|
|
714
|
-
function normalizePlayerRef(value) {
|
|
715
|
-
return requireNonNegativeInteger(value, "refId");
|
|
716
|
-
}
|
|
717
|
-
function normalizePlayerRank(value) {
|
|
718
|
-
if (value === 0 || value === "guest") return 0;
|
|
719
|
-
if (value === 1 || value === "crew") return 1;
|
|
720
|
-
if (value === 3 || value === "captain") return 3;
|
|
721
|
-
throw new RangeError(`rank must be 0, 1, 3, "guest", "crew", or "captain"`);
|
|
722
|
-
}
|
|
723
|
-
function buildShipManagementMessage(act, arg = null, extra = null) {
|
|
724
|
-
if (typeof act !== "string" || !act) throw new TypeError(`act must be a non-empty string`);
|
|
725
|
-
const message = { type: SHIP_MANAGEMENT_TYPE, act, arg };
|
|
726
|
-
if (extra && typeof extra === "object") Object.assign(message, extra);
|
|
727
|
-
return message;
|
|
728
|
-
}
|
|
729
|
-
function buildShipPrivacyMessage(privacy) {
|
|
730
|
-
return buildShipManagementMessage(SET_PRIVACY_ACTION, normalizePrivacy(privacy));
|
|
731
|
-
}
|
|
732
|
-
function buildShipGravityMessage(direction) {
|
|
733
|
-
return buildShipManagementMessage(GRAVITY_ACTION, normalizeGravityDirection(direction));
|
|
734
|
-
}
|
|
735
|
-
function buildSetPatronPerksMessage(enabled) {
|
|
736
|
-
if (typeof enabled !== "boolean") throw new TypeError("enabled must be a boolean");
|
|
737
|
-
return buildShipManagementMessage(SET_PATRON_PERKS_ACTION, enabled);
|
|
738
|
-
}
|
|
739
|
-
function buildStarterRecoveryMessage(itemId) {
|
|
740
|
-
return buildShipManagementMessage(STARTER_RECOVERY_ACTION, requireNonNegativeInteger(itemId, "itemId"));
|
|
741
|
-
}
|
|
742
|
-
function buildPlayerListMessage() {
|
|
743
|
-
return buildShipManagementMessage(PLAYER_LIST_ACTION);
|
|
744
|
-
}
|
|
745
|
-
function buildInviteResetMessage() {
|
|
746
|
-
return buildShipManagementMessage(INVITE_RESET_ACTION);
|
|
747
|
-
}
|
|
748
|
-
function buildSetPlayerRankMessage(refId, rank) {
|
|
749
|
-
return buildShipManagementMessage(SET_RANK_ACTION, normalizePlayerRef(refId), { rank: normalizePlayerRank(rank) });
|
|
750
|
-
}
|
|
751
|
-
function buildKickPlayerMessage(refId) {
|
|
752
|
-
return buildShipManagementMessage(KICK_ACTION, normalizePlayerRef(refId));
|
|
753
|
-
}
|
|
754
|
-
function buildBanPlayerMessage(refId) {
|
|
755
|
-
return buildShipManagementMessage(BAN_ACTION, normalizePlayerRef(refId));
|
|
756
|
-
}
|
|
757
|
-
function buildUnbanPlayerMessage(refId) {
|
|
758
|
-
return buildShipManagementMessage(UNBAN_ACTION, normalizePlayerRef(refId));
|
|
759
|
-
}
|
|
760
|
-
function buildDemoteSelfMessage() {
|
|
761
|
-
return buildShipManagementMessage(DEMOTE_SELF_ACTION);
|
|
762
|
-
}
|
|
763
|
-
function buildSaveShipMessage() {
|
|
764
|
-
return buildShipManagementMessage(SAVE_SHIP_ACTION);
|
|
765
|
-
}
|
|
766
|
-
function buildShipRenameRequestMessage() {
|
|
767
|
-
return buildShipManagementMessage(RENAME_REQUEST_ACTION);
|
|
768
|
-
}
|
|
769
|
-
function buildShipRenameCommitMessage(name, color) {
|
|
770
|
-
if (typeof name !== "string") throw new TypeError("name must be a string");
|
|
771
|
-
if (name.length > 32) throw new RangeError("name must be at most 32 UTF-16 code units");
|
|
772
|
-
if (typeof color !== "string" || !/^#[0-9a-f]{6}$/i.test(color)) {
|
|
773
|
-
throw new TypeError("color must be a #RRGGBB hex string");
|
|
774
|
-
}
|
|
775
|
-
return buildShipManagementMessage(RENAME_COMMIT_ACTION, name, { arg2: color });
|
|
776
|
-
}
|
|
777
|
-
function normalizeShipConfig(event = {}) {
|
|
778
|
-
const source = event && typeof event === "object" ? event : {};
|
|
779
|
-
const config = source.config && typeof source.config === "object" ? source.config : {};
|
|
780
|
-
return {
|
|
781
|
-
privacy: config.privacy ?? null,
|
|
782
|
-
privacyName: config.privacy === 0 ? "public" : config.privacy === 1 ? "private" : null,
|
|
783
|
-
inviteKey: config.invite_key ?? null,
|
|
784
|
-
teamId: source.team_id ?? null,
|
|
785
|
-
patronPerks: Array.isArray(source.patron_perks) ? source.patron_perks.slice() : []
|
|
786
|
-
};
|
|
787
|
-
}
|
|
788
|
-
function normalizeCaptainSubrank(event = {}) {
|
|
789
|
-
const source = event && typeof event === "object" ? event : {};
|
|
790
|
-
return {
|
|
791
|
-
subrank: source.subrank ?? null,
|
|
792
|
-
enableCheats: Boolean(source.enable_cheats)
|
|
793
|
-
};
|
|
794
|
-
}
|
|
795
|
-
function normalizeCrewLog(event = {}, previous = null) {
|
|
796
|
-
const source = event && typeof event === "object" ? event : {};
|
|
797
|
-
const reset = Boolean(source.reset);
|
|
798
|
-
const amend = Boolean(source.amend);
|
|
799
|
-
const entries = reset ? [] : (previous?.entries || []).slice();
|
|
800
|
-
if (amend) entries.pop();
|
|
801
|
-
const changes = Array.isArray(source.entries) ? source.entries.map((entry) => {
|
|
802
|
-
const value = entry && typeof entry === "object" ? entry : {};
|
|
803
|
-
return {
|
|
804
|
-
icon: value.icon ?? null,
|
|
805
|
-
text: flattenRichText(value.text),
|
|
806
|
-
rawText: value.text ?? null,
|
|
807
|
-
count: value.count ?? 1,
|
|
808
|
-
refId: value.ref ?? null,
|
|
809
|
-
secondaryRefId: value.ref2 ?? null
|
|
810
|
-
};
|
|
811
|
-
}) : [];
|
|
812
|
-
for (const entry of changes) entries.push(entry);
|
|
813
|
-
if (entries.length > CREW_LOG_LENGTH) entries.splice(0, entries.length - CREW_LOG_LENGTH);
|
|
814
|
-
return { entries, changes, reset, amend };
|
|
815
|
-
}
|
|
816
|
-
function normalizeShipPlayerList(event = {}, previous = null, currentCaptainSubrank = null) {
|
|
817
|
-
const source = event && typeof event === "object" ? event : {};
|
|
818
|
-
const changes = Array.isArray(source.player_list) ? source.player_list.map(normalizePlayerListChange) : [];
|
|
819
|
-
const removedPlayers = changes.filter((change) => change.remove && Number.isFinite(Number(change.refId))).map((change) => Number(change.refId));
|
|
820
|
-
const changedPlayers = changes.filter((change) => !change.remove).map(({ remove: _remove, ...change }) => change);
|
|
821
|
-
const players = mergePlayerListChanges(previous?.players, changes);
|
|
822
|
-
const ownerCaptainRank = ownerRankForPlayers(players);
|
|
823
|
-
applyPlayerControlState(players, currentCaptainSubrank);
|
|
824
|
-
applyPlayerControlState(changedPlayers, currentCaptainSubrank);
|
|
825
|
-
return {
|
|
826
|
-
ownerCaptainRank,
|
|
827
|
-
shipOwners: players.filter((player) => player.isShipOwner),
|
|
828
|
-
players,
|
|
829
|
-
changes: changedPlayers,
|
|
830
|
-
removedPlayers
|
|
831
|
-
};
|
|
832
|
-
}
|
|
833
|
-
function mergePlayerListChanges(previousPlayers, changes) {
|
|
834
|
-
if (!Array.isArray(previousPlayers) || !previousPlayers.length) return changes.filter((change) => !change.remove).map(({
|
|
835
|
-
remove: _remove,
|
|
836
|
-
...player
|
|
837
|
-
}) => ({ ...player }));
|
|
838
|
-
const existing = /* @__PURE__ */ new Map();
|
|
839
|
-
for (const player of previousPlayers) {
|
|
840
|
-
if (player?.refId == null) continue;
|
|
841
|
-
existing.set(player.refId, { ...player, isShipOwner: false });
|
|
842
|
-
}
|
|
843
|
-
const changedRefs = /* @__PURE__ */ new Set();
|
|
844
|
-
const merged = [];
|
|
845
|
-
for (const change of changes) {
|
|
846
|
-
if (change.refId == null) {
|
|
847
|
-
if (!change.remove) {
|
|
848
|
-
const { remove: _remove2, ...player2 } = change;
|
|
849
|
-
merged.push({ ...player2, isShipOwner: false });
|
|
989
|
+
try {
|
|
990
|
+
callback(...args);
|
|
991
|
+
} catch (error) {
|
|
992
|
+
if (type === "error" || !this.#listeners.has("error")) throw error;
|
|
993
|
+
this.emit("error", error);
|
|
850
994
|
}
|
|
851
|
-
continue;
|
|
852
|
-
}
|
|
853
|
-
changedRefs.add(change.refId);
|
|
854
|
-
if (change.remove) {
|
|
855
|
-
existing.delete(change.refId);
|
|
856
|
-
continue;
|
|
857
995
|
}
|
|
858
|
-
const { remove: _remove, ...changePlayer } = change;
|
|
859
|
-
const player = { ...existing.get(change.refId) || {}, ...changePlayer, isShipOwner: false };
|
|
860
|
-
existing.set(change.refId, player);
|
|
861
|
-
merged.push(player);
|
|
862
|
-
}
|
|
863
|
-
for (const player of previousPlayers) {
|
|
864
|
-
if (player?.refId == null || changedRefs.has(player.refId)) continue;
|
|
865
|
-
const retained = existing.get(player.refId);
|
|
866
|
-
if (retained) merged.push(retained);
|
|
867
996
|
}
|
|
868
|
-
|
|
869
|
-
}
|
|
870
|
-
function normalizePlayerListChange(entry = {}) {
|
|
871
|
-
const source = entry && typeof entry === "object" ? entry : {};
|
|
872
|
-
if (source._removed) return { refId: source.ref_id ?? null, remove: true };
|
|
873
|
-
return {
|
|
874
|
-
refId: source.ref_id ?? null,
|
|
875
|
-
remove: false,
|
|
876
|
-
discrim: source.discrim ?? null,
|
|
877
|
-
discrimColor: source.discrim_color ?? null,
|
|
878
|
-
teamRank: source.team_rank ?? null,
|
|
879
|
-
captainRank: source.captain_rank ?? null,
|
|
880
|
-
isCaptain: Number(source.captain_rank) > 0,
|
|
881
|
-
isShipOwner: false,
|
|
882
|
-
canBeManaged: false,
|
|
883
|
-
time: source.time ?? null,
|
|
884
|
-
items: Array.isArray(source.items) ? source.items.slice() : [],
|
|
885
|
-
aliasDiscrims: Array.isArray(source.alias_discrims) ? source.alias_discrims.slice() : [],
|
|
886
|
-
extraAliasCount: normalizeNonNegativeNumber(source.extra_aliases),
|
|
887
|
-
onlineCount: source.online_count ?? null
|
|
888
|
-
};
|
|
889
|
-
}
|
|
890
|
-
function normalizeNonNegativeNumber(value) {
|
|
891
|
-
const number = Number(value);
|
|
892
|
-
return Number.isFinite(number) && number > 0 ? number : 0;
|
|
893
|
-
}
|
|
894
|
-
function ownerRankForPlayers(players) {
|
|
895
|
-
const ranks = players.filter((player) => Number(player.captainRank) > 0).map((player) => Number(player.captainRank)).filter(Number.isFinite);
|
|
896
|
-
if (!ranks.length) return null;
|
|
897
|
-
const ownerRank = Math.min(...ranks);
|
|
898
|
-
for (const player of players) player.isShipOwner = Number(player.captainRank) === ownerRank;
|
|
899
|
-
return ownerRank;
|
|
900
|
-
}
|
|
901
|
-
function applyPlayerControlState(players, currentCaptainSubrank) {
|
|
902
|
-
const currentRank = currentCaptainRank(currentCaptainSubrank);
|
|
903
|
-
for (const player of players) player.canBeManaged = playerCanBeManagedBy(player, currentRank);
|
|
904
|
-
}
|
|
905
|
-
function currentCaptainRank(currentCaptainSubrank) {
|
|
906
|
-
const rank = Number(currentCaptainSubrank?.subrank);
|
|
907
|
-
return Number.isFinite(rank) && rank > 0 ? rank : null;
|
|
908
|
-
}
|
|
909
|
-
function playerCanBeManagedBy(player, currentRank) {
|
|
910
|
-
if (!Number.isFinite(currentRank) || !player) return false;
|
|
911
|
-
const targetCaptainRank = Number(player.captainRank);
|
|
912
|
-
if (Number.isFinite(targetCaptainRank) && targetCaptainRank > 0) return currentRank < targetCaptainRank;
|
|
913
|
-
const targetTeamRank = Number(player.teamRank);
|
|
914
|
-
return targetTeamRank === 0 || targetTeamRank === 1;
|
|
915
|
-
}
|
|
997
|
+
};
|
|
916
998
|
|
|
917
999
|
// src/client/domains/tips.js
|
|
918
1000
|
function timeoutValue(options) {
|
|
@@ -1076,25 +1158,6 @@
|
|
|
1076
1158
|
return this.#select(option);
|
|
1077
1159
|
});
|
|
1078
1160
|
}
|
|
1079
|
-
setRank(handle, rank, options = {}) {
|
|
1080
|
-
return this.#exclusive(async () => {
|
|
1081
|
-
const value = normalizePlayerRank(rank);
|
|
1082
|
-
const timeout = timeoutValue(options);
|
|
1083
|
-
if (!handle.exists()) throw new Error("Rank target no longer exists");
|
|
1084
|
-
if (handle.rank === value) return this.client;
|
|
1085
|
-
const text2 = { 0: "Restrict to Guests", 1: "Restrict to Crew", 3: "Restrict to Captains" }[value];
|
|
1086
|
-
await this.#open(handle, options);
|
|
1087
|
-
await waitFor(
|
|
1088
|
-
this.client,
|
|
1089
|
-
"model",
|
|
1090
|
-
() => handle.rank === value,
|
|
1091
|
-
timeout,
|
|
1092
|
-
"access rank update",
|
|
1093
|
-
() => this.#select(text2)
|
|
1094
|
-
);
|
|
1095
|
-
return this.client;
|
|
1096
|
-
});
|
|
1097
|
-
}
|
|
1098
1161
|
};
|
|
1099
1162
|
|
|
1100
1163
|
// src/client/core.js
|
|
@@ -4654,7 +4717,7 @@
|
|
|
4654
4717
|
[4, { name: "motion_aux", packedBits: [{ bit: 8, offset: 33 }], fields: numericFields({ 1: 20, 2: 24, 4: 28 }) }],
|
|
4655
4718
|
[5, {
|
|
4656
4719
|
name: "entity_health",
|
|
4657
|
-
//
|
|
4720
|
+
// Bar half-width and vertical offset start at 10 (one world unit).
|
|
4658
4721
|
// Field values on the wire are deltas relative to these defaults.
|
|
4659
4722
|
defaults: { q28: 10, q32: 10 },
|
|
4660
4723
|
fields: numericFields({ 1: 20, 2: 24, 4: 28, 8: 32 })
|
|
@@ -4938,7 +5001,11 @@
|
|
|
4938
5001
|
record.q44 = (record.q44 || 0) + reader.readFieldDelta();
|
|
4939
5002
|
}
|
|
4940
5003
|
}
|
|
4941
|
-
}]
|
|
5004
|
+
}],
|
|
5005
|
+
// Append new wire components without shifting stable Dredless table IDs.
|
|
5006
|
+
[79, { name: "launcher_config", defaults: { q20: 0, q24: 300 }, fields: numericFields({ 1: 20, 2: 24 }) }],
|
|
5007
|
+
[80, { name: "rank_filter", defaults: { q20: 4 }, fields: numericFields({ 1: 20 }) }],
|
|
5008
|
+
[81, { name: "spawn_point", fields: [] }]
|
|
4942
5009
|
]);
|
|
4943
5010
|
for (const spec of MODEL_TABLE_SPECS.values()) {
|
|
4944
5011
|
for (const blob of spec.blobs || []) blob.key = blobKey(blob.offset);
|
|
@@ -5035,7 +5102,10 @@
|
|
|
5035
5102
|
[166, 75],
|
|
5036
5103
|
[167, 76],
|
|
5037
5104
|
[168, 78],
|
|
5038
|
-
[169, 77]
|
|
5105
|
+
[169, 77],
|
|
5106
|
+
[170, 79],
|
|
5107
|
+
[171, 80],
|
|
5108
|
+
[172, 81]
|
|
5039
5109
|
]);
|
|
5040
5110
|
var MASK_ONLY_TABLES = /* @__PURE__ */ new Set([13, 22, 23, 27, 28, 30, 36, 40, 46, 48, 52, 58, 64, 65, 66, 68, 73, 74]);
|
|
5041
5111
|
var ENTITY_FOOTPRINTS = /* @__PURE__ */ new Map([
|
|
@@ -5389,6 +5459,8 @@
|
|
|
5389
5459
|
hp,
|
|
5390
5460
|
maxHp,
|
|
5391
5461
|
ratio: typeof hp === "number" && typeof maxHp === "number" && maxHp !== 0 ? hp / maxHp : null,
|
|
5462
|
+
barWidth: (record.q28 ?? 10) / 5,
|
|
5463
|
+
barOffsetY: (record.q32 ?? 10) / 10,
|
|
5392
5464
|
state: cloneRecord(record)
|
|
5393
5465
|
};
|
|
5394
5466
|
}
|
|
@@ -5711,6 +5783,7 @@
|
|
|
5711
5783
|
return {
|
|
5712
5784
|
entity,
|
|
5713
5785
|
...itemSummary(itemId, count),
|
|
5786
|
+
boxSprite: Boolean(itemRecord?.q29),
|
|
5714
5787
|
width: sizeRecord.q20 ?? null,
|
|
5715
5788
|
height: sizeRecord.q24 ?? null,
|
|
5716
5789
|
itemState: cloneRecord(itemRecord || healthRecord || {}),
|
|
@@ -5876,15 +5949,17 @@
|
|
|
5876
5949
|
if (!Number.isFinite(Number(value))) return null;
|
|
5877
5950
|
return (Number(value) % 360 + 360) % 360;
|
|
5878
5951
|
}
|
|
5879
|
-
function summarizeItemLauncher(entity, typeId, launcherRecord) {
|
|
5880
|
-
if (typeId !== ITEM_LAUNCHER_TYPE_ID || !launcherRecord) return null;
|
|
5881
|
-
const angleRadians = numberOrNull(launcherRecord.q32 ?? 0, 200);
|
|
5952
|
+
function summarizeItemLauncher(entity, typeId, launcherRecord, configRecord = null) {
|
|
5953
|
+
if (typeId !== ITEM_LAUNCHER_TYPE_ID || !launcherRecord && !configRecord) return null;
|
|
5954
|
+
const angleRadians = configRecord ? (configRecord.q20 ?? 0) / 10 * Math.PI / 180 : numberOrNull(launcherRecord.q32 ?? 0, 200);
|
|
5882
5955
|
return {
|
|
5883
5956
|
entity,
|
|
5884
|
-
angleRaw: launcherRecord.q32 ?? null,
|
|
5957
|
+
angleRaw: configRecord ? configRecord.q20 ?? 0 : launcherRecord.q32 ?? null,
|
|
5885
5958
|
angleRadians,
|
|
5886
5959
|
angleDegrees: angleRadians == null ? null : normalizeDegrees(angleRadians * 180 / Math.PI),
|
|
5887
|
-
|
|
5960
|
+
power: configRecord ? (configRecord.q24 ?? 300) / 10 : null,
|
|
5961
|
+
configState: configRecord ? cloneRecord(configRecord) : null,
|
|
5962
|
+
state: cloneRecord(launcherRecord || {})
|
|
5888
5963
|
};
|
|
5889
5964
|
}
|
|
5890
5965
|
function summarizeSign(entity, signRecord) {
|
|
@@ -5905,23 +5980,28 @@
|
|
|
5905
5980
|
state: cloneRecord(projectorRecord || {})
|
|
5906
5981
|
};
|
|
5907
5982
|
}
|
|
5908
|
-
function
|
|
5909
|
-
const
|
|
5983
|
+
function summarizeRankFilter(legacyRecord, filterRecord, modern = false) {
|
|
5984
|
+
const legacyRank = Number.isFinite(Number(legacyRecord?.q20)) ? Number(legacyRecord.q20) : 0;
|
|
5985
|
+
const rankMask = filterRecord ? (filterRecord.q20 ?? 4) >>> 0 : modern ? null : { 0: 7, 1: 6, 3: 4 }[legacyRank] ?? 0;
|
|
5986
|
+
return {
|
|
5987
|
+
rankMask,
|
|
5988
|
+
allowedRanks: rankMask == null ? null : ["guest", "crew", "captain"].filter((_, i) => rankMask & 1 << i),
|
|
5989
|
+
allRanks: rankMask === 4294967295,
|
|
5990
|
+
rankState: cloneRecord(filterRecord || legacyRecord || {})
|
|
5991
|
+
};
|
|
5992
|
+
}
|
|
5993
|
+
function summarizeSpawnPoint(entity, spawnRecord, filterRecord = null, markerRecord = null) {
|
|
5910
5994
|
return {
|
|
5911
5995
|
entity,
|
|
5912
|
-
|
|
5913
|
-
|
|
5914
|
-
state: cloneRecord(spawnRecord || {})
|
|
5996
|
+
...summarizeRankFilter(spawnRecord, filterRecord, markerRecord != null),
|
|
5997
|
+
state: cloneRecord(markerRecord || spawnRecord || {})
|
|
5915
5998
|
};
|
|
5916
5999
|
}
|
|
5917
|
-
function summarizeDoor(entity, rankRecord, doorRecord) {
|
|
5918
|
-
const rank = Number.isFinite(Number(rankRecord?.q20)) ? Number(rankRecord.q20) : 0;
|
|
6000
|
+
function summarizeDoor(entity, rankRecord, doorRecord, filterRecord = null) {
|
|
5919
6001
|
return {
|
|
5920
6002
|
entity,
|
|
5921
|
-
|
|
5922
|
-
rankName: enumValueName(TEAM_RANK_NAMES, rank),
|
|
6003
|
+
...summarizeRankFilter(rankRecord, filterRecord),
|
|
5923
6004
|
open: doorRecord?.q21 === 1,
|
|
5924
|
-
rankState: cloneRecord(rankRecord || {}),
|
|
5925
6005
|
state: cloneRecord(doorRecord || {})
|
|
5926
6006
|
};
|
|
5927
6007
|
}
|
|
@@ -6433,9 +6513,9 @@
|
|
|
6433
6513
|
if (reader.trailingZeroOnly()) break;
|
|
6434
6514
|
throw new Error(`unsupported model_data section tag ${tag}`);
|
|
6435
6515
|
}
|
|
6436
|
-
const
|
|
6437
|
-
update.sections.push(
|
|
6438
|
-
for (const record of
|
|
6516
|
+
const section2 = this.#readSection(reader, tag, tableId);
|
|
6517
|
+
update.sections.push(section2);
|
|
6518
|
+
for (const record of section2.records) update.changedEntities.add(record.entity);
|
|
6439
6519
|
}
|
|
6440
6520
|
} catch (error) {
|
|
6441
6521
|
update.error = error;
|
|
@@ -6574,10 +6654,10 @@
|
|
|
6574
6654
|
#updateDerived(update) {
|
|
6575
6655
|
if (!this._derived) return;
|
|
6576
6656
|
if (!update.removals.length && !update.changedEntities.size) return;
|
|
6577
|
-
for (const
|
|
6578
|
-
for (const record of
|
|
6657
|
+
for (const section2 of update.sections) {
|
|
6658
|
+
for (const record of section2.records || []) this.#addDerivedEntityTable(record.entity, section2.table);
|
|
6579
6659
|
}
|
|
6580
|
-
if (update.sections.some((
|
|
6660
|
+
if (update.sections.some((section2) => section2.table === 12)) {
|
|
6581
6661
|
for (const entityId of this.table(55).keys()) update.changedEntities.add(entityId);
|
|
6582
6662
|
}
|
|
6583
6663
|
for (const entityId of update.removals) this.#removeDerivedEntity(entityId);
|
|
@@ -6588,9 +6668,9 @@
|
|
|
6588
6668
|
#updateNavigationUnitAutoWarp(update) {
|
|
6589
6669
|
const trackedBeforeUpdate = new Set(this.#navigationUnitAutoWarp.keys());
|
|
6590
6670
|
const initializedThisUpdate = /* @__PURE__ */ new Set();
|
|
6591
|
-
for (const
|
|
6592
|
-
if (
|
|
6593
|
-
for (const changed of
|
|
6671
|
+
for (const section2 of update.sections || []) {
|
|
6672
|
+
if (section2.table !== 78) continue;
|
|
6673
|
+
for (const changed of section2.records || []) {
|
|
6594
6674
|
const typeId = entityTypeIdFromRecord2(this.record(7, changed.entity));
|
|
6595
6675
|
if (typeId !== NAVIGATION_UNIT_TYPE_ID2) continue;
|
|
6596
6676
|
const record = this.record(78, changed.entity);
|
|
@@ -6653,12 +6733,12 @@
|
|
|
6653
6733
|
}
|
|
6654
6734
|
}
|
|
6655
6735
|
#updateHelmOccupancy(update) {
|
|
6656
|
-
const table7 = update.sections.find((
|
|
6736
|
+
const table7 = update.sections.find((section2) => section2.table === 7);
|
|
6657
6737
|
if (!table7) return;
|
|
6658
6738
|
const changedZoomState = /* @__PURE__ */ new Map();
|
|
6659
|
-
for (const
|
|
6660
|
-
if (
|
|
6661
|
-
for (const changed of
|
|
6739
|
+
for (const section2 of update.sections) {
|
|
6740
|
+
if (section2.table !== 55) continue;
|
|
6741
|
+
for (const changed of section2.records) {
|
|
6662
6742
|
if (!(changed.mask & 16)) continue;
|
|
6663
6743
|
const player = this.record(55, changed.entity);
|
|
6664
6744
|
changedZoomState.set(changed.entity, Boolean(player?.q107));
|
|
@@ -6677,7 +6757,7 @@
|
|
|
6677
6757
|
}
|
|
6678
6758
|
}
|
|
6679
6759
|
#updateCommsStationOccupancy(update) {
|
|
6680
|
-
const table7 = update.sections.find((
|
|
6760
|
+
const table7 = update.sections.find((section2) => section2.table === 7);
|
|
6681
6761
|
if (!table7) return;
|
|
6682
6762
|
for (const changed of table7.records) {
|
|
6683
6763
|
const record = this.record(7, changed.entity);
|
|
@@ -7003,7 +7083,7 @@
|
|
|
7003
7083
|
const thruster = summarizeThruster2(entityId, typeId, thrusterRecord);
|
|
7004
7084
|
const pusher = summarizePusher2(entityId, pusherRecord, loaderFilterSlotsRecord);
|
|
7005
7085
|
const pusherBeam = summarizePusherBeam2(entityId, pusherBeamRecord);
|
|
7006
|
-
const launcher = summarizeItemLauncher2(entityId, typeId, launcherRecord);
|
|
7086
|
+
const launcher = summarizeItemLauncher2(entityId, typeId, launcherRecord, rec(79));
|
|
7007
7087
|
const loader = typeId === LOADER_TYPE_ID2 || typeId == null && (loaderRecord || loaderFilterRecord || loaderFilterSlotsRecord) ? summarizeLoader2(entityId, loaderRecord, loaderFilterRecord, loaderFilterSlotsRecord, typeId === LOADER_TYPE_ID2, itemHolderRecord) : null;
|
|
7008
7088
|
const cargoHatch = summarizeCargoHatch2(entityId, typeId, loaderFilterRecord, loaderFilterSlotsRecord, rec(45));
|
|
7009
7089
|
const navigationUnit = summarizeNavigationUnit2(entityId, typeId, navigationRecord, this.#navigationUnitAutoWarp.get(entityId));
|
|
@@ -7020,8 +7100,8 @@
|
|
|
7020
7100
|
const helm = summarizeHelm2(entityId, typeId, this.#helmOccupied.get(entityId));
|
|
7021
7101
|
const commsStation = summarizeCommsStation2(entityId, typeId, commsStationRecord, this.#commsStationOccupied.get(entityId));
|
|
7022
7102
|
const sign = typeId === 218 ? summarizeSign2(entityId, signRecord) : null;
|
|
7023
|
-
const spawnPoint = typeId === 219 ? summarizeSpawnPoint2(entityId, spawnPointRecord) : null;
|
|
7024
|
-
const door = typeId === 220 ? summarizeDoor2(entityId, spawnPointRecord, doorRecord) : null;
|
|
7103
|
+
const spawnPoint = typeId === 219 || rec(81) ? summarizeSpawnPoint2(entityId, spawnPointRecord, rec(80), rec(81)) : null;
|
|
7104
|
+
const door = typeId === 220 ? summarizeDoor2(entityId, spawnPointRecord, doorRecord, rec(80)) : null;
|
|
7025
7105
|
const shipSize = shipControl && this.isOverworld ? summarizeShipSize2(entityId, rec(3)) : null;
|
|
7026
7106
|
const hoverOutline = summarizeHoverOutline2(entityId, crateSizeRecord);
|
|
7027
7107
|
const expandoBox = isExpandoBox ? summarizeExpandoBox2(entityId, itemHolderRecord, expandoSizeRecord) : null;
|
|
@@ -7279,7 +7359,7 @@
|
|
|
7279
7359
|
return this.#readSectionRecords(reader, tag, tableId, spec);
|
|
7280
7360
|
}
|
|
7281
7361
|
#readSectionRecords(reader, tag, tableId, spec) {
|
|
7282
|
-
const
|
|
7362
|
+
const section2 = { tag, table: tableId, name: spec?.name || null, records: [] };
|
|
7283
7363
|
let entity = 0;
|
|
7284
7364
|
while (reader.remaining > 0) {
|
|
7285
7365
|
const recordOffset = reader.offset;
|
|
@@ -7306,9 +7386,9 @@
|
|
|
7306
7386
|
throw new Error(`model table ${tableId} tag ${tag} entity ${entity} mask ${mask} offset ${reader.offset}: ${error.message}`);
|
|
7307
7387
|
}
|
|
7308
7388
|
const changed = { entity, mask };
|
|
7309
|
-
|
|
7389
|
+
section2.records.push(changed);
|
|
7310
7390
|
}
|
|
7311
|
-
return
|
|
7391
|
+
return section2;
|
|
7312
7392
|
}
|
|
7313
7393
|
#getRecord(tableId, entity) {
|
|
7314
7394
|
if (!this.tables.has(tableId)) this.tables.set(tableId, /* @__PURE__ */ new Map());
|
|
@@ -7364,11 +7444,11 @@
|
|
|
7364
7444
|
removals: update.removals.length,
|
|
7365
7445
|
unknownTags: update.unknownTags,
|
|
7366
7446
|
error: update.error?.message || null,
|
|
7367
|
-
sections: update.sections.map((
|
|
7368
|
-
tag:
|
|
7369
|
-
table:
|
|
7370
|
-
name:
|
|
7371
|
-
records:
|
|
7447
|
+
sections: update.sections.map((section2) => ({
|
|
7448
|
+
tag: section2.tag,
|
|
7449
|
+
table: section2.table,
|
|
7450
|
+
name: section2.name,
|
|
7451
|
+
records: section2.records.length
|
|
7372
7452
|
}))
|
|
7373
7453
|
};
|
|
7374
7454
|
}
|
|
@@ -8046,12 +8126,44 @@
|
|
|
8046
8126
|
|
|
8047
8127
|
// src/protocol/outbound/chat.js
|
|
8048
8128
|
var CHAT_MESSAGE_TYPE = 2;
|
|
8049
|
-
function buildChatMessage(
|
|
8129
|
+
function buildChatMessage(message2 = "") {
|
|
8050
8130
|
return {
|
|
8051
8131
|
type: CHAT_MESSAGE_TYPE,
|
|
8052
|
-
msg: String(
|
|
8132
|
+
msg: String(message2)
|
|
8133
|
+
};
|
|
8134
|
+
}
|
|
8135
|
+
|
|
8136
|
+
// src/protocol/outbound/comms.js
|
|
8137
|
+
var COMMS_MESSAGE_TYPE = 3;
|
|
8138
|
+
function buildCommsMessage(message2 = "") {
|
|
8139
|
+
return {
|
|
8140
|
+
type: COMMS_MESSAGE_TYPE,
|
|
8141
|
+
msg: String(message2)
|
|
8142
|
+
};
|
|
8143
|
+
}
|
|
8144
|
+
function normalizeCommsEvent(event) {
|
|
8145
|
+
const rawMessages = Array.isArray(event?.msgs_text) ? event.msgs_text : [];
|
|
8146
|
+
return {
|
|
8147
|
+
...event,
|
|
8148
|
+
entity: event?.ent_id != null && Number.isFinite(Number(event.ent_id)) ? Number(event.ent_id) : null,
|
|
8149
|
+
rawMessages,
|
|
8150
|
+
messages: rawMessages.map((message2) => ({
|
|
8151
|
+
raw: message2,
|
|
8152
|
+
text: flattenRichText(message2)
|
|
8153
|
+
}))
|
|
8053
8154
|
};
|
|
8054
8155
|
}
|
|
8156
|
+
function flattenRichText(value) {
|
|
8157
|
+
if (value == null) return "";
|
|
8158
|
+
if (typeof value === "string") return value;
|
|
8159
|
+
if (typeof value === "number" || typeof value === "boolean") return String(value);
|
|
8160
|
+
if (Array.isArray(value)) return value.map(flattenRichText).join("");
|
|
8161
|
+
if (typeof value === "object") {
|
|
8162
|
+
if (Object.hasOwn(value, "c")) return flattenRichText(value.c);
|
|
8163
|
+
if (Object.hasOwn(value, "text")) return flattenRichText(value.text);
|
|
8164
|
+
}
|
|
8165
|
+
return "";
|
|
8166
|
+
}
|
|
8055
8167
|
|
|
8056
8168
|
// src/protocol/outbound/commands.js
|
|
8057
8169
|
init_constants();
|
|
@@ -8272,81 +8384,324 @@
|
|
|
8272
8384
|
if (!EQUIPMENT_SLOT_NAMES.has(normalized)) {
|
|
8273
8385
|
throw new RangeError(`equipment slot must be an EquipmentSlot value`);
|
|
8274
8386
|
}
|
|
8275
|
-
return normalized;
|
|
8387
|
+
return normalized;
|
|
8388
|
+
}
|
|
8389
|
+
function equipmentSlotName(slot) {
|
|
8390
|
+
return EQUIPMENT_SLOT_NAMES.get(Number(slot)) ?? null;
|
|
8391
|
+
}
|
|
8392
|
+
function buildInventoryDragCommand(source, target, split = false) {
|
|
8393
|
+
return {
|
|
8394
|
+
drag: {
|
|
8395
|
+
source: normalizeInventoryIndex(source, "source"),
|
|
8396
|
+
target: normalizeInventoryIndex(target, "target"),
|
|
8397
|
+
split: Boolean(split)
|
|
8398
|
+
}
|
|
8399
|
+
};
|
|
8400
|
+
}
|
|
8401
|
+
function normalizeInventoryEvent(event) {
|
|
8402
|
+
const items = Array.isArray(event?.items) ? event.items : [];
|
|
8403
|
+
const counts = Array.isArray(event?.item_counts) ? event.item_counts : [];
|
|
8404
|
+
const rawHotbarSize = Number(event?.general_slots ?? 0);
|
|
8405
|
+
const hotbarSize = Number.isFinite(rawHotbarSize) && rawHotbarSize > 0 ? Math.trunc(rawHotbarSize) : 0;
|
|
8406
|
+
const slotSnapshot = (index, kind) => {
|
|
8407
|
+
const count = normalizeCount(counts[index]);
|
|
8408
|
+
const itemId = normalizeItemId(items[index], count);
|
|
8409
|
+
return {
|
|
8410
|
+
index,
|
|
8411
|
+
itemId,
|
|
8412
|
+
itemName: itemNameFromId(itemId),
|
|
8413
|
+
count,
|
|
8414
|
+
kind,
|
|
8415
|
+
equipmentSlot: equipmentSlotName(index),
|
|
8416
|
+
empty: itemId == null || count <= 0
|
|
8417
|
+
};
|
|
8418
|
+
};
|
|
8419
|
+
const slotsByIndex = /* @__PURE__ */ new Map();
|
|
8420
|
+
for (let index = 0; index < hotbarSize; index++) {
|
|
8421
|
+
slotsByIndex.set(index, slotSnapshot(index, "hotbar"));
|
|
8422
|
+
}
|
|
8423
|
+
slotsByIndex.set(EQUIPMENT_SLOT_INDEXES.head, slotSnapshot(EQUIPMENT_SLOT_INDEXES.head, "equipment"));
|
|
8424
|
+
slotsByIndex.set(EQUIPMENT_SLOT_INDEXES.face, slotSnapshot(EQUIPMENT_SLOT_INDEXES.face, "equipment"));
|
|
8425
|
+
slotsByIndex.set(EQUIPMENT_SLOT_INDEXES.body, slotSnapshot(EQUIPMENT_SLOT_INDEXES.body, "equipment"));
|
|
8426
|
+
slotsByIndex.set(EQUIPMENT_SLOT_INDEXES.back, slotSnapshot(EQUIPMENT_SLOT_INDEXES.back, "equipment"));
|
|
8427
|
+
slotsByIndex.set(EQUIPMENT_SLOT_INDEXES.hands, slotSnapshot(EQUIPMENT_SLOT_INDEXES.hands, "equipment"));
|
|
8428
|
+
slotsByIndex.set(EQUIPMENT_SLOT_INDEXES.feet, slotSnapshot(EQUIPMENT_SLOT_INDEXES.feet, "equipment"));
|
|
8429
|
+
const slots = [...slotsByIndex.values()].sort((a, b) => a.index - b.index);
|
|
8430
|
+
const hotbar = slots.filter((slot) => slot.kind === "hotbar");
|
|
8431
|
+
const equipment = {
|
|
8432
|
+
head: slotsByIndex.get(EQUIPMENT_SLOT_INDEXES.head),
|
|
8433
|
+
face: slotsByIndex.get(EQUIPMENT_SLOT_INDEXES.face),
|
|
8434
|
+
body: slotsByIndex.get(EQUIPMENT_SLOT_INDEXES.body),
|
|
8435
|
+
back: slotsByIndex.get(EQUIPMENT_SLOT_INDEXES.back),
|
|
8436
|
+
hands: slotsByIndex.get(EQUIPMENT_SLOT_INDEXES.hands),
|
|
8437
|
+
feet: slotsByIndex.get(EQUIPMENT_SLOT_INDEXES.feet)
|
|
8438
|
+
};
|
|
8439
|
+
return {
|
|
8440
|
+
type: "inventory",
|
|
8441
|
+
filter: event?.filter,
|
|
8442
|
+
hotbarSize,
|
|
8443
|
+
slots,
|
|
8444
|
+
hotbar,
|
|
8445
|
+
equipment
|
|
8446
|
+
};
|
|
8447
|
+
}
|
|
8448
|
+
function normalizeInventoryIndex(value, name) {
|
|
8449
|
+
const number = Number(value);
|
|
8450
|
+
if (!Number.isInteger(number) || number < 0) throw new RangeError(`${name} must be a non-negative integer inventory slot`);
|
|
8451
|
+
return number;
|
|
8452
|
+
}
|
|
8453
|
+
function normalizeCount(value) {
|
|
8454
|
+
const number = Number(value ?? 0);
|
|
8455
|
+
return Number.isFinite(number) ? number : 0;
|
|
8456
|
+
}
|
|
8457
|
+
function normalizeItemId(value, count) {
|
|
8458
|
+
if (value == null) return null;
|
|
8459
|
+
const number = Number(value);
|
|
8460
|
+
if (!Number.isFinite(number)) return null;
|
|
8461
|
+
return number === 0 && count === 0 ? null : number;
|
|
8462
|
+
}
|
|
8463
|
+
|
|
8464
|
+
// src/protocol/outbound/ship-management.js
|
|
8465
|
+
var SHIP_MANAGEMENT_TYPE = 4;
|
|
8466
|
+
var CREW_LOG_LENGTH = 500;
|
|
8467
|
+
var SET_PRIVACY_ACTION = "set_privacy";
|
|
8468
|
+
var GRAVITY_ACTION = "gravity";
|
|
8469
|
+
var SET_PATRON_PERKS_ACTION = "set_patron_perks";
|
|
8470
|
+
var STARTER_RECOVERY_ACTION = "starter_recovery";
|
|
8471
|
+
var PLAYER_LIST_ACTION = "player_list";
|
|
8472
|
+
var INVITE_RESET_ACTION = "invite_reset";
|
|
8473
|
+
var SET_RANK_ACTION = "set_rank";
|
|
8474
|
+
var KICK_ACTION = "kick";
|
|
8475
|
+
var BAN_ACTION = "ban";
|
|
8476
|
+
var UNBAN_ACTION = "unban";
|
|
8477
|
+
var DEMOTE_SELF_ACTION = "demote_self";
|
|
8478
|
+
var SAVE_SHIP_ACTION = "save_team";
|
|
8479
|
+
var RENAME_REQUEST_ACTION = "rename_request";
|
|
8480
|
+
var RENAME_COMMIT_ACTION = "rename_commit";
|
|
8481
|
+
var GravityDirection = Object.freeze({
|
|
8482
|
+
Down: "down",
|
|
8483
|
+
Up: "up",
|
|
8484
|
+
Left: "left",
|
|
8485
|
+
Right: "right"
|
|
8486
|
+
});
|
|
8487
|
+
function normalizeGravityDirection(value) {
|
|
8488
|
+
if (value === GravityDirection.Down || value === 0) return 0;
|
|
8489
|
+
if (value === GravityDirection.Up || value === 1) return 1;
|
|
8490
|
+
if (value === GravityDirection.Left || value === 2) return 2;
|
|
8491
|
+
if (value === GravityDirection.Right || value === 3) return 3;
|
|
8492
|
+
throw new RangeError('direction must be "down", "up", "left", "right", or an integer from 0 to 3');
|
|
8493
|
+
}
|
|
8494
|
+
function requireNonNegativeInteger(value, name) {
|
|
8495
|
+
const number = Number(value);
|
|
8496
|
+
if (!Number.isInteger(number) || number < 0) throw new RangeError(`${name} must be a non-negative integer`);
|
|
8497
|
+
return number;
|
|
8498
|
+
}
|
|
8499
|
+
function normalizePrivacy(value) {
|
|
8500
|
+
if (value === true || value === 1 || value === "private") return 1;
|
|
8501
|
+
if (value === false || value === 0 || value === "public") return 0;
|
|
8502
|
+
throw new RangeError(`privacy must be 0, 1, true, false, "public", or "private"`);
|
|
8503
|
+
}
|
|
8504
|
+
function normalizePlayerRef(value) {
|
|
8505
|
+
return requireNonNegativeInteger(value, "refId");
|
|
8506
|
+
}
|
|
8507
|
+
function normalizePlayerRank(value) {
|
|
8508
|
+
if (value === 0 || value === "guest") return 0;
|
|
8509
|
+
if (value === 1 || value === "crew") return 1;
|
|
8510
|
+
if (value === 3 || value === "captain") return 3;
|
|
8511
|
+
throw new RangeError(`rank must be 0, 1, 3, "guest", "crew", or "captain"`);
|
|
8512
|
+
}
|
|
8513
|
+
function buildShipManagementMessage(act, arg = null, extra = null) {
|
|
8514
|
+
if (typeof act !== "string" || !act) throw new TypeError(`act must be a non-empty string`);
|
|
8515
|
+
const message2 = { type: SHIP_MANAGEMENT_TYPE, act, arg };
|
|
8516
|
+
if (extra && typeof extra === "object") Object.assign(message2, extra);
|
|
8517
|
+
return message2;
|
|
8518
|
+
}
|
|
8519
|
+
function buildShipPrivacyMessage(privacy) {
|
|
8520
|
+
return buildShipManagementMessage(SET_PRIVACY_ACTION, normalizePrivacy(privacy));
|
|
8521
|
+
}
|
|
8522
|
+
function buildShipGravityMessage(direction) {
|
|
8523
|
+
return buildShipManagementMessage(GRAVITY_ACTION, normalizeGravityDirection(direction));
|
|
8524
|
+
}
|
|
8525
|
+
function buildSetPatronPerksMessage(enabled) {
|
|
8526
|
+
if (typeof enabled !== "boolean") throw new TypeError("enabled must be a boolean");
|
|
8527
|
+
return buildShipManagementMessage(SET_PATRON_PERKS_ACTION, enabled);
|
|
8528
|
+
}
|
|
8529
|
+
function buildStarterRecoveryMessage(itemId) {
|
|
8530
|
+
return buildShipManagementMessage(STARTER_RECOVERY_ACTION, requireNonNegativeInteger(itemId, "itemId"));
|
|
8531
|
+
}
|
|
8532
|
+
function buildPlayerListMessage() {
|
|
8533
|
+
return buildShipManagementMessage(PLAYER_LIST_ACTION);
|
|
8534
|
+
}
|
|
8535
|
+
function buildInviteResetMessage() {
|
|
8536
|
+
return buildShipManagementMessage(INVITE_RESET_ACTION);
|
|
8537
|
+
}
|
|
8538
|
+
function buildSetPlayerRankMessage(refId, rank) {
|
|
8539
|
+
return buildShipManagementMessage(SET_RANK_ACTION, normalizePlayerRef(refId), { rank: normalizePlayerRank(rank) });
|
|
8540
|
+
}
|
|
8541
|
+
function buildKickPlayerMessage(refId) {
|
|
8542
|
+
return buildShipManagementMessage(KICK_ACTION, normalizePlayerRef(refId));
|
|
8543
|
+
}
|
|
8544
|
+
function buildBanPlayerMessage(refId) {
|
|
8545
|
+
return buildShipManagementMessage(BAN_ACTION, normalizePlayerRef(refId));
|
|
8546
|
+
}
|
|
8547
|
+
function buildUnbanPlayerMessage(refId) {
|
|
8548
|
+
return buildShipManagementMessage(UNBAN_ACTION, normalizePlayerRef(refId));
|
|
8549
|
+
}
|
|
8550
|
+
function buildDemoteSelfMessage() {
|
|
8551
|
+
return buildShipManagementMessage(DEMOTE_SELF_ACTION);
|
|
8552
|
+
}
|
|
8553
|
+
function buildSaveShipMessage() {
|
|
8554
|
+
return buildShipManagementMessage(SAVE_SHIP_ACTION);
|
|
8555
|
+
}
|
|
8556
|
+
function buildShipRenameRequestMessage() {
|
|
8557
|
+
return buildShipManagementMessage(RENAME_REQUEST_ACTION);
|
|
8558
|
+
}
|
|
8559
|
+
function buildShipRenameCommitMessage(name, color) {
|
|
8560
|
+
if (typeof name !== "string") throw new TypeError("name must be a string");
|
|
8561
|
+
if (name.length > 32) throw new RangeError("name must be at most 32 UTF-16 code units");
|
|
8562
|
+
if (typeof color !== "string" || !/^#[0-9a-f]{6}$/i.test(color)) {
|
|
8563
|
+
throw new TypeError("color must be a #RRGGBB hex string");
|
|
8564
|
+
}
|
|
8565
|
+
return buildShipManagementMessage(RENAME_COMMIT_ACTION, name, { arg2: color });
|
|
8276
8566
|
}
|
|
8277
|
-
function
|
|
8278
|
-
|
|
8567
|
+
function normalizeShipConfig(event = {}) {
|
|
8568
|
+
const source = event && typeof event === "object" ? event : {};
|
|
8569
|
+
const config = source.config && typeof source.config === "object" ? source.config : {};
|
|
8570
|
+
return {
|
|
8571
|
+
privacy: config.privacy ?? null,
|
|
8572
|
+
privacyName: config.privacy === 0 ? "public" : config.privacy === 1 ? "private" : null,
|
|
8573
|
+
inviteKey: config.invite_key ?? null,
|
|
8574
|
+
teamId: source.team_id ?? null,
|
|
8575
|
+
patronPerks: Array.isArray(source.patron_perks) ? source.patron_perks.slice() : []
|
|
8576
|
+
};
|
|
8279
8577
|
}
|
|
8280
|
-
function
|
|
8578
|
+
function normalizeCaptainSubrank(event = {}) {
|
|
8579
|
+
const source = event && typeof event === "object" ? event : {};
|
|
8281
8580
|
return {
|
|
8282
|
-
|
|
8283
|
-
|
|
8284
|
-
target: normalizeInventoryIndex(target, "target"),
|
|
8285
|
-
split: Boolean(split)
|
|
8286
|
-
}
|
|
8581
|
+
subrank: source.subrank ?? null,
|
|
8582
|
+
enableCheats: Boolean(source.enable_cheats)
|
|
8287
8583
|
};
|
|
8288
8584
|
}
|
|
8289
|
-
function
|
|
8290
|
-
const
|
|
8291
|
-
const
|
|
8292
|
-
const
|
|
8293
|
-
const
|
|
8294
|
-
|
|
8295
|
-
|
|
8296
|
-
const
|
|
8585
|
+
function normalizeCrewLog(event = {}, previous = null) {
|
|
8586
|
+
const source = event && typeof event === "object" ? event : {};
|
|
8587
|
+
const reset = Boolean(source.reset);
|
|
8588
|
+
const amend = Boolean(source.amend);
|
|
8589
|
+
const entries = reset ? [] : (previous?.entries || []).slice();
|
|
8590
|
+
if (amend) entries.pop();
|
|
8591
|
+
const changes = Array.isArray(source.entries) ? source.entries.map((entry) => {
|
|
8592
|
+
const value = entry && typeof entry === "object" ? entry : {};
|
|
8297
8593
|
return {
|
|
8298
|
-
|
|
8299
|
-
|
|
8300
|
-
|
|
8301
|
-
count,
|
|
8302
|
-
|
|
8303
|
-
|
|
8304
|
-
empty: itemId == null || count <= 0
|
|
8594
|
+
icon: value.icon ?? null,
|
|
8595
|
+
text: flattenRichText(value.text),
|
|
8596
|
+
rawText: value.text ?? null,
|
|
8597
|
+
count: value.count ?? 1,
|
|
8598
|
+
refId: value.ref ?? null,
|
|
8599
|
+
secondaryRefId: value.ref2 ?? null
|
|
8305
8600
|
};
|
|
8601
|
+
}) : [];
|
|
8602
|
+
for (const entry of changes) entries.push(entry);
|
|
8603
|
+
if (entries.length > CREW_LOG_LENGTH) entries.splice(0, entries.length - CREW_LOG_LENGTH);
|
|
8604
|
+
return { entries, changes, reset, amend };
|
|
8605
|
+
}
|
|
8606
|
+
function normalizeShipPlayerList(event = {}, previous = null, currentCaptainSubrank = null) {
|
|
8607
|
+
const source = event && typeof event === "object" ? event : {};
|
|
8608
|
+
const changes = Array.isArray(source.player_list) ? source.player_list.map(normalizePlayerListChange) : [];
|
|
8609
|
+
const removedPlayers = changes.filter((change) => change.remove && Number.isFinite(Number(change.refId))).map((change) => Number(change.refId));
|
|
8610
|
+
const changedPlayers = changes.filter((change) => !change.remove).map(({ remove: _remove, ...change }) => change);
|
|
8611
|
+
const players = mergePlayerListChanges(previous?.players, changes);
|
|
8612
|
+
const ownerCaptainRank = ownerRankForPlayers(players);
|
|
8613
|
+
applyPlayerControlState(players, currentCaptainSubrank);
|
|
8614
|
+
applyPlayerControlState(changedPlayers, currentCaptainSubrank);
|
|
8615
|
+
return {
|
|
8616
|
+
ownerCaptainRank,
|
|
8617
|
+
shipOwners: players.filter((player) => player.isShipOwner),
|
|
8618
|
+
players,
|
|
8619
|
+
changes: changedPlayers,
|
|
8620
|
+
removedPlayers
|
|
8306
8621
|
};
|
|
8307
|
-
|
|
8308
|
-
|
|
8309
|
-
|
|
8622
|
+
}
|
|
8623
|
+
function mergePlayerListChanges(previousPlayers, changes) {
|
|
8624
|
+
if (!Array.isArray(previousPlayers) || !previousPlayers.length) return changes.filter((change) => !change.remove).map(({
|
|
8625
|
+
remove: _remove,
|
|
8626
|
+
...player
|
|
8627
|
+
}) => ({ ...player }));
|
|
8628
|
+
const existing = /* @__PURE__ */ new Map();
|
|
8629
|
+
for (const player of previousPlayers) {
|
|
8630
|
+
if (player?.refId == null) continue;
|
|
8631
|
+
existing.set(player.refId, { ...player, isShipOwner: false });
|
|
8310
8632
|
}
|
|
8311
|
-
|
|
8312
|
-
|
|
8313
|
-
|
|
8314
|
-
|
|
8315
|
-
|
|
8316
|
-
|
|
8317
|
-
|
|
8318
|
-
|
|
8319
|
-
|
|
8320
|
-
|
|
8321
|
-
|
|
8322
|
-
|
|
8323
|
-
|
|
8324
|
-
|
|
8325
|
-
|
|
8326
|
-
|
|
8633
|
+
const changedRefs = /* @__PURE__ */ new Set();
|
|
8634
|
+
const merged = [];
|
|
8635
|
+
for (const change of changes) {
|
|
8636
|
+
if (change.refId == null) {
|
|
8637
|
+
if (!change.remove) {
|
|
8638
|
+
const { remove: _remove2, ...player2 } = change;
|
|
8639
|
+
merged.push({ ...player2, isShipOwner: false });
|
|
8640
|
+
}
|
|
8641
|
+
continue;
|
|
8642
|
+
}
|
|
8643
|
+
changedRefs.add(change.refId);
|
|
8644
|
+
if (change.remove) {
|
|
8645
|
+
existing.delete(change.refId);
|
|
8646
|
+
continue;
|
|
8647
|
+
}
|
|
8648
|
+
const { remove: _remove, ...changePlayer } = change;
|
|
8649
|
+
const player = { ...existing.get(change.refId) || {}, ...changePlayer, isShipOwner: false };
|
|
8650
|
+
existing.set(change.refId, player);
|
|
8651
|
+
merged.push(player);
|
|
8652
|
+
}
|
|
8653
|
+
for (const player of previousPlayers) {
|
|
8654
|
+
if (player?.refId == null || changedRefs.has(player.refId)) continue;
|
|
8655
|
+
const retained = existing.get(player.refId);
|
|
8656
|
+
if (retained) merged.push(retained);
|
|
8657
|
+
}
|
|
8658
|
+
return merged;
|
|
8659
|
+
}
|
|
8660
|
+
function normalizePlayerListChange(entry = {}) {
|
|
8661
|
+
const source = entry && typeof entry === "object" ? entry : {};
|
|
8662
|
+
if (source._removed) return { refId: source.ref_id ?? null, remove: true };
|
|
8327
8663
|
return {
|
|
8328
|
-
|
|
8329
|
-
|
|
8330
|
-
|
|
8331
|
-
|
|
8332
|
-
|
|
8333
|
-
|
|
8664
|
+
refId: source.ref_id ?? null,
|
|
8665
|
+
remove: false,
|
|
8666
|
+
discrim: source.discrim ?? null,
|
|
8667
|
+
discrimColor: source.discrim_color ?? null,
|
|
8668
|
+
teamRank: source.team_rank ?? null,
|
|
8669
|
+
captainRank: source.captain_rank ?? null,
|
|
8670
|
+
isCaptain: Number(source.captain_rank) > 0,
|
|
8671
|
+
isShipOwner: false,
|
|
8672
|
+
canBeManaged: false,
|
|
8673
|
+
time: source.time ?? null,
|
|
8674
|
+
items: Array.isArray(source.items) ? source.items.slice() : [],
|
|
8675
|
+
aliasDiscrims: Array.isArray(source.alias_discrims) ? source.alias_discrims.slice() : [],
|
|
8676
|
+
extraAliasCount: normalizeNonNegativeNumber(source.extra_aliases),
|
|
8677
|
+
onlineCount: source.online_count ?? null
|
|
8334
8678
|
};
|
|
8335
8679
|
}
|
|
8336
|
-
function
|
|
8680
|
+
function normalizeNonNegativeNumber(value) {
|
|
8337
8681
|
const number = Number(value);
|
|
8338
|
-
|
|
8339
|
-
return number;
|
|
8682
|
+
return Number.isFinite(number) && number > 0 ? number : 0;
|
|
8340
8683
|
}
|
|
8341
|
-
function
|
|
8342
|
-
const
|
|
8343
|
-
|
|
8684
|
+
function ownerRankForPlayers(players) {
|
|
8685
|
+
const ranks = players.filter((player) => Number(player.captainRank) > 0).map((player) => Number(player.captainRank)).filter(Number.isFinite);
|
|
8686
|
+
if (!ranks.length) return null;
|
|
8687
|
+
const ownerRank = Math.min(...ranks);
|
|
8688
|
+
for (const player of players) player.isShipOwner = Number(player.captainRank) === ownerRank;
|
|
8689
|
+
return ownerRank;
|
|
8344
8690
|
}
|
|
8345
|
-
function
|
|
8346
|
-
|
|
8347
|
-
const
|
|
8348
|
-
|
|
8349
|
-
|
|
8691
|
+
function applyPlayerControlState(players, currentCaptainSubrank) {
|
|
8692
|
+
const currentRank = currentCaptainRank(currentCaptainSubrank);
|
|
8693
|
+
for (const player of players) player.canBeManaged = playerCanBeManagedBy(player, currentRank);
|
|
8694
|
+
}
|
|
8695
|
+
function currentCaptainRank(currentCaptainSubrank) {
|
|
8696
|
+
const rank = Number(currentCaptainSubrank?.subrank);
|
|
8697
|
+
return Number.isFinite(rank) && rank > 0 ? rank : null;
|
|
8698
|
+
}
|
|
8699
|
+
function playerCanBeManagedBy(player, currentRank) {
|
|
8700
|
+
if (!Number.isFinite(currentRank) || !player) return false;
|
|
8701
|
+
const targetCaptainRank = Number(player.captainRank);
|
|
8702
|
+
if (Number.isFinite(targetCaptainRank) && targetCaptainRank > 0) return currentRank < targetCaptainRank;
|
|
8703
|
+
const targetTeamRank = Number(player.teamRank);
|
|
8704
|
+
return targetTeamRank === 0 || targetTeamRank === 1;
|
|
8350
8705
|
}
|
|
8351
8706
|
|
|
8352
8707
|
// src/protocol/outbound/sign.js
|
|
@@ -8486,6 +8841,11 @@
|
|
|
8486
8841
|
return number;
|
|
8487
8842
|
}
|
|
8488
8843
|
var CLIPBOARD_TARGET_VALUES = /* @__PURE__ */ new Map([
|
|
8844
|
+
["launcher", 8],
|
|
8845
|
+
["spawn", 9],
|
|
8846
|
+
["spawn-point", 9],
|
|
8847
|
+
["spawnPoint", 9],
|
|
8848
|
+
["door", 10],
|
|
8489
8849
|
["loader", 1],
|
|
8490
8850
|
["loader-config", 1],
|
|
8491
8851
|
["loaderConfig", 1],
|
|
@@ -8932,11 +9292,11 @@
|
|
|
8932
9292
|
send(command = {}) {
|
|
8933
9293
|
return this.client.send(command);
|
|
8934
9294
|
}
|
|
8935
|
-
sendMessage(
|
|
8936
|
-
return this.client.sendMessage(
|
|
9295
|
+
sendMessage(message2, options = {}) {
|
|
9296
|
+
return this.client.sendMessage(message2, options);
|
|
8937
9297
|
}
|
|
8938
|
-
sendRaw(
|
|
8939
|
-
return this.client.sendRaw(
|
|
9298
|
+
sendRaw(message2, options = {}) {
|
|
9299
|
+
return this.client.sendRaw(message2, options);
|
|
8940
9300
|
}
|
|
8941
9301
|
sendEntityCommand(cmd, args = [-1, -1, -1]) {
|
|
8942
9302
|
return this.client.sendEntityCommand(cmd, args);
|
|
@@ -9344,7 +9704,7 @@
|
|
|
9344
9704
|
this.id = Number(data.entity ?? data.id);
|
|
9345
9705
|
this.entity = this.id;
|
|
9346
9706
|
this.position = data.transform || null;
|
|
9347
|
-
this.rotation = data.transform?.
|
|
9707
|
+
this.rotation = data.transform?.rot ?? null;
|
|
9348
9708
|
this.type = entityPublicType(data, this.#contents);
|
|
9349
9709
|
this.features = Object.freeze(entityFeatures(data, this.#contents));
|
|
9350
9710
|
deepFreeze(this.#contents);
|
|
@@ -9798,11 +10158,23 @@
|
|
|
9798
10158
|
get state() {
|
|
9799
10159
|
return summaryForEntity(this.client, this.scope, this.id)?.contents?.launcher || null;
|
|
9800
10160
|
}
|
|
9801
|
-
|
|
9802
|
-
return this.client.
|
|
10161
|
+
configure(config = {}) {
|
|
10162
|
+
return this.client.sendLauncherConfig(this.id, config);
|
|
10163
|
+
}
|
|
10164
|
+
copy(config = {}) {
|
|
10165
|
+
return this.client.copyLauncherConfig(this.id, config);
|
|
10166
|
+
}
|
|
10167
|
+
paste(config = {}) {
|
|
10168
|
+
return this.client.pasteLauncherConfig(this.id, config);
|
|
10169
|
+
}
|
|
10170
|
+
setAngle(angle, config = {}) {
|
|
10171
|
+
return this.client.setLauncherAngle(this.id, angle, config);
|
|
10172
|
+
}
|
|
10173
|
+
setPower(power, config = {}) {
|
|
10174
|
+
return this.client.setLauncherPower(this.id, power, config);
|
|
9803
10175
|
}
|
|
9804
|
-
|
|
9805
|
-
return this.
|
|
10176
|
+
get power() {
|
|
10177
|
+
return this.state?.power;
|
|
9806
10178
|
}
|
|
9807
10179
|
get angleDegrees() {
|
|
9808
10180
|
return this.state?.angleDegrees;
|
|
@@ -9899,8 +10271,8 @@
|
|
|
9899
10271
|
panel() {
|
|
9900
10272
|
return this.client.commsPanels.get(this.id) || null;
|
|
9901
10273
|
}
|
|
9902
|
-
sendMessage(
|
|
9903
|
-
return this.client.sendCommsMessage(
|
|
10274
|
+
sendMessage(message2 = "") {
|
|
10275
|
+
return this.client.sendCommsMessage(message2);
|
|
9904
10276
|
}
|
|
9905
10277
|
};
|
|
9906
10278
|
var SignHandle = class extends MachineHandle {
|
|
@@ -9967,28 +10339,58 @@
|
|
|
9967
10339
|
}
|
|
9968
10340
|
};
|
|
9969
10341
|
var DoorHandle = class extends MachineHandle {
|
|
9970
|
-
|
|
9971
|
-
return this.client.
|
|
10342
|
+
configure(config = {}) {
|
|
10343
|
+
return this.client.sendDoorConfig(this.id, config);
|
|
10344
|
+
}
|
|
10345
|
+
copy(config = {}) {
|
|
10346
|
+
return this.client.copyDoorConfig(this.id, config);
|
|
10347
|
+
}
|
|
10348
|
+
paste(config = {}) {
|
|
10349
|
+
return this.client.pasteDoorConfig(this.id, config);
|
|
10350
|
+
}
|
|
10351
|
+
setAllowedRanks(allowedRanks) {
|
|
10352
|
+
return this.configure({ allowedRanks });
|
|
10353
|
+
}
|
|
10354
|
+
setRankMask(rankMask) {
|
|
10355
|
+
return this.configure({ rankMask });
|
|
9972
10356
|
}
|
|
9973
10357
|
get state() {
|
|
9974
10358
|
return summaryForEntity(this.client, this.scope, this.id)?.contents?.door || null;
|
|
9975
10359
|
}
|
|
9976
|
-
get
|
|
9977
|
-
return this.state?.
|
|
10360
|
+
get rankMask() {
|
|
10361
|
+
return this.state?.rankMask;
|
|
10362
|
+
}
|
|
10363
|
+
get allowedRanks() {
|
|
10364
|
+
return this.state?.allowedRanks;
|
|
9978
10365
|
}
|
|
9979
10366
|
get open() {
|
|
9980
10367
|
return this.state?.open;
|
|
9981
10368
|
}
|
|
9982
10369
|
};
|
|
9983
10370
|
var SpawnPointHandle = class extends MachineHandle {
|
|
9984
|
-
|
|
9985
|
-
return this.client.
|
|
10371
|
+
configure(config = {}) {
|
|
10372
|
+
return this.client.sendSpawnPointConfig(this.id, config);
|
|
10373
|
+
}
|
|
10374
|
+
copy(config = {}) {
|
|
10375
|
+
return this.client.copySpawnPointConfig(this.id, config);
|
|
10376
|
+
}
|
|
10377
|
+
paste(config = {}) {
|
|
10378
|
+
return this.client.pasteSpawnPointConfig(this.id, config);
|
|
10379
|
+
}
|
|
10380
|
+
setAllowedRanks(allowedRanks) {
|
|
10381
|
+
return this.configure({ allowedRanks });
|
|
10382
|
+
}
|
|
10383
|
+
setRankMask(rankMask) {
|
|
10384
|
+
return this.configure({ rankMask });
|
|
9986
10385
|
}
|
|
9987
10386
|
get state() {
|
|
9988
10387
|
return summaryForEntity(this.client, this.scope, this.id)?.contents?.spawnPoint || null;
|
|
9989
10388
|
}
|
|
9990
|
-
get
|
|
9991
|
-
return this.state?.
|
|
10389
|
+
get rankMask() {
|
|
10390
|
+
return this.state?.rankMask;
|
|
10391
|
+
}
|
|
10392
|
+
get allowedRanks() {
|
|
10393
|
+
return this.state?.allowedRanks;
|
|
9992
10394
|
}
|
|
9993
10395
|
};
|
|
9994
10396
|
var ShieldProjectorHandle = class extends MachineHandle {
|
|
@@ -10382,18 +10784,6 @@
|
|
|
10382
10784
|
if (!Number.isInteger(number) || number <= 0) throw new RangeError(`${name} must be a positive integer`);
|
|
10383
10785
|
return number;
|
|
10384
10786
|
}
|
|
10385
|
-
function normalizeDegrees3(value) {
|
|
10386
|
-
const number = Number(value);
|
|
10387
|
-
if (!Number.isFinite(number)) throw new RangeError(`angle must be a finite number`);
|
|
10388
|
-
return (Math.round(number) % 360 + 360) % 360;
|
|
10389
|
-
}
|
|
10390
|
-
function normalizeLauncherPower(value) {
|
|
10391
|
-
const number = Number(value);
|
|
10392
|
-
if (!Number.isInteger(number) || number < 0 || number > 30) {
|
|
10393
|
-
throw new RangeError(`launcher power must be an integer between 0 and 30`);
|
|
10394
|
-
}
|
|
10395
|
-
return number;
|
|
10396
|
-
}
|
|
10397
10787
|
function normalizeScannerResultPacket(packet) {
|
|
10398
10788
|
const manifest = packet?.manifest && typeof packet.manifest === "object" ? packet.manifest : {};
|
|
10399
10789
|
const hasMaterials = manifest.materials && typeof manifest.materials === "object";
|
|
@@ -10613,18 +11003,18 @@
|
|
|
10613
11003
|
this.emit("command", normalized);
|
|
10614
11004
|
return this;
|
|
10615
11005
|
}
|
|
10616
|
-
sendMessage(
|
|
11006
|
+
sendMessage(message2, { afterReady = true } = {}) {
|
|
10617
11007
|
this.#assertWritable();
|
|
10618
11008
|
if (!this.connected || afterReady && !this.ready) {
|
|
10619
|
-
this.#queuedMessages.push({ message, afterReady });
|
|
11009
|
+
this.#queuedMessages.push({ message: message2, afterReady });
|
|
10620
11010
|
return this;
|
|
10621
11011
|
}
|
|
10622
|
-
this.ws.send(encodeMsgpack(
|
|
10623
|
-
this.emit("message",
|
|
11012
|
+
this.ws.send(encodeMsgpack(message2));
|
|
11013
|
+
this.emit("message", message2);
|
|
10624
11014
|
return this;
|
|
10625
11015
|
}
|
|
10626
|
-
sendRaw(
|
|
10627
|
-
return this.sendMessage(
|
|
11016
|
+
sendRaw(message2, options = {}) {
|
|
11017
|
+
return this.sendMessage(message2, options);
|
|
10628
11018
|
}
|
|
10629
11019
|
sendBlueprintPlacement(placement) {
|
|
10630
11020
|
return this.sendMessage(buildBlueprintPlacementMessage(placement));
|
|
@@ -10752,7 +11142,7 @@
|
|
|
10752
11142
|
}
|
|
10753
11143
|
async recoverStarterItem(itemId, { timeout = 1e4 } = {}) {
|
|
10754
11144
|
this.#assertWritable();
|
|
10755
|
-
const
|
|
11145
|
+
const message2 = buildStarterRecoveryMessage(itemId);
|
|
10756
11146
|
if (!Number.isFinite(timeout) || timeout <= 0 || timeout > 2147483647) {
|
|
10757
11147
|
throw new RangeError("timeout must be positive milliseconds no greater than 2147483647");
|
|
10758
11148
|
}
|
|
@@ -10790,7 +11180,7 @@
|
|
|
10790
11180
|
this.on("disconnect", disconnected);
|
|
10791
11181
|
this.on("demote", demoted);
|
|
10792
11182
|
try {
|
|
10793
|
-
this.sendMessage(
|
|
11183
|
+
this.sendMessage(message2);
|
|
10794
11184
|
} catch (error) {
|
|
10795
11185
|
cleanup();
|
|
10796
11186
|
reject(error);
|
|
@@ -10824,7 +11214,7 @@
|
|
|
10824
11214
|
async demoteSelf(options = {}) {
|
|
10825
11215
|
await this.#awaitManagementConfirmation("Self-demotion", buildDemoteSelfMessage(), "demote", () => true, options);
|
|
10826
11216
|
}
|
|
10827
|
-
async #awaitManagementConfirmation(operation,
|
|
11217
|
+
async #awaitManagementConfirmation(operation, message2, event, accept, { timeout = 1e4 } = {}) {
|
|
10828
11218
|
this.#assertWritable();
|
|
10829
11219
|
if (!Number.isFinite(timeout) || timeout <= 0 || timeout > 2147483647) {
|
|
10830
11220
|
throw new RangeError("timeout must be positive milliseconds no greater than 2147483647");
|
|
@@ -10860,7 +11250,7 @@
|
|
|
10860
11250
|
this.on("disconnect", disconnected);
|
|
10861
11251
|
if (event !== "demote") this.on("demote", demoted);
|
|
10862
11252
|
try {
|
|
10863
|
-
this.sendMessage(
|
|
11253
|
+
this.sendMessage(message2);
|
|
10864
11254
|
} catch (error) {
|
|
10865
11255
|
fail(error);
|
|
10866
11256
|
}
|
|
@@ -10872,11 +11262,11 @@
|
|
|
10872
11262
|
sendEntityCommand(cmd, args = [-1, -1, -1]) {
|
|
10873
11263
|
return this.sendMessage({ type: 5, cmd, args });
|
|
10874
11264
|
}
|
|
10875
|
-
sendChatMessage(
|
|
10876
|
-
return this.sendMessage(buildChatMessage(
|
|
11265
|
+
sendChatMessage(message2 = "") {
|
|
11266
|
+
return this.sendMessage(buildChatMessage(message2));
|
|
10877
11267
|
}
|
|
10878
|
-
sendCommsMessage(
|
|
10879
|
-
return this.sendMessage(buildCommsMessage(
|
|
11268
|
+
sendCommsMessage(message2 = "") {
|
|
11269
|
+
return this.sendMessage(buildCommsMessage(message2));
|
|
10880
11270
|
}
|
|
10881
11271
|
sendFabricatorMessage(cmd, args = [-1, -1, -1]) {
|
|
10882
11272
|
return this.sendEntityCommand(cmd, args);
|
|
@@ -10905,11 +11295,38 @@
|
|
|
10905
11295
|
fabricatorEject(row) {
|
|
10906
11296
|
return this.sendFabricatorMessage("eject", [row, -1, -1]);
|
|
10907
11297
|
}
|
|
10908
|
-
|
|
10909
|
-
return this.
|
|
11298
|
+
sendLauncherConfig(entity, config = {}) {
|
|
11299
|
+
return this.sendUiConfig(buildLauncherConfigData(entity, this.#launcherConfigDefaults(entity, config)));
|
|
10910
11300
|
}
|
|
10911
|
-
|
|
10912
|
-
return this.
|
|
11301
|
+
setLauncherAngle(entity, angle, config = {}) {
|
|
11302
|
+
return this.sendLauncherConfig(entity, { ...config, angle });
|
|
11303
|
+
}
|
|
11304
|
+
setLauncherPower(entity, power, config = {}) {
|
|
11305
|
+
return this.sendLauncherConfig(entity, { ...config, power });
|
|
11306
|
+
}
|
|
11307
|
+
copyLauncherConfig(entity, config = {}) {
|
|
11308
|
+
return this.sendUiConfig(buildLauncherCopyConfigData(this.#launcherConfigDefaults(entity, config)));
|
|
11309
|
+
}
|
|
11310
|
+
pasteLauncherConfig(entity, config = {}) {
|
|
11311
|
+
return this.sendUiConfig(buildLauncherPasteConfigData(entity, this.#launcherConfigDefaults(entity, config)));
|
|
11312
|
+
}
|
|
11313
|
+
sendDoorConfig(entity, config = {}) {
|
|
11314
|
+
return this.sendUiConfig(buildDoorConfigData(entity, this.#rankFilterConfigDefaults(entity, "door", config)));
|
|
11315
|
+
}
|
|
11316
|
+
copyDoorConfig(entity, config = {}) {
|
|
11317
|
+
return this.sendUiConfig(buildDoorCopyConfigData(this.#doorClipboardConfigDefaults(entity, config)));
|
|
11318
|
+
}
|
|
11319
|
+
pasteDoorConfig(entity, config = {}) {
|
|
11320
|
+
return this.sendUiConfig(buildDoorPasteConfigData(entity, this.#doorClipboardConfigDefaults(entity, config)));
|
|
11321
|
+
}
|
|
11322
|
+
sendSpawnPointConfig(entity, config = {}) {
|
|
11323
|
+
return this.sendUiConfig(buildSpawnPointConfigData(entity, this.#rankFilterConfigDefaults(entity, "spawnPoint", config)));
|
|
11324
|
+
}
|
|
11325
|
+
copySpawnPointConfig(entity, config = {}) {
|
|
11326
|
+
return this.sendUiConfig(buildSpawnPointCopyConfigData(this.#rankFilterConfigDefaults(entity, "spawnPoint", config)));
|
|
11327
|
+
}
|
|
11328
|
+
pasteSpawnPointConfig(entity, config = {}) {
|
|
11329
|
+
return this.sendUiConfig(buildSpawnPointPasteConfigData(entity, this.#rankFilterConfigDefaults(entity, "spawnPoint", config)));
|
|
10913
11330
|
}
|
|
10914
11331
|
setSignText(text2 = "", mode = 0) {
|
|
10915
11332
|
return this.sendMessage(buildSignTextMessage(text2, mode));
|
|
@@ -11111,14 +11528,14 @@
|
|
|
11111
11528
|
return this.useHeldItem(options, command);
|
|
11112
11529
|
}
|
|
11113
11530
|
placeBlueprint(placement, { invSlot = 0, hold = true, mx = null, my = null } = {}, command = {}) {
|
|
11114
|
-
const
|
|
11115
|
-
this.sendMessage(
|
|
11531
|
+
const message2 = buildBlueprintPlacementMessage(placement);
|
|
11532
|
+
this.sendMessage(message2);
|
|
11116
11533
|
return this.placeHeldItem(
|
|
11117
11534
|
{ invSlot, hold },
|
|
11118
11535
|
{
|
|
11119
11536
|
...command,
|
|
11120
|
-
mx: mx ??
|
|
11121
|
-
my: my ??
|
|
11537
|
+
mx: mx ?? message2.x,
|
|
11538
|
+
my: my ?? message2.y
|
|
11122
11539
|
}
|
|
11123
11540
|
);
|
|
11124
11541
|
}
|
|
@@ -11323,12 +11740,12 @@
|
|
|
11323
11740
|
}
|
|
11324
11741
|
#bindAttachedSocket() {
|
|
11325
11742
|
const open = () => this.#attachedOpen();
|
|
11326
|
-
const
|
|
11743
|
+
const message2 = (event) => this.#handleSocketMessage(event?.data ?? event);
|
|
11327
11744
|
const error = (event) => this.#fail(event?.error || new Error("WebSocket error"));
|
|
11328
11745
|
const close = (event, reason) => this.#handleSocketClose(event, reason);
|
|
11329
11746
|
if (typeof this.ws.addEventListener === "function") {
|
|
11330
11747
|
this.ws.addEventListener("open", open);
|
|
11331
|
-
this.ws.addEventListener("message",
|
|
11748
|
+
this.ws.addEventListener("message", message2);
|
|
11332
11749
|
this.ws.addEventListener("error", error);
|
|
11333
11750
|
this.ws.addEventListener("close", close);
|
|
11334
11751
|
return;
|
|
@@ -11340,7 +11757,7 @@
|
|
|
11340
11757
|
this.ws.on("close", close);
|
|
11341
11758
|
return;
|
|
11342
11759
|
}
|
|
11343
|
-
for (const [type, handler] of Object.entries({ open, message, error, close })) {
|
|
11760
|
+
for (const [type, handler] of Object.entries({ open, message: message2, error, close })) {
|
|
11344
11761
|
const previous = this.ws[`on${type}`];
|
|
11345
11762
|
this.ws[`on${type}`] = (...args) => {
|
|
11346
11763
|
if (typeof previous === "function") previous.apply(this.ws, args);
|
|
@@ -11653,6 +12070,25 @@
|
|
|
11653
12070
|
autoWarpOnNoCaptains: config.autoWarpOnNoCaptains ?? summary?.autoWarpOnNoCaptains ?? false
|
|
11654
12071
|
};
|
|
11655
12072
|
}
|
|
12073
|
+
#launcherConfigDefaults(entity, config = {}) {
|
|
12074
|
+
const summary = this.worlds.shipWorld()?.entity(entity)?.contents?.launcher;
|
|
12075
|
+
return {
|
|
12076
|
+
angle: config.angle !== void 0 ? config.angle : summary?.angleDegrees ?? 0,
|
|
12077
|
+
power: config.power !== void 0 ? config.power : summary?.power ?? 30
|
|
12078
|
+
};
|
|
12079
|
+
}
|
|
12080
|
+
#rankFilterConfigDefaults(entity, kind, config = {}) {
|
|
12081
|
+
if (config.allowedRanks !== void 0 || config.rankMask !== void 0) return { ...config };
|
|
12082
|
+
const summary = this.worlds.shipWorld()?.entity(entity)?.contents?.[kind];
|
|
12083
|
+
return { ...config, rankMask: summary?.rankMask ?? 4 };
|
|
12084
|
+
}
|
|
12085
|
+
#doorClipboardConfigDefaults(entity, config = {}) {
|
|
12086
|
+
const angle = this.entity(entity)?.transform?.rot ?? 0;
|
|
12087
|
+
return {
|
|
12088
|
+
...this.#rankFilterConfigDefaults(entity, "door", config),
|
|
12089
|
+
orientation: config.orientation ?? (Math.abs(Math.round(angle / (Math.PI / 2))) % 2 ? "horizontal" : "vertical")
|
|
12090
|
+
};
|
|
12091
|
+
}
|
|
11656
12092
|
#pusherConfigDefaults(entity, config = {}) {
|
|
11657
12093
|
const summary = this.entity(entity)?.contents?.pusher || null;
|
|
11658
12094
|
return {
|