Advertisement
Guest User

Untitled

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