Advertisement
MagneticaMusic

Source Code

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