Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dhadzhiew committed May 23, 2019
1 parent c4470ae commit 1589a77
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
13 changes: 7 additions & 6 deletions src/Godlike.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';


Expand All @@ -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,
]);
}

Expand All @@ -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);
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/pdo/PDO.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/std/Time.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down

0 comments on commit 1589a77

Please sign in to comment.