Advertisement
Guest User

Untitled

a guest
Nov 24th, 2017
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.57 KB | None | 0 0
  1. 'use strict'
  2.  
  3. const config = require('../config')
  4. const async = require('async')
  5. const fs = require('fs')
  6. const Trade = require('./index')
  7.  
  8. const SteamUser = require('steam-user')
  9. const SteamCommunity = require('steamcommunity')
  10. const SteamTotp = require('steam-totp')
  11. const TradeOfferManager = require('steam-tradeoffer-manager')
  12. const GlobalOffensive = require('globaloffensive')
  13.  
  14. Trade.prototype.startBots = function startBots(done) {
  15. const self = this
  16. let count = 0
  17.  
  18. async.eachOfSeries(config.bots, (bot, id, callback) => {
  19. count += 1
  20. const client = new SteamUser({
  21. dataDirectory: null,
  22. })
  23. const csgo = new GlobalOffensive(client)
  24. self.instances[id] = {
  25. client,
  26. csgo,
  27. community: new SteamCommunity(),
  28. manager: new TradeOfferManager({
  29. steam: client,
  30. domain: config.domain,
  31. language: 'en',
  32. cancelTime: 600000,
  33. }),
  34. login: {
  35. accountName: bot.accountName,
  36. password: bot.password,
  37. twoFactorCode: SteamTotp.getAuthCode(bot.twoFactorCode),
  38. },
  39. user: bot,
  40. }
  41. // identifiers
  42. self.instances[id].client.bot_id = id
  43. self.instances[id].community.bot_id = id
  44. self.instances[id].manager.bot_id = id
  45. // polldata
  46. if (fs.existsSync(`./polls/${id}.json`)) {
  47. self.instances[id].manager.pollData = JSON.parse(fs.readFileSync(`./polls/${id}.json`))
  48. }
  49. // personaState
  50. const LookingToTrade = SteamUser.Steam.EPersonaState.LookingToTrade
  51. // login
  52. self.instances[id].client.logOn(self.instances[id].login)
  53. self.instances[id].client.addListener('webSession', (sessionID, cookies) => {
  54. self.instances[id].manager.setCookies(cookies, (err) => {
  55. if (err) {
  56. return callback(err)
  57. }
  58. return true
  59. })
  60. self.instances[id].community.setCookies(cookies)
  61. self.instances[id].client.setPersona(LookingToTrade, bot.personaName)
  62. // Initialize CS:GO
  63. self.instances[id].client.gamesPlayed([config.appID])
  64. })
  65. self.instances[id].manager.on('pollData', (data) => {
  66. fs.writeFile(`./polls/${id}.json`, JSON.stringify(data))
  67. })
  68. self.instances[id].csgo.on('itemAcquired', (item) => {
  69. if (item) {
  70. self.floats[item.itemid] = {
  71. defindex: item.defindex,
  72. paintindex: item.paintindex,
  73. rarity: item.rarity,
  74. quality: item.quality,
  75. paintwear: item.paintwear,
  76. paintseed: item.paintseed,
  77. }
  78. }
  79. })
  80. self.instances[id].csgo.on('inspectItemInfo', (item) => {
  81. if (item) {
  82. self.floats[item.itemid] = {
  83. defindex: item.defindex,
  84. paintindex: item.paintindex,
  85. rarity: item.rarity,
  86. quality: item.quality,
  87. paintwear: item.paintwear,
  88. paintseed: item.paintseed,
  89. }
  90. }
  91. })
  92. // authenticated
  93. console.log(`Bot (${id}) has been logged-in.`)
  94. setTimeout(() => {
  95. if (count >= Object.keys(config.bots).length) {
  96. return this.startFloatChecker(id, () => {
  97. return callback()
  98. })
  99. }
  100. console.log('Waiting until floats are checked before authenticating the second bot.')
  101. this.startFloatChecker(id, () => {
  102. console.log('Waiting 30 seconds before authenticating another bot to avoid Steam cooldowns.')
  103. return setTimeout(() => {
  104. callback()
  105. }, 30000)
  106. })
  107. }, 15000)
  108. }, () => {
  109. console.log('[!] All bots online.')
  110. if (typeof done === 'function') {
  111. done()
  112. }
  113. })
  114. }
  115.  
  116. Trade.prototype.addBotListeners = function addBotListeners() {
  117. this.botListen('manager', 'newOffer', (offer) => {
  118. setTimeout(() => offer.decline(), 30000)
  119. })
  120. }
  121.  
  122. Trade.prototype.reloadBotSessions = function reloadBotSessions() {
  123. const self = this
  124. Object.keys(self.instances).forEach((id) => {
  125. self.instances[id].client.webLogOn()
  126. })
  127. }
  128.  
  129. Trade.prototype.getBot = function getBot(id) {
  130. return this.instances[id]
  131. }
  132.  
  133. Trade.prototype.botConfirmation = function botConfirmation(id, offerid, callback) {
  134. const bot = this.instances[id]
  135. bot.community.acceptConfirmationForObject(bot.user.identitySecret, offerid, callback)
  136. }
  137.  
  138. Trade.prototype.botListen = function botListen(obj, listen, fn) {
  139. const self = this
  140. Object.keys(self.instances).forEach((id) => {
  141. self.instances[id][obj].on(listen, fn)
  142. })
  143. }
  144.  
  145. Trade.prototype.startFloatChecker = function startFloatChecker(instanceID, done) {
  146. const self = this
  147. const instance = self.instances[instanceID]
  148. // Fetch instance inventory
  149. Trade.prototype.getInventory(config.bots[instanceID].steamID64, config.appID, config.contextID, (err, items) => {
  150. if (err) {
  151. console.log('[FloatChecker:Error]', `Could not get inventory for "${instanceID}", can't set floats.`)
  152. return done()
  153. }
  154. if (!items || !Object.keys(items).length) {
  155. console.log('[FloatChecker:Error]', `Could not get items for "${instanceID}", empty inventory?`)
  156. return done()
  157. }
  158. console.log('[FloatChecker:Progress]', `Starting to acquire floats for bot "${instanceID}". This can take a while if you have a lot of items.`)
  159. const csgo = instance.csgo
  160. // Go through all inventory items and inspect them for float values (paint wear)
  161. // Once all items have been checked, we callback and continue with the next bot
  162. async.eachOfSeries(items, (item, assetid, itemCallback) => {
  163. // Check if we already have inspected the item
  164. if (typeof self.floats[assetid] !== 'undefined' || !item.inspect) {
  165. return itemCallback()
  166. }
  167. csgo.inspectItem(item.inspect)
  168. setTimeout(itemCallback, 3000)
  169. }, () => {
  170. console.log('[FloatChecker:Progress]', `Done floats for bot "${instanceID}".`)
  171. return done()
  172. })
  173. })
  174. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement