From be298768ee12cc4878551057ad95b5dde0a300dc Mon Sep 17 00:00:00 2001 From: "Niklas (Krymonota)" Date: Thu, 26 Sep 2024 17:11:28 +0200 Subject: [PATCH 01/14] Only support supported PHP versions (8.1, 8.2, 8.3) --- .github/workflows/Tests.yml | 10 +--------- README.md | 2 +- composer.json | 4 ++-- 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/.github/workflows/Tests.yml b/.github/workflows/Tests.yml index 1400c755..051a1309 100644 --- a/.github/workflows/Tests.yml +++ b/.github/workflows/Tests.yml @@ -13,18 +13,10 @@ jobs: strategy: fail-fast: false matrix: - php: [7.0, 7.1, 7.2, 7.3, 7.4, 8.0, 8.1] + php: [8.1, 8.2, 8.3] ocular: [^1.9] experimental: [false] composer-extra: [''] - include: - - php: 5.6 - experimental: false - ocular: ~1.8.1 - - php: 8.2 - experimental: true - ocular: ^1.9 - composer-extra: '--ignore-platform-req=php+' env: PHP_VERSION: ${{ matrix.php }} name: PHP ${{ matrix.php }} diff --git a/README.md b/README.md index f6780f7c..b3b4fb32 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ GameQ is a PHP library that allows you to query multiple types of multiplayer ga This repository is a maintained fork of [Austinb/GameQ](https://github.com/Austinb/GameQ). ## Requirements -* PHP 5.6.40+ - [Tested](https://github.com/KrymoSoftware/GameQ/actions/workflows/Tests.yml) in PHP 5.6, 7.0, 7.1, 7.2, 7.3, 7.4, 8.0, 8.1 & 8.2-dev +* PHP 8.1+ - [Tested](https://github.com/KrymoSoftware/GameQ/actions/workflows/Tests.yml) in PHP 8.1, 8.2 and 8.3 * [Bzip2](http://www.php.net/manual/en/book.bzip2.php) - Used for A2S compressed responses ## Installation diff --git a/composer.json b/composer.json index 1d384689..3caff509 100644 --- a/composer.json +++ b/composer.json @@ -60,13 +60,13 @@ "wiki": "https://github.com/Austinb/GameQ/wiki" }, "require": { - "php": ">=5.6.40", + "php": ">=8.1", "ext-bz2": "*", "ext-xml": "*" }, "require-dev": { "ext-curl": "*", - "phpunit/phpunit": "^5.7 | ^6.0 | ^7.0 | ^8.0 | ^9.0", + "phpunit/phpunit": "^9.0", "phpunit/php-invoker": "*", "phpmd/phpmd": "@stable", "squizlabs/php_codesniffer": "3.*@stable", From e8e8c8d5832a08a8a703267718a43337d4854406 Mon Sep 17 00:00:00 2001 From: "Niklas (Krymonota)" Date: Thu, 26 Sep 2024 17:56:39 +0200 Subject: [PATCH 02/14] Add PHPStan --- .github/workflows/Tests.yml | 3 +++ composer.json | 15 +++++++++++++-- phpstan.dist.neon | 4 ++++ 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 phpstan.dist.neon diff --git a/.github/workflows/Tests.yml b/.github/workflows/Tests.yml index 051a1309..ad5bb503 100644 --- a/.github/workflows/Tests.yml +++ b/.github/workflows/Tests.yml @@ -51,5 +51,8 @@ jobs: vendor/bin/phpcs src tests --extensions=php --ignore=bootstrap --report=checkstyle --report-file=build/logs/checkstyle.xml --standard=build/config/phpcs.xml -v vendor/bin/phpmd src,tests xml build/config/phpmd.xml + - name: Run PHPStan + run: composer phpstan + - name: Run PHPUnit run: vendor/bin/phpunit -c phpunit.xml --verbose diff --git a/composer.json b/composer.json index 3caff509..84063746 100644 --- a/composer.json +++ b/composer.json @@ -70,7 +70,11 @@ "phpunit/php-invoker": "*", "phpmd/phpmd": "@stable", "squizlabs/php_codesniffer": "3.*@stable", - "corneltek/getoptionkit": "~2" + "corneltek/getoptionkit": "~2", + "phpstan/phpstan": "^1.12", + "phpstan/extension-installer": "^1.4", + "phpstan/phpstan-deprecation-rules": "^1.2", + "phpstan/phpstan-phpunit": "^1.4" }, "autoload": { "psr-4": { @@ -86,16 +90,23 @@ "test": [ "@test-phpcs", "@test-phpmd", + "@phpstan", "@test-php" ], "test-php": "vendor/bin/phpunit", "test-phpcs": "vendor/bin/phpcs src tests --extensions=php --ignore=bootstrap --report=checkstyle --report-file=build/logs/checkstyle.xml --standard=build/config/phpcs.xml -v", - "test-phpmd": "vendor/bin/phpmd src,tests xml build/config/phpmd.xml" + "test-phpmd": "vendor/bin/phpmd src,tests xml build/config/phpmd.xml", + "phpstan": "vendor/bin/phpstan analyse src" }, "scripts-descriptions": { "test": "Run all tests!", "test-php": "Run phpunit tests", "test-phpcs": "Run PHP Code Style checks", "test-phpmd": "Run PHP Mess Detector checks" + }, + "config": { + "allow-plugins": { + "phpstan/extension-installer": true + } } } diff --git a/phpstan.dist.neon b/phpstan.dist.neon new file mode 100644 index 00000000..91e64530 --- /dev/null +++ b/phpstan.dist.neon @@ -0,0 +1,4 @@ +parameters: + level: 5 + paths: + - src From 8db59fc4aede7d312670907d6bee2ba89e4fac17 Mon Sep 17 00:00:00 2001 From: "Niklas (Krymonota)" Date: Thu, 26 Sep 2024 18:05:51 +0200 Subject: [PATCH 03/14] Remove PHPMD --- .github/workflows/Tests.yml | 7 ++--- CONTRIBUTING.md | 15 ++++----- build/config/phpmd.xml | 63 ------------------------------------- composer.json | 21 ++++++------- 4 files changed, 18 insertions(+), 88 deletions(-) delete mode 100644 build/config/phpmd.xml diff --git a/.github/workflows/Tests.yml b/.github/workflows/Tests.yml index ad5bb503..cf809240 100644 --- a/.github/workflows/Tests.yml +++ b/.github/workflows/Tests.yml @@ -35,7 +35,7 @@ jobs: - name: Validate composer.json run: composer validate - + - name: Cache composer files uses: actions/cache@v3 with: @@ -48,11 +48,10 @@ jobs: - name: PHP CodeStyle run: | mkdir -p build/logs - vendor/bin/phpcs src tests --extensions=php --ignore=bootstrap --report=checkstyle --report-file=build/logs/checkstyle.xml --standard=build/config/phpcs.xml -v - vendor/bin/phpmd src,tests xml build/config/phpmd.xml + composer phpcs - name: Run PHPStan run: composer phpstan - name: Run PHPUnit - run: vendor/bin/phpunit -c phpunit.xml --verbose + run: composer phpunit diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index caf5489c..2ce1f615 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -5,33 +5,30 @@ Contributions are **welcome** and will be fully **credited**. ## Pull Requests - **Document any change in behavior** - Make sure the `README.md` and any other relevant documentation are kept up-to-date. - - **Create feature branches** - Don't ask us to pull from your master branch. - - **One pull request per feature** - If you want to do more than one thing, send multiple pull requests. ## Coding Standard - The **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** is to be used for all code. -- **[PHPMD](http://phpmd.org/)** is used to help keep the code clean but exceptions can exist. - +- **[PHPStan](https://phpstan.org/)** is used to help keep the code clean. At the moment, PHPStan level 5 is enforced. - Use the following commands to check your code before committing it: ```sh -$ vendor/bin/phpcs src tests --extensions=php --ignore=bootstrap --report=checkstyle --report-file=build/logs/checkstyle.xml --standard=build/config/phpcs.xml -v -$ vendor/bin/phpmd src,tests xml build/config/phpmd.xml +$ composer phpcs +$ composer phpstan ``` ## Tests - **Add tests!** - Your patch won't be accepted if it doesn't have tests. +- Use the following command to run the tests: -- Run tests by calling `phpunit` ```sh -$ vendor/bin/phpunit +$ composer phpunit ``` -The coding standard, mess detection and tests are validated by [GitHub Actions](.github). +The code quality is validated by [GitHub Actions](.github). # Can't Contribute? diff --git a/build/config/phpmd.xml b/build/config/phpmd.xml deleted file mode 100644 index ad293eef..00000000 --- a/build/config/phpmd.xml +++ /dev/null @@ -1,63 +0,0 @@ - - - - GameQ v3 mess detector rule set - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/composer.json b/composer.json index 84063746..ba28bf0e 100644 --- a/composer.json +++ b/composer.json @@ -68,7 +68,6 @@ "ext-curl": "*", "phpunit/phpunit": "^9.0", "phpunit/php-invoker": "*", - "phpmd/phpmd": "@stable", "squizlabs/php_codesniffer": "3.*@stable", "corneltek/getoptionkit": "~2", "phpstan/phpstan": "^1.12", @@ -88,21 +87,19 @@ }, "scripts": { "test": [ - "@test-phpcs", - "@test-phpmd", + "@phpcs", "@phpstan", - "@test-php" + "@phpunit" ], - "test-php": "vendor/bin/phpunit", - "test-phpcs": "vendor/bin/phpcs src tests --extensions=php --ignore=bootstrap --report=checkstyle --report-file=build/logs/checkstyle.xml --standard=build/config/phpcs.xml -v", - "test-phpmd": "vendor/bin/phpmd src,tests xml build/config/phpmd.xml", - "phpstan": "vendor/bin/phpstan analyse src" + "phpcs": "vendor/bin/phpcs src tests --extensions=php --ignore=bootstrap --report=checkstyle --report-file=build/logs/checkstyle.xml --standard=build/config/phpcs.xml -v", + "phpstan": "vendor/bin/phpstan analyse src", + "phpunit": "vendor/bin/phpunit" }, "scripts-descriptions": { - "test": "Run all tests!", - "test-php": "Run phpunit tests", - "test-phpcs": "Run PHP Code Style checks", - "test-phpmd": "Run PHP Mess Detector checks" + "test": "Run all tests and checks", + "phpcs": "Run PHP Code Style checks", + "phpstan": "Run PHPStan checks", + "phpunit": "Run PHPUnit tests" }, "config": { "allow-plugins": { From 8f40d00062f5d4c72159f7b4dcab06b9a2338348 Mon Sep 17 00:00:00 2001 From: "Niklas (Krymonota)" Date: Thu, 26 Sep 2024 18:06:21 +0200 Subject: [PATCH 04/14] Add `.gitkeep` file to `build/logs` folder Running tests failed locally unless you explicitly created the folder. --- .gitignore | 2 +- build/logs/.gitkeep | 0 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 build/logs/.gitkeep diff --git a/.gitignore b/.gitignore index c054e9b7..6d03f590 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ - /.buildpath /.project /.settings/* @@ -7,6 +6,7 @@ vendor composer.lock composer.phar coverage/ +!build/logs/.gitkeep build/logs/ test.php *.iml diff --git a/build/logs/.gitkeep b/build/logs/.gitkeep new file mode 100644 index 00000000..e69de29b From 0e0f55818be071da3d873310cd82f1256b189def Mon Sep 17 00:00:00 2001 From: "Niklas (Krymonota)" Date: Thu, 26 Sep 2024 18:06:45 +0200 Subject: [PATCH 05/14] Fix PHPStan errors up to level 5 --- src/GameQ/Filters/Stripcolors.php | 2 -- src/GameQ/Filters/Test.php | 2 -- src/GameQ/GameQ.php | 29 ++++++++++++++++------------ src/GameQ/Protocol.php | 8 ++------ src/GameQ/Protocols/Arma3.php | 3 +-- src/GameQ/Protocols/Bf3.php | 2 +- src/GameQ/Protocols/Bfbc2.php | 4 ++-- src/GameQ/Protocols/Cfx.php | 9 +-------- src/GameQ/Protocols/Codmw2.php | 5 ++--- src/GameQ/Protocols/Cs2d.php | 4 +--- src/GameQ/Protocols/Doom3.php | 8 ++------ src/GameQ/Protocols/Etqw.php | 6 +----- src/GameQ/Protocols/Ffow.php | 11 +---------- src/GameQ/Protocols/Gamespy.php | 3 --- src/GameQ/Protocols/Gamespy2.php | 4 ---- src/GameQ/Protocols/Gamespy3.php | 1 + src/GameQ/Protocols/Killingfloor.php | 2 -- src/GameQ/Protocols/Lhmp.php | 4 +--- src/GameQ/Protocols/M2mp.php | 8 ++------ src/GameQ/Protocols/Openttd.php | 9 ++++----- src/GameQ/Protocols/Quake2.php | 9 ++------- src/GameQ/Protocols/Quake3.php | 9 ++------- src/GameQ/Protocols/Quake4.php | 3 +-- src/GameQ/Protocols/Samp.php | 6 ------ src/GameQ/Protocols/Ship.php | 2 -- src/GameQ/Protocols/Source.php | 17 +--------------- src/GameQ/Protocols/Starmade.php | 2 -- src/GameQ/Protocols/Teamspeak2.php | 2 +- src/GameQ/Protocols/Teamspeak3.php | 2 +- src/GameQ/Protocols/Teeworlds.php | 2 -- src/GameQ/Protocols/Unreal2.php | 6 +----- src/GameQ/Protocols/Warsow.php | 3 --- src/GameQ/Query/Core.php | 2 -- src/GameQ/Query/Native.php | 9 +-------- src/GameQ/Result.php | 12 ++++++------ tests/MockDNS.php | 2 -- tests/Protocols/Base.php | 2 -- 37 files changed, 55 insertions(+), 159 deletions(-) diff --git a/src/GameQ/Filters/Stripcolors.php b/src/GameQ/Filters/Stripcolors.php index 1760b73a..0679b92e 100644 --- a/src/GameQ/Filters/Stripcolors.php +++ b/src/GameQ/Filters/Stripcolors.php @@ -33,8 +33,6 @@ class Stripcolors extends Base /** * Apply this filter * - * @SuppressWarnings(PHPMD.CyclomaticComplexity) - * * @param array $result * @param \GameQ\Server $server * diff --git a/src/GameQ/Filters/Test.php b/src/GameQ/Filters/Test.php index 836ddf3d..51c83292 100644 --- a/src/GameQ/Filters/Test.php +++ b/src/GameQ/Filters/Test.php @@ -32,8 +32,6 @@ class Test extends Base /** * Apply the filter. For this we just return whatever is sent * - * @SuppressWarnings(PHPMD) - * * @param array $result * @param \GameQ\Server $server * diff --git a/src/GameQ/GameQ.php b/src/GameQ/GameQ.php index a4ec2036..19b2a124 100644 --- a/src/GameQ/GameQ.php +++ b/src/GameQ/GameQ.php @@ -33,11 +33,11 @@ * * @author Austin Bischoff * - * @property bool $debug - * @property string $capture_packets_file - * @property int $stream_timeout - * @property int $timeout - * @property int $write_wait + * @property bool $debug + * @property string|null $capture_packets_file + * @property int $stream_timeout + * @property int $timeout + * @property int $write_wait */ class GameQ { @@ -149,15 +149,16 @@ public function __get($option) * * @param mixed $option * @param mixed $value - * - * @return bool */ public function __set($option, $value) { $this->options[$option] = $value; + } - return true; + public function __isset($option) + { + return isset($this->options[$option]); } public function getServers() @@ -437,9 +438,11 @@ protected function doChallenges() // We have at least one server with a challenge, we need to listen for responses if ($server_challenge) { // Now we need to listen for and grab challenge response(s) - $responses = call_user_func_array( + $responses = call_user_func( [$this->query, 'getResponses'], - [$sockets, $this->timeout, $this->stream_timeout] + $sockets, + $this->timeout, + $this->stream_timeout ); // Iterate over the challenge responses @@ -535,9 +538,11 @@ protected function doQueries() } // Now we need to listen for and grab response(s) - $responses = call_user_func_array( + $responses = call_user_func( [$this->query, 'getResponses'], - [$sockets, $this->timeout, $this->stream_timeout] + $sockets, + $this->timeout, + $this->stream_timeout ); // Iterate over the responses diff --git a/src/GameQ/Protocol.php b/src/GameQ/Protocol.php index 6d94a45f..5c8deff0 100644 --- a/src/GameQ/Protocol.php +++ b/src/GameQ/Protocol.php @@ -23,8 +23,6 @@ /** * Handles the core functionality for the protocols * - * @SuppressWarnings(PHPMD.NumberOfChildren) - * * @author Austin Bischoff */ abstract class Protocol @@ -356,7 +354,7 @@ public function options($options = []) /** * Return specific packet(s) * - * @param array $type + * @param array|string $type * * @return array */ @@ -375,7 +373,7 @@ public function getPacket($type = []) $packets[$packet_type] = $packet_data; } } - } elseif ($type == '!challenge') { + } elseif ($type === '!challenge') { // Loop the packets foreach ($this->packets as $packet_type => $packet_data) { // Dont want challenge packets @@ -434,7 +432,6 @@ public function hasChallenge() * This should be overloaded by extending class * * @codeCoverageIgnore - * @SuppressWarnings(PHPMD.UnusedFormalParameter) * * @param \GameQ\Buffer $challenge_buffer * @@ -483,7 +480,6 @@ public function getNormalize() * Generic method to allow protocol classes to do work right before the query is sent * * @codeCoverageIgnore - * @SuppressWarnings(PHPMD.UnusedFormalParameter) * * @param \GameQ\Server $server */ diff --git a/src/GameQ/Protocols/Arma3.php b/src/GameQ/Protocols/Arma3.php index fdc2cba4..62a2b63f 100644 --- a/src/GameQ/Protocols/Arma3.php +++ b/src/GameQ/Protocols/Arma3.php @@ -133,8 +133,7 @@ protected function processRules(Buffer $buffer) // Make a new buffer with the reassembled data $responseBuffer = new Buffer($data); - // Kill the old buffer, should be empty - unset($buffer, $data); + unset($data); // Set the result to a new result instance $result = new Result(); diff --git a/src/GameQ/Protocols/Bf3.php b/src/GameQ/Protocols/Bf3.php index 90845159..a83b74bb 100644 --- a/src/GameQ/Protocols/Bf3.php +++ b/src/GameQ/Protocols/Bf3.php @@ -305,7 +305,7 @@ protected function processVersion(Buffer $buffer) $result->add('version', $items[2]); - unset($buffer, $items); + unset($items); return $result->fetch(); } diff --git a/src/GameQ/Protocols/Bfbc2.php b/src/GameQ/Protocols/Bfbc2.php index b7167a02..e9ed0683 100644 --- a/src/GameQ/Protocols/Bfbc2.php +++ b/src/GameQ/Protocols/Bfbc2.php @@ -156,7 +156,7 @@ public function processResponse() // Check to make sure the expected length matches the real length // Subtract 4 for the header burn - if ($packetLength != ($buffer->readInt32() - 4)) { + if ($packetLength !== ($buffer->readInt32() - 4)) { throw new Exception(__METHOD__ . " packet length does not match expected length!"); } @@ -283,7 +283,7 @@ protected function processVersion(Buffer $buffer) $result->add('version', $items[2]); - unset($buffer, $items); + unset($items); return $result->fetch(); } diff --git a/src/GameQ/Protocols/Cfx.php b/src/GameQ/Protocols/Cfx.php index 0aa92659..06fe7a02 100644 --- a/src/GameQ/Protocols/Cfx.php +++ b/src/GameQ/Protocols/Cfx.php @@ -82,8 +82,6 @@ class Cfx extends Protocol /** * Holds the Player list so we can overwrite it back - * - * @var string */ protected $PlayerList = []; @@ -140,9 +138,7 @@ public function processResponse() } // Offload the call - $results = call_user_func_array([$this, $this->responses[$response_type]], [$buffer]); - - return $results; + return $this->{$this->responses[$response_type]}($buffer); } /* @@ -170,9 +166,6 @@ protected function processStatus(Buffer $buffer) // Explode the data $data = explode('\\', $buffer->getBuffer()); - // No longer needed - unset($buffer); - $itemCount = count($data); // Now lets loop the array diff --git a/src/GameQ/Protocols/Codmw2.php b/src/GameQ/Protocols/Codmw2.php index 290e43c9..c68b5666 100644 --- a/src/GameQ/Protocols/Codmw2.php +++ b/src/GameQ/Protocols/Codmw2.php @@ -80,9 +80,8 @@ protected function processPlayers(Buffer $buffer) // Add Playercount $result->add('clients', count($players)); - - // Clear - unset($buffer, $players); + + unset($players); return $result->fetch(); } diff --git a/src/GameQ/Protocols/Cs2d.php b/src/GameQ/Protocols/Cs2d.php index 0f238fdd..d4cb2b12 100644 --- a/src/GameQ/Protocols/Cs2d.php +++ b/src/GameQ/Protocols/Cs2d.php @@ -208,8 +208,6 @@ protected function processDetails(Buffer $buffer) $result->add('num_bots', (($this->readFlag($serverFlags, 5)) ? $buffer->readInt8() : 0)); $result->add('dedicated', 1); - unset($buffer); - return $result->fetch(); } @@ -243,7 +241,7 @@ protected function processPlayers(Buffer $buffer) } } - unset($buffer, $id); + unset($id); return $result->fetch(); } diff --git a/src/GameQ/Protocols/Doom3.php b/src/GameQ/Protocols/Doom3.php index 2e00f5f1..f277213f 100644 --- a/src/GameQ/Protocols/Doom3.php +++ b/src/GameQ/Protocols/Doom3.php @@ -123,7 +123,7 @@ public function processResponse() throw new Exception(__METHOD__ . " response type '" . bin2hex($header) . "' is not valid"); } - return call_user_func_array([$this, $this->responses[$header]], [$buffer]); + return $this->{$this->responses[$header]}($buffer); } /** @@ -143,8 +143,6 @@ protected function processStatus(Buffer $buffer) $this->processPlayers($buffer) ); - unset($buffer); - // Return results return $results; } @@ -176,8 +174,6 @@ protected function processServerInfo(Buffer $buffer) $result->add($key, $val); } - unset($buffer); - return $result->fetch(); } @@ -214,7 +210,7 @@ protected function processPlayers(Buffer $buffer) $result->add('clients', $playerCount); // Clear - unset($buffer, $playerCount); + unset($playerCount); return $result->fetch(); } diff --git a/src/GameQ/Protocols/Etqw.php b/src/GameQ/Protocols/Etqw.php index 1f3a446c..bbb78ae0 100644 --- a/src/GameQ/Protocols/Etqw.php +++ b/src/GameQ/Protocols/Etqw.php @@ -117,9 +117,7 @@ public function processResponse() } // Offload the call - $results = call_user_func_array([$this, $this->responses[$response_type]], [$buffer]); - - return $results; + return $this->{$this->responses[$response_type]}($buffer); } /* @@ -176,8 +174,6 @@ protected function processStatus(Buffer $buffer) // Now let's parse the extended player info $this->parsePlayersExtra($buffer, $result); - unset($buffer); - return $result->fetch(); } diff --git a/src/GameQ/Protocols/Ffow.php b/src/GameQ/Protocols/Ffow.php index 00c33d47..e419b726 100644 --- a/src/GameQ/Protocols/Ffow.php +++ b/src/GameQ/Protocols/Ffow.php @@ -185,8 +185,6 @@ protected function processInfo(Buffer $buffer) $result->add('max_rounds', $buffer->readInt8()); $result->add('time_left', $buffer->readInt16()); - unset($buffer); - return $result->fetch(); } @@ -217,8 +215,6 @@ protected function processRules(Buffer $buffer) } } - unset($buffer); - return $result->fetch(); } @@ -233,11 +229,6 @@ protected function processRules(Buffer $buffer) */ protected function processPlayers(Buffer $buffer) { - // Set the result to a new result instance - $result = new Result(); - - unset($buffer); - - return $result->fetch(); + return (new Result())->fetch(); } } diff --git a/src/GameQ/Protocols/Gamespy.php b/src/GameQ/Protocols/Gamespy.php index b1a1e4fa..0c7707f3 100644 --- a/src/GameQ/Protocols/Gamespy.php +++ b/src/GameQ/Protocols/Gamespy.php @@ -131,9 +131,6 @@ protected function processStatus(Buffer $buffer) // Explode the data $data = explode('\\', $buffer->getBuffer()); - // No longer needed - unset($buffer); - // Init some vars $numPlayers = 0; $numTeams = 0; diff --git a/src/GameQ/Protocols/Gamespy2.php b/src/GameQ/Protocols/Gamespy2.php index c7788d9e..f8cdea29 100644 --- a/src/GameQ/Protocols/Gamespy2.php +++ b/src/GameQ/Protocols/Gamespy2.php @@ -185,8 +185,6 @@ protected function processDetails(Buffer $buffer) $result->add($key, utf8_encode($buffer->readString())); } - unset($buffer); - return $result->fetch(); } @@ -213,8 +211,6 @@ protected function processPlayers(Buffer $buffer) // Teams are next $this->parsePlayerTeam('teams', $buffer, $result); - unset($buffer); - return $result->fetch(); } diff --git a/src/GameQ/Protocols/Gamespy3.php b/src/GameQ/Protocols/Gamespy3.php index 2df0a4bd..a043531b 100644 --- a/src/GameQ/Protocols/Gamespy3.php +++ b/src/GameQ/Protocols/Gamespy3.php @@ -99,6 +99,7 @@ public function challengeParseAndApply(Buffer $challenge_buffer) // Check for valid challenge (see #197) if ($challenge) { + $challenge = (int) $challenge; // Encode chellenge result $challenge_result = sprintf( "%c%c%c%c", diff --git a/src/GameQ/Protocols/Killingfloor.php b/src/GameQ/Protocols/Killingfloor.php index 9cc19643..dfa5593e 100644 --- a/src/GameQ/Protocols/Killingfloor.php +++ b/src/GameQ/Protocols/Killingfloor.php @@ -89,8 +89,6 @@ protected function processDetails(Buffer $buffer) $result->add('maxplayers', $buffer->readInt32()); $result->add('currentwave', $buffer->readInt32()); - unset($buffer); - return $result->fetch(); } } diff --git a/src/GameQ/Protocols/Lhmp.php b/src/GameQ/Protocols/Lhmp.php index 3d5e81f3..1c664196 100644 --- a/src/GameQ/Protocols/Lhmp.php +++ b/src/GameQ/Protocols/Lhmp.php @@ -176,8 +176,6 @@ protected function processDetails(Buffer $buffer) $result->add('website', utf8_encode($buffer->readPascalString())); $result->add('mapname', utf8_encode($buffer->readPascalString())); - unset($buffer); - return $result->fetch(); } @@ -207,7 +205,7 @@ protected function processPlayers(Buffer $buffer) } } - unset($buffer, $id); + unset($id); return $result->fetch(); } diff --git a/src/GameQ/Protocols/M2mp.php b/src/GameQ/Protocols/M2mp.php index a6076e3a..2efbf586 100644 --- a/src/GameQ/Protocols/M2mp.php +++ b/src/GameQ/Protocols/M2mp.php @@ -128,11 +128,11 @@ public function processResponse() // Header // Figure out which packet response this is - if ($header != "M2MP") { + if ($header !== "M2MP") { throw new Exception(__METHOD__ . " response type '" . bin2hex($header) . "' is not valid"); } - return call_user_func_array([$this, $this->responses[$header]], [$buffer]); + return $this->{$this->responses[$header]}($buffer); } /** @@ -152,8 +152,6 @@ protected function processStatus(Buffer $buffer) $this->processPlayers($buffer) ); - unset($buffer); - // Return results return $results; } @@ -181,8 +179,6 @@ protected function processServerInfo(Buffer $buffer) $result->add('gamemode', $buffer->readPascalString(1, true)); $result->add('password', (bool) $buffer->readInt8()); - unset($buffer); - return $result->fetch(); } diff --git a/src/GameQ/Protocols/Openttd.php b/src/GameQ/Protocols/Openttd.php index 75c44fe1..e20af384 100644 --- a/src/GameQ/Protocols/Openttd.php +++ b/src/GameQ/Protocols/Openttd.php @@ -106,15 +106,15 @@ public function processResponse() // Grab the header $length = $buffer->readInt16(); //$type = $buffer->readInt8(); - $buffer->skip(1); // Skip the "$type" as its not used in the code, and to comply with phpmd it cant be assigned and not used. + $buffer->skip(1); // Skip the "$type" as its not used in the code. // Header // Figure out which packet response this is - if ($packetLength != $length) { - throw new Exception(__METHOD__ . " response type '" . bin2hex($length) . "' is not valid"); + if ($packetLength !== $length) { + throw new Exception(__METHOD__ . " header length '" .$length . "' does not match packet length '" . $packetLength . "'."); } - return call_user_func_array([$this, 'processServerInfo'], [$buffer]); + return $this->processServerInfo($buffer); } /** @@ -176,7 +176,6 @@ protected function processServerInfo(Buffer $buffer) $result->add('dedicated', $buffer->readInt8()); // Cascades all the way down even if case is meet } - unset($buffer); return $result->fetch(); } diff --git a/src/GameQ/Protocols/Quake2.php b/src/GameQ/Protocols/Quake2.php index f0366c2c..31f1a3bf 100644 --- a/src/GameQ/Protocols/Quake2.php +++ b/src/GameQ/Protocols/Quake2.php @@ -108,7 +108,7 @@ public function processResponse() throw new Exception(__METHOD__ . " response type '" . bin2hex($header) . "' is not valid"); } - return call_user_func_array([$this, $this->responses[$header]], [$buffer]); + return $this->{$this->responses[$header]}($buffer); } /** @@ -128,8 +128,6 @@ protected function processStatus(Buffer $buffer) $this->processPlayers(new Buffer($buffer->getBuffer())) ); - unset($buffer); - // Return results return $results; } @@ -161,8 +159,6 @@ protected function processServerInfo(Buffer $buffer) $result->add('password', 0); $result->add('mod', 0); - unset($buffer); - return $result->fetch(); } @@ -211,8 +207,7 @@ protected function processPlayers(Buffer $buffer) $result->add('clients', $playerCount); - // Clear - unset($buffer, $playerCount); + unset($playerCount); return $result->fetch(); } diff --git a/src/GameQ/Protocols/Quake3.php b/src/GameQ/Protocols/Quake3.php index 6269b927..cffd844a 100644 --- a/src/GameQ/Protocols/Quake3.php +++ b/src/GameQ/Protocols/Quake3.php @@ -108,7 +108,7 @@ public function processResponse() throw new Exception(__METHOD__ . " response type '" . bin2hex($header) . "' is not valid"); } - return call_user_func_array([$this, $this->responses[$header]], [$buffer]); + return $this->{$this->responses[$header]}($buffer); } protected function processStatus(Buffer $buffer) @@ -121,8 +121,6 @@ protected function processStatus(Buffer $buffer) $this->processPlayers(new Buffer($buffer->getBuffer())) ); - unset($buffer); - // Return results return $results; } @@ -151,8 +149,6 @@ protected function processServerInfo(Buffer $buffer) ); } - unset($buffer); - return $result->fetch(); } @@ -206,8 +202,7 @@ protected function processPlayers(Buffer $buffer) $result->add('clients', $playerCount); - // Clear - unset($buffer, $playerCount); + unset($playerCount); return $result->fetch(); } diff --git a/src/GameQ/Protocols/Quake4.php b/src/GameQ/Protocols/Quake4.php index 6a5f5c7e..4fcee943 100644 --- a/src/GameQ/Protocols/Quake4.php +++ b/src/GameQ/Protocols/Quake4.php @@ -76,8 +76,7 @@ protected function processPlayers(Buffer $buffer) // Add the number of players to the result $result->add('numplayers', $playerCount); - // Clear - unset($buffer, $playerCount); + unset($playerCount); return $result->fetch(); } diff --git a/src/GameQ/Protocols/Samp.php b/src/GameQ/Protocols/Samp.php index cf01f834..caba7a81 100644 --- a/src/GameQ/Protocols/Samp.php +++ b/src/GameQ/Protocols/Samp.php @@ -217,8 +217,6 @@ protected function processStatus(Buffer $buffer) $result->add('gametype', $buffer->read($buffer->readInt32())); $result->add('language', $buffer->read($buffer->readInt32())); - unset($buffer); - return $result->fetch(); } @@ -246,8 +244,6 @@ protected function processPlayers(Buffer $buffer) $result->addPlayer('ping', $buffer->readInt32()); } - unset($buffer); - return $result->fetch(); } @@ -272,8 +268,6 @@ protected function processRules(Buffer $buffer) $result->add($buffer->readPascalString(), $buffer->readPascalString()); } - unset($buffer); - return $result->fetch(); } } diff --git a/src/GameQ/Protocols/Ship.php b/src/GameQ/Protocols/Ship.php index 9c3bee9e..e4ad6ca9 100644 --- a/src/GameQ/Protocols/Ship.php +++ b/src/GameQ/Protocols/Ship.php @@ -88,8 +88,6 @@ protected function processPlayers(Buffer $buffer) } } - unset($buffer); - return $result->fetch(); } } diff --git a/src/GameQ/Protocols/Source.php b/src/GameQ/Protocols/Source.php index dbf9212a..4c6e81b5 100644 --- a/src/GameQ/Protocols/Source.php +++ b/src/GameQ/Protocols/Source.php @@ -29,8 +29,6 @@ * This class is used as the basis for all other source based servers * that rely on the source protocol for game querying. * - * @SuppressWarnings(PHPMD.NumberOfChildren) - * * @author Austin Bischoff */ class Source extends Protocol @@ -217,7 +215,7 @@ public function processResponse() } // Free up memory - unset($packets, $packet, $packet_id, $response_type); + unset($packets, $packet_id, $response_type); return $results; } @@ -229,8 +227,6 @@ public function processResponse() /** * Process the split packets and decompress if necessary * - * @SuppressWarnings(PHPMD.UnusedLocalVariable) - * * @param $packet_id * @param array $packets * @@ -323,9 +319,6 @@ protected function processPackets($packet_id, array $packets = []) unset($buffer); } - // Free some memory - unset($packets, $packet); - // Sort the packets by packet number ksort($packs); @@ -401,8 +394,6 @@ protected function processDetails(Buffer $buffer) unset($edf); } - unset($buffer); - return $result->fetch(); } @@ -449,8 +440,6 @@ protected function processDetailsGoldSource(Buffer $buffer) $result->add('secure', $buffer->readInt8()); $result->add('num_bots', $buffer->readInt8()); - unset($buffer); - return $result->fetch(); } @@ -486,8 +475,6 @@ protected function processPlayers(Buffer $buffer) $result->addPlayer('time', $buffer->readFloat32()); } - unset($buffer); - return $result->fetch(); } @@ -515,8 +502,6 @@ protected function processRules(Buffer $buffer) $result->add($buffer->readString(), $buffer->readString()); } - unset($buffer); - return $result->fetch(); } } diff --git a/src/GameQ/Protocols/Starmade.php b/src/GameQ/Protocols/Starmade.php index 09a033fb..ee591fea 100644 --- a/src/GameQ/Protocols/Starmade.php +++ b/src/GameQ/Protocols/Starmade.php @@ -151,8 +151,6 @@ public function processResponse() /** * Parse the server response parameters * - * @SuppressWarnings(PHPMD.CyclomaticComplexity) - * * @param \GameQ\Buffer $buffer * * @return array diff --git a/src/GameQ/Protocols/Teamspeak2.php b/src/GameQ/Protocols/Teamspeak2.php index df0d59aa..69954dd2 100644 --- a/src/GameQ/Protocols/Teamspeak2.php +++ b/src/GameQ/Protocols/Teamspeak2.php @@ -184,7 +184,7 @@ public function processResponse() } } - unset($buffer, $sections, $section, $check); + unset($buffer, $sections, $check); return $result->fetch(); } diff --git a/src/GameQ/Protocols/Teamspeak3.php b/src/GameQ/Protocols/Teamspeak3.php index c66f6a44..96f9c99d 100644 --- a/src/GameQ/Protocols/Teamspeak3.php +++ b/src/GameQ/Protocols/Teamspeak3.php @@ -198,7 +198,7 @@ public function processResponse() } } - unset($buffer, $sections, $section, $check); + unset($buffer, $sections, $check); return $result->fetch(); } diff --git a/src/GameQ/Protocols/Teeworlds.php b/src/GameQ/Protocols/Teeworlds.php index 1bdaa472..75e52d1d 100644 --- a/src/GameQ/Protocols/Teeworlds.php +++ b/src/GameQ/Protocols/Teeworlds.php @@ -174,8 +174,6 @@ protected function processAll(Buffer $buffer) $result->addPlayer('team', $buffer->readString()); } - unset($buffer); - return $result->fetch(); } } diff --git a/src/GameQ/Protocols/Unreal2.php b/src/GameQ/Protocols/Unreal2.php index 0ef06757..4bc296ff 100644 --- a/src/GameQ/Protocols/Unreal2.php +++ b/src/GameQ/Protocols/Unreal2.php @@ -174,8 +174,6 @@ protected function processDetails(Buffer $buffer) $result->add('maxplayers', $buffer->readInt32()); $result->add('ping', $buffer->readInt32()); // 0 - unset($buffer); - return $result->fetch(); } @@ -207,7 +205,7 @@ protected function processPlayers(Buffer $buffer) } } - unset($buffer, $id); + unset($id); return $result->fetch(); } @@ -239,8 +237,6 @@ protected function processRules(Buffer $buffer) $result->add(strtolower($key), utf8_encode($buffer->readPascalString(1))); } - unset($buffer); - return $result->fetch(); } } diff --git a/src/GameQ/Protocols/Warsow.php b/src/GameQ/Protocols/Warsow.php index f1d629a9..ed803fae 100644 --- a/src/GameQ/Protocols/Warsow.php +++ b/src/GameQ/Protocols/Warsow.php @@ -88,9 +88,6 @@ protected function processPlayers(Buffer $buffer) unset($playerInfo); } - // Clear - unset($buffer); - return $result->fetch(); } } diff --git a/src/GameQ/Query/Core.php b/src/GameQ/Query/Core.php index fd1949da..016dad27 100644 --- a/src/GameQ/Query/Core.php +++ b/src/GameQ/Query/Core.php @@ -177,8 +177,6 @@ abstract public function close(); /** * Read the responses from the socket(s) * - * @SuppressWarnings(PHPMD.UnusedFormalParameter) - * * @param array $sockets * @param int $timeout * @param int $stream_timeout diff --git a/src/GameQ/Query/Native.php b/src/GameQ/Query/Native.php index 24200b0c..455f087f 100644 --- a/src/GameQ/Query/Native.php +++ b/src/GameQ/Query/Native.php @@ -133,9 +133,6 @@ protected function create() /** * Pull the responses out of the stream * - * @SuppressWarnings(PHPMD.CyclomaticComplexity) - * @SuppressWarnings(PHPMD.NPathComplexity) - * * @param array $sockets * @param int $timeout * @param int $stream_timeout @@ -144,10 +141,6 @@ protected function create() */ public function getResponses(array $sockets, $timeout, $stream_timeout) { - - // Set the loop to active - $loop_active = true; - // Will hold the responses read from the sockets $responses = []; @@ -180,7 +173,7 @@ public function getResponses(array $sockets, $timeout, $stream_timeout) $time_stop = microtime(true) + $timeout; // Let's loop until we break something. - while ($loop_active && microtime(true) < $time_stop) { + while (microtime(true) < $time_stop) { // Check to make sure $read is not empty, if so we are done if (empty($read)) { break; diff --git a/src/GameQ/Result.php b/src/GameQ/Result.php index 7023f17a..74f17f66 100644 --- a/src/GameQ/Result.php +++ b/src/GameQ/Result.php @@ -37,8 +37,8 @@ class Result /** * Adds variable to results * - * @param string $name Variable name - * @param string|array $value Variable value + * @param string $name Variable name + * @param string|array|int|float|bool $value Variable value */ public function add($name, $value) { @@ -49,8 +49,8 @@ public function add($name, $value) /** * Adds player variable to output * - * @param string $name Variable name - * @param string $value Variable value + * @param string $name Variable name + * @param string|int|float $value Variable value */ public function addPlayer($name, $value) { @@ -61,8 +61,8 @@ public function addPlayer($name, $value) /** * Adds player variable to output * - * @param string $name Variable name - * @param string $value Variable value + * @param string $name Variable name + * @param string|int|float $value Variable value */ public function addTeam($name, $value) { diff --git a/tests/MockDNS.php b/tests/MockDNS.php index 1821b719..a0e1777e 100644 --- a/tests/MockDNS.php +++ b/tests/MockDNS.php @@ -6,8 +6,6 @@ * MockDNS class using monkey patching. Inspired by symfony/phpunit-bridge * * @see https://github.com/symfony/phpunit-bridge/blob/5.3/DnsMock.php - * - * @SuppressWarnings(PHPMD) */ class MockDNS { diff --git a/tests/Protocols/Base.php b/tests/Protocols/Base.php index 27820e9e..55d36291 100644 --- a/tests/Protocols/Base.php +++ b/tests/Protocols/Base.php @@ -23,8 +23,6 @@ /** * Class Base for protocol tests * - * @SuppressWarnings(PHPMD.NumberOfChildren) - * * @package GameQ\Tests\Protocols */ abstract class Base extends TestBase From 2c07be92296a23f5821961c96897a6c30ea47b66 Mon Sep 17 00:00:00 2001 From: "Niklas (Krymonota)" Date: Thu, 26 Sep 2024 18:29:42 +0200 Subject: [PATCH 06/14] Fix some more obvious code issues --- src/GameQ/Buffer.php | 42 ++++++++++-------------------- src/GameQ/Filters/Stripcolors.php | 4 +-- src/GameQ/GameQ.php | 6 ++--- src/GameQ/Protocols/Ase.php | 4 +-- src/GameQ/Protocols/Cfx.php | 7 +++-- src/GameQ/Protocols/Cfxplayers.php | 3 +-- src/GameQ/Protocols/Doom3.php | 5 +--- src/GameQ/Protocols/Dow.php | 2 -- src/GameQ/Protocols/Etqw.php | 6 ++--- src/GameQ/Protocols/Ffow.php | 2 +- src/GameQ/Protocols/Gamespy.php | 2 +- src/GameQ/Protocols/Gamespy2.php | 6 ++--- src/GameQ/Protocols/Gamespy3.php | 9 ++++--- src/GameQ/Protocols/Lhmp.php | 2 +- src/GameQ/Protocols/M2mp.php | 5 +--- src/GameQ/Protocols/Mumble.php | 2 +- src/GameQ/Protocols/Quake2.php | 5 +--- src/GameQ/Protocols/Quake3.php | 6 +---- src/GameQ/Protocols/Samp.php | 4 +-- src/GameQ/Protocols/Source.php | 15 +++++------ src/GameQ/Protocols/Starmade.php | 2 +- src/GameQ/Protocols/Teamspeak2.php | 8 +++--- src/GameQ/Protocols/Teamspeak3.php | 10 +++---- src/GameQ/Protocols/Tibia.php | 5 ++-- src/GameQ/Protocols/Tshock.php | 4 +-- src/GameQ/Protocols/Ventrilo.php | 4 +-- src/GameQ/Query/Core.php | 2 +- src/GameQ/Query/Native.php | 2 +- src/GameQ/Result.php | 2 +- src/GameQ/Server.php | 14 +++++----- 30 files changed, 77 insertions(+), 113 deletions(-) diff --git a/src/GameQ/Buffer.php b/src/GameQ/Buffer.php index a080e427..e78e8cec 100644 --- a/src/GameQ/Buffer.php +++ b/src/GameQ/Buffer.php @@ -48,7 +48,7 @@ class Buffer * * @type string */ - private $number_type = self::NUMBER_TYPE_LITTLEENDIAN; + private $number_type; /** * The original data @@ -130,7 +130,7 @@ public function read($length = 1) { if (($length + $this->index) > $this->length) { - throw new Exception("Unable to read length={$length} from buffer. Bad protocol format or return?"); + throw new Exception("Unable to read length=$length from buffer. Bad protocol format or return?"); } $string = substr($this->data, $this->index, $length); @@ -332,18 +332,11 @@ public function readInt16() { // Change the integer type we are looking up - switch ($this->number_type) { - case self::NUMBER_TYPE_BIGENDIAN: - $type = 'nint'; - break; - - case self::NUMBER_TYPE_LITTLEENDIAN: - $type = 'vint'; - break; - - default: - $type = 'Sint'; - } + $type = match ($this->number_type) { + self::NUMBER_TYPE_BIGENDIAN => 'nint', + self::NUMBER_TYPE_LITTLEENDIAN => 'vint', + default => 'Sint', + }; $int = unpack($type, $this->read(2)); @@ -442,20 +435,13 @@ public function readInt64() { // We have the pack 64-bit codes available. See: http://php.net/manual/en/function.pack.php - if (version_compare(PHP_VERSION, '5.6.3') >= 0 && PHP_INT_SIZE == 8) { + if (version_compare(PHP_VERSION, '5.6.3') >= 0 && PHP_INT_SIZE === 8) { // Change the integer type we are looking up - switch ($this->number_type) { - case self::NUMBER_TYPE_BIGENDIAN: - $type = 'Jint'; - break; - - case self::NUMBER_TYPE_LITTLEENDIAN: - $type = 'Pint'; - break; - - default: - $type = 'Qint'; - } + $type = match ($this->number_type) { + self::NUMBER_TYPE_BIGENDIAN => 'Jint', + self::NUMBER_TYPE_LITTLEENDIAN => 'Pint', + default => 'Qint', + }; $int64 = unpack($type, $this->read(8)); @@ -463,7 +449,7 @@ public function readInt64() unset($int64); } else { - if ($this->number_type == self::NUMBER_TYPE_BIGENDIAN) { + if ($this->number_type === self::NUMBER_TYPE_BIGENDIAN) { $high = $this->readInt32(); $low = $this->readInt32(); } else { diff --git a/src/GameQ/Filters/Stripcolors.php b/src/GameQ/Filters/Stripcolors.php index 0679b92e..d71ea554 100644 --- a/src/GameQ/Filters/Stripcolors.php +++ b/src/GameQ/Filters/Stripcolors.php @@ -53,6 +53,7 @@ public function apply(array $result, Server $server) switch ($server->protocol()->getProtocol()) { case 'quake2': case 'quake3': + case 'gta5m': case 'doom3': array_walk_recursive($result, [$this, 'stripQuake']); break; @@ -65,9 +66,6 @@ public function apply(array $result, Server $server) case 'source': array_walk_recursive($result, [$this, 'stripSource']); break; - case 'gta5m': - array_walk_recursive($result, [$this, 'stripQuake']); - break; } /*$data['filtered'][ $server->id() ] = $result; diff --git a/src/GameQ/GameQ.php b/src/GameQ/GameQ.php index 19b2a124..c8b5c298 100644 --- a/src/GameQ/GameQ.php +++ b/src/GameQ/GameQ.php @@ -141,7 +141,7 @@ public function __construct() public function __get($option) { - return isset($this->options[$option]) ? $this->options[$option] : null; + return $this->options[$option] ?? null; } /** @@ -623,7 +623,7 @@ protected function doParseResponse(Server $server) $results['gq_transport'] = $server->protocol()->transport(); // Process the join link - if (!isset($results['gq_joinlink']) || empty($results['gq_joinlink'])) { + if (empty($results['gq_joinlink'])) { $results['gq_joinlink'] = $server->getJoinLink(); } @@ -653,7 +653,7 @@ protected function doApplyFilters(array $results, Server $server) // Apply the filter to the data $results = $filter->apply($results, $server); - } catch (\ReflectionException $exception) { + } catch (\ReflectionException) { // Invalid, skip it continue; } diff --git a/src/GameQ/Protocols/Ase.php b/src/GameQ/Protocols/Ase.php index abc47818..6acd7641 100644 --- a/src/GameQ/Protocols/Ase.php +++ b/src/GameQ/Protocols/Ase.php @@ -157,7 +157,7 @@ public function processResponse() * @param \GameQ\Buffer $buffer * @param \GameQ\Result $result */ - protected function processKeyValuePairs(Buffer &$buffer, Result &$result) + protected function processKeyValuePairs(Buffer $buffer, Result $result) { // Key / value pairs @@ -185,7 +185,7 @@ protected function processKeyValuePairs(Buffer &$buffer, Result &$result) * @param \GameQ\Buffer $buffer * @param \GameQ\Result $result */ - protected function processPlayersAndTeams(Buffer &$buffer, Result &$result) + protected function processPlayersAndTeams(Buffer $buffer, Result $result) { // Players and team info diff --git a/src/GameQ/Protocols/Cfx.php b/src/GameQ/Protocols/Cfx.php index 06fe7a02..914b4e32 100644 --- a/src/GameQ/Protocols/Cfx.php +++ b/src/GameQ/Protocols/Cfx.php @@ -23,7 +23,6 @@ use GameQ\Protocol; use GameQ\Result; use GameQ\Server; -use GameQ\Protocols\Http; /** * GTA Five M Protocol Class @@ -115,7 +114,7 @@ public function beforeSend(Server $server) 'host' => "$server->ip:$server->port_query", ]); $results = $GameQ->process(); - $this->PlayerList = isset($results[0]) && isset($results[0][0]) ? $results[0][0] : []; + $this->PlayerList = $results[0][0] ?? []; } /** @@ -134,7 +133,7 @@ public function processResponse() // Figure out which packet response this is if (empty($response_type) || !array_key_exists($response_type, $this->responses)) { - throw new Exception(__METHOD__ . " response type '{$response_type}' is not valid"); + throw new Exception(__METHOD__ . " response type '$response_type' is not valid"); } // Offload the call @@ -174,7 +173,7 @@ protected function processStatus(Buffer $buffer) $key = $data[$x]; $val = $data[$x + 1]; - if (in_array($key, ['challenge'])) { + if ($key === 'challenge') { continue; // skip } diff --git a/src/GameQ/Protocols/Cfxplayers.php b/src/GameQ/Protocols/Cfxplayers.php index 02897c38..353b6850 100644 --- a/src/GameQ/Protocols/Cfxplayers.php +++ b/src/GameQ/Protocols/Cfxplayers.php @@ -20,7 +20,6 @@ namespace GameQ\Protocols; use GameQ\Exception\Protocol as Exception; -use GameQ\Protocols\Http; /** * GTA Five M Protocol Class @@ -35,7 +34,7 @@ * @author Jesse Lukas */ -class CFXPlayers extends Http +class Cfxplayers extends Http { /** * Holds the real ip so we can overwrite it back diff --git a/src/GameQ/Protocols/Doom3.php b/src/GameQ/Protocols/Doom3.php index f277213f..861e6b05 100644 --- a/src/GameQ/Protocols/Doom3.php +++ b/src/GameQ/Protocols/Doom3.php @@ -138,13 +138,10 @@ protected function processStatus(Buffer $buffer) // We need to split the data and offload $results = $this->processServerInfo($buffer); - $results = array_merge_recursive( + return array_merge_recursive( $results, $this->processPlayers($buffer) ); - - // Return results - return $results; } /** diff --git a/src/GameQ/Protocols/Dow.php b/src/GameQ/Protocols/Dow.php index b66512a7..548f49fa 100644 --- a/src/GameQ/Protocols/Dow.php +++ b/src/GameQ/Protocols/Dow.php @@ -18,8 +18,6 @@ namespace GameQ\Protocols; -use GameQ\Buffer; - /** * Class Dow * diff --git a/src/GameQ/Protocols/Etqw.php b/src/GameQ/Protocols/Etqw.php index bbb78ae0..88cfe38a 100644 --- a/src/GameQ/Protocols/Etqw.php +++ b/src/GameQ/Protocols/Etqw.php @@ -113,7 +113,7 @@ public function processResponse() // Figure out which packet response this is if (!array_key_exists($response_type, $this->responses)) { - throw new Exception(__METHOD__ . " response type '{$response_type}' is not valid"); + throw new Exception(__METHOD__ . " response type '$response_type' is not valid"); } // Offload the call @@ -183,7 +183,7 @@ protected function processStatus(Buffer $buffer) * @param Buffer $buffer * @param Result $result */ - protected function parsePlayers(Buffer &$buffer, Result &$result) + protected function parsePlayers(Buffer $buffer, Result $result) { // By default there are 0 players $players = 0; @@ -212,7 +212,7 @@ protected function parsePlayers(Buffer &$buffer, Result &$result) * @param Buffer $buffer * @param Result $result */ - protected function parsePlayersExtra(Buffer &$buffer, Result &$result) + protected function parsePlayersExtra(Buffer $buffer, Result $result) { // Iterate over the extra player info while (($id = $buffer->readInt8()) != 32) { diff --git a/src/GameQ/Protocols/Ffow.php b/src/GameQ/Protocols/Ffow.php index e419b726..530b66f4 100644 --- a/src/GameQ/Protocols/Ffow.php +++ b/src/GameQ/Protocols/Ffow.php @@ -207,7 +207,7 @@ protected function processRules(Buffer $buffer) while ($buffer->getLength()) { $key = $buffer->readString(); // Check for map - if (strstr($key, "Map:")) { + if (str_contains($key, "Map:")) { $result->addSub("maplist", "name", $buffer->readString()); } else // Regular rule { diff --git a/src/GameQ/Protocols/Gamespy.php b/src/GameQ/Protocols/Gamespy.php index 0c7707f3..2c318f75 100644 --- a/src/GameQ/Protocols/Gamespy.php +++ b/src/GameQ/Protocols/Gamespy.php @@ -21,7 +21,7 @@ use GameQ\Protocol; use GameQ\Buffer; use GameQ\Result; -use \GameQ\Exception\Protocol as Exception; +use GameQ\Exception\Protocol as Exception; /** * GameSpy Protocol class diff --git a/src/GameQ/Protocols/Gamespy2.php b/src/GameQ/Protocols/Gamespy2.php index f8cdea29..a20f4a47 100644 --- a/src/GameQ/Protocols/Gamespy2.php +++ b/src/GameQ/Protocols/Gamespy2.php @@ -223,7 +223,7 @@ protected function processPlayers(Buffer $buffer) * * @throws Exception */ - protected function parsePlayerTeam($dataType, Buffer &$buffer, Result &$result) + protected function parsePlayerTeam($dataType, Buffer $buffer, Result $result) { // Do count @@ -243,7 +243,7 @@ protected function parsePlayerTeam($dataType, Buffer &$buffer, Result &$result) } // Check if there are any value entries - if ($buffer->lookAhead() == "\x00") { + if ($buffer->lookAhead() === "\x00") { $buffer->skip(); return; @@ -259,7 +259,5 @@ protected function parsePlayerTeam($dataType, Buffer &$buffer, Result &$result) break; } } - - return; } } diff --git a/src/GameQ/Protocols/Gamespy3.php b/src/GameQ/Protocols/Gamespy3.php index a043531b..1a82952d 100644 --- a/src/GameQ/Protocols/Gamespy3.php +++ b/src/GameQ/Protocols/Gamespy3.php @@ -212,7 +212,7 @@ protected function cleanPackets(array $packets = []) $sndvar = substr($snd, 0, strpos($snd, "\x00")); // Check if fstvar is a substring of sndvar // If so, remove it from the first string - if (!empty($fstvar) && strpos($sndvar, $fstvar) !== false) { + if (!empty($fstvar) && str_contains($sndvar, $fstvar)) { $packets[$i] = preg_replace("#(\\x00[^\\x00]+\\x00)$#", "\x00", $packets[$i]); } } @@ -224,7 +224,8 @@ protected function cleanPackets(array $packets = []) $prefix = $buffer->readString(); // Check to see if the return before has the same prefix present - if ($prefix != null && strstr($packets[($x - 1)], $prefix)) { + if ($prefix !== null && str_contains($packets[($x - 1)], $prefix) + ) { // Update the return by removing the prefix plus 2 chars $packets[$x] = substr(str_replace($prefix, '', $packets[$x]), 2); } @@ -306,12 +307,12 @@ protected function processPlayersAndTeams(Buffer &$buffer, Result &$result) * For now we just strip out these characters */ // Check to see if $item has a _ at the end, this is player info - if (substr($item, -1) == '_') { + if (str_ends_with($item, '_')) { // Set the item group $item_group = 'players'; // Set the item type, rip off any trailing stuff and bad chars $item_type = rtrim(str_replace("\x01", '', $item), '_'); - } elseif (substr($item, -2) == '_t') { + } elseif (str_ends_with($item, '_t')) { // Check to see if $item has a _t at the end, this is team info // Set the item group $item_group = 'teams'; diff --git a/src/GameQ/Protocols/Lhmp.php b/src/GameQ/Protocols/Lhmp.php index 1c664196..86219125 100644 --- a/src/GameQ/Protocols/Lhmp.php +++ b/src/GameQ/Protocols/Lhmp.php @@ -134,7 +134,7 @@ public function processResponse() foreach ($packets as $header => $packetGroup) { // Figure out which packet response this is if (!array_key_exists($header, $this->responses)) { - throw new Exception(__METHOD__ . " response type '{$header}' is not valid"); + throw new Exception(__METHOD__ . " response type '$header' is not valid"); } // Now we need to call the proper method diff --git a/src/GameQ/Protocols/M2mp.php b/src/GameQ/Protocols/M2mp.php index 2efbf586..2028912c 100644 --- a/src/GameQ/Protocols/M2mp.php +++ b/src/GameQ/Protocols/M2mp.php @@ -147,13 +147,10 @@ protected function processStatus(Buffer $buffer) // We need to split the data and offload $results = $this->processServerInfo($buffer); - $results = array_merge_recursive( + return array_merge_recursive( $results, $this->processPlayers($buffer) ); - - // Return results - return $results; } /** diff --git a/src/GameQ/Protocols/Mumble.php b/src/GameQ/Protocols/Mumble.php index 299389cf..95426396 100644 --- a/src/GameQ/Protocols/Mumble.php +++ b/src/GameQ/Protocols/Mumble.php @@ -135,7 +135,7 @@ public function processResponse() // Let's iterate over the response items, there are a lot foreach ($data as $key => $value) { // Ignore root for now, that is where all of the channel/player info is housed - if (in_array($key, ['root'])) { + if ($key === 'root') { continue; } diff --git a/src/GameQ/Protocols/Quake2.php b/src/GameQ/Protocols/Quake2.php index 31f1a3bf..a40ceeb7 100644 --- a/src/GameQ/Protocols/Quake2.php +++ b/src/GameQ/Protocols/Quake2.php @@ -123,13 +123,10 @@ protected function processStatus(Buffer $buffer) // We need to split the data and offload $results = $this->processServerInfo(new Buffer($buffer->readString("\x0A"))); - $results = array_merge_recursive( + return array_merge_recursive( $results, $this->processPlayers(new Buffer($buffer->getBuffer())) ); - - // Return results - return $results; } /** diff --git a/src/GameQ/Protocols/Quake3.php b/src/GameQ/Protocols/Quake3.php index cffd844a..a4436acc 100644 --- a/src/GameQ/Protocols/Quake3.php +++ b/src/GameQ/Protocols/Quake3.php @@ -115,14 +115,10 @@ protected function processStatus(Buffer $buffer) { // We need to split the data and offload $results = $this->processServerInfo(new Buffer($buffer->readString("\x0A"))); - - $results = array_merge_recursive( + return array_merge_recursive( $results, $this->processPlayers(new Buffer($buffer->getBuffer())) ); - - // Return results - return $results; } /** diff --git a/src/GameQ/Protocols/Samp.php b/src/GameQ/Protocols/Samp.php index caba7a81..076698db 100644 --- a/src/GameQ/Protocols/Samp.php +++ b/src/GameQ/Protocols/Samp.php @@ -158,7 +158,7 @@ public function processResponse() // Check the header, should be SAMP if (($header = $buffer->read(4)) !== 'SAMP') { - throw new Exception(__METHOD__ . " header response '{$header}' is not valid"); + throw new Exception(__METHOD__ . " header response '$header' is not valid"); } // Check to make sure the server response code matches what we sent @@ -171,7 +171,7 @@ public function processResponse() // Figure out which packet response this is if (!array_key_exists($response_type, $this->responses)) { - throw new Exception(__METHOD__ . " response type '{$response_type}' is not valid"); + throw new Exception(__METHOD__ . " response type '$response_type' is not valid"); } // Now we need to call the proper method diff --git a/src/GameQ/Protocols/Source.php b/src/GameQ/Protocols/Source.php index 4c6e81b5..c80d271d 100644 --- a/src/GameQ/Protocols/Source.php +++ b/src/GameQ/Protocols/Source.php @@ -166,14 +166,13 @@ public function processResponse() $header = $buffer->readInt32Signed(); // Single packet - if ($header == -1) { + if ($header === -1) { // We need to peek and see what kind of engine this is for later processing - if ($buffer->lookAhead(1) == "\x6d") { + if ($buffer->lookAhead(1) === "\x6d") { $this->source_engine = self::GOLDSOURCE_ENGINE; } $packets[] = $buffer->getBuffer(); - continue; } else { // Split packet @@ -202,7 +201,7 @@ public function processResponse() // Figure out which packet response this is if (!array_key_exists($response_type, $this->responses)) { - throw new Exception(__METHOD__ . " response type '{$response_type}' is not valid"); + throw new Exception(__METHOD__ . " response type '$response_type' is not valid"); } // Now we need to call the proper method @@ -286,17 +285,17 @@ protected function processPackets($packet_id, array $packets = []) $result = bzdecompress($buffer->getBuffer()); // Now verify the length - if (strlen($result) != $packet_length) { + if (strlen($result) !== $packet_length) { // @codeCoverageIgnoreStart throw new Exception( - "Checksum for compressed packet failed! Length expected: {$packet_length}, length + "Checksum for compressed packet failed! Length expected: $packet_length, length returned: " . strlen($result) ); // @codeCoverageIgnoreEnd } // We need to burn the extra header (\xFF\xFF\xFF\xFF) on first loop - if ($i == 0) { + if ($i === 0) { $result = substr($result, 4); } } else { @@ -304,7 +303,7 @@ protected function processPackets($packet_id, array $packets = []) $buffer->readInt16Signed(); // We need to burn the extra header (\xFF\xFF\xFF\xFF) on first loop - if ($i == 0) { + if ($i === 0) { $buffer->read(4); } diff --git a/src/GameQ/Protocols/Starmade.php b/src/GameQ/Protocols/Starmade.php index ee591fea..0f880b8c 100644 --- a/src/GameQ/Protocols/Starmade.php +++ b/src/GameQ/Protocols/Starmade.php @@ -156,7 +156,7 @@ public function processResponse() * @return array * @throws \GameQ\Exception\Protocol */ - protected function parseServerParameters(Buffer &$buffer) + protected function parseServerParameters(Buffer $buffer) { // Init the parsed data array diff --git a/src/GameQ/Protocols/Teamspeak2.php b/src/GameQ/Protocols/Teamspeak2.php index 69954dd2..f6df0e0a 100644 --- a/src/GameQ/Protocols/Teamspeak2.php +++ b/src/GameQ/Protocols/Teamspeak2.php @@ -149,7 +149,7 @@ public function processResponse() // Check the header [TS] if (($header = trim($buffer->readString("\n"))) !== '[TS]') { - throw new Exception(__METHOD__ . " Expected header '{$header}' does not match expected '[TS]'."); + throw new Exception(__METHOD__ . " Expected header '$header' does not match expected '[TS]'."); } // Split this buffer as the data blocks are bound by "OK" and drop any empty values @@ -200,7 +200,7 @@ public function processResponse() * @param string $data * @param \GameQ\Result $result */ - protected function processDetails($data, Result &$result) + protected function processDetails($data, Result $result) { // Create a buffer @@ -230,7 +230,7 @@ protected function processDetails($data, Result &$result) * @param string $data * @param \GameQ\Result $result */ - protected function processChannels($data, Result &$result) + protected function processChannels($data, Result $result) { // Create a buffer @@ -262,7 +262,7 @@ protected function processChannels($data, Result &$result) * @param string $data * @param \GameQ\Result $result */ - protected function processPlayers($data, Result &$result) + protected function processPlayers($data, Result $result) { // Create a buffer diff --git a/src/GameQ/Protocols/Teamspeak3.php b/src/GameQ/Protocols/Teamspeak3.php index 96f9c99d..c03fe2ca 100644 --- a/src/GameQ/Protocols/Teamspeak3.php +++ b/src/GameQ/Protocols/Teamspeak3.php @@ -149,7 +149,7 @@ public function processResponse() // Check the header TS3 if (($header = trim($buffer->readString("\n"))) !== 'TS3') { - throw new Exception(__METHOD__ . " Expected header '{$header}' does not match expected 'TS3'."); + throw new Exception(__METHOD__ . " Expected header '$header' does not match expected 'TS3'."); } // Convert all the escaped characters @@ -171,7 +171,7 @@ public function processResponse() $value = trim($value); // Not empty string or a message response for "error id=\d" - return !empty($value) && substr($value, 0, 5) !== 'error'; + return !empty($value) && !str_starts_with($value, 'error'); }); // Trim up the values to remove extra whitespace @@ -251,7 +251,7 @@ protected function processProperties($data) * @param string $data * @param \GameQ\Result $result */ - protected function processDetails($data, Result &$result) + protected function processDetails($data, Result $result) { // Offload the parsing for these values @@ -280,7 +280,7 @@ protected function processDetails($data, Result &$result) * @param string $data * @param \GameQ\Result $result */ - protected function processChannels($data, Result &$result) + protected function processChannels($data, Result $result) { // We need to split the data at the pipe @@ -306,7 +306,7 @@ protected function processChannels($data, Result &$result) * @param string $data * @param \GameQ\Result $result */ - protected function processPlayers($data, Result &$result) + protected function processPlayers($data, Result $result) { // We need to split the data at the pipe diff --git a/src/GameQ/Protocols/Tibia.php b/src/GameQ/Protocols/Tibia.php index 8702bfa3..9f9a0461 100644 --- a/src/GameQ/Protocols/Tibia.php +++ b/src/GameQ/Protocols/Tibia.php @@ -19,7 +19,6 @@ namespace GameQ\Protocols; use GameQ\Protocol; -use GameQ\Buffer; use GameQ\Result; use GameQ\Exception\Protocol as Exception; @@ -124,7 +123,7 @@ public function processResponse() // Iterate over the info foreach (['serverinfo', 'owner', 'map', 'npcs', 'monsters', 'players'] as $property) { foreach ($xmlDoc->{$property}->attributes() as $key => $value) { - if (!in_array($property, ['serverinfo'])) { + if ($property !== 'serverinfo') { $key = $property . '_' . $key; } @@ -135,7 +134,7 @@ public function processResponse() $result->add("motd", (string)$xmlDoc->motd); - unset($xmlDoc, $xmlDoc); + unset($xmlDoc); return $result->fetch(); } diff --git a/src/GameQ/Protocols/Tshock.php b/src/GameQ/Protocols/Tshock.php index 551a09e4..37a2a7b7 100644 --- a/src/GameQ/Protocols/Tshock.php +++ b/src/GameQ/Protocols/Tshock.php @@ -109,8 +109,8 @@ public function processResponse() } // Check the status response - if ($json->status != 200) { - throw new Exception("JSON status from Tshock protocol response was '{$json->status}', expected '200'."); + if ($json->status !== 200) { + throw new Exception("JSON status from Tshock protocol response was '$json->status', expected '200'."); } $result = new Result(); diff --git a/src/GameQ/Protocols/Ventrilo.php b/src/GameQ/Protocols/Ventrilo.php index 6986bedc..05b332fe 100644 --- a/src/GameQ/Protocols/Ventrilo.php +++ b/src/GameQ/Protocols/Ventrilo.php @@ -838,7 +838,7 @@ protected function decryptPackets(array $packets = []) * @param int $fieldCount * @param \GameQ\Result $result */ - protected function processChannel($data, $fieldCount, Result &$result) + protected function processChannel($data, $fieldCount, Result $result) { // Split the items on the comma @@ -860,7 +860,7 @@ protected function processChannel($data, $fieldCount, Result &$result) * @param int $fieldCount * @param \GameQ\Result $result */ - protected function processPlayer($data, $fieldCount, Result &$result) + protected function processPlayer($data, $fieldCount, Result $result) { // Split the items on the comma diff --git a/src/GameQ/Query/Core.php b/src/GameQ/Query/Core.php index 016dad27..cee4cfac 100644 --- a/src/GameQ/Query/Core.php +++ b/src/GameQ/Query/Core.php @@ -161,7 +161,7 @@ abstract public function get(); /** * Write data to the socket * - * @param string $data + * @param string|array $data * * @return int The number of bytes written */ diff --git a/src/GameQ/Query/Native.php b/src/GameQ/Query/Native.php index 455f087f..c23ae75e 100644 --- a/src/GameQ/Query/Native.php +++ b/src/GameQ/Query/Native.php @@ -124,7 +124,7 @@ protected function create() // Something bad happened, throw query exception throw new Exception( - __METHOD__ . " - Error creating socket to server {$this->ip}:{$this->port}. Error: " . $errstr, + __METHOD__ . " - Error creating socket to server $this->ip:$this->port. Error: " . $errstr, $errno ); } diff --git a/src/GameQ/Result.php b/src/GameQ/Result.php index 74f17f66..ddf0b3fa 100644 --- a/src/GameQ/Result.php +++ b/src/GameQ/Result.php @@ -125,6 +125,6 @@ public function fetch() public function get($var) { - return isset($this->result[$var]) ? $this->result[$var] : null; + return $this->result[$var] ?? null; } } diff --git a/src/GameQ/Server.php b/src/GameQ/Server.php index 1725d461..8de8aa2d 100644 --- a/src/GameQ/Server.php +++ b/src/GameQ/Server.php @@ -141,7 +141,7 @@ public function __construct(array $server_info = []) ); $this->protocol = $class->newInstanceArgs([$this->options]); - } catch (\ReflectionException $e) { + } catch (\ReflectionException) { throw new Exception("Unable to locate Protocols class for '{$server_info[self::SERVER_TYPE]}'!"); } @@ -164,7 +164,7 @@ protected function checkAndSetIpPort($ip_address) // Test for IPv6 if (substr_count($ip_address, ':') > 1) { // See if we have a port, input should be in the format [::1]:27015 or similar - if (strstr($ip_address, ']:')) { + if (str_contains($ip_address, ']:')) { // Explode to get port $server_addr = explode(':', $ip_address); @@ -178,18 +178,18 @@ protected function checkAndSetIpPort($ip_address) } else { // Just the IPv6 address, no port defined, fail throw new Exception( - "The host address '{$ip_address}' is missing the port. All " + "The host address '$ip_address' is missing the port. All " . "servers must have a port defined!" ); } // Now let's validate the IPv6 value sent, remove the square brackets ([]) first if (!filter_var(trim($this->ip, '[]'), FILTER_VALIDATE_IP, ['flags' => FILTER_FLAG_IPV6,])) { - throw new Exception("The IPv6 address '{$this->ip}' is invalid."); + throw new Exception("The IPv6 address '$this->ip' is invalid."); } } else { // We have IPv4 with a port defined - if (strstr($ip_address, ':')) { + if (str_contains($ip_address, ':')) { list($this->ip, $this->port_client) = explode(':', $ip_address); // Type case the port @@ -197,7 +197,7 @@ protected function checkAndSetIpPort($ip_address) } else { // No port, fail throw new Exception( - "The host address '{$ip_address}' is missing the port. All " + "The host address '$ip_address' is missing the port. All " . "servers must have a port defined!" ); } @@ -210,7 +210,7 @@ protected function checkAndSetIpPort($ip_address) // When gethostbyname() fails it returns the original string if ($this->ip === $resolved) { // so if ip and the result from gethostbyname() are equal this failed. - throw new Exception("Unable to resolve the host '{$this->ip}' to an IP address."); + throw new Exception("Unable to resolve the host '$this->ip' to an IP address."); } else { $this->ip = $resolved; } From 4d524055b05f4e3c2f37b18368ef374826791673 Mon Sep 17 00:00:00 2001 From: "Niklas (Krymonota)" Date: Thu, 26 Sep 2024 19:27:32 +0200 Subject: [PATCH 07/14] Fix implicit type conversion --- src/GameQ/Protocols/Samp.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/GameQ/Protocols/Samp.php b/src/GameQ/Protocols/Samp.php index 076698db..688a7a93 100644 --- a/src/GameQ/Protocols/Samp.php +++ b/src/GameQ/Protocols/Samp.php @@ -124,9 +124,9 @@ class Samp extends Protocol */ public function beforeSend(Server $server) { - // Build the server code - $this->server_code = implode('', array_map('chr', explode('.', $server->ip()))) . + $ipNumbers = array_map('intval', explode('.', $server->ip())); + $this->server_code = implode('', array_map('chr', $ipNumbers)) . pack("S", $server->portClient()); // Loop over the packets and update them From c73a8b7ea3bb973653fb7042138f88db92fe4769 Mon Sep 17 00:00:00 2001 From: "Niklas (Krymonota)" Date: Thu, 26 Sep 2024 19:41:47 +0200 Subject: [PATCH 08/14] Replace usage of deprecated `utf8_encode` function --- src/GameQ/GameQ.php | 14 ------------ src/GameQ/Protocol.php | 34 ++++++++++++++++++++++++++++ src/GameQ/Protocols/Codmw2.php | 2 +- src/GameQ/Protocols/Cs2d.php | 6 ++--- src/GameQ/Protocols/Doom3.php | 4 ++-- src/GameQ/Protocols/Gamespy.php | 2 +- src/GameQ/Protocols/Gamespy2.php | 4 ++-- src/GameQ/Protocols/Gamespy3.php | 4 ++-- src/GameQ/Protocols/Killingfloor.php | 4 ++-- src/GameQ/Protocols/Lhmp.php | 8 +++---- src/GameQ/Protocols/M2mp.php | 2 +- src/GameQ/Protocols/Quake2.php | 4 ++-- src/GameQ/Protocols/Quake3.php | 4 ++-- src/GameQ/Protocols/Quake4.php | 2 +- src/GameQ/Protocols/Samp.php | 4 ++-- src/GameQ/Protocols/Teamspeak2.php | 6 ++--- src/GameQ/Protocols/Teamspeak3.php | 2 +- src/GameQ/Protocols/Unreal2.php | 8 +++---- src/GameQ/Protocols/Ventrilo.php | 6 ++--- src/GameQ/Protocols/Warsow.php | 2 +- 20 files changed, 71 insertions(+), 51 deletions(-) diff --git a/src/GameQ/GameQ.php b/src/GameQ/GameQ.php index c8b5c298..98a57af4 100644 --- a/src/GameQ/GameQ.php +++ b/src/GameQ/GameQ.php @@ -117,20 +117,6 @@ public static function factory() */ protected $query = null; - /** - * GameQ constructor. - * - * Do some checks as needed so this will operate - */ - public function __construct() - { - // Check for missing utf8_encode function - if (!function_exists('utf8_encode')) { - throw new \Exception("PHP's utf8_encode() function is required - " - . "http://php.net/manual/en/function.utf8-encode.php. Check your php installation."); - } - } - /** * Get an option's value * diff --git a/src/GameQ/Protocol.php b/src/GameQ/Protocol.php index 5c8deff0..d3fd02dc 100644 --- a/src/GameQ/Protocol.php +++ b/src/GameQ/Protocol.php @@ -461,6 +461,40 @@ protected function challengeApply($challenge_string) return true; } + /** + * Converts a string from ISO-8859-1 to UTF-8. + * This is a replacement for PHP's utf8_encode function that was deprecated with PHP 8.2. + * + * Source: symfony/polyfill-php72 + * See https://github.com/symfony/polyfill-php72/blob/bf44a9fd41feaac72b074de600314a93e2ae78e2/Php72.php#L24-L38 + * + * @author Nicolas Grekas + * @author Dariusz Rumiński > 1, $j = 0; $i < $len; ++$i, ++$j) { + switch (true) { + case $s[$i] < "\x80": + $s[$j] = $s[$i]; + break; + case $s[$i] < "\xC0": + $s[$j] = "\xC2"; + $s[++$j] = $s[$i]; + break; + default: + $s[$j] = "\xC3"; + $s[++$j] = \chr(\ord($s[$i]) - 64); + break; + } + } + + return substr($s, 0, $j); + } + /** * Get the normalize settings for the protocol * diff --git a/src/GameQ/Protocols/Codmw2.php b/src/GameQ/Protocols/Codmw2.php index c68b5666..066e1f3a 100644 --- a/src/GameQ/Protocols/Codmw2.php +++ b/src/GameQ/Protocols/Codmw2.php @@ -63,7 +63,7 @@ protected function processPlayers(Buffer $buffer) $playerInfo->skip(1); // Add player name, encoded - $player['name'] = utf8_encode(trim(($playerInfo->readString('"')))); + $player['name'] = $this->convertToUtf8(trim(($playerInfo->readString('"')))); // Add player $players[] = $player; diff --git a/src/GameQ/Protocols/Cs2d.php b/src/GameQ/Protocols/Cs2d.php index d4cb2b12..ed923257 100644 --- a/src/GameQ/Protocols/Cs2d.php +++ b/src/GameQ/Protocols/Cs2d.php @@ -200,8 +200,8 @@ protected function processDetails(Buffer $buffer) $result->add('lua_scripts', (int)$this->readFlag($serverFlags, 6)); // Read the rest of the buffer data - $result->add('servername', utf8_encode($buffer->readPascalString(0))); - $result->add('mapname', utf8_encode($buffer->readPascalString(0))); + $result->add('servername', $this->convertToUtf8($buffer->readPascalString(0))); + $result->add('mapname', $this->convertToUtf8($buffer->readPascalString(0))); $result->add('num_players', $buffer->readInt8()); $result->add('max_players', $buffer->readInt8()); $result->add('game_mode', $buffer->readInt8()); @@ -234,7 +234,7 @@ protected function processPlayers(Buffer $buffer) if (($id = $buffer->readInt8()) !== 0) { // Add the results $result->addPlayer('id', $id); - $result->addPlayer('name', utf8_encode($buffer->readPascalString(0))); + $result->addPlayer('name', $this->convertToUtf8($buffer->readPascalString(0))); $result->addPlayer('team', $buffer->readInt8()); $result->addPlayer('score', $buffer->readInt32()); $result->addPlayer('deaths', $buffer->readInt32()); diff --git a/src/GameQ/Protocols/Doom3.php b/src/GameQ/Protocols/Doom3.php index 861e6b05..15afee8e 100644 --- a/src/GameQ/Protocols/Doom3.php +++ b/src/GameQ/Protocols/Doom3.php @@ -161,7 +161,7 @@ protected function processServerInfo(Buffer $buffer) // Key / value pairs, delimited by an empty pair while ($buffer->getLength()) { $key = trim($buffer->readString()); - $val = utf8_encode(trim($buffer->readString())); + $val = $this->convertToUtf8(trim($buffer->readString())); // Something is empty so we are done if (empty($key) && empty($val)) { @@ -197,7 +197,7 @@ protected function processPlayers(Buffer $buffer) $result->addPlayer('ping', $buffer->readInt16()); $result->addPlayer('rate', $buffer->readInt32()); // Add player name, encoded - $result->addPlayer('name', utf8_encode(trim($buffer->readString()))); + $result->addPlayer('name', $this->convertToUtf8(trim($buffer->readString()))); // Increment $playerCount++; diff --git a/src/GameQ/Protocols/Gamespy.php b/src/GameQ/Protocols/Gamespy.php index 2c318f75..3aa828dc 100644 --- a/src/GameQ/Protocols/Gamespy.php +++ b/src/GameQ/Protocols/Gamespy.php @@ -156,7 +156,7 @@ protected function processStatus(Buffer $buffer) if (substr($key, 0, $suffix) == 'playername') { $numPlayers++; } - $result->addPlayer(substr($key, 0, $suffix), utf8_encode($val)); + $result->addPlayer(substr($key, 0, $suffix), $this->convertToUtf8($val)); } } else { // Regular variable so just add the value. diff --git a/src/GameQ/Protocols/Gamespy2.php b/src/GameQ/Protocols/Gamespy2.php index a20f4a47..77db324b 100644 --- a/src/GameQ/Protocols/Gamespy2.php +++ b/src/GameQ/Protocols/Gamespy2.php @@ -182,7 +182,7 @@ protected function processDetails(Buffer $buffer) if (strlen($key) == 0) { break; } - $result->add($key, utf8_encode($buffer->readString())); + $result->add($key, $this->convertToUtf8($buffer->readString())); } return $result->fetch(); @@ -252,7 +252,7 @@ protected function parsePlayerTeam($dataType, Buffer $buffer, Result $result) // Get the values while ($buffer->getLength() > 4) { foreach ($varNames as $varName) { - $result->addSub($dataType, utf8_encode($varName), utf8_encode($buffer->readString())); + $result->addSub($dataType, $this->convertToUtf8($varName), $this->convertToUtf8($buffer->readString())); } if ($buffer->lookAhead() === "\x00") { $buffer->skip(); diff --git a/src/GameQ/Protocols/Gamespy3.php b/src/GameQ/Protocols/Gamespy3.php index 1a82952d..997a3c33 100644 --- a/src/GameQ/Protocols/Gamespy3.php +++ b/src/GameQ/Protocols/Gamespy3.php @@ -254,7 +254,7 @@ protected function processDetails(Buffer &$buffer, Result &$result) if (strlen($key) == 0) { break; } - $result->add($key, utf8_encode($buffer->readString())); + $result->add($key, $this->convertToUtf8($buffer->readString())); } } @@ -330,7 +330,7 @@ protected function processPlayersAndTeams(Buffer &$buffer, Result &$result) break; } // Add the value to the proper item in the correct group - $result->addSub($item_group, $item_type, utf8_encode(trim($val))); + $result->addSub($item_group, $item_type, $this->convertToUtf8(trim($val))); } // Unset our buffer unset($buf_temp); diff --git a/src/GameQ/Protocols/Killingfloor.php b/src/GameQ/Protocols/Killingfloor.php index dfa5593e..2a6cf0c8 100644 --- a/src/GameQ/Protocols/Killingfloor.php +++ b/src/GameQ/Protocols/Killingfloor.php @@ -80,10 +80,10 @@ protected function processDetails(Buffer $buffer) $buffer->skip(1); // Read as a regular string since the length is incorrect (what we skipped earlier) - $result->add('servername', utf8_encode($buffer->readString())); + $result->add('servername', $this->convertToUtf8($buffer->readString())); // The rest is read as normal - $result->add('mapname', utf8_encode($buffer->readPascalString(1))); + $result->add('mapname', $this->convertToUtf8($buffer->readPascalString(1))); $result->add('gametype', $buffer->readPascalString(1)); $result->add('numplayers', $buffer->readInt32()); $result->add('maxplayers', $buffer->readInt32()); diff --git a/src/GameQ/Protocols/Lhmp.php b/src/GameQ/Protocols/Lhmp.php index 86219125..61e80155 100644 --- a/src/GameQ/Protocols/Lhmp.php +++ b/src/GameQ/Protocols/Lhmp.php @@ -171,10 +171,10 @@ protected function processDetails(Buffer $buffer) $result->add('password', $buffer->readString()); $result->add('numplayers', $buffer->readInt16()); $result->add('maxplayers', $buffer->readInt16()); - $result->add('servername', utf8_encode($buffer->readPascalString())); + $result->add('servername', $this->convertToUtf8($buffer->readPascalString())); $result->add('gamemode', $buffer->readPascalString()); - $result->add('website', utf8_encode($buffer->readPascalString())); - $result->add('mapname', utf8_encode($buffer->readPascalString())); + $result->add('website', $this->convertToUtf8($buffer->readPascalString())); + $result->add('mapname', $this->convertToUtf8($buffer->readPascalString())); return $result->fetch(); } @@ -201,7 +201,7 @@ protected function processPlayers(Buffer $buffer) if (($id = $buffer->readInt16()) !== 0) { // Add the results $result->addPlayer('id', $id); - $result->addPlayer('name', utf8_encode($buffer->readPascalString())); + $result->addPlayer('name', $this->convertToUtf8($buffer->readPascalString())); } } diff --git a/src/GameQ/Protocols/M2mp.php b/src/GameQ/Protocols/M2mp.php index 2028912c..c3600042 100644 --- a/src/GameQ/Protocols/M2mp.php +++ b/src/GameQ/Protocols/M2mp.php @@ -201,7 +201,7 @@ protected function processPlayers(Buffer $buffer) // Only player name information is available // Add player name, encoded - $result->addPlayer('name', utf8_encode(trim($buffer->readPascalString(1, true)))); + $result->addPlayer('name', $this->convertToUtf8(trim($buffer->readPascalString(1, true)))); } // Clear diff --git a/src/GameQ/Protocols/Quake2.php b/src/GameQ/Protocols/Quake2.php index a40ceeb7..c030de4a 100644 --- a/src/GameQ/Protocols/Quake2.php +++ b/src/GameQ/Protocols/Quake2.php @@ -149,7 +149,7 @@ protected function processServerInfo(Buffer $buffer) // Add result $result->add( trim($buffer->readString('\\')), - utf8_encode(trim($buffer->readStringMulti(['\\', "\x0a"]))) + $this->convertToUtf8(trim($buffer->readStringMulti(['\\', "\x0a"]))) ); } @@ -187,7 +187,7 @@ protected function processPlayers(Buffer $buffer) $playerInfo->skip(1); // Add player name, encoded - $result->addPlayer('name', utf8_encode(trim(($playerInfo->readString('"'))))); + $result->addPlayer('name', $this->convertToUtf8(trim(($playerInfo->readString('"'))))); // Skip first " $playerInfo->skip(2); diff --git a/src/GameQ/Protocols/Quake3.php b/src/GameQ/Protocols/Quake3.php index a4436acc..4d82ff30 100644 --- a/src/GameQ/Protocols/Quake3.php +++ b/src/GameQ/Protocols/Quake3.php @@ -141,7 +141,7 @@ protected function processServerInfo(Buffer $buffer) // Add result $result->add( trim($buffer->readString('\\')), - utf8_encode(trim($buffer->readStringMulti(['\\', "\x0a"]))) + $this->convertToUtf8(trim($buffer->readStringMulti(['\\', "\x0a"]))) ); } @@ -187,7 +187,7 @@ protected function processPlayers(Buffer $buffer) } // Add player name, encoded - $result->addPlayer('name', utf8_encode(trim($buffer->readString('"')))); + $result->addPlayer('name', $this->convertToUtf8(trim($buffer->readString('"')))); // Burn ending delimiter $buffer->read(); diff --git a/src/GameQ/Protocols/Quake4.php b/src/GameQ/Protocols/Quake4.php index 4fcee943..1fc55849 100644 --- a/src/GameQ/Protocols/Quake4.php +++ b/src/GameQ/Protocols/Quake4.php @@ -67,7 +67,7 @@ protected function processPlayers(Buffer $buffer) $result->addPlayer('ping', $buffer->readInt16()); $result->addPlayer('rate', $buffer->readInt32()); // Add player name, encoded - $result->addPlayer('name', utf8_encode(trim($buffer->readString()))); + $result->addPlayer('name', $this->convertToUtf8(trim($buffer->readString()))); $result->addPlayer('clantag', $buffer->readString()); // Increment $playerCount++; diff --git a/src/GameQ/Protocols/Samp.php b/src/GameQ/Protocols/Samp.php index 688a7a93..a6e63347 100644 --- a/src/GameQ/Protocols/Samp.php +++ b/src/GameQ/Protocols/Samp.php @@ -213,7 +213,7 @@ protected function processStatus(Buffer $buffer) $result->add('max_players', $buffer->readInt16()); // These are read differently for these last 3 - $result->add('servername', utf8_encode($buffer->read($buffer->readInt32()))); + $result->add('servername', $this->convertToUtf8($buffer->read($buffer->readInt32()))); $result->add('gametype', $buffer->read($buffer->readInt32())); $result->add('language', $buffer->read($buffer->readInt32())); @@ -239,7 +239,7 @@ protected function processPlayers(Buffer $buffer) // Run until we run out of buffer while ($buffer->getLength()) { $result->addPlayer('id', $buffer->readInt8()); - $result->addPlayer('name', utf8_encode($buffer->readPascalString())); + $result->addPlayer('name', $this->convertToUtf8($buffer->readPascalString())); $result->addPlayer('score', $buffer->readInt32()); $result->addPlayer('ping', $buffer->readInt32()); } diff --git a/src/GameQ/Protocols/Teamspeak2.php b/src/GameQ/Protocols/Teamspeak2.php index f6df0e0a..b8bdbf31 100644 --- a/src/GameQ/Protocols/Teamspeak2.php +++ b/src/GameQ/Protocols/Teamspeak2.php @@ -218,7 +218,7 @@ protected function processDetails($data, Result $result) list($key, $value) = explode('=', $row, 2); // Add this to the result - $result->add($key, utf8_encode($value)); + $result->add($key, $this->convertToUtf8($value)); } unset($data, $buffer, $row, $key, $value); @@ -249,7 +249,7 @@ protected function processChannels($data, Result $result) foreach ($data as $key => $value) { // Now add the data to the result - $result->addTeam($key, utf8_encode($value)); + $result->addTeam($key, $this->convertToUtf8($value)); } } @@ -281,7 +281,7 @@ protected function processPlayers($data, Result $result) foreach ($data as $key => $value) { // Now add the data to the result - $result->addPlayer($key, utf8_encode($value)); + $result->addPlayer($key, $this->convertToUtf8($value)); } } diff --git a/src/GameQ/Protocols/Teamspeak3.php b/src/GameQ/Protocols/Teamspeak3.php index c03fe2ca..fd565b4f 100644 --- a/src/GameQ/Protocols/Teamspeak3.php +++ b/src/GameQ/Protocols/Teamspeak3.php @@ -231,7 +231,7 @@ protected function processProperties($data) list($key, $value) = array_pad(explode('=', $item, 2), 2, ''); // Convert spaces and other character changes - $properties[$key] = utf8_encode(str_replace( + $properties[$key] = $this->convertToUtf8(str_replace( [ '\\s', // Translate spaces ], diff --git a/src/GameQ/Protocols/Unreal2.php b/src/GameQ/Protocols/Unreal2.php index 4bc296ff..a26aca03 100644 --- a/src/GameQ/Protocols/Unreal2.php +++ b/src/GameQ/Protocols/Unreal2.php @@ -167,8 +167,8 @@ protected function processDetails(Buffer $buffer) $result->add('serverip', $buffer->readPascalString(1)); // empty $result->add('gameport', $buffer->readInt32()); $result->add('queryport', $buffer->readInt32()); // 0 - $result->add('servername', utf8_encode($buffer->readPascalString(1))); - $result->add('mapname', utf8_encode($buffer->readPascalString(1))); + $result->add('servername', $this->convertToUtf8($buffer->readPascalString(1))); + $result->add('mapname', $this->convertToUtf8($buffer->readPascalString(1))); $result->add('gametype', $buffer->readPascalString(1)); $result->add('numplayers', $buffer->readInt32()); $result->add('maxplayers', $buffer->readInt32()); @@ -196,7 +196,7 @@ protected function processPlayers(Buffer $buffer) if (($id = $buffer->readInt32()) !== 0) { // Add the results $result->addPlayer('id', $id); - $result->addPlayer('name', utf8_encode($buffer->readPascalString(1))); + $result->addPlayer('name', $this->convertToUtf8($buffer->readPascalString(1))); $result->addPlayer('ping', $buffer->readInt32()); $result->addPlayer('score', $buffer->readInt32()); @@ -234,7 +234,7 @@ protected function processRules(Buffer $buffer) $key .= ++$inc; } - $result->add(strtolower($key), utf8_encode($buffer->readPascalString(1))); + $result->add(strtolower($key), $this->convertToUtf8($buffer->readPascalString(1))); } return $result->fetch(); diff --git a/src/GameQ/Protocols/Ventrilo.php b/src/GameQ/Protocols/Ventrilo.php index 05b332fe..ee3b38ed 100644 --- a/src/GameQ/Protocols/Ventrilo.php +++ b/src/GameQ/Protocols/Ventrilo.php @@ -723,7 +723,7 @@ function ($matches) { // By default we just add they key as an item default: - $result->add($key, utf8_encode($value)); + $result->add($key, $this->convertToUtf8($value)); break; } } @@ -849,7 +849,7 @@ protected function processChannel($data, $fieldCount, Result $result) // Split the key=value pair list($key, $value) = explode("=", $item, 2); - $result->addTeam(strtolower($key), utf8_encode($value)); + $result->addTeam(strtolower($key), $this->convertToUtf8($value)); } } @@ -871,7 +871,7 @@ protected function processPlayer($data, $fieldCount, Result $result) // Split the key=value pair list($key, $value) = explode("=", $item, 2); - $result->addPlayer(strtolower($key), utf8_encode($value)); + $result->addPlayer(strtolower($key), $this->convertToUtf8($value)); } } } diff --git a/src/GameQ/Protocols/Warsow.php b/src/GameQ/Protocols/Warsow.php index ed803fae..7f890ee5 100644 --- a/src/GameQ/Protocols/Warsow.php +++ b/src/GameQ/Protocols/Warsow.php @@ -76,7 +76,7 @@ protected function processPlayers(Buffer $buffer) $playerInfo->skip(1); // Add player name, encoded - $result->addPlayer('name', utf8_encode(trim(($playerInfo->readString('"'))))); + $result->addPlayer('name', $this->convertToUtf8(trim(($playerInfo->readString('"'))))); // Skip space $playerInfo->skip(1); From 2f4737472cc032954a1da2db9107ab2b20d0d106 Mon Sep 17 00:00:00 2001 From: "Niklas (Krymonota)" Date: Thu, 26 Sep 2024 21:18:22 +0200 Subject: [PATCH 09/14] Clean up `.gitignore` file --- .coveralls.yml | 8 -------- .gitattributes | 1 - .gitignore | 3 +-- 3 files changed, 1 insertion(+), 11 deletions(-) delete mode 100644 .coveralls.yml diff --git a/.coveralls.yml b/.coveralls.yml deleted file mode 100644 index dc54b92a..00000000 --- a/.coveralls.yml +++ /dev/null @@ -1,8 +0,0 @@ -# .coveralls.yml example configuration - -# service name -service_name: travis-ci - -# for php-coveralls -coverage_clover: build/logs/clover.xml -json_path: build/logs/coveralls-upload.json diff --git a/.gitattributes b/.gitattributes index a8f1669d..5151e9d3 100644 --- a/.gitattributes +++ b/.gitattributes @@ -4,7 +4,6 @@ /build export-ignore /examples export-ignore /tests export-ignore -/.coveralls.yml export-ignore /.gitattributes export-ignore /.gitignore export-ignore /CONTRIBUTING.md export-ignore diff --git a/.gitignore b/.gitignore index 6d03f590..2a962deb 100644 --- a/.gitignore +++ b/.gitignore @@ -3,11 +3,10 @@ /.settings/* vendor /.idea +.phpunit.result.cache composer.lock composer.phar -coverage/ !build/logs/.gitkeep build/logs/ test.php *.iml -/remotes/ From 1e2e3e7205c6c385e43ccc1ec7fa86017b285026 Mon Sep 17 00:00:00 2001 From: "Niklas (Krymonota)" Date: Thu, 26 Sep 2024 21:23:05 +0200 Subject: [PATCH 10/14] Fix status check in Tshock protocol --- src/GameQ/Protocols/Tshock.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/GameQ/Protocols/Tshock.php b/src/GameQ/Protocols/Tshock.php index 37a2a7b7..0b9f9157 100644 --- a/src/GameQ/Protocols/Tshock.php +++ b/src/GameQ/Protocols/Tshock.php @@ -104,12 +104,17 @@ public function processResponse() preg_match('/\{(.*)\}/ms', implode('', $this->packets_response), $matches); // Return should be JSON, let's validate - if (!isset($matches[0]) || ($json = json_decode($matches[0])) === null) { + if (!isset($matches[0]) || ($json = json_decode( + $matches[0], + false, + 512, + JSON_THROW_ON_ERROR + )) === null) { throw new Exception("JSON response from Tshock protocol is invalid."); } // Check the status response - if ($json->status !== 200) { + if ($json->status !== '200') { throw new Exception("JSON status from Tshock protocol response was '$json->status', expected '200'."); } From b8bd63c90de1da922c480fb8732d32a734e95c8d Mon Sep 17 00:00:00 2001 From: "Niklas (Krymonota)" Date: Thu, 26 Sep 2024 21:26:59 +0200 Subject: [PATCH 11/14] Add `ext-simplexml` to `composer.json` --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index ba28bf0e..2ee8debe 100644 --- a/composer.json +++ b/composer.json @@ -62,7 +62,8 @@ "require": { "php": ">=8.1", "ext-bz2": "*", - "ext-xml": "*" + "ext-xml": "*", + "ext-simplexml": "*" }, "require-dev": { "ext-curl": "*", From 94d24f5bf23a4f0159f9baf59c4699eec1403f6f Mon Sep 17 00:00:00 2001 From: "Niklas (Krymonota)" Date: Thu, 26 Sep 2024 23:05:10 +0200 Subject: [PATCH 12/14] Fix many more code issues and missing type hints --- src/GameQ/Autoloader.php | 4 +- src/GameQ/Buffer.php | 134 ++++-------- src/GameQ/Filters/Base.php | 18 +- src/GameQ/Filters/Normalize.php | 17 +- src/GameQ/Filters/Secondstohuman.php | 24 +-- src/GameQ/Filters/Stripcolors.php | 26 +-- src/GameQ/Filters/Test.php | 8 +- src/GameQ/GameQ.php | 154 ++++--------- src/GameQ/Protocol.php | 215 +++++-------------- src/GameQ/Protocols/Aa3.php | 12 +- src/GameQ/Protocols/Aapg.php | 8 +- src/GameQ/Protocols/Arkse.php | 12 +- src/GameQ/Protocols/Arma.php | 8 +- src/GameQ/Protocols/Arma3.php | 52 ++--- src/GameQ/Protocols/Armedassault2oa.php | 12 +- src/GameQ/Protocols/Ase.php | 36 +--- src/GameQ/Protocols/Atlas.php | 12 +- src/GameQ/Protocols/Avorion.php | 15 +- src/GameQ/Protocols/Barotrauma.php | 12 +- src/GameQ/Protocols/Batt1944.php | 16 +- src/GameQ/Protocols/Bf1942.php | 20 +- src/GameQ/Protocols/Bf2.php | 22 +- src/GameQ/Protocols/Bf3.php | 57 ++--- src/GameQ/Protocols/Bf4.php | 13 +- src/GameQ/Protocols/Bfbc2.php | 55 ++--- src/GameQ/Protocols/Bfh.php | 8 +- src/GameQ/Protocols/Blackmesa.php | 8 +- src/GameQ/Protocols/Brink.php | 12 +- src/GameQ/Protocols/Cfx.php | 45 ++-- src/GameQ/Protocols/Cfxplayers.php | 33 +-- src/GameQ/Protocols/Citadel.php | 8 +- src/GameQ/Protocols/Cod.php | 8 +- src/GameQ/Protocols/Cod2.php | 8 +- src/GameQ/Protocols/Cod4.php | 8 +- src/GameQ/Protocols/Codmw2.php | 10 +- src/GameQ/Protocols/Codmw3.php | 12 +- src/GameQ/Protocols/Coduo.php | 8 +- src/GameQ/Protocols/Codwaw.php | 8 +- src/GameQ/Protocols/Conanexiles.php | 8 +- src/GameQ/Protocols/Contagion.php | 8 +- src/GameQ/Protocols/Crysis.php | 8 +- src/GameQ/Protocols/Crysis2.php | 8 +- src/GameQ/Protocols/Crysiswars.php | 8 +- src/GameQ/Protocols/Cs15.php | 8 +- src/GameQ/Protocols/Cs16.php | 8 +- src/GameQ/Protocols/Cs2d.php | 43 ++-- src/GameQ/Protocols/Cscz.php | 8 +- src/GameQ/Protocols/Csgo.php | 8 +- src/GameQ/Protocols/Css.php | 8 +- src/GameQ/Protocols/Dal.php | 8 +- src/GameQ/Protocols/Dayz.php | 14 +- src/GameQ/Protocols/Dayzmod.php | 8 +- src/GameQ/Protocols/Dod.php | 8 +- src/GameQ/Protocols/Dods.php | 8 +- src/GameQ/Protocols/Doom3.php | 35 +-- src/GameQ/Protocols/Dow.php | 12 +- src/GameQ/Protocols/Eco.php | 26 +-- src/GameQ/Protocols/Egs.php | 12 +- src/GameQ/Protocols/Et.php | 8 +- src/GameQ/Protocols/Etqw.php | 37 +--- src/GameQ/Protocols/Ffe.php | 8 +- src/GameQ/Protocols/Ffow.php | 46 +--- src/GameQ/Protocols/Fof.php | 8 +- src/GameQ/Protocols/Gamespy.php | 37 ++-- src/GameQ/Protocols/Gamespy2.php | 51 ++--- src/GameQ/Protocols/Gamespy3.php | 65 ++---- src/GameQ/Protocols/Gmod.php | 8 +- src/GameQ/Protocols/Grav.php | 8 +- src/GameQ/Protocols/Gta5m.php | 12 +- src/GameQ/Protocols/Gtan.php | 33 ++- src/GameQ/Protocols/Gtar.php | 33 ++- src/GameQ/Protocols/Had2.php | 16 +- src/GameQ/Protocols/Halo.php | 8 +- src/GameQ/Protocols/Hl1.php | 8 +- src/GameQ/Protocols/Hl2dm.php | 8 +- src/GameQ/Protocols/Hll.php | 30 +-- src/GameQ/Protocols/Http.php | 20 +- src/GameQ/Protocols/Hurtworld.php | 8 +- src/GameQ/Protocols/Insurgency.php | 8 +- src/GameQ/Protocols/Insurgencysand.php | 12 +- src/GameQ/Protocols/Jediacademy.php | 8 +- src/GameQ/Protocols/Jedioutcast.php | 8 +- src/GameQ/Protocols/Justcause2.php | 32 +-- src/GameQ/Protocols/Justcause3.php | 12 +- src/GameQ/Protocols/Killingfloor.php | 21 +- src/GameQ/Protocols/Killingfloor2.php | 12 +- src/GameQ/Protocols/Kingpin.php | 8 +- src/GameQ/Protocols/L4d.php | 8 +- src/GameQ/Protocols/L4d2.php | 8 +- src/GameQ/Protocols/Lhmp.php | 35 +-- src/GameQ/Protocols/Lifeisfeudal.php | 12 +- src/GameQ/Protocols/M2mp.php | 42 +--- src/GameQ/Protocols/Minecraft.php | 16 +- src/GameQ/Protocols/Minecraftbe.php | 12 +- src/GameQ/Protocols/Minecraftpe.php | 8 +- src/GameQ/Protocols/Miscreated.php | 16 +- src/GameQ/Protocols/Modiverse.php | 8 +- src/GameQ/Protocols/Mohaa.php | 18 +- src/GameQ/Protocols/Mordhau.php | 18 +- src/GameQ/Protocols/Mta.php | 16 +- src/GameQ/Protocols/Mumble.php | 51 ++--- src/GameQ/Protocols/Nmrih.php | 8 +- src/GameQ/Protocols/Ns2.php | 12 +- src/GameQ/Protocols/Of.php | 8 +- src/GameQ/Protocols/Openttd.php | 30 +-- src/GameQ/Protocols/Pixark.php | 12 +- src/GameQ/Protocols/Postscriptum.php | 12 +- src/GameQ/Protocols/Projectrealitybf2.php | 8 +- src/GameQ/Protocols/Quake2.php | 37 +--- src/GameQ/Protocols/Quake3.php | 37 +--- src/GameQ/Protocols/Quake4.php | 11 +- src/GameQ/Protocols/Quakelive.php | 8 +- src/GameQ/Protocols/Raknet.php | 32 +-- src/GameQ/Protocols/Redorchestra2.php | 12 +- src/GameQ/Protocols/Redorchestraostfront.php | 8 +- src/GameQ/Protocols/Rf2.php | 12 +- src/GameQ/Protocols/Rfactor.php | 8 +- src/GameQ/Protocols/Rfactor2.php | 8 +- src/GameQ/Protocols/Risingstorm2.php | 14 +- src/GameQ/Protocols/Rust.php | 10 +- src/GameQ/Protocols/Samp.php | 47 ++-- src/GameQ/Protocols/Sco.php | 12 +- src/GameQ/Protocols/Serioussam.php | 16 +- src/GameQ/Protocols/Sevendaystodie.php | 12 +- src/GameQ/Protocols/Ship.php | 11 +- src/GameQ/Protocols/Sof2.php | 12 +- src/GameQ/Protocols/Soldat.php | 16 +- src/GameQ/Protocols/Source.php | 77 +++---- src/GameQ/Protocols/Spaceengineers.php | 8 +- src/GameQ/Protocols/Squad.php | 12 +- src/GameQ/Protocols/Starmade.php | 37 +--- src/GameQ/Protocols/Stormworks.php | 12 +- src/GameQ/Protocols/Swat4.php | 12 +- src/GameQ/Protocols/Teamspeak2.php | 68 ++---- src/GameQ/Protocols/Teamspeak3.php | 67 ++---- src/GameQ/Protocols/Teeworlds.php | 33 +-- src/GameQ/Protocols/Terraria.php | 16 +- src/GameQ/Protocols/Tf2.php | 8 +- src/GameQ/Protocols/Theforrest.php | 12 +- src/GameQ/Protocols/Tibia.php | 34 +-- src/GameQ/Protocols/Tshock.php | 19 +- src/GameQ/Protocols/Unreal2.php | 41 ++-- src/GameQ/Protocols/Unturned.php | 12 +- src/GameQ/Protocols/Urbanterror.php | 12 +- src/GameQ/Protocols/Ut.php | 16 +- src/GameQ/Protocols/Ut2004.php | 8 +- src/GameQ/Protocols/Ut3.php | 28 +-- src/GameQ/Protocols/Valheim.php | 12 +- src/GameQ/Protocols/Ventrilo.php | 70 +++--- src/GameQ/Protocols/Vrising.php | 12 +- src/GameQ/Protocols/Warsow.php | 18 +- src/GameQ/Protocols/Won.php | 16 +- src/GameQ/Protocols/Wurm.php | 8 +- src/GameQ/Protocols/Zomboid.php | 8 +- src/GameQ/Query/Core.php | 79 ++----- src/GameQ/Query/Native.php | 22 +- src/GameQ/Result.php | 41 +--- src/GameQ/Server.php | 121 ++++------- 158 files changed, 986 insertions(+), 2599 deletions(-) diff --git a/src/GameQ/Autoloader.php b/src/GameQ/Autoloader.php index 7c8eb415..eb3d374e 100644 --- a/src/GameQ/Autoloader.php +++ b/src/GameQ/Autoloader.php @@ -26,10 +26,8 @@ * i.e. require_once('/path/to/src/GameQ/Autoloader.php'); * * See: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader-examples.md - * - * @codeCoverageIgnore */ -spl_autoload_register(function ($class) { +spl_autoload_register(static function ($class) { // project-specific namespace prefix $prefix = 'GameQ\\'; diff --git a/src/GameQ/Buffer.php b/src/GameQ/Buffer.php index e78e8cec..95651065 100644 --- a/src/GameQ/Buffer.php +++ b/src/GameQ/Buffer.php @@ -39,47 +39,31 @@ class Buffer /** * Constants for the byte code types we need to read as */ - const NUMBER_TYPE_BIGENDIAN = 'be', - NUMBER_TYPE_LITTLEENDIAN = 'le', - NUMBER_TYPE_MACHINE = 'm'; + public const NUMBER_TYPE_BIGENDIAN = 'be'; + public const NUMBER_TYPE_LITTLEENDIAN = 'le'; /** * The number type we use for reading integers. Defaults to little endian - * - * @type string */ - private $number_type; + private string $number_type; /** * The original data - * - * @type string */ - private $data; + private string $data; /** * The original data - * - * @type int */ - private $length; + private int $length; /** * Position of pointer - * - * @type int */ - private $index = 0; + private int $index = 0; - /** - * Constructor - * - * @param string $data - * @param string $number_type - */ - public function __construct($data, $number_type = self::NUMBER_TYPE_LITTLEENDIAN) + public function __construct(string $data, string $number_type = self::NUMBER_TYPE_LITTLEENDIAN) { - $this->number_type = $number_type; $this->data = $data; $this->length = strlen($data); @@ -87,10 +71,8 @@ public function __construct($data, $number_type = self::NUMBER_TYPE_LITTLEENDIAN /** * Return all the data - * - * @return string The data */ - public function getData() + public function getData(): string { return $this->data; @@ -98,10 +80,8 @@ public function getData() /** * Return data currently in the buffer - * - * @return string The data currently in the buffer */ - public function getBuffer() + public function getBuffer(): string { return substr($this->data, $this->index); @@ -109,10 +89,8 @@ public function getBuffer() /** * Returns the number of bytes in the buffer - * - * @return int Length of the buffer */ - public function getLength() + public function getLength(): int { return max($this->length - $this->index, 0); @@ -121,12 +99,9 @@ public function getLength() /** * Read from the buffer * - * @param int $length - * - * @return string * @throws \GameQ\Exception\Protocol */ - public function read($length = 1) + public function read(int $length = 1): string { if (($length + $this->index) > $this->length) { @@ -144,28 +119,22 @@ public function read($length = 1) * * Unlike the other read functions, this function actually removes * the character from the buffer. - * - * @return string */ - public function readLast() + public function readLast(): string { $len = strlen($this->data); $string = $this->data[strlen($this->data) - 1]; $this->data = substr($this->data, 0, $len - 1); - $this->length -= 1; + --$this->length; return $string; } /** * Look at the buffer, but don't remove - * - * @param int $length - * - * @return string */ - public function lookAhead($length = 1) + public function lookAhead(int $length = 1): string { return substr($this->data, $this->index, $length); @@ -173,10 +142,8 @@ public function lookAhead($length = 1) /** * Skip forward in the buffer - * - * @param int $length */ - public function skip($length = 1) + public function skip(int $length = 1): void { $this->index += $length; @@ -185,10 +152,8 @@ public function skip($length = 1) /** * Jump to a specific position in the buffer, * will not jump past end of buffer - * - * @param $index */ - public function jumpto($index) + public function jumpto(int $index): void { $this->index = min($index, $this->length - 1); @@ -196,10 +161,8 @@ public function jumpto($index) /** * Get the current pointer position - * - * @return int */ - public function getPosition() + public function getPosition(): int { return $this->index; @@ -210,14 +173,10 @@ public function getPosition() * * If not found, return everything * - * @param string $delim - * - * @return string * @throws \GameQ\Exception\Protocol */ - public function readString($delim = "\x00") + public function readString(string $delim = "\x00"): string { - // Get position of delimiter $len = strpos($this->data, $delim, min($this->index, $this->length)); @@ -239,10 +198,9 @@ public function readString($delim = "\x00") * @param int $offset Number of bits to cut off the end * @param bool $read_offset True if the data after the offset is to be read * - * @return string * @throws \GameQ\Exception\Protocol */ - public function readPascalString($offset = 0, $read_offset = false) + public function readPascalString(int $offset = 0, bool $read_offset = false): string { // Get the proper offset @@ -252,9 +210,9 @@ public function readPascalString($offset = 0, $read_offset = false) // Read the data if ($read_offset) { return $this->read($offset); - } else { - return substr($this->read($len), 0, $offset); } + + return substr($this->read($len), 0, $offset); } /** @@ -262,15 +220,11 @@ public function readPascalString($offset = 0, $read_offset = false) * * If not found, return everything * - * @param $delims - * @param null|string &$delimfound - * - * @return string * @throws \GameQ\Exception\Protocol * * @todo: Check to see if this is even used anymore */ - public function readStringMulti($delims, &$delimfound = null) + public function readStringMulti(array $delims, ?string &$delimfound = null): string { // Get position of delimiters @@ -297,13 +251,12 @@ public function readStringMulti($delims, &$delimfound = null) /** * Read an 8-bit unsigned integer * - * @return int * @throws \GameQ\Exception\Protocol */ - public function readInt8() + public function readInt8(): int { - $int = unpack('Cint', $this->read(1)); + $int = unpack('Cint', $this->read()); return $int['int']; } @@ -311,13 +264,12 @@ public function readInt8() /** * Read and 8-bit signed integer * - * @return int * @throws \GameQ\Exception\Protocol */ - public function readInt8Signed() + public function readInt8Signed(): int { - $int = unpack('cint', $this->read(1)); + $int = unpack('cint', $this->read()); return $int['int']; } @@ -325,10 +277,9 @@ public function readInt8Signed() /** * Read a 16-bit unsigned integer * - * @return int * @throws \GameQ\Exception\Protocol */ - public function readInt16() + public function readInt16(): int { // Change the integer type we are looking up @@ -346,17 +297,16 @@ public function readInt16() /** * Read a 16-bit signed integer * - * @return int * @throws \GameQ\Exception\Protocol */ - public function readInt16Signed() + public function readInt16Signed(): int { // Read the data into a string $string = $this->read(2); // For big endian we need to reverse the bytes - if ($this->number_type == self::NUMBER_TYPE_BIGENDIAN) { + if ($this->number_type === self::NUMBER_TYPE_BIGENDIAN) { $string = strrev($string); } @@ -370,10 +320,9 @@ public function readInt16Signed() /** * Read a 32-bit unsigned integer * - * @return int * @throws \GameQ\Exception\Protocol */ - public function readInt32($length = 4) + public function readInt32($length = 4): int { // Change the integer type we are looking up $littleEndian = null; @@ -404,17 +353,16 @@ public function readInt32($length = 4) /** * Read a 32-bit signed integer * - * @return int * @throws \GameQ\Exception\Protocol */ - public function readInt32Signed() + public function readInt32Signed(): int { // Read the data into a string $string = $this->read(4); // For big endian we need to reverse the bytes - if ($this->number_type == self::NUMBER_TYPE_BIGENDIAN) { + if ($this->number_type === self::NUMBER_TYPE_BIGENDIAN) { $string = strrev($string); } @@ -428,14 +376,13 @@ public function readInt32Signed() /** * Read a 64-bit unsigned integer * - * @return int * @throws \GameQ\Exception\Protocol */ - public function readInt64() + public function readInt64(): int { // We have the pack 64-bit codes available. See: http://php.net/manual/en/function.pack.php - if (version_compare(PHP_VERSION, '5.6.3') >= 0 && PHP_INT_SIZE === 8) { + if (PHP_INT_SIZE === 8 && version_compare(PHP_VERSION, '5.6.3') >= 0) { // Change the integer type we are looking up $type = match ($this->number_type) { self::NUMBER_TYPE_BIGENDIAN => 'Jint', @@ -469,17 +416,16 @@ public function readInt64() /** * Read a 32-bit float * - * @return float * @throws \GameQ\Exception\Protocol */ - public function readFloat32() + public function readFloat32(): float { // Read the data into a string $string = $this->read(4); // For big endian we need to reverse the bytes - if ($this->number_type == self::NUMBER_TYPE_BIGENDIAN) { + if ($this->number_type === self::NUMBER_TYPE_BIGENDIAN) { $string = strrev($string); } @@ -490,7 +436,7 @@ public function readFloat32() return $float['float']; } - private static function extendBinaryString($input, $length = 4, $littleEndian = null) + private static function extendBinaryString(string $input, int $length = 4, $littleEndian = null): string { if (is_null($littleEndian)) { $littleEndian = self::isLittleEndian(); @@ -500,12 +446,12 @@ private static function extendBinaryString($input, $length = 4, $littleEndian = if ($littleEndian) { return $input . $extension; - } else { - return $extension . $input; } + + return $extension . $input; } - private static function isLittleEndian() + private static function isLittleEndian(): bool { return 0x00FF === current(unpack('v', pack('S', 0x00FF))); } diff --git a/src/GameQ/Filters/Base.php b/src/GameQ/Filters/Base.php index 501f77d4..4d28983b 100644 --- a/src/GameQ/Filters/Base.php +++ b/src/GameQ/Filters/Base.php @@ -30,34 +30,22 @@ abstract class Base /** * Holds the options for this instance of the filter - * - * @type array */ - protected $options = []; + protected array $options = []; - /** - * Construct - * - * @param array $options - */ public function __construct(array $options = []) { $this->options = $options; } - public function getOptions() + public function getOptions(): array { return $this->options; } /** * Apply the filter to the data - * - * @param array $result - * @param \GameQ\Server $server - * - * @return mixed */ - abstract public function apply(array $result, Server $server); + abstract public function apply(array $result, Server $server): mixed; } diff --git a/src/GameQ/Filters/Normalize.php b/src/GameQ/Filters/Normalize.php index 5771c929..5e89c8bc 100644 --- a/src/GameQ/Filters/Normalize.php +++ b/src/GameQ/Filters/Normalize.php @@ -30,20 +30,15 @@ class Normalize extends Base /** * Holds the protocol specific normalize information - * - * @type array */ - protected $normalize = []; + protected array $normalize = []; /** * Apply this filter * - * @param array $result - * @param \GameQ\Server $server - * - * @return array + * @return mixed */ - public function apply(array $result, Server $server) + public function apply(array $result, Server $server): mixed { // No result passed so just return @@ -117,11 +112,9 @@ protected function check($section, $data) break; } } - } else { + } elseif (array_key_exists($raw, $data)) { // String - if (array_key_exists($raw, $data)) { - $value = $data[$raw]; - } + $value = $data[$raw]; } $normalized['gq_' . $property] = $value; diff --git a/src/GameQ/Filters/Secondstohuman.php b/src/GameQ/Filters/Secondstohuman.php index 1b413f74..0855780d 100644 --- a/src/GameQ/Filters/Secondstohuman.php +++ b/src/GameQ/Filters/Secondstohuman.php @@ -37,19 +37,17 @@ class Secondstohuman extends Base /** * The options key for setting the data key(s) to look for to convert */ - const OPTION_TIMEKEYS = 'timekeys'; + public const OPTION_TIMEKEYS = 'timekeys'; /** * The result key added when applying this filter to a result */ - const RESULT_KEY = 'gq_%s_human'; + public const RESULT_KEY = 'gq_%s_human'; /** * Holds the default 'time' keys from the response array. This is key is usually 'time' from A2S responses - * - * @var array */ - protected $timeKeysDefault = ['time']; + protected array $timeKeysDefault = ['time']; /** * Secondstohuman constructor. @@ -74,12 +72,9 @@ public function __construct(array $options = []) /** * Apply this filter to the result data * - * @param array $result - * @param Server $server - * - * @return array + * @return mixed */ - public function apply(array $result, Server $server) + public function apply(array $result, Server $server): mixed { // Send the results off to be iterated and return the updated result return $this->iterate($result); @@ -103,9 +98,14 @@ protected function iterate(array &$result) if (is_array($value)) { // Iterate and update the result $result[$key] = $this->iterate($value); - } elseif (in_array($key, $this->options[self::OPTION_TIMEKEYS])) { + } elseif (in_array( + $key, + $this->options[self::OPTION_TIMEKEYS], + true + ) + ) { // Make sure the value is a float (throws E_WARNING in PHP 7.1+) - $value = floatval($value); + $value = (float)$value; // We match one of the keys we are wanting to convert so add it and move on $result[sprintf(self::RESULT_KEY, $key)] = sprintf( "%02d:%02d:%02d", diff --git a/src/GameQ/Filters/Stripcolors.php b/src/GameQ/Filters/Stripcolors.php index d71ea554..915beb03 100644 --- a/src/GameQ/Filters/Stripcolors.php +++ b/src/GameQ/Filters/Stripcolors.php @@ -33,12 +33,9 @@ class Stripcolors extends Base /** * Apply this filter * - * @param array $result - * @param \GameQ\Server $server - * - * @return array + * @return mixed */ - public function apply(array $result, Server $server) + public function apply(array $result, Server $server): mixed { // No result passed so just return @@ -49,8 +46,13 @@ public function apply(array $result, Server $server) //$data = []; //$data['raw'][ $server->id() ] = $result; + $protocol = $server->protocol(); + if ($protocol === null) { + return $result; + } + // Switch based on the base (not game) protocol - switch ($server->protocol()->getProtocol()) { + switch ($protocol->getProtocol()) { case 'quake2': case 'quake3': case 'gta5m': @@ -84,30 +86,24 @@ public function apply(array $result, Server $server) /** * Strip color codes from quake based games - * - * @param string $string */ - protected function stripQuake(&$string) + protected function stripQuake(string &$string): void { $string = preg_replace('#(\^.)#', '', $string); } /** * Strip color codes from Source based games - * - * @param string $string */ - protected function stripSource(&$string) + protected function stripSource(string &$string): void { $string = strip_tags($string); } /** * Strip color codes from Unreal based games - * - * @param string $string */ - protected function stripUnreal(&$string) + protected function stripUnreal(string &$string): void { $string = preg_replace('/\x1b.../', '', $string); } diff --git a/src/GameQ/Filters/Test.php b/src/GameQ/Filters/Test.php index 51c83292..38758f44 100644 --- a/src/GameQ/Filters/Test.php +++ b/src/GameQ/Filters/Test.php @@ -32,14 +32,10 @@ class Test extends Base /** * Apply the filter. For this we just return whatever is sent * - * @param array $result - * @param \GameQ\Server $server - * - * @return array + * @return mixed */ - public function apply(array $result, Server $server) + public function apply(array $result, Server $server): mixed { - return $result; } } diff --git a/src/GameQ/GameQ.php b/src/GameQ/GameQ.php index 98a57af4..16ff370c 100644 --- a/src/GameQ/GameQ.php +++ b/src/GameQ/GameQ.php @@ -20,6 +20,8 @@ use GameQ\Exception\Protocol as ProtocolException; use GameQ\Exception\Query as QueryException; +use GameQ\Query\Core; +use GameQ\Query\Native; /** * Base GameQ Class @@ -41,32 +43,20 @@ */ class GameQ { - /* - * Constants - */ - const PROTOCOLS_DIRECTORY = __DIR__ . '/Protocols'; - - /* Static Section */ - /** * Holds the instance of itself * * @type self */ - protected static $instance = null; + protected static GameQ $instance; /** * Create a new instance of this class - * - * @return \GameQ\GameQ */ - public static function factory() + public static function factory(): self { - - // Create a new instance self::$instance = new self(); - // Return this new instance return self::$instance; } @@ -74,10 +64,8 @@ public static function factory() /** * Default options - * - * @type array */ - protected $options = [ + protected array $options = [ 'debug' => false, 'timeout' => 3, // Seconds 'filters' => [ @@ -98,33 +86,25 @@ public static function factory() /** * Array of servers being queried - * - * @type array */ - protected $servers = []; + protected array $servers = []; /** * The query library to use. Default is Native - * - * @type string */ - protected $queryLibrary = 'GameQ\\Query\\Native'; + protected string $queryLibrary = Native::class; /** * Holds the instance of the queryLibrary - * - * @type \GameQ\Query\Core|null */ - protected $query = null; + protected ?Core $query = null; /** * Get an option's value * - * @param mixed $option - * * @return mixed|null */ - public function __get($option) + public function __get(string $option) { return $this->options[$option] ?? null; @@ -132,72 +112,52 @@ public function __get($option) /** * Set an option's value - * - * @param mixed $option - * @param mixed $value */ - public function __set($option, $value) + public function __set(string $option, mixed $value): void { - $this->options[$option] = $value; } - public function __isset($option) + public function __isset(string $option) { return isset($this->options[$option]); } - public function getServers() + public function getServers(): array { return $this->servers; } - public function getOptions() + public function getOptions(): array { return $this->options; } /** * Chainable call to __set, uses set as the actual setter - * - * @param mixed $var - * @param mixed $value - * - * @return $this */ - public function setOption($var, $value) + public function setOption(string $var, mixed $value): self { - - // Use magic $this->{$var} = $value; - return $this; // Make chainable + return $this; } /** * Add a single server - * - * @param array $server_info - * - * @return $this */ - public function addServer(array $server_info = []) + public function addServer(array $server_info = []): self { - // Add and validate the server - $this->servers[uniqid()] = new Server($server_info); + $this->servers[uniqid('', true)] = new Server($server_info); - return $this; // Make calls chainable + return $this; } /** * Add multiple servers in a single call - * - * @param array $servers - * - * @return $this */ - public function addServers(array $servers = []) + public function addServers(array $servers = []): self { // Loop through all the servers and add them @@ -205,7 +165,7 @@ public function addServers(array $servers = []) $this->addServer($server_info); } - return $this; // Make calls chainable + return $this; } /** @@ -213,12 +173,9 @@ public function addServers(array $servers = []) * Supported formats: * JSON * - * @param array $files - * - * @return $this * @throws \Exception */ - public function addServersFromFiles($files = []) + public function addServersFromFiles(array $files = []): self { // Since we expect an array let us turn a string (i.e. single file) into an array @@ -249,28 +206,19 @@ public function addServersFromFiles($files = []) } /** - * Clear all of the defined servers - * - * @return $this + * Clear all the defined servers */ - public function clearServers() + public function clearServers(): self { - - // Reset all the servers $this->servers = []; - return $this; // Make Chainable + return $this; } /** * Add a filter to the processing list - * - * @param string $filterName - * @param array $options - * - * @return $this */ - public function addFilter($filterName, $options = []) + public function addFilter(string $filterName, array $options = []): self { // Create the filter hash so we can run multiple versions of the same filter $filterHash = sprintf('%s_%s', strtolower($filterName), md5(json_encode($options))); @@ -288,12 +236,8 @@ public function addFilter($filterName, $options = []) /** * Remove an added filter - * - * @param string $filterHash - * - * @return $this */ - public function removeFilter($filterHash) + public function removeFilter(string $filterHash): self { // Make lower case $filterHash = strtolower($filterHash); @@ -303,30 +247,24 @@ public function removeFilter($filterHash) unset($this->options['filters'][$filterHash]); } - unset($filterHash); - return $this; } /** * Return the list of applied filters - * - * @return array */ - public function listFilters() + public function listFilters(): array { return $this->options['filters']; } /** - * Main method used to actually process all of the added servers and return the information + * Main method used to actually process all the added servers and return the information * - * @return array * @throws \Exception */ - public function process() + public function process(): array { - // Initialize the query library we are using $class = new \ReflectionClass($this->queryLibrary); @@ -369,9 +307,8 @@ public function process() /** * Do server challenges, where required */ - protected function doChallenges() + protected function doChallenges(): void { - // Initialize the sockets for reading $sockets = []; @@ -458,9 +395,8 @@ protected function doChallenges() /** * Run the actual queries and get the response(s) */ - protected function doQueries() + protected function doQueries(): void { - // Initialize the array of sockets $sockets = []; @@ -474,7 +410,7 @@ protected function doQueries() // Get all the non-challenge packets we need to send $packets = $server->protocol()->getPacket('!' . Protocol::PACKET_CHALLENGE); - if (count($packets) == 0) { + if (count($packets) === 0) { // Skip nothing else to do for some reason. continue; } @@ -546,7 +482,7 @@ protected function doQueries() unset($server); } - // Now we need to close all of the sockets + // Now we need to close all the sockets foreach ($sockets as $socketInfo) { /* @var $socket \GameQ\Query\Core */ $socket = $socketInfo['socket']; @@ -563,16 +499,11 @@ protected function doQueries() /** * Parse the response for a specific server * - * @param \GameQ\Server $server - * - * @return array * @throws \Exception */ - protected function doParseResponse(Server $server) + protected function doParseResponse(Server $server): array { - try { - // @codeCoverageIgnoreStart // We want to save this server's response to a file (useful for unit testing) if (!is_null($this->capture_packets_file)) { file_put_contents( @@ -580,7 +511,6 @@ protected function doParseResponse(Server $server) implode(PHP_EOL . '||' . PHP_EOL, $server->protocol()->packetResponse()) ); } - // @codeCoverageIgnoreEnd // Get the server response $results = $server->protocol()->processResponse(); @@ -600,9 +530,10 @@ protected function doParseResponse(Server $server) } // Now add some default stuff - $results['gq_address'] = (isset($results['gq_address'])) ? $results['gq_address'] : $server->ip(); + $results['gq_address'] = $results['gq_address'] ?? $server->ip(); $results['gq_port_client'] = $server->portClient(); - $results['gq_port_query'] = (isset($results['gq_port_query'])) ? $results['gq_port_query'] : $server->portQuery(); + $results['gq_port_query'] = $results['gq_port_query'] ?? + $server->portQuery(); $results['gq_protocol'] = $server->protocol()->getProtocol(); $results['gq_type'] = (string)$server->protocol(); $results['gq_name'] = $server->protocol()->nameLong(); @@ -610,7 +541,7 @@ protected function doParseResponse(Server $server) // Process the join link if (empty($results['gq_joinlink'])) { - $results['gq_joinlink'] = $server->getJoinLink(); + $results['gq_joinlink'] = $server->getJoinLink() ?? ''; } return $results; @@ -618,13 +549,8 @@ protected function doParseResponse(Server $server) /** * Apply any filters to the results - * - * @param array $results - * @param \GameQ\Server $server - * - * @return array */ - protected function doApplyFilters(array $results, Server $server) + protected function doApplyFilters(array $results, Server $server): array { // Loop over the filters @@ -638,7 +564,7 @@ protected function doApplyFilters(array $results, Server $server) $filter = $class->newInstanceArgs([$filterOptions['options']]); // Apply the filter to the data - $results = $filter->apply($results, $server); + $results = $filter?->apply($results, $server); } catch (\ReflectionException) { // Invalid, skip it continue; diff --git a/src/GameQ/Protocol.php b/src/GameQ/Protocol.php index d3fd02dc..faac80e8 100644 --- a/src/GameQ/Protocol.php +++ b/src/GameQ/Protocol.php @@ -31,142 +31,97 @@ abstract class Protocol /** * Constants for class states */ - const STATE_TESTING = 1; - - const STATE_BETA = 2; - - const STATE_STABLE = 3; - - const STATE_DEPRECATED = 4; + public const STATE_TESTING = 1; + public const STATE_BETA = 2; + public const STATE_STABLE = 3; + public const STATE_DEPRECATED = 4; /** * Constants for packet keys */ - const PACKET_ALL = 'all'; // Some protocols allow all data to be sent back in one call. - - const PACKET_BASIC = 'basic'; - - const PACKET_CHALLENGE = 'challenge'; - - const PACKET_CHANNELS = 'channels'; // Voice servers - - const PACKET_DETAILS = 'details'; - - const PACKET_INFO = 'info'; + public const PACKET_ALL = 'all'; // Some protocols allow all data to be sent back in one call. + public const PACKET_BASIC = 'basic'; - const PACKET_PLAYERS = 'players'; - - const PACKET_STATUS = 'status'; - - const PACKET_RULES = 'rules'; - - const PACKET_VERSION = 'version'; + public const PACKET_CHALLENGE = 'challenge'; + public const PACKET_CHANNELS = 'channels'; // Voice servers + public const PACKET_DETAILS = 'details'; + public const PACKET_INFO = 'info'; + public const PACKET_PLAYERS = 'players'; + public const PACKET_STATUS = 'status'; + public const PACKET_RULES = 'rules'; + public const PACKET_VERSION = 'version'; /** * Transport constants */ - const TRANSPORT_UDP = 'udp'; - - const TRANSPORT_TCP = 'tcp'; - - const TRANSPORT_SSL = 'ssl'; - - const TRANSPORT_TLS = 'tls'; + public const TRANSPORT_UDP = 'udp'; + public const TRANSPORT_TCP = 'tcp'; + public const TRANSPORT_SSL = 'ssl'; + public const TRANSPORT_TLS = 'tls'; /** * Short name of the protocol - * - * @type string */ - protected $name = 'unknown'; + protected string $name = 'unknown'; /** * The longer, fancier name for the protocol - * - * @type string */ - protected $name_long = 'unknown'; + protected string $name_long = 'unknown'; /** * The difference between the client port and query port - * - * @type int */ - protected $port_diff = 0; + protected int $port_diff = 0; /** * The transport method to use to actually send the data * Default is UDP - * - * @type string */ - protected $transport = self::TRANSPORT_UDP; + protected string $transport = self::TRANSPORT_UDP; /** * The protocol type used when querying the server - * - * @type string */ - protected $protocol = 'unknown'; + protected string $protocol = 'unknown'; /** * Holds the valid packet types this protocol has available. - * - * @type array */ - protected $packets = []; + protected array $packets = []; /** * Holds the response headers and the method to use to process them. - * - * @type array */ - protected $responses = []; + protected array $responses = []; /** * Holds the list of methods to run when parsing the packet response(s) data. These * methods should provide all the return information. - * - * @type array */ - protected $process_methods = []; + protected array $process_methods = []; /** * The packet responses received - * - * @type array - */ - protected $packets_response = []; - - /** - * Holds the instance of the result class - * - * @type null */ - protected $result = null; + protected array $packets_response = []; /** * Options for this protocol - * - * @type array */ - protected $options = []; + protected array $options = []; /** * Define the state of this class - * - * @type int */ - protected $state = self::STATE_STABLE; + protected int $state = self::STATE_STABLE; /** * Holds specific normalize settings * * @todo: Remove this ugly bulk by moving specific ones to their specific game(s) - * - * @type array */ - protected $normalize = [ + protected array $normalize = [ // General 'general' => [ // target => source @@ -203,14 +158,9 @@ abstract class Protocol /** * Quick join link - * - * @type string */ - protected $join_link = ''; + protected ?string $join_link = null; - /** - * @param array $options - */ public function __construct(array $options = []) { @@ -220,10 +170,8 @@ public function __construct(array $options = []) /** * String name of this class - * - * @return string */ - public function __toString() + public function __toString(): string { return $this->name; @@ -231,10 +179,8 @@ public function __toString() /** * Get the port difference between the server's client (game) and query ports - * - * @return int */ - public function portDiff() + public function portDiff(): int { return $this->port_diff; @@ -244,12 +190,8 @@ public function portDiff() * "Find" the query port based off of the client port and port_diff * * This method is meant to be overloaded for more complex maths or lookup tables - * - * @param int $clientPort - * - * @return int */ - public function findQueryPort($clientPort) + public function findQueryPort(int $clientPort): int { return $clientPort + $this->port_diff; @@ -257,10 +199,8 @@ public function findQueryPort($clientPort) /** * Return the join_link as defined by the protocol class - * - * @return string */ - public function joinLink() + public function joinLink(): ?string { return $this->join_link; @@ -268,10 +208,8 @@ public function joinLink() /** * Short (callable) name of this class - * - * @return string */ - public function name() + public function name(): string { return $this->name; @@ -279,10 +217,8 @@ public function name() /** * Long name of this class - * - * @return string */ - public function nameLong() + public function nameLong(): string { return $this->name_long; @@ -290,10 +226,8 @@ public function nameLong() /** * Return the status of this Protocol Class - * - * @return int */ - public function state() + public function state(): int { return $this->state; @@ -301,10 +235,8 @@ public function state() /** * Return the protocol property - * - * @return string */ - public function getProtocol() + public function getProtocol(): string { return $this->protocol; @@ -312,16 +244,10 @@ public function getProtocol() /** * Get/set the transport type for this protocol - * - * @param string|null $type - * - * @return string */ - public function transport($type = null) + public function transport(?string $type = null): ?string { - - // Act as setter - if (!is_null($type)) { + if ($type !== null) { $this->transport = $type; } @@ -330,15 +256,10 @@ public function transport($type = null) /** * Set the options for the protocol call - * - * @param array $options - * - * @return array */ - public function options($options = []) + public function options(array $options = []): array { - // Act as setter if (!empty($options)) { $this->options = $options; } @@ -353,23 +274,18 @@ public function options($options = []) /** * Return specific packet(s) - * - * @param array|string $type - * - * @return array */ - public function getPacket($type = []) + public function getPacket(array|string $type = []): array { $packets = []; - // We want an array of packets back if (is_array($type) && !empty($type)) { // Loop the packets foreach ($this->packets as $packet_type => $packet_data) { // We want this packet - if (in_array($packet_type, $type)) { + if (in_array($packet_type, $type, true)) { $packets[$packet_type] = $packet_data; } } @@ -377,7 +293,7 @@ public function getPacket($type = []) // Loop the packets foreach ($this->packets as $packet_type => $packet_data) { // Dont want challenge packets - if ($packet_type != self::PACKET_CHALLENGE) { + if ($packet_type !== self::PACKET_CHALLENGE) { $packets[$packet_type] = $packet_data; } } @@ -395,15 +311,9 @@ public function getPacket($type = []) /** * Get/set the packet response - * - * @param array|null $response - * - * @return array */ - public function packetResponse(array $response = null) + public function packetResponse(?array $response = null): array { - - // Act as setter if (!empty($response)) { $this->packets_response = $response; } @@ -418,26 +328,17 @@ public function packetResponse(array $response = null) /** * Determine whether or not this protocol has a challenge needed before querying - * - * @return bool */ - public function hasChallenge() + public function hasChallenge(): bool { - return (isset($this->packets[self::PACKET_CHALLENGE]) && !empty($this->packets[self::PACKET_CHALLENGE])); } /** * Parse the challenge response and add it to the buffer items that need it. * This should be overloaded by extending class - * - * @codeCoverageIgnore - * - * @param \GameQ\Buffer $challenge_buffer - * - * @return bool */ - public function challengeParseAndApply(Buffer $challenge_buffer) + public function challengeParseAndApply(Buffer $challenge_buffer): bool { return true; @@ -445,12 +346,8 @@ public function challengeParseAndApply(Buffer $challenge_buffer) /** * Apply the challenge string to all the packets that need it. - * - * @param string $challenge_string - * - * @return bool */ - protected function challengeApply($challenge_string) + protected function challengeApply(string $challenge_string): bool { // Let's loop through all the packets and append the challenge where it is needed @@ -497,10 +394,8 @@ public function convertToUtf8(string $s): string /** * Get the normalize settings for the protocol - * - * @return array */ - public function getNormalize() + public function getNormalize(): array { return $this->normalize; @@ -512,19 +407,13 @@ public function getNormalize() /** * Generic method to allow protocol classes to do work right before the query is sent - * - * @codeCoverageIgnore - * - * @param \GameQ\Server $server */ - public function beforeSend(Server $server) + public function beforeSend(Server $server): void { } /** * Method called to process query response data. Each extending class has to have one of these functions. - * - * @return mixed */ - abstract public function processResponse(); + abstract public function processResponse(): mixed; } diff --git a/src/GameQ/Protocols/Aa3.php b/src/GameQ/Protocols/Aa3.php index 6ffd412a..2ad70c16 100644 --- a/src/GameQ/Protocols/Aa3.php +++ b/src/GameQ/Protocols/Aa3.php @@ -29,25 +29,19 @@ class Aa3 extends Source /** * String name of this protocol class - * - * @type string */ - protected $name = 'aa3'; + protected string $name = 'aa3'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "America's Army 3"; + protected string $name_long = "America's Army 3"; /** * Query port = client_port + 18243 * * client_port default 8777 * query_port default 27020 - * - * @type int */ - protected $port_diff = 18243; + protected int $port_diff = 18243; } diff --git a/src/GameQ/Protocols/Aapg.php b/src/GameQ/Protocols/Aapg.php index a207d4fe..784907e9 100644 --- a/src/GameQ/Protocols/Aapg.php +++ b/src/GameQ/Protocols/Aapg.php @@ -28,15 +28,11 @@ class Aapg extends Aa3 { /** * String name of this protocol class - * - * @type string */ - protected $name = 'aapg'; + protected string $name = 'aapg'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "America's Army: Proving Grounds"; + protected string $name_long = "America's Army: Proving Grounds"; } diff --git a/src/GameQ/Protocols/Arkse.php b/src/GameQ/Protocols/Arkse.php index 3193c5a6..75c82288 100644 --- a/src/GameQ/Protocols/Arkse.php +++ b/src/GameQ/Protocols/Arkse.php @@ -29,23 +29,17 @@ class Arkse extends Source /** * String name of this protocol class - * - * @type string */ - protected $name = 'arkse'; + protected string $name = 'arkse'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "ARK: Survival Evolved"; + protected string $name_long = "ARK: Survival Evolved"; /** * query_port = client_port + 19238 * 27015 = 7777 + 19238 - * - * @type int */ - protected $port_diff = 19238; + protected int $port_diff = 19238; } diff --git a/src/GameQ/Protocols/Arma.php b/src/GameQ/Protocols/Arma.php index 2653872f..87e7c8c0 100644 --- a/src/GameQ/Protocols/Arma.php +++ b/src/GameQ/Protocols/Arma.php @@ -29,15 +29,11 @@ class Arma extends Gamespy2 { /** * String name of this protocol class - * - * @type string */ - protected $name = 'arma'; + protected string $name = 'arma'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "ArmA Armed Assault"; + protected string $name_long = "ArmA Armed Assault"; } diff --git a/src/GameQ/Protocols/Arma3.php b/src/GameQ/Protocols/Arma3.php index 62a2b63f..5fe5faca 100644 --- a/src/GameQ/Protocols/Arma3.php +++ b/src/GameQ/Protocols/Arma3.php @@ -33,36 +33,34 @@ class Arma3 extends Source { // Base DLC names - const BASE_DLC_KART = 'Karts'; - const BASE_DLC_MARKSMEN = 'Marksmen'; - const BASE_DLC_HELI = 'Helicopters'; - const BASE_DLC_CURATOR = 'Curator'; - const BASE_DLC_EXPANSION = 'Expansion'; - const BASE_DLC_JETS = 'Jets'; - const BASE_DLC_ORANGE = 'Laws of War'; - const BASE_DLC_ARGO = 'Malden'; - const BASE_DLC_TACOPS = 'Tac-Ops'; - const BASE_DLC_TANKS = 'Tanks'; - const BASE_DLC_CONTACT = 'Contact'; - const BASE_DLC_ENOCH = 'Contact (Platform)'; + private const BASE_DLC_KART = 'Karts'; + private const BASE_DLC_MARKSMEN = 'Marksmen'; + private const BASE_DLC_HELI = 'Helicopters'; + private const BASE_DLC_CURATOR = 'Curator'; + private const BASE_DLC_EXPANSION = 'Expansion'; + private const BASE_DLC_JETS = 'Jets'; + private const BASE_DLC_ORANGE = 'Laws of War'; + private const BASE_DLC_ARGO = 'Malden'; + private const BASE_DLC_TACOPS = 'Tac-Ops'; + private const BASE_DLC_TANKS = 'Tanks'; + private const BASE_DLC_CONTACT = 'Contact'; + private const BASE_DLC_ENOCH = 'Contact (Platform)'; // Special - const BASE_DLC_AOW = 'Art of War'; + private const BASE_DLC_AOW = 'Art of War'; // Creator DLC names - const CREATOR_DLC_GM = 'Global Mobilization'; - const CREATOR_DLC_VN = 'S.O.G. Prairie Fire'; - const CREATOR_DLC_CSLA = 'ČSLA - Iron Curtain'; - const CREATOR_DLC_WS = 'Western Sahara'; + private const CREATOR_DLC_GM = 'Global Mobilization'; + private const CREATOR_DLC_VN = 'S.O.G. Prairie Fire'; + private const CREATOR_DLC_CSLA = 'ČSLA - Iron Curtain'; + private const CREATOR_DLC_WS = 'Western Sahara'; /** * DLC Flags/Bits as defined in the documentation. * * @see https://community.bistudio.com/wiki/Arma_3:_ServerBrowserProtocol3 - * - * @var array */ - protected $dlcFlags = [ + protected array $dlcFlags = [ 0b0000000000000001 => self::BASE_DLC_KART, 0b0000000000000010 => self::BASE_DLC_MARKSMEN, 0b0000000000000100 => self::BASE_DLC_HELI, @@ -83,30 +81,22 @@ class Arma3 extends Source /** * String name of this protocol class - * - * @type string */ - protected $name = 'arma3'; + protected string $name = 'arma3'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Arma3"; + protected string $name_long = "Arma3"; /** * Query port = client_port + 1 - * - * @type int */ - protected $port_diff = 1; + protected int $port_diff = 1; /** * Process the rules since Arma3 changed their response for rules * - * @param Buffer $buffer - * * @return array * @throws \GameQ\Exception\Protocol */ diff --git a/src/GameQ/Protocols/Armedassault2oa.php b/src/GameQ/Protocols/Armedassault2oa.php index e527a38d..7b08c28a 100644 --- a/src/GameQ/Protocols/Armedassault2oa.php +++ b/src/GameQ/Protocols/Armedassault2oa.php @@ -29,22 +29,16 @@ class Armedassault2oa extends Source /** * String name of this protocol class - * - * @type string */ - protected $name = "armedassault2oa"; + protected string $name = "armedassault2oa"; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Armed Assault 2: Operation Arrowhead"; + protected string $name_long = "Armed Assault 2: Operation Arrowhead"; /** * Query port = client_port + 1 - * - * @type int */ - protected $port_diff = 1; + protected int $port_diff = 1; } diff --git a/src/GameQ/Protocols/Ase.php b/src/GameQ/Protocols/Ase.php index 6acd7641..61ccc26e 100644 --- a/src/GameQ/Protocols/Ase.php +++ b/src/GameQ/Protocols/Ase.php @@ -34,47 +34,35 @@ class Ase extends Protocol /** * Array of packets we want to look up. * Each key should correspond to a defined method in this or a parent class - * - * @type array */ - protected $packets = [ + protected array $packets = [ self::PACKET_ALL => "s", ]; /** * The query protocol used to make the call - * - * @type string */ - protected $protocol = 'ase'; + protected string $protocol = 'ase'; /** * String name of this protocol class - * - * @type string */ - protected $name = 'ase'; + protected string $name = 'ase'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "All-Seeing Eye"; + protected string $name_long = "All-Seeing Eye"; /** * The client join link - * - * @type string */ - protected $join_link = null; + protected ?string $join_link = null; /** * Normalize settings for this protocol - * - * @type array */ - protected $normalize = [ + protected array $normalize = [ // General 'general' => [ // target => source @@ -100,10 +88,10 @@ class Ase extends Protocol /** * Process the response * - * @return array + * @return mixed * @throws \GameQ\Exception\Protocol */ - public function processResponse() + public function processResponse(): mixed { // Create a new buffer $buffer = new Buffer(implode('', $this->packets_response)); @@ -153,13 +141,9 @@ public function processResponse() /** * Handles processing the extra key/value pairs for server settings - * - * @param \GameQ\Buffer $buffer - * @param \GameQ\Result $result */ protected function processKeyValuePairs(Buffer $buffer, Result $result) { - // Key / value pairs while ($buffer->getLength()) { $key = $buffer->readPascalString(1, true); @@ -181,13 +165,9 @@ protected function processKeyValuePairs(Buffer $buffer, Result $result) /** * Handles processing the player and team data into a usable format - * - * @param \GameQ\Buffer $buffer - * @param \GameQ\Result $result */ protected function processPlayersAndTeams(Buffer $buffer, Result $result) { - // Players and team info while ($buffer->getLength()) { // Get the flags diff --git a/src/GameQ/Protocols/Atlas.php b/src/GameQ/Protocols/Atlas.php index 83406bae..64c6d4a0 100644 --- a/src/GameQ/Protocols/Atlas.php +++ b/src/GameQ/Protocols/Atlas.php @@ -29,17 +29,13 @@ class Atlas extends Source /** * String name of this protocol class - * - * @type string */ - protected $name = 'atlas'; + protected string $name = 'atlas'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Atlas"; + protected string $name_long = "Atlas"; /** * query_port = client_port + 51800 @@ -48,8 +44,6 @@ class Atlas extends Source * this is the default value for the stock game server, both ports * can be independently changed from the stock ones, * making the port_diff logic useless. - * - * @type int */ - protected $port_diff = 51800; + protected int $port_diff = 51800; } diff --git a/src/GameQ/Protocols/Avorion.php b/src/GameQ/Protocols/Avorion.php index b4aa2d7a..95ce25d8 100644 --- a/src/GameQ/Protocols/Avorion.php +++ b/src/GameQ/Protocols/Avorion.php @@ -27,22 +27,11 @@ class Avorion extends Source { /** * String name of this protocol class - * - * @type string */ - protected $name = 'avorion'; + protected string $name = 'avorion'; /** * Longer string name of this protocol class - * - * @type string - */ - protected $name_long = "Avorion"; - - /** - * query_port = client_port + 1 - * - * @type int - * protected $port_diff = 1; */ + protected string $name_long = "Avorion"; } diff --git a/src/GameQ/Protocols/Barotrauma.php b/src/GameQ/Protocols/Barotrauma.php index 643428a2..dd0d2c76 100644 --- a/src/GameQ/Protocols/Barotrauma.php +++ b/src/GameQ/Protocols/Barotrauma.php @@ -28,22 +28,16 @@ class Barotrauma extends Source { /** * String name of this protocol class - * - * @type string */ - protected $name = 'barotrauma'; + protected string $name = 'barotrauma'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Barotrauma"; + protected string $name_long = "Barotrauma"; /** * query_port = client_port + 1 - * - * @type int */ - protected $port_diff = 1; + protected int $port_diff = 1; } diff --git a/src/GameQ/Protocols/Batt1944.php b/src/GameQ/Protocols/Batt1944.php index f0ff38e6..539e0a99 100644 --- a/src/GameQ/Protocols/Batt1944.php +++ b/src/GameQ/Protocols/Batt1944.php @@ -29,31 +29,23 @@ class Batt1944 extends Source /** * String name of this protocol class - * - * @type string */ - protected $name = 'batt1944'; + protected string $name = 'batt1944'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Battalion 1944"; + protected string $name_long = "Battalion 1944"; /** * query_port = client_port + 3 - * - * @type int */ - protected $port_diff = 3; + protected int $port_diff = 3; /** * Normalize main fields - * - * @var array */ - protected $normalize = [ + protected array $normalize = [ // General 'general' => [ // target => source diff --git a/src/GameQ/Protocols/Bf1942.php b/src/GameQ/Protocols/Bf1942.php index 4cf06c5e..f48f5b64 100644 --- a/src/GameQ/Protocols/Bf1942.php +++ b/src/GameQ/Protocols/Bf1942.php @@ -29,39 +29,29 @@ class Bf1942 extends Gamespy /** * String name of this protocol class - * - * @type string */ - protected $name = 'bf1942'; + protected string $name = 'bf1942'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Battlefield 1942"; + protected string $name_long = "Battlefield 1942"; /** * query_port = client_port + 8433 * 23000 = 14567 + 8433 - * - * @type int */ - protected $port_diff = 8433; + protected int $port_diff = 8433; /** * The client join link - * - * @type string */ - protected $join_link = "bf1942://%s:%d"; + protected ?string $join_link = "bf1942://%s:%d"; /** * Normalize settings for this protocol - * - * @type array */ - protected $normalize = [ + protected array $normalize = [ // General 'general' => [ // target => source diff --git a/src/GameQ/Protocols/Bf2.php b/src/GameQ/Protocols/Bf2.php index 0610f9d0..ca107d2c 100644 --- a/src/GameQ/Protocols/Bf2.php +++ b/src/GameQ/Protocols/Bf2.php @@ -29,48 +29,38 @@ class Bf2 extends Gamespy3 /** * String name of this protocol class - * - * @type string */ - protected $name = 'bf2'; + protected string $name = 'bf2'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Battlefield 2"; + protected string $name_long = "Battlefield 2"; /** * query_port = client_port + 8433 * 29900 = 16567 + 13333 - * - * @type int */ - protected $port_diff = 13333; + protected int $port_diff = 13333; /** * The client join link - * - * @type string */ - protected $join_link = "bf2://%s:%d"; + protected ?string $join_link = "bf2://%s:%d"; /** * BF2 has a different query packet to send than "normal" Gamespy 3 * * @var array */ - protected $packets = [ + protected array $packets = [ self::PACKET_ALL => "\xFE\xFD\x00\x10\x20\x30\x40\xFF\xFF\xFF\x01", ]; /** * Normalize settings for this protocol - * - * @type array */ - protected $normalize = [ + protected array $normalize = [ // General 'general' => [ // target => source diff --git a/src/GameQ/Protocols/Bf3.php b/src/GameQ/Protocols/Bf3.php index a83b74bb..8de1b567 100644 --- a/src/GameQ/Protocols/Bf3.php +++ b/src/GameQ/Protocols/Bf3.php @@ -36,10 +36,8 @@ class Bf3 extends Protocol /** * Array of packets we want to query. - * - * @type array */ - protected $packets = [ + protected array $packets = [ self::PACKET_STATUS => "\x00\x00\x00\x21\x1b\x00\x00\x00\x01\x00\x00\x00\x0a\x00\x00\x00serverInfo\x00", self::PACKET_VERSION => "\x00\x00\x00\x22\x18\x00\x00\x00\x01\x00\x00\x00\x07\x00\x00\x00version\x00", self::PACKET_PLAYERS => @@ -49,9 +47,8 @@ class Bf3 extends Protocol /** * Use the response flag to figure out what method to run * - * @type array */ - protected $responses = [ + protected array $responses = [ 1627389952 => "processDetails", // a 1644167168 => "processVersion", // b 1660944384 => "processPlayers", // c @@ -59,53 +56,39 @@ class Bf3 extends Protocol /** * The transport mode for this protocol is TCP - * - * @type string - */ - protected $transport = self::TRANSPORT_TCP; + */ + protected string $transport = self::TRANSPORT_TCP; /** * The query protocol used to make the call - * - * @type string */ - protected $protocol = 'bf3'; + protected string $protocol = 'bf3'; /** * String name of this protocol class - * - * @type string */ - protected $name = 'bf3'; + protected string $name = 'bf3'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Battlefield 3"; + protected string $name_long = "Battlefield 3"; /** * The client join link - * - * @type string */ - protected $join_link = null; + protected ?string $join_link = null; /** * query_port = client_port + 22000 * 47200 = 25200 + 22000 - * - * @type int */ - protected $port_diff = 22000; + protected int $port_diff = 22000; /** * Normalize settings for this protocol - * - * @type array */ - protected $normalize = [ + protected array $normalize = [ // General 'general' => [ // target => source @@ -129,10 +112,10 @@ class Bf3 extends Protocol /** * Process the response for the StarMade server * - * @return array + * @return mixed * @throws \GameQ\Exception\Protocol */ - public function processResponse() + public function processResponse(): mixed { // Holds the results sent back @@ -176,7 +159,7 @@ public function processResponse() // Check to make sure the expected length matches the real length // Subtract 4 for the sequence_id pulled out earlier - if ($packetLength != ($buffer->readInt32() - 4)) { + if ($packetLength !== ($buffer->readInt32() - 4)) { throw new Exception(__METHOD__ . " packet length does not match expected length!"); } @@ -196,8 +179,7 @@ public function processResponse() /** * Decode the buffer into a usable format - * - * @param \GameQ\Buffer $buffer + * * @return array */ @@ -223,8 +205,7 @@ protected function decode(Buffer $buffer) /** * Process the server details - * - * @param \GameQ\Buffer $buffer + * * @return array */ @@ -282,15 +263,14 @@ protected function processDetails(Buffer $buffer) // Added in R29, No docs as of yet $result->add('quickmatch', (int)$items[$index_current + 13]); // Guessed from research - unset($items, $index_current, $teamCount, $buffer); + unset($items, $index_current, $teamCount); return $result->fetch(); } /** * Process the server version - * - * @param \GameQ\Buffer $buffer + * * @return array */ @@ -312,8 +292,7 @@ protected function processVersion(Buffer $buffer) /** * Process the players - * - * @param \GameQ\Buffer $buffer + * * @return array */ diff --git a/src/GameQ/Protocols/Bf4.php b/src/GameQ/Protocols/Bf4.php index 69517529..ce13a33a 100644 --- a/src/GameQ/Protocols/Bf4.php +++ b/src/GameQ/Protocols/Bf4.php @@ -34,22 +34,17 @@ class Bf4 extends Bf3 /** * String name of this protocol class - * - * @type string */ - protected $name = 'bf4'; + protected string $name = 'bf4'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Battlefield 4"; + protected string $name_long = "Battlefield 4"; /** * Handle processing details since they are different than BF3 - * - * @param \GameQ\Buffer $buffer + * * @return array */ @@ -107,7 +102,7 @@ protected function processDetails(Buffer $buffer) $result->add('blaze_player_count', (int) $items[$index_current + 13]); $result->add('blaze_game_state', (int) $items[$index_current + 14]); - unset($items, $index_current, $teamCount, $buffer); + unset($items, $index_current, $teamCount); return $result->fetch(); } diff --git a/src/GameQ/Protocols/Bfbc2.php b/src/GameQ/Protocols/Bfbc2.php index e9ed0683..f32a1cff 100644 --- a/src/GameQ/Protocols/Bfbc2.php +++ b/src/GameQ/Protocols/Bfbc2.php @@ -39,10 +39,8 @@ class Bfbc2 extends Protocol /** * Array of packets we want to query. - * - * @type array */ - protected $packets = [ + protected array $packets = [ self::PACKET_VERSION => "\x00\x00\x00\x00\x18\x00\x00\x00\x01\x00\x00\x00\x07\x00\x00\x00version\x00", self::PACKET_STATUS => "\x00\x00\x00\x00\x1b\x00\x00\x00\x01\x00\x00\x00\x0a\x00\x00\x00serverInfo\x00", self::PACKET_PLAYERS => "\x00\x00\x00\x00\x24\x00\x00\x00\x02\x00\x00\x00\x0b\x00\x00\x00listPlayers\x00\x03\x00\x00\x00\x61ll\x00", @@ -51,9 +49,8 @@ class Bfbc2 extends Protocol /** * Use the response flag to figure out what method to run * - * @type array */ - protected $responses = [ + protected array $responses = [ "processVersion", "processDetails", "processPlayers", @@ -61,53 +58,39 @@ class Bfbc2 extends Protocol /** * The transport mode for this protocol is TCP - * - * @type string - */ - protected $transport = self::TRANSPORT_TCP; + */ + protected string $transport = self::TRANSPORT_TCP; /** * The query protocol used to make the call - * - * @type string */ - protected $protocol = 'bfbc2'; + protected string $protocol = 'bfbc2'; /** * String name of this protocol class - * - * @type string */ - protected $name = 'bfbc2'; + protected string $name = 'bfbc2'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Battlefield Bad Company 2"; + protected string $name_long = "Battlefield Bad Company 2"; /** * The client join link - * - * @type string */ - protected $join_link = null; + protected ?string $join_link = null; /** * query_port = client_port + 29321 * 48888 = 19567 + 29321 - * - * @type int */ - protected $port_diff = 29321; + protected int $port_diff = 29321; /** * Normalize settings for this protocol - * - * @type array */ - protected $normalize = [ + protected array $normalize = [ // General 'general' => [ // target => source @@ -131,10 +114,10 @@ class Bfbc2 extends Protocol /** * Process the response for the StarMade server * - * @return array + * @return mixed * @throws \GameQ\Exception\Protocol */ - public function processResponse() + public function processResponse(): mixed { //print_r($this->packets_response); @@ -178,8 +161,7 @@ public function processResponse() /** * Decode the buffer into a usable format - * - * @param \GameQ\Buffer $buffer + * * @return array */ @@ -205,8 +187,7 @@ protected function decode(Buffer $buffer) /** * Process the server details - * - * @param \GameQ\Buffer $buffer + * * @return array */ @@ -261,15 +242,14 @@ protected function processDetails(Buffer $buffer) $result->add('join_queue', (($items[$index_current + 11] == 'true') ? 1 : 0)); $result->add('region', $items[$index_current + 12]); - unset($items, $index_current, $teamCount, $buffer); + unset($items, $index_current, $teamCount); return $result->fetch(); } /** * Process the server version - * - * @param \GameQ\Buffer $buffer + * * @return array */ @@ -290,8 +270,7 @@ protected function processVersion(Buffer $buffer) /** * Process the players - * - * @param \GameQ\Buffer $buffer + * * @return array */ diff --git a/src/GameQ/Protocols/Bfh.php b/src/GameQ/Protocols/Bfh.php index 067d77f9..5e8d47ff 100644 --- a/src/GameQ/Protocols/Bfh.php +++ b/src/GameQ/Protocols/Bfh.php @@ -29,15 +29,11 @@ class Bfh extends Bf4 /** * String name of this protocol class - * - * @type string */ - protected $name = 'bfh'; + protected string $name = 'bfh'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Battlefield Hardline"; + protected string $name_long = "Battlefield Hardline"; } diff --git a/src/GameQ/Protocols/Blackmesa.php b/src/GameQ/Protocols/Blackmesa.php index efaafdfb..903c8d13 100644 --- a/src/GameQ/Protocols/Blackmesa.php +++ b/src/GameQ/Protocols/Blackmesa.php @@ -28,15 +28,11 @@ class Blackmesa extends Source { /** * String name of this protocol class - * - * @type string */ - protected $name = 'blackmesa'; + protected string $name = 'blackmesa'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Black Mesa"; + protected string $name_long = "Black Mesa"; } diff --git a/src/GameQ/Protocols/Brink.php b/src/GameQ/Protocols/Brink.php index 20226525..d1696bba 100644 --- a/src/GameQ/Protocols/Brink.php +++ b/src/GameQ/Protocols/Brink.php @@ -29,22 +29,16 @@ class Brink extends Source { /** * String name of this protocol class - * - * @type string */ - protected $name = 'brink'; + protected string $name = 'brink'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Brink"; + protected string $name_long = "Brink"; /** * query_port = client_port + 1 - * - * @type int */ - protected $port_diff = 1; + protected int $port_diff = 1; } diff --git a/src/GameQ/Protocols/Cfx.php b/src/GameQ/Protocols/Cfx.php index 914b4e32..0faacde9 100644 --- a/src/GameQ/Protocols/Cfx.php +++ b/src/GameQ/Protocols/Cfx.php @@ -42,54 +42,43 @@ class Cfx extends Protocol /** * Array of packets we want to look up. * Each key should correspond to a defined method in this or a parent class - * - * @type array */ - protected $packets = [ + protected array $packets = [ self::PACKET_STATUS => "\xFF\xFF\xFF\xFFgetinfo xxx", ]; /** * Use the response flag to figure out what method to run * - * @type array */ - protected $responses = [ + protected array $responses = [ "\xFF\xFF\xFF\xFFinfoResponse" => "processStatus", ]; /** * The query protocol used to make the call - * - * @type string */ - protected $protocol = 'cfx'; + protected string $protocol = 'cfx'; /** * String name of this protocol class - * - * @type string */ - protected $name = 'cfx'; + protected string $name = 'cfx'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "CitizenFX"; + protected string $name_long = "CitizenFX"; /** - * Holds the Player list so we can overwrite it back + * Holds the player list so we can overwrite it back */ - protected $PlayerList = []; + protected array $playerList = []; /** * Normalize settings for this protocol - * - * @type array */ - protected $normalize = [ + protected array $normalize = [ // General 'general' => [ // target => source @@ -106,7 +95,7 @@ class Cfx extends Protocol /** * Get FiveM players list using a sub query */ - public function beforeSend(Server $server) + public function beforeSend(Server $server): void { $GameQ = new \GameQ\GameQ(); $GameQ->addServer([ @@ -114,16 +103,16 @@ public function beforeSend(Server $server) 'host' => "$server->ip:$server->port_query", ]); $results = $GameQ->process(); - $this->PlayerList = $results[0][0] ?? []; + $this->playerList = $results[0][0] ?? []; } /** * Process the response * - * @return array + * @return mixed * @throws \GameQ\Exception\Protocol */ - public function processResponse() + public function processResponse(): mixed { // In case it comes back as multiple packets (it shouldn't) $buffer = new Buffer(implode('', $this->packets_response)); @@ -147,8 +136,6 @@ public function processResponse() /** * Handle processing the status response * - * @param Buffer $buffer - * * @return array */ protected function processStatus(Buffer $buffer) @@ -157,9 +144,9 @@ protected function processStatus(Buffer $buffer) $result = new Result(); // Lets peek and see if the data starts with a \ - if ($buffer->lookAhead(1) == '\\') { + if ($buffer->lookAhead() === '\\') { // Burn the first one - $buffer->skip(1); + $buffer->skip(); } // Explode the data @@ -182,8 +169,8 @@ protected function processStatus(Buffer $buffer) } // Add result of sub http-protocol if available - if ($this->PlayerList) { - $result->add('players', $this->PlayerList); + if ($this->playerList) { + $result->add('players', $this->playerList); } return $result->fetch(); diff --git a/src/GameQ/Protocols/Cfxplayers.php b/src/GameQ/Protocols/Cfxplayers.php index 353b6850..393e8441 100644 --- a/src/GameQ/Protocols/Cfxplayers.php +++ b/src/GameQ/Protocols/Cfxplayers.php @@ -36,57 +36,34 @@ class Cfxplayers extends Http { - /** - * Holds the real ip so we can overwrite it back - * - * @var string - */ - protected $realIp = null; - - /** - * Holds the real port so we can overwrite it back - * - * @var int - */ - protected $realPortQuery = null; - /** * Packets to send - * - * @var array */ - protected $packets = [ + protected array $packets = [ self::PACKET_STATUS => "GET /players.json HTTP/1.0\r\nAccept: */*\r\n\r\n", // Player List ]; /** * The protocol being used - * - * @var string */ - protected $protocol = 'cfxplayers'; + protected string $protocol = 'cfxplayers'; /** * String name of this protocol class - * - * @var string */ - protected $name = 'cfxplayers'; + protected string $name = 'cfxplayers'; /** * Longer string name of this protocol class - * - * @var string */ - protected $name_long = "cfxplayers"; + protected string $name_long = "cfxplayers"; /** * Process the response * - * @return array * @throws Exception */ - public function processResponse() + public function processResponse(): mixed { // Make sure we have any players if (empty($this->packets_response)) { diff --git a/src/GameQ/Protocols/Citadel.php b/src/GameQ/Protocols/Citadel.php index 3d1074b1..86147720 100644 --- a/src/GameQ/Protocols/Citadel.php +++ b/src/GameQ/Protocols/Citadel.php @@ -28,15 +28,11 @@ class Citadel extends Source { /** * String name of this protocol class - * - * @type string */ - protected $name = 'citadel'; + protected string $name = 'citadel'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Citadel"; + protected string $name_long = "Citadel"; } diff --git a/src/GameQ/Protocols/Cod.php b/src/GameQ/Protocols/Cod.php index 2425ea67..354f5dca 100644 --- a/src/GameQ/Protocols/Cod.php +++ b/src/GameQ/Protocols/Cod.php @@ -29,15 +29,11 @@ class Cod extends Quake3 { /** * String name of this protocol class - * - * @type string */ - protected $name = 'cod'; + protected string $name = 'cod'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Call of Duty"; + protected string $name_long = "Call of Duty"; } diff --git a/src/GameQ/Protocols/Cod2.php b/src/GameQ/Protocols/Cod2.php index 79be7ca2..31d573f3 100644 --- a/src/GameQ/Protocols/Cod2.php +++ b/src/GameQ/Protocols/Cod2.php @@ -28,15 +28,11 @@ class Cod2 extends Quake3 { /** * String name of this protocol class - * - * @type string */ - protected $name = 'cod2'; + protected string $name = 'cod2'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Call of Duty 2"; + protected string $name_long = "Call of Duty 2"; } diff --git a/src/GameQ/Protocols/Cod4.php b/src/GameQ/Protocols/Cod4.php index 9838d9cb..95cc47e9 100644 --- a/src/GameQ/Protocols/Cod4.php +++ b/src/GameQ/Protocols/Cod4.php @@ -28,15 +28,11 @@ class Cod4 extends Quake3 { /** * String name of this protocol class - * - * @type string */ - protected $name = 'cod4'; + protected string $name = 'cod4'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Call of Duty 4"; + protected string $name_long = "Call of Duty 4"; } diff --git a/src/GameQ/Protocols/Codmw2.php b/src/GameQ/Protocols/Codmw2.php index 066e1f3a..abf1c89b 100644 --- a/src/GameQ/Protocols/Codmw2.php +++ b/src/GameQ/Protocols/Codmw2.php @@ -31,17 +31,13 @@ class Codmw2 extends Quake3 { /** * String name of this protocol class - * - * @type string */ - protected $name = 'codmw2'; + protected string $name = 'codmw2'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Call of Duty: Modern Warfare 2"; + protected string $name_long = "Call of Duty: Modern Warfare 2"; protected function processPlayers(Buffer $buffer) { @@ -60,7 +56,7 @@ protected function processPlayers(Buffer $buffer) ]; // Skip first " - $playerInfo->skip(1); + $playerInfo->skip(); // Add player name, encoded $player['name'] = $this->convertToUtf8(trim(($playerInfo->readString('"')))); diff --git a/src/GameQ/Protocols/Codmw3.php b/src/GameQ/Protocols/Codmw3.php index 1049b602..603cac1c 100644 --- a/src/GameQ/Protocols/Codmw3.php +++ b/src/GameQ/Protocols/Codmw3.php @@ -29,22 +29,16 @@ class Codmw3 extends Source /** * String name of this protocol class - * - * @type string */ - protected $name = 'codmw3'; + protected string $name = 'codmw3'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Call of Duty: Modern Warfare 3"; + protected string $name_long = "Call of Duty: Modern Warfare 3"; /** * query_port = client_port + 2 - * - * @type int */ - protected $port_diff = 2; + protected int $port_diff = 2; } diff --git a/src/GameQ/Protocols/Coduo.php b/src/GameQ/Protocols/Coduo.php index 2dd9a182..41368a40 100644 --- a/src/GameQ/Protocols/Coduo.php +++ b/src/GameQ/Protocols/Coduo.php @@ -29,15 +29,11 @@ class Coduo extends Quake3 { /** * String name of this protocol class - * - * @type string */ - protected $name = 'coduo'; + protected string $name = 'coduo'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Call of Duty: United Offensive"; + protected string $name_long = "Call of Duty: United Offensive"; } diff --git a/src/GameQ/Protocols/Codwaw.php b/src/GameQ/Protocols/Codwaw.php index f730678e..05f1c899 100644 --- a/src/GameQ/Protocols/Codwaw.php +++ b/src/GameQ/Protocols/Codwaw.php @@ -29,15 +29,11 @@ class Codwaw extends Quake3 { /** * String name of this protocol class - * - * @type string */ - protected $name = 'codwaw'; + protected string $name = 'codwaw'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Call of Duty: World at War"; + protected string $name_long = "Call of Duty: World at War"; } diff --git a/src/GameQ/Protocols/Conanexiles.php b/src/GameQ/Protocols/Conanexiles.php index a097e1d8..a5f8a274 100644 --- a/src/GameQ/Protocols/Conanexiles.php +++ b/src/GameQ/Protocols/Conanexiles.php @@ -28,15 +28,11 @@ class Conanexiles extends Source { /** * String name of this protocol class - * - * @type string */ - protected $name = 'conanexiles'; + protected string $name = 'conanexiles'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Conan Exiles"; + protected string $name_long = "Conan Exiles"; } diff --git a/src/GameQ/Protocols/Contagion.php b/src/GameQ/Protocols/Contagion.php index 64d0b76e..d8873956 100644 --- a/src/GameQ/Protocols/Contagion.php +++ b/src/GameQ/Protocols/Contagion.php @@ -29,14 +29,10 @@ class Contagion extends Source { /** * String name of this protocol class - * - * @type string */ - protected $name = 'contagion'; + protected string $name = 'contagion'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Contagion"; + protected string $name_long = "Contagion"; } diff --git a/src/GameQ/Protocols/Crysis.php b/src/GameQ/Protocols/Crysis.php index e09a673d..b380c61e 100644 --- a/src/GameQ/Protocols/Crysis.php +++ b/src/GameQ/Protocols/Crysis.php @@ -29,15 +29,11 @@ class Crysis extends Gamespy3 { /** * String name of this protocol class - * - * @type string */ - protected $name = 'crysis'; + protected string $name = 'crysis'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Crysis"; + protected string $name_long = "Crysis"; } diff --git a/src/GameQ/Protocols/Crysis2.php b/src/GameQ/Protocols/Crysis2.php index 75c6614a..03c383f3 100644 --- a/src/GameQ/Protocols/Crysis2.php +++ b/src/GameQ/Protocols/Crysis2.php @@ -29,15 +29,11 @@ class Crysis2 extends Gamespy3 { /** * String name of this protocol class - * - * @type string */ - protected $name = 'crysis2'; + protected string $name = 'crysis2'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Crysis 2"; + protected string $name_long = "Crysis 2"; } diff --git a/src/GameQ/Protocols/Crysiswars.php b/src/GameQ/Protocols/Crysiswars.php index 44dcdcf1..756efacd 100644 --- a/src/GameQ/Protocols/Crysiswars.php +++ b/src/GameQ/Protocols/Crysiswars.php @@ -29,15 +29,11 @@ class Crysiswars extends Gamespy3 { /** * String name of this protocol class - * - * @type string */ - protected $name = 'crysiswars'; + protected string $name = 'crysiswars'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Crysis Wars"; + protected string $name_long = "Crysis Wars"; } diff --git a/src/GameQ/Protocols/Cs15.php b/src/GameQ/Protocols/Cs15.php index ba375240..8769b456 100644 --- a/src/GameQ/Protocols/Cs15.php +++ b/src/GameQ/Protocols/Cs15.php @@ -31,15 +31,11 @@ class Cs15 extends Won /** * String name of this protocol class - * - * @type string */ - protected $name = 'cs15'; + protected string $name = 'cs15'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Counter-Strike 1.5"; + protected string $name_long = "Counter-Strike 1.5"; } diff --git a/src/GameQ/Protocols/Cs16.php b/src/GameQ/Protocols/Cs16.php index 25a66029..806b348a 100644 --- a/src/GameQ/Protocols/Cs16.php +++ b/src/GameQ/Protocols/Cs16.php @@ -29,17 +29,13 @@ class Cs16 extends Source /** * String name of this protocol class - * - * @type string */ - protected $name = 'cs16'; + protected string $name = 'cs16'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Counter-Strike 1.6"; + protected string $name_long = "Counter-Strike 1.6"; /** * In the case of cs 1.6 we offload split packets here because the split packet response for rules is in diff --git a/src/GameQ/Protocols/Cs2d.php b/src/GameQ/Protocols/Cs2d.php index ed923257..3fa9f147 100644 --- a/src/GameQ/Protocols/Cs2d.php +++ b/src/GameQ/Protocols/Cs2d.php @@ -36,10 +36,8 @@ class Cs2d extends Protocol /** * Array of packets we want to query. - * - * @type array */ - protected $packets = [ + protected array $packets = [ self::PACKET_STATUS => "\x01\x00\xFB\x01", //self::PACKET_STATUS => "\x01\x00\x03\x10\x21\xFB\x01\x75\x00", self::PACKET_PLAYERS => "\x01\x00\xFB\x05", @@ -48,47 +46,36 @@ class Cs2d extends Protocol /** * Use the response flag to figure out what method to run * - * @type array */ - protected $responses = [ + protected array $responses = [ "\x01\x00\xFB\x01" => "processDetails", "\x01\x00\xFB\x05" => "processPlayers", ]; /** * The query protocol used to make the call - * - * @type string */ - protected $protocol = 'cs2d'; + protected string $protocol = 'cs2d'; /** * String name of this protocol class - * - * @type string */ - protected $name = 'cs2d'; + protected string $name = 'cs2d'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Counter-Strike 2d"; + protected string $name_long = "Counter-Strike 2d"; /** * The client join link - * - * @type string */ - protected $join_link = "cs2d://%s:%d/"; + protected ?string $join_link = "cs2d://%s:%d/"; /** * Normalize settings for this protocol - * - * @type array */ - protected $normalize = [ + protected array $normalize = [ // General 'general' => [ // target => source @@ -112,10 +99,10 @@ class Cs2d extends Protocol /** * Process the response for the Tibia server * - * @return array + * @return mixed * @throws \GameQ\Exception\Protocol */ - public function processResponse() + public function processResponse(): mixed { // We have a merged packet, try to split it back up @@ -178,8 +165,6 @@ public function processResponse() /** * Handles processing the details data into a usable format * - * @param Buffer $buffer - * * @return array * @throws Exception */ @@ -200,8 +185,8 @@ protected function processDetails(Buffer $buffer) $result->add('lua_scripts', (int)$this->readFlag($serverFlags, 6)); // Read the rest of the buffer data - $result->add('servername', $this->convertToUtf8($buffer->readPascalString(0))); - $result->add('mapname', $this->convertToUtf8($buffer->readPascalString(0))); + $result->add('servername', $this->convertToUtf8($buffer->readPascalString())); + $result->add('mapname', $this->convertToUtf8($buffer->readPascalString())); $result->add('num_players', $buffer->readInt8()); $result->add('max_players', $buffer->readInt8()); $result->add('game_mode', $buffer->readInt8()); @@ -214,8 +199,6 @@ protected function processDetails(Buffer $buffer) /** * Handles processing the player data into a usable format * - * @param Buffer $buffer - * * @return array * @throws Exception */ @@ -234,7 +217,7 @@ protected function processPlayers(Buffer $buffer) if (($id = $buffer->readInt8()) !== 0) { // Add the results $result->addPlayer('id', $id); - $result->addPlayer('name', $this->convertToUtf8($buffer->readPascalString(0))); + $result->addPlayer('name', $this->convertToUtf8($buffer->readPascalString())); $result->addPlayer('team', $buffer->readInt8()); $result->addPlayer('score', $buffer->readInt32()); $result->addPlayer('deaths', $buffer->readInt32()); @@ -256,6 +239,6 @@ protected function processPlayers(Buffer $buffer) */ protected function readFlag($flags, $offset) { - return !!($flags & (1 << $offset)); + return (bool)($flags & (1 << $offset)); } } diff --git a/src/GameQ/Protocols/Cscz.php b/src/GameQ/Protocols/Cscz.php index b539128f..e3de7037 100644 --- a/src/GameQ/Protocols/Cscz.php +++ b/src/GameQ/Protocols/Cscz.php @@ -31,15 +31,11 @@ class Cscz extends Cs16 /** * String name of this protocol class - * - * @type string */ - protected $name = 'cscz'; + protected string $name = 'cscz'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Counter-Strike: Condition Zero"; + protected string $name_long = "Counter-Strike: Condition Zero"; } diff --git a/src/GameQ/Protocols/Csgo.php b/src/GameQ/Protocols/Csgo.php index 41af7352..ea37ddae 100644 --- a/src/GameQ/Protocols/Csgo.php +++ b/src/GameQ/Protocols/Csgo.php @@ -29,15 +29,11 @@ class Csgo extends Source /** * String name of this protocol class - * - * @type string */ - protected $name = 'csgo'; + protected string $name = 'csgo'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Counter-Strike: Global Offensive"; + protected string $name_long = "Counter-Strike: Global Offensive"; } diff --git a/src/GameQ/Protocols/Css.php b/src/GameQ/Protocols/Css.php index be75da3d..1e82cc9e 100644 --- a/src/GameQ/Protocols/Css.php +++ b/src/GameQ/Protocols/Css.php @@ -28,15 +28,11 @@ class Css extends Source { /** * String name of this protocol class - * - * @type string */ - protected $name = 'css'; + protected string $name = 'css'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Counter-Strike: Source"; + protected string $name_long = "Counter-Strike: Source"; } diff --git a/src/GameQ/Protocols/Dal.php b/src/GameQ/Protocols/Dal.php index 6b05037d..4e518b65 100644 --- a/src/GameQ/Protocols/Dal.php +++ b/src/GameQ/Protocols/Dal.php @@ -29,15 +29,11 @@ class Dal extends Arkse /** * String name of this protocol class - * - * @type string */ - protected $name = 'dal'; + protected string $name = 'dal'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Dark and Light"; + protected string $name_long = "Dark and Light"; } diff --git a/src/GameQ/Protocols/Dayz.php b/src/GameQ/Protocols/Dayz.php index 01c7c28d..3cff46bd 100644 --- a/src/GameQ/Protocols/Dayz.php +++ b/src/GameQ/Protocols/Dayz.php @@ -29,26 +29,18 @@ class Dayz extends Source /** * String name of this protocol class - * - * @type string */ - protected $name = 'dayz'; + protected string $name = 'dayz'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "DayZ Standalone"; + protected string $name_long = "DayZ Standalone"; /** * Overload the math used to guess at the Query Port - * - * @param int $clientPort - * - * @return int */ - public function findQueryPort($clientPort) + public function findQueryPort(int $clientPort): int { /* diff --git a/src/GameQ/Protocols/Dayzmod.php b/src/GameQ/Protocols/Dayzmod.php index 2ce1076d..07be900e 100644 --- a/src/GameQ/Protocols/Dayzmod.php +++ b/src/GameQ/Protocols/Dayzmod.php @@ -30,15 +30,11 @@ class Dayzmod extends Armedassault2oa /** * String name of this protocol class - * - * @type string */ - protected $name = 'dayzmod'; + protected string $name = 'dayzmod'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "DayZ Mod"; + protected string $name_long = "DayZ Mod"; } diff --git a/src/GameQ/Protocols/Dod.php b/src/GameQ/Protocols/Dod.php index 0c7baf69..d99287e2 100644 --- a/src/GameQ/Protocols/Dod.php +++ b/src/GameQ/Protocols/Dod.php @@ -31,15 +31,11 @@ class Dod extends Cs16 /** * String name of this protocol class - * - * @type string */ - protected $name = 'dod'; + protected string $name = 'dod'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Day of Defeat"; + protected string $name_long = "Day of Defeat"; } diff --git a/src/GameQ/Protocols/Dods.php b/src/GameQ/Protocols/Dods.php index 898d75b9..dcc3380a 100644 --- a/src/GameQ/Protocols/Dods.php +++ b/src/GameQ/Protocols/Dods.php @@ -28,15 +28,11 @@ class Dods extends Source { /** * String name of this protocol class - * - * @type string */ - protected $name = 'dods'; + protected string $name = 'dods'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Day of Defeat: Source"; + protected string $name_long = "Day of Defeat: Source"; } diff --git a/src/GameQ/Protocols/Doom3.php b/src/GameQ/Protocols/Doom3.php index 15afee8e..cbf8c489 100644 --- a/src/GameQ/Protocols/Doom3.php +++ b/src/GameQ/Protocols/Doom3.php @@ -36,56 +36,43 @@ class Doom3 extends Protocol /** * Array of packets we want to look up. * Each key should correspond to a defined method in this or a parent class - * - * @type array */ - protected $packets = [ + protected array $packets = [ self::PACKET_ALL => "\xFF\xFFgetInfo\x00PiNGPoNG\x00", ]; /** * Use the response flag to figure out what method to run * - * @type array */ - protected $responses = [ + protected array $responses = [ "\xFF\xFFinfoResponse" => 'processStatus', ]; /** * The query protocol used to make the call - * - * @type string */ - protected $protocol = 'doom3'; + protected string $protocol = 'doom3'; /** * String name of this protocol class - * - * @type string */ - protected $name = 'doom3'; + protected string $name = 'doom3'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Doom 3"; + protected string $name_long = "Doom 3"; /** * The client join link - * - * @type string */ - protected $join_link = null; + protected ?string $join_link = null; /** * Normalize settings for this protocol - * - * @type array */ - protected $normalize = [ + protected array $normalize = [ // General 'general' => [ // target => source @@ -109,7 +96,7 @@ class Doom3 extends Protocol * @return mixed * @throws Exception */ - public function processResponse() + public function processResponse(): mixed { // Make a buffer $buffer = new Buffer(implode('', $this->packets_response)); @@ -129,8 +116,6 @@ public function processResponse() /** * Process the status response * - * @param Buffer $buffer - * * @return array */ protected function processStatus(Buffer $buffer) @@ -147,8 +132,6 @@ protected function processStatus(Buffer $buffer) /** * Handle processing the server information * - * @param Buffer $buffer - * * @return array */ protected function processServerInfo(Buffer $buffer) @@ -177,8 +160,6 @@ protected function processServerInfo(Buffer $buffer) /** * Handle processing of player data * - * @param Buffer $buffer - * * @return array */ protected function processPlayers(Buffer $buffer) diff --git a/src/GameQ/Protocols/Dow.php b/src/GameQ/Protocols/Dow.php index 548f49fa..6c28b6c0 100644 --- a/src/GameQ/Protocols/Dow.php +++ b/src/GameQ/Protocols/Dow.php @@ -30,24 +30,18 @@ class Dow extends Source { /** * String name of this protocol class - * - * @type string */ - protected $name = 'dow'; + protected string $name = 'dow'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Days of War"; + protected string $name_long = "Days of War"; /** * Normalize main fields - * - * @var array */ - protected $normalize = [ + protected array $normalize = [ // General 'general' => [ // target => source diff --git a/src/GameQ/Protocols/Eco.php b/src/GameQ/Protocols/Eco.php index a2292e90..0ccf4eb3 100644 --- a/src/GameQ/Protocols/Eco.php +++ b/src/GameQ/Protocols/Eco.php @@ -33,51 +33,43 @@ class Eco extends Http * * @var array */ - protected $packets = [ + protected array $packets = [ self::PACKET_STATUS => "GET /frontpage HTTP/1.0\r\nAccept: */*\r\n\r\n", ]; /** * Http protocol is SSL * - * @var string */ - protected $transport = self::TRANSPORT_TCP; + protected string $transport = self::TRANSPORT_TCP; /** * The protocol being used * - * @var string */ - protected $protocol = 'eco'; + protected string $protocol = 'eco'; /** * String name of this protocol class * - * @var string */ - protected $name = 'eco'; + protected string $name = 'eco'; /** * Longer string name of this protocol class * - * @var string */ - protected $name_long = "ECO Global Survival"; + protected string $name_long = "ECO Global Survival"; /** * query_port = client_port + 1 - * - * @type int */ - protected $port_diff = 1; + protected int $port_diff = 1; /** * Normalize some items - * - * @var array */ - protected $normalize = [ + protected array $normalize = [ // General 'general' => [ // target => source @@ -92,10 +84,10 @@ class Eco extends Http /** * Process the response * - * @return array + * @return mixed * @throws Exception */ - public function processResponse() + public function processResponse(): mixed { if (empty($this->packets_response)) { return []; diff --git a/src/GameQ/Protocols/Egs.php b/src/GameQ/Protocols/Egs.php index aab79aea..d7b6c60d 100644 --- a/src/GameQ/Protocols/Egs.php +++ b/src/GameQ/Protocols/Egs.php @@ -30,22 +30,16 @@ class Egs extends Source /** * String name of this protocol class - * - * @type string */ - protected $name = 'egs'; + protected string $name = 'egs'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Empyrion - Galactic Survival"; + protected string $name_long = "Empyrion - Galactic Survival"; /** * query_port = client_port + 1 - * - * @type int */ - protected $port_diff = 1; + protected int $port_diff = 1; } diff --git a/src/GameQ/Protocols/Et.php b/src/GameQ/Protocols/Et.php index 63b5beb7..7a3c208d 100644 --- a/src/GameQ/Protocols/Et.php +++ b/src/GameQ/Protocols/Et.php @@ -29,15 +29,11 @@ class Et extends Quake3 { /** * String name of this protocol class - * - * @type string */ - protected $name = 'et'; + protected string $name = 'et'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Wolfenstein Enemy Territory"; + protected string $name_long = "Wolfenstein Enemy Territory"; } diff --git a/src/GameQ/Protocols/Etqw.php b/src/GameQ/Protocols/Etqw.php index 88cfe38a..bdd2e151 100644 --- a/src/GameQ/Protocols/Etqw.php +++ b/src/GameQ/Protocols/Etqw.php @@ -34,10 +34,8 @@ class Etqw extends Protocol /** * Array of packets we want to look up. * Each key should correspond to a defined method in this or a parent class - * - * @type array */ - protected $packets = [ + protected array $packets = [ self::PACKET_STATUS => "\xFF\xFFgetInfoEx\x00\x00\x00\x00", //self::PACKET_STATUS => "\xFF\xFFgetInfo\x00\x00\x00\x00\x00", ]; @@ -45,39 +43,30 @@ class Etqw extends Protocol /** * Use the response flag to figure out what method to run * - * @type array */ - protected $responses = [ + protected array $responses = [ "\xFF\xFFinfoExResponse" => "processStatus", ]; /** * The query protocol used to make the call - * - * @type string */ - protected $protocol = 'etqw'; + protected string $protocol = 'etqw'; /** * String name of this protocol class - * - * @type string */ - protected $name = 'etqw'; + protected string $name = 'etqw'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Enemy Territory Quake Wars"; + protected string $name_long = "Enemy Territory Quake Wars"; /** * Normalize settings for this protocol - * - * @type array */ - protected $normalize = [ + protected array $normalize = [ // General 'general' => [ // target => source @@ -100,10 +89,10 @@ class Etqw extends Protocol /** * Process the response * - * @return array + * @return mixed * @throws \GameQ\Exception\Protocol */ - public function processResponse() + public function processResponse(): mixed { // In case it comes back as multiple packets (it shouldn't) $buffer = new Buffer(implode('', $this->packets_response)); @@ -127,8 +116,6 @@ public function processResponse() /** * Handle processing the status response * - * @param Buffer $buffer - * * @return array */ protected function processStatus(Buffer $buffer) @@ -179,9 +166,6 @@ protected function processStatus(Buffer $buffer) /** * Parse players out of the status ex response - * - * @param Buffer $buffer - * @param Result $result */ protected function parsePlayers(Buffer $buffer, Result $result) { @@ -189,7 +173,7 @@ protected function parsePlayers(Buffer $buffer, Result $result) $players = 0; // Iterate over the players until we run out - while (($id = $buffer->readInt8()) != 32) { + while (($id = $buffer->readInt8()) !== 32) { $result->addPlayer('id', $id); $result->addPlayer('ping', $buffer->readInt16()); $result->addPlayer('name', $buffer->readString()); @@ -208,9 +192,6 @@ protected function parsePlayers(Buffer $buffer, Result $result) /** * Handle parsing extra player data - * - * @param Buffer $buffer - * @param Result $result */ protected function parsePlayersExtra(Buffer $buffer, Result $result) { diff --git a/src/GameQ/Protocols/Ffe.php b/src/GameQ/Protocols/Ffe.php index c0947bdc..f91d3dd7 100644 --- a/src/GameQ/Protocols/Ffe.php +++ b/src/GameQ/Protocols/Ffe.php @@ -29,15 +29,11 @@ class Ffe extends Source /** * String name of this protocol class - * - * @type string */ - protected $name = 'ffe'; + protected string $name = 'ffe'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Fortress Forever"; + protected string $name_long = "Fortress Forever"; } diff --git a/src/GameQ/Protocols/Ffow.php b/src/GameQ/Protocols/Ffow.php index 530b66f4..9dee3299 100644 --- a/src/GameQ/Protocols/Ffow.php +++ b/src/GameQ/Protocols/Ffow.php @@ -23,10 +23,8 @@ class Ffow extends Protocol /** * Array of packets we want to look up. * Each key should correspond to a defined method in this or a parent class - * - * @type array */ - protected $packets = [ + protected array $packets = [ self::PACKET_CHALLENGE => "\xFF\xFF\xFF\xFF\x57", self::PACKET_RULES => "\xFF\xFF\xFF\xFF\x56%s", self::PACKET_PLAYERS => "\xFF\xFF\xFF\xFF\x55%s", @@ -36,9 +34,8 @@ class Ffow extends Protocol /** * Use the response flag to figure out what method to run * - * @type array */ - protected $responses = [ + protected array $responses = [ "\xFF\xFF\xFF\xFF\x49\x02" => 'processInfo', // I "\xFF\xFF\xFF\xFF\x45\x00" => 'processRules', // E "\xFF\xFF\xFF\xFF\x44\x00" => 'processPlayers', // D @@ -46,45 +43,33 @@ class Ffow extends Protocol /** * The query protocol used to make the call - * - * @type string */ - protected $protocol = 'ffow'; + protected string $protocol = 'ffow'; /** * String name of this protocol class - * - * @type string */ - protected $name = 'ffow'; + protected string $name = 'ffow'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Frontlines Fuel of War"; + protected string $name_long = "Frontlines Fuel of War"; /** * The client join link - * - * @type string */ - protected $join_link = null; + protected ?string $join_link = null; /** * query_port = client_port + 2 - * - * @type int */ - protected $port_diff = 2; + protected int $port_diff = 2; /** * Normalize settings for this protocol - * - * @type array */ - protected $normalize = [ + protected array $normalize = [ // General 'general' => [ // target => source @@ -107,12 +92,9 @@ class Ffow extends Protocol /** * Parse the challenge response and apply it to all the packet types * - * @param \GameQ\Buffer $challenge_buffer - * - * @return bool * @throws \GameQ\Exception\Protocol */ - public function challengeParseAndApply(Buffer $challenge_buffer) + public function challengeParseAndApply(Buffer $challenge_buffer): bool { // Burn padding $challenge_buffer->skip(5); @@ -127,7 +109,7 @@ public function challengeParseAndApply(Buffer $challenge_buffer) * @return mixed * @throws Exception */ - public function processResponse() + public function processResponse(): mixed { // Init results $results = []; @@ -158,8 +140,6 @@ public function processResponse() /** * Handle processing the server information * - * @param Buffer $buffer - * * @return array */ protected function processInfo(Buffer $buffer) @@ -191,8 +171,6 @@ protected function processInfo(Buffer $buffer) /** * Handle processing the server rules * - * @param Buffer $buffer - * * @return array */ protected function processRules(Buffer $buffer) @@ -201,7 +179,7 @@ protected function processRules(Buffer $buffer) $result = new Result(); // Burn extra header - $buffer->skip(1); + $buffer->skip(); // Read rules until we run out of buffer while ($buffer->getLength()) { @@ -223,8 +201,6 @@ protected function processRules(Buffer $buffer) * * @todo: Build this out when there is a server with players to test against * - * @param Buffer $buffer - * * @return array */ protected function processPlayers(Buffer $buffer) diff --git a/src/GameQ/Protocols/Fof.php b/src/GameQ/Protocols/Fof.php index a35c4c0a..ca844146 100644 --- a/src/GameQ/Protocols/Fof.php +++ b/src/GameQ/Protocols/Fof.php @@ -29,15 +29,11 @@ class Fof extends Source { /** * String name of this protocol class - * - * @type string */ - protected $name = 'fof'; + protected string $name = 'fof'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Fistful of Frags"; + protected string $name_long = "Fistful of Frags"; } diff --git a/src/GameQ/Protocols/Gamespy.php b/src/GameQ/Protocols/Gamespy.php index 3aa828dc..9c224f42 100644 --- a/src/GameQ/Protocols/Gamespy.php +++ b/src/GameQ/Protocols/Gamespy.php @@ -34,48 +34,37 @@ class Gamespy extends Protocol /** * Array of packets we want to look up. * Each key should correspond to a defined method in this or a parent class - * - * @type array */ - protected $packets = [ + protected array $packets = [ self::PACKET_STATUS => "\x5C\x73\x74\x61\x74\x75\x73\x5C", ]; /** * The query protocol used to make the call - * - * @type string */ - protected $protocol = 'gamespy'; + protected string $protocol = 'gamespy'; /** * String name of this protocol class - * - * @type string */ - protected $name = 'gamespy'; + protected string $name = 'gamespy'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "GameSpy Server"; + protected string $name_long = "GameSpy Server"; /** * The client join link - * - * @type string */ - protected $join_link = null; + protected ?string $join_link = null; /** * Process the response for this protocol * - * @return array * @throws Exception */ - public function processResponse() + public function processResponse(): mixed { // Holds the processed packets so we can sort them in case they come in an unordered $processed = []; @@ -84,13 +73,13 @@ public function processResponse() foreach ($this->packets_response as $response) { // Check to see if we had a preg_match error if (($match = preg_match("#^(.*)\\\\queryid\\\\([^\\\\]+)(\\\\|$)#", $response, $matches)) === false - || $match != 1 + || $match !== 1 ) { throw new Exception(__METHOD__ . " An error occurred while parsing the packets for 'queryid'"); } // Multiply so we move the decimal point out of the way, if there is one - $key = (int)(floatval($matches[2]) * 1000); + $key = (int)((float)$matches[2] * 1000); // Add this packet to the processed $processed[$key] = $matches[1]; @@ -110,8 +99,6 @@ public function processResponse() /** * Handle processing the status buffer * - * @param Buffer $buffer - * * @return array */ protected function processStatus(Buffer $buffer) @@ -123,9 +110,9 @@ protected function processStatus(Buffer $buffer) $result->add('dedicated', 1); // Lets peek and see if the data starts with a \ - if ($buffer->lookAhead(1) == '\\') { + if ($buffer->lookAhead() === '\\') { // Burn the first one - $buffer->skip(1); + $buffer->skip(); } // Explode the data @@ -148,12 +135,12 @@ protected function processStatus(Buffer $buffer) // Check for _ variable (i.e players) if (($suffix = strrpos($key, '_')) !== false && is_numeric(substr($key, $suffix + 1))) { // See if this is a team designation - if (substr($key, 0, $suffix) == 'teamname') { + if (str_starts_with($key, 'teamname')) { $result->addTeam('teamname', $val); $numTeams++; } else { // Its a player - if (substr($key, 0, $suffix) == 'playername') { + if (str_starts_with($key, 'playername')) { $numPlayers++; } $result->addPlayer(substr($key, 0, $suffix), $this->convertToUtf8($val)); diff --git a/src/GameQ/Protocols/Gamespy2.php b/src/GameQ/Protocols/Gamespy2.php index 77db324b..ab4f3c4b 100644 --- a/src/GameQ/Protocols/Gamespy2.php +++ b/src/GameQ/Protocols/Gamespy2.php @@ -37,18 +37,14 @@ class Gamespy2 extends Protocol /** * Define the state of this class - * - * @type int */ - protected $state = self::STATE_BETA; + protected int $state = self::STATE_BETA; /** * Array of packets we want to look up. * Each key should correspond to a defined method in this or a parent class - * - * @type array */ - protected $packets = [ + protected array $packets = [ self::PACKET_DETAILS => "\xFE\xFD\x00\x43\x4F\x52\x59\xFF\x00\x00", self::PACKET_PLAYERS => "\xFE\xFD\x00\x43\x4F\x52\x58\x00\xFF\xFF", ]; @@ -56,47 +52,36 @@ class Gamespy2 extends Protocol /** * Use the response flag to figure out what method to run * - * @type array */ - protected $responses = [ + protected array $responses = [ "\x00\x43\x4F\x52\x59" => "processDetails", "\x00\x43\x4F\x52\x58" => "processPlayers", ]; /** * The query protocol used to make the call - * - * @type string */ - protected $protocol = 'gamespy2'; + protected string $protocol = 'gamespy2'; /** * String name of this protocol class - * - * @type string */ - protected $name = 'gamespy2'; + protected string $name = 'gamespy2'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "GameSpy2 Server"; + protected string $name_long = "GameSpy2 Server"; /** * The client join link - * - * @type string */ - protected $join_link = null; + protected ?string $join_link = null; /** * Normalize settings for this protocol - * - * @type array */ - protected $normalize = [ + protected array $normalize = [ // General 'general' => [ // target => source @@ -115,10 +100,10 @@ class Gamespy2 extends Protocol /** * Process the response * - * @return array + * @return mixed * @throws Exception */ - public function processResponse() + public function processResponse(): mixed { // Will hold the packets after sorting @@ -164,8 +149,7 @@ public function processResponse() /** * Handles processing the details data into a usable format - * - * @param \GameQ\Buffer $buffer + * * @return array * @throws Exception @@ -179,7 +163,7 @@ protected function processDetails(Buffer $buffer) // We go until we hit an empty key while ($buffer->getLength()) { $key = $buffer->readString(); - if (strlen($key) == 0) { + if ($key === '') { break; } $result->add($key, $this->convertToUtf8($buffer->readString())); @@ -190,8 +174,7 @@ protected function processDetails(Buffer $buffer) /** * Handles processing the players data into a usable format - * - * @param \GameQ\Buffer $buffer + * * @return array * @throws Exception @@ -203,7 +186,7 @@ protected function processPlayers(Buffer $buffer) $result = new Result(); // Skip the header - $buffer->skip(1); + $buffer->skip(); // Players are first $this->parsePlayerTeam('players', $buffer, $result); @@ -217,13 +200,9 @@ protected function processPlayers(Buffer $buffer) /** * Parse the player/team info returned from the player call * - * @param string $dataType - * @param \GameQ\Buffer $buffer - * @param \GameQ\Result $result - * * @throws Exception */ - protected function parsePlayerTeam($dataType, Buffer $buffer, Result $result) + protected function parsePlayerTeam(string $dataType, Buffer $buffer, Result $result) { // Do count diff --git a/src/GameQ/Protocols/Gamespy3.php b/src/GameQ/Protocols/Gamespy3.php index 997a3c33..64243d6a 100644 --- a/src/GameQ/Protocols/Gamespy3.php +++ b/src/GameQ/Protocols/Gamespy3.php @@ -37,62 +37,45 @@ class Gamespy3 extends Protocol /** * Array of packets we want to look up. * Each key should correspond to a defined method in this or a parent class - * - * @type array */ - protected $packets = [ + protected array $packets = [ self::PACKET_CHALLENGE => "\xFE\xFD\x09\x10\x20\x30\x40", self::PACKET_ALL => "\xFE\xFD\x00\x10\x20\x30\x40%s\xFF\xFF\xFF\x01", ]; /** * The query protocol used to make the call - * - * @type string */ - protected $protocol = 'gamespy3'; + protected string $protocol = 'gamespy3'; /** * String name of this protocol class - * - * @type string */ - protected $name = 'gamespy3'; + protected string $name = 'gamespy3'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "GameSpy3 Server"; + protected string $name_long = "GameSpy3 Server"; /** * The client join link - * - * @type string */ - protected $join_link = null; + protected ?string $join_link = null; /** * This defines the split between the server info and player/team info. * This value can vary by game. This value is the default split. - * - * @var string */ - protected $packetSplit = "/\\x00\\x00\\x01/m"; + protected string $packetsplit = "/\\x00\\x00\\x01/m"; /** * Parse the challenge response and apply it to all the packet types - * - * @param \GameQ\Buffer $challenge_buffer - * - * @return bool - * @throws \GameQ\Exception\Protocol */ - public function challengeParseAndApply(Buffer $challenge_buffer) + public function challengeParseAndApply(Buffer $challenge_buffer): bool { // Pull out the challenge - $challenge = substr(preg_replace("/[^0-9\-]/si", "", $challenge_buffer->getBuffer()), 1); + $challenge = substr(preg_replace("/[^0-9\-]/i", "", $challenge_buffer->getBuffer()), 1); // By default, no challenge result (see #197) $challenge_result = ''; @@ -116,10 +99,8 @@ public function challengeParseAndApply(Buffer $challenge_buffer) /** * Process the response - * - * @return array */ - public function processResponse() + public function processResponse(): mixed { // Holds the processed packets @@ -143,7 +124,7 @@ public function processResponse() $id = $buffer->readInt8(); // Burn next byte not sure what it is used for - $buffer->skip(1); + $buffer->skip(); // Add this packet to the processed $processed[$id] = $buffer->getBuffer(); @@ -158,7 +139,7 @@ public function processResponse() $packets = $this->cleanPackets(array_values($processed)); // Split the packets by type general and the rest (i.e. players & teams) - $split = preg_split($this->packetSplit, implode('', $packets)); + $split = preg_split($this->packetsplit, implode('', $packets)); // Create a new result $result = new Result(); @@ -186,12 +167,8 @@ public function processResponse() /** * Handles cleaning up packets since the responses can be a bit "dirty" - * - * @param array $packets - * - * @return array */ - protected function cleanPackets(array $packets = []) + protected function cleanPackets(array $packets = []): array { // Get the number of packets @@ -224,7 +201,7 @@ protected function cleanPackets(array $packets = []) $prefix = $buffer->readString(); // Check to see if the return before has the same prefix present - if ($prefix !== null && str_contains($packets[($x - 1)], $prefix) + if (str_contains($packets[($x - 1)], $prefix) ) { // Update the return by removing the prefix plus 2 chars $packets[$x] = substr(str_replace($prefix, '', $packets[$x]), 2); @@ -241,17 +218,13 @@ protected function cleanPackets(array $packets = []) /** * Handles processing the details data into a usable format - * - * @param \GameQ\Buffer $buffer - * @param \GameQ\Result $result */ - protected function processDetails(Buffer &$buffer, Result &$result) + protected function processDetails(Buffer $buffer, Result $result): void { - // We go until we hit an empty key while ($buffer->getLength()) { $key = $buffer->readString(); - if (strlen($key) == 0) { + if ($key === '') { break; } $result->add($key, $this->convertToUtf8($buffer->readString())); @@ -260,13 +233,9 @@ protected function processDetails(Buffer &$buffer, Result &$result) /** * Handles processing the player and team data into a usable format - * - * @param \GameQ\Buffer $buffer - * @param \GameQ\Result $result */ - protected function processPlayersAndTeams(Buffer &$buffer, Result &$result) + protected function processPlayersAndTeams(Buffer $buffer, Result $result): void { - /* * Explode the data into groups. First is player, next is team (item_t) * Each group should be as follows: @@ -291,7 +260,7 @@ protected function processPlayersAndTeams(Buffer &$buffer, Result &$result) // Pull out the item $item = $data[$x]; // If this is an empty item, move on - if ($item == '' || $item == "\x00") { + if ($item === '' || $item === "\x00") { continue; } /* diff --git a/src/GameQ/Protocols/Gmod.php b/src/GameQ/Protocols/Gmod.php index 65967247..f110dfdb 100644 --- a/src/GameQ/Protocols/Gmod.php +++ b/src/GameQ/Protocols/Gmod.php @@ -28,15 +28,11 @@ class Gmod extends Source { /** * String name of this protocol class - * - * @type string */ - protected $name = 'gmod'; + protected string $name = 'gmod'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Garry's Mod"; + protected string $name_long = "Garry's Mod"; } diff --git a/src/GameQ/Protocols/Grav.php b/src/GameQ/Protocols/Grav.php index e025075a..07e7589d 100644 --- a/src/GameQ/Protocols/Grav.php +++ b/src/GameQ/Protocols/Grav.php @@ -28,15 +28,11 @@ class Grav extends Source { /** * String name of this protocol class - * - * @type string */ - protected $name = 'grav'; + protected string $name = 'grav'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "GRAV Online"; + protected string $name_long = "GRAV Online"; } diff --git a/src/GameQ/Protocols/Gta5m.php b/src/GameQ/Protocols/Gta5m.php index 59843f66..d1ea57cb 100644 --- a/src/GameQ/Protocols/Gta5m.php +++ b/src/GameQ/Protocols/Gta5m.php @@ -36,22 +36,16 @@ class Gta5m extends Cfx { /** * The query protocol used to make the call - * - * @type string */ - protected $protocol = 'gta5m'; + protected string $protocol = 'gta5m'; /** * String name of this protocol class - * - * @type string */ - protected $name = 'gta5m'; + protected string $name = 'gta5m'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "GTA Five M"; + protected string $name_long = "GTA Five M"; } diff --git a/src/GameQ/Protocols/Gtan.php b/src/GameQ/Protocols/Gtan.php index f7b531ee..31bf7fc2 100644 --- a/src/GameQ/Protocols/Gtan.php +++ b/src/GameQ/Protocols/Gtan.php @@ -39,7 +39,7 @@ class Gtan extends Http * * @var array */ - protected $packets = [ + protected array $packets = [ //self::PACKET_STATUS => "GET /apiservers HTTP/1.0\r\nHost: master.gtanet.work\r\nAccept: */*\r\n\r\n", self::PACKET_STATUS => "GET /gtan/api.php?ip=%s&raw HTTP/1.0\r\nHost: multiplayerhosting.info\r\nAccept: */*\r\n\r\n", ]; @@ -47,46 +47,41 @@ class Gtan extends Http /** * Http protocol is SSL * - * @var string */ - protected $transport = self::TRANSPORT_SSL; + protected string $transport = self::TRANSPORT_SSL; /** * The protocol being used * - * @var string */ - protected $protocol = 'gtan'; + protected string $protocol = 'gtan'; /** * String name of this protocol class * - * @var string */ - protected $name = 'gtan'; + protected string $name = 'gtan'; /** * Longer string name of this protocol class * - * @var string */ - protected $name_long = "Grand Theft Auto Network"; + protected string $name_long = "Grand Theft Auto Network"; /** * Holds the real ip so we can overwrite it back - * - * @var string */ - protected $realIp = null; + protected ?string $realIp = null; - protected $realPortQuery = null; + /** + * Holds the real query port so we can overwrite it back + */ + protected ?int $realPortQuery = null; /** * Normalize some items - * - * @var array */ - protected $normalize = [ + protected array $normalize = [ // General 'general' => [ // target => source @@ -100,7 +95,7 @@ class Gtan extends Http ], ]; - public function beforeSend(Server $server) + public function beforeSend(Server $server): void { // Loop over the packets and update them foreach ($this->packets as $packetType => $packet) { @@ -120,10 +115,10 @@ public function beforeSend(Server $server) /** * Process the response * - * @return array + * @return mixed * @throws Exception */ - public function processResponse() + public function processResponse(): mixed { // No response, assume offline if (empty($this->packets_response)) { diff --git a/src/GameQ/Protocols/Gtar.php b/src/GameQ/Protocols/Gtar.php index 2121e07c..17e0fc5e 100644 --- a/src/GameQ/Protocols/Gtar.php +++ b/src/GameQ/Protocols/Gtar.php @@ -37,53 +37,48 @@ class Gtar extends Http * * @var array */ - protected $packets = [ + protected array $packets = [ self::PACKET_STATUS => "GET /master/ HTTP/1.0\r\nHost: cdn.rage.mp\r\nAccept: */*\r\n\r\n", ]; /** * Http protocol is SSL * - * @var string */ - protected $transport = self::TRANSPORT_SSL; + protected string $transport = self::TRANSPORT_SSL; /** * The protocol being used * - * @var string */ - protected $protocol = 'gtar'; + protected string $protocol = 'gtar'; /** * String name of this protocol class * - * @var string */ - protected $name = 'gtar'; + protected string $name = 'gtar'; /** * Longer string name of this protocol class * - * @var string */ - protected $name_long = "Grand Theft Auto Rage"; + protected string $name_long = "Grand Theft Auto Rage"; /** * Holds the real ip so we can overwrite it back - * - * @var string */ - protected $realIp = null; + protected ?string $realIp = null; - protected $realPortQuery = null; + /** + * Holds the real query port so we can overwrite it back + */ + protected ?int $realPortQuery = null; /** * Normalize some items - * - * @var array */ - protected $normalize = [ + protected array $normalize = [ // General 'general' => [ // target => source @@ -95,7 +90,7 @@ class Gtar extends Http ], ]; - public function beforeSend(Server $server) + public function beforeSend(Server $server): void { // Loop over the packets and update them foreach ($this->packets as $packetType => $packet) { @@ -114,10 +109,10 @@ public function beforeSend(Server $server) /** * Process the response * - * @return array + * @return mixed * @throws Exception */ - public function processResponse() + public function processResponse(): mixed { // No response, assume offline if (empty($this->packets_response)) { diff --git a/src/GameQ/Protocols/Had2.php b/src/GameQ/Protocols/Had2.php index 92134351..e65bcd4e 100644 --- a/src/GameQ/Protocols/Had2.php +++ b/src/GameQ/Protocols/Had2.php @@ -28,31 +28,23 @@ class Had2 extends Gamespy2 /** * String name of this protocol class - * - * @type string */ - protected $name = 'had2'; + protected string $name = 'had2'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Hidden & Dangerous 2"; + protected string $name_long = "Hidden & Dangerous 2"; /** * The difference between the client port and query port - * - * @type int */ - protected $port_diff = 3; + protected int $port_diff = 3; /** * Normalize settings for this protocol - * - * @type array */ - protected $normalize = [ + protected array $normalize = [ // General 'general' => [ // target => source diff --git a/src/GameQ/Protocols/Halo.php b/src/GameQ/Protocols/Halo.php index f402f94d..d1baf0be 100644 --- a/src/GameQ/Protocols/Halo.php +++ b/src/GameQ/Protocols/Halo.php @@ -28,15 +28,11 @@ class Halo extends Gamespy2 /** * String name of this protocol class - * - * @type string */ - protected $name = 'halo'; + protected string $name = 'halo'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Halo: Combat Evolved"; + protected string $name_long = "Halo: Combat Evolved"; } diff --git a/src/GameQ/Protocols/Hl1.php b/src/GameQ/Protocols/Hl1.php index e17667b6..b065868c 100644 --- a/src/GameQ/Protocols/Hl1.php +++ b/src/GameQ/Protocols/Hl1.php @@ -29,15 +29,11 @@ class Hl1 extends Source { /** * String name of this protocol class - * - * @type string */ - protected $name = 'hl1'; + protected string $name = 'hl1'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Half Life"; + protected string $name_long = "Half Life"; } diff --git a/src/GameQ/Protocols/Hl2dm.php b/src/GameQ/Protocols/Hl2dm.php index 15f881aa..977a8e0f 100644 --- a/src/GameQ/Protocols/Hl2dm.php +++ b/src/GameQ/Protocols/Hl2dm.php @@ -28,15 +28,11 @@ class Hl2dm extends Source { /** * String name of this protocol class - * - * @type string */ - protected $name = 'hl2dm'; + protected string $name = 'hl2dm'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Half Life 2: Deathmatch"; + protected string $name_long = "Half Life 2: Deathmatch"; } diff --git a/src/GameQ/Protocols/Hll.php b/src/GameQ/Protocols/Hll.php index bf0b00c1..0ad0a862 100644 --- a/src/GameQ/Protocols/Hll.php +++ b/src/GameQ/Protocols/Hll.php @@ -28,41 +28,17 @@ class Hll extends Source { /** * String name of this protocol class - * - * @type string */ - protected $name = 'hll'; + protected string $name = 'hll'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Hell Let Loose"; + protected string $name_long = "Hell Let Loose"; /** * query_port = client_port + 15 * 64015 = 64000 + 15 - * - * @type int */ - protected $port_diff = 15; - - /** - * Normalize settings for this protocol - * - * @type array - */ - /*protected $normalize = [ - 'general' => [ - // target => source - 'dedicated' => 'dedicated', - 'gametype' => 'gametype', - 'servername' => 'hostname', - 'mapname' => 'mapname', - 'maxplayers' => 'maxplayers', - 'numplayers' => 'numplayers', - 'password' => 'password', - ], - ];*/ + protected int $port_diff = 15; } diff --git a/src/GameQ/Protocols/Http.php b/src/GameQ/Protocols/Http.php index 2a86d8d1..b965b3b3 100644 --- a/src/GameQ/Protocols/Http.php +++ b/src/GameQ/Protocols/Http.php @@ -32,36 +32,26 @@ abstract class Http extends Protocol { /** * The query protocol used to make the call - * - * @type string */ - protected $protocol = 'http'; + protected string $protocol = 'http'; /** * String name of this protocol class - * - * @type string */ - protected $name = 'http'; + protected string $name = 'http'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Generic HTTP protocol"; + protected string $name_long = "Generic HTTP protocol"; /** * Http protocol is TCP - * - * @var string */ - protected $transport = self::TRANSPORT_TCP; + protected string $transport = self::TRANSPORT_TCP; /** * The client join link - * - * @type string */ - protected $join_link = null; + protected ?string $join_link = null; } diff --git a/src/GameQ/Protocols/Hurtworld.php b/src/GameQ/Protocols/Hurtworld.php index fa54654a..e0020e21 100644 --- a/src/GameQ/Protocols/Hurtworld.php +++ b/src/GameQ/Protocols/Hurtworld.php @@ -29,14 +29,10 @@ class Hurtworld extends Source { /** * String name of this protocol class - * - * @type string */ - protected $name = 'hurtworld'; + protected string $name = 'hurtworld'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Hurtworld"; + protected string $name_long = "Hurtworld"; } diff --git a/src/GameQ/Protocols/Insurgency.php b/src/GameQ/Protocols/Insurgency.php index 77b8329e..e9c7635b 100644 --- a/src/GameQ/Protocols/Insurgency.php +++ b/src/GameQ/Protocols/Insurgency.php @@ -28,15 +28,11 @@ class Insurgency extends Source { /** * String name of this protocol class - * - * @type string */ - protected $name = 'insurgency'; + protected string $name = 'insurgency'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Insurgency"; + protected string $name_long = "Insurgency"; } diff --git a/src/GameQ/Protocols/Insurgencysand.php b/src/GameQ/Protocols/Insurgencysand.php index 407d6e26..d628020b 100644 --- a/src/GameQ/Protocols/Insurgencysand.php +++ b/src/GameQ/Protocols/Insurgencysand.php @@ -28,22 +28,16 @@ class Insurgencysand extends Source { /** * String name of this protocol class - * - * @type string */ - protected $name = 'insurgencysand'; + protected string $name = 'insurgencysand'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Insurgency: Sandstorm"; + protected string $name_long = "Insurgency: Sandstorm"; /** * query_port = client_port + 29 - * - * @type int */ - protected $port_diff = 29; + protected int $port_diff = 29; } diff --git a/src/GameQ/Protocols/Jediacademy.php b/src/GameQ/Protocols/Jediacademy.php index a051a3a9..3ca6b07b 100644 --- a/src/GameQ/Protocols/Jediacademy.php +++ b/src/GameQ/Protocols/Jediacademy.php @@ -28,15 +28,11 @@ class Jediacademy extends Quake3 { /** * String name of this protocol class - * - * @type string */ - protected $name = 'jediacademy'; + protected string $name = 'jediacademy'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Star Wars Jedi Knight: Jedi Academy"; + protected string $name_long = "Star Wars Jedi Knight: Jedi Academy"; } diff --git a/src/GameQ/Protocols/Jedioutcast.php b/src/GameQ/Protocols/Jedioutcast.php index 1afd9afe..aa07f253 100644 --- a/src/GameQ/Protocols/Jedioutcast.php +++ b/src/GameQ/Protocols/Jedioutcast.php @@ -28,15 +28,11 @@ class Jedioutcast extends Quake3 { /** * String name of this protocol class - * - * @type string */ - protected $name = 'jedioutcast'; + protected string $name = 'jedioutcast'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Star Wars Jedi Knight II: Jedi Outcast"; + protected string $name_long = "Star Wars Jedi Knight II: Jedi Outcast"; } diff --git a/src/GameQ/Protocols/Justcause2.php b/src/GameQ/Protocols/Justcause2.php index 648cb6d5..e1996103 100644 --- a/src/GameQ/Protocols/Justcause2.php +++ b/src/GameQ/Protocols/Justcause2.php @@ -33,48 +33,38 @@ class Justcause2 extends Gamespy4 { /** * String name of this protocol class - * - * @type string */ - protected $name = 'justcause2'; + protected string $name = 'justcause2'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Just Cause 2 Multiplayer"; + protected string $name_long = "Just Cause 2 Multiplayer"; /** * The client join link - * - * @type string */ - protected $join_link = "steam://connect/%s:%d/"; + protected ?string $join_link = "steam://connect/%s:%d/"; /** * Change the packets used * * @var array */ - protected $packets = [ + protected array $packets = [ self::PACKET_CHALLENGE => "\xFE\xFD\x09\x10\x20\x30\x40", self::PACKET_ALL => "\xFE\xFD\x00\x10\x20\x30\x40%s\xFF\xFF\xFF\x02", ]; /** * Override the packet split - * - * @var string */ - protected $packetSplit = "/\\x00\\x00\\x00/m"; + protected string $packetsplit = "/\\x00\\x00\\x00/m"; /** * Normalize settings for this protocol - * - * @type array */ - protected $normalize = [ + protected array $normalize = [ 'general' => [ // target => source 'dedicated' => 'dedicated', @@ -94,11 +84,8 @@ class Justcause2 extends Gamespy4 /** * Overload so we can add in some static data points - * - * @param Buffer $buffer - * @param Result $result */ - protected function processDetails(Buffer &$buffer, Result &$result) + protected function processDetails(Buffer $buffer, Result $result): void { parent::processDetails($buffer, $result); @@ -110,12 +97,9 @@ protected function processDetails(Buffer &$buffer, Result &$result) /** * Override the parent, this protocol is returned differently * - * @param Buffer $buffer - * @param Result $result - * * @see Gamespy3::processPlayersAndTeams() */ - protected function processPlayersAndTeams(Buffer &$buffer, Result &$result) + protected function processPlayersAndTeams(Buffer $buffer, Result $result): void { // Loop until we run out of data while ($buffer->getLength()) { diff --git a/src/GameQ/Protocols/Justcause3.php b/src/GameQ/Protocols/Justcause3.php index c4e901d9..cdc48409 100644 --- a/src/GameQ/Protocols/Justcause3.php +++ b/src/GameQ/Protocols/Justcause3.php @@ -29,22 +29,16 @@ class Justcause3 extends Source /** * String name of this protocol class - * - * @type string */ - protected $name = 'justcause3'; + protected string $name = 'justcause3'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Just Cause 3"; + protected string $name_long = "Just Cause 3"; /** * Query port = client_port + 1 - * - * @type int */ - protected $port_diff = 1; + protected int $port_diff = 1; } diff --git a/src/GameQ/Protocols/Killingfloor.php b/src/GameQ/Protocols/Killingfloor.php index 2a6cf0c8..c2685715 100644 --- a/src/GameQ/Protocols/Killingfloor.php +++ b/src/GameQ/Protocols/Killingfloor.php @@ -32,36 +32,27 @@ class Killingfloor extends Unreal2 /** * String name of this protocol class - * - * @type string */ - protected $name = 'killing floor'; + protected string $name = 'killing floor'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Killing Floor"; + protected string $name_long = "Killing Floor"; /** * query_port = client_port + 1 - * - * @type int */ - protected $port_diff = 1; + protected int $port_diff = 1; /** * The client join link - * - * @type string */ - protected $join_link = "steam://connect/%s:%d/"; + protected ?string $join_link = "steam://connect/%s:%d/"; /** * Overload the default detail process since this version is different - * - * @param \GameQ\Buffer $buffer + * * @return array */ @@ -77,7 +68,7 @@ protected function processDetails(Buffer $buffer) $result->add('queryport', $buffer->readInt32()); // 0 // We burn the first char since it is not always correct with the hostname - $buffer->skip(1); + $buffer->skip(); // Read as a regular string since the length is incorrect (what we skipped earlier) $result->add('servername', $this->convertToUtf8($buffer->readString())); diff --git a/src/GameQ/Protocols/Killingfloor2.php b/src/GameQ/Protocols/Killingfloor2.php index a134f258..c3203841 100644 --- a/src/GameQ/Protocols/Killingfloor2.php +++ b/src/GameQ/Protocols/Killingfloor2.php @@ -29,23 +29,17 @@ class Killingfloor2 extends Source /** * String name of this protocol class - * - * @type string */ - protected $name = 'killing floor 2'; + protected string $name = 'killing floor 2'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Killing Floor 2"; + protected string $name_long = "Killing Floor 2"; /** * query_port = client_port + 19238 * 27015 = 7777 + 19238 - * - * @type int */ - protected $port_diff = 19238; + protected int $port_diff = 19238; } diff --git a/src/GameQ/Protocols/Kingpin.php b/src/GameQ/Protocols/Kingpin.php index 87007d91..fd0a1bf0 100644 --- a/src/GameQ/Protocols/Kingpin.php +++ b/src/GameQ/Protocols/Kingpin.php @@ -29,15 +29,11 @@ class Kingpin extends Quake2 { /** * String name of this protocol class - * - * @type string */ - protected $name = 'kingpin'; + protected string $name = 'kingpin'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Kingpin: Life of Crime"; + protected string $name_long = "Kingpin: Life of Crime"; } diff --git a/src/GameQ/Protocols/L4d.php b/src/GameQ/Protocols/L4d.php index 596452a7..c5b569ef 100644 --- a/src/GameQ/Protocols/L4d.php +++ b/src/GameQ/Protocols/L4d.php @@ -28,15 +28,11 @@ class L4d extends Source { /** * String name of this protocol class - * - * @type string */ - protected $name = 'l4d'; + protected string $name = 'l4d'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Left 4 Dead"; + protected string $name_long = "Left 4 Dead"; } diff --git a/src/GameQ/Protocols/L4d2.php b/src/GameQ/Protocols/L4d2.php index 475514c9..085638ce 100644 --- a/src/GameQ/Protocols/L4d2.php +++ b/src/GameQ/Protocols/L4d2.php @@ -28,15 +28,11 @@ class L4d2 extends Source { /** * String name of this protocol class - * - * @type string */ - protected $name = 'l4d2'; + protected string $name = 'l4d2'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Left 4 Dead 2"; + protected string $name_long = "Left 4 Dead 2"; } diff --git a/src/GameQ/Protocols/Lhmp.php b/src/GameQ/Protocols/Lhmp.php index 61e80155..4195fe88 100644 --- a/src/GameQ/Protocols/Lhmp.php +++ b/src/GameQ/Protocols/Lhmp.php @@ -36,10 +36,8 @@ class Lhmp extends Protocol /** * Array of packets we want to look up. * Each key should correspond to a defined method in this or a parent class - * - * @type array */ - protected $packets = [ + protected array $packets = [ self::PACKET_DETAILS => "LHMPo", self::PACKET_PLAYERS => "LHMPp", ]; @@ -47,47 +45,36 @@ class Lhmp extends Protocol /** * Use the response flag to figure out what method to run * - * @type array */ - protected $responses = [ + protected array $responses = [ "LHMPo" => "processDetails", "LHMPp" => "processPlayers", ]; /** * The query protocol used to make the call - * - * @type string */ - protected $protocol = 'lhmp'; + protected string $protocol = 'lhmp'; /** * String name of this protocol class - * - * @type string */ - protected $name = 'lhmp'; + protected string $name = 'lhmp'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Lost Heaven"; + protected string $name_long = "Lost Heaven"; /** * query_port = client_port + 1 - * - * @type int */ - protected $port_diff = 1; + protected int $port_diff = 1; /** * Normalize settings for this protocol - * - * @type array */ - protected $normalize = [ + protected array $normalize = [ // General 'general' => [ // target => source @@ -107,10 +94,10 @@ class Lhmp extends Protocol /** * Process the response * - * @return array + * @return mixed * @throws \GameQ\Exception\Protocol */ - public function processResponse() + public function processResponse(): mixed { // Will hold the packets after sorting $packets = []; @@ -156,8 +143,6 @@ public function processResponse() /** * Handles processing the details data into a usable format * - * @param Buffer $buffer - * * @return array * @throws Exception */ @@ -182,8 +167,6 @@ protected function processDetails(Buffer $buffer) /** * Handles processing the player data into a usable format * - * @param Buffer $buffer - * * @return array */ protected function processPlayers(Buffer $buffer) diff --git a/src/GameQ/Protocols/Lifeisfeudal.php b/src/GameQ/Protocols/Lifeisfeudal.php index 0db79805..d9123331 100644 --- a/src/GameQ/Protocols/Lifeisfeudal.php +++ b/src/GameQ/Protocols/Lifeisfeudal.php @@ -28,22 +28,16 @@ class Lifeisfeudal extends Source { /** * String name of this protocol class - * - * @type string */ - protected $name = 'lifeisfeudal'; + protected string $name = 'lifeisfeudal'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Life is Feudal"; + protected string $name_long = "Life is Feudal"; /** * query_port = client_port + 2 - * - * @type int */ - protected $port_diff = 2; + protected int $port_diff = 2; } diff --git a/src/GameQ/Protocols/M2mp.php b/src/GameQ/Protocols/M2mp.php index c3600042..54fdd4c1 100644 --- a/src/GameQ/Protocols/M2mp.php +++ b/src/GameQ/Protocols/M2mp.php @@ -40,63 +40,48 @@ class M2mp extends Protocol /** * Array of packets we want to look up. * Each key should correspond to a defined method in this or a parent class - * - * @type array */ - protected $packets = [ + protected array $packets = [ self::PACKET_ALL => "M2MP", ]; /** * Use the response flag to figure out what method to run * - * @type array */ - protected $responses = [ + protected array $responses = [ "M2MP" => 'processStatus', ]; /** * The query protocol used to make the call - * - * @type string */ - protected $protocol = 'm2mp'; + protected string $protocol = 'm2mp'; /** * String name of this protocol class - * - * @type string */ - protected $name = 'm2mp'; + protected string $name = 'm2mp'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Mafia 2 Multiplayer"; + protected string $name_long = "Mafia 2 Multiplayer"; /** * The client join link - * - * @type string */ - protected $join_link = null; + protected ?string $join_link = null; /** * The difference between the client port and query port - * - * @type int */ - protected $port_diff = 1; + protected int $port_diff = 1; /** * Normalize settings for this protocol - * - * @type array */ - protected $normalize = [ + protected array $normalize = [ // General 'general' => [ // target => source @@ -118,7 +103,7 @@ class M2mp extends Protocol * @return mixed * @throws Exception */ - public function processResponse() + public function processResponse(): mixed { // Make a buffer $buffer = new Buffer(implode('', $this->packets_response)); @@ -138,8 +123,6 @@ public function processResponse() /** * Process the status response * - * @param Buffer $buffer - * * @return array */ protected function processStatus(Buffer $buffer) @@ -156,8 +139,6 @@ protected function processStatus(Buffer $buffer) /** * Handle processing the server information * - * @param Buffer $buffer - * * @return array */ protected function processServerInfo(Buffer $buffer) @@ -182,8 +163,6 @@ protected function processServerInfo(Buffer $buffer) /** * Handle processing of player data * - * @param Buffer $buffer - * * @return array */ protected function processPlayers(Buffer $buffer) @@ -204,9 +183,6 @@ protected function processPlayers(Buffer $buffer) $result->addPlayer('name', $this->convertToUtf8(trim($buffer->readPascalString(1, true)))); } - // Clear - unset($buffer); - return $result->fetch(); } } diff --git a/src/GameQ/Protocols/Minecraft.php b/src/GameQ/Protocols/Minecraft.php index a895cb87..d1fa4fa5 100644 --- a/src/GameQ/Protocols/Minecraft.php +++ b/src/GameQ/Protocols/Minecraft.php @@ -43,31 +43,23 @@ class Minecraft extends Gamespy3 /** * String name of this protocol class - * - * @type string */ - protected $name = 'minecraft'; + protected string $name = 'minecraft'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Minecraft"; + protected string $name_long = "Minecraft"; /** * The client join link - * - * @type string */ - protected $join_link = "minecraft://%s:%d/"; + protected ?string $join_link = "minecraft://%s:%d/"; /** * Normalize settings for this protocol - * - * @type array */ - protected $normalize = [ + protected array $normalize = [ // General 'general' => [ // target => source diff --git a/src/GameQ/Protocols/Minecraftbe.php b/src/GameQ/Protocols/Minecraftbe.php index 60209679..298238a9 100644 --- a/src/GameQ/Protocols/Minecraftbe.php +++ b/src/GameQ/Protocols/Minecraftbe.php @@ -30,24 +30,18 @@ class Minecraftbe extends Raknet /** * String name of this protocol class - * - * @type string */ - protected $name = 'minecraftbe'; + protected string $name = 'minecraftbe'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Minecraft Bedrock Edition"; + protected string $name_long = "Minecraft Bedrock Edition"; /** * Normalize settings for this protocol - * - * @type array */ - protected $normalize = [ + protected array $normalize = [ // General 'general' => [ // target => source diff --git a/src/GameQ/Protocols/Minecraftpe.php b/src/GameQ/Protocols/Minecraftpe.php index 21d11868..dc0496df 100644 --- a/src/GameQ/Protocols/Minecraftpe.php +++ b/src/GameQ/Protocols/Minecraftpe.php @@ -30,15 +30,11 @@ class Minecraftpe extends Minecraft /** * String name of this protocol class - * - * @type string */ - protected $name = 'minecraftpe'; + protected string $name = 'minecraftpe'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "MinecraftPE"; + protected string $name_long = "MinecraftPE"; } diff --git a/src/GameQ/Protocols/Miscreated.php b/src/GameQ/Protocols/Miscreated.php index d59fed12..ffb5a5ae 100644 --- a/src/GameQ/Protocols/Miscreated.php +++ b/src/GameQ/Protocols/Miscreated.php @@ -28,32 +28,24 @@ class Miscreated extends Source { /** * String name of this protocol class - * - * @type string */ - protected $name = 'miscreated'; + protected string $name = 'miscreated'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Miscreated"; + protected string $name_long = "Miscreated"; /** * query_port = client_port + 2 * 64092 = 64090 + 2 - * - * @type int */ - protected $port_diff = 2; + protected int $port_diff = 2; /** * Normalize settings for this protocol - * - * @type array */ - protected $normalize = [ + protected array $normalize = [ 'general' => [ // target => source 'dedicated' => 'dedicated', diff --git a/src/GameQ/Protocols/Modiverse.php b/src/GameQ/Protocols/Modiverse.php index 64b41ed5..be35fbec 100644 --- a/src/GameQ/Protocols/Modiverse.php +++ b/src/GameQ/Protocols/Modiverse.php @@ -29,15 +29,11 @@ class Modiverse extends Source { /** * String name of this protocol class - * - * @type string */ - protected $name = 'modiverse'; + protected string $name = 'modiverse'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Modiverse"; + protected string $name_long = "Modiverse"; } diff --git a/src/GameQ/Protocols/Mohaa.php b/src/GameQ/Protocols/Mohaa.php index 66ddd7e7..dac15a3c 100644 --- a/src/GameQ/Protocols/Mohaa.php +++ b/src/GameQ/Protocols/Mohaa.php @@ -29,24 +29,18 @@ class Mohaa extends Gamespy { /** * String name of this protocol class - * - * @type string */ - protected $name = 'mohaa'; + protected string $name = 'mohaa'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Medal of honor: Allied Assault"; + protected string $name_long = "Medal of honor: Allied Assault"; /** * Normalize settings for this protocol - * - * @type array */ - protected $normalize = [ + protected array $normalize = [ 'general' => [ // target => source 'dedicated' => 'dedicated', @@ -67,12 +61,8 @@ class Mohaa extends Gamespy /** * Query port is always the client port + 97 in MOHAA - * - * @param int $clientPort - * - * @return int */ - public function findQueryPort($clientPort) + public function findQueryPort(int $clientPort): int { return $clientPort + 97; } diff --git a/src/GameQ/Protocols/Mordhau.php b/src/GameQ/Protocols/Mordhau.php index fa305ce1..dec895ba 100644 --- a/src/GameQ/Protocols/Mordhau.php +++ b/src/GameQ/Protocols/Mordhau.php @@ -29,25 +29,11 @@ class Mordhau extends Source /** * String name of this protocol class - * - * @type string */ - protected $name = 'mordhau'; + protected string $name = 'mordhau'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "MORDHAU"; - - #protected $port = 7777; - - /** - * query_port = client_port + 19238 - * 27015 = 7777 + 19238 - * - * @type int - */ - #protected $port_diff = 19238; + protected string $name_long = "MORDHAU"; } diff --git a/src/GameQ/Protocols/Mta.php b/src/GameQ/Protocols/Mta.php index b95dc4c8..da8d5282 100644 --- a/src/GameQ/Protocols/Mta.php +++ b/src/GameQ/Protocols/Mta.php @@ -31,29 +31,21 @@ class Mta extends Ase /** * String name of this protocol class - * - * @type string */ - protected $name = 'mta'; + protected string $name = 'mta'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Multi Theft Auto"; + protected string $name_long = "Multi Theft Auto"; /** * query_port = client_port + 123 - * - * @type int */ - protected $port_diff = 123; + protected int $port_diff = 123; /** * The client join link - * - * @type string */ - protected $join_link = "mtasa://%s:%d/"; + protected ?string $join_link = "mtasa://%s:%d/"; } diff --git a/src/GameQ/Protocols/Mumble.php b/src/GameQ/Protocols/Mumble.php index 95426396..f55ab805 100644 --- a/src/GameQ/Protocols/Mumble.php +++ b/src/GameQ/Protocols/Mumble.php @@ -36,61 +36,45 @@ class Mumble extends Protocol /** * Array of packets we want to look up. * Each key should correspond to a defined method in this or a parent class - * - * @type array */ - protected $packets = [ + protected array $packets = [ self::PACKET_ALL => "\x6A\x73\x6F\x6E", // JSON packet ]; /** * The transport mode for this protocol is TCP - * - * @type string - */ - protected $transport = self::TRANSPORT_TCP; + */ + protected string $transport = self::TRANSPORT_TCP; /** * The query protocol used to make the call - * - * @type string */ - protected $protocol = 'mumble'; + protected string $protocol = 'mumble'; /** * String name of this protocol class - * - * @type string */ - protected $name = 'mumble'; + protected string $name = 'mumble'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Mumble Server"; + protected string $name_long = "Mumble Server"; /** * The client join link - * - * @type string */ - protected $join_link = "mumble://%s:%d/"; + protected ?string $join_link = "mumble://%s:%d/"; /** * 27800 = 64738 - 36938 - * - * @type int */ - protected $port_diff = -36938; + protected int $port_diff = -36938; /** * Normalize settings for this protocol - * - * @type array */ - protected $normalize = [ + protected array $normalize = [ // General 'general' => [ 'dedicated' => 'dedicated', @@ -115,14 +99,19 @@ class Mumble extends Protocol /** * Process the response * - * @return array + * @return mixed * @throws \GameQ\Exception\Protocol */ - public function processResponse() + public function processResponse(): mixed { // Try to json_decode, make it into an array - if (($data = json_decode(implode('', $this->packets_response), true)) === null) { + if (($data = json_decode( + implode('', $this->packets_response), + true, + 512, + JSON_THROW_ON_ERROR + )) === null) { throw new Exception(__METHOD__ . " Unable to decode JSON data."); } @@ -160,13 +149,9 @@ public function processResponse() /** * Handles processing the the channels and user info - * - * @param array $data - * @param \GameQ\Result $result */ - protected function processChannelsAndUsers(array $data, Result &$result) + protected function processChannelsAndUsers(array $data, Result $result): void { - // Let's add all of the channel information foreach ($data as $key => $value) { // We will handle these later diff --git a/src/GameQ/Protocols/Nmrih.php b/src/GameQ/Protocols/Nmrih.php index acae3b6e..3002894d 100644 --- a/src/GameQ/Protocols/Nmrih.php +++ b/src/GameQ/Protocols/Nmrih.php @@ -29,15 +29,11 @@ class Nmrih extends Source { /** * No More Room in Hell protocol class - * - * @type string */ - protected $name = 'nmrih'; + protected string $name = 'nmrih'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "No More Room in Hell"; + protected string $name_long = "No More Room in Hell"; } diff --git a/src/GameQ/Protocols/Ns2.php b/src/GameQ/Protocols/Ns2.php index 4c323929..1f3ef06e 100644 --- a/src/GameQ/Protocols/Ns2.php +++ b/src/GameQ/Protocols/Ns2.php @@ -28,22 +28,16 @@ class Ns2 extends Source { /** * String name of this protocol class - * - * @type string */ - protected $name = 'ns2'; + protected string $name = 'ns2'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Natural Selection 2"; + protected string $name_long = "Natural Selection 2"; /** * query_port = client_port + 1 - * - * @type int */ - protected $port_diff = 1; + protected int $port_diff = 1; } diff --git a/src/GameQ/Protocols/Of.php b/src/GameQ/Protocols/Of.php index bce7612d..7c69f3b2 100644 --- a/src/GameQ/Protocols/Of.php +++ b/src/GameQ/Protocols/Of.php @@ -29,15 +29,11 @@ class Of extends Source { /** * Open Fortress protocol class - * - * @type string */ - protected $name = 'of'; + protected string $name = 'of'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Open Fortress"; + protected string $name_long = "Open Fortress"; } diff --git a/src/GameQ/Protocols/Openttd.php b/src/GameQ/Protocols/Openttd.php index e20af384..620b2999 100644 --- a/src/GameQ/Protocols/Openttd.php +++ b/src/GameQ/Protocols/Openttd.php @@ -36,47 +36,35 @@ class Openttd extends Protocol /** * Array of packets we want to look up. * Each key should correspond to a defined method in this or a parent class - * - * @type array */ - protected $packets = [ + protected array $packets = [ self::PACKET_ALL => "\x03\x00\x00", ]; /** * The query protocol used to make the call - * - * @type string */ - protected $protocol = 'openttd'; + protected string $protocol = 'openttd'; /** * String name of this protocol class - * - * @type string */ - protected $name = 'openttd'; + protected string $name = 'openttd'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Open Transport Tycoon Deluxe"; + protected string $name_long = "Open Transport Tycoon Deluxe"; /** * The client join link - * - * @type string */ - protected $join_link = null; + protected ?string $join_link = null; /** * Normalize settings for this protocol - * - * @type array */ - protected $normalize = [ + protected array $normalize = [ // General 'general' => [ // target => source @@ -95,7 +83,7 @@ class Openttd extends Protocol * @return mixed * @throws Exception */ - public function processResponse() + public function processResponse(): mixed { // Make a buffer $buffer = new Buffer(implode('', $this->packets_response)); @@ -106,7 +94,7 @@ public function processResponse() // Grab the header $length = $buffer->readInt16(); //$type = $buffer->readInt8(); - $buffer->skip(1); // Skip the "$type" as its not used in the code. + $buffer->skip(); // Skip the "$type" as its not used in the code. // Header // Figure out which packet response this is @@ -120,8 +108,6 @@ public function processResponse() /** * Handle processing the server information * - * @param Buffer $buffer - * * @return array */ protected function processServerInfo(Buffer $buffer) diff --git a/src/GameQ/Protocols/Pixark.php b/src/GameQ/Protocols/Pixark.php index 445f6541..69d47d7d 100644 --- a/src/GameQ/Protocols/Pixark.php +++ b/src/GameQ/Protocols/Pixark.php @@ -29,22 +29,16 @@ class Pixark extends Arkse /** * String name of this protocol class - * - * @type string */ - protected $name = 'pixark'; + protected string $name = 'pixark'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "PixARK"; + protected string $name_long = "PixARK"; /** * Query port = client_port + 1 - * - * @type int */ - protected $port_diff = 1; + protected int $port_diff = 1; } diff --git a/src/GameQ/Protocols/Postscriptum.php b/src/GameQ/Protocols/Postscriptum.php index 555ba7d1..2174ae4b 100644 --- a/src/GameQ/Protocols/Postscriptum.php +++ b/src/GameQ/Protocols/Postscriptum.php @@ -28,23 +28,17 @@ class Postscriptum extends Source { /** * String name of this protocol class - * - * @type string */ - protected $name = 'postscriptum'; + protected string $name = 'postscriptum'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Post Scriptum"; + protected string $name_long = "Post Scriptum"; /** * query_port = client_port + 10 * 64092 = 64090 + 10 - * - * @type int */ - protected $port_diff = 10; + protected int $port_diff = 10; } diff --git a/src/GameQ/Protocols/Projectrealitybf2.php b/src/GameQ/Protocols/Projectrealitybf2.php index 6f4b5ce0..271fc43a 100644 --- a/src/GameQ/Protocols/Projectrealitybf2.php +++ b/src/GameQ/Protocols/Projectrealitybf2.php @@ -31,15 +31,11 @@ class Projectrealitybf2 extends Bf2 /** * String name of this protocol class - * - * @type string */ - protected $name = 'projectrealitybf2'; + protected string $name = 'projectrealitybf2'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Project Reality: Battlefield 2"; + protected string $name_long = "Project Reality: Battlefield 2"; } diff --git a/src/GameQ/Protocols/Quake2.php b/src/GameQ/Protocols/Quake2.php index c030de4a..e0a55fab 100644 --- a/src/GameQ/Protocols/Quake2.php +++ b/src/GameQ/Protocols/Quake2.php @@ -20,56 +20,43 @@ class Quake2 extends Protocol /** * Array of packets we want to look up. * Each key should correspond to a defined method in this or a parent class - * - * @type array */ - protected $packets = [ + protected array $packets = [ self::PACKET_STATUS => "\xFF\xFF\xFF\xFFstatus\x00", ]; /** * Use the response flag to figure out what method to run * - * @type array */ - protected $responses = [ + protected array $responses = [ "\xFF\xFF\xFF\xFF\x70\x72\x69\x6e\x74" => 'processStatus', ]; /** * The query protocol used to make the call - * - * @type string */ - protected $protocol = 'quake2'; + protected string $protocol = 'quake2'; /** * String name of this protocol class - * - * @type string */ - protected $name = 'quake2'; + protected string $name = 'quake2'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Quake 2 Server"; + protected string $name_long = "Quake 2 Server"; /** * The client join link - * - * @type string */ - protected $join_link = null; + protected ?string $join_link = null; /** * Normalize settings for this protocol - * - * @type array */ - protected $normalize = [ + protected array $normalize = [ // General 'general' => [ // target => source @@ -95,7 +82,7 @@ class Quake2 extends Protocol * @return mixed * @throws Exception */ - public function processResponse() + public function processResponse(): mixed { // Make a buffer $buffer = new Buffer(implode('', $this->packets_response)); @@ -114,8 +101,6 @@ public function processResponse() /** * Process the status response * - * @param Buffer $buffer - * * @return array */ protected function processStatus(Buffer $buffer) @@ -132,8 +117,6 @@ protected function processStatus(Buffer $buffer) /** * Handle processing the server information * - * @param Buffer $buffer - * * @return array */ protected function processServerInfo(Buffer $buffer) @@ -162,8 +145,6 @@ protected function processServerInfo(Buffer $buffer) /** * Handle processing of player data * - * @param Buffer $buffer - * * @return array */ protected function processPlayers(Buffer $buffer) @@ -184,7 +165,7 @@ protected function processPlayers(Buffer $buffer) $result->addPlayer('ping', $playerInfo->readString("\x20")); // Skip first " - $playerInfo->skip(1); + $playerInfo->skip(); // Add player name, encoded $result->addPlayer('name', $this->convertToUtf8(trim(($playerInfo->readString('"'))))); diff --git a/src/GameQ/Protocols/Quake3.php b/src/GameQ/Protocols/Quake3.php index 4d82ff30..c8afe031 100644 --- a/src/GameQ/Protocols/Quake3.php +++ b/src/GameQ/Protocols/Quake3.php @@ -20,56 +20,43 @@ class Quake3 extends Protocol /** * Array of packets we want to look up. * Each key should correspond to a defined method in this or a parent class - * - * @type array */ - protected $packets = [ + protected array $packets = [ self::PACKET_STATUS => "\xFF\xFF\xFF\xFF\x67\x65\x74\x73\x74\x61\x74\x75\x73\x0A", ]; /** * Use the response flag to figure out what method to run * - * @type array */ - protected $responses = [ + protected array $responses = [ "\xFF\xFF\xFF\xFFstatusResponse" => 'processStatus', ]; /** * The query protocol used to make the call - * - * @type string */ - protected $protocol = 'quake3'; + protected string $protocol = 'quake3'; /** * String name of this protocol class - * - * @type string */ - protected $name = 'quake3'; + protected string $name = 'quake3'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Quake 3 Server"; + protected string $name_long = "Quake 3 Server"; /** * The client join link - * - * @type string */ - protected $join_link = null; + protected ?string $join_link = null; /** * Normalize settings for this protocol - * - * @type array */ - protected $normalize = [ + protected array $normalize = [ // General 'general' => [ // target => source @@ -95,7 +82,7 @@ class Quake3 extends Protocol * @return mixed * @throws Exception */ - public function processResponse() + public function processResponse(): mixed { // Make a buffer $buffer = new Buffer(implode('', $this->packets_response)); @@ -124,8 +111,6 @@ protected function processStatus(Buffer $buffer) /** * Handle processing the server information * - * @param Buffer $buffer - * * @return array */ protected function processServerInfo(Buffer $buffer) @@ -151,8 +136,6 @@ protected function processServerInfo(Buffer $buffer) /** * Handle processing of player data * - * @param Buffer $buffer - * * @return array * @throws Exception */ @@ -171,10 +154,10 @@ protected function processPlayers(Buffer $buffer) $result->addPlayer('ping', $buffer->readString("\x20")); // Look ahead to see if we have a name or team - $checkTeam = $buffer->lookAhead(1); + $checkTeam = $buffer->lookAhead(); // We have team info - if ($checkTeam != '' and $checkTeam != '"') { + if ($checkTeam !== '' && $checkTeam !== '"') { $result->addPlayer('team', $buffer->readString("\x20")); } diff --git a/src/GameQ/Protocols/Quake4.php b/src/GameQ/Protocols/Quake4.php index 1fc55849..9c1a1753 100644 --- a/src/GameQ/Protocols/Quake4.php +++ b/src/GameQ/Protocols/Quake4.php @@ -32,22 +32,17 @@ class Quake4 extends Doom3 { /** * String name of this protocol class - * - * @type string */ - protected $name = 'quake4'; + protected string $name = 'quake4'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Quake 4"; + protected string $name_long = "Quake 4"; /** * Handle processing of player data - * - * @param \GameQ\Buffer $buffer + * * @return array */ diff --git a/src/GameQ/Protocols/Quakelive.php b/src/GameQ/Protocols/Quakelive.php index d5df3501..62877d53 100644 --- a/src/GameQ/Protocols/Quakelive.php +++ b/src/GameQ/Protocols/Quakelive.php @@ -28,15 +28,11 @@ class Quakelive extends Source { /** * String name of this protocol class - * - * @type string */ - protected $name = 'quakelive'; + protected string $name = 'quakelive'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Quake Live"; + protected string $name_long = "Quake Live"; } diff --git a/src/GameQ/Protocols/Raknet.php b/src/GameQ/Protocols/Raknet.php index 539cc688..3a033861 100644 --- a/src/GameQ/Protocols/Raknet.php +++ b/src/GameQ/Protocols/Raknet.php @@ -36,52 +36,40 @@ class Raknet extends Protocol /** * The magic string that is sent to get access to the server information */ - const OFFLINE_MESSAGE_DATA_ID = "\x00\xFF\xFF\x00\xFE\xFE\xFE\xFE\xFD\xFD\xFD\xFD\x12\x34\x56\x78"; + public const OFFLINE_MESSAGE_DATA_ID = "\x00\xFF\xFF\x00\xFE\xFE\xFE\xFE\xFD\xFD\xFD\xFD\x12\x34\x56\x78"; /** * Expected first part of the response from the server after query */ - const ID_UNCONNECTED_PONG = "\x1C"; + public const ID_UNCONNECTED_PONG = "\x1C"; /** * Array of packets we want to look up. * Each key should correspond to a defined method in this or a parent class - * - * @type array */ - protected $packets = [ + protected array $packets = [ self::PACKET_STATUS => "\x01%s%s\x02\x00\x00\x00\x00\x00\x00\x00", // Format time, magic, ]; /** * The query protocol used to make the call - * - * @type string */ - protected $protocol = 'raknet'; + protected string $protocol = 'raknet'; /** * String name of this protocol class - * - * @type string */ - protected $name = 'raknet'; + protected string $name = 'raknet'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Raknet Server"; + protected string $name_long = "Raknet Server"; /** * Do some work to build the packet we need to send out to query - * - * @param Server $server - * - * @return void */ - public function beforeSend(Server $server) + public function beforeSend(Server $server): void { // Update the server status packet before it is sent $this->packets[self::PACKET_STATUS] = sprintf( @@ -94,16 +82,16 @@ public function beforeSend(Server $server) /** * Process the response * - * @return array + * @return mixed * @throws \GameQ\Exception\Protocol */ - public function processResponse() + public function processResponse(): mixed { // Merge the response array into a buffer. Unknown if this protocol does split packets or not $buffer = new Buffer(implode($this->packets_response)); // Read first character from response. It should match below - $header = $buffer->read(1); + $header = $buffer->read(); // Check first character to make sure the header matches if ($header !== self::ID_UNCONNECTED_PONG) { diff --git a/src/GameQ/Protocols/Redorchestra2.php b/src/GameQ/Protocols/Redorchestra2.php index 67330167..fd49ce19 100644 --- a/src/GameQ/Protocols/Redorchestra2.php +++ b/src/GameQ/Protocols/Redorchestra2.php @@ -28,23 +28,17 @@ class Redorchestra2 extends Source { /** * String name of this protocol class - * - * @type string */ - protected $name = 'redorchestra2'; + protected string $name = 'redorchestra2'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Red Orchestra 2"; + protected string $name_long = "Red Orchestra 2"; /** * query_port = client_port + 19238 * 27015 = 7777 + 19238 - * - * @type int */ - protected $port_diff = 19238; + protected int $port_diff = 19238; } diff --git a/src/GameQ/Protocols/Redorchestraostfront.php b/src/GameQ/Protocols/Redorchestraostfront.php index 4c83b7eb..7ade3f67 100644 --- a/src/GameQ/Protocols/Redorchestraostfront.php +++ b/src/GameQ/Protocols/Redorchestraostfront.php @@ -29,15 +29,11 @@ class Redorchestraostfront extends Source { /** * String name of this protocol class - * - * @type string */ - protected $name = 'redorchestraostfront'; + protected string $name = 'redorchestraostfront'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Red Orchestra: Ostfront 41-45"; + protected string $name_long = "Red Orchestra: Ostfront 41-45"; } diff --git a/src/GameQ/Protocols/Rf2.php b/src/GameQ/Protocols/Rf2.php index 9901c425..8b358fc4 100644 --- a/src/GameQ/Protocols/Rf2.php +++ b/src/GameQ/Protocols/Rf2.php @@ -28,23 +28,17 @@ class Rf2 extends Source { /** * String name of this protocol class - * - * @type string */ - protected $name = 'rf2'; + protected string $name = 'rf2'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "rFactor 2"; + protected string $name_long = "rFactor 2"; /** * query_port = client_port + 2 * 64092 = 64090 + 2 - * - * @type int */ - protected $port_diff = 2; + protected int $port_diff = 2; } diff --git a/src/GameQ/Protocols/Rfactor.php b/src/GameQ/Protocols/Rfactor.php index 296f4c16..78d1e2c2 100644 --- a/src/GameQ/Protocols/Rfactor.php +++ b/src/GameQ/Protocols/Rfactor.php @@ -29,15 +29,11 @@ class Rfactor extends Source { /** * String name of this protocol class - * - * @type string */ - protected $name = 'rfactor'; + protected string $name = 'rfactor'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "rFactor"; + protected string $name_long = "rFactor"; } diff --git a/src/GameQ/Protocols/Rfactor2.php b/src/GameQ/Protocols/Rfactor2.php index 22a0c085..bee9f996 100644 --- a/src/GameQ/Protocols/Rfactor2.php +++ b/src/GameQ/Protocols/Rfactor2.php @@ -29,15 +29,11 @@ class Rfactor2 extends Source { /** * String name of this protocol class - * - * @type string */ - protected $name = 'rfactor2'; + protected string $name = 'rfactor2'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "rFactor2"; + protected string $name_long = "rFactor2"; } diff --git a/src/GameQ/Protocols/Risingstorm2.php b/src/GameQ/Protocols/Risingstorm2.php index ddb82a53..feb4a4e0 100644 --- a/src/GameQ/Protocols/Risingstorm2.php +++ b/src/GameQ/Protocols/Risingstorm2.php @@ -29,26 +29,18 @@ class Risingstorm2 extends Source /** * String name of this protocol class - * - * @type string */ - protected $name = 'rising storm 2'; + protected string $name = 'rising storm 2'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Rising Storm 2"; + protected string $name_long = "Rising Storm 2"; /** * Query port is always 27015 - * - * @param int $clientPort - * - * @return int */ - public function findQueryPort($clientPort) + public function findQueryPort(int $clientPort): int { return 27015; } diff --git a/src/GameQ/Protocols/Rust.php b/src/GameQ/Protocols/Rust.php index 356cc19f..fc0bcbac 100644 --- a/src/GameQ/Protocols/Rust.php +++ b/src/GameQ/Protocols/Rust.php @@ -31,22 +31,16 @@ class Rust extends Source /** * String name of this protocol class - * - * @type string */ - protected $name = 'rust'; + protected string $name = 'rust'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Rust"; + protected string $name_long = "Rust"; /** * Overload so we can get max players from mp of keywords and num players from cp keyword - * - * @param Buffer $buffer */ protected function processDetails(Buffer $buffer) { diff --git a/src/GameQ/Protocols/Samp.php b/src/GameQ/Protocols/Samp.php index a6e63347..7c39ca3c 100644 --- a/src/GameQ/Protocols/Samp.php +++ b/src/GameQ/Protocols/Samp.php @@ -38,10 +38,8 @@ class Samp extends Protocol /** * Array of packets we want to look up. * Each key should correspond to a defined method in this or a parent class - * - * @type array */ - protected $packets = [ + protected array $packets = [ self::PACKET_STATUS => "SAMP%si", self::PACKET_PLAYERS => "SAMP%sd", self::PACKET_RULES => "SAMP%sr", @@ -50,9 +48,8 @@ class Samp extends Protocol /** * Use the response flag to figure out what method to run * - * @type array */ - protected $responses = [ + protected array $responses = [ "\x69" => "processStatus", // i "\x64" => "processPlayers", // d "\x72" => "processRules", // r @@ -60,45 +57,33 @@ class Samp extends Protocol /** * The query protocol used to make the call - * - * @type string */ - protected $protocol = 'samp'; + protected string $protocol = 'samp'; /** * String name of this protocol class - * - * @type string */ - protected $name = 'samp'; + protected string $name = 'samp'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "San Andreas Multiplayer"; + protected string $name_long = "San Andreas Multiplayer"; /** * Holds the calculated server code that is passed when querying for information - * - * @type string */ - protected $server_code = null; + protected ?string $server_code = null; /** * The client join link - * - * @type string */ - protected $join_link = "samp://%s:%d/"; + protected ?string $join_link = "samp://%s:%d/"; /** * Normalize settings for this protocol - * - * @type array */ - protected $normalize = [ + protected array $normalize = [ // General 'general' => [ // target => source @@ -119,10 +104,8 @@ class Samp extends Protocol /** * Handle some work before sending the packets out to the server - * - * @param \GameQ\Server $server */ - public function beforeSend(Server $server) + public function beforeSend(Server $server): void { // Build the server code $ipNumbers = array_map('intval', explode('.', $server->ip())); @@ -139,10 +122,10 @@ public function beforeSend(Server $server) /** * Process the response * - * @return array + * @return mixed * @throws \GameQ\Exception\Protocol */ - public function processResponse() + public function processResponse(): mixed { // Results that will be returned @@ -167,7 +150,7 @@ public function processResponse() } // Figure out what packet response this is for - $response_type = $buffer->read(1); + $response_type = $buffer->read(); // Figure out which packet response this is if (!array_key_exists($response_type, $this->responses)) { @@ -193,8 +176,6 @@ public function processResponse() /** * Handles processing the server status data * - * @param \GameQ\Buffer $buffer - * * @return array * @throws \GameQ\Exception\Protocol */ @@ -223,8 +204,6 @@ protected function processStatus(Buffer $buffer) /** * Handles processing the player data into a usable format * - * @param \GameQ\Buffer $buffer - * * @return array */ protected function processPlayers(Buffer $buffer) @@ -250,8 +229,6 @@ protected function processPlayers(Buffer $buffer) /** * Handles processing the rules data into a usable format * - * @param \GameQ\Buffer $buffer - * * @return array */ protected function processRules(Buffer $buffer) diff --git a/src/GameQ/Protocols/Sco.php b/src/GameQ/Protocols/Sco.php index a920fbd8..564a960f 100644 --- a/src/GameQ/Protocols/Sco.php +++ b/src/GameQ/Protocols/Sco.php @@ -29,22 +29,16 @@ class Sco extends Source { /** * Sven Co-op protocol class - * - * @type string */ - protected $name = 'sco'; + protected string $name = 'sco'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Sven Co-op"; + protected string $name_long = "Sven Co-op"; /** * query_port = client_port + 1 - * - * @type int */ - protected $port_diff = 1; + protected int $port_diff = 1; } diff --git a/src/GameQ/Protocols/Serioussam.php b/src/GameQ/Protocols/Serioussam.php index 64a03cf7..5a192866 100644 --- a/src/GameQ/Protocols/Serioussam.php +++ b/src/GameQ/Protocols/Serioussam.php @@ -28,31 +28,23 @@ class Serioussam extends Gamespy /** * String name of this protocol class - * - * @type string */ - protected $name = 'serioussam'; + protected string $name = 'serioussam'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Serious Sam"; + protected string $name_long = "Serious Sam"; /** * query_port = client_port + 1 - * - * @type int */ - protected $port_diff = 1; + protected int $port_diff = 1; /** * Normalize settings for this protocol - * - * @type array */ - protected $normalize = [ + protected array $normalize = [ // General 'general' => [ // target => source diff --git a/src/GameQ/Protocols/Sevendaystodie.php b/src/GameQ/Protocols/Sevendaystodie.php index 8919b97f..d6ecf9f2 100644 --- a/src/GameQ/Protocols/Sevendaystodie.php +++ b/src/GameQ/Protocols/Sevendaystodie.php @@ -28,22 +28,16 @@ class Sevendaystodie extends Source { /** * String name of this protocol class - * - * @type string */ - protected $name = 'sevendaystodie'; + protected string $name = 'sevendaystodie'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "7 Days to Die"; + protected string $name_long = "7 Days to Die"; /** * query_port = client_port + 0 - * - * @type int */ - protected $port_diff = 0; + protected int $port_diff = 0; } diff --git a/src/GameQ/Protocols/Ship.php b/src/GameQ/Protocols/Ship.php index e4ad6ca9..a9507ff3 100644 --- a/src/GameQ/Protocols/Ship.php +++ b/src/GameQ/Protocols/Ship.php @@ -34,24 +34,19 @@ class Ship extends Source /** * String name of this protocol class - * - * @type string */ - protected $name = 'ship'; + protected string $name = 'ship'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "The Ship"; + protected string $name_long = "The Ship"; /** * Specific player parse for The Ship * * Player response has unknown data after the last real player - * - * @param \GameQ\Buffer $buffer + * * @return array */ diff --git a/src/GameQ/Protocols/Sof2.php b/src/GameQ/Protocols/Sof2.php index 96a4db25..34821fac 100644 --- a/src/GameQ/Protocols/Sof2.php +++ b/src/GameQ/Protocols/Sof2.php @@ -28,22 +28,16 @@ class Sof2 extends Quake3 { /** * String name of this protocol class - * - * @type string */ - protected $name = 'sof2'; + protected string $name = 'sof2'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Solder of Fortune II"; + protected string $name_long = "Solder of Fortune II"; /** * The client join link - * - * @type string */ - protected $join_link = "sof2mp://%s:%d/"; + protected ?string $join_link = "sof2mp://%s:%d/"; } diff --git a/src/GameQ/Protocols/Soldat.php b/src/GameQ/Protocols/Soldat.php index a9dbbc4e..68fc9086 100644 --- a/src/GameQ/Protocols/Soldat.php +++ b/src/GameQ/Protocols/Soldat.php @@ -31,29 +31,21 @@ class Soldat extends Ase /** * String name of this protocol class - * - * @type string */ - protected $name = 'soldat'; + protected string $name = 'soldat'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Soldat"; + protected string $name_long = "Soldat"; /** * query_port = client_port + 123 - * - * @type int */ - protected $port_diff = 123; + protected int $port_diff = 123; /** * The client join link - * - * @type string */ - protected $join_link = "soldat://%s:%d/"; + protected ?string $join_link = "soldat://%s:%d/"; } diff --git a/src/GameQ/Protocols/Source.php b/src/GameQ/Protocols/Source.php index c80d271d..e0ebe71c 100644 --- a/src/GameQ/Protocols/Source.php +++ b/src/GameQ/Protocols/Source.php @@ -37,16 +37,14 @@ class Source extends Protocol /* * Source engine type constants */ - const SOURCE_ENGINE = 0, - GOLDSOURCE_ENGINE = 1; + public const SOURCE_ENGINE = 0; + public const GOLDSOURCE_ENGINE = 1; /** * Array of packets we want to look up. * Each key should correspond to a defined method in this or a parent class - * - * @type array */ - protected $packets = [ + protected array $packets = [ self::PACKET_CHALLENGE => "\xFF\xFF\xFF\xFF\x56\x00\x00\x00\x00", self::PACKET_DETAILS => "\xFF\xFF\xFF\xFFTSource Engine Query\x00%s", self::PACKET_PLAYERS => "\xFF\xFF\xFF\xFF\x55%s", @@ -56,9 +54,8 @@ class Source extends Protocol /** * Use the response flag to figure out what method to run * - * @type array */ - protected $responses = [ + protected array $responses = [ "\x49" => "processDetails", // I "\x6d" => "processDetailsGoldSource", // m, goldsource "\x44" => "processPlayers", // D @@ -67,45 +64,33 @@ class Source extends Protocol /** * The query protocol used to make the call - * - * @type string */ - protected $protocol = 'source'; + protected string $protocol = 'source'; /** * String name of this protocol class - * - * @type string */ - protected $name = 'source'; + protected string $name = 'source'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Source Server"; + protected string $name_long = "Source Server"; /** * Define the Source engine type. By default it is assumed to be Source - * - * @type int */ - protected $source_engine = self::SOURCE_ENGINE; + protected int $source_engine = self::SOURCE_ENGINE; /** * The client join link - * - * @type string */ - protected $join_link = "steam://connect/%s:%d/"; + protected ?string $join_link = "steam://connect/%s:%d/"; /** * Normalize settings for this protocol - * - * @type array */ - protected $normalize = [ + protected array $normalize = [ // General 'general' => [ // target => source @@ -129,12 +114,9 @@ class Source extends Protocol /** * Parse the challenge response and apply it to all the packet types * - * @param \GameQ\Buffer $challenge_buffer - * - * @return bool * @throws \GameQ\Exception\Protocol */ - public function challengeParseAndApply(Buffer $challenge_buffer) + public function challengeParseAndApply(Buffer $challenge_buffer): bool { // Skip the header @@ -147,10 +129,10 @@ public function challengeParseAndApply(Buffer $challenge_buffer) /** * Process the response * - * @return array + * @return mixed * @throws \GameQ\Exception\Protocol */ - public function processResponse() + public function processResponse(): mixed { // Will hold the results when complete $results = []; @@ -168,7 +150,7 @@ public function processResponse() // Single packet if ($header === -1) { // We need to peek and see what kind of engine this is for later processing - if ($buffer->lookAhead(1) === "\x6d") { + if ($buffer->lookAhead() === "\x6d") { $this->source_engine = self::GOLDSOURCE_ENGINE; } @@ -197,7 +179,7 @@ public function processResponse() } // Figure out what packet response this is for - $response_type = $buffer->read(1); + $response_type = $buffer->read(); // Figure out which packet response this is if (!array_key_exists($response_type, $this->responses)) { @@ -244,12 +226,12 @@ protected function processPackets($packet_id, array $packets = []) $buffer = new Buffer($packet); // Gold source - if ($this->source_engine == self::GOLDSOURCE_ENGINE) { + if ($this->source_engine === self::GOLDSOURCE_ENGINE) { // Grab the packet number (byte) $packet_number = $buffer->readInt8(); // We need to burn the extra header (\xFF\xFF\xFF\xFF) on first loop - if ($i == 0) { + if ($i === 0) { $buffer->read(4); } @@ -267,12 +249,10 @@ protected function processPackets($packet_id, array $packets = []) if ($packet_id & 0x80000000) { // Check to see if we have Bzip2 installed if (!function_exists('bzdecompress')) { - // @codeCoverageIgnoreStart throw new Exception( 'Bzip2 is not installed. See http://www.php.net/manual/en/book.bzip2.php for more info.', 0 ); - // @codeCoverageIgnoreEnd } // Get the length of the packet (long) @@ -286,12 +266,10 @@ protected function processPackets($packet_id, array $packets = []) // Now verify the length if (strlen($result) !== $packet_length) { - // @codeCoverageIgnoreStart throw new Exception( "Checksum for compressed packet failed! Length expected: $packet_length, length returned: " . strlen($result) ); - // @codeCoverageIgnoreEnd } // We need to burn the extra header (\xFF\xFF\xFF\xFF) on first loop @@ -328,8 +306,6 @@ protected function processPackets($packet_id, array $packets = []) /** * Handles processing the details data into a usable format * - * @param \GameQ\Buffer $buffer - * * @return mixed * @throws \GameQ\Exception\Protocol */ @@ -354,7 +330,7 @@ protected function processDetails(Buffer $buffer) $result->add('secure', $buffer->readInt8()); // Special result for The Ship only (appid=2400) - if ($result->get('steamappid') == 2400) { + if ($result->get('steamappid') === 2400) { $result->add('game_mode', $buffer->readInt8()); $result->add('witness_count', $buffer->readInt8()); $result->add('witness_time', $buffer->readInt8()); @@ -363,7 +339,7 @@ protected function processDetails(Buffer $buffer) $result->add('version', $buffer->readString()); // Because of php 5.4... - $edfCheck = $buffer->lookAhead(1); + $edfCheck = $buffer->lookAhead(); // Extra data flag if (!empty($edfCheck)) { @@ -398,8 +374,7 @@ protected function processDetails(Buffer $buffer) /** * Handles processing the server details from goldsource response - * - * @param \GameQ\Buffer $buffer + * * @return array * @throws \GameQ\Exception\Protocol @@ -426,7 +401,7 @@ protected function processDetailsGoldSource(Buffer $buffer) $result->add('ismod', $buffer->readInt8()); // We only run these if ismod is 1 (true) - if ($result->get('ismod') == 1) { + if ($result->get('ismod') === 1) { $result->add('mod_urlinfo', $buffer->readString()); $result->add('mod_urldl', $buffer->readString()); $buffer->skip(); @@ -445,9 +420,7 @@ protected function processDetailsGoldSource(Buffer $buffer) /** * Handles processing the player data into a usable format * - * @param \GameQ\Buffer $buffer - * - * @return mixed + * @return array */ protected function processPlayers(Buffer $buffer) { @@ -462,7 +435,7 @@ protected function processPlayers(Buffer $buffer) $result->add('num_players', $num_players); // No players so no need to look any further - if ($num_players == 0) { + if ($num_players === 0) { return $result->fetch(); } @@ -480,9 +453,7 @@ protected function processPlayers(Buffer $buffer) /** * Handles processing the rules data into a usable format * - * @param \GameQ\Buffer $buffer - * - * @return mixed + * @return array */ protected function processRules(Buffer $buffer) { diff --git a/src/GameQ/Protocols/Spaceengineers.php b/src/GameQ/Protocols/Spaceengineers.php index ddf8567d..2c2e04ab 100644 --- a/src/GameQ/Protocols/Spaceengineers.php +++ b/src/GameQ/Protocols/Spaceengineers.php @@ -28,15 +28,11 @@ class Spaceengineers extends Source { /** * String name of this protocol class - * - * @type string */ - protected $name = 'spaceengineers'; + protected string $name = 'spaceengineers'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Space Engineers"; + protected string $name_long = "Space Engineers"; } diff --git a/src/GameQ/Protocols/Squad.php b/src/GameQ/Protocols/Squad.php index 3c021885..d35396eb 100644 --- a/src/GameQ/Protocols/Squad.php +++ b/src/GameQ/Protocols/Squad.php @@ -31,23 +31,17 @@ class Squad extends Source /** * String name of this protocol class - * - * @type string */ - protected $name = 'squad'; + protected string $name = 'squad'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Squad"; + protected string $name_long = "Squad"; /** * query_port = client_port + 19378 * 27165 = 7787 + 19378 - * - * @type int */ - protected $port_diff = 19378; + protected int $port_diff = 19378; } diff --git a/src/GameQ/Protocols/Starmade.php b/src/GameQ/Protocols/Starmade.php index 0f880b8c..7497fc09 100644 --- a/src/GameQ/Protocols/Starmade.php +++ b/src/GameQ/Protocols/Starmade.php @@ -37,54 +37,40 @@ class Starmade extends Protocol /** * Array of packets we want to query. - * - * @type array */ - protected $packets = [ + protected array $packets = [ self::PACKET_STATUS => "\x00\x00\x00\x09\x2a\xff\xff\x01\x6f\x00\x00\x00\x00", ]; /** * The transport mode for this protocol is TCP - * - * @type string - */ - protected $transport = self::TRANSPORT_TCP; + */ + protected string $transport = self::TRANSPORT_TCP; /** * The query protocol used to make the call - * - * @type string */ - protected $protocol = 'starmade'; + protected string $protocol = 'starmade'; /** * String name of this protocol class - * - * @type string */ - protected $name = 'starmade'; + protected string $name = 'starmade'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "StarMade"; + protected string $name_long = "StarMade"; /** * The client join link - * - * @type string */ - protected $join_link = null; + protected ?string $join_link = null; /** * Normalize settings for this protocol - * - * @type array */ - protected $normalize = [ + protected array $normalize = [ // General 'general' => [ // target => source @@ -99,10 +85,10 @@ class Starmade extends Protocol /** * Process the response for the StarMade server * - * @return array + * @return mixed * @throws \GameQ\Exception\Protocol */ - public function processResponse() + public function processResponse(): mixed { // Implode the packets, not sure if there is any split logic for multiple packets @@ -150,8 +136,7 @@ public function processResponse() /** * Parse the server response parameters - * - * @param \GameQ\Buffer $buffer + * * @return array * @throws \GameQ\Exception\Protocol diff --git a/src/GameQ/Protocols/Stormworks.php b/src/GameQ/Protocols/Stormworks.php index 735b5776..9885665e 100644 --- a/src/GameQ/Protocols/Stormworks.php +++ b/src/GameQ/Protocols/Stormworks.php @@ -29,22 +29,16 @@ class Stormworks extends Source { /** * Stormworks protocol class - * - * @type string */ - protected $name = 'stormworks'; + protected string $name = 'stormworks'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Stormworks"; + protected string $name_long = "Stormworks"; /** * query_port = client_port + 1 - * - * @type int */ - protected $port_diff = 1; + protected int $port_diff = 1; } diff --git a/src/GameQ/Protocols/Swat4.php b/src/GameQ/Protocols/Swat4.php index 7b8e1200..2de57e4f 100644 --- a/src/GameQ/Protocols/Swat4.php +++ b/src/GameQ/Protocols/Swat4.php @@ -29,22 +29,16 @@ class Swat4 extends Gamespy2 { /** * String name of this protocol class - * - * @type string */ - protected $name = 'swat4'; + protected string $name = 'swat4'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "SWAT 4"; + protected string $name_long = "SWAT 4"; /** * query_port = client_port + 1 - * - * @type int */ - protected $port_diff = 1; + protected int $port_diff = 1; } diff --git a/src/GameQ/Protocols/Teamspeak2.php b/src/GameQ/Protocols/Teamspeak2.php index b8bdbf31..1787e521 100644 --- a/src/GameQ/Protocols/Teamspeak2.php +++ b/src/GameQ/Protocols/Teamspeak2.php @@ -40,10 +40,8 @@ class Teamspeak2 extends Protocol /** * Array of packets we want to look up. * Each key should correspond to a defined method in this or a parent class - * - * @type array */ - protected $packets = [ + protected array $packets = [ self::PACKET_DETAILS => "sel %d\x0asi\x0a", self::PACKET_CHANNELS => "sel %d\x0acl\x0a", self::PACKET_PLAYERS => "sel %d\x0apl\x0a", @@ -51,45 +49,33 @@ class Teamspeak2 extends Protocol /** * The transport mode for this protocol is TCP - * - * @type string - */ - protected $transport = self::TRANSPORT_TCP; + */ + protected string $transport = self::TRANSPORT_TCP; /** * The query protocol used to make the call - * - * @type string */ - protected $protocol = 'teamspeak2'; + protected string $protocol = 'teamspeak2'; /** * String name of this protocol class - * - * @type string */ - protected $name = 'teamspeak2'; + protected string $name = 'teamspeak2'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Teamspeak 2"; + protected string $name_long = "Teamspeak 2"; /** * The client join link - * - * @type string */ - protected $join_link = "teamspeak://%s:%d/"; + protected ?string $join_link = "teamspeak://%s:%d/"; /** * Normalize settings for this protocol - * - * @type array */ - protected $normalize = [ + protected array $normalize = [ // General 'general' => [ 'dedicated' => 'dedicated', @@ -114,11 +100,9 @@ class Teamspeak2 extends Protocol /** * Before we send off the queries we need to update the packets * - * @param \GameQ\Server $server - * * @throws \GameQ\Exception\Protocol */ - public function beforeSend(Server $server) + public function beforeSend(Server $server): void { // Check to make sure we have a query_port because it is required @@ -138,10 +122,10 @@ public function beforeSend(Server $server) /** * Process the response * - * @return array + * @return mixed * @throws \GameQ\Exception\Protocol */ - public function processResponse() + public function processResponse(): mixed { // Make a new buffer out of all of the packets @@ -153,7 +137,7 @@ public function processResponse() } // Split this buffer as the data blocks are bound by "OK" and drop any empty values - $sections = array_filter(explode("OK", $buffer->getBuffer()), function ($value) { + $sections = array_filter(explode("OK", $buffer->getBuffer()), static function ($value) { $value = trim($value); @@ -172,13 +156,13 @@ public function processResponse() $check = substr($section, 0, 7); // Offload to the proper method - if ($check == 'server_') { + if ($check === 'server_') { // Server settings and info $this->processDetails($section, $result); - } elseif ($check == "id\tcode") { + } elseif ($check === "id\tcode") { // Channel info $this->processChannels($section, $result); - } elseif ($check == "p_id\tc_") { + } elseif ($check === "p_id\tc_") { // Player info $this->processPlayers($section, $result); } @@ -196,13 +180,9 @@ public function processResponse() /** * Handles processing the details data into a usable format - * - * @param string $data - * @param \GameQ\Result $result */ - protected function processDetails($data, Result $result) + protected function processDetails(string $data, Result $result) { - // Create a buffer $buffer = new Buffer($data); @@ -221,16 +201,13 @@ protected function processDetails($data, Result $result) $result->add($key, $this->convertToUtf8($value)); } - unset($data, $buffer, $row, $key, $value); + unset($buffer, $row, $key, $value); } /** * Process the channel listing - * - * @param string $data - * @param \GameQ\Result $result */ - protected function processChannels($data, Result $result) + protected function processChannels(string $data, Result $result) { // Create a buffer @@ -253,16 +230,13 @@ protected function processChannels($data, Result $result) } } - unset($data, $buffer, $row, $columns, $key, $value); + unset($buffer, $row, $columns, $key, $value); } /** * Process the user listing - * - * @param string $data - * @param \GameQ\Result $result */ - protected function processPlayers($data, Result $result) + protected function processPlayers(string $data, Result $result) { // Create a buffer @@ -285,6 +259,6 @@ protected function processPlayers($data, Result $result) } } - unset($data, $buffer, $row, $columns, $key, $value); + unset($buffer, $row, $columns, $key, $value); } } diff --git a/src/GameQ/Protocols/Teamspeak3.php b/src/GameQ/Protocols/Teamspeak3.php index fd565b4f..e26ace52 100644 --- a/src/GameQ/Protocols/Teamspeak3.php +++ b/src/GameQ/Protocols/Teamspeak3.php @@ -40,10 +40,8 @@ class Teamspeak3 extends Protocol /** * Array of packets we want to look up. * Each key should correspond to a defined method in this or a parent class - * - * @type array */ - protected $packets = [ + protected array $packets = [ self::PACKET_DETAILS => "use port=%d\x0Aserverinfo\x0A", self::PACKET_PLAYERS => "use port=%d\x0Aclientlist\x0A", self::PACKET_CHANNELS => "use port=%d\x0Achannellist -topic\x0A", @@ -51,45 +49,33 @@ class Teamspeak3 extends Protocol /** * The transport mode for this protocol is TCP - * - * @type string - */ - protected $transport = self::TRANSPORT_TCP; + */ + protected string $transport = self::TRANSPORT_TCP; /** * The query protocol used to make the call - * - * @type string */ - protected $protocol = 'teamspeak3'; + protected string $protocol = 'teamspeak3'; /** * String name of this protocol class - * - * @type string */ - protected $name = 'teamspeak3'; + protected string $name = 'teamspeak3'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Teamspeak 3"; + protected string $name_long = "Teamspeak 3"; /** * The client join link - * - * @type string */ - protected $join_link = "ts3server://%s?port=%d"; + protected ?string $join_link = "ts3server://%s?port=%d"; /** * Normalize settings for this protocol - * - * @type array */ - protected $normalize = [ + protected array $normalize = [ // General 'general' => [ 'dedicated' => 'dedicated', @@ -114,11 +100,9 @@ class Teamspeak3 extends Protocol /** * Before we send off the queries we need to update the packets * - * @param \GameQ\Server $server - * * @throws \GameQ\Exception\Protocol */ - public function beforeSend(Server $server) + public function beforeSend(Server $server): void { // Check to make sure we have a query_port because it is required @@ -138,10 +122,10 @@ public function beforeSend(Server $server) /** * Process the response * - * @return array + * @return mixed * @throws \GameQ\Exception\Protocol */ - public function processResponse() + public function processResponse(): mixed { // Make a new buffer out of all of the packets @@ -166,7 +150,7 @@ public function processResponse() ); // Explode the sections and filter to remove empty, junk ones - $sections = array_filter(explode("\n", $raw), function ($value) { + $sections = array_filter(explode("\n", $raw), static function ($value) { $value = trim($value); @@ -186,13 +170,13 @@ public function processResponse() $check = substr(trim($section), 0, 4); // Use the first part of the response to figure out where we need to go - if ($check == 'virt') { + if ($check === 'virt') { // Server info $this->processDetails($section, $result); - } elseif ($check == 'cid=') { + } elseif ($check === 'cid=') { // Channels $this->processChannels($section, $result); - } elseif ($check == 'clid') { + } elseif ($check === 'clid') { // Clients (players) $this->processPlayers($section, $result); } @@ -247,11 +231,8 @@ protected function processProperties($data) /** * Handles processing the details data into a usable format - * - * @param string $data - * @param \GameQ\Result $result */ - protected function processDetails($data, Result $result) + protected function processDetails(string $data, Result $result) { // Offload the parsing for these values @@ -271,16 +252,13 @@ protected function processDetails($data, Result $result) ($properties['virtualserver_clientsonline'] - $properties['virtualserver_queryclientsonline']) ); - unset($data, $properties, $key, $value); + unset($properties, $key, $value); } /** * Process the channel listing - * - * @param string $data - * @param \GameQ\Result $result */ - protected function processChannels($data, Result $result) + protected function processChannels(string $data, Result $result) { // We need to split the data at the pipe @@ -297,16 +275,13 @@ protected function processChannels($data, Result $result) } } - unset($data, $channel, $channels, $properties, $key, $value); + unset($channels, $properties, $key); } /** * Process the user listing - * - * @param string $data - * @param \GameQ\Result $result */ - protected function processPlayers($data, Result $result) + protected function processPlayers(string $data, Result $result) { // We need to split the data at the pipe @@ -323,6 +298,6 @@ protected function processPlayers($data, Result $result) } } - unset($data, $player, $players, $properties, $key, $value); + unset($players, $properties, $key); } } diff --git a/src/GameQ/Protocols/Teeworlds.php b/src/GameQ/Protocols/Teeworlds.php index 75e52d1d..c512ca08 100644 --- a/src/GameQ/Protocols/Teeworlds.php +++ b/src/GameQ/Protocols/Teeworlds.php @@ -37,10 +37,8 @@ class Teeworlds extends Protocol /** * Array of packets we want to look up. * Each key should correspond to a defined method in this or a parent class - * - * @type array */ - protected $packets = [ + protected array $packets = [ self::PACKET_ALL => "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x67\x69\x65\x33\x05", // 0.5 Packet (not compatible, maybe some wants to implement "Teeworldsold") //self::PACKET_STATUS => "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFFgief", @@ -49,46 +47,35 @@ class Teeworlds extends Protocol /** * Use the response flag to figure out what method to run * - * @type array */ - protected $responses = [ + protected array $responses = [ "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xffinf35" => "processAll", ]; /** * The query protocol used to make the call - * - * @type string */ - protected $protocol = 'teeworlds'; + protected string $protocol = 'teeworlds'; /** * String name of this protocol class - * - * @type string */ - protected $name = 'teeworlds'; + protected string $name = 'teeworlds'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Teeworlds Server"; + protected string $name_long = "Teeworlds Server"; /** * The client join link - * - * @type string */ - protected $join_link = "steam://connect/%s:%d/"; + protected ?string $join_link = "steam://connect/%s:%d/"; /** * Normalize settings for this protocol - * - * @type array */ - protected $normalize = [ + protected array $normalize = [ // General 'general' => [ // target => source @@ -107,10 +94,10 @@ class Teeworlds extends Protocol /** * Process the response * - * @return array + * @return mixed * @throws Exception */ - public function processResponse() + public function processResponse(): mixed { // Holds the results $results = []; @@ -143,8 +130,6 @@ public function processResponse() /** * Handle processing all of the data returned * - * @param Buffer $buffer - * * @return array */ protected function processAll(Buffer $buffer) diff --git a/src/GameQ/Protocols/Terraria.php b/src/GameQ/Protocols/Terraria.php index d9455ef5..717de08d 100644 --- a/src/GameQ/Protocols/Terraria.php +++ b/src/GameQ/Protocols/Terraria.php @@ -30,30 +30,22 @@ class Terraria extends Tshock /** * String name of this protocol class - * - * @type string */ - protected $name = 'terraria'; + protected string $name = 'terraria'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Terraria"; + protected string $name_long = "Terraria"; /** * query_port = client_port + 101 * 7878 = 7777 + 101 - * - * @type int */ - protected $port_diff = 101; + protected int $port_diff = 101; /** * The client join link - * - * @type string */ - protected $join_link = "steam://connect/%s:%d/"; + protected ?string $join_link = "steam://connect/%s:%d/"; } diff --git a/src/GameQ/Protocols/Tf2.php b/src/GameQ/Protocols/Tf2.php index e08411b7..15fd864b 100644 --- a/src/GameQ/Protocols/Tf2.php +++ b/src/GameQ/Protocols/Tf2.php @@ -28,15 +28,11 @@ class Tf2 extends Source { /** * String name of this protocol class - * - * @type string */ - protected $name = 'tf2'; + protected string $name = 'tf2'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Team Fortress 2"; + protected string $name_long = "Team Fortress 2"; } diff --git a/src/GameQ/Protocols/Theforrest.php b/src/GameQ/Protocols/Theforrest.php index 975c3f6f..6b591020 100644 --- a/src/GameQ/Protocols/Theforrest.php +++ b/src/GameQ/Protocols/Theforrest.php @@ -29,22 +29,16 @@ class Theforrest extends Source /** * String name of this protocol class - * - * @type string */ - protected $name = 'theforrest'; + protected string $name = 'theforrest'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "The Forrest"; + protected string $name_long = "The Forrest"; /** * query_port = client_port + 1 - * - * @type int */ - protected $port_diff = 1; + protected int $port_diff = 1; } diff --git a/src/GameQ/Protocols/Tibia.php b/src/GameQ/Protocols/Tibia.php index 9f9a0461..462a4440 100644 --- a/src/GameQ/Protocols/Tibia.php +++ b/src/GameQ/Protocols/Tibia.php @@ -37,54 +37,40 @@ class Tibia extends Protocol /** * Array of packets we want to query. - * - * @type array */ - protected $packets = [ + protected array $packets = [ self::PACKET_STATUS => "\x06\x00\xFF\xFF\x69\x6E\x66\x6F", ]; /** * The transport mode for this protocol is TCP - * - * @type string - */ - protected $transport = self::TRANSPORT_TCP; + */ + protected string $transport = self::TRANSPORT_TCP; /** * The query protocol used to make the call - * - * @type string */ - protected $protocol = 'tibia'; + protected string $protocol = 'tibia'; /** * String name of this protocol class - * - * @type string */ - protected $name = 'tibia'; + protected string $name = 'tibia'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Tibia"; + protected string $name_long = "Tibia"; /** * The client join link - * - * @type string */ - protected $join_link = "otserv://%s/%d/"; + protected ?string $join_link = "otserv://%s/%d/"; /** * Normalize settings for this protocol - * - * @type array */ - protected $normalize = [ + protected array $normalize = [ // General 'general' => [ // target => source @@ -101,10 +87,10 @@ class Tibia extends Protocol /** * Process the response for the Tibia server * - * @return array + * @return mixed * @throws \GameQ\Exception\Protocol */ - public function processResponse() + public function processResponse(): mixed { // Merge the response packets $xmlString = implode('', $this->packets_response); diff --git a/src/GameQ/Protocols/Tshock.php b/src/GameQ/Protocols/Tshock.php index 0b9f9157..684fcdcc 100644 --- a/src/GameQ/Protocols/Tshock.php +++ b/src/GameQ/Protocols/Tshock.php @@ -40,37 +40,32 @@ class Tshock extends Http * * @var array */ - protected $packets = [ + protected array $packets = [ self::PACKET_STATUS => "GET /v2/server/status?players=true&rules=true HTTP/1.0\r\nAccept: */*\r\n\r\n", ]; /** * The protocol being used * - * @var string */ - protected $protocol = 'tshock'; + protected string $protocol = 'tshock'; /** * String name of this protocol class * - * @var string */ - protected $name = 'tshock'; + protected string $name = 'tshock'; /** * Longer string name of this protocol class * - * @var string */ - protected $name_long = "Tshock"; + protected string $name_long = "Tshock"; /** * Normalize some items - * - * @var array */ - protected $normalize = [ + protected array $normalize = [ // General 'general' => [ // target => source @@ -91,10 +86,10 @@ class Tshock extends Http /** * Process the response * - * @return array + * @return mixed * @throws Exception */ - public function processResponse() + public function processResponse(): mixed { if (empty($this->packets_response)) { return []; diff --git a/src/GameQ/Protocols/Unreal2.php b/src/GameQ/Protocols/Unreal2.php index a26aca03..4642ac3a 100644 --- a/src/GameQ/Protocols/Unreal2.php +++ b/src/GameQ/Protocols/Unreal2.php @@ -34,10 +34,8 @@ class Unreal2 extends Protocol /** * Array of packets we want to look up. * Each key should correspond to a defined method in this or a parent class - * - * @type array */ - protected $packets = [ + protected array $packets = [ self::PACKET_DETAILS => "\x79\x00\x00\x00\x00", self::PACKET_RULES => "\x79\x00\x00\x00\x01", self::PACKET_PLAYERS => "\x79\x00\x00\x00\x02", @@ -46,9 +44,8 @@ class Unreal2 extends Protocol /** * Use the response flag to figure out what method to run * - * @type array */ - protected $responses = [ + protected array $responses = [ "\x80\x00\x00\x00\x00" => "processDetails", // 0 "\x80\x00\x00\x00\x01" => "processRules", // 1 "\x80\x00\x00\x00\x02" => "processPlayers", // 2 @@ -56,31 +53,23 @@ class Unreal2 extends Protocol /** * The query protocol used to make the call - * - * @type string */ - protected $protocol = 'unreal2'; + protected string $protocol = 'unreal2'; /** * String name of this protocol class - * - * @type string */ - protected $name = 'unreal2'; + protected string $name = 'unreal2'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Unreal 2"; + protected string $name_long = "Unreal 2"; /** * Normalize settings for this protocol - * - * @type array */ - protected $normalize = [ + protected array $normalize = [ // General 'general' => [ // target => source @@ -102,10 +91,10 @@ class Unreal2 extends Protocol /** * Process the response * - * @return array + * @return mixed * @throws \GameQ\Exception\Protocol */ - public function processResponse() + public function processResponse(): mixed { // Will hold the packets after sorting @@ -151,10 +140,9 @@ public function processResponse() /** * Handles processing the details data into a usable format + * - * @param \GameQ\Buffer $buffer - * - * @return mixed + * @return array * @throws \GameQ\Exception\Protocol */ protected function processDetails(Buffer $buffer) @@ -179,10 +167,9 @@ protected function processDetails(Buffer $buffer) /** * Handles processing the player data into a usable format + * - * @param \GameQ\Buffer $buffer - * - * @return mixed + * @return array */ protected function processPlayers(Buffer $buffer) { @@ -213,9 +200,7 @@ protected function processPlayers(Buffer $buffer) /** * Handles processing the rules data into a usable format * - * @param \GameQ\Buffer $buffer - * - * @return mixed + * @return array */ protected function processRules(Buffer $buffer) { diff --git a/src/GameQ/Protocols/Unturned.php b/src/GameQ/Protocols/Unturned.php index 4829b37a..d7de41a2 100644 --- a/src/GameQ/Protocols/Unturned.php +++ b/src/GameQ/Protocols/Unturned.php @@ -28,22 +28,16 @@ class Unturned extends Source { /** * String name of this protocol class - * - * @type string */ - protected $name = 'unturned'; + protected string $name = 'unturned'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Unturned"; + protected string $name_long = "Unturned"; /** * query_port = client_port + 1 - * - * @type int */ - protected $port_diff = 1; + protected int $port_diff = 1; } diff --git a/src/GameQ/Protocols/Urbanterror.php b/src/GameQ/Protocols/Urbanterror.php index 682f91e6..1400fc3a 100644 --- a/src/GameQ/Protocols/Urbanterror.php +++ b/src/GameQ/Protocols/Urbanterror.php @@ -28,22 +28,16 @@ class Urbanterror extends Quake3 { /** * String name of this protocol class - * - * @type string */ - protected $name = 'urbanterror'; + protected string $name = 'urbanterror'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Urban Terror"; + protected string $name_long = "Urban Terror"; /** * The client join link - * - * @type string */ - protected $join_link = "urt://%s:%d/"; + protected ?string $join_link = "urt://%s:%d/"; } diff --git a/src/GameQ/Protocols/Ut.php b/src/GameQ/Protocols/Ut.php index 75722ce1..0f385e79 100644 --- a/src/GameQ/Protocols/Ut.php +++ b/src/GameQ/Protocols/Ut.php @@ -28,31 +28,23 @@ class Ut extends Gamespy /** * String name of this protocol class - * - * @type string */ - protected $name = 'ut'; + protected string $name = 'ut'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Unreal Tournament"; + protected string $name_long = "Unreal Tournament"; /** * query_port = client_port + 1 - * - * @type int */ - protected $port_diff = 1; + protected int $port_diff = 1; /** * Normalize settings for this protocol - * - * @type array */ - protected $normalize = [ + protected array $normalize = [ // General 'general' => [ // target => source diff --git a/src/GameQ/Protocols/Ut2004.php b/src/GameQ/Protocols/Ut2004.php index 953089f9..b87bec36 100644 --- a/src/GameQ/Protocols/Ut2004.php +++ b/src/GameQ/Protocols/Ut2004.php @@ -28,15 +28,11 @@ class Ut2004 extends Unreal2 /** * String name of this protocol class - * - * @type string */ - protected $name = 'ut2004'; + protected string $name = 'ut2004'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Unreal Tournament 2004"; + protected string $name_long = "Unreal Tournament 2004"; } diff --git a/src/GameQ/Protocols/Ut3.php b/src/GameQ/Protocols/Ut3.php index b55cc340..0e174fb6 100644 --- a/src/GameQ/Protocols/Ut3.php +++ b/src/GameQ/Protocols/Ut3.php @@ -32,24 +32,18 @@ class Ut3 extends Gamespy3 /** * String name of this protocol class - * - * @type string */ - protected $name = 'ut3'; + protected string $name = 'ut3'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Unreal Tournament 3"; + protected string $name_long = "Unreal Tournament 3"; /** * Normalize settings for this protocol - * - * @type array */ - protected $normalize = [ + protected array $normalize = [ // General 'general' => [ 'dedicated' => 'bIsDedicated', @@ -61,13 +55,12 @@ class Ut3 extends Gamespy3 /** * Overload the response process so we can make some changes * - * @return array + * @return mixed */ - public function processResponse() + public function processResponse(): mixed { // Grab the result from the parent - /** @type array $result */ $result = parent::processResponse(); // Move some stuff around @@ -102,12 +95,8 @@ public function processResponse() /** * Dirty hack to rename result entries into something more useful - * - * @param array $result - * @param string $old - * @param string $new */ - protected function renameResult(array &$result, $old, $new) + protected function renameResult(array &$result, string $old, string $new): void { // Check to see if the old item is there @@ -119,11 +108,8 @@ protected function renameResult(array &$result, $old, $new) /** * Dirty hack to delete result items - * - * @param array $result - * @param array $array */ - protected function deleteResult(array &$result, array $array) + protected function deleteResult(array &$result, array $array): void { foreach ($array as $key) { diff --git a/src/GameQ/Protocols/Valheim.php b/src/GameQ/Protocols/Valheim.php index 18469229..2679ea6a 100644 --- a/src/GameQ/Protocols/Valheim.php +++ b/src/GameQ/Protocols/Valheim.php @@ -27,22 +27,16 @@ class Valheim extends Source { /** * String name of this protocol class - * - * @type string */ - protected $name = 'valheim'; + protected string $name = 'valheim'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Valheim"; + protected string $name_long = "Valheim"; /** * query_port = client_port + 1 - * - * @type int */ - protected $port_diff = 1; + protected int $port_diff = 1; } diff --git a/src/GameQ/Protocols/Ventrilo.php b/src/GameQ/Protocols/Ventrilo.php index ee3b38ed..7f112a68 100644 --- a/src/GameQ/Protocols/Ventrilo.php +++ b/src/GameQ/Protocols/Ventrilo.php @@ -40,48 +40,36 @@ class Ventrilo extends Protocol /** * Array of packets we want to look up. * Each key should correspond to a defined method in this or a parent class - * - * @type array */ - protected $packets = [ + protected array $packets = [ self::PACKET_ALL => "V\xc8\xf4\xf9`\xa2\x1e\xa5M\xfb\x03\xccQN\xa1\x10\x95\xaf\xb2g\x17g\x812\xfbW\xfd\x8e\xd2\x22r\x034z\xbb\x98", ]; /** * The query protocol used to make the call - * - * @type string */ - protected $protocol = 'ventrilo'; + protected string $protocol = 'ventrilo'; /** * String name of this protocol class - * - * @type string */ - protected $name = 'ventrilo'; + protected string $name = 'ventrilo'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Ventrilo"; + protected string $name_long = "Ventrilo"; /** * The client join link - * - * @type string */ - protected $join_link = "ventrilo://%s:%d/"; + protected ?string $join_link = "ventrilo://%s:%d/"; /** * Normalize settings for this protocol - * - * @type array */ - protected $normalize = [ + protected array $normalize = [ // General 'general' => [ 'dedicated' => 'dedicated', @@ -633,10 +621,10 @@ class Ventrilo extends Protocol /** * Process the response * - * @return array + * @return mixed * @throws \GameQ\Exception\Protocol */ - public function processResponse() + public function processResponse(): mixed { // We need to decrypt the packets @@ -645,7 +633,7 @@ public function processResponse() // Now let us convert special characters from hex to ascii all at once $decrypted = preg_replace_callback( '|%([0-9A-F]{2})|', - function ($matches) { + static function ($matches) { // Pack this into ascii return pack('H*', $matches[1]); @@ -672,7 +660,7 @@ function ($matches) { $line = trim($line); // We dont have anything in this line - if (strlen($line) == 0) { + if ($line === '') { continue; } @@ -741,10 +729,6 @@ function ($matches) { /** * Decrypt the incoming packets * - * @codeCoverageIgnore - * - * @param array $packets - * * @return string * @throws \GameQ\Exception\Protocol */ @@ -810,21 +794,23 @@ protected function decryptPackets(array $packets = []) $a1 = $header_items['datakey'] & 0xFF; $a2 = $header_items['datakey'] >> 8; - if ($a1 == 0) { + if ($a1 === 0) { throw new Exception(__METHOD__ . ": Data key is invalid"); } $chars = unpack("C*", substr($packet, 20)); - $data = ""; - $characterCount = count($chars); - - for ($index = 1; $index <= $characterCount; $index++) { - $chars[$index] -= ($table[$a2] + (($index - 1) % 72)) & 0xFF; - $a2 = ($a2 + $a1) & 0xFF; - $data .= chr($chars[$index]); + if ($chars !== false) { + $data = ""; + $characterCount = count($chars); + + for ($index = 1; $index <= $characterCount; $index++) { + $chars[$index] -= ($table[$a2] + (($index - 1) % 72)) & 0xFF; + $a2 = ($a2 + $a1) & 0xFF; + $data .= chr($chars[$index]); + } + //@todo: Check CRC ??? + $decrypted[$header_items['pck']] = $data; } - //@todo: Check CRC ??? - $decrypted[$header_items['pck']] = $data; } // Return the decrypted packets as one string @@ -833,12 +819,8 @@ protected function decryptPackets(array $packets = []) /** * Process the channel listing - * - * @param string $data - * @param int $fieldCount - * @param \GameQ\Result $result */ - protected function processChannel($data, $fieldCount, Result $result) + protected function processChannel(string $data, int $fieldCount, Result $result) { // Split the items on the comma @@ -855,12 +837,8 @@ protected function processChannel($data, $fieldCount, Result $result) /** * Process the user listing - * - * @param string $data - * @param int $fieldCount - * @param \GameQ\Result $result */ - protected function processPlayer($data, $fieldCount, Result $result) + protected function processPlayer(string $data, int $fieldCount, Result $result) { // Split the items on the comma diff --git a/src/GameQ/Protocols/Vrising.php b/src/GameQ/Protocols/Vrising.php index 08549469..8c06de27 100644 --- a/src/GameQ/Protocols/Vrising.php +++ b/src/GameQ/Protocols/Vrising.php @@ -27,22 +27,16 @@ class Vrising extends Source { /** * String name of this protocol class - * - * @type string */ - protected $name = 'vrising'; + protected string $name = 'vrising'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "V Rising"; + protected string $name_long = "V Rising"; /** * query_port = client_port + 1 - * - * @type int */ - protected $port_diff = 1; + protected int $port_diff = 1; } diff --git a/src/GameQ/Protocols/Warsow.php b/src/GameQ/Protocols/Warsow.php index 7f890ee5..7ed1ad0a 100644 --- a/src/GameQ/Protocols/Warsow.php +++ b/src/GameQ/Protocols/Warsow.php @@ -31,30 +31,22 @@ class Warsow extends Quake3 { /** * String name of this protocol class - * - * @type string */ - protected $name = 'warsow'; + protected string $name = 'warsow'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Warsow"; + protected string $name_long = "Warsow"; /** * The client join link - * - * @type string */ - protected $join_link = "warsow://%s:%d/"; + protected ?string $join_link = "warsow://%s:%d/"; /** * Handle player info, different than quake3 base * - * @param Buffer $buffer - * * @return array * @throws \GameQ\Exception\Protocol */ @@ -73,13 +65,13 @@ protected function processPlayers(Buffer $buffer) $result->addPlayer('ping', $playerInfo->readString("\x20")); // Skip first " - $playerInfo->skip(1); + $playerInfo->skip(); // Add player name, encoded $result->addPlayer('name', $this->convertToUtf8(trim(($playerInfo->readString('"'))))); // Skip space - $playerInfo->skip(1); + $playerInfo->skip(); // Add team $result->addPlayer('team', $playerInfo->read()); diff --git a/src/GameQ/Protocols/Won.php b/src/GameQ/Protocols/Won.php index bef09841..a047648b 100644 --- a/src/GameQ/Protocols/Won.php +++ b/src/GameQ/Protocols/Won.php @@ -34,10 +34,8 @@ class Won extends Source /** * Array of packets we want to look up. * Each key should correspond to a defined method in this or a parent class - * - * @type array */ - protected $packets = [ + protected array $packets = [ self::PACKET_DETAILS => "\xFF\xFF\xFF\xFFdetails\x00", self::PACKET_PLAYERS => "\xFF\xFF\xFF\xFFplayers", self::PACKET_RULES => "\xFF\xFF\xFF\xFFrules", @@ -45,22 +43,16 @@ class Won extends Source /** * The query protocol used to make the call - * - * @type string */ - protected $protocol = 'won'; + protected string $protocol = 'won'; /** * String name of this protocol class - * - * @type string */ - protected $name = 'won'; + protected string $name = 'won'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "World Opponent Network"; + protected string $name_long = "World Opponent Network"; } diff --git a/src/GameQ/Protocols/Wurm.php b/src/GameQ/Protocols/Wurm.php index c5936522..424f400f 100644 --- a/src/GameQ/Protocols/Wurm.php +++ b/src/GameQ/Protocols/Wurm.php @@ -28,15 +28,11 @@ class Wurm extends Source { /** * String name of this protocol class - * - * @type string */ - protected $name = 'wurm'; + protected string $name = 'wurm'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Wurm Unlimited"; + protected string $name_long = "Wurm Unlimited"; } diff --git a/src/GameQ/Protocols/Zomboid.php b/src/GameQ/Protocols/Zomboid.php index 4733d97a..32a14ac0 100644 --- a/src/GameQ/Protocols/Zomboid.php +++ b/src/GameQ/Protocols/Zomboid.php @@ -28,15 +28,11 @@ class Zomboid extends Source { /** * String name of this protocol class - * - * @type string */ - protected $name = 'zomboid'; + protected string $name = 'zomboid'; /** * Longer string name of this protocol class - * - * @type string */ - protected $name_long = "Project Zomboid"; + protected string $name_long = "Project Zomboid"; } diff --git a/src/GameQ/Query/Core.php b/src/GameQ/Query/Core.php index cee4cfac..9aac781f 100644 --- a/src/GameQ/Query/Core.php +++ b/src/GameQ/Query/Core.php @@ -31,157 +31,116 @@ abstract class Core * * @type null|resource */ - public $socket = null; + public $socket; /** * The transport type (udp, tcp, etc...) * See http://php.net/manual/en/transports.php for the supported list - * - * @type string - */ - protected $transport = null; + */ + protected ?string $transport; /** * Connection IP address - * - * @type string */ - protected $ip = null; + protected ?string $ip = null; /** * Connection port - * - * @type int */ - protected $port = null; + protected ?int $port = null; /** * The time in seconds to wait before timing out while connecting to the socket - * - * @type int */ - protected $timeout = 3; // Seconds + protected int $timeout = 3; // Seconds /** * Socket is blocking? - * - * @type bool */ - protected $blocking = false; + protected bool $blocking = false; /** * Called when the class is cloned */ public function __clone() { - // Reset the properties for this class when cloned $this->reset(); } /** * Set the connection information for the socket - * - * @param string $transport - * @param string $ip - * @param int $port - * @param int $timeout seconds - * @param bool $blocking */ - public function set($transport, $ip, $port, $timeout = 3, $blocking = false) + public function set(?string $transport, string $ip, int $port, int $timeout = 3, bool $blocking = false): void { - $this->transport = $transport; - $this->ip = $ip; - $this->port = $port; - $this->timeout = $timeout; - $this->blocking = $blocking; } /** * Reset this instance's properties */ - public function reset() + public function reset(): void { - $this->transport = null; - $this->ip = null; - $this->port = null; - $this->timeout = 3; - $this->blocking = false; } - public function getTransport() + public function getTransport(): ?string { return $this->transport; } - public function getIp() + public function getIp(): ?string { return $this->ip; } - public function getPort() + public function getPort(): ?int { return $this->port; } - public function getTimeout() + public function getTimeout(): int { return $this->timeout; } - public function getBlocking() + public function getBlocking(): bool { return $this->blocking; } /** * Create a new socket - * - * @return void */ - abstract protected function create(); + abstract protected function create(): void; /** * Get the socket - * - * @return mixed */ - abstract public function get(); + abstract public function get(): mixed; /** * Write data to the socket * - * @param string|array $data - * * @return int The number of bytes written */ - abstract public function write($data); + abstract public function write(string|array $data): int; /** * Close the socket - * - * @return void */ - abstract public function close(); + abstract public function close(): void; /** * Read the responses from the socket(s) - * - * @param array $sockets - * @param int $timeout - * @param int $stream_timeout - * - * @return array */ - abstract public function getResponses(array $sockets, $timeout, $stream_timeout); + abstract public function getResponses(array $sockets, int $timeout, int $stream_timeout): array; } diff --git a/src/GameQ/Query/Native.php b/src/GameQ/Query/Native.php index c23ae75e..e2c97893 100644 --- a/src/GameQ/Query/Native.php +++ b/src/GameQ/Query/Native.php @@ -30,10 +30,10 @@ class Native extends Core /** * Get the current socket or create one and return * - * @return resource|null + * @return mixed * @throws \GameQ\Exception\Query */ - public function get() + public function get(): mixed { // No socket for this server, make one @@ -47,12 +47,12 @@ public function get() /** * Write data to the socket * - * @param string $data + * @param string|array $data * * @return int The number of bytes written * @throws \GameQ\Exception\Query */ - public function write($data) + public function write(string|array $data): int { try { @@ -71,7 +71,7 @@ public function write($data) /** * Close the current socket */ - public function close() + public function close(): void { if ($this->socket) { @@ -85,7 +85,7 @@ public function close() * * @throws \GameQ\Exception\Query */ - protected function create() + protected function create(): void { // Create the remote address @@ -132,14 +132,8 @@ protected function create() /** * Pull the responses out of the stream - * - * @param array $sockets - * @param int $timeout - * @param int $stream_timeout - * - * @return array Raw responses */ - public function getResponses(array $sockets, $timeout, $stream_timeout) + public function getResponses(array $sockets, int $timeout, int $stream_timeout): array { // Will hold the responses read from the sockets $responses = []; @@ -197,7 +191,7 @@ public function getResponses(array $sockets, $timeout, $stream_timeout) } // Check to see if the response is empty, if so we are done with this server - if (strlen($response) == 0) { + if ($response === '') { // Remove this server from any future read loops unset($sockets_tmp[(int)$socket]); continue; diff --git a/src/GameQ/Result.php b/src/GameQ/Result.php index ddf0b3fa..b88f0459 100644 --- a/src/GameQ/Result.php +++ b/src/GameQ/Result.php @@ -29,18 +29,13 @@ class Result /** * Formatted server response - * - * @var array */ - protected $result = []; + protected array $result = []; /** * Adds variable to results - * - * @param string $name Variable name - * @param string|array|int|float|bool $value Variable value */ - public function add($name, $value) + public function add(string $name, mixed $value): void { $this->result[$name] = $value; @@ -48,11 +43,8 @@ public function add($name, $value) /** * Adds player variable to output - * - * @param string $name Variable name - * @param string|int|float $value Variable value */ - public function addPlayer($name, $value) + public function addPlayer(string $name, mixed $value): void { $this->addSub('players', $name, $value); @@ -60,11 +52,8 @@ public function addPlayer($name, $value) /** * Adds player variable to output - * - * @param string $name Variable name - * @param string|int|float $value Variable value */ - public function addTeam($name, $value) + public function addTeam(string $name, mixed $value): void { $this->addSub('teams', $name, $value); @@ -72,24 +61,20 @@ public function addTeam($name, $value) /** * Add a variable to a category - * - * @param $sub string The category - * @param $key string The variable name - * @param $value string The variable value */ - public function addSub($sub, $key, $value) + public function addSub(string $sub, string $key, string $value): void { // Nothing of this type yet, set an empty array - if (!isset($this->result[$sub]) or !is_array($this->result[$sub])) { + if (!isset($this->result[$sub]) || !is_array($this->result[$sub])) { $this->result[$sub] = []; } // Find the first entry that doesn't have this variable $found = false; $count = count($this->result[$sub]); - for ($i = 0; $i != $count; $i++) { - if (!isset($this->result[$sub][$i][$key])) { + foreach ($this->result[$sub] as $i => $iValue) { + if (!isset($iValue[$key])) { $this->result[$sub][$i][$key] = $value; $found = true; break; @@ -106,10 +91,8 @@ public function addSub($sub, $key, $value) /** * Return all stored results - * - * @return array All results */ - public function fetch() + public function fetch(): array { return $this->result; @@ -117,12 +100,8 @@ public function fetch() /** * Return a single variable - * - * @param string $var The variable name - * - * @return mixed The variable value */ - public function get($var) + public function get(string $var): mixed { return $this->result[$var] ?? null; diff --git a/src/GameQ/Server.php b/src/GameQ/Server.php index 8de8aa2d..a608d8db 100644 --- a/src/GameQ/Server.php +++ b/src/GameQ/Server.php @@ -19,6 +19,7 @@ namespace GameQ; use GameQ\Exception\Server as Exception; +use GameQ\Query\Core; /** * Server class to represent each server entity @@ -30,13 +31,10 @@ class Server /* * Server array keys */ - const SERVER_TYPE = 'type'; - - const SERVER_HOST = 'host'; - - const SERVER_ID = 'id'; - - const SERVER_OPTIONS = 'options'; + public const SERVER_TYPE = 'type'; + public const SERVER_HOST = 'host'; + public const SERVER_ID = 'id'; + public const SERVER_OPTIONS = 'options'; /* * Server options keys @@ -45,62 +43,46 @@ class Server /* * Use this option when the query_port and client connect ports are different */ - const SERVER_OPTIONS_QUERY_PORT = 'query_port'; + public const SERVER_OPTIONS_QUERY_PORT = 'query_port'; /** * The protocol class for this server - * - * @type \GameQ\Protocol */ - protected $protocol = null; + protected ?Protocol $protocol = null; /** * Id of this server - * - * @type string */ - public $id = null; + public ?string $id = null; /** * IP Address of this server - * - * @type string */ - public $ip = null; + public ?string $ip = null; /** * The server's client port (connect port) - * - * @type int */ - public $port_client = null; + public ?int $port_client = null; /** * The server's query port - * - * @type int */ - public $port_query = null; + public ?int $port_query = null; /** * Holds other server specific options - * - * @type array */ - protected $options = []; + protected array $options = []; /** * Holds the sockets already open for this server - * - * @type array */ - protected $sockets = []; + protected array $sockets = []; /** * Construct the class with the passed options * - * @param array $server_info - * * @throws \GameQ\Exception\Server */ public function __construct(array $server_info = []) @@ -148,17 +130,15 @@ public function __construct(array $server_info = []) // Check and set any server options $this->checkAndSetServerOptions(); - unset($server_info, $class); + unset($class); } /** * Check and set the ip address for this server * - * @param $ip_address - * * @throws \GameQ\Exception\Server */ - protected function checkAndSetIpPort($ip_address) + protected function checkAndSetIpPort(string $ip_address): void { // Test for IPv6 @@ -203,7 +183,7 @@ protected function checkAndSetIpPort($ip_address) } // Validate the IPv4 value, if FALSE is not a valid IP, maybe a hostname. - if (! filter_var($this->ip, FILTER_VALIDATE_IP, ['flags' => FILTER_FLAG_IPV4,])) { + if (!filter_var($this->ip, FILTER_VALIDATE_IP, ['flags' => FILTER_FLAG_IPV4,])) { // Try to resolve the hostname to IPv4 $resolved = gethostbyname($this->ip); @@ -211,9 +191,9 @@ protected function checkAndSetIpPort($ip_address) if ($this->ip === $resolved) { // so if ip and the result from gethostbyname() are equal this failed. throw new Exception("Unable to resolve the host '$this->ip' to an IP address."); - } else { - $this->ip = $resolved; } + + $this->ip = $resolved; } } } @@ -221,7 +201,7 @@ protected function checkAndSetIpPort($ip_address) /** * Check and set any server specific options */ - protected function checkAndSetServerOptions() + protected function checkAndSetServerOptions(): void { // Specific query port defined @@ -236,30 +216,22 @@ protected function checkAndSetServerOptions() /** * Set an option for this server * - * @param $key - * @param $value - * * @return $this */ - public function setOption($key, $value) + public function setOption(string $key, mixed $value): self { - $this->options[$key] = $value; - return $this; // Make chainable + return $this; } /** * Return set option value - * - * @param mixed $key - * - * @return mixed */ - public function getOption($key) + public function getOption(string $key): mixed { - return (array_key_exists($key, $this->options)) ? $this->options[$key] : null; + return $this->options[$key] ?? null; } public function getOptions() @@ -269,10 +241,8 @@ public function getOptions() /** * Get the ID for this server - * - * @return string */ - public function id() + public function id(): string { return $this->id; @@ -280,10 +250,8 @@ public function id() /** * Get the IP address for this server - * - * @return string */ - public function ip() + public function ip(): string { return $this->ip; @@ -291,10 +259,8 @@ public function ip() /** * Get the client port for this server - * - * @return int */ - public function portClient() + public function portClient(): int { return $this->port_client; @@ -302,10 +268,8 @@ public function portClient() /** * Get the query port for this server - * - * @return int */ - public function portQuery() + public function portQuery(): int { return $this->port_query; @@ -313,10 +277,8 @@ public function portQuery() /** * Return the protocol class for this server - * - * @return \GameQ\Protocol */ - public function protocol() + public function protocol(): ?Protocol { return $this->protocol; @@ -324,13 +286,16 @@ public function protocol() /** * Get the join link for this server - * - * @return string */ - public function getJoinLink() + public function getJoinLink(): ?string { + $joinLink = $this->protocol?->joinLink(); - return sprintf($this->protocol->joinLink(), $this->ip, $this->portClient()); + if ($joinLink === null) { + return null; + } + + return sprintf($joinLink, $this->ip, $this->portClient()); } /* @@ -339,12 +304,8 @@ public function getJoinLink() /** * Add a socket for this server to be reused - * - * @codeCoverageIgnore - * - * @param \GameQ\Query\Core $socket */ - public function socketAdd(Query\Core $socket) + public function socketAdd(Core $socket): void { $this->sockets[] = $socket; @@ -352,12 +313,8 @@ public function socketAdd(Query\Core $socket) /** * Get a socket from the list to reuse, if any are available - * - * @codeCoverageIgnore - * - * @return \GameQ\Query\Core|null */ - public function socketGet() + public function socketGet(): ?Core { $socket = null; @@ -371,10 +328,8 @@ public function socketGet() /** * Clear any sockets still listed and attempt to close them - * - * @codeCoverageIgnore */ - public function socketCleanse() + public function socketCleanse(): void { // Close all of the sockets available From e4bd2d98b3396491ec0b2138735c18116dfd1557 Mon Sep 17 00:00:00 2001 From: "Niklas (Krymonota)" Date: Thu, 26 Sep 2024 23:15:31 +0200 Subject: [PATCH 13/14] Fix PHPStan errors --- src/GameQ/GameQ.php | 7 +++++-- src/GameQ/Protocols/Arma3.php | 2 ++ src/GameQ/Result.php | 7 +------ src/GameQ/Server.php | 7 +++---- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/GameQ/GameQ.php b/src/GameQ/GameQ.php index 16ff370c..1dd4e5cf 100644 --- a/src/GameQ/GameQ.php +++ b/src/GameQ/GameQ.php @@ -20,6 +20,7 @@ use GameQ\Exception\Protocol as ProtocolException; use GameQ\Exception\Query as QueryException; +use GameQ\Filters\Base; use GameQ\Query\Core; use GameQ\Query\Native; @@ -563,8 +564,10 @@ protected function doApplyFilters(array $results, Server $server): array // Create a new instance of the filter class specified $filter = $class->newInstanceArgs([$filterOptions['options']]); - // Apply the filter to the data - $results = $filter?->apply($results, $server); + if ($filter instanceof Base) { + // Apply the filter to the data + $results = $filter->apply($results, $server); + } } catch (\ReflectionException) { // Invalid, skip it continue; diff --git a/src/GameQ/Protocols/Arma3.php b/src/GameQ/Protocols/Arma3.php index 5fe5faca..f8a4e921 100644 --- a/src/GameQ/Protocols/Arma3.php +++ b/src/GameQ/Protocols/Arma3.php @@ -50,10 +50,12 @@ class Arma3 extends Source private const BASE_DLC_AOW = 'Art of War'; // Creator DLC names + /* private const CREATOR_DLC_GM = 'Global Mobilization'; private const CREATOR_DLC_VN = 'S.O.G. Prairie Fire'; private const CREATOR_DLC_CSLA = 'ČSLA - Iron Curtain'; private const CREATOR_DLC_WS = 'Western Sahara'; + */ /** * DLC Flags/Bits as defined in the documentation. diff --git a/src/GameQ/Result.php b/src/GameQ/Result.php index b88f0459..e5d82f38 100644 --- a/src/GameQ/Result.php +++ b/src/GameQ/Result.php @@ -26,7 +26,6 @@ */ class Result { - /** * Formatted server response */ @@ -37,7 +36,6 @@ class Result */ public function add(string $name, mixed $value): void { - $this->result[$name] = $value; } @@ -46,7 +44,6 @@ public function add(string $name, mixed $value): void */ public function addPlayer(string $name, mixed $value): void { - $this->addSub('players', $name, $value); } @@ -55,16 +52,14 @@ public function addPlayer(string $name, mixed $value): void */ public function addTeam(string $name, mixed $value): void { - $this->addSub('teams', $name, $value); } /** * Add a variable to a category */ - public function addSub(string $sub, string $key, string $value): void + public function addSub(string $sub, string $key, mixed $value): void { - // Nothing of this type yet, set an empty array if (!isset($this->result[$sub]) || !is_array($this->result[$sub])) { $this->result[$sub] = []; diff --git a/src/GameQ/Server.php b/src/GameQ/Server.php index a608d8db..dbc30d8a 100644 --- a/src/GameQ/Server.php +++ b/src/GameQ/Server.php @@ -170,10 +170,9 @@ protected function checkAndSetIpPort(string $ip_address): void } else { // We have IPv4 with a port defined if (str_contains($ip_address, ':')) { - list($this->ip, $this->port_client) = explode(':', $ip_address); - - // Type case the port - $this->port_client = (int)$this->port_client; + $addressParts = explode(':', $ip_address); + $this->ip = $addressParts[0]; + $this->port_client = (int)$addressParts[1]; } else { // No port, fail throw new Exception( From b6a3f47c492deed2f2a3b9d05c8fabc7f2557b9b Mon Sep 17 00:00:00 2001 From: "Niklas (Krymonota)" Date: Thu, 26 Sep 2024 23:27:58 +0200 Subject: [PATCH 14/14] Fix PHPUnit errors and failure --- src/GameQ/Filters/Stripcolors.php | 18 ++++++++++++------ src/GameQ/GameQ.php | 3 +-- src/GameQ/Protocol.php | 3 +-- src/GameQ/Protocols/Mumble.php | 10 +++++----- tests/Protocols/Mumble.php | 3 +-- 5 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/GameQ/Filters/Stripcolors.php b/src/GameQ/Filters/Stripcolors.php index 915beb03..e49c676d 100644 --- a/src/GameQ/Filters/Stripcolors.php +++ b/src/GameQ/Filters/Stripcolors.php @@ -87,24 +87,30 @@ public function apply(array $result, Server $server): mixed /** * Strip color codes from quake based games */ - protected function stripQuake(string &$string): void + protected function stripQuake(mixed &$string): void { - $string = preg_replace('#(\^.)#', '', $string); + if (is_string($string)) { + $string = preg_replace('#(\^.)#', '', $string); + } } /** * Strip color codes from Source based games */ - protected function stripSource(string &$string): void + protected function stripSource(mixed &$string): void { - $string = strip_tags($string); + if (is_string($string)) { + $string = strip_tags($string); + } } /** * Strip color codes from Unreal based games */ - protected function stripUnreal(string &$string): void + protected function stripUnreal(mixed &$string): void { - $string = preg_replace('/\x1b.../', '', $string); + if (is_string($string)) { + $string = preg_replace('/\x1b.../', '', $string); + } } } diff --git a/src/GameQ/GameQ.php b/src/GameQ/GameQ.php index 1dd4e5cf..3c8d6674 100644 --- a/src/GameQ/GameQ.php +++ b/src/GameQ/GameQ.php @@ -176,9 +176,8 @@ public function addServers(array $servers = []): self * * @throws \Exception */ - public function addServersFromFiles(array $files = []): self + public function addServersFromFiles(string|array $files = []): self { - // Since we expect an array let us turn a string (i.e. single file) into an array if (!is_array($files)) { $files = [$files]; diff --git a/src/GameQ/Protocol.php b/src/GameQ/Protocol.php index faac80e8..29b39239 100644 --- a/src/GameQ/Protocol.php +++ b/src/GameQ/Protocol.php @@ -275,9 +275,8 @@ public function options(array $options = []): array /** * Return specific packet(s) */ - public function getPacket(array|string $type = []): array + public function getPacket(array|string $type = []): array|string { - $packets = []; // We want an array of packets back diff --git a/src/GameQ/Protocols/Mumble.php b/src/GameQ/Protocols/Mumble.php index f55ab805..b51f7510 100644 --- a/src/GameQ/Protocols/Mumble.php +++ b/src/GameQ/Protocols/Mumble.php @@ -104,15 +104,15 @@ class Mumble extends Protocol */ public function processResponse(): mixed { - - // Try to json_decode, make it into an array - if (($data = json_decode( + $data = json_decode( implode('', $this->packets_response), true, 512, JSON_THROW_ON_ERROR - )) === null) { - throw new Exception(__METHOD__ . " Unable to decode JSON data."); + ); + + if (!is_array($data)) { + throw new Exception('Failed to decode JSON response to array'); } // Set the result to a new result instance diff --git a/tests/Protocols/Mumble.php b/tests/Protocols/Mumble.php index b90703d3..65a58ea5 100644 --- a/tests/Protocols/Mumble.php +++ b/tests/Protocols/Mumble.php @@ -66,8 +66,7 @@ public function testPackets() */ public function testBadResponseFormat() { - $this->expectException(\Exception::class); - $this->expectExceptionMessage("GameQ\Protocols\Mumble::processResponse Unable to decode JSON data."); + $this->expectException(\JsonException::class); // Should fail out $this->queryTest('127.0.0.1:27015', 'mumble', [ '{"key1": "val", "key2" :}' ], true); }