steamutils 1.5.10 → 1.5.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. package/SteamClient.js +53 -99
  2. package/const.js +51 -0
  3. package/index.js +7949 -7933
  4. package/package.json +2 -1
package/SteamClient.js CHANGED
@@ -3,62 +3,13 @@ import _ from "lodash";
3
3
  import SteamID from "steamid";
4
4
  import axios from "axios";
5
5
  import SteamUser from "./index.js";
6
+ import { LOCS, RANKS } from "./const.js";
6
7
  import { v4 as uuidv4 } from "uuid";
7
8
  import EFriendRelationship from "steam-user/enums/EFriendRelationship.js";
8
9
  import moment from "moment-timezone";
9
10
  import { encode, encodeUids } from "./bufferHelpers.js";
10
11
  import { ESteamProto, SteamProto, SteamProtoType } from "./steamproto.js";
11
-
12
- export const RANKS = {
13
- 0: "Unranked",
14
- 1: "Silver I",
15
- 2: "Silver II",
16
- 3: "Silver III",
17
- 4: "Silver IV",
18
- 5: "Silver Elite",
19
- 6: "Silver Elite Master",
20
- 7: "Gold Nova I",
21
- 8: "Gold Nova II",
22
- 9: "Gold Nova III",
23
- 10: "Gold Nova Master",
24
- 11: "Master Guardian I",
25
- 12: "Master Guardian II",
26
- 13: "Master Guardian Elite",
27
- 14: "Distinguished Master Guardian",
28
- 15: "Legendary Eagle",
29
- 16: "Legendary Eagle Master",
30
- 17: "Supreme Master First Class",
31
- 18: "The Global Elite",
32
- };
33
-
34
- export const LOCS = {
35
- 20054: "VN",
36
- 23115: "KZ",
37
- 20041: "IN",
38
- 20035: "CN",
39
- 17474: "BD",
40
- 17481: "ID",
41
- 22861: "MY",
42
- 18516: "TH",
43
- 22356: "TW",
44
- 21067: "KR",
45
- 19272: "HK",
46
- 18512: "PH",
47
- 21842: "RU",
48
- 16716: "LA",
49
- 20558: "NP",
50
- 18259: "SG",
51
- 19789: "MM",
52
- 20045: "MN",
53
- 18251: "KG",
54
- 18507: "KH",
55
- 22605: "MX",
56
- 19280: "PK",
57
- 20301: "HK/MO", //hongkong or macau
58
- 21333: "Unknown",
59
- 21825: "AU",
60
- 20034: "Unkown",
61
- };
12
+ import PQueue from "p-queue";
62
13
 
63
14
  const AppID = 730;
64
15
  export let CSGO_VER = 13960;
@@ -93,6 +44,8 @@ export const SteamClientEvents = {
93
44
  logOff: "logOff",
94
45
  };
95
46
 
47
+ const _sendMessageDelayQueue = new PQueue({ concurrency: 1 });
48
+
96
49
  function SteamClient({ username, cookie, clientJsToken, isAutoRequestFreeLicense = true, isFakeGameScore = true, isPartyRegister = true, isAutoPlay = false, isInvisible = false, autoAcceptTradeRequest = false, autoReconnect = true, games = null }) {
97
50
  let steamClient = null;
98
51
  let prime = null;
@@ -2296,59 +2249,43 @@ function SteamClient({ username, cookie, clientJsToken, isAutoRequestFreeLicense
2296
2249
  );
2297
2250
  }
2298
2251
 
2299
- const MessageQueue = [];
2252
+ const messageQueue = new PQueue({ concurrency: 1 });
2253
+ const messageController = new AbortController();
2300
2254
 
2301
2255
  function clearMessageQueue() {
2302
- while (MessageQueue.length) {
2303
- const item = MessageQueue.shift();
2304
- item?.callback?.();
2305
- }
2256
+ messageQueue.clear();
2257
+ messageController.abort();
2306
2258
  }
2307
2259
 
2308
- let isSendingFriendMessages = false;
2309
- async function _execMessageQueue() {
2310
- if (isLogOff) {
2311
- clearMessageQueue();
2312
- return;
2313
- }
2314
-
2315
- if (isSendingFriendMessages) {
2316
- return;
2317
- }
2318
- while (MessageQueue.length) {
2319
- try {
2320
- isSendingFriendMessages = true;
2321
- const item = MessageQueue.shift();
2322
- if (!item) {
2323
- break;
2324
- }
2325
- const result = await _sendFriendMessage(item.steamId, item.message);
2326
- if (typeof item.callback === "function") {
2327
- try {
2328
- await item.callback(result);
2329
- } catch (e) {}
2330
- }
2331
- if (MessageQueue.length) {
2332
- await sleep(1000);
2333
- }
2334
- } catch (e) {
2335
- console.error("_execMessageQueue", e);
2336
- }
2337
- }
2338
- isSendingFriendMessages = false;
2339
- }
2340
-
2341
- async function _sendFriendMessage(steamId, message) {
2260
+ async function _sendFriendMessage({ steamId, message, signal }) {
2342
2261
  let result = null;
2343
2262
  for (let i = 0; i < 10; i++) {
2344
2263
  if (isLogOff) {
2345
2264
  return;
2346
2265
  }
2347
- result = await new Promise((resolve) => {
2348
- steamClient.chat.sendFriendMessage(steamId, message, undefined, function (...args) {
2349
- resolve(args);
2266
+
2267
+ try {
2268
+ result = await new Promise((resolve, reject) => {
2269
+ function listener() {
2270
+ reject(new Error("aborted"));
2271
+ removeListener();
2272
+ }
2273
+
2274
+ function removeListener() {
2275
+ signal.removeEventListener("abort", listener);
2276
+ }
2277
+
2278
+ signal.addEventListener("abort", listener);
2279
+ steamClient.chat.sendFriendMessage(steamId, message, undefined, function (...args) {
2280
+ resolve(args);
2281
+ removeListener();
2282
+ });
2350
2283
  });
2351
- });
2284
+ } catch (e) {
2285
+ console.error("_sendFriendMessage Error", e);
2286
+ return;
2287
+ }
2288
+
2352
2289
  if (result?.[1]?.server_timestamp) {
2353
2290
  return result?.[1];
2354
2291
  } else if (result?.[0]?.message?.includes?.("RateLimitExceeded")) {
@@ -2364,10 +2301,16 @@ function SteamClient({ username, cookie, clientJsToken, isAutoRequestFreeLicense
2364
2301
  if (isLogOff) {
2365
2302
  return;
2366
2303
  }
2367
- return new Promise((resolve) => {
2368
- MessageQueue.push({ steamId, message, callback: resolve });
2369
- _execMessageQueue();
2370
- });
2304
+ try {
2305
+ return await messageQueue.add(
2306
+ async ({ signal }) => {
2307
+ try {
2308
+ return await _sendFriendMessage({ steamId, message, signal });
2309
+ } catch (error) {}
2310
+ },
2311
+ { signal: messageController.signal },
2312
+ );
2313
+ } catch (error) {}
2371
2314
  }
2372
2315
 
2373
2316
  async function autoRequestFreeLicense(shouldLog = false, max = 10) {
@@ -2889,7 +2832,18 @@ function SteamClient({ username, cookie, clientJsToken, isAutoRequestFreeLicense
2889
2832
  setPersona(state, name) {
2890
2833
  steamClient.setPersona(state, name);
2891
2834
  },
2892
- sendFriendMessage,
2835
+ sendFriendMessage: async (steamId, message) => {
2836
+ if (isLogOff) {
2837
+ return;
2838
+ }
2839
+
2840
+ return new Promise(async (resolve, reject) => {
2841
+ _sendMessageDelayQueue.add(async () => {
2842
+ sendFriendMessage(steamId, message).then(resolve).catch(reject);
2843
+ await sleep(500);
2844
+ });
2845
+ });
2846
+ },
2893
2847
  sendFriendTyping,
2894
2848
  getSteamClient() {
2895
2849
  return steamClient;
package/const.js CHANGED
@@ -516,3 +516,54 @@ export const ItemQuality = {
516
516
  Favoured: 13,
517
517
  Max: 14,
518
518
  };
519
+
520
+ export const RANKS = {
521
+ 0: "Unranked",
522
+ 1: "Silver I",
523
+ 2: "Silver II",
524
+ 3: "Silver III",
525
+ 4: "Silver IV",
526
+ 5: "Silver Elite",
527
+ 6: "Silver Elite Master",
528
+ 7: "Gold Nova I",
529
+ 8: "Gold Nova II",
530
+ 9: "Gold Nova III",
531
+ 10: "Gold Nova Master",
532
+ 11: "Master Guardian I",
533
+ 12: "Master Guardian II",
534
+ 13: "Master Guardian Elite",
535
+ 14: "Distinguished Master Guardian",
536
+ 15: "Legendary Eagle",
537
+ 16: "Legendary Eagle Master",
538
+ 17: "Supreme Master First Class",
539
+ 18: "The Global Elite",
540
+ };
541
+
542
+ export const LOCS = {
543
+ 20054: "VN",
544
+ 23115: "KZ",
545
+ 20041: "IN",
546
+ 20035: "CN",
547
+ 17474: "BD",
548
+ 17481: "ID",
549
+ 22861: "MY",
550
+ 18516: "TH",
551
+ 22356: "TW",
552
+ 21067: "KR",
553
+ 19272: "HK",
554
+ 18512: "PH",
555
+ 21842: "RU",
556
+ 16716: "LA",
557
+ 20558: "NP",
558
+ 18259: "SG",
559
+ 19789: "MM",
560
+ 20045: "MN",
561
+ 18251: "KG",
562
+ 18507: "KH",
563
+ 22605: "MX",
564
+ 19280: "PK",
565
+ 20301: "HK/MO", //hongkong or macau
566
+ 21333: "Unknown",
567
+ 21825: "AU",
568
+ 20034: "Unkown",
569
+ };