dredless 1.2.2 → 1.3.1

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.
@@ -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
- return text2.match(/Object\.defineProperty\(exports,"GAME_VERSION",\{enumerable:true,get:\(\)=>e\}\);const e="([^"]+)"/)?.[1] || null;
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 match = text2.match(/const n=(true|false);const \$="([^"]+)";const o="([^"]+)";const T="([^"]+)";const t="([^"]+)";const S=\[([^\]]+)\];const c=\[([^\]]+)\];const A="([^"]+)";const I="([^"]+)"/s);
440
- if (!match) return null;
441
- const [localDomain, baseDomain, testDomain, testGameDomain] = match.slice(2, 6);
442
- const domains = [...match[6].matchAll(/"((?:[^"\\]|\\.)*)"/g)].map((m) => m[1]);
443
- const names = [...match[7].matchAll(/"((?:[^"\\]|\\.)*)"/g)].map((m) => m[1]);
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: match[8],
450
- testMasterDomain: match[9]
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((domain, index) => server(index, domain, names[index] || `Server ${index + 1}`)),
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
- this.meta = await cache.get(this.baseUrl);
485
- return this;
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
- if (!this.meta.version) throw new Error("Unable to locate GAME_VERSION in drednot bundle");
495
- return this.meta.version;
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
- if (!this.meta.serverInfo) throw new Error("Unable to locate server list in drednot bundle");
503
- return this.meta.serverInfo.servers;
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, version: parseGameVersion(text2), serverInfo: parseServerInfo(text2, this.baseUrl) };
769
+ return { text: text2 };
517
770
  }
518
771
  };
519
772
  fetchGameVersion = (baseUrl = DEFAULT_BASE_URL) => new ServerDirectory(baseUrl).version();
@@ -4121,6 +4374,8 @@
4121
4374
  summarizeProjectile: () => summarizeProjectile,
4122
4375
  summarizePusher: () => summarizePusher,
4123
4376
  summarizePusherBeam: () => summarizePusherBeam,
4377
+ summarizePvpEvent: () => summarizePvpEvent,
4378
+ summarizePvpPartyEntry: () => summarizePvpPartyEntry,
4124
4379
  summarizeRcd: () => summarizeRcd,
4125
4380
  summarizeRecycler: () => summarizeRecycler,
4126
4381
  summarizeShieldGenerator: () => summarizeShieldGenerator,
@@ -4810,6 +5065,19 @@
4810
5065
  defaults: { q28: 10 },
4811
5066
  fields: numericFields({ 1: 20, 2: 24, 4: 28 })
4812
5067
  }],
5068
+ [33, {
5069
+ name: "pvp_event",
5070
+ fields: numericFields({ 2: 20, 4: 24, 8: 28, 16: 32, 32: 36, 64: 40, 128: 44, 256: 48, 512: 52 })
5071
+ }],
5072
+ [34, { name: "pvp_party_config", fields: numericFields({ 2: 20 }) }],
5073
+ [35, {
5074
+ name: "pvp_party_entry",
5075
+ packedBeforeValues: true,
5076
+ orderedValues: true,
5077
+ packedBits: [{ bit: 4, offset: 37 }],
5078
+ blobs: [{ bit: 1, offset: 24 }],
5079
+ fields: numericFields({ 2: 20 })
5080
+ }],
4813
5081
  [37, { name: "loose_item_marker", packedBits: [{ bit: 2, offset: 29 }], fields: numericFields({ 1: 20, 4: 24 }) }],
4814
5082
  [38, { name: "flag_state", packedBits: [{ bit: 1, offset: 21 }], fields: [] }],
4815
5083
  [39, { name: "comms_transmit", ...TWO_FIELD_SPEC }],
@@ -4972,6 +5240,9 @@
4972
5240
  [93, 30],
4973
5241
  [94, 31],
4974
5242
  [95, 32],
5243
+ [96, 33],
5244
+ [97, 34],
5245
+ [98, 35],
4975
5246
  [99, 36],
4976
5247
  [120, 37],
4977
5248
  [121, 38],
@@ -5623,6 +5894,36 @@
5623
5894
  state: cloneRecord(record)
5624
5895
  };
5625
5896
  }
5897
+ function summarizePvpEvent(entity, record, shipsLeft) {
5898
+ if (!record) return null;
5899
+ const damageBonusPercent = record.q52 ?? 0;
5900
+ return {
5901
+ entity,
5902
+ active: (record.q44 ?? 0) >= 0,
5903
+ bounds: {
5904
+ minX: (record.q20 ?? 0) / 10,
5905
+ minY: (record.q24 ?? 0) / 10,
5906
+ maxX: (record.q28 ?? 0) / 10,
5907
+ maxY: (record.q32 ?? 0) / 10
5908
+ },
5909
+ worldBounds: { minX: 0, minY: 0, maxX: record.q36 ?? 0, maxY: record.q40 ?? 0 },
5910
+ timeSeconds: record.q44 ?? 0,
5911
+ damageBonusPercent,
5912
+ damagePercent: damageBonusPercent + 100,
5913
+ damageMultiplier: (damageBonusPercent + 100) / 100,
5914
+ shipsLeft,
5915
+ state: cloneRecord(record)
5916
+ };
5917
+ }
5918
+ function summarizePvpPartyEntry(entity, record) {
5919
+ return {
5920
+ entity,
5921
+ partyId: record.q20 ?? 0,
5922
+ hexCode: decodeText(record.blob24),
5923
+ kind: record.q37 ? "join-request" : "invitation",
5924
+ state: cloneRecord(record)
5925
+ };
5926
+ }
5626
5927
  function summarizeShipSize(entity, record) {
5627
5928
  if (!record) return null;
5628
5929
  return {
@@ -6251,6 +6552,8 @@
6251
6552
  botIdentifierFromState: botIdentifierFromState2,
6252
6553
  summarizeShieldGenerator: summarizeShieldGenerator2,
6253
6554
  summarizeShipControl: summarizeShipControl2,
6555
+ summarizePvpEvent: summarizePvpEvent2,
6556
+ summarizePvpPartyEntry: summarizePvpPartyEntry2,
6254
6557
  summarizeShipSize: summarizeShipSize2,
6255
6558
  summarizeShipWorldMetadata: summarizeShipWorldMetadata2,
6256
6559
  summarizeItemCrate: summarizeItemCrate2,
@@ -6421,6 +6724,8 @@
6421
6724
  balls: derived.specialEntities.balls.slice(),
6422
6725
  recyclers: derived.specialEntities.recyclers.slice(),
6423
6726
  shipControls: derived.shipControls.slice(),
6727
+ pvpEvent: this.pvpEvent(),
6728
+ pvpParties: this.pvpParties(),
6424
6729
  machines: this.#machinesSnapshot(derived.machines),
6425
6730
  tables: includeTables ? this.tablesSnapshot() : derived.tableSummaries.slice()
6426
6731
  };
@@ -6462,6 +6767,26 @@
6462
6767
  shipControls() {
6463
6768
  return this.#derivedState().shipControls.slice();
6464
6769
  }
6770
+ pvpEvent() {
6771
+ const entry = this.table(33).entries().next().value;
6772
+ if (!entry) return null;
6773
+ let shipsLeft = 0;
6774
+ for (const ship of this.table(20).values()) {
6775
+ if (!ship.q153) shipsLeft += 1;
6776
+ }
6777
+ return summarizePvpEvent2(entry[0], entry[1], shipsLeft);
6778
+ }
6779
+ pvpParties() {
6780
+ const config = this.table(34).entries().next().value;
6781
+ const entries = this.table(35);
6782
+ if (!config && entries.size === 0) return null;
6783
+ return {
6784
+ configEntity: config?.[0] ?? null,
6785
+ maxShips: config ? config[1].q20 ?? 0 : 35,
6786
+ entries: [...entries].map(([entity, record]) => summarizePvpPartyEntry2(entity, record)),
6787
+ configState: config ? cloneRecord2(config[1]) : null
6788
+ };
6789
+ }
6465
6790
  shipMetadata() {
6466
6791
  if (this.isOverworld) return null;
6467
6792
  const lockdownRecord = firstRecord2(this.table(11));
@@ -7730,6 +8055,8 @@
7730
8055
  balls: model.balls,
7731
8056
  recyclers: model.recyclers,
7732
8057
  shipControls: model.shipControls,
8058
+ pvpEvent: model.pvpEvent,
8059
+ pvpParties: model.pvpParties,
7733
8060
  commsBubbles: this.commsBubbles.slice(),
7734
8061
  tiles: includeTiles ? [...this.tiles.values()] : void 0
7735
8062
  };
@@ -8810,6 +9137,23 @@
8810
9137
  return typeof data === "string" ? JSON.parse(data) : decodeMsgpack(toUint8Array(data));
8811
9138
  }
8812
9139
 
9140
+ // src/protocol/outbound/pvp.js
9141
+ var TARGETED_KINDS = /* @__PURE__ */ new Set(["Join", "Invite", "Kick", "JoinCancel", "InviteCancel"]);
9142
+ function requireHexCode(value) {
9143
+ if (typeof value !== "string") throw new TypeError("hexCode must be a ship hex code string");
9144
+ const hexCode = value.trim();
9145
+ if (!/^[0-9a-f]+$/i.test(hexCode)) throw new RangeError("hexCode must contain hexadecimal digits");
9146
+ return hexCode;
9147
+ }
9148
+ function buildPvpPartyMessage(kind, hexCode) {
9149
+ if (kind === "NewTeam" || kind === "Leave") {
9150
+ if (hexCode !== void 0) throw new TypeError(`${kind} does not take a ship hex code`);
9151
+ return { type: 10, info: { kind } };
9152
+ }
9153
+ if (!TARGETED_KINDS.has(kind)) throw new RangeError("unsupported PvP party command kind");
9154
+ return { type: 10, info: { kind, hex: requireHexCode(hexCode) } };
9155
+ }
9156
+
8813
9157
  // src/client/domains/index.js
8814
9158
  function normalizeAttachMode(mode = "observe") {
8815
9159
  const value = String(mode || "observe").toLowerCase();
@@ -9159,6 +9503,55 @@
9159
9503
  return worldStateFor(this.client, this.scope)?.snapshot(options) || null;
9160
9504
  }
9161
9505
  };
9506
+ var PvpEventDomain = class {
9507
+ constructor(client) {
9508
+ this.client = client;
9509
+ }
9510
+ state() {
9511
+ return this.#read("pvpEvent");
9512
+ }
9513
+ parties() {
9514
+ return this.#read("pvpParties");
9515
+ }
9516
+ #read(method) {
9517
+ const overworld = this.client.worlds.overworld();
9518
+ const summary = overworld?.model[method]();
9519
+ if (summary != null) return summary;
9520
+ for (const world of this.client.worlds.worlds.values()) {
9521
+ if (world === overworld) continue;
9522
+ const value = world.model[method]();
9523
+ if (value != null) return value;
9524
+ }
9525
+ return null;
9526
+ }
9527
+ createParty() {
9528
+ return this.client.sendMessage(buildPvpPartyMessage("NewTeam"));
9529
+ }
9530
+ leaveParty() {
9531
+ return this.client.sendMessage(buildPvpPartyMessage("Leave"));
9532
+ }
9533
+ joinParty(hexCode) {
9534
+ return this.client.sendMessage(buildPvpPartyMessage("Join", hexCode));
9535
+ }
9536
+ inviteShip(hexCode) {
9537
+ return this.client.sendMessage(buildPvpPartyMessage("Invite", hexCode));
9538
+ }
9539
+ acceptInvitation(hexCode) {
9540
+ return this.joinParty(hexCode);
9541
+ }
9542
+ acceptJoinRequest(hexCode) {
9543
+ return this.inviteShip(hexCode);
9544
+ }
9545
+ kickShip(hexCode) {
9546
+ return this.client.sendMessage(buildPvpPartyMessage("Kick", hexCode));
9547
+ }
9548
+ cancelJoinRequest(hexCode) {
9549
+ return this.client.sendMessage(buildPvpPartyMessage("JoinCancel", hexCode));
9550
+ }
9551
+ cancelInvitation(hexCode) {
9552
+ return this.client.sendMessage(buildPvpPartyMessage("InviteCancel", hexCode));
9553
+ }
9554
+ };
9162
9555
  var ShipDomain = class extends WorldDomain {
9163
9556
  entity() {
9164
9557
  const summary = this.client.worlds.currentShipEntity();
@@ -10402,6 +10795,7 @@
10402
10795
  this.inventory = new InventoryDomain(this);
10403
10796
  this.tips = new TipDomain(this);
10404
10797
  this.management = new ShipManagementDomain(this);
10798
+ this.pvpEvent = new PvpEventDomain(this);
10405
10799
  this.cpuLoad = null;
10406
10800
  this.inventoryState = normalizeInventoryEvent({ type: "inventory", general_slots: 5 });
10407
10801
  this.puiPanels = /* @__PURE__ */ new Map();