-
-
Save fogmoon/0caa7bdaa64ca5f98dfaa931bd99fa0a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| .... | |
| exports.genGameHash = function(serverSeed) { | |
| return crypto.createHash('sha256').update(serverSeed).digest('hex'); | |
| }; | |
| function divisible(hash, mod) { | |
| // We will read in 4 hex at a time, but the first chunk might be a bit smaller | |
| // So ABCDEFGHIJ should be chunked like AB CDEF GHIJ | |
| var val = 0; | |
| var o = hash.length % 4; | |
| for (var i = o > 0 ? o - 4 : 0; i < hash.length; i += 4) { | |
| val = ((val << 16) + parseInt(hash.substring(i, i+4), 16)) % mod; | |
| } | |
| return val === 0; | |
| } | |
| // newest for zcash block 135400 | |
| var clientSeed ='0000000003a96dc6e52672a487ec577fc32e71a8f99bdbbf7329bf27f9772544'; | |
| exports.crashPointFromHash = function(serverSeed) { | |
| var hash = crypto.createHmac('sha256', serverSeed).update(clientSeed).digest('hex'); | |
| // In 1 of 101 games the game crashes instantly. | |
| if (divisible(hash, 101)) | |
| return 0; | |
| // Use the most significant 52-bit from the hash to calculate the crash point | |
| var h = parseInt(hash.slice(0,52/4),16); | |
| var e = Math.pow(2,52); | |
| return Math.floor((100 * e - h) / (e - h)); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment