steamutils 1.0.22 → 1.0.24
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 +61 -12
- package/package.json +1 -1
package/SteamClient.js
CHANGED
@@ -587,21 +587,64 @@ function SteamClient({
|
|
587
587
|
})
|
588
588
|
}
|
589
589
|
|
590
|
-
async function
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
590
|
+
async function getNewCookie(cookie){
|
591
|
+
let response = (await axios.request({
|
592
|
+
url: 'https://store.steampowered.com/', headers: {
|
593
|
+
cookie,
|
594
|
+
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.7",
|
595
|
+
}
|
596
|
+
}))
|
597
|
+
while (Array.isArray(response.headers?.["set-cookie"])) {
|
598
|
+
const cookieObj = cookie.split(';').reduce(function (accumulator, currentValue) {
|
599
|
+
accumulator[currentValue.trim().split('=')[0].trim()] = currentValue.trim().split('=')[1].trim()
|
600
|
+
return accumulator
|
601
|
+
}, {})
|
602
|
+
for (const mcookie of response.headers["set-cookie"]) {
|
603
|
+
const name = mcookie.split('=')[0].trim()
|
604
|
+
const value = mcookie.split('=')[1].split(";")[0].trim()
|
605
|
+
cookieObj[name] = value
|
606
|
+
}
|
607
|
+
cookie = Object.keys(cookieObj).map(name => `${name}=${cookieObj[name]}`).join(';')
|
608
|
+
response = (await axios.request({
|
609
|
+
url: 'https://store.steampowered.com/', headers: {
|
595
610
|
cookie,
|
611
|
+
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.7",
|
596
612
|
}
|
597
|
-
}))
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
613
|
+
}))
|
614
|
+
}
|
615
|
+
return cookie
|
616
|
+
}
|
617
|
+
|
618
|
+
|
619
|
+
async function loginWithCookie(cookie, tryNewCookie = false) {
|
620
|
+
const response = (await axios.request({
|
621
|
+
url: 'https://steamcommunity.com/chat/clientjstoken', headers: {
|
622
|
+
cookie,
|
623
|
+
}
|
624
|
+
}))
|
625
|
+
const result = response?.data
|
626
|
+
if (result?.logged_in) {
|
627
|
+
Object.assign(result, {
|
628
|
+
steamID: new SteamID(result.steamid), accountName: result.account_name, webLogonToken: result.token
|
629
|
+
})
|
630
|
+
steamClient.logOn(result)
|
631
|
+
return cookie
|
632
|
+
} else {
|
633
|
+
if (tryNewCookie) {
|
604
634
|
console.log('You are not logged in', cookie)
|
635
|
+
return null
|
636
|
+
} else {
|
637
|
+
return await loginWithCookie(await getNewCookie(cookie), true)
|
638
|
+
}
|
639
|
+
}
|
640
|
+
}
|
641
|
+
|
642
|
+
async function login() {
|
643
|
+
if (cookie) {
|
644
|
+
console.log('login with cookie')
|
645
|
+
const newCookie = await loginWithCookie(cookie)
|
646
|
+
if (newCookie) {
|
647
|
+
cookie = newCookie
|
605
648
|
}
|
606
649
|
} else if (username && password) {
|
607
650
|
console.log(`login with username ${username}`)
|
@@ -654,6 +697,12 @@ function SteamClient({
|
|
654
697
|
getUsername() {
|
655
698
|
return username
|
656
699
|
},
|
700
|
+
getCookie() {
|
701
|
+
return cookie
|
702
|
+
},
|
703
|
+
getLogOnDetails() {
|
704
|
+
return steamClient?._logOnDetails
|
705
|
+
},
|
657
706
|
onEvent(name, cb) {
|
658
707
|
if (!events[name]) {
|
659
708
|
events[name] = []
|