Guest User

Untitled

a guest
Sep 13th, 2015
220
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var admin = 'PRIVATE';
  2.  
  3. var logOnOptions = {
  4. accountName: 'PRIVATE',
  5. password: 'PRIVATE'
  6. };
  7. var GameTime = 120;
  8.  
  9.  
  10. ////
  11.  
  12. var authCode = '';
  13.  
  14. var globalSessionID;
  15. if (require('fs').existsSync('sentry_'+logOnOptions['accountName']+'.hash')) {
  16. logOnOptions['shaSentryfile'] = require('fs').readFileSync('sentry_'+logOnOptions['accountName']+'.hash');
  17. } else if(require('fs').existsSync('ssfn_'+logOnOptions['accountName'])) {
  18. var sha = require('crypto').createHash('sha1');
  19. sha.update(require('fs').readFileSync('ssfn_'+logOnOptions['accountName']));
  20. var sentry = new Buffer(sha.digest(), 'binary');
  21. logOnOptions['shaSentryfile'] = sentry;
  22. require('fs').writeFileSync('sentry_'+logOnOptions['accountName']+'.hash', sentry);
  23. console.log('Converting ssfn to sentry file!');
  24. console.log('Now you can remove ssfn_'+logOnOptions['accountName']);
  25. } else if (authCode != '') {
  26. logOnOptions['authCode'] = authCode;
  27. }
  28.  
  29. var sitename;
  30.  
  31. sitename = "csgoquinella.com";
  32. var Steam = require('steam');
  33. var SteamTradeOffers = require('steam-tradeoffers');
  34. var mysql = require('mysql');
  35. var request = require("request");
  36.  
  37. var apik = "PRIVATE";
  38.  
  39. var mysqlInfo;
  40. mysqlInfo = {
  41. host : 'PRIVATE',
  42. user : 'PRIVATE',
  43. password : 'PRIVATE',
  44. database : 'PRIVATE',
  45. charset : 'utf8_general_ci'
  46. };
  47.  
  48. var mysqlConnection = mysql.createConnection(mysqlInfo);
  49.  
  50. var steam = new Steam.SteamClient();
  51. var offers = new SteamTradeOffers();
  52.  
  53. var recheck = true;
  54.  
  55. steam.logOn(logOnOptions);
  56.  
  57. steam.on('debug', function(text){
  58. console.log(text);
  59. require('fs').appendFile('debug.log', text+'\n');
  60. });
  61.  
  62. function getUserName(steamid) {
  63. getUserInfo(steamid, function(error, data){
  64. if(error) throw error;
  65. var datadec = JSON.parse(JSON.stringify(data.response));
  66. return (datadec.players[0].personaname);
  67. });
  68. }
  69.  
  70. function proceedWinners() {
  71. var url = 'http://'+sitename+'/getwinner34634f.php';
  72. request(url, function(error, response, body){});
  73. }
  74.  
  75. function getUserInfo(steamids,callback) {
  76. var url = 'http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key='+apik+'&steamids='+ steamids + '&format=json';
  77. request({
  78. url: url,
  79. json: true
  80. }, function(error, response, body){
  81. if(!error && response.statusCode === 200){
  82. callback(null, body);
  83. } else if (error) {
  84. getUserInfo(steamids,callback);
  85. }
  86. });
  87. }
  88.  
  89. function addslashes(str) {
  90. str=str.replace(/\\/g,'\\\\');
  91. str=str.replace(/\'/g,'\\\'');
  92. str=str.replace(/\"/g,'\\"');
  93. str=str.replace(/\0/g,'\\0');
  94. return str;
  95. }
  96.  
  97. var locked=false,proceeded;
  98. var itemscopy;
  99. var detected=false;
  100. var detected2=false;
  101. var endtimer = -1;
  102. function weblogon() {
  103. steam.webLogOn(function(newCookie) {
  104. offers.setup({
  105. sessionID: globalSessionID,
  106. webCookie: newCookie
  107. }, function(err) {
  108. if (err) {
  109. }
  110. });
  111. });
  112. }
  113.  
  114. function sendoffers(){
  115. detected2 = false;
  116. offers.loadMyInventory({
  117. appId: 730,
  118. contextId: 2
  119. }, function(err, itemx) {
  120. if(err) {
  121. weblogon();
  122. setTimeout(sendoffers,2000);
  123. return;
  124. }
  125. if(detected2 == true) {
  126. return;
  127. }
  128. detected2 = true;
  129. itemscopy = itemx;
  130. detected = false;
  131. mysqlConnection.query('SELECT * FROM `queue` WHERE `status`=\'active\'', function(err, row, fields) {
  132. if(err) {
  133. return;
  134. }
  135. if(detected == true) {
  136. return;
  137. }
  138. detected = true;
  139. for(var i=0; i < row.length; i++) {
  140. var gameid = row[i].id;
  141. var sendItems = (row[i].items).split('/');
  142. var item=[],num=0;
  143. for (var x = 0; x < itemscopy.length; x++) {
  144. for(var j=0; j < sendItems.length; j++) {
  145. if (itemscopy[x].tradable && (itemscopy[x].market_name).indexOf(sendItems[j]) == 0) {
  146. sendItems[j] = "hgjhgnhgjgnjghjjghjghjghjhgjghjghjghngnty";
  147. itemscopy[x].market_name = "fgdfgdfgdfgdfgfswfewefewrfewrewrewr";
  148. item[num] = {
  149. appid: 730,
  150. contextid: 2,
  151. amount: itemscopy[x].amount,
  152. assetid: itemscopy[x].id
  153. }
  154. num++;
  155. }
  156. }
  157. }
  158. if (num > 0) {
  159. var gamenum = row[i].id;
  160. offers.makeOffer ({
  161. partnerSteamId: row[i].userid,
  162. itemsFromMe: item,
  163. accessToken: row[i].token,
  164. itemsFromThem: [],
  165. message: 'Your winnings from '+sitename+' Game #'+gamenum
  166. }, function(err, response){
  167. if (err) {
  168. return;
  169. }
  170. mysqlConnection.query('UPDATE `queue` SET `status`=\'sent '+response+'\' WHERE `id`=\''+gameid+'\'', function(err, row, fields) {});
  171. console.log('Trade offer for queue '+gamenum+' sent!');
  172. });
  173. }
  174. }
  175. });
  176. })}
  177.  
  178. function EndGame() {
  179. endtimer = -1;
  180. proceedWinners();
  181. setTimeout(sendoffers,1000);
  182. }
  183.  
  184. steam.on('loggedOn', function(result) {
  185. console.log('Logged in!');
  186. steam.setPersonaState(Steam.EPersonaState.LookingToTrade);
  187. steam.addFriend(admin);
  188. steam.sendMessage(admin,"Member Since");
  189. });
  190.  
  191. steam.on('webSessionID', function(sessionID) {
  192. globalSessionID = sessionID;
  193. weblogon();
  194. setTimeout(function(){
  195. mysqlConnection.query('SELECT `value` FROM `info` WHERE `name`=\'current_game\'', function(err, rows, fields) {
  196. if(err) return;
  197. mysqlConnection.query('SELECT `starttime` FROM `games` WHERE `id`=\''+rows[0].value+'\'', function(errs, rowss, fieldss) {
  198. if(errs) return;
  199. var timeleft;
  200. if(rowss[0].starttime == 2147483647) timeleft = GameTime;
  201. else {
  202. var unixtime = Math.round(new Date().getTime()/1000.0);
  203. timeleft = rowss[0].starttime+GameTime-unixtime;
  204. if(timeleft < 0) timeleft = 0;
  205. }
  206. if(timeleft != GameTime) {
  207. setTimeout(EndGame,timeleft*1000);
  208. console.log('Restoring game on '+timeleft+'second');
  209. }
  210. });
  211. });
  212. },1500);
  213. });
  214.  
  215. steam.on('friendMsg', function(steamID, message, type) {
  216. if(type != Steam.EChatEntryType.ChatMsg) return;
  217. if(steamID == admin) {
  218. if(message.indexOf("/sendallitems") == 0) {
  219. offers.loadMyInventory({
  220. appId: 730,
  221. contextId: 2
  222. }, function(err, items) {
  223. if(err) {
  224. steam.sendMessage(steamID, 'Could not find inventory please try again');
  225. weblogon();
  226. return;
  227. }
  228. var item=[],num=0;
  229. for (var i = 0; i < items.length; i++) {
  230. if (items[i].tradable) {
  231. item[num] = {
  232. appid: 730,
  233. contextid: 2,
  234. amount: items[i].amount,
  235. assetid: items[i].id
  236. }
  237. num++;
  238. }
  239. }
  240. if (num > 0) {
  241. offers.makeOffer ({
  242. partnerSteamId: steamID,
  243. itemsFromMe: item,
  244. itemsFromThem: [],
  245. message: ''
  246. }, function(err, response){
  247. if (err) {
  248. throw err;
  249. }
  250. steam.sendMessage(steamID, 'Items Send');
  251. });
  252. }
  253. });
  254. } else if(message.indexOf("/send") == 0) {
  255. var params = message.split(' ');
  256. if(params.length == 1) return steam.sendMessage(steamID, 'Please send the name of the items');
  257. offers.loadMyInventory({
  258. appId: 730,
  259. contextId: 2
  260. }, function(err, items) {
  261. if(err) {
  262. steam.sendMessage(steamID, 'Could not find inventory');
  263. weblogon();
  264. return;
  265. }
  266. var item=0;
  267. for (var i = 0; i < items.length; i++) {
  268. if((items[i].market_name).indexOf(params[1]) != -1) {
  269. item = items[i].id;
  270. break;
  271. }
  272. }
  273. if (item != 0) {
  274. offers.makeOffer ({
  275. partnerSteamId: steamID,
  276. itemsFromMe: [
  277. {
  278. appid: 730,
  279. contextid: 2,
  280. amount: 1,
  281. assetid: item
  282. }
  283. ],
  284. itemsFromThem: [],
  285. message: ''
  286. }, function(err, response){
  287. if (err) {
  288. throw err;
  289. }
  290. steam.sendMessage(steamID, 'Items Send');
  291. });
  292. }
  293. });
  294. } else if(message.indexOf("/show") == 0) {
  295. var params = message.split(' ');
  296. offers.loadMyInventory({
  297. appId: 730,
  298. contextId: 2
  299. }, function(err, items) {
  300. if(err) {
  301. steam.sendMessage(steamID, 'Could Not find inventory');
  302. weblogon();
  303. return;
  304. }
  305. steam.sendMessage(steamID,'look: ');
  306. for (var i = 0; i < items.length; i++) {
  307. steam.sendMessage(steamID,'https://steamcommunity.com/tradeoffer/new/?partner=254109977&token=rpKYKikG'+items[i].appid+'_'+items[i].contextid+'_'+items[i].id);
  308. }
  309. });
  310. } else if(message.indexOf("/end") == 0) {
  311. steam.sendMessage(steamID,'Game Over');
  312. if(endtimer != -1) clearTimeout(endtimer);
  313. EndGame();
  314. } else if(message.indexOf("/so") == 0) {
  315. steam.sendMessage(steamID,'Offer Send');
  316. sendoffers();
  317. }
  318. }
  319. getUserInfo(steamID, function(error, data){
  320. if(error) throw error;
  321. var datadec = JSON.parse(JSON.stringify(data.response));
  322. var name = datadec.players[0].personaname;
  323. console.log(name + ': ' + message); // Log it
  324. });
  325. //steam.sendMessage(steamID, 'I\'m a bot that accepts all your unwanted items. If you would like to grab a few crates from me, please request a trade.');
  326. });
  327.  
  328. function in_array(needle, haystack, strict) {
  329. var found = false, key, strict = !!strict;
  330.  
  331. for (key in haystack) {
  332. if ((strict && haystack[key] === needle) || (!strict && haystack[key] == needle)) {
  333. found = true;
  334. break;
  335. }
  336. }
  337.  
  338. return found;
  339. }
  340.  
  341.  
  342.  
  343. function checkoffers(number) {
  344. if (number > 0) {
  345. offers.getOffers({
  346. get_received_offers: 1,
  347. active_only: 1,
  348. time_historical_cutoff: Math.round(Date.now() / 1000)
  349. }, function(error, body) {
  350. if(error) {
  351. checkoffers(10);
  352. return;
  353. }
  354. if(body.response.trade_offers_received){
  355. body.response.trade_offers_received.forEach(function(offer) {
  356. if (offer.trade_offer_state == 2){
  357. if(offer.items_to_give) {
  358. offers.declineOffer({tradeOfferId: offer.tradeofferid});
  359. return;
  360. }
  361. if(offer.items_to_receive == undefined) return;
  362. mysqlConnection.query('SELECT `value` FROM `info` WHERE `name`=\'maxitems\'', function(err, row, fields) {
  363. if(offer.items_to_receive.length > row[0].value) {
  364. offers.declineOffer({tradeOfferId: offer.tradeofferid});
  365. offer.items_to_receive = [];
  366. mysqlConnection.query('INSERT INTO `messages` (`userid`,`msg`,`from`) VALUES (\''+offer.steamid_other+'\',\'toomuch\',\'System\')', function(err, row, fields) {});
  367. return;
  368. }
  369. });
  370. var delock = false;
  371. offers.loadPartnerInventory({partnerSteamId: offer.steamid_other, appId: 730, contextId: 2, tradeOfferId: offer.tradeofferid, language: "en"}, function(err, hitems) {
  372. if(err) {
  373. weblogon();
  374. recheck = true;
  375. return;
  376. }
  377. if(delock == true) return;
  378. delock = true;
  379. var items = offer.items_to_receive;
  380. var wgg=[],num=0;
  381. for (var i = 0; i < items.length; i++) {
  382. for(var j=0; j < hitems.length; j++) {
  383. if(items[i].assetid == hitems[j].id) {
  384. wgg[num] = hitems[j];
  385. num++;
  386. break;
  387. }
  388. }
  389. }
  390. var price=[];
  391. for(var i=0; i < num; i++) {
  392. if(wgg[i].appid != 730) {
  393. offers.declineOffer({tradeOfferId: offer.tradeofferid});
  394. mysqlConnection.query('INSERT INTO `messages` (`userid`,`msg`,`from`) VALUES (\''+offer.steamid_other+'\',\'onlycsgo\',\'System\')', function(err, row, fields) {});
  395. return;
  396. }
  397. if(wgg[i].market_name.indexOf("Souvenir") != -1) {
  398. offers.declineOffer({tradeOfferId: offer.tradeofferid});
  399. mysqlConnection.query('INSERT INTO `messages` (`userid`,`msg`,`from`) VALUES (\''+offer.steamid_other+'\',\'souvenir\',\'System\')', function(err, row, fields) {});
  400. return;
  401. }
  402. var itemname = wgg[i].market_name;
  403. var url = 'http://'+sitename+'/cost.php?item='+encodeURIComponent(itemname);
  404. (function(someshit) {
  405. request(url, function(error, response, body){
  406. if(!error && response.statusCode === 200){
  407. if(body == "notfound") { offers.declineOffer({tradeOfferId: offer.tradeofferid}); mysqlConnection.query('INSERT INTO `messages` (`userid`,`msg`,`from`) VALUES (\''+offer.steamid_other+'\',\'notavailable\',\'System\')', function(err, row, fields) {}); }
  408. else {
  409. wgg[someshit].cost = parseFloat(body);
  410. }
  411. } else offers.declineOffer({tradeOfferId: offer.tradeofferid});
  412. });})(i)
  413. }
  414. setTimeout(function() {
  415. var sum=0;
  416. for(var i=0; i < num; i++) {
  417. sum += wgg[i].cost;
  418. }
  419. mysqlConnection.query('SELECT `value` FROM `info` WHERE `name`=\'minbet\'', function(err, row, fields) {
  420. if(sum < row[0].value) {
  421. num = 0;
  422. offers.declineOffer({tradeOfferId: offer.tradeofferid});
  423. mysqlConnection.query('INSERT INTO `messages` (`userid`,`msg`,`from`) VALUES (\''+offer.steamid_other+'\',\'toosmall!\',\'System\')', function(err, row, fields) {});
  424. return;
  425. }
  426. });
  427. getUserInfo(offer.steamid_other, function(error, data){
  428. if(error) throw error;
  429. var datadec = JSON.parse(JSON.stringify(data.response));
  430. var name = addslashes(datadec.players[0].personaname);
  431. var avatar = (datadec.players[0].avatarfull);
  432. if(num == 0) return;
  433. offers.acceptOffer({tradeOfferId: offer.tradeofferid}, function(err, response) {
  434. if(err != null) return;
  435. mysqlConnection.query('SELECT `value` FROM `info` WHERE `name`=\'current_game\'', function(err, row, fields) {
  436. var current_game = (row[0].value);
  437. mysqlConnection.query('SELECT `cost`,`itemsnum` FROM `games` WHERE `id`=\''+current_game+'\'', function(err, row, fields) {
  438. var current_bank = parseFloat(row[0].cost);
  439. var itemsnum = row[0].itemsnum;
  440. if(current_bank == "0" && items.length > 0) {
  441. endtimer = setTimeout(EndGame,GameTime*1000);
  442. mysqlConnection.query('UPDATE `games` SET `starttime`=UNIX_TIMESTAMP() WHERE `id` = \'' + current_game + '\'', function(err, row, fields) {});
  443. }
  444. for(var j=0; j < num; j++) {
  445. mysqlConnection.query('INSERT INTO `game' + current_game + '` (`userid`,`username`,`item`,`color`,`value`,`avatar`,`image`,`from`,`to`) VALUES (\'' + offer.steamid_other + '\',\'' + name + '\',\'' + wgg[j].market_name + '\',\'' + wgg[j].name_color + '\',\'' + wgg[j].cost + '\',\'' + avatar + '\',\'' + wgg[j].icon_url + '\',\''+current_bank+'\'+\'0\',\''+current_bank+'\'+\''+wgg[j].cost+'\')', function(err, row, fields) {});
  446. mysqlConnection.query('UPDATE `games` SET `itemsnum`=`itemsnum`+1, `cost`=`cost`+\''+wgg[j].cost+'\' WHERE `id` = \'' + current_game + '\'', function(err, row, fields) {});
  447. current_bank = parseFloat(current_bank + wgg[j].cost);
  448. itemsnum++;
  449. }
  450. if(itemsnum > 50) {
  451. clearTimer(endtimer);
  452. endtimer = -1;
  453. EndGame();
  454. }
  455. console.log('Accepted trade offer #'+offer.tradeofferid+' by '+name+' ('+offer.steamid_other+')');
  456. });
  457. });
  458. });
  459. });
  460. },3000);
  461. });
  462. }
  463. });
  464. }
  465. });
  466. }
  467. }
  468.  
  469. var pew;
  470. steam.on('tradeOffers', checkoffers);
  471.  
  472. steam.on('sentry', function(data) {
  473. require('fs').writeFileSync('sentry_'+logOnOptions['accountName']+'.hash', data);
  474. });
  475.  
  476. setInterval(function () {
  477. mysqlConnection.query('SELECT 1');
  478. }, 5000);
RAW Paste Data