Skip to content

Conversation

@Gowdareddydn
Copy link

<title>bc.game Crash - Game Verification Script by bcgame</title> <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js"></script> <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/crypto-js.min.js"></script> <style> *, body, button, input, textarea, select { text-rendering: optimizeLegibility; -moz-osx-font-smoothing: grayscale; } body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,fieldset,input,textarea,p,blockquote,th,td { margin:0; padding:0; } table { border-collapse:collapse; border-spacing:0; } fieldset,img { border:0; } address,caption,cite,code,dfn,em,strong,th,var { font-style:normal; font-weight:normal; } ol,ul { list-style:none; } caption,th { text-align:left; } h1,h2,h3,h4,h5,h6 { font-size:100%; font-weight:normal; } q:before,q:after { content:''; } abbr,acronym { border:0;} </style> <style type="text/css"> table { table-layout: fixed; } table thead tr th:first-child { width: 80%; } table tbody tr td { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } .is-first { background-color: rgba(195, 111, 24, 0.2); } .is-over-median { color: #44B39D; } .is-at-median { color: #3B3C3D; } .is-under-median { color: #BF4A67; } </style>

bc.game Crash - Game Verification Script

Third party script used to verify games on crash game.



Game's hash Bust
<script type="text/javascript"> var isVerifying = false; $('#game_verify_submit').on('click', () => { if (isVerifying) return; isVerifying = true; $('#game_hash_input').parent().addClass('is-loading'); $('#game_verify_submit').addClass('is-loading'); $('#game_hash_input, #game_amount_input, #game_verify_submit').attr('disabled', 'disabled'); $('#game_verify_table').html('');
    let prevHash = null;
    for (let i = 0; i < $('#game_amount_input').val(); i++) {
      let hash = String(prevHash ? CryptoJS.SHA256(String(prevHash)) : $('#game_hash_input').val());
      let bust = gameResult(hash);

      setTimeout(function() {
        addTableRow(hash, bust, i)
      }, i * 1);

      prevHash = hash;
    }
  });

  $('#game_amount_input').on('keyup', () => {
    if ($('#game_amount_input').val() >= 10000) {
      if ($('#game_verify_warning').length) return;
      $('#game_verify_submit').parent().append(
        $('<span/>').attr({
          'id': 'game_verify_warning',
          'class': 'tag is-warning'
        }).text("Verifying a huge amount of games may consume more ressources from your CPU")
      );
    } else {
      if ($('#game_verify_warning').length) {
        $('#game_verify_warning').remove();
      }
    }
  });

  const addTableRow = (hash, bust, index) => {
    $('<tr/>').attr({
      'class': index === 0 ? 'is-first' : null
    }).append(
      $('<td/>').text(hash)
    ).append(
      $('<td/>').text(bust).attr({
        'class': bust === 1.98 ? 'is-at-median' : bust > 1.98 ? 'is-over-median' : 'is-under-median'
      })
    ).appendToWithIndex($('#game_verify_table'), index);

    if (index >= $('#game_amount_input').val() - 1) {
      $('#game_hash_input').parent().removeClass('is-loading');
      $('#game_verify_submit').removeClass('is-loading');
      $('#game_hash_input, #game_amount_input, #game_verify_submit').removeAttr("disabled");
      isVerifying = false;
    }
  };

  const gameResult = (seed) => {
    const nBits = 52; // number of most significant bits to use

    // 1. r = 52 most significant bits
    seed = seed.slice(0, nBits / 4);
    const r = parseInt(seed, 16);

    // 2. X = r / 2^52
    let X = r / Math.pow(2, nBits); // uniformly distributed in [0; 1)

    // 3. X = 99 / (1-X)
    X = 99 / (1 - X);

    // 4. return max(trunc(X), 100)
    const result = Math.floor(X);
    return Math.max(1, result / 100);
  };

  $.fn.appendToWithIndex = function(to, index) {
    if (!to instanceof jQuery) {
      to = $(to);
    };
    if (index === 0) {
      $(this).prependTo(to)
    } else {
      $(this).insertAfter(to.children().eq(index - 1));
    }
  };

  var hash_url = window.location.search
  if ((/\?hash=/).test(hash_url)) {
    var hash = hash_url.replace(/\?hash=/, '')
    $('#game_hash_input').val(hash)
    $('#game_verify_submit').click()
  }
</script>
<script>
  // tell the embed parent frame the height of the content
  if (window.parent && window.parent.parent) {
    window.parent.parent.postMessage(["resultsFrame", {
      height: document.body.getBoundingClientRect().height,
      slug: "nwu2ffkv"
    }], "*")
  }
</script>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants