Advertisement
Guest User

Untitled

a guest
Feb 16th, 2016
3,817
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'use strict';
  2. var apik = ""; // GO ON THE BOTS ACCOUNT AND CREATE AN API KEY ( IT HAS TO BE THROUGH THE BOTS ACCOUNT )
  3.  
  4. var botsteamid =''; // STEAM ID 64 OF YOUR BOT ACCOUNT : GET IT AT HTTP://WWW.STEAMID.IO/
  5. var shared_secret =''; // SHARED SECRET CODE YOU CAN GET IT THROUGH : 2FA / STEAM DESKTOP AUTHENTICATOR ( BOTH OPTIONS ARE INCLUDED )
  6. var identity_secret=''; // IDENTITY SECRET CODE YOU CAN GET IT THROUGH : 2FA / STEAM DESKTOP AUTHENTICATOR ( BOTH OPTIONS ARE INCLUDED )
  7.  
  8. // CSGO.NETWORK - New Libraries
  9. var SteamTotp = require('steam-totp'); // CSGO.NETWORK - This library generates the key
  10. var SteamConfirm = require('steamcommunity-mobile-confirmations');  // CSGO.NETWORK - This library accepts all outgoing trades = sends the winnings to the user in time
  11. var pooling_interval  = 10000; // CSGO.NETWORK - This is how often it will check for outgoing trade confirmations - Current time: 10 seconds
  12.  
  13.  
  14. var fs = require('fs');
  15. var Steam = require('steam');
  16. var SteamUser = require('steam-user');
  17. var TradeOfferManager = require('steam-tradeoffer-manager');
  18. var Winston = require('winston');
  19. var randomstring = require('randomstring');
  20. var express = require('express');
  21. var bodyParser = require('body-parser');
  22. var Firebase = require('firebase');
  23. var FirebaseTokenGenerator = require('firebase-token-generator');
  24. var tokenGenerator = new FirebaseTokenGenerator('AXziJWINPTvK21i9Hye99HnWIeYm1HK6ODc1r8Yl');
  25. var expiry = (new Date().getTime()/1000) + 10 * 365 * 24 * 60 * 60;
  26. var token = tokenGenerator.createToken({uid: "website"}, {admin: true, expires: expiry});
  27.  
  28. // CSGO.NETWORK - I added this part - This creates the device ID of your ,,mobile device" - Requires a new library: crypto
  29. var hash = require('crypto').createHash('sha1');
  30. hash.update(Math.random().toString());
  31. hash = hash.digest('hex');
  32. var device_id = 'android:' + hash; // CSGO.NETWORK - This is the only part I'm concerned about, just because it says ,,1001"
  33.  
  34. var ref = new Firebase('https://steambotupdate.firebaseio.com');
  35.  
  36. ref.authWithCustomToken(token, function(error, authData) {
  37.   if (error) {
  38.     console.log('error! ', error);
  39.   } else {
  40.     console.log('Authenticated');
  41.   }
  42. });
  43.  
  44. var offerServer = express();
  45.  
  46. offerServer.use(bodyParser.json());
  47. offerServer.use(bodyParser.urlencoded({ extended: true}));
  48.  
  49. var pendingRef = new Firebase('https://steambotupdate.firebaseio.com/pending_offers');
  50.  
  51. var queueRef = new Firebase('https://steambotupdate.firebaseio.com/queue');
  52.  
  53. var winningRef = new Firebase('https://steambotupdate.firebaseio.com/winning_offers');
  54.  
  55. var userRef = new Firebase('https://steambotupdate.firebaseio.com/users');
  56.  
  57. var logger = new (Winston.Logger)({
  58.   transports: [
  59.     new (Winston.transports.Console)({
  60.       colorize: true,
  61.       level: 'debug'
  62.     }),
  63.     new (Winston.transports.File)({
  64.       level: 'info',
  65.       timestamp: true,
  66.       filename: 'cratedump.log',
  67.       json: false
  68.     })
  69.   ]
  70. });
  71.  
  72. var client = new SteamUser();
  73. var offers = new TradeOfferManager({
  74.     steam:        client,
  75.     domain:       'website.com',
  76.     language:     'en',
  77.     pollInterval: 10000,
  78.     cancelTime:   null
  79. });
  80.  
  81. var botInfo = {
  82.   username: '',
  83.   password: '',
  84.   id: 1,
  85.   name: 'Bot #1',
  86.   port: process.env.PORT,
  87. };
  88.  
  89.  
  90. var globalSessionID;
  91.  
  92.  
  93. fs.readFile('polldata.json', function (err, data) {
  94.   if (err) {
  95.     logger.warn('Error reading polldata.json. If this is the first run, this is expected behavior: ' + err);
  96.   } else {
  97.     logger.debug('Found previous trade offer poll data.  Importing it to keep things running smoothly.');
  98.     offers.pollData = JSON.parse(data);
  99.   }
  100. });
  101.  
  102.  
  103.  
  104. client.logOn({
  105.   accountName: botInfo.username,
  106.   password: botInfo.password,
  107.   twoFactorCode: SteamTotp.generateAuthCode(shared_secret)
  108. });
  109.  
  110. client.on('loggedOn', function (details) {
  111.   logger.info('Logged into Steam as ' + client.steamID.getSteam3RenderedID());
  112. });
  113.  
  114. client.on('error', function (e) {
  115.   // Some error occurred during logon.  ENums found here:
  116.   // https://github.com/SteamRE/SteamKit/blob/SteamKit_1.6.3/Resources/SteamLanguage/eresult.steamd
  117.   logger.error(e);
  118.   process.exit(1);
  119. });
  120.  
  121.  
  122. client.on('accountLimitations', function (limited, communityBanned, locked, canInviteFriends) {
  123.   if (limited) {
  124.     logger.warn('Our account is limited. We cannot send friend invites, use the market, open group chat, or access the web API.');
  125.   }
  126.   if (communityBanned){
  127.     logger.warn('Our account is banned from Steam Community');
  128.   }
  129.   if (locked){
  130.     logger.error('Our account is locked. We cannot trade/gift/purchase items, play on VAC servers, or access Steam Community.  Shutting down.');
  131.     process.exit(1);
  132.   }
  133.   if (!canInviteFriends){
  134.     logger.warn('Our account is unable to send friend requests.');
  135.   }
  136. });
  137.  
  138. offers.on('newOffer', function (offer) {
  139.   logger.info('User ' + offer.partner.getSteam3RenderedID() + ' offered an invalid trade.  Declining offer.');
  140.   offer.decline(function (err) {
  141.     if (err) {
  142.       logger.error('Unable to decline offer ' + offer.id + ' : ' + err.message);
  143.     } else {
  144.       logger.debug('Offer declined');
  145.     }
  146.   });
  147. });
  148.  
  149. offers.on('sentOfferChanged', function (offer, oldState) {
  150.   if (offer.state === TradeOfferManager.ETradeOfferState.Accepted) {
  151.     logger.info("Our sent offer # " + offer.id + " has been accepted.");
  152.     pendingRef.child(offer.id).once('value', function(trade) {
  153.       var tradeData = trade.val();
  154.       if (tradeData) {
  155.         queueRef.push(tradeData, function() {
  156.           console.log('Successfully added pending offer ' + offer.id + ' to queue');
  157.           pendingRef.child(offer.id).remove();
  158.         });
  159.       } else {
  160.         winningRef.child(offer.id).once('value', function(data) {
  161.           console.log('We could not find this offer under pending, checking winning database');
  162.           var winningOffer = data.val();
  163.           if (winningOffer) {
  164.             console.log('Offer accepted was a winning offer, removing it from database');
  165.             winningRef.child(offer.id).remove();
  166.           } else {
  167.             console.log('We could not find this trade anywhere');
  168.           }
  169.         });
  170.       }
  171.     });
  172.   } else if (offer.state === TradeOfferManager.ETradeOfferState.InvalidItems) {
  173.     winningRef.child(offer.id).once('value', function(data) {
  174.       console.log('Items unavailable for trade error, checking...');
  175.       var winningOffer = data.val();
  176.       if (winningOffer) {
  177.         console.log('This offer was a winning offer, re-send it');
  178.         userWithdraw(winningOffer.userInfo);
  179.       } else {
  180.         console.log('This was just an offer that had unavailable items');
  181.       }
  182.     });
  183.   } else {
  184.     pendingRef.child(offer.id).once('value', function(trade) {
  185.       if (trade.val() && trade.val().id) {
  186.         userRef.child(trade.val().id).update({
  187.           tradeID: '',
  188.           protectionCode: '',
  189.         }, function() {
  190.           console.log('Trade offer canceled, tradeID: ', trade.val().id);
  191.           pendingRef.child(offer.id).remove();
  192.         });
  193.       } else {
  194.         console.log('There was an error with a trade');
  195.       }
  196.     });
  197.   }
  198. });
  199.  
  200. // Steam is down or the API is having issues
  201. offers.on('pollFailure', function (err) {
  202.   logger.error('Error polling for trade offers: ' + err);
  203. });
  204.  
  205. // When we receive new trade offer data, save it so we can use it after a crash/quit
  206. offers.on('pollData', function (pollData) {
  207.   fs.writeFile('polldata.json', JSON.stringify(pollData));
  208. });
  209.  
  210. function init() {
  211.   logger.log('info', 'Bot is now fully logged in');
  212.  
  213.   if (botInfo.state !== 'running') {
  214.  
  215.     var offerServerHandle = startOfferServer();
  216.  
  217.     botInfo.state = 'running';
  218.  
  219.     process.on('exit', exitHandler.bind(null,{server_handle : offerServerHandle, cleanup: true, exit:true}));
  220.     process.on('SIGINT', exitHandler.bind(null, {server_handle : offerServerHandle, cleanup: true, exit:true}));
  221.     process.on('uncaughtException', exitHandler.bind(null, {server_handle : offerServerHandle, exit:true}));
  222.   }
  223.  
  224. }
  225.  
  226. weblogon();
  227.  
  228. var startOfferServer = function() {
  229.   var offerServerHandle = offerServer.listen(botInfo.port);
  230.   return offerServerHandle;
  231. };
  232.  
  233. var userDeposit = function(userInfo, res) {
  234.   console.log('trade token is ', userInfo.tradeToken);
  235.   var trade = offers.createOffer(userInfo.id);
  236.   var protectionCode = randomstring.generate(7).toUpperCase();
  237.  
  238.   trade.addTheirItems(userInfo.items);
  239.   trade.send('Deposit for SkinLottery.net! Protection Code: ' + protectionCode, userInfo.tradeToken, function(err, status) {
  240.     if (err) {
  241.       logger.log('info', err);
  242.       offerError(err, userInfo, res, false);
  243.     } else {
  244.       pendingRef.child(trade.id).set({avatar: userInfo.avatar, displayName: userInfo.displayName, id: userInfo.id, items: userInfo.items, itemsCount: userInfo.itemsCount, itemsValue: userInfo.itemsValue, tradeToken: userInfo.tradeToken});
  245.       userRef.child(userInfo.id).update({
  246.         tradeID: trade.id,
  247.         protectionCode: protectionCode,
  248.       });
  249.       res.json({status: 'Trade offer status: ' + status + ', protection code: ' + protectionCode + ' trade ID: ' + trade.id});
  250.     }
  251.   });
  252. };
  253.  
  254. offerServer.post('/user-deposit', function(req, res) {
  255.   console.log('CALLING BOT DEPOSIT', req.body);
  256.   var userInfo = req.body;
  257.   userDeposit(userInfo, res);
  258. });
  259.  
  260. var userWithdraw = function(userInfo, res) {
  261.  
  262.   var items = [];
  263.   var rake = false;
  264.   var rakeTen = userInfo.jackpotValue * 0.10;
  265.   var rakeNine = userInfo.jackpotValue * 0.09;
  266.   var rakeEight = userInfo.jackpotValue * 0.08;
  267.   var rakeSeven = userInfo.jackpotValue * 0.07;
  268.   var rakeSix = userInfo.jackpotValue * 0.06;
  269.   var rakeFive = userInfo.jackpotValue * 0.05;
  270.   var rakeFour = userInfo.jackpotValue * 0.04;
  271.   var rakeThree = userInfo.jackpotValue * 0.03;
  272.   var rakeTwo = userInfo.jackpotValue * 0.02;
  273.  
  274.   userInfo.items = userInfo.items.sort(function(a, b) {
  275.     return b.market_price - a.market_price;
  276.   });
  277.  
  278.   offers.loadInventory(730, 2, true, function (err, inventory) {
  279.     var inventoryData = inventory;
  280.     var raked = '';
  281.     console.log('Loading inventory');
  282.     if (err) {
  283.       logger.log('info', err);
  284.     } else {
  285.       for (var i = 0; i < userInfo.items.length; i++) {
  286.         for (var j = 0; j < inventoryData.length; j++) {
  287.           if (inventoryData[j].market_hash_name.replace(/[.#$]/g, "") === userInfo.items[i].market_hash_name) {
  288.             var itemPrice = parseFloat(userInfo.items[i].market_price);
  289.             if (!rake) {
  290.               if (itemPrice > rakeNine && itemPrice < rakeTen) {
  291.                 rake = true;
  292.                 raked = userInfo.items[i].market_hash_name;
  293.                 break;
  294.               }
  295.               else if (itemPrice > rakeEight && itemPrice < rakeNine) {
  296.                 rake = true;
  297.                 raked = userInfo.items[i].market_hash_name;
  298.                 break;
  299.               }
  300.               else if (itemPrice > rakeSeven && itemPrice < rakeEight) {
  301.                 rake = true;
  302.                 raked = userInfo.items[i].market_hash_name;
  303.                 break;
  304.               }
  305.               else if (itemPrice > rakeSix && itemPrice < rakeSeven) {
  306.                 rake = true;
  307.                 raked = userInfo.items[i].market_hash_name;
  308.                 break;
  309.               }
  310.               else if (itemPrice > rakeFive && itemPrice < rakeSix) {
  311.                 rake = true;
  312.                 raked = userInfo.items[i].market_hash_name;
  313.                 break;
  314.               }
  315.               else if (itemPrice > rakeFour && itemPrice < rakeFive) {
  316.                 rake = true;
  317.                 raked = userInfo.items[i].market_hash_name;
  318.                 break;
  319.               }
  320.               else if (itemPrice > rakeThree && itemPrice < rakeFour) {
  321.                 rake = true;
  322.                 raked = userInfo.items[i].market_hash_name;
  323.                 break;
  324.               }
  325.               else if (itemPrice > rakeTwo && itemPrice < rakeThree) {
  326.                 rake = true;
  327.                 raked = userInfo.items[i].market_hash_name;
  328.                 break;
  329.               } else {
  330.                 items.push(inventoryData[j]);
  331.                 inventoryData.splice(j, 1);
  332.                 break;
  333.               }
  334.             } else {
  335.               items.push(inventoryData[j]);
  336.               inventoryData.splice(j, 1);
  337.               break;
  338.             }
  339.           }
  340.         }
  341.       }
  342.       var trade = offers.createOffer(userInfo.winner.id);
  343.       trade.addMyItems(items);
  344.       trade.send('Congratulations on winning! Our rake was: ' + raked + ' Still feeling lucky? Play again!', userInfo.tradeToken, function(err, status) {
  345.         if (err) {
  346.           logger.log('info', err);
  347.           offerError(err, userInfo, false, true);
  348.         } else {
  349.           console.log('Successfully sent items back to user, tradeID: ', trade.id);
  350.           winningRef.child(trade.id).set({
  351.             userInfo: userInfo
  352.           }, function() {
  353.             console.log('Added this trade to the winning database. Trade ID: ', trade.id);
  354.             return;
  355.           });
  356.         }
  357.       });
  358.     }
  359.   });
  360. };
  361.  
  362.  
  363. offerServer.post('/user-withdraw', function(req, res) {
  364.   console.log('CALLING BOT WITHDRAW', req.body);
  365.   var userInfo = req.body;
  366.   userWithdraw(userInfo, res);
  367. });
  368.  
  369. // [if we dont receive a route we can handle]
  370. offerServer.all('*', function(req, resp) {
  371.   resp.type('application/json');
  372.   resp.json({'error' : 'server error'});
  373.   resp.end();
  374. });
  375.  
  376. function offerError(err, userInfo, res, withdraw) {
  377.   err = String(err);
  378.  
  379.   if (err.indexOf('401') > -1) {
  380.     client.webLogOn();
  381.     setTimeout(function() {
  382.       if (withdraw) {
  383.         console.log('Re-trying withdrawal');
  384.         userWithdraw(userInfo);
  385.       } else {
  386.         console.log('Re-trying deposit');
  387.         userDeposit(userInfo, res);
  388.       }
  389.     }, 10000);
  390.   }
  391.   else if (err.indexOf('20') > -1) {
  392.     setTimeout(function() {
  393.       console.log('Steam is down/delayed, trying to send offer again in 10 seconds');
  394.       if (withdraw) {
  395.         console.log('Re-trying withdrawal');
  396.         userWithdraw(userInfo);
  397.       } else {
  398.         console.log('Re-trying deposit');
  399.         userDeposit(userInfo, res);
  400.       }
  401.     }, 10000);
  402.   }
  403. }
  404.  
  405.  
  406. function exitHandler(options, err) {
  407.   process.stdin.resume();
  408.   if (options.cleanup) {
  409.     options.server_handle.close();
  410.   }
  411.  
  412.   if (err) {
  413.     console.log(err.stack);
  414.   }
  415.   if (options.exit) {
  416.     process.exit();
  417.   }
  418. }
  419.  
  420. function weblogon() { // CSGO.NETWORK - I have completely modified this part, added: API Key to the offers.setup, which is why I think they should use the api from the bot
  421.     steam.webLogOn(function(newCookie) {
  422.         offers.setup({
  423.             sessionID: globalSessionID,
  424.             webCookie: newCookie,
  425.             APIKey: apik
  426.         }, function(err)
  427.         {
  428.             if(err)
  429.             {
  430.                 logger.info(err);
  431.             }
  432.             var steamapi=apik; // CSGO.NETWORK - This part accepts the outgoing trades so you can send the winnings to users
  433.             var SteamcommunityMobileConfirmations = require('steamcommunity-mobile-confirmations');
  434.             var steamcommunityMobileConfirmations = new SteamcommunityMobileConfirmations(
  435.             {
  436.                 steamid:         botsteamid,
  437.                 identity_secret: identity_secret,
  438.                 device_id:       device_id, // Generated on the top of the script
  439.                 webCookie:       newCookie,
  440.             });
  441.             setInterval(checkConfirmations(steamcommunityMobileConfirmations);, pooling_interval);
  442.             logger.info("Set interval successfully");
  443.             if (err)
  444.             {
  445.                
  446.             }
  447.         });
  448.     });
  449. }
  450.  
  451. client.on('webSession', function (sessionID, cookies) {
  452.   logger.debug('Got web session');
  453.   client.friends.setPersonaState(SteamUser.Steam.EPersonaState.Online);
  454.   offers.setCookies(cookies, function (err){
  455.     if (err) {
  456.       logger.error('Unable to set trade offer cookies: ' + err);
  457.       process.exit(1);
  458.     }
  459.     init();
  460.     logger.debug('Trade offer cookies set.  Got API Key: ' + offers.apiKey);
  461.   });
  462. });
  463.  
  464. // CSGO.NETWORK - This part accepts outgoing trades = winnings sent out by the bot.
  465. function checkConfirmations(steamcommunityMobileConfirmations){
  466.     steamcommunityMobileConfirmations.FetchConfirmations((function (err, confirmations)
  467.         {
  468.             if (err)
  469.             {
  470.                 console.log(err);
  471.                 return;
  472.             }
  473.             if(confirmations.length>0)
  474.             {
  475.                 logger.info('Recieved ' + confirmations.length + ' confirmations.');
  476.             }
  477.             if ( ! confirmations.length)
  478.             {
  479.                 return;
  480.             }
  481.             steamcommunityMobileConfirmations.AcceptConfirmation(confirmations[0], (function (err, result)
  482.             {
  483.                 if (err)
  484.                 {
  485.                     console.log(err);
  486.                     return;
  487.                 }
  488.                 logger.info('steamcommunityMobileConfirmations.AcceptConfirmation result: ' + result);
  489.             }).bind(this));
  490.         }).bind(this));
  491. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement