Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var currentWorkingSite = 'http://www.skinbattles.net/',
- //var currentWorkingSite = 'http://localhost/skinbattles/',
- superPassword = 'gWEh7aFR';
- /*
- DONT FORGET TO REMOVE HANDCODED STEAM IDS;
- */
- /**
- * first class variables
- */
- var config = require('./config.js'),
- fs = require('fs'),
- crypto = require('crypto');
- /**
- * configure express
- */
- var expressApp = require('express')();
- /**
- * configure http server
- */
- var http = require('http').Server(expressApp);
- http.listen(8080);
- /**
- * configure request-json
- */
- var reqJSON = require('request-json'),
- requestJSON = reqJSON.createClient(currentWorkingSite);
- /**
- * configure socket.io
- */
- var io = require('socket.io')(http);
- /**
- * configure steam npm package
- * configure steam-trade-offers package;
- *
- * libraries
- *
- */
- var SteamUser = require('steam-user');
- var SteamTotp = require('steam-totp');
- var SteamMobileAuth = require('steamcommunity-mobile-confirmations');
- var SteamTradeOffers = require('steam-tradeoffers');
- var getSteamApiKey = require('steam-web-api-key');
- /**
- * constructors
- */
- //console.log(config.botAccounts);
- var steamOffers = [],
- client = [],
- mobileConfirmations = [];
- var totalBotsFound = Object.keys(config.botAccounts).length;
- var botsInQueue = [];
- console.log('Found '+totalBotsFound+' bot(s). Trying to connect them');
- for (var key in config.botAccounts) {
- var progName = config.botAccounts[key].name;
- botsInQueue.push(progName);
- }
- var checkForBots = function(key) {
- connectBotWithKey(key);
- }
- var connectBotWithKey = function(key) {
- var progName = config.botAccounts[key].name;
- steamOffers[progName] = new SteamTradeOffers();
- client[progName] = new SteamUser();
- client[progName].setSentry(getSHA1(fs.readFileSync(__dirname + '/' + config.botAccounts[key].ssfn)));
- config.botAccounts[key].logOnOptions.twoFactorCode = SteamTotp.generateAuthCode(config.botAccounts[key].shared_secret);
- client[progName].logOn(config.botAccounts[key].logOnOptions);
- client[progName].on('loggedOn', function(details) {
- console.log('Steam client for ' + progName + ' ('+config.botAccounts[key].logOnOptions['accountName']+') connected');
- client[progName].setPersona(SteamUser.Steam.EPersonaState.Online);
- });
- client[progName].on('error', function() {
- client[progName].logOn(config.botAccounts[key].logOnOptions);
- });
- client[progName].on('webSession', function (sessionID, cookies) {
- console.log('Web session set for ' + progName);
- getSteamApiKey({
- sessionID: sessionID,
- webCookie: cookies
- }, function(err, apiKey) {
- steamOffers[progName].setup({
- sessionID: sessionID,
- webCookie: cookies,
- APIKey: apiKey
- });
- console.log('Steam webLogon is fine for ' + progName);
- });
- //we only set executeInterval once;
- if (key === 0) {
- console.log(progName + ' has been detected as primary bot. Initializing trade-offers request every X seconds');
- var intervalForOffers = executeIntervalForOffers();
- }
- mobileConfirmations[progName] = new SteamMobileAuth({
- steamid: config.botAccounts[key].steamid,
- identity_secret: config.botAccounts[key].identity_secret,
- device_id: "android:" + Date.now(),
- webCookie: cookies
- });
- botsInQueue.splice(0,1);
- if (botsInQueue.length > 0) {
- checkForBots(key+1);
- }
- });
- }
- checkForBots(0);
- /**
- * Checking in 10 sec interval if new trade confirmation have to be accepted.
- */
- setInterval(function () {
- if (Object.keys(mobileConfirmations).length) {
- //for (var key in mobileConfirmations) {
- mobileConfirmations['FirstBot'].FetchConfirmations(function (err, confirmations) {
- if (err) {
- return;
- }
- if (confirmations.length > 0) {
- if (!confirmations.length){
- return;
- }
- console.log('Received ' + confirmations.length + ' outstanding confirmations for FirstBot');
- mobileConfirmations['FirstBot'].AcceptConfirmation(confirmations[0], function (err, result ){
- if (err) {
- console.log(err);
- return;
- }
- console.log('Accepted confirmation result for FirstBot: '+result);
- });
- };
- });
- mobileConfirmations['SecondBot'].FetchConfirmations(function (err, confirmations) {
- if (err) {
- return;
- }
- if (confirmations.length > 0) {
- if (!confirmations.length){
- return;
- }
- console.log('Received ' + confirmations.length + ' outstanding confirmations for SecondBot');
- mobileConfirmations['SecondBot'].AcceptConfirmation(confirmations[0], function (err, result ){
- if (err) {
- console.log(err);
- return;
- }
- console.log('Accepted confirmation result for SecondBot : '+result);
- });
- };
- });
- mobileConfirmations['ThirdBot'].FetchConfirmations(function (err, confirmations) {
- if (err) {
- return;
- }
- if (confirmations.length > 0) {
- if (!confirmations.length){
- return;
- }
- console.log('Received ' + confirmations.length + ' outstanding confirmations for ThirdBot');
- mobileConfirmations['ThirdBot'].AcceptConfirmation(confirmations[0], function (err, result ){
- if (err) {
- console.log(err);
- return;
- }
- console.log('Accepted confirmation result for ThirdBot : '+result);
- });
- };
- });
- }
- }, 10000);
- /**
- * new round initialization;
- */
- //check if there is a new round already active;
- requestJSON.get('api/activeRoundGoingOn', function(err, res, json) {
- if (res.statusCode === 200) {
- if (json.success === true) {
- WinningPercentage = json.game.ticket;
- HashOfGame = json.game.game_hash;
- SaltOfGame = json.game.game_salt;
- currentGameID = json.game.id;
- console.log('Found new active round with id #' + json.game.id + '. Setting it up');
- //emit new round;
- io.emit('newGameRound', {
- gameID: currentGameID,
- gameHash: HashOfGame
- });
- respondToConsole();
- } else {
- initiateNewRound();
- }
- }
- });
- requestJSON.get('api/activeRoundGoingOnRoulette', function(err, res, json) {
- if (typeof res === 'undefined') return;
- if (res.statusCode === 200) {
- if (json.success === true) {
- console.log('Found new active round with id #' + json.game.id + '. Setting it up');
- //emit new round;
- io.emit('newGameRoundRoulette', {
- gameID: json.game.id
- });
- startTimerForRoundRoulette();
- } else {
- initiateNewRoundRoulette();
- }
- }
- });
- var timerIDRoulette,
- timerToTickRoulette = 30;//seconds
- function startTimerForRoundRoulette() {
- if (!timerIDRoulette) {
- timerIDRoulette = setInterval(function() {
- timerToTickRoulette--;
- io.emit('timerTickRoulette', {
- timer: timerToTickRoulette
- });
- if (timerToTickRoulette <= 0) {
- console.log('Time is over roulette');
- pickWinners();
- clearInterval(timerIDRoulette);
- timerIDRoulette = false;
- }
- }, 1000);
- }
- }
- function startTimerForRound() {
- //comes from request json activeRoundGoingOn;
- //not only;
- if (!timerID) {
- timerToTick = config.gameDuration;
- timerID = setInterval(function() {
- timerToTick--;
- var minute = Math.floor(timerToTick / 60),
- second = timerToTick % 60;
- second = second.toString();
- second = second.substr(0, 2);
- io.emit('timerTick', {
- timerToTick: minute + ":" + second
- });
- if (timerToTick <= 0) {
- console.log('Time is over');
- pickAWinner(currentGameID);
- clearInterval(timerID);
- timerID = false;
- }
- }, 1000);
- } else {
- console.log('timerID is defined already');
- }
- }
- var SaltOfGame = null,
- WinningPercentage = null,
- HashOfGame = null,
- currentGameID = null,
- currentTotalPotItems = 0,
- pendingWinningTradeoffers = [],
- timerID = null;
- function respondToConsole() {
- console.log('Current Game Salt: ' + SaltOfGame);
- console.log('Next Winner percentage is: ' + WinningPercentage + '%');
- console.log('Current Game Hash is: ' + HashOfGame);
- }
- function initiateNewRoundRoulette() {
- //add new game to sql;
- addNewGameToDB_roulette();
- }
- function initiateNewRound() {
- if (gameIsPaused) {
- gameIsPaused = false;
- }
- WinningPercentage = randomInRange(0, 100);
- SaltOfGame = makeid();
- HashOfGame = crypto.createHash('md5').update(SaltOfGame + ':' + WinningPercentage).digest('hex');
- currentGameID = null;
- //add new game to sql;
- addNewGameToDB();
- }
- var peers = [],
- pendingSentOffers = [],
- timerInterval = null,
- gameIsPaused = false,
- timerToTick = 0,
- pendingUserToGetOffered = [],
- chatMessages = [],
- pendingChatMessageForUserApiKey = [],
- userIDPendingOffer = [];
- io.on('connection', function(socket) {
- //push client
- peers.push(socket);
- //emit peers
- socket.emit('peers', {
- totalPeers: peers.length
- });
- requestJSON.get('api/getChatMessages', function(err, res, json) {
- if (typeof res === 'undefined') return;
- if (res.statusCode === 200 && json.success) {
- io.emit('sendChatData', json.html);
- }
- });
- //initial request
- socket.on('ez', function() {
- requestJSON.post('api/getRoundPotRe', {
- gameid: (currentGameID ? currentGameID : 0)
- }, function(err, res, json) {
- if (typeof res === 'undefined') return;
- if (res.statusCode === 200 && json.success) {
- if (typeof io.sockets.connected === 'undefined' || typeof socket.id === 'undefined' || typeof io.sockets.connected[socket.id] === 'undefined') {
- return;
- }
- io.sockets.connected[socket.id].emit('roundPot', {
- potplayers: json.html,
- potitems: json.potitems,
- timerisactive: (!timerID ? false : true)
- });
- }
- });
- requestJSON.post('api/getRoundPotRoulette', {}, function(err, res, json) {
- if (res.statusCode === 200 && json.success) {
- if (typeof io.sockets.connected === 'undefined' || typeof socket.id === 'undefined' || typeof io.sockets.connected[socket.id] === 'undefined') {
- return;
- }
- io.sockets.connected[socket.id].emit('roundPotRoulette', {
- potplayers: json.html,
- potitems: json.potitems
- });
- }
- });
- });
- //on disconnect
- socket.on('disconnect', function(socket) {
- //delete from peers list
- peers.splice(peers.indexOf(socket), 1);
- //update count
- io.emit('peers', {
- totalPeers: peers.length
- });
- });
- //requestWithdraw
- socket.on('requestWithdraw', function(data) {
- requestJSON.get('api/userExists/' + data.apikey, function(err, res, user) {
- if (typeof res === 'undefined') return;
- if (res.statusCode === 200 && user.success) {
- requestJSON.post('api/checkWithdrawItems', {
- items: data.items,
- userid: user.userid
- }, function(err, res, json) {
- //json.success
- //json.reason (success == false);
- //json.items.id/json.items.name (success == true);
- //json.tradeurl
- if (typeof res === 'undefined') return;
- if (res.statusCode === 200 && json.success) {
- console.log('Items of a withdrawal request were all found in our database. We proceed with a steam trade offer.');
- //iterate through all bots
- //cache all bots;
- //get first bot account;
- var botsToQueue = [];
- for (var key in config.botAccounts) {
- var progName = config.botAccounts[key].name;
- botsToQueue.push(progName);
- }
- //cache withdrawal items;
- var withdrawalItems = json.items,
- theoryCache = json.items.length;
- var withdrawFromBot = function(botKEY) {
- var currentAccountBotName = config.botAccounts[botKEY].name;
- botsToQueue.splice(0,1);
- steamOffers[currentAccountBotName].loadMyInventory({
- appId: 730,
- contextId: 2,
- tradableOnly: true
- }, function(err, inventoryItems) {
- //if err reversewithdrawitems;
- if (err) {
- requestJSON.post('api/reverseStatusWithdrawItems', {
- items: data.items,
- userid: user.userid
- }, function(err, res, json) {
- if (typeof res === 'undefined') return;
- if (res.statusCode === 200 && json.success) {
- console.log('Withdrawal items were successfully set to pending status after failing to send them');
- } else {
- console.log('WEIRD ERROR CALL DAKIS');
- }
- });
- console.log('Couldnt load my inventory');
- return;
- }
- console.log('Loaded inventory upon withdrawal request of ' + user.userid);
- var itemsFound = [];
- for (var key in withdrawalItems) {
- //json.items[]id/json.items[]name
- for (var x in inventoryItems) {
- if (inventoryItems[x].market_hash_name === withdrawalItems[key].name) {
- itemsFound.push({
- name: inventoryItems[x].market_hash_name,
- assetid: inventoryItems[x].id
- });
- inventoryItems.splice(x, 1);
- break;
- }
- }
- }
- for (var o in itemsFound) {
- for (var z in withdrawalItems) {
- if (itemsFound[o].name === withdrawalItems[z].name) {
- withdrawalItems.splice(z, 1);
- break;
- }
- }
- }
- //if (itemsFound.length === json.items.length) {
- //console.log('Found all items. Proceeding to give items to winner with userID: ' + user.userid);
- //} else {
- console.log('Found '+itemsFound.length+' on BOT #'+currentAccountBotName +'. Items left to send:' + withdrawalItems.length);
- //}
- var itemsToSend = [],
- retriesToSendWinnerItems = 5;
- for (var wiss in itemsFound) {
- itemsToSend.push({
- "appid": 730,
- "contextid": 2,
- "amount": 1,
- "assetid": itemsFound[wiss].assetid
- });
- }
- var sendWinner = function() {
- retriesToSendWinnerItems--;
- var token = null,
- accountid = null;
- if (!json.tradeurl) {
- io.emit('playerError', {
- apikey: data.apikey,
- html: "Something weird came up while sending your items. Please try again. <div class='modal-close'>close</div>"
- });
- console.log('Couldnt find tradeurl wtf');
- return;
- }
- token = json.tradeurl;
- token = token.substr(token.indexOf('&token') + 7);
- accountid = json.tradeurl;
- accountid = accountid.substr(accountid.indexOf('?partner') + 9);
- accountid = accountid.substring(0, accountid.indexOf('&'));
- steamOffers[currentAccountBotName].getHoldDuration({
- partnerAccountId:accountid,
- accessToken:token
- }, function (err,duration) {
- if (err) {
- console.log('Error for game hold duration during withdrawl');
- requestJSON.post('api/reverseStatusWithdrawItems', {
- items: data.items,
- userid: user.userid
- }, function(err, res, json) {
- if (typeof res === 'undefined') return;
- if (res.statusCode === 200 && json.success) {
- console.log('Withdrawal items were successfully set to pending status after failing to send them');
- } else {
- console.log('WEIRD ERROR CALL DAKIS');
- }
- });
- socket.emit('playerError', {
- apikey: data.apikey,
- html: "Error trying to send you your items. Please try again. You might have mobile auth or escrow off. <div class='modal-close'>close</div>"
- });
- return;
- }
- if ((duration.my == 0) && (duration.their == 0)) {
- steamOffers[currentAccountBotName].makeOffer({
- partnerAccountId: accountid,
- accessToken: token,
- itemsFromMe: itemsToSend,
- itemsFromThem: [],
- message: 'Withdrawal items upon request. Thanks for playing.'
- }, function(err, response) {
- if (err) {
- console.log('Error sending withdrawal request to userID ' + user.userid);
- if (retriesToSendWinnerItems >= 0) {
- console.log('Retry sending offer: ' + retriesToSendWinnerItems);
- setTimeout(function() {
- sendWinner();
- }, 2000);
- } else {
- requestJSON.post('api/reverseStatusWithdrawItems', {
- items: data.items,
- userid: user.userid
- }, function(err, res, json) {
- if (typeof res === 'undefined') return;
- if (res.statusCode === 200 && json.success) {
- console.log('Withdrawal items were successfully set to pending status after failing to send them');
- } else {
- console.log('WEIRD ERROR CALL DAKIS');
- }
- });
- io.emit('playerError', {
- apikey: data.apikey,
- html: "We tried 5 times to send you your withdraws. Our bot will retry shortly. <div class='modal-close'>close</div>"
- });
- }
- return;
- }
- console.log('Withdrawal was successful for user ' + user.userid);
- if (withdrawalItems.length > 0 && botsToQueue.length > 0) {
- console.log('I still have items to send. Ill proceed with another bot inventory');
- withdrawFromBot(botKEY+1);
- } else {
- //no need for update now;
- io.emit('winnerMessage', {
- apikey: data.apikey,
- html: "Your items has been sent to you. <a href='https://steamcommunity.com/tradeoffer/" + response.tradeofferid + "' class='link' target='_blank'>Click here to accept your items.</a><div class='modal-close'>close</div>",
- });
- }
- });
- } else {
- requestJSON.post('api/reverseStatusWithdrawItems', {
- items: data.items,
- userid: user.userid
- }, function(err, res, json) {
- if (typeof res === 'undefined') return;
- if (res.statusCode === 200 && json.success) {
- console.log('Withdrawal items were successfully set to pending status after failing to send them');
- } else {
- console.log('WEIRD ERROR CALL DAKIS');
- }
- });
- socket.emit('playerError', {
- apikey: data.apikey,
- html: "Error trying to send you your items. Please try again. You might have mobile auth or escrow off. <div class='modal-close'>close</div>"
- });
- return;
- }
- });
- };
- if (itemsFound.length === 0 && (withdrawalItems.length > 0 && botsToQueue.length > 0)) {
- console.log('Current bot has no items to withdraw but still got items to send. Proceeding with another bot.');
- withdrawFromBot(botKEY+1);
- } else if (itemsFound.length === 0) {
- console.log('Didnt found all items. Send everything i found.');
- return;
- } else {
- sendWinner();
- }
- });
- }
- withdrawFromBot(0);
- } else {
- requestJSON.post('api/reverseStatusWithdrawItems', {
- items: data.items,
- userid: user.userid
- }, function(err, res, json) {
- if (typeof res === 'undefined') return;
- if (res.statusCode === 200 && json.success) {
- console.log('Withdrawal items were successfully set to pending status after failing to send them');
- } else {
- console.log('WEIRD ERROR CALL DAKIS');
- }
- });
- socket.emit('playerError', {
- apikey: data.apikey,
- html: (json.reason ? json.reason : "Something went terribly wrong. Please try again") + "<div class='modal-close'>close</div>"
- });
- return;
- }
- });
- }
- });
- });
- //requestDeposit;
- socket.on('requestDeposit', function(data) {
- requestJSON.get('api/userExists/' + data.apikey, function(err, res, user) {
- if (typeof res === 'undefined') return;
- if (res.statusCode === 200 && user.success) {
- if (data.action == 'roulette') {
- requestJSON.post('api/validateItemsRoulette', {
- items: data.items,
- userid: user.userid,
- type: data.type
- }, function(err, res, json) {
- if (res.statusCode === 200 && json.success) {
- if (json.error) {
- socket.emit('playerError', {
- apikey: data.apikey,
- html: "Oops! "+json.message+". Please try again. <div class='modal-close'>close</div>"
- });
- return;
- }
- io.emit('enterPot', {
- apikey: data.apikey,
- html: "You successfully have entered current Game Roulette Round. <div class='modal-close'>close</div>"
- });
- requestJSON.post('api/getRoundPotRoulette', {
- gameid: currentGameID
- }, function(err, res, json) {
- if (res.statusCode === 200 && json.success) {
- io.emit('roundPotRoulette', {
- potplayers: json.html,
- potitems: json.potitems
- });
- }
- });
- } else {
- console.log(json);
- socket.emit('playerError', {
- apikey: data.apikey,
- html: "Oops! Something went wrong while we were trying to deposit your items. Please try again. <div class='modal-close'>close</div>"
- });
- return;
- }
- });
- } else {
- requestJSON.post('api/validateItems', {
- items: data.items,
- userid: user.userid,
- gameid: currentGameID
- }, function(err, res, json) {
- if (typeof res === 'undefined') return;
- if (res.statusCode === 200 && json.success) {
- if (json.error) {
- socket.emit('playerError', {
- apikey: data.apikey,
- html: "Oops! We're afraid that you tried to deposit more than 10 items in current round. Please try again. <div class='modal-close'>close</div>"
- });
- return;
- }
- io.emit('enterPot', {
- gameid: currentGameID,
- apikey: data.apikey,
- html: "You entered Game Round # " + currentGameID + ". You can view more stats on the Current Pot Players sidebar. <div class='modal-close'>close</div>"
- });
- requestJSON.post('api/getRoundPotRe', {
- gameid: currentGameID
- }, function(err, res, json) {
- if (res.statusCode === 200 && json.success) {
- io.emit('roundPot', {
- potplayers: json.html,
- potitems: json.potitems,
- timerisactive: (!timerID ? false : true)
- });
- currentTotalPotItems = json.totalPotItems;
- if (currentTotalPotItems >= config.itemsToStart) {
- if (wheelStillSpinning) {
- setTimeout(function() {
- startTimerForRound();
- }, 10000);
- } else {
- startTimerForRound();
- }
- }
- }
- });
- } else {
- socket.emit('playerError', {
- apikey: data.apikey,
- html: "Oops! Something went wrong while we were trying to deposit your items. Please try again. <div class='modal-close'>close</div>"
- });
- return;
- }
- });
- }
- }
- });
- });
- //requestOffer
- socket.on('requestOffer', function(data) {
- //rewrote;
- requestJSON.get('api/userExists/' + data.apikey, function(err, res, user) {
- //**user.userid
- //**user.tradeurl
- //**user.steamid
- //**user.avatar
- if (typeof res === 'undefined') return;
- if (res.statusCode === 200 && user.success) {
- if (userIDPendingOffer.indexOf(user.userid) > -1) {
- console.log('Cant offer him. Still awaiting for another offer to be accepted/declined of user: ' + user.userid);
- socket.emit('playerError', {
- apikey: data.apikey,
- html: "There is already a pending offer for you. Please either accept or decline it to be able to make a new trade. <div class='modal-close'>close</div>"
- });
- return;
- }
- if (pendingUserToGetOffered.indexOf(user.userid) > -1) {
- //there is a pending getOffer request; return;
- console.log('Cant offer him. Still awaiting for steam to respond for another trade offer of ' + user.userid);
- socket.emit('playerError', {
- apikey: data.apikey,
- html: "There is already a pending offer for you and we're afraid that steam is delayed :( <div class='modal-close'>close</div>"
- });
- return;
- }
- pendingUserToGetOffered.push(user.userid);
- userIDPendingOffer.push(user.userid);
- var token = user.tradeurl;
- token = token.substr(token.indexOf('&token') + 7);
- var accountid = user.tradeurl;
- accountid = accountid.substr(accountid.indexOf('?partner') + 9);
- accountid = accountid.substring(0, accountid.indexOf('&'));
- //iterate through all bots
- //cache all bots;
- //get first bot account;
- var botsToQueue = [];
- for (var key in config.botAccounts) {
- var progName = config.botAccounts[key].name;
- botsToQueue.push(progName);
- }
- var makeOfferFromBot = function(key) {
- var currentAccountBotName = config.botAccounts[key].name;
- botsToQueue.splice(0,1);
- steamOffers[currentAccountBotName].loadMyInventory({
- appId: 730,
- contextId: 2,
- tradableOnly: true
- }, function(err, inventoryItems) {
- if (typeof data.items === 'undefined' || typeof inventoryItems === 'undefined') {
- console.log('FUCK STEAM YO');
- socket.emit('playerError', {
- apikey: data.apikey,
- html: "Couldn't reach steam. Please try again. <div class='modal-close'>close</div>"
- });
- pendingUserToGetOffered.splice(pendingUserToGetOffered.indexOf(user.userid), 1);
- userIDPendingOffer.splice(userIDPendingOffer.indexOf(user.userid), 1);
- return;
- }
- if ((data.items.length + inventoryItems.length) >= 999) {
- console.log('Bot #'+currentAccountBotName + ' is full. Proceeding with another bot to make an offer');
- if (botsToQueue.length > 0) {
- makeOfferFromBot(key+1);
- }
- return;
- }
- //we got our bot that can accept that offer;
- steamOffers[currentAccountBotName].getHoldDuration({
- partnerAccountId: accountid,
- accessToken: token
- }, function (err1, duration) {
- if (!err1) {
- if ((duration.my == 0) && (duration.their == 0)) {
- var partnerInventoryRetry = 5;
- var loadPartnerInventory = function() {
- partnerInventoryRetry--;
- steamOffers[currentAccountBotName].loadPartnerInventory({
- appId: 730,
- contextId: 2,
- partnerAccountId: accountid
- }, function(err, items) {
- if (err) {
- console.log('Error loadPartnerInventory ' + err);
- if (partnerInventoryRetry >= 0) {
- console.log('Retry loadPartnerInventory step: ' + partnerInventoryRetry);
- setTimeout(function() {
- loadPartnerInventory();
- }, 2000);
- } else {
- userIDPendingOffer.splice(userIDPendingOffer.indexOf(user.userid), 1);
- }
- } else {
- var lengthToCheck = data.items.length,
- itemsExist = 0,
- itemsInfo = [];
- for (var i = 0; i < items.length; i++) {
- for (var z in data.items) {
- if (items[i].id === data.items[z] && items[i].tradable) {
- itemsInfo.push({
- name: items[i].market_hash_name
- });
- itemsExist += 1;
- continue;
- }
- if (itemsExist === lengthToCheck) break;
- }
- }
- //after loading inventory
- if (itemsExist === lengthToCheck) {
- //all items proposed from site exists
- //move on and make him an offer;
- var itemsToRequest = buildItemsArrayToRequest(data.items);
- console.log('Trying to make ' + user.steamid + ' an offer');
- //check if he has alreayd a pending offer with same assetid;
- if (pendingSentOffers.length > 0) {
- var newArray_ = [];
- for (var z in itemsToRequest) {
- newArray_.push(itemsToRequest[z].assetid);
- }
- for (var z in pendingSentOffers) {
- if (pendingSentOffers[z].userid == user.userid) {
- for (var ex in pendingSentOffers[z].assetids) {
- if (newArray_.indexOf(pendingSentOffers[z].assetids[ex]) > -1) {
- socket.emit('playerError', {
- apikey: data.apikey,
- html: "You tried to deposit an already pending item. <div class='modal-close'>close</div>"
- });
- pendingUserToGetOffered.splice(pendingUserToGetOffered.indexOf(user.userid), 1);
- userIDPendingOffer.splice(userIDPendingOffer.indexOf(user.userid), 1);
- return;
- }
- }
- }
- }
- }
- var makeHimAnOfferTries = 5;
- var makeHimAnOffer = function() {
- steamOffers[currentAccountBotName].makeOffer({
- partnerAccountId: accountid,
- accessToken: token,
- itemsFromMe: [],
- itemsFromThem: itemsToRequest,
- message: 'Deposit skins to Skinbattles inventory'
- }, function(err, response) {
- if (err) {
- console.log('Error making an offer: Retry ' + makeHimAnOfferTries);
- makeHimAnOfferTries--;
- if (makeHimAnOfferTries > 0) {
- setTimeout(function() {
- makeHimAnOffer();
- }, 3000);
- } else {
- socket.emit('playerError', {
- apikey: data.apikey,
- html: "Couldn't reach steam. Please try again. <div class='modal-close'>close</div>"
- });
- pendingUserToGetOffered.splice(pendingUserToGetOffered.indexOf(user.userid), 1);
- userIDPendingOffer.splice(userIDPendingOffer.indexOf(user.userid), 1);
- }
- return;
- }
- requestJSON.post('api/getItemInfo', {
- items: itemsInfo
- }, function(err, res, json) {
- if (json["items"].length === itemsInfo.length) {
- var assetidsMotherfucker = [];
- for (var z in itemsToRequest) {
- assetidsMotherfucker.push(itemsToRequest[z].assetid);
- }
- pendingSentOffers.push({
- botName: currentAccountBotName,
- tradeofferid: response.tradeofferid,
- steamid: user.steamid,
- userid: user.userid,
- items: json.items,
- assetids: assetidsMotherfucker
- });
- socket.emit('playerDeposited', {
- apikey: data.apikey,
- html: "Your deposit has been successful <a href='https://steamcommunity.com/tradeoffer/" + response.tradeofferid + "' class='link' target='_blank'>Click here to view the trade offer</a><div class='modal-close'>close</div>",
- });
- console.log('Offer with id ' + response.tradeofferid + ' of user with steam id ' + user.steamid + ' has been pushed');
- }
- pendingUserToGetOffered.splice(pendingUserToGetOffered.indexOf(user.userid), 1);
- });
- });
- }
- makeHimAnOffer();
- } else {
- socket.emit('playerError', {
- apikey: data.apikey,
- html: "Couldn't find deposited items in your inventory. Please try again. <div class='modal-close'>close</div>"
- });
- pendingUserToGetOffered.splice(pendingUserToGetOffered.indexOf(user.userid), 1);
- }
- }
- });
- }
- loadPartnerInventory();
- } else {
- console.log("Removing user from queue. Has mobile auth off/escrow more than 0");
- socket.emit('playerError', {
- apikey: data.apikey,
- html: "You either don't have mobile auth or escrow and a trade to you is unavailabe. <div class='modal-close'>close</div>"
- });
- pendingUserToGetOffered.splice(pendingUserToGetOffered.indexOf(user.userid), 1);
- userIDPendingOffer.splice(userIDPendingOffer.indexOf(user.userid), 1);
- }
- } else {
- console.log("Removing user from queue to get offered. Got an error.");
- socket.emit('playerError', {
- apikey: data.apikey,
- html: "Error trying to make you an offer. Please try again. You might have mobile auth or escrow off. <div class='modal-close'>close</div>"
- });
- pendingUserToGetOffered.splice(pendingUserToGetOffered.indexOf(user.userid), 1);
- userIDPendingOffer.splice(userIDPendingOffer.indexOf(user.userid), 1);
- }
- });
- });
- }
- makeOfferFromBot(0);
- }
- });
- });
- socket.on('sendChatMessage', function(data) {
- if (pendingChatMessageForUserApiKey.indexOf(data.apikey) > -1) {
- console.log('Didnt push his previous message. Returning');
- return;
- }
- pendingChatMessageForUserApiKey.push(data.apikey);
- requestJSON.post('api/saveChatMessage', {
- apikey: data.apikey,
- message: data.message
- }, function(err, res, json) {
- if (res.statusCode === 200 && json.success) {
- io.emit('sendChatData', json.html);
- } else {
- console.log('Error api/saveChatMessage');
- }
- pendingChatMessageForUserApiKey.splice(pendingChatMessageForUserApiKey.indexOf(data.apikey), 1);
- });
- });
- /**
- * admin emits
- */
- socket.on('deletedMessages', function() {
- requestJSON.get('api/getChatMessages', function(err, res, json) {
- if (res.statusCode === 200 && json.success) {
- io.emit('sendChatData', json.html);
- }
- });
- });
- socket.on('loadBotHistory', function() {
- steamOffers.getOffers({
- get_sent_offers: 1, //for sent offers
- time_historical_cutoff: Math.round(Date.now() / 1000),
- get_descriptions: 1
- }, function(error, body) {
- if (body && body.response && body.response.trade_offers_sent) {
- body.response.trade_offers_sent.splice(50, 500);
- socket.emit('loadedBotHistory', {
- descriptions: body.response.descriptions,
- offers: body.response.trade_offers_sent
- });
- }
- });
- });
- socket.on('sendExtraItems', function(data) {
- console.log('Got an emit to send extra items to admin. Proceeding to load my inventory');
- //x === bot name;
- //data.items[x] === assetids;
- steamOffers[data.botname].loadMyInventory({
- appId: 730,
- contextId: 2,
- tradableOnly: true
- }, function(err, inventoryItems) {
- if (err) {
- console.log('Couldnt load my inventory to send items to admin');
- return;
- }
- if (typeof data.items === 'undefined' || !data.items) {
- console.log('FUCK STEAM YO');
- return;
- }
- console.log('Loaded '+data.botname+' inventory to send '+data.items.length+' items to admin');
- var itemsFound = [];
- for (var key in data.items) {
- //dakis (3)
- //json.items[]id/json.items[]name
- for (var x in inventoryItems) {
- //dakis (2);
- if (inventoryItems[x].id == data.items[key]) {
- itemsFound.push({
- name: inventoryItems[x].market_hash_name,
- assetid: inventoryItems[x].id
- });
- inventoryItems.splice(x, 1);
- break;
- }
- }
- }
- console.log('Found '+itemsFound.length+' to send to admin');
- var itemsToSend = [],
- retriesToSendWinnerItems = 5;
- for (var wiss in itemsFound) {
- itemsToSend.push({
- "appid": 730,
- "contextid": 2,
- "amount": 1,
- "assetid": itemsFound[wiss].assetid
- });
- }
- //https://steamcommunity.com/tradeoffer/new/?partner=5713742&token=92nQauGO
- steamOffers[data.botname].getHoldDuration({
- partnerAccountId: '204212989',//'5713742',//'204212989',
- accessToken: 'Iy5PVF-h',//'92nQauGO',//'Iy5PVF-h'
- }, function (err,duration) {
- if (err) {
- console.log('Error for game hold duration to send admin extra items');
- return;
- }
- if ((duration.my == 0) && (duration.their == 0)) {
- steamOffers[data.botname].makeOffer({
- partnerAccountId: '204212989',//'5713742',//'204212989',
- accessToken: 'Iy5PVF-h',//'92nQauGO',//'Iy5PVF-h'
- itemsFromMe: itemsToSend,
- itemsFromThem: [],
- message: 'Withdrawal items upon request.'
- }, function(err, response) {
- if (err) {
- console.log('Error sending extra items to admin');
- return;
- }
- requestJSON.get('api/setHoldItemsToSent', function(err, res, json) {
- if (typeof res === 'undefined') return;
- });
- console.log('Extra items were send to admin from '+data.botname+' and their statuses were set to SENT');
- });
- } else {
- console.log('Duration isnt 0 for admin. wtf');
- return;
- }
- });
- });
- });
- if (currentGameID) {
- socket.emit('newGameRound', {
- gameID: currentGameID,
- gameHash: HashOfGame
- });
- }
- //get game no roulette
- requestJSON.get('api/currentRouletteGame', function(err, res, json) {
- if (res.statusCode === 200 && json.success) {
- socket.emit('newGameRoundRoulette', {
- gameID: json.gameID,
- });
- }
- });
- });
- var buildItemsArrayToRequest = function(items) {
- var itemsToSend = [];
- for (var z in items) {
- //z key
- //items[0] item.id;
- itemsToSend.push({
- appid: 730,
- contextid: 2,
- amount: 1,
- assetid: items[z]
- });
- }
- return itemsToSend;
- }
- /**
- * functions;
- */
- var pendingHoldTradeOfferIds = [],
- pendingHoldWinnerTradeOfferIds = [];
- var timesCheckedAnID = [];
- function executeIntervalForOffers() {
- setInterval(function() {
- if (pendingSentOffers.length > 0 && !gameIsPaused) {
- pendingSentOffers.forEach(function(offer, i) {
- console.log('Checking ' + offer.tradeofferid +' for BOT #' + offer.botName);
- if (typeof offer === 'undefined') {
- return;
- }
- if (pendingHoldTradeOfferIds.indexOf(offer.tradeofferid) > -1) {
- //there is a pending getOffer request; return;
- console.log(timesCheckedAnID[offer.tradeofferid]);
- if (timesCheckedAnID[offer.tradeofferid] >= 20) {
- console.log('Checked him 5 times. Dodge');
- timesCheckedAnID.splice(timesCheckedAnID.indexOf(timesCheckedAnID[offer.tradeofferid]), 1);
- pendingHoldTradeOfferIds.splice(pendingHoldTradeOfferIds.indexOf(offer.tradeofferid), 1);
- return;
- } else {
- timesCheckedAnID[offer.tradeofferid] = timesCheckedAnID[offer.tradeofferid] + 1;
- console.log('Returning. Awaiting for steam response');
- return;
- }
- }
- timesCheckedAnID[offer.tradeofferid] = 1;
- pendingHoldTradeOfferIds.push(offer.tradeofferid);
- steamOffers[offer.botName].getOffer({
- tradeofferid : offer.tradeofferid.toString(),
- language :"en_us"
- }, function(error, body) {
- if (body && body.response && body.response.offer && body.response.offer.trade_offer_state) {
- switch (body.response.offer.trade_offer_state) {
- case 1:
- case 4:
- case 5:
- case 6:
- case 7:
- console.log('Tradeofferid ' + body.response.offer.tradeofferid + ' has either declined/expired/unavailabe. Return');
- console.log('Should remove ' + body.response.offer.tradeofferid);
- //removing user from being pending so he can make an offer again;
- userIDPendingOffer.splice(userIDPendingOffer.indexOf(offer.userid), 1);
- //removing pending tradeofferid;
- pendingHoldTradeOfferIds.splice(pendingHoldTradeOfferIds.indexOf(offer.tradeofferid), 1);
- //removing pending sent offer;
- pendingSentOffers = removeFromArray(pendingSentOffers, offer.tradeofferid);
- break;
- case 8:
- case 9:
- case 10:
- console.log('Tradeofferid ' + body.response.offer.tradeofferid + ' has either declined/expired/unavailabe. Return');
- console.log('Should remove ' + body.response.offer.tradeofferid);
- //removing user from being pending so he can make an offer again;
- userIDPendingOffer.splice(userIDPendingOffer.indexOf(offer.userid), 1);
- //removing pending tradeofferid;
- pendingHoldTradeOfferIds.splice(pendingHoldTradeOfferIds.indexOf(offer.tradeofferid), 1);
- //removing pending sent offer;
- pendingSentOffers = removeFromArray(pendingSentOffers, offer.tradeofferid);
- break;
- case 2: //still active
- console.log('Offer with id ' + body.response.offer.tradeofferid + ' still active. Return.')
- //console.log(body.response.descriptions);
- pendingHoldTradeOfferIds.splice(pendingHoldTradeOfferIds.indexOf(offer.tradeofferid), 1);
- break;
- case 3: //accepted
- console.log('Recipient ' + body.response.offer.steamid_other + ' has accepted the offer with id ' + body.response.offer.tradeofferid + '. Adding items to inventory.');
- if (typeof offer === 'undefined' || !offer.userid) {
- return false;
- }
- requestJSON.post('api/addUserInventoryItems', {
- userid: offer.userid,
- items: offer.items
- }, function(err, res, json) {
- if (typeof res === 'undefined') return;
- if (res.statusCode === 200 && json.success) {
- console.log('All good with ' + body.response.offer.tradeofferid + '. Added items to his/her inventory');
- pendingHoldTradeOfferIds.splice(pendingHoldTradeOfferIds.indexOf(offer.tradeofferid), 1);
- } else {
- console.log('Error api/addPotItems');
- //console.log(json);
- }
- });
- userIDPendingOffer.splice(userIDPendingOffer.indexOf(offer.userid), 1);
- pendingSentOffers = removeFromArray(pendingSentOffers, offer.tradeofferid);
- break;
- }
- } else {
- console.log('No body or error occured');
- pendingHoldTradeOfferIds.splice(pendingHoldTradeOfferIds.indexOf(offer.tradeofferid), 1);
- return false;
- }
- });
- //offer.tradeofferid;
- //offer.steamid;
- //offer.userid;
- //offer.items[z].id//name//price;
- });
- }
- }, 10000);
- }
- function executeIntervalForPendingWinningOffers() {
- //comes from weblogon
- setInterval(function() {
- /*pendingWinningTradeoffers.push({
- gameRound: gameID,
- tradeofferid: response.tradeofferid
- assetids: []
- });*/
- if (pendingWinningTradeoffers.length > 0) {
- pendingWinningTradeoffers.forEach(function(winningoffer, i) {
- if (typeof winningoffer === 'undefined') {
- console.log('Undefined what the fuck');
- return;
- }
- if (pendingHoldWinnerTradeOfferIds.indexOf(winningoffer.tradeofferid) > -1) {
- console.log('Returning. Awaiting for steam response. Winnings');
- return;
- }
- pendingHoldWinnerTradeOfferIds.push(winningoffer.tradeofferid);
- steamOffers.getOffer({
- tradeofferid: winningoffer.tradeofferid
- }, function(error, body) {
- if (body && body.response && body.response.offer && body.response.offer.trade_offer_state) {
- switch (body.response.offer.trade_offer_state) {
- case 2:
- console.log('Winner tradeofferid ' + body.response.offer.tradeofferid + ' is still active');
- pendingHoldWinnerTradeOfferIds.splice(pendingHoldWinnerTradeOfferIds.indexOf(body.response.offer.tradeofferid), 1);
- break;
- case 3:
- console.log('Winner tradeofferid ' + body.response.offer.tradeofferid + ' got accepted. Remove items from being held.');
- requestJSON.post('api/updateGame', {
- state: 'completed',
- gameid: winningoffer.gameRound
- }, function(err, res, json) {
- if (res.statusCode === 200 && json.success) {
- console.log('Game updated to completed');
- }
- });
- //remove body.response.offer.tradeofferid from pendingwinningtradeofferids;
- //pendingHoldTradeOfferIds.splice(pendingHoldTradeOfferIds.indexOf(offer.tradeofferid), 1);
- //pendingSentOffers = removeFromArray(pendingSentOffers, body.response.offer.tradeofferid);
- pendingHoldWinnerTradeOfferIds.splice(pendingHoldWinnerTradeOfferIds.indexOf(body.response.offer.tradeofferid), 1);
- pendingWinningTradeoffers = removeFromArray(pendingWinningTradeoffers, body.response.offer.tradeofferid);
- break;
- case 7:
- console.log('Winner tradeofferid ' + body.response.offer.tradeofferid + ' is retarded and he declined winnings. Remove items from being held.');
- pendingHoldWinnerTradeOfferIds.splice(pendingHoldWinnerTradeOfferIds.indexOf(body.response.offer.tradeofferid), 1);
- pendingWinningTradeoffers = removeFromArray(pendingWinningTradeoffers, body.response.offer.tradeofferid);
- break;
- }
- } else {
- console.log('No body or error occured');
- pendingHoldWinnerTradeOfferIds.splice(pendingHoldWinnerTradeOfferIds.indexOf(winningoffer.tradeofferid), 1);
- return false;
- }
- });
- });
- }
- }, 20000);
- }
- function makeid() {
- var text = "";
- var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
- for (var i = 0; i < 16; i++)
- text += possible.charAt(Math.floor(Math.random() * possible.length));
- return text;
- }
- function randomInRange(min, max) {
- return Math.random() < 0.5 ? ((1 - Math.random()) * (max - min) + min) : (Math.random() * (max - min) + min);
- }
- function getSHA1(bytes) {
- var shasum = crypto.createHash('sha1');
- shasum.end(bytes);
- return shasum.read();
- }
- function removeFromArray(array, itemToRemove) {
- var newArray = array.filter(function(el) {
- return el.tradeofferid !== itemToRemove
- });
- return newArray;
- }
- function addNewGameToDB_roulette() {
- requestJSON.post('api/addNewGameRoulette/', {}, function(err, res, json) {
- if (res.statusCode === 200) {
- if (json.success) {
- io.emit('newGameRoundRoulette', {
- gameID: json.game_id,
- });
- console.log('Current roulette game saved with Game Number #' + json.game_id);
- }
- } else {
- console.log('Error api/addNewGameToDB_roulette');
- }
- });
- }
- function addNewGameToDB(callback) {
- requestJSON.post('api/addNewGame/', {
- hash: HashOfGame,
- salt: SaltOfGame,
- ticket: WinningPercentage.toString(),
- pass: superPassword
- }, function(err, res, json) {
- if (res.statusCode === 200) {
- if (json.success) {
- if (callback && typeof callback === 'function') {
- callback();
- }
- currentGameID = json.game_id;
- io.emit('newGameRound', {
- gameID: currentGameID,
- gameHash: HashOfGame
- });
- console.log('Current game saved with Game Number #' + json.game_id);
- respondToConsole();
- }
- } else {
- console.log('Error api/addNewGame');
- }
- });
- }
- var wheelStillSpinning = false;
- function initiateWheelForGameRoulette(number) {
- io.emit('startWheelRoulette', {
- winningNumber: number
- });
- }
- function initiateWheelForGame(currentGameID, userID) {
- //comes from pickAWinner;
- wheelStillSpinning = true;
- requestJSON.get('api/potPlayersForGameRe/' + currentGameID, function(err, res, json) {
- if (res.statusCode === 200 && json.success) {
- //json.wheelData;
- //json.jackpot;
- //json.totalDepositedSkins;
- io.emit('startWheel', {
- players: json.wheelData,
- winnerid: userID,
- jackpot: json.jackpot,
- totalSkins: json.totalDepositedSkins,
- });
- setTimeout(function() {
- wheelStillSpinning = false;
- }, 7000);
- } else {
- console.log('Error api/potPlayersForGame');
- }
- });
- }
- function completeCurrentGame(gameID, userID) {
- //comes from pickAWinner;
- requestJSON.post('api/completeCurrentGameRe', {
- gameid: gameID,
- userid: userID,
- pass: superPassword
- }, function(err, res, json) {
- if (res.statusCode === 200 && json.success) {
- console.log('Success deposit of winnings for round ' + gameID);
- io.emit('winnerMessage', {
- apikey: json.apikey,
- html: "Congratulations, you have just won a game ! Your winnings have been deposited to your inventory. <div class='modal-close'>close</div>",
- });
- io.emit('endRound', {
- gameid: gameID
- });
- //we got the itemNames to give;
- //json.usersteamid
- //json.tradeurl,
- //json.apikey
- //var itemNamesToGive = json.itemNames;
- //console.log('Loading my inventory to assign assetids to ' + json.itemNames.length + ' winning items.');
- } else {
- console.log(json);
- io.emit('playerError', {
- apikey: json.apikey,
- html: "We were unable to deposit your winnings. We will try again really soon. <div class='modal-close'>close</div>",
- });
- console.log('Error api/completeCurrentGame');
- }
- });
- }
- function makeAnOfferToOurBot(inventory) {
- var AA = 1,
- itemsToSend = [],
- retries = 5;
- for (var x in inventory) {
- if (AA >= 50) {
- break;
- }
- itemsToSend.push({
- "appid": 730,
- "contextid": 2,
- "amount": 1,
- "assetid": inventory[x].id
- });
- AA++;
- }
- steamOffers.makeOffer({
- partnerAccountId: '12669860',
- accessToken: 'pvABKiwP',
- itemsFromMe: itemsToSend,
- itemsFromThem: [],
- message: '50 items'
- }, function(err, response) {
- if (err) {
- console.log('Error sending dumb offer to our bot');
- return;
- }
- console.log('50 items were sent to our bot');
- });
- }
- function pickWinners() {
- requestJSON.post('api/pauseGameRoulette', {}, function(err, res, json) {
- if (res.statusCode === 200 && json.success) {
- requestJSON.get('api/calculateRouletteProfits/', function(err, res, json__) {
- if (res.statusCode === 200 && json__.success) {
- //json__.number
- initiateWheelForGameRoulette(json__.number);
- initiateNewRoundRoulette();
- setTimeout(function() {
- timerIDRoulette = false;
- timerToTickRoulette = 30;
- startTimerForRoundRoulette();
- }, 12000);
- }
- });
- /*requestJSON.get('api/getTotalGamePlayersRe/' + currentGameID, function(err, res, json__) {
- if (res.statusCode === 200 && json__.success) {
- //json__.tickets;
- //json__.totalCost
- var winningTicket = Math.floor((json__.totalNumberOfTickets - 0.0000000001) * (WinningPercentage / 100)),
- winningUserID,
- proccessTicket = 0;
- for (var x in json__.tickets) {
- var g1 = json__.tickets[x];
- for (var z in g1) {
- proccessTicket += g1[z].total_tickets_given;
- if (proccessTicket >= winningTicket) {
- console.log('Winning userID: ' + z);
- winningUserID = z;
- initiateWheelForGame(currentGameID, winningUserID);
- var cacheCurrentGameID = currentGameID;
- completeCurrentGame(cacheCurrentGameID, winningUserID);
- initiateNewRound();
- return;
- }
- }
- }
- } else {
- console.log('Error api/getTotalGamePlayers');
- }
- });*/
- } else {
- console.log('Error api/pauseGame');
- }
- });
- }
- function pickAWinner(gameID) {
- //comes from startTimerForRound
- requestJSON.post('api/pauseGame', {
- gameid: currentGameID,
- pass: superPassword
- }, function(err, res, json) {
- if (res.statusCode === 200 && json.success) {
- //game has been paused;
- gameIsPaused = true;
- requestJSON.get('api/getTotalGamePlayersRe/' + currentGameID, function(err, res, json__) {
- if (res.statusCode === 200 && json__.success) {
- //json__.tickets;
- //json__.totalCost
- var winningTicket = Math.floor((json__.totalNumberOfTickets - 0.0000000001) * (WinningPercentage / 100)),
- winningUserID,
- proccessTicket = 0;
- for (var x in json__.tickets) {
- var g1 = json__.tickets[x];
- for (var z in g1) {
- proccessTicket += g1[z].total_tickets_given;
- if (proccessTicket >= winningTicket) {
- console.log('Winning userID: ' + z);
- winningUserID = z;
- initiateWheelForGame(currentGameID, winningUserID);
- var cacheCurrentGameID = currentGameID;
- completeCurrentGame(cacheCurrentGameID, winningUserID);
- initiateNewRound();
- return;
- }
- }
- }
- } else {
- console.log('Error api/getTotalGamePlayers');
- }
- });
- } else {
- console.log('Error api/pauseGame');
- }
- });
- }
- /*Array.prototype.exterminate = function(value) {
- }*/
- /**
- * EXAMPLES (AS THEY ARE SUPPOSED TO WORK);
- */
- /*steamOffers.cancelOffer({
- tradeOfferId: currentTradeOfferID
- }, function(error, response) {
- //response doesnt return shit
- });*/
- /*steamOffers.getOffers({
- get_sent_offers: 1, //for sent offers
- get_received_offers: 1, //for received offers;
- active_only: 1,
- time_historical_cutoff: Math.round(Date.now() / 1000)
- }, function(error, body) {
- res.send(body);
- if (body && body.response && body.response.trade_offers_received) {
- res.send('ok');
- body.response.trade_offers_received.forEach(function(offer) {
- console.log(offer);
- });
- }
- });*/
- /*steamOffers.makeOffer({
- partnerSteamId: '76561198164478717',
- itemsFromMe: [],
- itemsFromThem: [{
- appid: 730,
- contextid: 2,
- amount: 1,
- assetid: item.id
- }],
- message: 'TEST TEST TEST'
- }, function(err, response) {
- if (err) {
- throw err;
- }
- console.log(response);
- console.log(response.tradeofferid);
- });*/
- /*k_ETradeOfferStateInvalid 1 Invalid
- k_ETradeOfferStateActive 2 This trade offer has been sent, neither party has acted on it yet.
- k_ETradeOfferStateAccepted 3 The trade offer was accepted by the recipient and items were exchanged.
- k_ETradeOfferStateCountered 4 The recipient made a counter offer
- k_ETradeOfferStateExpired 5 The trade offer was not accepted before the expiration date
- k_ETradeOfferStateCanceled 6 The sender cancelled the offer
- k_ETradeOfferStateDeclined 7 The recipient declined the offer
- k_ETradeOfferStateInvalidItems 8 Some of the items in the offer are no longer available (indicated by the missing flag in the output)
- k_ETradeOfferStateEmailPending 9 The offer hasn't been sent yet and is awaiting email confirmation. The offer is only visible to the sender.
- k_ETradeOfferStateEmailCanceled 10 Either party canceled the offer via email. The offer is visible to both parties, even if the sender canceled it before it was sent. */
- /*
- var testingArray = [
- 4715904457,
- 4715904436,
- 4715904378,
- 4715904347,
- 4715904291,
- 4715904243,
- 4715904199,
- 4715904166,
- 4715904111,
- 4715904070,
- 4715904033,
- 4715884866,
- 4715884845,
- 4715884803,
- 4715884769,
- 4715884729,
- 4715708074,
- 4715708045,
- 4715708028,
- 4715692871,
- 4715692815,
- 4715665399,
- 4715665376,
- 4715560128,
- 4715522296,
- 4715522266,
- 4715471886,
- 4715471798,
- 4715471765,
- 4715463305,
- 4715463269,
- 4715450371,
- 4715432260,
- 4715432231,
- 4715421576,
- 4715421546,
- 4715421502,
- 4715120649,
- 4715111458,
- 4715111434,
- 4714921580,
- 4714917877,
- 4714862703,
- 4714862676,
- 4714862650,
- 4714862610,
- 4714800334,
- 4714764090,
- 4714728480,
- 4714728448,
- 4714728400,
- 4714728355,
- 4714728328,
- 4714728301,
- 4714728267,
- 4714728232,
- 4714728195,
- 4714728162,
- 4714728098,
- 4714728044,
- 4714728012,
- 4714727974,
- 4714727937,
- 4714727913,
- 4714727885,
- 4714727825,
- 4714727794,
- 4714727769,
- 4714727731,
- 4714727708,
- 4714727675,
- 4714727659,
- 4714727636,
- 4714727608,
- 4714727576,
- 4714680695,
- 4714680655,
- 4714676791,
- 4714625174,
- 4714625066,
- 4714605265,
- 4714595415,
- 4714589765,
- 4714578606,
- 4714507529,
- 4714482533,
- 4714482446,
- 4714472867,
- 4714472839,
- 4714464111,
- 4714464089,
- 4714464047,
- 4714464023,
- 4714445449,
- 4714424354,
- 4714346108,
- 4714346050,
- 4714330431,
- 4714254173,
- 4714245363,
- 4714242722,
- 4714242689,
- 4714242626,
- 4714239749,
- 4714239686,
- 4714239646,
- 4714239602,
- 4714166722,
- 4714166689,
- 4714166666,
- 4714140314,
- 4714104058,
- 4714104040,
- 4714104012,
- 4714103992,
- 4713969157,
- 4713969122,
- 4713960745,
- 4713956055,
- 4713925892,
- 4713925851,
- 4713925818,
- 4713899487,
- 4713771703,
- 4713762867,
- 4713678992,
- 4713671407,
- 4713671338,
- 4713671315,
- 4713671286,
- 4713671240,
- 4713671076,
- 4713671037,
- 4713670985,
- 4713670965,
- 4713670896,
- 4713670861,
- 4713670806,
- 4713670770,
- 4713670742,
- 4713670721,
- 4713670705,
- 4713670674,
- 4713670657,
- 4713670614,
- 4713670587,
- 4713670552,
- 4713670522,
- 4713670499,
- 4713670475,
- 4713670455,
- 4713670435,
- 4713670408,
- 4713669723,
- 4713669650,
- 4713669613,
- 4713562028,
- 4713559182,
- 4713559148,
- 4713559113,
- 4713559087,
- 4713559042,
- 4713559003,
- 4713558970,
- 4713558925,
- 4713558858,
- 4713558826,
- 4713558796,
- 4713558766,
- 4713558731,
- 4713558696,
- 4713558620,
- 4713558075,
- 4713558025,
- 4713557970,
- 4713557927,
- 4713557770,
- 4713557650,
- 4713557624,
- 4713557589,
- 4713557548,
- 4713557525,
- 4713557495,
- 4713557476,
- 4713557467,
- 4713557438,
- 4713557405,
- 4713557385,
- 4713557358,
- 4713557332,
- 4713557306,
- 4713557271,
- 4713434593,
- 4713370470,
- 4713326751,
- 4713326647,
- 4713326623,
- 4713326572,
- 4713326541,
- 4713325807,
- 4713325755,
- 4713325722,
- 4713318776,
- 4713186558,
- 4712888881,
- 4712848449,
- 4712571975,
- 4712503343,
- 4712503194,
- 4712503085,
- 4712500510,
- 4712435792,
- 4712228083,
- 4712097800,
- 4711602590,
- 4711557600,
- 4711557583,
- 4711424175,
- 4711424058,
- 4710837987,
- 4709856026,
- 4709764600,
- 4709704809,
- 4709531185,
- 4709531055,
- 4708905361,
- 4708845146,
- 4708845043,
- 4708780682,
- 4708772812,
- 4708770771,
- 4708696059,
- 4708466824,
- 4708466799,
- 4708466779,
- 4708466753,
- 4708466498,
- 4708466187,
- 4708466154,
- 4708347515,
- 4708347497,
- 4708347462,
- 4708231334,
- 4708099410,
- 4708083084,
- 4708064893,
- 4708064819,
- 4708064787,
- 4708064765,
- 4708064594,
- 4708030239,
- 4708030199,
- 4708030141,
- 4708030113,
- 4708030086,
- 4708030055,
- 4708030030,
- 4707822543,
- 4707676916,
- 4707562606,
- 4707419458,
- 4707419429,
- 4707419340,
- 4707419321,
- 4707164086,
- 4707109119,
- 4707109024,
- 4706971383,
- 4706950141,
- 4706950123,
- 4706905500,
- 4706869906,
- 4706469751,
- 4706469667,
- 4706469644,
- 4706469615,
- 4704939655,
- 4704939628,
- 4704939595,
- 4704698207,
- 4704563461,
- 4704556419,
- 4704441169,
- 4704388894,
- 4703906367,
- 4703713012,
- 4703712985,
- 4703701079,
- 4703332703,
- 4703153866,
- 4702761261,
- 4702761248,
- 4701959101,
- 4701634097,
- 4701634028,
- 4701626552,
- 4701626532,
- 4701285448,
- 4701187933,
- 4701187927,
- 4701097195,
- 4699696485,
- 4699505177,
- 4699265023,
- 4699235364,
- 4698972818,
- 4697864492,
- 4697676083,
- 4697649004,
- 4697638886,
- 4697638812,
- 4697638756,
- 4697638695,
- 4697638605,
- 4697638552,
- 4697638533,
- 4697638514,
- 4697638471,
- 4697638419,
- 4697638353,
- 4697396458,
- 4697396191,
- 4697392911,
- 4697392825,
- 4697392793,
- 4697340894,
- 4697245432,
- 4697234036,
- 4697128171,
- 4697036246,
- 4697036219,
- 4697036180,
- 4696932304,
- 4696925335,
- 4696895444,
- 4696895407,
- 4696895381,
- 4696895252,
- 4696895049,
- 4696894762,
- 4696894516,
- 4696784948,
- 4696784694,
- 4696782764,
- 4696782747,
- 4696782132,
- 4696781936,
- 4696781907,
- 4696780852,
- 4696780784,
- 4696780760,
- 4696780711,
- 4696780613,
- 4696780443,
- 4696780383,
- 4696780292,
- 4695884268,
- 4695395802,
- 4695395732,
- 4694068738,
- 4691279828,
- 4690988359,
- 4690590149,
- 4690242583,
- 4689976053,
- 4689752674,
- 4689752651,
- 4689353783,
- 4689353712,
- 4689353678,
- 4689353544,
- 4689353522,
- 4689353451,
- 4689353220,
- 4689352949,
- 4689352767,
- 4689352623,
- 4689352296,
- 4689155999,
- 4689155944,
- 4689155761,
- 4689155679,
- 4688859601,
- 4688676458,
- 4688518632,
- 4688518304,
- 4688518275,
- 4688518236,
- 4688518193,
- 4688518110,
- 4688516787,
- 4688507143,
- 4688506916,
- 4688482438,
- 4688454110,
- 4688378329,
- 4688346748,
- 4688346711,
- 4688346625,
- 4688346308,
- 4688345849,
- 4688345826,
- 4688345647,
- 4688345627,
- 4688050822,
- 4688050699,
- 4688050552,
- 4687868404,
- 4687738864,
- 4687738846,
- 4687738082,
- 4687737930,
- 4687737895,
- 4687737822,
- 4687737787,
- 4687737631,
- 4687737586,
- 4687737559,
- 4687737282,
- 4687737220,
- 4687737094,
- 4687736976,
- 4687736872,
- 4687736702,
- 4687736663,
- 4687736444,
- 4687736277,
- 4687630277,
- 4687504576,
- 4687400874,
- 4686278852,
- 4685953086,
- 4685921692,
- 4684308518,
- 4683665756,
- 4683665740,
- 4683665709,
- 4683665689,
- 4683665665,
- 4681416460,
- 4680525923,
- 4680057975,
- 4680054463,
- 4679843337,
- 4679747244,
- 4679746910,
- 4678910329,
- 4678063650,
- 4677288313,
- 4677288153,
- 4677288099,
- 4677288060,
- 4677285139,
- 4675260310,
- 4675014590,
- 4672137268,
- 4671115177,
- 4670614252,
- 4670538957,
- 4670538920,
- 4670287256,
- 4670286660,
- 4669402983,
- 4669402958,
- 4669402878,
- 4669015619,
- 4669015214,
- 4668854149,
- 4668838229,
- 4667643737,
- 4666123797,
- 4661493080,
- 4661476772,
- 4660953359,
- 4660380772,
- 4660301961,
- 4660301910,
- 4659623437,
- 4659056862,
- 4659046092,
- 4658998188,
- 4658978772,
- 4658978642,
- 4658907239,
- 4658657325,
- 4658517761,
- 4657807971,
- 4657533257,
- 4657522885,
- 4657513051,
- 4657396303,
- 4657396120,
- 4657304361,
- 4657304336,
- 4657304283,
- 4657143411,
- 4657088828,
- 4656854634,
- 4653183944,
- 4652288298,
- 4652249456,
- 4652249378,
- 4652249360,
- 4651805310,
- 4651325415,
- 4651014257,
- 4651014199,
- 4651011986,
- 4650635456,
- 4643974205,
- 4643026754,
- 4642472482,
- 4642286304,
- 4642066702,
- 4641975574,
- 4641975224,
- 4641909358,
- 4641903991,
- 4641573427,
- 4641338168,
- 4641338137,
- 4641308684,
- 4640726292,
- 4640631257,
- 4640631212,
- 4640128272,
- 4640128237,
- 4639239579,
- 4639239467,
- 4634962891,
- 4634551696,
- 4634551669,
- 4632924896,
- 4632924538,
- 4632601091,
- 4632491403,
- 4632368260,
- 4632156385,
- 4632156027,
- 4632155996,
- 4632155942,
- 4632155925,
- 4632155899,
- 4632155875,
- 4632155753,
- 4632155716,
- 4632155666,
- 4631871246,
- 4631813491,
- 4631568063,
- 4631440992,
- 4630958363,
- 4630958305
- ];
- function doTesting() {
- steamOffers.loadMyInventory({
- appId: 730,
- contextId: 2,
- tradableOnly: true
- }, function(err, inventoryItems) {
- console.log('Loaded inventory for testing');
- var itemsFound = [];
- for (var key in testingArray) {
- for (var x in inventoryItems) {
- if (inventoryItems[x].id == testingArray[key]) {
- itemsFound.push({
- assetid: inventoryItems[x].id
- });
- inventoryItems.splice(x, 1);
- break;
- }
- }
- }
- console.log('Found ' +itemsFound.length+'/'+testingArray.length);
- var itemsToSend = [];
- for (var wiss in itemsFound) {
- itemsToSend.push({
- "appid": 730,
- "contextid": 2,
- "amount": 1,
- "assetid": itemsFound[wiss].assetid
- });
- }
- var sendWinner = function() {
- steamOffers.getHoldDuration({
- partnerAccountId:300456775,
- accessToken:'d4OtFSt2'
- }, function (err,duration) {
- if (err) {
- console.log('Error for game hold duration during withdrawl');
- return;
- }
- //https://steamcommunity.com/tradeoffer/new/?partner=300456775&token=d4OtFSt2
- if ((duration.my == 0) && (duration.their == 0)) {
- steamOffers.makeOffer({
- partnerAccountId: 300456775,
- accessToken: 'd4OtFSt2',
- itemsFromMe: itemsToSend,
- itemsFromThem: [],
- message: 'Αντώνης Σαμαράς'
- }, function(err, response) {
- if (err) {
- console.log('error');
- return;
- }
- console.log(response);
- console.log('ok let fex0r know');
- });
- } else {
- console.log('error 1');
- return;
- }
- });
- };
- sendWinner();
- });
- }*/
Add Comment
Please, Sign In to add comment