Advertisement
Guest User

MirArix.

a guest
Apr 18th, 2016
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. En este código esta implementada la nueva librería donde pide los valores de los items directamente usando nodejs.
  2. Como siempre y se que vos queres todo nuevo, no es para utilizarla en si pero es un código limpio, ordenado y por sobre todas las cosas es un código que funciona. O por lo menos eso aparenta.
  3. Lo bueno es que podemos sacar muy buenas idea de acá.
  4.  
  5. var site = '';
  6. var apiKey = '';
  7. var shared_secret = '';
  8. var botID = '';
  9. var identity_secret = '';
  10. var accountName = '';
  11. var accountPassword = '';
  12. var sitePassword = 'Amina1808';
  13.  
  14. var crypto = require('crypto');
  15. var market = require('steam-market-pricing');
  16. var hash = crypto.createHash('sha1');
  17. hash.update(Math.random().toString());
  18. hash = hash.digest('hex');
  19. var device_id = 'android:' + hash;
  20.  
  21. var SteamUser = require('steam-user');
  22. var TradeOfferManager = require('steam-tradeoffer-manager');
  23. var SteamTradeOffers = require('steam-tradeoffers');
  24. var fs = require('fs');
  25. var request = require('request');
  26. var SteamTotp = require('steam-totp');
  27. var code = SteamTotp.generateAuthCode(shared_secret);
  28. var SteamcommunityMobileConfirmations = require('steamcommunity-mobile-confirmations');
  29. var steamcommunityMobileConfirmations = null;
  30.  
  31. var client = new SteamUser();
  32. var offers = new SteamTradeOffers();
  33. var manager = new TradeOfferManager({
  34.     "steam": client,
  35.     "domain": "example.com",
  36.     "language": "ru"
  37. });
  38.  
  39. manager.apiKey = apiKey;
  40.  
  41. var logOnOptions = {
  42.     "accountName": accountName,
  43.     "password": accountPassword,
  44.     "twoFactorCode": code
  45. };
  46.  
  47. client.setSentry(fs.readFileSync('sentry'));
  48.  
  49. client.logOn(logOnOptions);
  50.  
  51. client.on('loggedOn', function() {
  52.     client.setPersona(SteamUser.Steam.EPersonaState.Online);
  53. });
  54.  
  55. client.on('webSession', function(sessionID, cookies) {
  56.    
  57.     steamcommunityMobileConfirmations = new SteamcommunityMobileConfirmations(
  58.     {
  59.         steamid:         botID,
  60.         identity_secret: identity_secret,
  61.         device_id:       device_id.toString(),
  62.         webCookie:       cookies
  63.     });
  64.  
  65.     mobileConfirm();
  66.    
  67.     offers.setup({
  68.         sessionID: sessionID,
  69.         webCookie: cookies
  70.     });
  71.    
  72.     manager.setCookies(cookies, function(err) {
  73.         if(err) {
  74.             console.log(err);
  75.             process.exit(1);
  76.             return;
  77.         }
  78.         console.log("Logged in");
  79.     });
  80. });
  81.  
  82. client.on("tradeOffers", function(count){
  83.     if(count > 0){
  84.         handleOffer();
  85.     }
  86. });
  87.  
  88. /*--------------------------
  89. * MY FUNCTIONS START
  90. --------------------------*/
  91. function getSHA1(bytes) {
  92.   var shasum = crypto.createHash('sha1');
  93.   shasum.end(bytes);
  94.   return shasum.read();
  95. }
  96. function reAuth(){
  97.     client.logOff();
  98.     var code = SteamTotp.generateAuthCode(shared_secret);
  99.     var logOnOptions = {
  100.         "accountName": accountName,
  101.         "password": accountPassword,
  102.         "twoFactorCode": code
  103.     };
  104.     client.logOn(logOnOptions);
  105.     client.webLogOn();
  106. }
  107. function mobileConfirm(){
  108.     steamcommunityMobileConfirmations.FetchConfirmations((function (err, confirmations)
  109.     {
  110.         if (err)
  111.         {
  112.             console.log(err);
  113.             return;
  114.         }
  115.         if (!confirmations.length)
  116.         {
  117.             return;
  118.         }
  119.         confirmations.forEach(function(confirmation) {
  120.             steamcommunityMobileConfirmations.AcceptConfirmation(confirmation, (function (err, result)
  121.             {
  122.                 if (err)
  123.                 {
  124.                     console.log(err);
  125.                     return;
  126.                 }
  127.                 console.log('Mobile Confirmation: ' + result);
  128.             }));
  129.         });
  130.     }));
  131. }
  132. /// --- Aca esta el codigo de la consulta a la base de datos de Steam, por los precios. --- ///
  133. function price(classid,steamid){
  134.     steamid = steamid.toString();
  135.     classid = classid.toString();
  136.     var countIteration = 0;
  137.     var nameUrl = "http://api.steampowered.com/ISteamEconomy/GetAssetClassInfo/v0001?key="+apiKey+"&format=json&language=ru&appid=730&class_count=2&classid0=0&classid1="+classid;
  138.     request(nameUrl, function (error, response, body)
  139.     {
  140.         if(countIteration != 0){
  141.             return;
  142.         }
  143.         countIteration++;
  144.         var countIteration2 = 0;
  145.         if (!error && response.statusCode == 200) {
  146.             var json = JSON.parse(body);
  147.             if(json['result'][classid]['tradable'] != "")
  148.             {
  149.                 var market_hash_name = json['result'][classid]['market_hash_name'].toString();
  150.                 market.getItemPrice(730, market_hash_name, function(err, data)
  151.                 {
  152.                     if(!err)
  153.                     {
  154.                         if(countIteration2 != 0)
  155.                         {
  156.                             return;
  157.                         }
  158.                         countIteration2++;
  159.                         var cost = data;
  160.                         cost = cost['lowest_price'].replace(',','.');
  161.                         cost = cost.replace('$','');
  162.                         cost = parseFloat(cost);
  163.                         cost = (cost*100);
  164.                         var postData=
  165.                         {
  166.                             steamid: steamid,
  167.                             sum: cost,
  168.                             password: sitePassword
  169.                         };
  170.                         request.post(
  171.                         {
  172.                           headers: {'content-type' : 'application/x-www-form-urlencoded'},
  173.                           url:     site+'balance',
  174.                           body:    require('querystring').stringify(postData)
  175.                         }, function(error, response, body)
  176.                         {
  177.                             if (!error && response.statusCode == 200) {
  178.                                 console.log("Sent money to "+ steamid);
  179.                             }
  180.                         });
  181.                     }
  182.                 });
  183.             };
  184.         }
  185.     });
  186. }
  187. /// --- Aca termina. --- ///
  188. function handleOffer(){
  189.     manager.getOffers(1, function(err, sent, received){
  190.         if(err){
  191.             reAuth();
  192.         }
  193.         received.forEach(function(offer) {
  194.            
  195.             var itemToRecieve = offer.itemsToReceive;
  196.                        
  197.             if(itemToRecieve === undefined || itemToRecieve === null){
  198.                 offer.decline();
  199.                 return;
  200.             }
  201.                        
  202.             for(var i = 0; i < itemToRecieve.length; i++)
  203.             {
  204.                 if(itemToRecieve[i].appid != "730")
  205.                 {
  206.                     offer.decline();
  207.                     return;
  208.                 }
  209.             }
  210.            
  211.             if (offer.itemsToGive.length == 0) {
  212.                 offer.getEscrowDuration(function(err, daysTheirEscrow, daysMyEscrow){
  213.                     if(daysTheirEscrow == 0 || daysTheirEscrow == undefined){
  214.                         if(offer.state == 11){
  215.                             return;
  216.                         }
  217.                         console.log("New offer #" + offer.id + " from " + offer.partner);
  218.                         offer.accept(function(err) {
  219.                             if(err) {
  220.                                 console.log("Unable to accept offer: " + err.message);
  221.                                 reAuth();
  222.                                 return;
  223.                             } else {
  224.                                 console.log("Offer accepted");
  225.                                 var items = offer.itemsToReceive;
  226.                                 var steamid = offer.partner;
  227.                                 for(var x = 0; x < items.length; x++) {
  228.                                     price(items[x].classid, steamid);
  229.                                 }
  230.                                 request(site+'updateItems', function (error, response, body){
  231.                                     if(!error && response.statusCode == 200) {
  232.                                        
  233.                                     }
  234.                                 });
  235.                             }
  236.                         });
  237.                     }else{
  238.                         if(offer.state == 11){
  239.                             return;
  240.                         }else{
  241.                             console.log("New offer #" + offer.id + " from " + offer.partner);
  242.                             offer.decline();
  243.                             console.log("Escrow");
  244.                         }
  245.                     }
  246.                 });
  247.                
  248.             }else {
  249.                 offer.decline();
  250.                 console.log("I don't accept this shit!");
  251.             }
  252.         });
  253.     });
  254. };
  255.  
  256. function sendoffers(){
  257.     request(site+"winner", function (error, response, body) {
  258.         if(!error && response.statusCode == 200) {
  259.             var str = body.toString();
  260.             var winner = JSON.parse(str);
  261.             if(winner === null || winner === undefined){
  262.                 return;
  263.             }
  264.             var gameid = winner['id'];
  265.             var sendItem = winner['items'];
  266.             var item=[], num = 0;
  267.             var detected2 = false;
  268.             manager.loadInventory(730, 2, false, function(err, items, currencies) {
  269.                 if(err){
  270.                     reAuth();
  271.                 }
  272.                 itemscopy = items;
  273.                 for (var x = 0; x < itemscopy.length; x++) {
  274.                         if (itemscopy[x].tradable && itemscopy[x].classid == sendItem) {
  275.                             itemscopy[x].market_name = "fgdfgdfgdfgdfgfswfewefewrfewrewrewr";
  276.                             item[0] = {
  277.                                 appid: 730,
  278.                                 contextid: 2,
  279.                                 amount: 1,
  280.                                 assetid: itemscopy[x].id
  281.                             }
  282.                             num++;
  283.                         }
  284.                 }
  285.                 if (num > 0) {
  286.                     var gamenum = winner['id'];
  287.                     offers.makeOffer({
  288.                         partnerSteamId: winner['usersteamid'].toString(),
  289.                         itemsFromMe: item,
  290.                         accessToken: winner['token'].toString(),
  291.                         itemsFromThem: []
  292.                     }, function(err, response){
  293.                         if (err){
  294.                             console.log(err);
  295.                             reAuth();
  296.                             return;
  297.                         }
  298.                         var postData={
  299.                             id: gamenum,
  300.                             password: sitePassword
  301.                         };
  302.                         request.post({
  303.                           headers: {'content-type' : 'application/x-www-form-urlencoded'},
  304.                           url:     site+'delivery',
  305.                           body:    require('querystring').stringify(postData)
  306.                         });
  307.                         console.log('Trade offer for queue '+gamenum+' sent!');
  308.                         mobileConfirm();
  309.                     });
  310.                 }
  311.             });
  312.         }
  313.     });
  314. }
  315. setInterval(function(){sendoffers()}, 13000);
  316. /*--------------------------
  317. * MY FUNCTIONS END
  318. --------------------------*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement