steamutils 1.2.87 → 1.2.88

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 (3) hide show
  1. package/SteamClient.js +198 -166
  2. package/index.js +2 -2
  3. package/package.json +1 -1
package/SteamClient.js CHANGED
@@ -78,9 +78,9 @@ const appid = 730
78
78
  export let CSGO_VER = 13960
79
79
  const FreeAppList = JSON.parse(fs.readFileSync(path.join(__dirname, 'free_packages.json'))).packages
80
80
 
81
- // SteamUtils.GetCurrentVersion(appid).then(function (ver) {
82
- // CSGO_VER = ver
83
- // })
81
+ SteamUtils.getAppVersion(appid).then(function (ver) {
82
+ CSGO_VER = ver
83
+ })
84
84
 
85
85
  const PersonasCache = []
86
86
 
@@ -105,7 +105,7 @@ function SteamClient({
105
105
  let sendMessageTimestamp = 0
106
106
  let lastTimePartyRegister = 0
107
107
  let lastTimePartySearch = 0
108
- let appsPlayed = []
108
+ const appsPlayed = []
109
109
 
110
110
  const onAnyCallbacks = []
111
111
 
@@ -373,9 +373,9 @@ function SteamClient({
373
373
  prime = false,
374
374
  game_type = 'Competitive',
375
375
  rank = 'Silver Elite',
376
- timeout = 10000,
376
+ timeout = 5000,
377
377
  } = {}) {
378
- return new Promise(resolve => {
378
+ const players = await new Promise(resolve => {
379
379
  steamClient.sendToGC(appid, Protos.csgo.ECsgoGCMsg.k_EMsgGCCStrike15_v2_Party_Search, {}, protoEncode(Protos.csgo.CMsgGCCStrike15_v2_Party_Search, {
380
380
  ver: CSGO_VER,
381
381
  apr: prime ? 1 : 0,
@@ -387,6 +387,17 @@ function SteamClient({
387
387
  lastTimePartySearch = new Date().getTime()
388
388
  pushGCCallback('partySearch', resolve, timeout)
389
389
  })
390
+ if (Array.isArray(players) && players.length) {
391
+ const personas = await getPersonas(players.map(p => p.steamId))
392
+ for (const player of players) {
393
+ const persona = personas.find(p => p.id == player.steamId)
394
+ if (persona) {
395
+ player.player_name = persona.player_name
396
+ player.avatar_hash = persona.avatar_hash
397
+ }
398
+ }
399
+ }
400
+ return players
390
401
  }
391
402
 
392
403
  async function createLobby() {
@@ -568,13 +579,13 @@ function SteamClient({
568
579
  const result = protoDecode(Protos.csgo.CSOPersonaDataPublic, object_data);
569
580
  obj.PersonaDataPublic = result
570
581
  const example = {
571
- "player_level": 4,
572
- "commendation": {
573
- "cmd_friendly": 149,
574
- "cmd_teaching": 108,
575
- "cmd_leader": 115
582
+ player_level: 4,
583
+ commendation: {
584
+ cmd_friendly: 149,
585
+ cmd_teaching: 108,
586
+ cmd_leader: 115
576
587
  },
577
- "elevated_state": true
588
+ elevated_state: true
578
589
  }
579
590
  break
580
591
  }
@@ -585,11 +596,11 @@ function SteamClient({
585
596
  case 7: {
586
597
  const CSOEconGameAccountClient = protoDecode(Protos.csgo.CSOEconGameAccountClient, object_data);
587
598
  const CSOEconGameAccountClientExample = {
588
- "additional_backpack_slots": 0,
589
- "bonus_xp_timestamp_refresh": 1688518800,//Wednesday 1:00:00 AM every week
590
- "bonus_xp_usedflags": 19,
591
- "elevated_state": 5,
592
- "elevated_timestamp": 5
599
+ additional_backpack_slots: 0,
600
+ bonus_xp_timestamp_refresh: 1688518800,//Wednesday 1:00:00 AM every week
601
+ bonus_xp_usedflags: 19,
602
+ elevated_state: 5,
603
+ elevated_timestamp: 5
593
604
  } //1688518800
594
605
  if ((CSOEconGameAccountClient.bonus_xp_usedflags & 16) != 0) { // EXPBonusFlag::PrestigeEarned
595
606
  prime = true
@@ -637,10 +648,10 @@ function SteamClient({
637
648
  case 43: {
638
649
  const result = protoDecode(Protos.csgo.CSOEconDefaultEquippedDefinitionInstanceClient, object_data);
639
650
  const example = {
640
- "account_id": 1080136620,
641
- "item_definition": 61,
642
- "class_id": 3,
643
- "slot_id": 2
651
+ account_id: 1080136620,
652
+ item_definition: 61,
653
+ class_id: 3,
654
+ slot_id: 2
644
655
  }
645
656
  break
646
657
  }
@@ -811,73 +822,68 @@ function SteamClient({
811
822
  const result = protoDecode(Protos.csgo.CMsgGCCStrike15_v2_Party_SearchResults, payload)
812
823
  const entries = _.uniqBy(result.entries, 'id')
813
824
  //{
814
- // "id": 144900402,
815
- // "grp": 0,
816
- // "game_type": 8,
817
- // "apr": 1,
818
- // "ark": 17,
819
- // "loc": 20041,
820
- // "accountid": 0
825
+ // id: 144900402,
826
+ // grp: 0,
827
+ // game_type: 8,
828
+ // apr: 1,
829
+ // ark: 17,
830
+ // loc: 20041,
831
+ // accountid: 0
821
832
  // }
822
833
 
823
- const players = []
824
834
 
825
- const steamIDs = entries
826
- .map(p => SteamID.fromIndividualAccountID(p.id).getSteamID64())
827
- const personas = await getPersonas(steamIDs)
828
835
  //{
829
- // "id": "76561199265943339",
830
- // "rich_presence": [],
831
- // "persona_state": null,
832
- // "game_played_app_id": null,
833
- // "game_server_ip": null,
834
- // "game_server_port": null,
835
- // "persona_state_flags": null,
836
- // "online_session_instances": null,
837
- // "persona_set_by_user": null,
838
- // "player_name": "杀人不见血",
839
- // "query_port": null,
840
- // "steamid_source": null,
841
- // "avatar_hash": "33994e26f1fe7e2093f8c7dee66c1ac91531050d",
842
- // "last_logoff": null,
843
- // "last_logon": null,
844
- // "last_seen_online": null,
845
- // "clan_rank": null,
846
- // "game_name": null,
847
- // "gameid": null,
848
- // "game_data_blob": null,
849
- // "clan_data": null,
850
- // "clan_tag": null,
851
- // "broadcast_id": null,
852
- // "game_lobby_id": null,
853
- // "watching_broadcast_accountid": null,
854
- // "watching_broadcast_appid": null,
855
- // "watching_broadcast_viewers": null,
856
- // "watching_broadcast_title": null,
857
- // "is_community_banned": null,
858
- // "player_name_pending_review": null,
859
- // "avatar_pending_review": null,
860
- // "avatar_url_icon": "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/33/33994e26f1fe7e2093f8c7dee66c1ac91531050d.jpg",
861
- // "avatar_url_medium": "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/33/33994e26f1fe7e2093f8c7dee66c1ac91531050d_medium.jpg",
862
- // "avatar_url_full": "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/33/33994e26f1fe7e2093f8c7dee66c1ac91531050d_full.jpg"
836
+ // id: "76561199265943339",
837
+ // rich_presence: [],
838
+ // persona_state: null,
839
+ // game_played_app_id: null,
840
+ // game_server_ip: null,
841
+ // game_server_port: null,
842
+ // persona_state_flags: null,
843
+ // online_session_instances: null,
844
+ // persona_set_by_user: null,
845
+ // player_name: "杀人不见血",
846
+ // query_port: null,
847
+ // steamid_source: null,
848
+ // avatar_hash: "33994e26f1fe7e2093f8c7dee66c1ac91531050d",
849
+ // last_logoff: null,
850
+ // last_logon: null,
851
+ // last_seen_online: null,
852
+ // clan_rank: null,
853
+ // game_name: null,
854
+ // gameid: null,
855
+ // game_data_blob: null,
856
+ // clan_data: null,
857
+ // clan_tag: null,
858
+ // broadcast_id: null,
859
+ // game_lobby_id: null,
860
+ // watching_broadcast_accountid: null,
861
+ // watching_broadcast_appid: null,
862
+ // watching_broadcast_viewers: null,
863
+ // watching_broadcast_title: null,
864
+ // is_community_banned: null,
865
+ // player_name_pending_review: null,
866
+ // avatar_pending_review: null,
867
+ // avatar_url_icon: "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/33/33994e26f1fe7e2093f8c7dee66c1ac91531050d.jpg",
868
+ // avatar_url_medium: "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/33/33994e26f1fe7e2093f8c7dee66c1ac91531050d_medium.jpg",
869
+ // avatar_url_full: "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/33/33994e26f1fe7e2093f8c7dee66c1ac91531050d_full.jpg"
863
870
  // }
871
+
872
+ const players = []
864
873
  for (const player of entries) {
865
874
  try {
866
875
  const prime = player.apr === 1 ? 'PRIME' : 'NON-PRIME'
867
876
  const loc = LOCS[player.loc] || player.loc
868
877
  const steamId = SteamID.fromIndividualAccountID(player.id).getSteamID64()
869
- const persona = personas.find(p => p.id == steamId)
870
878
  const friendCode = FriendCode.encode(steamId)
871
879
 
872
880
  // if ((LOCS[player.loc] == 'VN' || !LOCS[player.loc])) {
873
881
  players.push({
874
882
  prime,
875
- player_name: persona.player_name,
876
883
  rank: RANKS[player.ark] !== undefined ? RANKS[player.ark] : player.ark,
877
- loc: loc,
884
+ loc,
878
885
  steamId,
879
886
  friendCode,
880
- avatar_hash: persona.avatar_hash,
881
887
  })
882
888
  // }
883
889
  } catch (e) {
@@ -978,66 +984,66 @@ function SteamClient({
978
984
  async user(steamId, data) {
979
985
  callEvent(events.user, {steamId: steamId.getSteamID64(), data})
980
986
  const dataExample = {
981
- "rich_presence": [
987
+ rich_presence: [
982
988
  {
983
- "key": "status",
984
- "value": "Competitive Mirage [ 3 : 6 ]"
989
+ key: "status",
990
+ value: "Competitive Mirage [ 3 : 6 ]"
985
991
  },
986
992
  {
987
- "key": "version",
988
- "value": "13875"
993
+ key: "version",
994
+ value: "13875"
989
995
  },
990
996
  {
991
- "key": "game:state",
992
- "value": "game"
997
+ key: "game:state",
998
+ value: "game"
993
999
  },
994
1000
  {
995
- "key": "steam_display",
996
- "value": "#display_GameKnownMapScore"
1001
+ key: "steam_display",
1002
+ value: "#display_GameKnownMapScore"
997
1003
  },
998
1004
  {
999
- "key": "game:mode",
1000
- "value": "competitive"
1005
+ key: "game:mode",
1006
+ value: "competitive"
1001
1007
  },
1002
1008
  {
1003
- "key": "game:mapgroupname",
1004
- "value": "mg_de_mirage"
1009
+ key: "game:mapgroupname",
1010
+ value: "mg_de_mirage"
1005
1011
  },
1006
1012
  {
1007
- "key": "game:map",
1008
- "value": "de_mirage"
1013
+ key: "game:map",
1014
+ value: "de_mirage"
1009
1015
  },
1010
1016
  {
1011
- "key": "game:server",
1012
- "value": "kv"
1017
+ key: "game:server",
1018
+ value: "kv"
1013
1019
  },
1014
1020
  {
1015
- "key": "watch",
1016
- "value": "1"
1021
+ key: "watch",
1022
+ value: "1"
1017
1023
  },
1018
1024
  {
1019
- "key": "steam_player_group",
1020
- "value": "2134948645"
1025
+ key: "steam_player_group",
1026
+ value: "2134948645"
1021
1027
  },
1022
1028
  {
1023
- "key": "game:score",
1024
- "value": "[ 3 : 6 ]"
1029
+ key: "game:score",
1030
+ value: "[ 3 : 6 ]"
1025
1031
  }
1026
1032
  ],
1027
- "friendid": "76561199405834425",
1028
- "persona_state": 1,
1029
- "game_played_app_id": 730,
1030
- "game_server_ip": null,
1031
- "game_server_port": null,
1032
- "persona_state_flags": 1,
1033
- "online_session_instances": 1,
1034
- "persona_set_by_user": null,
1035
- "player_name": "quỷ súng",
1036
- "query_port": null,
1037
- "steamid_source": "0",
1038
- "avatar_hash": {
1039
- "type": "Buffer",
1040
- "data": [
1033
+ friendid: "76561199405834425",
1034
+ persona_state: 1,
1035
+ game_played_app_id: 730,
1036
+ game_server_ip: null,
1037
+ game_server_port: null,
1038
+ persona_state_flags: 1,
1039
+ online_session_instances: 1,
1040
+ persona_set_by_user: null,
1041
+ player_name: "quỷ súng",
1042
+ query_port: null,
1043
+ steamid_source: "0",
1044
+ avatar_hash: {
1045
+ type: "Buffer",
1046
+ data: [
1041
1047
  23,
1042
1048
  163,
1043
1049
  216,
@@ -1060,27 +1066,27 @@ function SteamClient({
1060
1066
  205
1061
1067
  ]
1062
1068
  },
1063
- "last_logoff": 1683950268,
1064
- "last_logon": 1683950281,
1065
- "last_seen_online": 1683950268,
1066
- "clan_rank": null,
1067
- "game_name": "",
1068
- "gameid": "730",
1069
- "game_data_blob": {
1070
- "type": "Buffer",
1071
- "data": []
1069
+ last_logoff: 1683950268,
1070
+ last_logon: 1683950281,
1071
+ last_seen_online: 1683950268,
1072
+ clan_rank: null,
1073
+ game_name: "",
1074
+ gameid: "730",
1075
+ game_data_blob: {
1076
+ type: "Buffer",
1077
+ data: []
1072
1078
  },
1073
- "clan_data": null,
1074
- "clan_tag": null,
1075
- "broadcast_id": "0",
1076
- "game_lobby_id": "0",
1077
- "watching_broadcast_accountid": null,
1078
- "watching_broadcast_appid": null,
1079
- "watching_broadcast_viewers": null,
1080
- "watching_broadcast_title": null,
1081
- "is_community_banned": null,
1082
- "player_name_pending_review": null,
1083
- "avatar_pending_review": null
1079
+ clan_data: null,
1080
+ clan_tag: null,
1081
+ broadcast_id: "0",
1082
+ game_lobby_id: "0",
1083
+ watching_broadcast_accountid: null,
1084
+ watching_broadcast_appid: null,
1085
+ watching_broadcast_viewers: null,
1086
+ watching_broadcast_title: null,
1087
+ is_community_banned: null,
1088
+ player_name_pending_review: null,
1089
+ avatar_pending_review: null
1084
1090
  }
1085
1091
  },
1086
1092
  async playingState(playing_blocked, playing_app) {
@@ -1150,21 +1156,21 @@ function SteamClient({
1150
1156
  data.message_no_bbcode = data.message_no_bbcode?.replaceAll(`ː`, `:`)
1151
1157
  data.message = data.message?.replaceAll(`ː`, `:`)
1152
1158
  const example = {
1153
- "steamid_friend": {
1154
- "universe": 1,
1155
- "type": 1,
1156
- "instance": 1,
1157
- "accountid": 1080136620
1159
+ steamid_friend: {
1160
+ universe: 1,
1161
+ type: 1,
1162
+ instance: 1,
1163
+ accountid: 1080136620
1158
1164
  },
1159
- "chat_entry_type": 1,
1160
- "from_limited_account": false,
1161
- "message": "xxx",
1162
- "ordinal": 0,
1163
- "local_echo": false,
1164
- "message_no_bbcode": "xxx",
1165
- "low_priority": false,
1166
- "server_timestamp": "2023-05-14T09:26:25.000Z",
1167
- "message_bbcode_parsed": [
1165
+ chat_entry_type: 1,
1166
+ from_limited_account: false,
1167
+ message: "xxx",
1168
+ ordinal: 0,
1169
+ local_echo: false,
1170
+ message_no_bbcode: "xxx",
1171
+ low_priority: false,
1172
+ server_timestamp: "2023-05-14T09:26:25.000Z",
1173
+ message_bbcode_parsed: [
1168
1174
  "xxx"
1169
1175
  ]
1170
1176
  }
@@ -1446,10 +1452,10 @@ function SteamClient({
1446
1452
  }
1447
1453
 
1448
1454
  async function autoRequestFreeLicense(shouldLog = false, max = 10) {
1449
- const mCookies = await getCookiesWait()
1450
- if (!mCookies) return
1451
- const steamUtils = new SteamUtils(mCookies)
1452
- const recommendedApps = _.shuffle(FreeAppList)
1455
+ // const mCookies = await getCookiesWait()
1456
+ // if (!mCookies) return
1457
+ const freeAppList = Array.isArray(steamClient.licenses) ? FreeAppList.filter(appId => steamClient.licenses.every(({package_id}) => package_id !== appId)) : FreeAppList;
1458
+ const recommendedApps = _.shuffle(freeAppList)
1453
1459
  if (max) {
1454
1460
  recommendedApps.length = Math.min(recommendedApps.length, max)
1455
1461
  }
@@ -1477,12 +1483,12 @@ function SteamClient({
1477
1483
  // }
1478
1484
  // }
1479
1485
 
1480
- if (shouldLog) {
1481
- await sleep(20000)
1482
- const ownedAppsCount2 = (await steamUtils.getDynamicStoreUserData())?.rgOwnedApps?.length || 0
1483
- const increaseNumber = ownedAppsCount2 - ownedAppsCount;
1484
- log(`OwnedApps length ${ownedAppsCount2}, increase ${increaseNumber}`)
1485
- }
1486
+ // if (shouldLog) {
1487
+ // await sleep(20000)
1488
+ // const ownedAppsCount2 = (await steamUtils.getDynamicStoreUserData())?.rgOwnedApps?.length || 0
1489
+ // const increaseNumber = ownedAppsCount2 - ownedAppsCount;
1490
+ // log(`OwnedApps length ${ownedAppsCount2}, increase ${increaseNumber}`)
1491
+ // }
1486
1492
  }
1487
1493
 
1488
1494
  async function playCSGO() {
@@ -1581,7 +1587,10 @@ function SteamClient({
1581
1587
  if (!Array.isArray(apps)) {
1582
1588
  apps = [apps]
1583
1589
  }
1584
- appsPlayed = apps
1590
+
1591
+ appsPlayed.length = 0
1592
+ appsPlayed.push(...apps)
1593
+
1585
1594
  if (apps.length) {
1586
1595
  state = 'InGame'
1587
1596
  } else {
@@ -1610,28 +1619,28 @@ function SteamClient({
1610
1619
  /*
1611
1620
  users
1612
1621
  * {
1613
- "rich_presence": [],
1614
- "player_name": "Kei #SkinsMonkey",
1615
- "avatar_hash": [123,4543],
1616
- "last_logoff": "2023-05-20T05:00:42.000Z",
1617
- "last_logon": "2023-05-20T05:02:16.000Z",
1618
- "last_seen_online": "2023-05-20T05:00:42.000Z",
1619
- "avatar_url_icon": "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/3e/3e9da0b107ac2ec384759544368a8a977359537a.jpg",
1620
- "avatar_url_medium": "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/3e/3e9da0b107ac2ec384759544368a8a977359537a_medium.jpg",
1621
- "avatar_url_full": "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/3e/3e9da0b107ac2ec384759544368a8a977359537a_full.jpg"
1622
+ rich_presence: [],
1623
+ player_name: "Kei #SkinsMonkey",
1624
+ avatar_hash: [123,4543],
1625
+ last_logoff: "2023-05-20T05:00:42.000Z",
1626
+ last_logon: "2023-05-20T05:02:16.000Z",
1627
+ last_seen_online: "2023-05-20T05:00:42.000Z",
1628
+ avatar_url_icon: "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/3e/3e9da0b107ac2ec384759544368a8a977359537a.jpg",
1629
+ avatar_url_medium: "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/3e/3e9da0b107ac2ec384759544368a8a977359537a_medium.jpg",
1630
+ avatar_url_full: "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/3e/3e9da0b107ac2ec384759544368a8a977359537a_full.jpg"
1622
1631
  }
1623
1632
  *
1624
1633
 
1625
1634
  myFriends
1626
1635
  {
1627
- "76561198365087582": 3,
1628
- "76561199490395123": 3
1636
+ 76561198365087582: 3,
1637
+ 76561199490395123: 3
1629
1638
  }
1630
1639
  * */
1631
1640
  /*steamClient._send({
1632
- "msg": 151,
1633
- "proto": {
1634
- "target_job_name": methodName
1641
+ msg: 151,
1642
+ proto: {
1643
+ target_job_name: methodName
1635
1644
  }
1636
1645
  }, Buffer.alloc(0), function (body, hdr) {
1637
1646
  const result = hdr.proto.eresult
@@ -1764,6 +1773,29 @@ function SteamClient({
1764
1773
  },
1765
1774
  getLastTimePartySearch(){
1766
1775
  return lastTimePartySearch
1776
+ },
1777
+ getLicenses(){
1778
+ return steamClient.licenses
1779
+ const exampleLicenses = [{
1780
+ package_id: 303386,
1781
+ time_created: 1680491335,
1782
+ time_next_process: 0,
1783
+ minute_limit: 0,
1784
+ minutes_used: 0,
1785
+ payment_method: 1024,
1786
+ flags: 512,
1787
+ purchase_country_code: "VN",
1788
+ license_type: 1,
1789
+ territory_code: 0,
1790
+ change_number: 20615891,
1791
+ owner_id: 1530068060,
1792
+ initial_period: 0,
1793
+ initial_time_unit: 0,
1794
+ renewal_period: 0,
1795
+ renewal_time_unit: 0,
1796
+ access_token: "8049398090486337961",
1797
+ master_package_id: null
1798
+ }]
1767
1799
  }
1768
1800
  }
1769
1801
  }
package/index.js CHANGED
@@ -1319,8 +1319,8 @@ class SteamUser {
1319
1319
  }
1320
1320
  }
1321
1321
 
1322
- static async GetCurrentVersion(appID) {
1323
- for (let i = 0; i < 10; i++) {
1322
+ static async getAppVersion(appID) {
1323
+ for (let i = 0; i < 3; i++) {
1324
1324
  try {
1325
1325
  return (await request(
1326
1326
  `https://api.steampowered.com/ISteamApps/UpToDateCheck/v1/?format=json&appid=${appID}&version=0`)).data.response.required_version
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "steamutils",
3
- "version": "1.2.87",
3
+ "version": "1.2.88",
4
4
  "main": "index.js",
5
5
  "dependencies": {
6
6
  "axios": "^1.5.1",