From cc9c512667aa0dcabb780ecf30cb7edc414ac0de Mon Sep 17 00:00:00 2001 From: indifferentketchup Date: Thu, 30 Apr 2026 20:36:26 +0000 Subject: [PATCH] Add ProjectZomboidCmdLog (cmd.txt) Per-line client RPC trace. Parser captures only the timestamp; analysers decompose steamid/player/command/coords via CmdPattern::FIELDS. Detectors: filename match plus content signature on the 'steamid "name" command @ x,y,z' line shape. --- .../ProjectZomboid/ProjectZomboidCmdLog.php | 44 +++++++++++++++++++ src/Pattern/ProjectZomboid/CmdPattern.php | 18 ++++++++ .../ProjectZomboid/fixtures/cmd-minimal.txt | 10 +++++ .../Log/ProjectZomboidCmdLogTest.php | 42 ++++++++++++++++++ 4 files changed, 114 insertions(+) create mode 100644 src/Log/ProjectZomboid/ProjectZomboidCmdLog.php create mode 100644 src/Pattern/ProjectZomboid/CmdPattern.php create mode 100644 test/src/Games/ProjectZomboid/fixtures/cmd-minimal.txt create mode 100644 test/tests/Games/ProjectZomboid/Log/ProjectZomboidCmdLogTest.php diff --git a/src/Log/ProjectZomboid/ProjectZomboidCmdLog.php b/src/Log/ProjectZomboid/ProjectZomboidCmdLog.php new file mode 100644 index 0000000..7724dca --- /dev/null +++ b/src/Log/ProjectZomboid/ProjectZomboidCmdLog.php @@ -0,0 +1,44 @@ +setPattern('/_cmd\.txt$/') + ->setWeight(0.95), + (new WeightedSinglePatternDetector()) + ->setPattern('/^\[[^\]]+\] \d{17} "[^"]+" \w[\w.]+ @ \d/m') + ->setWeight(0.85), + ]; + } + + public function getTitle(): string + { + return "Project Zomboid Command Log"; + } +} diff --git a/src/Pattern/ProjectZomboid/CmdPattern.php b/src/Pattern/ProjectZomboid/CmdPattern.php new file mode 100644 index 0000000..1f9947a --- /dev/null +++ b/src/Pattern/ProjectZomboid/CmdPattern.php @@ -0,0 +1,18 @@ +\d{17}) "(?[^"]+)" (?\S+) @ (?\d+),(?\d+),(?\d+)\.$/'; +} diff --git a/test/src/Games/ProjectZomboid/fixtures/cmd-minimal.txt b/test/src/Games/ProjectZomboid/fixtures/cmd-minimal.txt new file mode 100644 index 0000000..5c449ef --- /dev/null +++ b/test/src/Games/ProjectZomboid/fixtures/cmd-minimal.txt @@ -0,0 +1,10 @@ +[16-04-26 16:17:50.114] 76561198000000001 "Player1" ISLogSystem.writeLog @ 1000,2000,0. +[16-04-26 16:17:50.115] 76561198000000001 "Player1" ISLogSystem.writeLog @ 1000,2000,0. +[16-04-26 16:17:50.120] 76561198000000001 "Player1" example.RelayRequestDataController @ 1000,2000,0. +[16-04-26 16:17:59.081] 76561198000000001 "Player1" example.syncPartAnimation @ 1001,2001,0. +[16-04-26 16:17:59.315] 76561198000000001 "Player1" example.savePartsCondition @ 1001,2001,0. +[16-04-26 16:18:10.220] 76561198000000002 "Player2" ISLogSystem.writeLog @ 1010,2010,0. +[16-04-26 16:18:10.230] 76561198000000002 "Player2" example.syncPartAnimation @ 1010,2010,0. +[16-04-26 16:19:02.500] 76561198000000003 "AdminUser" admin.broadcastMessage @ 1020,2020,0. +[16-04-26 16:19:30.812] 76561198000000003 "AdminUser" admin.kickPlayer @ 1020,2020,0. +[16-04-26 16:20:00.014] 76561198000000001 "Player1" ISLogSystem.writeLog @ 1002,2002,0. diff --git a/test/tests/Games/ProjectZomboid/Log/ProjectZomboidCmdLogTest.php b/test/tests/Games/ProjectZomboid/Log/ProjectZomboidCmdLogTest.php new file mode 100644 index 0000000..1243c58 --- /dev/null +++ b/test/tests/Games/ProjectZomboid/Log/ProjectZomboidCmdLogTest.php @@ -0,0 +1,42 @@ +setLogFile(new PathLogFile($this->fixturePath())); + $log->parse(); + + $this->assertCount(10, $log->getEntries()); + } + + public function testFieldsRegexExtractsCommand(): void + { + $line = '[16-04-26 16:19:30.812] 76561198000000003 "AdminUser" admin.kickPlayer @ 1020,2020,0.'; + $this->assertSame(1, preg_match(CmdPattern::FIELDS, $line, $m)); + $this->assertSame('AdminUser', $m['player']); + $this->assertSame('admin.kickPlayer', $m['command']); + } + + public function testDetectiveDispatchesByContent(): void + { + $detective = (new Detective()) + ->setLogFile(new PathLogFile($this->fixturePath())) + ->addPossibleLogClass(ProjectZomboidCmdLog::class); + + $this->assertInstanceOf(ProjectZomboidCmdLog::class, $detective->detect()); + } +}