Add ProjectZomboidClientActionLog (ClientActionLog.txt)
Strict 5-field bracketed format. Parser captures only the timestamp;
analysers that want steamid/action/player/coords/param decompose the
Line text via ClientActionPattern::FIELDS. Detectors: filename match
plus content signature on the IS{Enter,Exit}Vehicle / ISWalkToTimedAction
action tokens.
This commit is contained in:
44
src/Log/ProjectZomboid/ProjectZomboidClientActionLog.php
Normal file
44
src/Log/ProjectZomboid/ProjectZomboidClientActionLog.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\ClientActionPattern;
|
||||
|
||||
class ProjectZomboidClientActionLog extends ProjectZomboidEventLog
|
||||
{
|
||||
public static function getDefaultParser(): ParserInterface
|
||||
{
|
||||
return static::makePatternParser(
|
||||
ClientActionPattern::LINE,
|
||||
[PatternParser::TIME]
|
||||
);
|
||||
}
|
||||
|
||||
public static function getDefaultAnalyser(): AnalyserInterface
|
||||
{
|
||||
return new PatternAnalyser();
|
||||
}
|
||||
|
||||
public static function getDetectors(): array
|
||||
{
|
||||
return [
|
||||
(new FilenameDetector())
|
||||
->setPattern('/_ClientActionLog\.txt$/')
|
||||
->setWeight(0.95),
|
||||
(new WeightedSinglePatternDetector())
|
||||
->setPattern('/\[\d{17}\]\[(?:ISEnterVehicle|ISExitVehicle|ISWalkToTimedAction)\]\[/')
|
||||
->setWeight(0.95),
|
||||
];
|
||||
}
|
||||
|
||||
public function getTitle(): string
|
||||
{
|
||||
return "Project Zomboid Client Action Log";
|
||||
}
|
||||
}
|
||||
21
src/Pattern/ProjectZomboid/ClientActionPattern.php
Normal file
21
src/Pattern/ProjectZomboid/ClientActionPattern.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace IndifferentKetchup\Codex\Pattern\ProjectZomboid;
|
||||
|
||||
/**
|
||||
* Regex constants for the Project Zomboid ClientActionLog.txt format.
|
||||
*
|
||||
* Strict 5-field bracketed structure:
|
||||
* [time] [steamid][action][player][x,y,z][param].
|
||||
*
|
||||
* LINE captures, in order:
|
||||
* 1. time (DD-MM-YY HH:MM:SS.mmm)
|
||||
*
|
||||
* The remaining bracketed fields are extractable via FIELDS for analysers.
|
||||
*/
|
||||
class ClientActionPattern
|
||||
{
|
||||
public const string LINE = '/^\[(\d{2}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3})\] \[\d{17}\]\[[^\]]+\]\[[^\]]+\]\[\d+,\d+,\d+\]\[[^\]]+\]\.$/';
|
||||
|
||||
public const string FIELDS = '/^\[\d{2}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3}\] \[(?<steamid>\d{17})\]\[(?<action>[^\]]+)\]\[(?<player>[^\]]+)\]\[(?<x>\d+),(?<y>\d+),(?<z>\d+)\]\[(?<param>[^\]]+)\]\.$/';
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
[29-04-26 21:41:25.084] [76561198000000001][ISEnterVehicle][Player1][1000,2000,0][Van_LectroMax].
|
||||
[29-04-26 21:42:30.152] [76561198000000001][ISExitVehicle][Player1][1001,2001,0][Van_LectroMax].
|
||||
[29-04-26 21:46:31.034] [76561198000000001][ISEnterVehicle][Player1][1002,2002,0][Van_LectroMax].
|
||||
[29-04-26 21:46:53.257] [76561198000000001][ISExitVehicle][Player1][1003,2003,0][Van_LectroMax].
|
||||
[29-04-26 21:47:04.159] [76561198000000002][ISEnterVehicle][Player2][1010,2010,0][Pickup_Truck].
|
||||
[29-04-26 21:47:30.512] [76561198000000002][ISWalkToTimedAction][Player2][1011,2011,0][None].
|
||||
[29-04-26 21:48:00.812] [76561198000000002][ISExitVehicle][Player2][1011,2011,0][Pickup_Truck].
|
||||
[29-04-26 21:50:14.221] [76561198000000003][ISEnterVehicle][AdminUser][1020,2020,0][SUV_Modern].
|
||||
[29-04-26 21:51:00.512] [76561198000000003][ISExitVehicle][AdminUser][1021,2021,0][SUV_Modern].
|
||||
[29-04-26 21:52:15.018] [76561198000000001][ISEnterVehicle][Player1][1004,2004,0][Van_LectroMax].
|
||||
@@ -0,0 +1,44 @@
|
||||
<?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\ProjectZomboidClientActionLog;
|
||||
use IndifferentKetchup\Codex\Pattern\ProjectZomboid\ClientActionPattern;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ProjectZomboidClientActionLogTest extends TestCase
|
||||
{
|
||||
private function fixturePath(): string
|
||||
{
|
||||
return __DIR__ . '/../../../../src/Games/ProjectZomboid/fixtures/client-action-minimal.txt';
|
||||
}
|
||||
|
||||
public function testParsesEachLineAsAnEntry(): void
|
||||
{
|
||||
$log = (new ProjectZomboidClientActionLog())->setLogFile(new PathLogFile($this->fixturePath()));
|
||||
$log->parse();
|
||||
|
||||
$this->assertCount(10, $log->getEntries());
|
||||
}
|
||||
|
||||
public function testFieldsRegexExtractsStructuredData(): void
|
||||
{
|
||||
$line = "[29-04-26 21:41:25.084] [76561198000000001][ISEnterVehicle][Player1][1000,2000,0][Van_LectroMax].";
|
||||
$this->assertSame(1, preg_match(ClientActionPattern::FIELDS, $line, $m));
|
||||
$this->assertSame('76561198000000001', $m['steamid']);
|
||||
$this->assertSame('ISEnterVehicle', $m['action']);
|
||||
$this->assertSame('Player1', $m['player']);
|
||||
$this->assertSame('Van_LectroMax', $m['param']);
|
||||
}
|
||||
|
||||
public function testDetectiveDispatchesByContent(): void
|
||||
{
|
||||
$detective = (new Detective())
|
||||
->setLogFile(new PathLogFile($this->fixturePath()))
|
||||
->addPossibleLogClass(ProjectZomboidClientActionLog::class);
|
||||
|
||||
$this->assertInstanceOf(ProjectZomboidClientActionLog::class, $detective->detect());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user