Guest User

Untitled

a guest
Mar 1st, 2016
434
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 62.80 KB | None | 0 0
  1. var currentWorkingSite = 'http://www.skinbattles.net/',
  2. //var currentWorkingSite = 'http://localhost/skinbattles/',
  3. superPassword = 'gWEh7aFR';
  4. /*
  5.  
  6. DONT FORGET TO REMOVE HANDCODED STEAM IDS;
  7.  
  8. */
  9.  
  10.  
  11. /**
  12. * first class variables
  13. */
  14.  
  15. var config = require('./config.js'),
  16. fs = require('fs'),
  17. crypto = require('crypto');
  18.  
  19. /**
  20. * configure express
  21. */
  22. var expressApp = require('express')();
  23.  
  24. /**
  25. * configure http server
  26. */
  27. var http = require('http').Server(expressApp);
  28. http.listen(8080);
  29. /**
  30. * configure request-json
  31. */
  32. var reqJSON = require('request-json'),
  33. requestJSON = reqJSON.createClient(currentWorkingSite);
  34. /**
  35. * configure socket.io
  36. */
  37. var io = require('socket.io')(http);
  38. /**
  39. * configure steam npm package
  40. * configure steam-trade-offers package;
  41. *
  42. * libraries
  43. *
  44. */
  45. var SteamUser = require('steam-user');
  46. var SteamTotp = require('steam-totp');
  47. var SteamMobileAuth = require('steamcommunity-mobile-confirmations');
  48. var SteamTradeOffers = require('steam-tradeoffers');
  49. var getSteamApiKey = require('steam-web-api-key');
  50.  
  51. /**
  52. * constructors
  53. */
  54. //console.log(config.botAccounts);
  55.  
  56. var steamOffers = [],
  57. client = [],
  58. mobileConfirmations = [];
  59.  
  60. var totalBotsFound = Object.keys(config.botAccounts).length;
  61.  
  62. var botsInQueue = [];
  63.  
  64. console.log('Found '+totalBotsFound+' bot(s). Trying to connect them');
  65.  
  66. for (var key in config.botAccounts) {
  67. var progName = config.botAccounts[key].name;
  68. botsInQueue.push(progName);
  69. }
  70.  
  71. var checkForBots = function(key) {
  72. connectBotWithKey(key);
  73. }
  74.  
  75. var connectBotWithKey = function(key) {
  76.  
  77. var progName = config.botAccounts[key].name;
  78.  
  79. steamOffers[progName] = new SteamTradeOffers();
  80. client[progName] = new SteamUser();
  81.  
  82. client[progName].setSentry(getSHA1(fs.readFileSync(__dirname + '/' + config.botAccounts[key].ssfn)));
  83.  
  84. config.botAccounts[key].logOnOptions.twoFactorCode = SteamTotp.generateAuthCode(config.botAccounts[key].shared_secret);
  85.  
  86. client[progName].logOn(config.botAccounts[key].logOnOptions);
  87.  
  88. client[progName].on('loggedOn', function(details) {
  89. console.log('Steam client for ' + progName + ' ('+config.botAccounts[key].logOnOptions['accountName']+') connected');
  90. client[progName].setPersona(SteamUser.Steam.EPersonaState.Online);
  91. });
  92.  
  93. client[progName].on('error', function() {
  94. client[progName].logOn(config.botAccounts[key].logOnOptions);
  95. });
  96.  
  97. client[progName].on('webSession', function (sessionID, cookies) {
  98.  
  99. console.log('Web session set for ' + progName);
  100.  
  101. getSteamApiKey({
  102. sessionID: sessionID,
  103. webCookie: cookies
  104. }, function(err, apiKey) {
  105.  
  106. steamOffers[progName].setup({
  107. sessionID: sessionID,
  108. webCookie: cookies,
  109. APIKey: apiKey
  110. });
  111.  
  112. console.log('Steam webLogon is fine for ' + progName);
  113.  
  114. });
  115.  
  116. //we only set executeInterval once;
  117. if (key === 0) {
  118. console.log(progName + ' has been detected as primary bot. Initializing trade-offers request every X seconds');
  119. var intervalForOffers = executeIntervalForOffers();
  120. }
  121.  
  122. mobileConfirmations[progName] = new SteamMobileAuth({
  123. steamid: config.botAccounts[key].steamid,
  124. identity_secret: config.botAccounts[key].identity_secret,
  125. device_id: "android:" + Date.now(),
  126. webCookie: cookies
  127. });
  128.  
  129. botsInQueue.splice(0,1);
  130. if (botsInQueue.length > 0) {
  131. checkForBots(key+1);
  132. }
  133.  
  134. });
  135. }
  136.  
  137. checkForBots(0);
  138.  
  139. /**
  140. * Checking in 10 sec interval if new trade confirmation have to be accepted.
  141. */
  142. setInterval(function () {
  143. if (Object.keys(mobileConfirmations).length) {
  144.  
  145. //for (var key in mobileConfirmations) {
  146. mobileConfirmations['FirstBot'].FetchConfirmations(function (err, confirmations) {
  147. if (err) {
  148. return;
  149. }
  150. if (confirmations.length > 0) {
  151.  
  152. if (!confirmations.length){
  153. return;
  154. }
  155.  
  156. console.log('Received ' + confirmations.length + ' outstanding confirmations for FirstBot');
  157.  
  158. mobileConfirmations['FirstBot'].AcceptConfirmation(confirmations[0], function (err, result ){
  159. if (err) {
  160. console.log(err);
  161. return;
  162. }
  163. console.log('Accepted confirmation result for FirstBot: '+result);
  164. });
  165.  
  166. };
  167. });
  168.  
  169. mobileConfirmations['SecondBot'].FetchConfirmations(function (err, confirmations) {
  170. if (err) {
  171. return;
  172. }
  173. if (confirmations.length > 0) {
  174.  
  175. if (!confirmations.length){
  176. return;
  177. }
  178.  
  179. console.log('Received ' + confirmations.length + ' outstanding confirmations for SecondBot');
  180.  
  181. mobileConfirmations['SecondBot'].AcceptConfirmation(confirmations[0], function (err, result ){
  182. if (err) {
  183. console.log(err);
  184. return;
  185. }
  186. console.log('Accepted confirmation result for SecondBot : '+result);
  187. });
  188.  
  189. };
  190. });
  191.  
  192. mobileConfirmations['ThirdBot'].FetchConfirmations(function (err, confirmations) {
  193. if (err) {
  194. return;
  195. }
  196. if (confirmations.length > 0) {
  197.  
  198. if (!confirmations.length){
  199. return;
  200. }
  201.  
  202. console.log('Received ' + confirmations.length + ' outstanding confirmations for ThirdBot');
  203.  
  204. mobileConfirmations['ThirdBot'].AcceptConfirmation(confirmations[0], function (err, result ){
  205. if (err) {
  206. console.log(err);
  207. return;
  208. }
  209. console.log('Accepted confirmation result for ThirdBot : '+result);
  210. });
  211.  
  212. };
  213. });
  214.  
  215. }
  216.  
  217. }, 10000);
  218.  
  219.  
  220. /**
  221. * new round initialization;
  222. */
  223.  
  224. //check if there is a new round already active;
  225. requestJSON.get('api/activeRoundGoingOn', function(err, res, json) {
  226. if (res.statusCode === 200) {
  227. if (json.success === true) {
  228. WinningPercentage = json.game.ticket;
  229. HashOfGame = json.game.game_hash;
  230. SaltOfGame = json.game.game_salt;
  231. currentGameID = json.game.id;
  232. console.log('Found new active round with id #' + json.game.id + '. Setting it up');
  233. //emit new round;
  234. io.emit('newGameRound', {
  235. gameID: currentGameID,
  236. gameHash: HashOfGame
  237. });
  238. respondToConsole();
  239. } else {
  240. initiateNewRound();
  241. }
  242. }
  243. });
  244. requestJSON.get('api/activeRoundGoingOnRoulette', function(err, res, json) {
  245.  
  246. if (typeof res === 'undefined') return;
  247.  
  248. if (res.statusCode === 200) {
  249. if (json.success === true) {
  250. console.log('Found new active round with id #' + json.game.id + '. Setting it up');
  251. //emit new round;
  252. io.emit('newGameRoundRoulette', {
  253. gameID: json.game.id
  254. });
  255. startTimerForRoundRoulette();
  256. } else {
  257. initiateNewRoundRoulette();
  258. }
  259. }
  260. });
  261. var timerIDRoulette,
  262. timerToTickRoulette = 30;//seconds
  263.  
  264. function startTimerForRoundRoulette() {
  265. if (!timerIDRoulette) {
  266. timerIDRoulette = setInterval(function() {
  267. timerToTickRoulette--;
  268.  
  269. io.emit('timerTickRoulette', {
  270. timer: timerToTickRoulette
  271. });
  272.  
  273. if (timerToTickRoulette <= 0) {
  274. console.log('Time is over roulette');
  275. pickWinners();
  276. clearInterval(timerIDRoulette);
  277. timerIDRoulette = false;
  278. }
  279. }, 1000);
  280. }
  281. }
  282. function startTimerForRound() {
  283. //comes from request json activeRoundGoingOn;
  284. //not only;
  285. if (!timerID) {
  286. timerToTick = config.gameDuration;
  287. timerID = setInterval(function() {
  288. timerToTick--;
  289.  
  290. var minute = Math.floor(timerToTick / 60),
  291. second = timerToTick % 60;
  292.  
  293. second = second.toString();
  294. second = second.substr(0, 2);
  295. io.emit('timerTick', {
  296. timerToTick: minute + ":" + second
  297. });
  298.  
  299. if (timerToTick <= 0) {
  300. console.log('Time is over');
  301. pickAWinner(currentGameID);
  302. clearInterval(timerID);
  303. timerID = false;
  304. }
  305. }, 1000);
  306. } else {
  307. console.log('timerID is defined already');
  308. }
  309. }
  310. var SaltOfGame = null,
  311. WinningPercentage = null,
  312. HashOfGame = null,
  313. currentGameID = null,
  314. currentTotalPotItems = 0,
  315. pendingWinningTradeoffers = [],
  316. timerID = null;
  317.  
  318. function respondToConsole() {
  319. console.log('Current Game Salt: ' + SaltOfGame);
  320. console.log('Next Winner percentage is: ' + WinningPercentage + '%');
  321. console.log('Current Game Hash is: ' + HashOfGame);
  322. }
  323. function initiateNewRoundRoulette() {
  324. //add new game to sql;
  325. addNewGameToDB_roulette();
  326. }
  327. function initiateNewRound() {
  328. if (gameIsPaused) {
  329. gameIsPaused = false;
  330. }
  331. WinningPercentage = randomInRange(0, 100);
  332. SaltOfGame = makeid();
  333. HashOfGame = crypto.createHash('md5').update(SaltOfGame + ':' + WinningPercentage).digest('hex');
  334. currentGameID = null;
  335. //add new game to sql;
  336. addNewGameToDB();
  337. }
  338.  
  339. var peers = [],
  340. pendingSentOffers = [],
  341. timerInterval = null,
  342. gameIsPaused = false,
  343. timerToTick = 0,
  344. pendingUserToGetOffered = [],
  345. chatMessages = [],
  346. pendingChatMessageForUserApiKey = [],
  347. userIDPendingOffer = [];
  348.  
  349. io.on('connection', function(socket) {
  350. //push client
  351. peers.push(socket);
  352. //emit peers
  353. socket.emit('peers', {
  354. totalPeers: peers.length
  355. });
  356.  
  357. requestJSON.get('api/getChatMessages', function(err, res, json) {
  358. if (typeof res === 'undefined') return;
  359.  
  360. if (res.statusCode === 200 && json.success) {
  361. io.emit('sendChatData', json.html);
  362. }
  363. });
  364.  
  365. //initial request
  366. socket.on('ez', function() {
  367. requestJSON.post('api/getRoundPotRe', {
  368. gameid: (currentGameID ? currentGameID : 0)
  369. }, function(err, res, json) {
  370.  
  371. if (typeof res === 'undefined') return;
  372.  
  373. if (res.statusCode === 200 && json.success) {
  374. if (typeof io.sockets.connected === 'undefined' || typeof socket.id === 'undefined' || typeof io.sockets.connected[socket.id] === 'undefined') {
  375. return;
  376. }
  377. io.sockets.connected[socket.id].emit('roundPot', {
  378. potplayers: json.html,
  379. potitems: json.potitems,
  380. timerisactive: (!timerID ? false : true)
  381. });
  382. }
  383. });
  384. requestJSON.post('api/getRoundPotRoulette', {}, function(err, res, json) {
  385. if (res.statusCode === 200 && json.success) {
  386. if (typeof io.sockets.connected === 'undefined' || typeof socket.id === 'undefined' || typeof io.sockets.connected[socket.id] === 'undefined') {
  387. return;
  388. }
  389. io.sockets.connected[socket.id].emit('roundPotRoulette', {
  390. potplayers: json.html,
  391. potitems: json.potitems
  392. });
  393. }
  394. });
  395. });
  396.  
  397. //on disconnect
  398. socket.on('disconnect', function(socket) {
  399. //delete from peers list
  400. peers.splice(peers.indexOf(socket), 1);
  401. //update count
  402. io.emit('peers', {
  403. totalPeers: peers.length
  404. });
  405. });
  406.  
  407. //requestWithdraw
  408. socket.on('requestWithdraw', function(data) {
  409. requestJSON.get('api/userExists/' + data.apikey, function(err, res, user) {
  410. if (typeof res === 'undefined') return;
  411.  
  412. if (res.statusCode === 200 && user.success) {
  413. requestJSON.post('api/checkWithdrawItems', {
  414. items: data.items,
  415. userid: user.userid
  416. }, function(err, res, json) {
  417. //json.success
  418. //json.reason (success == false);
  419. //json.items.id/json.items.name (success == true);
  420. //json.tradeurl
  421. if (typeof res === 'undefined') return;
  422.  
  423. if (res.statusCode === 200 && json.success) {
  424.  
  425. console.log('Items of a withdrawal request were all found in our database. We proceed with a steam trade offer.');
  426. //iterate through all bots
  427. //cache all bots;
  428. //get first bot account;
  429. var botsToQueue = [];
  430.  
  431. for (var key in config.botAccounts) {
  432. var progName = config.botAccounts[key].name;
  433. botsToQueue.push(progName);
  434. }
  435.  
  436.  
  437. //cache withdrawal items;
  438. var withdrawalItems = json.items,
  439. theoryCache = json.items.length;
  440.  
  441. var withdrawFromBot = function(botKEY) {
  442.  
  443. var currentAccountBotName = config.botAccounts[botKEY].name;
  444.  
  445. botsToQueue.splice(0,1);
  446.  
  447. steamOffers[currentAccountBotName].loadMyInventory({
  448. appId: 730,
  449. contextId: 2,
  450. tradableOnly: true
  451. }, function(err, inventoryItems) {
  452.  
  453. //if err reversewithdrawitems;
  454. if (err) {
  455. requestJSON.post('api/reverseStatusWithdrawItems', {
  456. items: data.items,
  457. userid: user.userid
  458. }, function(err, res, json) {
  459. if (typeof res === 'undefined') return;
  460.  
  461. if (res.statusCode === 200 && json.success) {
  462. console.log('Withdrawal items were successfully set to pending status after failing to send them');
  463. } else {
  464. console.log('WEIRD ERROR CALL DAKIS');
  465. }
  466. });
  467. console.log('Couldnt load my inventory');
  468. return;
  469. }
  470.  
  471. console.log('Loaded inventory upon withdrawal request of ' + user.userid);
  472.  
  473. var itemsFound = [];
  474.  
  475. for (var key in withdrawalItems) {
  476. //json.items[]id/json.items[]name
  477. for (var x in inventoryItems) {
  478. if (inventoryItems[x].market_hash_name === withdrawalItems[key].name) {
  479.  
  480. itemsFound.push({
  481. name: inventoryItems[x].market_hash_name,
  482. assetid: inventoryItems[x].id
  483. });
  484.  
  485. inventoryItems.splice(x, 1);
  486. break;
  487. }
  488. }
  489.  
  490. }
  491.  
  492. for (var o in itemsFound) {
  493. for (var z in withdrawalItems) {
  494. if (itemsFound[o].name === withdrawalItems[z].name) {
  495. withdrawalItems.splice(z, 1);
  496. break;
  497. }
  498. }
  499. }
  500. //if (itemsFound.length === json.items.length) {
  501. //console.log('Found all items. Proceeding to give items to winner with userID: ' + user.userid);
  502. //} else {
  503. console.log('Found '+itemsFound.length+' on BOT #'+currentAccountBotName +'. Items left to send:' + withdrawalItems.length);
  504. //}
  505.  
  506.  
  507. var itemsToSend = [],
  508. retriesToSendWinnerItems = 5;
  509.  
  510. for (var wiss in itemsFound) {
  511. itemsToSend.push({
  512. "appid": 730,
  513. "contextid": 2,
  514. "amount": 1,
  515. "assetid": itemsFound[wiss].assetid
  516. });
  517. }
  518.  
  519. var sendWinner = function() {
  520. retriesToSendWinnerItems--;
  521. var token = null,
  522. accountid = null;
  523.  
  524. if (!json.tradeurl) {
  525. io.emit('playerError', {
  526. apikey: data.apikey,
  527. html: "Something weird came up while sending your items. Please try again. <div class='modal-close'>close</div>"
  528. });
  529. console.log('Couldnt find tradeurl wtf');
  530. return;
  531. }
  532.  
  533. token = json.tradeurl;
  534. token = token.substr(token.indexOf('&token') + 7);
  535. accountid = json.tradeurl;
  536. accountid = accountid.substr(accountid.indexOf('?partner') + 9);
  537. accountid = accountid.substring(0, accountid.indexOf('&'));
  538.  
  539. steamOffers[currentAccountBotName].getHoldDuration({
  540. partnerAccountId:accountid,
  541. accessToken:token
  542. }, function (err,duration) {
  543.  
  544. if (err) {
  545. console.log('Error for game hold duration during withdrawl');
  546. requestJSON.post('api/reverseStatusWithdrawItems', {
  547. items: data.items,
  548. userid: user.userid
  549. }, function(err, res, json) {
  550. if (typeof res === 'undefined') return;
  551.  
  552. if (res.statusCode === 200 && json.success) {
  553. console.log('Withdrawal items were successfully set to pending status after failing to send them');
  554. } else {
  555. console.log('WEIRD ERROR CALL DAKIS');
  556. }
  557. });
  558. socket.emit('playerError', {
  559. apikey: data.apikey,
  560. 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>"
  561. });
  562. return;
  563. }
  564.  
  565. if ((duration.my == 0) && (duration.their == 0)) {
  566.  
  567. steamOffers[currentAccountBotName].makeOffer({
  568. partnerAccountId: accountid,
  569. accessToken: token,
  570. itemsFromMe: itemsToSend,
  571. itemsFromThem: [],
  572. message: 'Withdrawal items upon request. Thanks for playing.'
  573. }, function(err, response) {
  574. if (err) {
  575. console.log('Error sending withdrawal request to userID ' + user.userid);
  576. if (retriesToSendWinnerItems >= 0) {
  577. console.log('Retry sending offer: ' + retriesToSendWinnerItems);
  578. setTimeout(function() {
  579. sendWinner();
  580. }, 2000);
  581. } else {
  582. requestJSON.post('api/reverseStatusWithdrawItems', {
  583. items: data.items,
  584. userid: user.userid
  585. }, function(err, res, json) {
  586. if (typeof res === 'undefined') return;
  587.  
  588. if (res.statusCode === 200 && json.success) {
  589. console.log('Withdrawal items were successfully set to pending status after failing to send them');
  590. } else {
  591. console.log('WEIRD ERROR CALL DAKIS');
  592. }
  593. });
  594. io.emit('playerError', {
  595. apikey: data.apikey,
  596. html: "We tried 5 times to send you your withdraws. Our bot will retry shortly. <div class='modal-close'>close</div>"
  597. });
  598. }
  599. return;
  600. }
  601. console.log('Withdrawal was successful for user ' + user.userid);
  602.  
  603. if (withdrawalItems.length > 0 && botsToQueue.length > 0) {
  604. console.log('I still have items to send. Ill proceed with another bot inventory');
  605. withdrawFromBot(botKEY+1);
  606. } else {
  607. //no need for update now;
  608. io.emit('winnerMessage', {
  609. apikey: data.apikey,
  610. 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>",
  611. });
  612. }
  613.  
  614. });
  615.  
  616. } else {
  617. requestJSON.post('api/reverseStatusWithdrawItems', {
  618. items: data.items,
  619. userid: user.userid
  620. }, function(err, res, json) {
  621. if (typeof res === 'undefined') return;
  622.  
  623. if (res.statusCode === 200 && json.success) {
  624. console.log('Withdrawal items were successfully set to pending status after failing to send them');
  625. } else {
  626. console.log('WEIRD ERROR CALL DAKIS');
  627. }
  628. });
  629. socket.emit('playerError', {
  630. apikey: data.apikey,
  631. 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>"
  632. });
  633. return;
  634. }
  635. });
  636. };
  637. if (itemsFound.length === 0 && (withdrawalItems.length > 0 && botsToQueue.length > 0)) {
  638. console.log('Current bot has no items to withdraw but still got items to send. Proceeding with another bot.');
  639. withdrawFromBot(botKEY+1);
  640. } else if (itemsFound.length === 0) {
  641. console.log('Didnt found all items. Send everything i found.');
  642. return;
  643. } else {
  644. sendWinner();
  645. }
  646. });
  647.  
  648. }
  649.  
  650. withdrawFromBot(0);
  651.  
  652. } else {
  653.  
  654. requestJSON.post('api/reverseStatusWithdrawItems', {
  655. items: data.items,
  656. userid: user.userid
  657. }, function(err, res, json) {
  658. if (typeof res === 'undefined') return;
  659.  
  660. if (res.statusCode === 200 && json.success) {
  661. console.log('Withdrawal items were successfully set to pending status after failing to send them');
  662. } else {
  663. console.log('WEIRD ERROR CALL DAKIS');
  664. }
  665. });
  666.  
  667. socket.emit('playerError', {
  668. apikey: data.apikey,
  669. html: (json.reason ? json.reason : "Something went terribly wrong. Please try again") + "<div class='modal-close'>close</div>"
  670. });
  671. return;
  672. }
  673. });
  674. }
  675. });
  676. });
  677.  
  678. //requestDeposit;
  679. socket.on('requestDeposit', function(data) {
  680. requestJSON.get('api/userExists/' + data.apikey, function(err, res, user) {
  681.  
  682. if (typeof res === 'undefined') return;
  683.  
  684. if (res.statusCode === 200 && user.success) {
  685. if (data.action == 'roulette') {
  686.  
  687. requestJSON.post('api/validateItemsRoulette', {
  688. items: data.items,
  689. userid: user.userid,
  690. type: data.type
  691. }, function(err, res, json) {
  692. if (res.statusCode === 200 && json.success) {
  693.  
  694. if (json.error) {
  695. socket.emit('playerError', {
  696. apikey: data.apikey,
  697. html: "Oops! "+json.message+". Please try again. <div class='modal-close'>close</div>"
  698. });
  699. return;
  700. }
  701.  
  702. io.emit('enterPot', {
  703. apikey: data.apikey,
  704. html: "You successfully have entered current Game Roulette Round. <div class='modal-close'>close</div>"
  705. });
  706.  
  707. requestJSON.post('api/getRoundPotRoulette', {
  708. gameid: currentGameID
  709. }, function(err, res, json) {
  710. if (res.statusCode === 200 && json.success) {
  711. io.emit('roundPotRoulette', {
  712. potplayers: json.html,
  713. potitems: json.potitems
  714. });
  715. }
  716. });
  717.  
  718. } else {
  719. console.log(json);
  720. socket.emit('playerError', {
  721. apikey: data.apikey,
  722. html: "Oops! Something went wrong while we were trying to deposit your items. Please try again. <div class='modal-close'>close</div>"
  723. });
  724. return;
  725. }
  726. });
  727.  
  728. } else {
  729. requestJSON.post('api/validateItems', {
  730. items: data.items,
  731. userid: user.userid,
  732. gameid: currentGameID
  733. }, function(err, res, json) {
  734. if (typeof res === 'undefined') return;
  735.  
  736. if (res.statusCode === 200 && json.success) {
  737.  
  738. if (json.error) {
  739. socket.emit('playerError', {
  740. apikey: data.apikey,
  741. 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>"
  742. });
  743. return;
  744. }
  745.  
  746. io.emit('enterPot', {
  747. gameid: currentGameID,
  748. apikey: data.apikey,
  749. html: "You entered Game Round # " + currentGameID + ". You can view more stats on the Current Pot Players sidebar. <div class='modal-close'>close</div>"
  750. });
  751.  
  752. requestJSON.post('api/getRoundPotRe', {
  753. gameid: currentGameID
  754. }, function(err, res, json) {
  755. if (res.statusCode === 200 && json.success) {
  756. io.emit('roundPot', {
  757. potplayers: json.html,
  758. potitems: json.potitems,
  759. timerisactive: (!timerID ? false : true)
  760. });
  761. currentTotalPotItems = json.totalPotItems;
  762. if (currentTotalPotItems >= config.itemsToStart) {
  763. if (wheelStillSpinning) {
  764. setTimeout(function() {
  765. startTimerForRound();
  766. }, 10000);
  767. } else {
  768. startTimerForRound();
  769. }
  770. }
  771. }
  772. });
  773.  
  774. } else {
  775. socket.emit('playerError', {
  776. apikey: data.apikey,
  777. html: "Oops! Something went wrong while we were trying to deposit your items. Please try again. <div class='modal-close'>close</div>"
  778. });
  779. return;
  780. }
  781. });
  782. }
  783.  
  784. }
  785.  
  786. });
  787. });
  788.  
  789. //requestOffer
  790. socket.on('requestOffer', function(data) {
  791. //rewrote;
  792. requestJSON.get('api/userExists/' + data.apikey, function(err, res, user) {
  793. //**user.userid
  794. //**user.tradeurl
  795. //**user.steamid
  796. //**user.avatar
  797. if (typeof res === 'undefined') return;
  798.  
  799. if (res.statusCode === 200 && user.success) {
  800.  
  801. if (userIDPendingOffer.indexOf(user.userid) > -1) {
  802. console.log('Cant offer him. Still awaiting for another offer to be accepted/declined of user: ' + user.userid);
  803. socket.emit('playerError', {
  804. apikey: data.apikey,
  805. 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>"
  806. });
  807. return;
  808. }
  809.  
  810. if (pendingUserToGetOffered.indexOf(user.userid) > -1) {
  811. //there is a pending getOffer request; return;
  812. console.log('Cant offer him. Still awaiting for steam to respond for another trade offer of ' + user.userid);
  813. socket.emit('playerError', {
  814. apikey: data.apikey,
  815. html: "There is already a pending offer for you and we're afraid that steam is delayed :( <div class='modal-close'>close</div>"
  816. });
  817. return;
  818. }
  819.  
  820. pendingUserToGetOffered.push(user.userid);
  821. userIDPendingOffer.push(user.userid);
  822.  
  823.  
  824. var token = user.tradeurl;
  825. token = token.substr(token.indexOf('&token') + 7);
  826.  
  827. var accountid = user.tradeurl;
  828. accountid = accountid.substr(accountid.indexOf('?partner') + 9);
  829. accountid = accountid.substring(0, accountid.indexOf('&'));
  830.  
  831. //iterate through all bots
  832. //cache all bots;
  833. //get first bot account;
  834. var botsToQueue = [];
  835.  
  836. for (var key in config.botAccounts) {
  837. var progName = config.botAccounts[key].name;
  838. botsToQueue.push(progName);
  839. }
  840.  
  841. var makeOfferFromBot = function(key) {
  842.  
  843. var currentAccountBotName = config.botAccounts[key].name;
  844.  
  845. botsToQueue.splice(0,1);
  846.  
  847. steamOffers[currentAccountBotName].loadMyInventory({
  848. appId: 730,
  849. contextId: 2,
  850. tradableOnly: true
  851. }, function(err, inventoryItems) {
  852.  
  853. if (typeof data.items === 'undefined' || typeof inventoryItems === 'undefined') {
  854. console.log('FUCK STEAM YO');
  855. socket.emit('playerError', {
  856. apikey: data.apikey,
  857. html: "Couldn't reach steam. Please try again. <div class='modal-close'>close</div>"
  858. });
  859. pendingUserToGetOffered.splice(pendingUserToGetOffered.indexOf(user.userid), 1);
  860. userIDPendingOffer.splice(userIDPendingOffer.indexOf(user.userid), 1);
  861. return;
  862. }
  863.  
  864. if ((data.items.length + inventoryItems.length) >= 999) {
  865. console.log('Bot #'+currentAccountBotName + ' is full. Proceeding with another bot to make an offer');
  866. if (botsToQueue.length > 0) {
  867. makeOfferFromBot(key+1);
  868. }
  869. return;
  870. }
  871.  
  872. //we got our bot that can accept that offer;
  873. steamOffers[currentAccountBotName].getHoldDuration({
  874. partnerAccountId: accountid,
  875. accessToken: token
  876. }, function (err1, duration) {
  877. if (!err1) {
  878.  
  879. if ((duration.my == 0) && (duration.their == 0)) {
  880.  
  881. var partnerInventoryRetry = 5;
  882.  
  883. var loadPartnerInventory = function() {
  884.  
  885. partnerInventoryRetry--;
  886.  
  887. steamOffers[currentAccountBotName].loadPartnerInventory({
  888. appId: 730,
  889. contextId: 2,
  890. partnerAccountId: accountid
  891. }, function(err, items) {
  892.  
  893. if (err) {
  894. console.log('Error loadPartnerInventory ' + err);
  895. if (partnerInventoryRetry >= 0) {
  896.  
  897. console.log('Retry loadPartnerInventory step: ' + partnerInventoryRetry);
  898. setTimeout(function() {
  899. loadPartnerInventory();
  900. }, 2000);
  901.  
  902. } else {
  903. userIDPendingOffer.splice(userIDPendingOffer.indexOf(user.userid), 1);
  904. }
  905. } else {
  906.  
  907. var lengthToCheck = data.items.length,
  908. itemsExist = 0,
  909. itemsInfo = [];
  910.  
  911. for (var i = 0; i < items.length; i++) {
  912. for (var z in data.items) {
  913. if (items[i].id === data.items[z] && items[i].tradable) {
  914. itemsInfo.push({
  915. name: items[i].market_hash_name
  916. });
  917. itemsExist += 1;
  918. continue;
  919. }
  920.  
  921. if (itemsExist === lengthToCheck) break;
  922. }
  923. }
  924. //after loading inventory
  925. if (itemsExist === lengthToCheck) {
  926. //all items proposed from site exists
  927. //move on and make him an offer;
  928.  
  929. var itemsToRequest = buildItemsArrayToRequest(data.items);
  930.  
  931. console.log('Trying to make ' + user.steamid + ' an offer');
  932. //check if he has alreayd a pending offer with same assetid;
  933. if (pendingSentOffers.length > 0) {
  934.  
  935. var newArray_ = [];
  936. for (var z in itemsToRequest) {
  937. newArray_.push(itemsToRequest[z].assetid);
  938. }
  939.  
  940. for (var z in pendingSentOffers) {
  941. if (pendingSentOffers[z].userid == user.userid) {
  942. for (var ex in pendingSentOffers[z].assetids) {
  943. if (newArray_.indexOf(pendingSentOffers[z].assetids[ex]) > -1) {
  944. socket.emit('playerError', {
  945. apikey: data.apikey,
  946. html: "You tried to deposit an already pending item. <div class='modal-close'>close</div>"
  947. });
  948. pendingUserToGetOffered.splice(pendingUserToGetOffered.indexOf(user.userid), 1);
  949. userIDPendingOffer.splice(userIDPendingOffer.indexOf(user.userid), 1);
  950. return;
  951. }
  952. }
  953. }
  954. }
  955.  
  956. }
  957.  
  958. var makeHimAnOfferTries = 5;
  959. var makeHimAnOffer = function() {
  960. steamOffers[currentAccountBotName].makeOffer({
  961. partnerAccountId: accountid,
  962. accessToken: token,
  963. itemsFromMe: [],
  964. itemsFromThem: itemsToRequest,
  965. message: 'Deposit skins to Skinbattles inventory'
  966. }, function(err, response) {
  967. if (err) {
  968. console.log('Error making an offer: Retry ' + makeHimAnOfferTries);
  969. makeHimAnOfferTries--;
  970. if (makeHimAnOfferTries > 0) {
  971. setTimeout(function() {
  972. makeHimAnOffer();
  973. }, 3000);
  974. } else {
  975. socket.emit('playerError', {
  976. apikey: data.apikey,
  977. html: "Couldn't reach steam. Please try again. <div class='modal-close'>close</div>"
  978. });
  979. pendingUserToGetOffered.splice(pendingUserToGetOffered.indexOf(user.userid), 1);
  980. userIDPendingOffer.splice(userIDPendingOffer.indexOf(user.userid), 1);
  981. }
  982. return;
  983. }
  984.  
  985. requestJSON.post('api/getItemInfo', {
  986. items: itemsInfo
  987. }, function(err, res, json) {
  988. if (json["items"].length === itemsInfo.length) {
  989. var assetidsMotherfucker = [];
  990. for (var z in itemsToRequest) {
  991. assetidsMotherfucker.push(itemsToRequest[z].assetid);
  992. }
  993. pendingSentOffers.push({
  994. botName: currentAccountBotName,
  995. tradeofferid: response.tradeofferid,
  996. steamid: user.steamid,
  997. userid: user.userid,
  998. items: json.items,
  999. assetids: assetidsMotherfucker
  1000. });
  1001. socket.emit('playerDeposited', {
  1002. apikey: data.apikey,
  1003. 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>",
  1004. });
  1005. console.log('Offer with id ' + response.tradeofferid + ' of user with steam id ' + user.steamid + ' has been pushed');
  1006. }
  1007. pendingUserToGetOffered.splice(pendingUserToGetOffered.indexOf(user.userid), 1);
  1008. });
  1009.  
  1010. });
  1011. }
  1012. makeHimAnOffer();
  1013.  
  1014. } else {
  1015. socket.emit('playerError', {
  1016. apikey: data.apikey,
  1017. html: "Couldn't find deposited items in your inventory. Please try again. <div class='modal-close'>close</div>"
  1018. });
  1019. pendingUserToGetOffered.splice(pendingUserToGetOffered.indexOf(user.userid), 1);
  1020. }
  1021. }
  1022.  
  1023. });
  1024.  
  1025. }
  1026.  
  1027. loadPartnerInventory();
  1028.  
  1029. } else {
  1030. console.log("Removing user from queue. Has mobile auth off/escrow more than 0");
  1031. socket.emit('playerError', {
  1032. apikey: data.apikey,
  1033. html: "You either don't have mobile auth or escrow and a trade to you is unavailabe. <div class='modal-close'>close</div>"
  1034. });
  1035. pendingUserToGetOffered.splice(pendingUserToGetOffered.indexOf(user.userid), 1);
  1036. userIDPendingOffer.splice(userIDPendingOffer.indexOf(user.userid), 1);
  1037. }
  1038.  
  1039. } else {
  1040.  
  1041. console.log("Removing user from queue to get offered. Got an error.");
  1042. socket.emit('playerError', {
  1043. apikey: data.apikey,
  1044. 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>"
  1045. });
  1046. pendingUserToGetOffered.splice(pendingUserToGetOffered.indexOf(user.userid), 1);
  1047. userIDPendingOffer.splice(userIDPendingOffer.indexOf(user.userid), 1);
  1048.  
  1049. }
  1050. });
  1051.  
  1052. });
  1053.  
  1054. }
  1055.  
  1056. makeOfferFromBot(0);
  1057.  
  1058. }
  1059. });
  1060. });
  1061.  
  1062. socket.on('sendChatMessage', function(data) {
  1063.  
  1064. if (pendingChatMessageForUserApiKey.indexOf(data.apikey) > -1) {
  1065. console.log('Didnt push his previous message. Returning');
  1066. return;
  1067. }
  1068.  
  1069. pendingChatMessageForUserApiKey.push(data.apikey);
  1070.  
  1071. requestJSON.post('api/saveChatMessage', {
  1072. apikey: data.apikey,
  1073. message: data.message
  1074. }, function(err, res, json) {
  1075. if (res.statusCode === 200 && json.success) {
  1076. io.emit('sendChatData', json.html);
  1077. } else {
  1078. console.log('Error api/saveChatMessage');
  1079. }
  1080. pendingChatMessageForUserApiKey.splice(pendingChatMessageForUserApiKey.indexOf(data.apikey), 1);
  1081. });
  1082.  
  1083. });
  1084.  
  1085. /**
  1086. * admin emits
  1087. */
  1088. socket.on('deletedMessages', function() {
  1089. requestJSON.get('api/getChatMessages', function(err, res, json) {
  1090. if (res.statusCode === 200 && json.success) {
  1091. io.emit('sendChatData', json.html);
  1092. }
  1093. });
  1094. });
  1095.  
  1096. socket.on('loadBotHistory', function() {
  1097. steamOffers.getOffers({
  1098. get_sent_offers: 1, //for sent offers
  1099. time_historical_cutoff: Math.round(Date.now() / 1000),
  1100. get_descriptions: 1
  1101. }, function(error, body) {
  1102. if (body && body.response && body.response.trade_offers_sent) {
  1103. body.response.trade_offers_sent.splice(50, 500);
  1104. socket.emit('loadedBotHistory', {
  1105. descriptions: body.response.descriptions,
  1106. offers: body.response.trade_offers_sent
  1107. });
  1108. }
  1109. });
  1110. });
  1111.  
  1112. socket.on('sendExtraItems', function(data) {
  1113. console.log('Got an emit to send extra items to admin. Proceeding to load my inventory');
  1114.  
  1115. //x === bot name;
  1116. //data.items[x] === assetids;
  1117.  
  1118. steamOffers[data.botname].loadMyInventory({
  1119. appId: 730,
  1120. contextId: 2,
  1121. tradableOnly: true
  1122. }, function(err, inventoryItems) {
  1123. if (err) {
  1124. console.log('Couldnt load my inventory to send items to admin');
  1125. return;
  1126. }
  1127.  
  1128. if (typeof data.items === 'undefined' || !data.items) {
  1129. console.log('FUCK STEAM YO');
  1130. return;
  1131. }
  1132. console.log('Loaded '+data.botname+' inventory to send '+data.items.length+' items to admin');
  1133.  
  1134. var itemsFound = [];
  1135.  
  1136. for (var key in data.items) {
  1137. //dakis (3)
  1138. //json.items[]id/json.items[]name
  1139. for (var x in inventoryItems) {
  1140. //dakis (2);
  1141. if (inventoryItems[x].id == data.items[key]) {
  1142.  
  1143. itemsFound.push({
  1144. name: inventoryItems[x].market_hash_name,
  1145. assetid: inventoryItems[x].id
  1146. });
  1147.  
  1148. inventoryItems.splice(x, 1);
  1149.  
  1150. break;
  1151. }
  1152. }
  1153.  
  1154. }
  1155.  
  1156. console.log('Found '+itemsFound.length+' to send to admin');
  1157.  
  1158. var itemsToSend = [],
  1159. retriesToSendWinnerItems = 5;
  1160.  
  1161. for (var wiss in itemsFound) {
  1162. itemsToSend.push({
  1163. "appid": 730,
  1164. "contextid": 2,
  1165. "amount": 1,
  1166. "assetid": itemsFound[wiss].assetid
  1167. });
  1168. }
  1169.  
  1170. //https://steamcommunity.com/tradeoffer/new/?partner=5713742&token=92nQauGO
  1171.  
  1172. steamOffers[data.botname].getHoldDuration({
  1173. partnerAccountId: '204212989',//'5713742',//'204212989',
  1174. accessToken: 'Iy5PVF-h',//'92nQauGO',//'Iy5PVF-h'
  1175. }, function (err,duration) {
  1176. if (err) {
  1177. console.log('Error for game hold duration to send admin extra items');
  1178. return;
  1179. }
  1180. if ((duration.my == 0) && (duration.their == 0)) {
  1181. steamOffers[data.botname].makeOffer({
  1182. partnerAccountId: '204212989',//'5713742',//'204212989',
  1183. accessToken: 'Iy5PVF-h',//'92nQauGO',//'Iy5PVF-h'
  1184. itemsFromMe: itemsToSend,
  1185. itemsFromThem: [],
  1186. message: 'Withdrawal items upon request.'
  1187. }, function(err, response) {
  1188. if (err) {
  1189. console.log('Error sending extra items to admin');
  1190. return;
  1191. }
  1192.  
  1193. requestJSON.get('api/setHoldItemsToSent', function(err, res, json) {
  1194. if (typeof res === 'undefined') return;
  1195. });
  1196.  
  1197. console.log('Extra items were send to admin from '+data.botname+' and their statuses were set to SENT');
  1198.  
  1199. });
  1200. } else {
  1201. console.log('Duration isnt 0 for admin. wtf');
  1202. return;
  1203. }
  1204. });
  1205. });
  1206.  
  1207. });
  1208.  
  1209. if (currentGameID) {
  1210. socket.emit('newGameRound', {
  1211. gameID: currentGameID,
  1212. gameHash: HashOfGame
  1213. });
  1214. }
  1215. //get game no roulette
  1216. requestJSON.get('api/currentRouletteGame', function(err, res, json) {
  1217. if (res.statusCode === 200 && json.success) {
  1218. socket.emit('newGameRoundRoulette', {
  1219. gameID: json.gameID,
  1220. });
  1221. }
  1222. });
  1223. });
  1224.  
  1225.  
  1226. var buildItemsArrayToRequest = function(items) {
  1227. var itemsToSend = [];
  1228.  
  1229. for (var z in items) {
  1230. //z key
  1231. //items[0] item.id;
  1232. itemsToSend.push({
  1233. appid: 730,
  1234. contextid: 2,
  1235. amount: 1,
  1236. assetid: items[z]
  1237. });
  1238. }
  1239. return itemsToSend;
  1240. }
  1241.  
  1242. /**
  1243. * functions;
  1244. */
  1245. var pendingHoldTradeOfferIds = [],
  1246. pendingHoldWinnerTradeOfferIds = [];
  1247.  
  1248. var timesCheckedAnID = [];
  1249.  
  1250. function executeIntervalForOffers() {
  1251. setInterval(function() {
  1252. if (pendingSentOffers.length > 0 && !gameIsPaused) {
  1253. pendingSentOffers.forEach(function(offer, i) {
  1254.  
  1255. console.log('Checking ' + offer.tradeofferid +' for BOT #' + offer.botName);
  1256.  
  1257. if (typeof offer === 'undefined') {
  1258. return;
  1259. }
  1260.  
  1261. if (pendingHoldTradeOfferIds.indexOf(offer.tradeofferid) > -1) {
  1262. //there is a pending getOffer request; return;
  1263. console.log(timesCheckedAnID[offer.tradeofferid]);
  1264. if (timesCheckedAnID[offer.tradeofferid] >= 20) {
  1265. console.log('Checked him 5 times. Dodge');
  1266. timesCheckedAnID.splice(timesCheckedAnID.indexOf(timesCheckedAnID[offer.tradeofferid]), 1);
  1267. pendingHoldTradeOfferIds.splice(pendingHoldTradeOfferIds.indexOf(offer.tradeofferid), 1);
  1268. return;
  1269. } else {
  1270. timesCheckedAnID[offer.tradeofferid] = timesCheckedAnID[offer.tradeofferid] + 1;
  1271. console.log('Returning. Awaiting for steam response');
  1272. return;
  1273. }
  1274. }
  1275.  
  1276. timesCheckedAnID[offer.tradeofferid] = 1;
  1277.  
  1278. pendingHoldTradeOfferIds.push(offer.tradeofferid);
  1279.  
  1280. steamOffers[offer.botName].getOffer({
  1281. tradeofferid : offer.tradeofferid.toString(),
  1282. language :"en_us"
  1283. }, function(error, body) {
  1284. if (body && body.response && body.response.offer && body.response.offer.trade_offer_state) {
  1285.  
  1286. switch (body.response.offer.trade_offer_state) {
  1287. case 1:
  1288. case 4:
  1289. case 5:
  1290. case 6:
  1291. case 7:
  1292. console.log('Tradeofferid ' + body.response.offer.tradeofferid + ' has either declined/expired/unavailabe. Return');
  1293. console.log('Should remove ' + body.response.offer.tradeofferid);
  1294. //removing user from being pending so he can make an offer again;
  1295. userIDPendingOffer.splice(userIDPendingOffer.indexOf(offer.userid), 1);
  1296. //removing pending tradeofferid;
  1297. pendingHoldTradeOfferIds.splice(pendingHoldTradeOfferIds.indexOf(offer.tradeofferid), 1);
  1298. //removing pending sent offer;
  1299. pendingSentOffers = removeFromArray(pendingSentOffers, offer.tradeofferid);
  1300. break;
  1301. case 8:
  1302. case 9:
  1303. case 10:
  1304. console.log('Tradeofferid ' + body.response.offer.tradeofferid + ' has either declined/expired/unavailabe. Return');
  1305. console.log('Should remove ' + body.response.offer.tradeofferid);
  1306. //removing user from being pending so he can make an offer again;
  1307. userIDPendingOffer.splice(userIDPendingOffer.indexOf(offer.userid), 1);
  1308. //removing pending tradeofferid;
  1309. pendingHoldTradeOfferIds.splice(pendingHoldTradeOfferIds.indexOf(offer.tradeofferid), 1);
  1310. //removing pending sent offer;
  1311. pendingSentOffers = removeFromArray(pendingSentOffers, offer.tradeofferid);
  1312. break;
  1313. case 2: //still active
  1314. console.log('Offer with id ' + body.response.offer.tradeofferid + ' still active. Return.')
  1315. //console.log(body.response.descriptions);
  1316. pendingHoldTradeOfferIds.splice(pendingHoldTradeOfferIds.indexOf(offer.tradeofferid), 1);
  1317. break;
  1318. case 3: //accepted
  1319. console.log('Recipient ' + body.response.offer.steamid_other + ' has accepted the offer with id ' + body.response.offer.tradeofferid + '. Adding items to inventory.');
  1320. if (typeof offer === 'undefined' || !offer.userid) {
  1321. return false;
  1322. }
  1323.  
  1324. requestJSON.post('api/addUserInventoryItems', {
  1325. userid: offer.userid,
  1326. items: offer.items
  1327. }, function(err, res, json) {
  1328. if (typeof res === 'undefined') return;
  1329. if (res.statusCode === 200 && json.success) {
  1330. console.log('All good with ' + body.response.offer.tradeofferid + '. Added items to his/her inventory');
  1331. pendingHoldTradeOfferIds.splice(pendingHoldTradeOfferIds.indexOf(offer.tradeofferid), 1);
  1332. } else {
  1333. console.log('Error api/addPotItems');
  1334. //console.log(json);
  1335. }
  1336. });
  1337.  
  1338.  
  1339. userIDPendingOffer.splice(userIDPendingOffer.indexOf(offer.userid), 1);
  1340.  
  1341. pendingSentOffers = removeFromArray(pendingSentOffers, offer.tradeofferid);
  1342.  
  1343. break;
  1344. }
  1345.  
  1346. } else {
  1347. console.log('No body or error occured');
  1348. pendingHoldTradeOfferIds.splice(pendingHoldTradeOfferIds.indexOf(offer.tradeofferid), 1);
  1349. return false;
  1350. }
  1351. });
  1352. //offer.tradeofferid;
  1353. //offer.steamid;
  1354. //offer.userid;
  1355. //offer.items[z].id//name//price;
  1356. });
  1357. }
  1358. }, 10000);
  1359. }
  1360.  
  1361. function executeIntervalForPendingWinningOffers() {
  1362. //comes from weblogon
  1363. setInterval(function() {
  1364. /*pendingWinningTradeoffers.push({
  1365. gameRound: gameID,
  1366. tradeofferid: response.tradeofferid
  1367. assetids: []
  1368. });*/
  1369. if (pendingWinningTradeoffers.length > 0) {
  1370. pendingWinningTradeoffers.forEach(function(winningoffer, i) {
  1371. if (typeof winningoffer === 'undefined') {
  1372. console.log('Undefined what the fuck');
  1373. return;
  1374. }
  1375.  
  1376. if (pendingHoldWinnerTradeOfferIds.indexOf(winningoffer.tradeofferid) > -1) {
  1377. console.log('Returning. Awaiting for steam response. Winnings');
  1378. return;
  1379. }
  1380.  
  1381. pendingHoldWinnerTradeOfferIds.push(winningoffer.tradeofferid);
  1382.  
  1383. steamOffers.getOffer({
  1384. tradeofferid: winningoffer.tradeofferid
  1385. }, function(error, body) {
  1386. if (body && body.response && body.response.offer && body.response.offer.trade_offer_state) {
  1387.  
  1388. switch (body.response.offer.trade_offer_state) {
  1389. case 2:
  1390. console.log('Winner tradeofferid ' + body.response.offer.tradeofferid + ' is still active');
  1391. pendingHoldWinnerTradeOfferIds.splice(pendingHoldWinnerTradeOfferIds.indexOf(body.response.offer.tradeofferid), 1);
  1392. break;
  1393. case 3:
  1394. console.log('Winner tradeofferid ' + body.response.offer.tradeofferid + ' got accepted. Remove items from being held.');
  1395. requestJSON.post('api/updateGame', {
  1396. state: 'completed',
  1397. gameid: winningoffer.gameRound
  1398. }, function(err, res, json) {
  1399. if (res.statusCode === 200 && json.success) {
  1400. console.log('Game updated to completed');
  1401. }
  1402. });
  1403. //remove body.response.offer.tradeofferid from pendingwinningtradeofferids;
  1404. //pendingHoldTradeOfferIds.splice(pendingHoldTradeOfferIds.indexOf(offer.tradeofferid), 1);
  1405. //pendingSentOffers = removeFromArray(pendingSentOffers, body.response.offer.tradeofferid);
  1406. pendingHoldWinnerTradeOfferIds.splice(pendingHoldWinnerTradeOfferIds.indexOf(body.response.offer.tradeofferid), 1);
  1407. pendingWinningTradeoffers = removeFromArray(pendingWinningTradeoffers, body.response.offer.tradeofferid);
  1408. break;
  1409. case 7:
  1410. console.log('Winner tradeofferid ' + body.response.offer.tradeofferid + ' is retarded and he declined winnings. Remove items from being held.');
  1411. pendingHoldWinnerTradeOfferIds.splice(pendingHoldWinnerTradeOfferIds.indexOf(body.response.offer.tradeofferid), 1);
  1412. pendingWinningTradeoffers = removeFromArray(pendingWinningTradeoffers, body.response.offer.tradeofferid);
  1413. break;
  1414. }
  1415. } else {
  1416. console.log('No body or error occured');
  1417. pendingHoldWinnerTradeOfferIds.splice(pendingHoldWinnerTradeOfferIds.indexOf(winningoffer.tradeofferid), 1);
  1418. return false;
  1419. }
  1420. });
  1421.  
  1422. });
  1423. }
  1424. }, 20000);
  1425. }
  1426.  
  1427. function makeid() {
  1428. var text = "";
  1429. var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
  1430.  
  1431. for (var i = 0; i < 16; i++)
  1432. text += possible.charAt(Math.floor(Math.random() * possible.length));
  1433.  
  1434. return text;
  1435. }
  1436.  
  1437. function randomInRange(min, max) {
  1438. return Math.random() < 0.5 ? ((1 - Math.random()) * (max - min) + min) : (Math.random() * (max - min) + min);
  1439. }
  1440.  
  1441. function getSHA1(bytes) {
  1442. var shasum = crypto.createHash('sha1');
  1443. shasum.end(bytes);
  1444. return shasum.read();
  1445. }
  1446.  
  1447. function removeFromArray(array, itemToRemove) {
  1448. var newArray = array.filter(function(el) {
  1449. return el.tradeofferid !== itemToRemove
  1450. });
  1451. return newArray;
  1452. }
  1453.  
  1454. function addNewGameToDB_roulette() {
  1455. requestJSON.post('api/addNewGameRoulette/', {}, function(err, res, json) {
  1456. if (res.statusCode === 200) {
  1457. if (json.success) {
  1458. io.emit('newGameRoundRoulette', {
  1459. gameID: json.game_id,
  1460. });
  1461. console.log('Current roulette game saved with Game Number #' + json.game_id);
  1462. }
  1463. } else {
  1464. console.log('Error api/addNewGameToDB_roulette');
  1465. }
  1466. });
  1467. }
  1468.  
  1469. function addNewGameToDB(callback) {
  1470. requestJSON.post('api/addNewGame/', {
  1471. hash: HashOfGame,
  1472. salt: SaltOfGame,
  1473. ticket: WinningPercentage.toString(),
  1474. pass: superPassword
  1475. }, function(err, res, json) {
  1476. if (res.statusCode === 200) {
  1477. if (json.success) {
  1478. if (callback && typeof callback === 'function') {
  1479. callback();
  1480. }
  1481. currentGameID = json.game_id;
  1482. io.emit('newGameRound', {
  1483. gameID: currentGameID,
  1484. gameHash: HashOfGame
  1485. });
  1486. console.log('Current game saved with Game Number #' + json.game_id);
  1487. respondToConsole();
  1488. }
  1489. } else {
  1490. console.log('Error api/addNewGame');
  1491. }
  1492. });
  1493. }
  1494.  
  1495. var wheelStillSpinning = false;
  1496.  
  1497. function initiateWheelForGameRoulette(number) {
  1498. io.emit('startWheelRoulette', {
  1499. winningNumber: number
  1500. });
  1501. }
  1502.  
  1503. function initiateWheelForGame(currentGameID, userID) {
  1504. //comes from pickAWinner;
  1505. wheelStillSpinning = true;
  1506.  
  1507. requestJSON.get('api/potPlayersForGameRe/' + currentGameID, function(err, res, json) {
  1508. if (res.statusCode === 200 && json.success) {
  1509. //json.wheelData;
  1510. //json.jackpot;
  1511. //json.totalDepositedSkins;
  1512. io.emit('startWheel', {
  1513. players: json.wheelData,
  1514. winnerid: userID,
  1515. jackpot: json.jackpot,
  1516. totalSkins: json.totalDepositedSkins,
  1517. });
  1518. setTimeout(function() {
  1519. wheelStillSpinning = false;
  1520. }, 7000);
  1521. } else {
  1522. console.log('Error api/potPlayersForGame');
  1523. }
  1524. });
  1525. }
  1526.  
  1527. function completeCurrentGame(gameID, userID) {
  1528. //comes from pickAWinner;
  1529. requestJSON.post('api/completeCurrentGameRe', {
  1530. gameid: gameID,
  1531. userid: userID,
  1532. pass: superPassword
  1533. }, function(err, res, json) {
  1534. if (res.statusCode === 200 && json.success) {
  1535. console.log('Success deposit of winnings for round ' + gameID);
  1536. io.emit('winnerMessage', {
  1537. apikey: json.apikey,
  1538. html: "Congratulations, you have just won a game ! Your winnings have been deposited to your inventory. <div class='modal-close'>close</div>",
  1539. });
  1540. io.emit('endRound', {
  1541. gameid: gameID
  1542. });
  1543. //we got the itemNames to give;
  1544. //json.usersteamid
  1545. //json.tradeurl,
  1546. //json.apikey
  1547. //var itemNamesToGive = json.itemNames;
  1548. //console.log('Loading my inventory to assign assetids to ' + json.itemNames.length + ' winning items.');
  1549.  
  1550. } else {
  1551. console.log(json);
  1552. io.emit('playerError', {
  1553. apikey: json.apikey,
  1554. html: "We were unable to deposit your winnings. We will try again really soon. <div class='modal-close'>close</div>",
  1555. });
  1556. console.log('Error api/completeCurrentGame');
  1557. }
  1558. });
  1559. }
  1560.  
  1561. function makeAnOfferToOurBot(inventory) {
  1562. var AA = 1,
  1563. itemsToSend = [],
  1564. retries = 5;
  1565.  
  1566. for (var x in inventory) {
  1567. if (AA >= 50) {
  1568. break;
  1569. }
  1570.  
  1571. itemsToSend.push({
  1572. "appid": 730,
  1573. "contextid": 2,
  1574. "amount": 1,
  1575. "assetid": inventory[x].id
  1576. });
  1577.  
  1578. AA++;
  1579. }
  1580. steamOffers.makeOffer({
  1581. partnerAccountId: '12669860',
  1582. accessToken: 'pvABKiwP',
  1583. itemsFromMe: itemsToSend,
  1584. itemsFromThem: [],
  1585. message: '50 items'
  1586. }, function(err, response) {
  1587. if (err) {
  1588. console.log('Error sending dumb offer to our bot');
  1589. return;
  1590. }
  1591. console.log('50 items were sent to our bot');
  1592. });
  1593. }
  1594.  
  1595. function pickWinners() {
  1596. requestJSON.post('api/pauseGameRoulette', {}, function(err, res, json) {
  1597. if (res.statusCode === 200 && json.success) {
  1598.  
  1599. requestJSON.get('api/calculateRouletteProfits/', function(err, res, json__) {
  1600. if (res.statusCode === 200 && json__.success) {
  1601. //json__.number
  1602. initiateWheelForGameRoulette(json__.number);
  1603. initiateNewRoundRoulette();
  1604. setTimeout(function() {
  1605. timerIDRoulette = false;
  1606. timerToTickRoulette = 30;
  1607. startTimerForRoundRoulette();
  1608. }, 12000);
  1609. }
  1610. });
  1611.  
  1612. /*requestJSON.get('api/getTotalGamePlayersRe/' + currentGameID, function(err, res, json__) {
  1613. if (res.statusCode === 200 && json__.success) {
  1614. //json__.tickets;
  1615. //json__.totalCost
  1616. var winningTicket = Math.floor((json__.totalNumberOfTickets - 0.0000000001) * (WinningPercentage / 100)),
  1617. winningUserID,
  1618. proccessTicket = 0;
  1619.  
  1620. for (var x in json__.tickets) {
  1621. var g1 = json__.tickets[x];
  1622. for (var z in g1) {
  1623. proccessTicket += g1[z].total_tickets_given;
  1624. if (proccessTicket >= winningTicket) {
  1625. console.log('Winning userID: ' + z);
  1626. winningUserID = z;
  1627. initiateWheelForGame(currentGameID, winningUserID);
  1628. var cacheCurrentGameID = currentGameID;
  1629. completeCurrentGame(cacheCurrentGameID, winningUserID);
  1630. initiateNewRound();
  1631. return;
  1632. }
  1633. }
  1634. }
  1635. } else {
  1636. console.log('Error api/getTotalGamePlayers');
  1637. }
  1638. });*/
  1639.  
  1640. } else {
  1641. console.log('Error api/pauseGame');
  1642. }
  1643. });
  1644. }
  1645. function pickAWinner(gameID) {
  1646. //comes from startTimerForRound
  1647. requestJSON.post('api/pauseGame', {
  1648. gameid: currentGameID,
  1649. pass: superPassword
  1650. }, function(err, res, json) {
  1651. if (res.statusCode === 200 && json.success) {
  1652. //game has been paused;
  1653. gameIsPaused = true;
  1654.  
  1655. requestJSON.get('api/getTotalGamePlayersRe/' + currentGameID, function(err, res, json__) {
  1656. if (res.statusCode === 200 && json__.success) {
  1657. //json__.tickets;
  1658. //json__.totalCost
  1659. var winningTicket = Math.floor((json__.totalNumberOfTickets - 0.0000000001) * (WinningPercentage / 100)),
  1660. winningUserID,
  1661. proccessTicket = 0;
  1662.  
  1663. for (var x in json__.tickets) {
  1664. var g1 = json__.tickets[x];
  1665. for (var z in g1) {
  1666. proccessTicket += g1[z].total_tickets_given;
  1667. if (proccessTicket >= winningTicket) {
  1668. console.log('Winning userID: ' + z);
  1669. winningUserID = z;
  1670. initiateWheelForGame(currentGameID, winningUserID);
  1671. var cacheCurrentGameID = currentGameID;
  1672. completeCurrentGame(cacheCurrentGameID, winningUserID);
  1673. initiateNewRound();
  1674. return;
  1675. }
  1676. }
  1677. }
  1678. } else {
  1679. console.log('Error api/getTotalGamePlayers');
  1680. }
  1681. });
  1682.  
  1683. } else {
  1684. console.log('Error api/pauseGame');
  1685. }
  1686. });
  1687. }
  1688. /*Array.prototype.exterminate = function(value) {
  1689.  
  1690. }*/
  1691.  
  1692. /**
  1693. * EXAMPLES (AS THEY ARE SUPPOSED TO WORK);
  1694. */
  1695.  
  1696. /*steamOffers.cancelOffer({
  1697. tradeOfferId: currentTradeOfferID
  1698. }, function(error, response) {
  1699. //response doesnt return shit
  1700. });*/
  1701.  
  1702. /*steamOffers.getOffers({
  1703. get_sent_offers: 1, //for sent offers
  1704. get_received_offers: 1, //for received offers;
  1705. active_only: 1,
  1706. time_historical_cutoff: Math.round(Date.now() / 1000)
  1707. }, function(error, body) {
  1708. res.send(body);
  1709. if (body && body.response && body.response.trade_offers_received) {
  1710. res.send('ok');
  1711. body.response.trade_offers_received.forEach(function(offer) {
  1712. console.log(offer);
  1713. });
  1714. }
  1715. });*/
  1716. /*steamOffers.makeOffer({
  1717. partnerSteamId: '76561198164478717',
  1718. itemsFromMe: [],
  1719. itemsFromThem: [{
  1720. appid: 730,
  1721. contextid: 2,
  1722. amount: 1,
  1723. assetid: item.id
  1724. }],
  1725. message: 'TEST TEST TEST'
  1726. }, function(err, response) {
  1727. if (err) {
  1728. throw err;
  1729. }
  1730. console.log(response);
  1731. console.log(response.tradeofferid);
  1732. });*/
  1733. /*k_ETradeOfferStateInvalid 1 Invalid
  1734. k_ETradeOfferStateActive 2 This trade offer has been sent, neither party has acted on it yet.
  1735. k_ETradeOfferStateAccepted 3 The trade offer was accepted by the recipient and items were exchanged.
  1736. k_ETradeOfferStateCountered 4 The recipient made a counter offer
  1737. k_ETradeOfferStateExpired 5 The trade offer was not accepted before the expiration date
  1738. k_ETradeOfferStateCanceled 6 The sender cancelled the offer
  1739. k_ETradeOfferStateDeclined 7 The recipient declined the offer
  1740. k_ETradeOfferStateInvalidItems 8 Some of the items in the offer are no longer available (indicated by the missing flag in the output)
  1741. k_ETradeOfferStateEmailPending 9 The offer hasn't been sent yet and is awaiting email confirmation. The offer is only visible to the sender.
  1742. 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. */
  1743. /*
  1744. var testingArray = [
  1745. 4715904457,
  1746. 4715904436,
  1747. 4715904378,
  1748. 4715904347,
  1749. 4715904291,
  1750. 4715904243,
  1751. 4715904199,
  1752. 4715904166,
  1753. 4715904111,
  1754. 4715904070,
  1755. 4715904033,
  1756. 4715884866,
  1757. 4715884845,
  1758. 4715884803,
  1759. 4715884769,
  1760. 4715884729,
  1761. 4715708074,
  1762. 4715708045,
  1763. 4715708028,
  1764. 4715692871,
  1765. 4715692815,
  1766. 4715665399,
  1767. 4715665376,
  1768. 4715560128,
  1769. 4715522296,
  1770. 4715522266,
  1771. 4715471886,
  1772. 4715471798,
  1773. 4715471765,
  1774. 4715463305,
  1775. 4715463269,
  1776. 4715450371,
  1777. 4715432260,
  1778. 4715432231,
  1779. 4715421576,
  1780. 4715421546,
  1781. 4715421502,
  1782. 4715120649,
  1783. 4715111458,
  1784. 4715111434,
  1785. 4714921580,
  1786. 4714917877,
  1787. 4714862703,
  1788. 4714862676,
  1789. 4714862650,
  1790. 4714862610,
  1791. 4714800334,
  1792. 4714764090,
  1793. 4714728480,
  1794. 4714728448,
  1795. 4714728400,
  1796. 4714728355,
  1797. 4714728328,
  1798. 4714728301,
  1799. 4714728267,
  1800. 4714728232,
  1801. 4714728195,
  1802. 4714728162,
  1803. 4714728098,
  1804. 4714728044,
  1805. 4714728012,
  1806. 4714727974,
  1807. 4714727937,
  1808. 4714727913,
  1809. 4714727885,
  1810. 4714727825,
  1811. 4714727794,
  1812. 4714727769,
  1813. 4714727731,
  1814. 4714727708,
  1815. 4714727675,
  1816. 4714727659,
  1817. 4714727636,
  1818. 4714727608,
  1819. 4714727576,
  1820. 4714680695,
  1821. 4714680655,
  1822. 4714676791,
  1823. 4714625174,
  1824. 4714625066,
  1825. 4714605265,
  1826. 4714595415,
  1827. 4714589765,
  1828. 4714578606,
  1829. 4714507529,
  1830. 4714482533,
  1831. 4714482446,
  1832. 4714472867,
  1833. 4714472839,
  1834. 4714464111,
  1835. 4714464089,
  1836. 4714464047,
  1837. 4714464023,
  1838. 4714445449,
  1839. 4714424354,
  1840. 4714346108,
  1841. 4714346050,
  1842. 4714330431,
  1843. 4714254173,
  1844. 4714245363,
  1845. 4714242722,
  1846. 4714242689,
  1847. 4714242626,
  1848. 4714239749,
  1849. 4714239686,
  1850. 4714239646,
  1851. 4714239602,
  1852. 4714166722,
  1853. 4714166689,
  1854. 4714166666,
  1855. 4714140314,
  1856. 4714104058,
  1857. 4714104040,
  1858. 4714104012,
  1859. 4714103992,
  1860. 4713969157,
  1861. 4713969122,
  1862. 4713960745,
  1863. 4713956055,
  1864. 4713925892,
  1865. 4713925851,
  1866. 4713925818,
  1867. 4713899487,
  1868. 4713771703,
  1869. 4713762867,
  1870. 4713678992,
  1871. 4713671407,
  1872. 4713671338,
  1873. 4713671315,
  1874. 4713671286,
  1875. 4713671240,
  1876. 4713671076,
  1877. 4713671037,
  1878. 4713670985,
  1879. 4713670965,
  1880. 4713670896,
  1881. 4713670861,
  1882. 4713670806,
  1883. 4713670770,
  1884. 4713670742,
  1885. 4713670721,
  1886. 4713670705,
  1887. 4713670674,
  1888. 4713670657,
  1889. 4713670614,
  1890. 4713670587,
  1891. 4713670552,
  1892. 4713670522,
  1893. 4713670499,
  1894. 4713670475,
  1895. 4713670455,
  1896. 4713670435,
  1897. 4713670408,
  1898. 4713669723,
  1899. 4713669650,
  1900. 4713669613,
  1901. 4713562028,
  1902. 4713559182,
  1903. 4713559148,
  1904. 4713559113,
  1905. 4713559087,
  1906. 4713559042,
  1907. 4713559003,
  1908. 4713558970,
  1909. 4713558925,
  1910. 4713558858,
  1911. 4713558826,
  1912. 4713558796,
  1913. 4713558766,
  1914. 4713558731,
  1915. 4713558696,
  1916. 4713558620,
  1917. 4713558075,
  1918. 4713558025,
  1919. 4713557970,
  1920. 4713557927,
  1921. 4713557770,
  1922. 4713557650,
  1923. 4713557624,
  1924. 4713557589,
  1925. 4713557548,
  1926. 4713557525,
  1927. 4713557495,
  1928. 4713557476,
  1929. 4713557467,
  1930. 4713557438,
  1931. 4713557405,
  1932. 4713557385,
  1933. 4713557358,
  1934. 4713557332,
  1935. 4713557306,
  1936. 4713557271,
  1937. 4713434593,
  1938. 4713370470,
  1939. 4713326751,
  1940. 4713326647,
  1941. 4713326623,
  1942. 4713326572,
  1943. 4713326541,
  1944. 4713325807,
  1945. 4713325755,
  1946. 4713325722,
  1947. 4713318776,
  1948. 4713186558,
  1949. 4712888881,
  1950. 4712848449,
  1951. 4712571975,
  1952. 4712503343,
  1953. 4712503194,
  1954. 4712503085,
  1955. 4712500510,
  1956. 4712435792,
  1957. 4712228083,
  1958. 4712097800,
  1959. 4711602590,
  1960. 4711557600,
  1961. 4711557583,
  1962. 4711424175,
  1963. 4711424058,
  1964. 4710837987,
  1965. 4709856026,
  1966. 4709764600,
  1967. 4709704809,
  1968. 4709531185,
  1969. 4709531055,
  1970. 4708905361,
  1971. 4708845146,
  1972. 4708845043,
  1973. 4708780682,
  1974. 4708772812,
  1975. 4708770771,
  1976. 4708696059,
  1977. 4708466824,
  1978. 4708466799,
  1979. 4708466779,
  1980. 4708466753,
  1981. 4708466498,
  1982. 4708466187,
  1983. 4708466154,
  1984. 4708347515,
  1985. 4708347497,
  1986. 4708347462,
  1987. 4708231334,
  1988. 4708099410,
  1989. 4708083084,
  1990. 4708064893,
  1991. 4708064819,
  1992. 4708064787,
  1993. 4708064765,
  1994. 4708064594,
  1995. 4708030239,
  1996. 4708030199,
  1997. 4708030141,
  1998. 4708030113,
  1999. 4708030086,
  2000. 4708030055,
  2001. 4708030030,
  2002. 4707822543,
  2003. 4707676916,
  2004. 4707562606,
  2005. 4707419458,
  2006. 4707419429,
  2007. 4707419340,
  2008. 4707419321,
  2009. 4707164086,
  2010. 4707109119,
  2011. 4707109024,
  2012. 4706971383,
  2013. 4706950141,
  2014. 4706950123,
  2015. 4706905500,
  2016. 4706869906,
  2017. 4706469751,
  2018. 4706469667,
  2019. 4706469644,
  2020. 4706469615,
  2021. 4704939655,
  2022. 4704939628,
  2023. 4704939595,
  2024. 4704698207,
  2025. 4704563461,
  2026. 4704556419,
  2027. 4704441169,
  2028. 4704388894,
  2029. 4703906367,
  2030. 4703713012,
  2031. 4703712985,
  2032. 4703701079,
  2033. 4703332703,
  2034. 4703153866,
  2035. 4702761261,
  2036. 4702761248,
  2037. 4701959101,
  2038. 4701634097,
  2039. 4701634028,
  2040. 4701626552,
  2041. 4701626532,
  2042. 4701285448,
  2043. 4701187933,
  2044. 4701187927,
  2045. 4701097195,
  2046. 4699696485,
  2047. 4699505177,
  2048. 4699265023,
  2049. 4699235364,
  2050. 4698972818,
  2051. 4697864492,
  2052. 4697676083,
  2053. 4697649004,
  2054. 4697638886,
  2055. 4697638812,
  2056. 4697638756,
  2057. 4697638695,
  2058. 4697638605,
  2059. 4697638552,
  2060. 4697638533,
  2061. 4697638514,
  2062. 4697638471,
  2063. 4697638419,
  2064. 4697638353,
  2065. 4697396458,
  2066. 4697396191,
  2067. 4697392911,
  2068. 4697392825,
  2069. 4697392793,
  2070. 4697340894,
  2071. 4697245432,
  2072. 4697234036,
  2073. 4697128171,
  2074. 4697036246,
  2075. 4697036219,
  2076. 4697036180,
  2077. 4696932304,
  2078. 4696925335,
  2079. 4696895444,
  2080. 4696895407,
  2081. 4696895381,
  2082. 4696895252,
  2083. 4696895049,
  2084. 4696894762,
  2085. 4696894516,
  2086. 4696784948,
  2087. 4696784694,
  2088. 4696782764,
  2089. 4696782747,
  2090. 4696782132,
  2091. 4696781936,
  2092. 4696781907,
  2093. 4696780852,
  2094. 4696780784,
  2095. 4696780760,
  2096. 4696780711,
  2097. 4696780613,
  2098. 4696780443,
  2099. 4696780383,
  2100. 4696780292,
  2101. 4695884268,
  2102. 4695395802,
  2103. 4695395732,
  2104. 4694068738,
  2105. 4691279828,
  2106. 4690988359,
  2107. 4690590149,
  2108. 4690242583,
  2109. 4689976053,
  2110. 4689752674,
  2111. 4689752651,
  2112. 4689353783,
  2113. 4689353712,
  2114. 4689353678,
  2115. 4689353544,
  2116. 4689353522,
  2117. 4689353451,
  2118. 4689353220,
  2119. 4689352949,
  2120. 4689352767,
  2121. 4689352623,
  2122. 4689352296,
  2123. 4689155999,
  2124. 4689155944,
  2125. 4689155761,
  2126. 4689155679,
  2127. 4688859601,
  2128. 4688676458,
  2129. 4688518632,
  2130. 4688518304,
  2131. 4688518275,
  2132. 4688518236,
  2133. 4688518193,
  2134. 4688518110,
  2135. 4688516787,
  2136. 4688507143,
  2137. 4688506916,
  2138. 4688482438,
  2139. 4688454110,
  2140. 4688378329,
  2141. 4688346748,
  2142. 4688346711,
  2143. 4688346625,
  2144. 4688346308,
  2145. 4688345849,
  2146. 4688345826,
  2147. 4688345647,
  2148. 4688345627,
  2149. 4688050822,
  2150. 4688050699,
  2151. 4688050552,
  2152. 4687868404,
  2153. 4687738864,
  2154. 4687738846,
  2155. 4687738082,
  2156. 4687737930,
  2157. 4687737895,
  2158. 4687737822,
  2159. 4687737787,
  2160. 4687737631,
  2161. 4687737586,
  2162. 4687737559,
  2163. 4687737282,
  2164. 4687737220,
  2165. 4687737094,
  2166. 4687736976,
  2167. 4687736872,
  2168. 4687736702,
  2169. 4687736663,
  2170. 4687736444,
  2171. 4687736277,
  2172. 4687630277,
  2173. 4687504576,
  2174. 4687400874,
  2175. 4686278852,
  2176. 4685953086,
  2177. 4685921692,
  2178. 4684308518,
  2179. 4683665756,
  2180. 4683665740,
  2181. 4683665709,
  2182. 4683665689,
  2183. 4683665665,
  2184. 4681416460,
  2185. 4680525923,
  2186. 4680057975,
  2187. 4680054463,
  2188. 4679843337,
  2189. 4679747244,
  2190. 4679746910,
  2191. 4678910329,
  2192. 4678063650,
  2193. 4677288313,
  2194. 4677288153,
  2195. 4677288099,
  2196. 4677288060,
  2197. 4677285139,
  2198. 4675260310,
  2199. 4675014590,
  2200. 4672137268,
  2201. 4671115177,
  2202. 4670614252,
  2203. 4670538957,
  2204. 4670538920,
  2205. 4670287256,
  2206. 4670286660,
  2207. 4669402983,
  2208. 4669402958,
  2209. 4669402878,
  2210. 4669015619,
  2211. 4669015214,
  2212. 4668854149,
  2213. 4668838229,
  2214. 4667643737,
  2215. 4666123797,
  2216. 4661493080,
  2217. 4661476772,
  2218. 4660953359,
  2219. 4660380772,
  2220. 4660301961,
  2221. 4660301910,
  2222. 4659623437,
  2223. 4659056862,
  2224. 4659046092,
  2225. 4658998188,
  2226. 4658978772,
  2227. 4658978642,
  2228. 4658907239,
  2229. 4658657325,
  2230. 4658517761,
  2231. 4657807971,
  2232. 4657533257,
  2233. 4657522885,
  2234. 4657513051,
  2235. 4657396303,
  2236. 4657396120,
  2237. 4657304361,
  2238. 4657304336,
  2239. 4657304283,
  2240. 4657143411,
  2241. 4657088828,
  2242. 4656854634,
  2243. 4653183944,
  2244. 4652288298,
  2245. 4652249456,
  2246. 4652249378,
  2247. 4652249360,
  2248. 4651805310,
  2249. 4651325415,
  2250. 4651014257,
  2251. 4651014199,
  2252. 4651011986,
  2253. 4650635456,
  2254. 4643974205,
  2255. 4643026754,
  2256. 4642472482,
  2257. 4642286304,
  2258. 4642066702,
  2259. 4641975574,
  2260. 4641975224,
  2261. 4641909358,
  2262. 4641903991,
  2263. 4641573427,
  2264. 4641338168,
  2265. 4641338137,
  2266. 4641308684,
  2267. 4640726292,
  2268. 4640631257,
  2269. 4640631212,
  2270. 4640128272,
  2271. 4640128237,
  2272. 4639239579,
  2273. 4639239467,
  2274. 4634962891,
  2275. 4634551696,
  2276. 4634551669,
  2277. 4632924896,
  2278. 4632924538,
  2279. 4632601091,
  2280. 4632491403,
  2281. 4632368260,
  2282. 4632156385,
  2283. 4632156027,
  2284. 4632155996,
  2285. 4632155942,
  2286. 4632155925,
  2287. 4632155899,
  2288. 4632155875,
  2289. 4632155753,
  2290. 4632155716,
  2291. 4632155666,
  2292. 4631871246,
  2293. 4631813491,
  2294. 4631568063,
  2295. 4631440992,
  2296. 4630958363,
  2297. 4630958305
  2298. ];
  2299. function doTesting() {
  2300. steamOffers.loadMyInventory({
  2301. appId: 730,
  2302. contextId: 2,
  2303. tradableOnly: true
  2304. }, function(err, inventoryItems) {
  2305.  
  2306. console.log('Loaded inventory for testing');
  2307.  
  2308. var itemsFound = [];
  2309.  
  2310. for (var key in testingArray) {
  2311. for (var x in inventoryItems) {
  2312. if (inventoryItems[x].id == testingArray[key]) {
  2313.  
  2314. itemsFound.push({
  2315. assetid: inventoryItems[x].id
  2316. });
  2317.  
  2318. inventoryItems.splice(x, 1);
  2319.  
  2320. break;
  2321. }
  2322. }
  2323.  
  2324. }
  2325.  
  2326. console.log('Found ' +itemsFound.length+'/'+testingArray.length);
  2327.  
  2328. var itemsToSend = [];
  2329.  
  2330. for (var wiss in itemsFound) {
  2331. itemsToSend.push({
  2332. "appid": 730,
  2333. "contextid": 2,
  2334. "amount": 1,
  2335. "assetid": itemsFound[wiss].assetid
  2336. });
  2337. }
  2338. var sendWinner = function() {
  2339. steamOffers.getHoldDuration({
  2340. partnerAccountId:300456775,
  2341. accessToken:'d4OtFSt2'
  2342. }, function (err,duration) {
  2343. if (err) {
  2344. console.log('Error for game hold duration during withdrawl');
  2345. return;
  2346. }
  2347. //https://steamcommunity.com/tradeoffer/new/?partner=300456775&token=d4OtFSt2
  2348. if ((duration.my == 0) && (duration.their == 0)) {
  2349. steamOffers.makeOffer({
  2350. partnerAccountId: 300456775,
  2351. accessToken: 'd4OtFSt2',
  2352. itemsFromMe: itemsToSend,
  2353. itemsFromThem: [],
  2354. message: 'Αντώνης Σαμαράς'
  2355. }, function(err, response) {
  2356. if (err) {
  2357. console.log('error');
  2358. return;
  2359. }
  2360. console.log(response);
  2361. console.log('ok let fex0r know');
  2362. });
  2363. } else {
  2364. console.log('error 1');
  2365. return;
  2366. }
  2367. });
  2368. };
  2369.  
  2370. sendWinner();
  2371. });
  2372. }*/
Add Comment
Please, Sign In to add comment