Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2016
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 33.86 KB | None | 0 0
  1. /*
  2. _____ _ _ ___ __ __
  3. / ____| | || | / _ \ / //_ |
  4. | | __ ___ _ __ __ _ ___| || || (_) |/ /_ | |
  5. | | |_ |/ _ \ '__/ _` |/ _ \__ _\__, | '_ \| |
  6. | |__| | __/ | | (_| | (_) | | | / /| (_) | |
  7. \_____|\___|_| \__, |\___/ |_| /_/ \___/|_|
  8. __/ |
  9. |___/
  10.  
  11.  
  12. The CSGO.Network V2 bot was made by Gregory Steam (Gergo4961) and is the property of CSGO.Network.
  13. If you need any special site/bot customization you can reach me on Steam!
  14.  
  15. Please note that I do not provide support for CSGO.Network.
  16.  
  17. http://steamcommunity.com/id/gergo4961/
  18.  
  19. */
  20.  
  21. var Steam = require('steam');
  22. var SteamUser = require('steam-user');
  23. var TradeOfferManager = require('steam-tradeoffer-manager');
  24. var SteamTotp = require('steam-totp');
  25. var SteamConfirm = require('steamcommunity-mobile-confirmations');
  26. var TOTP = require('onceler').TOTP;
  27. var request = require('request');
  28.  
  29. // GENERAL INFORMATION
  30.  
  31. var sitepath;
  32. sitepath = "xxx"; // The path to the index.php of your website without HTTP://
  33. var sitename;
  34. sitename = "xxx"; // The name of your site, it will be shown in the Trade Offer Message
  35.  
  36. var apik = "xxx"; // Must be the API Key associated with the current bot. Get it here: https://steamcommunity.com/dev/apikey
  37. var admin = 'xxx'; // The Admin, Main Owner of the site. You will be able to communicate with the bot, ask for the rake items, etc. Can be obtained at steamid.io
  38. var botsteamid = 'xxx'; // The bot's steam id, it is required to generate the Device ID and to confirm mobile confirmations. Can be obtained at steamid.io
  39. var identitysecret = 'zxxx'; // It's required to confirm mobile confirmations
  40. var sharedsecret = 'xxx'; // You won't be able to log in without this code
  41. var pooling_interval = 10000; // 10 seconds by default, the bot checks for outgoing confirmations every X seconds, defined here
  42. var rsecret='xxx'; // Also change this to the same code in endround.php and p2endround.php, this prevents people from randomly breaking your site by ending blank games or ending games sooner
  43.  
  44. var p2=false; // If this is the bot for your Jackpot 2 set this to true
  45.  
  46. // GENERAL INFORMATION
  47.  
  48. // LOGIN DETAILS
  49.  
  50. var details = {
  51. "accountName" : "xxx", // Bot username
  52. "password" : "xxx", // Bot password
  53. "twoFactorCode" : SteamTotp.generateAuthCode(sharedsecret)
  54. };
  55.  
  56. // LOGIN DETAILS
  57.  
  58.  
  59. var client = new SteamUser();
  60.  
  61. var manager = new TradeOfferManager({
  62. "steam" : client,
  63. "domain" : "localhost",
  64. "language" : "en"
  65. })
  66.  
  67. var deviceid=SteamTotp.getDeviceID(botsteamid);
  68.  
  69. if(p2==true)
  70. {
  71. var pot2='p2';
  72. }
  73. else
  74. {
  75. var pot2='';
  76. }
  77.  
  78. var GameTime = 120;
  79. var endtimer = -1;
  80. var timeleft;
  81.  
  82. // MYSQL INFO
  83.  
  84. var mysql = require('mysql');
  85. var connection = mysql.createConnection({
  86. host : 'xxx', // MySQL Host
  87. user : 'xxx', // MySQL User
  88. password : '9xxxxx', // MySQL Password
  89. database : 'xxxx' // MySQL Databse
  90. });
  91.  
  92. // MYSQL INFO
  93.  
  94. connection.connect();
  95.  
  96. client.logOn(details);
  97.  
  98. function EndGame()
  99. {
  100. endtimer = -1;
  101. proceedWinners();
  102. setTimeout(sendOffers,5000);
  103. }
  104.  
  105. function proceedWinners()
  106. {
  107. console.log('[SERVER] Ending current game & choosing winner.');
  108. var url = 'http://'+sitepath+'/'+pot2+'endround.php?secret='+rsecret+'';
  109. request(url, function(error, response, body)
  110. {
  111. if(error)
  112. {
  113. console.log('Couldn\'t end round, error: '+error);
  114. }
  115. });
  116.  
  117. }
  118.  
  119. function is_float(mixed_var)
  120. {
  121.  
  122. return +mixed_var === mixed_var && (!isFinite(mixed_var) || !! (mixed_var % 1));
  123. }
  124.  
  125. function isNumeric(n){
  126. return (typeof n == "number" && !isNaN(n));
  127. }
  128.  
  129.  
  130. function getUserInfo(steamids,callback)
  131. {
  132. var url = 'http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key='+apik+'&steamids='+ steamids + '&format=json';
  133. request({
  134. url: url,
  135. json: true
  136. }, function(error, response, body){
  137. if(!error && response.statusCode === 200){
  138. callback(null, body);
  139. } else if (error) {
  140. getUserInfo(steamids,callback);
  141. }
  142. });
  143. }
  144.  
  145.  
  146. function addslashes(str)
  147. {
  148. str=str.replace(/\\/g,'\\\\');
  149. str=str.replace(/\'/g,'\\\'');
  150. str=str.replace(/\"/g,'\\"');
  151. str=str.replace(/\0/g,'\\0');
  152. return str;
  153. }
  154.  
  155. client.on('loggedOn', function(details)
  156. {
  157. client.on('webSession', function(sessionID, cookies){
  158. manager.setCookies(cookies, function(err) {
  159. if(err) {
  160. console.log('setCookies error: '+err);
  161. process.exit(1); // Fatal error since we couldn't get our API key
  162. return;
  163. }
  164. var steamapi=manager.apiKey;
  165. var SteamcommunityMobileConfirmations = require('steamcommunity-mobile-confirmations');
  166. var steamcommunityMobileConfirmations = new SteamcommunityMobileConfirmations(
  167. {
  168. steamid: botsteamid,
  169. identity_secret: identitysecret,
  170. device_id: deviceid,
  171. webCookie: cookies,
  172. });
  173. setInterval(function(){
  174. checkConfirmations(steamcommunityMobileConfirmations)
  175. }, pooling_interval);
  176. console.log("[SERVER] The Bot has logged in!");
  177. client.addFriend(admin);
  178. client.chatMessage(admin, "[SERVER] Successfully logged in!");
  179. client.setPersona(Steam.EPersonaState.LookingToTrade);
  180. setTimeout(function()
  181. {
  182. connection.query('SELECT `value` FROM `'+pot2+'info` WHERE `name`=\'current_game\'', function(err, rows, fields)
  183. {
  184. if(err)
  185. {
  186. return;
  187. }
  188. connection.query('SELECT `starttime` FROM `'+pot2+'games` WHERE `id`=\''+rows[0].value+'\'', function(errs, rowss, fieldss)
  189. {
  190. if(errs)
  191. {
  192. return;
  193. }
  194. var timeleft;
  195. if(rowss[0].starttime == 2147483647)
  196. {
  197. timeleft = GameTime;
  198. }
  199. else
  200. {
  201. var unixtime = Math.round(new Date().getTime()/1000.0);
  202. timeleft = rowss[0].starttime+GameTime-unixtime;
  203. if(timeleft < 0)
  204. {
  205. timeleft = 0;
  206. }
  207. }
  208. if(timeleft != GameTime && endtimer==-1)
  209. {
  210. setTimeout(EndGame,timeleft*1000);
  211. console.log('[SERVER] Restoring the latest game with '+timeleft+' seconds left!');
  212. }
  213. });
  214. });
  215. },1500);
  216.  
  217.  
  218. });
  219. });
  220. });
  221.  
  222. function checkOffers() {
  223. manager.on('newOffer', function(offer)
  224. {
  225. var proceed=true;
  226. var steamid=offer.partner.getSteamID64();
  227. getUserInfo(steamid, function(error, data)
  228. {
  229. connection.query('SELECT `value` FROM `'+pot2+'info` WHERE `name`=\'current_game\'', function(err, rows, fields)
  230. {
  231. if(err)
  232. {
  233. return;
  234. }
  235. connection.query('SELECT `starttime` FROM `'+pot2+'games` WHERE `id`=\''+rows[0].value+'\'', function(errs, rowss, fieldss)
  236. {
  237. if(errs)
  238. {
  239. return;
  240. }
  241. var timeleft;
  242. if(rowss[0].starttime == 2147483647)
  243. {
  244. timeleft = GameTime;
  245. }
  246. else
  247. {
  248. var unixtime = Math.round(new Date().getTime()/1000.0);
  249. timeleft = rowss[0].starttime+GameTime-unixtime;
  250. if(timeleft < 0)
  251. {
  252. timeleft = 0;
  253. }
  254.  
  255. }
  256. if(timeleft > 80)
  257. {
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266. if(error)
  267. {
  268. console.log('getUserInfo error: '+error);
  269. proceed=false;
  270. offer.decline(function(err)
  271. {
  272. console.log('[DEBUG] Declined offer #'+offer.id+' from '+name+' (ID:'+steamid+'). | Reason: getUserInfo error');
  273. if (err)
  274. {
  275. console.log('Decline error: '+err);
  276. }
  277. connection.query('INSERT INTO `messages` (`type`,`app`,`userid`,`title`,`msg`,`time`,`active`) VALUES (\'error\',\'1\',\''+steamid+'\',\'Trade Offer Declined!\',\'Reason: Steam Servers are busy, try again in a minute!\',\'25\',\'1\')', function(err, row, fields) {});
  278. });
  279. return;
  280. }
  281. var datadec = JSON.parse(JSON.stringify(data.response));
  282. var name = addslashes(datadec.players[0].personaname);
  283. var avatar = (datadec.players[0].avatarfull);
  284.  
  285. console.log('[DEBUG] Processing offer #'+offer.id+' from '+name+' (ID:'+steamid+').');
  286.  
  287. if(offer.itemsToGive.length!=0)
  288. {
  289. proceed=false;
  290. offer.decline(function(err)
  291. {
  292. console.log('[DEBUG] Declined offer #'+offer.id+' from '+name+' (ID:'+steamid+'). | Reason: Asked for a skin on the Bot');
  293. if (err)
  294. {
  295. console.log('Decline error: '+err);
  296. }
  297. connection.query('INSERT INTO `messages` (`type`,`app`,`userid`,`title`,`msg`,`time`,`active`) VALUES (\'error\',\'1\',\''+steamid+'\',\'Trade Offer Declined!\',\'Reason: Asking for any of the bots items? Brave!\',\'25\',\'1\')', function(err, row, fields) {});
  298. });
  299. return;
  300. }
  301. offer.getEscrowDuration(function(err, daysTheirEscrow, daysMyEscrow)
  302. {
  303.  
  304. if(err)
  305. {
  306. console.log('getEscrowDuration error: '+err);
  307. proceed=false;
  308. offer.decline(function(err)
  309. {
  310. console.log('[DEBUG] Declined offer #'+offer.id+' from '+name+' (ID:'+steamid+'). | Reason: Steam Servers are busy, couldn\'t get escrow duration');
  311. if (err)
  312. {
  313. console.log('Decline error: '+err);
  314. }
  315. connection.query('INSERT INTO `messages` (`type`,`app`,`userid`,`title`,`msg`,`time`,`active`) VALUES (\'error\',\'1\',\''+steamid+'\',\'Trade Offer Declined!\',\'Reason: Steam Servers are busy, couldnt get escrow duration!\',\'25\',\'1\')', function(err, row, fields) {});
  316. });
  317. return;
  318. return;
  319. }
  320. else
  321. {
  322. if (daysTheirEscrow != 0)
  323. {
  324. proceed=false;
  325. offer.decline(function(err)
  326. {
  327. console.log('[DEBUG] Declined offer #'+offer.id+' from '+name+' (ID:'+steamid+'). | Reason: User is in Escrow for '+daysTheirEscrow+' days');
  328. if (err)
  329. {
  330. console.log('Decline error: '+err);
  331. }
  332. connection.query('INSERT INTO `messages` (`type`,`app`,`userid`,`title`,`msg`,`time`,`active`) VALUES (\'error\',\'1\',\''+steamid+'\',\'Trade Offer Declined!\',\'Reason: You are in Escrow for '+daysTheirEscrow+' days!\',\'25\',\'1\')', function(err, row, fields) {});
  333. });
  334. return;
  335. }
  336. else
  337. {
  338. connection.query('SELECT * FROM `'+pot2+'info`', function(err, row)
  339. {
  340. var minbet = row[3].value;
  341. var maxbet = row[7].value;
  342. var maxitems = row[4].value;
  343. var maxritems = row[10].value;
  344. if(offer.itemsToReceive.length>maxitems)
  345. {
  346. proceed=false;
  347. offer.decline(function(err)
  348. {
  349. console.log('[DEBUG] Declined offer #'+offer.id+' from '+name+' (ID:'+steamid+'). | Reason: User sent more than '+maxitems+' skins');
  350. if (err)
  351. {
  352. console.log('Decline error: '+err);
  353. }
  354. connection.query('INSERT INTO `messages` (`type`,`app`,`userid`,`title`,`msg`,`time`,`active`) VALUES (\'error\',\'1\',\''+steamid+'\',\'Trade Offer Declined!\',\'Reason: We only accept up to '+maxitems+' skins!\',\'25\',\'1\')', function(err, row, fields) {});
  355.  
  356. });
  357. return;
  358. }
  359.  
  360. var items = offer.itemsToReceive;
  361. var totaldeposit=0;
  362. var depitems=[],skinssent=0;
  363. items.forEach(function(item, i , arr)
  364. {
  365. if (item.appid != 730)
  366. {
  367. proceed=false;
  368. offer.decline(function(err)
  369. {
  370. console.log('[DEBUG] Declined offer #'+offer.id+' from '+name+' (ID:'+steamid+'). | Reason: User sent a Non-CSGO skin');
  371. if (err)
  372. {
  373. console.log('Decline error: '+err);
  374. }
  375. });
  376. connection.query('INSERT INTO `messages` (`type`,`app`,`userid`,`title`,`msg`,`time`,`active`) VALUES (\'error\',\'1\',\''+steamid+'\',\'Trade Offer Declined!\',\'Reason: We only accept CSGO skins!\',\'25\',\'1\')', function(err, row, fields) {});
  377. return;
  378. }
  379. if(item.market_hash_name.indexOf("Souvenir") != -1)
  380. {
  381. proceed=false;
  382. offer.decline(function(err)
  383. {
  384. console.log('[DEBUG] Declined offer #'+offer.id+' from '+name+' (ID:'+steamid+'). | Reason: User sent a Souvenir Skin');
  385. if (err)
  386. {
  387. console.log('Decline error: '+err);
  388. }
  389. });
  390. connection.query('INSERT INTO `messages` (`type`,`app`,`userid`,`title`,`msg`,`time`,`active`) VALUES (\'error\',\'1\',\''+steamid+'\',\'Trade Offer Declined!\',\'Reason: No souvenir skins allowed!\',\'25\',\'1\')', function(err, row, fields) {});
  391. return;
  392. }
  393. depitems[i]=[];
  394. depitems[i].name=item.market_name;
  395. depitems[i].color=item.name_color;
  396. depitems[i].url=item.icon_url;
  397. depitems[i].value=0;
  398. var itemname = item.market_name;
  399. var url = 'http://'+sitepath+'/cost.php?item='+encodeURIComponent(itemname);
  400.  
  401. (function(someshit) {
  402. request(url, function(error, response, body)
  403. {
  404. if(!error && response.statusCode === 200)
  405. {
  406. if(body == "notfound")
  407. {
  408. proceed=false;
  409. offer.decline(function(err)
  410. {
  411. console.log('[DEBUG] Declined offer #'+offer.id+' from '+name+' (ID:'+steamid+'). | Reason: Steam Market Issues (Can\'t get the skin\'s value)');
  412. if (err)
  413. {
  414. console.log('Decline error: '+err);
  415. }
  416. });
  417. connection.query('INSERT INTO `messages` (`type`,`app`,`userid`,`title`,`msg`,`time`,`active`) VALUES (\'error\',\'1\',\''+steamid+'\',\'Trade Offer Declined!\',\'Reason: Steam Market issues!\',\'25\',\'1\')', function(err, row, fields) {});
  418. return;
  419. }
  420. else
  421. {
  422. depitems[i].value = parseFloat(body);
  423. totaldeposit+=depitems[i].value;
  424. if(depitems[i].value=="notfound" || depitems[i].value=="NaN" || depitems[i].value=="null" || depitems[i].value=="undefined" || depitems[i].value==0 || !depitems[i].value)
  425. {
  426. proceed=false;
  427. offer.decline(function(err)
  428. {
  429. console.log('[DEBUG] Declined offer #'+offer.id+' from '+name+' (ID:'+steamid+'). | Reason: Steam Market Issues (Can\'t get the skin\'s value)');
  430. if (err)
  431. {
  432. console.log('Decline error: '+err);
  433. }
  434. });
  435. connection.query('INSERT INTO `messages` (`type`,`app`,`userid`,`title`,`msg`,`time`,`active`) VALUES (\'error\',\'1\',\''+steamid+'\',\'Trade Offer Declined!\',\'Reason: Steam Market issues!\',\'25\',\'1\')', function(err, row, fields) {});
  436. return;
  437. }
  438. }
  439. }
  440. else
  441. {
  442. proceed=false;
  443. offer.decline(function(err)
  444. {
  445. console.log('[DEBUG] Declined offer #'+offer.id+' from '+name+' (ID:'+steamid+'). | Reason: Steam Market Issues (Can\'t get the skin\'s value)');
  446. if (err)
  447. {
  448. console.log('Decline error: '+err);
  449. }
  450. });
  451. connection.query('INSERT INTO `messages` (`type`,`app`,`userid`,`title`,`msg`,`time`,`active`) VALUES (\'error\',\'1\',\''+steamid+'\',\'Trade Offer Declined!\',\'Reason: Steam Market issues!\',\'25\',\'1\')', function(err, row, fields) {});
  452. return;
  453. }
  454. });
  455. })(i)
  456. skinssent++;
  457.  
  458.  
  459. });
  460.  
  461. setTimeout(function()
  462. {
  463.  
  464. if(totaldeposit>maxbet)
  465. {
  466. proceed=false;
  467. offer.decline(function(err)
  468. {
  469. console.log('[DEBUG] Declined offer #'+offer.id+' from '+name+' (ID:'+steamid+'). | Reason: User sent too much in skin value');
  470. if (err)
  471. {
  472. console.log('Decline error: '+err);
  473. }
  474. });
  475. connection.query('INSERT INTO `messages` (`type`,`app`,`userid`,`title`,`msg`,`time`,`active`) VALUES (\'error\',\'1\',\''+steamid+'\',\'Trade Offer Declined!\',\'Reason: You can deposit more than $'+maxbet+'\',\'25\',\'1\')', function(err, row, fields) {});
  476. return;
  477.  
  478.  
  479. }
  480. if(totaldeposit<minbet)
  481. {
  482. proceed=false;
  483. offer.decline(function(err)
  484. {
  485. console.log('[DEBUG] Declined offer #'+offer.id+' from '+name+' (ID:'+steamid+'). | Reason: User sent below the minimal bet amount ($'+minbet+')');
  486. if (err)
  487. {
  488. console.log('Decline error: '+err);
  489. }
  490. });
  491. connection.query('INSERT INTO `messages` (`type`,`app`,`userid`,`title`,`msg`,`time`,`active`) VALUES (\'error\',\'1\',\''+steamid+'\',\'Trade Offer Declined!\',\'Reason: Minimum deposit value: $'+minbet+'\',\'25\',\'1\')', function(err, row, fields) {});
  492. return;
  493. }
  494. if(skinssent>maxitems)
  495. {
  496. proceed=false;
  497. offer.decline(function(err)
  498. {
  499. console.log('[DEBUG] Declined offer #'+offer.id+' from '+name+' (ID:'+steamid+'). | Reason: User sent too many skins');
  500. if (err)
  501. {
  502. console.log('Decline error: '+err);
  503. }
  504. });
  505. connection.query('INSERT INTO `messages` (`type`,`app`,`userid`,`title`,`msg`,`time`,`active`) VALUES (\'error\',\'1\',\''+steamid+'\',\'Trade Offer Declined!\',\'Reason: We only accept up to '+maxitems+' skins!\',\'25\',\'1\')', function(err, row, fields) {});
  506. return;
  507.  
  508. }
  509. if(proceed=true)
  510. {
  511. connection.query('SELECT * FROM `'+pot2+'info`', function(err, row)
  512. {
  513.  
  514. var cg = row[0].value;
  515. connection.query('SELECT COUNT(value) as skinsin,SUM(value) as moneyin FROM `'+pot2+'game'+cg+'` WHERE `userid`=\''+steamid+'\'', function(err, row, fields)
  516. {
  517. skinsin = row[0].skinsin;
  518. skinsin=skinsin+skinssent;
  519. moneyin = row[0].moneyin;
  520. moneyin=moneyin+totaldeposit;
  521.  
  522. if(skinsin>maxitems)
  523. {
  524. offer.decline(function(err)
  525. {
  526. console.log('[DEBUG] Declined offer #'+offer.id+' from '+name+' (ID:'+steamid+'). | Reason: RECHECK - User sent too many skins');
  527. if (err)
  528. {
  529. console.log('Decline error: '+err);
  530. }
  531. });
  532. connection.query('INSERT INTO `messages` (`type`,`app`,`userid`,`title`,`msg`,`time`,`active`) VALUES (\'error\',\'1\',\''+steamid+'\',\'Trade Offer Declined!\',\'Reason: You can not deposit more than '+maxitems+' skins\',\'25\',\'1\')', function(err, row, fields) {});
  533. return;
  534. }
  535.  
  536. if(moneyin > maxbet)
  537. {
  538. offer.decline(function(err)
  539. {
  540. console.log('[DEBUG] Declined offer #'+offer.id+' from '+name+' (ID:'+steamid+'). | Reason: RECHECK - User sent too much in skin value');
  541. if (err)
  542. {
  543. console.log('Decline error: '+err);
  544. }
  545. });
  546. connection.query('INSERT INTO `messages` (`type`,`app`,`userid`,`title`,`msg`,`time`,`active`) VALUES (\'error\',\'1\',\''+steamid+'\',\'Trade Offer Declined!\',\'Reason: You can deposit more than $'+maxbet+'\',\'25\',\'1\')', function(err, row, fields) {});
  547. return;
  548. }
  549. for(var i=0; i < skinssent; i++)
  550. {
  551. if(!isNumeric(depitems[i].value))
  552. {
  553. offer.decline(function(err)
  554. {
  555. console.log('[DEBUG] Declined offer #'+offer.id+' from '+name+' (ID:'+steamid+'). | Reason: RECHECK - Steam Market Issues (Can\'t get the skin\'s value) ');
  556. if (err)
  557. {
  558. console.log('Decline error: '+err);
  559. }
  560. });
  561. connection.query('INSERT INTO `messages` (`type`,`app`,`userid`,`title`,`msg`,`time`,`active`) VALUES (\'error\',\'1\',\''+steamid+'\',\'Trade Offer Declined!\',\'Reason: Steam Market issues!\',\'25\',\'1\')', function(err, row, fields) {});
  562. return;
  563. }
  564. }
  565.  
  566. connection.query('SELECT * FROM `users` WHERE `steamid`=\''+steamid+'\'', function(err, row, fields)
  567. {
  568. if(err)
  569. {
  570. console.log('MYSQL Error: '+err);
  571. offer.decline(function(err)
  572. {
  573. console.log('[DEBUG] Declined offer #'+offer.id+' from '+name+' (ID:'+steamid+'). | Reason: MYSQL Error (as seen above) ');
  574. if (err)
  575. {
  576. console.log('Decline error: '+err);
  577. }
  578. });
  579. connection.query('INSERT INTO `messages` (`type`,`app`,`userid`,`title`,`msg`,`time`,`active`) VALUES (\'error\',\'1\',\''+steamid+'\',\'Trade Offer Declined!\',\'Reason: MYSQL Error\',\'25\',\'1\')', function(err, row, fields) {});
  580. return;
  581. }
  582. if(row.length!=0)
  583. {
  584. ban=row[0].ban;
  585. tlink=row[0].tlink;
  586. if(ban==1)
  587. {
  588. proceed=false;
  589. offer.decline(function(err)
  590. {
  591. console.log('[DEBUG] Declined offer #'+offer.id+' from '+name+' (ID:'+steamid+'). | Reason: User is banned');
  592. if (err)
  593. {
  594. console.log('Decline error: '+err);
  595. }
  596. });
  597. connection.query('INSERT INTO `messages` (`type`,`app`,`userid`,`title`,`msg`,`time`,`active`) VALUES (\'error\',\'1\',\''+steamid+'\',\'Trade Offer Declined!\',\'Reason: You are banned from betting\',\'25\',\'1\')', function(err, row, fields) {});
  598. return;
  599. }
  600. if(!tlink)
  601. {
  602. offer.decline(function(err)
  603. {
  604. console.log('[DEBUG] Declined offer #'+offer.id+' from '+name+' (ID:'+steamid+'). | Reason: User doesn\'t have a TradeLink set ');
  605. if (err)
  606. {
  607. console.log('Decline error: '+err);
  608. }
  609. });
  610. connection.query('INSERT INTO `messages` (`type`,`app`,`userid`,`title`,`msg`,`time`,`active`) VALUES (\'error\',\'1\',\''+steamid+'\',\'Trade Offer Declined!\',\'Reason: No Trade URL Set\',\'25\',\'1\')', function(err, row, fields) {});
  611. return;
  612. }
  613.  
  614. connection.query('SELECT * FROM `'+pot2+'games` WHERE `id`=\''+cg+'\'', function(err, row, fields)
  615. {
  616. itemsin=row[0].itemsnum;
  617. offer.accept(function(err)
  618. {
  619.  
  620.  
  621. if(err)
  622. {
  623. console.log('Accept error: '+err);
  624. /*if(err!="error: http error 503") Experimental function please do not use
  625. {
  626. return;
  627. }*/
  628. return;
  629. }
  630. for(var i=0; i < skinssent; i++)
  631. {
  632. var itemname = addslashes(depitems[i].name);
  633. connection.query('INSERT INTO `'+pot2+'game' +cg+ '` (`userid`,`username`,`item`,`offerid`,`color`,`value`,`avatar`,`image`) VALUES (\'' + steamid + '\',\'' + name + '\',\'' + itemname + '\',\''+offer.id+'\',\'' + depitems[i].color + '\',\'' + depitems[i].value + '\',\'' + avatar + '\',\'' + depitems[i].url + '\')', function(err, row, fields)
  634. {
  635. if(err)
  636. {
  637. console.log(err);
  638. }
  639. });
  640. connection.query('UPDATE `'+pot2+'games` SET `itemsnum`=`itemsnum`+1, `cost`=`cost`+\''+depitems[i].value+'\' WHERE `id` = \''+cg+'\'', function(err, row, fields) {});
  641. }
  642. connection.query('UPDATE `users` SET `skinssent`=`skinssent`+'+skinssent+' WHERE `steamid` = \'' + steamid + '\'', function(err, row, fields) {});
  643. console.log('[SERVER] Accepted offer #'+offer.id+' from '+name+' (ID:'+steamid+').');
  644. offer.getReceivedItems(function(err, items)
  645. {
  646. if(err)
  647. {
  648. console.log('getReceivedItems SERIOUS GAME BREAKING error: '+err);
  649. }
  650. items.forEach(function(item)
  651. {
  652. var itemn=addslashes(item.market_name);
  653. connection.query('UPDATE `'+pot2+'game'+cg+'` SET `assetid`=\''+item.id+'\' WHERE `userid` = \'' + steamid + '\' AND `item`=\''+itemn+'\' AND `assetid`=\'\' LIMIT 1', function(err, row, fields) {});
  654. })
  655. });
  656. connection.query('INSERT INTO `messages` (`type`,`app`,`userid`,`title`,`msg`,`time`,`active`) VALUES (\'success\',\'0\',\''+steamid+'\',\'Trade Offer Accepted (Game #'+cg+')!\',\'We wish you Good luck and happy betting!\',\'25\',\'1\')', function(err, row, fields) {});
  657. connection.query('SELECT COUNT(DISTINCT userid) AS playersCount FROM `'+pot2+'game'+cg+'`', function(err, rows)
  658. {
  659. players = rows[0].playersCount;
  660. if(players == 1 && skinssent > 0 && endtimer==-1)
  661. {
  662. console.log('[SERVER] Starting the countdown for Game #'+cg+'');
  663. endtimer = setTimeout(EndGame,GameTime*1000);
  664. connection.query('UPDATE `'+pot2+'games` SET `starttime`=UNIX_TIMESTAMP() WHERE `id` = \'' + cg + '\'', function(err, row, fields) {});
  665. }
  666. if(itemsin > maxritems)
  667. {
  668. clearTimeout(endtimer);
  669. endtimer = -1;
  670. EndGame();
  671. }
  672.  
  673. });
  674. });
  675.  
  676.  
  677. });
  678. }
  679. else
  680. {
  681. offer.decline(function(err)
  682. {
  683. console.log('[DEBUG] Declined offer #'+offer.id+' from '+name+' (ID:'+steamid+'). | Reason: User is not in the MYSQL Database');
  684. if (err)
  685. {
  686. console.log('Decline error: '+err);
  687. }
  688. });
  689. return;
  690. }
  691.  
  692. return;
  693.  
  694. });
  695.  
  696.  
  697. });
  698. });
  699. }
  700. else
  701. {
  702.  
  703. offer.decline(function(err)
  704. {
  705. console.log('[DEBUG] Declined offer #'+offer.id+' from '+name+' (ID:'+steamid+'). | Reason: Unkown error (proceed = false in node) - Probably Steam Issues');
  706. if (err)
  707. {
  708. console.log('Decline error: '+err);
  709. }
  710. });
  711. connection.query('INSERT INTO `messages` (`type`,`app`,`userid`,`title`,`msg`,`time`,`active`) VALUES (\'error\',\'1\',\''+steamid+'\',\'Trade Offer Declined!\',\'Reason: Steam Issues\',\'25\',\'1\')', function(err, row, fields) {});
  712. return;
  713. }
  714.  
  715.  
  716. },2000);
  717. });
  718. }
  719. }
  720. });
  721. }
  722. if(timeleft < 80)
  723. {
  724.  
  725. console.log('[SERVER] Time is lower than 80 seconds, offer will be skiped to the next round, current time'+timeleft+' seconds');
  726.  
  727. }
  728. });
  729. });
  730. });
  731. });
  732. };
  733.  
  734. client.on('friendMessage#'+admin+'', function(steamID, message)
  735. {
  736.  
  737. console.log("[SERVER] Admin to Bot: " + message);
  738. if(message.indexOf("/sendrake") == 0)
  739. {
  740. client.chatMessage(admin, '[SERVER] Calling the sendRake function (sends the latest query, call it more times if needed)');
  741. sendRake(1);
  742. }
  743. if(message.indexOf("/sendoffers") == 0)
  744. {
  745. client.chatMessage(admin, '[SERVER] Calling the sendOffers function (sends the latest query, call it more times if needed)');
  746. sendOffers(1);
  747.  
  748. }
  749. if(message.indexOf("/code") == 0)
  750. {
  751. var code = SteamTotp.generateAuthCode(sharedsecret);
  752. client.chatMessage(admin, '[SERVER] Current login code (retry if it doesnt work): '+code+'');
  753. }
  754. if(message.indexOf("/end") == 0)
  755. {
  756. client.chatMessage(admin, '[SERVER] Ending the current game!');
  757. if(endtimer != -1) clearTimeout(endtimer);
  758. EndGame();
  759. }
  760. if(message.indexOf("/offers") == 0)
  761. {
  762. connection.query('SELECT ID FROM `'+pot2+'queue` WHERE `status`=\'active\' GROUP BY `id` DESC', function(err, row, fields)
  763. {
  764. if(row.length!=0)
  765. {
  766. console.log(row);
  767. client.chatMessage(admin, '[SERVER] Check your console for the ID\'s!');
  768. }
  769. else
  770. {
  771. client.chatMessage(admin, '[SERVER] There aren\'t any active queue ID\'s.');
  772. }
  773. });
  774. }
  775. if(message.indexOf("/rakes") == 0)
  776. {
  777. connection.query('SELECT ID FROM `'+pot2+'rakeitems` WHERE `status`=\'active\' GROUP BY `id` DESC', function(err, row, fields)
  778. {
  779. if(row.length!=0)
  780. {
  781. console.log(row);
  782. client.chatMessage(admin, '[SERVER] Check your console for the ID\'s!');
  783. }
  784. else
  785. {
  786. client.chatMessage(admin, '[SERVER] There aren\'t any active rake ID\'s.');
  787. }
  788. });
  789. }
  790.  
  791. });
  792.  
  793. function sendOffers(param)
  794. {
  795. connection.query('SELECT * FROM `'+pot2+'info`', function(err, row)
  796. {
  797. var cg = row[0].value;
  798. var cgm1 = cg-1;
  799. connection.query('SELECT * FROM `'+pot2+'games` WHERE `id`=\''+cgm1+'\'', function(err, row, fields)
  800. {
  801. var hashh=row[0].hash;
  802. connection.query('SELECT * FROM `'+pot2+'queue` WHERE `status`=\'active\' GROUP BY `id` DESC LIMIT 1', function(err, row, fields)
  803.  
  804. {
  805. if(row.length!=0)
  806. {
  807. var assetids=(row[0].assetid).split('/');
  808. manager.loadInventory(730, 2, true, function (err, inventory)
  809. {
  810. if (err)
  811. {
  812. console.log(err);
  813. if(param==1)
  814. {
  815. client.chatMessage(admin, '[SERVER] Error while loading the Bot\'s Inventory, try again later boss!');
  816. }
  817. return;
  818.  
  819. }
  820. else
  821. {
  822. var token=row[0].token;
  823. var gameid=row[0].id;
  824. var message='Congratulations! You won on '+sitename+' in Game #'+gameid+' Hash: '+hashh+'';
  825. var offer = manager.createOffer(row[0].userid);
  826.  
  827. inventory.forEach(function(item)
  828. {
  829. assetids.forEach(function(asset)
  830. {
  831. if(item.id==asset)
  832. {
  833. offer.addMyItem(item);
  834. }
  835. })
  836. })
  837. setTimeout(function()
  838. {
  839. offer.send(message, token, function(err)
  840. {
  841. if(err)
  842. {
  843. console.log('Error sending Trade Offer for Game #'+gameid+':');
  844. console.log(err);
  845. if(param==1)
  846. {
  847. client.chatMessage(admin, '[SERVER] Error while sending the tradeoffer, try again later boss!');
  848. }
  849. return;
  850. }
  851. connection.query('UPDATE `'+pot2+'queue` SET `status`="sent" WHERE `id`=\''+gameid+'\'');
  852. console.log('[SERVER] Trade Offer for Game #'+gameid+' has been successfully sent and is awaiting mobile confirmation.');
  853. if(param==1)
  854. {
  855. client.chatMessage(admin, '[SERVER] Successfully sent the trade for Game #'+gameid+'!');
  856. }
  857. });
  858.  
  859. },2000);
  860. }
  861. });
  862. }
  863. else
  864. {
  865. if(param==1)
  866. {
  867. client.chatMessage(admin, '[SERVER] No more Winnings Queries!');
  868. return;
  869. }
  870. }
  871. }); });
  872. });
  873. }
  874.  
  875. function sendRake(param)
  876. {
  877. connection.query('SELECT * FROM `'+pot2+'rakeitems` WHERE `status`=\'active\' GROUP BY `id` DESC LIMIT 1', function(err, row, fields)
  878. {
  879. if(row.length!=0)
  880. {
  881. var assetids=(row[0].assetid).split('/');
  882. manager.loadInventory(730, 2, true, function (err, inventory)
  883. {
  884. if (err)
  885. {
  886. if(param==1)
  887. {
  888. client.chatMessage(admin, '[SERVER] Error while loading the Bot\'s Inventory, try again later boss!');
  889. }
  890. return;
  891. }
  892. else
  893. {
  894. var token=row[0].token;
  895. var gameid=row[0].id;
  896. var value=row[0].value;
  897. var message='Rake for Game #'+gameid+' ($'+value+')';
  898. var offer = manager.createOffer(row[0].userid);
  899.  
  900. inventory.forEach(function(item)
  901. {
  902. assetids.forEach(function(asset)
  903. {
  904. if(item.id==asset)
  905. {
  906. offer.addMyItem(item);
  907. }
  908. })
  909. })
  910. setTimeout(function()
  911. {
  912. offer.send(message, token, function(err)
  913. {
  914. if(err)
  915. {
  916. console.log('Error sending Rake for Game #'+gameid+':');
  917. console.log(err);
  918. if(param==1)
  919. {
  920. client.chatMessage(admin, '[SERVER] Error while sending the tradeoffer for the rake, try again later boss!');
  921. return;
  922. }
  923. return;
  924. }
  925. connection.query('UPDATE `'+pot2+'rakeitems` SET `status`="sent" WHERE `id`=\''+gameid+'\'');
  926. console.log('[SERVER] Rake for Game #'+gameid+' has been successfully sent and is awaiting mobile confirmation.');
  927. if(param==1)
  928. {
  929. client.chatMessage(admin, '[SERVER] Successfully sent the rake for Game #'+gameid+'!');
  930. }
  931. });
  932.  
  933. },2000);
  934. }
  935. });
  936. }
  937. else
  938. {
  939. if(param==1)
  940. {
  941. client.chatMessage(admin, '[SERVER] No more Rake Queries!');
  942. return;
  943. }
  944. }
  945. });
  946. }
  947.  
  948.  
  949. function checkConfirmations(steamcommunityMobileConfirmations){
  950. steamcommunityMobileConfirmations.FetchConfirmations((function (err, confirmations)
  951. {
  952. if (err)
  953. {
  954. console.log(err);
  955. return;
  956. }
  957. if(confirmations.length>0)
  958. {
  959. console.log('[SERVER] Received ' + confirmations.length + ' confirmations');
  960. }
  961. if ( ! confirmations.length)
  962. {
  963. return;
  964. }
  965. steamcommunityMobileConfirmations.AcceptConfirmation(confirmations[0], (function (err, result)
  966. {
  967. if (err)
  968. {
  969. console.log(err);
  970. return;
  971. }
  972. console.log('[SERVER] Confirmation handling result: ' + result);
  973.  
  974. }).bind(this));
  975. }).bind(this));
  976. }
  977.  
  978.  
  979. checkOffers();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement