1
+ const config = require ( 'config' ) ;
1
2
const SteamUser = require ( 'steam-user' ) ;
2
3
const GlobalOffensive = require ( 'globaloffensive' ) ;
3
4
const SteamTotp = require ( 'steam-totp' ) ;
4
5
const _ = require ( 'lodash' ) ;
5
6
const logger = require ( './Logger' ) ;
7
+ const Encryption = require ( './Encryption' ) ;
6
8
7
- // TODO: Add this to a config or to a database and encrypt it.
8
- const accounts = [ ] ;
9
+ const accounts = config . get ( 'steam.accounts' ) . map ( ( account ) => ( {
10
+ username : account . username ,
11
+ password : Encryption . decrypt ( account . password ) ,
12
+ sharedSecret : Encryption . decrypt ( account . sharedSecret ) ,
13
+ } ) ) ;
9
14
10
15
const clients = [ ] ;
11
16
12
17
accounts . forEach ( ( account ) => {
13
- const client = new SteamUser ( ) ;
18
+ const client = new SteamUser ( {
19
+ // This is necessary for `ownsApp` to work.
20
+ enablePicsCache : true ,
21
+ } ) ;
22
+
14
23
const csgo = new GlobalOffensive ( client ) ;
15
24
16
25
client . logOn ( {
@@ -25,6 +34,23 @@ accounts.forEach((account) => {
25
34
client . gamesPlayed ( 730 , true ) ;
26
35
} ) ;
27
36
37
+ client . on ( 'appOwnershipCached' , ( ) => {
38
+ // If the account does not own CS:GO yet, claim the free license first.
39
+ // This is necessary to connect to the game coordinator via `gamesPlayed`,
40
+ // and `gamesPlayed` is necessary to inspect skins.
41
+ if ( ! client . ownsApp ( 730 ) ) {
42
+ client . requestFreeLicense ( 730 , ( err ) => {
43
+ if ( err ) {
44
+ logger . warn ( 'Failed to acquire lisence for CS:GO' ) ;
45
+ logger . error ( err ) ;
46
+ } else {
47
+ logger . info ( 'Successfully acquired license for CS:GO' ) ;
48
+ client . gamesPlayed ( 730 , true ) ;
49
+ }
50
+ } ) ;
51
+ }
52
+ } ) ;
53
+
28
54
client . on ( 'error' , ( e ) => {
29
55
// Some error occurred during logon
30
56
logger . error ( 'Client error' ) ;
0 commit comments