@honeybbq/teamspeak-client 0.0.0 → 0.1.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.
Files changed (137) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +208 -0
  3. package/dist/api.d.ts +17 -0
  4. package/dist/api.d.ts.map +1 -0
  5. package/dist/client.d.ts +39 -0
  6. package/dist/client.d.ts.map +1 -0
  7. package/dist/command/command.d.ts +12 -0
  8. package/dist/command/command.d.ts.map +1 -0
  9. package/dist/command/command.test.d.ts +2 -0
  10. package/dist/command/command.test.d.ts.map +1 -0
  11. package/dist/command/index.cjs +1 -0
  12. package/dist/command/index.d.ts +4 -0
  13. package/dist/command/index.d.ts.map +1 -0
  14. package/dist/command/index.mjs +3 -0
  15. package/dist/command/parser.d.ts +3 -0
  16. package/dist/command/parser.d.ts.map +1 -0
  17. package/dist/command-Cu2v-5-K.cjs +4 -0
  18. package/dist/command-Cu2v-5-K.cjs.map +1 -0
  19. package/dist/command-caXc4h0n.js +76 -0
  20. package/dist/command-caXc4h0n.js.map +1 -0
  21. package/dist/commands.d.ts +48 -0
  22. package/dist/commands.d.ts.map +1 -0
  23. package/dist/crypt-handshake-CHmvZ2qs.js +55 -0
  24. package/dist/crypt-handshake-CHmvZ2qs.js.map +1 -0
  25. package/dist/crypt-handshake-Dbj2cSBZ.cjs +2 -0
  26. package/dist/crypt-handshake-Dbj2cSBZ.cjs.map +1 -0
  27. package/dist/crypt-init2-BIbQ7TN0.cjs +2 -0
  28. package/dist/crypt-init2-BIbQ7TN0.cjs.map +1 -0
  29. package/dist/crypt-init2-C63eypta.js +165 -0
  30. package/dist/crypt-init2-C63eypta.js.map +1 -0
  31. package/dist/crypto/crypt-ops.d.ts +7 -0
  32. package/dist/crypto/crypt-ops.d.ts.map +1 -0
  33. package/dist/crypto/crypt.d.ts +22 -0
  34. package/dist/crypto/crypt.d.ts.map +1 -0
  35. package/dist/crypto/eax.d.ts +12 -0
  36. package/dist/crypto/eax.d.ts.map +1 -0
  37. package/dist/crypto/eax.test.d.ts +2 -0
  38. package/dist/crypto/eax.test.d.ts.map +1 -0
  39. package/dist/crypto/identity.d.ts +18 -0
  40. package/dist/crypto/identity.d.ts.map +1 -0
  41. package/dist/crypto/identity.test.d.ts +2 -0
  42. package/dist/crypto/identity.test.d.ts.map +1 -0
  43. package/dist/crypto/index.cjs +1 -0
  44. package/dist/crypto/index.d.ts +6 -0
  45. package/dist/crypto/index.d.ts.map +1 -0
  46. package/dist/crypto/index.mjs +3 -0
  47. package/dist/crypto/primitives.d.ts +28 -0
  48. package/dist/crypto/primitives.d.ts.map +1 -0
  49. package/dist/crypto-C3gBJkh2.cjs +2 -0
  50. package/dist/crypto-C3gBJkh2.cjs.map +1 -0
  51. package/dist/crypto-IGJlkTAl.js +165 -0
  52. package/dist/crypto-IGJlkTAl.js.map +1 -0
  53. package/dist/discovery/index.cjs +1 -0
  54. package/dist/discovery/index.d.ts +2 -0
  55. package/dist/discovery/index.d.ts.map +1 -0
  56. package/dist/discovery/index.mjs +2 -0
  57. package/dist/discovery/resolver.d.ts +8 -0
  58. package/dist/discovery/resolver.d.ts.map +1 -0
  59. package/dist/errors.d.ts +34 -0
  60. package/dist/errors.d.ts.map +1 -0
  61. package/dist/events.d.ts +10 -0
  62. package/dist/events.d.ts.map +1 -0
  63. package/dist/handler-C2vxlHYC.js +458 -0
  64. package/dist/handler-C2vxlHYC.js.map +1 -0
  65. package/dist/handler-DQteUMKT.cjs +2 -0
  66. package/dist/handler-DQteUMKT.cjs.map +1 -0
  67. package/dist/handshake/crypt-handshake.d.ts +8 -0
  68. package/dist/handshake/crypt-handshake.d.ts.map +1 -0
  69. package/dist/handshake/crypt-init2.d.ts +7 -0
  70. package/dist/handshake/crypt-init2.d.ts.map +1 -0
  71. package/dist/handshake/index.cjs +1 -0
  72. package/dist/handshake/index.d.ts +4 -0
  73. package/dist/handshake/index.d.ts.map +1 -0
  74. package/dist/handshake/index.mjs +3 -0
  75. package/dist/handshake/license.d.ts +28 -0
  76. package/dist/handshake/license.d.ts.map +1 -0
  77. package/dist/handshake.d.ts +9 -0
  78. package/dist/handshake.d.ts.map +1 -0
  79. package/dist/helpers.d.ts +14 -0
  80. package/dist/helpers.d.ts.map +1 -0
  81. package/dist/helpers.test.d.ts +2 -0
  82. package/dist/helpers.test.d.ts.map +1 -0
  83. package/dist/index.cjs +2 -0
  84. package/dist/index.cjs.map +1 -0
  85. package/dist/index.d.ts +9 -0
  86. package/dist/index.d.ts.map +1 -0
  87. package/dist/index.mjs +761 -0
  88. package/dist/index.mjs.map +1 -0
  89. package/dist/integration.test.d.ts +12 -0
  90. package/dist/integration.test.d.ts.map +1 -0
  91. package/dist/notifications.d.ts +32 -0
  92. package/dist/notifications.d.ts.map +1 -0
  93. package/dist/notifications.test.d.ts +2 -0
  94. package/dist/notifications.test.d.ts.map +1 -0
  95. package/dist/parser-CJjP3LlO.js +33 -0
  96. package/dist/parser-CJjP3LlO.js.map +1 -0
  97. package/dist/parser-DhAWj-TI.cjs +2 -0
  98. package/dist/parser-DhAWj-TI.cjs.map +1 -0
  99. package/dist/primitives-BxtDMP7x.cjs +2 -0
  100. package/dist/primitives-BxtDMP7x.cjs.map +1 -0
  101. package/dist/primitives-CmIK1O7L.js +1836 -0
  102. package/dist/primitives-CmIK1O7L.js.map +1 -0
  103. package/dist/resolver-DDZWomrF.js +165 -0
  104. package/dist/resolver-DDZWomrF.js.map +1 -0
  105. package/dist/resolver-Dey6omBe.cjs +4 -0
  106. package/dist/resolver-Dey6omBe.cjs.map +1 -0
  107. package/dist/throttle.d.ts +11 -0
  108. package/dist/throttle.d.ts.map +1 -0
  109. package/dist/throttle.test.d.ts +2 -0
  110. package/dist/throttle.test.d.ts.map +1 -0
  111. package/dist/transfer.d.ts +34 -0
  112. package/dist/transfer.d.ts.map +1 -0
  113. package/dist/transport/generation-window.d.ts +15 -0
  114. package/dist/transport/generation-window.d.ts.map +1 -0
  115. package/dist/transport/generation-window.test.d.ts +2 -0
  116. package/dist/transport/generation-window.test.d.ts.map +1 -0
  117. package/dist/transport/handler.d.ts +18 -0
  118. package/dist/transport/handler.d.ts.map +1 -0
  119. package/dist/transport/index.cjs +1 -0
  120. package/dist/transport/index.d.ts +6 -0
  121. package/dist/transport/index.d.ts.map +1 -0
  122. package/dist/transport/index.mjs +2 -0
  123. package/dist/transport/packet.d.ts +36 -0
  124. package/dist/transport/packet.d.ts.map +1 -0
  125. package/dist/transport/packet.test.d.ts +2 -0
  126. package/dist/transport/packet.test.d.ts.map +1 -0
  127. package/dist/transport/quicklz.d.ts +5 -0
  128. package/dist/transport/quicklz.d.ts.map +1 -0
  129. package/dist/transport/quicklz.test.d.ts +2 -0
  130. package/dist/transport/quicklz.test.d.ts.map +1 -0
  131. package/dist/types-CGKgXvpG.js +18 -0
  132. package/dist/types-CGKgXvpG.js.map +1 -0
  133. package/dist/types-DrnoCdSW.cjs +2 -0
  134. package/dist/types-DrnoCdSW.cjs.map +1 -0
  135. package/dist/types.d.ts +114 -0
  136. package/dist/types.d.ts.map +1 -0
  137. package/package.json +87 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crypto-IGJlkTAl.js","names":["#key","#cmac","#cachedKeys","#getSharedSecret"],"sources":["../src/crypto/eax.ts","../src/crypto/crypt.ts"],"sourcesContent":["import { createCipheriv, timingSafeEqual } from \"node:crypto\";\nimport { EAXTagMismatchError } from \"../errors.js\";\n\nconst EAX_TAG_SIZE = 8;\nconst EAX_BLOCK_SIZE = 16;\n\n/**\n * AES-EAX AEAD implementation for TS3 (64-bit tag, AES-128).\n * Uses AES-CMAC for authentication and AES-CTR for encryption.\n */\nexport class EAX {\n readonly #key: Uint8Array;\n\n constructor(key: Uint8Array) {\n if (key.length !== 16) throw new Error(\"EAX requires a 16-byte key\");\n this.#key = key;\n }\n\n encrypt(\n nonce: Uint8Array,\n header: Uint8Array,\n plaintext: Uint8Array,\n ): [ciphertext: Uint8Array, tag: Uint8Array] {\n const nStar = this.#cmac(0, nonce);\n const hStar = this.#cmac(1, header);\n\n const ciphertext = aesCtr(this.#key, nStar, plaintext);\n\n const cStar = this.#cmac(2, ciphertext);\n\n const tag = new Uint8Array(EAX_TAG_SIZE);\n for (let i = 0; i < EAX_TAG_SIZE; i++) {\n tag[i] = nStar[i]! ^ hStar[i]! ^ cStar[i]!;\n }\n\n return [ciphertext, tag];\n }\n\n decrypt(\n nonce: Uint8Array,\n header: Uint8Array,\n ciphertext: Uint8Array,\n tag: Uint8Array,\n ): Uint8Array {\n const nStar = this.#cmac(0, nonce);\n const hStar = this.#cmac(1, header);\n const cStar = this.#cmac(2, ciphertext);\n\n const expected = new Uint8Array(EAX_TAG_SIZE);\n for (let i = 0; i < EAX_TAG_SIZE; i++) {\n expected[i] = nStar[i]! ^ hStar[i]! ^ cStar[i]!;\n }\n\n if (!timingSafeEqual(Buffer.from(expected), Buffer.from(tag.slice(0, EAX_TAG_SIZE)))) {\n throw new EAXTagMismatchError();\n }\n\n return aesCtr(this.#key, nStar, ciphertext);\n }\n\n /**\n * AES-CMAC per RFC 4493:\n * input = [0…0 tag] ++ data (one block prefix)\n */\n #cmac(tagByte: number, data: Uint8Array): Uint8Array {\n const input = new Uint8Array(EAX_BLOCK_SIZE + data.length);\n // first block: zeros then tag byte at the last position\n input[EAX_BLOCK_SIZE - 1] = tagByte;\n input.set(data, EAX_BLOCK_SIZE);\n\n return aesCmac(this.#key, input);\n }\n}\n\n// ---- AES-CTR ----------------------------------------------------------------\n\nfunction aesCtr(key: Uint8Array, iv: Uint8Array, data: Uint8Array): Uint8Array {\n const cipher = createCipheriv(\"aes-128-ctr\", Buffer.from(key), Buffer.from(iv));\n return Buffer.concat([cipher.update(Buffer.from(data)), cipher.final()]);\n}\n\n// ---- AES-CMAC (RFC 4493) ----------------------------------------------------\n\nfunction aesEcb(key: Uint8Array, block: Uint8Array): Uint8Array {\n // Node.js does not expose ECB directly; simulate via CTR with zero IV and\n // a zero-input (CTR of 0-block XOR with input = ECB)\n const cipher = createCipheriv(\"aes-128-ecb\", Buffer.from(key), null);\n cipher.setAutoPadding(false);\n return Buffer.concat([cipher.update(Buffer.from(block)), cipher.final()]);\n}\n\nfunction xorBlock(a: Uint8Array, b: Uint8Array): Uint8Array {\n const out = new Uint8Array(EAX_BLOCK_SIZE);\n for (let i = 0; i < EAX_BLOCK_SIZE; i++) out[i] = a[i]! ^ b[i]!;\n return out;\n}\n\nfunction shiftLeft1(b: Uint8Array): Uint8Array {\n const out = new Uint8Array(EAX_BLOCK_SIZE);\n let carry = 0;\n for (let i = EAX_BLOCK_SIZE - 1; i >= 0; i--) {\n const shifted = ((b[i]! << 1) | carry) & 0xff;\n carry = b[i]! >> 7;\n out[i] = shifted;\n }\n return out;\n}\n\nconst RB = new Uint8Array(EAX_BLOCK_SIZE);\nRB[EAX_BLOCK_SIZE - 1] = 0x87;\n\nfunction generateSubkeys(key: Uint8Array): [Uint8Array, Uint8Array] {\n const zero = new Uint8Array(EAX_BLOCK_SIZE);\n const L = aesEcb(key, zero);\n\n let K1 = shiftLeft1(L);\n if ((L[0]! & 0x80) !== 0) K1 = xorBlock(K1, RB);\n\n let K2 = shiftLeft1(K1);\n if ((K1[0]! & 0x80) !== 0) K2 = xorBlock(K2, RB);\n\n return [K1, K2];\n}\n\nexport function aesCmac(key: Uint8Array, message: Uint8Array): Uint8Array {\n const [K1, K2] = generateSubkeys(key);\n\n const n = Math.max(1, Math.ceil(message.length / EAX_BLOCK_SIZE));\n const lastBlockComplete = message.length > 0 && message.length % EAX_BLOCK_SIZE === 0;\n\n let X: Uint8Array = new Uint8Array(EAX_BLOCK_SIZE);\n\n for (let i = 0; i < n - 1; i++) {\n const block = message.slice(i * EAX_BLOCK_SIZE, (i + 1) * EAX_BLOCK_SIZE);\n X = Uint8Array.from(aesEcb(key, xorBlock(X, block)));\n }\n\n const lastBlock = new Uint8Array(EAX_BLOCK_SIZE);\n const lastStart = (n - 1) * EAX_BLOCK_SIZE;\n const lastSlice = message.slice(lastStart);\n lastBlock.set(lastSlice);\n\n let Mn: Uint8Array;\n if (lastBlockComplete) {\n Mn = xorBlock(lastBlock, K1);\n } else {\n if (lastSlice.length < EAX_BLOCK_SIZE) lastBlock[lastSlice.length] = 0x80;\n Mn = xorBlock(lastBlock, K2);\n }\n\n return Uint8Array.from(aesEcb(key, xorBlock(X, Mn)));\n}\n","import { createHash, createECDH } from \"node:crypto\";\nimport { FakeSignatureMismatchError } from \"../errors.js\";\nimport type { Identity } from \"./identity.js\";\nimport { importPublicKey } from \"./identity.js\";\nimport { EAX } from \"./eax.js\";\n\nconst FAKE_SIGNATURE_SIZE = 8;\nconst IV_ALPHA_SIZE = 10;\nconst INIT1_PACKET_TYPE = 8;\nconst PACKET_TYPE_MASK = 0x0f;\n\nconst INIT1_MAC = Buffer.from(\"TS3INIT1\");\n\nexport interface KeyNonce {\n key: Uint8Array;\n nonce: Uint8Array;\n gen: number;\n}\n\n/** Precomputed dummy key/nonce matching the TS3 client pre-crypto placeholder. */\nconst DUMMY_KEY = Buffer.from(\"c:\\\\windows\\\\syste\");\nconst DUMMY_NONCE = Buffer.from(\"m\\\\firewall32.cpl\");\n\nexport class Crypt {\n readonly identity: Identity;\n\n ivStruct: Uint8Array = new Uint8Array(0);\n fakeSignature: Uint8Array = new Uint8Array(FAKE_SIGNATURE_SIZE);\n alphaTmp: Uint8Array = new Uint8Array(0);\n cryptoInitComplete = false;\n\n readonly #cachedKeys = new Map<bigint, KeyNonce>();\n\n constructor(identity: Identity) {\n this.identity = identity;\n }\n\n solveRsaChallenge(data: Uint8Array, offset: number, level: number): Uint8Array {\n if (level < 0 || level > 1_000_000) {\n throw new Error(\"RSA challenge level out of range\");\n }\n\n const xBytes = data.slice(offset, offset + 64);\n const nBytes = data.slice(offset + 64, offset + 128);\n\n let y = bytesToBigInt(xBytes);\n const n = bytesToBigInt(nBytes);\n\n for (let i = 0; i < level; i++) {\n y = (y * y) % n;\n }\n\n return bigIntToBytes(y, 64);\n }\n\n initCrypto(alpha: string, beta: string, omega: string): void {\n const alphaBytes = Buffer.from(alpha, \"base64\");\n const betaBytes = Buffer.from(beta, \"base64\");\n const omegaBytes = Buffer.from(omega, \"base64\");\n\n const serverPubKey = importPublicKey(omegaBytes);\n const sharedSecret = this.#getSharedSecret(serverPubKey);\n\n this.setSharedSecret(alphaBytes, betaBytes, sharedSecret);\n }\n\n setSharedSecret(alpha: Uint8Array, beta: Uint8Array, sharedKey: Uint8Array): void {\n this.ivStruct = new Uint8Array(IV_ALPHA_SIZE + beta.length);\n for (let i = 0; i < IV_ALPHA_SIZE; i++) {\n const a = sharedKey[i];\n const b = alpha[i];\n this.ivStruct[i] = ((a !== undefined ? a : 0) ^ (b !== undefined ? b : 0)) & 0xff;\n }\n for (let i = 0; i < beta.length; i++) {\n const a = sharedKey[IV_ALPHA_SIZE + i];\n const b = beta[i];\n this.ivStruct[IV_ALPHA_SIZE + i] =\n ((a !== undefined ? a : 0) ^ (b !== undefined ? b : 0)) & 0xff;\n }\n\n const digest = createHash(\"sha1\").update(this.ivStruct).digest();\n this.fakeSignature = new Uint8Array(digest.buffer, digest.byteOffset, FAKE_SIGNATURE_SIZE);\n this.cryptoInitComplete = true;\n }\n\n getKeyNonce(\n fromServer: boolean,\n packetID: number,\n generationID: number,\n packetType: number,\n dummy: boolean,\n ): [key: Uint8Array, nonce: Uint8Array] {\n if (dummy) {\n return [Uint8Array.from(DUMMY_KEY), Uint8Array.from(DUMMY_NONCE)];\n }\n\n const cacheKey = makeCacheKey(fromServer, packetType, generationID);\n let kn = this.#cachedKeys.get(cacheKey);\n\n if (kn === undefined) {\n const tmpToHash = new Uint8Array(6 + this.ivStruct.length);\n tmpToHash[0] = fromServer ? 0x30 : 0x31;\n tmpToHash[1] = packetType & PACKET_TYPE_MASK;\n new DataView(tmpToHash.buffer).setUint32(2, generationID, false);\n tmpToHash.set(this.ivStruct, 6);\n\n const hash = createHash(\"sha256\").update(tmpToHash).digest();\n kn = {\n key: Uint8Array.from(hash.slice(0, 16)),\n nonce: Uint8Array.from(hash.slice(16, 32)),\n gen: generationID,\n };\n this.#cachedKeys.set(cacheKey, kn);\n }\n\n const key = Uint8Array.from(kn.key);\n key[0] = (key[0] !== undefined ? key[0] : 0) ^ ((packetID >> 8) & 0xff);\n key[1] = (key[1] !== undefined ? key[1] : 0) ^ (packetID & 0xff);\n\n return [key, kn.nonce];\n }\n\n encrypt(\n packetType: number,\n packetID: number,\n generationID: number,\n header: Uint8Array,\n plaintext: Uint8Array,\n dummy: boolean,\n unencrypted: boolean,\n ): [ciphertext: Uint8Array, mac: Uint8Array] {\n if (packetType === INIT1_PACKET_TYPE) {\n return [plaintext, INIT1_MAC];\n }\n if (unencrypted) {\n return [plaintext, this.fakeSignature];\n }\n\n const [key, nonce] = this.getKeyNonce(false, packetID, generationID, packetType, dummy);\n const eax = new EAX(key);\n return eax.encrypt(nonce, header, plaintext);\n }\n\n decrypt(\n packetType: number,\n packetID: number,\n generationID: number,\n header: Uint8Array,\n ciphertext: Uint8Array,\n tag: Uint8Array,\n dummy: boolean,\n unencrypted: boolean,\n ): Uint8Array {\n if (packetType === INIT1_PACKET_TYPE) {\n return ciphertext;\n }\n if (unencrypted) {\n const fsSub = tag.slice(0, FAKE_SIGNATURE_SIZE);\n if (!Buffer.from(fsSub).equals(Buffer.from(this.fakeSignature))) {\n throw new FakeSignatureMismatchError();\n }\n return ciphertext;\n }\n\n const [key, nonce] = this.getKeyNonce(true, packetID, generationID, packetType, dummy);\n const eax = new EAX(key);\n return eax.decrypt(nonce, header, ciphertext, tag);\n }\n\n #getSharedSecret(serverPubKey: import(\"node:crypto\").KeyObject): Uint8Array {\n const privJwk = this.identity.privateKey.export({ format: \"jwk\" }) as {\n d: string;\n };\n const pubJwk = serverPubKey.export({ format: \"jwk\" }) as {\n x: string;\n y: string;\n };\n\n const ecdh = createECDH(\"prime256v1\");\n const dBytes = Buffer.from(privJwk.d, \"base64url\");\n ecdh.setPrivateKey(dBytes);\n\n const xBytes = base64UrlToBytes(pubJwk.x, 32);\n const yBytes = base64UrlToBytes(pubJwk.y, 32);\n const uncompressed = Buffer.alloc(65);\n uncompressed[0] = 0x04;\n xBytes.copy(uncompressed, 1);\n yBytes.copy(uncompressed, 33);\n\n const rawSecret = ecdh.computeSecret(uncompressed);\n return createHash(\"sha1\").update(rawSecret).digest();\n }\n}\n\n// ---- Helpers ----------------------------------------------------------------\n\nfunction makeCacheKey(fromServer: boolean, packetType: number, generationID: number): bigint {\n let key = 0n;\n if (fromServer) key |= 1n << 40n;\n key |= BigInt(packetType & PACKET_TYPE_MASK) << 32n;\n key |= BigInt(generationID);\n return key;\n}\n\nfunction bytesToBigInt(bytes: Uint8Array): bigint {\n let result = 0n;\n for (const b of bytes) result = (result << 8n) | BigInt(b);\n return result;\n}\n\nfunction bigIntToBytes(value: bigint, size: number): Uint8Array {\n const result = new Uint8Array(size);\n let v = value;\n for (let i = size - 1; i >= 0; i--) {\n result[i] = Number(v & 0xffn);\n v >>= 8n;\n }\n return result;\n}\n\nfunction base64UrlToBytes(b64url: string, size: number): Buffer {\n const buf = Buffer.from(b64url, \"base64url\");\n if (buf.length === size) return buf;\n const padded = Buffer.alloc(size);\n buf.copy(padded, size - buf.length);\n return padded;\n}\n"],"mappings":";;;AAGA,IAAM,IAAe,GACf,IAAiB,IAMV,IAAb,MAAiB;CACf;CAEA,YAAY,GAAiB;AAC3B,MAAI,EAAI,WAAW,GAAI,OAAU,MAAM,6BAA6B;AACpE,QAAA,IAAY;;CAGd,QACE,GACA,GACA,GAC2C;EAC3C,IAAM,IAAQ,MAAA,EAAW,GAAG,EAAM,EAC5B,IAAQ,MAAA,EAAW,GAAG,EAAO,EAE7B,IAAa,EAAO,MAAA,GAAW,GAAO,EAAU,EAEhD,IAAQ,MAAA,EAAW,GAAG,EAAW,EAEjC,IAAM,IAAI,WAAW,EAAa;AACxC,OAAK,IAAI,IAAI,GAAG,IAAI,GAAc,IAChC,GAAI,KAAK,EAAM,KAAM,EAAM,KAAM,EAAM;AAGzC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K,cAAc,EAAa;AAClD,SAAO,EAAW,OAAO,CAAC,OAAO,EAAU,CAAC,QAAQ;;;AAMxD,SAAS,EAAa,GAAqB,GAAoB,GAA8B;CAC3F,IAAI,IAAM;AAIV,QAHI,MAAY,KAAO,MAAM,MAC7B,KAAO,OAAO,IAAa,EAAiB,IAAI,KAChD,KAAO,OAAO,EAAa,EACpB;;AAGT,SAAS,EAAc,GAA2B;CAChD,IAAI,IAAS;AACb,MAAK,IAAM,KAAK,EAAO,KAAU,KAAU,KAAM,OAAO,EAAE;AAC1D,QAAO;;AAGT,SAAS,EAAc,GAAe,GAA0B;CAC9D,IAAM,IAAS,IAAI,WAAW,EAAK,EAC/B,IAAI;AACR,MAAK,IAAI,IAAI,IAAO,GAAG,KAAK,GAAG,IAE7B,CADA,EAAO,KAAK,OAAO,IAAI,KAAM,EAC7B,MAAM;AAER,QAAO;;AAGT,SAAS,EAAiB,GAAgB,GAAsB;CAC9D,IAAM,IAAM,OAAO,KAAK,GAAQ,YAAY;AAC5C,KAAI,EAAI,WAAW,EAAM,QAAO;CAChC,IAAM,IAAS,OAAO,MAAM,EAAK;AAEjC,QADA,EAAI,KAAK,GAAQ,IAAO,EAAI,OAAO,EAC5B"}
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../resolver-Dey6omBe.cjs`);exports.Resolver=e.t;
@@ -0,0 +1,2 @@
1
+ export { Resolver } from "./resolver.js";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/discovery/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { t as e } from "../resolver-DDZWomrF.js";
2
+ export { e as Resolver };
@@ -0,0 +1,8 @@
1
+ import type { Logger } from "../types.js";
2
+ import type { ResolvedAddr } from "../types.js";
3
+ export declare class Resolver {
4
+ #private;
5
+ constructor(log?: Logger);
6
+ resolve(inputAddr: string, signal?: AbortSignal): Promise<ResolvedAddr[]>;
7
+ }
8
+ //# sourceMappingURL=resolver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolver.d.ts","sourceRoot":"","sources":["../../src/discovery/resolver.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAOhD,qBAAa,QAAQ;;gBAIP,GAAG,GAAE,MAAmB;IAI9B,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;CA+GhF"}
@@ -0,0 +1,34 @@
1
+ export declare class TeamspeakError extends Error {
2
+ constructor(message: string, options?: ErrorOptions);
3
+ }
4
+ export declare class ServerError extends TeamspeakError {
5
+ readonly id: string;
6
+ readonly serverMessage: string;
7
+ constructor(id: string, serverMessage: string);
8
+ }
9
+ export declare class CommandTimeoutError extends TeamspeakError {
10
+ readonly command: string;
11
+ constructor(command: string);
12
+ }
13
+ export declare class AlreadyConnectedError extends TeamspeakError {
14
+ constructor();
15
+ }
16
+ export declare class EAXTagMismatchError extends TeamspeakError {
17
+ constructor();
18
+ }
19
+ export declare class FakeSignatureMismatchError extends TeamspeakError {
20
+ constructor();
21
+ }
22
+ export declare class FileTransferError extends TeamspeakError {
23
+ constructor(message: string, options?: ErrorOptions);
24
+ }
25
+ export declare class FileTransferTimeoutError extends TeamspeakError {
26
+ constructor();
27
+ }
28
+ export declare class CryptoInitError extends TeamspeakError {
29
+ constructor(message: string, options?: ErrorOptions);
30
+ }
31
+ export declare class InvalidIdentityError extends TeamspeakError {
32
+ constructor(message?: string);
33
+ }
34
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,cAAe,SAAQ,KAAK;gBAC3B,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAIpD;AAED,qBAAa,WAAY,SAAQ,cAAc;IAC7C,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;gBAEnB,EAAE,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM;CAM9C;AAED,qBAAa,mBAAoB,SAAQ,cAAc;IACrD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;gBAEb,OAAO,EAAE,MAAM;CAK5B;AAED,qBAAa,qBAAsB,SAAQ,cAAc;;CAKxD;AAED,qBAAa,mBAAoB,SAAQ,cAAc;;CAKtD;AAED,qBAAa,0BAA2B,SAAQ,cAAc;;CAK7D;AAED,qBAAa,iBAAkB,SAAQ,cAAc;gBACvC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAIpD;AAED,qBAAa,wBAAyB,SAAQ,cAAc;;CAK3D;AAED,qBAAa,eAAgB,SAAQ,cAAc;gBACrC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAIpD;AAED,qBAAa,oBAAqB,SAAQ,cAAc;gBAC1C,OAAO,SAA4B;CAIhD"}
@@ -0,0 +1,10 @@
1
+ import type { EventMap, CommandMiddleware, EventMiddleware } from "./types.js";
2
+ type EventHandler<K extends keyof EventMap> = EventMap[K] extends void ? () => void : (payload: EventMap[K]) => void;
3
+ export type { EventHandler };
4
+ /**
5
+ * Compose a chain of middlewares around a base handler.
6
+ * Rightmost middleware wraps the base first.
7
+ */
8
+ export declare function buildCommandChain(middlewares: CommandMiddleware[], base: (cmd: string) => Promise<void>): (cmd: string) => Promise<void>;
9
+ export declare function buildEventChain(middlewares: EventMiddleware[], base: (evt: EventMap[keyof EventMap]) => void): (evt: EventMap[keyof EventMap]) => void;
10
+ //# sourceMappingURL=events.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE/E,KAAK,YAAY,CAAC,CAAC,SAAS,MAAM,QAAQ,IAAI,QAAQ,CAAC,CAAC,CAAC,SAAS,IAAI,GAClE,MAAM,IAAI,GACV,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;AAEnC,YAAY,EAAE,YAAY,EAAE,CAAC;AAE7B;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,WAAW,EAAE,iBAAiB,EAAE,EAChC,IAAI,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,GACnC,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAMhC;AAED,wBAAgB,eAAe,CAC7B,WAAW,EAAE,eAAe,EAAE,EAC9B,IAAI,EAAE,CAAC,GAAG,EAAE,QAAQ,CAAC,MAAM,QAAQ,CAAC,KAAK,IAAI,GAC5C,CAAC,GAAG,EAAE,QAAQ,CAAC,MAAM,QAAQ,CAAC,KAAK,IAAI,CAMzC"}
@@ -0,0 +1,458 @@
1
+ import { r as e } from "./types-CGKgXvpG.js";
2
+ import { n as t } from "./crypt-handshake-CHmvZ2qs.js";
3
+ import { createSocket as n } from "node:dgram";
4
+ //#region src/transport/packet.ts
5
+ var r = /* @__PURE__ */ function(e) {
6
+ return e[e.Voice = 0] = "Voice", e[e.VoiceWhisper = 1] = "VoiceWhisper", e[e.Command = 2] = "Command", e[e.CommandLow = 3] = "CommandLow", e[e.Ping = 4] = "Ping", e[e.Pong = 5] = "Pong", e[e.Ack = 6] = "Ack", e[e.AckLow = 7] = "AckLow", e[e.Init1 = 8] = "Init1", e;
7
+ }({}), i = /* @__PURE__ */ function(e) {
8
+ return e[e.Fragmented = 16] = "Fragmented", e[e.NewProtocol = 32] = "NewProtocol", e[e.Compressed = 64] = "Compressed", e[e.Unencrypted = 128] = "Unencrypted", e;
9
+ }({});
10
+ function a(e) {
11
+ return e.typeFlagged & 15;
12
+ }
13
+ function o(e) {
14
+ return e.typeFlagged & 240;
15
+ }
16
+ function s(e) {
17
+ return (o(e) & i.Unencrypted) !== 0;
18
+ }
19
+ function c(e) {
20
+ let t = new Uint8Array(5), n = new DataView(t.buffer);
21
+ return n.setUint16(0, e.id, !1), n.setUint16(2, e.clientID, !1), t[4] = e.typeFlagged, t;
22
+ }
23
+ function l(e) {
24
+ return {
25
+ id: new DataView(e.buffer, e.byteOffset, e.byteLength).getUint16(0, !1),
26
+ typeFlagged: e[2]
27
+ };
28
+ }
29
+ function u(e) {
30
+ let t = new DataView(e.buffer, e.byteOffset, e.byteLength);
31
+ return {
32
+ id: t.getUint16(0, !1),
33
+ clientID: t.getUint16(2, !1),
34
+ typeFlagged: e[4]
35
+ };
36
+ }
37
+ //#endregion
38
+ //#region src/transport/generation-window.ts
39
+ var d = class {
40
+ #e = 0;
41
+ #t = 0;
42
+ #n;
43
+ #r;
44
+ constructor(e, t) {
45
+ this.#n = e, this.#r = t;
46
+ }
47
+ get generation() {
48
+ return this.#t;
49
+ }
50
+ advance(e) {
51
+ if (e <= 0) return;
52
+ let t = this.#e + e, n = Math.floor(t / this.#n);
53
+ n > 0 && (this.#t = Math.min(this.#t + n, 4294967295)), this.#e = t % this.#n;
54
+ }
55
+ advanceToExcluded(e) {
56
+ let t = e - this.#e;
57
+ t < 0 && (t += this.#n), this.advance(t + 1);
58
+ }
59
+ syncTo(e) {
60
+ let t = e - this.#e;
61
+ t < 0 && (t += this.#n), this.advance(t);
62
+ }
63
+ isInWindow(e) {
64
+ let t = this.#e + this.#r;
65
+ return t < this.#n ? e >= this.#e && e < t : e >= this.#e || e < t - this.#n;
66
+ }
67
+ mappedToIndex(e) {
68
+ return this.#i(e) ? e + this.#n - this.#e : e - this.#e;
69
+ }
70
+ isOldPacket(e) {
71
+ return this.mappedToIndex(e) < 0;
72
+ }
73
+ isFuturePacket(e) {
74
+ return this.mappedToIndex(e) >= this.#r;
75
+ }
76
+ #i(e) {
77
+ return this.#e > this.#n - this.#r && e < this.#e + this.#r - this.#n;
78
+ }
79
+ getGeneration(e) {
80
+ return this.#i(e) ? this.#t + 1 : this.#t;
81
+ }
82
+ reset() {
83
+ this.#e = 0, this.#t = 0;
84
+ }
85
+ }, f = 4096, p = class {
86
+ #e = new Int32Array(f);
87
+ decompress(e) {
88
+ let { headerLen: t, decompressedSize: n, flags: r } = m(e), i = new Uint8Array(n);
89
+ if (!(r & 1)) return i.set(e.slice(t, t + n)), i;
90
+ this.#e.fill(0);
91
+ let a = {
92
+ control: 1,
93
+ sourcePos: t,
94
+ destPos: 0,
95
+ nextHashed: 0
96
+ };
97
+ for (; this.#t(e, a);) if (a.control & 1) {
98
+ if (!this.#n(e, i, a)) break;
99
+ } else if (this.#r(e, i, n, a)) break;
100
+ return i;
101
+ }
102
+ #t(e, t) {
103
+ return t.control === 1 ? t.sourcePos + 4 > e.length ? !1 : (t.control = (e[t.sourcePos] | e[t.sourcePos + 1] << 8 | e[t.sourcePos + 2] << 16 | e[t.sourcePos + 3] << 24) >>> 0, t.sourcePos += 4, !0) : !0;
104
+ }
105
+ #n(e, t, n) {
106
+ if (n.control = n.control >>> 1 >>> 0, n.sourcePos + 2 > e.length) return !1;
107
+ let r = e[n.sourcePos], i = e[n.sourcePos + 1];
108
+ n.sourcePos += 2;
109
+ let a = r >> 4 | i << 4, o = r & 15;
110
+ if (o !== 0) o += 2;
111
+ else {
112
+ if (n.sourcePos >= e.length) return !1;
113
+ o = e[n.sourcePos], n.sourcePos++;
114
+ }
115
+ let s = this.#e[a];
116
+ for (let e = 0; e < o; e++) n.destPos < t.length && s + e < n.destPos && (t[n.destPos] = t[s + e], n.destPos++);
117
+ let c = n.destPos + 1 - o;
118
+ return this.#i(t, n, c), n.nextHashed = n.destPos, !0;
119
+ }
120
+ #r(e, t, n, r) {
121
+ let i = Math.max(n, 10) - 10;
122
+ if (r.destPos >= i) {
123
+ for (; r.destPos < n;) {
124
+ if (r.control === 1) {
125
+ if (r.sourcePos += 4, r.sourcePos > e.length) break;
126
+ r.control = (e[r.sourcePos - 4] | e[r.sourcePos - 3] << 8 | e[r.sourcePos - 2] << 16 | e[r.sourcePos - 1] << 24) >>> 0;
127
+ }
128
+ if (r.sourcePos >= e.length) break;
129
+ t[r.destPos++] = e[r.sourcePos++], r.control = r.control >>> 1 >>> 0;
130
+ }
131
+ return !0;
132
+ }
133
+ if (r.sourcePos >= e.length || r.destPos >= t.length) return !0;
134
+ t[r.destPos++] = e[r.sourcePos++], r.control = r.control >>> 1 >>> 0;
135
+ let a = Math.max(r.destPos - 2, 0);
136
+ return this.#i(t, r, a), r.nextHashed < a && (r.nextHashed = a), !1;
137
+ }
138
+ #i(e, t, n) {
139
+ for (; t.nextHashed < n && !(t.nextHashed + 3 > e.length);) {
140
+ let n = (e[t.nextHashed] | e[t.nextHashed + 1] << 8 | e[t.nextHashed + 2] << 16) >>> 0, r = (n >> 12 ^ n) & 4095;
141
+ this.#e[r] = t.nextHashed, t.nextHashed++;
142
+ }
143
+ }
144
+ };
145
+ function m(e) {
146
+ if (e.length < 3) throw Error("QuickLZ: data too short");
147
+ let t = e[0];
148
+ if ((t >> 2 & 3) != 1) throw Error("QuickLZ: only level 1 is supported");
149
+ let n = t & 2 ? 9 : 3;
150
+ if (e.length < n) throw Error("QuickLZ: data too short for header");
151
+ let r;
152
+ return r = t & 2 ? (e[5] | e[6] << 8 | e[7] << 16 | e[8] << 24) >>> 0 : e[2], {
153
+ headerLen: n,
154
+ decompressedSize: r,
155
+ flags: t
156
+ };
157
+ }
158
+ //#endregion
159
+ //#region src/transport/handler.ts
160
+ var h = 500, g = 1024, _ = 5e3, v = 6e4, y = 1e3, b = 5, x = 8, S = 3, C = 500, w = 100, T = class {
161
+ onPacket = null;
162
+ onClosed = null;
163
+ #e;
164
+ #t;
165
+ #n = null;
166
+ #r = 0;
167
+ #i = !1;
168
+ #a = null;
169
+ #o = null;
170
+ #s = Date.now();
171
+ #c = new Uint16Array(9);
172
+ #l = new Uint32Array(9);
173
+ #u = new d(65536, g);
174
+ #d = new d(65536, g);
175
+ #f = new d(65536, g);
176
+ #p = new d(65536, g);
177
+ #m = /* @__PURE__ */ new Map();
178
+ #h = /* @__PURE__ */ new Map();
179
+ #g = /* @__PURE__ */ new Map();
180
+ #_ = null;
181
+ constructor(t, n = e) {
182
+ this.#e = t, this.#t = n;
183
+ }
184
+ setClientID(e) {
185
+ this.#r = e;
186
+ }
187
+ connect(e) {
188
+ return new Promise((t, r) => {
189
+ let [i, a] = e.lastIndexOf(":") > 0 ? [e.slice(0, e.lastIndexOf(":")), e.slice(e.lastIndexOf(":") + 1)] : [e, "9987"], o = parseInt(a, 10), s = n("udp4");
190
+ s.once("error", r), s.connect(o, i, () => {
191
+ s.off("error", r), this.start(s), t();
192
+ });
193
+ });
194
+ }
195
+ start(e) {
196
+ this.#n = e, this.#i = !1, this.#s = Date.now(), e.on("message", (e) => {
197
+ this.#s = Date.now(), this.#x(new Uint8Array(e.buffer, e.byteOffset, e.byteLength));
198
+ }), e.on("error", (e) => {
199
+ this.#t.error("udp error", e), this.#R(e);
200
+ }), e.on("close", () => this.#R(null)), this.#c[r.Command] = 1, this.#c[r.Init1] = 101;
201
+ let n = t(this.#e, null);
202
+ n && this.#y(r.Init1, n, 0);
203
+ let a = setInterval(() => {
204
+ this.#e.cryptoInitComplete && this.sendPacket(r.Ping, new Uint8Array(), i.Unencrypted);
205
+ }, _);
206
+ this.#a = () => clearInterval(a);
207
+ let o = setInterval(() => this.#I(), w);
208
+ this.#o = () => clearInterval(o);
209
+ }
210
+ receivedFinalInitAck() {
211
+ this.#_ = null;
212
+ }
213
+ sendPacket(e, t, n) {
214
+ let i = !this.#e.cryptoInitComplete;
215
+ if (t.length > 487 && e !== r.Voice && e !== r.VoiceWhisper) {
216
+ this.#v(e, t, n, i);
217
+ return;
218
+ }
219
+ this.#y(e, t, n, i);
220
+ }
221
+ sendVoicePacket(e, t) {
222
+ let n = this.#c[r.Voice], a = this.#l[r.Voice];
223
+ this.#c[r.Voice] = n + 1 & 65535, this.#c[r.Voice] === 0 && this.#l[r.Voice]++;
224
+ let o = S + e.length, s = new Uint8Array(o);
225
+ new DataView(s.buffer).setUint16(0, n, !1), s[2] = t, s.set(e, S);
226
+ let l = c({
227
+ typeFlagged: r.Voice | i.Unencrypted,
228
+ id: n,
229
+ clientID: this.#r,
230
+ generationID: a,
231
+ data: s,
232
+ receivedAt: 0
233
+ }), u = new Uint8Array(x + b + o);
234
+ u.set(this.#e.fakeSignature, 0), u.set(l, x), u.set(s, x + b), this.#b(u);
235
+ }
236
+ close() {
237
+ this.#i || (this.#i = !0, this.#a?.(), this.#o?.(), this.#n?.close());
238
+ }
239
+ #v(e, t, n, r) {
240
+ let a = h - b - x, o = 0, s = !0;
241
+ for (; o < t.length;) {
242
+ let c = Math.min(t.length - o, a), l = o + c === t.length, u = n;
243
+ s !== l && (u |= i.Fragmented), this.#y(e, t.slice(o, o + c), u, r), o += c, s = !1;
244
+ }
245
+ }
246
+ #y(e, t, n, r = !this.#e.cryptoInitComplete) {
247
+ n = E(e, n);
248
+ let [a, o] = this.#P(e), s = {
249
+ typeFlagged: e | n,
250
+ id: a,
251
+ clientID: this.#r,
252
+ generationID: o,
253
+ data: t,
254
+ receivedAt: 0
255
+ }, l = (n & i.Unencrypted) !== 0, u = c(s), [d, f] = this.#e.encrypt(e, a, o, u, t, r, l), p = new Uint8Array(x + b + d.length);
256
+ p.set(f.slice(0, x), 0), p.set(u, x), p.set(d, x + b), this.#b(p);
257
+ let m = {
258
+ packet: s,
259
+ firstSend: Date.now(),
260
+ lastSend: Date.now(),
261
+ retryCount: 0,
262
+ nextInterval: C
263
+ };
264
+ this.#F(e, s, m);
265
+ }
266
+ #b(e) {
267
+ this.#n?.send(Buffer.from(e), (e) => {
268
+ e && this.#t.warn("udp send error", e);
269
+ });
270
+ }
271
+ #x(e) {
272
+ if (e.length < 11) return;
273
+ let t = e.slice(0, x), n = e.slice(x, x + 3), i = e.slice(x + 3), o = l(n), s = {
274
+ ...o,
275
+ clientID: 0,
276
+ generationID: this.#S(o.id, o.typeFlagged & 15),
277
+ data: new Uint8Array(),
278
+ receivedAt: Date.now()
279
+ }, c = this.#C(s, n, i, t);
280
+ if (c !== null) {
281
+ if (s.data = c.plaintext, a(s) === r.Ping) {
282
+ this.#E(s.id, c.dummyUsed);
283
+ return;
284
+ }
285
+ this.#w(s, c.dummyUsed) && (this.#D(s), this.#N(s));
286
+ }
287
+ }
288
+ #S(e, t) {
289
+ switch (t) {
290
+ case r.Command: return this.#u.getGeneration(e);
291
+ case r.CommandLow: return this.#d.getGeneration(e);
292
+ case r.Ack: return this.#f.getGeneration(e);
293
+ case r.AckLow: return this.#p.getGeneration(e);
294
+ default: return 0;
295
+ }
296
+ }
297
+ #C(e, t, n, s) {
298
+ let c = (o(e) & i.Unencrypted) !== 0, l = !this.#e.cryptoInitComplete, u = l, d = a(e), f = e.generationID;
299
+ try {
300
+ return {
301
+ plaintext: this.#e.decrypt(d, e.id, f, t, n, s, l, c),
302
+ dummyUsed: u
303
+ };
304
+ } catch {
305
+ for (let r of [-1, 1]) {
306
+ let i = f + r;
307
+ if (!(i < 0)) try {
308
+ return {
309
+ plaintext: this.#e.decrypt(d, e.id, i, t, n, s, !1, !1),
310
+ dummyUsed: !1
311
+ };
312
+ } catch {}
313
+ }
314
+ if (d === r.Command || d === r.CommandLow || d === r.Ack) try {
315
+ return {
316
+ plaintext: this.#e.decrypt(d, e.id, f, t, n, s, !0, c),
317
+ dummyUsed: !0
318
+ };
319
+ } catch {}
320
+ return this.#t.debug("packet decryption failed", {
321
+ type: d,
322
+ id: e.id
323
+ }), null;
324
+ }
325
+ }
326
+ #w(e, t) {
327
+ let n = a(e);
328
+ if (n !== r.Command && n !== r.CommandLow) return !0;
329
+ let i = n === r.Command ? this.#u : this.#d, o = n === r.Command ? r.Ack : r.AckLow;
330
+ return i.isInWindow(e.id) ? (this.#T(e.id, o, t), !0) : (i.isOldPacket(e.id) && this.#T(e.id, o, t), !1);
331
+ }
332
+ #T(e, t, n) {
333
+ let r = new Uint8Array(2);
334
+ new DataView(r.buffer).setUint16(0, e, !1), this.#y(t, r, 0, n);
335
+ }
336
+ #E(e, t) {
337
+ let n = new Uint8Array(2);
338
+ new DataView(n.buffer).setUint16(0, e, !1), this.#y(r.Pong, n, i.Unencrypted, t);
339
+ }
340
+ #D(e) {
341
+ let t = a(e);
342
+ if (t !== r.Command && t !== r.CommandLow) {
343
+ this.onPacket?.(e);
344
+ return;
345
+ }
346
+ let n = t === r.Command, i = n ? this.#m : this.#h, o = n ? this.#u : this.#d;
347
+ for (i.set(e.id, e), n ? this.#A(i, o, !0) : this.#A(i, o, !1);;) {
348
+ let e = n ? this.#O : this.#k, t = i.get(e);
349
+ if (t === void 0) break;
350
+ let r = this.#j(t, i, e, o);
351
+ if (!r) break;
352
+ let [a, s] = r;
353
+ n ? this.#O = s : this.#k = s, this.#M(a), this.onPacket?.(a);
354
+ }
355
+ }
356
+ #O = 0;
357
+ #k = 0;
358
+ #A(e, t, n) {
359
+ let r = n ? this.#O : this.#k;
360
+ for (; !e.has(r) && D(e, r);) r = r + 1 & 65535, t.advance(1);
361
+ n ? this.#O = r : this.#k = r;
362
+ }
363
+ #j(e, t, n, r) {
364
+ if ((o(e) & i.Fragmented) === 0) return t.delete(n), r.advance(1), [e, n + 1 & 65535];
365
+ let a = [], s = 0, c = n, l = !1, u = !1;
366
+ for (;;) {
367
+ let e = t.get(c);
368
+ if (!e) return null;
369
+ a.push(e), s += e.data.length;
370
+ let n = (o(e) & i.Fragmented) !== 0;
371
+ if (!l) {
372
+ if (l = !0, !n) {
373
+ u = !0;
374
+ break;
375
+ }
376
+ } else if (n) {
377
+ u = !0;
378
+ break;
379
+ }
380
+ c = c + 1 & 65535;
381
+ }
382
+ if (!u) return null;
383
+ let d = new Uint8Array(s), f = 0;
384
+ for (let e of a) d.set(e.data, f), f += e.data.length, t.delete(n), r.advance(1), n = n + 1 & 65535;
385
+ return e.data = d, e.typeFlagged &= ~i.Fragmented, [e, n];
386
+ }
387
+ #M(e) {
388
+ if ((o(e) & i.Compressed) !== 0) try {
389
+ e.data = new p().decompress(e.data), e.typeFlagged &= ~i.Compressed;
390
+ } catch (t) {
391
+ this.#t.debug("decompression failed", {
392
+ id: e.id,
393
+ err: t
394
+ });
395
+ }
396
+ }
397
+ #N(e) {
398
+ let t = a(e);
399
+ if (t === r.Init1) {
400
+ this.#_ = null;
401
+ return;
402
+ }
403
+ if ((t === r.Ack || t === r.AckLow) && e.data.length >= 2) {
404
+ let n = new DataView(e.data.buffer, e.data.byteOffset).getUint16(0, !1), i = (t === r.Ack ? r.Command : r.CommandLow) << 16 | n;
405
+ this.#g.delete(i);
406
+ }
407
+ }
408
+ #P(e) {
409
+ let t = this.#c[e], n = this.#l[e];
410
+ return e === r.Init1 ? [t, n] : (this.#c[e] = t + 1 & 65535, this.#c[e] === 0 && (this.#l[e] = n + 1 >>> 0), e === r.Command ? this.#f.advanceToExcluded(t) : e === r.CommandLow && this.#p.advanceToExcluded(t), [t, n]);
411
+ }
412
+ #F(e, t, n) {
413
+ if (e === r.Init1) {
414
+ this.#_ = n;
415
+ return;
416
+ }
417
+ if (e === r.Command || e === r.CommandLow) {
418
+ let r = e << 16 | t.id;
419
+ this.#g.set(r, n);
420
+ }
421
+ }
422
+ #I() {
423
+ let e = Date.now();
424
+ if (e - this.#s > v) {
425
+ this.#t.warn("idle timeout"), this.#R(/* @__PURE__ */ Error("idle timeout"));
426
+ return;
427
+ }
428
+ this.#_ && this.#L(this.#_, e);
429
+ for (let [t, n] of this.#g) {
430
+ if (e - n.firstSend > v) {
431
+ this.#g.delete(t), this.#R(/* @__PURE__ */ Error("packet ack timeout"));
432
+ return;
433
+ }
434
+ this.#L(n, e);
435
+ }
436
+ }
437
+ #L(e, t) {
438
+ if (t - e.lastSend < e.nextInterval) return;
439
+ e.lastSend = t, e.retryCount++, e.nextInterval = Math.min(e.nextInterval * 2, y);
440
+ let n = !this.#e.cryptoInitComplete, r = (o(e.packet) & i.Unencrypted) !== 0, s = c(e.packet), l = a(e.packet), [u, d] = this.#e.encrypt(l, e.packet.id, e.packet.generationID, s, e.packet.data, n, r), f = new Uint8Array(x + b + u.length);
441
+ f.set(d.slice(0, x), 0), f.set(s, x), f.set(u, x + b), this.#b(f);
442
+ }
443
+ #R(e) {
444
+ this.#i || (this.close(), this.onClosed?.(e));
445
+ }
446
+ };
447
+ function E(e, t) {
448
+ return e === r.Command || e === r.CommandLow ? t | i.NewProtocol : t;
449
+ }
450
+ function D(e, t) {
451
+ let n = Date.now();
452
+ for (let [r, i] of e) if ((r - t + 65536 & 65535) < 32768 && n - i.receivedAt > 5e3) return !0;
453
+ return !1;
454
+ }
455
+ //#endregion
456
+ export { r as a, o as c, l as d, i, a as l, p as n, c as o, d as r, s, T as t, u };
457
+
458
+ //# sourceMappingURL=handler-C2vxlHYC.js.map