Advertisement
Guest User

Untitled

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