steamutils 1.0.44 → 1.0.45

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 (2) hide show
  1. package/SteamClient.js +55 -21
  2. package/package.json +1 -1
package/SteamClient.js CHANGED
@@ -95,10 +95,33 @@ function SteamClient({
95
95
 
96
96
  const events = {
97
97
  loggedOn: [],
98
+ csgoOnline: [],
98
99
  webSession: [],
99
100
  friendMessage: [],
100
101
  friendTyping: [],
101
102
  }
103
+ function callEvent(_events, data) {
104
+ _events.forEach((e) => {
105
+ e.callback?.(data)
106
+ e.timeout && clearTimeout(e.timeout)
107
+ delete e.timeout
108
+ if (e.once) {
109
+ delete e.callback
110
+ }
111
+ })
112
+ _.remove(_events, e => e.once)
113
+ }
114
+ function onEvent(name, callback, once, timeout) {
115
+ if (!events[name]) {
116
+ events[name] = []
117
+ }
118
+ const t = timeout ? setTimeout(callback, timeout) : null
119
+ events[name].push({
120
+ once,
121
+ callback,
122
+ timeout: t,
123
+ })
124
+ }
102
125
 
103
126
  const intervals = {}
104
127
 
@@ -255,7 +278,7 @@ function SteamClient({
255
278
  steamClient.on('webSession', (sessionID, cookies) => {
256
279
  const webSession = {sessionID, cookies};
257
280
  steamClient.webSession = webSession
258
- events.webSession.forEach(e => e?.(webSession))
281
+ callEvent(events.webSession, webSession)
259
282
  })
260
283
 
261
284
  steamClient.on('receivedFromGC', async (appid, msgType, payload) => {
@@ -307,9 +330,13 @@ function SteamClient({
307
330
  }
308
331
  break
309
332
  }
333
+ default: {
334
+ console.log("cache_object.type_id", cache_object.type_id);
335
+ }
310
336
  }
311
337
  }
312
338
  }
339
+ callEvent(events.csgoOnline)
313
340
  break
314
341
  }
315
342
  case Protos.csgo.ECsgoGCMsg.k_EMsgGCCStrike15_v2_MatchmakingGC2ClientUpdate: {
@@ -506,7 +533,6 @@ function SteamClient({
506
533
  player_cur_xp: 327682846,
507
534
  player_xp_bonus_flags: 0
508
535
  }]
509
- console.log(data);
510
536
 
511
537
  const accountid = data?.[0]?.account_id
512
538
  const cb = getPlayersProfileCallback[accountid]
@@ -575,7 +601,7 @@ function SteamClient({
575
601
  console.log(`app ${appid} launched on account ${getAccountInfoName()}`)
576
602
  await sendHello()
577
603
 
578
- events.loggedOn.forEach(e => e?.())
604
+ callEvent(events.loggedOn)
579
605
  })
580
606
 
581
607
  steamClient.on('friendMessage', async (user, message) => {
@@ -584,26 +610,26 @@ function SteamClient({
584
610
  const player_name = personas[sid64]?.player_name || ''
585
611
  console.log('friendMessage', sid64, message);
586
612
 
587
- if ([`Invited you to play a game!`, `Đã mời bạn chơi một trò chơi!`].includes(message)) {
588
- if (events.friendMessage.length) {
589
- events.friendMessage.forEach(e => e?.({
613
+ if ([`Inited you to play a game!`, `Đã mời bạn chơi một trò chơi!`].includes(message)) {
614
+ callEvent(events.friendMessage, {
590
615
  player_name,
591
616
  message,
592
617
  invite: true,
593
618
  sid64,
594
- }))
595
- }
619
+ })
596
620
  } else {
597
- events.friendMessage.forEach(e => e?.({
621
+ callEvent(events.friendMessage, {
598
622
  message,
599
623
  player_name,
600
624
  sid64,
601
- }))
625
+ })
602
626
  }
603
627
  });
604
628
 
605
629
  steamClient.on('friendTyping', async function (steamID, message) {
606
- events.friendTyping.forEach(e => e?.(steamID, message))
630
+ callEvent(events.friendTyping, {
631
+ steamID, message
632
+ })
607
633
  });
608
634
  }
609
635
 
@@ -625,6 +651,20 @@ function SteamClient({
625
651
  })
626
652
  }
627
653
 
654
+ async function checkPlayerPrimeStatus(accountid) {
655
+ const profile = await getPlayersProfile(accountid)
656
+ if(!profile) return false
657
+
658
+ if(profile.ranking?.account_id){
659
+ return true
660
+ }
661
+
662
+ if(profile.player_level || profile.player_cur_xp){
663
+ return true
664
+ }
665
+ return false
666
+ }
667
+
628
668
  async function getNewCookie(cookie) {
629
669
  let response = (await axios.request({
630
670
  url: 'https://store.steampowered.com/', headers: {
@@ -795,15 +835,7 @@ function SteamClient({
795
835
  getLogOnDetails() {
796
836
  return steamClient?._logOnDetails
797
837
  },
798
- onEvent(name, cb) {
799
- if (!events[name]) {
800
- events[name] = []
801
- }
802
- events[name].push(cb)
803
- },
804
- onEventLoggedOn(cb) {
805
- events.loggedOn.push(cb)
806
- },
838
+ onEvent,
807
839
  setPersona(state, name) {
808
840
  steamClient.setPersona(state, name)
809
841
  },
@@ -826,7 +858,9 @@ function SteamClient({
826
858
  await sleep(2000)
827
859
  steamClient.setPersona(SteamUser.EPersonaState.LookingToPlay)
828
860
  sendHello()
829
- }
861
+ },
862
+ sendHello,
863
+ checkPlayerPrimeStatus,
830
864
  }
831
865
  }
832
866
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "steamutils",
3
- "version": "1.0.44",
3
+ "version": "1.0.45",
4
4
  "dependencies": {
5
5
  "axios": "^1.3.4",
6
6
  "cheerio": "^1.0.0-rc.12",