Add ProjectZomboidUserLog (user.txt)

Two row variants: low-level Connection events and player join/disconnect
events. The LINE regex accepts both shapes; analysers route via
CONNECTION (action/index/guid/id) and PLAYER_EVENT (steamid/player/event)
named-group regexes. Detectors: filename match plus content signatures
on either variant.
This commit is contained in:
2026-04-30 20:42:19 +00:00
parent 7b3342b3d2
commit d7c36ffc07
4 changed files with 136 additions and 0 deletions

View File

@@ -0,0 +1,47 @@
<?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\UserPattern;
class ProjectZomboidUserLog extends ProjectZomboidEventLog
{
public static function getDefaultParser(): ParserInterface
{
return static::makePatternParser(
UserPattern::LINE,
[PatternParser::TIME]
);
}
public static function getDefaultAnalyser(): AnalyserInterface
{
return new PatternAnalyser();
}
public static function getDetectors(): array
{
return [
(new FilenameDetector())
->setPattern('/_user\.txt$/')
->setWeight(0.95),
(new WeightedSinglePatternDetector())
->setPattern('/^\[[^\]]+\] Connection (?:add|disconnect) index=\d+ guid=\d+/m')
->setWeight(0.90),
(new WeightedSinglePatternDetector())
->setPattern('/^\[[^\]]+\] \d{17} "[^"]+" (?:attempting to join|allowed to join)/m')
->setWeight(0.85),
];
}
public function getTitle(): string
{
return "Project Zomboid User Log";
}
}

View File

@@ -0,0 +1,22 @@
<?php
namespace IndifferentKetchup\Codex\Pattern\ProjectZomboid;
/**
* Regex constants for the Project Zomboid user.txt format.
*
* Two row variants share the file: low-level connection events
* [time] Connection {add|disconnect} index=N guid=N id={N|null}.
* and player join/leave events
* [time] steamid "player" {attempting|allowed} to join.
*
* Both variants are accepted by LINE, which captures only the timestamp.
*/
class UserPattern
{
public const string LINE = '/^\[(\d{2}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3})\] (?:Connection (?:add|disconnect) index=\d+ guid=\d+ id=(?:\d+|null)|\d{17} "[^"]+" .+?)\.?$/';
public const string CONNECTION = '/^\[\d{2}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3}\] Connection (?<action>add|disconnect) index=(?<index>\d+) guid=(?<guid>\d+) id=(?<id>\d+|null)\.?$/';
public const string PLAYER_EVENT = '/^\[\d{2}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3}\] (?<steamid>\d{17}) "(?<player>[^"]+)" (?<event>.+?)\.?$/';
}