I have a laravel PHP 2 functions. In the first function, I simply create a game and generate a hash
for it:
$token = bin2hex(random_bytes(64));
Game::query()->create([
'hash' => $token,
]);
and then i create new record from Game model laravel.
In second function, I need to somehow call a nodejs file, where numbers are simply generated, and the resulting numbers are passed to PHP for saving in the database. My simply second function:
public function setStatus(Request $r)
{
$status = $r->get('status');
$game = $this->getGameInController();
$game->update([
'status' => $status
]);
if ($status === 1) {
$game->update([
AND HERE I WANT TO RECEIVED INFORMATION FROM NODEJS FILE
]);
return $multiplier;
}
}
Then i has test.js file, where i want to pass the hash
value from the table:
// You need to edit this value
var gameHash = 'HASH FROM LARAVEL GAME MODEL';
/*
Below this line is the formula which we use to calculate the result
*/
var crypto = require('crypto');
const INSTANT_CRASH_PERCENTAGE = 6.66;
var crashPointFromHash = function (serverSeed) {
var hash = crypto.createHmac('sha256', serverSeed).digest('hex');
// 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);
const result = (100 * e - h) / (e - h);
// INSTANT_CRASH_PERCENTAGE of 6.66 will result in modifier of 0.934 = 6.66% house edge with a lowest crashpoint of 1.00x
const houseEdgeModifier = 1 - INSTANT_CRASH_PERCENTAGE / 100;
const endResult = Math.max(100, result * houseEdgeModifier);
return Math.floor(endResult);
};
console.log(`Hash: ${gameHash}\n\nGame crashed at ${(crashPointFromHash(gameHash) / 100).toFixed(2)}x`);
And than i want save in database the value, from {(crashPointFromHash(gameHash) / 100).toFixed(2)}
How i can make it? I hope for your help!