amule-ec-client 0.4.3 → 0.5.1

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.js CHANGED
@@ -631,7 +631,9 @@ var init_Tag = __esm({
631
631
  }
632
632
  }
633
633
  encodeValue() {
634
- return Buffer.from([this.getValue()]);
634
+ const buf = Buffer.allocUnsafe(1);
635
+ buf.writeUInt8(this.getValue());
636
+ return buf;
635
637
  }
636
638
  getShort() {
637
639
  return this.getValue();
@@ -811,23 +813,24 @@ var init_Tag = __esm({
811
813
  return new _DoubleTag(name, value, subtags);
812
814
  }
813
815
  parseValue(value) {
814
- if (value[value.length - 1] !== 0) {
815
- throw new Error("DoubleTag value must be null terminated");
816
- }
817
- this.setValue(parseFloat(value.toString("utf8", 0, value.length - 1)));
816
+ const numValue = value.length >= 8 ? value.readDoubleBE(0) : 0;
817
+ this.setValue(numValue);
818
818
  }
819
819
  encodeValue() {
820
- return Buffer.concat([Buffer.from(this.getValue().toString(), "utf8"), Buffer.from([0])]);
820
+ const buf = Buffer.allocUnsafe(8);
821
+ buf.writeDoubleBE(this.getValue());
822
+ return buf;
821
823
  }
822
824
  };
823
825
  Ipv4Tag = class _Ipv4Tag extends Tag {
824
- constructor(name, subtags = [], nameValue = name) {
826
+ constructor(name, value, subtags = [], nameValue = name) {
825
827
  super(name, 8 /* EC_TAGTYPE_IPV4 */, subtags, nameValue);
828
+ if (value !== void 0) {
829
+ this.setValue(value);
830
+ }
826
831
  }
827
832
  static withValue(name, value, subtags = []) {
828
- const tag = new _Ipv4Tag(name, subtags);
829
- tag.setValue(value);
830
- return tag;
833
+ return new _Ipv4Tag(name, value, subtags);
831
834
  }
832
835
  parseValue(value) {
833
836
  if (value.length !== 6) {
@@ -839,7 +842,7 @@ var init_Tag = __esm({
839
842
  }
840
843
  encodeValue() {
841
844
  const val = this.getValue();
842
- const parts = val.address.split(".").map((p) => parseInt(p));
845
+ const parts = val.address.split(".").map(Number);
843
846
  const buf = Buffer.allocUnsafe(6);
844
847
  buf[0] = parts[0];
845
848
  buf[1] = parts[1];
@@ -1015,6 +1018,370 @@ var init_StatsResponse = __esm({
1015
1018
  }
1016
1019
  });
1017
1020
 
1021
+ // src/request/UpdateRequest.ts
1022
+ var UpdateRequest_exports = {};
1023
+ __export(UpdateRequest_exports, {
1024
+ UpdateRequest: () => UpdateRequest
1025
+ });
1026
+ var UpdateRequest;
1027
+ var init_UpdateRequest = __esm({
1028
+ "src/request/UpdateRequest.ts"() {
1029
+ "use strict";
1030
+ init_Request();
1031
+ init_Codes();
1032
+ init_Tag();
1033
+ UpdateRequest = class extends Request {
1034
+ constructor(detailLevel = 4 /* EC_DETAIL_INC_UPDATE */) {
1035
+ super(82 /* EC_OP_GET_UPDATE */);
1036
+ this.addTag(new UByteTag(4 /* EC_TAG_DETAIL_LEVEL */, detailLevel));
1037
+ }
1038
+ };
1039
+ }
1040
+ });
1041
+
1042
+ // src/response/utils.ts
1043
+ function formatIp(ip) {
1044
+ if (ip === void 0) return "";
1045
+ return [ip >>> 24 & 255, ip >>> 16 & 255, ip >>> 8 & 255, ip & 255].join(".");
1046
+ }
1047
+ function toOptionalNumber(value) {
1048
+ if (value === void 0) return void 0;
1049
+ return typeof value === "bigint" ? Number(value) : value;
1050
+ }
1051
+ function toOptionalBool(value) {
1052
+ if (value === void 0) return void 0;
1053
+ return value !== 0;
1054
+ }
1055
+ function toOptionalIp(value) {
1056
+ if (value === void 0) return void 0;
1057
+ return formatIp(value);
1058
+ }
1059
+ var init_utils = __esm({
1060
+ "src/response/utils.ts"() {
1061
+ "use strict";
1062
+ }
1063
+ });
1064
+
1065
+ // src/response/SharedFilesResponse.ts
1066
+ var SharedFilesResponse_exports = {};
1067
+ __export(SharedFilesResponse_exports, {
1068
+ SharedFilesResponseParser: () => SharedFilesResponseParser
1069
+ });
1070
+ var SharedFilesResponseParser;
1071
+ var init_SharedFilesResponse = __esm({
1072
+ "src/response/SharedFilesResponse.ts"() {
1073
+ "use strict";
1074
+ init_Codes();
1075
+ init_Tag();
1076
+ init_utils();
1077
+ SharedFilesResponseParser = class {
1078
+ static fromPacket(packet) {
1079
+ const files = [];
1080
+ const knownfileTags = packet.tags.filter((tag) => tag.name === 1024 /* EC_TAG_KNOWNFILE */);
1081
+ for (const fileTag of knownfileTags) {
1082
+ const tags = fileTag.nestedTags || [];
1083
+ const hashTag = findTag(tags, 798 /* EC_TAG_PARTFILE_HASH */);
1084
+ const fileNameTag = findTag(tags, 769 /* EC_TAG_PARTFILE_NAME */);
1085
+ const file = {
1086
+ fileHashHexString: hashTag ? hashTag.getValue().toString("hex") : void 0,
1087
+ fileName: fileNameTag ? fileNameTag.getValue() : void 0,
1088
+ filePath: findTag(tags, 1032 /* EC_TAG_KNOWNFILE_FILENAME */)?.getValue(),
1089
+ sizeFull: toOptionalNumber(findNumericTag(tags, 771 /* EC_TAG_PARTFILE_SIZE_FULL */)?.getLong()),
1090
+ fileEd2kLink: findTag(tags, 782 /* EC_TAG_PARTFILE_ED2K_LINK */)?.getValue(),
1091
+ upPrio: findNumericTag(tags, 1035 /* EC_TAG_KNOWNFILE_PRIO */)?.getInt(),
1092
+ getRequests: findNumericTag(tags, 1027 /* EC_TAG_KNOWNFILE_REQ_COUNT */)?.getShort(),
1093
+ getAllRequests: findNumericTag(tags, 1028 /* EC_TAG_KNOWNFILE_REQ_COUNT_ALL */)?.getInt(),
1094
+ getAccepts: findNumericTag(tags, 1029 /* EC_TAG_KNOWNFILE_ACCEPT_COUNT */)?.getShort(),
1095
+ getAllAccepts: findNumericTag(tags, 1030 /* EC_TAG_KNOWNFILE_ACCEPT_COUNT_ALL */)?.getInt(),
1096
+ getXferred: toOptionalNumber(findNumericTag(tags, 1025 /* EC_TAG_KNOWNFILE_XFERRED */)?.getLong()),
1097
+ getAllXferred: toOptionalNumber(findNumericTag(tags, 1026 /* EC_TAG_KNOWNFILE_XFERRED_ALL */)?.getLong()),
1098
+ getCompleteSourcesLow: findNumericTag(tags, 1033 /* EC_TAG_KNOWNFILE_COMPLETE_SOURCES_LOW */)?.getShort(),
1099
+ getCompleteSourcesHigh: findNumericTag(tags, 1034 /* EC_TAG_KNOWNFILE_COMPLETE_SOURCES_HIGH */)?.getShort(),
1100
+ getCompleteSources: findNumericTag(tags, 1037 /* EC_TAG_KNOWNFILE_COMPLETE_SOURCES */)?.getShort(),
1101
+ getOnQueue: findNumericTag(tags, 1036 /* EC_TAG_KNOWNFILE_ON_QUEUE */)?.getShort(),
1102
+ getComment: findTag(tags, 1038 /* EC_TAG_KNOWNFILE_COMMENT */)?.getValue(),
1103
+ getRating: findNumericTag(tags, 1039 /* EC_TAG_KNOWNFILE_RATING */)?.getInt()
1104
+ };
1105
+ files.push(file);
1106
+ }
1107
+ return { files };
1108
+ }
1109
+ };
1110
+ }
1111
+ });
1112
+
1113
+ // src/response/DownloadQueueResponse.ts
1114
+ var DownloadQueueResponse_exports = {};
1115
+ __export(DownloadQueueResponse_exports, {
1116
+ DownloadQueueResponseParser: () => DownloadQueueResponseParser
1117
+ });
1118
+ var DownloadQueueResponseParser;
1119
+ var init_DownloadQueueResponse = __esm({
1120
+ "src/response/DownloadQueueResponse.ts"() {
1121
+ "use strict";
1122
+ init_Codes();
1123
+ init_Tag();
1124
+ init_utils();
1125
+ DownloadQueueResponseParser = class {
1126
+ static fromPacket(packet) {
1127
+ const files = [];
1128
+ const partfileTags = packet.tags.filter((tag) => tag.name === 768 /* EC_TAG_PARTFILE */);
1129
+ for (const fileTag of partfileTags) {
1130
+ const tags = fileTag.nestedTags || [];
1131
+ const hashTag = findTag(tags, 798 /* EC_TAG_PARTFILE_HASH */);
1132
+ const fileNameTag = findTag(tags, 769 /* EC_TAG_PARTFILE_NAME */);
1133
+ let a4afSources = void 0;
1134
+ const a4afSourcesTag = findTag(tags, 802 /* EC_TAG_PARTFILE_A4AF_SOURCES */);
1135
+ if (a4afSourcesTag) {
1136
+ a4afSources = [];
1137
+ a4afSourcesTag.nestedTags = a4afSourcesTag.nestedTags || [];
1138
+ for (const sourceTag of a4afSourcesTag.nestedTags) {
1139
+ if (sourceTag.name === 15 /* EC_TAG_ECID */) {
1140
+ a4afSources.push(sourceTag.getValue());
1141
+ }
1142
+ }
1143
+ }
1144
+ const file = {
1145
+ fileHashHexString: hashTag ? hashTag.getValue().toString("hex") : void 0,
1146
+ fileName: fileNameTag ? fileNameTag.getValue() : void 0,
1147
+ filePath: findTag(tags, 1032 /* EC_TAG_KNOWNFILE_FILENAME */)?.getValue(),
1148
+ sizeFull: toOptionalNumber(findNumericTag(tags, 771 /* EC_TAG_PARTFILE_SIZE_FULL */)?.getLong()),
1149
+ fileEd2kLink: findTag(tags, 782 /* EC_TAG_PARTFILE_ED2K_LINK */)?.getValue(),
1150
+ // Transfer info
1151
+ partMetID: findNumericTag(tags, 770 /* EC_TAG_PARTFILE_PARTMETID */)?.getShort(),
1152
+ sizeXfer: toOptionalNumber(findNumericTag(tags, 772 /* EC_TAG_PARTFILE_SIZE_XFER */)?.getLong()),
1153
+ sizeDone: toOptionalNumber(findNumericTag(tags, 774 /* EC_TAG_PARTFILE_SIZE_DONE */)?.getLong()),
1154
+ fileStatus: findNumericTag(tags, 776 /* EC_TAG_PARTFILE_STATUS */)?.getInt(),
1155
+ stopped: toOptionalBool(findNumericTag(tags, 791 /* EC_TAG_PARTFILE_STOPPED */)?.getInt()),
1156
+ sourceCount: findNumericTag(tags, 778 /* EC_TAG_PARTFILE_SOURCE_COUNT */)?.getShort(),
1157
+ sourceNotCurrCount: findNumericTag(tags, 780 /* EC_TAG_PARTFILE_SOURCE_COUNT_NOT_CURRENT */)?.getShort(),
1158
+ sourceXferCount: findNumericTag(tags, 781 /* EC_TAG_PARTFILE_SOURCE_COUNT_XFER */)?.getShort(),
1159
+ sourceCountA4AF: findNumericTag(tags, 779 /* EC_TAG_PARTFILE_SOURCE_COUNT_A4AF */)?.getShort(),
1160
+ speed: toOptionalNumber(findNumericTag(tags, 775 /* EC_TAG_PARTFILE_SPEED */)?.getLong()),
1161
+ downPrio: findNumericTag(tags, 777 /* EC_TAG_PARTFILE_PRIO */)?.getInt(),
1162
+ fileCat: toOptionalNumber(findNumericTag(tags, 783 /* EC_TAG_PARTFILE_CAT */)?.getLong()),
1163
+ lastSeenComplete: toOptionalNumber(findNumericTag(tags, 785 /* EC_TAG_PARTFILE_LAST_SEEN_COMP */)?.getLong()),
1164
+ lastDateChanged: toOptionalNumber(findNumericTag(tags, 784 /* EC_TAG_PARTFILE_LAST_RECV */)?.getLong()),
1165
+ downloadActiveTime: findNumericTag(tags, 792 /* EC_TAG_PARTFILE_DOWNLOAD_ACTIVE */)?.getInt(),
1166
+ availablePartCount: findNumericTag(tags, 797 /* EC_TAG_PARTFILE_AVAILABLE_PARTS */)?.getShort(),
1167
+ a4AFAuto: toOptionalBool(findNumericTag(tags, 801 /* EC_TAG_PARTFILE_A4AFAUTO */)?.getInt()),
1168
+ hashingProgress: toOptionalBool(findNumericTag(tags, 800 /* EC_TAG_PARTFILE_HASHED_PART_COUNT */)?.getInt()),
1169
+ // Statistics
1170
+ getLostDueToCorruption: toOptionalNumber(findNumericTag(tags, 793 /* EC_TAG_PARTFILE_LOST_CORRUPTION */)?.getLong()),
1171
+ getGainDueToCompression: toOptionalNumber(findNumericTag(tags, 794 /* EC_TAG_PARTFILE_GAINED_COMPRESSION */)?.getLong()),
1172
+ totalPacketsSavedDueToICH: findNumericTag(tags, 795 /* EC_TAG_PARTFILE_SAVED_ICH */)?.getInt(),
1173
+ // Known file shared info
1174
+ upPrio: findNumericTag(tags, 1035 /* EC_TAG_KNOWNFILE_PRIO */)?.getInt(),
1175
+ getRequests: findNumericTag(tags, 1027 /* EC_TAG_KNOWNFILE_REQ_COUNT */)?.getShort(),
1176
+ getAllRequests: findNumericTag(tags, 1028 /* EC_TAG_KNOWNFILE_REQ_COUNT_ALL */)?.getInt(),
1177
+ getAccepts: findNumericTag(tags, 1029 /* EC_TAG_KNOWNFILE_ACCEPT_COUNT */)?.getShort(),
1178
+ getAllAccepts: findNumericTag(tags, 1030 /* EC_TAG_KNOWNFILE_ACCEPT_COUNT_ALL */)?.getInt(),
1179
+ getXferred: toOptionalNumber(findNumericTag(tags, 1025 /* EC_TAG_KNOWNFILE_XFERRED */)?.getLong()),
1180
+ getAllXferred: toOptionalNumber(findNumericTag(tags, 1026 /* EC_TAG_KNOWNFILE_XFERRED_ALL */)?.getLong()),
1181
+ getCompleteSourcesLow: findNumericTag(tags, 1033 /* EC_TAG_KNOWNFILE_COMPLETE_SOURCES_LOW */)?.getShort(),
1182
+ getCompleteSourcesHigh: findNumericTag(tags, 1034 /* EC_TAG_KNOWNFILE_COMPLETE_SOURCES_HIGH */)?.getShort(),
1183
+ getCompleteSources: findNumericTag(tags, 1037 /* EC_TAG_KNOWNFILE_COMPLETE_SOURCES */)?.getShort(),
1184
+ getOnQueue: findNumericTag(tags, 1036 /* EC_TAG_KNOWNFILE_ON_QUEUE */)?.getShort(),
1185
+ getComment: findTag(tags, 1038 /* EC_TAG_KNOWNFILE_COMMENT */)?.getValue(),
1186
+ getRating: findNumericTag(tags, 1039 /* EC_TAG_KNOWNFILE_RATING */)?.getInt(),
1187
+ a4afSources
1188
+ };
1189
+ files.push(file);
1190
+ }
1191
+ return { files };
1192
+ }
1193
+ };
1194
+ }
1195
+ });
1196
+
1197
+ // src/response/ClientQueueResponse.ts
1198
+ var ClientQueueResponse_exports = {};
1199
+ __export(ClientQueueResponse_exports, {
1200
+ ClientQueueResponseParser: () => ClientQueueResponseParser
1201
+ });
1202
+ var ClientQueueResponseParser;
1203
+ var init_ClientQueueResponse = __esm({
1204
+ "src/response/ClientQueueResponse.ts"() {
1205
+ "use strict";
1206
+ init_Codes();
1207
+ init_Tag();
1208
+ init_utils();
1209
+ ClientQueueResponseParser = class {
1210
+ static fromPacket(packet) {
1211
+ return this.fromTags(packet.tags);
1212
+ }
1213
+ static fromTags(allTags) {
1214
+ const clients = [];
1215
+ const clientTags = allTags.filter((tag) => tag.name === 1536 /* EC_TAG_CLIENT */);
1216
+ for (const clientTag of clientTags) {
1217
+ const tags = clientTag.nestedTags || [];
1218
+ const client = {
1219
+ clientName: findTag(tags, 256 /* EC_TAG_CLIENT_NAME */)?.getValue(),
1220
+ userHashHexString: findTag(tags, 1539 /* EC_TAG_CLIENT_HASH */)?.getValue()?.toString("hex"),
1221
+ userID: findNumericTag(tags, 1566 /* EC_TAG_CLIENT_USER_ID */)?.getInt(),
1222
+ score: findNumericTag(tags, 1538 /* EC_TAG_CLIENT_SCORE */)?.getInt(),
1223
+ software: findTag(tags, 1537 /* EC_TAG_CLIENT_SOFTWARE */)?.getValue(),
1224
+ softVerStr: findTag(tags, 1557 /* EC_TAG_CLIENT_SOFT_VER_STR */)?.getValue(),
1225
+ userIP: toOptionalIp(findNumericTag(tags, 1552 /* EC_TAG_CLIENT_USER_IP */)?.getInt()),
1226
+ userPort: findNumericTag(tags, 1553 /* EC_TAG_CLIENT_USER_PORT */)?.getInt(),
1227
+ sourceFrom: toOptionalNumber(findNumericTag(tags, 1551 /* EC_TAG_CLIENT_FROM */)?.getLong()),
1228
+ serverIP: toOptionalIp(findNumericTag(tags, 1554 /* EC_TAG_CLIENT_SERVER_IP */)?.getInt()),
1229
+ serverPort: findNumericTag(tags, 1555 /* EC_TAG_CLIENT_SERVER_PORT */)?.getInt(),
1230
+ serverName: findTag(tags, 1556 /* EC_TAG_CLIENT_SERVER_NAME */)?.getValue(),
1231
+ upSpeed: toOptionalNumber(findNumericTag(tags, 1549 /* EC_TAG_CLIENT_UP_SPEED */)?.getLong()),
1232
+ downSpeed: toOptionalNumber(findNumericTag(tags, 1550 /* EC_TAG_CLIENT_DOWN_SPEED */)?.getLong()),
1233
+ uploadSession: toOptionalNumber(findNumericTag(tags, 1545 /* EC_TAG_CLIENT_UPLOAD_SESSION */)?.getLong()),
1234
+ transferredDown: toOptionalNumber(findNumericTag(tags, 772 /* EC_TAG_PARTFILE_SIZE_XFER */)?.getLong()),
1235
+ uploadedTotal: toOptionalNumber(findNumericTag(tags, 1546 /* EC_TAG_CLIENT_UPLOAD_TOTAL */)?.getLong()),
1236
+ downloadedTotal: toOptionalNumber(findNumericTag(tags, 1547 /* EC_TAG_CLIENT_DOWNLOAD_TOTAL */)?.getLong()),
1237
+ uploadState: findNumericTag(tags, 1564 /* EC_TAG_CLIENT_UPLOAD_STATE */)?.getInt(),
1238
+ downloadState: findNumericTag(tags, 1548 /* EC_TAG_CLIENT_DOWNLOAD_STATE */)?.getInt(),
1239
+ identState: findNumericTag(tags, 1559 /* EC_TAG_CLIENT_IDENT_STATE */)?.getInt(),
1240
+ extProtocol: findNumericTag(tags, 1565 /* EC_TAG_CLIENT_EXT_PROTOCOL */)?.getInt(),
1241
+ waitingPosition: findNumericTag(tags, 1558 /* EC_TAG_CLIENT_WAITING_POSITION */)?.getInt(),
1242
+ remoteQueueRank: findNumericTag(tags, 1562 /* EC_TAG_CLIENT_REMOTE_QUEUE_RANK */)?.getInt(),
1243
+ oldRemoteQueueRank: findNumericTag(tags, 1570 /* EC_TAG_CLIENT_OLD_REMOTE_QUEUE_RANK */)?.getInt(),
1244
+ obfuscationStatus: findNumericTag(tags, 1560 /* EC_TAG_CLIENT_OBFUSCATION_STATUS */)?.getInt(),
1245
+ kadPort: findNumericTag(tags, 1571 /* EC_TAG_CLIENT_KAD_PORT */)?.getInt(),
1246
+ friendSlot: findNumericTag(tags, 1540 /* EC_TAG_CLIENT_FRIEND_SLOT */)?.getInt(),
1247
+ uploadFileId: toOptionalNumber(findNumericTag(tags, 1567 /* EC_TAG_CLIENT_UPLOAD_FILE */)?.getLong()),
1248
+ uploadFilename: findTag(tags, 769 /* EC_TAG_PARTFILE_NAME */)?.getValue(),
1249
+ requestFileId: toOptionalNumber(findNumericTag(tags, 1568 /* EC_TAG_CLIENT_REQUEST_FILE */)?.getLong()),
1250
+ remoteFilename: findTag(tags, 1575 /* EC_TAG_CLIENT_REMOTE_FILENAME */)?.getValue(),
1251
+ disableViewShared: toOptionalBool(findNumericTag(tags, 1563 /* EC_TAG_CLIENT_DISABLE_VIEW_SHARED */)?.getInt()),
1252
+ version: findNumericTag(tags, 257 /* EC_TAG_CLIENT_VERSION */)?.getInt(),
1253
+ modVersion: findTag(tags, 1576 /* EC_TAG_CLIENT_MOD_VERSION */)?.getValue(),
1254
+ osInfo: findTag(tags, 1577 /* EC_TAG_CLIENT_OS_INFO */)?.getValue(),
1255
+ availableParts: findNumericTag(tags, 1578 /* EC_TAG_CLIENT_AVAILABLE_PARTS */)?.getInt(),
1256
+ partStatus: findTag(tags, 1572 /* EC_TAG_CLIENT_PART_STATUS */)?.getValue(),
1257
+ nextRequestedPart: findNumericTag(tags, 1573 /* EC_TAG_CLIENT_NEXT_REQUESTED_PART */)?.getInt(),
1258
+ lastDownloadingPart: findNumericTag(tags, 1574 /* EC_TAG_CLIENT_LAST_DOWNLOADING_PART */)?.getInt(),
1259
+ uploadPartStatus: findTag(tags, 1579 /* EC_TAG_CLIENT_UPLOAD_PART_STATUS */)?.getValue()
1260
+ // Additional fields can be added here as needed
1261
+ };
1262
+ clients.push(client);
1263
+ }
1264
+ return { clients };
1265
+ }
1266
+ };
1267
+ }
1268
+ });
1269
+
1270
+ // src/response/ServerListResponse.ts
1271
+ var ServerListResponse_exports = {};
1272
+ __export(ServerListResponse_exports, {
1273
+ ServerListResponseParser: () => ServerListResponseParser
1274
+ });
1275
+ var ServerListResponseParser;
1276
+ var init_ServerListResponse = __esm({
1277
+ "src/response/ServerListResponse.ts"() {
1278
+ "use strict";
1279
+ init_Codes();
1280
+ init_Tag();
1281
+ init_utils();
1282
+ ServerListResponseParser = class {
1283
+ static fromPacket(packet) {
1284
+ return this.fromTags(packet.tags);
1285
+ }
1286
+ static fromTags(allTags) {
1287
+ const servers = [];
1288
+ const serverTags = allTags.filter((tag) => tag.name === 1280 /* EC_TAG_SERVER */);
1289
+ for (const serverTag of serverTags) {
1290
+ const nested = serverTag.nestedTags || [];
1291
+ const ipv4Tag = findTag(nested, 1292 /* EC_TAG_SERVER_IP */) || findTag(nested, 1283 /* EC_TAG_SERVER_ADDRESS */) || (serverTag.constructor.name.includes("Ipv4") ? serverTag : null);
1292
+ let ip = void 0;
1293
+ let port = void 0;
1294
+ if (ipv4Tag && ipv4Tag.getValue() && typeof ipv4Tag.getValue() === "object" && "address" in ipv4Tag.getValue()) {
1295
+ const val = ipv4Tag.getValue();
1296
+ ip = val.address;
1297
+ port = val.port;
1298
+ } else {
1299
+ const ipNum = findNumericTag(nested, 1292 /* EC_TAG_SERVER_IP */)?.getInt() || findNumericTag(allTags, 1292 /* EC_TAG_SERVER_IP */)?.getInt();
1300
+ port = findNumericTag(nested, 1293 /* EC_TAG_SERVER_PORT */)?.getInt() || findNumericTag(allTags, 1293 /* EC_TAG_SERVER_PORT */)?.getInt();
1301
+ ip = ipNum !== void 0 ? formatIp(ipNum) : void 0;
1302
+ }
1303
+ if (port === void 0 || port === 0) {
1304
+ const extraPort = findNumericTag(nested, 1293 /* EC_TAG_SERVER_PORT */)?.getInt();
1305
+ if (extraPort !== void 0) port = extraPort;
1306
+ }
1307
+ servers.push({
1308
+ name: findTag(nested, 1281 /* EC_TAG_SERVER_NAME */)?.getValue(),
1309
+ description: findTag(nested, 1282 /* EC_TAG_SERVER_DESC */)?.getValue(),
1310
+ address: findTag(nested, 1283 /* EC_TAG_SERVER_ADDRESS */)?.getValue(),
1311
+ ip,
1312
+ port,
1313
+ ping: findNumericTag(nested, 1284 /* EC_TAG_SERVER_PING */)?.getInt(),
1314
+ users: findNumericTag(nested, 1285 /* EC_TAG_SERVER_USERS */)?.getInt(),
1315
+ maxUsers: findNumericTag(nested, 1286 /* EC_TAG_SERVER_USERS_MAX */)?.getInt(),
1316
+ files: findNumericTag(nested, 1287 /* EC_TAG_SERVER_FILES */)?.getInt(),
1317
+ priority: findNumericTag(nested, 1288 /* EC_TAG_SERVER_PRIO */)?.getInt(),
1318
+ version: findTag(nested, 1291 /* EC_TAG_SERVER_VERSION */)?.getValue(),
1319
+ isStatic: toOptionalBool(findNumericTag(nested, 1290 /* EC_TAG_SERVER_STATIC */)?.getInt()),
1320
+ failedCount: findNumericTag(nested, 1289 /* EC_TAG_SERVER_FAILED */)?.getInt()
1321
+ });
1322
+ }
1323
+ return { servers };
1324
+ }
1325
+ };
1326
+ }
1327
+ });
1328
+
1329
+ // src/response/UpdateResponse.ts
1330
+ var UpdateResponse_exports = {};
1331
+ __export(UpdateResponse_exports, {
1332
+ UpdateResponseParser: () => UpdateResponseParser
1333
+ });
1334
+ var UpdateResponseParser;
1335
+ var init_UpdateResponse = __esm({
1336
+ "src/response/UpdateResponse.ts"() {
1337
+ "use strict";
1338
+ init_Codes();
1339
+ init_Tag();
1340
+ init_utils();
1341
+ init_SharedFilesResponse();
1342
+ init_DownloadQueueResponse();
1343
+ init_ClientQueueResponse();
1344
+ init_ServerListResponse();
1345
+ UpdateResponseParser = class {
1346
+ static fromPacket(packet) {
1347
+ const sharedFiles = SharedFilesResponseParser.fromPacket(packet).files;
1348
+ const downloadQueue = DownloadQueueResponseParser.fromPacket(packet).files;
1349
+ const clientContainer = findTag(packet.tags, 1536 /* EC_TAG_CLIENT */);
1350
+ const clients = clientContainer && clientContainer.nestedTags ? ClientQueueResponseParser.fromTags(clientContainer.nestedTags).clients : [];
1351
+ const serverContainer = findTag(packet.tags, 1280 /* EC_TAG_SERVER */);
1352
+ const servers = serverContainer && serverContainer.nestedTags ? ServerListResponseParser.fromTags(serverContainer.nestedTags).servers : [];
1353
+ const friendContainer = findTag(packet.tags, 2048 /* EC_TAG_FRIEND */);
1354
+ const friends = friendContainer && friendContainer.nestedTags ? this.parseFriends(friendContainer.nestedTags) : [];
1355
+ return {
1356
+ sharedFiles,
1357
+ downloadQueue,
1358
+ clients,
1359
+ servers,
1360
+ friends
1361
+ };
1362
+ }
1363
+ static parseFriends(tags) {
1364
+ const friends = [];
1365
+ const friendTags = tags.filter((t) => t.name === 2048 /* EC_TAG_FRIEND */);
1366
+ for (const friendTag of friendTags) {
1367
+ const nested = friendTag.nestedTags || [];
1368
+ friends.push({
1369
+ name: findTag(nested, 2049 /* EC_TAG_FRIEND_NAME */)?.getValue(),
1370
+ userHashHexString: findTag(nested, 2050 /* EC_TAG_FRIEND_HASH */)?.getValue()?.toString("hex"),
1371
+ ip: toOptionalIp(findNumericTag(nested, 2051 /* EC_TAG_FRIEND_IP */)?.getInt()),
1372
+ port: findNumericTag(nested, 2052 /* EC_TAG_FRIEND_PORT */)?.getInt(),
1373
+ friendSlot: toOptionalBool(findNumericTag(nested, 2056 /* EC_TAG_FRIEND_FRIENDSLOT */)?.getInt()),
1374
+ shared: toOptionalBool(findNumericTag(nested, 2057 /* EC_TAG_FRIEND_SHARED */)?.getInt()),
1375
+ // Friend client information might be nested as a client tag
1376
+ client: ClientQueueResponseParser.fromTags(nested).clients[0]
1377
+ });
1378
+ }
1379
+ return friends;
1380
+ }
1381
+ };
1382
+ }
1383
+ });
1384
+
1018
1385
  // src/model/index.ts
1019
1386
  var model_exports = {};
1020
1387
  __export(model_exports, {
@@ -1318,92 +1685,6 @@ var init_DownloadQueueRequest = __esm({
1318
1685
  }
1319
1686
  });
1320
1687
 
1321
- // src/response/DownloadQueueResponse.ts
1322
- var DownloadQueueResponse_exports = {};
1323
- __export(DownloadQueueResponse_exports, {
1324
- DownloadQueueResponseParser: () => DownloadQueueResponseParser
1325
- });
1326
- function toNumber(value, defaultValue = 0) {
1327
- if (value === void 0) return defaultValue;
1328
- return typeof value === "bigint" ? Number(value) : value;
1329
- }
1330
- var DownloadQueueResponseParser;
1331
- var init_DownloadQueueResponse = __esm({
1332
- "src/response/DownloadQueueResponse.ts"() {
1333
- "use strict";
1334
- init_Codes();
1335
- init_Tag();
1336
- DownloadQueueResponseParser = class {
1337
- static fromPacket(packet) {
1338
- const files = [];
1339
- const partfileTags = packet.tags.filter((tag) => tag.name === 768 /* EC_TAG_PARTFILE */);
1340
- for (const fileTag of partfileTags) {
1341
- const tags = fileTag.nestedTags || [];
1342
- const hashTag = findTag(tags, 798 /* EC_TAG_PARTFILE_HASH */);
1343
- const fileNameTag = findTag(tags, 769 /* EC_TAG_PARTFILE_NAME */);
1344
- const a4afSources = [];
1345
- const a4afSourcesTag = findTag(tags, 802 /* EC_TAG_PARTFILE_A4AF_SOURCES */);
1346
- if (a4afSourcesTag) {
1347
- a4afSourcesTag.nestedTags = a4afSourcesTag.nestedTags || [];
1348
- for (const sourceTag of a4afSourcesTag.nestedTags) {
1349
- if (sourceTag.name === 15 /* EC_TAG_ECID */) {
1350
- a4afSources.push(sourceTag.getValue());
1351
- }
1352
- }
1353
- }
1354
- const file = {
1355
- fileHashHexString: hashTag ? hashTag.getValue().toString("hex") : void 0,
1356
- fileName: fileNameTag ? fileNameTag.getValue() : void 0,
1357
- filePath: findTag(tags, 1032 /* EC_TAG_KNOWNFILE_FILENAME */)?.getValue(),
1358
- sizeFull: toNumber(findNumericTag(tags, 771 /* EC_TAG_PARTFILE_SIZE_FULL */)?.getLong()),
1359
- fileEd2kLink: findTag(tags, 782 /* EC_TAG_PARTFILE_ED2K_LINK */)?.getValue(),
1360
- // Transfer info
1361
- partMetID: findNumericTag(tags, 770 /* EC_TAG_PARTFILE_PARTMETID */)?.getShort(),
1362
- sizeXfer: toNumber(findNumericTag(tags, 772 /* EC_TAG_PARTFILE_SIZE_XFER */)?.getLong()),
1363
- sizeDone: toNumber(findNumericTag(tags, 774 /* EC_TAG_PARTFILE_SIZE_DONE */)?.getLong()),
1364
- fileStatus: findNumericTag(tags, 776 /* EC_TAG_PARTFILE_STATUS */)?.getInt() ?? 0,
1365
- stopped: (findNumericTag(tags, 791 /* EC_TAG_PARTFILE_STOPPED */)?.getInt() ?? 0) !== 0,
1366
- sourceCount: findNumericTag(tags, 778 /* EC_TAG_PARTFILE_SOURCE_COUNT */)?.getShort() ?? 0,
1367
- sourceNotCurrCount: findNumericTag(tags, 780 /* EC_TAG_PARTFILE_SOURCE_COUNT_NOT_CURRENT */)?.getShort() ?? 0,
1368
- sourceXferCount: findNumericTag(tags, 781 /* EC_TAG_PARTFILE_SOURCE_COUNT_XFER */)?.getShort() ?? 0,
1369
- sourceCountA4AF: findNumericTag(tags, 779 /* EC_TAG_PARTFILE_SOURCE_COUNT_A4AF */)?.getShort() ?? 0,
1370
- speed: toNumber(findNumericTag(tags, 775 /* EC_TAG_PARTFILE_SPEED */)?.getLong()),
1371
- downPrio: findNumericTag(tags, 777 /* EC_TAG_PARTFILE_PRIO */)?.getInt() ?? 0,
1372
- fileCat: toNumber(findNumericTag(tags, 783 /* EC_TAG_PARTFILE_CAT */)?.getLong()),
1373
- lastSeenComplete: toNumber(findNumericTag(tags, 785 /* EC_TAG_PARTFILE_LAST_SEEN_COMP */)?.getLong()),
1374
- lastDateChanged: toNumber(findNumericTag(tags, 784 /* EC_TAG_PARTFILE_LAST_RECV */)?.getLong()),
1375
- downloadActiveTime: findNumericTag(tags, 792 /* EC_TAG_PARTFILE_DOWNLOAD_ACTIVE */)?.getInt() ?? 0,
1376
- availablePartCount: findNumericTag(tags, 797 /* EC_TAG_PARTFILE_AVAILABLE_PARTS */)?.getShort() ?? 0,
1377
- a4AFAuto: (findNumericTag(tags, 801 /* EC_TAG_PARTFILE_A4AFAUTO */)?.getInt() ?? 0) !== 0,
1378
- hashingProgress: (findNumericTag(tags, 800 /* EC_TAG_PARTFILE_HASHED_PART_COUNT */)?.getInt() ?? 0) !== 0,
1379
- // Statistics
1380
- getLostDueToCorruption: toNumber(findNumericTag(tags, 793 /* EC_TAG_PARTFILE_LOST_CORRUPTION */)?.getLong()),
1381
- getGainDueToCompression: toNumber(findNumericTag(tags, 794 /* EC_TAG_PARTFILE_GAINED_COMPRESSION */)?.getLong()),
1382
- totalPacketsSavedDueToICH: findNumericTag(tags, 795 /* EC_TAG_PARTFILE_SAVED_ICH */)?.getInt() ?? 0,
1383
- // Known file shared info (defaults)
1384
- upPrio: findNumericTag(tags, 1035 /* EC_TAG_KNOWNFILE_PRIO */)?.getInt() ?? 0,
1385
- getRequests: findNumericTag(tags, 1027 /* EC_TAG_KNOWNFILE_REQ_COUNT */)?.getShort() ?? 0,
1386
- getAllRequests: findNumericTag(tags, 1028 /* EC_TAG_KNOWNFILE_REQ_COUNT_ALL */)?.getInt() ?? 0,
1387
- getAccepts: findNumericTag(tags, 1029 /* EC_TAG_KNOWNFILE_ACCEPT_COUNT */)?.getShort() ?? 0,
1388
- getAllAccepts: findNumericTag(tags, 1030 /* EC_TAG_KNOWNFILE_ACCEPT_COUNT_ALL */)?.getInt() ?? 0,
1389
- getXferred: toNumber(findNumericTag(tags, 1025 /* EC_TAG_KNOWNFILE_XFERRED */)?.getLong()),
1390
- getAllXferred: toNumber(findNumericTag(tags, 1026 /* EC_TAG_KNOWNFILE_XFERRED_ALL */)?.getLong()),
1391
- getCompleteSourcesLow: findNumericTag(tags, 1033 /* EC_TAG_KNOWNFILE_COMPLETE_SOURCES_LOW */)?.getShort() ?? 0,
1392
- getCompleteSourcesHigh: findNumericTag(tags, 1034 /* EC_TAG_KNOWNFILE_COMPLETE_SOURCES_HIGH */)?.getShort() ?? 0,
1393
- getCompleteSources: findNumericTag(tags, 1037 /* EC_TAG_KNOWNFILE_COMPLETE_SOURCES */)?.getShort() ?? 0,
1394
- getOnQueue: findNumericTag(tags, 1036 /* EC_TAG_KNOWNFILE_ON_QUEUE */)?.getShort() ?? 0,
1395
- getComment: findTag(tags, 1038 /* EC_TAG_KNOWNFILE_COMMENT */)?.getValue(),
1396
- getRating: findNumericTag(tags, 1039 /* EC_TAG_KNOWNFILE_RATING */)?.getInt(),
1397
- a4afSources
1398
- };
1399
- files.push(file);
1400
- }
1401
- return { files };
1402
- }
1403
- };
1404
- }
1405
- });
1406
-
1407
1688
  // src/request/SharedFilesRequest.ts
1408
1689
  var SharedFilesRequest_exports = {};
1409
1690
  __export(SharedFilesRequest_exports, {
@@ -1425,57 +1706,6 @@ var init_SharedFilesRequest = __esm({
1425
1706
  }
1426
1707
  });
1427
1708
 
1428
- // src/response/SharedFilesResponse.ts
1429
- var SharedFilesResponse_exports = {};
1430
- __export(SharedFilesResponse_exports, {
1431
- SharedFilesResponseParser: () => SharedFilesResponseParser
1432
- });
1433
- function toNumber2(value, defaultValue = 0) {
1434
- if (value === void 0) return defaultValue;
1435
- return typeof value === "bigint" ? Number(value) : value;
1436
- }
1437
- var SharedFilesResponseParser;
1438
- var init_SharedFilesResponse = __esm({
1439
- "src/response/SharedFilesResponse.ts"() {
1440
- "use strict";
1441
- init_Codes();
1442
- init_Tag();
1443
- SharedFilesResponseParser = class {
1444
- static fromPacket(packet) {
1445
- const files = [];
1446
- const knownfileTags = packet.tags.filter((tag) => tag.name === 1024 /* EC_TAG_KNOWNFILE */);
1447
- for (const fileTag of knownfileTags) {
1448
- const tags = fileTag.nestedTags || [];
1449
- const hashTag = findTag(tags, 798 /* EC_TAG_PARTFILE_HASH */);
1450
- const fileNameTag = findTag(tags, 769 /* EC_TAG_PARTFILE_NAME */);
1451
- const file = {
1452
- fileHashHexString: hashTag ? hashTag.getValue().toString("hex") : void 0,
1453
- fileName: fileNameTag ? fileNameTag.getValue() : void 0,
1454
- filePath: findTag(tags, 1032 /* EC_TAG_KNOWNFILE_FILENAME */)?.getValue(),
1455
- sizeFull: toNumber2(findNumericTag(tags, 771 /* EC_TAG_PARTFILE_SIZE_FULL */)?.getLong()),
1456
- fileEd2kLink: findTag(tags, 782 /* EC_TAG_PARTFILE_ED2K_LINK */)?.getValue(),
1457
- upPrio: findNumericTag(tags, 1035 /* EC_TAG_KNOWNFILE_PRIO */)?.getInt() ?? 0,
1458
- getRequests: findNumericTag(tags, 1027 /* EC_TAG_KNOWNFILE_REQ_COUNT */)?.getShort() ?? 0,
1459
- getAllRequests: findNumericTag(tags, 1028 /* EC_TAG_KNOWNFILE_REQ_COUNT_ALL */)?.getInt() ?? 0,
1460
- getAccepts: findNumericTag(tags, 1029 /* EC_TAG_KNOWNFILE_ACCEPT_COUNT */)?.getShort() ?? 0,
1461
- getAllAccepts: findNumericTag(tags, 1030 /* EC_TAG_KNOWNFILE_ACCEPT_COUNT_ALL */)?.getInt() ?? 0,
1462
- getXferred: toNumber2(findNumericTag(tags, 1025 /* EC_TAG_KNOWNFILE_XFERRED */)?.getLong()),
1463
- getAllXferred: toNumber2(findNumericTag(tags, 1026 /* EC_TAG_KNOWNFILE_XFERRED_ALL */)?.getLong()),
1464
- getCompleteSourcesLow: findNumericTag(tags, 1033 /* EC_TAG_KNOWNFILE_COMPLETE_SOURCES_LOW */)?.getShort() ?? 0,
1465
- getCompleteSourcesHigh: findNumericTag(tags, 1034 /* EC_TAG_KNOWNFILE_COMPLETE_SOURCES_HIGH */)?.getShort() ?? 0,
1466
- getCompleteSources: findNumericTag(tags, 1037 /* EC_TAG_KNOWNFILE_COMPLETE_SOURCES */)?.getShort() ?? 0,
1467
- getOnQueue: findNumericTag(tags, 1036 /* EC_TAG_KNOWNFILE_ON_QUEUE */)?.getShort() ?? 0,
1468
- getComment: findTag(tags, 1038 /* EC_TAG_KNOWNFILE_COMMENT */)?.getValue(),
1469
- getRating: findNumericTag(tags, 1039 /* EC_TAG_KNOWNFILE_RATING */)?.getInt()
1470
- };
1471
- files.push(file);
1472
- }
1473
- return { files };
1474
- }
1475
- };
1476
- }
1477
- });
1478
-
1479
1709
  // src/request/ClientQueueRequest.ts
1480
1710
  var ClientQueueRequest_exports = {};
1481
1711
  __export(ClientQueueRequest_exports, {
@@ -1497,91 +1727,6 @@ var init_ClientQueueRequest = __esm({
1497
1727
  }
1498
1728
  });
1499
1729
 
1500
- // src/response/utils.ts
1501
- function formatIp(ip) {
1502
- if (ip === void 0) return "";
1503
- return [ip >>> 24 & 255, ip >>> 16 & 255, ip >>> 8 & 255, ip & 255].join(".");
1504
- }
1505
- var init_utils = __esm({
1506
- "src/response/utils.ts"() {
1507
- "use strict";
1508
- }
1509
- });
1510
-
1511
- // src/response/ClientQueueResponse.ts
1512
- var ClientQueueResponse_exports = {};
1513
- __export(ClientQueueResponse_exports, {
1514
- ClientQueueResponseParser: () => ClientQueueResponseParser
1515
- });
1516
- function toNumber3(value, defaultValue = 0) {
1517
- if (value === void 0) return defaultValue;
1518
- return typeof value === "bigint" ? Number(value) : value;
1519
- }
1520
- var ClientQueueResponseParser;
1521
- var init_ClientQueueResponse = __esm({
1522
- "src/response/ClientQueueResponse.ts"() {
1523
- "use strict";
1524
- init_Codes();
1525
- init_Tag();
1526
- init_utils();
1527
- ClientQueueResponseParser = class {
1528
- static fromPacket(packet) {
1529
- const clients = [];
1530
- const clientTags = packet.tags.filter((tag) => tag.name === 1536 /* EC_TAG_CLIENT */);
1531
- for (const clientTag of clientTags) {
1532
- const tags = clientTag.nestedTags || [];
1533
- const client = {
1534
- clientName: findTag(tags, 256 /* EC_TAG_CLIENT_NAME */)?.getValue(),
1535
- userHashHexString: findTag(tags, 1539 /* EC_TAG_CLIENT_HASH */)?.getValue().toString("hex"),
1536
- userID: findNumericTag(tags, 1566 /* EC_TAG_CLIENT_USER_ID */)?.getInt(),
1537
- score: findNumericTag(tags, 1538 /* EC_TAG_CLIENT_SCORE */)?.getInt(),
1538
- software: findTag(tags, 1537 /* EC_TAG_CLIENT_SOFTWARE */)?.getValue(),
1539
- softVerStr: findTag(tags, 1557 /* EC_TAG_CLIENT_SOFT_VER_STR */)?.getValue(),
1540
- userIP: formatIp(findNumericTag(tags, 1552 /* EC_TAG_CLIENT_USER_IP */)?.getInt()),
1541
- userPort: findNumericTag(tags, 1553 /* EC_TAG_CLIENT_USER_PORT */)?.getInt(),
1542
- sourceFrom: toNumber3(findNumericTag(tags, 1551 /* EC_TAG_CLIENT_FROM */)?.getLong()),
1543
- serverIP: formatIp(findNumericTag(tags, 1554 /* EC_TAG_CLIENT_SERVER_IP */)?.getInt()),
1544
- serverPort: findNumericTag(tags, 1555 /* EC_TAG_CLIENT_SERVER_PORT */)?.getInt(),
1545
- serverName: findTag(tags, 1556 /* EC_TAG_CLIENT_SERVER_NAME */)?.getValue(),
1546
- upSpeed: toNumber3(findNumericTag(tags, 1549 /* EC_TAG_CLIENT_UP_SPEED */)?.getLong()),
1547
- downSpeed: toNumber3(findNumericTag(tags, 1550 /* EC_TAG_CLIENT_DOWN_SPEED */)?.getLong()),
1548
- uploadSession: toNumber3(findNumericTag(tags, 1545 /* EC_TAG_CLIENT_UPLOAD_SESSION */)?.getLong()),
1549
- transferredDown: toNumber3(findNumericTag(tags, 772 /* EC_TAG_PARTFILE_SIZE_XFER */)?.getLong()),
1550
- uploadedTotal: toNumber3(findNumericTag(tags, 1546 /* EC_TAG_CLIENT_UPLOAD_TOTAL */)?.getLong()),
1551
- downloadedTotal: toNumber3(findNumericTag(tags, 1547 /* EC_TAG_CLIENT_DOWNLOAD_TOTAL */)?.getLong()),
1552
- uploadState: findNumericTag(tags, 1564 /* EC_TAG_CLIENT_UPLOAD_STATE */)?.getInt(),
1553
- downloadState: findNumericTag(tags, 1548 /* EC_TAG_CLIENT_DOWNLOAD_STATE */)?.getInt(),
1554
- identState: findNumericTag(tags, 1559 /* EC_TAG_CLIENT_IDENT_STATE */)?.getInt(),
1555
- extProtocol: findNumericTag(tags, 1565 /* EC_TAG_CLIENT_EXT_PROTOCOL */)?.getInt(),
1556
- waitingPosition: findNumericTag(tags, 1558 /* EC_TAG_CLIENT_WAITING_POSITION */)?.getInt(),
1557
- remoteQueueRank: findNumericTag(tags, 1562 /* EC_TAG_CLIENT_REMOTE_QUEUE_RANK */)?.getInt(),
1558
- oldRemoteQueueRank: findNumericTag(tags, 1570 /* EC_TAG_CLIENT_OLD_REMOTE_QUEUE_RANK */)?.getInt(),
1559
- obfuscationStatus: findNumericTag(tags, 1560 /* EC_TAG_CLIENT_OBFUSCATION_STATUS */)?.getInt(),
1560
- kadPort: findNumericTag(tags, 1571 /* EC_TAG_CLIENT_KAD_PORT */)?.getInt(),
1561
- friendSlot: findNumericTag(tags, 1540 /* EC_TAG_CLIENT_FRIEND_SLOT */)?.getInt(),
1562
- uploadFileId: toNumber3(findNumericTag(tags, 1567 /* EC_TAG_CLIENT_UPLOAD_FILE */)?.getLong()),
1563
- uploadFilename: findTag(tags, 769 /* EC_TAG_PARTFILE_NAME */)?.getValue(),
1564
- requestFileId: toNumber3(findNumericTag(tags, 1568 /* EC_TAG_CLIENT_REQUEST_FILE */)?.getLong()),
1565
- remoteFilename: findTag(tags, 1575 /* EC_TAG_CLIENT_REMOTE_FILENAME */)?.getValue(),
1566
- disableViewShared: !!findNumericTag(tags, 1563 /* EC_TAG_CLIENT_DISABLE_VIEW_SHARED */)?.getInt(),
1567
- version: findNumericTag(tags, 257 /* EC_TAG_CLIENT_VERSION */)?.getInt(),
1568
- modVersion: findTag(tags, 1576 /* EC_TAG_CLIENT_MOD_VERSION */)?.getValue(),
1569
- osInfo: findTag(tags, 1577 /* EC_TAG_CLIENT_OS_INFO */)?.getValue(),
1570
- availableParts: findNumericTag(tags, 1578 /* EC_TAG_CLIENT_AVAILABLE_PARTS */)?.getInt(),
1571
- partStatus: findTag(tags, 1572 /* EC_TAG_CLIENT_PART_STATUS */)?.getValue(),
1572
- nextRequestedPart: findNumericTag(tags, 1573 /* EC_TAG_CLIENT_NEXT_REQUESTED_PART */)?.getInt(),
1573
- lastDownloadingPart: findNumericTag(tags, 1574 /* EC_TAG_CLIENT_LAST_DOWNLOADING_PART */)?.getInt(),
1574
- uploadPartStatus: findTag(tags, 1579 /* EC_TAG_CLIENT_UPLOAD_PART_STATUS */)?.getValue()
1575
- // Additional fields can be added here as needed
1576
- };
1577
- clients.push(client);
1578
- }
1579
- return { clients };
1580
- }
1581
- };
1582
- }
1583
- });
1584
-
1585
1730
  // src/request/ServerListRequest.ts
1586
1731
  var ServerListRequest_exports = {};
1587
1732
  __export(ServerListRequest_exports, {
@@ -1601,61 +1746,6 @@ var init_ServerListRequest = __esm({
1601
1746
  }
1602
1747
  });
1603
1748
 
1604
- // src/response/ServerListResponse.ts
1605
- var ServerListResponse_exports = {};
1606
- __export(ServerListResponse_exports, {
1607
- ServerListResponseParser: () => ServerListResponseParser
1608
- });
1609
- var ServerListResponseParser;
1610
- var init_ServerListResponse = __esm({
1611
- "src/response/ServerListResponse.ts"() {
1612
- "use strict";
1613
- init_Codes();
1614
- init_Tag();
1615
- init_utils();
1616
- ServerListResponseParser = class {
1617
- static fromPacket(packet) {
1618
- const servers = [];
1619
- const serverTags = packet.tags.filter((tag) => tag.name === 1280 /* EC_TAG_SERVER */);
1620
- for (const serverTag of serverTags) {
1621
- const nested = serverTag.nestedTags || [];
1622
- const ipv4Tag = findTag(nested, 1292 /* EC_TAG_SERVER_IP */) || findTag(nested, 1283 /* EC_TAG_SERVER_ADDRESS */) || (serverTag.constructor.name.includes("Ipv4") ? serverTag : null);
1623
- let ip = "";
1624
- let port = 0;
1625
- if (ipv4Tag && ipv4Tag.getValue() && typeof ipv4Tag.getValue() === "object" && "address" in ipv4Tag.getValue()) {
1626
- const val = ipv4Tag.getValue();
1627
- ip = val.address;
1628
- port = val.port;
1629
- } else {
1630
- const ipNum = findNumericTag(nested, 1292 /* EC_TAG_SERVER_IP */)?.getInt() || findNumericTag(packet.tags, 1292 /* EC_TAG_SERVER_IP */)?.getInt();
1631
- port = findNumericTag(nested, 1293 /* EC_TAG_SERVER_PORT */)?.getInt() || findNumericTag(packet.tags, 1293 /* EC_TAG_SERVER_PORT */)?.getInt() || 0;
1632
- ip = formatIp(ipNum);
1633
- }
1634
- if (port === 0) {
1635
- port = findNumericTag(nested, 1293 /* EC_TAG_SERVER_PORT */)?.getInt() || 0;
1636
- }
1637
- servers.push({
1638
- name: findTag(nested, 1281 /* EC_TAG_SERVER_NAME */)?.getValue() || "Unknown",
1639
- description: findTag(nested, 1282 /* EC_TAG_SERVER_DESC */)?.getValue(),
1640
- address: findTag(nested, 1283 /* EC_TAG_SERVER_ADDRESS */)?.getValue(),
1641
- ip,
1642
- port,
1643
- ping: findNumericTag(nested, 1284 /* EC_TAG_SERVER_PING */)?.getInt(),
1644
- users: findNumericTag(nested, 1285 /* EC_TAG_SERVER_USERS */)?.getInt(),
1645
- maxUsers: findNumericTag(nested, 1286 /* EC_TAG_SERVER_USERS_MAX */)?.getInt(),
1646
- files: findNumericTag(nested, 1287 /* EC_TAG_SERVER_FILES */)?.getInt(),
1647
- priority: findNumericTag(nested, 1288 /* EC_TAG_SERVER_PRIO */)?.getInt() || 0,
1648
- version: findTag(nested, 1291 /* EC_TAG_SERVER_VERSION */)?.getValue(),
1649
- isStatic: !!findNumericTag(nested, 1290 /* EC_TAG_SERVER_STATIC */)?.getInt(),
1650
- failedCount: findNumericTag(nested, 1289 /* EC_TAG_SERVER_FAILED */)?.getInt() || 0
1651
- });
1652
- }
1653
- return { servers };
1654
- }
1655
- };
1656
- }
1657
- });
1658
-
1659
1749
  // src/request/ServerConnectRequest.ts
1660
1750
  var ServerConnectRequest_exports = {};
1661
1751
  __export(ServerConnectRequest_exports, {
@@ -1671,12 +1761,9 @@ var init_ServerConnectRequest = __esm({
1671
1761
  ServerConnectRequest = class extends Request {
1672
1762
  constructor(ip, port) {
1673
1763
  super(47 /* EC_OP_SERVER_CONNECT */);
1674
- this.addTag(new UIntTag(1292 /* EC_TAG_SERVER_IP */, this.ipToNumber(ip)));
1675
- this.addTag(new UShortTag(1293 /* EC_TAG_SERVER_PORT */, port));
1676
- }
1677
- ipToNumber(ip) {
1678
- const parts = ip.split(".").map((p) => parseInt(p, 10));
1679
- return (parts[0] << 24 | parts[1] << 16 | parts[2] << 8 | parts[3]) >>> 0;
1764
+ if (ip && port) {
1765
+ this.addTag(new Ipv4Tag(1280 /* EC_TAG_SERVER */, { address: ip, port }));
1766
+ }
1680
1767
  }
1681
1768
  };
1682
1769
  }
@@ -2135,8 +2222,8 @@ var TagParser = class {
2135
2222
  return new StringTag(name, strValue);
2136
2223
  }
2137
2224
  case 7 /* EC_TAGTYPE_DOUBLE */: {
2138
- const strValue = value[value.length - 1] === 0 ? value.toString("utf-8", 0, value.length - 1) : value.toString("utf-8");
2139
- return new DoubleTag(name, parseFloat(strValue));
2225
+ const numValue2 = value.length >= 8 ? value.readDoubleBE(0) : 0;
2226
+ return new DoubleTag(name, numValue2);
2140
2227
  }
2141
2228
  case 8 /* EC_TAGTYPE_IPV4 */: {
2142
2229
  if (value.length !== 6) {
@@ -2401,30 +2488,15 @@ var TagEncoder = class {
2401
2488
  }
2402
2489
  return offset;
2403
2490
  // Empty custom tag, no data to write
2404
- case 6 /* EC_TAGTYPE_STRING */:
2405
- encoded.copy(buffer, offset);
2406
- return offset + encoded.length;
2407
2491
  case 2 /* EC_TAGTYPE_UINT8 */:
2408
- buffer.writeUInt8(tag.getValue(), offset);
2409
- return offset + 1;
2410
2492
  case 3 /* EC_TAGTYPE_UINT16 */:
2411
- buffer.writeUInt16BE(tag.getValue(), offset);
2412
- return offset + 2;
2413
2493
  case 4 /* EC_TAGTYPE_UINT32 */:
2414
- buffer.writeUInt32BE(tag.getValue(), offset);
2415
- return offset + 4;
2416
2494
  case 5 /* EC_TAGTYPE_UINT64 */:
2417
- buffer.writeBigUInt64BE(tag.getValue(), offset);
2418
- return offset + 8;
2495
+ case 6 /* EC_TAGTYPE_STRING */:
2419
2496
  case 7 /* EC_TAGTYPE_DOUBLE */:
2420
- buffer.writeDoubleBE(tag.getValue(), offset);
2421
- return offset + 8;
2422
2497
  case 8 /* EC_TAGTYPE_IPV4 */:
2423
- buffer.writeUInt32BE(tag.getValue().ip, offset);
2424
- buffer.writeUInt16BE(tag.getValue().port, offset + 4);
2425
- return offset + 6;
2426
- case 10 /* EC_TAGTYPE_UINT128 */:
2427
2498
  case 9 /* EC_TAGTYPE_HASH16 */:
2499
+ case 10 /* EC_TAGTYPE_UINT128 */:
2428
2500
  encoded.copy(buffer, offset);
2429
2501
  return offset + encoded.length;
2430
2502
  default:
@@ -2803,6 +2875,16 @@ var AmuleClient = class {
2803
2875
  const packet = await this.connection.sendRequest(request);
2804
2876
  return StatsResponseParser2.fromPacket(packet);
2805
2877
  }
2878
+ /**
2879
+ * Get incremental updates for files, clients, servers, and friends
2880
+ */
2881
+ async getUpdate(detailLevel = 4 /* EC_DETAIL_INC_UPDATE */) {
2882
+ const { UpdateRequest: UpdateRequest2 } = await Promise.resolve().then(() => (init_UpdateRequest(), UpdateRequest_exports));
2883
+ const { UpdateResponseParser: UpdateResponseParser2 } = await Promise.resolve().then(() => (init_UpdateResponse(), UpdateResponse_exports));
2884
+ const request = new UpdateRequest2(detailLevel);
2885
+ const packet = await this.connection.sendRequest(request);
2886
+ return UpdateResponseParser2.fromPacket(packet);
2887
+ }
2806
2888
  /**
2807
2889
  * Start an asynchronous search
2808
2890
  */