From da68be0fb1277bbcffa7bb71354c0979e54711f2 Mon Sep 17 00:00:00 2001 From: Anthony Birkett Date: Tue, 1 Jun 2021 21:50:37 +0100 Subject: [PATCH] Rename SocketType -> EngineType. --- .../{Socket/SocketType.php => EngineType.php} | 13 +++++++++---- SourceQuery/Socket/GoldSourceSocket.php | 5 +++-- SourceQuery/Socket/SocketInterface.php | 2 +- SourceQuery/Socket/SourceSocket.php | 5 +++-- SourceQuery/Socket/TestableSocket.php | 11 ++++++----- SourceQuery/SourceQuery.php | 3 +-- Tests/Tests.php | 6 +++--- 7 files changed, 26 insertions(+), 19 deletions(-) rename SourceQuery/{Socket/SocketType.php => EngineType.php} (50%) diff --git a/SourceQuery/Socket/SocketType.php b/SourceQuery/EngineType.php similarity index 50% rename from SourceQuery/Socket/SocketType.php rename to SourceQuery/EngineType.php index 58c3bce..95a9797 100644 --- a/SourceQuery/Socket/SocketType.php +++ b/SourceQuery/EngineType.php @@ -13,10 +13,15 @@ declare(strict_types=1); * @internal */ -namespace xPaw\SourceQuery\Socket; +namespace xPaw\SourceQuery; -abstract class SocketType +abstract class EngineType { - public const GOLDSOURCE = 0; - public const SOURCE = 1; + public const GOLDSOURCE = 'GoldSource'; + public const SOURCE = 'Source'; + + public const ALL_ENGINES = [ + self::GOLDSOURCE, + self::SOURCE, + ]; } diff --git a/SourceQuery/Socket/GoldSourceSocket.php b/SourceQuery/Socket/GoldSourceSocket.php index 5a68848..79affaa 100644 --- a/SourceQuery/Socket/GoldSourceSocket.php +++ b/SourceQuery/Socket/GoldSourceSocket.php @@ -15,14 +15,15 @@ declare(strict_types=1); namespace xPaw\SourceQuery\Socket; +use xPaw\SourceQuery\EngineType; use xPaw\SourceQuery\Socket\Traits\GoldSourcePacketDataTrait; final class GoldSourceSocket extends AbstractSocket { use GoldSourcePacketDataTrait; - public function getType(): int + public function getType(): string { - return SocketType::GOLDSOURCE; + return EngineType::GOLDSOURCE; } } diff --git a/SourceQuery/Socket/SocketInterface.php b/SourceQuery/Socket/SocketInterface.php index 8f1fca9..963d297 100644 --- a/SourceQuery/Socket/SocketInterface.php +++ b/SourceQuery/Socket/SocketInterface.php @@ -36,7 +36,7 @@ interface SocketInterface /** * Get the socket type (goldsrc/src). */ - public function getType(): int; + public function getType(): string; public function open(string $address, int $port, int $timeout): void; diff --git a/SourceQuery/Socket/SourceSocket.php b/SourceQuery/Socket/SourceSocket.php index 27b66c0..fc807b6 100644 --- a/SourceQuery/Socket/SourceSocket.php +++ b/SourceQuery/Socket/SourceSocket.php @@ -15,14 +15,15 @@ declare(strict_types=1); namespace xPaw\SourceQuery\Socket; +use xPaw\SourceQuery\EngineType; use xPaw\SourceQuery\Socket\Traits\SourcePacketDataTrait; final class SourceSocket extends AbstractSocket { use SourcePacketDataTrait; - public function getType(): int + public function getType(): string { - return SocketType::SOURCE; + return EngineType::SOURCE; } } diff --git a/SourceQuery/Socket/TestableSocket.php b/SourceQuery/Socket/TestableSocket.php index 17ef936..bb84dc8 100644 --- a/SourceQuery/Socket/TestableSocket.php +++ b/SourceQuery/Socket/TestableSocket.php @@ -16,6 +16,7 @@ declare(strict_types=1); namespace xPaw\SourceQuery\Socket; use xPaw\SourceQuery\Buffer; +use xPaw\SourceQuery\EngineType; use xPaw\SourceQuery\Exception\InvalidPacketException; use xPaw\SourceQuery\Socket\Traits\GoldSourcePacketDataTrait; use xPaw\SourceQuery\Socket\Traits\SourcePacketDataTrait; @@ -35,18 +36,18 @@ final class TestableSocket extends AbstractSocket */ private array $packetQueue; - private int $type; + private string $type; /** * TestableSocket constructor. */ - public function __construct(int $type = SocketType::SOURCE) + public function __construct(string $type = EngineType::SOURCE) { $this->packetQueue = []; $this->type = $type; } - public function getType(): int + public function getType(): string { return $this->type; } @@ -117,7 +118,7 @@ final class TestableSocket extends AbstractSocket ?int &$checksum ): void { switch ($this->type) { - case SocketType::GOLDSOURCE: + case EngineType::GOLDSOURCE: $this->readInternalPacketDataGoldSource( $buffer, $count, @@ -128,7 +129,7 @@ final class TestableSocket extends AbstractSocket break; - case SocketType::SOURCE: + case EngineType::SOURCE: default: $this->readInternalPacketDataSource( $buffer, diff --git a/SourceQuery/SourceQuery.php b/SourceQuery/SourceQuery.php index 4bcc911..428e9a3 100644 --- a/SourceQuery/SourceQuery.php +++ b/SourceQuery/SourceQuery.php @@ -25,7 +25,6 @@ use xPaw\SourceQuery\QueryResponse\RulesQueryResponse; use xPaw\SourceQuery\QueryResponse\SourceInfoQueryResponse; use xPaw\SourceQuery\Rcon\RconInterface; use xPaw\SourceQuery\Socket\SocketInterface; -use xPaw\SourceQuery\Socket\SocketType; final class SourceQuery { @@ -201,7 +200,7 @@ final class SourceQuery } // Old GoldSource protocol, HLTV still uses it. - if (self::S2A_INFO_OLD === $type && SocketType::GOLDSOURCE === $this->socket->getType()) { + if (self::S2A_INFO_OLD === $type && EngineType::GOLDSOURCE === $this->socket->getType()) { return GoldSourceInfoQueryResponse::fromBuffer($buffer); } diff --git a/Tests/Tests.php b/Tests/Tests.php index 61ea988..2d97fa4 100644 --- a/Tests/Tests.php +++ b/Tests/Tests.php @@ -3,12 +3,12 @@ declare(strict_types=1); use PHPUnit\Framework\TestCase; +use xPaw\SourceQuery\EngineType; use xPaw\SourceQuery\Exception\AuthenticationException; use xPaw\SourceQuery\Exception\InvalidArgumentException; use xPaw\SourceQuery\Exception\InvalidPacketException; use xPaw\SourceQuery\Exception\SocketException; use xPaw\SourceQuery\Rcon\TestableRcon; -use xPaw\SourceQuery\Socket\SocketType; use xPaw\SourceQuery\Socket\TestableSocket; use xPaw\SourceQuery\SourceQuery; @@ -140,8 +140,8 @@ final class Tests extends TestCase public function testGetInfo(string $rawInput, array $expectedOutput): void { $socketType = isset($expectedOutput['IsMod']) - ? SocketType::GOLDSOURCE - : SocketType::SOURCE; + ? EngineType::GOLDSOURCE + : EngineType::SOURCE; $socket = new TestableSocket($socketType); $sourceQuery = $this->create($socket);