From d9bab8aa2582b018f07ab08988db572b25dda590 Mon Sep 17 00:00:00 2001 From: Anthony Birkett Date: Mon, 31 May 2021 11:52:18 +0100 Subject: [PATCH] Remove engine from the Sockets. Docblock changes. Reorder methods to be logical. --- Examples/Example.php | 24 ++-- Examples/RconExample.php | 22 +-- Examples/View.php | 84 +++++------ SourceQuery/Buffer.php | 7 - .../Exception/SourceQueryException.php | 2 +- SourceQuery/Rcon/AbstractRcon.php | 27 ++-- SourceQuery/Rcon/GoldSourceRcon.php | 78 +++++----- SourceQuery/Rcon/RconInterface.php | 29 ++-- SourceQuery/Rcon/SourceRcon.php | 135 ++++++++---------- SourceQuery/Socket/AbstractSocket.php | 75 ++++------ SourceQuery/Socket/GoldSourceSocket.php | 11 ++ SourceQuery/Socket/SocketInterface.php | 31 ++-- SourceQuery/Socket/SocketType.php | 11 ++ SourceQuery/Socket/SourceSocket.php | 15 +- SourceQuery/Socket/TestableSocket.php | 49 ++++--- SourceQuery/SourceQuery.php | 48 +++---- Tests/Tests.php | 119 ++++++--------- 17 files changed, 364 insertions(+), 403 deletions(-) diff --git a/Examples/Example.php b/Examples/Example.php index 59ed770..9ad9b85 100644 --- a/Examples/Example.php +++ b/Examples/Example.php @@ -6,29 +6,21 @@ require __DIR__ . '/../vendor/autoload.php'; use xPaw\SourceQuery\SourceQuery; use xPaw\SourceQuery\Socket\SourceSocket; -use xPaw\SourceQuery\Socket\SocketType; // For the sake of this example header('Content-Type: text/plain'); header('X-Content-Type-Options: nosniff'); -// Edit this -> -define('SQ_SERVER_ADDR', 'localhost'); -define('SQ_SERVER_PORT', 27015); -define('SQ_TIMEOUT', 1); -define('SQ_ENGINE', SocketType::SOURCE); -// Edit this <- - -$Query = new SourceQuery(new SourceSocket()); +$query = new SourceQuery(new SourceSocket()); try { - $Query->connect(SQ_SERVER_ADDR, SQ_SERVER_PORT, SQ_TIMEOUT, SQ_ENGINE); + $query->connect('localhost', 27015, 1); - print_r($Query->getInfo()); - print_r($Query->getPlayers()); - print_r($Query->getRules()); -} catch (Exception $e) { - echo $e->getMessage(); + print_r($query->getInfo()); + print_r($query->getPlayers()); + print_r($query->getRules()); +} catch (Exception $exception) { + echo $exception->getMessage(); } finally { - $Query->disconnect(); + $query->disconnect(); } diff --git a/Examples/RconExample.php b/Examples/RconExample.php index 641043e..f367bbc 100644 --- a/Examples/RconExample.php +++ b/Examples/RconExample.php @@ -6,29 +6,21 @@ require __DIR__ . '/../vendor/autoload.php'; use xPaw\SourceQuery\SourceQuery; use xPaw\SourceQuery\Socket\SourceSocket; -use xPaw\SourceQuery\Socket\SocketType; // For the sake of this example header('Content-Type: text/plain'); header('X-Content-Type-Options: nosniff'); -// Edit this -> -define('SQ_SERVER_ADDR', 'localhost'); -define('SQ_SERVER_PORT', 27015); -define('SQ_TIMEOUT', 1); -define('SQ_ENGINE', SocketType::SOURCE); -// Edit this <- - -$Query = new SourceQuery(new SourceSocket()); +$query = new SourceQuery(new SourceSocket()); try { - $Query->connect(SQ_SERVER_ADDR, SQ_SERVER_PORT, SQ_TIMEOUT, SQ_ENGINE); + $query->connect('localhost', 27015, 1); - $Query->setRconPassword('my_awesome_password'); + $query->setRconPassword('my_awesome_password'); - var_dump($Query->rcon('say hello')); -} catch (Exception $e) { - echo $e->getMessage(); + var_dump($query->rcon('say hello')); +} catch (Exception $exception) { + echo $exception->getMessage(); } finally { - $Query->disconnect(); + $query->disconnect(); } diff --git a/Examples/View.php b/Examples/View.php index 083a45b..bcccc40 100644 --- a/Examples/View.php +++ b/Examples/View.php @@ -6,38 +6,30 @@ require __DIR__ . '/../vendor/autoload.php'; use xPaw\SourceQuery\SourceQuery; use xPaw\SourceQuery\Socket\SourceSocket; -use xPaw\SourceQuery\Socket\SocketType; -// Edit this -> -define('SQ_SERVER_ADDR', 'localhost'); -define('SQ_SERVER_PORT', 27015); -define('SQ_TIMEOUT', 3); -define('SQ_ENGINE', SocketType::SOURCE); -// Edit this <- +$timer = microtime(true); -$Timer = microtime(true); +$query = new SourceQuery(new SourceSocket()); -$Query = new SourceQuery(new SourceSocket()); - -$Info = []; -$Rules = []; -$Players = []; -$Exception = null; +$info = []; +$rules = []; +$players = []; +$exception = null; try { - $Query->connect(SQ_SERVER_ADDR, SQ_SERVER_PORT, SQ_TIMEOUT, SQ_ENGINE); + $query->connect('localhost', 27015, 3); //$Query->SetUseOldGetChallengeMethod( true ); // Use this when players/rules retrieval fails on games like Starbound - $Info = $Query->getInfo(); - $Players = $Query->getPlayers(); - $Rules = $Query->getRules(); + $info = $query->getInfo(); + $players = $query->getPlayers(); + $rules = $query->getRules(); } catch (Exception $e) { - $Exception = $e; + $exception = $e; } finally { - $Query->disconnect(); + $query->disconnect(); } -$Timer = number_format(microtime(true) - $Timer, 4, '.', ''); +$timer = number_format(microtime(true) - $timer, 4, '.', ''); ?> @@ -47,7 +39,7 @@ $Timer = number_format(microtime(true) - $Timer, 4, '.', ''); Source Query PHP Library -