From dc56ee1c063bb655208997e54aeb603f6b8dd8ca Mon Sep 17 00:00:00 2001 From: hided62 Date: Fri, 7 Aug 2026 16:35:53 +0000 Subject: [PATCH] fix: project troop times for game clock responses --- hwe/sammo/API/Nation/GeneralList.php | 12 ++++++++---- tests/GameClockBoundaryTest.php | 23 +++++++++++++++++++++++ 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/hwe/sammo/API/Nation/GeneralList.php b/hwe/sammo/API/Nation/GeneralList.php index 26001519..31e3e3c8 100644 --- a/hwe/sammo/API/Nation/GeneralList.php +++ b/hwe/sammo/API/Nation/GeneralList.php @@ -151,6 +151,11 @@ class GeneralList extends \sammo\BaseAPI $gameStor = \sammo\KVStorage::getStorage($db, 'game_env'); $env = $gameStor->getValues(['year', 'month', 'turntime', 'turnterm', 'autorun_user', 'killturn']); + $clock = GameClock::isInitialized($gameStor) ? GameClock::fromStorage($gameStor) : null; + $formatStoredTime = static fn (mixed $value): string => $clock === null + ? (string)$value + : $clock->formatTick(Util::toInt($value)); + $env['turntime'] = $formatStoredTime($env['turntime']); $me = $db->queryFirstRow( 'SELECT refresh_score, turntime, belong, nation, officer_level, permission, penalty FROM `general` @@ -187,7 +192,7 @@ class GeneralList extends \sammo\BaseAPI if (!key_exists($troopLeaderID, $rawGeneralList)) { continue; } - $troopTurnTime = $rawGeneralList[$troopLeaderID]['turntime']; + $troopTurnTime = $formatStoredTime($rawGeneralList[$troopLeaderID]['turntime']); $troops[$troopLeaderID] = new ArrayObject([ 'id' => $troopLeaderID, 'name' => $troopName, @@ -265,11 +270,10 @@ class GeneralList extends \sammo\BaseAPI 'honorText' => fn ($rawGeneral) => getHonor($rawGeneral['experience']), 'dedLevelText' => fn ($rawGeneral) => getDedLevelText($rawGeneral['dedlevel']), //'0000-00-00 11:23'; - 'turntime' => fn ($rawGeneral) => GameClock::fromStorage($gameStor) - ->formatTick(Util::toInt($rawGeneral['turntime'])), + 'turntime' => fn ($rawGeneral) => substr($formatStoredTime($rawGeneral['turntime']), 0, 19), 'recent_war' => fn ($rawGeneral) => $rawGeneral['recent_war'] === null ? null - : GameClock::fromStorage($gameStor)->formatTick(Util::toInt($rawGeneral['recent_war'])), + : substr($formatStoredTime($rawGeneral['recent_war']), 0, 19), 'bill' => fn ($rawGeneral) => getBillByLevel($rawGeneral['dedlevel']), 'reservedCommand' => fn ($rawGeneral) => $reservedCommand[$rawGeneral['no']] ?? null, 'autorun_limit' => fn ($rawGeneral) => ($rawGeneral['aux'] ?? [])['autorun_limit'] ?? 0, diff --git a/tests/GameClockBoundaryTest.php b/tests/GameClockBoundaryTest.php index 9799f955..36e57144 100644 --- a/tests/GameClockBoundaryTest.php +++ b/tests/GameClockBoundaryTest.php @@ -183,4 +183,27 @@ final class GameClockBoundaryTest extends TestCase ); } + public function testNationGeneralListProjectsStoredTimesAtApiBoundary(): void + { + $source = file_get_contents(__DIR__ . '/../hwe/sammo/API/Nation/GeneralList.php'); + self::assertIsString($source); + + self::assertStringContainsString( + '$clock = GameClock::isInitialized($gameStor) ? GameClock::fromStorage($gameStor) : null;', + $source, + ); + self::assertStringContainsString( + '$env[\'turntime\'] = $formatStoredTime($env[\'turntime\']);', + $source, + ); + self::assertStringContainsString( + '$troopTurnTime = $formatStoredTime($rawGeneralList[$troopLeaderID][\'turntime\']);', + $source, + ); + self::assertStringContainsString( + "? (string)\$value", + $source, + ); + } + }