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.
This commit is contained in:
44
src/Log/ProjectZomboid/ProjectZomboidCmdLog.php
Normal file
44
src/Log/ProjectZomboid/ProjectZomboidCmdLog.php
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace IndifferentKetchup\Codex\Log\ProjectZomboid;
|
||||||
|
|
||||||
|
use IndifferentKetchup\Codex\Analyser\AnalyserInterface;
|
||||||
|
use IndifferentKetchup\Codex\Analyser\PatternAnalyser;
|
||||||
|
use IndifferentKetchup\Codex\Detective\FilenameDetector;
|
||||||
|
use IndifferentKetchup\Codex\Detective\WeightedSinglePatternDetector;
|
||||||
|
use IndifferentKetchup\Codex\Parser\ParserInterface;
|
||||||
|
use IndifferentKetchup\Codex\Parser\PatternParser;
|
||||||
|
use IndifferentKetchup\Codex\Pattern\ProjectZomboid\CmdPattern;
|
||||||
|
|
||||||
|
class ProjectZomboidCmdLog extends ProjectZomboidEventLog
|
||||||
|
{
|
||||||
|
public static function getDefaultParser(): ParserInterface
|
||||||
|
{
|
||||||
|
return static::makePatternParser(
|
||||||
|
CmdPattern::LINE,
|
||||||
|
[PatternParser::TIME]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getDefaultAnalyser(): AnalyserInterface
|
||||||
|
{
|
||||||
|
return new PatternAnalyser();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getDetectors(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
(new FilenameDetector())
|
||||||
|
->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";
|
||||||
|
}
|
||||||
|
}
|
||||||
18
src/Pattern/ProjectZomboid/CmdPattern.php
Normal file
18
src/Pattern/ProjectZomboid/CmdPattern.php
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace IndifferentKetchup\Codex\Pattern\ProjectZomboid;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Regex constants for the Project Zomboid cmd.txt format.
|
||||||
|
*
|
||||||
|
* [time] steamid "player" command @ x,y,z.
|
||||||
|
*
|
||||||
|
* LINE captures, in order:
|
||||||
|
* 1. time
|
||||||
|
*/
|
||||||
|
class CmdPattern
|
||||||
|
{
|
||||||
|
public const string LINE = '/^\[(\d{2}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3})\] \d{17} "[^"]+" \S+ @ \d+,\d+,\d+\.$/';
|
||||||
|
|
||||||
|
public const string FIELDS = '/^\[\d{2}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3}\] (?<steamid>\d{17}) "(?<player>[^"]+)" (?<command>\S+) @ (?<x>\d+),(?<y>\d+),(?<z>\d+)\.$/';
|
||||||
|
}
|
||||||
10
test/src/Games/ProjectZomboid/fixtures/cmd-minimal.txt
Normal file
10
test/src/Games/ProjectZomboid/fixtures/cmd-minimal.txt
Normal file
@@ -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.
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace IndifferentKetchup\Codex\Test\Tests\Games\ProjectZomboid\Log;
|
||||||
|
|
||||||
|
use IndifferentKetchup\Codex\Detective\Detective;
|
||||||
|
use IndifferentKetchup\Codex\Log\File\PathLogFile;
|
||||||
|
use IndifferentKetchup\Codex\Log\ProjectZomboid\ProjectZomboidCmdLog;
|
||||||
|
use IndifferentKetchup\Codex\Pattern\ProjectZomboid\CmdPattern;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
class ProjectZomboidCmdLogTest extends TestCase
|
||||||
|
{
|
||||||
|
private function fixturePath(): string
|
||||||
|
{
|
||||||
|
return __DIR__ . '/../../../../src/Games/ProjectZomboid/fixtures/cmd-minimal.txt';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testParsesEachLineAsAnEntry(): void
|
||||||
|
{
|
||||||
|
$log = (new ProjectZomboidCmdLog())->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());
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user