mirror of
https://github.com/xPaw/PHP-Source-Query.git
synced 2026-06-10 21:43:16 +02:00
Create a factory for easy setup.
Update README.md.
This commit is contained in:
@@ -2,16 +2,15 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
require __DIR__ . '/../vendor/autoload.php';
|
require_once __DIR__ . '/../vendor/autoload.php';
|
||||||
|
|
||||||
use xPaw\SourceQuery\Socket\SourceSocket;
|
use xPaw\SourceQuery\SourceQueryFactory;
|
||||||
use xPaw\SourceQuery\SourceQuery;
|
|
||||||
|
|
||||||
// For the sake of this example
|
// For the sake of this example
|
||||||
header('Content-Type: text/plain');
|
header('Content-Type: text/plain');
|
||||||
header('X-Content-Type-Options: nosniff');
|
header('X-Content-Type-Options: nosniff');
|
||||||
|
|
||||||
$query = new SourceQuery(new SourceSocket());
|
$query = SourceQueryFactory::createSourceQuery();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$query->connect('localhost', 27015, 1);
|
$query->connect('localhost', 27015, 1);
|
||||||
|
|||||||
@@ -2,16 +2,15 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
require __DIR__ . '/../vendor/autoload.php';
|
require_once __DIR__ . '/../vendor/autoload.php';
|
||||||
|
|
||||||
use xPaw\SourceQuery\Socket\SourceSocket;
|
use xPaw\SourceQuery\SourceQueryFactory;
|
||||||
use xPaw\SourceQuery\SourceQuery;
|
|
||||||
|
|
||||||
// For the sake of this example
|
// For the sake of this example
|
||||||
header('Content-Type: text/plain');
|
header('Content-Type: text/plain');
|
||||||
header('X-Content-Type-Options: nosniff');
|
header('X-Content-Type-Options: nosniff');
|
||||||
|
|
||||||
$query = new SourceQuery(new SourceSocket());
|
$query = SourceQueryFactory::createSourceQuery();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$query->connect('localhost', 27015, 1);
|
$query->connect('localhost', 27015, 1);
|
||||||
|
|||||||
+5
-6
@@ -2,14 +2,13 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
require __DIR__ . '/../vendor/autoload.php';
|
require_once __DIR__ . '/../vendor/autoload.php';
|
||||||
|
|
||||||
use xPaw\SourceQuery\Socket\SourceSocket;
|
use xPaw\SourceQuery\SourceQueryFactory;
|
||||||
use xPaw\SourceQuery\SourceQuery;
|
|
||||||
|
|
||||||
$timer = microtime(true);
|
$timer = microtime(true);
|
||||||
|
|
||||||
$query = new SourceQuery(new SourceSocket());
|
$query = SourceQueryFactory::createSourceQuery();
|
||||||
|
|
||||||
$info = [];
|
$info = [];
|
||||||
$rules = [];
|
$rules = [];
|
||||||
@@ -17,8 +16,8 @@ $players = [];
|
|||||||
$exception = null;
|
$exception = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$query->connect('localhost', 27015, 3);
|
$query->connect('localhost', 27015);
|
||||||
//$Query->SetUseOldGetChallengeMethod( true ); // Use this when players/rules retrieval fails on games like Starbound
|
//$query->setUseOldGetChallengeMethod( true ); // Use this when players/rules retrieval fails on games like Starbound
|
||||||
|
|
||||||
$info = $query->getInfo();
|
$info = $query->getInfo();
|
||||||
$players = $query->getPlayers();
|
$players = $query->getPlayers();
|
||||||
|
|||||||
@@ -1,8 +1,12 @@
|
|||||||
# PHP Source Query
|
# 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)
|
* Refactored, split up to make the GoldSource / Source functionality extendable.
|
||||||
[](https://packagist.org/packages/xpaw/php-source-query-class)
|
* 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.
|
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.
|
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: |
|
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
|
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: |
|
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
|
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: |
|
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: |
|
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
|
## Functions
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Connect( $Ip, $Port, $Timeout, $Engine )</td>
|
<td>connect($host, $port, $timeout)</td>
|
||||||
<td>Opens connection to a server</td>
|
<td>Opens connection to a server</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Disconnect( )</td>
|
<td>disconnect()</td>
|
||||||
<td>Closes all open connections</td>
|
<td>Closes all open connections</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Ping( )</td>
|
<td>ping()</td>
|
||||||
<td>Ping the server to see if it exists<br><b>Warning:</b> Source engine may not answer to this</td>
|
<td>Ping the server to see if it exists<br><b>Warning:</b> Source engine may not answer to this</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>GetInfo( )</td>
|
<td>getInfo()</td>
|
||||||
<td>Returns server info in an array</td>
|
<td>Returns server info in an array</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>GetPlayers( )</td>
|
<td>getPlayers()</td>
|
||||||
<td>Returns players on the server in an array</td>
|
<td>Returns players on the server in an array</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>GetRules( )</td>
|
<td>getRules()</td>
|
||||||
<td>Returns public rules <i>(cvars)</i> in an array</td>
|
<td>Returns public rules <i>(cvars)</i> in an array</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>SetRconPassword( $Password )</td>
|
<td>setRconPassword($password)</td>
|
||||||
<td>Sets rcon password for later use with <i>Rcon()</i></td>
|
<td>Sets rcon password for later use with <i>Rcon()</i></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Rcon( $Command )</td>
|
<td>rcon($command)</td>
|
||||||
<td>Execute rcon command on the server</td>
|
<td>Execute rcon command on the server</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
Also refer to [examples folder](Examples/) to work things out.
|
Also refer to [examples folder](Examples) to work things out.
|
||||||
|
|
||||||
## License
|
## License
|
||||||
PHP Source Query
|
PHP Source Query
|
||||||
|
|||||||
@@ -146,7 +146,7 @@ final class SourceQuery
|
|||||||
*
|
*
|
||||||
* @return bool Previous value
|
* @return bool Previous value
|
||||||
*/
|
*/
|
||||||
public function SetUseOldGetChallengeMethod(bool $value): bool
|
public function setUseOldGetChallengeMethod(bool $value): bool
|
||||||
{
|
{
|
||||||
$previous = $this->useOldGetChallengeMethod;
|
$previous = $this->useOldGetChallengeMethod;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace xPaw\SourceQuery;
|
||||||
|
|
||||||
|
use xPaw\SourceQuery\Socket\GoldSourceSocket;
|
||||||
|
use xPaw\SourceQuery\Socket\SourceSocket;
|
||||||
|
|
||||||
|
final class SourceQueryFactory
|
||||||
|
{
|
||||||
|
public static function createGoldSourceQuery(): SourceQuery
|
||||||
|
{
|
||||||
|
return new SourceQuery(new SourceSocket());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function createSourceQuery(): SourceQuery
|
||||||
|
{
|
||||||
|
return new SourceQuery(new GoldSourceSocket());
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user