dredless 1.3.1 → 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 +640 -457
- 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/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/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
|
@@ -774,6 +774,110 @@
|
|
|
774
774
|
}
|
|
775
775
|
});
|
|
776
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
|
+
|
|
777
881
|
// src/network/connection.js
|
|
778
882
|
init_constants();
|
|
779
883
|
init_runtime();
|
|
@@ -847,8 +951,8 @@
|
|
|
847
951
|
});
|
|
848
952
|
}
|
|
849
953
|
var DisconnectError = class extends Error {
|
|
850
|
-
constructor(disconnect,
|
|
851
|
-
super(`${
|
|
954
|
+
constructor(disconnect, message2 = "Disconnected") {
|
|
955
|
+
super(`${message2}: ${disconnect.name ?? "Unknown"} (${disconnect.code})${disconnect.reason ? ` \u2014 ${disconnect.reason}` : ""}`);
|
|
852
956
|
this.name = "DisconnectError";
|
|
853
957
|
this.disconnect = disconnect;
|
|
854
958
|
}
|
|
@@ -892,281 +996,6 @@
|
|
|
892
996
|
}
|
|
893
997
|
};
|
|
894
998
|
|
|
895
|
-
// src/protocol/outbound/comms.js
|
|
896
|
-
var COMMS_MESSAGE_TYPE = 3;
|
|
897
|
-
function buildCommsMessage(message = "") {
|
|
898
|
-
return {
|
|
899
|
-
type: COMMS_MESSAGE_TYPE,
|
|
900
|
-
msg: String(message)
|
|
901
|
-
};
|
|
902
|
-
}
|
|
903
|
-
function normalizeCommsEvent(event) {
|
|
904
|
-
const rawMessages = Array.isArray(event?.msgs_text) ? event.msgs_text : [];
|
|
905
|
-
return {
|
|
906
|
-
...event,
|
|
907
|
-
entity: event?.ent_id != null && Number.isFinite(Number(event.ent_id)) ? Number(event.ent_id) : null,
|
|
908
|
-
rawMessages,
|
|
909
|
-
messages: rawMessages.map((message) => ({
|
|
910
|
-
raw: message,
|
|
911
|
-
text: flattenRichText(message)
|
|
912
|
-
}))
|
|
913
|
-
};
|
|
914
|
-
}
|
|
915
|
-
function flattenRichText(value) {
|
|
916
|
-
if (value == null) return "";
|
|
917
|
-
if (typeof value === "string") return value;
|
|
918
|
-
if (typeof value === "number" || typeof value === "boolean") return String(value);
|
|
919
|
-
if (Array.isArray(value)) return value.map(flattenRichText).join("");
|
|
920
|
-
if (typeof value === "object") {
|
|
921
|
-
if (Object.hasOwn(value, "c")) return flattenRichText(value.c);
|
|
922
|
-
if (Object.hasOwn(value, "text")) return flattenRichText(value.text);
|
|
923
|
-
}
|
|
924
|
-
return "";
|
|
925
|
-
}
|
|
926
|
-
|
|
927
|
-
// src/protocol/outbound/ship-management.js
|
|
928
|
-
var SHIP_MANAGEMENT_TYPE = 4;
|
|
929
|
-
var CREW_LOG_LENGTH = 500;
|
|
930
|
-
var SET_PRIVACY_ACTION = "set_privacy";
|
|
931
|
-
var GRAVITY_ACTION = "gravity";
|
|
932
|
-
var SET_PATRON_PERKS_ACTION = "set_patron_perks";
|
|
933
|
-
var STARTER_RECOVERY_ACTION = "starter_recovery";
|
|
934
|
-
var PLAYER_LIST_ACTION = "player_list";
|
|
935
|
-
var INVITE_RESET_ACTION = "invite_reset";
|
|
936
|
-
var SET_RANK_ACTION = "set_rank";
|
|
937
|
-
var KICK_ACTION = "kick";
|
|
938
|
-
var BAN_ACTION = "ban";
|
|
939
|
-
var UNBAN_ACTION = "unban";
|
|
940
|
-
var DEMOTE_SELF_ACTION = "demote_self";
|
|
941
|
-
var SAVE_SHIP_ACTION = "save_team";
|
|
942
|
-
var RENAME_REQUEST_ACTION = "rename_request";
|
|
943
|
-
var RENAME_COMMIT_ACTION = "rename_commit";
|
|
944
|
-
var GravityDirection = Object.freeze({
|
|
945
|
-
Down: "down",
|
|
946
|
-
Up: "up",
|
|
947
|
-
Left: "left",
|
|
948
|
-
Right: "right"
|
|
949
|
-
});
|
|
950
|
-
function normalizeGravityDirection(value) {
|
|
951
|
-
if (value === GravityDirection.Down || value === 0) return 0;
|
|
952
|
-
if (value === GravityDirection.Up || value === 1) return 1;
|
|
953
|
-
if (value === GravityDirection.Left || value === 2) return 2;
|
|
954
|
-
if (value === GravityDirection.Right || value === 3) return 3;
|
|
955
|
-
throw new RangeError('direction must be "down", "up", "left", "right", or an integer from 0 to 3');
|
|
956
|
-
}
|
|
957
|
-
function requireNonNegativeInteger(value, name) {
|
|
958
|
-
const number = Number(value);
|
|
959
|
-
if (!Number.isInteger(number) || number < 0) throw new RangeError(`${name} must be a non-negative integer`);
|
|
960
|
-
return number;
|
|
961
|
-
}
|
|
962
|
-
function normalizePrivacy(value) {
|
|
963
|
-
if (value === true || value === 1 || value === "private") return 1;
|
|
964
|
-
if (value === false || value === 0 || value === "public") return 0;
|
|
965
|
-
throw new RangeError(`privacy must be 0, 1, true, false, "public", or "private"`);
|
|
966
|
-
}
|
|
967
|
-
function normalizePlayerRef(value) {
|
|
968
|
-
return requireNonNegativeInteger(value, "refId");
|
|
969
|
-
}
|
|
970
|
-
function normalizePlayerRank(value) {
|
|
971
|
-
if (value === 0 || value === "guest") return 0;
|
|
972
|
-
if (value === 1 || value === "crew") return 1;
|
|
973
|
-
if (value === 3 || value === "captain") return 3;
|
|
974
|
-
throw new RangeError(`rank must be 0, 1, 3, "guest", "crew", or "captain"`);
|
|
975
|
-
}
|
|
976
|
-
function buildShipManagementMessage(act, arg = null, extra = null) {
|
|
977
|
-
if (typeof act !== "string" || !act) throw new TypeError(`act must be a non-empty string`);
|
|
978
|
-
const message = { type: SHIP_MANAGEMENT_TYPE, act, arg };
|
|
979
|
-
if (extra && typeof extra === "object") Object.assign(message, extra);
|
|
980
|
-
return message;
|
|
981
|
-
}
|
|
982
|
-
function buildShipPrivacyMessage(privacy) {
|
|
983
|
-
return buildShipManagementMessage(SET_PRIVACY_ACTION, normalizePrivacy(privacy));
|
|
984
|
-
}
|
|
985
|
-
function buildShipGravityMessage(direction) {
|
|
986
|
-
return buildShipManagementMessage(GRAVITY_ACTION, normalizeGravityDirection(direction));
|
|
987
|
-
}
|
|
988
|
-
function buildSetPatronPerksMessage(enabled) {
|
|
989
|
-
if (typeof enabled !== "boolean") throw new TypeError("enabled must be a boolean");
|
|
990
|
-
return buildShipManagementMessage(SET_PATRON_PERKS_ACTION, enabled);
|
|
991
|
-
}
|
|
992
|
-
function buildStarterRecoveryMessage(itemId) {
|
|
993
|
-
return buildShipManagementMessage(STARTER_RECOVERY_ACTION, requireNonNegativeInteger(itemId, "itemId"));
|
|
994
|
-
}
|
|
995
|
-
function buildPlayerListMessage() {
|
|
996
|
-
return buildShipManagementMessage(PLAYER_LIST_ACTION);
|
|
997
|
-
}
|
|
998
|
-
function buildInviteResetMessage() {
|
|
999
|
-
return buildShipManagementMessage(INVITE_RESET_ACTION);
|
|
1000
|
-
}
|
|
1001
|
-
function buildSetPlayerRankMessage(refId, rank) {
|
|
1002
|
-
return buildShipManagementMessage(SET_RANK_ACTION, normalizePlayerRef(refId), { rank: normalizePlayerRank(rank) });
|
|
1003
|
-
}
|
|
1004
|
-
function buildKickPlayerMessage(refId) {
|
|
1005
|
-
return buildShipManagementMessage(KICK_ACTION, normalizePlayerRef(refId));
|
|
1006
|
-
}
|
|
1007
|
-
function buildBanPlayerMessage(refId) {
|
|
1008
|
-
return buildShipManagementMessage(BAN_ACTION, normalizePlayerRef(refId));
|
|
1009
|
-
}
|
|
1010
|
-
function buildUnbanPlayerMessage(refId) {
|
|
1011
|
-
return buildShipManagementMessage(UNBAN_ACTION, normalizePlayerRef(refId));
|
|
1012
|
-
}
|
|
1013
|
-
function buildDemoteSelfMessage() {
|
|
1014
|
-
return buildShipManagementMessage(DEMOTE_SELF_ACTION);
|
|
1015
|
-
}
|
|
1016
|
-
function buildSaveShipMessage() {
|
|
1017
|
-
return buildShipManagementMessage(SAVE_SHIP_ACTION);
|
|
1018
|
-
}
|
|
1019
|
-
function buildShipRenameRequestMessage() {
|
|
1020
|
-
return buildShipManagementMessage(RENAME_REQUEST_ACTION);
|
|
1021
|
-
}
|
|
1022
|
-
function buildShipRenameCommitMessage(name, color) {
|
|
1023
|
-
if (typeof name !== "string") throw new TypeError("name must be a string");
|
|
1024
|
-
if (name.length > 32) throw new RangeError("name must be at most 32 UTF-16 code units");
|
|
1025
|
-
if (typeof color !== "string" || !/^#[0-9a-f]{6}$/i.test(color)) {
|
|
1026
|
-
throw new TypeError("color must be a #RRGGBB hex string");
|
|
1027
|
-
}
|
|
1028
|
-
return buildShipManagementMessage(RENAME_COMMIT_ACTION, name, { arg2: color });
|
|
1029
|
-
}
|
|
1030
|
-
function normalizeShipConfig(event = {}) {
|
|
1031
|
-
const source = event && typeof event === "object" ? event : {};
|
|
1032
|
-
const config = source.config && typeof source.config === "object" ? source.config : {};
|
|
1033
|
-
return {
|
|
1034
|
-
privacy: config.privacy ?? null,
|
|
1035
|
-
privacyName: config.privacy === 0 ? "public" : config.privacy === 1 ? "private" : null,
|
|
1036
|
-
inviteKey: config.invite_key ?? null,
|
|
1037
|
-
teamId: source.team_id ?? null,
|
|
1038
|
-
patronPerks: Array.isArray(source.patron_perks) ? source.patron_perks.slice() : []
|
|
1039
|
-
};
|
|
1040
|
-
}
|
|
1041
|
-
function normalizeCaptainSubrank(event = {}) {
|
|
1042
|
-
const source = event && typeof event === "object" ? event : {};
|
|
1043
|
-
return {
|
|
1044
|
-
subrank: source.subrank ?? null,
|
|
1045
|
-
enableCheats: Boolean(source.enable_cheats)
|
|
1046
|
-
};
|
|
1047
|
-
}
|
|
1048
|
-
function normalizeCrewLog(event = {}, previous = null) {
|
|
1049
|
-
const source = event && typeof event === "object" ? event : {};
|
|
1050
|
-
const reset = Boolean(source.reset);
|
|
1051
|
-
const amend = Boolean(source.amend);
|
|
1052
|
-
const entries = reset ? [] : (previous?.entries || []).slice();
|
|
1053
|
-
if (amend) entries.pop();
|
|
1054
|
-
const changes = Array.isArray(source.entries) ? source.entries.map((entry) => {
|
|
1055
|
-
const value = entry && typeof entry === "object" ? entry : {};
|
|
1056
|
-
return {
|
|
1057
|
-
icon: value.icon ?? null,
|
|
1058
|
-
text: flattenRichText(value.text),
|
|
1059
|
-
rawText: value.text ?? null,
|
|
1060
|
-
count: value.count ?? 1,
|
|
1061
|
-
refId: value.ref ?? null,
|
|
1062
|
-
secondaryRefId: value.ref2 ?? null
|
|
1063
|
-
};
|
|
1064
|
-
}) : [];
|
|
1065
|
-
for (const entry of changes) entries.push(entry);
|
|
1066
|
-
if (entries.length > CREW_LOG_LENGTH) entries.splice(0, entries.length - CREW_LOG_LENGTH);
|
|
1067
|
-
return { entries, changes, reset, amend };
|
|
1068
|
-
}
|
|
1069
|
-
function normalizeShipPlayerList(event = {}, previous = null, currentCaptainSubrank = null) {
|
|
1070
|
-
const source = event && typeof event === "object" ? event : {};
|
|
1071
|
-
const changes = Array.isArray(source.player_list) ? source.player_list.map(normalizePlayerListChange) : [];
|
|
1072
|
-
const removedPlayers = changes.filter((change) => change.remove && Number.isFinite(Number(change.refId))).map((change) => Number(change.refId));
|
|
1073
|
-
const changedPlayers = changes.filter((change) => !change.remove).map(({ remove: _remove, ...change }) => change);
|
|
1074
|
-
const players = mergePlayerListChanges(previous?.players, changes);
|
|
1075
|
-
const ownerCaptainRank = ownerRankForPlayers(players);
|
|
1076
|
-
applyPlayerControlState(players, currentCaptainSubrank);
|
|
1077
|
-
applyPlayerControlState(changedPlayers, currentCaptainSubrank);
|
|
1078
|
-
return {
|
|
1079
|
-
ownerCaptainRank,
|
|
1080
|
-
shipOwners: players.filter((player) => player.isShipOwner),
|
|
1081
|
-
players,
|
|
1082
|
-
changes: changedPlayers,
|
|
1083
|
-
removedPlayers
|
|
1084
|
-
};
|
|
1085
|
-
}
|
|
1086
|
-
function mergePlayerListChanges(previousPlayers, changes) {
|
|
1087
|
-
if (!Array.isArray(previousPlayers) || !previousPlayers.length) return changes.filter((change) => !change.remove).map(({
|
|
1088
|
-
remove: _remove,
|
|
1089
|
-
...player
|
|
1090
|
-
}) => ({ ...player }));
|
|
1091
|
-
const existing = /* @__PURE__ */ new Map();
|
|
1092
|
-
for (const player of previousPlayers) {
|
|
1093
|
-
if (player?.refId == null) continue;
|
|
1094
|
-
existing.set(player.refId, { ...player, isShipOwner: false });
|
|
1095
|
-
}
|
|
1096
|
-
const changedRefs = /* @__PURE__ */ new Set();
|
|
1097
|
-
const merged = [];
|
|
1098
|
-
for (const change of changes) {
|
|
1099
|
-
if (change.refId == null) {
|
|
1100
|
-
if (!change.remove) {
|
|
1101
|
-
const { remove: _remove2, ...player2 } = change;
|
|
1102
|
-
merged.push({ ...player2, isShipOwner: false });
|
|
1103
|
-
}
|
|
1104
|
-
continue;
|
|
1105
|
-
}
|
|
1106
|
-
changedRefs.add(change.refId);
|
|
1107
|
-
if (change.remove) {
|
|
1108
|
-
existing.delete(change.refId);
|
|
1109
|
-
continue;
|
|
1110
|
-
}
|
|
1111
|
-
const { remove: _remove, ...changePlayer } = change;
|
|
1112
|
-
const player = { ...existing.get(change.refId) || {}, ...changePlayer, isShipOwner: false };
|
|
1113
|
-
existing.set(change.refId, player);
|
|
1114
|
-
merged.push(player);
|
|
1115
|
-
}
|
|
1116
|
-
for (const player of previousPlayers) {
|
|
1117
|
-
if (player?.refId == null || changedRefs.has(player.refId)) continue;
|
|
1118
|
-
const retained = existing.get(player.refId);
|
|
1119
|
-
if (retained) merged.push(retained);
|
|
1120
|
-
}
|
|
1121
|
-
return merged;
|
|
1122
|
-
}
|
|
1123
|
-
function normalizePlayerListChange(entry = {}) {
|
|
1124
|
-
const source = entry && typeof entry === "object" ? entry : {};
|
|
1125
|
-
if (source._removed) return { refId: source.ref_id ?? null, remove: true };
|
|
1126
|
-
return {
|
|
1127
|
-
refId: source.ref_id ?? null,
|
|
1128
|
-
remove: false,
|
|
1129
|
-
discrim: source.discrim ?? null,
|
|
1130
|
-
discrimColor: source.discrim_color ?? null,
|
|
1131
|
-
teamRank: source.team_rank ?? null,
|
|
1132
|
-
captainRank: source.captain_rank ?? null,
|
|
1133
|
-
isCaptain: Number(source.captain_rank) > 0,
|
|
1134
|
-
isShipOwner: false,
|
|
1135
|
-
canBeManaged: false,
|
|
1136
|
-
time: source.time ?? null,
|
|
1137
|
-
items: Array.isArray(source.items) ? source.items.slice() : [],
|
|
1138
|
-
aliasDiscrims: Array.isArray(source.alias_discrims) ? source.alias_discrims.slice() : [],
|
|
1139
|
-
extraAliasCount: normalizeNonNegativeNumber(source.extra_aliases),
|
|
1140
|
-
onlineCount: source.online_count ?? null
|
|
1141
|
-
};
|
|
1142
|
-
}
|
|
1143
|
-
function normalizeNonNegativeNumber(value) {
|
|
1144
|
-
const number = Number(value);
|
|
1145
|
-
return Number.isFinite(number) && number > 0 ? number : 0;
|
|
1146
|
-
}
|
|
1147
|
-
function ownerRankForPlayers(players) {
|
|
1148
|
-
const ranks = players.filter((player) => Number(player.captainRank) > 0).map((player) => Number(player.captainRank)).filter(Number.isFinite);
|
|
1149
|
-
if (!ranks.length) return null;
|
|
1150
|
-
const ownerRank = Math.min(...ranks);
|
|
1151
|
-
for (const player of players) player.isShipOwner = Number(player.captainRank) === ownerRank;
|
|
1152
|
-
return ownerRank;
|
|
1153
|
-
}
|
|
1154
|
-
function applyPlayerControlState(players, currentCaptainSubrank) {
|
|
1155
|
-
const currentRank = currentCaptainRank(currentCaptainSubrank);
|
|
1156
|
-
for (const player of players) player.canBeManaged = playerCanBeManagedBy(player, currentRank);
|
|
1157
|
-
}
|
|
1158
|
-
function currentCaptainRank(currentCaptainSubrank) {
|
|
1159
|
-
const rank = Number(currentCaptainSubrank?.subrank);
|
|
1160
|
-
return Number.isFinite(rank) && rank > 0 ? rank : null;
|
|
1161
|
-
}
|
|
1162
|
-
function playerCanBeManagedBy(player, currentRank) {
|
|
1163
|
-
if (!Number.isFinite(currentRank) || !player) return false;
|
|
1164
|
-
const targetCaptainRank = Number(player.captainRank);
|
|
1165
|
-
if (Number.isFinite(targetCaptainRank) && targetCaptainRank > 0) return currentRank < targetCaptainRank;
|
|
1166
|
-
const targetTeamRank = Number(player.teamRank);
|
|
1167
|
-
return targetTeamRank === 0 || targetTeamRank === 1;
|
|
1168
|
-
}
|
|
1169
|
-
|
|
1170
999
|
// src/client/domains/tips.js
|
|
1171
1000
|
function timeoutValue(options) {
|
|
1172
1001
|
const timeout = options.timeout ?? 5e3;
|
|
@@ -1329,25 +1158,6 @@
|
|
|
1329
1158
|
return this.#select(option);
|
|
1330
1159
|
});
|
|
1331
1160
|
}
|
|
1332
|
-
setRank(handle, rank, options = {}) {
|
|
1333
|
-
return this.#exclusive(async () => {
|
|
1334
|
-
const value = normalizePlayerRank(rank);
|
|
1335
|
-
const timeout = timeoutValue(options);
|
|
1336
|
-
if (!handle.exists()) throw new Error("Rank target no longer exists");
|
|
1337
|
-
if (handle.rank === value) return this.client;
|
|
1338
|
-
const text2 = { 0: "Restrict to Guests", 1: "Restrict to Crew", 3: "Restrict to Captains" }[value];
|
|
1339
|
-
await this.#open(handle, options);
|
|
1340
|
-
await waitFor(
|
|
1341
|
-
this.client,
|
|
1342
|
-
"model",
|
|
1343
|
-
() => handle.rank === value,
|
|
1344
|
-
timeout,
|
|
1345
|
-
"access rank update",
|
|
1346
|
-
() => this.#select(text2)
|
|
1347
|
-
);
|
|
1348
|
-
return this.client;
|
|
1349
|
-
});
|
|
1350
|
-
}
|
|
1351
1161
|
};
|
|
1352
1162
|
|
|
1353
1163
|
// src/client/core.js
|
|
@@ -4907,7 +4717,7 @@
|
|
|
4907
4717
|
[4, { name: "motion_aux", packedBits: [{ bit: 8, offset: 33 }], fields: numericFields({ 1: 20, 2: 24, 4: 28 }) }],
|
|
4908
4718
|
[5, {
|
|
4909
4719
|
name: "entity_health",
|
|
4910
|
-
//
|
|
4720
|
+
// Bar half-width and vertical offset start at 10 (one world unit).
|
|
4911
4721
|
// Field values on the wire are deltas relative to these defaults.
|
|
4912
4722
|
defaults: { q28: 10, q32: 10 },
|
|
4913
4723
|
fields: numericFields({ 1: 20, 2: 24, 4: 28, 8: 32 })
|
|
@@ -5191,7 +5001,11 @@
|
|
|
5191
5001
|
record.q44 = (record.q44 || 0) + reader.readFieldDelta();
|
|
5192
5002
|
}
|
|
5193
5003
|
}
|
|
5194
|
-
}]
|
|
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: [] }]
|
|
5195
5009
|
]);
|
|
5196
5010
|
for (const spec of MODEL_TABLE_SPECS.values()) {
|
|
5197
5011
|
for (const blob of spec.blobs || []) blob.key = blobKey(blob.offset);
|
|
@@ -5288,7 +5102,10 @@
|
|
|
5288
5102
|
[166, 75],
|
|
5289
5103
|
[167, 76],
|
|
5290
5104
|
[168, 78],
|
|
5291
|
-
[169, 77]
|
|
5105
|
+
[169, 77],
|
|
5106
|
+
[170, 79],
|
|
5107
|
+
[171, 80],
|
|
5108
|
+
[172, 81]
|
|
5292
5109
|
]);
|
|
5293
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]);
|
|
5294
5111
|
var ENTITY_FOOTPRINTS = /* @__PURE__ */ new Map([
|
|
@@ -5642,6 +5459,8 @@
|
|
|
5642
5459
|
hp,
|
|
5643
5460
|
maxHp,
|
|
5644
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,
|
|
5645
5464
|
state: cloneRecord(record)
|
|
5646
5465
|
};
|
|
5647
5466
|
}
|
|
@@ -5964,6 +5783,7 @@
|
|
|
5964
5783
|
return {
|
|
5965
5784
|
entity,
|
|
5966
5785
|
...itemSummary(itemId, count),
|
|
5786
|
+
boxSprite: Boolean(itemRecord?.q29),
|
|
5967
5787
|
width: sizeRecord.q20 ?? null,
|
|
5968
5788
|
height: sizeRecord.q24 ?? null,
|
|
5969
5789
|
itemState: cloneRecord(itemRecord || healthRecord || {}),
|
|
@@ -6129,15 +5949,17 @@
|
|
|
6129
5949
|
if (!Number.isFinite(Number(value))) return null;
|
|
6130
5950
|
return (Number(value) % 360 + 360) % 360;
|
|
6131
5951
|
}
|
|
6132
|
-
function summarizeItemLauncher(entity, typeId, launcherRecord) {
|
|
6133
|
-
if (typeId !== ITEM_LAUNCHER_TYPE_ID || !launcherRecord) return null;
|
|
6134
|
-
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);
|
|
6135
5955
|
return {
|
|
6136
5956
|
entity,
|
|
6137
|
-
angleRaw: launcherRecord.q32 ?? null,
|
|
5957
|
+
angleRaw: configRecord ? configRecord.q20 ?? 0 : launcherRecord.q32 ?? null,
|
|
6138
5958
|
angleRadians,
|
|
6139
5959
|
angleDegrees: angleRadians == null ? null : normalizeDegrees(angleRadians * 180 / Math.PI),
|
|
6140
|
-
|
|
5960
|
+
power: configRecord ? (configRecord.q24 ?? 300) / 10 : null,
|
|
5961
|
+
configState: configRecord ? cloneRecord(configRecord) : null,
|
|
5962
|
+
state: cloneRecord(launcherRecord || {})
|
|
6141
5963
|
};
|
|
6142
5964
|
}
|
|
6143
5965
|
function summarizeSign(entity, signRecord) {
|
|
@@ -6158,23 +5980,28 @@
|
|
|
6158
5980
|
state: cloneRecord(projectorRecord || {})
|
|
6159
5981
|
};
|
|
6160
5982
|
}
|
|
6161
|
-
function
|
|
6162
|
-
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) {
|
|
6163
5994
|
return {
|
|
6164
5995
|
entity,
|
|
6165
|
-
|
|
6166
|
-
|
|
6167
|
-
state: cloneRecord(spawnRecord || {})
|
|
5996
|
+
...summarizeRankFilter(spawnRecord, filterRecord, markerRecord != null),
|
|
5997
|
+
state: cloneRecord(markerRecord || spawnRecord || {})
|
|
6168
5998
|
};
|
|
6169
5999
|
}
|
|
6170
|
-
function summarizeDoor(entity, rankRecord, doorRecord) {
|
|
6171
|
-
const rank = Number.isFinite(Number(rankRecord?.q20)) ? Number(rankRecord.q20) : 0;
|
|
6000
|
+
function summarizeDoor(entity, rankRecord, doorRecord, filterRecord = null) {
|
|
6172
6001
|
return {
|
|
6173
6002
|
entity,
|
|
6174
|
-
|
|
6175
|
-
rankName: enumValueName(TEAM_RANK_NAMES, rank),
|
|
6003
|
+
...summarizeRankFilter(rankRecord, filterRecord),
|
|
6176
6004
|
open: doorRecord?.q21 === 1,
|
|
6177
|
-
rankState: cloneRecord(rankRecord || {}),
|
|
6178
6005
|
state: cloneRecord(doorRecord || {})
|
|
6179
6006
|
};
|
|
6180
6007
|
}
|
|
@@ -6686,9 +6513,9 @@
|
|
|
6686
6513
|
if (reader.trailingZeroOnly()) break;
|
|
6687
6514
|
throw new Error(`unsupported model_data section tag ${tag}`);
|
|
6688
6515
|
}
|
|
6689
|
-
const
|
|
6690
|
-
update.sections.push(
|
|
6691
|
-
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);
|
|
6692
6519
|
}
|
|
6693
6520
|
} catch (error) {
|
|
6694
6521
|
update.error = error;
|
|
@@ -6827,10 +6654,10 @@
|
|
|
6827
6654
|
#updateDerived(update) {
|
|
6828
6655
|
if (!this._derived) return;
|
|
6829
6656
|
if (!update.removals.length && !update.changedEntities.size) return;
|
|
6830
|
-
for (const
|
|
6831
|
-
for (const record of
|
|
6657
|
+
for (const section2 of update.sections) {
|
|
6658
|
+
for (const record of section2.records || []) this.#addDerivedEntityTable(record.entity, section2.table);
|
|
6832
6659
|
}
|
|
6833
|
-
if (update.sections.some((
|
|
6660
|
+
if (update.sections.some((section2) => section2.table === 12)) {
|
|
6834
6661
|
for (const entityId of this.table(55).keys()) update.changedEntities.add(entityId);
|
|
6835
6662
|
}
|
|
6836
6663
|
for (const entityId of update.removals) this.#removeDerivedEntity(entityId);
|
|
@@ -6841,9 +6668,9 @@
|
|
|
6841
6668
|
#updateNavigationUnitAutoWarp(update) {
|
|
6842
6669
|
const trackedBeforeUpdate = new Set(this.#navigationUnitAutoWarp.keys());
|
|
6843
6670
|
const initializedThisUpdate = /* @__PURE__ */ new Set();
|
|
6844
|
-
for (const
|
|
6845
|
-
if (
|
|
6846
|
-
for (const changed of
|
|
6671
|
+
for (const section2 of update.sections || []) {
|
|
6672
|
+
if (section2.table !== 78) continue;
|
|
6673
|
+
for (const changed of section2.records || []) {
|
|
6847
6674
|
const typeId = entityTypeIdFromRecord2(this.record(7, changed.entity));
|
|
6848
6675
|
if (typeId !== NAVIGATION_UNIT_TYPE_ID2) continue;
|
|
6849
6676
|
const record = this.record(78, changed.entity);
|
|
@@ -6906,12 +6733,12 @@
|
|
|
6906
6733
|
}
|
|
6907
6734
|
}
|
|
6908
6735
|
#updateHelmOccupancy(update) {
|
|
6909
|
-
const table7 = update.sections.find((
|
|
6736
|
+
const table7 = update.sections.find((section2) => section2.table === 7);
|
|
6910
6737
|
if (!table7) return;
|
|
6911
6738
|
const changedZoomState = /* @__PURE__ */ new Map();
|
|
6912
|
-
for (const
|
|
6913
|
-
if (
|
|
6914
|
-
for (const changed of
|
|
6739
|
+
for (const section2 of update.sections) {
|
|
6740
|
+
if (section2.table !== 55) continue;
|
|
6741
|
+
for (const changed of section2.records) {
|
|
6915
6742
|
if (!(changed.mask & 16)) continue;
|
|
6916
6743
|
const player = this.record(55, changed.entity);
|
|
6917
6744
|
changedZoomState.set(changed.entity, Boolean(player?.q107));
|
|
@@ -6930,7 +6757,7 @@
|
|
|
6930
6757
|
}
|
|
6931
6758
|
}
|
|
6932
6759
|
#updateCommsStationOccupancy(update) {
|
|
6933
|
-
const table7 = update.sections.find((
|
|
6760
|
+
const table7 = update.sections.find((section2) => section2.table === 7);
|
|
6934
6761
|
if (!table7) return;
|
|
6935
6762
|
for (const changed of table7.records) {
|
|
6936
6763
|
const record = this.record(7, changed.entity);
|
|
@@ -7256,7 +7083,7 @@
|
|
|
7256
7083
|
const thruster = summarizeThruster2(entityId, typeId, thrusterRecord);
|
|
7257
7084
|
const pusher = summarizePusher2(entityId, pusherRecord, loaderFilterSlotsRecord);
|
|
7258
7085
|
const pusherBeam = summarizePusherBeam2(entityId, pusherBeamRecord);
|
|
7259
|
-
const launcher = summarizeItemLauncher2(entityId, typeId, launcherRecord);
|
|
7086
|
+
const launcher = summarizeItemLauncher2(entityId, typeId, launcherRecord, rec(79));
|
|
7260
7087
|
const loader = typeId === LOADER_TYPE_ID2 || typeId == null && (loaderRecord || loaderFilterRecord || loaderFilterSlotsRecord) ? summarizeLoader2(entityId, loaderRecord, loaderFilterRecord, loaderFilterSlotsRecord, typeId === LOADER_TYPE_ID2, itemHolderRecord) : null;
|
|
7261
7088
|
const cargoHatch = summarizeCargoHatch2(entityId, typeId, loaderFilterRecord, loaderFilterSlotsRecord, rec(45));
|
|
7262
7089
|
const navigationUnit = summarizeNavigationUnit2(entityId, typeId, navigationRecord, this.#navigationUnitAutoWarp.get(entityId));
|
|
@@ -7273,8 +7100,8 @@
|
|
|
7273
7100
|
const helm = summarizeHelm2(entityId, typeId, this.#helmOccupied.get(entityId));
|
|
7274
7101
|
const commsStation = summarizeCommsStation2(entityId, typeId, commsStationRecord, this.#commsStationOccupied.get(entityId));
|
|
7275
7102
|
const sign = typeId === 218 ? summarizeSign2(entityId, signRecord) : null;
|
|
7276
|
-
const spawnPoint = typeId === 219 ? summarizeSpawnPoint2(entityId, spawnPointRecord) : null;
|
|
7277
|
-
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;
|
|
7278
7105
|
const shipSize = shipControl && this.isOverworld ? summarizeShipSize2(entityId, rec(3)) : null;
|
|
7279
7106
|
const hoverOutline = summarizeHoverOutline2(entityId, crateSizeRecord);
|
|
7280
7107
|
const expandoBox = isExpandoBox ? summarizeExpandoBox2(entityId, itemHolderRecord, expandoSizeRecord) : null;
|
|
@@ -7532,7 +7359,7 @@
|
|
|
7532
7359
|
return this.#readSectionRecords(reader, tag, tableId, spec);
|
|
7533
7360
|
}
|
|
7534
7361
|
#readSectionRecords(reader, tag, tableId, spec) {
|
|
7535
|
-
const
|
|
7362
|
+
const section2 = { tag, table: tableId, name: spec?.name || null, records: [] };
|
|
7536
7363
|
let entity = 0;
|
|
7537
7364
|
while (reader.remaining > 0) {
|
|
7538
7365
|
const recordOffset = reader.offset;
|
|
@@ -7559,9 +7386,9 @@
|
|
|
7559
7386
|
throw new Error(`model table ${tableId} tag ${tag} entity ${entity} mask ${mask} offset ${reader.offset}: ${error.message}`);
|
|
7560
7387
|
}
|
|
7561
7388
|
const changed = { entity, mask };
|
|
7562
|
-
|
|
7389
|
+
section2.records.push(changed);
|
|
7563
7390
|
}
|
|
7564
|
-
return
|
|
7391
|
+
return section2;
|
|
7565
7392
|
}
|
|
7566
7393
|
#getRecord(tableId, entity) {
|
|
7567
7394
|
if (!this.tables.has(tableId)) this.tables.set(tableId, /* @__PURE__ */ new Map());
|
|
@@ -7617,11 +7444,11 @@
|
|
|
7617
7444
|
removals: update.removals.length,
|
|
7618
7445
|
unknownTags: update.unknownTags,
|
|
7619
7446
|
error: update.error?.message || null,
|
|
7620
|
-
sections: update.sections.map((
|
|
7621
|
-
tag:
|
|
7622
|
-
table:
|
|
7623
|
-
name:
|
|
7624
|
-
records:
|
|
7447
|
+
sections: update.sections.map((section2) => ({
|
|
7448
|
+
tag: section2.tag,
|
|
7449
|
+
table: section2.table,
|
|
7450
|
+
name: section2.name,
|
|
7451
|
+
records: section2.records.length
|
|
7625
7452
|
}))
|
|
7626
7453
|
};
|
|
7627
7454
|
}
|
|
@@ -8299,12 +8126,44 @@
|
|
|
8299
8126
|
|
|
8300
8127
|
// src/protocol/outbound/chat.js
|
|
8301
8128
|
var CHAT_MESSAGE_TYPE = 2;
|
|
8302
|
-
function buildChatMessage(
|
|
8129
|
+
function buildChatMessage(message2 = "") {
|
|
8303
8130
|
return {
|
|
8304
8131
|
type: CHAT_MESSAGE_TYPE,
|
|
8305
|
-
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
|
+
}))
|
|
8306
8154
|
};
|
|
8307
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
|
+
}
|
|
8308
8167
|
|
|
8309
8168
|
// src/protocol/outbound/commands.js
|
|
8310
8169
|
init_constants();
|
|
@@ -8525,81 +8384,324 @@
|
|
|
8525
8384
|
if (!EQUIPMENT_SLOT_NAMES.has(normalized)) {
|
|
8526
8385
|
throw new RangeError(`equipment slot must be an EquipmentSlot value`);
|
|
8527
8386
|
}
|
|
8528
|
-
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 });
|
|
8529
8566
|
}
|
|
8530
|
-
function
|
|
8531
|
-
|
|
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
|
+
};
|
|
8532
8577
|
}
|
|
8533
|
-
function
|
|
8578
|
+
function normalizeCaptainSubrank(event = {}) {
|
|
8579
|
+
const source = event && typeof event === "object" ? event : {};
|
|
8534
8580
|
return {
|
|
8535
|
-
|
|
8536
|
-
|
|
8537
|
-
target: normalizeInventoryIndex(target, "target"),
|
|
8538
|
-
split: Boolean(split)
|
|
8539
|
-
}
|
|
8581
|
+
subrank: source.subrank ?? null,
|
|
8582
|
+
enableCheats: Boolean(source.enable_cheats)
|
|
8540
8583
|
};
|
|
8541
8584
|
}
|
|
8542
|
-
function
|
|
8543
|
-
const
|
|
8544
|
-
const
|
|
8545
|
-
const
|
|
8546
|
-
const
|
|
8547
|
-
|
|
8548
|
-
|
|
8549
|
-
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 : {};
|
|
8550
8593
|
return {
|
|
8551
|
-
|
|
8552
|
-
|
|
8553
|
-
|
|
8554
|
-
count,
|
|
8555
|
-
|
|
8556
|
-
|
|
8557
|
-
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
|
|
8558
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
|
|
8559
8621
|
};
|
|
8560
|
-
|
|
8561
|
-
|
|
8562
|
-
|
|
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 });
|
|
8563
8632
|
}
|
|
8564
|
-
|
|
8565
|
-
|
|
8566
|
-
|
|
8567
|
-
|
|
8568
|
-
|
|
8569
|
-
|
|
8570
|
-
|
|
8571
|
-
|
|
8572
|
-
|
|
8573
|
-
|
|
8574
|
-
|
|
8575
|
-
|
|
8576
|
-
|
|
8577
|
-
|
|
8578
|
-
|
|
8579
|
-
|
|
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 };
|
|
8580
8663
|
return {
|
|
8581
|
-
|
|
8582
|
-
|
|
8583
|
-
|
|
8584
|
-
|
|
8585
|
-
|
|
8586
|
-
|
|
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
|
|
8587
8678
|
};
|
|
8588
8679
|
}
|
|
8589
|
-
function
|
|
8680
|
+
function normalizeNonNegativeNumber(value) {
|
|
8590
8681
|
const number = Number(value);
|
|
8591
|
-
|
|
8592
|
-
return number;
|
|
8682
|
+
return Number.isFinite(number) && number > 0 ? number : 0;
|
|
8593
8683
|
}
|
|
8594
|
-
function
|
|
8595
|
-
const
|
|
8596
|
-
|
|
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;
|
|
8597
8690
|
}
|
|
8598
|
-
function
|
|
8599
|
-
|
|
8600
|
-
const
|
|
8601
|
-
|
|
8602
|
-
|
|
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;
|
|
8603
8705
|
}
|
|
8604
8706
|
|
|
8605
8707
|
// src/protocol/outbound/sign.js
|
|
@@ -8739,6 +8841,11 @@
|
|
|
8739
8841
|
return number;
|
|
8740
8842
|
}
|
|
8741
8843
|
var CLIPBOARD_TARGET_VALUES = /* @__PURE__ */ new Map([
|
|
8844
|
+
["launcher", 8],
|
|
8845
|
+
["spawn", 9],
|
|
8846
|
+
["spawn-point", 9],
|
|
8847
|
+
["spawnPoint", 9],
|
|
8848
|
+
["door", 10],
|
|
8742
8849
|
["loader", 1],
|
|
8743
8850
|
["loader-config", 1],
|
|
8744
8851
|
["loaderConfig", 1],
|
|
@@ -9185,11 +9292,11 @@
|
|
|
9185
9292
|
send(command = {}) {
|
|
9186
9293
|
return this.client.send(command);
|
|
9187
9294
|
}
|
|
9188
|
-
sendMessage(
|
|
9189
|
-
return this.client.sendMessage(
|
|
9295
|
+
sendMessage(message2, options = {}) {
|
|
9296
|
+
return this.client.sendMessage(message2, options);
|
|
9190
9297
|
}
|
|
9191
|
-
sendRaw(
|
|
9192
|
-
return this.client.sendRaw(
|
|
9298
|
+
sendRaw(message2, options = {}) {
|
|
9299
|
+
return this.client.sendRaw(message2, options);
|
|
9193
9300
|
}
|
|
9194
9301
|
sendEntityCommand(cmd, args = [-1, -1, -1]) {
|
|
9195
9302
|
return this.client.sendEntityCommand(cmd, args);
|
|
@@ -9597,7 +9704,7 @@
|
|
|
9597
9704
|
this.id = Number(data.entity ?? data.id);
|
|
9598
9705
|
this.entity = this.id;
|
|
9599
9706
|
this.position = data.transform || null;
|
|
9600
|
-
this.rotation = data.transform?.
|
|
9707
|
+
this.rotation = data.transform?.rot ?? null;
|
|
9601
9708
|
this.type = entityPublicType(data, this.#contents);
|
|
9602
9709
|
this.features = Object.freeze(entityFeatures(data, this.#contents));
|
|
9603
9710
|
deepFreeze(this.#contents);
|
|
@@ -10051,11 +10158,23 @@
|
|
|
10051
10158
|
get state() {
|
|
10052
10159
|
return summaryForEntity(this.client, this.scope, this.id)?.contents?.launcher || null;
|
|
10053
10160
|
}
|
|
10054
|
-
|
|
10055
|
-
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);
|
|
10056
10175
|
}
|
|
10057
|
-
|
|
10058
|
-
return this.
|
|
10176
|
+
get power() {
|
|
10177
|
+
return this.state?.power;
|
|
10059
10178
|
}
|
|
10060
10179
|
get angleDegrees() {
|
|
10061
10180
|
return this.state?.angleDegrees;
|
|
@@ -10152,8 +10271,8 @@
|
|
|
10152
10271
|
panel() {
|
|
10153
10272
|
return this.client.commsPanels.get(this.id) || null;
|
|
10154
10273
|
}
|
|
10155
|
-
sendMessage(
|
|
10156
|
-
return this.client.sendCommsMessage(
|
|
10274
|
+
sendMessage(message2 = "") {
|
|
10275
|
+
return this.client.sendCommsMessage(message2);
|
|
10157
10276
|
}
|
|
10158
10277
|
};
|
|
10159
10278
|
var SignHandle = class extends MachineHandle {
|
|
@@ -10220,28 +10339,58 @@
|
|
|
10220
10339
|
}
|
|
10221
10340
|
};
|
|
10222
10341
|
var DoorHandle = class extends MachineHandle {
|
|
10223
|
-
|
|
10224
|
-
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 });
|
|
10225
10356
|
}
|
|
10226
10357
|
get state() {
|
|
10227
10358
|
return summaryForEntity(this.client, this.scope, this.id)?.contents?.door || null;
|
|
10228
10359
|
}
|
|
10229
|
-
get
|
|
10230
|
-
return this.state?.
|
|
10360
|
+
get rankMask() {
|
|
10361
|
+
return this.state?.rankMask;
|
|
10362
|
+
}
|
|
10363
|
+
get allowedRanks() {
|
|
10364
|
+
return this.state?.allowedRanks;
|
|
10231
10365
|
}
|
|
10232
10366
|
get open() {
|
|
10233
10367
|
return this.state?.open;
|
|
10234
10368
|
}
|
|
10235
10369
|
};
|
|
10236
10370
|
var SpawnPointHandle = class extends MachineHandle {
|
|
10237
|
-
|
|
10238
|
-
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 });
|
|
10239
10385
|
}
|
|
10240
10386
|
get state() {
|
|
10241
10387
|
return summaryForEntity(this.client, this.scope, this.id)?.contents?.spawnPoint || null;
|
|
10242
10388
|
}
|
|
10243
|
-
get
|
|
10244
|
-
return this.state?.
|
|
10389
|
+
get rankMask() {
|
|
10390
|
+
return this.state?.rankMask;
|
|
10391
|
+
}
|
|
10392
|
+
get allowedRanks() {
|
|
10393
|
+
return this.state?.allowedRanks;
|
|
10245
10394
|
}
|
|
10246
10395
|
};
|
|
10247
10396
|
var ShieldProjectorHandle = class extends MachineHandle {
|
|
@@ -10635,18 +10784,6 @@
|
|
|
10635
10784
|
if (!Number.isInteger(number) || number <= 0) throw new RangeError(`${name} must be a positive integer`);
|
|
10636
10785
|
return number;
|
|
10637
10786
|
}
|
|
10638
|
-
function normalizeDegrees3(value) {
|
|
10639
|
-
const number = Number(value);
|
|
10640
|
-
if (!Number.isFinite(number)) throw new RangeError(`angle must be a finite number`);
|
|
10641
|
-
return (Math.round(number) % 360 + 360) % 360;
|
|
10642
|
-
}
|
|
10643
|
-
function normalizeLauncherPower(value) {
|
|
10644
|
-
const number = Number(value);
|
|
10645
|
-
if (!Number.isInteger(number) || number < 0 || number > 30) {
|
|
10646
|
-
throw new RangeError(`launcher power must be an integer between 0 and 30`);
|
|
10647
|
-
}
|
|
10648
|
-
return number;
|
|
10649
|
-
}
|
|
10650
10787
|
function normalizeScannerResultPacket(packet) {
|
|
10651
10788
|
const manifest = packet?.manifest && typeof packet.manifest === "object" ? packet.manifest : {};
|
|
10652
10789
|
const hasMaterials = manifest.materials && typeof manifest.materials === "object";
|
|
@@ -10866,18 +11003,18 @@
|
|
|
10866
11003
|
this.emit("command", normalized);
|
|
10867
11004
|
return this;
|
|
10868
11005
|
}
|
|
10869
|
-
sendMessage(
|
|
11006
|
+
sendMessage(message2, { afterReady = true } = {}) {
|
|
10870
11007
|
this.#assertWritable();
|
|
10871
11008
|
if (!this.connected || afterReady && !this.ready) {
|
|
10872
|
-
this.#queuedMessages.push({ message, afterReady });
|
|
11009
|
+
this.#queuedMessages.push({ message: message2, afterReady });
|
|
10873
11010
|
return this;
|
|
10874
11011
|
}
|
|
10875
|
-
this.ws.send(encodeMsgpack(
|
|
10876
|
-
this.emit("message",
|
|
11012
|
+
this.ws.send(encodeMsgpack(message2));
|
|
11013
|
+
this.emit("message", message2);
|
|
10877
11014
|
return this;
|
|
10878
11015
|
}
|
|
10879
|
-
sendRaw(
|
|
10880
|
-
return this.sendMessage(
|
|
11016
|
+
sendRaw(message2, options = {}) {
|
|
11017
|
+
return this.sendMessage(message2, options);
|
|
10881
11018
|
}
|
|
10882
11019
|
sendBlueprintPlacement(placement) {
|
|
10883
11020
|
return this.sendMessage(buildBlueprintPlacementMessage(placement));
|
|
@@ -11005,7 +11142,7 @@
|
|
|
11005
11142
|
}
|
|
11006
11143
|
async recoverStarterItem(itemId, { timeout = 1e4 } = {}) {
|
|
11007
11144
|
this.#assertWritable();
|
|
11008
|
-
const
|
|
11145
|
+
const message2 = buildStarterRecoveryMessage(itemId);
|
|
11009
11146
|
if (!Number.isFinite(timeout) || timeout <= 0 || timeout > 2147483647) {
|
|
11010
11147
|
throw new RangeError("timeout must be positive milliseconds no greater than 2147483647");
|
|
11011
11148
|
}
|
|
@@ -11043,7 +11180,7 @@
|
|
|
11043
11180
|
this.on("disconnect", disconnected);
|
|
11044
11181
|
this.on("demote", demoted);
|
|
11045
11182
|
try {
|
|
11046
|
-
this.sendMessage(
|
|
11183
|
+
this.sendMessage(message2);
|
|
11047
11184
|
} catch (error) {
|
|
11048
11185
|
cleanup();
|
|
11049
11186
|
reject(error);
|
|
@@ -11077,7 +11214,7 @@
|
|
|
11077
11214
|
async demoteSelf(options = {}) {
|
|
11078
11215
|
await this.#awaitManagementConfirmation("Self-demotion", buildDemoteSelfMessage(), "demote", () => true, options);
|
|
11079
11216
|
}
|
|
11080
|
-
async #awaitManagementConfirmation(operation,
|
|
11217
|
+
async #awaitManagementConfirmation(operation, message2, event, accept, { timeout = 1e4 } = {}) {
|
|
11081
11218
|
this.#assertWritable();
|
|
11082
11219
|
if (!Number.isFinite(timeout) || timeout <= 0 || timeout > 2147483647) {
|
|
11083
11220
|
throw new RangeError("timeout must be positive milliseconds no greater than 2147483647");
|
|
@@ -11113,7 +11250,7 @@
|
|
|
11113
11250
|
this.on("disconnect", disconnected);
|
|
11114
11251
|
if (event !== "demote") this.on("demote", demoted);
|
|
11115
11252
|
try {
|
|
11116
|
-
this.sendMessage(
|
|
11253
|
+
this.sendMessage(message2);
|
|
11117
11254
|
} catch (error) {
|
|
11118
11255
|
fail(error);
|
|
11119
11256
|
}
|
|
@@ -11125,11 +11262,11 @@
|
|
|
11125
11262
|
sendEntityCommand(cmd, args = [-1, -1, -1]) {
|
|
11126
11263
|
return this.sendMessage({ type: 5, cmd, args });
|
|
11127
11264
|
}
|
|
11128
|
-
sendChatMessage(
|
|
11129
|
-
return this.sendMessage(buildChatMessage(
|
|
11265
|
+
sendChatMessage(message2 = "") {
|
|
11266
|
+
return this.sendMessage(buildChatMessage(message2));
|
|
11130
11267
|
}
|
|
11131
|
-
sendCommsMessage(
|
|
11132
|
-
return this.sendMessage(buildCommsMessage(
|
|
11268
|
+
sendCommsMessage(message2 = "") {
|
|
11269
|
+
return this.sendMessage(buildCommsMessage(message2));
|
|
11133
11270
|
}
|
|
11134
11271
|
sendFabricatorMessage(cmd, args = [-1, -1, -1]) {
|
|
11135
11272
|
return this.sendEntityCommand(cmd, args);
|
|
@@ -11158,11 +11295,38 @@
|
|
|
11158
11295
|
fabricatorEject(row) {
|
|
11159
11296
|
return this.sendFabricatorMessage("eject", [row, -1, -1]);
|
|
11160
11297
|
}
|
|
11161
|
-
|
|
11162
|
-
return this.
|
|
11298
|
+
sendLauncherConfig(entity, config = {}) {
|
|
11299
|
+
return this.sendUiConfig(buildLauncherConfigData(entity, this.#launcherConfigDefaults(entity, config)));
|
|
11163
11300
|
}
|
|
11164
|
-
|
|
11165
|
-
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)));
|
|
11166
11330
|
}
|
|
11167
11331
|
setSignText(text2 = "", mode = 0) {
|
|
11168
11332
|
return this.sendMessage(buildSignTextMessage(text2, mode));
|
|
@@ -11364,14 +11528,14 @@
|
|
|
11364
11528
|
return this.useHeldItem(options, command);
|
|
11365
11529
|
}
|
|
11366
11530
|
placeBlueprint(placement, { invSlot = 0, hold = true, mx = null, my = null } = {}, command = {}) {
|
|
11367
|
-
const
|
|
11368
|
-
this.sendMessage(
|
|
11531
|
+
const message2 = buildBlueprintPlacementMessage(placement);
|
|
11532
|
+
this.sendMessage(message2);
|
|
11369
11533
|
return this.placeHeldItem(
|
|
11370
11534
|
{ invSlot, hold },
|
|
11371
11535
|
{
|
|
11372
11536
|
...command,
|
|
11373
|
-
mx: mx ??
|
|
11374
|
-
my: my ??
|
|
11537
|
+
mx: mx ?? message2.x,
|
|
11538
|
+
my: my ?? message2.y
|
|
11375
11539
|
}
|
|
11376
11540
|
);
|
|
11377
11541
|
}
|
|
@@ -11576,12 +11740,12 @@
|
|
|
11576
11740
|
}
|
|
11577
11741
|
#bindAttachedSocket() {
|
|
11578
11742
|
const open = () => this.#attachedOpen();
|
|
11579
|
-
const
|
|
11743
|
+
const message2 = (event) => this.#handleSocketMessage(event?.data ?? event);
|
|
11580
11744
|
const error = (event) => this.#fail(event?.error || new Error("WebSocket error"));
|
|
11581
11745
|
const close = (event, reason) => this.#handleSocketClose(event, reason);
|
|
11582
11746
|
if (typeof this.ws.addEventListener === "function") {
|
|
11583
11747
|
this.ws.addEventListener("open", open);
|
|
11584
|
-
this.ws.addEventListener("message",
|
|
11748
|
+
this.ws.addEventListener("message", message2);
|
|
11585
11749
|
this.ws.addEventListener("error", error);
|
|
11586
11750
|
this.ws.addEventListener("close", close);
|
|
11587
11751
|
return;
|
|
@@ -11593,7 +11757,7 @@
|
|
|
11593
11757
|
this.ws.on("close", close);
|
|
11594
11758
|
return;
|
|
11595
11759
|
}
|
|
11596
|
-
for (const [type, handler] of Object.entries({ open, message, error, close })) {
|
|
11760
|
+
for (const [type, handler] of Object.entries({ open, message: message2, error, close })) {
|
|
11597
11761
|
const previous = this.ws[`on${type}`];
|
|
11598
11762
|
this.ws[`on${type}`] = (...args) => {
|
|
11599
11763
|
if (typeof previous === "function") previous.apply(this.ws, args);
|
|
@@ -11906,6 +12070,25 @@
|
|
|
11906
12070
|
autoWarpOnNoCaptains: config.autoWarpOnNoCaptains ?? summary?.autoWarpOnNoCaptains ?? false
|
|
11907
12071
|
};
|
|
11908
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
|
+
}
|
|
11909
12092
|
#pusherConfigDefaults(entity, config = {}) {
|
|
11910
12093
|
const summary = this.entity(entity)?.contents?.pusher || null;
|
|
11911
12094
|
return {
|