From 006ca76922e6b7217587ae0d656922d9c56d9626 Mon Sep 17 00:00:00 2001 From: Hide_D Date: Tue, 30 Aug 2022 22:51:14 +0900 Subject: [PATCH] =?UTF-8?q?refac:=20ExecuteEngine=20=EB=B0=98=ED=99=98=20?= =?UTF-8?q?=ED=83=80=EC=9E=85=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/sammo/API/Global/ExecuteEngine.php | 17 ++++++++++++++- hwe/sammo/TurnExecutionHelper.php | 30 ++++++++++++++++++-------- hwe/ts/SammoAPI.ts | 7 +++++- hwe/ts/defs/API/Global.ts | 7 ++++++ 4 files changed, 50 insertions(+), 11 deletions(-) diff --git a/hwe/sammo/API/Global/ExecuteEngine.php b/hwe/sammo/API/Global/ExecuteEngine.php index cd8cf8ed..54077faa 100644 --- a/hwe/sammo/API/Global/ExecuteEngine.php +++ b/hwe/sammo/API/Global/ExecuteEngine.php @@ -3,8 +3,10 @@ namespace sammo\API\Global; use sammo\Session; +use sammo\DB; use DateTimeInterface; use sammo\TurnExecutionHelper; +use sammo\UniqueConst; class ExecuteEngine extends \sammo\BaseAPI { @@ -20,10 +22,23 @@ class ExecuteEngine extends \sammo\BaseAPI public function launch(Session $session, ?DateTimeInterface $modifiedSince, ?string $reqEtag) { - $updated = TurnExecutionHelper::executeAllCommand(); + $reqServerID = $this->args['serverID'] ?? null; + if($reqServerID && $reqServerID !== UniqueConst::$serverID){ + return [ + 'result' => false, + 'reason' => '서버 아이디가 다릅니다', + 'reqRefresh' => true, + ]; + } + + $updated = false; + $locked = false; + $lastExecuted = TurnExecutionHelper::executeAllCommand($updated, $locked); return [ 'result' => true, 'updated' => $updated, + 'locked' => $locked, + 'lastExecuted' => $lastExecuted, ]; } } diff --git a/hwe/sammo/TurnExecutionHelper.php b/hwe/sammo/TurnExecutionHelper.php index 29e5fc71..d334bda3 100644 --- a/hwe/sammo/TurnExecutionHelper.php +++ b/hwe/sammo/TurnExecutionHelper.php @@ -353,26 +353,26 @@ class TurnExecutionHelper return [false, $currentTurn]; } - static public function executeAllCommand(): bool + static public function executeAllCommand(&$executed = false, &$locked = false): string { - //if(!timeover()) { return; } - $db = DB::db(); $gameStor = KVStorage::getStorage($db, 'game_env'); if (TimeUtil::now(true) < $gameStor->turntime) { //턴 시각 이전이면 아무것도 하지 않음 - return false; + return $gameStor->turntime; } if (!tryLock()) { - return false; + $locked = true; + return $gameStor->turntime; } if ($gameStor->isunited == 2 || $gameStor->isunited == 3) { //천통시에는 동결 - return false; + $locked = true; + return $gameStor->turntime; } $gameStor->cacheAll(); @@ -414,10 +414,14 @@ class TurnExecutionHelper if ($executionOver) { if ($currentTurn !== null) { + $executed = true; $gameStor->turntime = $currentTurn; } unlock(); - return $currentTurn !== null && $lastExecuted !== $currentTurn; + if($lastExecuted !== $currentTurn){ + $executed = true; + } + return $gameStor->turntime; } $monthlyRng = new RandUtil(new LiteHashDRBG(Util::simpleSerialize( @@ -505,6 +509,7 @@ class TurnExecutionHelper ); if ($currentTurn !== null) { + $executed = true; $gameStor->turntime = $currentTurn; } @@ -512,10 +517,17 @@ class TurnExecutionHelper processTournament(); //거래 처리 processAuction(); - // 잡금 해제 + // 잠금 해제 + + $turntime = $gameStor->turntime; + $gameStor->resetCache(); unlock(); - return $currentTurn !== null && $lastExecuted !== $currentTurn; + if($lastExecuted !== $currentTurn){ + $executed = true; + } + + return $turntime; } } diff --git a/hwe/ts/SammoAPI.ts b/hwe/ts/SammoAPI.ts index 2a0f2b41..a61bbea8 100644 --- a/hwe/ts/SammoAPI.ts +++ b/hwe/ts/SammoAPI.ts @@ -22,6 +22,7 @@ import type { SetBlockWarResponse, GeneralListResponse as NationGeneralListRespo import type { UploadImageResponse } from "./defs/API/Misc"; import type { GeneralLogType, GetGeneralLogResponse, JoinArgs } from "./defs/API/General"; import type { +ExecuteResponse, GetConstResponse, GetCurrentHistoryResponse, GetDiplomacyResponse, @@ -144,7 +145,11 @@ const apiRealPath = { >, GetCachedMap: GET as APICallT, GetDiplomacy: GET as APICallT, - ExecuteEngine: POST as APICallT, + ExecuteEngine: POST as APICallT<{ + serverID: string | undefined + }, ExecuteResponse, InvalidResponse & { + reqRefresh?: boolean + }>, GetRecentRecord: GET as APICallT<{ lastGeneralRecordID: number; lastWorldHistoryID: number; diff --git a/hwe/ts/defs/API/Global.ts b/hwe/ts/defs/API/Global.ts index 936e4ddf..7b51ea32 100644 --- a/hwe/ts/defs/API/Global.ts +++ b/hwe/ts/defs/API/Global.ts @@ -78,6 +78,13 @@ export type GetDiplomacyResponse = { myNationID: number; } +export type ExecuteResponse = { + result: true; + updated: boolean; + locked: boolean; + lastExecuted: string; +}; + export type GetRecentRecordResponse = { result: true; history: [number, string][];