|
| 1 | +const SteamUser = require('steam-user'); |
| 2 | +const GlobalOffensive = require('globaloffensive'); |
| 3 | +const SteamTotp = require('steam-totp'); |
| 4 | +const _ = require('lodash'); |
| 5 | +const logger = require('./Logger'); |
| 6 | + |
| 7 | +// TODO: Add this to a config or to a database and encrypt it. |
| 8 | +const accounts = []; |
| 9 | + |
| 10 | +const clients = []; |
| 11 | + |
| 12 | +accounts.forEach((account) => { |
| 13 | + const client = new SteamUser(); |
| 14 | + const csgo = new GlobalOffensive(client); |
| 15 | + |
| 16 | + client.logOn({ |
| 17 | + accountName: account.username, |
| 18 | + password: account.password, |
| 19 | + twoFactorCode: SteamTotp.getAuthCode(account.sharedSecret), |
| 20 | + }); |
| 21 | + |
| 22 | + client.on('loggedOn', () => { |
| 23 | + logger.info(`Logged into Steam as ${client.steamID.getSteam3RenderedID()}`); |
| 24 | + client.setPersona(SteamUser.EPersonaState.Online); |
| 25 | + client.gamesPlayed(730, true); |
| 26 | + }); |
| 27 | + |
| 28 | + client.on('error', (e) => { |
| 29 | + // Some error occurred during logon |
| 30 | + logger.error('Client error'); |
| 31 | + logger.error(e); |
| 32 | + }); |
| 33 | + |
| 34 | + client.on('webSession', () => { |
| 35 | + logger.info('Got web session'); |
| 36 | + // Do something with these cookies if you wish |
| 37 | + }); |
| 38 | + |
| 39 | + csgo.on('connectedToGC', () => { |
| 40 | + logger.info('Connected to CS:GO game coordinator'); |
| 41 | + }); |
| 42 | + |
| 43 | + csgo.on('inspectItemTimedOut', (assetid) => { |
| 44 | + logger.warn(`Inspect timed out for assetid ${assetid}`); |
| 45 | + }); |
| 46 | + |
| 47 | + clients.push({ |
| 48 | + client, |
| 49 | + csgo, |
| 50 | + }); |
| 51 | +}); |
| 52 | + |
| 53 | +class Inspector { |
| 54 | + static getClients() { |
| 55 | + return clients; |
| 56 | + } |
| 57 | + |
| 58 | + static inspect(url, timeoutMs = 5000) { |
| 59 | + return new Promise((resolve, reject) => { |
| 60 | + const client = _.sample(_.filter(clients, ((x) => x.csgo.haveGCSession))); |
| 61 | + |
| 62 | + if (_.isUndefined(client)) { |
| 63 | + reject( |
| 64 | + new Error('There is currently no client available with an active game coordinator connection'), |
| 65 | + ); |
| 66 | + } |
| 67 | + |
| 68 | + client.csgo.inspectItem(url, (item) => { |
| 69 | + resolve(item); |
| 70 | + }); |
| 71 | + |
| 72 | + setTimeout(() => { |
| 73 | + reject(new Error(`Inspection timed out after ${timeoutMs} ms`)); |
| 74 | + }, timeoutMs); |
| 75 | + }); |
| 76 | + } |
| 77 | +} |
| 78 | + |
| 79 | +module.exports = Inspector; |
0 commit comments