amule-ec-client 0.6.1 → 0.7.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 (46) hide show
  1. package/README.md +10 -2
  2. package/dist/{AddLinkRequest-D2IME4eb.js → AddLinkRequest-DEKGy-R2.js} +2 -3
  3. package/dist/{ClientQueueRequest-DFfCiNcz.js → ClientQueueRequest-DrLXSxtp.js} +2 -3
  4. package/dist/{ClientQueueResponse-JTrBqrr1.js → ClientQueueResponse-CXxY_9wU.js} +6 -4
  5. package/dist/{CreateCategoryRequest-CRUMcPo5.js → CreateCategoryRequest-COulF12x.js} +2 -3
  6. package/dist/{DeleteCategoryRequest-C8v9oGZ-.js → DeleteCategoryRequest-D-mljaNV.js} +2 -3
  7. package/dist/{DownloadCommandRequest-B3KV_bvm.js → DownloadCommandRequest-Bf1Ez8Da.js} +2 -3
  8. package/dist/{DownloadFileRequest-BjrroO3h.js → DownloadFileRequest-WfOIV07R.js} +2 -3
  9. package/dist/{DownloadQueueRequest-Dil5hl3D.js → DownloadQueueRequest-Br-pgrRt.js} +2 -3
  10. package/dist/DownloadQueueResponse-C-5d4teB.js +241 -0
  11. package/dist/{GetPreferencesRequest-DsxlghqT.js → GetPreferencesRequest-BE3RbRRn.js} +2 -3
  12. package/dist/{PreferencesDetailsResponse-DapscVQi.js → PreferencesDetailsResponse-D8lBd8Ot.js} +1 -2
  13. package/dist/{PreferencesResponse-8n1STWUZ.js → PreferencesResponse-BmGTQM30.js} +1 -2
  14. package/dist/{ReloadSharedFilesRequest-kt0Pxs8A.js → ReloadSharedFilesRequest-BbDUeGcq.js} +2 -2
  15. package/dist/{Request-C0UUuQIX.js → Request-BvScDpeu.js} +3 -9
  16. package/dist/{SearchProgressResponse-C1CdzKnz.js → SearchProgressResponse-BQPliUup.js} +1 -2
  17. package/dist/{SearchRequest-DQnKfA5Z.js → SearchRequest-DOakj8fA.js} +2 -3
  18. package/dist/{SearchResultsRequest-2ejFGQmQ.js → SearchResultsRequest-oZBs5KKm.js} +2 -2
  19. package/dist/{SearchResultsResponse-DwmvbQop.js → SearchResultsResponse-C9I9x035.js} +1 -2
  20. package/dist/{SearchStatusRequest-B_xr4-72.js → SearchStatusRequest-B1ZzSQlE.js} +2 -2
  21. package/dist/{SearchStopRequest-8hwXobty.js → SearchStopRequest-FfXf_DCn.js} +2 -2
  22. package/dist/{ServerConnectRequest-BhNpGiEJ.js → ServerConnectRequest-Cdiw-KWu.js} +2 -3
  23. package/dist/{ServerDisconnectRequest-BjCitLtU.js → ServerDisconnectRequest-BVXSumxX.js} +2 -2
  24. package/dist/{ServerListRequest-BWXLGJib.js → ServerListRequest-3yMrgZID.js} +2 -2
  25. package/dist/{ServerListResponse-BUJ7sz5p.js → ServerListResponse-Do3iRai0.js} +5 -4
  26. package/dist/{ServerUpdateFromUrlRequest-K8C_d0UQ.js → ServerUpdateFromUrlRequest-DpxBII5W.js} +2 -3
  27. package/dist/{SetFileCategoryRequest-VwroLBTV.js → SetFileCategoryRequest-CFgkJB-H.js} +2 -3
  28. package/dist/{SetPreferencesRequest-KZ23VaBY.js → SetPreferencesRequest-BdZ40Ao_.js} +2 -3
  29. package/dist/{SharedFilePriorityRequest-7BriqAcr.js → SharedFilePriorityRequest-BMNmaL06.js} +2 -3
  30. package/dist/{SharedFilesRequest-B72XyRcA.js → SharedFilesRequest-BZKz0oyn.js} +2 -3
  31. package/dist/SharedFilesResponse-DE0cd1DT.js +45 -0
  32. package/dist/{StatsRequest-CGGumOOx.js → StatsRequest-DVwx5wk1.js} +2 -3
  33. package/dist/{StatsResponse-DxQk686g.js → StatsResponse-CP2F2zt0.js} +25 -2
  34. package/dist/{Codes-CjiW7Pdl.js → Tag-B5gWV2XF.js} +268 -1
  35. package/dist/{UpdateCategoryRequest-CzKJa_rC.js → UpdateCategoryRequest-Bu22YjOm.js} +2 -3
  36. package/dist/{UpdateRequest-g2ReOQ5m.js → UpdateRequest-CaQ867p8.js} +2 -3
  37. package/dist/UpdateState-Dn-SuAsj.js +173 -0
  38. package/dist/index.d.ts +358 -336
  39. package/dist/index.js +93 -51
  40. package/dist/rolldown-runtime-D7D4PA-g.js +13 -0
  41. package/dist/{utils-DBnUQnZ-.js → utils-CNoUroOI.js} +11 -1
  42. package/package.json +1 -1
  43. package/dist/DownloadQueueResponse-DUam_zNf.js +0 -259
  44. package/dist/SharedFilesResponse-CkqvYd3N.js +0 -39
  45. package/dist/Tag-CZF6BRMY.js +0 -260
  46. package/dist/UpdateResponse-CGwVjn0Y.js +0 -45
@@ -1,259 +0,0 @@
1
- import "./Codes-CjiW7Pdl.js";
2
- import { f as findNumericTag, p as findTag } from "./Tag-CZF6BRMY.js";
3
- import { n as PARTSIZE, t as ChunkStatus } from "./download-details-OM0FJUhZ.js";
4
- import { i as toOptionalNumber, n as toOptionalBool, t as formatIp } from "./utils-DBnUQnZ-.js";
5
- //#region src/response/DownloadDetailsResponse.ts
6
- function rleDecode(buf) {
7
- const output = [];
8
- let index = 0;
9
- while (index < buf.length) if (index < buf.length - 2 && buf[index + 1] === buf[index]) {
10
- const value = buf[index];
11
- const count = buf[index + 2];
12
- for (let i = 0; i < count; i++) output.push(value);
13
- index += 3;
14
- } else {
15
- output.push(buf[index]);
16
- index += 1;
17
- }
18
- return Buffer.from(output);
19
- }
20
- function decodePartStatus(buf) {
21
- const decoded = rleDecode(buf);
22
- const result = new Array(decoded.length);
23
- for (let i = 0; i < decoded.length; i++) result[i] = decoded[i];
24
- return result;
25
- }
26
- function decodeUint64Array(buf) {
27
- const decoded = rleDecode(buf);
28
- if (decoded.length === 0 || decoded.length % 8 !== 0) return [];
29
- const valueCount = decoded.length / 8;
30
- const values = new Array(valueCount);
31
- for (let i = 0; i < valueCount; i++) {
32
- let value = 0;
33
- for (let byte = 7; byte >= 0; byte--) value = value * 256 + decoded[i + byte * valueCount];
34
- values[i] = value;
35
- }
36
- return values;
37
- }
38
- function stringValue(tag) {
39
- if (!tag) return "";
40
- const value = tag.getValue();
41
- return typeof value === "string" ? value : "";
42
- }
43
- function bufferValue(tag) {
44
- if (!tag) return;
45
- const value = tag.getValue();
46
- return Buffer.isBuffer(value) ? value : void 0;
47
- }
48
- function nestedTag(parent, tagName) {
49
- return parent.nestedTags ? findTag(parent.nestedTags, tagName) : void 0;
50
- }
51
- function nestedNumeric(parent, tagName) {
52
- if (!parent.nestedTags) return 0;
53
- const numeric = findNumericTag(parent.nestedTags, tagName);
54
- if (numeric) return Number(numeric.getValue());
55
- const tag = findTag(parent.nestedTags, tagName);
56
- if (!tag) return 0;
57
- const value = tag.getValue();
58
- if (typeof value === "number") return value;
59
- if (typeof value === "bigint") return Number(value);
60
- return 0;
61
- }
62
- function nestedString(parent, tagName) {
63
- if (!parent.nestedTags) return "";
64
- return stringValue(findTag(parent.nestedTags, tagName));
65
- }
66
- function nestedIp(parent, tagName) {
67
- const ipAsNumber = nestedNumeric(parent, tagName);
68
- if (ipAsNumber === 0) return "";
69
- return formatIp(ipAsNumber);
70
- }
71
- var DownloadChunkDetailsResponseParser = class {
72
- static fromPacket(packet) {
73
- const result = {};
74
- const partfileTags = packet.tags.filter((tag) => tag.name === 768);
75
- for (const fileTag of partfileTags) {
76
- const hash = bufferValue(nestedTag(fileTag, 798));
77
- if (!hash) continue;
78
- const fileHash = hash.toString("hex");
79
- const sizeFull = nestedNumeric(fileTag, 771);
80
- const partCount = sizeFull > 0 ? Math.ceil(sizeFull / PARTSIZE) : 0;
81
- const partStatusBuf = bufferValue(nestedTag(fileTag, 786));
82
- const gapStatusBuf = bufferValue(nestedTag(fileTag, 787));
83
- const reqStatusBuf = bufferValue(nestedTag(fileTag, 788));
84
- const availability = new Array(partCount).fill(0);
85
- if (partStatusBuf && partStatusBuf.length > 0) {
86
- const decodedAvailability = decodePartStatus(partStatusBuf);
87
- for (let i = 0; i < Math.min(decodedAvailability.length, partCount); i++) availability[i] = decodedAvailability[i];
88
- }
89
- const chunks = new Array(partCount).fill(ChunkStatus.COMPLETE);
90
- if (partCount > 0 && gapStatusBuf && gapStatusBuf.length > 0) {
91
- const gapValues = decodeUint64Array(gapStatusBuf);
92
- for (let i = 0; i + 1 < gapValues.length; i += 2) {
93
- const gapStart = gapValues[i];
94
- const gapEnd = gapValues[i + 1];
95
- if (gapStart > sizeFull || gapEnd > sizeFull || gapStart >= gapEnd) continue;
96
- const startPart = Math.floor(gapStart / PARTSIZE);
97
- const endPart = Math.min(Math.floor(gapEnd / PARTSIZE) + 1, partCount);
98
- for (let part = startPart; part < endPart; part++) {
99
- const chunkStart = part * PARTSIZE;
100
- if (gapStart < Math.min((part + 1) * 9728e3, sizeFull) && gapEnd > chunkStart) chunks[part] = availability[part] > 0 ? ChunkStatus.AVAILABLE : ChunkStatus.UNAVAILABLE;
101
- }
102
- }
103
- }
104
- if (partCount > 0 && reqStatusBuf && reqStatusBuf.length > 0) {
105
- const reqValues = decodeUint64Array(reqStatusBuf);
106
- for (let i = 0; i + 1 < reqValues.length; i += 2) {
107
- const reqStart = reqValues[i];
108
- const reqEnd = reqValues[i + 1];
109
- if (reqStart > sizeFull || reqEnd > sizeFull || reqStart >= reqEnd) continue;
110
- const startPart = Math.floor(reqStart / PARTSIZE);
111
- const endPart = Math.min(Math.floor(reqEnd / PARTSIZE) + 1, partCount);
112
- for (let part = startPart; part < endPart; part++) {
113
- if (chunks[part] === ChunkStatus.COMPLETE) continue;
114
- const chunkStart = part * PARTSIZE;
115
- if (reqStart < Math.min((part + 1) * 9728e3, sizeFull) && reqEnd > chunkStart) chunks[part] = ChunkStatus.DOWNLOADING;
116
- }
117
- }
118
- }
119
- result[fileHash] = {
120
- chunks,
121
- availability,
122
- partCount,
123
- sizeFull
124
- };
125
- }
126
- return result;
127
- }
128
- };
129
- var DownloadSourceDetailsResponseParser = class {
130
- static fromPacket(packet) {
131
- const result = {};
132
- const partfileTags = packet.tags.filter((tag) => tag.name === 768);
133
- for (const fileTag of partfileTags) {
134
- const hash = bufferValue(nestedTag(fileTag, 798));
135
- if (!hash) continue;
136
- const fileHash = hash.toString("hex");
137
- const sourceNames = [];
138
- const sources = [];
139
- for (const nested of fileTag.nestedTags || []) {
140
- if (nested.name !== 1536) continue;
141
- sources.push({
142
- clientName: nestedString(nested, 256) || "Unknown",
143
- userHash: bufferValue(nestedTag(nested, 1539))?.toString("hex") || "",
144
- software: nestedString(nested, 1537),
145
- softwareVersion: nestedString(nested, 1557),
146
- score: nestedNumeric(nested, 1538),
147
- uploadSpeed: nestedNumeric(nested, 1549),
148
- downloadSpeed: nestedNumeric(nested, 1550),
149
- uploadState: nestedNumeric(nested, 1564),
150
- downloadState: nestedNumeric(nested, 1548),
151
- ip: nestedIp(nested, 1552),
152
- port: nestedNumeric(nested, 1553),
153
- remoteQueueRank: nestedNumeric(nested, 1562),
154
- waitingPosition: nestedNumeric(nested, 1558),
155
- identState: nestedNumeric(nested, 1559),
156
- obfuscationStatus: nestedNumeric(nested, 1560),
157
- remoteFilename: nestedString(nested, 1575),
158
- availableParts: nestedNumeric(nested, 1578),
159
- sourceFrom: nestedNumeric(nested, 1551)
160
- });
161
- }
162
- const namesTag = nestedTag(fileTag, 789);
163
- const countsTag = nestedTag(fileTag, 796);
164
- const nameTags = namesTag?.nestedTags || [];
165
- const countTags = countsTag?.nestedTags || [];
166
- for (let i = 0; i < nameTags.length; i++) {
167
- const name = stringValue(nameTags[i]);
168
- if (!name) continue;
169
- const rawCount = countTags[i]?.getValue();
170
- const count = typeof rawCount === "number" ? rawCount : typeof rawCount === "bigint" ? Number(rawCount) : 1;
171
- sourceNames.push({
172
- name,
173
- count
174
- });
175
- }
176
- result[fileHash] = {
177
- sources,
178
- sourceNames
179
- };
180
- }
181
- return result;
182
- }
183
- };
184
- //#endregion
185
- //#region src/response/DownloadQueueResponse.ts
186
- var DownloadQueueResponseParser = class {
187
- static fromPacket(packet) {
188
- const files = [];
189
- const chunkDetailsByHash = DownloadChunkDetailsResponseParser.fromPacket(packet);
190
- const sourceDetailsByHash = DownloadSourceDetailsResponseParser.fromPacket(packet);
191
- const partfileTags = packet.tags.filter((tag) => tag.name === 768);
192
- for (const fileTag of partfileTags) {
193
- const tags = fileTag.nestedTags || [];
194
- const hashTag = findTag(tags, 798);
195
- const fileNameTag = findTag(tags, 769);
196
- let a4afSources = void 0;
197
- const a4afSourcesTag = findTag(tags, 802);
198
- if (a4afSourcesTag) {
199
- a4afSources = [];
200
- a4afSourcesTag.nestedTags = a4afSourcesTag.nestedTags || [];
201
- for (const sourceTag of a4afSourcesTag.nestedTags) if (sourceTag.name === 15) a4afSources.push(sourceTag.getValue());
202
- }
203
- const file = {
204
- fileHashHexString: hashTag ? hashTag.getValue().toString("hex") : void 0,
205
- fileName: fileNameTag ? fileNameTag.getValue() : void 0,
206
- filePath: findTag(tags, 1032)?.getValue(),
207
- sizeFull: toOptionalNumber(findNumericTag(tags, 771)?.getLong()),
208
- fileEd2kLink: findTag(tags, 782)?.getValue(),
209
- partMetID: findNumericTag(tags, 770)?.getShort(),
210
- sizeXfer: toOptionalNumber(findNumericTag(tags, 772)?.getLong()),
211
- sizeDone: toOptionalNumber(findNumericTag(tags, 774)?.getLong()),
212
- fileStatus: findNumericTag(tags, 776)?.getInt(),
213
- stopped: toOptionalBool(findNumericTag(tags, 791)?.getInt()),
214
- sourceCount: findNumericTag(tags, 778)?.getShort(),
215
- sourceNotCurrCount: findNumericTag(tags, 780)?.getShort(),
216
- sourceXferCount: findNumericTag(tags, 781)?.getShort(),
217
- sourceCountA4AF: findNumericTag(tags, 779)?.getShort(),
218
- speed: toOptionalNumber(findNumericTag(tags, 775)?.getLong()),
219
- downPrio: findNumericTag(tags, 777)?.getInt(),
220
- fileCat: toOptionalNumber(findNumericTag(tags, 783)?.getLong()),
221
- lastSeenComplete: toOptionalNumber(findNumericTag(tags, 785)?.getLong()),
222
- lastDateChanged: toOptionalNumber(findNumericTag(tags, 784)?.getLong()),
223
- downloadActiveTime: findNumericTag(tags, 792)?.getInt(),
224
- availablePartCount: findNumericTag(tags, 797)?.getShort(),
225
- a4AFAuto: toOptionalBool(findNumericTag(tags, 801)?.getInt()),
226
- hashingProgress: toOptionalBool(findNumericTag(tags, 800)?.getInt()),
227
- getLostDueToCorruption: toOptionalNumber(findNumericTag(tags, 793)?.getLong()),
228
- getGainDueToCompression: toOptionalNumber(findNumericTag(tags, 794)?.getLong()),
229
- totalPacketsSavedDueToICH: findNumericTag(tags, 795)?.getInt(),
230
- upPrio: findNumericTag(tags, 1035)?.getInt(),
231
- getRequests: findNumericTag(tags, 1027)?.getShort(),
232
- getAllRequests: findNumericTag(tags, 1028)?.getInt(),
233
- getAccepts: findNumericTag(tags, 1029)?.getShort(),
234
- getAllAccepts: findNumericTag(tags, 1030)?.getInt(),
235
- getXferred: toOptionalNumber(findNumericTag(tags, 1025)?.getLong()),
236
- getAllXferred: toOptionalNumber(findNumericTag(tags, 1026)?.getLong()),
237
- getCompleteSourcesLow: findNumericTag(tags, 1033)?.getShort(),
238
- getCompleteSourcesHigh: findNumericTag(tags, 1034)?.getShort(),
239
- getCompleteSources: findNumericTag(tags, 1037)?.getShort(),
240
- getOnQueue: findNumericTag(tags, 1036)?.getShort(),
241
- getComment: findTag(tags, 1038)?.getValue(),
242
- getRating: findNumericTag(tags, 1039)?.getInt(),
243
- a4afSources
244
- };
245
- if (file.fileHashHexString) {
246
- file.chunkInfo = chunkDetailsByHash[file.fileHashHexString];
247
- const sourceDetails = sourceDetailsByHash[file.fileHashHexString];
248
- if (sourceDetails) {
249
- file.sources = sourceDetails.sources;
250
- file.sourceNames = sourceDetails.sourceNames;
251
- }
252
- }
253
- files.push(file);
254
- }
255
- return { files };
256
- }
257
- };
258
- //#endregion
259
- export { DownloadQueueResponseParser };
@@ -1,39 +0,0 @@
1
- import "./Codes-CjiW7Pdl.js";
2
- import { f as findNumericTag, p as findTag } from "./Tag-CZF6BRMY.js";
3
- import { i as toOptionalNumber } from "./utils-DBnUQnZ-.js";
4
- //#region src/response/SharedFilesResponse.ts
5
- var SharedFilesResponseParser = class {
6
- static fromPacket(packet) {
7
- const files = [];
8
- const knownfileTags = packet.tags.filter((tag) => tag.name === 1024);
9
- for (const fileTag of knownfileTags) {
10
- const tags = fileTag.nestedTags || [];
11
- const hashTag = findTag(tags, 798);
12
- const fileNameTag = findTag(tags, 769);
13
- const file = {
14
- fileHashHexString: hashTag ? hashTag.getValue().toString("hex") : void 0,
15
- fileName: fileNameTag ? fileNameTag.getValue() : void 0,
16
- filePath: findTag(tags, 1032)?.getValue(),
17
- sizeFull: toOptionalNumber(findNumericTag(tags, 771)?.getLong()),
18
- fileEd2kLink: findTag(tags, 782)?.getValue(),
19
- upPrio: findNumericTag(tags, 1035)?.getInt(),
20
- getRequests: findNumericTag(tags, 1027)?.getShort(),
21
- getAllRequests: findNumericTag(tags, 1028)?.getInt(),
22
- getAccepts: findNumericTag(tags, 1029)?.getShort(),
23
- getAllAccepts: findNumericTag(tags, 1030)?.getInt(),
24
- getXferred: toOptionalNumber(findNumericTag(tags, 1025)?.getLong()),
25
- getAllXferred: toOptionalNumber(findNumericTag(tags, 1026)?.getLong()),
26
- getCompleteSourcesLow: findNumericTag(tags, 1033)?.getShort(),
27
- getCompleteSourcesHigh: findNumericTag(tags, 1034)?.getShort(),
28
- getCompleteSources: findNumericTag(tags, 1037)?.getShort(),
29
- getOnQueue: findNumericTag(tags, 1036)?.getShort(),
30
- getComment: findTag(tags, 1038)?.getValue(),
31
- getRating: findNumericTag(tags, 1039)?.getInt()
32
- };
33
- files.push(file);
34
- }
35
- return { files };
36
- }
37
- };
38
- //#endregion
39
- export { SharedFilesResponseParser };
@@ -1,260 +0,0 @@
1
- //#region src/ec/tag/Tag.ts
2
- var Tag = class {
3
- name;
4
- type;
5
- nameValue;
6
- value;
7
- nestedTags;
8
- constructor(name, type, nestedTags = [], nameValue = name) {
9
- this.name = name;
10
- this.type = type;
11
- this.nameValue = nameValue;
12
- if (nestedTags.length > 0) this.nestedTags = nestedTags;
13
- }
14
- getValue() {
15
- return this.value;
16
- }
17
- setValue(value) {
18
- this.value = value;
19
- }
20
- };
21
- var CustomTag = class extends Tag {
22
- constructor(name, value, subtags = [], nameValue = name) {
23
- super(name, 1, subtags, nameValue);
24
- if (value !== void 0) this.setValue(value);
25
- }
26
- parseValue(value) {
27
- this.setValue(value);
28
- }
29
- encodeValue() {
30
- return this.getValue();
31
- }
32
- };
33
- var UByteTag = class UByteTag extends Tag {
34
- constructor(name, value, subtags = [], nameValue = name) {
35
- super(name, 2, subtags, nameValue);
36
- if (value !== void 0) this.setValue(value);
37
- }
38
- static withValue(name, value, subtags = []) {
39
- return new UByteTag(name, value, subtags);
40
- }
41
- parseValue(value) {
42
- if (value.length === 0) this.setValue(0);
43
- else if (value.length === 1) this.setValue(value[0]);
44
- else throw new Error("UInt8Tag value must be 1 byte long");
45
- }
46
- encodeValue() {
47
- const buf = Buffer.allocUnsafe(1);
48
- buf.writeUInt8(this.getValue());
49
- return buf;
50
- }
51
- getShort() {
52
- return this.getValue();
53
- }
54
- getInt() {
55
- return this.getValue();
56
- }
57
- getLong() {
58
- return BigInt(this.getValue());
59
- }
60
- };
61
- var UShortTag = class UShortTag extends Tag {
62
- constructor(name, value, subtags = [], nameValue = name) {
63
- super(name, 3, subtags, nameValue);
64
- if (value !== void 0) this.setValue(value);
65
- }
66
- static withValue(name, value, subtags = []) {
67
- return new UShortTag(name, value, subtags);
68
- }
69
- parseValue(value) {
70
- if (value.length === 0) this.setValue(0);
71
- else if (value.length === 2) this.setValue(value.readUInt16BE(0));
72
- else throw new Error("UInt16Tag value must be 2 bytes long");
73
- }
74
- encodeValue() {
75
- const buf = Buffer.allocUnsafe(2);
76
- buf.writeUInt16BE(this.getValue());
77
- return buf;
78
- }
79
- getShort() {
80
- return this.getValue();
81
- }
82
- getInt() {
83
- return this.getValue();
84
- }
85
- getLong() {
86
- return BigInt(this.getValue());
87
- }
88
- };
89
- var UIntTag = class UIntTag extends Tag {
90
- constructor(name, value, subtags = [], nameValue = name) {
91
- super(name, 4, subtags, nameValue);
92
- if (value !== void 0) this.setValue(value);
93
- }
94
- static withValue(name, value, subtags = []) {
95
- return new UIntTag(name, value, subtags);
96
- }
97
- parseValue(value) {
98
- if (value.length === 0) this.setValue(0);
99
- else if (value.length === 4) this.setValue(value.readUInt32BE(0));
100
- else throw new Error("UInt32Tag value must be 4 bytes long");
101
- }
102
- encodeValue() {
103
- const buf = Buffer.allocUnsafe(4);
104
- buf.writeUInt32BE(this.getValue());
105
- return buf;
106
- }
107
- getShort() {
108
- throw new Error("Unsigned Integer cannot be cast to short");
109
- }
110
- getInt() {
111
- return this.getValue();
112
- }
113
- getLong() {
114
- return BigInt(this.getValue());
115
- }
116
- };
117
- var ULongTag = class ULongTag extends Tag {
118
- constructor(name, value, subtags = [], nameValue = name) {
119
- super(name, 5, subtags, nameValue);
120
- if (value !== void 0) this.setValue(value);
121
- }
122
- static withValue(name, value, subtags = []) {
123
- return new ULongTag(name, value, subtags);
124
- }
125
- parseValue(value) {
126
- if (value.length === 0) this.setValue(0n);
127
- else if (value.length === 8) this.setValue(value.readBigUInt64BE(0));
128
- else throw new Error("UInt64Tag value must be 8 bytes long");
129
- }
130
- encodeValue() {
131
- const buf = Buffer.allocUnsafe(8);
132
- buf.writeBigUInt64BE(this.getValue());
133
- return buf;
134
- }
135
- getShort() {
136
- throw new Error("Unsigned Long cannot be cast to short");
137
- }
138
- getInt() {
139
- throw new Error("Unsigned Long cannot be cast to int");
140
- }
141
- getLong() {
142
- return this.getValue();
143
- }
144
- };
145
- var UInt128Tag = class UInt128Tag extends Tag {
146
- constructor(name, value, subtags = [], nameValue = name) {
147
- super(name, 10, subtags, nameValue);
148
- if (value !== void 0) this.setValue(value);
149
- }
150
- static withValue(name, value, subtags = []) {
151
- return new UInt128Tag(name, value, subtags);
152
- }
153
- parseValue(value) {
154
- if (value.length === 0) this.setValue(0n);
155
- else {
156
- let result = 0n;
157
- for (let i = 0; i < value.length; i++) result = result << 8n | BigInt(value[i]);
158
- this.setValue(result);
159
- }
160
- }
161
- encodeValue() {
162
- const val = this.getValue();
163
- const bytes = [];
164
- let remaining = val;
165
- while (remaining > 0n) {
166
- bytes.unshift(Number(remaining & 255n));
167
- remaining >>= 8n;
168
- }
169
- while (bytes.length < 16) bytes.unshift(0);
170
- return Buffer.from(bytes);
171
- }
172
- };
173
- var StringTag = class StringTag extends Tag {
174
- constructor(name, value, subtags = [], nameValue = name) {
175
- super(name, 6, subtags, nameValue);
176
- if (value !== void 0) this.setValue(value);
177
- }
178
- static withValue(name, value, subtags = []) {
179
- return new StringTag(name, value, subtags);
180
- }
181
- parseValue(value) {
182
- if (value[value.length - 1] !== 0) throw new Error("StringTag value must be null terminated");
183
- this.setValue(value.toString("utf8", 0, value.length - 1));
184
- }
185
- encodeValue() {
186
- return Buffer.concat([Buffer.from(this.getValue(), "utf8"), Buffer.from([0])]);
187
- }
188
- };
189
- var DoubleTag = class DoubleTag extends Tag {
190
- constructor(name, value, subtags = [], nameValue = name) {
191
- super(name, 7, subtags, nameValue);
192
- if (value !== void 0) this.setValue(value);
193
- }
194
- static withValue(name, value, subtags = []) {
195
- return new DoubleTag(name, value, subtags);
196
- }
197
- parseValue(value) {
198
- const numValue = value.length >= 8 ? value.readDoubleBE(0) : 0;
199
- this.setValue(numValue);
200
- }
201
- encodeValue() {
202
- const buf = Buffer.allocUnsafe(8);
203
- buf.writeDoubleBE(this.getValue());
204
- return buf;
205
- }
206
- };
207
- var Ipv4Tag = class Ipv4Tag extends Tag {
208
- constructor(name, value, subtags = [], nameValue = name) {
209
- super(name, 8, subtags, nameValue);
210
- if (value !== void 0) this.setValue(value);
211
- }
212
- static withValue(name, value, subtags = []) {
213
- return new Ipv4Tag(name, value, subtags);
214
- }
215
- parseValue(value) {
216
- if (value.length !== 6) throw new Error("Ipv4Tag value must be 6 bytes long");
217
- const address = `${value[0]}.${value[1]}.${value[2]}.${value[3]}`;
218
- const port = value.readUInt16BE(4);
219
- this.setValue({
220
- address,
221
- port
222
- });
223
- }
224
- encodeValue() {
225
- const val = this.getValue();
226
- const parts = val.address.split(".").map(Number);
227
- const buf = Buffer.allocUnsafe(6);
228
- buf[0] = parts[0];
229
- buf[1] = parts[1];
230
- buf[2] = parts[2];
231
- buf[3] = parts[3];
232
- buf.writeUInt16BE(val.port, 4);
233
- return buf;
234
- }
235
- };
236
- var Hash16Tag = class Hash16Tag extends Tag {
237
- constructor(name, value, subtags = [], nameValue = name) {
238
- super(name, 9, subtags, nameValue);
239
- if (value !== void 0) this.setValue(value);
240
- }
241
- static withValue(name, value, subtags = []) {
242
- return new Hash16Tag(name, value, subtags);
243
- }
244
- parseValue(value) {
245
- if (value.length === 16) this.setValue(value);
246
- else throw new Error("Hash16Tag value must be 16 bytes long");
247
- }
248
- encodeValue() {
249
- return this.getValue();
250
- }
251
- };
252
- function findTag(tags, name) {
253
- return tags.find((tag) => tag.name === name);
254
- }
255
- function findNumericTag(tags, name) {
256
- const tag = tags.find((tag) => tag.name === name);
257
- if (tag && "getInt" in tag && "getShort" in tag && "getLong" in tag) return tag;
258
- }
259
- //#endregion
260
- export { StringTag as a, UInt128Tag as c, UShortTag as d, findNumericTag as f, Ipv4Tag as i, UIntTag as l, DoubleTag as n, Tag as o, findTag as p, Hash16Tag as r, UByteTag as s, CustomTag as t, ULongTag as u };
@@ -1,45 +0,0 @@
1
- import "./Codes-CjiW7Pdl.js";
2
- import { f as findNumericTag, p as findTag } from "./Tag-CZF6BRMY.js";
3
- import { n as toOptionalBool, r as toOptionalIp } from "./utils-DBnUQnZ-.js";
4
- import { ClientQueueResponseParser } from "./ClientQueueResponse-JTrBqrr1.js";
5
- import { DownloadQueueResponseParser } from "./DownloadQueueResponse-DUam_zNf.js";
6
- import { ServerListResponseParser } from "./ServerListResponse-BUJ7sz5p.js";
7
- import { SharedFilesResponseParser } from "./SharedFilesResponse-CkqvYd3N.js";
8
- //#region src/response/UpdateResponse.ts
9
- var UpdateResponseParser = class {
10
- static fromPacket(packet) {
11
- const sharedFiles = SharedFilesResponseParser.fromPacket(packet).files;
12
- const downloadQueue = DownloadQueueResponseParser.fromPacket(packet).files;
13
- const clientContainer = findTag(packet.tags, 1536);
14
- const clients = clientContainer && clientContainer.nestedTags ? ClientQueueResponseParser.fromTags(clientContainer.nestedTags).clients : [];
15
- const serverContainer = findTag(packet.tags, 1280);
16
- const servers = serverContainer && serverContainer.nestedTags ? ServerListResponseParser.fromTags(serverContainer.nestedTags).servers : [];
17
- const friendContainer = findTag(packet.tags, 2048);
18
- return {
19
- sharedFiles,
20
- downloadQueue,
21
- clients,
22
- servers,
23
- friends: friendContainer && friendContainer.nestedTags ? this.parseFriends(friendContainer.nestedTags) : []
24
- };
25
- }
26
- static parseFriends(tags) {
27
- const friends = [];
28
- const friendTags = tags.filter((t) => t.name === 2048);
29
- for (const friendTag of friendTags) {
30
- const nested = friendTag.nestedTags || [];
31
- friends.push({
32
- name: findTag(nested, 2049)?.getValue(),
33
- userHashHexString: findTag(nested, 2050)?.getValue()?.toString("hex"),
34
- ip: toOptionalIp(findNumericTag(nested, 2051)?.getInt()),
35
- port: findNumericTag(nested, 2052)?.getInt(),
36
- friendSlot: toOptionalBool(findNumericTag(nested, 2056)?.getInt()),
37
- shared: toOptionalBool(findNumericTag(nested, 2057)?.getInt()),
38
- client: ClientQueueResponseParser.fromTags(nested).clients[0]
39
- });
40
- }
41
- return friends;
42
- }
43
- };
44
- //#endregion
45
- export { UpdateResponseParser };