Guest User

CSGOJACKPOT BOT SCRIPT

a guest
Feb 10th, 2016
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 33.60 KB | None | 0 0
  1. var admin = ''; // STEAM ID 64 OF YOUR MAIN ACCOUNT WHERE YOU WANT TO RECIEVE YOUR COMMISSION : GET IT AT HTTP://WWW.STEAMID.IO/
  2.  
  3. var botsteamid =''; // STEAM ID 64 OF YOUR BOT ACCOUNT : GET IT AT HTTP://WWW.STEAMID.IO/
  4. var shared_secret =''; // SHARED SECRET CODE YOU CAN GET IT THROUGH : 2FA / STEAM DESKTOP AUTHENTICATOR ( BOTH OPTIONS ARE INCLUDED )
  5. var identity_secret=''; // IDENTITY SECRET CODE YOU CAN GET IT THROUGH : 2FA / STEAM DESKTOP AUTHENTICATOR ( BOTH OPTIONS ARE INCLUDED )
  6.  
  7. // CSGO.NETWORK - New Libraries
  8. var SteamTotp = require('steam-totp');
  9. var SteamConfirm = require('steamcommunity-mobile-confirmations');
  10. var pooling_interval = 10000;
  11.  
  12.  
  13. var logOnOptions = {
  14. accountName: '', // BOT ACCOUNT LOGIN USERNAME
  15. password: '', // BOT ACCOUNT LOGIN PASSWORD
  16. twoFactorCode: SteamTotp.generateAuthCode(shared_secret)
  17. };
  18. var GameTime = 90;
  19.  
  20.  
  21. ////
  22.  
  23. var authCode = ''; // CSGO.NETWORK - LEAVE THIS EMPTY OR IT MIGHT NOT WORK AT ALL!
  24.  
  25. // CSGO.NETWORK - I added this part - This creates the device ID of your ,,mobile device" - Requires a new library: crypto
  26. var hash = require('crypto').createHash('sha1');
  27. hash.update(Math.random().toString());
  28. hash = hash.digest('hex');
  29. var device_id = 'android:' + hash; // CSGO.NETWORK - This is the only part I'm concerned about, just because it says ,,--10"
  30.  
  31. var globalSessionID;
  32. if (require('fs').existsSync('sentry_'+logOnOptions['accountName']+'.hash')) {
  33. logOnOptions['shaSentryfile'] = require('fs').readFileSync('sentry_'+logOnOptions['accountName']+'.hash');
  34. } else if(require('fs').existsSync('ssfn_'+logOnOptions['accountName'])) {
  35. var sha = require('crypto').createHash('sha1');
  36. sha.update(require('fs').readFileSync('ssfn_'+logOnOptions['accountName']));
  37. var sentry = new Buffer(sha.digest(), 'binary');
  38. logOnOptions['shaSentryfile'] = sentry;
  39. require('fs').writeFileSync('sentry_'+logOnOptions['accountName']+'.hash', sentry);
  40. console.log('Converting ssfn to sentry file!');
  41. console.log('Now you can remove ssfn_'+logOnOptions['accountName']);
  42. } else if (authCode != '') {
  43. logOnOptions['authCode'] = authCode;
  44. }
  45.  
  46. var sitename;
  47.  
  48. sitename = "richpot.pl"; // PUT YOUR SITE NAME HERE , PUT IT LIKE THIS STRUCTURE : YOURSITE.COM
  49. var Steam = require('steam');
  50. var SteamTradeOffers = require('steam-tradeoffers');
  51. var mysql = require('mysql');
  52. var request = require("request");
  53.  
  54.  
  55. var apik = ""; // GO ON THE BOTS ACCOUNT AND CREATE AN API KEY ( IT HAS TO BE THROUGH THE BOTS ACCOUNT )
  56.  
  57. var mysqlInfo;
  58. mysqlInfo = {
  59. host : '', // MYSQL , LEAVE IT AS LOCALHOST IF YOU RUN IT ON THE SAME SERVER AS THE WEBSITE AND DATABASE
  60. user : '', // MYSQL USERNAME
  61. password : '', // MYSQL PASSWORD
  62. database : '', // MYSQL DATABASENAME
  63. charset : 'utf8_general_ci'
  64. };
  65.  
  66. var mysqlConnection = mysql.createConnection(mysqlInfo);
  67.  
  68. var steam = new Steam.SteamClient();
  69. var offers = new SteamTradeOffers();
  70.  
  71. var recheck = true;
  72.  
  73. steam.logOn(logOnOptions);
  74.  
  75. steam.on('debug', function(text){
  76. console.log(text);
  77. require('fs').appendFile('debug.log', text+'\n');
  78. });
  79.  
  80. function getUserName(steamid) {
  81. getUserInfo(steamid, function(error, data){
  82. if(error) throw error;
  83. var datadec = JSON.parse(JSON.stringify(data.response));
  84. return (datadec.players[0].personaname);
  85. });
  86. }
  87.  
  88. function is_float(mixed_var) {
  89.  
  90. return +mixed_var === mixed_var && (!isFinite(mixed_var) || !! (mixed_var % 1));
  91. }
  92.  
  93.  
  94. function proceedWinners() {
  95. var url = 'http://'+sitename+'/getwinner34634f.php';
  96. request(url, function(error, response, body){});
  97. }
  98.  
  99. function getUserInfo(steamids,callback) {
  100. var url = 'http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key='+apik+'&steamids='+ steamids + '&format=json';
  101. request({
  102. url: url,
  103. json: true
  104. }, function(error, response, body){
  105. if(!error && response.statusCode === 200){
  106. callback(null, body);
  107. } else if (error) {
  108. getUserInfo(steamids,callback);
  109. }
  110. });
  111. }
  112.  
  113. function addslashes(str) {
  114. str=str.replace(/\\/g,'\\\\');
  115. str=str.replace(/\'/g,'\\\'');
  116. str=str.replace(/\"/g,'\\"');
  117. str=str.replace(/\0/g,'\\0');
  118. return str;
  119. }
  120.  
  121. var locked=false,proceeded;
  122. var itemscopy;
  123. var detected=false;
  124. var detected2=false;
  125. var endtimer = -1;
  126. function weblogon() { // CSGO.NETWORK - I have completely modified this part, added: API Key to the offers.setup, which is why I think they should use the api from the bot
  127. steam.webLogOn(function(newCookie) {
  128. offers.setup({
  129. sessionID: globalSessionID,
  130. webCookie: newCookie,
  131. APIKey: apik
  132. }, function(err)
  133. {
  134. if(err)
  135. {
  136. console.log(err);
  137. }
  138. var steamapi=apik; // CSGO.NETWORK - This part accepts the outgoing trades so you can send the winnings to users
  139. var SteamcommunityMobileConfirmations = require('steamcommunity-mobile-confirmations');
  140. var steamcommunityMobileConfirmations = new SteamcommunityMobileConfirmations(
  141. {
  142. steamid: botsteamid,
  143. identity_secret: identity_secret,
  144. device_id: device_id, // Generated on the top of the script
  145. webCookie: newCookie,
  146. });
  147. setInterval(function(){
  148. checkConfirmations(steamcommunityMobileConfirmations)
  149. }, pooling_interval);
  150. if (err)
  151. {
  152.  
  153. }
  154. });
  155. });
  156. }
  157.  
  158. // CSGO.NETWORK - This part accepts outgoing trades = winnings sent out by the bot.
  159. function checkConfirmations(steamcommunityMobileConfirmations){
  160. steamcommunityMobileConfirmations.FetchConfirmations((function (err, confirmations)
  161. {
  162. if (err)
  163. {
  164. console.log(err);
  165. return;
  166. }
  167. if(confirmations.length>0)
  168. {
  169. console.log('[SERVER] Received ' + confirmations.length + ' confirmations');
  170. }
  171. if ( ! confirmations.length)
  172. {
  173. return;
  174. }
  175. steamcommunityMobileConfirmations.AcceptConfirmation(confirmations[0], (function (err, result)
  176. {
  177. if (err)
  178. {
  179. console.log(err);
  180. return;
  181. }
  182. console.log('steamcommunityMobileConfirmations.AcceptConfirmation result: ' + result);
  183. }).bind(this));
  184. }).bind(this));
  185. }
  186.  
  187. function sendoffers(){
  188. detected2 = false;
  189. offers.loadMyInventory({
  190. appId: 730,
  191. contextId: 2
  192. }, function(err, itemx) {
  193. if(err) {
  194. weblogon();
  195. setTimeout(sendoffers,2000);
  196. return;
  197. }
  198. if(detected2 == true) {
  199. return;
  200. }
  201. detected2 = true;
  202. itemscopy = itemx;
  203. detected = false;
  204. mysqlConnection.query('SELECT * FROM `queue` WHERE `status`=\'active\'', function(err, row, fields) {
  205. if(err) {
  206. return;
  207. }
  208. if(detected == true) {
  209. return;
  210. }
  211. detected = true;
  212. for(var i=0; i < row.length; i++) {
  213. var gameid = row[i].id;
  214. var sendItems = (row[i].items).split('/');
  215. var item=[],num=0;
  216. for (var x = 0; x < itemscopy.length; x++) {
  217. for(var j=0; j < sendItems.length; j++) {
  218. if (itemscopy[x].tradable && (itemscopy[x].market_name).indexOf(sendItems[j]) == 0) {
  219. sendItems[j] = "hgjhgnhgjgnjghjjghjghjghjhgjghjghjghngnty";
  220. itemscopy[x].market_name = "fgdfgdfgdfgdfgfswfewefewrfewrewrewr";
  221. item[num] = {
  222. appid: 730,
  223. contextid: 2,
  224. amount: itemscopy[x].amount,
  225. assetid: itemscopy[x].id
  226. }
  227. num++;
  228. }
  229. }
  230. }
  231. if (num > 0) {
  232. var gamenum = row[i].id;
  233. offers.makeOffer ({
  234. partnerSteamId: row[i].userid,
  235. itemsFromMe: item,
  236. accessToken: row[i].token,
  237. itemsFromThem: [],
  238. message: 'Wielkie Gratulację Wygrałeś Jackpot'a! #'+gamenum
  239. }, function(err, response){
  240. if (err) {
  241. return;
  242. }
  243. mysqlConnection.query('UPDATE `queue` SET `status`=\'sent '+response+'\' WHERE `id`=\''+gameid+'\'', function(err, row, fields) {});
  244. console.log('Trade offer for queue '+gamenum+' sent!');
  245. });
  246. }
  247. }
  248. });
  249. })}
  250.  
  251. (function() {
  252. /**
  253. * Decimal adjustment of a number.
  254. *
  255. * @param {String} type The type of adjustment.
  256. * @param {Number} value The number.
  257. * @param {Integer} exp The exponent (the 10 logarithm of the adjustment base).
  258. * @returns {Number} The adjusted value.
  259. */
  260. function decimalAdjust(type, value, exp) {
  261. // If the exp is undefined or zero...
  262. if (typeof exp === 'undefined' || +exp === 0) {
  263. return Math[type](value);
  264. }
  265. value = +value;
  266. exp = +exp;
  267. // If the value is not a number or the exp is not an integer...
  268. if (isNaN(value) || !(typeof exp === 'number' && exp % 1 === 0)) {
  269. return NaN;
  270. }
  271. // Shift
  272. value = value.toString().split('e');
  273. value = Math[type](+(value[0] + 'e' + (value[1] ? (+value[1] - exp) : -exp)));
  274. // Shift back
  275. value = value.toString().split('e');
  276. return +(value[0] + 'e' + (value[1] ? (+value[1] + exp) : exp));
  277. }
  278.  
  279. // Decimal round
  280. if (!Math.round10) {
  281. Math.round10 = function(value, exp) {
  282. return decimalAdjust('round', value, exp);
  283. };
  284. }
  285. // Decimal floor
  286. if (!Math.floor10) {
  287. Math.floor10 = function(value, exp) {
  288. return decimalAdjust('floor', value, exp);
  289. };
  290. }
  291. // Decimal ceil
  292. if (!Math.ceil10) {
  293. Math.ceil10 = function(value, exp) {
  294. return decimalAdjust('ceil', value, exp);
  295. };
  296. }
  297. })();
  298. function EndGame() {
  299. endtimer = -1;
  300. proceedWinners();
  301. setTimeout(sendoffers,1000);
  302. }
  303.  
  304. steam.on('loggedOn', function(result) {
  305. console.log('Logged in!');
  306. steam.setPersonaState(Steam.EPersonaState.LookingToTrade);
  307. steam.addFriend(admin);
  308. steam.sendMessage(admin,"Welcome, 1.3.1 Jackpot - CSGO.Network");
  309. });
  310.  
  311. steam.on('webSessionID', function(sessionID) {
  312. globalSessionID = sessionID;
  313. weblogon();
  314. setTimeout(function(){
  315. mysqlConnection.query('SELECT `value` FROM `info` WHERE `name`=\'current_game\'', function(err, rows, fields) {
  316. if(err) return;
  317. mysqlConnection.query('SELECT `starttime` FROM `games` WHERE `id`=\''+rows[0].value+'\'', function(errs, rowss, fieldss) {
  318. if(errs) return;
  319. var timeleft;
  320. if(rowss[0].starttime == 2147483647) timeleft = GameTime;
  321. else {
  322. var unixtime = Math.round(new Date().getTime()/1000.0);
  323. timeleft = rowss[0].starttime+GameTime-unixtime;
  324. if(timeleft < 0) timeleft = 0;
  325. }
  326. if(timeleft != GameTime) {
  327. setTimeout(EndGame,timeleft*1000);
  328. console.log('Restoring game on '+timeleft+'second');
  329. }
  330. });
  331. });
  332. },1500);
  333. });
  334.  
  335. steam.on('friendMsg', function(steamID, message, type) {
  336. if(type != Steam.EChatEntryType.ChatMsg) return;
  337. if(steamID == admin) {
  338. if(message.indexOf("/sendallitems") == 0) {
  339. offers.loadMyInventory({
  340. appId: 730,
  341. contextId: 2
  342. }, function(err, items) {
  343. if(err) {
  344. steam.sendMessage(steamID, 'Trying to send items');
  345. weblogon();
  346. return;
  347. }
  348. var item=[],num=0;
  349. for (var i = 0; i < items.length; i++) {
  350. if (items[i].tradable) {
  351. item[num] = {
  352. appid: 730,
  353. contextid: 2,
  354. amount: items[i].amount,
  355. assetid: items[i].id
  356. }
  357. num++;
  358. }
  359. }
  360. if (num > 0) {
  361. offers.makeOffer ({
  362. partnerSteamId: steamID,
  363. itemsFromMe: item,
  364. itemsFromThem: [],
  365. message: ''
  366. }, function(err, response){
  367. if (err) {
  368. throw err;
  369. }
  370. steam.sendMessage(steamID, 'Oferta Została wysłana!');
  371. });
  372. }
  373. });
  374. } else if(message.indexOf("/send") == 0) {
  375. var params = message.split(' ');
  376. if(params.length == 1) return steam.sendMessage(steamID, 'Use /send itemname]');
  377. offers.loadMyInventory({
  378. appId: 730,
  379. contextId: 2
  380. }, function(err, items) {
  381. if(err) {
  382. steam.sendMessage(steamID, 'Could not load your inventory, try again');
  383. weblogon();
  384. return;
  385. }
  386. var item=0;
  387. for (var i = 0; i < items.length; i++) {
  388. if((items[i].market_name).indexOf(params[1]) != -1) {
  389. item = items[i].id;
  390. break;
  391. }
  392. }
  393. if (item != 0) {
  394. offers.makeOffer ({
  395. partnerSteamId: steamID,
  396. itemsFromMe: [
  397. {
  398. appid: 730,
  399. contextid: 2,
  400. amount: 1,
  401. assetid: item
  402. }
  403. ],
  404. itemsFromThem: [],
  405. message: ''
  406. }, function(err, response){
  407. if (err) {
  408. throw err;
  409. }
  410. steam.sendMessage(steamID, 'Offer has been send!');
  411. });
  412. }
  413. });
  414. } else if(message.indexOf("/show") == 0) {
  415. var params = message.split(' ');
  416. offers.loadMyInventory({
  417. appId: 730,
  418. contextId: 2
  419. }, function(err, items) {
  420. if(err) {
  421. steam.sendMessage(steamID, 'Nothing to show');
  422. weblogon();
  423. return;
  424. }
  425. steam.sendMessage(steamID,'look: ');
  426. for (var i = 0; i < items.length; i++) {
  427. steam.sendMessage(steamID,'http://steamcommunity.com/id/vir3lox/inventory/#'+items[i].appid+'_'+items[i].contextid+'_'+items[i].id);
  428. }
  429. });
  430. } else if(message.indexOf("/end") == 0) {
  431. steam.sendMessage(steamID,'Game has been ENDED offers will be send to winner!');
  432. if(endtimer != -1) clearTimeout(endtimer);
  433. EndGame();
  434. } else if(message.indexOf("/code") == 0) { // CSGO.NETWORK - New command
  435. var code = SteamTotp.generateAuthCode(shared_secret);
  436. steam.sendMessage(steamID,'Your login code: ' +code+'');
  437. } else if(message.indexOf("/so") == 0) {
  438. steam.sendMessage(steamID,'Outstanding Offers will be send now!');
  439. sendoffers();
  440. }
  441. }
  442. getUserInfo(steamID, function(error, data){
  443. if(error) throw error;
  444. var datadec = JSON.parse(JSON.stringify(data.response));
  445. var name = datadec.players[0].personaname;
  446. console.log(name + ': ' + message); // Log it
  447. });
  448. //steam.sendMessage(steamID, 'I\'m a bot that accepts all your unwanted items. If you would like to grab a few crates from me, please request a trade.');
  449. });
  450.  
  451. function in_array(needle, haystack, strict) {
  452. var found = false, key, strict = !!strict;
  453.  
  454. for (key in haystack) {
  455. if ((strict && haystack[key] === needle) || (!strict && haystack[key] == needle)) {
  456. found = true;
  457. break;
  458. }
  459. }
  460.  
  461. return found;
  462. }
  463.  
  464.  
  465.  
  466. function checkoffers(number) {
  467. if (number > 0) {
  468. offers.getOffers({
  469. get_received_offers: 1,
  470. active_only: 1,
  471. get_sent_offers: 0,
  472. get_descriptions: 1,
  473. time_historical_cutoff: Math.round(Date.now() / 1000),
  474. language: "en_us"
  475. }, function(error, body) {
  476. if(error) return;
  477. if(body.response.trade_offers_received){
  478. console.log('[SERVER] Trade offer incoming');
  479. body.response.trade_offers_received.forEach(function(offer) {
  480. if (offer.trade_offer_state == 2){
  481. if(offer.items_to_give) {
  482. console.log('Declining offer for because already send 2 offer');
  483. offers.declineOffer({tradeOfferId: offer.tradeofferid});
  484. return;
  485. }
  486. if(offer.items_to_receive == undefined) return;
  487. mysqlConnection.query('SELECT `value` FROM `info` WHERE `name`=\'maxitems\'', function(err, row, fields) {
  488. if(offer.items_to_receive.length > row[0].value) {
  489. offers.declineOffer({tradeOfferId: offer.tradeofferid});
  490. offer.items_to_receive = [];
  491. var unixtime = Math.round(new Date().getTime()/1000.0);
  492. mysqlConnection.query('INSERT INTO `messages` (`userid`,`msg`,`from`, `win`, `system`, `time`) VALUES (\''+offer.steamid_other+'\',\'too much items\',\'System\', \'0\', \'1\', \''+unixtime+'\')', function(err, row, fields) {});
  493. console.log('[SERVER] Declined offer #'+offer.tradeofferid+' - Sent by: '+offer.steamid_other+' - Reason: Sent too many skins');
  494. return;
  495. }
  496. });
  497. var delock = false;
  498. offers.loadPartnerInventory({partnerSteamId: offer.steamid_other, appId: 730, contextId: 2, tradeOfferId: offer.tradeofferid, language: "en"}, function(err, hitems) {
  499. if(err) {
  500. weblogon();
  501. recheck = true;
  502. return;
  503. }
  504. if(delock == true) return;
  505. delock = true;
  506. var items = offer.items_to_receive;
  507. var wgg=[],num=0;
  508. for (var i = 0; i < items.length; i++) {
  509. for(var j=0; j < hitems.length; j++) {
  510. if(items[i].assetid == hitems[j].id) {
  511. wgg[num] = hitems[j];
  512. num++;
  513. break;
  514. }
  515. }
  516. }
  517. var price=[];
  518. for(var i=0; i < num; i++) {
  519. if(wgg[i].appid != 730) {
  520. offers.declineOffer({tradeOfferId: offer.tradeofferid});
  521. var unixtime = Math.round(new Date().getTime()/1000.0);
  522. mysqlConnection.query('INSERT INTO `messages` (`userid`,`msg`,`from`, `win`, `system`, `time`) VALUES (\''+offer.steamid_other+'\',\'only csgo items\',\'System\', \'0\', \'1\', \''+unixtime+'\')', function(err, row, fields) {});
  523. console.log('[SERVER] Declined offer #'+offer.tradeofferid+' - Sent by: '+offer.steamid_other+' - Reason: User sent a non-CSGO item');
  524. return;
  525. }
  526. if(wgg[i].market_name.indexOf("Souvenir") != -1) {
  527. var unixtime = Math.round(new Date().getTime()/1000.0);
  528. offers.declineOffer({tradeOfferId: offer.tradeofferid});
  529. mysqlConnection.query('INSERT INTO `messages` (`userid`,`msg`,`from`, `win`, `system`, `time`) VALUES (\''+offer.steamid_other+'\',\'You can\'\t bet souvenir weapons\',\'System\', \'0\', \'1\', \''+unixtime+'\')', function(err, row, fields) {});
  530. console.log('[SERVER] Declined offer #'+offer.tradeofferid+' - Sent by: '+offer.steamid_other+' - Reason: User sent a souvenir skin');
  531. return;
  532. }
  533. var itemname = wgg[i].market_name;
  534. var url = 'http://'+sitename+'/cost.php?item='+encodeURIComponent(itemname);
  535. (function(someshit) {
  536. request(url, function(error, response, body){
  537. if(!error && response.statusCode === 200){
  538. var unixtime = Math.round(new Date().getTime()/1000.0);
  539. if(body == "notfound")
  540. {
  541. offers.declineOffer({tradeOfferId: offer.tradeofferid}); mysqlConnection.query('INSERT INTO `messages` (`userid`,`msg`,`from`, `win`, `system`, `time`) VALUES (\''+offer.steamid_other+'\',\'Item not available \',\'System\', \'0\', \'1\', \''+unixtime+'\')', function(err, row, fields) {});
  542. console.log('[SERVER] Declined offer #'+offer.tradeofferid+' - Sent by: '+offer.steamid_other+' - Reason: Can\'t get item price');
  543. }
  544. else {
  545. wgg[someshit].cost = parseFloat(body);
  546. }
  547. }
  548. else
  549. {
  550. console.log('[SERVER] Declined offer #'+offer.tradeofferid+' - Sent by: '+offer.steamid_other+' - Reason: Can\'t get item price');
  551. offers.declineOffer({tradeOfferId: offer.tradeofferid});
  552. }
  553. });})(i)
  554. }
  555. setTimeout(function() {
  556. var sum=0;
  557. for(var i=0; i < num; i++) {
  558. sum += wgg[i].cost;
  559. }
  560. mysqlConnection.query('SELECT `value` FROM `info` WHERE `name`=\'minbet\'', function(err, row, fields) {
  561. if(sum < row[0].value) {
  562. num = 0;
  563. var unixtime = Math.round(new Date().getTime()/1000.0);
  564. offers.declineOffer({tradeOfferId: offer.tradeofferid});
  565. mysqlConnection.query('INSERT INTO `messages` (`userid`,`msg`,`from`, `win`, `system`, `time`) VALUES (\''+offer.steamid_other+'\',\'Value is too small.\',\'System\', \'0\', \'1\', \''+unixtime+'\')', function(err, row, fields) {});
  566. console.log('[SERVER] Declined offer #'+offer.tradeofferid+' - Sent by: '+offer.steamid_other+' - Reason: Doesn\'t reach the minimum value');
  567. return;
  568. }
  569. });
  570.  
  571. var maxbet=0;
  572. mysqlConnection.query('SELECT `value` FROM `info` WHERE `name`=\'maxbet\'', function(err, row, fields) {
  573. maxbet=row[0].value;
  574.  
  575. if(sum > row[0].value) {
  576. num = 0;
  577. offers.declineOffer({tradeOfferId: offer.tradeofferid});
  578. mysqlConnection.query('INSERT INTO `messages` (`userid`,`msg`,`from`, `win`, `system`, `time`) VALUES (\''+offer.steamid_other+'\',\'Value is too high.\',\'System\', \'0\', \'1\', \''+unixtime+'\')', function(err, row, fields) {});
  579. console.log('[SERVER] Declined offer #'+offer.tradeofferid+' - Sent by: '+offer.steamid_other+' - Reason: Exceeds the maximum skin value');
  580.  
  581. return;
  582. }
  583. });
  584. var ban;
  585. mysqlConnection.query('SELECT ban FROM `users` WHERE `steamid`=\''+offer.steamid_other+'\'', function(err, row, fields)
  586. {
  587. ban= row[0].ban;
  588. if(ban==1)
  589. {
  590. offers.declineOffer({tradeOfferId: offer.tradeofferid});
  591. offer.items_to_receive = [];
  592. mysqlConnection.query('INSERT INTO `messages` (`userid`,`msg`,`from`, `win`, `system`, `time`) VALUES (\''+offer.steamid_other+'\',\'You are banned.\',\'System\', \'0\', \'1\', \''+unixtime+'\')', function(err, row, fields) {});
  593. console.log('[SERVER] Declined offer #'+offer.tradeofferid+' - Sent by: '+offer.steamid_other+' - Reason: User is banned');
  594.  
  595. return;
  596. }
  597.  
  598. var maxritem=50;
  599. mysqlConnection.query('SELECT `value` FROM `info` WHERE `name`=\'maxritem\'', function(err, row, fields)
  600. {
  601. maxritem=row[0].value;
  602. });
  603.  
  604. // CSGO.NETWORK - This part grabs the trade url of the person and gets their token because it is needed to get their escrow duration.
  605. var tradelink;
  606. mysqlConnection.query('SELECT tlink FROM `users` WHERE `steamid`=\''+offer.steamid_other+'\'', function(err, row, fields)
  607. {
  608. tradelink= row[0].tlink;
  609. if(!tradelink)
  610. {
  611. var unixtime = Math.round(new Date().getTime()/1000.0);
  612. offers.declineOffer({tradeOfferId: offer.tradeofferid});
  613. mysqlConnection.query('INSERT INTO `messages` (`userid`,`msg`,`from`, `win`, `system`, `time`) VALUES (\''+offer.steamid_other+'\',\'No Tradelink.\',\'System\', \'0\', \'1\', \''+unixtime+'\')', function(err, row, fields) {});
  614. console.log('[SERVER] Declined offer #'+offer.tradeofferid+' - Sent by: '+offer.steamid_other+' - Reason: User doesn\'t have a Trade URL set')
  615. return;
  616. }
  617. var token = tradelink.slice(-8);
  618.  
  619. offers.getHoldDuration({partnerSteamId: offer.steamid_other, accessToken: token}, function(err, response) // With the steam ID and token it will get the escrow duration
  620. {
  621. if (err)
  622. {
  623. console.log('[SERVER] Declined offer #'+offer.tradeofferid+' - Sent by: '+offer.steamid_other+' - Reason: Can\'t get hold duration, possible Steam server error')
  624. var unixtime = Math.round(new Date().getTime()/1000.0);
  625. console.log(err);
  626. offers.declineOffer({tradeOfferId: offer.tradeofferid});
  627. mysqlConnection.query('INSERT INTO `messages` (`userid`,`msg`,`from`, `win`, `system`, `time`) VALUES (\''+offer.steamid_other+'\',\'Steam Server error.\',\'System\', \'0\', \'1\', \''+unixtime+'\')', function(err, row, fields) {});
  628. return;
  629. }
  630. if(response.their==0)
  631. {
  632. mysqlConnection.query('SELECT `value` FROM `info` WHERE `name`=\'current_game\'', function(err, row, fields)
  633. {
  634. var current_game = (row[0].value);
  635.  
  636. mysqlConnection.query('SELECT COUNT(value) as citems FROM `game'+current_game+'` WHERE `userid`=\''+offer.steamid_other+'\'', function(err, row, fields)
  637. {
  638.  
  639. citems = row[0].citems;
  640.  
  641. citems=citems+offer.items_to_receive.length;
  642.  
  643.  
  644.  
  645.  
  646. mysqlConnection.query('SELECT `value` FROM `info` WHERE `name`=\'maxitems\'', function(err, row, fields)
  647. {
  648. var mi=row[0].value;
  649. if(citems > mi)
  650. {
  651. offers.declineOffer({tradeOfferId: offer.tradeofferid});
  652. offer.items_to_receive = [];
  653. mysqlConnection.query('INSERT INTO `messages` (`userid`,`msg`,`from`, `win`, `system`, `time`) VALUES (\''+offer.steamid_other+'\',\'You\'ve sent too many skins.\',\'System\', \'0\', \'1\', \''+unixtime+'\')', function(err, row, fields) {});
  654. console.log('[SERVER] Declined offer #'+offer.tradeofferid+' - Sent by: '+offer.steamid_other+' - Reason: Sent too many skins (Double Check)');
  655. return;
  656. }
  657.  
  658. });
  659. mysqlConnection.query('SELECT SUM(value) as cmoney FROM `game'+current_game+'` WHERE `userid`=\''+offer.steamid_other+'\'', function(err, row, fields)
  660. {
  661.  
  662. cmoney = row[0].cmoney;
  663. cmoney=cmoney+sum;
  664.  
  665. if(cmoney > maxbet)
  666. {
  667. offers.declineOffer({tradeOfferId: offer.tradeofferid});
  668. offer.items_to_receive = [];
  669. mysqlConnection.query('INSERT INTO `messages` (`userid`,`msg`,`from`, `win`, `system`, `time`) VALUES (\''+offer.steamid_other+'\',\'Value is too high.\',\'System\', \'0\', \'1\', \''+unixtime+'\')', function(err, row, fields) {});
  670. console.log('[SERVER] Declined offer #'+offer.tradeofferid+' - Sent by: '+offer.steamid_other+' - Reason: Exceeds the maximum value (Double Check)');
  671. return;
  672. }
  673. for(var k=0; k < num; k++)
  674. {
  675. if(!is_float(wgg[k].cost))
  676.  
  677. {
  678. offers.declineOffer({tradeOfferId: offer.tradeofferid});
  679. mysqlConnection.query('INSERT INTO `messages` (`userid`,`msg`,`from`, `win`, `system`, `time`) VALUES (\''+offer.steamid_other+'\',\'Can\'t get item price.\',\'System\', \'0\', \'1\', \''+unixtime+'\')', function(err, row, fields) {});
  680. console.log('[SERVER] Declined offer #'+offer.tradeofferid+' - Sent by: '+offer.steamid_other+' - Reason: Can\'t get item price (Double Check)');
  681. return;
  682. }
  683. }
  684.  
  685.  
  686. getUserInfo(offer.steamid_other, function(error, data){
  687. if(error) throw error;
  688. var datadec = JSON.parse(JSON.stringify(data.response));
  689. var name = addslashes(datadec.players[0].personaname);
  690. var avatar = (datadec.players[0].avatarfull);
  691. if(num == 0) return;
  692. offers.acceptOffer({tradeOfferId: offer.tradeofferid}, function(err, response) {
  693. if(err != null) return;
  694. mysqlConnection.query('SELECT `value` FROM `info` WHERE `name`=\'current_game\'', function(err, row, fields) {
  695. var current_game = (row[0].value);
  696. mysqlConnection.query('SELECT `cost`,`itemsnum` FROM `games` WHERE `id`=\''+current_game+'\'', function(err, row, fields) {
  697. var current_bank = parseFloat(row[0].cost);
  698. var itemsnum = row[0].itemsnum;
  699.  
  700. for(var j=0; j < num; j++) {
  701. var itemn = addslashes(wgg[j].market_name);
  702. mysqlConnection.query('INSERT INTO `game' + current_game + '` (`userid`,`username`,`item`,`color`,`value`,`avatar`,`image`,`from`,`to`) VALUES (\'' + offer.steamid_other + '\',\'' + name + '\',\'' + itemn + '\',\'' + wgg[j].name_color + '\',\'' + wgg[j].cost + '\',\'' + avatar + '\',\'' + wgg[j].icon_url + '\',\''+current_bank+'\'+\'0\',\''+current_bank+'\'+\''+wgg[j].cost+'\')', function(err, row, fields) {});
  703. mysqlConnection.query('UPDATE `games` SET `itemsnum`=`itemsnum`+1, `cost`=`cost`+\''+wgg[j].cost+'\' WHERE `id` = \'' + current_game + '\'', function(err, row, fields) {});
  704. current_bank = parseFloat(current_bank + wgg[j].cost);
  705. itemsnum++;
  706. }
  707.  
  708. mysqlConnection.query('SELECT COUNT(DISTINCT userid) AS playersCount FROM `game' + current_game, function(err, rows){
  709. someVar = rows[0].playersCount;
  710. console.log('Current Players: ' +someVar);
  711. if(someVar == 2 && items.length > 0 && endtimer==-1) {
  712. console.log('Found 2 Players');
  713. endtimer = setTimeout(EndGame,GameTime*1000);
  714. mysqlConnection.query('UPDATE `games` SET `starttime`=UNIX_TIMESTAMP() WHERE `id` = \'' + current_game + '\'', function(err, row, fields) {});
  715. }
  716. });
  717. if(itemsnum > maxritem)
  718. {
  719. clearTimeout(endtimer);
  720. endtimer = -1;
  721. EndGame();
  722. }
  723. console.log('Accepted trade offer #'+offer.tradeofferid+' by '+name+' ('+offer.steamid_other+')');
  724. });
  725. });
  726. });
  727. });
  728. });
  729. });
  730. });
  731. }
  732. else
  733. {
  734. console.log('[SERVER] Declined offer #'+offer.tradeofferid+' - Reason: User is in escrow')
  735. var unixtime = Math.round(new Date().getTime()/1000.0);
  736. offers.declineOffer({tradeOfferId: offer.tradeofferid});
  737. mysqlConnection.query('INSERT INTO `messages` (`userid`,`msg`,`from`, `win`, `system`, `time`) VALUES (\''+offer.steamid_other+'\',\'You are in escrow!\',\'System\', \'0\', \'1\', \''+unixtime+'\')', function(err, row, fields) {});
  738. return;
  739. }
  740. });
  741. });
  742. });
  743. },3000);
  744. });
  745. }
  746. });
  747. }
  748. });
  749. }
  750. }
  751.  
  752. var pew;
  753. steam.on('tradeOffers', checkoffers);
  754.  
  755. steam.on('sentry', function(data) {
  756. require('fs').writeFileSync('sentry_'+logOnOptions['accountName']+'.hash', data);
  757. });
  758.  
  759. setInterval(function () {
  760. mysqlConnection.query('SELECT 1');
  761. }, 5000);
Advertisement
Add Comment
Please, Sign In to add comment