From 56a023e19508b44495a85b0f19d2508719271caa Mon Sep 17 00:00:00 2001 From: hided62 Date: Thu, 6 Aug 2026 02:56:43 +0000 Subject: [PATCH] fix: preserve reserved and wall-clock server info --- hwe/j_server_basic_info.php | 18 +++++++++++++----- tests/GameClockBoundaryTest.php | 29 ++++++++++++++++++++++++++++- tests/GameClockTest.php | 4 ++++ 3 files changed, 45 insertions(+), 6 deletions(-) diff --git a/hwe/j_server_basic_info.php b/hwe/j_server_basic_info.php index 92e86b96..4cfc30f1 100644 --- a/hwe/j_server_basic_info.php +++ b/hwe/j_server_basic_info.php @@ -19,7 +19,6 @@ if(!class_exists('\\sammo\\DB')){ $db = DB::db(); $gameStor = KVStorage::getStorage($db, 'game_env'); -$clock = GameClock::fromStorage($gameStor); if(file_exists(__DIR__.'/.htaccess')){ $reserved = $db->queryFirstRow( @@ -71,15 +70,24 @@ if(file_exists(__DIR__.'/.htaccess')){ //TODO: 천통시에도 예약 오픈 알림이 필요..? +$usesLogicalClock = GameClock::isInitialized($gameStor); $admin = $gameStor->getValues(['isunited', 'npcmode', 'year', 'month', 'scenario', 'scenario_text', 'maxgeneral', 'turnterm', 'opentime', 'turntime', 'join_mode', 'fiction', 'block_general_create', 'autorun_user']); $admin['maxUserCnt'] = $admin['maxgeneral']; $admin['npcMode'] = $admin['npcmode']; $admin['turnTerm'] = $admin['turnterm']; $admin['isUnited'] = $admin['isunited']; -$admin['isOpen'] = $clock->nowTick() >= Util::toInt($admin['opentime']); -$admin['opentime'] = $clock->formatTick(Util::toInt($admin['opentime'])); -$admin['starttime'] = substr($admin['opentime'], 5, 11); -$admin['turntime'] = substr($clock->formatTick(Util::toInt($admin['turntime'])), 5, 11); +if($usesLogicalClock){ + $clock = GameClock::fromStorage($gameStor); + $admin['isOpen'] = $clock->nowTick() >= Util::toInt($admin['opentime']); + $admin['opentime'] = $clock->formatTick(Util::toInt($admin['opentime'])); + $admin['starttime'] = substr($admin['opentime'], 5, 11); + $admin['turntime'] = substr($clock->formatTick(Util::toInt($admin['turntime'])), 5, 11); +} +else{ + $admin['isOpen'] = new \DateTimeImmutable((string)$admin['opentime']) <= GameClock::readWallTime(); + $admin['starttime'] = substr((string)$admin['opentime'], 5, 11); + $admin['turntime'] = substr((string)$admin['turntime'], 5, 11); +} unset($admin['npcmode']); unset($admin['maxgeneral']); unset($admin['turnterm']); diff --git a/tests/GameClockBoundaryTest.php b/tests/GameClockBoundaryTest.php index df8d7fb9..9799f955 100644 --- a/tests/GameClockBoundaryTest.php +++ b/tests/GameClockBoundaryTest.php @@ -146,14 +146,41 @@ final class GameClockBoundaryTest extends TestCase self::assertStringNotContainsString('formatTime(new Date())', file_get_contents(__DIR__ . '/../hwe/ts/PageVote.vue')); } - public function testGatewayFormatsLogicalOpenTimeBeforeReturningIt(): void + public function testGatewayReadsClockOnlyAfterClosedReservationResponse(): void + { + $source = file_get_contents(__DIR__ . '/../hwe/j_server_basic_info.php'); + self::assertIsString($source); + + $closedBranch = strpos($source, "if(file_exists(__DIR__.'/.htaccess'))"); + $closedBranchEnd = strpos($source, '//TODO: 천통시에도 예약 오픈 알림이 필요..?'); + $clockDetection = strpos($source, 'GameClock::isInitialized($gameStor)'); + $clockRead = strpos($source, 'GameClock::fromStorage($gameStor)'); + + self::assertNotFalse($closedBranch); + self::assertNotFalse($closedBranchEnd); + self::assertNotFalse($clockDetection); + self::assertNotFalse($clockRead); + self::assertGreaterThan($closedBranch, $closedBranchEnd); + self::assertGreaterThan($closedBranchEnd, $clockDetection); + self::assertGreaterThan($closedBranchEnd, $clockRead); + } + + public function testGatewayPreservesWallClockProfilesAndFormatsLogicalOpenTime(): void { $source = file_get_contents(__DIR__ . '/../hwe/j_server_basic_info.php'); self::assertIsString($source); + self::assertStringContainsString( + '$usesLogicalClock = GameClock::isInitialized($gameStor);', + $source, + ); self::assertStringContainsString( '$admin[\'opentime\'] = $clock->formatTick(Util::toInt($admin[\'opentime\']));', $source, ); + self::assertStringContainsString( + '$admin[\'isOpen\'] = new \\DateTimeImmutable((string)$admin[\'opentime\']) <= GameClock::readWallTime();', + $source, + ); } } diff --git a/tests/GameClockTest.php b/tests/GameClockTest.php index 063468a6..1ab16c79 100644 --- a/tests/GameClockTest.php +++ b/tests/GameClockTest.php @@ -109,6 +109,10 @@ final class GameClockTest extends TestCase ]); self::assertFalse(GameClock::isInitialized($legacyStorage)); + $reservedResetStorage = $this->createMock(KVStorage::class); + $reservedResetStorage->method('getValues')->willReturn([]); + self::assertFalse(GameClock::isInitialized($reservedResetStorage)); + $partialStorage = $this->createMock(KVStorage::class); $partialStorage->method('getValues')->willReturn([ 'clock_tick' => 0,