fix: preserve reserved and wall-clock server info

This commit is contained in:
2026-08-06 02:56:43 +00:00
parent 69fb122ab1
commit 56a023e195
3 changed files with 45 additions and 6 deletions
+13 -5
View File
@@ -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']);
+28 -1
View File
@@ -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,
);
}
}
+4
View File
@@ -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,