steamutils 1.0.16 → 1.0.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/SteamClient.js +26 -18
- package/package.json +1 -1
package/SteamClient.js
CHANGED
@@ -80,6 +80,7 @@ async function GetCurrentVersion(appid) {
|
|
80
80
|
return result.data.response.required_version
|
81
81
|
}
|
82
82
|
|
83
|
+
const PersonasCache = []
|
83
84
|
function SteamClient({
|
84
85
|
username,
|
85
86
|
password,
|
@@ -95,11 +96,13 @@ function SteamClient({
|
|
95
96
|
friendTyping: [],
|
96
97
|
}
|
97
98
|
|
98
|
-
|
99
|
+
function getAccountInfoName() {
|
100
|
+
return [steamClient?.accountInfo?.name, steamClient?._logOnDetails?.account_name].filter(Boolean).join(" - ")
|
101
|
+
}
|
99
102
|
|
100
103
|
async function getPersonas(steamIDs) {
|
101
|
-
const notCachesteamIDs = steamIDs.filter(id => !
|
102
|
-
const cachedPersonas =
|
104
|
+
const notCachesteamIDs = steamIDs.filter(id => !PersonasCache.some(p => p.id == id))
|
105
|
+
const cachedPersonas = PersonasCache.filter(p => steamIDs.includes(p.id))
|
103
106
|
|
104
107
|
if (notCachesteamIDs.length) {
|
105
108
|
let personas = null
|
@@ -123,14 +126,14 @@ function SteamClient({
|
|
123
126
|
for (let sid64 in personas) {
|
124
127
|
personas[sid64].id = sid64
|
125
128
|
personas[sid64].avatar_hash = Buffer.from(personas[sid64].avatar_hash).toString("hex")
|
126
|
-
|
129
|
+
PersonasCache.push(personas[sid64])
|
127
130
|
cachedPersonas.push(personas[sid64])
|
128
131
|
}
|
129
132
|
}
|
130
133
|
}
|
131
134
|
|
132
|
-
while (
|
133
|
-
|
135
|
+
while (PersonasCache.length > 500) {
|
136
|
+
PersonasCache.shift()
|
134
137
|
}
|
135
138
|
return cachedPersonas
|
136
139
|
}
|
@@ -172,10 +175,10 @@ function SteamClient({
|
|
172
175
|
}
|
173
176
|
|
174
177
|
async function sendHello() {
|
175
|
-
console.log('sendHello')
|
178
|
+
console.log('sendHello', getAccountInfoName())
|
176
179
|
steamClient.sendToGC(appid, Protos.csgo.ECsgoGCMsg.k_EMsgGCCStrike15_v2_MatchmakingClient2GCHello, {}, Buffer.alloc(0))
|
177
180
|
steamClient.sendToGC(appid, Protos.csgo.EGCBaseClientMsg.k_EMsgGCClientHello, {}, Buffer.alloc(0))
|
178
|
-
console.log('sendHello done')
|
181
|
+
console.log('sendHello done', getAccountInfoName())
|
179
182
|
}
|
180
183
|
|
181
184
|
const requestCoPlaysCallback = []
|
@@ -503,8 +506,11 @@ function SteamClient({
|
|
503
506
|
}
|
504
507
|
|
505
508
|
steamClient.on('loggedOn', async (loggedOnResponse) => {
|
506
|
-
|
507
|
-
|
509
|
+
try {
|
510
|
+
await steamClient.requestFreeLicense(appid)
|
511
|
+
await sleep(5000)
|
512
|
+
} catch (e) {
|
513
|
+
}
|
508
514
|
|
509
515
|
if (gamename) {
|
510
516
|
steamClient.gamesPlayed([{
|
@@ -520,30 +526,32 @@ function SteamClient({
|
|
520
526
|
await sleep(500)
|
521
527
|
}
|
522
528
|
|
523
|
-
console.log(`app ${appid} launched on account ${
|
529
|
+
console.log(`app ${appid} launched on account ${getAccountInfoName()}`)
|
524
530
|
await sendHello()
|
525
531
|
|
526
532
|
events.loggedOn.forEach(e => e?.())
|
527
533
|
})
|
528
534
|
|
529
535
|
steamClient.on('friendMessage', async (user, message) => {
|
536
|
+
const sid64 = user.getSteamID64();
|
537
|
+
const personas = await getPersonas([sid64]);
|
538
|
+
const player_name = personas[sid64]?.player_name || ''
|
539
|
+
console.log('friendMessage', sid64, message);
|
540
|
+
|
530
541
|
if ([`Invited you to play a game!`, `Đã mời bạn chơi một trò chơi!`].includes(message)) {
|
531
542
|
if (events.friendMessage.length) {
|
532
|
-
const sid = user;
|
533
|
-
const personas = await getPersonas([sid]);
|
534
|
-
const player_name = personas[sid]?.player_name || ''
|
535
543
|
events.friendMessage.forEach(e => e?.({
|
536
544
|
player_name,
|
537
545
|
message,
|
538
546
|
invite: true,
|
539
|
-
sid64
|
547
|
+
sid64,
|
540
548
|
}))
|
541
549
|
}
|
542
550
|
} else {
|
543
|
-
console.log('friendMessage', user.getSteamID64(), message);
|
544
551
|
events.friendMessage.forEach(e => e?.({
|
545
552
|
message,
|
546
|
-
|
553
|
+
player_name,
|
554
|
+
sid64,
|
547
555
|
}))
|
548
556
|
}
|
549
557
|
});
|
@@ -593,7 +601,7 @@ function SteamClient({
|
|
593
601
|
|
594
602
|
|
595
603
|
function partyRegister() {
|
596
|
-
console.log("partyRegister",
|
604
|
+
console.log("partyRegister", getAccountInfoName(), prime);
|
597
605
|
steamClient.sendToGC(730, Protos.csgo.ECsgoGCMsg.k_EMsgGCCStrike15_v2_Party_Register, {}, protoEncode(Protos.csgo.CMsgGCCStrike15_v2_Party_Register, {
|
598
606
|
// id : 0,
|
599
607
|
ver: CSGO_VER, apr: prime ? 1 : 0,//prime
|