Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2016
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 31.00 KB | None | 0 0
  1. /*
  2. __ _________ ________ ____ _____ _
  3. \ \ / / ____\ \ / / ____| _ \ | __ \| |
  4. \ \_/ / | __ \ \ /\ / /| |__ | |_) || |__) | |
  5. \ /| | |_ | \ \/ \/ / | __| | _ < | ___/| |
  6. | | | |__| | \ /\ / | |____| |_) || | | |____
  7. |_| \_____| \/ \/ |______|____(_)_| |______|
  8.  
  9. */
  10. var SteamTotp = require('steam-totp');
  11. var Steam = require('steam');
  12. var SteamTradeOffers = require('steam-tradeoffers');
  13. var request = require("request");
  14. var SteamConfirm = require('steamcommunity-mobile-confirmations');
  15. var mysql = require('mysql');
  16. var io = require('socket.io')(9182);
  17. require('events').EventEmitter.defaultMaxListeners = Infinity;
  18. /*
  19. Konfiguracja skryptu
  20. */
  21. var admin = '76561198084673749'; // SteamID64 administratora
  22. var botsteamid = '76561198096932160'; // SteamID64 bota
  23. var shared_secret ='tajne='; // Shared secret konta bota
  24. var identity_secret='tajne='; // Identity secret konta bota
  25. var pooling_interval = 100000; // Częstotliwość akceptowania wymian w ms (10000ms to 10s)
  26. var apik = 'tajne'; // APIKey Steam konta bota -> http://steamcommunity.com/dev/apikey
  27. var sitename = 'ygpot.com'; // Adres strony WWW bez protokołu (np. ygpot.com)
  28. var GameTime = 90; // Czas trwania rundy
  29. //var souvenir = 1; // Przedmioty pamiątki (0 - nie, 1 - tak)
  30. var logOnOptions = {
  31. accountName: 'bartek4176', // Login steam do konta bota
  32. password: 'tajne', // Hasło steam do konta bota
  33. twoFactorCode: SteamTotp.generateAuthCode(shared_secret) // Generowanie mobilnego tokenu
  34. }
  35. var mysqlInfo = {
  36. host : 'localhost', // Host bazy danych
  37. user : 'root', // Nazwa użytkownika bazy danych
  38. password : 'tajne', // Hasło do bazy danych
  39. database : 'jackpot', // Nazwa bazy danych
  40. charset : 'utf8_general_ci' // Kodowanie bazy danych
  41. };
  42. /*
  43. Koniec konfiguracji skryptu
  44.  
  45. Edycja poniższego kodu wiąże się z utratą pomocy technicznej na skrypt
  46. */
  47. function getDateTime() {
  48. var date = new Date();
  49. var hour = date.getHours();
  50. hour = (hour < 10 ? "0" : "") + hour;
  51. var min = date.getMinutes();
  52. min = (min < 10 ? "0" : "") + min;
  53. var sec = date.getSeconds();
  54. sec = (sec < 10 ? "0" : "") + sec;
  55. var year = date.getFullYear();
  56. var month = date.getMonth() + 1;
  57. month = (month < 10 ? "0" : "") + month;
  58. var day = date.getDate();
  59. day = (day < 10 ? "0" : "") + day;
  60. return year + ":" + month + ":" + day + ":" + hour + ":" + min + ":" + sec;
  61. }
  62. var mysqlConnection = mysql.createConnection(mysqlInfo, {multipleStatements: true});
  63. var Entities = require('html-entities').AllHtmlEntities;
  64. entities = new Entities();
  65. var steam = new Steam.SteamClient();
  66. var offers = new SteamTradeOffers();
  67. var hash = require('crypto').createHash('sha1');
  68. var express = require("express");
  69. hash.update(Math.random().toString());
  70. hash = hash.digest('hex');
  71. var device_id = 'android:' + hash;
  72. var globalSessionID;
  73. var locked = false, proceeded;
  74. var itemscopy;
  75. var detected = false;
  76. var detected2 = false;
  77. var endtimer = -1;
  78. var authCode = '';
  79. var userCount = 0;
  80. var actual_time = null;
  81. var lasted = getDateTime();
  82. io.on('connection', function(socket) {
  83. //var login = '<span style="color: red;">System</span>';
  84. //var system = 'http://blodhren.pl/img/system.png';
  85. //io.emit('message', { avatar: system, login: login, message: '<b>Welcome to YGPot!</b>' });
  86. mysqlConnection.query("SELECT `value` FROM `info` WHERE `name`=\'current_game\'", function(err, row) {
  87. var round = row[0].value;
  88. var lastgame = row[0].value - 1;
  89. mysqlConnection.query("SELECT SUM(value) AS value FROM `game"+lastgame+"`", function(err, row) {
  90. var lastpot = row[0].value;
  91. mysqlConnection.query("SELECT `cost` FROM `games` ORDER BY `cost` DESC", function(err, row) {
  92. if(lastpot == null) {
  93. lastpot = "0.00";
  94. } else {
  95. lastpot = parseFloat(lastpot).toFixed(2);
  96. }
  97. var biggestwin = parseFloat(row[0].cost).toFixed(2);
  98. mysqlConnection.query('SELECT `value` FROM `info` WHERE `name`=\'current_game\'', function(err, row, fields) {
  99. var current_game = (row[0].value);
  100. mysqlConnection.query('SELECT `cost`,`itemsnum` FROM `games` WHERE `id`=\''+current_game+'\'', function(err, row, fields) {
  101. var current_bank2 = row[0].cost;
  102. var current_bank = parseFloat(current_bank2).toFixed(2);
  103. var itemsnum = row[0].itemsnum;
  104. socket.emit('gameinfo', { current_money: current_bank, itemsnum: itemsnum });
  105. // io.emit('gameinfo', { current_money: current_bank, itemsnum: itemsnum });
  106. });
  107. });
  108. socket.emit('info', { round: round, biggestwin: biggestwin, lastpot: lastpot });
  109.  
  110. });
  111. });
  112. });
  113. socket.on('message', function(data){
  114. var last_chat = lasted;
  115. var date = getDateTime();
  116. if(date != last_chat){
  117. var steamid = data.steamid;
  118. if(steamid != undefined && data.hash != undefined){
  119. mysqlConnection.query('SELECT `admin` FROM `users` WHERE `steamid`=\''+steamid+'\'', function(errss, rowsss, fieldsss) {
  120. mysqlConnection.query('SELECT `hash` FROM `users` WHERE `steamid`=\''+steamid+'\'', function(errs, rowss, fieldss) {
  121. if(data.admin == rowsss[0].admin){
  122. if(errs) console.log(errs);
  123. if(rowss[0].hash != undefined) var hash = rowss[0].hash;
  124. if(hash == data.hash){
  125. if(data.admin == 1) {
  126. var login = '<span style="color: red;">'+data.login+'</span>';
  127. } else if(data.admin == 2) {
  128. var login = '<span style="color: green;">'+data.login+'</span>';
  129. } else if(data.admin == 3) {
  130. var login = '<span style="color: orange;">[STREAMER] '+data.login+'</span>';
  131. } else {
  132. var login = data.login;
  133. }
  134. if(data.admin != 4) {
  135. var message = entities.encode(data.message);
  136. lasted = getDateTime();
  137. io.emit('message', { avatar: data.avatar, login: login, message: message });
  138. }
  139. } else {
  140. console.log("[YGWEB] ERROR HASH CHAT");
  141. }
  142. }
  143. });
  144. });
  145. }
  146. } else {
  147. console.log("[YGWEB] TOO LATE CHAT");
  148. }
  149. });
  150. mysqlConnection.query('SELECT `value` FROM `info` WHERE `name`=\'current_game\'', function(err, row, fields){
  151. var current_game = (row[0].value);
  152. mysqlConnection.query('SELECT * FROM `game'+current_game+'` ORDER BY `value` DESC', function(err, row) {
  153. if(err) {
  154. console.log('[YGWEB] ERROR: '+err);
  155. // throw err;
  156. } else {
  157. for(var i in row) {
  158. io.to(socket.id).emit('item', { userid: row[i].userid, username: row[i].username, item: row[i].item, color: row[i].color, value: row[i].value, avatar: row[i].avatar, image: row[i].image });
  159. }
  160. }
  161. });
  162. });
  163. userCount++;
  164. io.sockets.emit('userCount', { userCount: userCount });
  165. socket.on('disconnect', function() {
  166. userCount--;
  167. io.sockets.emit('userCount', { userCount: userCount });
  168. });
  169. setInterval(function() {
  170. request({
  171. uri: "http://"+sitename+"/game_info.php?info=timeleft",
  172. }, function(error, response, body) {
  173. var timeleft = body;
  174. if(timeleft < 0 || timeleft == 0 || timeleft == 1) {
  175. timeleft = 0;
  176. var url = 'http://'+sitename+'/inc/winner.php';
  177. request(url, function(error, response, body){});
  178. EndGame();
  179. io.emit('time', { timeleft: timeleft });
  180. io.emit('end', { end: 66 });
  181. } else {
  182. io.emit('time', { timeleft: timeleft });
  183. }
  184. });
  185. }, 500);
  186. });
  187. if (require('fs').existsSync('sentry_'+logOnOptions['accountName']+'.hash')) {
  188. logOnOptions['shaSentryfile'] = require('fs').readFileSync('sentry_'+logOnOptions['accountName']+'.hash');
  189. } else if(require('fs').existsSync('ssfn_'+logOnOptions['accountName'])) {
  190. var sha = require('crypto').createHash('sha1');
  191. sha.update(require('fs').readFileSync('ssfn_'+logOnOptions['accountName']));
  192. var sentry = new Buffer(sha.digest(), 'binary');
  193. logOnOptions['shaSentryfile'] = sentry;
  194. require('fs').writeFileSync('sentry_'+logOnOptions['accountName']+'.hash', sentry);
  195. } else if (authCode != '') {
  196. logOnOptions['authCode'] = authCode;
  197. }
  198.  
  199. var recheck = true;
  200. steam.logOn(logOnOptions);
  201.  
  202. function getUserName(steamid) {
  203. getUserInfo(steamid, function(error, data) {
  204. // if(error) throw error;
  205. if(error) console.log('[YGWEB] ERROR: '+error);
  206. var datadec = JSON.parse(JSON.stringify(data.response));
  207. return (datadec.players[0].personaname);
  208. });
  209. }
  210. function is_float(mixed_var) {
  211. return +mixed_var === mixed_var && (!isFinite(mixed_var) || !! (mixed_var % 1));
  212. }
  213. function proceedWinners() {
  214. var url = 'http://'+sitename+'/inc/winner.php';
  215. request(url, function(error, response, body){});
  216. }
  217. function getUserInfo(steamids,callback) {
  218. var url = 'http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key='+apik+'&steamids='+ steamids + '&format=json';
  219. request({
  220. url: url,
  221. json: true
  222. }, function(error, response, body) {
  223. if(!error && response.statusCode === 200) {
  224. callback(null, body);
  225. } else if (error) {
  226. getUserInfo(steamids,callback);
  227. }
  228. });
  229. }
  230. function addslashes(str) {
  231. str=str.replace(/\\/g,'\\\\');
  232. str=str.replace(/\'/g,'\\\'');
  233. str=str.replace(/\"/g,'\\"');
  234. str=str.replace(/\0/g,'\\0');
  235. return str;
  236. }
  237. function weblogon() {
  238. steam.webLogOn(function(newCookie) {
  239. COOKIE = newCookie;
  240. offers.setup({
  241. sessionID: globalSessionID,
  242. webCookie: newCookie,
  243. APIKey: apik
  244. }, function(err){
  245. if(err){
  246. console.log(err);
  247. }
  248. var steamapi=apik;
  249. var SteamcommunityMobileConfirmations = require('steamcommunity-mobile-confirmations');
  250. var steamcommunityMobileConfirmations = new SteamcommunityMobileConfirmations(
  251. {
  252. steamid: botsteamid,
  253. identity_secret: identity_secret,
  254. device_id: "android:" + require('crypto').randomBytes(16).toString('hex'),
  255. webCookie: newCookie
  256. });
  257. setInterval(function(){
  258. steamcommunityMobileConfirmations.FetchConfirmations((function (err, confirmations)
  259. {
  260. if (err)
  261. {
  262. console.log(err);
  263. return;
  264. }
  265. if(confirmations.length>0)
  266. {
  267. console.log('[YGWEB] Potwierdzono ' + confirmations.length + ' wymian!');
  268. }
  269. if ( ! confirmations.length)
  270. {
  271. return;
  272. }
  273. steamcommunityMobileConfirmations.AcceptConfirmation(confirmations[0], (function (err, result)
  274. {
  275. if (err) {
  276. console.log(err);
  277. return;
  278. }
  279. }).bind(this));
  280. }).bind(this));
  281. }, pooling_interval);
  282. if (err)
  283. {
  284.  
  285. }
  286. });
  287. });
  288. }
  289. weblogon();
  290. function sendoffers(){
  291. detected2 = false;
  292. offers.loadMyInventory({
  293. appId: 730,
  294. contextId: 2,
  295. APIKey: apik
  296. }, function(err, itemx) {
  297. if(err) {
  298. weblogon();
  299. setTimeout(sendoffers,1000);
  300. return;
  301. }
  302. if(detected2 == true) {
  303. return;
  304. }
  305. detected2 = true;
  306. itemscopy = itemx;
  307. detected = false;
  308. mysqlConnection.query('SELECT * FROM `queue` WHERE `status`=\'active\'', function(err, row, fields) {
  309. if(err) {
  310. console.log(err);
  311. var num = 0;
  312. }
  313. if(detected == true) {
  314. return;
  315. }
  316. detected = true;
  317. for(var i=0; i < row.length; i++) {
  318. var gameid = row[i].id;
  319. var sendItems = (row[i].items).split('/');
  320. var item=[],num=0;
  321. for (var x = 0; x < itemscopy.length; x++) {
  322. for(var j=0; j < sendItems.length; j++) {
  323. if (itemscopy[x].tradable && (itemscopy[x].market_name).indexOf(sendItems[j]) == 0) {
  324. sendItems[j] = "hgjhgnhgjgnjghjjghjghjghjhgjghjghjghngnty";
  325. itemscopy[x].market_name = "fgdfgdfgdfgdfgfswfewefewrfewrewrewr";
  326. item[num] = {
  327. appid: 730,
  328. contextid: 2,
  329. amount: itemscopy[x].amount,
  330. assetid: itemscopy[x].id
  331. }
  332. num++;
  333. }
  334. }
  335. }
  336.  
  337. if (num > 0) {
  338. var gamenum = row[i].id;
  339. offers.makeOffer ({
  340. partnerSteamId: row[i].userid,
  341. itemsFromMe: item,
  342. accessToken: row[i].token,
  343. itemsFromThem: [],
  344. message: 'Congratulation! This is your winning from '+sitename+''
  345. }, function(err, response){
  346. if (err) {
  347. mysqlConnection.query('UPDATE `queue` SET `status`=\'sent '+err+'\' WHERE `id`=\''+gameid+'\'', function(err, row, fields) {});
  348. return;
  349. } else {
  350. // mysqlConnection.query('UPDATE `queue` SET `status`=\'sent '+response+'\' WHERE `id`=\''+gameid+'\'', function(err, row, fields) {});
  351. mysqlConnection.query('UPDATE `queue` SET `status`=\'sent '+response+'\'', function(err, row, fields) {});
  352. console.log('[YGWEB] Nagroda z rundy '+gamenum+' wyslana do zwycięzcy!');
  353. setTimeout(confirmS,5000);
  354. }
  355. });
  356. }
  357. }
  358. });
  359. })}
  360. (function() {
  361. /**
  362. * Decimal adjustment of a number.
  363. *
  364. * @param {String} type The type of adjustment.
  365. * @param {Number} value The number.
  366. * @param {Integer} exp The exponent (the 10 logarithm of the adjustment base).
  367. * @returns {Number} The adjusted value.
  368. */
  369. function decimalAdjust(type, value, exp) {
  370. if (typeof exp === 'undefined' || +exp === 0) {
  371. return Math[type](value);
  372. }
  373. value = +value;
  374. exp = +exp;
  375. if (isNaN(value) || !(typeof exp === 'number' && exp % 1 === 0)) {
  376. return NaN;
  377. }
  378. value = value.toString().split('e');
  379. value = Math[type](+(value[0] + 'e' + (value[1] ? (+value[1] - exp) : -exp)));
  380. value = value.toString().split('e');
  381. return +(value[0] + 'e' + (value[1] ? (+value[1] + exp) : exp));
  382. }
  383. if (!Math.round10) {
  384. Math.round10 = function(value, exp) {
  385. return decimalAdjust('round', value, exp);
  386. };
  387. }
  388. if (!Math.floor10) {
  389. Math.floor10 = function(value, exp) {
  390. return decimalAdjust('floor', value, exp);
  391. };
  392. }
  393. if (!Math.ceil10) {
  394. Math.ceil10 = function(value, exp) {
  395. return decimalAdjust('ceil', value, exp);
  396. };
  397. }
  398. })();
  399. function EndGame() {
  400. endtimer = -1;
  401. proceedWinners();
  402. setTimeout(sendoffers,1000);
  403. }
  404. steam.on('loggedOn', function(result) {
  405. console.log('[YGWEB] Steam bot - Zalogowano');
  406. steam.setPersonaState(Steam.EPersonaState.LookingToTrade);
  407. });
  408. steam.on('webSessionID', function(sessionID) {
  409. globalSessionID = sessionID;
  410. weblogon();
  411. setTimeout(function(){
  412. mysqlConnection.query('SELECT `value` FROM `info` WHERE `name`=\'current_game\'', function(err, rows, fields) {
  413. if(err) return;
  414. mysqlConnection.query('SELECT `starttime` FROM `games` WHERE `id`=\''+rows[0].value+'\'', function(errs, rowss, fieldss) {
  415. if(errs) return;
  416. var timeleft;
  417. if(rowss[0].starttime == 2147483647) timeleft = GameTime;
  418. else {
  419. var unixtime = Math.round(new Date().getTime()/1000.0);
  420. timeleft = rowss[0].starttime+GameTime-unixtime;
  421. if(timeleft < 0) timeleft = 0;
  422. }
  423. if(timeleft != GameTime) {
  424. setTimeout(EndGame,timeleft*1000);
  425. endtimer = setTimeout(EndGame,GameTime*1000);
  426. mysqlConnection.query('SELECT `value` FROM `info` WHERE `name`=\'current_game\'', function(err, row, fields){
  427. var current_game = (row[0].value);
  428. mysqlConnection.query('UPDATE IGNORE `games` SET `starttime`=UNIX_TIMESTAMP() WHERE `id` = \'' + current_game + '\'', function(err, row, fields) {});
  429. console.log('[YGWEB] Przywracamy gre z '+timeleft+' sekund!');
  430. });
  431. }
  432. });
  433. });
  434. },1500);
  435. });
  436. steam.on('friendMsg', function(steamID, message, type) {
  437. if(type != Steam.EChatEntryType.ChatMsg) return;
  438. if(steamID == admin) {
  439. if(message.indexOf("/sendallitems") == 0) {
  440. offers.loadMyInventory({
  441. appId: 730,
  442. contextId: 2,
  443. APIKey: apik
  444. }, function(err, items) {
  445. if(err) {
  446. steam.sendMessage(steamID, '[YGWEB] Próbujemy wysłać przedmioty...');
  447. weblogon();
  448. return;
  449. }
  450. var item=[],num=0;
  451. for (var i = 0; i < items.length; i++) {
  452. if (items[i].tradable) {
  453. item[num] = {
  454. appid: 730,
  455. contextid: 2,
  456. amount: items[i].amount,
  457. assetid: items[i].id
  458. }
  459. num++;
  460. }
  461. }
  462. if (num > 0) {
  463. offers.makeOffer ({
  464. partnerSteamId: steamID,
  465. itemsFromMe: item,
  466. itemsFromThem: [],
  467. message: ''
  468. }, function(err, response){
  469. if (err) {
  470. throw err;
  471. }
  472. steam.sendMessage(steamID, '[YGWEB] Oferta została wysłana z wszystkimi przedmiotami!');
  473. });
  474. }
  475. });
  476. } else if(message.indexOf("/send") == 0) {
  477. var params = message.split(' ');
  478. if(params.length == 1) return steam.sendMessage(steamID, 'Używaj /send [nazwa_przedmiotu]');
  479. offers.loadMyInventory({
  480. appId: 730,
  481. contextId: 2
  482. }, function(err, items) {
  483. if(err) {
  484. steam.sendMessage(steamID, 'Błąd z ładowaniem ekwipunku...');
  485. weblogon();
  486. return;
  487. }
  488. var item=0;
  489. for (var i = 0; i < items.length; i++) {
  490. if((items[i].market_name).indexOf(params[1]) != -1) {
  491. item = items[i].id;
  492. break;
  493. }
  494. }
  495. if (item != 0) {
  496. offers.makeOffer ({
  497. partnerSteamId: steamID,
  498. itemsFromMe: [
  499. {
  500. appid: 730,
  501. contextid: 2,
  502. amount: 1,
  503. assetid: item
  504. }
  505. ],
  506. itemsFromThem: [],
  507. message: ''
  508. }, function(err, response){
  509. if (err) {
  510. throw err;
  511. }
  512. steam.sendMessage(steamID, '[YGWEB] Oferta wysłana z przedmiotem '+item);
  513. });
  514. }
  515. });
  516. } else if(message.indexOf("/end") == 0) {
  517. steam.sendMessage(steamID,'Gra została zakończona!');
  518. if(endtimer != -1) clearTimeout(endtimer);
  519. EndGame();
  520. } else if(message.indexOf("/so") == 0) {
  521. steam.sendMessage(steamID,'Nagroday wysylamy natychmiastowo!');
  522. sendoffers();
  523. }
  524. }
  525. });
  526.  
  527. function in_array(needle, haystack, strict) {
  528. var found = false, key, strict = !!strict;
  529.  
  530. for (key in haystack) {
  531. if ((strict && haystack[key] === needle) || (!strict && haystack[key] == needle)) {
  532. found = true;
  533. break;
  534. }
  535. }
  536.  
  537. return found;
  538. }
  539.  
  540. function checkoffers(number) {
  541. if (number > 0) {
  542. offers.getOffers({
  543. get_received_offers: 1,
  544. active_only: 1,
  545. get_sent_offers: 0,
  546. get_descriptions: 1,
  547. time_historical_cutoff: Math.round(Date.now() / 1000),
  548. language: "en_us"
  549. }, function(error, body) {
  550. if(error) return;
  551. if(body.response.trade_offers_received){
  552. body.response.trade_offers_received.forEach(function(offer) {
  553. if (offer.trade_offer_state == 2){
  554. if(offer.items_to_give) {
  555. console.log('[YGWEB] Anulujemy oferte '+offer.tradeofferid);
  556. offers.declineOffer({tradeOfferId: offer.tradeofferid});
  557. return;
  558. }
  559. if(offer.items_to_receive == undefined) return;
  560. mysqlConnection.query('SELECT `value` FROM `info` WHERE `name`=\'maxitems\'', function(err, row, fields) {
  561. if(offer.items_to_receive.length > row[0].value) {
  562. offers.declineOffer({tradeOfferId: offer.tradeofferid});
  563. offer.items_to_receive = [];
  564. var unixtime = Math.round(new Date().getTime()/1000.0);
  565. console.log('[YGWEB] Oferta #'+offer.tradeofferid+' wyslana przez: '+offer.steamid_other+' anulowana! Zbyt duzo przedmiotow!');
  566. return;
  567. }
  568. });
  569. var delock = false;
  570. offers.loadPartnerInventory({partnerSteamId: offer.steamid_other, appId: 730, contextId: 2, tradeOfferId: offer.tradeofferid, language: "en"}, function(err, hitems) {
  571. if(err) {
  572. weblogon();
  573. recheck = true;
  574. return;
  575. }
  576. if(delock == true) return;
  577. delock = true;
  578. var items = offer.items_to_receive;
  579. var wgg=[],num=0;
  580. for (var i = 0; i < items.length; i++) {
  581. for(var j=0; j < hitems.length; j++) {
  582. if(items[i].assetid == hitems[j].id) {
  583. wgg[num] = hitems[j];
  584. num++;
  585. break;
  586. }
  587. }
  588. }
  589. var price=[];
  590. for(var i=0; i < num; i++) {
  591. if(wgg[i].appid != 730) {
  592. offers.declineOffer({tradeOfferId: offer.tradeofferid});
  593. console.log('[YGWEB] Items is not CSGO skins.');
  594. var unixtime = Math.round(new Date().getTime()/1000.0);
  595. return;
  596. }
  597. /* if(souvenir == 0){
  598. if(wgg[i].market_name.indexOf("Souvenir") != -1) {
  599. var unixtime = Math.round(new Date().getTime()/1000.0);
  600. offers.declineOffer({tradeOfferId: offer.tradeofferid});
  601. console.log('[SERVER] Declined offer #'+offer.tradeofferid+' - Sent by: '+offer.steamid_other+' - Reason: User sent a souvenir skin');
  602. return;
  603. }
  604. }*/
  605. var itemname = wgg[i].market_name;
  606. var url = 'http://'+sitename+'/inc/cost.php?item='+encodeURIComponent(itemname);
  607. (function(someshit) {
  608. request(url, function(error, response, body){
  609. if(!error && response.statusCode === 200){
  610. var unixtime = Math.round(new Date().getTime()/1000.0);
  611. if(body == "notfound"){
  612. console.log('[YGWEB] Oferta wyslana przez '+offer.steamid_other+' anulowana! nie mozna pobrac ceny przedmiotow!');
  613. } else {
  614. wgg[someshit].cost = parseFloat(body);
  615. }
  616. } else {
  617. console.log('[YGWEB] Oferta wyslana przez '+offer.steamid_other+' anulowana! nie mozna pobrac ceny przedmiotow!');
  618. offers.declineOffer({tradeOfferId: offer.tradeofferid});
  619. }
  620. });
  621. })(i)
  622. }
  623. setTimeout(function() {
  624. var sum=0;
  625. for(var i=0; i < num; i++) {
  626. sum += wgg[i].cost;
  627. }
  628.  
  629. var tradelink;
  630. mysqlConnection.query('SELECT tlink FROM `users` WHERE `steamid`=\''+offer.steamid_other+'\'', function(err, row, fields){
  631. tradelink= row[0].tlink;
  632. if(!tradelink){
  633. var unixtime = Math.round(new Date().getTime()/1000.0);
  634. offers.declineOffer({tradeOfferId: offer.tradeofferid});
  635. console.log('[YGWEB] Oferta wyslana przez '+offer.steamid_other+' anulowana, poniewaz nie uzupelnil on tradelinku!')
  636. return;
  637. }
  638. var token = tradelink.slice(-8);
  639.  
  640. offers.getHoldDuration({partnerSteamId: offer.steamid_other, accessToken: token}, function(err, response){
  641. if (err) {
  642. console.log('[YGWEB] Oferta wyslana przez '+offer.steamid_other+' anulowana, error!')
  643. var unixtime = Math.round(new Date().getTime()/1000.0);
  644. console.log(err);
  645. offers.declineOffer({tradeOfferId: offer.tradeofferid});
  646. return;
  647. }
  648. if(response.their==0){
  649. mysqlConnection.query('SELECT `value` FROM `info` WHERE `name`=\'current_game\'', function(err, row, fields){
  650. var current_game = (row[0].value);
  651.  
  652. mysqlConnection.query('SELECT COUNT(value) as citems FROM `game'+current_game+'` WHERE `userid`=\''+offer.steamid_other+'\'', function(err, row, fields){
  653. citems = row[0].citems;
  654. citems=citems+offer.items_to_receive.length;
  655. mysqlConnection.query('SELECT `value` FROM `info` WHERE `name`=\'maxitems\'', function(err, row, fields){
  656. var mi=row[0].value;
  657. if(citems > mi){
  658. offers.declineOffer({tradeOfferId: offer.tradeofferid});
  659. offer.items_to_receive = [];
  660. console.log('[YGWEB] Oferta wyslana przez '+offer.steamid_other+' anulowana, poniewaz wyslal on za duzo skinow!');
  661. return;
  662. }
  663. });
  664. mysqlConnection.query('SELECT SUM(value) as cmoney FROM `game'+current_game+'` WHERE `userid`=\''+offer.steamid_other+'\'', function(err, row, fields){
  665. /*cmoney = row[0].cmoney;
  666. cmoney=cmoney+sum;
  667. for(var k=0; k < num; k++){
  668. if(!is_float(wgg[k].cost)){
  669. if(err){
  670. console.log('err float');
  671. }
  672. //console.log('float');
  673. //offers.declineOffer({tradeOfferId: offer.tradeofferid});
  674. // return;
  675. }
  676. }*/
  677.  
  678.  
  679. getUserInfo(offer.steamid_other, function(error, data){
  680. // if(error) throw error;
  681. if(error) console.log('[YGWEB] ERROR: '+error);
  682. var datadec = JSON.parse(JSON.stringify(data.response));
  683. var name = addslashes(datadec.players[0].personaname);
  684. var avatar = (datadec.players[0].avatarfull);
  685. if(num == 0) return;
  686. offers.acceptOffer({tradeOfferId: offer.tradeofferid}, function(err, response) {
  687. if(err != null) return;
  688. mysqlConnection.query('SELECT `value` FROM `info` WHERE `name`=\'current_game\'', function(err, row, fields) {
  689. var current_game = (row[0].value);
  690. mysqlConnection.query('SELECT `cost`,`itemsnum` FROM `games` WHERE `id`=\''+current_game+'\'', function(err, row, fields) {
  691. var current_bank2 = parseFloat(row[0].cost);
  692. //var current_bank = parseFloat(row[0].cost).toFixed(2);
  693. var itemsnum = row[0].itemsnum;
  694. var current_bank3 = 0.00;
  695. for(var j=0; j < num; j++) {
  696. var itemn = addslashes(wgg[j].market_name);
  697. mysqlConnection.query('INSERT IGNORE INTO `game' + current_game + '` (`userid`,`username`,`item`,`color`,`value`,`avatar`,`image`,`from`,`to`) VALUES (\'' + offer.steamid_other + '\',\'' + name + '\',\'' + itemn + '\',\'' + wgg[j].name_color + '\',\'' + wgg[j].cost + '\',\'' + avatar + '\',\'' + wgg[j].icon_url + '\',\''+current_bank+'\'+\'0\',\''+current_bank+'\'+\''+wgg[j].cost+'\')', function(err, row, fields) {});
  698. io.emit('item', { userid: offer.steamid_other, username: name, item: itemn, color: wgg[j].name_color, value: wgg[j].cost, avatar: avatar, image: wgg[j].icon_url });
  699. mysqlConnection.query('UPDATE IGNORE `games` SET `itemsnum`=`itemsnum`+1, `cost`=`cost`+\''+wgg[j].cost+'\' WHERE `id` = \'' + current_game + '\'', function(err, row, fields) {});
  700. // current_bank = current_bank + wgg[j].cost;
  701. var current_bank3 = current_bank3 + current_bank2 + wgg[j].cost;
  702. itemsnum++;
  703. }
  704. var current_bank = parseFloat(current_bank3).toFixed(2);
  705. io.emit('gameinfo', { current_money: current_bank, itemsnum: itemsnum });
  706.  
  707. mysqlConnection.query('SELECT COUNT(DISTINCT userid) AS playersCount FROM `game' + current_game + '`', function(err, rows){
  708. someVar = rows[0].playersCount;
  709. console.log('[YGWEB] Graczy w puli: ' +someVar);
  710. if(someVar == 1 && items.length > 0 && endtimer==-1) {
  711. console.log('[YGWEB] Odliczanie rozpoczete!');
  712. endtimer = setTimeout(EndGame,GameTime*1000);
  713.  
  714. mysqlConnection.query('UPDATE IGNORE `games` SET `starttime`=UNIX_TIMESTAMP() WHERE `id` = \'' + current_game + '\'', function(err, row, fields) {});
  715. }
  716.  
  717. });
  718. console.log('[YGWEB] Zaakceptowano oferte #'+offer.tradeofferid+' wysylajacy '+name+'');
  719. });
  720. });
  721. });
  722. });
  723. });
  724. });
  725. });
  726. } else {
  727. console.log('[YGWEB] Gracz wysylajacy nie posiada aktywowanego ESCROW!');
  728. var unixtime = Math.round(new Date().getTime()/1000.0);
  729. offers.declineOffer({tradeOfferId: offer.tradeofferid});
  730. return;
  731. }
  732. });
  733. });
  734. },2000);
  735. });
  736. }
  737. });
  738. }
  739. });
  740. }
  741. }
  742. setInterval(sendoffers,30000);
  743. var pew;
  744. steam.on('tradeOffers', checkoffers);
  745. //setInterval(function(){
  746. // steam.on('tradeOffers', checkoffers);
  747. //}, 30000);
  748.  
  749. steam.on('sentry', function(data) {
  750. require('fs').writeFileSync('sentry_'+logOnOptions['accountName']+'.hash', data);
  751. });
  752.  
  753. console.log("[YGWEB] Potwierdzanie ofert - Zalogowano");
  754. function confirmS(){
  755. var SteamCommunity = require('steamcommunity');
  756. var SteamTotp = require('steam-totp');
  757. var code = SteamTotp.generateAuthCode('nlyt3AbVvNrBQILanB6r4QrVmlQ=');
  758. var client = new SteamCommunity();
  759. client.login({
  760. "accountName": "bartek4176",
  761. "password": "tajne",
  762. "twoFactorCode": code
  763. }, function(err, sessionId, cookies, steamguard) {
  764. var hash = require('crypto').createHash('sha1');
  765. hash.update(Math.random().toString());
  766. hash = hash.digest('hex');
  767. device_id2 = 'android:' + hash;
  768. //console.log(this.device_id2);
  769. var SteamcommunityMobileConfirmations = require('steamcommunity-mobile-confirmations');
  770. var steamcommunityMobileConfirmations = new SteamcommunityMobileConfirmations({
  771. steamid: "76561198096932160",
  772. identity_secret: "tajne=",
  773. device_id2: this.device_id2,
  774. webCookie: cookies,
  775. });
  776.  
  777. steamcommunityMobileConfirmations.FetchConfirmations((function (err, confirmations){
  778. if (err){
  779. console.log(err);
  780. return;
  781. }
  782. if(confirmations.length != 0){
  783. console.log('[YGWEB] Potwierdzono ' + confirmations.length + ' wymian');
  784. }
  785. if (!confirmations.length){
  786. return;
  787. }
  788. steamcommunityMobileConfirmations.AcceptConfirmation(confirmations[0], (function (err, result){
  789. if (err){
  790. console.log(err);
  791. return;
  792. }
  793. console.log('[YGWEB] Wynik: ' + result);
  794. }).bind(this));
  795. }).bind(this));
  796.  
  797. })
  798. }
  799. setInterval(confirmS,60000);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement