Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var SteamCommunity = require('steamcommunity');
- var fs = require('fs');
- var SteamTotp = require('steam-totp');
- var community = new SteamCommunity();
- var TradeOfferManager = require('steam-tradeoffer-manager');
- var io = require('socket.io-client');
- var socket = io.connect('http://localhost:3000');
- var config = require('config.json')('./config.json');
- var xssEscape = require('xss-escape');
- var request = require("request");
- var async = require("async");
- var md5 = require("md5");
- var ready = false;
- socket.on('connect', function () {
- console.log("socket connected");
- });
- setTimeout(function(){
- console.log("Restart bota");
- process.exit(1);
- }, 3600000);
- var mysql = require('mysql');
- var connection = mysql.createConnection({
- host : config.mysql.host,
- user : config.mysql.user,
- password : config.mysql.pass,
- database : config.mysql.db
- });
- var twofactor = JSON.parse(fs.readFileSync(config.bots[process.argv[2]].twofactor, 'utf8')); //Tutaj Zmienic na wlasne
- var code = SteamTotp.generateAuthCode(twofactor.shared_secret);
- var manager = new TradeOfferManager({
- "domain": config.domain,
- "language": "en",
- "pollInterval": 5000
- });
- if(fs.existsSync('polldata_'+config.bots[process.argv[2]].login+'.json')){
- manager.pollData = JSON.parse(fs.readFileSync('polldata_'+config.bots[process.argv[2]].login+'.json'));
- }
- community.login({
- "accountName": config.bots[process.argv[2]].login, //Tutaj Zmienic na wlasne
- "password": config.bots[process.argv[2]].pass, //Tutaj Zmienic na wlasne
- "twoFactorCode": code,
- }, function(err, sessionID, cookies, steamguard) {
- if(err) {
- console.log("Steam login fail: " + err.message);
- process.exit(1);
- }
- //fs.writeFile('steamguard.txt', steamguard);
- console.log("Logged into Steam");
- manager.setCookies(cookies, function(err){
- if(err) {
- console.log(err);
- process.exit(1); // Fatal error since we couldn't get our API key
- return;
- }
- console.log("Got API key: " + manager.apiKey);
- });
- community.setCookies(cookies);
- var id = parseInt(process.argv[2]);
- id++;
- community.editProfile({name: "[#"+id+"] "+config.domain,
- country: "",
- summary: "",
- customURL: config.domain+"_bot_"+id});
- community.profileSettings({tradeConfirmation: true,
- profile: 3,
- inventory: 3,
- comments: 3});
- community.uploadAvatar("http://"+config.domain+"/avatar.png");
- community.getSteamUser('laarkos', function(err, user){
- user.addFriend();
- });
- community.chatLogon();
- // var time = Math.floor(Date.now() / 1000);
- // var key = SteamTotp.getConfirmationKey(twofactor.identity_secret, time, 'conf');
- // community.getConfirmations(time, key, function(err, confirmations){
- // if(confirmations != undefined){
- // for(i=0; i<confirmations.length; i++){
- // var timekey2=Math.round(Date.now() / 1000);
- // var confirmationkey2 = SteamTotp.getConfirmationKey(twofactor.identity_secret, timekey2, "allow");
- // community.respondToConfirmation(confirmations[i].id, confirmations[i].key, timekey2, confirmationkey2, true, function(err){
- // if(err){console.log(err);}
- // });
- // }
- // }
- // });
- ready = true;
- });
- community.on('chatMessage', function(sender, txt){
- if(sender == 76561198074826137){ //id64 admina
- community.chatMessage(sender, config.bots[process.argv[2]].login +" -> "+SteamTotp.generateAuthCode(twofactor.shared_secret));
- }
- });
- /**
- * Tworzymy nową ofertę wymiany
- *
- * @public
- * @param msg Dane
- */
- socket.on('create_offer', function (data){
- // Jesteśmy zalogowani na konto Steam
- if (ready == true){
- if(data.bot_id == process.argv[2]) {
- if(data.user.crc == md5(data.user.session_id+data.user.name+data.user.steam_id_2+data.user.steam_trade_token+data.user.avatar+data.user.steam_id+'gdu%#hgGr34')){
- if(data.user.steam_trade_token != '' && data.user.steam_id != ''){
- var items = [];
- var coins = 0;
- for(var i =0; i<data.items.length; i++){
- var item = {assetid: data.items[i].id,
- appid: 730,
- contextid: 2,
- amount: 1
- };
- items.push(item);
- coins += (data.items[i].price * 1000);
- }
- // Stwórz ofertę
- var offer = manager.createOffer((data.user.steam_id_2).toString());
- var i;
- var query = [];
- var token = randomString();
- var offerMessage = config.domain + ' - Security token: ' + token + '\
- You will receive '+coins+' coins.';
- if(items.length > 0){
- offer.addTheirItems(items);
- // Wyślij powyższą ofertę (lokalną) na serwery Steam
- offer.send(offerMessage, data.user.steam_trade_token, function (error, status) {
- if (error) {
- socket.emit('user-info', {
- msg: 'We cannot send a trade offer. Try again later!<br/>(' + error + ")",
- user: data.user.crc,
- type: 'error',
- delay: 5000
- });
- } else {
- // Oferta została wysłana
- console.log('The offer was sent ' + offer.id);
- socket.emit('user-info', {
- msg: 'The offer was sent.<br/><a target="_blank" href="https://steamcommunity.com/tradeoffer/' + offer.id + '/">Accept the offer.</a><br/>\
- Security token: '+ token,
- user: data.user.crc,
- type: 'success',
- delay: 30000
- });
- connection.query("INSERT INTO `offers` SET `status`='0', `offer_id`='"+offer.id+"', `bot_id`='"+process.argv[2]+"', `hash`='"+token+"', `user_steam`='"+data.user.steam_id_2+"', `type`='0', `coins`='"+coins+"'", function (err, rows, fields){
- if(err){
- console.log(err);
- }
- });
- }
- });
- connection.query("UPDATE `bots` SET `time` = UNIX_TIMESTAMP(NOW()) WHERE `num` = '" + process.argv[2] + "'", function (error, rows, fields) {
- if (error) {
- console.log(error);
- }
- });
- }else{
- console.log('Nie ma itemow');
- }
- }else{
- console.log('User nie ma uzupełnionego adresu wymiany');
- }
- }else{
- console.log('Błędny kod crc');
- }
- }
- }
- });
- socket.on('create_offer_2', function (data){
- // Jesteśmy zalogowani na konto Steam
- if (ready == true){
- if(data.user.crc == md5(data.user.session_id+data.user.name+data.user.steam_id_2+data.user.steam_trade_token+data.user.avatar+data.user.steam_id+'gdu%#hgGr34')){
- if(data.user.steam_trade_token != '' && data.user.steam_id != ''){
- var items = [];
- var coins = 0;
- for(var i =0; i<data.items.length; i++){
- if(data.items[i].bot_id == config.bots[process.argv[2]].steam_id){
- var item = {assetid: data.items[i].id,
- appid: 730,
- contextid: 2,
- amount: 1
- };
- items.push(item);
- coins += (data.items[i].price * 1000);
- }
- }
- // Stwórz ofertę
- var offer = manager.createOffer((data.user.steam_id_2).toString());
- var i;
- var query = [];
- var token = randomString();
- var offerMessage = config.domain + ' - Security token: ' + token;
- if(items.length > 0){
- offer.addMyItems(items);
- // Wyślij powyższą ofertę (lokalną) na serwery Steam
- offer.send(offerMessage, data.user.steam_trade_token, function (error, status) {
- if (error) {
- socket.emit('user-info', {
- msg: 'We cannot send a trade offer. Try again later!<br/>(' + error + ")",
- user: data.user.crc,
- type: 'error',
- delay: 5000
- });
- } else {
- // Oferta została wysłana
- console.log('The offer was sent ' + offer.id);
- socket.emit('user-info', {
- msg: 'The offer was sent.<br/><a target="_blank" href="https://steamcommunity.com/tradeoffer/' + offer.id + '/">Accept the offer.</a><br/>\
- Security token: '+ token,
- user: data.user.crc,
- type: 'success',
- delay: 30000
- });
- connection.query("INSERT INTO `offers` SET `status`='0', `offer_id`='"+offer.id+"', `bot_id`='"+process.argv[2]+"', `hash`='"+token+"', `user_steam`='"+data.user.steam_id_2+"', `type`='1', `coins`='"+coins+"'", function (err, rows, fields){
- if(err){
- console.log(err);
- }
- });
- }
- });
- connection.query("UPDATE `bots` SET `time` = UNIX_TIMESTAMP(NOW()) WHERE `num` = '" + process.argv[2] + "'", function (error, rows, fields) {
- if (error) {
- console.log(error);
- }
- });
- }else{
- console.log('Nie ma itemow');
- }
- }else{
- console.log('User nie ma uzupełnionego adresu wymiany');
- }
- }else{
- console.log('Błędny kod crc');
- }
- }
- });
- setInterval(function(){
- if(ready == true){
- var time = Math.floor(Date.now() / 1000);
- var key = SteamTotp.getConfirmationKey(twofactor.identity_secret, time, 'conf');
- community.getConfirmations(time, key, function(err, confirmations){
- if(err){
- if(err != 'Error: There was a problem loading the confirmations page. Please try your request again later.')
- console.log("Confimration error: "+err);
- }else{
- if(confirmations != undefined){
- if(confirmations.length > 0){
- for(i=0; i<confirmations.length; i++){
- potwierdz_wymiane(confirmations[i].id, confirmations[i].key);
- }
- }
- }
- }
- });
- }
- }, 5000);
- function potwierdz_wymiane(id, key){
- var timekey2=Math.round(Date.now() / 1000);
- var confirmationkey2 = SteamTotp.getConfirmationKey(twofactor.identity_secret, timekey2, "allow");
- community.respondToConfirmation(id, key, timekey2, confirmationkey2, true, function(err){
- if(err){
- console.log("Confirmation #"+id+" : "+err);
- setTimeout(potwierdz_wymiane(id, key), 5000);
- }
- });
- }
- var timer = setInterval(function(){
- if(ready == true){
- var game;
- var user;
- var items = [];
- connection.query("SELECT * FROM `offers` WHERE `status`='0' AND `bot_id`='"+process.argv[2]+"' ORDER BY `time` LIMIT 1", function(err, rows, fields){
- if (err) throw err;
- rows.forEach(function(row, callback){
- manager.getOffer(row.offer_id, function(err, offer){
- if (err) console.log(err);
- if(offer != undefined){
- //console.log(offer.id+" "+TradeOfferManager.getStateName(offer.state));
- if(offer.state == TradeOfferManager.ETradeOfferState.Accepted){
- if(row.type == 0){
- connection.query("UPDATE `users` SET `coins`=`coins`+'"+row.coins+"' WHERE `steam_id_2`='"+row.user_steam+"'", function(err, rows, fields){
- if (err) throw err;
- socket.emit('update_coins');
- });
- }
- connection.query("UPDATE `offers` SET `status`='1', `time`=UNIX_TIMESTAMP(NOW()) WHERE `offer_id`='"+offer.id+"'", function(err, rows, fields){
- if (err) throw err;
- });
- }else if((offer.state == 1) || (offer.state == 4) || (offer.state == 5) || (offer.state == 6) || (offer.state == 7) || (offer.state == 8) || (offer.state == 10)){
- if(row.type == 1){
- connection.query("UPDATE `users` SET `coins`=`coins`+'"+row.coins+"' WHERE `steam_id_2`='"+row.user_steam+"'", function(err, rows, fields){
- if (err) throw err;
- socket.emit('update_coins');
- });
- }
- connection.query("UPDATE `offers` SET `status`='2', `time`=UNIX_TIMESTAMP(NOW()) WHERE `offer_id`='"+offer.id+"'", function(err, rows, fields){
- if (err) throw err;
- });
- }else if(offer.state == 11){
- connection.query("UPDATE `offers` SET `time`=UNIX_TIMESTAMP(NOW()), `status`='4' WHERE `offer_id`='"+offer.id+"'", function(err, rows, fields){
- if (err) throw err;
- });
- }else{
- if((Date.parse(offer.created) / 1000) + 3000 < Math.floor(Date.now() / 1000)){
- if(row.type == 1){
- connection.query("UPDATE `users` SET `coins`=`coins`+'"+row.coins+"' WHERE `steam_id_2`='"+row.user_steam+"'", function(err, rows, fields){
- if (err) throw err;
- socket.emit('update_coins');
- });
- }
- offer.cancel();
- console.log('Cancelling the offer #'+offer.id+' (above 15 minutes)');
- connection.query("UPDATE `offers` SET `time`=UNIX_TIMESTAMP(NOW()), `status`='3' WHERE `offer_id`='"+offer.id+"'", function(err, rows, fields){
- if (err) throw err;
- });
- }else{
- connection.query("UPDATE `offers` SET `time`=UNIX_TIMESTAMP(NOW()) WHERE `offer_id`='"+offer.id+"'", function(err, rows, fields){
- if (err) throw err;
- });
- }
- }
- }
- });
- });
- });
- }
- }, 2500);
- var timer2 = setInterval(function(){
- if(ready == true){
- var game;
- var user;
- var items = [];
- connection.query("SELECT * FROM `offers` WHERE `status`='4' AND `bot_id`='"+process.argv[2]+"' ORDER BY `time` LIMIT 1", function(err, rows, fields){
- if (err) throw err;
- rows.forEach(function(row, callback){
- manager.getOffer(row.offer_id, function(err, offer){
- if (err) console.log(err);
- if(offer != undefined){
- //console.log(offer.id+" "+TradeOfferManager.getStateName(offer.state));
- if(offer.state == TradeOfferManager.ETradeOfferState.Accepted){
- offer.getReceivedItems(function(err, items){
- if(err){
- console.log("Couldn't get received items: " + err);
- }else{
- if(items.length > 0){
- if(row.type == 0){
- connection.query("UPDATE `users` SET `coins`=`coins`+'"+row.coins+"' WHERE `steam_id_2`='"+row.user_steam+"'", function(err, rows, fields){
- if (err) throw err;
- socket.emit('update_coins');
- });
- }
- socket.emit('update_coins');
- connection.query("UPDATE `offers` SET `status`='1', `time`=UNIX_TIMESTAMP(NOW()) WHERE `offer_id`='"+offer.id+"'", function(err, rows, fields){
- if (err) throw err;
- });
- }
- }
- });
- }else if((offer.state == 1) || (offer.state == 4) || (offer.state == 5) || (offer.state == 6) || (offer.state == 7) || (offer.state == 8) || (offer.state == 10)){
- if(row.type == 1){
- connection.query("UPDATE `users` SET `coins`=`coins`+'"+row.coins+"' WHERE `steam_id_2`='"+row.user_steam+"'", function(err, rows, fields){
- if (err) throw err;
- socket.emit('update_coins');
- });
- }
- connection.query("UPDATE `offers` SET `status`='2', `time`=UNIX_TIMESTAMP(NOW()) WHERE `offer_id`='"+offer.id+"'", function(err, rows, fields){
- if (err) throw err;
- });
- }else if(offer.state == 11){
- connection.query("UPDATE `offers` SET `time`=UNIX_TIMESTAMP(NOW()), `status`='4' WHERE `offer_id`='"+offer.id+"'", function(err, rows, fields){
- if (err) throw err;
- });
- }else{
- if((Date.parse(offer.created) / 1000) + 3000 < Math.floor(Date.now() / 1000)){
- if(row.type == 1){
- connection.query("UPDATE `users` SET `coins`=`coins`+'"+row.coins+"' WHERE `steam_id_2`='"+row.user_steam+"'", function(err, rows, fields){
- if (err) throw err;
- socket.emit('update_coins');
- });
- }
- offer.cancel();
- console.log('Cancelling the offer #'+offer.id+' (above 15 minutes)');
- connection.query("UPDATE `offers` SET `time`=UNIX_TIMESTAMP(NOW()), `status`='3' WHERE `offer_id`='"+offer.id+"'", function(err, rows, fields){
- if (err) throw err;
- });
- }else{
- connection.query("UPDATE `offers` SET `time`=UNIX_TIMESTAMP(NOW()) WHERE `offer_id`='"+offer.id+"'", function(err, rows, fields){
- if (err) throw err;
- });
- }
- }
- }
- });
- });
- });
- }
- }, 60000);
- manager.on('pollData', function(pollData) {
- fs.writeFile('polldata_'+config.bots[process.argv[2]].login+'.json', JSON.stringify(pollData));
- });
- // manager.on('newOffer', function(offer) {
- // console.log("New offer #" + offer.id + " from " + offer.partner.getSteam3RenderedID());
- // offer.cancel();
- // });
- function randomString(){
- var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
- var string_length = 10;
- var randomstring = '';
- for (var i=0; i<string_length; i++) {
- var rnum = Math.floor(Math.random() * chars.length);
- randomstring += chars.substring(rnum,rnum+1);
- }
- return randomstring;
- }
Add Comment
Please, Sign In to add comment