steamutils 1.3.70 → 1.3.72

Sign up to get free protection for your applications and to get access to all the features.
Files changed (240) hide show
  1. package/.idea/codeStyles/Project.xml +58 -0
  2. package/.idea/codeStyles/codeStyleConfig.xml +5 -0
  3. package/.idea/deployment.xml +1 -8
  4. package/.idea/steamutils.iml +1 -1
  5. package/.idea/vcs.xml +1 -1
  6. package/.prettierrc.json +3 -3
  7. package/SteamClient.js +2416 -2417
  8. package/bufferHelpers.js +115 -115
  9. package/cheerio.js +103 -103
  10. package/const.js +336 -336
  11. package/create_remote_file.js +66 -66
  12. package/free_packages.json +10048 -10048
  13. package/index.js +311 -2
  14. package/package.json +1 -1
  15. package/protos/csgo/base_gcmessages.proto +553 -553
  16. package/protos/csgo/base_gcmessages_csgo.proto +547 -547
  17. package/protos/csgo/c_peer2peer_netmessages.proto +55 -55
  18. package/protos/csgo/clientmessages.proto +48 -48
  19. package/protos/csgo/connectionless_netmessages.proto +17 -17
  20. package/protos/csgo/cs_gameevents.proto +35 -35
  21. package/protos/csgo/cs_usercmd.proto +34 -34
  22. package/protos/csgo/cstrike15_gcmessages.proto +1431 -1431
  23. package/protos/csgo/cstrike15_usermessages.proto +592 -592
  24. package/protos/csgo/demo.proto +165 -165
  25. package/protos/csgo/econ_gcmessages.proto +219 -219
  26. package/protos/csgo/engine_gcmessages.proto +14 -14
  27. package/protos/csgo/enums_clientserver.proto +1529 -1529
  28. package/protos/csgo/fatdemo.proto +125 -125
  29. package/protos/csgo/gameevents.proto +120 -120
  30. package/protos/csgo/gcsdk_gcmessages.proto +323 -323
  31. package/protos/csgo/gcsystemmsgs.proto +243 -243
  32. package/protos/csgo/netmessages.proto +618 -618
  33. package/protos/csgo/network_connection.proto +126 -126
  34. package/protos/csgo/networkbasetypes.proto +246 -246
  35. package/protos/csgo/networksystem_protomessages.proto +17 -17
  36. package/protos/csgo/steamdatagram_messages_auth.proto +65 -65
  37. package/protos/csgo/steamdatagram_messages_sdr.proto +534 -534
  38. package/protos/csgo/steammessages.proto +620 -620
  39. package/protos/csgo/steammessages_base.proto +301 -301
  40. package/protos/csgo/steammessages_cloud.steamworkssdk.proto +68 -68
  41. package/protos/csgo/steammessages_gamenetworkingui.proto +61 -61
  42. package/protos/csgo/steammessages_helprequest.steamworkssdk.proto +22 -22
  43. package/protos/csgo/steammessages_oauth.steamworkssdk.proto +18 -18
  44. package/protos/csgo/steammessages_player.steamworkssdk.proto +254 -254
  45. package/protos/csgo/steammessages_publishedfile.steamworkssdk.proto +233 -233
  46. package/protos/csgo/steammessages_unified_base.steamworkssdk.proto +30 -30
  47. package/protos/csgo/steamnetworkingsockets_messages.proto +205 -205
  48. package/protos/csgo/steamnetworkingsockets_messages_certs.proto +39 -39
  49. package/protos/csgo/steamnetworkingsockets_messages_udp.proto +75 -75
  50. package/protos/csgo/te.proto +259 -259
  51. package/protos/csgo/uifontfile_format.proto +13 -13
  52. package/protos/csgo/usercmd.proto +39 -39
  53. package/protos/csgo/usermessages.proto +752 -752
  54. package/protos/csgo/valveextensions.proto +17 -17
  55. package/protos/google/protobuf/descriptor.proto +281 -281
  56. package/protos/steam/clientmetrics.proto +45 -45
  57. package/protos/steam/content_manifest.proto +62 -62
  58. package/protos/steam/contenthubs.proto +41 -41
  59. package/protos/steam/encrypted_app_ticket.proto +10 -10
  60. package/protos/steam/enums.proto +501 -501
  61. package/protos/steam/enums_clientserver.proto +1508 -1508
  62. package/protos/steam/enums_productinfo.proto +14 -14
  63. package/protos/steam/htmlmessages.proto +1039 -1039
  64. package/protos/steam/offline_ticket.proto +8 -8
  65. package/protos/steam/steamdatagram_messages_auth.proto +65 -65
  66. package/protos/steam/steamdatagram_messages_sdr.proto +533 -533
  67. package/protos/steam/steammessages_accounthardware.steamclient.proto +167 -167
  68. package/protos/steam/steammessages_appoverview.proto +204 -204
  69. package/protos/steam/steammessages_auth.steamclient.proto +375 -375
  70. package/protos/steam/steammessages_base.proto +335 -335
  71. package/protos/steam/steammessages_broadcast.steamclient.proto +618 -618
  72. package/protos/steam/steammessages_chat.steamclient.proto +1070 -1070
  73. package/protos/steam/steammessages_client_objects.proto +649 -649
  74. package/protos/steam/steammessages_clientlanp2p.proto +43 -43
  75. package/protos/steam/steammessages_clientmetrics.steamclient.proto +192 -192
  76. package/protos/steam/steammessages_clientnotificationtypes.proto +250 -250
  77. package/protos/steam/steammessages_clientserver.proto +392 -392
  78. package/protos/steam/steammessages_clientserver_2.proto +771 -771
  79. package/protos/steam/steammessages_clientserver_appinfo.proto +131 -131
  80. package/protos/steam/steammessages_clientserver_friends.proto +260 -260
  81. package/protos/steam/steammessages_clientserver_gameservers.proto +159 -159
  82. package/protos/steam/steammessages_clientserver_lbs.proto +70 -70
  83. package/protos/steam/steammessages_clientserver_login.proto +167 -167
  84. package/protos/steam/steammessages_clientserver_mms.proto +233 -233
  85. package/protos/steam/steammessages_clientserver_ucm.proto +207 -207
  86. package/protos/steam/steammessages_clientserver_uds.proto +125 -125
  87. package/protos/steam/steammessages_clientserver_ufs.proto +45 -45
  88. package/protos/steam/steammessages_clientserver_userstats.proto +80 -80
  89. package/protos/steam/steammessages_clientsettings.proto +208 -208
  90. package/protos/steam/steammessages_cloud.steamclient.proto +422 -422
  91. package/protos/steam/steammessages_contentsystem.steamclient.proto +123 -123
  92. package/protos/steam/steammessages_credentials.steamclient.proto +96 -96
  93. package/protos/steam/steammessages_datapublisher.steamclient.proto +102 -102
  94. package/protos/steam/steammessages_depotbuilder.steamclient.proto +99 -99
  95. package/protos/steam/steammessages_deviceauth.steamclient.proto +169 -169
  96. package/protos/steam/steammessages_econ.steamclient.proto +137 -137
  97. package/protos/steam/steammessages_familygroups.steamclient.proto +441 -441
  98. package/protos/steam/steammessages_friendmessages.steamclient.proto +141 -141
  99. package/protos/steam/steammessages_gamenetworking.steamclient.proto +25 -25
  100. package/protos/steam/steammessages_gamenetworkingui.proto +61 -61
  101. package/protos/steam/steammessages_gamenotifications.steamclient.proto +131 -131
  102. package/protos/steam/steammessages_gameservers.steamclient.proto +136 -136
  103. package/protos/steam/steammessages_hiddevices.proto +157 -157
  104. package/protos/steam/steammessages_inventory.steamclient.proto +172 -172
  105. package/protos/steam/steammessages_linkfilter.steamclient.proto +39 -39
  106. package/protos/steam/steammessages_lobbymatchmaking.steamclient.proto +29 -29
  107. package/protos/steam/steammessages_market.steamclient.proto +22 -22
  108. package/protos/steam/steammessages_marketingmessages.steamclient.proto +273 -273
  109. package/protos/steam/steammessages_offline.steamclient.proto +33 -33
  110. package/protos/steam/steammessages_parental.steamclient.proto +262 -262
  111. package/protos/steam/steammessages_parties.steamclient.proto +75 -75
  112. package/protos/steam/steammessages_partnerapps.steamclient.proto +106 -106
  113. package/protos/steam/steammessages_player.steamclient.proto +915 -915
  114. package/protos/steam/steammessages_publishedfile.steamclient.proto +737 -737
  115. package/protos/steam/steammessages_qms.steamclient.proto +111 -111
  116. package/protos/steam/steammessages_remoteclient.proto +100 -100
  117. package/protos/steam/steammessages_remoteclient_discovery.proto +244 -244
  118. package/protos/steam/steammessages_remoteclient_service.steamclient.proto +31 -31
  119. package/protos/steam/steammessages_remoteclient_service_messages.proto +217 -217
  120. package/protos/steam/steammessages_remoteplay.proto +975 -975
  121. package/protos/steam/steammessages_secrets.steamclient.proto +35 -35
  122. package/protos/steam/steammessages_shader.steamclient.proto +89 -89
  123. package/protos/steam/steammessages_site_license.steamclient.proto +103 -103
  124. package/protos/steam/steammessages_sitelicenseclient.proto +38 -38
  125. package/protos/steam/steammessages_siteserverui.proto +130 -130
  126. package/protos/steam/steammessages_steamtv.steamclient.proto +533 -533
  127. package/protos/steam/steammessages_store.steamclient.proto +404 -404
  128. package/protos/steam/steammessages_storebrowse.steamclient.proto +457 -457
  129. package/protos/steam/steammessages_timedtrial.steamclient.proto +40 -40
  130. package/protos/steam/steammessages_twofactor.steamclient.proto +157 -157
  131. package/protos/steam/steammessages_unified_base.steamclient.proto +45 -45
  132. package/protos/steam/steammessages_unified_test.steamclient.proto +51 -51
  133. package/protos/steam/steammessages_useraccount.steamclient.proto +211 -211
  134. package/protos/steam/steammessages_vac.steamclient.proto +37 -37
  135. package/protos/steam/steammessages_video.steamclient.proto +68 -68
  136. package/protos/steam/steammessages_virtualcontroller.proto +138 -138
  137. package/protos/steam/steammessages_workshop.steamclient.proto +19 -19
  138. package/protos/steam/steamnetworkingsockets_messages.proto +205 -205
  139. package/protos/steam/steamnetworkingsockets_messages_certs.proto +39 -39
  140. package/protos/steam/steamnetworkingsockets_messages_udp.proto +75 -75
  141. package/protos/steam/webuimessages_achievements.proto +29 -29
  142. package/protos/steam/webuimessages_base.proto +24 -24
  143. package/protos/steam/webuimessages_gamenotes.proto +21 -21
  144. package/protos/steam/webuimessages_gamescope.proto +57 -57
  145. package/protos/steam/webuimessages_steamengine.proto +41 -41
  146. package/protos/steam/webuimessages_steamos.proto +114 -114
  147. package/protos/steam/webuimessages_storagedevicemanager.proto +110 -110
  148. package/protos/steam/webuimessages_systemmanager.proto +17 -17
  149. package/protos/steam/webuimessages_transport.proto +22 -22
  150. package/protos/steam/webuimessages_transportvalidation.proto +111 -111
  151. package/protos/webui/common.proto +4024 -0
  152. package/protos/webui/common_base.proto +27 -0
  153. package/protos/webui/service_accountcart.proto +153 -0
  154. package/protos/webui/service_accountlinking.proto +27 -0
  155. package/protos/webui/service_accountprivacy.proto +42 -0
  156. package/protos/webui/service_accountprivateapps.proto +34 -0
  157. package/protos/webui/service_auction.proto +97 -0
  158. package/protos/webui/service_authentication.proto +222 -0
  159. package/protos/webui/service_authenticationsupport.proto +74 -0
  160. package/protos/webui/service_broadcast.proto +562 -0
  161. package/protos/webui/service_chat.proto +11 -0
  162. package/protos/webui/service_chatroom.proto +810 -0
  163. package/protos/webui/service_chatusability.proto +107 -0
  164. package/protos/webui/service_checkout.proto +84 -0
  165. package/protos/webui/service_clan.proto +41 -0
  166. package/protos/webui/service_clanchatrooms.proto +25 -0
  167. package/protos/webui/service_clanfaqs.proto +202 -0
  168. package/protos/webui/service_clientcomm.proto +151 -0
  169. package/protos/webui/service_clientmetrics.proto +22 -0
  170. package/protos/webui/service_cloud.proto +222 -0
  171. package/protos/webui/service_cloudconfigstore.proto +51 -0
  172. package/protos/webui/service_cloudgaming.proto +30 -0
  173. package/protos/webui/service_community.proto +365 -0
  174. package/protos/webui/service_dailydeal.proto +89 -0
  175. package/protos/webui/service_econ.proto +134 -0
  176. package/protos/webui/service_embedded.proto +24 -0
  177. package/protos/webui/service_experimentservice.proto +6 -0
  178. package/protos/webui/service_familygroups.proto +355 -0
  179. package/protos/webui/service_fovasvideo.proto +15 -0
  180. package/protos/webui/service_friendmessages.proto +133 -0
  181. package/protos/webui/service_friendslist.proto +70 -0
  182. package/protos/webui/service_gamenotes.proto +15 -0
  183. package/protos/webui/service_gamerecording.proto +265 -0
  184. package/protos/webui/service_gamerecordingclip.proto +85 -0
  185. package/protos/webui/service_gamerecordingdebug.proto +52 -0
  186. package/protos/webui/service_helprequestlogs.proto +16 -0
  187. package/protos/webui/service_loyaltyrewards.proto +252 -0
  188. package/protos/webui/service_marketingmessages.proto +215 -0
  189. package/protos/webui/service_mobileapp.proto +18 -0
  190. package/protos/webui/service_mobileauth.proto +24 -0
  191. package/protos/webui/service_mobiledevice.proto +26 -0
  192. package/protos/webui/service_mobileperaccount.proto +31 -0
  193. package/protos/webui/service_news.proto +110 -0
  194. package/protos/webui/service_parental.proto +258 -0
  195. package/protos/webui/service_partnermembershipinvite.proto +34 -0
  196. package/protos/webui/service_partnerstorebrowse.proto +28 -0
  197. package/protos/webui/service_phone.proto +51 -0
  198. package/protos/webui/service_physicalgoods.proto +15 -0
  199. package/protos/webui/service_player.proto +918 -0
  200. package/protos/webui/service_promotioneventinvites.proto +109 -0
  201. package/protos/webui/service_promotionplanning.proto +186 -0
  202. package/protos/webui/service_promotionstats.proto +23 -0
  203. package/protos/webui/service_publishedfile.proto +714 -0
  204. package/protos/webui/service_publishing.proto +200 -0
  205. package/protos/webui/service_quest.proto +127 -0
  206. package/protos/webui/service_salefeature.proto +373 -0
  207. package/protos/webui/service_saleitemrewards.proto +54 -0
  208. package/protos/webui/service_shoppingcart.proto +152 -0
  209. package/protos/webui/service_steamawards.proto +76 -0
  210. package/protos/webui/service_steamcharts.proto +75 -0
  211. package/protos/webui/service_steamengine.proto +36 -0
  212. package/protos/webui/service_steamlearn.proto +876 -0
  213. package/protos/webui/service_steamnotification.proto +73 -0
  214. package/protos/webui/service_steamtv.proto +495 -0
  215. package/protos/webui/service_steamvrvoicechat.proto +67 -0
  216. package/protos/webui/service_steamvrwebrtc.proto +48 -0
  217. package/protos/webui/service_storagedevicemanager.proto +104 -0
  218. package/protos/webui/service_store.proto +359 -0
  219. package/protos/webui/service_storeappsimilarity.proto +76 -0
  220. package/protos/webui/service_storebrowse.proto +103 -0
  221. package/protos/webui/service_storemarketing.proto +44 -0
  222. package/protos/webui/service_storequery.proto +103 -0
  223. package/protos/webui/service_storesales.proto +87 -0
  224. package/protos/webui/service_storetopsellers.proto +44 -0
  225. package/protos/webui/service_systemmanager.proto +11 -0
  226. package/protos/webui/service_test_transporterror.proto +6 -0
  227. package/protos/webui/service_transportauth.proto +17 -0
  228. package/protos/webui/service_transportvalidation.proto +69 -0
  229. package/protos/webui/service_twofactor.proto +170 -0
  230. package/protos/webui/service_useraccount.proto +142 -0
  231. package/protos/webui/service_usergameactivity.proto +34 -0
  232. package/protos/webui/service_usergamenotes.proto +70 -0
  233. package/protos/webui/service_usernews.proto +68 -0
  234. package/protos/webui/service_userreviews.proto +97 -0
  235. package/protos/webui/service_video.proto +50 -0
  236. package/protos/webui/service_videoclip.proto +62 -0
  237. package/protos/webui/service_voicechat.proto +139 -0
  238. package/protos/webui/service_webrtc.proto +52 -0
  239. package/remote.js +5766 -5766
  240. package/test_steamclient.js +9 -0
package/SteamClient.js CHANGED
@@ -1,2417 +1,2416 @@
1
- import NodeSteamUser from "steam-user";
2
- import _ from "lodash";
3
- import fs from "fs";
4
- import { protoDecode, protoEncode } from "./helpers/util.js";
5
- import SteamID from "steamid";
6
- import FriendCode from "csgo-friendcode";
7
- import axios from "axios";
8
- import helpers, { loadProfos } from "./helpers/protos.js";
9
- import { fileURLToPath } from "url";
10
- import path from "path";
11
- import SteamUser from "./index.js";
12
- import { v4 as uuidv4 } from "uuid";
13
- import EFriendRelationship from "steam-user/enums/EFriendRelationship.js";
14
- import SteamCommunity from "steamcommunity";
15
- import moment from "moment-timezone";
16
- import { encode, encodeUids } from "./bufferHelpers.js";
17
-
18
- const __filename = fileURLToPath(import.meta.url);
19
- const __dirname = path.dirname(__filename);
20
-
21
- const Protos = helpers([
22
- {
23
- name: "csgo",
24
- protos: loadProfos(`${__dirname}/protos/`),
25
- },
26
- ]);
27
-
28
- export const RANKS = {
29
- 0: "Unranked",
30
- 1: "Silver I",
31
- 2: "Silver II",
32
- 3: "Silver III",
33
- 4: "Silver IV",
34
- 5: "Silver Elite",
35
- 6: "Silver Elite Master",
36
- 7: "Gold Nova I",
37
- 8: "Gold Nova II",
38
- 9: "Gold Nova III",
39
- 10: "Gold Nova Master",
40
- 11: "Master Guardian I",
41
- 12: "Master Guardian II",
42
- 13: "Master Guardian Elite",
43
- 14: "Distinguished Master Guardian",
44
- 15: "Legendary Eagle",
45
- 16: "Legendary Eagle Master",
46
- 17: "Supreme Master First Class",
47
- 18: "The Global Elite",
48
- };
49
- export const LOCS = {
50
- 20054: "VN",
51
- 23115: "KZ",
52
- 20041: "IN",
53
- 20035: "CN",
54
- 17474: "BD",
55
- 17481: "ID",
56
- 22861: "MY",
57
- 18516: "TH",
58
- 22356: "TW",
59
- 21067: "KR",
60
- 19272: "HK",
61
- 18512: "PH",
62
- 21842: "RU",
63
- 16716: "LA",
64
- 20558: "NP",
65
- 18259: "SG",
66
- 19789: "MM",
67
- 20045: "MN",
68
- 18251: "KG",
69
- 18507: "KH",
70
- 22605: "MX",
71
- 19280: "PK",
72
- 20301: "HK/MO", //hongkong or macau
73
- 21333: "Unknown",
74
- 21825: "AU",
75
- 20034: "Unkown",
76
- };
77
-
78
- const AppID = 730;
79
- export let CSGO_VER = 13960;
80
- export const FreeAppList = JSON.parse(fs.readFileSync(path.join(__dirname, "free_packages.json"))).packages;
81
-
82
- SteamUser.getAppVersion(AppID).then(function (ver) {
83
- CSGO_VER = ver;
84
- });
85
-
86
- const PersonasCache = [];
87
- let isSendingFriendMessages = false;
88
-
89
- function SteamClient({ username, password, cookie, clientJsToken, isAutoRequestFreeLicense = true, isFakeGameScore = true, isPartyRegister = true, isAutoPlay = false, isInvisible = false, autoAcceptTradeRequest = false, autoReconnect = true, MAX_GAME_PLAY = 10, games = null }) {
90
- const steamClient = new NodeSteamUser();
91
- let prime = null;
92
- let state = "Offline"; //InGame, Online, Invisible
93
- let isLogOff = false;
94
- let playingBlocked = null;
95
- const richPresence = {};
96
- let sendMessageTimestamp = 0;
97
- let lastTimePartyRegister = 0;
98
- let lastTimePartySearch = 0;
99
- const ownedApps = [];
100
- let logOffEvent = null;
101
-
102
- const currentLobby = {
103
- lobbyID: null,
104
- timestamp: 0,
105
- };
106
-
107
- const onAnyCallbacks = [];
108
-
109
- const events = {
110
- user: [],
111
- loggedOn: [],
112
- csgoOnline: [],
113
- csgoClientHello: [],
114
- webSession: [],
115
- friendMessage: [],
116
- friendTyping: [],
117
- disconnected: [],
118
- error: [],
119
- playersProfile: [],
120
- fatalError: [],
121
- partyInvite: [],
122
- friendRelationship: [],
123
- tradeOffers: [],
124
- offlineMessages: [],
125
- friendsList: [],
126
- gifts: [],
127
- playingState: [],
128
- emailInfo: [],
129
- accountLimitations: [],
130
- };
131
-
132
- const gcCallback = {};
133
-
134
- function pushGCCallback(name, cb, timeout) {
135
- if (!gcCallback[name]) {
136
- gcCallback[name] = {};
137
- }
138
- let t = null;
139
- let id = uuidv4();
140
-
141
- function callback(...arg) {
142
- if (t) {
143
- clearTimeout(t);
144
- }
145
- delete gcCallback[name][id];
146
- cb?.apply(null, arg);
147
- }
148
-
149
- if (timeout) {
150
- t = setTimeout(callback, timeout);
151
- }
152
- gcCallback[name][id] = callback;
153
- }
154
-
155
- function callGCCallback(name, ...arg) {
156
- if (gcCallback[name]) {
157
- for (const id in gcCallback[name]) {
158
- gcCallback[name][id]?.(...arg);
159
- }
160
- }
161
- }
162
-
163
- function callEvent(_events, data) {
164
- const eventName = Object.keys(events).find((eventName) => events[eventName] === _events);
165
- eventName && onAnyCallbacks.forEach((cb) => cb?.({ eventName, data }));
166
-
167
- _events?.forEach?.((e) => {
168
- e.callback?.(data);
169
- e.timeout && clearTimeout(e.timeout);
170
- delete e.timeout;
171
- if (e.once) {
172
- delete e.callback;
173
- }
174
- });
175
- _.remove(_events, (e) => !e || e?.once);
176
- }
177
-
178
- function onEvent(name, callback, once, timeout) {
179
- if (!events[name]) {
180
- events[name] = [];
181
- }
182
- const t = timeout ? setTimeout(callback, timeout) : null;
183
- events[name].push({
184
- once,
185
- callback,
186
- timeout: t,
187
- });
188
- }
189
-
190
- function offEvent(name) {
191
- if (Array.isArray(events[name])) {
192
- for (const eventElement of events[name]) {
193
- if (eventElement.timeout) {
194
- clearTimeout(eventElement.timeout);
195
- }
196
- }
197
- }
198
-
199
- delete events[name];
200
- }
201
-
202
- function onAnyEvent(callback) {
203
- onAnyCallbacks.push(callback);
204
- }
205
-
206
- function offAllEvent() {
207
- for (const name in events) {
208
- for (const event of events[name]) {
209
- if (event.timeout) {
210
- try {
211
- clearTimeout(event.timeout);
212
- } catch (e) {}
213
- delete event.timeout;
214
- }
215
- }
216
- delete events[name];
217
- }
218
- onAnyCallbacks.length = 0;
219
- }
220
-
221
- const intervals = {};
222
- const intervalRandoms = {};
223
-
224
- function doSetInterval(cb, timeout, key) {
225
- const isRandom = Array.isArray(timeout);
226
- if (!key) {
227
- key = uuidv4();
228
- }
229
- if (isRandom) {
230
- if (intervalRandoms[key] !== undefined) {
231
- try {
232
- clearTimeout(intervalRandoms[key]);
233
- } catch (e) {}
234
- }
235
- intervalRandoms[key] = setTimeout(
236
- function () {
237
- doSetInterval(cb, timeout, key);
238
- if (state !== "Offline") {
239
- cb();
240
- }
241
- },
242
- _.random(timeout[0], timeout[1]),
243
- );
244
- } else {
245
- if (intervals[key] !== undefined) {
246
- try {
247
- clearInterval(intervals[key]);
248
- } catch (e) {}
249
- }
250
-
251
- intervals[key] = setInterval(function () {
252
- if (state !== "Offline") {
253
- cb();
254
- }
255
- }, timeout);
256
- }
257
-
258
- return key;
259
- }
260
-
261
- function doClearIntervals() {
262
- for (const key in intervals) {
263
- clearInterval(intervals[key]);
264
- delete intervals[key];
265
- }
266
- for (const key in intervalRandoms) {
267
- clearTimeout(intervalRandoms[key]);
268
- delete intervalRandoms[key];
269
- }
270
- }
271
-
272
- function doClearInterval(key) {
273
- try {
274
- clearInterval(intervals[key]);
275
- } catch (e) {}
276
- delete intervals[key];
277
-
278
- try {
279
- clearTimeout(intervalRandoms[key]);
280
- } catch (e) {}
281
- delete intervalRandoms[key];
282
- }
283
-
284
- function getAccountInfoName() {
285
- return [steamClient?.accountInfo?.name, steamClient?._logOnDetails?.account_name].filter(Boolean).join(" - ");
286
- }
287
-
288
- function getPersonaName() {
289
- return steamClient?.accountInfo?.name;
290
- }
291
-
292
- function log(...msg) {
293
- const now = moment().tz("Asia/Ho_Chi_Minh").format("DD/MM/YYYY HH:mm:ss");
294
- console.log(`[${now}] [${getAccountInfoName()}]`, ...msg);
295
- }
296
-
297
- async function getPersonas(steamIDs) {
298
- steamIDs = steamIDs.map((steamId) => (steamId instanceof SteamID ? steamId.getSteamID64() : steamId));
299
- const notCachesteamIDs = steamIDs.filter((id) => !PersonasCache.some((p) => p.id == id));
300
- const cachedPersonas = PersonasCache.filter((p) => steamIDs.includes(p.id));
301
-
302
- if (notCachesteamIDs.length) {
303
- let personas = null;
304
- try {
305
- personas = (await steamClient.getPersonas(notCachesteamIDs))?.personas;
306
- } catch (e) {}
307
- if (!personas || !Object.keys(personas).length) {
308
- try {
309
- personas = (await steamClient.getPersonas(notCachesteamIDs))?.personas;
310
- } catch (e) {}
311
- }
312
- if (!personas || !Object.keys(personas).length) {
313
- try {
314
- personas = (await steamClient.getPersonas(notCachesteamIDs))?.personas;
315
- } catch (e) {}
316
- }
317
- if (personas && Object.keys(personas).length) {
318
- for (let sid64 in personas) {
319
- personas[sid64].id = sid64;
320
- personas[sid64].avatar_hash = Buffer.from(personas[sid64].avatar_hash).toString("hex");
321
- PersonasCache.push(personas[sid64]);
322
- cachedPersonas.push(personas[sid64]);
323
- }
324
- }
325
- }
326
-
327
- while (PersonasCache.length > 500) {
328
- PersonasCache.shift();
329
- }
330
- return cachedPersonas;
331
- }
332
-
333
- function sleep(ms) {
334
- return new Promise((resolve) => {
335
- setTimeout(resolve, ms);
336
- });
337
- }
338
-
339
- function getCookies() {
340
- return cookie || steamClient?.webSession?.cookies?.join?.(";");
341
- }
342
-
343
- async function getCookiesWait() {
344
- return (
345
- getCookies() ||
346
- new Promise((resolve) => {
347
- onEvent(
348
- "webSession",
349
- function (webSession) {
350
- resolve(webSession?.cookies);
351
- },
352
- true,
353
- 30000,
354
- );
355
- })
356
- );
357
- }
358
-
359
- async function gamePlay() {
360
- if ((Array.isArray(games) && games.length) || (games && (typeof games === "number" || typeof games === "string"))) {
361
- return gamesPlayed(games);
362
- }
363
-
364
- let ownedApps = [];
365
- for (let i = 0; i < 5; i++) {
366
- ownedApps = await getUserOwnedApps();
367
- if (ownedApps?.length) {
368
- break;
369
- }
370
- }
371
- if (!ownedApps?.length) {
372
- gamesPlayed(730);
373
- } else {
374
- ownedApps = ownedApps.map(({ appid }) => appid);
375
- ownedApps = _.shuffle(ownedApps);
376
- ownedApps.length = Math.min(ownedApps.length, MAX_GAME_PLAY - 1);
377
- _.remove(ownedApps, (app) => app == 730);
378
- gamesPlayed([...ownedApps, 730]);
379
- }
380
- }
381
-
382
- async function autoGamePlay() {
383
- await gamePlay();
384
- doSetInterval(gamePlay, [15 * 60000, 30 * 60000], "autoGamePlay");
385
- }
386
-
387
- async function offAutoGamePlay() {
388
- steamClient.gamesPlayed([]);
389
- doClearInterval("autoGamePlay");
390
- }
391
-
392
- async function updateAutoGamePlay() {
393
- if (isAutoPlay) {
394
- autoGamePlay();
395
- } else {
396
- offAutoGamePlay();
397
- }
398
- }
399
-
400
- /**
401
- * Get a list of lobbies (* = Unsure description could be wrong)
402
- * @param {Number} ver Game version we are searching for
403
- * @param {Boolean} apr Prime or not*
404
- * @param {Number} ark Rank multiplied by 10*
405
- * @param {Array.<Number>} grps *
406
- * @param {Number} launcher If we are using the China CSGO launcher or not*
407
- * @param {Number} game_type Game type, 8 Competitive, 10 Wingman
408
- * @returns {Promise.<Object>}
409
- */
410
- async function partySearch({ prime = false, game_type = "Competitive", rank = "Silver Elite", timeout = 5000 } = {}) {
411
- const players = await new Promise((resolve) => {
412
- steamClient.sendToGC(
413
- AppID,
414
- Protos.csgo.ECsgoGCMsg.k_EMsgGCCStrike15_v2_Party_Search,
415
- {},
416
- protoEncode(Protos.csgo.CMsgGCCStrike15_v2_Party_Search, {
417
- ver: CSGO_VER,
418
- apr: prime ? 1 : 0,
419
- ark: parseInt(Object.keys(RANKS).find((k) => RANKS[k] === rank)) * 10,
420
- grps: [],
421
- launcher: 0,
422
- game_type: game_type === "Competitive" ? 8 : 10,
423
- }),
424
- );
425
- lastTimePartySearch = new Date().getTime();
426
- pushGCCallback("partySearch", resolve, timeout);
427
- });
428
- if (Array.isArray(players) && players.length) {
429
- const personas = await getPersonas(players.map((p) => p.steamId));
430
- for (const player of players) {
431
- const persona = personas.find((p) => p.id == player.steamId);
432
- if (persona) {
433
- player.player_name = persona.player_name;
434
- player.avatar_hash = persona.avatar_hash;
435
- }
436
- }
437
- }
438
- return players;
439
- }
440
-
441
- async function createLobby() {
442
- if (!steamClient.steamID) {
443
- return;
444
- }
445
-
446
- return new Promise((resolve) => {
447
- const timeout = setTimeout(function () {
448
- resolve();
449
- }, 30000);
450
-
451
- steamClient._send(
452
- {
453
- msg: Protos.csgo.EMsg.k_EMsgClientMMSCreateLobby,
454
- proto: {
455
- steamid: steamClient.steamID.getSteamID64(),
456
- routing_appid: 730,
457
- },
458
- },
459
- protoEncode(Protos.csgo.CMsgClientMMSCreateLobby, {
460
- app_id: 730,
461
- max_members: 1,
462
- lobby_type: 1,
463
- lobby_flags: 1,
464
- }),
465
- function (payload) {
466
- clearTimeout(timeout);
467
- const result = protoDecode(Protos.csgo.CMsgClientMMSCreateLobbyResponse, payload.toBuffer());
468
- const steam_id_lobby = result.steam_id_lobby.toString();
469
- currentLobby.lobbyID = steam_id_lobby;
470
- currentLobby.timestamp = new Date().getTime();
471
- resolve(steam_id_lobby);
472
- },
473
- );
474
- });
475
-
476
- // return await getHandlerResult(Protos.csgo.EMsg.k_EMsgClientMMSCreateLobbyResponse, function (payload) {
477
- // const result = protoDecode(Protos.csgo.CMsgClientMMSCreateLobbyResponse, payload.toBuffer())
478
- // return result.steam_id_lobby.toString()
479
- // })
480
-
481
- // steamClient.sendToGC(730, Protos.csgo.EMsg.k_EMsgClientMMSCreateLobby, {
482
- // steamid: steamClient.steamID,
483
- // routing_appid: 730,
484
- // }, protoEncode(Protos.csgo.CMsgClientMMSCreateLobby, {
485
- // app_id: 730,
486
- // max_members: 1,
487
- // lobby_type: 1,
488
- // lobby_flags: 1
489
- // }))
490
- }
491
-
492
- async function updateLobby(lobbyID) {
493
- if (!steamClient.steamID) {
494
- return;
495
- }
496
-
497
- return new Promise((resolve) => {
498
- const timeout = setTimeout(function () {
499
- resolve();
500
- }, 30000);
501
-
502
- steamClient._send(
503
- {
504
- msg: Protos.csgo.EMsg.k_EMsgClientMMSSetLobbyData,
505
- proto: {
506
- steamid: steamClient.steamID.getSteamID64(),
507
- routing_appid: 730,
508
- },
509
- },
510
- protoEncode(Protos.csgo.CMsgClientMMSSetLobbyData, {
511
- app_id: 730,
512
- steam_id_lobby: lobbyID,
513
- steam_id_member: "0",
514
- max_members: 10,
515
- lobby_type: 1,
516
- lobby_flags: 1,
517
- metadata: encode(
518
- {
519
- "game:ark": "0",
520
- // Country/Message
521
- "game:loc": "",
522
- "game:mapgroupname": "mg_de_mirage",
523
- "game:mode": "competitive",
524
- "game:prime": "1",
525
- "game:type": "classic",
526
- "members:numPlayers": "1",
527
- "options:action": "custommatch",
528
- "options:anytypemode": "0",
529
- "system:access": "private",
530
- "system:network": "LIVE",
531
- uids: [steamClient.steamID],
532
- },
533
- [0x00, 0x00],
534
- [0x08],
535
- { uids: encodeUids },
536
- ).toBuffer(),
537
- }),
538
- function (payload) {
539
- clearTimeout(timeout);
540
- const result = protoDecode(Protos.csgo.CMsgClientMMSSetLobbyDataResponse, payload.toBuffer());
541
- const steam_id_lobby = result.steam_id_lobby.toString();
542
- currentLobby.lobbyID = steam_id_lobby;
543
- currentLobby.timestamp = new Date().getTime();
544
- resolve(steam_id_lobby);
545
- },
546
- );
547
- });
548
-
549
- // return await getHandlerResult(Protos.csgo.EMsg.k_EMsgClientMMSSetLobbyDataResponse, function (payload) {
550
- // const result = protoDecode(Protos.csgo.CMsgClientMMSSetLobbyDataResponse, payload.toBuffer())
551
- // return result.steam_id_lobby.toString()
552
- // })
553
- }
554
-
555
- async function invite2Lobby(lobbyID, steamId) {
556
- if (!steamClient.steamID) {
557
- return;
558
- }
559
-
560
- steamClient._send(
561
- {
562
- msg: Protos.csgo.EMsg.k_EMsgClientMMSInviteToLobby,
563
- proto: {
564
- steamid: steamClient.steamID.getSteamID64(),
565
- routing_appid: 730,
566
- },
567
- },
568
- protoEncode(Protos.csgo.CMsgClientMMSInviteToLobby, {
569
- app_id: 730,
570
- steam_id_lobby: lobbyID,
571
- steam_id_user_invited: steamId,
572
- }),
573
- );
574
-
575
- // lobbyID = new SteamID(lobbyID).accountid;
576
-
577
- // Protos.csgo.EMsg.k_EMsgGCHInviteUserToLobby
578
- // Protos.csgo.EMsg.k_EMsgClientMMSInviteToLobby
579
- // steamClient.sendToGC(730, Protos.csgo.EMsg.k_EMsgClientMMSInviteToLobby, {}, protoEncode(Protos.csgo.CMsgClientMMSInviteToLobby, {
580
- // app_id: 730,
581
- // steam_id_lobby: lobbyID,
582
- // steam_id_user_invited: accountid,
583
- // }), function (...args) {
584
- // console.log("invite2Lobby response", args)
585
- // })
586
- }
587
-
588
- async function createThenInvite2Lobby(steamIds, onInvite) {
589
- if (!steamClient.steamID) {
590
- return;
591
- }
592
-
593
- if (!Array.isArray(steamIds)) {
594
- steamIds = [steamIds];
595
- }
596
-
597
- let lobbyID = null;
598
- if (currentLobby.lobbyID && currentLobby.timestamp > new Date().getTime() - 30000) {
599
- //30 seconds
600
- lobbyID = currentLobby.lobbyID;
601
- } else {
602
- lobbyID = await createLobby();
603
- lobbyID = await updateLobby(lobbyID);
604
- }
605
-
606
- for (const steamId of steamIds) {
607
- onInvite?.(lobbyID, steamId);
608
- await invite2Lobby(lobbyID, steamId);
609
- }
610
-
611
- return lobbyID;
612
- }
613
-
614
- async function getLobbyData(lobbyID) {
615
- if (!steamClient.steamID) {
616
- return;
617
- }
618
-
619
- return new Promise((resolve) => {
620
- const timeout = setTimeout(function () {
621
- resolve();
622
- }, 30000);
623
-
624
- steamClient._send(
625
- {
626
- msg: Protos.csgo.EMsg.k_EMsgClientMMSGetLobbyData,
627
- proto: {
628
- steamid: steamClient.steamID.getSteamID64(),
629
- routing_appid: 730,
630
- },
631
- },
632
- protoEncode(Protos.csgo.CMsgClientMMSGetLobbyData, {
633
- app_id: 730,
634
- steam_id_lobby: lobbyID.toString(),
635
- }),
636
- function (payload) {
637
- clearTimeout(timeout);
638
- const result = protoDecode(Protos.csgo.CMsgClientMMSLobbyData, payload.toBuffer());
639
- result.steam_id_lobby = result.steam_id_lobby.toString();
640
- resolve(result);
641
- },
642
- );
643
- });
644
- }
645
-
646
- async function joinLobby(lobbyID) {
647
- log("joinLobby", lobbyID); //SteamID.fromIndividualAccountID(lobbyId).accountid
648
-
649
- steamClient._send(
650
- {
651
- msg: Protos.csgo.EMsg.k_EMsgClientMMSJoinLobby,
652
- proto: {
653
- steamid: steamClient.steamID.getSteamID64(),
654
- routing_appid: 730,
655
- },
656
- }, //CMsgClientMMSUserJoinedLobby CMsgClientMMSJoinLobby
657
- protoEncode(Protos.csgo.CMsgClientMMSJoinLobby, {
658
- app_id: 730,
659
- steam_id_lobby: lobbyID,
660
- persona_name: steamClient.accountInfo.name,
661
- }),
662
- function (payload) {
663
- const result = protoDecode(Protos.csgo.CMsgClientMMSJoinLobbyResponse, payload.toBuffer());
664
- result.steam_id_lobby = result.steam_id_lobby.toString();
665
- result.steam_id_owner = result.steam_id_owner.toString();
666
- console.log(result);
667
- const resultExample = {
668
- members: [],
669
- app_id: 730,
670
- steam_id_lobby: "3641224920",
671
- chat_room_enter_response: 2,
672
- max_members: 0,
673
- lobby_type: 0,
674
- lobby_flags: 0,
675
- steam_id_owner: "0",
676
- metadata: null, //Buffer
677
- };
678
- },
679
- );
680
- }
681
-
682
- async function sendHello() {
683
- steamClient.sendToGC(AppID, Protos.csgo.ECsgoGCMsg.k_EMsgGCCStrike15_v2_MatchmakingClient2GCHello, {}, Buffer.alloc(0));
684
- // steamClient.sendToGC(AppID, Protos.csgo.EGCBaseClientMsg.k_EMsgGCClientHello, {}, Buffer.alloc(0));
685
-
686
- steamClient.sendToGC(
687
- AppID,
688
- Protos.csgo.EGCBaseClientMsg.k_EMsgGCClientHello,
689
- {},
690
- protoEncode(Protos.csgo.CMsgClientHello, {
691
- version: 2000258, //get from https://github.com/SteamDatabase/GameTracking-CS2/commits
692
- client_session_need: 0,
693
- client_launcher: 0,
694
- steam_launcher: 0,
695
- }),
696
- );
697
- }
698
-
699
- async function requestCoPlays() {
700
- return new Promise((resolve) => {
701
- steamClient.sendToGC(AppID, Protos.csgo.ECsgoGCMsg.k_EMsgGCCStrike15_v2_Account_RequestCoPlays, {}, Buffer.alloc(0));
702
- pushGCCallback("RequestCoPlays", resolve, 30000);
703
- });
704
- }
705
-
706
- function bindEvent() {
707
- const _events = {
708
- async disconnected(eresult, msg) {
709
- state = "Offline";
710
- log("disconnected", eresult, msg);
711
-
712
- callEvent(events.disconnected, { eresult, msg });
713
-
714
- if (["ServiceUnavailable", "NoConnection"].includes(msg) && autoReconnect && !isLogOff) {
715
- async function relogin(retry) {
716
- if (isLogOff) {
717
- console.error("Cannot relogin (logoff)");
718
- return false;
719
- } else if (retry <= 0) {
720
- console.error("Cannot relogin");
721
- return false;
722
- } else {
723
- const isSuccess = await login(true);
724
- if (isSuccess) {
725
- const loggedOnResponse = await new Promise((resolve) => {
726
- onEvent("loggedOn", resolve, true, 180000);
727
- });
728
- if (loggedOnResponse) {
729
- console.log("Relogin success");
730
- return true;
731
- } else {
732
- const isLogOff = await new Promise((resolve, reject) => {
733
- logOffEvent = resolve;
734
- setTimeout(resolve, 120000);
735
- });
736
- logOffEvent = null;
737
- if (isLogOff === true) {
738
- return false;
739
- }
740
- return await relogin(retry - 1);
741
- }
742
- } else {
743
- const isLogOff = await new Promise((resolve, reject) => {
744
- logOffEvent = resolve;
745
- setTimeout(resolve, 120000);
746
- });
747
- logOffEvent = null;
748
- if (isLogOff === true) {
749
- return false;
750
- }
751
- return await relogin(retry - 1);
752
- }
753
- }
754
- }
755
-
756
- const isLogOff = await new Promise((resolve, reject) => {
757
- logOffEvent = resolve;
758
- setTimeout(resolve, 60000);
759
- });
760
- logOffEvent = null;
761
- if (isLogOff === true) {
762
- offAllEvent();
763
- doClearIntervals();
764
- } else {
765
- const isSuccess = await relogin(50);
766
- if (!isSuccess) {
767
- offAllEvent();
768
- doClearIntervals();
769
- }
770
- }
771
- } else {
772
- offAllEvent();
773
- doClearIntervals();
774
- }
775
- },
776
- async error(e) {
777
- let errorStr = "";
778
- switch (e.eresult) {
779
- case 5:
780
- errorStr = "Invalid Password";
781
- break;
782
- case 6:
783
- case 34:
784
- errorStr = "Logged In Elsewhere";
785
- break;
786
- case 84:
787
- errorStr = "Rate Limit Exceeded";
788
- break;
789
- case 65:
790
- errorStr = "steam guard is invalid";
791
- break;
792
- default:
793
- errorStr = `Unknown: ${e.eresult}`;
794
- break;
795
- }
796
- log(`error [isLogOff: ${isLogOff}]`, e?.message);
797
- doClearIntervals();
798
- callEvent(events.error, { eresult: e.eresult, msg: e.message, error: errorStr });
799
- },
800
- async webSession(sessionID, cookies) {
801
- const webSession = { sessionID, cookies };
802
- steamClient.webSession = webSession;
803
- callEvent(events.webSession, webSession);
804
- },
805
- async receivedFromGC(appid, msgType, payload) {
806
- const key = getECsgoGCMsgKey(msgType);
807
- switch (msgType) {
808
- case Protos.csgo.EMsg.k_EMsgClientChatInvite: {
809
- log(payload);
810
- break;
811
- }
812
- case Protos.csgo.ECsgoGCMsg.k_EMsgClientMMSJoinLobbyResponse: {
813
- const msg = protoDecode(Protos.csgo.CMsgClientMMSJoinLobbyResponse, payload);
814
- log(msg);
815
- break;
816
- }
817
- case Protos.csgo.ECsgoGCMsg.k_EMsgGCCStrike15_v2_Party_Invite: {
818
- const msg = protoDecode(Protos.csgo.CMsgGCCStrike15_v2_Party_Invite, payload);
819
- const sid64 = SteamID.fromIndividualAccountID(msg.accountid).getSteamID64();
820
- if (events.partyInvite?.length) {
821
- const personas = await getPersonas([sid64]);
822
- const player_name = personas.find((p) => p.id == sid64)?.player_name;
823
- if (player_name === undefined) {
824
- log(sid64, personas);
825
- }
826
- callEvent(events.partyInvite, { player_name, steamId: sid64, lobbyId: msg.lobbyid });
827
- }
828
- // log(player_name, `https://steamcommunity.com/profiles/${sid64}`);
829
- // joinLobby(msg.lobbyid, msg.accountid)
830
- break;
831
- }
832
- case Protos.csgo.ECsgoGCMsg.k_EMsgGCCStrike15_v2_Account_RequestCoPlays: {
833
- const msg = protoDecode(Protos.csgo.CMsgGCCStrike15_v2_Account_RequestCoPlays, payload);
834
- const personas = msg.players.map((p) => SteamID.fromIndividualAccountID(p.accountid));
835
- callGCCallback("RequestCoPlays", personas);
836
- break;
837
- }
838
- case Protos.csgo.EGCBaseClientMsg.k_EMsgGCClientWelcome: {
839
- prime = false;
840
- const CMsgClientWelcome = protoDecode(Protos.csgo.CMsgClientWelcome, payload);
841
- const obj = {};
842
- for (const outofdate_cache of CMsgClientWelcome.outofdate_subscribed_caches) {
843
- for (const cache_object of outofdate_cache.objects) {
844
- for (const object_data of cache_object.object_data) {
845
- switch (cache_object.type_id) {
846
- case 1: {
847
- const result = protoDecode(Protos.csgo.CSOEconItem, object_data);
848
- result.id = result.id.toNumber();
849
- break;
850
- }
851
- case 2: {
852
- const result = protoDecode(Protos.csgo.CSOPersonaDataPublic, object_data);
853
- obj.PersonaDataPublic = result;
854
- const example = {
855
- player_level: 4, //CSGO_Profile_Rank
856
- commendation: {
857
- cmd_friendly: 149,
858
- cmd_teaching: 108,
859
- cmd_leader: 115,
860
- },
861
- elevated_state: true,
862
- };
863
- break;
864
- }
865
- case 5: {
866
- const result = protoDecode(Protos.csgo.CSOItemRecipe, object_data);
867
- break;
868
- }
869
- case 7: {
870
- const CSOEconGameAccountClient = protoDecode(Protos.csgo.CSOEconGameAccountClient, object_data);
871
- const CSOEconGameAccountClientExample = {
872
- additional_backpack_slots: 0,
873
- bonus_xp_timestamp_refresh: 1688518800, //Wednesday 1:00:00 AM every week
874
- bonus_xp_usedflags: 19,
875
- elevated_state: 5,
876
- elevated_timestamp: 5,
877
- }; //1688518800
878
- if ((CSOEconGameAccountClient.bonus_xp_usedflags & 16) != 0) {
879
- // EXPBonusFlag::PrestigeEarned
880
- prime = true;
881
- CSOEconGameAccountClient.prime = true;
882
- }
883
- if (CSOEconGameAccountClient.elevated_state === 5) {
884
- // bought prime
885
- prime = true;
886
- CSOEconGameAccountClient.prime = true;
887
- }
888
- obj.GameAccountClient = CSOEconGameAccountClient;
889
- break;
890
- }
891
-
892
- case 35: {
893
- // const result =protoDecode(Protos.csgo.CSOSelectedItemPreset, object_data);
894
- break;
895
- }
896
-
897
- case 36: {
898
- // const result =protoDecode(Protos.csgo.CSOEconItemPresetInstance, object_data);
899
- break;
900
- }
901
- case 38: {
902
- const result = protoDecode(Protos.csgo.CSOEconItemDropRateBonus, object_data);
903
- break;
904
- }
905
- case 39: {
906
- const result = protoDecode(Protos.csgo.CSOEconItemLeagueViewPass, object_data);
907
- break;
908
- }
909
- case 40: {
910
- const result = protoDecode(Protos.csgo.CSOEconItemEventTicket, object_data);
911
- break;
912
- }
913
- case 41: {
914
- const result = protoDecode(Protos.csgo.CSOAccountSeasonalOperation, object_data);
915
- break;
916
- }
917
- case 42: {
918
- // const result =protoDecode(Protos.csgo.CSOEconItemTournamentPassport, object_data);
919
- break;
920
- }
921
- case 43: {
922
- const result = protoDecode(Protos.csgo.CSOEconDefaultEquippedDefinitionInstanceClient, object_data);
923
- const example = {
924
- account_id: 1080136620,
925
- item_definition: 61,
926
- class_id: 3,
927
- slot_id: 2,
928
- };
929
- break;
930
- }
931
- case 45: {
932
- const result = protoDecode(Protos.csgo.CSOEconCoupon, object_data);
933
- break;
934
- }
935
- case 46: {
936
- const result = protoDecode(Protos.csgo.CSOQuestProgress, object_data);
937
- break;
938
- }
939
- case 4: {
940
- const result = protoDecode(Protos.csgo.CSOAccountItemPersonalStore, object_data);
941
- result.generation_time = result.generation_time * 1000;
942
- if (Array.isArray(result.items)) {
943
- result.items = result.items.map((item) => item.toNumber());
944
- }
945
- obj.personalStore = result;
946
- break;
947
- }
948
-
949
- default: {
950
- log("cache_object.type_id", cache_object.type_id);
951
- }
952
- }
953
- }
954
- }
955
- }
956
- callEvent(events.csgoOnline, obj);
957
-
958
- if (isPartyRegister) {
959
- partyRegister();
960
- doSetInterval(
961
- function () {
962
- partyRegister();
963
- },
964
- [60000, 120000],
965
- "autoPartyRegister",
966
- );
967
- }
968
- break;
969
- }
970
- case Protos.csgo.ECsgoGCMsg.k_EMsgGCCStrike15_v2_MatchmakingGC2ClientUpdate: {
971
- const result = protoDecode(Protos.csgo.CMsgGCCStrike15_v2_MatchmakingGC2ClientUpdate, payload);
972
- break;
973
- }
974
- case Protos.csgo.ECsgoGCMsg.k_EMsgGCCStrike15_v2_GC2ClientGlobalStats: {
975
- const result = protoDecode(Protos.csgo.CMsgClientUGSGetGlobalStatsResponse, payload);
976
- break;
977
- }
978
- case Protos.csgo.ECsgoGCMsg.k_EMsgGCCStrike15_v2_ClientReportPlayer: {
979
- const result = protoDecode(Protos.csgo.CMsgGCCStrike15_v2_ClientReportPlayer, payload);
980
- break;
981
- }
982
- case Protos.csgo.ECsgoGCMsg.k_EMsgGCCStrike15_v2_GC2ClientTextMsg: {
983
- const result = protoDecode(Protos.csgo.CMsgGCCStrike15_v2_GC2ClientTextMsg, payload);
984
- break;
985
- }
986
- case Protos.csgo.ECsgoGCMsg.k_EMsgGCCStrike15_v2_MatchmakingGC2ClientHello: {
987
- const result = protoDecode(Protos.csgo.CMsgGCCStrike15_v2_MatchmakingGC2ClientHello, payload);
988
- const example = {
989
- my_current_event_teams: [],
990
- my_current_event_stages: [],
991
- rankings: [],
992
- account_id: 1080136620,
993
- ongoingmatch: null,
994
- global_stats: {
995
- search_statistics: [
996
- {
997
- game_type: 520,
998
- search_time_avg: 0,
999
- players_searching: 5141,
1000
- },
1001
- {
1002
- game_type: 32776,
1003
- search_time_avg: 0,
1004
- players_searching: 6561,
1005
- },
1006
- ],
1007
- players_online: 617207,
1008
- servers_online: 230638,
1009
- players_searching: 13550,
1010
- servers_available: 126352,
1011
- ongoing_matches: 23264,
1012
- search_time_avg: 95993,
1013
- main_post_url: "*XA=https://blast.tv/live*XT=https://www.twitch.tv/blastpremier*XB=https://live.bilibili.com/35*XG=playcast://https://gotv.blast.tv/major-a*T=SGTAB*L=2@https://steamcommunity.com/broadcast/watch/76561199492362089",
1014
- required_appid_version: 13879,
1015
- pricesheet_version: 1688084844,
1016
- twitch_streams_version: 2,
1017
- active_tournament_eventid: 21,
1018
- active_survey_id: 0,
1019
- rtime32_cur: 0,
1020
- rtime32_event_start: 0,
1021
- },
1022
- penalty_seconds: 0,
1023
- penalty_reason: 0,
1024
- vac_banned: 0,
1025
- ranking: {
1026
- account_id: 1080136620,
1027
- rank_id: 10,
1028
- wins: 209,
1029
- rank_change: 0,
1030
- rank_type_id: 6,
1031
- tv_control: 0,
1032
- },
1033
- commendation: {
1034
- cmd_friendly: 149,
1035
- cmd_teaching: 108,
1036
- cmd_leader: 115,
1037
- },
1038
- medals: null,
1039
- my_current_event: null,
1040
- my_current_team: null,
1041
- survey_vote: 0,
1042
- activity: null,
1043
- player_level: 4,
1044
- player_cur_xp: 327684501,
1045
- player_xp_bonus_flags: 0,
1046
- };
1047
- if (result?.global_stats?.required_appid_version && (!CSGO_VER || result.global_stats.required_appid_version > CSGO_VER)) {
1048
- CSGO_VER = result.global_stats.required_appid_version;
1049
- }
1050
- callEvent(events.csgoClientHello, result);
1051
- break;
1052
- }
1053
- case Protos.csgo.ECsgoGCMsg.k_EMsgGCCStrike15_v2_ClientReportResponse: {
1054
- const result = protoDecode(Protos.csgo.CMsgGCCStrike15_v2_ClientReportResponse, payload);
1055
- break;
1056
- }
1057
- case Protos.csgo.ECsgoGCMsg.k_EMsgGCCStrike15_v2_ClientCommendPlayerQueryResponse: {
1058
- const result = protoDecode(Protos.csgo.CMsgGCCStrike15_v2_ClientCommendPlayer, payload);
1059
- break;
1060
- }
1061
- case Protos.csgo.ECsgoGCMsg.k_EMsgGCCStrike15_v2_PlayerOverwatchCaseAssignment: {
1062
- const result = protoDecode(Protos.csgo.CMsgGCCStrike15_v2_PlayerOverwatchCaseAssignment, payload);
1063
- break;
1064
- }
1065
- case Protos.csgo.ECsgoGCMsg.k_EMsgGCCStrike15_v2_MatchList: {
1066
- const result = protoDecode(Protos.csgo.CMsgGCCStrike15_v2_MatchList, payload);
1067
- break;
1068
- }
1069
- case Protos.csgo.ECsgoGCMsg.k_EMsgGCCStrike15_v2_GetEventFavorites_Response: {
1070
- const result = protoDecode(Protos.csgo.CMsgGCCStrike15_v2_GetEventFavorites_Response, payload);
1071
- break;
1072
- }
1073
- case Protos.csgo.ECsgoGCMsg.k_EMsgGCCStrike15_StartAgreementSessionInGame: {
1074
- break;
1075
- }
1076
- case Protos.csgo.ECsgoGCMsg.k_EMsgGCCStrike15_ClientDeepStats: {
1077
- const result = protoDecode(Protos.csgo.CMsgGCCStrike15_ClientDeepStats, payload);
1078
- break;
1079
- }
1080
- case Protos.csgo.EGCBaseClientMsg.k_EMsgGCClientConnectionStatus: {
1081
- const result = protoDecode(Protos.csgo.CMsgConnectionStatus, payload);
1082
- break;
1083
- }
1084
- case Protos.csgo.EGCItemMsg.k_EMsgGCStoreGetUserDataResponse: {
1085
- const result = protoDecode(Protos.csgo.CMsgStoreGetUserDataResponse, payload);
1086
- break;
1087
- }
1088
- case Protos.csgo.EGCItemMsg.k_EMsgGCStorePurchaseFinalizeResponse: {
1089
- const result = protoDecode(Protos.csgo.CMsgGCStorePurchaseFinalizeResponse, payload);
1090
- break;
1091
- }
1092
- case Protos.csgo.EGCItemMsg.k_EMsgGCStorePurchaseCancelResponse: {
1093
- const result = protoDecode(Protos.csgo.CMsgGCStorePurchaseCancelResponse, payload);
1094
- break;
1095
- }
1096
- case Protos.csgo.EGCItemMsg.k_EMsgGCStorePurchaseInitResponse: {
1097
- const result = protoDecode(Protos.csgo.CMsgGCStorePurchaseInitResponse, payload);
1098
- break;
1099
- }
1100
- case Protos.csgo.EMsg.k_EMsgClientMMSCreateLobbyResponse: {
1101
- const result = protoDecode(Protos.csgo.CMsgClientMMSCreateLobbyResponse, payload);
1102
- console.log("k_EMsgClientMMSCreateLobbyResponse", result);
1103
- break;
1104
- }
1105
- case Protos.csgo.ECsgoGCMsg.k_EMsgGCCStrike15_v2_ClientGCRankUpdate: {
1106
- const result = protoDecode(Protos.csgo.CMsgGCCStrike15_v2_ClientGCRankUpdate, payload);
1107
- break;
1108
- }
1109
- case Protos.csgo.ECsgoGCMsg.k_EMsgGCCStrike15_v2_Party_Search: {
1110
- const result = protoDecode(Protos.csgo.CMsgGCCStrike15_v2_Party_SearchResults, payload);
1111
- const entries = _.uniqBy(result.entries, "id");
1112
- //{
1113
- // id: 144900402,
1114
- // grp: 0,
1115
- // game_type: 8,
1116
- // apr: 1,
1117
- // ark: 17,
1118
- // loc: 20041,
1119
- // accountid: 0
1120
- // }
1121
-
1122
- //{
1123
- // id: "76561199265943339",
1124
- // rich_presence: [],
1125
- // persona_state: null,
1126
- // game_played_app_id: null,
1127
- // game_server_ip: null,
1128
- // game_server_port: null,
1129
- // persona_state_flags: null,
1130
- // online_session_instances: null,
1131
- // persona_set_by_user: null,
1132
- // player_name: "杀人不见血",
1133
- // query_port: null,
1134
- // steamid_source: null,
1135
- // avatar_hash: "33994e26f1fe7e2093f8c7dee66c1ac91531050d",
1136
- // last_logoff: null,
1137
- // last_logon: null,
1138
- // last_seen_online: null,
1139
- // clan_rank: null,
1140
- // game_name: null,
1141
- // gameid: null,
1142
- // game_data_blob: null,
1143
- // clan_data: null,
1144
- // clan_tag: null,
1145
- // broadcast_id: null,
1146
- // game_lobby_id: null,
1147
- // watching_broadcast_accountid: null,
1148
- // watching_broadcast_appid: null,
1149
- // watching_broadcast_viewers: null,
1150
- // watching_broadcast_title: null,
1151
- // is_community_banned: null,
1152
- // player_name_pending_review: null,
1153
- // avatar_pending_review: null,
1154
- // avatar_url_icon: "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/33/33994e26f1fe7e2093f8c7dee66c1ac91531050d.jpg",
1155
- // avatar_url_medium: "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/33/33994e26f1fe7e2093f8c7dee66c1ac91531050d_medium.jpg",
1156
- // avatar_url_full: "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/33/33994e26f1fe7e2093f8c7dee66c1ac91531050d_full.jpg"
1157
- // }
1158
-
1159
- const players = [];
1160
- for (const player of entries) {
1161
- try {
1162
- const prime = player.apr === 1 ? "PRIME" : "NON-PRIME";
1163
- const loc = LOCS[player.loc] || player.loc;
1164
- const steamId = SteamID.fromIndividualAccountID(player.id).getSteamID64();
1165
- const friendCode = FriendCode.encode(steamId);
1166
-
1167
- // if ((LOCS[player.loc] == 'VN' || !LOCS[player.loc])) {
1168
- players.push({
1169
- prime,
1170
- rank: RANKS[player.ark] !== undefined ? RANKS[player.ark] : player.ark,
1171
- loc,
1172
- steamId,
1173
- friendCode,
1174
- });
1175
- // }
1176
- } catch (e) {}
1177
- }
1178
-
1179
- callGCCallback("partySearch", players);
1180
- break;
1181
- }
1182
- case Protos.csgo.ECsgoGCMsg.k_EMsgGCCStrike15_v2_PlayersProfile: {
1183
- let data = protoDecode(Protos.csgo.CMsgGCCStrike15_v2_PlayersProfile, payload)?.account_profiles;
1184
- const dataExample = [
1185
- {
1186
- my_current_event_teams: [],
1187
- my_current_event_stages: [],
1188
- rankings: [
1189
- {
1190
- account_id: 1225887169,
1191
- rank_id: 0,
1192
- wins: 6,
1193
- rank_change: 0,
1194
- rank_type_id: 7,
1195
- tv_control: 0,
1196
- },
1197
- {
1198
- account_id: 1225887169,
1199
- rank_id: 0,
1200
- wins: 0,
1201
- rank_change: 0,
1202
- rank_type_id: 10,
1203
- tv_control: 0,
1204
- },
1205
- ],
1206
- account_id: 1225887169,
1207
- ongoingmatch: null,
1208
- global_stats: null,
1209
- penalty_seconds: 0,
1210
- penalty_reason: 0,
1211
- vac_banned: 0,
1212
- ranking: {
1213
- account_id: 1225887169,
1214
- rank_id: 8,
1215
- wins: 469,
1216
- rank_change: 0,
1217
- rank_type_id: 6,
1218
- tv_control: 0,
1219
- },
1220
- commendation: {
1221
- cmd_friendly: 51,
1222
- cmd_teaching: 40,
1223
- cmd_leader: 40,
1224
- },
1225
- medals: {
1226
- display_items_defidx: [4819, 4737],
1227
- featured_display_item_defidx: 4819,
1228
- },
1229
- my_current_event: null,
1230
- my_current_team: null,
1231
- survey_vote: 0,
1232
- activity: null,
1233
- player_level: 32,
1234
- player_cur_xp: 327682846,
1235
- player_xp_bonus_flags: 0,
1236
- },
1237
- ];
1238
-
1239
- const player = data?.[0];
1240
- if (player) {
1241
- player.prime = !!(player.ranking?.account_id || player.player_level || player.player_cur_xp);
1242
- player.steamId = SteamID.fromIndividualAccountID(player.account_id).getSteamID64();
1243
- callGCCallback(`PlayersProfile_${player.account_id}`, player);
1244
- }
1245
- callEvent(events.playersProfile, player);
1246
- break;
1247
- }
1248
- case Protos.csgo.ECsgoGCMsg.k_EMsgGCCStrike15_v2_ClientLogonFatalError: {
1249
- const data = protoDecode(Protos.csgo.CMsgGCCStrike15_v2_ClientLogonFatalError, payload);
1250
- const dataExample = {
1251
- errorcode: 4,
1252
- message: "",
1253
- country: "VN",
1254
- };
1255
- callEvent(events.fatalError, data);
1256
- break;
1257
- }
1258
- default:
1259
- log(`receivedFromGC ${msgType} ${key}`);
1260
- const results = Object.values(Protos.csgo)
1261
- .map(function (p) {
1262
- try {
1263
- return protoDecode(p, payload);
1264
- } catch (e) {}
1265
- })
1266
- .filter(function (result) {
1267
- return result && Object.keys(result).length;
1268
- });
1269
- log(key, results);
1270
- }
1271
- },
1272
- async loggedOn(loggedOnResponse) {
1273
- callEvent(events.loggedOn, loggedOnResponse);
1274
- updateInvisible();
1275
- updateAutoRequestFreeLicense();
1276
- updateAutoGamePlay();
1277
- },
1278
- async user(steamId, data) {
1279
- callEvent(events.user, { steamId: steamId.getSteamID64(), data });
1280
- const dataExample = {
1281
- rich_presence: [
1282
- {
1283
- key: "status",
1284
- value: "Competitive Mirage [ 3 : 6 ]",
1285
- },
1286
- {
1287
- key: "version",
1288
- value: "13875",
1289
- },
1290
- {
1291
- key: "game:state",
1292
- value: "game",
1293
- },
1294
- {
1295
- key: "steam_display",
1296
- value: "#display_GameKnownMapScore",
1297
- },
1298
- {
1299
- key: "game:mode",
1300
- value: "competitive",
1301
- },
1302
- {
1303
- key: "game:mapgroupname",
1304
- value: "mg_de_mirage",
1305
- },
1306
- {
1307
- key: "game:map",
1308
- value: "de_mirage",
1309
- },
1310
- {
1311
- key: "game:server",
1312
- value: "kv",
1313
- },
1314
- {
1315
- key: "watch",
1316
- value: "1",
1317
- },
1318
- {
1319
- key: "steam_player_group",
1320
- value: "2134948645",
1321
- },
1322
- {
1323
- key: "game:score",
1324
- value: "[ 3 : 6 ]",
1325
- },
1326
- ],
1327
- friendid: "76561199405834425",
1328
- persona_state: 1,
1329
- game_played_app_id: 730,
1330
- game_server_ip: null,
1331
- game_server_port: null,
1332
- persona_state_flags: 1,
1333
- online_session_instances: 1,
1334
- persona_set_by_user: null,
1335
- player_name: "quỷ súng",
1336
- query_port: null,
1337
- steamid_source: "0",
1338
- avatar_hash: {
1339
- type: "Buffer",
1340
- data: [23, 163, 216, 209, 236, 179, 73, 228, 225, 30, 48, 190, 192, 170, 177, 246, 139, 71, 122, 205],
1341
- },
1342
- last_logoff: 1683950268,
1343
- last_logon: 1683950281,
1344
- last_seen_online: 1683950268,
1345
- clan_rank: null,
1346
- game_name: "",
1347
- gameid: "730",
1348
- game_data_blob: {
1349
- type: "Buffer",
1350
- data: [],
1351
- },
1352
- clan_data: null,
1353
- clan_tag: null,
1354
- broadcast_id: "0",
1355
- game_lobby_id: "0",
1356
- watching_broadcast_accountid: null,
1357
- watching_broadcast_appid: null,
1358
- watching_broadcast_viewers: null,
1359
- watching_broadcast_title: null,
1360
- is_community_banned: null,
1361
- player_name_pending_review: null,
1362
- avatar_pending_review: null,
1363
- };
1364
- },
1365
- async playingState(playing_blocked, playing_app) {
1366
- playingBlocked = playing_blocked;
1367
- if (playing_app === 0) {
1368
- playing_app = null;
1369
- }
1370
- if (playing_blocked) {
1371
- //true, false
1372
- console.log("Playing else where");
1373
- }
1374
- log("playingState", playing_blocked, playing_app);
1375
- callEvent(events.playingState, { playing_blocked, playing_app });
1376
- },
1377
- async friendRelationship(sid, relationship, previousRelationship) {
1378
- callEvent(events.friendRelationship, {
1379
- steamId: sid.getSteamID64(),
1380
- relationship,
1381
- previousRelationship,
1382
- });
1383
- switch (relationship) {
1384
- case EFriendRelationship.None: {
1385
- //we got unfriended.
1386
- break;
1387
- }
1388
- case EFriendRelationship.RequestRecipient: {
1389
- //we got invited as a friend
1390
- break;
1391
- }
1392
- case EFriendRelationship.Friend: {
1393
- //we got added as a friend
1394
- break;
1395
- }
1396
- }
1397
- },
1398
- async tradeOffers(count) {
1399
- callEvent(events.tradeOffers, count);
1400
- },
1401
- async offlineMessages(count, friends) {
1402
- callEvent(events.offlineMessages, { count, steamIdList: friends });
1403
- },
1404
- async tradeRequest(steamID, respond) {
1405
- if (autoAcceptTradeRequest) {
1406
- log(`Incoming trade request from ${steamID.getSteam3RenderedID()}, accepting`);
1407
- respond(true);
1408
- } else {
1409
- log(`Incoming trade request from ${steamID.getSteam3RenderedID()}, wating`);
1410
- }
1411
- },
1412
- async friendsList() {
1413
- callEvent(events.friendsList, getFriendList());
1414
- },
1415
- async gifts(gid, packageid, TimeCreated, TimeExpiration, TimeSent, TimeAcked, TimeRedeemed, RecipientAddress, SenderAddress, SenderName) {
1416
- callEvent(events.gifts, {
1417
- gid,
1418
- packageid,
1419
- TimeCreated,
1420
- TimeExpiration,
1421
- TimeSent,
1422
- TimeAcked,
1423
- TimeRedeemed,
1424
- RecipientAddress,
1425
- SenderAddress,
1426
- SenderName,
1427
- });
1428
- },
1429
- async emailInfo(address, validated) {
1430
- callEvent(events.emailInfo, { address, validated });
1431
- },
1432
- async appLaunched() {
1433
- setTimeout(function () {
1434
- state = getPlayingAppIds().length ? "InGame" : isInvisible ? "Invisible" : "Online";
1435
- }, 1000);
1436
- },
1437
- async appQuit() {
1438
- setTimeout(function () {
1439
- state = getPlayingAppIds().length ? "InGame" : isInvisible ? "Invisible" : "Online";
1440
- }, 1000);
1441
- },
1442
- async accountLimitations(bis_limited_account, bis_community_banned, bis_locked_account, bis_limited_account_allowed_to_invite_friends) {
1443
- callEvent(events.accountLimitations, {
1444
- limited: bis_limited_account,
1445
- communityBanned: bis_community_banned,
1446
- locked: bis_locked_account,
1447
- canInviteFriends: bis_limited_account_allowed_to_invite_friends,
1448
- });
1449
- },
1450
- };
1451
-
1452
- const _chatEvents = {
1453
- async friendMessage(data) {
1454
- if (!data) return;
1455
- data.message_no_bbcode = data.message_no_bbcode?.replaceAll("ː", ":");
1456
- data.message = data.message?.replaceAll("ː", ":");
1457
- const example = {
1458
- steamid_friend: {
1459
- universe: 1,
1460
- type: 1,
1461
- instance: 1,
1462
- accountid: 1080136620,
1463
- },
1464
- chat_entry_type: 1,
1465
- from_limited_account: false,
1466
- message: "xxx",
1467
- ordinal: 0,
1468
- local_echo: false,
1469
- message_no_bbcode: "xxx",
1470
- low_priority: false,
1471
- server_timestamp: "2023-05-14T09:26:25.000Z",
1472
- message_bbcode_parsed: ["xxx"],
1473
- };
1474
- const timestamp = new Date(data.server_timestamp).getTime();
1475
- const steamId = data.steamid_friend.getSteamID64();
1476
- const invite = ["Invited you to play a game!", "Đã mời bạn chơi một trò chơi!"].includes(data.message_no_bbcode || data.message);
1477
- const emotion = (data.message_no_bbcode || "").split(" ").find((m) => m.startsWith(":") && m.endsWith(":"));
1478
-
1479
- callEvent(events.friendMessage, {
1480
- ...data,
1481
- message: data.message_no_bbcode,
1482
- invite,
1483
- steamId,
1484
- timestamp,
1485
- emotion,
1486
- });
1487
- },
1488
- async friendTyping(steamId, message) {
1489
- callEvent(events.friendTyping, {
1490
- steamId,
1491
- message,
1492
- });
1493
- },
1494
- };
1495
-
1496
- // steamClient.on('lobbyInvite', (inviterID, lobbyID ) => {
1497
- // joinLobby(lobbyID)
1498
- // })
1499
-
1500
- // steamClient.on('debug', (msg) => {
1501
- // if (!["ClientPersonaState","ClientClanState"].some(c => msg.includes(c))) {
1502
- // if(msg.startsWith("Received")){
1503
- // console.log(`------- ${msg}`)
1504
- // } else {
1505
- // console.log(msg)
1506
- // }
1507
- // }
1508
- // })
1509
-
1510
- function getECsgoGCMsgKey(_key) {
1511
- for (let key in Protos.csgo.ECsgoGCMsg) {
1512
- if (Protos.csgo.ECsgoGCMsg[key] == _key) {
1513
- return key;
1514
- }
1515
- }
1516
- for (let key in Protos.csgo.EGCBaseClientMsg) {
1517
- if (Protos.csgo.EGCBaseClientMsg[key] == _key) {
1518
- return key;
1519
- }
1520
- }
1521
- for (let key in Protos.csgo.EMsg) {
1522
- if (Protos.csgo.EMsg[key] == _key) {
1523
- return key;
1524
- }
1525
- }
1526
- for (let key in Protos.csgo.EGCItemMsg) {
1527
- if (Protos.csgo.EGCItemMsg[key] == _key) {
1528
- return key;
1529
- }
1530
- }
1531
- }
1532
-
1533
- for (const [name, _event] of Object.entries(_events)) {
1534
- steamClient.on(name, _event);
1535
- }
1536
-
1537
- for (const [name, _event] of Object.entries(_chatEvents)) {
1538
- steamClient.chat.on(name, _event);
1539
- }
1540
- }
1541
-
1542
- function getHandlerResult(msg, handler) {
1543
- const timeout = { current: null };
1544
- return new Promise((resolve) => {
1545
- function myhandler(...args) {
1546
- timeout.current && clearTimeout(timeout.current);
1547
- removeHandler();
1548
- resolve(handler?.(...args));
1549
- }
1550
-
1551
- function removeHandler() {
1552
- if (Array.isArray(steamClient._handlerManager._handlers[msg])) {
1553
- const index = steamClient._handlerManager._handlers[msg].findIndex((_handler) => _handler === myhandler);
1554
- if (index > -1) {
1555
- steamClient._handlerManager._handlers[msg].splice(index, 1);
1556
- }
1557
- }
1558
- }
1559
-
1560
- timeout.current = setTimeout(function () {
1561
- removeHandler();
1562
- resolve();
1563
- }, 60000);
1564
- steamClient._handlerManager.add(msg, myhandler);
1565
- });
1566
- }
1567
-
1568
- function getFriendList() {
1569
- return Object.keys(steamClient.myFriends).filter((steamId) => steamClient.myFriends[steamId] === NodeSteamUser.EFriendRelationship.Friend);
1570
- }
1571
-
1572
- function sendFriendTyping(steamId, callback) {
1573
- steamClient.chat.sendFriendTyping(steamId, callback);
1574
- }
1575
-
1576
- /*
1577
- * usually take 400 -> 800 miliseconds
1578
- * */
1579
- function getPlayersProfile(steamId) {
1580
- const accountid = new SteamID(steamId).accountid;
1581
- steamClient.sendToGC(
1582
- 730,
1583
- Protos.csgo.ECsgoGCMsg.k_EMsgGCCStrike15_v2_ClientRequestPlayersProfile,
1584
- {},
1585
- protoEncode(Protos.csgo.CMsgGCCStrike15_v2_ClientRequestPlayersProfile, {
1586
- account_id: accountid, // account_id: new SteamID('76561199184696945').accountid,
1587
- request_level: 32,
1588
- }),
1589
- );
1590
- return new Promise((resolve) => {
1591
- pushGCCallback(`PlayersProfile_${accountid}`, resolve, 2000);
1592
- });
1593
- }
1594
-
1595
- async function checkPlayerPrimeStatus(steamId) {
1596
- const profile = await getPlayersProfile(steamId);
1597
- if (!profile) return false;
1598
-
1599
- if (profile.ranking?.account_id) {
1600
- return true;
1601
- }
1602
-
1603
- if (profile.player_level || profile.player_cur_xp) {
1604
- return true;
1605
- }
1606
- return false;
1607
- }
1608
-
1609
- async function _getStoreSteamPoweredResponse(cookie) {
1610
- let response = null;
1611
- for (let i = 0; i < 50; i++) {
1612
- if (!response) {
1613
- try {
1614
- response = await axios.request({
1615
- url: "https://store.steampowered.com/",
1616
- headers: {
1617
- cookie,
1618
- accept: "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.75",
1619
- },
1620
- });
1621
- } catch (e) {
1622
- await sleep(1000);
1623
- }
1624
- }
1625
- }
1626
- return response;
1627
- }
1628
-
1629
- async function getNewCookie(cookie) {
1630
- if (!cookie) {
1631
- return;
1632
- }
1633
- let response = await _getStoreSteamPoweredResponse(cookie);
1634
- if (!response) {
1635
- return;
1636
- }
1637
- while (Array.isArray(response?.headers?.["set-cookie"])) {
1638
- console.log(cookie);
1639
- const cookieObj = cookie.split(";").reduce(function (accumulator, currentValue) {
1640
- accumulator[currentValue.trim().split("=")[0].trim()] = currentValue.trim().split("=")[1].trim();
1641
- return accumulator;
1642
- }, {});
1643
- for (const mcookie of response.headers["set-cookie"]) {
1644
- const name = mcookie.split("=")[0].trim();
1645
- const value = mcookie.split("=")[1].split(";")[0].trim();
1646
- cookieObj[name] = value;
1647
- }
1648
- cookie = Object.keys(cookieObj)
1649
- .map((name) => `${name}=${cookieObj[name]}`)
1650
- .join(";");
1651
- response = await _getStoreSteamPoweredResponse(cookie);
1652
- }
1653
- return cookie;
1654
- }
1655
-
1656
- async function loginWithCookie(cookie, tryNewCookie = false) {
1657
- let response;
1658
- for (let i = 0; i < 20; i++) {
1659
- try {
1660
- response = await axios.request({
1661
- url: "https://steamcommunity.com/chat/clientjstoken",
1662
- headers: {
1663
- cookie,
1664
- },
1665
- });
1666
- } catch (e) {
1667
- await sleep(1000);
1668
- }
1669
- if (response) {
1670
- break;
1671
- }
1672
- }
1673
-
1674
- const result = response?.data;
1675
- if (result?.logged_in) {
1676
- Object.assign(result, {
1677
- steamID: new SteamID(result.steamid),
1678
- accountName: result.account_name,
1679
- webLogonToken: result.token,
1680
- });
1681
- steamClient.logOn(result);
1682
- return cookie;
1683
- } else {
1684
- if (tryNewCookie) {
1685
- log("You are not logged in", cookie);
1686
- return null;
1687
- } else {
1688
- const newCookie = await getNewCookie(cookie);
1689
- if (!newCookie) {
1690
- console.error("Cannot get new cookie");
1691
- return null;
1692
- } else {
1693
- return await loginWithCookie(newCookie, true);
1694
- }
1695
- }
1696
- }
1697
- }
1698
-
1699
- async function login(reconnect = false) {
1700
- function logOn(clientJsToken) {
1701
- try {
1702
- steamClient.logOn({
1703
- ...clientJsToken,
1704
- steamId: new SteamID(clientJsToken.steamid),
1705
- steamID: new SteamID(clientJsToken.steamid),
1706
- accountName: clientJsToken.account_name,
1707
- webLogonToken: clientJsToken.token,
1708
- });
1709
- return true;
1710
- } catch (e) {
1711
- console.error(e);
1712
- return false;
1713
- }
1714
- }
1715
-
1716
- if (clientJsToken?.logged_in === true) {
1717
- log(reconnect ? "reconnect with clientJsToken" : "login with clientJsToken");
1718
- setTimeout(function () {
1719
- clientJsToken = null;
1720
- }, 1000);
1721
- return logOn(clientJsToken);
1722
- } else if (cookie) {
1723
- log(reconnect ? "reconnect with cookie" : "login with cookie");
1724
- const _clientJsToken = await new SteamUser(typeof cookie === "function" ? await cookie() : cookie).getClientJsToken();
1725
- if (_clientJsToken?.logged_in === true) {
1726
- return logOn(_clientJsToken);
1727
- } else {
1728
- log(`Account not logged in ${clientJsToken?.account_name || ""}`);
1729
- return false;
1730
- }
1731
- } else if (username && password) {
1732
- log(reconnect ? `reconnect with username ${username}` : `login with username ${username}`);
1733
- steamClient.logOn({
1734
- accountName: username,
1735
- password: password,
1736
- rememberPassword: true,
1737
- machineName: "Natri",
1738
- });
1739
- return true;
1740
- } else {
1741
- log(`Account not logged in ${clientJsToken?.account_name || ""}`);
1742
- return false;
1743
- }
1744
- }
1745
-
1746
- function logOff() {
1747
- isLogOff = true;
1748
- logOffEvent?.(true);
1749
- steamClient.logOff();
1750
- }
1751
-
1752
- function onCookie(callback) {
1753
- if (getCookies()) {
1754
- callback(getCookies());
1755
- } else {
1756
- onEvent(
1757
- "webSession",
1758
- function (webSession) {
1759
- callback(webSession?.cookies?.join?.(";"));
1760
- },
1761
- true,
1762
- );
1763
- }
1764
- }
1765
-
1766
- async function init() {
1767
- bindEvent();
1768
- if (await login()) {
1769
- steamClient._handlerManager.add(Protos.csgo.EMsg.k_EMsgClientRequestedClientStats, function (payload) {
1770
- const result = protoDecode(Protos.csgo.CMsgClientRequestedClientStats, payload.toBuffer());
1771
- // console.log("CMsgClientRequestedClientStats", result);
1772
- });
1773
- steamClient._handlerManager.add(Protos.csgo.EMsg.k_EMsgClientMMSLobbyData, function (payload) {
1774
- const result = protoDecode(Protos.csgo.CMsgClientMMSLobbyData, payload.toBuffer());
1775
- // console.log("CMsgClientMMSLobbyData", result, result.metadata);
1776
- });
1777
- }
1778
- }
1779
-
1780
- function partyRegister() {
1781
- if (prime === null) {
1782
- _partyRegister(true);
1783
- _partyRegister(false);
1784
- } else {
1785
- _partyRegister(prime);
1786
- }
1787
- }
1788
-
1789
- function _partyRegister(prime) {
1790
- log("partyRegister", prime);
1791
- lastTimePartyRegister = new Date().getTime();
1792
- steamClient.sendToGC(
1793
- 730,
1794
- Protos.csgo.ECsgoGCMsg.k_EMsgGCCStrike15_v2_Party_Register,
1795
- {},
1796
- protoEncode(Protos.csgo.CMsgGCCStrike15_v2_Party_Register, {
1797
- // id : 0,
1798
- ver: CSGO_VER,
1799
- apr: prime ? 1 : 0, //prime
1800
- ark: prime ? 180 : 0,
1801
- grps: [],
1802
- launcher: 0,
1803
- game_type: 8,
1804
- }),
1805
- );
1806
- }
1807
-
1808
- async function sendFriendMessage(steamId, message) {
1809
- while (sendMessageTimestamp && new Date().getTime() - sendMessageTimestamp < 2000) {
1810
- await sleep(1000);
1811
- }
1812
-
1813
- while (isSendingFriendMessages) {
1814
- await sleep(5000);
1815
- }
1816
-
1817
- isSendingFriendMessages = true;
1818
- const now = new Date().getTime();
1819
- while (new Date().getTime() - now < 2 * 60000) {
1820
- //2 minutes
1821
- const result = await new Promise((resolve) => {
1822
- steamClient.chat.sendFriendMessage(steamId, message, undefined, function (...arg) {
1823
- sendMessageTimestamp = new Date().getTime();
1824
- resolve(arg);
1825
- });
1826
- });
1827
-
1828
- if (result?.[1]?.server_timestamp) {
1829
- isSendingFriendMessages = false;
1830
- return result?.[1];
1831
- } else if (result?.[0]?.message?.includes?.("RateLimitExceeded")) {
1832
- await sleep(5000);
1833
- } else {
1834
- isSendingFriendMessages = false;
1835
- return result;
1836
- }
1837
- }
1838
- isSendingFriendMessages = false;
1839
- }
1840
-
1841
- async function autoRequestFreeLicense(shouldLog = false, max = 10) {
1842
- return;
1843
- // const mCookies = await getCookiesWait()
1844
- // if (!mCookies) return
1845
- // let freeAppList = Array.isArray(steamClient.licenses) ? FreeAppList.filter(appId => steamClient.licenses.every(({package_id}) => package_id !== appId)) : FreeAppList;
1846
- const freeAppList = freeAppList.filter((appId) => ownedApps.some((app) => app.appid == appId));
1847
- const recommendedApps = _.shuffle(freeAppList);
1848
- if (max) {
1849
- recommendedApps.length = Math.min(recommendedApps.length, max);
1850
- }
1851
- try {
1852
- const response = await steamClient.requestFreeLicense(recommendedApps);
1853
- if (shouldLog) {
1854
- log(response);
1855
- }
1856
- } catch (e) {
1857
- log(e);
1858
- }
1859
- // if (Math.random() > 0.7) {
1860
- // for (const recommendedApp of recommendedApps) {
1861
- // try {
1862
- // await steamUtils.requestFreeLicense(recommendedApp)
1863
- // } catch (e) {
1864
- // }
1865
- // await sleep(2000)
1866
- // }
1867
- // } else {
1868
- // try {
1869
- // await steamClient.requestFreeLicense(recommendedApps)
1870
- // } catch (e) {
1871
- // log(e);
1872
- // }
1873
- // }
1874
-
1875
- // if (shouldLog) {
1876
- // await sleep(20000)
1877
- // const ownedAppsCount2 = (await steamUtils.getDynamicStoreUserData())?.rgOwnedApps?.length || 0
1878
- // const increaseNumber = ownedAppsCount2 - ownedAppsCount;
1879
- // log(`OwnedApps length ${ownedAppsCount2}, increase ${increaseNumber}`)
1880
- // }
1881
- }
1882
-
1883
- async function playCSGO() {
1884
- try {
1885
- await steamClient.requestFreeLicense(AppID);
1886
- await sleep(5000);
1887
- } catch (e) {}
1888
- gamesPlayed(AppID);
1889
- }
1890
-
1891
- function doFakeGameScore() {
1892
- const maxRound = Math.random() > 0.7 ? 16 : 12;
1893
- const maps = [
1894
- "ar_baggage",
1895
- "ar_dizzy",
1896
- "ar_monastery",
1897
- "ar_shoots",
1898
- "cs_agency",
1899
- "cs_assault",
1900
- "cs_italy",
1901
- "cs_militia",
1902
- "cs_office",
1903
- "de_ancient",
1904
- "de_anubis",
1905
- "de_bank",
1906
- "de_boyard",
1907
- "de_cache",
1908
- "de_canals",
1909
- "de_cbble",
1910
- "de_chalice",
1911
- "de_dust2",
1912
- "de_inferno",
1913
- "de_lake",
1914
- "de_mirage",
1915
- "de_nuke",
1916
- "de_overpass",
1917
- "de_safehouse",
1918
- // "de_shortnuke",
1919
- "de_stmarc",
1920
- "de_sugarcane",
1921
- "de_train",
1922
- "de_tuscan",
1923
- "de_vertigo",
1924
- "dz_ember",
1925
- "dz_vineyard",
1926
- "gd_cbble",
1927
- "training1",
1928
- ];
1929
-
1930
- if (richPresence.myScore === undefined) {
1931
- richPresence.myScore = _.random(0, maxRound);
1932
- }
1933
- if (richPresence.theirScore === undefined) {
1934
- richPresence.theirScore = _.random(0, maxRound);
1935
- }
1936
- if (richPresence.map === undefined) {
1937
- richPresence.map = maps[Math.floor(Math.random() * maps.length)];
1938
- }
1939
- if (richPresence.myScore === maxRound || richPresence.theirScore === maxRound) {
1940
- richPresence.myScore = 0;
1941
- richPresence.theirScore = 0;
1942
- richPresence.map = maps[Math.floor(Math.random() * maps.length)];
1943
- } else {
1944
- const isMyTeamWin = Math.random() > 0.5;
1945
- if (isMyTeamWin) {
1946
- richPresence.myScore++;
1947
- } else {
1948
- richPresence.theirScore++;
1949
- }
1950
- }
1951
-
1952
- const score = richPresence.myScore === 0 && richPresence.theirScore === 0 ? "" : `[ ${richPresence.myScore} : ${richPresence.theirScore} ]`;
1953
- steamClient.uploadRichPresence(730, {
1954
- "game:state": "game",
1955
- steam_display: "#display_GameKnownMapScore",
1956
- connect: "+gcconnectG082AA752",
1957
- version: CSGO_VER.toString(),
1958
- "game:mode": "competitive",
1959
- "game:map": richPresence.map,
1960
- "game:server": "kv",
1961
- watch: _.random(1, 5).toString(),
1962
- "game:score": score,
1963
- });
1964
- }
1965
-
1966
- function updateFakeGameScore() {
1967
- if (isFakeGameScore && getPlayingAppIds().some((a) => a == 730)) {
1968
- doSetInterval(doFakeGameScore, [60000, 180000], "uploadRichPresenceCSGO");
1969
- } else {
1970
- doClearInterval("uploadRichPresenceCSGO");
1971
- }
1972
- }
1973
-
1974
- function updateAutoRequestFreeLicense() {
1975
- if (isAutoRequestFreeLicense) {
1976
- doSetInterval(
1977
- function () {
1978
- autoRequestFreeLicense(false, 50);
1979
- },
1980
- [5 * 60000, 10 * 60000],
1981
- "autoRequestFreeLicense",
1982
- );
1983
- } else {
1984
- doClearInterval("autoRequestFreeLicense");
1985
- }
1986
- }
1987
-
1988
- function updateInvisible() {
1989
- if (isInvisible) {
1990
- steamClient.setPersona(NodeSteamUser.EPersonaState.Invisible);
1991
- state = "Invisible";
1992
- } else {
1993
- steamClient.setPersona(NodeSteamUser.EPersonaState.Online);
1994
- state = "Online";
1995
- }
1996
- }
1997
-
1998
- async function gamesPlayed(apps) {
1999
- if (!Array.isArray(apps)) {
2000
- apps = [apps];
2001
- }
2002
-
2003
- const processedApps = apps.map((app) => {
2004
- if (typeof app == "string") {
2005
- app = { game_id: "15190414816125648896", game_extra_info: app };
2006
- } else if (typeof app === "number" || typeof app != "object") {
2007
- app = { game_id: app };
2008
- }
2009
-
2010
- if (typeof app.game_ip_address == "number") {
2011
- app.game_ip_address = { v4: app.game_ip_address };
2012
- }
2013
-
2014
- return app;
2015
- });
2016
-
2017
- steamClient.gamesPlayed(processedApps);
2018
- if (processedApps.some((app) => parseInt(app.game_id) === 730)) {
2019
- await sleep(500);
2020
- await sendHello();
2021
- }
2022
- updateFakeGameScore();
2023
-
2024
- // await sleep(10000)
2025
- // self.steamUser.uploadRichPresence(730, {
2026
- // status: 'bussssss',
2027
- // 'game:state': 'lobby',
2028
- // steam_display: '#display_watch',
2029
- // currentmap: '#gamemap_de_empire',
2030
- // connect: '+gcconnectG082AA752',
2031
- // 'game:mode': 'competitive'
2032
- // })
2033
- }
2034
-
2035
- function getFriendsList() {
2036
- const methodName = "FriendsList.GetFriendsList#1";
2037
- const { users, myFriends } = steamClient; //object
2038
- /*
2039
- users
2040
- * {
2041
- rich_presence: [],
2042
- player_name: "Kei #SkinsMonkey",
2043
- avatar_hash: [123,4543],
2044
- last_logoff: "2023-05-20T05:00:42.000Z",
2045
- last_logon: "2023-05-20T05:02:16.000Z",
2046
- last_seen_online: "2023-05-20T05:00:42.000Z",
2047
- avatar_url_icon: "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/3e/3e9da0b107ac2ec384759544368a8a977359537a.jpg",
2048
- avatar_url_medium: "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/3e/3e9da0b107ac2ec384759544368a8a977359537a_medium.jpg",
2049
- avatar_url_full: "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/3e/3e9da0b107ac2ec384759544368a8a977359537a_full.jpg"
2050
- }
2051
- *
2052
-
2053
- myFriends
2054
- {
2055
- 76561198365087582: 3,
2056
- 76561199490395123: 3
2057
- }
2058
- * */
2059
- /*steamClient._send({
2060
- msg: 151,
2061
- proto: {
2062
- target_job_name: methodName
2063
- }
2064
- }, Buffer.alloc(0), function (body, hdr) {
2065
- const result = hdr.proto.eresult
2066
- const errorMessage = hdr.proto.error_message
2067
- const responseData = body.toBuffer()
2068
- console.log(`xxx`, result)
2069
- })*/
2070
-
2071
- steamClient.sendToGC(730, 767, {}, Buffer.alloc(0));
2072
- }
2073
-
2074
- async function getUserOwnedApps(steamId = steamClient.steamID) {
2075
- if (!steamId) {
2076
- return [];
2077
- }
2078
- if (typeof steamId?.getSteamID64 === "function") {
2079
- steamId = steamId.getSteamID64();
2080
- }
2081
- const isMe = steamId === steamClient.steamID.getSteamID64();
2082
- if (isMe && ownedApps.length) {
2083
- return ownedApps;
2084
- }
2085
- let result = {};
2086
- try {
2087
- result = await steamClient.getUserOwnedApps(steamId);
2088
- } catch (e) {
2089
- try {
2090
- result = await steamClient.getUserOwnedApps(steamId);
2091
- } catch (e) {
2092
- result = {};
2093
- }
2094
- }
2095
- if (isMe && Array.isArray(result.apps)) {
2096
- ownedApps.length = 0;
2097
- ownedApps.push(...result.apps);
2098
- }
2099
- return result.apps || [];
2100
- const resultExample = {
2101
- app_count: 22,
2102
- apps: [
2103
- {
2104
- content_descriptorids: [],
2105
- appid: 208030,
2106
- name: "Moon Breakers",
2107
- playtime_2weeks: null,
2108
- playtime_forever: 0,
2109
- img_icon_url: "",
2110
- has_community_visible_stats: null,
2111
- playtime_windows_forever: 0,
2112
- playtime_mac_forever: 0,
2113
- playtime_linux_forever: 0,
2114
- rtime_last_played: 0,
2115
- capsule_filename: null,
2116
- sort_as: null,
2117
- has_workshop: null,
2118
- has_market: null,
2119
- has_dlc: null,
2120
- has_leaderboards: null,
2121
- },
2122
- ],
2123
- };
2124
- }
2125
-
2126
- function getPlayingAppIds() {
2127
- return steamClient._playingAppIds || [];
2128
- }
2129
-
2130
- return {
2131
- init,
2132
- partySearch,
2133
- invite2Lobby,
2134
- createLobby,
2135
- updateLobby,
2136
- createThenInvite2Lobby,
2137
- joinLobby,
2138
- getLobbyData,
2139
- partyRegister,
2140
- requestCoPlays,
2141
- getPersonas,
2142
- getUsername() {
2143
- return username;
2144
- },
2145
- getCookies,
2146
- getCookiesWait,
2147
- getLogOnDetails() {
2148
- return steamClient?._logOnDetails;
2149
- },
2150
- onEvent,
2151
- offEvent,
2152
- offAllEvent,
2153
- setPersona(state, name) {
2154
- steamClient.setPersona(state, name);
2155
- },
2156
- sendFriendMessage,
2157
- sendFriendTyping,
2158
- getSteamClient() {
2159
- return steamClient;
2160
- },
2161
- getAccountInfoName,
2162
- getPersonaName,
2163
- async getPlayersProfile(steamId, retry = 3) {
2164
- for (let i = 0; i < retry; i++) {
2165
- const profile = await getPlayersProfile(steamId);
2166
- if (profile) {
2167
- return profile;
2168
- }
2169
- }
2170
- return null;
2171
- },
2172
- autoRequestFreeLicense,
2173
- playCSGO,
2174
- doSetInterval,
2175
- doClearIntervals,
2176
- gamesPlayed,
2177
- sendHello,
2178
- checkPlayerPrimeStatus,
2179
- doClearInterval,
2180
- gamePlay,
2181
- autoGamePlay,
2182
- offAutoGamePlay,
2183
- updateAutoGamePlay,
2184
- getFriendsList,
2185
- setIsPartyRegister(change) {
2186
- change = !!change;
2187
- if (isPartyRegister !== change) {
2188
- isPartyRegister = change;
2189
- if (!isPartyRegister) {
2190
- doClearInterval("autoPartyRegister");
2191
- } else {
2192
- sendHello();
2193
- }
2194
- }
2195
- },
2196
- setAutoPlay(change) {
2197
- change = !!change;
2198
- if (isAutoPlay !== change) {
2199
- isAutoPlay = change;
2200
- updateAutoGamePlay();
2201
- }
2202
- },
2203
- setIsInvisible(change) {
2204
- change = !!change;
2205
- if (isInvisible !== change) {
2206
- isInvisible = change;
2207
- updateInvisible();
2208
- }
2209
- },
2210
- setFakeGameScore(change) {
2211
- change = !!change;
2212
- if (isFakeGameScore !== change) {
2213
- isFakeGameScore = change;
2214
- updateFakeGameScore();
2215
- }
2216
- },
2217
- setAutoRequestFreeLicense(change) {
2218
- change = !!change;
2219
- if (isAutoRequestFreeLicense !== change) {
2220
- isAutoRequestFreeLicense = change;
2221
- updateAutoRequestFreeLicense();
2222
- }
2223
- },
2224
- getState() {
2225
- return state;
2226
- },
2227
- log,
2228
- isPrime() {
2229
- return prime === true;
2230
- },
2231
- getFriendList,
2232
- logOff,
2233
- isPlayingBlocked() {
2234
- return playingBlocked;
2235
- },
2236
- async getChatHistory(steamId) {
2237
- if (!steamClient.steamID) return [];
2238
- const mySteamId = typeof steamClient.steamID.getSteamID64 === "function" ? steamClient.steamID.getSteamID64() : steamClient.steamID;
2239
- return new Promise((resolve) => {
2240
- setTimeout(resolve, 90000);
2241
- steamClient.getChatHistory(steamId, async function (error, result) {
2242
- const messages = (result || []).map(function (msg) {
2243
- const fromSteamId = typeof msg.steamID?.getSteamID64 === "function" ? msg.steamID.getSteamID64() : msg.steamID;
2244
- return {
2245
- message: msg.message,
2246
- from: fromSteamId,
2247
- to: fromSteamId == mySteamId ? steamId : mySteamId,
2248
- _id: new Date(msg.timestamp).getTime().toString(),
2249
- timestamp: new Date(msg.timestamp).getTime(),
2250
- isMe: fromSteamId !== steamId,
2251
- };
2252
- });
2253
- resolve(messages);
2254
- });
2255
- });
2256
- },
2257
- onAnyEvent,
2258
- async redeemGift(gid) {
2259
- try {
2260
- const community = new SteamCommunity();
2261
- let cookies = await getCookiesWait();
2262
- community.setCookies(typeof cookies === "string" ? cookies.split(";") : cookies);
2263
- community.redeemGift(gid);
2264
- } catch (e) {}
2265
- },
2266
- async requestFreeLicense(...args) {
2267
- try {
2268
- return await steamClient.requestFreeLicense(...args);
2269
- } catch (e) {}
2270
- },
2271
- getSteamId() {
2272
- try {
2273
- return steamClient.steamID.getSteamID64();
2274
- } catch (e) {}
2275
- },
2276
- getLastTimePartyRegister() {
2277
- return lastTimePartyRegister;
2278
- },
2279
- getLastTimePartySearch() {
2280
- return lastTimePartySearch;
2281
- },
2282
- getLicenses() {
2283
- return steamClient.licenses;
2284
- const exampleLicenses = [
2285
- {
2286
- package_id: 303386,
2287
- time_created: 1680491335,
2288
- time_next_process: 0,
2289
- minute_limit: 0,
2290
- minutes_used: 0,
2291
- payment_method: 1024,
2292
- flags: 512,
2293
- purchase_country_code: "VN",
2294
- license_type: 1,
2295
- territory_code: 0,
2296
- change_number: 20615891,
2297
- owner_id: 1530068060,
2298
- initial_period: 0,
2299
- initial_time_unit: 0,
2300
- renewal_period: 0,
2301
- renewal_time_unit: 0,
2302
- access_token: "8049398090486337961",
2303
- master_package_id: null,
2304
- },
2305
- ];
2306
- },
2307
- uploadRichPresence(appid, richPresence) {
2308
- const _richPresence = Array.isArray(richPresence)
2309
- ? richPresence.reduce(function (previousValue, currentValue, currentIndex, array) {
2310
- if (currentValue.key) {
2311
- previousValue[currentValue.key] = currentValue.value?.toString() || "";
2312
- }
2313
- return previousValue;
2314
- }, {})
2315
- : richPresence;
2316
- steamClient.uploadRichPresence(appid, _richPresence);
2317
- },
2318
- getUserOwnedApps,
2319
- getPlayingAppIds,
2320
- getCurrentLobby() {
2321
- return currentLobby;
2322
- },
2323
- setGame(_games) {
2324
- games = _games;
2325
- },
2326
- };
2327
- }
2328
-
2329
- export default SteamClient;
2330
-
2331
- export function increaseCSGO_VER() {
2332
- return ++CSGO_VER;
2333
- }
2334
-
2335
- SteamClient.isAccountPlayable = async function isAccountPlayable({ cookie, clientJsToken, timeoutMs, onPlayable, onNotPlayable, ...rest }) {
2336
- if (!clientJsToken && cookie) {
2337
- clientJsToken = await new SteamUser(typeof cookie === "function" ? await cookie() : cookie).getClientJsToken();
2338
- }
2339
- if (clientJsToken?.logged_in !== true) {
2340
- if (typeof onNotPlayable === "function") {
2341
- await onNotPlayable(null);
2342
- }
2343
- return { invalidClientJsToken: true };
2344
- }
2345
- return await new Promise((resolve) => {
2346
- const timeouts = [
2347
- setTimeout(() => {
2348
- doResolve({ timedOut: true });
2349
- }, timeoutMs || 30000),
2350
- ];
2351
-
2352
- const steamClient = new SteamClient({
2353
- isFakeGameScore: false,
2354
- isAutoPlay: true,
2355
- isPartyRegister: false,
2356
- isInvisible: true,
2357
- MAX_GAME_PLAY: 10,
2358
- games: 730,
2359
- clientJsToken,
2360
- ...rest,
2361
- });
2362
-
2363
- steamClient.onEvent("error", ({ eresult, msg, error }) => {
2364
- doResolve({ eresult, msg, error });
2365
- });
2366
-
2367
- steamClient.onEvent("csgoOnline", (ClientWelcome) => {
2368
- doResolve({ playable: true });
2369
- });
2370
-
2371
- steamClient.onEvent("csgoClientHello", (ClientHello) => {
2372
- doResolve({ playable: true });
2373
- });
2374
-
2375
- steamClient.onEvent("playingState", ({ playing_blocked, playing_app }) => {
2376
- if (playing_blocked) {
2377
- doResolve({ playable: false });
2378
- } else {
2379
- timeouts.push(
2380
- setTimeout(function () {
2381
- const isBlocked = steamClient.isPlayingBlocked();
2382
- doResolve({ playable: !isBlocked });
2383
- }, 5000),
2384
- );
2385
- }
2386
- });
2387
-
2388
- // steamClient.onEvent("fatalError", () => {
2389
- // doResolve();
2390
- // });
2391
-
2392
- steamClient.init();
2393
-
2394
- async function doResolve(data) {
2395
- timeouts.forEach((timeout) => clearTimeout(timeout));
2396
- steamClient.doClearIntervals();
2397
- steamClient.offAllEvent();
2398
-
2399
- if (data?.playable === true) {
2400
- if (typeof onPlayable === "function") {
2401
- try {
2402
- await onPlayable(steamClient);
2403
- } catch (e) {}
2404
- }
2405
- } else {
2406
- if (typeof onNotPlayable === "function") {
2407
- try {
2408
- await onNotPlayable(steamClient);
2409
- } catch (e) {}
2410
- }
2411
- }
2412
-
2413
- steamClient.logOff();
2414
- return resolve(data);
2415
- }
2416
- });
2417
- };
1
+ import NodeSteamUser from "steam-user";
2
+ import _ from "lodash";
3
+ import fs from "fs";
4
+ import { protoDecode, protoEncode } from "./helpers/util.js";
5
+ import SteamID from "steamid";
6
+ import FriendCode from "csgo-friendcode";
7
+ import axios from "axios";
8
+ import helpers, { loadProfos } from "./helpers/protos.js";
9
+ import { fileURLToPath } from "url";
10
+ import path from "path";
11
+ import SteamUser from "./index.js";
12
+ import { v4 as uuidv4 } from "uuid";
13
+ import EFriendRelationship from "steam-user/enums/EFriendRelationship.js";
14
+ import SteamCommunity from "steamcommunity";
15
+ import moment from "moment-timezone";
16
+ import { encode, encodeUids } from "./bufferHelpers.js";
17
+
18
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
19
+
20
+ const Protos = helpers([
21
+ {
22
+ name: "csgo",
23
+ protos: loadProfos(`${__dirname}/protos/`),
24
+ },
25
+ ]);
26
+
27
+ export const RANKS = {
28
+ 0: "Unranked",
29
+ 1: "Silver I",
30
+ 2: "Silver II",
31
+ 3: "Silver III",
32
+ 4: "Silver IV",
33
+ 5: "Silver Elite",
34
+ 6: "Silver Elite Master",
35
+ 7: "Gold Nova I",
36
+ 8: "Gold Nova II",
37
+ 9: "Gold Nova III",
38
+ 10: "Gold Nova Master",
39
+ 11: "Master Guardian I",
40
+ 12: "Master Guardian II",
41
+ 13: "Master Guardian Elite",
42
+ 14: "Distinguished Master Guardian",
43
+ 15: "Legendary Eagle",
44
+ 16: "Legendary Eagle Master",
45
+ 17: "Supreme Master First Class",
46
+ 18: "The Global Elite",
47
+ };
48
+ export const LOCS = {
49
+ 20054: "VN",
50
+ 23115: "KZ",
51
+ 20041: "IN",
52
+ 20035: "CN",
53
+ 17474: "BD",
54
+ 17481: "ID",
55
+ 22861: "MY",
56
+ 18516: "TH",
57
+ 22356: "TW",
58
+ 21067: "KR",
59
+ 19272: "HK",
60
+ 18512: "PH",
61
+ 21842: "RU",
62
+ 16716: "LA",
63
+ 20558: "NP",
64
+ 18259: "SG",
65
+ 19789: "MM",
66
+ 20045: "MN",
67
+ 18251: "KG",
68
+ 18507: "KH",
69
+ 22605: "MX",
70
+ 19280: "PK",
71
+ 20301: "HK/MO", //hongkong or macau
72
+ 21333: "Unknown",
73
+ 21825: "AU",
74
+ 20034: "Unkown",
75
+ };
76
+
77
+ const AppID = 730;
78
+ export let CSGO_VER = 13960;
79
+ export const FreeAppList = JSON.parse(fs.readFileSync(path.join(__dirname, "free_packages.json"))).packages;
80
+
81
+ SteamUser.getAppVersion(AppID).then(function (ver) {
82
+ CSGO_VER = ver;
83
+ });
84
+
85
+ const PersonasCache = [];
86
+ let isSendingFriendMessages = false;
87
+
88
+ function SteamClient({ username, password, cookie, clientJsToken, isAutoRequestFreeLicense = true, isFakeGameScore = true, isPartyRegister = true, isAutoPlay = false, isInvisible = false, autoAcceptTradeRequest = false, autoReconnect = true, MAX_GAME_PLAY = 10, games = null }) {
89
+ const steamClient = new NodeSteamUser();
90
+ let prime = null;
91
+ let state = "Offline"; //InGame, Online, Invisible
92
+ let isLogOff = false;
93
+ let playingBlocked = null;
94
+ const richPresence = {};
95
+ let sendMessageTimestamp = 0;
96
+ let lastTimePartyRegister = 0;
97
+ let lastTimePartySearch = 0;
98
+ const ownedApps = [];
99
+ let logOffEvent = null;
100
+
101
+ const currentLobby = {
102
+ lobbyID: null,
103
+ timestamp: 0,
104
+ };
105
+
106
+ const onAnyCallbacks = [];
107
+
108
+ const events = {
109
+ user: [],
110
+ loggedOn: [],
111
+ csgoOnline: [],
112
+ csgoClientHello: [],
113
+ webSession: [],
114
+ friendMessage: [],
115
+ friendTyping: [],
116
+ disconnected: [],
117
+ error: [],
118
+ playersProfile: [],
119
+ fatalError: [],
120
+ partyInvite: [],
121
+ friendRelationship: [],
122
+ tradeOffers: [],
123
+ offlineMessages: [],
124
+ friendsList: [],
125
+ gifts: [],
126
+ playingState: [],
127
+ emailInfo: [],
128
+ accountLimitations: [],
129
+ };
130
+
131
+ const gcCallback = {};
132
+
133
+ function pushGCCallback(name, cb, timeout) {
134
+ if (!gcCallback[name]) {
135
+ gcCallback[name] = {};
136
+ }
137
+ let t = null;
138
+ let id = uuidv4();
139
+
140
+ function callback(...arg) {
141
+ if (t) {
142
+ clearTimeout(t);
143
+ }
144
+ delete gcCallback[name][id];
145
+ cb?.apply(null, arg);
146
+ }
147
+
148
+ if (timeout) {
149
+ t = setTimeout(callback, timeout);
150
+ }
151
+ gcCallback[name][id] = callback;
152
+ }
153
+
154
+ function callGCCallback(name, ...arg) {
155
+ if (gcCallback[name]) {
156
+ for (const id in gcCallback[name]) {
157
+ gcCallback[name][id]?.(...arg);
158
+ }
159
+ }
160
+ }
161
+
162
+ function callEvent(_events, data) {
163
+ const eventName = Object.keys(events).find((eventName) => events[eventName] === _events);
164
+ eventName && onAnyCallbacks.forEach((cb) => cb?.({ eventName, data }));
165
+
166
+ _events?.forEach?.((e) => {
167
+ e.callback?.(data);
168
+ e.timeout && clearTimeout(e.timeout);
169
+ delete e.timeout;
170
+ if (e.once) {
171
+ delete e.callback;
172
+ }
173
+ });
174
+ _.remove(_events, (e) => !e || e?.once);
175
+ }
176
+
177
+ function onEvent(name, callback, once, timeout) {
178
+ if (!events[name]) {
179
+ events[name] = [];
180
+ }
181
+ const t = timeout ? setTimeout(callback, timeout) : null;
182
+ events[name].push({
183
+ once,
184
+ callback,
185
+ timeout: t,
186
+ });
187
+ }
188
+
189
+ function offEvent(name) {
190
+ if (Array.isArray(events[name])) {
191
+ for (const eventElement of events[name]) {
192
+ if (eventElement.timeout) {
193
+ clearTimeout(eventElement.timeout);
194
+ }
195
+ }
196
+ }
197
+
198
+ delete events[name];
199
+ }
200
+
201
+ function onAnyEvent(callback) {
202
+ onAnyCallbacks.push(callback);
203
+ }
204
+
205
+ function offAllEvent() {
206
+ for (const name in events) {
207
+ for (const event of events[name]) {
208
+ if (event.timeout) {
209
+ try {
210
+ clearTimeout(event.timeout);
211
+ } catch (e) {}
212
+ delete event.timeout;
213
+ }
214
+ }
215
+ delete events[name];
216
+ }
217
+ onAnyCallbacks.length = 0;
218
+ }
219
+
220
+ const intervals = {};
221
+ const intervalRandoms = {};
222
+
223
+ function doSetInterval(cb, timeout, key) {
224
+ const isRandom = Array.isArray(timeout);
225
+ if (!key) {
226
+ key = uuidv4();
227
+ }
228
+ if (isRandom) {
229
+ if (intervalRandoms[key] !== undefined) {
230
+ try {
231
+ clearTimeout(intervalRandoms[key]);
232
+ } catch (e) {}
233
+ }
234
+ intervalRandoms[key] = setTimeout(
235
+ function () {
236
+ doSetInterval(cb, timeout, key);
237
+ if (state !== "Offline") {
238
+ cb();
239
+ }
240
+ },
241
+ _.random(timeout[0], timeout[1]),
242
+ );
243
+ } else {
244
+ if (intervals[key] !== undefined) {
245
+ try {
246
+ clearInterval(intervals[key]);
247
+ } catch (e) {}
248
+ }
249
+
250
+ intervals[key] = setInterval(function () {
251
+ if (state !== "Offline") {
252
+ cb();
253
+ }
254
+ }, timeout);
255
+ }
256
+
257
+ return key;
258
+ }
259
+
260
+ function doClearIntervals() {
261
+ for (const key in intervals) {
262
+ clearInterval(intervals[key]);
263
+ delete intervals[key];
264
+ }
265
+ for (const key in intervalRandoms) {
266
+ clearTimeout(intervalRandoms[key]);
267
+ delete intervalRandoms[key];
268
+ }
269
+ }
270
+
271
+ function doClearInterval(key) {
272
+ try {
273
+ clearInterval(intervals[key]);
274
+ } catch (e) {}
275
+ delete intervals[key];
276
+
277
+ try {
278
+ clearTimeout(intervalRandoms[key]);
279
+ } catch (e) {}
280
+ delete intervalRandoms[key];
281
+ }
282
+
283
+ function getAccountInfoName() {
284
+ return [steamClient?.accountInfo?.name, steamClient?._logOnDetails?.account_name].filter(Boolean).join(" - ");
285
+ }
286
+
287
+ function getPersonaName() {
288
+ return steamClient?.accountInfo?.name;
289
+ }
290
+
291
+ function log(...msg) {
292
+ const now = moment().tz("Asia/Ho_Chi_Minh").format("DD/MM/YYYY HH:mm:ss");
293
+ console.log(`[${now}] [${getAccountInfoName()}]`, ...msg);
294
+ }
295
+
296
+ async function getPersonas(steamIDs) {
297
+ steamIDs = steamIDs.map((steamId) => (steamId instanceof SteamID ? steamId.getSteamID64() : steamId));
298
+ const notCachesteamIDs = steamIDs.filter((id) => !PersonasCache.some((p) => p.id == id));
299
+ const cachedPersonas = PersonasCache.filter((p) => steamIDs.includes(p.id));
300
+
301
+ if (notCachesteamIDs.length) {
302
+ let personas = null;
303
+ try {
304
+ personas = (await steamClient.getPersonas(notCachesteamIDs))?.personas;
305
+ } catch (e) {}
306
+ if (!personas || !Object.keys(personas).length) {
307
+ try {
308
+ personas = (await steamClient.getPersonas(notCachesteamIDs))?.personas;
309
+ } catch (e) {}
310
+ }
311
+ if (!personas || !Object.keys(personas).length) {
312
+ try {
313
+ personas = (await steamClient.getPersonas(notCachesteamIDs))?.personas;
314
+ } catch (e) {}
315
+ }
316
+ if (personas && Object.keys(personas).length) {
317
+ for (let sid64 in personas) {
318
+ personas[sid64].id = sid64;
319
+ personas[sid64].avatar_hash = Buffer.from(personas[sid64].avatar_hash).toString("hex");
320
+ PersonasCache.push(personas[sid64]);
321
+ cachedPersonas.push(personas[sid64]);
322
+ }
323
+ }
324
+ }
325
+
326
+ while (PersonasCache.length > 500) {
327
+ PersonasCache.shift();
328
+ }
329
+ return cachedPersonas;
330
+ }
331
+
332
+ function sleep(ms) {
333
+ return new Promise((resolve) => {
334
+ setTimeout(resolve, ms);
335
+ });
336
+ }
337
+
338
+ function getCookies() {
339
+ return cookie || steamClient?.webSession?.cookies?.join?.(";");
340
+ }
341
+
342
+ async function getCookiesWait() {
343
+ return (
344
+ getCookies() ||
345
+ new Promise((resolve) => {
346
+ onEvent(
347
+ "webSession",
348
+ function (webSession) {
349
+ resolve(webSession?.cookies);
350
+ },
351
+ true,
352
+ 30000,
353
+ );
354
+ })
355
+ );
356
+ }
357
+
358
+ async function gamePlay() {
359
+ if ((Array.isArray(games) && games.length) || (games && (typeof games === "number" || typeof games === "string"))) {
360
+ return gamesPlayed(games);
361
+ }
362
+
363
+ let ownedApps = [];
364
+ for (let i = 0; i < 5; i++) {
365
+ ownedApps = await getUserOwnedApps();
366
+ if (ownedApps?.length) {
367
+ break;
368
+ }
369
+ }
370
+ if (!ownedApps?.length) {
371
+ gamesPlayed(730);
372
+ } else {
373
+ ownedApps = ownedApps.map(({ appid }) => appid);
374
+ ownedApps = _.shuffle(ownedApps);
375
+ ownedApps.length = Math.min(ownedApps.length, MAX_GAME_PLAY - 1);
376
+ _.remove(ownedApps, (app) => app == 730);
377
+ gamesPlayed([...ownedApps, 730]);
378
+ }
379
+ }
380
+
381
+ async function autoGamePlay() {
382
+ await gamePlay();
383
+ doSetInterval(gamePlay, [15 * 60000, 30 * 60000], "autoGamePlay");
384
+ }
385
+
386
+ async function offAutoGamePlay() {
387
+ steamClient.gamesPlayed([]);
388
+ doClearInterval("autoGamePlay");
389
+ }
390
+
391
+ async function updateAutoGamePlay() {
392
+ if (isAutoPlay) {
393
+ autoGamePlay();
394
+ } else {
395
+ offAutoGamePlay();
396
+ }
397
+ }
398
+
399
+ /**
400
+ * Get a list of lobbies (* = Unsure description could be wrong)
401
+ * @param {Number} ver Game version we are searching for
402
+ * @param {Boolean} apr Prime or not*
403
+ * @param {Number} ark Rank multiplied by 10*
404
+ * @param {Array.<Number>} grps *
405
+ * @param {Number} launcher If we are using the China CSGO launcher or not*
406
+ * @param {Number} game_type Game type, 8 Competitive, 10 Wingman
407
+ * @returns {Promise.<Object>}
408
+ */
409
+ async function partySearch({ prime = false, game_type = "Competitive", rank = "Silver Elite", timeout = 5000 } = {}) {
410
+ const players = await new Promise((resolve) => {
411
+ steamClient.sendToGC(
412
+ AppID,
413
+ Protos.csgo.ECsgoGCMsg.k_EMsgGCCStrike15_v2_Party_Search,
414
+ {},
415
+ protoEncode(Protos.csgo.CMsgGCCStrike15_v2_Party_Search, {
416
+ ver: CSGO_VER,
417
+ apr: prime ? 1 : 0,
418
+ ark: parseInt(Object.keys(RANKS).find((k) => RANKS[k] === rank)) * 10,
419
+ grps: [],
420
+ launcher: 0,
421
+ game_type: game_type === "Competitive" ? 8 : 10,
422
+ }),
423
+ );
424
+ lastTimePartySearch = new Date().getTime();
425
+ pushGCCallback("partySearch", resolve, timeout);
426
+ });
427
+ if (Array.isArray(players) && players.length) {
428
+ const personas = await getPersonas(players.map((p) => p.steamId));
429
+ for (const player of players) {
430
+ const persona = personas.find((p) => p.id == player.steamId);
431
+ if (persona) {
432
+ player.player_name = persona.player_name;
433
+ player.avatar_hash = persona.avatar_hash;
434
+ }
435
+ }
436
+ }
437
+ return players;
438
+ }
439
+
440
+ async function createLobby() {
441
+ if (!steamClient.steamID) {
442
+ return;
443
+ }
444
+
445
+ return new Promise((resolve) => {
446
+ const timeout = setTimeout(function () {
447
+ resolve();
448
+ }, 30000);
449
+
450
+ steamClient._send(
451
+ {
452
+ msg: Protos.csgo.EMsg.k_EMsgClientMMSCreateLobby,
453
+ proto: {
454
+ steamid: steamClient.steamID.getSteamID64(),
455
+ routing_appid: 730,
456
+ },
457
+ },
458
+ protoEncode(Protos.csgo.CMsgClientMMSCreateLobby, {
459
+ app_id: 730,
460
+ max_members: 1,
461
+ lobby_type: 1,
462
+ lobby_flags: 1,
463
+ }),
464
+ function (payload) {
465
+ clearTimeout(timeout);
466
+ const result = protoDecode(Protos.csgo.CMsgClientMMSCreateLobbyResponse, payload.toBuffer());
467
+ const steam_id_lobby = result.steam_id_lobby.toString();
468
+ currentLobby.lobbyID = steam_id_lobby;
469
+ currentLobby.timestamp = new Date().getTime();
470
+ resolve(steam_id_lobby);
471
+ },
472
+ );
473
+ });
474
+
475
+ // return await getHandlerResult(Protos.csgo.EMsg.k_EMsgClientMMSCreateLobbyResponse, function (payload) {
476
+ // const result = protoDecode(Protos.csgo.CMsgClientMMSCreateLobbyResponse, payload.toBuffer())
477
+ // return result.steam_id_lobby.toString()
478
+ // })
479
+
480
+ // steamClient.sendToGC(730, Protos.csgo.EMsg.k_EMsgClientMMSCreateLobby, {
481
+ // steamid: steamClient.steamID,
482
+ // routing_appid: 730,
483
+ // }, protoEncode(Protos.csgo.CMsgClientMMSCreateLobby, {
484
+ // app_id: 730,
485
+ // max_members: 1,
486
+ // lobby_type: 1,
487
+ // lobby_flags: 1
488
+ // }))
489
+ }
490
+
491
+ async function updateLobby(lobbyID) {
492
+ if (!steamClient.steamID) {
493
+ return;
494
+ }
495
+
496
+ return new Promise((resolve) => {
497
+ const timeout = setTimeout(function () {
498
+ resolve();
499
+ }, 30000);
500
+
501
+ steamClient._send(
502
+ {
503
+ msg: Protos.csgo.EMsg.k_EMsgClientMMSSetLobbyData,
504
+ proto: {
505
+ steamid: steamClient.steamID.getSteamID64(),
506
+ routing_appid: 730,
507
+ },
508
+ },
509
+ protoEncode(Protos.csgo.CMsgClientMMSSetLobbyData, {
510
+ app_id: 730,
511
+ steam_id_lobby: lobbyID,
512
+ steam_id_member: "0",
513
+ max_members: 10,
514
+ lobby_type: 1,
515
+ lobby_flags: 1,
516
+ metadata: encode(
517
+ {
518
+ "game:ark": "0",
519
+ // Country/Message
520
+ "game:loc": "",
521
+ "game:mapgroupname": "mg_de_mirage",
522
+ "game:mode": "competitive",
523
+ "game:prime": "1",
524
+ "game:type": "classic",
525
+ "members:numPlayers": "1",
526
+ "options:action": "custommatch",
527
+ "options:anytypemode": "0",
528
+ "system:access": "private",
529
+ "system:network": "LIVE",
530
+ uids: [steamClient.steamID],
531
+ },
532
+ [0x00, 0x00],
533
+ [0x08],
534
+ { uids: encodeUids },
535
+ ).toBuffer(),
536
+ }),
537
+ function (payload) {
538
+ clearTimeout(timeout);
539
+ const result = protoDecode(Protos.csgo.CMsgClientMMSSetLobbyDataResponse, payload.toBuffer());
540
+ const steam_id_lobby = result.steam_id_lobby.toString();
541
+ currentLobby.lobbyID = steam_id_lobby;
542
+ currentLobby.timestamp = new Date().getTime();
543
+ resolve(steam_id_lobby);
544
+ },
545
+ );
546
+ });
547
+
548
+ // return await getHandlerResult(Protos.csgo.EMsg.k_EMsgClientMMSSetLobbyDataResponse, function (payload) {
549
+ // const result = protoDecode(Protos.csgo.CMsgClientMMSSetLobbyDataResponse, payload.toBuffer())
550
+ // return result.steam_id_lobby.toString()
551
+ // })
552
+ }
553
+
554
+ async function invite2Lobby(lobbyID, steamId) {
555
+ if (!steamClient.steamID) {
556
+ return;
557
+ }
558
+
559
+ steamClient._send(
560
+ {
561
+ msg: Protos.csgo.EMsg.k_EMsgClientMMSInviteToLobby,
562
+ proto: {
563
+ steamid: steamClient.steamID.getSteamID64(),
564
+ routing_appid: 730,
565
+ },
566
+ },
567
+ protoEncode(Protos.csgo.CMsgClientMMSInviteToLobby, {
568
+ app_id: 730,
569
+ steam_id_lobby: lobbyID,
570
+ steam_id_user_invited: steamId,
571
+ }),
572
+ );
573
+
574
+ // lobbyID = new SteamID(lobbyID).accountid;
575
+
576
+ // Protos.csgo.EMsg.k_EMsgGCHInviteUserToLobby
577
+ // Protos.csgo.EMsg.k_EMsgClientMMSInviteToLobby
578
+ // steamClient.sendToGC(730, Protos.csgo.EMsg.k_EMsgClientMMSInviteToLobby, {}, protoEncode(Protos.csgo.CMsgClientMMSInviteToLobby, {
579
+ // app_id: 730,
580
+ // steam_id_lobby: lobbyID,
581
+ // steam_id_user_invited: accountid,
582
+ // }), function (...args) {
583
+ // console.log("invite2Lobby response", args)
584
+ // })
585
+ }
586
+
587
+ async function createThenInvite2Lobby(steamIds, onInvite) {
588
+ if (!steamClient.steamID) {
589
+ return;
590
+ }
591
+
592
+ if (!Array.isArray(steamIds)) {
593
+ steamIds = [steamIds];
594
+ }
595
+
596
+ let lobbyID = null;
597
+ if (currentLobby.lobbyID && currentLobby.timestamp > new Date().getTime() - 30000) {
598
+ //30 seconds
599
+ lobbyID = currentLobby.lobbyID;
600
+ } else {
601
+ lobbyID = await createLobby();
602
+ lobbyID = await updateLobby(lobbyID);
603
+ }
604
+
605
+ for (const steamId of steamIds) {
606
+ onInvite?.(lobbyID, steamId);
607
+ await invite2Lobby(lobbyID, steamId);
608
+ }
609
+
610
+ return lobbyID;
611
+ }
612
+
613
+ async function getLobbyData(lobbyID) {
614
+ if (!steamClient.steamID) {
615
+ return;
616
+ }
617
+
618
+ return new Promise((resolve) => {
619
+ const timeout = setTimeout(function () {
620
+ resolve();
621
+ }, 30000);
622
+
623
+ steamClient._send(
624
+ {
625
+ msg: Protos.csgo.EMsg.k_EMsgClientMMSGetLobbyData,
626
+ proto: {
627
+ steamid: steamClient.steamID.getSteamID64(),
628
+ routing_appid: 730,
629
+ },
630
+ },
631
+ protoEncode(Protos.csgo.CMsgClientMMSGetLobbyData, {
632
+ app_id: 730,
633
+ steam_id_lobby: lobbyID.toString(),
634
+ }),
635
+ function (payload) {
636
+ clearTimeout(timeout);
637
+ const result = protoDecode(Protos.csgo.CMsgClientMMSLobbyData, payload.toBuffer());
638
+ result.steam_id_lobby = result.steam_id_lobby.toString();
639
+ resolve(result);
640
+ },
641
+ );
642
+ });
643
+ }
644
+
645
+ async function joinLobby(lobbyID) {
646
+ log("joinLobby", lobbyID); //SteamID.fromIndividualAccountID(lobbyId).accountid
647
+
648
+ steamClient._send(
649
+ {
650
+ msg: Protos.csgo.EMsg.k_EMsgClientMMSJoinLobby,
651
+ proto: {
652
+ steamid: steamClient.steamID.getSteamID64(),
653
+ routing_appid: 730,
654
+ },
655
+ }, //CMsgClientMMSUserJoinedLobby CMsgClientMMSJoinLobby
656
+ protoEncode(Protos.csgo.CMsgClientMMSJoinLobby, {
657
+ app_id: 730,
658
+ steam_id_lobby: lobbyID,
659
+ persona_name: steamClient.accountInfo.name,
660
+ }),
661
+ function (payload) {
662
+ const result = protoDecode(Protos.csgo.CMsgClientMMSJoinLobbyResponse, payload.toBuffer());
663
+ result.steam_id_lobby = result.steam_id_lobby.toString();
664
+ result.steam_id_owner = result.steam_id_owner.toString();
665
+ console.log(result);
666
+ const resultExample = {
667
+ members: [],
668
+ app_id: 730,
669
+ steam_id_lobby: "3641224920",
670
+ chat_room_enter_response: 2,
671
+ max_members: 0,
672
+ lobby_type: 0,
673
+ lobby_flags: 0,
674
+ steam_id_owner: "0",
675
+ metadata: null, //Buffer
676
+ };
677
+ },
678
+ );
679
+ }
680
+
681
+ async function sendHello() {
682
+ steamClient.sendToGC(AppID, Protos.csgo.ECsgoGCMsg.k_EMsgGCCStrike15_v2_MatchmakingClient2GCHello, {}, Buffer.alloc(0));
683
+ // steamClient.sendToGC(AppID, Protos.csgo.EGCBaseClientMsg.k_EMsgGCClientHello, {}, Buffer.alloc(0));
684
+
685
+ steamClient.sendToGC(
686
+ AppID,
687
+ Protos.csgo.EGCBaseClientMsg.k_EMsgGCClientHello,
688
+ {},
689
+ protoEncode(Protos.csgo.CMsgClientHello, {
690
+ version: 2000258, //get from https://github.com/SteamDatabase/GameTracking-CS2/commits
691
+ client_session_need: 0,
692
+ client_launcher: 0,
693
+ steam_launcher: 0,
694
+ }),
695
+ );
696
+ }
697
+
698
+ async function requestCoPlays() {
699
+ return new Promise((resolve) => {
700
+ steamClient.sendToGC(AppID, Protos.csgo.ECsgoGCMsg.k_EMsgGCCStrike15_v2_Account_RequestCoPlays, {}, Buffer.alloc(0));
701
+ pushGCCallback("RequestCoPlays", resolve, 30000);
702
+ });
703
+ }
704
+
705
+ function bindEvent() {
706
+ const _events = {
707
+ async disconnected(eresult, msg) {
708
+ state = "Offline";
709
+ log("disconnected", eresult, msg);
710
+
711
+ callEvent(events.disconnected, { eresult, msg });
712
+
713
+ if (["ServiceUnavailable", "NoConnection"].includes(msg) && autoReconnect && !isLogOff) {
714
+ async function relogin(retry) {
715
+ if (isLogOff) {
716
+ console.error("Cannot relogin (logoff)");
717
+ return false;
718
+ } else if (retry <= 0) {
719
+ console.error("Cannot relogin");
720
+ return false;
721
+ } else {
722
+ const isSuccess = await login(true);
723
+ if (isSuccess) {
724
+ const loggedOnResponse = await new Promise((resolve) => {
725
+ onEvent("loggedOn", resolve, true, 180000);
726
+ });
727
+ if (loggedOnResponse) {
728
+ console.log("Relogin success");
729
+ return true;
730
+ } else {
731
+ const isLogOff = await new Promise((resolve, reject) => {
732
+ logOffEvent = resolve;
733
+ setTimeout(resolve, 120000);
734
+ });
735
+ logOffEvent = null;
736
+ if (isLogOff === true) {
737
+ return false;
738
+ }
739
+ return await relogin(retry - 1);
740
+ }
741
+ } else {
742
+ const isLogOff = await new Promise((resolve, reject) => {
743
+ logOffEvent = resolve;
744
+ setTimeout(resolve, 120000);
745
+ });
746
+ logOffEvent = null;
747
+ if (isLogOff === true) {
748
+ return false;
749
+ }
750
+ return await relogin(retry - 1);
751
+ }
752
+ }
753
+ }
754
+
755
+ const isLogOff = await new Promise((resolve, reject) => {
756
+ logOffEvent = resolve;
757
+ setTimeout(resolve, 60000);
758
+ });
759
+ logOffEvent = null;
760
+ if (isLogOff === true) {
761
+ offAllEvent();
762
+ doClearIntervals();
763
+ } else {
764
+ const isSuccess = await relogin(50);
765
+ if (!isSuccess) {
766
+ offAllEvent();
767
+ doClearIntervals();
768
+ }
769
+ }
770
+ } else {
771
+ offAllEvent();
772
+ doClearIntervals();
773
+ }
774
+ },
775
+ async error(e) {
776
+ let errorStr = "";
777
+ switch (e.eresult) {
778
+ case 5:
779
+ errorStr = "Invalid Password";
780
+ break;
781
+ case 6:
782
+ case 34:
783
+ errorStr = "Logged In Elsewhere";
784
+ break;
785
+ case 84:
786
+ errorStr = "Rate Limit Exceeded";
787
+ break;
788
+ case 65:
789
+ errorStr = "steam guard is invalid";
790
+ break;
791
+ default:
792
+ errorStr = `Unknown: ${e.eresult}`;
793
+ break;
794
+ }
795
+ log(`error [isLogOff: ${isLogOff}]`, e?.message);
796
+ doClearIntervals();
797
+ callEvent(events.error, { eresult: e.eresult, msg: e.message, error: errorStr });
798
+ },
799
+ async webSession(sessionID, cookies) {
800
+ const webSession = { sessionID, cookies };
801
+ steamClient.webSession = webSession;
802
+ callEvent(events.webSession, webSession);
803
+ },
804
+ async receivedFromGC(appid, msgType, payload) {
805
+ const key = getECsgoGCMsgKey(msgType);
806
+ switch (msgType) {
807
+ case Protos.csgo.EMsg.k_EMsgClientChatInvite: {
808
+ log(payload);
809
+ break;
810
+ }
811
+ case Protos.csgo.ECsgoGCMsg.k_EMsgClientMMSJoinLobbyResponse: {
812
+ const msg = protoDecode(Protos.csgo.CMsgClientMMSJoinLobbyResponse, payload);
813
+ log(msg);
814
+ break;
815
+ }
816
+ case Protos.csgo.ECsgoGCMsg.k_EMsgGCCStrike15_v2_Party_Invite: {
817
+ const msg = protoDecode(Protos.csgo.CMsgGCCStrike15_v2_Party_Invite, payload);
818
+ const sid64 = SteamID.fromIndividualAccountID(msg.accountid).getSteamID64();
819
+ if (events.partyInvite?.length) {
820
+ const personas = await getPersonas([sid64]);
821
+ const player_name = personas.find((p) => p.id == sid64)?.player_name;
822
+ if (player_name === undefined) {
823
+ log(sid64, personas);
824
+ }
825
+ callEvent(events.partyInvite, { player_name, steamId: sid64, lobbyId: msg.lobbyid });
826
+ }
827
+ // log(player_name, `https://steamcommunity.com/profiles/${sid64}`);
828
+ // joinLobby(msg.lobbyid, msg.accountid)
829
+ break;
830
+ }
831
+ case Protos.csgo.ECsgoGCMsg.k_EMsgGCCStrike15_v2_Account_RequestCoPlays: {
832
+ const msg = protoDecode(Protos.csgo.CMsgGCCStrike15_v2_Account_RequestCoPlays, payload);
833
+ const personas = msg.players.map((p) => SteamID.fromIndividualAccountID(p.accountid));
834
+ callGCCallback("RequestCoPlays", personas);
835
+ break;
836
+ }
837
+ case Protos.csgo.EGCBaseClientMsg.k_EMsgGCClientWelcome: {
838
+ prime = false;
839
+ const CMsgClientWelcome = protoDecode(Protos.csgo.CMsgClientWelcome, payload);
840
+ const obj = {};
841
+ for (const outofdate_cache of CMsgClientWelcome.outofdate_subscribed_caches) {
842
+ for (const cache_object of outofdate_cache.objects) {
843
+ for (const object_data of cache_object.object_data) {
844
+ switch (cache_object.type_id) {
845
+ case 1: {
846
+ const result = protoDecode(Protos.csgo.CSOEconItem, object_data);
847
+ result.id = result.id.toNumber();
848
+ break;
849
+ }
850
+ case 2: {
851
+ const result = protoDecode(Protos.csgo.CSOPersonaDataPublic, object_data);
852
+ obj.PersonaDataPublic = result;
853
+ const example = {
854
+ player_level: 4, //CSGO_Profile_Rank
855
+ commendation: {
856
+ cmd_friendly: 149,
857
+ cmd_teaching: 108,
858
+ cmd_leader: 115,
859
+ },
860
+ elevated_state: true,
861
+ };
862
+ break;
863
+ }
864
+ case 5: {
865
+ const result = protoDecode(Protos.csgo.CSOItemRecipe, object_data);
866
+ break;
867
+ }
868
+ case 7: {
869
+ const CSOEconGameAccountClient = protoDecode(Protos.csgo.CSOEconGameAccountClient, object_data);
870
+ const CSOEconGameAccountClientExample = {
871
+ additional_backpack_slots: 0,
872
+ bonus_xp_timestamp_refresh: 1688518800, //Wednesday 1:00:00 AM every week
873
+ bonus_xp_usedflags: 19,
874
+ elevated_state: 5,
875
+ elevated_timestamp: 5,
876
+ }; //1688518800
877
+ if ((CSOEconGameAccountClient.bonus_xp_usedflags & 16) != 0) {
878
+ // EXPBonusFlag::PrestigeEarned
879
+ prime = true;
880
+ CSOEconGameAccountClient.prime = true;
881
+ }
882
+ if (CSOEconGameAccountClient.elevated_state === 5) {
883
+ // bought prime
884
+ prime = true;
885
+ CSOEconGameAccountClient.prime = true;
886
+ }
887
+ obj.GameAccountClient = CSOEconGameAccountClient;
888
+ break;
889
+ }
890
+
891
+ case 35: {
892
+ // const result =protoDecode(Protos.csgo.CSOSelectedItemPreset, object_data);
893
+ break;
894
+ }
895
+
896
+ case 36: {
897
+ // const result =protoDecode(Protos.csgo.CSOEconItemPresetInstance, object_data);
898
+ break;
899
+ }
900
+ case 38: {
901
+ const result = protoDecode(Protos.csgo.CSOEconItemDropRateBonus, object_data);
902
+ break;
903
+ }
904
+ case 39: {
905
+ const result = protoDecode(Protos.csgo.CSOEconItemLeagueViewPass, object_data);
906
+ break;
907
+ }
908
+ case 40: {
909
+ const result = protoDecode(Protos.csgo.CSOEconItemEventTicket, object_data);
910
+ break;
911
+ }
912
+ case 41: {
913
+ const result = protoDecode(Protos.csgo.CSOAccountSeasonalOperation, object_data);
914
+ break;
915
+ }
916
+ case 42: {
917
+ // const result =protoDecode(Protos.csgo.CSOEconItemTournamentPassport, object_data);
918
+ break;
919
+ }
920
+ case 43: {
921
+ const result = protoDecode(Protos.csgo.CSOEconDefaultEquippedDefinitionInstanceClient, object_data);
922
+ const example = {
923
+ account_id: 1080136620,
924
+ item_definition: 61,
925
+ class_id: 3,
926
+ slot_id: 2,
927
+ };
928
+ break;
929
+ }
930
+ case 45: {
931
+ const result = protoDecode(Protos.csgo.CSOEconCoupon, object_data);
932
+ break;
933
+ }
934
+ case 46: {
935
+ const result = protoDecode(Protos.csgo.CSOQuestProgress, object_data);
936
+ break;
937
+ }
938
+ case 4: {
939
+ const result = protoDecode(Protos.csgo.CSOAccountItemPersonalStore, object_data);
940
+ result.generation_time = result.generation_time * 1000;
941
+ if (Array.isArray(result.items)) {
942
+ result.items = result.items.map((item) => item.toNumber());
943
+ }
944
+ obj.personalStore = result;
945
+ break;
946
+ }
947
+
948
+ default: {
949
+ log("cache_object.type_id", cache_object.type_id);
950
+ }
951
+ }
952
+ }
953
+ }
954
+ }
955
+ callEvent(events.csgoOnline, obj);
956
+
957
+ if (isPartyRegister) {
958
+ partyRegister();
959
+ doSetInterval(
960
+ function () {
961
+ partyRegister();
962
+ },
963
+ [60000, 120000],
964
+ "autoPartyRegister",
965
+ );
966
+ }
967
+ break;
968
+ }
969
+ case Protos.csgo.ECsgoGCMsg.k_EMsgGCCStrike15_v2_MatchmakingGC2ClientUpdate: {
970
+ const result = protoDecode(Protos.csgo.CMsgGCCStrike15_v2_MatchmakingGC2ClientUpdate, payload);
971
+ break;
972
+ }
973
+ case Protos.csgo.ECsgoGCMsg.k_EMsgGCCStrike15_v2_GC2ClientGlobalStats: {
974
+ const result = protoDecode(Protos.csgo.CMsgClientUGSGetGlobalStatsResponse, payload);
975
+ break;
976
+ }
977
+ case Protos.csgo.ECsgoGCMsg.k_EMsgGCCStrike15_v2_ClientReportPlayer: {
978
+ const result = protoDecode(Protos.csgo.CMsgGCCStrike15_v2_ClientReportPlayer, payload);
979
+ break;
980
+ }
981
+ case Protos.csgo.ECsgoGCMsg.k_EMsgGCCStrike15_v2_GC2ClientTextMsg: {
982
+ const result = protoDecode(Protos.csgo.CMsgGCCStrike15_v2_GC2ClientTextMsg, payload);
983
+ break;
984
+ }
985
+ case Protos.csgo.ECsgoGCMsg.k_EMsgGCCStrike15_v2_MatchmakingGC2ClientHello: {
986
+ const result = protoDecode(Protos.csgo.CMsgGCCStrike15_v2_MatchmakingGC2ClientHello, payload);
987
+ const example = {
988
+ my_current_event_teams: [],
989
+ my_current_event_stages: [],
990
+ rankings: [],
991
+ account_id: 1080136620,
992
+ ongoingmatch: null,
993
+ global_stats: {
994
+ search_statistics: [
995
+ {
996
+ game_type: 520,
997
+ search_time_avg: 0,
998
+ players_searching: 5141,
999
+ },
1000
+ {
1001
+ game_type: 32776,
1002
+ search_time_avg: 0,
1003
+ players_searching: 6561,
1004
+ },
1005
+ ],
1006
+ players_online: 617207,
1007
+ servers_online: 230638,
1008
+ players_searching: 13550,
1009
+ servers_available: 126352,
1010
+ ongoing_matches: 23264,
1011
+ search_time_avg: 95993,
1012
+ main_post_url: "*XA=https://blast.tv/live*XT=https://www.twitch.tv/blastpremier*XB=https://live.bilibili.com/35*XG=playcast://https://gotv.blast.tv/major-a*T=SGTAB*L=2@https://steamcommunity.com/broadcast/watch/76561199492362089",
1013
+ required_appid_version: 13879,
1014
+ pricesheet_version: 1688084844,
1015
+ twitch_streams_version: 2,
1016
+ active_tournament_eventid: 21,
1017
+ active_survey_id: 0,
1018
+ rtime32_cur: 0,
1019
+ rtime32_event_start: 0,
1020
+ },
1021
+ penalty_seconds: 0,
1022
+ penalty_reason: 0,
1023
+ vac_banned: 0,
1024
+ ranking: {
1025
+ account_id: 1080136620,
1026
+ rank_id: 10,
1027
+ wins: 209,
1028
+ rank_change: 0,
1029
+ rank_type_id: 6,
1030
+ tv_control: 0,
1031
+ },
1032
+ commendation: {
1033
+ cmd_friendly: 149,
1034
+ cmd_teaching: 108,
1035
+ cmd_leader: 115,
1036
+ },
1037
+ medals: null,
1038
+ my_current_event: null,
1039
+ my_current_team: null,
1040
+ survey_vote: 0,
1041
+ activity: null,
1042
+ player_level: 4,
1043
+ player_cur_xp: 327684501,
1044
+ player_xp_bonus_flags: 0,
1045
+ };
1046
+ if (result?.global_stats?.required_appid_version && (!CSGO_VER || result.global_stats.required_appid_version > CSGO_VER)) {
1047
+ CSGO_VER = result.global_stats.required_appid_version;
1048
+ }
1049
+ callEvent(events.csgoClientHello, result);
1050
+ break;
1051
+ }
1052
+ case Protos.csgo.ECsgoGCMsg.k_EMsgGCCStrike15_v2_ClientReportResponse: {
1053
+ const result = protoDecode(Protos.csgo.CMsgGCCStrike15_v2_ClientReportResponse, payload);
1054
+ break;
1055
+ }
1056
+ case Protos.csgo.ECsgoGCMsg.k_EMsgGCCStrike15_v2_ClientCommendPlayerQueryResponse: {
1057
+ const result = protoDecode(Protos.csgo.CMsgGCCStrike15_v2_ClientCommendPlayer, payload);
1058
+ break;
1059
+ }
1060
+ case Protos.csgo.ECsgoGCMsg.k_EMsgGCCStrike15_v2_PlayerOverwatchCaseAssignment: {
1061
+ const result = protoDecode(Protos.csgo.CMsgGCCStrike15_v2_PlayerOverwatchCaseAssignment, payload);
1062
+ break;
1063
+ }
1064
+ case Protos.csgo.ECsgoGCMsg.k_EMsgGCCStrike15_v2_MatchList: {
1065
+ const result = protoDecode(Protos.csgo.CMsgGCCStrike15_v2_MatchList, payload);
1066
+ break;
1067
+ }
1068
+ case Protos.csgo.ECsgoGCMsg.k_EMsgGCCStrike15_v2_GetEventFavorites_Response: {
1069
+ const result = protoDecode(Protos.csgo.CMsgGCCStrike15_v2_GetEventFavorites_Response, payload);
1070
+ break;
1071
+ }
1072
+ case Protos.csgo.ECsgoGCMsg.k_EMsgGCCStrike15_StartAgreementSessionInGame: {
1073
+ break;
1074
+ }
1075
+ case Protos.csgo.ECsgoGCMsg.k_EMsgGCCStrike15_ClientDeepStats: {
1076
+ const result = protoDecode(Protos.csgo.CMsgGCCStrike15_ClientDeepStats, payload);
1077
+ break;
1078
+ }
1079
+ case Protos.csgo.EGCBaseClientMsg.k_EMsgGCClientConnectionStatus: {
1080
+ const result = protoDecode(Protos.csgo.CMsgConnectionStatus, payload);
1081
+ break;
1082
+ }
1083
+ case Protos.csgo.EGCItemMsg.k_EMsgGCStoreGetUserDataResponse: {
1084
+ const result = protoDecode(Protos.csgo.CMsgStoreGetUserDataResponse, payload);
1085
+ break;
1086
+ }
1087
+ case Protos.csgo.EGCItemMsg.k_EMsgGCStorePurchaseFinalizeResponse: {
1088
+ const result = protoDecode(Protos.csgo.CMsgGCStorePurchaseFinalizeResponse, payload);
1089
+ break;
1090
+ }
1091
+ case Protos.csgo.EGCItemMsg.k_EMsgGCStorePurchaseCancelResponse: {
1092
+ const result = protoDecode(Protos.csgo.CMsgGCStorePurchaseCancelResponse, payload);
1093
+ break;
1094
+ }
1095
+ case Protos.csgo.EGCItemMsg.k_EMsgGCStorePurchaseInitResponse: {
1096
+ const result = protoDecode(Protos.csgo.CMsgGCStorePurchaseInitResponse, payload);
1097
+ break;
1098
+ }
1099
+ case Protos.csgo.EMsg.k_EMsgClientMMSCreateLobbyResponse: {
1100
+ const result = protoDecode(Protos.csgo.CMsgClientMMSCreateLobbyResponse, payload);
1101
+ console.log("k_EMsgClientMMSCreateLobbyResponse", result);
1102
+ break;
1103
+ }
1104
+ case Protos.csgo.ECsgoGCMsg.k_EMsgGCCStrike15_v2_ClientGCRankUpdate: {
1105
+ const result = protoDecode(Protos.csgo.CMsgGCCStrike15_v2_ClientGCRankUpdate, payload);
1106
+ break;
1107
+ }
1108
+ case Protos.csgo.ECsgoGCMsg.k_EMsgGCCStrike15_v2_Party_Search: {
1109
+ const result = protoDecode(Protos.csgo.CMsgGCCStrike15_v2_Party_SearchResults, payload);
1110
+ const entries = _.uniqBy(result.entries, "id");
1111
+ //{
1112
+ // id: 144900402,
1113
+ // grp: 0,
1114
+ // game_type: 8,
1115
+ // apr: 1,
1116
+ // ark: 17,
1117
+ // loc: 20041,
1118
+ // accountid: 0
1119
+ // }
1120
+
1121
+ //{
1122
+ // id: "76561199265943339",
1123
+ // rich_presence: [],
1124
+ // persona_state: null,
1125
+ // game_played_app_id: null,
1126
+ // game_server_ip: null,
1127
+ // game_server_port: null,
1128
+ // persona_state_flags: null,
1129
+ // online_session_instances: null,
1130
+ // persona_set_by_user: null,
1131
+ // player_name: "杀人不见血",
1132
+ // query_port: null,
1133
+ // steamid_source: null,
1134
+ // avatar_hash: "33994e26f1fe7e2093f8c7dee66c1ac91531050d",
1135
+ // last_logoff: null,
1136
+ // last_logon: null,
1137
+ // last_seen_online: null,
1138
+ // clan_rank: null,
1139
+ // game_name: null,
1140
+ // gameid: null,
1141
+ // game_data_blob: null,
1142
+ // clan_data: null,
1143
+ // clan_tag: null,
1144
+ // broadcast_id: null,
1145
+ // game_lobby_id: null,
1146
+ // watching_broadcast_accountid: null,
1147
+ // watching_broadcast_appid: null,
1148
+ // watching_broadcast_viewers: null,
1149
+ // watching_broadcast_title: null,
1150
+ // is_community_banned: null,
1151
+ // player_name_pending_review: null,
1152
+ // avatar_pending_review: null,
1153
+ // avatar_url_icon: "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/33/33994e26f1fe7e2093f8c7dee66c1ac91531050d.jpg",
1154
+ // avatar_url_medium: "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/33/33994e26f1fe7e2093f8c7dee66c1ac91531050d_medium.jpg",
1155
+ // avatar_url_full: "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/33/33994e26f1fe7e2093f8c7dee66c1ac91531050d_full.jpg"
1156
+ // }
1157
+
1158
+ const players = [];
1159
+ for (const player of entries) {
1160
+ try {
1161
+ const prime = player.apr === 1 ? "PRIME" : "NON-PRIME";
1162
+ const loc = LOCS[player.loc] || player.loc;
1163
+ const steamId = SteamID.fromIndividualAccountID(player.id).getSteamID64();
1164
+ const friendCode = FriendCode.encode(steamId);
1165
+
1166
+ // if ((LOCS[player.loc] == 'VN' || !LOCS[player.loc])) {
1167
+ players.push({
1168
+ prime,
1169
+ rank: RANKS[player.ark] !== undefined ? RANKS[player.ark] : player.ark,
1170
+ loc,
1171
+ steamId,
1172
+ friendCode,
1173
+ });
1174
+ // }
1175
+ } catch (e) {}
1176
+ }
1177
+
1178
+ callGCCallback("partySearch", players);
1179
+ break;
1180
+ }
1181
+ case Protos.csgo.ECsgoGCMsg.k_EMsgGCCStrike15_v2_PlayersProfile: {
1182
+ let data = protoDecode(Protos.csgo.CMsgGCCStrike15_v2_PlayersProfile, payload)?.account_profiles;
1183
+ const dataExample = [
1184
+ {
1185
+ my_current_event_teams: [],
1186
+ my_current_event_stages: [],
1187
+ rankings: [
1188
+ {
1189
+ account_id: 1225887169,
1190
+ rank_id: 0,
1191
+ wins: 6,
1192
+ rank_change: 0,
1193
+ rank_type_id: 7,
1194
+ tv_control: 0,
1195
+ },
1196
+ {
1197
+ account_id: 1225887169,
1198
+ rank_id: 0,
1199
+ wins: 0,
1200
+ rank_change: 0,
1201
+ rank_type_id: 10,
1202
+ tv_control: 0,
1203
+ },
1204
+ ],
1205
+ account_id: 1225887169,
1206
+ ongoingmatch: null,
1207
+ global_stats: null,
1208
+ penalty_seconds: 0,
1209
+ penalty_reason: 0,
1210
+ vac_banned: 0,
1211
+ ranking: {
1212
+ account_id: 1225887169,
1213
+ rank_id: 8,
1214
+ wins: 469,
1215
+ rank_change: 0,
1216
+ rank_type_id: 6,
1217
+ tv_control: 0,
1218
+ },
1219
+ commendation: {
1220
+ cmd_friendly: 51,
1221
+ cmd_teaching: 40,
1222
+ cmd_leader: 40,
1223
+ },
1224
+ medals: {
1225
+ display_items_defidx: [4819, 4737],
1226
+ featured_display_item_defidx: 4819,
1227
+ },
1228
+ my_current_event: null,
1229
+ my_current_team: null,
1230
+ survey_vote: 0,
1231
+ activity: null,
1232
+ player_level: 32,
1233
+ player_cur_xp: 327682846,
1234
+ player_xp_bonus_flags: 0,
1235
+ },
1236
+ ];
1237
+
1238
+ const player = data?.[0];
1239
+ if (player) {
1240
+ player.prime = !!(player.ranking?.account_id || player.player_level || player.player_cur_xp);
1241
+ player.steamId = SteamID.fromIndividualAccountID(player.account_id).getSteamID64();
1242
+ callGCCallback(`PlayersProfile_${player.account_id}`, player);
1243
+ }
1244
+ callEvent(events.playersProfile, player);
1245
+ break;
1246
+ }
1247
+ case Protos.csgo.ECsgoGCMsg.k_EMsgGCCStrike15_v2_ClientLogonFatalError: {
1248
+ const data = protoDecode(Protos.csgo.CMsgGCCStrike15_v2_ClientLogonFatalError, payload);
1249
+ const dataExample = {
1250
+ errorcode: 4,
1251
+ message: "",
1252
+ country: "VN",
1253
+ };
1254
+ callEvent(events.fatalError, data);
1255
+ break;
1256
+ }
1257
+ default:
1258
+ log(`receivedFromGC ${msgType} ${key}`);
1259
+ const results = Object.values(Protos.csgo)
1260
+ .map(function (p) {
1261
+ try {
1262
+ return protoDecode(p, payload);
1263
+ } catch (e) {}
1264
+ })
1265
+ .filter(function (result) {
1266
+ return result && Object.keys(result).length;
1267
+ });
1268
+ log(key, results);
1269
+ }
1270
+ },
1271
+ async loggedOn(loggedOnResponse) {
1272
+ callEvent(events.loggedOn, loggedOnResponse);
1273
+ updateInvisible();
1274
+ updateAutoRequestFreeLicense();
1275
+ updateAutoGamePlay();
1276
+ },
1277
+ async user(steamId, data) {
1278
+ callEvent(events.user, { steamId: steamId.getSteamID64(), data });
1279
+ const dataExample = {
1280
+ rich_presence: [
1281
+ {
1282
+ key: "status",
1283
+ value: "Competitive Mirage [ 3 : 6 ]",
1284
+ },
1285
+ {
1286
+ key: "version",
1287
+ value: "13875",
1288
+ },
1289
+ {
1290
+ key: "game:state",
1291
+ value: "game",
1292
+ },
1293
+ {
1294
+ key: "steam_display",
1295
+ value: "#display_GameKnownMapScore",
1296
+ },
1297
+ {
1298
+ key: "game:mode",
1299
+ value: "competitive",
1300
+ },
1301
+ {
1302
+ key: "game:mapgroupname",
1303
+ value: "mg_de_mirage",
1304
+ },
1305
+ {
1306
+ key: "game:map",
1307
+ value: "de_mirage",
1308
+ },
1309
+ {
1310
+ key: "game:server",
1311
+ value: "kv",
1312
+ },
1313
+ {
1314
+ key: "watch",
1315
+ value: "1",
1316
+ },
1317
+ {
1318
+ key: "steam_player_group",
1319
+ value: "2134948645",
1320
+ },
1321
+ {
1322
+ key: "game:score",
1323
+ value: "[ 3 : 6 ]",
1324
+ },
1325
+ ],
1326
+ friendid: "76561199405834425",
1327
+ persona_state: 1,
1328
+ game_played_app_id: 730,
1329
+ game_server_ip: null,
1330
+ game_server_port: null,
1331
+ persona_state_flags: 1,
1332
+ online_session_instances: 1,
1333
+ persona_set_by_user: null,
1334
+ player_name: "quỷ súng",
1335
+ query_port: null,
1336
+ steamid_source: "0",
1337
+ avatar_hash: {
1338
+ type: "Buffer",
1339
+ data: [23, 163, 216, 209, 236, 179, 73, 228, 225, 30, 48, 190, 192, 170, 177, 246, 139, 71, 122, 205],
1340
+ },
1341
+ last_logoff: 1683950268,
1342
+ last_logon: 1683950281,
1343
+ last_seen_online: 1683950268,
1344
+ clan_rank: null,
1345
+ game_name: "",
1346
+ gameid: "730",
1347
+ game_data_blob: {
1348
+ type: "Buffer",
1349
+ data: [],
1350
+ },
1351
+ clan_data: null,
1352
+ clan_tag: null,
1353
+ broadcast_id: "0",
1354
+ game_lobby_id: "0",
1355
+ watching_broadcast_accountid: null,
1356
+ watching_broadcast_appid: null,
1357
+ watching_broadcast_viewers: null,
1358
+ watching_broadcast_title: null,
1359
+ is_community_banned: null,
1360
+ player_name_pending_review: null,
1361
+ avatar_pending_review: null,
1362
+ };
1363
+ },
1364
+ async playingState(playing_blocked, playing_app) {
1365
+ playingBlocked = playing_blocked;
1366
+ if (playing_app === 0) {
1367
+ playing_app = null;
1368
+ }
1369
+ if (playing_blocked) {
1370
+ //true, false
1371
+ console.log("Playing else where");
1372
+ }
1373
+ log("playingState", playing_blocked, playing_app);
1374
+ callEvent(events.playingState, { playing_blocked, playing_app });
1375
+ },
1376
+ async friendRelationship(sid, relationship, previousRelationship) {
1377
+ callEvent(events.friendRelationship, {
1378
+ steamId: sid.getSteamID64(),
1379
+ relationship,
1380
+ previousRelationship,
1381
+ });
1382
+ switch (relationship) {
1383
+ case EFriendRelationship.None: {
1384
+ //we got unfriended.
1385
+ break;
1386
+ }
1387
+ case EFriendRelationship.RequestRecipient: {
1388
+ //we got invited as a friend
1389
+ break;
1390
+ }
1391
+ case EFriendRelationship.Friend: {
1392
+ //we got added as a friend
1393
+ break;
1394
+ }
1395
+ }
1396
+ },
1397
+ async tradeOffers(count) {
1398
+ callEvent(events.tradeOffers, count);
1399
+ },
1400
+ async offlineMessages(count, friends) {
1401
+ callEvent(events.offlineMessages, { count, steamIdList: friends });
1402
+ },
1403
+ async tradeRequest(steamID, respond) {
1404
+ if (autoAcceptTradeRequest) {
1405
+ log(`Incoming trade request from ${steamID.getSteam3RenderedID()}, accepting`);
1406
+ respond(true);
1407
+ } else {
1408
+ log(`Incoming trade request from ${steamID.getSteam3RenderedID()}, wating`);
1409
+ }
1410
+ },
1411
+ async friendsList() {
1412
+ callEvent(events.friendsList, getFriendList());
1413
+ },
1414
+ async gifts(gid, packageid, TimeCreated, TimeExpiration, TimeSent, TimeAcked, TimeRedeemed, RecipientAddress, SenderAddress, SenderName) {
1415
+ callEvent(events.gifts, {
1416
+ gid,
1417
+ packageid,
1418
+ TimeCreated,
1419
+ TimeExpiration,
1420
+ TimeSent,
1421
+ TimeAcked,
1422
+ TimeRedeemed,
1423
+ RecipientAddress,
1424
+ SenderAddress,
1425
+ SenderName,
1426
+ });
1427
+ },
1428
+ async emailInfo(address, validated) {
1429
+ callEvent(events.emailInfo, { address, validated });
1430
+ },
1431
+ async appLaunched() {
1432
+ setTimeout(function () {
1433
+ state = getPlayingAppIds().length ? "InGame" : isInvisible ? "Invisible" : "Online";
1434
+ }, 1000);
1435
+ },
1436
+ async appQuit() {
1437
+ setTimeout(function () {
1438
+ state = getPlayingAppIds().length ? "InGame" : isInvisible ? "Invisible" : "Online";
1439
+ }, 1000);
1440
+ },
1441
+ async accountLimitations(bis_limited_account, bis_community_banned, bis_locked_account, bis_limited_account_allowed_to_invite_friends) {
1442
+ callEvent(events.accountLimitations, {
1443
+ limited: bis_limited_account,
1444
+ communityBanned: bis_community_banned,
1445
+ locked: bis_locked_account,
1446
+ canInviteFriends: bis_limited_account_allowed_to_invite_friends,
1447
+ });
1448
+ },
1449
+ };
1450
+
1451
+ const _chatEvents = {
1452
+ async friendMessage(data) {
1453
+ if (!data) return;
1454
+ data.message_no_bbcode = data.message_no_bbcode?.replaceAll("ː", ":");
1455
+ data.message = data.message?.replaceAll("ː", ":");
1456
+ const example = {
1457
+ steamid_friend: {
1458
+ universe: 1,
1459
+ type: 1,
1460
+ instance: 1,
1461
+ accountid: 1080136620,
1462
+ },
1463
+ chat_entry_type: 1,
1464
+ from_limited_account: false,
1465
+ message: "xxx",
1466
+ ordinal: 0,
1467
+ local_echo: false,
1468
+ message_no_bbcode: "xxx",
1469
+ low_priority: false,
1470
+ server_timestamp: "2023-05-14T09:26:25.000Z",
1471
+ message_bbcode_parsed: ["xxx"],
1472
+ };
1473
+ const timestamp = new Date(data.server_timestamp).getTime();
1474
+ const steamId = data.steamid_friend.getSteamID64();
1475
+ const invite = ["Invited you to play a game!", "Đã mời bạn chơi một trò chơi!"].includes(data.message_no_bbcode || data.message);
1476
+ const emotion = (data.message_no_bbcode || "").split(" ").find((m) => m.startsWith(":") && m.endsWith(":"));
1477
+
1478
+ callEvent(events.friendMessage, {
1479
+ ...data,
1480
+ message: data.message_no_bbcode,
1481
+ invite,
1482
+ steamId,
1483
+ timestamp,
1484
+ emotion,
1485
+ });
1486
+ },
1487
+ async friendTyping(steamId, message) {
1488
+ callEvent(events.friendTyping, {
1489
+ steamId,
1490
+ message,
1491
+ });
1492
+ },
1493
+ };
1494
+
1495
+ // steamClient.on('lobbyInvite', (inviterID, lobbyID ) => {
1496
+ // joinLobby(lobbyID)
1497
+ // })
1498
+
1499
+ // steamClient.on('debug', (msg) => {
1500
+ // if (!["ClientPersonaState","ClientClanState"].some(c => msg.includes(c))) {
1501
+ // if(msg.startsWith("Received")){
1502
+ // console.log(`------- ${msg}`)
1503
+ // } else {
1504
+ // console.log(msg)
1505
+ // }
1506
+ // }
1507
+ // })
1508
+
1509
+ function getECsgoGCMsgKey(_key) {
1510
+ for (let key in Protos.csgo.ECsgoGCMsg) {
1511
+ if (Protos.csgo.ECsgoGCMsg[key] == _key) {
1512
+ return key;
1513
+ }
1514
+ }
1515
+ for (let key in Protos.csgo.EGCBaseClientMsg) {
1516
+ if (Protos.csgo.EGCBaseClientMsg[key] == _key) {
1517
+ return key;
1518
+ }
1519
+ }
1520
+ for (let key in Protos.csgo.EMsg) {
1521
+ if (Protos.csgo.EMsg[key] == _key) {
1522
+ return key;
1523
+ }
1524
+ }
1525
+ for (let key in Protos.csgo.EGCItemMsg) {
1526
+ if (Protos.csgo.EGCItemMsg[key] == _key) {
1527
+ return key;
1528
+ }
1529
+ }
1530
+ }
1531
+
1532
+ for (const [name, _event] of Object.entries(_events)) {
1533
+ steamClient.on(name, _event);
1534
+ }
1535
+
1536
+ for (const [name, _event] of Object.entries(_chatEvents)) {
1537
+ steamClient.chat.on(name, _event);
1538
+ }
1539
+ }
1540
+
1541
+ function getHandlerResult(msg, handler) {
1542
+ const timeout = { current: null };
1543
+ return new Promise((resolve) => {
1544
+ function myhandler(...args) {
1545
+ timeout.current && clearTimeout(timeout.current);
1546
+ removeHandler();
1547
+ resolve(handler?.(...args));
1548
+ }
1549
+
1550
+ function removeHandler() {
1551
+ if (Array.isArray(steamClient._handlerManager._handlers[msg])) {
1552
+ const index = steamClient._handlerManager._handlers[msg].findIndex((_handler) => _handler === myhandler);
1553
+ if (index > -1) {
1554
+ steamClient._handlerManager._handlers[msg].splice(index, 1);
1555
+ }
1556
+ }
1557
+ }
1558
+
1559
+ timeout.current = setTimeout(function () {
1560
+ removeHandler();
1561
+ resolve();
1562
+ }, 60000);
1563
+ steamClient._handlerManager.add(msg, myhandler);
1564
+ });
1565
+ }
1566
+
1567
+ function getFriendList() {
1568
+ return Object.keys(steamClient.myFriends).filter((steamId) => steamClient.myFriends[steamId] === NodeSteamUser.EFriendRelationship.Friend);
1569
+ }
1570
+
1571
+ function sendFriendTyping(steamId, callback) {
1572
+ steamClient.chat.sendFriendTyping(steamId, callback);
1573
+ }
1574
+
1575
+ /*
1576
+ * usually take 400 -> 800 miliseconds
1577
+ * */
1578
+ function getPlayersProfile(steamId) {
1579
+ const accountid = new SteamID(steamId).accountid;
1580
+ steamClient.sendToGC(
1581
+ 730,
1582
+ Protos.csgo.ECsgoGCMsg.k_EMsgGCCStrike15_v2_ClientRequestPlayersProfile,
1583
+ {},
1584
+ protoEncode(Protos.csgo.CMsgGCCStrike15_v2_ClientRequestPlayersProfile, {
1585
+ account_id: accountid, // account_id: new SteamID('76561199184696945').accountid,
1586
+ request_level: 32,
1587
+ }),
1588
+ );
1589
+ return new Promise((resolve) => {
1590
+ pushGCCallback(`PlayersProfile_${accountid}`, resolve, 2000);
1591
+ });
1592
+ }
1593
+
1594
+ async function checkPlayerPrimeStatus(steamId) {
1595
+ const profile = await getPlayersProfile(steamId);
1596
+ if (!profile) return false;
1597
+
1598
+ if (profile.ranking?.account_id) {
1599
+ return true;
1600
+ }
1601
+
1602
+ if (profile.player_level || profile.player_cur_xp) {
1603
+ return true;
1604
+ }
1605
+ return false;
1606
+ }
1607
+
1608
+ async function _getStoreSteamPoweredResponse(cookie) {
1609
+ let response = null;
1610
+ for (let i = 0; i < 50; i++) {
1611
+ if (!response) {
1612
+ try {
1613
+ response = await axios.request({
1614
+ url: "https://store.steampowered.com/",
1615
+ headers: {
1616
+ cookie,
1617
+ accept: "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.75",
1618
+ },
1619
+ });
1620
+ } catch (e) {
1621
+ await sleep(1000);
1622
+ }
1623
+ }
1624
+ }
1625
+ return response;
1626
+ }
1627
+
1628
+ async function getNewCookie(cookie) {
1629
+ if (!cookie) {
1630
+ return;
1631
+ }
1632
+ let response = await _getStoreSteamPoweredResponse(cookie);
1633
+ if (!response) {
1634
+ return;
1635
+ }
1636
+ while (Array.isArray(response?.headers?.["set-cookie"])) {
1637
+ console.log(cookie);
1638
+ const cookieObj = cookie.split(";").reduce(function (accumulator, currentValue) {
1639
+ accumulator[currentValue.trim().split("=")[0].trim()] = currentValue.trim().split("=")[1].trim();
1640
+ return accumulator;
1641
+ }, {});
1642
+ for (const mcookie of response.headers["set-cookie"]) {
1643
+ const name = mcookie.split("=")[0].trim();
1644
+ const value = mcookie.split("=")[1].split(";")[0].trim();
1645
+ cookieObj[name] = value;
1646
+ }
1647
+ cookie = Object.keys(cookieObj)
1648
+ .map((name) => `${name}=${cookieObj[name]}`)
1649
+ .join(";");
1650
+ response = await _getStoreSteamPoweredResponse(cookie);
1651
+ }
1652
+ return cookie;
1653
+ }
1654
+
1655
+ async function loginWithCookie(cookie, tryNewCookie = false) {
1656
+ let response;
1657
+ for (let i = 0; i < 20; i++) {
1658
+ try {
1659
+ response = await axios.request({
1660
+ url: "https://steamcommunity.com/chat/clientjstoken",
1661
+ headers: {
1662
+ cookie,
1663
+ },
1664
+ });
1665
+ } catch (e) {
1666
+ await sleep(1000);
1667
+ }
1668
+ if (response) {
1669
+ break;
1670
+ }
1671
+ }
1672
+
1673
+ const result = response?.data;
1674
+ if (result?.logged_in) {
1675
+ Object.assign(result, {
1676
+ steamID: new SteamID(result.steamid),
1677
+ accountName: result.account_name,
1678
+ webLogonToken: result.token,
1679
+ });
1680
+ steamClient.logOn(result);
1681
+ return cookie;
1682
+ } else {
1683
+ if (tryNewCookie) {
1684
+ log("You are not logged in", cookie);
1685
+ return null;
1686
+ } else {
1687
+ const newCookie = await getNewCookie(cookie);
1688
+ if (!newCookie) {
1689
+ console.error("Cannot get new cookie");
1690
+ return null;
1691
+ } else {
1692
+ return await loginWithCookie(newCookie, true);
1693
+ }
1694
+ }
1695
+ }
1696
+ }
1697
+
1698
+ async function login(reconnect = false) {
1699
+ function logOn(clientJsToken) {
1700
+ try {
1701
+ steamClient.logOn({
1702
+ ...clientJsToken,
1703
+ steamId: new SteamID(clientJsToken.steamid),
1704
+ steamID: new SteamID(clientJsToken.steamid),
1705
+ accountName: clientJsToken.account_name,
1706
+ webLogonToken: clientJsToken.token,
1707
+ });
1708
+ return true;
1709
+ } catch (e) {
1710
+ console.error(e);
1711
+ return false;
1712
+ }
1713
+ }
1714
+
1715
+ if (clientJsToken?.logged_in === true) {
1716
+ log(reconnect ? "reconnect with clientJsToken" : "login with clientJsToken");
1717
+ setTimeout(function () {
1718
+ clientJsToken = null;
1719
+ }, 1000);
1720
+ return logOn(clientJsToken);
1721
+ } else if (cookie) {
1722
+ log(reconnect ? "reconnect with cookie" : "login with cookie");
1723
+ const _clientJsToken = await new SteamUser(typeof cookie === "function" ? await cookie() : cookie).getClientJsToken();
1724
+ if (_clientJsToken?.logged_in === true) {
1725
+ return logOn(_clientJsToken);
1726
+ } else {
1727
+ log(`Account not logged in ${clientJsToken?.account_name || ""}`);
1728
+ return false;
1729
+ }
1730
+ } else if (username && password) {
1731
+ log(reconnect ? `reconnect with username ${username}` : `login with username ${username}`);
1732
+ steamClient.logOn({
1733
+ accountName: username,
1734
+ password: password,
1735
+ rememberPassword: true,
1736
+ machineName: "Natri",
1737
+ });
1738
+ return true;
1739
+ } else {
1740
+ log(`Account not logged in ${clientJsToken?.account_name || ""}`);
1741
+ return false;
1742
+ }
1743
+ }
1744
+
1745
+ function logOff() {
1746
+ isLogOff = true;
1747
+ logOffEvent?.(true);
1748
+ steamClient.logOff();
1749
+ }
1750
+
1751
+ function onCookie(callback) {
1752
+ if (getCookies()) {
1753
+ callback(getCookies());
1754
+ } else {
1755
+ onEvent(
1756
+ "webSession",
1757
+ function (webSession) {
1758
+ callback(webSession?.cookies?.join?.(";"));
1759
+ },
1760
+ true,
1761
+ );
1762
+ }
1763
+ }
1764
+
1765
+ async function init() {
1766
+ bindEvent();
1767
+ if (await login()) {
1768
+ steamClient._handlerManager.add(Protos.csgo.EMsg.k_EMsgClientRequestedClientStats, function (payload) {
1769
+ const result = protoDecode(Protos.csgo.CMsgClientRequestedClientStats, payload.toBuffer());
1770
+ // console.log("CMsgClientRequestedClientStats", result);
1771
+ });
1772
+ steamClient._handlerManager.add(Protos.csgo.EMsg.k_EMsgClientMMSLobbyData, function (payload) {
1773
+ const result = protoDecode(Protos.csgo.CMsgClientMMSLobbyData, payload.toBuffer());
1774
+ // console.log("CMsgClientMMSLobbyData", result, result.metadata);
1775
+ });
1776
+ }
1777
+ }
1778
+
1779
+ function partyRegister() {
1780
+ if (prime === null) {
1781
+ _partyRegister(true);
1782
+ _partyRegister(false);
1783
+ } else {
1784
+ _partyRegister(prime);
1785
+ }
1786
+ }
1787
+
1788
+ function _partyRegister(prime) {
1789
+ log("partyRegister", prime);
1790
+ lastTimePartyRegister = new Date().getTime();
1791
+ steamClient.sendToGC(
1792
+ 730,
1793
+ Protos.csgo.ECsgoGCMsg.k_EMsgGCCStrike15_v2_Party_Register,
1794
+ {},
1795
+ protoEncode(Protos.csgo.CMsgGCCStrike15_v2_Party_Register, {
1796
+ // id : 0,
1797
+ ver: CSGO_VER,
1798
+ apr: prime ? 1 : 0, //prime
1799
+ ark: prime ? 180 : 0,
1800
+ grps: [],
1801
+ launcher: 0,
1802
+ game_type: 8,
1803
+ }),
1804
+ );
1805
+ }
1806
+
1807
+ async function sendFriendMessage(steamId, message) {
1808
+ while (sendMessageTimestamp && new Date().getTime() - sendMessageTimestamp < 2000) {
1809
+ await sleep(1000);
1810
+ }
1811
+
1812
+ while (isSendingFriendMessages) {
1813
+ await sleep(5000);
1814
+ }
1815
+
1816
+ isSendingFriendMessages = true;
1817
+ const now = new Date().getTime();
1818
+ while (new Date().getTime() - now < 2 * 60000) {
1819
+ //2 minutes
1820
+ const result = await new Promise((resolve) => {
1821
+ steamClient.chat.sendFriendMessage(steamId, message, undefined, function (...arg) {
1822
+ sendMessageTimestamp = new Date().getTime();
1823
+ resolve(arg);
1824
+ });
1825
+ });
1826
+
1827
+ if (result?.[1]?.server_timestamp) {
1828
+ isSendingFriendMessages = false;
1829
+ return result?.[1];
1830
+ } else if (result?.[0]?.message?.includes?.("RateLimitExceeded")) {
1831
+ await sleep(5000);
1832
+ } else {
1833
+ isSendingFriendMessages = false;
1834
+ return result;
1835
+ }
1836
+ }
1837
+ isSendingFriendMessages = false;
1838
+ }
1839
+
1840
+ async function autoRequestFreeLicense(shouldLog = false, max = 10) {
1841
+ return;
1842
+ // const mCookies = await getCookiesWait()
1843
+ // if (!mCookies) return
1844
+ // let freeAppList = Array.isArray(steamClient.licenses) ? FreeAppList.filter(appId => steamClient.licenses.every(({package_id}) => package_id !== appId)) : FreeAppList;
1845
+ const freeAppList = freeAppList.filter((appId) => ownedApps.some((app) => app.appid == appId));
1846
+ const recommendedApps = _.shuffle(freeAppList);
1847
+ if (max) {
1848
+ recommendedApps.length = Math.min(recommendedApps.length, max);
1849
+ }
1850
+ try {
1851
+ const response = await steamClient.requestFreeLicense(recommendedApps);
1852
+ if (shouldLog) {
1853
+ log(response);
1854
+ }
1855
+ } catch (e) {
1856
+ log(e);
1857
+ }
1858
+ // if (Math.random() > 0.7) {
1859
+ // for (const recommendedApp of recommendedApps) {
1860
+ // try {
1861
+ // await steamUtils.requestFreeLicense(recommendedApp)
1862
+ // } catch (e) {
1863
+ // }
1864
+ // await sleep(2000)
1865
+ // }
1866
+ // } else {
1867
+ // try {
1868
+ // await steamClient.requestFreeLicense(recommendedApps)
1869
+ // } catch (e) {
1870
+ // log(e);
1871
+ // }
1872
+ // }
1873
+
1874
+ // if (shouldLog) {
1875
+ // await sleep(20000)
1876
+ // const ownedAppsCount2 = (await steamUtils.getDynamicStoreUserData())?.rgOwnedApps?.length || 0
1877
+ // const increaseNumber = ownedAppsCount2 - ownedAppsCount;
1878
+ // log(`OwnedApps length ${ownedAppsCount2}, increase ${increaseNumber}`)
1879
+ // }
1880
+ }
1881
+
1882
+ async function playCSGO() {
1883
+ try {
1884
+ await steamClient.requestFreeLicense(AppID);
1885
+ await sleep(5000);
1886
+ } catch (e) {}
1887
+ gamesPlayed(AppID);
1888
+ }
1889
+
1890
+ function doFakeGameScore() {
1891
+ const maxRound = Math.random() > 0.7 ? 16 : 12;
1892
+ const maps = [
1893
+ "ar_baggage",
1894
+ "ar_dizzy",
1895
+ "ar_monastery",
1896
+ "ar_shoots",
1897
+ "cs_agency",
1898
+ "cs_assault",
1899
+ "cs_italy",
1900
+ "cs_militia",
1901
+ "cs_office",
1902
+ "de_ancient",
1903
+ "de_anubis",
1904
+ "de_bank",
1905
+ "de_boyard",
1906
+ "de_cache",
1907
+ "de_canals",
1908
+ "de_cbble",
1909
+ "de_chalice",
1910
+ "de_dust2",
1911
+ "de_inferno",
1912
+ "de_lake",
1913
+ "de_mirage",
1914
+ "de_nuke",
1915
+ "de_overpass",
1916
+ "de_safehouse",
1917
+ // "de_shortnuke",
1918
+ "de_stmarc",
1919
+ "de_sugarcane",
1920
+ "de_train",
1921
+ "de_tuscan",
1922
+ "de_vertigo",
1923
+ "dz_ember",
1924
+ "dz_vineyard",
1925
+ "gd_cbble",
1926
+ "training1",
1927
+ ];
1928
+
1929
+ if (richPresence.myScore === undefined) {
1930
+ richPresence.myScore = _.random(0, maxRound);
1931
+ }
1932
+ if (richPresence.theirScore === undefined) {
1933
+ richPresence.theirScore = _.random(0, maxRound);
1934
+ }
1935
+ if (richPresence.map === undefined) {
1936
+ richPresence.map = maps[Math.floor(Math.random() * maps.length)];
1937
+ }
1938
+ if (richPresence.myScore === maxRound || richPresence.theirScore === maxRound) {
1939
+ richPresence.myScore = 0;
1940
+ richPresence.theirScore = 0;
1941
+ richPresence.map = maps[Math.floor(Math.random() * maps.length)];
1942
+ } else {
1943
+ const isMyTeamWin = Math.random() > 0.5;
1944
+ if (isMyTeamWin) {
1945
+ richPresence.myScore++;
1946
+ } else {
1947
+ richPresence.theirScore++;
1948
+ }
1949
+ }
1950
+
1951
+ const score = richPresence.myScore === 0 && richPresence.theirScore === 0 ? "" : `[ ${richPresence.myScore} : ${richPresence.theirScore} ]`;
1952
+ steamClient.uploadRichPresence(730, {
1953
+ "game:state": "game",
1954
+ steam_display: "#display_GameKnownMapScore",
1955
+ connect: "+gcconnectG082AA752",
1956
+ version: CSGO_VER.toString(),
1957
+ "game:mode": "competitive",
1958
+ "game:map": richPresence.map,
1959
+ "game:server": "kv",
1960
+ watch: _.random(1, 5).toString(),
1961
+ "game:score": score,
1962
+ });
1963
+ }
1964
+
1965
+ function updateFakeGameScore() {
1966
+ if (isFakeGameScore && getPlayingAppIds().some((a) => a == 730)) {
1967
+ doSetInterval(doFakeGameScore, [60000, 180000], "uploadRichPresenceCSGO");
1968
+ } else {
1969
+ doClearInterval("uploadRichPresenceCSGO");
1970
+ }
1971
+ }
1972
+
1973
+ function updateAutoRequestFreeLicense() {
1974
+ if (isAutoRequestFreeLicense) {
1975
+ doSetInterval(
1976
+ function () {
1977
+ autoRequestFreeLicense(false, 50);
1978
+ },
1979
+ [5 * 60000, 10 * 60000],
1980
+ "autoRequestFreeLicense",
1981
+ );
1982
+ } else {
1983
+ doClearInterval("autoRequestFreeLicense");
1984
+ }
1985
+ }
1986
+
1987
+ function updateInvisible() {
1988
+ if (isInvisible) {
1989
+ steamClient.setPersona(NodeSteamUser.EPersonaState.Invisible);
1990
+ state = "Invisible";
1991
+ } else {
1992
+ steamClient.setPersona(NodeSteamUser.EPersonaState.Online);
1993
+ state = "Online";
1994
+ }
1995
+ }
1996
+
1997
+ async function gamesPlayed(apps) {
1998
+ if (!Array.isArray(apps)) {
1999
+ apps = [apps];
2000
+ }
2001
+
2002
+ const processedApps = apps.map((app) => {
2003
+ if (typeof app == "string") {
2004
+ app = { game_id: "15190414816125648896", game_extra_info: app };
2005
+ } else if (typeof app === "number" || typeof app != "object") {
2006
+ app = { game_id: app };
2007
+ }
2008
+
2009
+ if (typeof app.game_ip_address == "number") {
2010
+ app.game_ip_address = { v4: app.game_ip_address };
2011
+ }
2012
+
2013
+ return app;
2014
+ });
2015
+
2016
+ steamClient.gamesPlayed(processedApps);
2017
+ if (processedApps.some((app) => parseInt(app.game_id) === 730)) {
2018
+ await sleep(500);
2019
+ await sendHello();
2020
+ }
2021
+ updateFakeGameScore();
2022
+
2023
+ // await sleep(10000)
2024
+ // self.steamUser.uploadRichPresence(730, {
2025
+ // status: 'bussssss',
2026
+ // 'game:state': 'lobby',
2027
+ // steam_display: '#display_watch',
2028
+ // currentmap: '#gamemap_de_empire',
2029
+ // connect: '+gcconnectG082AA752',
2030
+ // 'game:mode': 'competitive'
2031
+ // })
2032
+ }
2033
+
2034
+ function getFriendsList() {
2035
+ const methodName = "FriendsList.GetFriendsList#1";
2036
+ const { users, myFriends } = steamClient; //object
2037
+ /*
2038
+ users
2039
+ * {
2040
+ rich_presence: [],
2041
+ player_name: "Kei #SkinsMonkey",
2042
+ avatar_hash: [123,4543],
2043
+ last_logoff: "2023-05-20T05:00:42.000Z",
2044
+ last_logon: "2023-05-20T05:02:16.000Z",
2045
+ last_seen_online: "2023-05-20T05:00:42.000Z",
2046
+ avatar_url_icon: "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/3e/3e9da0b107ac2ec384759544368a8a977359537a.jpg",
2047
+ avatar_url_medium: "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/3e/3e9da0b107ac2ec384759544368a8a977359537a_medium.jpg",
2048
+ avatar_url_full: "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/3e/3e9da0b107ac2ec384759544368a8a977359537a_full.jpg"
2049
+ }
2050
+ *
2051
+
2052
+ myFriends
2053
+ {
2054
+ 76561198365087582: 3,
2055
+ 76561199490395123: 3
2056
+ }
2057
+ * */
2058
+ /*steamClient._send({
2059
+ msg: 151,
2060
+ proto: {
2061
+ target_job_name: methodName
2062
+ }
2063
+ }, Buffer.alloc(0), function (body, hdr) {
2064
+ const result = hdr.proto.eresult
2065
+ const errorMessage = hdr.proto.error_message
2066
+ const responseData = body.toBuffer()
2067
+ console.log(`xxx`, result)
2068
+ })*/
2069
+
2070
+ steamClient.sendToGC(730, 767, {}, Buffer.alloc(0));
2071
+ }
2072
+
2073
+ async function getUserOwnedApps(steamId = steamClient.steamID) {
2074
+ if (!steamId) {
2075
+ return [];
2076
+ }
2077
+ if (typeof steamId?.getSteamID64 === "function") {
2078
+ steamId = steamId.getSteamID64();
2079
+ }
2080
+ const isMe = steamId === steamClient.steamID.getSteamID64();
2081
+ if (isMe && ownedApps.length) {
2082
+ return ownedApps;
2083
+ }
2084
+ let result = {};
2085
+ try {
2086
+ result = await steamClient.getUserOwnedApps(steamId);
2087
+ } catch (e) {
2088
+ try {
2089
+ result = await steamClient.getUserOwnedApps(steamId);
2090
+ } catch (e) {
2091
+ result = {};
2092
+ }
2093
+ }
2094
+ if (isMe && Array.isArray(result.apps)) {
2095
+ ownedApps.length = 0;
2096
+ ownedApps.push(...result.apps);
2097
+ }
2098
+ return result.apps || [];
2099
+ const resultExample = {
2100
+ app_count: 22,
2101
+ apps: [
2102
+ {
2103
+ content_descriptorids: [],
2104
+ appid: 208030,
2105
+ name: "Moon Breakers",
2106
+ playtime_2weeks: null,
2107
+ playtime_forever: 0,
2108
+ img_icon_url: "",
2109
+ has_community_visible_stats: null,
2110
+ playtime_windows_forever: 0,
2111
+ playtime_mac_forever: 0,
2112
+ playtime_linux_forever: 0,
2113
+ rtime_last_played: 0,
2114
+ capsule_filename: null,
2115
+ sort_as: null,
2116
+ has_workshop: null,
2117
+ has_market: null,
2118
+ has_dlc: null,
2119
+ has_leaderboards: null,
2120
+ },
2121
+ ],
2122
+ };
2123
+ }
2124
+
2125
+ function getPlayingAppIds() {
2126
+ return steamClient._playingAppIds || [];
2127
+ }
2128
+
2129
+ return {
2130
+ init,
2131
+ partySearch,
2132
+ invite2Lobby,
2133
+ createLobby,
2134
+ updateLobby,
2135
+ createThenInvite2Lobby,
2136
+ joinLobby,
2137
+ getLobbyData,
2138
+ partyRegister,
2139
+ requestCoPlays,
2140
+ getPersonas,
2141
+ getUsername() {
2142
+ return username;
2143
+ },
2144
+ getCookies,
2145
+ getCookiesWait,
2146
+ getLogOnDetails() {
2147
+ return steamClient?._logOnDetails;
2148
+ },
2149
+ onEvent,
2150
+ offEvent,
2151
+ offAllEvent,
2152
+ setPersona(state, name) {
2153
+ steamClient.setPersona(state, name);
2154
+ },
2155
+ sendFriendMessage,
2156
+ sendFriendTyping,
2157
+ getSteamClient() {
2158
+ return steamClient;
2159
+ },
2160
+ getAccountInfoName,
2161
+ getPersonaName,
2162
+ async getPlayersProfile(steamId, retry = 3) {
2163
+ for (let i = 0; i < retry; i++) {
2164
+ const profile = await getPlayersProfile(steamId);
2165
+ if (profile) {
2166
+ return profile;
2167
+ }
2168
+ }
2169
+ return null;
2170
+ },
2171
+ autoRequestFreeLicense,
2172
+ playCSGO,
2173
+ doSetInterval,
2174
+ doClearIntervals,
2175
+ gamesPlayed,
2176
+ sendHello,
2177
+ checkPlayerPrimeStatus,
2178
+ doClearInterval,
2179
+ gamePlay,
2180
+ autoGamePlay,
2181
+ offAutoGamePlay,
2182
+ updateAutoGamePlay,
2183
+ getFriendsList,
2184
+ setIsPartyRegister(change) {
2185
+ change = !!change;
2186
+ if (isPartyRegister !== change) {
2187
+ isPartyRegister = change;
2188
+ if (!isPartyRegister) {
2189
+ doClearInterval("autoPartyRegister");
2190
+ } else {
2191
+ sendHello();
2192
+ }
2193
+ }
2194
+ },
2195
+ setAutoPlay(change) {
2196
+ change = !!change;
2197
+ if (isAutoPlay !== change) {
2198
+ isAutoPlay = change;
2199
+ updateAutoGamePlay();
2200
+ }
2201
+ },
2202
+ setIsInvisible(change) {
2203
+ change = !!change;
2204
+ if (isInvisible !== change) {
2205
+ isInvisible = change;
2206
+ updateInvisible();
2207
+ }
2208
+ },
2209
+ setFakeGameScore(change) {
2210
+ change = !!change;
2211
+ if (isFakeGameScore !== change) {
2212
+ isFakeGameScore = change;
2213
+ updateFakeGameScore();
2214
+ }
2215
+ },
2216
+ setAutoRequestFreeLicense(change) {
2217
+ change = !!change;
2218
+ if (isAutoRequestFreeLicense !== change) {
2219
+ isAutoRequestFreeLicense = change;
2220
+ updateAutoRequestFreeLicense();
2221
+ }
2222
+ },
2223
+ getState() {
2224
+ return state;
2225
+ },
2226
+ log,
2227
+ isPrime() {
2228
+ return prime === true;
2229
+ },
2230
+ getFriendList,
2231
+ logOff,
2232
+ isPlayingBlocked() {
2233
+ return playingBlocked;
2234
+ },
2235
+ async getChatHistory(steamId) {
2236
+ if (!steamClient.steamID) return [];
2237
+ const mySteamId = typeof steamClient.steamID.getSteamID64 === "function" ? steamClient.steamID.getSteamID64() : steamClient.steamID;
2238
+ return new Promise((resolve) => {
2239
+ setTimeout(resolve, 90000);
2240
+ steamClient.getChatHistory(steamId, async function (error, result) {
2241
+ const messages = (result || []).map(function (msg) {
2242
+ const fromSteamId = typeof msg.steamID?.getSteamID64 === "function" ? msg.steamID.getSteamID64() : msg.steamID;
2243
+ return {
2244
+ message: msg.message,
2245
+ from: fromSteamId,
2246
+ to: fromSteamId == mySteamId ? steamId : mySteamId,
2247
+ _id: new Date(msg.timestamp).getTime().toString(),
2248
+ timestamp: new Date(msg.timestamp).getTime(),
2249
+ isMe: fromSteamId !== steamId,
2250
+ };
2251
+ });
2252
+ resolve(messages);
2253
+ });
2254
+ });
2255
+ },
2256
+ onAnyEvent,
2257
+ async redeemGift(gid) {
2258
+ try {
2259
+ const community = new SteamCommunity();
2260
+ let cookies = await getCookiesWait();
2261
+ community.setCookies(typeof cookies === "string" ? cookies.split(";") : cookies);
2262
+ community.redeemGift(gid);
2263
+ } catch (e) {}
2264
+ },
2265
+ async requestFreeLicense(...args) {
2266
+ try {
2267
+ return await steamClient.requestFreeLicense(...args);
2268
+ } catch (e) {}
2269
+ },
2270
+ getSteamId() {
2271
+ try {
2272
+ return steamClient.steamID.getSteamID64();
2273
+ } catch (e) {}
2274
+ },
2275
+ getLastTimePartyRegister() {
2276
+ return lastTimePartyRegister;
2277
+ },
2278
+ getLastTimePartySearch() {
2279
+ return lastTimePartySearch;
2280
+ },
2281
+ getLicenses() {
2282
+ return steamClient.licenses;
2283
+ const exampleLicenses = [
2284
+ {
2285
+ package_id: 303386,
2286
+ time_created: 1680491335,
2287
+ time_next_process: 0,
2288
+ minute_limit: 0,
2289
+ minutes_used: 0,
2290
+ payment_method: 1024,
2291
+ flags: 512,
2292
+ purchase_country_code: "VN",
2293
+ license_type: 1,
2294
+ territory_code: 0,
2295
+ change_number: 20615891,
2296
+ owner_id: 1530068060,
2297
+ initial_period: 0,
2298
+ initial_time_unit: 0,
2299
+ renewal_period: 0,
2300
+ renewal_time_unit: 0,
2301
+ access_token: "8049398090486337961",
2302
+ master_package_id: null,
2303
+ },
2304
+ ];
2305
+ },
2306
+ uploadRichPresence(appid, richPresence) {
2307
+ const _richPresence = Array.isArray(richPresence)
2308
+ ? richPresence.reduce(function (previousValue, currentValue, currentIndex, array) {
2309
+ if (currentValue.key) {
2310
+ previousValue[currentValue.key] = currentValue.value?.toString() || "";
2311
+ }
2312
+ return previousValue;
2313
+ }, {})
2314
+ : richPresence;
2315
+ steamClient.uploadRichPresence(appid, _richPresence);
2316
+ },
2317
+ getUserOwnedApps,
2318
+ getPlayingAppIds,
2319
+ getCurrentLobby() {
2320
+ return currentLobby;
2321
+ },
2322
+ setGame(_games) {
2323
+ games = _games;
2324
+ },
2325
+ };
2326
+ }
2327
+
2328
+ export default SteamClient;
2329
+
2330
+ export function increaseCSGO_VER() {
2331
+ return ++CSGO_VER;
2332
+ }
2333
+
2334
+ SteamClient.isAccountPlayable = async function isAccountPlayable({ cookie, clientJsToken, timeoutMs, onPlayable, onNotPlayable, ...rest }) {
2335
+ if (!clientJsToken && cookie) {
2336
+ clientJsToken = await new SteamUser(typeof cookie === "function" ? await cookie() : cookie).getClientJsToken();
2337
+ }
2338
+ if (clientJsToken?.logged_in !== true) {
2339
+ if (typeof onNotPlayable === "function") {
2340
+ await onNotPlayable(null);
2341
+ }
2342
+ return { invalidClientJsToken: true };
2343
+ }
2344
+ return await new Promise((resolve) => {
2345
+ const timeouts = [
2346
+ setTimeout(() => {
2347
+ doResolve({ timedOut: true });
2348
+ }, timeoutMs || 30000),
2349
+ ];
2350
+
2351
+ const steamClient = new SteamClient({
2352
+ isFakeGameScore: false,
2353
+ isAutoPlay: true,
2354
+ isPartyRegister: false,
2355
+ isInvisible: true,
2356
+ MAX_GAME_PLAY: 10,
2357
+ games: 730,
2358
+ clientJsToken,
2359
+ ...rest,
2360
+ });
2361
+
2362
+ steamClient.onEvent("error", ({ eresult, msg, error }) => {
2363
+ doResolve({ eresult, msg, error });
2364
+ });
2365
+
2366
+ steamClient.onEvent("csgoOnline", (ClientWelcome) => {
2367
+ doResolve({ playable: true });
2368
+ });
2369
+
2370
+ steamClient.onEvent("csgoClientHello", (ClientHello) => {
2371
+ doResolve({ playable: true });
2372
+ });
2373
+
2374
+ steamClient.onEvent("playingState", ({ playing_blocked, playing_app }) => {
2375
+ if (playing_blocked) {
2376
+ doResolve({ playable: false });
2377
+ } else {
2378
+ timeouts.push(
2379
+ setTimeout(function () {
2380
+ const isBlocked = steamClient.isPlayingBlocked();
2381
+ doResolve({ playable: !isBlocked });
2382
+ }, 5000),
2383
+ );
2384
+ }
2385
+ });
2386
+
2387
+ // steamClient.onEvent("fatalError", () => {
2388
+ // doResolve();
2389
+ // });
2390
+
2391
+ steamClient.init();
2392
+
2393
+ async function doResolve(data) {
2394
+ timeouts.forEach((timeout) => clearTimeout(timeout));
2395
+ steamClient.doClearIntervals();
2396
+ steamClient.offAllEvent();
2397
+
2398
+ if (data?.playable === true) {
2399
+ if (typeof onPlayable === "function") {
2400
+ try {
2401
+ await onPlayable(steamClient);
2402
+ } catch (e) {}
2403
+ }
2404
+ } else {
2405
+ if (typeof onNotPlayable === "function") {
2406
+ try {
2407
+ await onNotPlayable(steamClient);
2408
+ } catch (e) {}
2409
+ }
2410
+ }
2411
+
2412
+ steamClient.logOff();
2413
+ return resolve(data);
2414
+ }
2415
+ });
2416
+ };