From 1589a77d79b57a6db26e300d150fe2f33658a985 Mon Sep 17 00:00:00 2001 From: dhadzhiew Date: Thu, 23 May 2019 18:30:01 +0300 Subject: [PATCH] Fixes --- src/Godlike.php | 13 +++++++------ src/pdo/PDO.php | 2 +- src/std/Time.php | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/Godlike.php b/src/Godlike.php index 86761c5..1131e17 100644 --- a/src/Godlike.php +++ b/src/Godlike.php @@ -11,6 +11,7 @@ require_once __DIR__ . '/common/Storage.php'; require_once __DIR__ . '/debug/Logger.php'; require_once __DIR__ . '/debug/Timer.php'; +require_once __DIR__ . '/debug/Snitch.php'; require_once __DIR__ . '/seed/Seeder.php'; @@ -24,15 +25,15 @@ final class Godlike { public static function enchant(): void { // Allow disable prepend or seed for the request. if (isset($_SERVER['HTTP_GODLIKE_NO_PREPEND']) && $_SERVER['HTTP_GODLIKE_NO_PREPEND']) return; - if (isset($_SERVER['HTTP_GODLIKE_NO_SEED']) && $_SERVER['HTTP_GODLIKE_SKIP_SEED']) return; - if (isset($_SERVER['HTTP_GODLIKE_NO_LOG']) && $_SERVER['HTTP_GODLIKE_SKIP_LOG']) return; + if (isset($_SERVER['HTTP_GODLIKE_NO_SEED']) && $_SERVER['HTTP_GODLIKE_NO_SEED']) return; + if (isset($_SERVER['HTTP_GODLIKE_NO_LOG']) && $_SERVER['HTTP_GODLIKE_NO_LOG']) return; self::$instance = new Godlike(); self::$instance->prepend([ 'name' => self::string($_SERVER['HTTP_GODLIKE_REQUEST_NAME'] ?? null), 'tags' => self::string($_SERVER['HTTP_GODLIKE_REQUEST_TAGS'] ?? null), 'rng' => self::int($_SERVER['HTTP_GODLIKE_SEED_RNG'] ?? null), - 'time' => self::int($_SERVER['HTTP_GODLIKE_SEED_TIME'] ?? null), + 'time' => self::int($_SERVER['HTTP_GODLIKE_SEED_TIME'] ?? null) ?: null, ]); } @@ -44,12 +45,12 @@ public static function api(): void { self::$instance = new Godlike(); } - $cmd = self::int($_REQUEST['cmd'] ?? ''); + $cmd = self::string($_REQUEST['cmd'] ?? ''); $params = []; if ($cmd === 'seed') { $params['rng'] = self::int($_REQUEST['rng'] ?? null); - $params['time'] = self::int($_REQUEST['time'] ?? null); + $params['time'] = self::int($_REQUEST['time'] ?? null) ?: null; $params['timeScale'] = self::float($_REQUEST['timeScale'] ?? null); $params['timeStepMin'] = self::int($_REQUEST['timeStepMin'] ?? null); $params['timeStepMax'] = self::int($_REQUEST['timeStepMax'] ?? null); @@ -317,7 +318,7 @@ private function append(): void { private function command(string $cmd, array $params = []) { // Call init first in case we have not added the prepend script yet. $this->init(); - + // Phpinfo request will exit. if ($cmd === 'phpinfo') { echo Snitch::phpinfo(); diff --git a/src/pdo/PDO.php b/src/pdo/PDO.php index d7eb229..9476e7e 100644 --- a/src/pdo/PDO.php +++ b/src/pdo/PDO.php @@ -63,7 +63,7 @@ public function __setGodlikeTimestamp(): void { $timestamp = 0; if (self::$__timestamp !== null) { - $timestamp = \bcdiv(self::$__timestamp, '1000000', 6); + $timestamp = \bcdiv(self::$__timestamp, '1000', 6); } parent::exec('SET timestamp = ' . $timestamp); diff --git a/src/std/Time.php b/src/std/Time.php index 86ad9fd..6b7d768 100644 --- a/src/std/Time.php +++ b/src/std/Time.php @@ -11,7 +11,7 @@ function __godlike_timestamp_cache(bool $real = false) { if ($real) { $e = getenv('FAKETIME_REALTIME'); if (is_string($e) && is_numeric($e) && strlen($e) > 0) $micro = $e; - else $micro = microtime_original(true) * 1000000; + else $micro = bcmul(microtime_original(true), 1000000); } else { if (!isset($_SERVER['GODLIKE_TIMESTAMP'])) return null; $micro = $_SERVER['GODLIKE_TIMESTAMP'];