steamutils 1.3.51 → 1.3.52
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/CookieManager.js +64 -0
- package/SteamClient.js +49 -11
- package/cheerio.js +103 -71
- package/const.js +336 -0
- package/index.js +6347 -6474
- package/package.json +2 -2
- package/remote.js +3858 -4036
- package/test_steamclient.js +14 -0
- package/string.js +0 -96
package/CookieManager.js
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
export default function CookieManager(cookie) {
|
2
|
+
const _CookieObj = {};
|
3
|
+
if (typeof cookie === "string") {
|
4
|
+
cookie.split(";").forEach(function (_cookie) {
|
5
|
+
setCookie(_cookie.split("=")[0].trim(), _cookie.split("=")[1].trim());
|
6
|
+
});
|
7
|
+
} else if (Array.isArray(cookie)) {
|
8
|
+
cookie.forEach(function (_cookie) {
|
9
|
+
if (typeof _cookie === "string") {
|
10
|
+
setCookie(_cookie.split("=")[0].trim(), _cookie.split("=")[1].trim());
|
11
|
+
} else {
|
12
|
+
//to do
|
13
|
+
}
|
14
|
+
});
|
15
|
+
} else if (typeof cookie === "object" && Object.keys(cookie).length) {
|
16
|
+
for (const key in cookie) {
|
17
|
+
setCookie(key, cookie[key]);
|
18
|
+
}
|
19
|
+
} else {
|
20
|
+
//to do
|
21
|
+
}
|
22
|
+
|
23
|
+
function setCookie(name, value) {
|
24
|
+
removeCookie(name);
|
25
|
+
_CookieObj[name] = value;
|
26
|
+
}
|
27
|
+
|
28
|
+
function removeCookie(name) {
|
29
|
+
const existedKey = Object.keys(_CookieObj).find((k) => k.toLowerCase() === name.toLowerCase());
|
30
|
+
if (existedKey) {
|
31
|
+
delete _CookieObj[existedKey];
|
32
|
+
}
|
33
|
+
}
|
34
|
+
|
35
|
+
function setCookies(cookies) {
|
36
|
+
if (Array.isArray(cookies)) {
|
37
|
+
for (let cookie of cookies) {
|
38
|
+
if (typeof cookie === "string") {
|
39
|
+
cookie = cookie.split(";")[0].trim();
|
40
|
+
setCookie(cookie.split("=")[0].trim(), cookie.split("=")[1].trim());
|
41
|
+
}
|
42
|
+
}
|
43
|
+
}
|
44
|
+
}
|
45
|
+
|
46
|
+
function getCookie(name) {
|
47
|
+
const existedKey = Object.keys(_CookieObj).find((k) => k.toLowerCase() === name.toLowerCase());
|
48
|
+
return _CookieObj[existedKey];
|
49
|
+
}
|
50
|
+
|
51
|
+
function toString() {
|
52
|
+
return Object.keys(_CookieObj)
|
53
|
+
.map((k) => `${k}=${_CookieObj[k]}`)
|
54
|
+
.join(";");
|
55
|
+
}
|
56
|
+
|
57
|
+
return {
|
58
|
+
setCookie,
|
59
|
+
removeCookie,
|
60
|
+
setCookies,
|
61
|
+
getCookie,
|
62
|
+
toString,
|
63
|
+
};
|
64
|
+
}
|
package/SteamClient.js
CHANGED
@@ -680,8 +680,17 @@ function SteamClient({ username, password, cookie, clientJsToken, isAutoRequestF
|
|
680
680
|
}
|
681
681
|
|
682
682
|
async function sendHello() {
|
683
|
-
steamClient.sendToGC(
|
684
|
-
|
683
|
+
steamClient.sendToGC(
|
684
|
+
AppID,
|
685
|
+
Protos.csgo.EGCBaseClientMsg.k_EMsgGCClientHello,
|
686
|
+
{},
|
687
|
+
protoEncode(Protos.csgo.CMsgClientHello, {
|
688
|
+
version: 2000258, //get from https://github.com/SteamDatabase/GameTracking-CS2/commits
|
689
|
+
client_session_need: 0,
|
690
|
+
client_launcher: 0,
|
691
|
+
steam_launcher: 0,
|
692
|
+
}),
|
693
|
+
);
|
685
694
|
}
|
686
695
|
|
687
696
|
async function requestCoPlays() {
|
@@ -1686,9 +1695,28 @@ function SteamClient({ username, password, cookie, clientJsToken, isAutoRequestF
|
|
1686
1695
|
}
|
1687
1696
|
|
1688
1697
|
async function login(reconnect = false) {
|
1698
|
+
function logOn(clientJsToken) {
|
1699
|
+
if (clientJsToken.steamid) {
|
1700
|
+
Object.assign(clientJsToken, {
|
1701
|
+
steamId: new SteamID(clientJsToken.steamid),
|
1702
|
+
accountName: clientJsToken.account_name,
|
1703
|
+
webLogonToken: clientJsToken.token,
|
1704
|
+
password,
|
1705
|
+
twoFactorCode,
|
1706
|
+
});
|
1707
|
+
}
|
1708
|
+
try {
|
1709
|
+
steamClient.logOn(clientJsToken);
|
1710
|
+
return true;
|
1711
|
+
} catch (e) {
|
1712
|
+
console.error(e);
|
1713
|
+
return false;
|
1714
|
+
}
|
1715
|
+
}
|
1716
|
+
|
1689
1717
|
if (clientJsToken?.logged_in === true) {
|
1690
1718
|
log(reconnect ? "reconnect with clientJsToken" : "login with clientJsToken");
|
1691
|
-
|
1719
|
+
return logOn(clientJsToken);
|
1692
1720
|
setTimeout(function () {
|
1693
1721
|
clientJsToken = null;
|
1694
1722
|
}, 1000);
|
@@ -1697,13 +1725,9 @@ function SteamClient({ username, password, cookie, clientJsToken, isAutoRequestF
|
|
1697
1725
|
log(reconnect ? "reconnect with cookie" : "login with cookie");
|
1698
1726
|
const _clientJsToken = await new SteamUser(typeof cookie === "function" ? await cookie() : cookie).getClientJsToken();
|
1699
1727
|
if (_clientJsToken?.logged_in === true) {
|
1700
|
-
|
1701
|
-
await steamClient.logOn(_clientJsToken);
|
1702
|
-
return true;
|
1703
|
-
} catch (e) {
|
1704
|
-
return false;
|
1705
|
-
}
|
1728
|
+
return logOn(_clientJsToken);
|
1706
1729
|
} else {
|
1730
|
+
log("Account not logged in");
|
1707
1731
|
return false;
|
1708
1732
|
}
|
1709
1733
|
} else if (username && password) {
|
@@ -1975,8 +1999,22 @@ function SteamClient({ username, password, cookie, clientJsToken, isAutoRequestF
|
|
1975
1999
|
apps = [apps];
|
1976
2000
|
}
|
1977
2001
|
|
1978
|
-
|
1979
|
-
|
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
|
+
const shouldHello = processedApps.some((app) => parseInt(app.game_id) === 730);
|
1980
2018
|
await sleep(2000);
|
1981
2019
|
if (shouldHello) {
|
1982
2020
|
await sendHello();
|
package/cheerio.js
CHANGED
@@ -1,71 +1,103 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
}
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
}
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
}
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
1
|
+
import * as cheerio from "cheerio";
|
2
|
+
|
3
|
+
export function tables2json($, tables, getValue) {
|
4
|
+
const tablesData = [];
|
5
|
+
$(tables).each(function (index, el) {
|
6
|
+
tablesData.push(table2json($, el, getValue));
|
7
|
+
});
|
8
|
+
return tablesData;
|
9
|
+
}
|
10
|
+
|
11
|
+
export function table2json(
|
12
|
+
$,
|
13
|
+
table,
|
14
|
+
getValue = function ($, el) {
|
15
|
+
return $(el).text().trim();
|
16
|
+
},
|
17
|
+
) {
|
18
|
+
const data = [];
|
19
|
+
const header = [];
|
20
|
+
$($(table)[0])
|
21
|
+
.find("tr")
|
22
|
+
.each(function (trIndex, trEl) {
|
23
|
+
const tr = $(trEl);
|
24
|
+
const row = [];
|
25
|
+
tr.children().each(function (tdIndex, tdEl) {
|
26
|
+
const isHeader = tdEl.name.toLowerCase() === "th";
|
27
|
+
tdEl = $(tdEl);
|
28
|
+
const tdContent = getValue($, tdEl, isHeader);
|
29
|
+
(isHeader ? header : row).push(tdContent);
|
30
|
+
});
|
31
|
+
if (row.length) {
|
32
|
+
data.push(row);
|
33
|
+
}
|
34
|
+
});
|
35
|
+
|
36
|
+
if (!header.length) return data;
|
37
|
+
|
38
|
+
for (let i = 0; i < data.length; i++) {
|
39
|
+
const obj = {};
|
40
|
+
for (let j = 0; j < header.length; j++) {
|
41
|
+
obj[header[j]] = data[i][j];
|
42
|
+
}
|
43
|
+
data[i] = obj;
|
44
|
+
}
|
45
|
+
|
46
|
+
return data;
|
47
|
+
}
|
48
|
+
|
49
|
+
export function getTableHasHeaders($, $tables, headers = []) {
|
50
|
+
headers = headers.slice();
|
51
|
+
const tables = [];
|
52
|
+
$($tables).each((tableIndex, tableEl) => {
|
53
|
+
const _headers = headers.slice();
|
54
|
+
let table;
|
55
|
+
if (table) {
|
56
|
+
return;
|
57
|
+
}
|
58
|
+
const $tableEl = $(tableEl);
|
59
|
+
$tableEl
|
60
|
+
.find("tr")
|
61
|
+
.children()
|
62
|
+
.each(function (trIndex, trEl) {
|
63
|
+
if (table) {
|
64
|
+
return;
|
65
|
+
}
|
66
|
+
const $trEl = $(trEl);
|
67
|
+
let text = $trEl.text().trim();
|
68
|
+
|
69
|
+
if (_headers.includes(text)) {
|
70
|
+
_headers.splice(_headers.indexOf(text), 1);
|
71
|
+
|
72
|
+
if (!_headers.length) {
|
73
|
+
table = $tableEl;
|
74
|
+
}
|
75
|
+
}
|
76
|
+
});
|
77
|
+
if (table) {
|
78
|
+
tables.push(table);
|
79
|
+
}
|
80
|
+
});
|
81
|
+
return tables;
|
82
|
+
}
|
83
|
+
|
84
|
+
export function querySelectorAll($, selector, root) {
|
85
|
+
try {
|
86
|
+
if (root) {
|
87
|
+
return [...root.find(selector)].map((el) => $(el));
|
88
|
+
} else {
|
89
|
+
return [...$(selector)].map((el) => $(el));
|
90
|
+
}
|
91
|
+
} catch (e) {
|
92
|
+
console.error(e);
|
93
|
+
return [];
|
94
|
+
}
|
95
|
+
}
|
96
|
+
|
97
|
+
export function getDocumentTitle(html) {
|
98
|
+
if (!html || typeof html !== "string") return;
|
99
|
+
return cheerio
|
100
|
+
.load(html.replaceAll(/[\t\n\r]/gi, "").trim())("head > title")
|
101
|
+
.text()
|
102
|
+
.trim();
|
103
|
+
}
|