ygopro-msg-encode 1.1.6 → 1.1.8

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/index.d.ts CHANGED
@@ -1,9 +1,6 @@
1
1
  export * from './src/binary/binary-meta';
2
2
  export * from './src/binary/fill-binary-fields';
3
- export * from './src/protos/common';
4
- export * from './src/protos/ctos';
5
- export * from './src/protos/stoc';
6
- export * from './src/protos/msg';
7
- export * from './src/protos/network-enums';
3
+ export * from './src/protos';
8
4
  export * from './src/vendor/ocgcore-constants';
9
5
  export * from './src/vendor/script-constants';
6
+ export * from './src/proto-base';
package/dist/index.mjs CHANGED
@@ -149,7 +149,8 @@ var fillBinaryFields = (obj, data, useClass) => {
149
149
  return;
150
150
  }
151
151
  if (type === "utf8" || type === "utf16") {
152
- const byteLength = resolveLength(obj, info.length, key);
152
+ const lengthValue = resolveLength(obj, info.length, key);
153
+ const byteLength = type === "utf16" ? lengthValue * 2 : lengthValue;
153
154
  obj[key] = readString(type, offset, byteLength);
154
155
  totalSize = Math.max(totalSize, offset + byteLength);
155
156
  return;
@@ -206,7 +207,8 @@ var toBinaryFields = (obj, useClass) => {
206
207
  }
207
208
  }
208
209
  } else if (type === "utf8" || type === "utf16") {
209
- const byteLength = resolveLength(obj, info.length, key);
210
+ const lengthValue = resolveLength(obj, info.length, key);
211
+ const byteLength = type === "utf16" ? lengthValue * 2 : lengthValue;
210
212
  totalSize = Math.max(totalSize, offset + byteLength);
211
213
  } else {
212
214
  const typeSize = getTypeSize(type);
@@ -284,7 +286,8 @@ var toBinaryFields = (obj, useClass) => {
284
286
  return;
285
287
  }
286
288
  if (type === "utf8" || type === "utf16") {
287
- const byteLength = resolveLength(obj, info.length, key);
289
+ const lengthValue = resolveLength(obj, info.length, key);
290
+ const byteLength = type === "utf16" ? lengthValue * 2 : lengthValue;
288
291
  writeString(type, offset, byteLength, value);
289
292
  return;
290
293
  }
@@ -1234,8 +1237,14 @@ var CardQuery = class {
1234
1237
  }
1235
1238
  };
1236
1239
 
1237
- // src/protos/ctos/base.ts
1238
- var YGOProCtosBase = class extends PayloadBase {
1240
+ // src/proto-base/ygopro-proto-base.ts
1241
+ var YGOProProtoBase = class extends PayloadBase {
1242
+ static {
1243
+ this.messageDirection = "";
1244
+ }
1245
+ get messageDirection() {
1246
+ return this.constructor.messageDirection;
1247
+ }
1239
1248
  /**
1240
1249
  * Serialize to full payload including header (length + identifier + body)
1241
1250
  * Format: [length 2 bytes LE][identifier 1 byte][body]
@@ -1261,20 +1270,20 @@ var YGOProCtosBase = class extends PayloadBase {
1261
1270
  fromFullPayload(data) {
1262
1271
  if (data.length < 3) {
1263
1272
  throw new Error(
1264
- `CTOS payload too short: expected at least 3 bytes, got ${data.length}`
1273
+ `${this.messageDirection} payload too short: expected at least 3 bytes, got ${data.length}`
1265
1274
  );
1266
1275
  }
1267
1276
  const declaredLength = data[0] | data[1] << 8;
1268
1277
  const identifier = data[2];
1269
1278
  if (identifier !== this.identifier) {
1270
1279
  throw new Error(
1271
- `CTOS identifier mismatch: expected 0x${this.identifier.toString(16)}, got 0x${identifier.toString(16)}`
1280
+ `${this.messageDirection} identifier mismatch: expected 0x${this.identifier.toString(16)}, got 0x${identifier.toString(16)}`
1272
1281
  );
1273
1282
  }
1274
1283
  const expectedTotalLength = 3 + declaredLength - 1;
1275
1284
  if (data.length < expectedTotalLength) {
1276
1285
  throw new Error(
1277
- `CTOS payload too short: declared length ${declaredLength} requires ${expectedTotalLength} bytes total, got ${data.length}`
1286
+ `${this.messageDirection} payload too short: declared length ${declaredLength} requires ${expectedTotalLength} bytes total, got ${data.length}`
1278
1287
  );
1279
1288
  }
1280
1289
  const bodyData = data.length > expectedTotalLength ? data.slice(3, expectedTotalLength) : data.slice(3);
@@ -1282,6 +1291,13 @@ var YGOProCtosBase = class extends PayloadBase {
1282
1291
  }
1283
1292
  };
1284
1293
 
1294
+ // src/protos/ctos/base.ts
1295
+ var YGOProCtosBase = class extends YGOProProtoBase {
1296
+ static {
1297
+ this.messageDirection = "CTOS";
1298
+ }
1299
+ };
1300
+
1285
1301
  // src/proto-base/registry-base.ts
1286
1302
  var RegistryBase = class {
1287
1303
  constructor(payloadClass, options = {}) {
@@ -1436,10 +1452,13 @@ var YGOProCtosTimeConfirm = class extends YGOProCtosBase {
1436
1452
  };
1437
1453
 
1438
1454
  // src/protos/ctos/proto/chat.ts
1439
- var YGOProCtosChat = class extends YGOProCtosBase {
1455
+ var YGOProCtosChat = class _YGOProCtosChat extends YGOProCtosBase {
1440
1456
  static {
1441
1457
  this.identifier = 22;
1442
1458
  }
1459
+ static {
1460
+ this.MAX_LENGTH = 256;
1461
+ }
1443
1462
  constructor() {
1444
1463
  super();
1445
1464
  this.msg = "";
@@ -1450,10 +1469,7 @@ var YGOProCtosChat = class extends YGOProCtosBase {
1450
1469
  return this;
1451
1470
  }
1452
1471
  toPayload() {
1453
- const encoder = new TextEncoder();
1454
- const utf8 = encoder.encode(this.msg);
1455
- const decoder = new TextDecoder("utf-8");
1456
- const text = decoder.decode(utf8);
1472
+ const text = this.msg.length > _YGOProCtosChat.MAX_LENGTH ? this.msg.substring(0, _YGOProCtosChat.MAX_LENGTH) : this.msg;
1457
1473
  const utf16 = new Uint16Array(text.length + 1);
1458
1474
  for (let i = 0; i < text.length; i++) {
1459
1475
  utf16[i] = text.charCodeAt(i);
@@ -1471,10 +1487,13 @@ var YGOProCtosChat = class extends YGOProCtosBase {
1471
1487
  };
1472
1488
 
1473
1489
  // src/protos/ctos/proto/external-address.ts
1474
- var YGOProCtosExternalAddress = class extends YGOProCtosBase {
1490
+ var YGOProCtosExternalAddress = class _YGOProCtosExternalAddress extends YGOProCtosBase {
1475
1491
  static {
1476
1492
  this.identifier = 23;
1477
1493
  }
1494
+ static {
1495
+ this.MAX_HOSTNAME_LENGTH = 256;
1496
+ }
1478
1497
  constructor() {
1479
1498
  super();
1480
1499
  this.real_ip = "0.0.0.0";
@@ -1519,10 +1538,10 @@ var YGOProCtosExternalAddress = class extends YGOProCtosBase {
1519
1538
  return this;
1520
1539
  }
1521
1540
  toPayload() {
1522
- const encoder = new TextEncoder();
1523
- const utf8 = encoder.encode(this.hostname);
1524
- const decoder = new TextDecoder("utf-8");
1525
- const text = decoder.decode(utf8);
1541
+ const text = this.hostname.length > _YGOProCtosExternalAddress.MAX_HOSTNAME_LENGTH ? this.hostname.substring(
1542
+ 0,
1543
+ _YGOProCtosExternalAddress.MAX_HOSTNAME_LENGTH
1544
+ ) : this.hostname;
1526
1545
  const utf16 = new Uint16Array(text.length + 1);
1527
1546
  for (let i = 0; i < text.length; i++) {
1528
1547
  utf16[i] = text.charCodeAt(i);
@@ -1626,50 +1645,9 @@ YGOProCtos.register(YGOProCtosHsStart);
1626
1645
  YGOProCtos.register(YGOProCtosRequestField);
1627
1646
 
1628
1647
  // src/protos/stoc/base.ts
1629
- var YGOProStocBase = class extends PayloadBase {
1630
- /**
1631
- * Serialize to full payload including header (length + identifier + body)
1632
- * Format: [length 2 bytes LE][identifier 1 byte][body]
1633
- * Length = 1 (identifier) + body.length
1634
- */
1635
- toFullPayload() {
1636
- const body = this.toPayload();
1637
- const length = 1 + body.length;
1638
- const fullPayload = new Uint8Array(3 + body.length);
1639
- fullPayload[0] = length & 255;
1640
- fullPayload[1] = length >> 8 & 255;
1641
- fullPayload[2] = this.identifier;
1642
- fullPayload.set(body, 3);
1643
- return fullPayload;
1644
- }
1645
- /**
1646
- * Deserialize from full payload including header (length + identifier + body)
1647
- * Format: [length 2 bytes LE][identifier 1 byte][body]
1648
- * @param data - Full payload data
1649
- * @returns this instance
1650
- * @throws Error if data is too short or identifier mismatch
1651
- */
1652
- fromFullPayload(data) {
1653
- if (data.length < 3) {
1654
- throw new Error(
1655
- `STOC payload too short: expected at least 3 bytes, got ${data.length}`
1656
- );
1657
- }
1658
- const declaredLength = data[0] | data[1] << 8;
1659
- const identifier = data[2];
1660
- if (identifier !== this.identifier) {
1661
- throw new Error(
1662
- `STOC identifier mismatch: expected 0x${this.identifier.toString(16)}, got 0x${identifier.toString(16)}`
1663
- );
1664
- }
1665
- const expectedTotalLength = 3 + declaredLength - 1;
1666
- if (data.length < expectedTotalLength) {
1667
- throw new Error(
1668
- `STOC payload too short: declared length ${declaredLength} requires ${expectedTotalLength} bytes total, got ${data.length}`
1669
- );
1670
- }
1671
- const bodyData = data.length > expectedTotalLength ? data.slice(3, expectedTotalLength) : data.slice(3);
1672
- return this.fromPayload(bodyData);
1648
+ var YGOProStocBase = class extends YGOProProtoBase {
1649
+ static {
1650
+ this.messageDirection = "STOC";
1673
1651
  }
1674
1652
  };
1675
1653
 
@@ -5831,10 +5809,13 @@ __decorateClass([
5831
5809
  ], YGOProStocTimeLimit.prototype, "left_time", 2);
5832
5810
 
5833
5811
  // src/protos/stoc/proto/chat.ts
5834
- var YGOProStocChat = class extends YGOProStocBase {
5812
+ var YGOProStocChat = class _YGOProStocChat extends YGOProStocBase {
5835
5813
  static {
5836
5814
  this.identifier = 25;
5837
5815
  }
5816
+ static {
5817
+ this.MAX_LENGTH = 256;
5818
+ }
5838
5819
  constructor() {
5839
5820
  super();
5840
5821
  this.player_type = 0;
@@ -5854,10 +5835,7 @@ var YGOProStocChat = class extends YGOProStocBase {
5854
5835
  return this;
5855
5836
  }
5856
5837
  toPayload() {
5857
- const encoder = new TextEncoder();
5858
- const utf8 = encoder.encode(this.msg);
5859
- const decoder = new TextDecoder("utf-8");
5860
- const text = decoder.decode(utf8);
5838
+ const text = this.msg.length > _YGOProStocChat.MAX_LENGTH ? this.msg.substring(0, _YGOProStocChat.MAX_LENGTH) : this.msg;
5861
5839
  const utf16 = new Uint16Array(text.length + 1);
5862
5840
  for (let i = 0; i < text.length; i++) {
5863
5841
  utf16[i] = text.charCodeAt(i);
@@ -6039,7 +6017,9 @@ export {
6039
6017
  NetPlayerType,
6040
6018
  OcgcoreCommonConstants,
6041
6019
  OcgcoreScriptConstants,
6020
+ PayloadBase,
6042
6021
  PlayerChangeState,
6022
+ RegistryBase,
6043
6023
  RoomStatus,
6044
6024
  SEND_TO_ALL,
6045
6025
  SEND_TO_PLAYERS,
@@ -6183,6 +6163,7 @@ export {
6183
6163
  YGOProMsgUpdateData,
6184
6164
  YGOProMsgWaiting,
6185
6165
  YGOProMsgWin,
6166
+ YGOProProtoBase,
6186
6167
  YGOProStoc,
6187
6168
  YGOProStocBase,
6188
6169
  YGOProStocChangeSide,