steamutils 1.2.94 → 1.2.97
Sign up to get free protection for your applications and to get access to all the features.
- package/SteamClient.js +58 -18
- package/index.js +36 -18
- package/package.json +1 -1
package/SteamClient.js
CHANGED
@@ -76,7 +76,7 @@ export const LOCS = {
|
|
76
76
|
|
77
77
|
const AppID = 730
|
78
78
|
export let CSGO_VER = 13960
|
79
|
-
const FreeAppList = JSON.parse(fs.readFileSync(path.join(__dirname, 'free_packages.json'))).packages
|
79
|
+
export const FreeAppList = JSON.parse(fs.readFileSync(path.join(__dirname, 'free_packages.json'))).packages
|
80
80
|
|
81
81
|
SteamUtils.getAppVersion(AppID).then(function (ver) {
|
82
82
|
CSGO_VER = ver
|
@@ -95,6 +95,7 @@ function SteamClient({
|
|
95
95
|
autoPlay = false,
|
96
96
|
autoAcceptTradeRequest = false,
|
97
97
|
autoReconnect = true,
|
98
|
+
MAX_GAME_PLAY = 10
|
98
99
|
}) {
|
99
100
|
const steamClient = new SteamUser()
|
100
101
|
let prime = null
|
@@ -106,6 +107,7 @@ function SteamClient({
|
|
106
107
|
let lastTimePartyRegister = 0
|
107
108
|
let lastTimePartySearch = 0
|
108
109
|
const appsPlayed = []
|
110
|
+
const ownedApps = []
|
109
111
|
|
110
112
|
const onAnyCallbacks = []
|
111
113
|
|
@@ -339,20 +341,22 @@ function SteamClient({
|
|
339
341
|
}
|
340
342
|
|
341
343
|
async function gamePlay() {
|
342
|
-
let ownedApps =
|
343
|
-
for (let i = 0; i <
|
344
|
-
|
345
|
-
|
346
|
-
await sleep(1000)
|
347
|
-
} else {
|
344
|
+
let ownedApps = []
|
345
|
+
for (let i = 0; i < 5; i++) {
|
346
|
+
ownedApps = await getUserOwnedApps()
|
347
|
+
if (ownedApps.length) {
|
348
348
|
break
|
349
349
|
}
|
350
350
|
}
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
351
|
+
if (!ownedApps.length) {
|
352
|
+
gamesPlayed(730)
|
353
|
+
} else {
|
354
|
+
ownedApps = ownedApps.map(({appid}) => appid)
|
355
|
+
ownedApps = _.shuffle(ownedApps)
|
356
|
+
ownedApps.length = Math.min(ownedApps.length, MAX_GAME_PLAY)
|
357
|
+
ownedApps = _.sortBy(ownedApps, app => app == 730 ? 1 : -1)
|
358
|
+
gamesPlayed(ownedApps)
|
359
|
+
}
|
356
360
|
}
|
357
361
|
|
358
362
|
async function autoGamePlay() {
|
@@ -982,10 +986,7 @@ function SteamClient({
|
|
982
986
|
}, [5 * 60000, 10 * 60000], 'autoRequestFreeLicense')
|
983
987
|
}
|
984
988
|
if (autoPlay) {
|
985
|
-
|
986
|
-
onCookie(function () {
|
987
|
-
autoGamePlay()
|
988
|
-
})
|
989
|
+
autoGamePlay()
|
989
990
|
}
|
990
991
|
},
|
991
992
|
async user(steamId, data) {
|
@@ -1154,7 +1155,7 @@ function SteamClient({
|
|
1154
1155
|
SenderAddress,
|
1155
1156
|
SenderName
|
1156
1157
|
})
|
1157
|
-
}
|
1158
|
+
},
|
1158
1159
|
}
|
1159
1160
|
|
1160
1161
|
const _chatEvents = {
|
@@ -1667,6 +1668,44 @@ function SteamClient({
|
|
1667
1668
|
steamClient.sendToGC(730, 767, {}, Buffer.alloc(0))
|
1668
1669
|
}
|
1669
1670
|
|
1671
|
+
async function getUserOwnedApps(steamId) {
|
1672
|
+
steamId = (steamId ? new SteamID(steamId) : steamClient.steamID).getSteamID64()
|
1673
|
+
const isMe = steamId === steamClient.steamID.getSteamID64();
|
1674
|
+
if (isMe && ownedApps.length) {
|
1675
|
+
return ownedApps
|
1676
|
+
}
|
1677
|
+
const result = await steamClient.getUserOwnedApps(steamId)
|
1678
|
+
if (isMe && Array.isArray(result.apps)) {
|
1679
|
+
ownedApps.length = 0
|
1680
|
+
ownedApps.push(...result.apps)
|
1681
|
+
}
|
1682
|
+
return result.apps || []
|
1683
|
+
const resultExample = {
|
1684
|
+
app_count: 22,
|
1685
|
+
apps: [
|
1686
|
+
{
|
1687
|
+
content_descriptorids: [],
|
1688
|
+
appid: 208030,
|
1689
|
+
name: "Moon Breakers",
|
1690
|
+
playtime_2weeks: null,
|
1691
|
+
playtime_forever: 0,
|
1692
|
+
img_icon_url: "",
|
1693
|
+
has_community_visible_stats: null,
|
1694
|
+
playtime_windows_forever: 0,
|
1695
|
+
playtime_mac_forever: 0,
|
1696
|
+
playtime_linux_forever: 0,
|
1697
|
+
rtime_last_played: 0,
|
1698
|
+
capsule_filename: null,
|
1699
|
+
sort_as: null,
|
1700
|
+
has_workshop: null,
|
1701
|
+
has_market: null,
|
1702
|
+
has_dlc: null,
|
1703
|
+
has_leaderboards: null
|
1704
|
+
},
|
1705
|
+
]
|
1706
|
+
}
|
1707
|
+
}
|
1708
|
+
|
1670
1709
|
return {
|
1671
1710
|
init,
|
1672
1711
|
partySearch,
|
@@ -1822,7 +1861,8 @@ function SteamClient({
|
|
1822
1861
|
})
|
1823
1862
|
}
|
1824
1863
|
steamClient.uploadRichPresence(appid, richPresence)
|
1825
|
-
}
|
1864
|
+
},
|
1865
|
+
getUserOwnedApps
|
1826
1866
|
}
|
1827
1867
|
}
|
1828
1868
|
|
package/index.js
CHANGED
@@ -1614,6 +1614,7 @@ class SteamUser {
|
|
1614
1614
|
}
|
1615
1615
|
|
1616
1616
|
async _httpRequest(params) {
|
1617
|
+
const isRedirect = typeof params.isRedirect === "boolean" ? params.isRedirect : true
|
1617
1618
|
params = this._formatHttpRequest(params)
|
1618
1619
|
|
1619
1620
|
if (!this._cookies) {
|
@@ -1675,19 +1676,23 @@ class SteamUser {
|
|
1675
1676
|
|
1676
1677
|
switch (response.status) {
|
1677
1678
|
case 302: {
|
1678
|
-
|
1679
|
+
if(isRedirect){
|
1680
|
+
redirectURL = response.headers.location
|
1679
1681
|
|
1680
|
-
|
1681
|
-
|
1682
|
-
|
1683
|
-
|
1682
|
+
if (redirectURL?.startsWith('https://steamcommunity.com/id/')) {
|
1683
|
+
const customURL = redirectURL.split('/')[4];
|
1684
|
+
if (customURL) {
|
1685
|
+
this._myProfile = `id/${customURL}`
|
1686
|
+
}
|
1687
|
+
} else if (redirectURL?.startsWith('https://steamcommunity.com/login/')) {
|
1688
|
+
console.error('Login first', this._steamid_user)
|
1689
|
+
return null
|
1684
1690
|
}
|
1685
|
-
} else if (redirectURL?.startsWith('https://steamcommunity.com/login/')) {
|
1686
|
-
console.error('Login first', this._steamid_user)
|
1687
|
-
return null
|
1688
|
-
}
|
1689
1691
|
|
1690
|
-
|
1692
|
+
console.log(`Redirect ${config.url} to ${redirectURL}`)
|
1693
|
+
} else {
|
1694
|
+
return response
|
1695
|
+
}
|
1691
1696
|
break
|
1692
1697
|
}
|
1693
1698
|
case 200: {
|
@@ -4355,15 +4360,24 @@ class SteamUser {
|
|
4355
4360
|
}
|
4356
4361
|
}
|
4357
4362
|
|
4358
|
-
async addFreeLicense(
|
4359
|
-
const
|
4360
|
-
|
4361
|
-
|
4362
|
-
|
4363
|
-
|
4363
|
+
async addFreeLicense(packageID) {//packageID not appID
|
4364
|
+
const form = new FormData();
|
4365
|
+
form.append('ajax', "true");
|
4366
|
+
form.append('sessionid', this.getSessionid());
|
4367
|
+
|
4368
|
+
const result = await this._httpRequestAjax({
|
4369
|
+
// url: `https://checkout.steampowered.com/checkout/addfreelicense/${appID}`,
|
4370
|
+
// url: `https://store.steampowered.com/checkout/addfreelicense/${appID}`,
|
4371
|
+
url: `https://store.steampowered.com/freelicense/addfreelicense/${packageID}`,
|
4372
|
+
data: form,
|
4364
4373
|
method: 'POST',
|
4374
|
+
headers: {
|
4375
|
+
'Content-Type': 'multipart/form-data',
|
4376
|
+
},
|
4365
4377
|
})
|
4366
|
-
|
4378
|
+
|
4379
|
+
const data = result.data
|
4380
|
+
return result.status === 200 && Array.isArray(data) && !data.length//empty array
|
4367
4381
|
}
|
4368
4382
|
|
4369
4383
|
async addSubFreeLicense(subid) {
|
@@ -5849,7 +5863,11 @@ class SteamUser {
|
|
5849
5863
|
|
5850
5864
|
static parseTradeURL(tradeURL) {
|
5851
5865
|
try {
|
5852
|
-
|
5866
|
+
let search = new URL(tradeURL).search;
|
5867
|
+
if(search.startsWith("?")){
|
5868
|
+
search = search.substring(1)
|
5869
|
+
}
|
5870
|
+
const tradeURLParams = search.split('&').reduce((accumulator, currentValue, index) => ({
|
5853
5871
|
...accumulator, [currentValue.split('=')[0]]: currentValue.split('=')[1]
|
5854
5872
|
}), {})
|
5855
5873
|
|