, Marco Orlandi // // Permission to use, copy, modify, and/or distribute this software for any // purpose with or without fee is hereby granted, provided that the above // copyright notice and this permission notice appear in all copies. // // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR // ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. // // Requirements: PHP 5 with PDO SQLite extension (GeoIP optional but suggested) // Flags can be found here: http://www.famfamfam.com/lab/icons/flags/famfamfam_flag_icons.zip $baseURL = 'https://dadi.lapo.it/'; header('Content-Type: text/html;charset=UTF-8'); header('Content-Style-Type: text/css'); header('Content-Script-Type: text/javascript'); header("Cache-Control: max-age=60"); // cacheable for 1 minute //if (include_once('Net/GeoIP.php') == TRUE) // $geoip = Net_GeoIP::getInstance("/path/to/geoipdb.dat"); $geoip = FALSE; //if (!$geoip) error_log('GeoIP extension not found.'); $type = '1d6'; if (isset($_POST['dices'])) $type = $_POST['dices']; ?> Tira dadi online

Descrizione 

Dado 

exec(' CREATE TABLE IF NOT EXISTS throw ( time INTEGER PRIMARY KEY, text TEXT, value TEXT, ip TEXT ); '); if (isset($_POST['send'])) { // calcola valore $val = ''; $totDices = 0; $parts = preg_split('/[+, ]+/', $_POST['dices']); foreach ($parts as $dice) { if (preg_match("/^([1-9][0-9]*)d([1-9][0-9]*|F)$/", $dice, $regs)) { $numDices=$regs[1]; $diceType=$regs[2]; for ( $i = 1; $i <= $numDices; $i++) { if (++$totDices > 20) { echo "Si possono tirare un massimo di 20 dadi contemporaneamente."; $val = ''; break; } if ($diceType == 'F') $currVal= mt_rand(-1, 1); else if ($diceType > 100) { echo "Si possono tirare dadi con un massimo di 100 facce."; $val = ''; break; } else $currVal= mt_rand(1, $diceType); $val .= "$currVal/$diceType "; } } else { echo "Formato Dado non valido: " . $dice; $val=''; break; } } if ($val) { // inserisce in DB $q = $db->prepare('INSERT INTO throw (time, text, value, ip) VALUES (?, ?, ?, ?);'); $q->execute(array(time(), "$_POST[throw] ($_POST[dices])", trim($val), $_SERVER['REMOTE_ADDR'])); } } function printDice($value, &$full, &$num) { $i = 0; foreach (explode(' ', $value) as $throw) { $parts = explode('/', $throw); $vals["$parts[0].$i"] = $parts; ++$i; } ksort($vals); $full = ''; $num = ''; foreach ($vals as $parts) { $full .= "$parts[0] "; $num .= "$parts[0] "; } $full = trim($full); $num = trim($num); } function mod($a, $b) { $r = $a % $b; return ($r >= 0) ? $r : $r + $b; } $user1 = array('screaming', 'rowling', 'red', 'green', 'magenta', 'mad', 'crazy', 'pillaging', 'drunken', 'flapping', 'flickering', 'phase', 'massive', 'mutant', 'radioactive', 'transgenic', 'solid', 'liquid', 'venom', 'big', 'small', 'tiny', 'huge', 'strange'); $user2 = array('monkey', 'lion', 'otter', 'tiger', 'puma', 'zebra', 'turtle', 'platypus', 'griffyn', 'leviathan', 'leontophone', 'boa', 'aspid', 'sheep', 'snake', 'dragonfly', 'unicorn', 'squid', 'cobra', 'spider', 'mantis'); $q = $db->prepare('SELECT * FROM throw WHERE time <= ? ORDER BY time DESC LIMIT 100;'); $q->execute(array(isset($_GET['time']) ? (int)$_GET['time'] : 0x7FFFFFFF)); $q->setFetchMode(PDO::FETCH_ASSOC); echo "\n"; while ($row = $q->fetch()) { $flag = ''; if ($geoip) { $cc = strtolower(geoip_country_code_by_name($row['ip'])); if ($cc) { $cn = htmlspecialchars(geoip_country_name_by_name($row['ip'])); $flag = 'Flag of: ' . $cn . ''; } } $crc = crc32($row['ip']); $user = $user1[mod($crc, count($user1))]; $user .= ' '; $user .= $user2[mod($crc + 65537, count($user2))]; printDice($row['value'], $full, $num); ?> \n"; ?>
%H:%M:%S', $row['time'])?>