refac: ExecuteEngine 반환 타입 변경
This commit is contained in:
@@ -3,8 +3,10 @@
|
|||||||
namespace sammo\API\Global;
|
namespace sammo\API\Global;
|
||||||
|
|
||||||
use sammo\Session;
|
use sammo\Session;
|
||||||
|
use sammo\DB;
|
||||||
use DateTimeInterface;
|
use DateTimeInterface;
|
||||||
use sammo\TurnExecutionHelper;
|
use sammo\TurnExecutionHelper;
|
||||||
|
use sammo\UniqueConst;
|
||||||
|
|
||||||
class ExecuteEngine extends \sammo\BaseAPI
|
class ExecuteEngine extends \sammo\BaseAPI
|
||||||
{
|
{
|
||||||
@@ -20,10 +22,23 @@ class ExecuteEngine extends \sammo\BaseAPI
|
|||||||
|
|
||||||
public function launch(Session $session, ?DateTimeInterface $modifiedSince, ?string $reqEtag)
|
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 [
|
return [
|
||||||
'result' => true,
|
'result' => true,
|
||||||
'updated' => $updated,
|
'updated' => $updated,
|
||||||
|
'locked' => $locked,
|
||||||
|
'lastExecuted' => $lastExecuted,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -353,26 +353,26 @@ class TurnExecutionHelper
|
|||||||
return [false, $currentTurn];
|
return [false, $currentTurn];
|
||||||
}
|
}
|
||||||
|
|
||||||
static public function executeAllCommand(): bool
|
static public function executeAllCommand(&$executed = false, &$locked = false): string
|
||||||
{
|
{
|
||||||
//if(!timeover()) { return; }
|
|
||||||
|
|
||||||
$db = DB::db();
|
$db = DB::db();
|
||||||
|
|
||||||
$gameStor = KVStorage::getStorage($db, 'game_env');
|
$gameStor = KVStorage::getStorage($db, 'game_env');
|
||||||
|
|
||||||
if (TimeUtil::now(true) < $gameStor->turntime) {
|
if (TimeUtil::now(true) < $gameStor->turntime) {
|
||||||
//턴 시각 이전이면 아무것도 하지 않음
|
//턴 시각 이전이면 아무것도 하지 않음
|
||||||
return false;
|
return $gameStor->turntime;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!tryLock()) {
|
if (!tryLock()) {
|
||||||
return false;
|
$locked = true;
|
||||||
|
return $gameStor->turntime;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($gameStor->isunited == 2 || $gameStor->isunited == 3) {
|
if ($gameStor->isunited == 2 || $gameStor->isunited == 3) {
|
||||||
//천통시에는 동결
|
//천통시에는 동결
|
||||||
return false;
|
$locked = true;
|
||||||
|
return $gameStor->turntime;
|
||||||
}
|
}
|
||||||
|
|
||||||
$gameStor->cacheAll();
|
$gameStor->cacheAll();
|
||||||
@@ -414,10 +414,14 @@ class TurnExecutionHelper
|
|||||||
|
|
||||||
if ($executionOver) {
|
if ($executionOver) {
|
||||||
if ($currentTurn !== null) {
|
if ($currentTurn !== null) {
|
||||||
|
$executed = true;
|
||||||
$gameStor->turntime = $currentTurn;
|
$gameStor->turntime = $currentTurn;
|
||||||
}
|
}
|
||||||
unlock();
|
unlock();
|
||||||
return $currentTurn !== null && $lastExecuted !== $currentTurn;
|
if($lastExecuted !== $currentTurn){
|
||||||
|
$executed = true;
|
||||||
|
}
|
||||||
|
return $gameStor->turntime;
|
||||||
}
|
}
|
||||||
|
|
||||||
$monthlyRng = new RandUtil(new LiteHashDRBG(Util::simpleSerialize(
|
$monthlyRng = new RandUtil(new LiteHashDRBG(Util::simpleSerialize(
|
||||||
@@ -505,6 +509,7 @@ class TurnExecutionHelper
|
|||||||
);
|
);
|
||||||
|
|
||||||
if ($currentTurn !== null) {
|
if ($currentTurn !== null) {
|
||||||
|
$executed = true;
|
||||||
$gameStor->turntime = $currentTurn;
|
$gameStor->turntime = $currentTurn;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -512,10 +517,17 @@ class TurnExecutionHelper
|
|||||||
processTournament();
|
processTournament();
|
||||||
//거래 처리
|
//거래 처리
|
||||||
processAuction();
|
processAuction();
|
||||||
// 잡금 해제
|
// 잠금 해제
|
||||||
|
|
||||||
|
$turntime = $gameStor->turntime;
|
||||||
|
|
||||||
$gameStor->resetCache();
|
$gameStor->resetCache();
|
||||||
unlock();
|
unlock();
|
||||||
|
|
||||||
return $currentTurn !== null && $lastExecuted !== $currentTurn;
|
if($lastExecuted !== $currentTurn){
|
||||||
|
$executed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $turntime;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-1
@@ -22,6 +22,7 @@ import type { SetBlockWarResponse, GeneralListResponse as NationGeneralListRespo
|
|||||||
import type { UploadImageResponse } from "./defs/API/Misc";
|
import type { UploadImageResponse } from "./defs/API/Misc";
|
||||||
import type { GeneralLogType, GetGeneralLogResponse, JoinArgs } from "./defs/API/General";
|
import type { GeneralLogType, GetGeneralLogResponse, JoinArgs } from "./defs/API/General";
|
||||||
import type {
|
import type {
|
||||||
|
ExecuteResponse,
|
||||||
GetConstResponse,
|
GetConstResponse,
|
||||||
GetCurrentHistoryResponse,
|
GetCurrentHistoryResponse,
|
||||||
GetDiplomacyResponse,
|
GetDiplomacyResponse,
|
||||||
@@ -144,7 +145,11 @@ const apiRealPath = {
|
|||||||
>,
|
>,
|
||||||
GetCachedMap: GET as APICallT<undefined, CachedMapResult>,
|
GetCachedMap: GET as APICallT<undefined, CachedMapResult>,
|
||||||
GetDiplomacy: GET as APICallT<undefined, GetDiplomacyResponse>,
|
GetDiplomacy: GET as APICallT<undefined, GetDiplomacyResponse>,
|
||||||
ExecuteEngine: POST as APICallT<undefined, ValidResponse & { updated: boolean }>,
|
ExecuteEngine: POST as APICallT<{
|
||||||
|
serverID: string | undefined
|
||||||
|
}, ExecuteResponse, InvalidResponse & {
|
||||||
|
reqRefresh?: boolean
|
||||||
|
}>,
|
||||||
GetRecentRecord: GET as APICallT<{
|
GetRecentRecord: GET as APICallT<{
|
||||||
lastGeneralRecordID: number;
|
lastGeneralRecordID: number;
|
||||||
lastWorldHistoryID: number;
|
lastWorldHistoryID: number;
|
||||||
|
|||||||
@@ -78,6 +78,13 @@ export type GetDiplomacyResponse = {
|
|||||||
myNationID: number;
|
myNationID: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type ExecuteResponse = {
|
||||||
|
result: true;
|
||||||
|
updated: boolean;
|
||||||
|
locked: boolean;
|
||||||
|
lastExecuted: string;
|
||||||
|
};
|
||||||
|
|
||||||
export type GetRecentRecordResponse = {
|
export type GetRecentRecordResponse = {
|
||||||
result: true;
|
result: true;
|
||||||
history: [number, string][];
|
history: [number, string][];
|
||||||
|
|||||||
Reference in New Issue
Block a user