Add AdminTeleportedInformation insight
This commit is contained in:
28
src/Analysis/ProjectZomboid/AdminTeleportedInformation.php
Normal file
28
src/Analysis/ProjectZomboid/AdminTeleportedInformation.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace IndifferentKetchup\Codex\Analysis\ProjectZomboid;
|
||||
|
||||
use IndifferentKetchup\Codex\Analysis\Information;
|
||||
use IndifferentKetchup\Codex\Analysis\PatternInsightInterface;
|
||||
use IndifferentKetchup\Codex\Pattern\ProjectZomboid\AdminPattern;
|
||||
|
||||
class AdminTeleportedInformation extends Information implements PatternInsightInterface
|
||||
{
|
||||
public static function getPatterns(): array
|
||||
{
|
||||
return [AdminPattern::TELEPORTED_ENTRY];
|
||||
}
|
||||
|
||||
public function setMatches(array $matches, mixed $patternKey): void
|
||||
{
|
||||
$this->setLabel('Admin teleported');
|
||||
$this->setValue(sprintf(
|
||||
'%s teleported %s to %s,%s,%s',
|
||||
$matches['admin'],
|
||||
$matches['target'],
|
||||
$matches['x'],
|
||||
$matches['y'],
|
||||
$matches['z']
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -42,4 +42,6 @@ class AdminPattern
|
||||
public const string CHANGED_OPTION_ENTRY = '/^\[\d{2}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3}\] (?<admin>.+?) changed option (?<option>\S+?)=(?<value>.+?)\.?$/';
|
||||
|
||||
public const string RELOADED_OPTIONS_ENTRY = '/^\[\d{2}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3}\] (?<admin>.+?) reloaded options\.?$/';
|
||||
|
||||
public const string TELEPORTED_ENTRY = '/^\[\d{2}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3}\] (?<admin>.+?) teleported (?<target>.+?) to (?<x>\d+),(?<y>\d+),(?<z>-?\d+)\.?$/';
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace IndifferentKetchup\Codex\Test\Tests\Games\ProjectZomboid\Analysis;
|
||||
|
||||
use IndifferentKetchup\Codex\Analysis\ProjectZomboid\AdminTeleportedInformation;
|
||||
use IndifferentKetchup\Codex\Pattern\ProjectZomboid\AdminPattern;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class AdminTeleportedInformationTest extends TestCase
|
||||
{
|
||||
public function testGetPatternsReturnsEntryRegex(): void
|
||||
{
|
||||
$this->assertSame([AdminPattern::TELEPORTED_ENTRY], AdminTeleportedInformation::getPatterns());
|
||||
}
|
||||
|
||||
public function testEntryRegexMatchesPositiveZ(): void
|
||||
{
|
||||
$line = "[16-04-26 18:38:00.225] AdminUser teleported Player1 to 1100,2200,0.";
|
||||
$this->assertSame(1, preg_match(AdminPattern::TELEPORTED_ENTRY, $line, $m));
|
||||
|
||||
$insight = new AdminTeleportedInformation();
|
||||
$insight->setMatches($m, 0);
|
||||
|
||||
$this->assertSame('Admin teleported', $insight->getLabel());
|
||||
$this->assertSame('AdminUser teleported Player1 to 1100,2200,0', $insight->getValue());
|
||||
}
|
||||
|
||||
public function testEntryRegexHandlesNegativeZ(): void
|
||||
{
|
||||
$line = "[16-04-26 18:39:15.500] AdminUser teleported Player2 to 1100,2200,-1.";
|
||||
$this->assertSame(1, preg_match(AdminPattern::TELEPORTED_ENTRY, $line, $m));
|
||||
$this->assertSame('-1', $m['z']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user