Advertisement
Guest User

Untitled

a guest
Jul 24th, 2017
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.86 KB | None | 0 0
  1. 'use strict';
  2.  
  3. var SteamUser = require('steam-user');
  4. var CMClient = require('steam-client').CMClient;
  5. var SteamCommunity = require('steamcommunity');
  6. var SteamTotp = require('steam-totp');
  7. var TradeOfferManager = require('steam-tradeoffer-manager');
  8. var fs = require('fs');
  9. var request = require('request');
  10. var ip = require('ip');
  11.  
  12. botAccount.prototype.__proto__ = require('events').EventEmitter.prototype;
  13.  
  14. function botAccount(accountDetails) {
  15. var self = this;
  16.  
  17. self.CMClient = new CMClient();
  18. self.CMClient.bind(accountDetails.ipAddress);
  19. self.steamClient = new SteamUser(self.CMClient);
  20. self.steamCommunity = new SteamCommunity({localAddress: accountDetails.ipAddress});
  21.  
  22. self.accountManager = new TradeOfferManager({
  23. "steam": self.steamClient,
  24. "community": self.steamCommunity,
  25. "apiKey": accountDetails.api,
  26. //"domain": "localhost",
  27. "language": "en",
  28. "pollInterval": accountDetails.pollInterval || 20000,
  29. "cancelTime": accountDetails.cancelTime || 1800000,
  30. "pendingCancelTime": 120000
  31. });
  32. self.accountDetails = accountDetails;
  33.  
  34. if (fs.existsSync('./polldata/polldata_'+self.accountDetails.accountName+'.json')) {
  35. self.accountManager.pollData = JSON.parse(fs.readFileSync('./polldata/polldata_'+self.accountDetails.accountName+'.json'));
  36. }
  37.  
  38. self.steamClient.on('loggedOn', function(details) {
  39. self.steamClient.setPersona(1);
  40. self.emit('loggedOn', details);
  41.  
  42. /*self.steamCommunity.httpRequestGet('https://api.ipify.org?format=json', function(err, response, body) {
  43. console.log(self.accountDetails.ipAddress, body);
  44. });*/
  45. });
  46.  
  47. self.accountManager.on('unknownOfferSent', function(offer) {
  48. self.emit('unknownOfferSent', offer);
  49. });
  50. self.accountManager.on('sentOfferChanged', function(offer, oldState) {
  51. self.emit('sentOfferChanged', offer, oldState);
  52. });
  53. self.accountManager.on('receivedOfferChanged', function(offer, oldState) {
  54. self.emit('receivedOfferChanged', offer, oldState);
  55. });
  56. self.accountManager.on('newOffer', function(offer) {
  57. self.emit('newOffer', offer);
  58. });
  59. self.accountManager.on('pollData', function(pollData) {
  60. fs.writeFile('./polldata/polldata_'+self.accountDetails.accountName+'.json', JSON.stringify(pollData));
  61. });
  62.  
  63. self.steamClient.on('webSession', function(sessionID, cookies) {
  64. console.log('WEB SESSION');
  65. self.steamCommunity.setCookies(cookies);
  66. self.steamCommunity.startConfirmationChecker(10000, self.accountDetails.identitySecret);
  67. self.accountManager.setCookies(cookies, function(err) {
  68. if (err) {
  69. console.log(err);
  70. process.exit(1);
  71. return;
  72. }
  73. self.steamCommunity.startConfirmationChecker(10000, self.accountDetails.identitySecret);
  74. console.log("Got API key: " + self.accountManager.apiKey);
  75. });
  76. });
  77. self.steamCommunity.on('sessionExpired', function() {
  78. console.log('EXPIRED');
  79. self.steamClient.webLogOn();
  80. });
  81. setInterval(function() {
  82. self.steamClient.webLogOn();
  83. }, 900000);
  84. };
  85. botAccount.prototype.loginAccount = function() {
  86. var self = this;
  87.  
  88. self.generateAuthCode(function(twoFactorCode) {
  89. self.accountDetails.twoFactorCode = twoFactorCode;
  90. //self.accountDetails.rememberPassword = true;
  91. //self.accountDetails.logonId = 100;
  92.  
  93. self.steamClient.logOn(self.accountDetails);
  94. });
  95. };
  96. botAccount.prototype.generateAuthCode = function (callback) {
  97. var self = this;
  98.  
  99. request('http://'+ip.address()+':1666/code/'+self.accountDetails.accountName, function (error, response, body) {
  100. callback(body.toString('utf8'));
  101. });
  102. };
  103. botAccount.prototype.getDisplayName = function (callback) {
  104. var self = this;
  105.  
  106. return (self.accountDetails.hasOwnProperty("displayName") ? self.accountDetails.displayName : null);
  107. };
  108. botAccount.prototype.fromInvidualAccountID = function (steamID, callback) {
  109. return new TradeOfferManager.SteamID.fromIndividualAccountID(steamID);
  110. };
  111.  
  112. module.exports = botAccount;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement