Advertisement
Guest User

skinup.gg crash

a guest
Feb 17th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.48 KB | None | 0 0
  1. $(function() {
  2. "use strict";
  3. window.crash = {
  4. _chartBox: $(".box-chart"),
  5. _chart: $(".chart"),
  6. _chartInfo: $(".chart-info"),
  7. _roundHash: $(".round-hash"),
  8. _roundInfo: $(".round-info"),
  9. _bets: $(".box-bets table"),
  10. _betCoins: $('#bet-coins'),
  11. _betCashout: $('#bet-cashout'),
  12. _pattern: 0.0006,
  13. _pointsPerSec: 20,
  14. minBet: 100,
  15. maxBet: 100000,
  16. _data: [],
  17. _i: null,
  18. _now: null,
  19. _started: false,
  20. interval: false,
  21. _myBet: 0,
  22. multiplier: false,
  23. _status: null,
  24. autobetSettings: {},
  25. _options: {
  26. xaxis: {
  27. show: false
  28. },
  29. grid: {
  30. borderColor: "white",
  31. borderWidth: {
  32. top: 0,
  33. right: 0,
  34. left: 2,
  35. bottom: 2
  36. }
  37. },
  38. yaxis: {
  39. min: 1,
  40. tickFormatter: function(val) {
  41. if (val==1) return '';
  42. return '<span style="color: white; font-weight: bold">'+val.toFixed(1)+'x</span>';
  43. }
  44. },
  45. colors: []
  46. },
  47. colors: {
  48. red: '#d53131',
  49. green: '#88e685'
  50. },
  51. set status(x) {
  52. this._status = x;
  53.  
  54. this.state = x;
  55. },
  56. get status() {
  57. return this._status;
  58. },
  59. setWay: function (ele) {
  60. $('[class*="-way-content"]', this._bet).hide();
  61. $('.way div', this._bet).removeClass('active');
  62. $(ele).addClass('active');
  63. $('.'+$(ele).data('show')+'-way-content').show();
  64. },
  65. init: function () {
  66. this._options.yaxis.max = 1.26;
  67. this._options.xaxis.max = 10;
  68. this._roundInfo.hide();
  69. this._chartInfo
  70. .text("Connecting...");
  71. this.status = 'connecting';
  72. this.draw();
  73.  
  74. this.astate = "idle";
  75. },
  76. draw: function () {
  77. $.plot(this._chart, [ {data: this._data, lines: {fill: true}} ], this._options);
  78. },
  79. resize: function () {
  80. this.draw();
  81. },
  82. countDown: function(time) {
  83. this.status = 'timeToStart';
  84. this._chartInfo
  85. .removeClass("crash-info play-info")
  86. .text("Start in "+time+"s...");
  87.  
  88. var countDownInterval = setInterval(function () {
  89. time -= 0.1;
  90. if (time < 0.1) {
  91. this.status = 'preparingStart';
  92. clearInterval(countDownInterval);
  93. this._chartInfo
  94. .text("Preparing round...");
  95. } else {
  96. this.status = 'timeToStart';
  97. this._chartInfo
  98. .text("Start in "+time.toFixed(1)+"s...");
  99. }
  100. }.bind(this), 100);
  101. },
  102. crash_info: function (data) {
  103. this.countDown(data.start_in);
  104.  
  105. this._hash = data.hash;
  106. this._roundHash.text(data.hash);
  107. this._roundInfo.fadeIn(500);
  108.  
  109.  
  110. this._myBet = 0;
  111.  
  112. $('.player-bet').remove();
  113. data.players.forEach(function (prop) {
  114. crash.player_bet(prop);
  115. });
  116.  
  117. this._data = [];
  118. this._options.xaxis.max = 10;
  119. this._options.yaxis.max = 1.26;
  120. this._started = false;
  121.  
  122. this.draw();
  123. },
  124. crash_start: function (data) {
  125. cancelAnimationFrame(this.interval);
  126. this._i = 0;
  127. this._data = [ [0,1] ];
  128. this._options.xaxis.max = 10;
  129. this._options.yaxis.max = 1.26;
  130. this._options.colors[0] = this.colors.green;
  131. this._now = 1;
  132. this._dateStart = new Date().getTime() - data.time;
  133. this._chartInfo
  134. .removeClass("crash-info")
  135. .addClass("play-info");
  136. this.crash_draw(data.multiplier);
  137. },
  138. crash_draw: function (multiplier) {
  139. this.status = 'game';
  140. multiplier = multiplier || false;
  141. cancelAnimationFrame(this.interval);
  142.  
  143. this._time = (new Date().getTime() - this._dateStart);
  144.  
  145. while(this._now < Math.pow(Math.E, this._pattern * this._time)) {
  146. this.crash_add();
  147. }
  148.  
  149. this._options.xaxis.max = Math.max(this._i*1.1, 5000/this._pointsPerSec);
  150. this._options.yaxis.max = Math.max(this._now*1.1, 2);
  151. this._chartInfo.text(this._now.toFixed(2)+'x');
  152. this.multiplier = parseFloat(this._now);
  153.  
  154. if (multiplier !== false && 0.95 > Math.floor(parseFloat(multiplier)*100) / Math.floor(parseFloat(this._now)*100) || Math.floor(parseFloat(multiplier)*100) / Math.floor(parseFloat(this._now)*100) > 1.05) {
  155. console.log('Synchronization is not fully correct. Local: ' + Math.floor(parseFloat(this._now)*100)/100 + ', server: ' + Math.floor(parseFloat(multiplier)*100)/100);
  156. }
  157.  
  158. this.draw();
  159.  
  160. this.interval = requestAnimationFrame(function () {
  161. this.crash_draw(false);
  162. }.bind(this));
  163. },
  164. crash_add: function() {
  165. this._i++;
  166. this._now = parseFloat( Math.pow(Math.E, this._pattern * this._i * 1000/this._pointsPerSec) );
  167. this._data.push([ this._i, this._now ]);
  168. },
  169. crash_end: function (data) {
  170. cancelAnimationFrame(this.interval);
  171. this.status = 'crash';
  172. this._options.colors[0] = this.colors.red;
  173. this._chartInfo
  174. .removeClass("play-info")
  175. .addClass("crash-info")
  176. .html('Crashed!<br>'+parseFloat(data.multiplier).toFixed(2)+'x');
  177. this.draw();
  178. data.time = Date.now();
  179. this.history(data);
  180.  
  181. $('.box-bets tr:not(.win)[data-steamid]').each(function() {
  182. var _div = $(this);
  183. var _bet = parseInt(_div.data('bet'));
  184. var _multi = $('td:nth-child(3)', _div);
  185. var _profit = $('td:nth-child(4)', _div);
  186.  
  187. _div.attr('data-profit', _bet*-1);
  188. _multi.text('-');
  189. _profit.text(_bet*-1);
  190. _div.addClass('lose');
  191. });
  192.  
  193. this.player_sort('profit');
  194.  
  195. setTimeout(function() {
  196. if(this.status != 'crash') return;
  197. this.status = 'preparingNext';
  198. this._data = [];
  199. this._chartInfo
  200. .removeClass("crash-info play-info")
  201. .text("Preparing next round...");
  202. $('.box-bets tr:not(:first-child)').fadeOut(500, function() {
  203. $(this).remove();
  204. });
  205. this._roundInfo.fadeOut(500);
  206. this.draw();
  207. }.bind(this), 4000);
  208. },
  209. player_bet: function (data) {
  210. $('<tr class="player-bet' + (data.multiplier ? ' win' : '') + (data.profile.steamid == steamid ? ' my' : '') + '" data-steamid="'+data.profile.steamid+'" data-bet="'+data.bet+'">' +
  211. '<td><img src="'+data.profile.avatar+'"> '+data.profile.username+'</td>' +
  212. '<td>'+data.bet+'</td>' +
  213. '<td>' + (data.multiplier ? parseFloat(data.multiplier).toFixed(2) : '?') + '</td>' +
  214. '<td>' + (data.multiplier ? Math.floor(parseInt(data.bet, 10) * parseFloat(data.multiplier) - parseInt(data.bet, 10)) : '?') + '</td>' +
  215. '</tr>')
  216. .appendTo(this._bets)
  217. .hide()
  218. .fadeIn(500);
  219. this.player_sort('bet');
  220. },
  221. player_drop: function (steamid, multiplier) {
  222. var _div = $('tr[data-steamid="'+steamid+'"]', this._bets);
  223. var _bet = parseInt(_div.data('bet'));
  224. var _multi = $('td:nth-child(3)', _div);
  225. var _profit = $('td:nth-child(4)', _div);
  226. var profit = Math.round(parseFloat(multiplier) * _bet - _bet);
  227.  
  228. _div.attr('data-profit', profit);
  229. _multi.text(multiplier+'x');
  230. _profit.text(profit);
  231. _div.removeClass('lose').addClass('win');
  232. },
  233. player_sort: function (sort) {
  234. this._bets
  235. .find('tr[data-bet]')
  236. .sort(function(a, b) {
  237. return +b.dataset[sort] - +a.dataset[sort];
  238. })
  239. .appendTo(this._bets);
  240. },
  241. verify: function(hash, secret, multiplier) {
  242. if (hash && secret && multiplier) {
  243. var shaObj = new jsSHA("SHA-256", "TEXT");
  244. shaObj.setHMACKey(secret, "TEXT");
  245. shaObj.update(multiplier.toString());
  246. if (hash === shaObj.getHMAC("HEX")) {
  247. notify('success', 'Hashes does match!');
  248. } else {
  249. notify('error', 'Hashes doesn\'t match!');
  250. }
  251. }
  252. else notify("error", "Hashes doesn\'t match!");
  253. },
  254.  
  255. bet: function () {
  256. var self = crash;
  257. if (self.status == 'game' && self._myBet > 0) {
  258. socket.emit('crash withdraw');
  259.  
  260. self.state = 'can';
  261.  
  262. self._myBet = 0;
  263. } else {
  264. var coins = parseInt(self._betCoins.val());
  265. var cashout = parseFloat(self._betCashout.val());
  266. var error = false;
  267.  
  268. if (coins < self.minBet) return notify('error', vsprintf(locale['crashMinBet'], [coins, self.minBet]));
  269. if (coins > self.maxBet) return notify('error', vsprintf(locale['crashMaxBet'], [coins, self.maxBet]));
  270.  
  271. self._betCoins.removeClass('error');
  272. self._betCashout.removeClass('error');
  273.  
  274. if (isNaN(coins) || coins < 1) {
  275. self._betCoins.addClass('error');
  276. error = true;
  277. }
  278.  
  279. if (isNaN(cashout) || cashout < 1) {
  280. cashout = '';
  281. }
  282.  
  283. if (error) return;
  284.  
  285. self._betCoins.val(coins);
  286. self._betCashout.val(cashout);
  287. self._myBet = coins;
  288. socket.emit('crash bet', {
  289. bet: coins,
  290. cashout: cashout
  291. });
  292. }
  293. },
  294. _state: "",
  295. _astate: "",
  296. get state() {
  297. return this._state;
  298. },
  299. set state(x) {
  300. this._state = x;
  301. var disabled = false;
  302. var text = 'undefined state ('+x+')';
  303.  
  304. switch(x) {
  305. case 'connecting':
  306. text = 'Connecting...';
  307. disabled = true;
  308. break;
  309. case 'can':
  310. case 'timeToStart':
  311. if (this._myBet > 0) {
  312. text = 'Placed ('+this._myBet+')';
  313. disabled = true;
  314. } else {
  315. text = 'Place bet';
  316. }
  317.  
  318. break;
  319. case 'preparingStart':
  320. case 'preparingNext':
  321. text = 'Preparing round...';
  322. disabled = true;
  323. break;
  324. case 'game':
  325. if (this._myBet == 0) {
  326. text = 'Wait for next round...';
  327. disabled = true;
  328. } else {
  329. text = 'Withdraw '+(this.multiplier !== false ? '('+Math.floor( this._myBet*this.multiplier )+')':'');
  330. }
  331. break;
  332. case 'crash':
  333. text = 'Wait for next round...';
  334. disabled = true;
  335. break;
  336. }
  337.  
  338. $('.bet-butt')
  339. .prop('disabled', disabled)
  340. .text(text);
  341. },
  342. get astate() {
  343. return this._astate;
  344. },
  345. set astate(x) {
  346. var butt = $('.autobet-butt');
  347. this._astate = x;
  348.  
  349. switch (x) {
  350. case 'idle':
  351. butt.text('START AUTO BET');
  352. break;
  353. case 'working':
  354. butt.text('STOP AUTO BET');
  355. break;
  356. default:
  357. butt.text("UNDEFINED STATE OF BUTTON");
  358. console.log("UNDEFINED STATE OF BUTTON", x);
  359. }
  360. },
  361. autobet: function() {
  362. var self = crash;
  363.  
  364. if (self.astate == 'idle') {
  365. self.autobetSettings = {
  366. base: parseInt($('#autobet-coins').val()),
  367. cashout: parseFloat($('#autobet-cashout').val()),
  368. stop: parseInt($('#autobet-limit').val()),
  369. onLose: ($('#autobet-on-lose-multiply-select').prop('checked') ? parseFloat($('#autobet-on-lose-multiply').val()) : 0),
  370. onWin: ($('#autobet-on-win-multiply-select').prop('checked') ? parseFloat($('#autobet-on-win-multiply').val()) : 0),
  371. maxBets: parseInt($('#autobet-max-bets').val())
  372. };
  373.  
  374. self.autobetProps = {
  375. betsDone: 0,
  376. betsLeft: (self.autobetSettings.maxBets === 0 || isNaN(self.autobetSettings.maxBets) ? null : self.autobetSettings.maxBets),
  377. lastResult: null,
  378. lastValue: null
  379. };
  380.  
  381. self.autobetStart();
  382. } else {
  383. self.autobetStop();
  384. }
  385. },
  386. autobetStart: function() {
  387. var self = crash;
  388.  
  389. self.astate = 'working';
  390.  
  391. if (self.status === 'timeToStart' && self._myBet === 0) {
  392. self.autobetPlay(self.autobetSettings.base, self.autobetSettings.cashout);
  393. } else {
  394. self.autobetSetEvents();
  395. }
  396. },
  397. autobetSetEvents: function() {
  398. var self = crash;
  399.  
  400. console.log('[Autobet] Setting events!');
  401.  
  402. socket.removeListener('crash info', self.autobetInfoListener);
  403.  
  404. if (self.autobetProps.betsDone > 0) {
  405. socket.once('crash end', function(data) {
  406. console.log('[Autobet] Game end!');
  407.  
  408. if (data.multiplier > self.autobetSettings.cashout) {
  409. console.log('[Autobet] Result: win!');
  410. self.autobetProps.lastResult = 'win';
  411. self.autobetInfoListener = function(data) {
  412. console.log('[Autobet] Game start!');
  413. self.autobetPlay((self.autobetSettings.onWin == 0 ? self.autobetSettings.base : self.autobetProps.lastValue * self.autobetSettings.onWin), self.autobetSettings.cashout);
  414. };
  415. } else if (data.multiplier < self.autobetSettings.cashout) {
  416. console.log('[Autobet] Result: lose!');
  417. self.autobetProps.lastResult = 'lose';
  418. self.autobetInfoListener = function(data) {
  419. console.log('[Autobet] Game start!');
  420. self.autobetPlay((self.autobetSettings.onLose == 0 ? self.autobetSettings.base : self.autobetProps.lastValue * self.autobetSettings.onLose), self.autobetSettings.cashout);
  421. };
  422. }
  423.  
  424. socket.once('crash info', self.autobetInfoListener);
  425. });
  426. } else {
  427. self.autobetInfoListener = function(data) {
  428. console.log('[Autobet] Game start!');
  429. self.autobetPlay(self.autobetSettings.base, self.autobetSettings.cashout);
  430. };
  431.  
  432. socket.once('crash info', self.autobetInfoListener);
  433. }
  434. },
  435. autobetPlay: function(value, cashout) {
  436. var self = crash;
  437. if (self.astate !== 'working') return;
  438. if (self.autobetProps.betsLeft === 0 || self.autobetSettings.stop && value > self.autobetSettings.stop || value > $('.balance').data('balance')) return self.autobetStop();
  439.  
  440. console.log('[Autobet] Playing ' + value + ' coins, cashout: ' + cashout);
  441.  
  442. socket.emit('crash bet', {
  443. bet: value,
  444. cashout: cashout
  445. });
  446.  
  447. self.autobetProps.betsDone++;
  448. self.autobetProps.lastValue = value;
  449. if (self.autobetProps.betsLeft) self.autobetProps.betsLeft--;
  450.  
  451. self.autobetSetEvents();
  452. },
  453. autobetStop: function() {
  454. var self = crash;
  455. self.astate = 'idle';
  456. socket.removeListener('crash info', self.autobetInfoListener);
  457. },
  458. history: function (game) {
  459. var bet_class = '';
  460. if (game.multiplier < 1.😎 bet_class = 'lose';
  461. else if (game.multiplier > 2) bet_class = 'win';
  462.  
  463. var date = new Date(game.time);
  464. var time = '';
  465.  
  466. time += (date.getHours() < 10 ? '0' : '') + date.getHours();
  467. time += ':' + (date.getMinutes() < 10 ? '0' : '') + date.getMinutes();
  468.  
  469. $('<div class="'+bet_class+'"><time class="date">' + time + '</time><span class="multiplier">' + parseFloat(game.multiplier).toFixed(2) + 'x</span></div>').prependTo($('.history'));
  470. }
  471. };
  472. crash.init();
  473.  
  474. $(window).resize(crash.resize.bind(crash));
  475.  
  476.  
  477. socket.on('crash info', function(data) {
  478. crash.crash_info(data);
  479. });
  480.  
  481. socket.on('crash start', function(data) {
  482. if (_soundOn) new buzz.sound("/sounds/crashstart.mp3").play();
  483. crash.crash_start(data);
  484. });
  485.  
  486. socket.on('crash tick', function(data) {
  487. crash.crash_start(data);
  488. });
  489.  
  490. socket.on('crash end', function(data) {
  491. crash.crash_end(data);
  492. });
  493.  
  494. socket.on('crash history', function(history) {
  495. history.forEach(function (prop) {
  496. crash.history(prop);
  497. });
  498. });
  499.  
  500. socket.on('player drop', function(data) {
  501. crash.player_drop(data.profile.steamid, data.multiplier);
  502. });
  503.  
  504. socket.on('player new', function(bet) {
  505. bet.forEach(function (prop) {
  506. crash.player_bet(prop);
  507. });
  508. });
  509.  
  510. socket.on('crash my bet', function(bet) {
  511. crash._myBet = bet;
  512. });
  513.  
  514. socket.on('crash settings', function(data) {
  515. if (data.minBet) {
  516. crash.minBet = data.minBet;
  517. $('.min-bet').text(data.minBet.toString().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,"));
  518. }
  519. if (data.maxBet) {
  520. crash.maxBet = data.maxBet;
  521. $('.max-bet').text(data.maxBet.toString().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,"));
  522. }
  523. });
  524. setInterval(function() {
  525. $('time.timeAgo').each(function(i, el) {
  526. $(el).text(jQuery.timeago($(el).data('time')));
  527. });
  528. }, 1000);
  529. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement