ygopro-msg-encode 1.1.7 → 1.1.9

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.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
  }
@@ -1449,10 +1452,14 @@ var YGOProCtosTimeConfirm = class extends YGOProCtosBase {
1449
1452
  };
1450
1453
 
1451
1454
  // src/protos/ctos/proto/chat.ts
1455
+ var CTOS_CHAT_MAX_LENGTH = 256;
1452
1456
  var YGOProCtosChat = class extends YGOProCtosBase {
1453
1457
  static {
1454
1458
  this.identifier = 22;
1455
1459
  }
1460
+ static {
1461
+ this.MAX_LENGTH = CTOS_CHAT_MAX_LENGTH;
1462
+ }
1456
1463
  constructor() {
1457
1464
  super();
1458
1465
  this.msg = "";
@@ -1463,10 +1470,7 @@ var YGOProCtosChat = class extends YGOProCtosBase {
1463
1470
  return this;
1464
1471
  }
1465
1472
  toPayload() {
1466
- const encoder = new TextEncoder();
1467
- const utf8 = encoder.encode(this.msg);
1468
- const decoder = new TextDecoder("utf-8");
1469
- const text = decoder.decode(utf8);
1473
+ const text = this.msg.length > CTOS_CHAT_MAX_LENGTH ? this.msg.substring(0, CTOS_CHAT_MAX_LENGTH) : this.msg;
1470
1474
  const utf16 = new Uint16Array(text.length + 1);
1471
1475
  for (let i = 0; i < text.length; i++) {
1472
1476
  utf16[i] = text.charCodeAt(i);
@@ -1484,10 +1488,17 @@ var YGOProCtosChat = class extends YGOProCtosBase {
1484
1488
  };
1485
1489
 
1486
1490
  // src/protos/ctos/proto/external-address.ts
1491
+ var CTOS_EXTERNAL_ADDRESS_MAX_HOSTNAME_LENGTH = 256;
1487
1492
  var YGOProCtosExternalAddress = class extends YGOProCtosBase {
1488
1493
  static {
1489
1494
  this.identifier = 23;
1490
1495
  }
1496
+ static {
1497
+ this.MAX_LENGTH = CTOS_EXTERNAL_ADDRESS_MAX_HOSTNAME_LENGTH;
1498
+ }
1499
+ static {
1500
+ this.MAX_HOSTNAME_LENGTH = CTOS_EXTERNAL_ADDRESS_MAX_HOSTNAME_LENGTH;
1501
+ }
1491
1502
  constructor() {
1492
1503
  super();
1493
1504
  this.real_ip = "0.0.0.0";
@@ -1532,10 +1543,10 @@ var YGOProCtosExternalAddress = class extends YGOProCtosBase {
1532
1543
  return this;
1533
1544
  }
1534
1545
  toPayload() {
1535
- const encoder = new TextEncoder();
1536
- const utf8 = encoder.encode(this.hostname);
1537
- const decoder = new TextDecoder("utf-8");
1538
- const text = decoder.decode(utf8);
1546
+ const text = this.hostname.length > CTOS_EXTERNAL_ADDRESS_MAX_HOSTNAME_LENGTH ? this.hostname.substring(
1547
+ 0,
1548
+ CTOS_EXTERNAL_ADDRESS_MAX_HOSTNAME_LENGTH
1549
+ ) : this.hostname;
1539
1550
  const utf16 = new Uint16Array(text.length + 1);
1540
1551
  for (let i = 0; i < text.length; i++) {
1541
1552
  utf16[i] = text.charCodeAt(i);
@@ -5803,10 +5814,14 @@ __decorateClass([
5803
5814
  ], YGOProStocTimeLimit.prototype, "left_time", 2);
5804
5815
 
5805
5816
  // src/protos/stoc/proto/chat.ts
5817
+ var STOC_CHAT_MAX_LENGTH = 256;
5806
5818
  var YGOProStocChat = class extends YGOProStocBase {
5807
5819
  static {
5808
5820
  this.identifier = 25;
5809
5821
  }
5822
+ static {
5823
+ this.MAX_LENGTH = STOC_CHAT_MAX_LENGTH;
5824
+ }
5810
5825
  constructor() {
5811
5826
  super();
5812
5827
  this.player_type = 0;
@@ -5826,10 +5841,7 @@ var YGOProStocChat = class extends YGOProStocBase {
5826
5841
  return this;
5827
5842
  }
5828
5843
  toPayload() {
5829
- const encoder = new TextEncoder();
5830
- const utf8 = encoder.encode(this.msg);
5831
- const decoder = new TextDecoder("utf-8");
5832
- const text = decoder.decode(utf8);
5844
+ const text = this.msg.length > STOC_CHAT_MAX_LENGTH ? this.msg.substring(0, STOC_CHAT_MAX_LENGTH) : this.msg;
5833
5845
  const utf16 = new Uint16Array(text.length + 1);
5834
5846
  for (let i = 0; i < text.length; i++) {
5835
5847
  utf16[i] = text.charCodeAt(i);