diff --git a/Examples/Example.php b/Examples/Example.php index 1ce622e..abbbdd3 100644 --- a/Examples/Example.php +++ b/Examples/Example.php @@ -2,16 +2,15 @@ declare(strict_types=1); -require __DIR__ . '/../vendor/autoload.php'; +require_once __DIR__ . '/../vendor/autoload.php'; -use xPaw\SourceQuery\Socket\SourceSocket; -use xPaw\SourceQuery\SourceQuery; +use xPaw\SourceQuery\SourceQueryFactory; // For the sake of this example header('Content-Type: text/plain'); header('X-Content-Type-Options: nosniff'); -$query = new SourceQuery(new SourceSocket()); +$query = SourceQueryFactory::createSourceQuery(); try { $query->connect('localhost', 27015, 1); diff --git a/Examples/RconExample.php b/Examples/RconExample.php index c07bf27..2304a4b 100644 --- a/Examples/RconExample.php +++ b/Examples/RconExample.php @@ -2,16 +2,15 @@ declare(strict_types=1); -require __DIR__ . '/../vendor/autoload.php'; +require_once __DIR__ . '/../vendor/autoload.php'; -use xPaw\SourceQuery\Socket\SourceSocket; -use xPaw\SourceQuery\SourceQuery; +use xPaw\SourceQuery\SourceQueryFactory; // For the sake of this example header('Content-Type: text/plain'); header('X-Content-Type-Options: nosniff'); -$query = new SourceQuery(new SourceSocket()); +$query = SourceQueryFactory::createSourceQuery(); try { $query->connect('localhost', 27015, 1); diff --git a/Examples/View.php b/Examples/View.php index b0f4287..3afb7f3 100644 --- a/Examples/View.php +++ b/Examples/View.php @@ -2,14 +2,13 @@ declare(strict_types=1); -require __DIR__ . '/../vendor/autoload.php'; +require_once __DIR__ . '/../vendor/autoload.php'; -use xPaw\SourceQuery\Socket\SourceSocket; -use xPaw\SourceQuery\SourceQuery; +use xPaw\SourceQuery\SourceQueryFactory; $timer = microtime(true); -$query = new SourceQuery(new SourceSocket()); +$query = SourceQueryFactory::createSourceQuery(); $info = []; $rules = []; @@ -17,8 +16,8 @@ $players = []; $exception = null; try { - $query->connect('localhost', 27015, 3); - //$Query->SetUseOldGetChallengeMethod( true ); // Use this when players/rules retrieval fails on games like Starbound + $query->connect('localhost', 27015); + //$query->setUseOldGetChallengeMethod( true ); // Use this when players/rules retrieval fails on games like Starbound $info = $query->getInfo(); $players = $query->getPlayers(); diff --git a/README.md b/README.md index 1fa7a3d..7937a16 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,12 @@ # PHP Source Query +A fork of [xPaw's PHP Source Query library.](https://github.com/xPaw/PHP-Source-Query) -[](https://packagist.org/packages/xpaw/php-source-query-class) -[](https://packagist.org/packages/xpaw/php-source-query-class) +* Refactored, split up to make the GoldSource / Source functionality extendable. + * Removed most of the tight coupling, extend rather than handling differences in-line. +* Improved error handling. +* Still roughly API compatible (functions have been renamed to lower camel case). +# Original Readme This class was created to query game server which use the Source query protocol, this includes all source games, and all the games that implement Steamworks. The class also allows you to query servers using RCON although this only works for half-life 1 and source engine games. @@ -35,7 +39,7 @@ AppID | Game | Query | RCON | Notes 70000 | [Dino D-Day](http://store.steampowered.com/app/70000/) | :white_check_mark: | :white_check_mark: | 107410 | [Arma 3](http://store.steampowered.com/app/107410/) | :white_check_mark: | :x: | Add +1 to the server port 115300 | [Call of Duty: Modern Warfare 3](http://store.steampowered.com/app/115300/) | :white_check_mark: | :white_check_mark: | -211820 | [Starbound](http://store.steampowered.com/app/211820/) | :white_check_mark: | :white_check_mark: | Call `SetUseOldGetChallengeMethod` method after connecting +211820 | [Starbound](http://store.steampowered.com/app/211820/) | :white_check_mark: | :white_check_mark: | Call `setUseOldGetChallengeMethod` method after connecting 244850 | [Space Engineers](http://store.steampowered.com/app/244850/) | :white_check_mark: | :x: | Add +1 to the server port 251570 | [7 Days to Die](http://store.steampowered.com/app/251570) | :white_check_mark: | :x: | 252490 | [Rust](http://store.steampowered.com/app/252490/) | :white_check_mark: | :x: | @@ -52,40 +56,40 @@ Add your server to your favourites in Steam server browser, and if Steam can dis ## Functions
Connect( $Ip, $Port, $Timeout, $Engine ) | +connect($host, $port, $timeout) | Opens connection to a server |
Disconnect( ) | +disconnect() | Closes all open connections |
Ping( ) | +ping() | Ping the server to see if it exists Warning: Source engine may not answer to this |
GetInfo( ) | +getInfo() | Returns server info in an array |
GetPlayers( ) | +getPlayers() | Returns players on the server in an array |
GetRules( ) | +getRules() | Returns public rules (cvars) in an array |
SetRconPassword( $Password ) | +setRconPassword($password) | Sets rcon password for later use with Rcon() |
Rcon( $Command ) | +rcon($command) | Execute rcon command on the server |