diff --git a/hwe/api.php b/hwe/api.php new file mode 100644 index 00000000..af91d505 --- /dev/null +++ b/hwe/api.php @@ -0,0 +1,90 @@ +getMessage()); +} + +if (!key_exists('path', $input)) { + Json::dieWithReason('path가 지정되지 않았습니다.'); +} + +if (key_exists('args', $input) && !is_array($input['args'])) { + Json::dieWithReason('args가 array가 아닙니다.' . gettype($input['args'])); +} + +try { + $obj = buildAPIExecutorClass($input['path'], $input['args'] ?? []); + $api = + $validateResult = $obj->validateArgs(); + if ($validateResult !== null) { + Json::dieWithReason($validateResult); + } + + $sessionMode = $obj->getRequiredSessionMode(); + if ($sessionMode === BaseAPI::NO_SESSION) { + $session = null; + } else { + if ($sessionMode & BaseAPI::REQ_GAME_LOGIN) { + $session = Session::requireGameLogin(); + } else if ($sessionMode & BaseAPI::REQ_LOGIN) { + $session = Session::requireLogin(); + } else { + Json::dieWithReason("올바르지 않은 SessionMode: {$sessionMode}"); + } + + if ($sessionMode & BaseAPI::REQ_READ_ONLY) { + $session->setReadOnly(); + } + } + + $modifiedSince = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) + ? new \DateTimeImmutable($_SERVER['HTTP_IF_MODIFIED_SINCE'], new \DateTimeZone("UTC")) + : null; + $reqEtags = isset($_SERVER['HTTP_IF_NONE_MATCH']) ? trim($_SERVER['HTTP_IF_NONE_MATCH']) : null; + + $result = $obj->launch($session, $modifiedSince, $reqEtags); + if (is_string($result)) { + Json::dieWithReason($result); + } + + $cacheResult = $obj->tryCache(); + if ($cacheResult !== null) { + /** @var \DateTimeInterface $lastModified */ + [$lastModified, $etag] = $cacheResult; + + if ($lastModified !== null) { + header("Last-Modified: " . gmdate("D, d M Y H:i:s", TimeUtil::DateTimeToSeconds($lastModified, true)) . " GMT"); + } + if ($etag !== null) { + header("Etag: $etag"); + } + + if ($modifiedSince !== null && $lastModified !== null && TimeUtil::DateIntervalToSeconds($modifiedSince->diff($lastModified)) == 0) { + header("HTTP/1.1 304 Not Modified"); + die(); + } + if ($reqEtags !== null && $reqEtags === $etag) { + header("HTTP/1.1 304 Not Modified"); + die(); + } + } + + if ($result === null) { + Json::die([ + 'result' => true, + 'reason' => 'success' + ], $cacheResult === null ? Json::NO_CACHE : 0); + } + Json::die($result, $cacheResult === null ? Json::NO_CACHE : 0); +} catch (\Exception $e) { + Json::dieWithReason($e->getMessage()); +} catch (mixed $e) { + Json::dieWithReason($e); +} diff --git a/hwe/func.php b/hwe/func.php index 3867a236..ddf8fa49 100644 --- a/hwe/func.php +++ b/hwe/func.php @@ -2345,7 +2345,7 @@ function getRandTurn($term, ?\DateTimeInterface $baseDateTime = null) $randSecond = Util::randRangeInt(0, 60 * $term - 1); $randFraction = Util::randRangeInt(0, 999999) / 1000000; //6자리 소수 - return $baseDateTime->add(TimeUtil::secondsToDateInterval($randSecond + $randFraction))->format('Y-m-d H:i:s'); + return $baseDateTime->add(TimeUtil::secondsToDateInterval($randSecond + $randFraction))->format('Y-m-d H:i:s.u'); } function getRandTurn2($term, ?\DateTimeInterface $baseDateTime = null) @@ -2360,5 +2360,5 @@ function getRandTurn2($term, ?\DateTimeInterface $baseDateTime = null) $randSecond = Util::randRangeInt(0, 60 * $term - 1); $randFraction = Util::randRangeInt(0, 999999) / 1000000; //6자리 소수 - return $baseDateTime->sub(TimeUtil::secondsToDateInterval($randSecond + $randFraction))->format('Y-m-d H:i:s'); + return $baseDateTime->sub(TimeUtil::secondsToDateInterval($randSecond + $randFraction))->format('Y-m-d H:i:s.u'); } diff --git a/hwe/func_converter.php b/hwe/func_converter.php index 7c696083..9508b13a 100644 --- a/hwe/func_converter.php +++ b/hwe/func_converter.php @@ -1,4 +1,4 @@ -0.5, ]; $inheritStor = KVStorage::getStorage(DB::db(), "inheritance_{$userID}"); $totalPoint = 0; - foreach($inheritStor->getAll() as $key=>[$value,]){ - if(key_exists($key, $rebirthDegraded)){ + $allPoints = $inheritStor->getAll(); + if(count($allPoints) == 0){ + //비었으므로 리셋 안함 + return 0; + } + if(count($allPoints) == 1 && key_exists('previous', $allPoints)){ + //이미 리셋되었으므로 리셋 안함 + return $allPoints['previous']; + } + foreach($allPoints as $key=>[$value,]){ + if($isRebirth && key_exists($key, $rebirthDegraded)){ $value *= $rebirthDegraded[$key]; } $totalPoint += $value; @@ -1166,6 +1175,7 @@ function resetInheritanceUser(int $userID, bool $isRebirth=false){ $totalPoint = Util::toInt($totalPoint); $inheritStor->resetValues(); $inheritStor->setValue('previous', [$totalPoint, null]); + return $totalPoint; } function updateMaxDomesticCritical(General $general, $score){ diff --git a/hwe/join_post.php b/hwe/join_post.php index fbd6b58a..e9fb0d22 100644 --- a/hwe/join_post.php +++ b/hwe/join_post.php @@ -1,39 +1,50 @@