function userInput() { echo "Input {number of dice}d{number of sides}. \n"; $handle = fopen("php://stdin", "r"); $line = fgets($handle); if (strpos($line, "d") > 0) { $inputs = explode("d", $line); } else { echo "Input invlaid. Please enter input {number of dice}d{number of sides}"; userInput(); } $numDice = intval($inputs[0]); $numSides = intval($inputs[1]); rollDice($numDice, $numSides); }
function createPost($user, $content) { # VARIABLES $time = time(); $ident = hash("crc32", $_SERVER["REMOTE_ADDR"]); $content = trim(htmlspecialchars($content)); # DICE ROLLING $pattern = "/^@roll (.*?)( .*)?\$/m"; preg_match_all($pattern, $content, $matches); $i = 0; while ($i < count($matches)) { $input = $matches[0][$i]; $result = rollDice($matches[1][$i]); $content = str_replace($input, $result, $content); $i++; } # FULL POSTING $string = "{ ident: {$ident}, name: {$user}, created: {$time}, edited: 0 }\n{$content}"; $file = fopen(location . "{$time}.{$ident}.txt", "w"); fwrite($file, $string); }
function turn($player, $playerScore) { $roll = rollDice(); $mod = $roll % 2; if ($roll >= 20 && $mod == 0) { $playerScore--; } else { if ($roll >= 20 && $mod != 0) { $playerScore++; } else { if ($roll <= 19 && $mod == 0) { $playerScore++; } else { if ($roll <= 19 && $mod != 0) { $playerScore--; } } } } //This line needs to be called ON THE GAME PAGE AFTER EVERY TURN. echo $player . " rolled " . $roll . ", changing his score to " . $playerScore . "."; }
* outputs: * server hash correctness * roll result */ if (count($argv) != 5) { print "useage: php verifyMonerodice.php serverHash serverSeed userSeed nonce \n"; exit; } if (hash('sha256', $argv[2]) == $argv[1]) { //check if hashed serverSeed matches serverHash print "Server Hash is correct! \n"; } else { print "Server Hash is incorrect! \n"; } //simulate dice roll to get the exact roll result print "Roll result is: " . rollDice($argv[2], $argv[3] . '_' . $argv[4]); //function which executes dice roll based on your input function rollDice($server_seed, $secret) { $hash = hash_hmac('sha512', $server_seed, $secret); for ($i = 0; $i < strlen($hash); $i += 5) { $sub = substr($hash, $i, 5); if (strlen($sub) == 5) { $decimal_number = hexdec($sub); if ($decimal_number < 1000000) { $decimal_fourc = bcmod($decimal_number, 10000); $final_decimal = bcdiv($decimal_fourc, 100, 2); return $final_decimal; } } else { break;
<!DOCTYPE html> <html> <head> </head> <body> well this is working kind of </body> </html> <?php require 'functions.php'; echo rollDice();
function damageRoll($o_target, $i_pow=0, $b_boosted=false) { if($b_boosted) { $s_roll = '3D6'; $i_roll = rollDice(3); } else { $s_roll = '2D6'; $i_roll = rollDice(2); } $i_dmg = $this->i_str + $i_pow + $i_roll - $o_target->i_arm; if($i_dmg > 0) { $o_target->i_dmg -= $i_dmg; debug('['.$o_target->s_warbeastName.'] took ['.$i_dmg.'] {P+S '.($this->i_str + $i_pow).' + roll '.$i_roll.'('.$s_roll.') = '.($this->i_str + $i_pow + $i_roll).' - '.$o_target->i_arm.' = '.$i_dmg.'} damage ('.$o_target->i_dmg.' left) <br />'); return $i_dmg; } else { debug('['.$o_target->s_warbeastName.'] took no damage <br />'); return 0; } }