Advertisement
Guest User

Untitled

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