mirror of
https://github.com/xPaw/PHP-Source-Query.git
synced 2026-05-18 13:43:33 +02:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e798d8f7c2 | |||
| b50daaef4c | |||
| dc2a08e503 | |||
| 41741b24a2 | |||
| 65a2493c3c | |||
| 1578c9f12f | |||
| 80cf750db5 | |||
| 346151b51f | |||
| 2591684d24 | |||
| e570cf796c | |||
| 9af9cf4f6b |
@@ -0,0 +1,8 @@
|
||||
# http://editorconfig.org
|
||||
|
||||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
indent_style = tab
|
||||
insert_final_newline = true
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
require __DIR__ . '/SourceQuery/SourceQuery.class.php';
|
||||
require __DIR__ . '/../SourceQuery/bootstrap.php';
|
||||
|
||||
use xPaw\SourceQuery\SourceQuery;
|
||||
|
||||
// For the sake of this example
|
||||
Header( 'Content-Type: text/plain' );
|
||||
@@ -9,7 +11,7 @@
|
||||
define( 'SQ_SERVER_ADDR', 'localhost' );
|
||||
define( 'SQ_SERVER_PORT', 27015 );
|
||||
define( 'SQ_TIMEOUT', 1 );
|
||||
define( 'SQ_ENGINE', SourceQuery :: SOURCE );
|
||||
define( 'SQ_ENGINE', SourceQuery::SOURCE );
|
||||
// Edit this <-
|
||||
|
||||
$Query = new SourceQuery( );
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
require __DIR__ . '/SourceQuery/SourceQuery.class.php';
|
||||
require __DIR__ . '/../SourceQuery/bootstrap.php';
|
||||
|
||||
use xPaw\SourceQuery\SourceQuery;
|
||||
|
||||
// For the sake of this example
|
||||
Header( 'Content-Type: text/plain' );
|
||||
@@ -9,7 +11,7 @@
|
||||
define( 'SQ_SERVER_ADDR', 'localhost' );
|
||||
define( 'SQ_SERVER_PORT', 27015 );
|
||||
define( 'SQ_TIMEOUT', 1 );
|
||||
define( 'SQ_ENGINE', SourceQuery :: SOURCE );
|
||||
define( 'SQ_ENGINE', SourceQuery::SOURCE );
|
||||
// Edit this <-
|
||||
|
||||
$Query = new SourceQuery( );
|
||||
@@ -1,11 +1,13 @@
|
||||
<?php
|
||||
require __DIR__ . '/SourceQuery/SourceQuery.class.php';
|
||||
require __DIR__ . '/../SourceQuery/bootstrap.php';
|
||||
|
||||
use xPaw\SourceQuery\SourceQuery;
|
||||
|
||||
// Edit this ->
|
||||
define( 'SQ_SERVER_ADDR', 'localhost' );
|
||||
define( 'SQ_SERVER_PORT', 27015 );
|
||||
define( 'SQ_TIMEOUT', 3 );
|
||||
define( 'SQ_ENGINE', SourceQuery :: SOURCE );
|
||||
define( 'SQ_ENGINE', SourceQuery::SOURCE );
|
||||
// Edit this <-
|
||||
|
||||
$Timer = MicroTime( true );
|
||||
@@ -38,13 +40,12 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Source Query PHP Class</title>
|
||||
<title>Source Query PHP Library</title>
|
||||
|
||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
|
||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
|
||||
<style type="text/css">
|
||||
.jumbotron {
|
||||
margin-top: 30px;
|
||||
border-radius: 0;
|
||||
.table {
|
||||
border-top-color: #428BCA;
|
||||
}
|
||||
|
||||
.table thead th {
|
||||
@@ -56,19 +57,21 @@
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="jumbotron">
|
||||
<h1>Source Query PHP Class</h1>
|
||||
<div class="jumbotron">
|
||||
<div class="container">
|
||||
<h1>Source Query PHP Library</h1>
|
||||
|
||||
<p>This class was created to query game server which use the Source (Steamworks) query protocol.</p>
|
||||
<p class="lead">This library was created to query game server which use the Source (Steamworks) query protocol.</p>
|
||||
|
||||
<p>
|
||||
<a class="btn btn-large btn-primary" href="http://xpaw.me">Made by xPaw</a>
|
||||
<a class="btn btn-large btn-primary" href="https://github.com/xPaw/PHP-Source-Query-Class">View on GitHub</a>
|
||||
<a class="btn btn-large btn-danger" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">CC BY-NC-SA 3.0</a>
|
||||
<a class="btn btn-large btn-primary" href="https://xpaw.me">Made by xPaw</a>
|
||||
<a class="btn btn-large btn-primary" href="https://github.com/xPaw/PHP-Source-Query">View on GitHub</a>
|
||||
<a class="btn btn-large btn-danger" href="https://github.com/xPaw/PHP-Source-Query/blob/master/LICENSE">LGPL v2.1</a>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="container">
|
||||
<?php if( isset( $Exception ) ): ?>
|
||||
<div class="panel panel-primary">
|
||||
<div class="panel-heading"><?php echo Get_Class( $Exception ); ?> at line <?php echo $Exception->getLine( ); ?></div>
|
||||
@@ -81,7 +84,8 @@
|
||||
<table class="table table-bordered table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th colspan="2">Server Info <span class="label label-<?php echo $Timer > 1.0 ? 'danger' : 'success'; ?>"><?php echo $Timer; ?>s</span></th>
|
||||
<th>Server Info</th>
|
||||
<th><span class="label label-<?php echo $Timer > 1.0 ? 'danger' : 'success'; ?>"><?php echo $Timer; ?>s</span></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -132,7 +136,7 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if( Is_Array( $Players ) ): ?>
|
||||
<?php if( !empty( $Players ) ): ?>
|
||||
<?php foreach( $Players as $Player ): ?>
|
||||
<tr>
|
||||
<td><?php echo htmlspecialchars( $Player[ 'Name' ] ); ?></td>
|
||||
@@ -1,4 +1,4 @@
|
||||
# PHP Source Query [](https://packagist.org/packages/xpaw/php-source-query-class)
|
||||
# PHP Source Query [](https://packagist.org/packages/xpaw/php-source-query-class) [](https://packagist.org/packages/xpaw/php-source-query-class)
|
||||
|
||||
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.
|
||||
|
||||
@@ -10,7 +10,7 @@ The class also allows you to query servers using RCON although this only works f
|
||||
|
||||
**:warning: Please do not create issues when you are unable to retrieve information from a server, unless you can prove that there is a bug within the library.**
|
||||
|
||||
### Protocol specifications can be found over at VDC
|
||||
## Protocol Specifications
|
||||
* https://developer.valvesoftware.com/wiki/Server_queries
|
||||
* https://developer.valvesoftware.com/wiki/Source_RCON_Protocol
|
||||
|
||||
@@ -36,7 +36,7 @@ AppID | Game | Query | RCON | Notes
|
||||
|
||||
Open a pull request if you know another game which supports Source Query and/or RCON protocols.
|
||||
|
||||
# How to tell if the game supports Source Query Protocol?
|
||||
## How to tell if the game supports Source Query Protocol?
|
||||
|
||||
Add your server to your favourites in Steam server browser, and if Steam can display information about your server, then the protocol is supported.
|
||||
|
||||
@@ -76,7 +76,7 @@ Add your server to your favourites in Steam server browser, and if Steam can dis
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
Also refer to [an example](Example.php) to work things out.
|
||||
Also refer to [examples folder](Examples/) to work things out.
|
||||
|
||||
## License
|
||||
PHP Source Query
|
||||
|
||||
@@ -1,12 +1,23 @@
|
||||
<?php
|
||||
/**
|
||||
* Class written by xPaw
|
||||
* @author Pavel Djundik <sourcequery@xpaw.me>
|
||||
*
|
||||
* Website: https://xpaw.me
|
||||
* GitHub: https://github.com/xPaw/PHP-Source-Query-Class
|
||||
* @link https://xpaw.me
|
||||
* @link https://github.com/xPaw/PHP-Source-Query
|
||||
*
|
||||
* @license GNU Lesser General Public License, version 2.1
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
|
||||
class SourceQueryBuffer
|
||||
|
||||
namespace xPaw\SourceQuery;
|
||||
|
||||
/**
|
||||
* Class Buffer
|
||||
*
|
||||
* @package xPaw\SourceQuery
|
||||
*/
|
||||
class Buffer
|
||||
{
|
||||
/**
|
||||
* Buffer
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Pavel Djundik <sourcequery@xpaw.me>
|
||||
*
|
||||
* @link https://xpaw.me
|
||||
* @link https://github.com/xPaw/PHP-Source-Query
|
||||
*
|
||||
* @license GNU Lesser General Public License, version 2.1
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
|
||||
namespace xPaw\SourceQuery\Exception;
|
||||
|
||||
class AuthenticationException extends SourceQueryException
|
||||
{
|
||||
const BAD_PASSWORD = 1;
|
||||
const BANNED = 2;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Pavel Djundik <sourcequery@xpaw.me>
|
||||
*
|
||||
* @link https://xpaw.me
|
||||
* @link https://github.com/xPaw/PHP-Source-Query
|
||||
*
|
||||
* @license GNU Lesser General Public License, version 2.1
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
|
||||
namespace xPaw\SourceQuery\Exception;
|
||||
|
||||
class InvalidArgumentException extends SourceQueryException
|
||||
{
|
||||
const TIMEOUT_NOT_INTEGER = 1;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Pavel Djundik <sourcequery@xpaw.me>
|
||||
*
|
||||
* @link https://xpaw.me
|
||||
* @link https://github.com/xPaw/PHP-Source-Query
|
||||
*
|
||||
* @license GNU Lesser General Public License, version 2.1
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
|
||||
namespace xPaw\SourceQuery\Exception;
|
||||
|
||||
class InvalidPacketException extends SourceQueryException
|
||||
{
|
||||
const PACKET_HEADER_MISMATCH = 1;
|
||||
const BUFFER_EMPTY = 2;
|
||||
const BUFFER_NOT_EMPTY = 3;
|
||||
const CHECKSUM_MISMATCH = 4;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Pavel Djundik <sourcequery@xpaw.me>
|
||||
*
|
||||
* @link https://xpaw.me
|
||||
* @link https://github.com/xPaw/PHP-Source-Query
|
||||
*
|
||||
* @license GNU Lesser General Public License, version 2.1
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
|
||||
namespace xPaw\SourceQuery\Exception;
|
||||
|
||||
class SocketException extends SourceQueryException
|
||||
{
|
||||
const COULD_NOT_CREATE_SOCKET = 1;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Pavel Djundik <sourcequery@xpaw.me>
|
||||
*
|
||||
* @link https://xpaw.me
|
||||
* @link https://github.com/xPaw/PHP-Source-Query
|
||||
*
|
||||
* @license GNU Lesser General Public License, version 2.1
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
|
||||
namespace xPaw\SourceQuery\Exception;
|
||||
|
||||
abstract class SourceQueryException extends \Exception
|
||||
{
|
||||
// Base exception class
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Pavel Djundik <sourcequery@xpaw.me>
|
||||
*
|
||||
* @link https://xpaw.me
|
||||
* @link https://github.com/xPaw/PHP-Source-Query
|
||||
*
|
||||
* @license GNU Lesser General Public License, version 2.1
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
|
||||
namespace xPaw\SourceQuery\Exception;
|
||||
|
||||
class TimeoutException extends SourceQueryException
|
||||
{
|
||||
const TIMEOUT_CONNECT = 1;
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Class written by xPaw
|
||||
*
|
||||
* Website: https://xpaw.me
|
||||
* GitHub: https://github.com/xPaw/PHP-Source-Query-Class
|
||||
*/
|
||||
|
||||
namespace xPaw\SourceQuery\Exception;
|
||||
|
||||
abstract class SourceQueryException extends \Exception
|
||||
{
|
||||
// Base exception class
|
||||
}
|
||||
|
||||
class InvalidArgumentException extends SourceQueryException
|
||||
{
|
||||
const TIMEOUT_NOT_INTEGER = 1;
|
||||
}
|
||||
|
||||
class TimeoutException extends SourceQueryException
|
||||
{
|
||||
const TIMEOUT_CONNECT = 1;
|
||||
}
|
||||
|
||||
class InvalidPacketException extends SourceQueryException
|
||||
{
|
||||
const PACKET_HEADER_MISMATCH = 1;
|
||||
const BUFFER_EMPTY = 2;
|
||||
const BUFFER_NOT_EMPTY = 3;
|
||||
const CHECKSUM_MISMATCH = 4;
|
||||
}
|
||||
|
||||
class AuthenticationException extends SourceQueryException
|
||||
{
|
||||
const BAD_PASSWORD = 1;
|
||||
const BANNED = 2;
|
||||
}
|
||||
|
||||
class SocketException extends SourceQueryException
|
||||
{
|
||||
const COULD_NOT_CREATE_SOCKET = 1;
|
||||
}
|
||||
@@ -1,26 +1,39 @@
|
||||
<?php
|
||||
/**
|
||||
* Class written by xPaw
|
||||
* @author Pavel Djundik <sourcequery@xpaw.me>
|
||||
*
|
||||
* Website: https://xpaw.me
|
||||
* GitHub: https://github.com/xPaw/PHP-Source-Query-Class
|
||||
* @link https://xpaw.me
|
||||
* @link https://github.com/xPaw/PHP-Source-Query
|
||||
*
|
||||
* @license GNU Lesser General Public License, version 2.1
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
|
||||
namespace xPaw\SourceQuery;
|
||||
|
||||
use xPaw\SourceQuery\Exception\AuthenticationException;
|
||||
|
||||
class SourceQueryGoldSourceRcon
|
||||
|
||||
/**
|
||||
* Class GoldSourceRcon
|
||||
*
|
||||
* @package xPaw\SourceQuery
|
||||
*
|
||||
* @uses xPaw\SourceQuery\Exception\AuthenticationException
|
||||
*/
|
||||
class GoldSourceRcon
|
||||
{
|
||||
/**
|
||||
* Points to buffer class
|
||||
*
|
||||
* @var SourceQueryBuffer
|
||||
* @var Buffer
|
||||
*/
|
||||
private $Buffer;
|
||||
|
||||
/**
|
||||
* Points to socket class
|
||||
*
|
||||
* @var SourceQuerySocket
|
||||
* @var Socket
|
||||
*/
|
||||
private $Socket;
|
||||
|
||||
@@ -57,13 +70,14 @@
|
||||
/**
|
||||
* @param int $Length
|
||||
* @throws AuthenticationException
|
||||
* @return bool
|
||||
*/
|
||||
public function Read( $Length = 1400 )
|
||||
{
|
||||
// GoldSource RCON has same structure as Query
|
||||
$this->Socket->Read( );
|
||||
|
||||
if( $this->Buffer->GetByte( ) !== SourceQuery :: S2A_RCON )
|
||||
if( $this->Buffer->GetByte( ) !== SourceQuery::S2A_RCON )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -88,7 +102,7 @@
|
||||
{
|
||||
$this->Socket->Read( );
|
||||
|
||||
$ReadMore = $this->Buffer->Remaining( ) > 0 && $this->Buffer->GetByte( ) === SourceQuery :: S2A_RCON;
|
||||
$ReadMore = $this->Buffer->Remaining( ) > 0 && $this->Buffer->GetByte( ) === SourceQuery::S2A_RCON;
|
||||
|
||||
if( $ReadMore )
|
||||
{
|
||||
@@ -1,15 +1,29 @@
|
||||
<?php
|
||||
/**
|
||||
* Class written by xPaw
|
||||
* @author Pavel Djundik <sourcequery@xpaw.me>
|
||||
*
|
||||
* Website: https://xpaw.me
|
||||
* GitHub: https://github.com/xPaw/PHP-Source-Query-Class
|
||||
* @link https://xpaw.me
|
||||
* @link https://github.com/xPaw/PHP-Source-Query
|
||||
*
|
||||
* @license GNU Lesser General Public License, version 2.1
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
|
||||
namespace xPaw\SourceQuery;
|
||||
|
||||
use xPaw\SourceQuery\Exception\InvalidPacketException;
|
||||
use xPaw\SourceQuery\Exception\SocketException;
|
||||
|
||||
class SourceQuerySocket
|
||||
|
||||
/**
|
||||
* Class Socket
|
||||
*
|
||||
* @package xPaw\SourceQuery
|
||||
*
|
||||
* @uses xPaw\SourceQuery\Exception\InvalidPacketException
|
||||
* @uses xPaw\SourceQuery\Exception\SocketException
|
||||
*/
|
||||
class Socket
|
||||
{
|
||||
public $Socket;
|
||||
public $Engine;
|
||||
@@ -21,7 +35,7 @@
|
||||
/**
|
||||
* Points to buffer class
|
||||
*
|
||||
* @var SourceQueryBuffer
|
||||
* @var Buffer
|
||||
*/
|
||||
private $Buffer;
|
||||
|
||||
@@ -101,7 +115,7 @@
|
||||
|
||||
switch( $this->Engine )
|
||||
{
|
||||
case SourceQuery :: GOLDSOURCE:
|
||||
case SourceQuery::GOLDSOURCE:
|
||||
{
|
||||
$PacketCountAndNumber = $this->Buffer->GetByte( );
|
||||
$PacketCount = $PacketCountAndNumber & 0xF;
|
||||
@@ -109,7 +123,7 @@
|
||||
|
||||
break;
|
||||
}
|
||||
case SourceQuery :: SOURCE:
|
||||
case SourceQuery::SOURCE:
|
||||
{
|
||||
$IsCompressed = ( $RequestID & 0x80000000 ) !== 0;
|
||||
$PacketCount = $this->Buffer->GetByte( );
|
||||
@@ -144,7 +158,7 @@
|
||||
// Let's make sure this function exists, it's not included in PHP by default
|
||||
if( !Function_Exists( 'bzdecompress' ) )
|
||||
{
|
||||
throw new RuntimeException( 'Received compressed packet, PHP doesn\'t have Bzip2 library installed, can\'t decompress.' );
|
||||
throw new \RuntimeException( 'Received compressed packet, PHP doesn\'t have Bzip2 library installed, can\'t decompress.' );
|
||||
}
|
||||
|
||||
$Buffer = bzdecompress( $Buffer );
|
||||
@@ -1,30 +1,36 @@
|
||||
<?php
|
||||
/**
|
||||
* Class written by xPaw
|
||||
* This class provides the public interface to the PHP-Source-Query library.
|
||||
*
|
||||
* Website: https://xpaw.me
|
||||
* GitHub: https://github.com/xPaw/PHP-Source-Query-Class
|
||||
* @author Pavel Djundik <sourcequery@xpaw.me>
|
||||
*
|
||||
* Special thanks to koraktor for his awesome Steam Condenser class,
|
||||
* I used it as a reference at some points.
|
||||
* @link https://xpaw.me
|
||||
* @link https://github.com/xPaw/PHP-Source-Query
|
||||
*
|
||||
* @license GNU Lesser General Public License, version 2.1
|
||||
*/
|
||||
|
||||
require __DIR__ . '/Exceptions.class.php';
|
||||
require __DIR__ . '/Buffer.class.php';
|
||||
require __DIR__ . '/Socket.class.php';
|
||||
require __DIR__ . '/SourceRcon.class.php';
|
||||
require __DIR__ . '/GoldSourceRcon.class.php';
|
||||
|
||||
|
||||
namespace xPaw\SourceQuery;
|
||||
|
||||
use xPaw\SourceQuery\Exception\InvalidArgumentException;
|
||||
use xPaw\SourceQuery\Exception\TimeoutException;
|
||||
use xPaw\SourceQuery\Exception\InvalidPacketException;
|
||||
|
||||
|
||||
/**
|
||||
* Class SourceQuery
|
||||
*
|
||||
* @package xPaw\SourceQuery
|
||||
*
|
||||
* @uses xPaw\SourceQuery\Exception\InvalidArgumentException
|
||||
* @uses xPaw\SourceQuery\Exception\TimeoutException
|
||||
* @uses xPaw\SourceQuery\Exception\InvalidPacketException
|
||||
*/
|
||||
class SourceQuery
|
||||
{
|
||||
/**
|
||||
* Values returned by GetChallenge()
|
||||
*
|
||||
* TODO: Get rid of this? Improve? Do something else?
|
||||
* @todo Get rid of this? Improve? Do something else?
|
||||
*/
|
||||
const GETCHALLENGE_FAILED = 0;
|
||||
const GETCHALLENGE_ALL_CLEAR = 1;
|
||||
@@ -71,21 +77,21 @@
|
||||
/**
|
||||
* Points to rcon class
|
||||
*
|
||||
* @var SourceQueryRcon
|
||||
* @var SourceRcon
|
||||
*/
|
||||
private $Rcon;
|
||||
|
||||
/**
|
||||
* Points to buffer class
|
||||
*
|
||||
* @var SourceQueryBuffer
|
||||
* @var Buffer
|
||||
*/
|
||||
private $Buffer;
|
||||
|
||||
/**
|
||||
* Points to socket class
|
||||
*
|
||||
* @var SourceQuerySocket
|
||||
* @var Socket
|
||||
*/
|
||||
private $Socket;
|
||||
|
||||
@@ -112,8 +118,8 @@
|
||||
|
||||
public function __construct( )
|
||||
{
|
||||
$this->Buffer = new SourceQueryBuffer( );
|
||||
$this->Socket = new SourceQuerySocket( $this->Buffer );
|
||||
$this->Buffer = new Buffer( );
|
||||
$this->Socket = new Socket( $this->Buffer );
|
||||
}
|
||||
|
||||
public function __destruct( )
|
||||
@@ -132,7 +138,7 @@
|
||||
* @throws InvalidArgumentException
|
||||
* @throws TimeoutException
|
||||
*/
|
||||
public function Connect( $Ip, $Port, $Timeout = 3, $Engine = self :: SOURCE )
|
||||
public function Connect( $Ip, $Port, $Timeout = 3, $Engine = self::SOURCE )
|
||||
{
|
||||
$this->Disconnect( );
|
||||
|
||||
@@ -198,10 +204,10 @@
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->Socket->Write( self :: A2S_PING );
|
||||
$this->Socket->Write( self::A2S_PING );
|
||||
$this->Socket->Read( );
|
||||
|
||||
return $this->Buffer->GetByte( ) === self :: S2A_PING;
|
||||
return $this->Buffer->GetByte( ) === self::S2A_PING;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -218,7 +224,7 @@
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->Socket->Write( self :: A2S_INFO, "Source Engine Query\0" );
|
||||
$this->Socket->Write( self::A2S_INFO, "Source Engine Query\0" );
|
||||
$this->Socket->Read( );
|
||||
|
||||
$Type = $this->Buffer->GetByte( );
|
||||
@@ -229,7 +235,7 @@
|
||||
}
|
||||
|
||||
// Old GoldSource protocol, HLTV still uses it
|
||||
if( $Type === self :: S2A_INFO_OLD && $this->Socket->Engine === self :: GOLDSOURCE )
|
||||
if( $Type === self::S2A_INFO_OLD && $this->Socket->Engine === self::GOLDSOURCE )
|
||||
{
|
||||
/**
|
||||
* If we try to read data again, and we get the result with type S2A_INFO (0x49)
|
||||
@@ -272,7 +278,7 @@
|
||||
return $Server;
|
||||
}
|
||||
|
||||
if( $Type !== self :: S2A_INFO )
|
||||
if( $Type !== self::S2A_INFO )
|
||||
{
|
||||
throw new InvalidPacketException( 'GetInfo: Packet header mismatch. (0x' . DecHex( $Type ) . ')', InvalidPacketException::PACKET_HEADER_MISMATCH );
|
||||
}
|
||||
@@ -361,15 +367,15 @@
|
||||
return false;
|
||||
}
|
||||
|
||||
switch( $this->GetChallenge( self :: A2S_PLAYER, self :: S2A_PLAYER ) )
|
||||
switch( $this->GetChallenge( self::A2S_PLAYER, self::S2A_PLAYER ) )
|
||||
{
|
||||
case self :: GETCHALLENGE_FAILED:
|
||||
case self::GETCHALLENGE_FAILED:
|
||||
{
|
||||
return false;
|
||||
}
|
||||
case self :: GETCHALLENGE_ALL_CLEAR:
|
||||
case self::GETCHALLENGE_ALL_CLEAR:
|
||||
{
|
||||
$this->Socket->Write( self :: A2S_PLAYER, $this->Challenge );
|
||||
$this->Socket->Write( self::A2S_PLAYER, $this->Challenge );
|
||||
$this->Socket->Read( 14000 ); // Moronic Arma 3 developers do not split their packets, so we have to read more data
|
||||
// This violates the protocol spec, and they probably should fix it: https://developer.valvesoftware.com/wiki/Server_queries#Protocol
|
||||
|
||||
@@ -379,7 +385,7 @@
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if( $Type !== self :: S2A_PLAYER )
|
||||
else if( $Type !== self::S2A_PLAYER )
|
||||
{
|
||||
throw new InvalidPacketException( 'GetPlayers: Packet header mismatch. (0x' . DecHex( $Type ) . ')', InvalidPacketException::PACKET_HEADER_MISMATCH );
|
||||
}
|
||||
@@ -419,15 +425,15 @@
|
||||
return false;
|
||||
}
|
||||
|
||||
switch( $this->GetChallenge( self :: A2S_RULES, self :: S2A_RULES ) )
|
||||
switch( $this->GetChallenge( self::A2S_RULES, self::S2A_RULES ) )
|
||||
{
|
||||
case self :: GETCHALLENGE_FAILED:
|
||||
case self::GETCHALLENGE_FAILED:
|
||||
{
|
||||
return false;
|
||||
}
|
||||
case self :: GETCHALLENGE_ALL_CLEAR:
|
||||
case self::GETCHALLENGE_ALL_CLEAR:
|
||||
{
|
||||
$this->Socket->Write( self :: A2S_RULES, $this->Challenge );
|
||||
$this->Socket->Write( self::A2S_RULES, $this->Challenge );
|
||||
$this->Socket->Read( );
|
||||
|
||||
$Type = $this->Buffer->GetByte( );
|
||||
@@ -436,7 +442,7 @@
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if( $Type !== self :: S2A_RULES )
|
||||
else if( $Type !== self::S2A_RULES )
|
||||
{
|
||||
throw new InvalidPacketException( 'GetRules: Packet header mismatch. (0x' . DecHex( $Type ) . ')', InvalidPacketException::PACKET_HEADER_MISMATCH );
|
||||
}
|
||||
@@ -474,12 +480,12 @@
|
||||
{
|
||||
if( $this->Challenge )
|
||||
{
|
||||
return self :: GETCHALLENGE_ALL_CLEAR;
|
||||
return self::GETCHALLENGE_ALL_CLEAR;
|
||||
}
|
||||
|
||||
if( $this->UseOldGetChallengeMethod )
|
||||
{
|
||||
$Header = self :: A2S_SERVERQUERY_GETCHALLENGE;
|
||||
$Header = self::A2S_SERVERQUERY_GETCHALLENGE;
|
||||
}
|
||||
|
||||
$this->Socket->Write( $Header, 0xFFFFFFFF );
|
||||
@@ -489,21 +495,21 @@
|
||||
|
||||
switch( $Type )
|
||||
{
|
||||
case self :: S2A_CHALLENGE:
|
||||
case self::S2A_CHALLENGE:
|
||||
{
|
||||
$this->Challenge = $this->Buffer->Get( 4 );
|
||||
|
||||
return self :: GETCHALLENGE_ALL_CLEAR;
|
||||
return self::GETCHALLENGE_ALL_CLEAR;
|
||||
}
|
||||
case $ExpectedResult:
|
||||
{
|
||||
// Goldsource (HLTV)
|
||||
|
||||
return self :: GETCHALLENGE_CONTAINS_ANSWER;
|
||||
return self::GETCHALLENGE_CONTAINS_ANSWER;
|
||||
}
|
||||
case 0:
|
||||
{
|
||||
return self :: GETCHALLENGE_FAILED;
|
||||
return self::GETCHALLENGE_FAILED;
|
||||
}
|
||||
default:
|
||||
{
|
||||
@@ -528,15 +534,15 @@
|
||||
|
||||
switch( $this->Socket->Engine )
|
||||
{
|
||||
case SourceQuery :: GOLDSOURCE:
|
||||
case SourceQuery::GOLDSOURCE:
|
||||
{
|
||||
$this->Rcon = new SourceQueryGoldSourceRcon( $this->Buffer, $this->Socket );
|
||||
$this->Rcon = new GoldSourceRcon( $this->Buffer, $this->Socket );
|
||||
|
||||
break;
|
||||
}
|
||||
case SourceQuery :: SOURCE:
|
||||
case SourceQuery::SOURCE:
|
||||
{
|
||||
$this->Rcon = new SourceQuerySourceRcon( $this->Buffer, $this->Socket );
|
||||
$this->Rcon = new SourceRcon( $this->Buffer, $this->Socket );
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -1,28 +1,43 @@
|
||||
<?php
|
||||
/**
|
||||
* Class written by xPaw
|
||||
* @author Pavel Djundik <sourcequery@xpaw.me>
|
||||
*
|
||||
* Website: https://xpaw.me
|
||||
* GitHub: https://github.com/xPaw/PHP-Source-Query-Class
|
||||
* @link https://xpaw.me
|
||||
* @link https://github.com/xPaw/PHP-Source-Query
|
||||
*
|
||||
* @license GNU Lesser General Public License, version 2.1
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
|
||||
namespace xPaw\SourceQuery;
|
||||
|
||||
use xPaw\SourceQuery\Exception\AuthenticationException;
|
||||
use xPaw\SourceQuery\Exception\TimeoutException;
|
||||
use xPaw\SourceQuery\Exception\InvalidPacketException;
|
||||
|
||||
class SourceQuerySourceRcon
|
||||
|
||||
/**
|
||||
* Class SourceRcon
|
||||
*
|
||||
* @package xPaw\SourceQuery
|
||||
*
|
||||
* @uses xPaw\SourceQuery\Exception\AuthenticationException
|
||||
* @uses xPaw\SourceQuery\Exception\TimeoutException
|
||||
* @uses xPaw\SourceQuery\Exception\InvalidPacketException
|
||||
*/
|
||||
class SourceRcon
|
||||
{
|
||||
/**
|
||||
* Points to buffer class
|
||||
*
|
||||
* @var SourceQueryBuffer
|
||||
* @var Buffer
|
||||
*/
|
||||
private $Buffer;
|
||||
|
||||
/**
|
||||
* Points to socket class
|
||||
*
|
||||
* @var SourceQuerySocket
|
||||
* @var Socket
|
||||
*/
|
||||
private $Socket;
|
||||
|
||||
@@ -114,7 +129,7 @@
|
||||
|
||||
public function Command( $Command )
|
||||
{
|
||||
$this->Write( SourceQuery :: SERVERDATA_EXECCOMMAND, $Command );
|
||||
$this->Write( SourceQuery::SERVERDATA_EXECCOMMAND, $Command );
|
||||
|
||||
$this->Read( );
|
||||
|
||||
@@ -122,11 +137,11 @@
|
||||
|
||||
$Type = $this->Buffer->GetLong( );
|
||||
|
||||
if( $Type === SourceQuery :: SERVERDATA_AUTH_RESPONSE )
|
||||
if( $Type === SourceQuery::SERVERDATA_AUTH_RESPONSE )
|
||||
{
|
||||
throw new AuthenticationException( 'Bad rcon_password.', AuthenticationException::BAD_PASSWORD );
|
||||
}
|
||||
else if( $Type !== SourceQuery :: SERVERDATA_RESPONSE_VALUE )
|
||||
else if( $Type !== SourceQuery::SERVERDATA_RESPONSE_VALUE )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -139,13 +154,13 @@
|
||||
{
|
||||
do
|
||||
{
|
||||
$this->Write( SourceQuery :: SERVERDATA_RESPONSE_VALUE );
|
||||
$this->Write( SourceQuery::SERVERDATA_RESPONSE_VALUE );
|
||||
|
||||
$this->Read( );
|
||||
|
||||
$this->Buffer->GetLong( ); // RequestID
|
||||
|
||||
if( $this->Buffer->GetLong( ) !== SourceQuery :: SERVERDATA_RESPONSE_VALUE )
|
||||
if( $this->Buffer->GetLong( ) !== SourceQuery::SERVERDATA_RESPONSE_VALUE )
|
||||
{
|
||||
break;
|
||||
}
|
||||
@@ -167,7 +182,7 @@
|
||||
|
||||
public function Authorize( $Password )
|
||||
{
|
||||
$this->Write( SourceQuery :: SERVERDATA_AUTH, $Password );
|
||||
$this->Write( SourceQuery::SERVERDATA_AUTH, $Password );
|
||||
$this->Read( );
|
||||
|
||||
$RequestID = $this->Buffer->GetLong( );
|
||||
@@ -176,7 +191,7 @@
|
||||
// If we receive SERVERDATA_RESPONSE_VALUE, then we need to read again
|
||||
// More info: https://developer.valvesoftware.com/wiki/Source_RCON_Protocol#Additional_Comments
|
||||
|
||||
if( $Type === SourceQuery :: SERVERDATA_RESPONSE_VALUE )
|
||||
if( $Type === SourceQuery::SERVERDATA_RESPONSE_VALUE )
|
||||
{
|
||||
$this->Read( );
|
||||
|
||||
@@ -184,7 +199,7 @@
|
||||
$Type = $this->Buffer->GetLong( );
|
||||
}
|
||||
|
||||
if( $RequestID === -1 || $Type !== SourceQuery :: SERVERDATA_AUTH_RESPONSE )
|
||||
if( $RequestID === -1 || $Type !== SourceQuery::SERVERDATA_AUTH_RESPONSE )
|
||||
{
|
||||
throw new AuthenticationException( 'RCON authorization failed.', AuthenticationException::BAD_PASSWORD );
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
/**
|
||||
* Library to query servers that implement Source Engine Query protocol.
|
||||
*
|
||||
* Special thanks to koraktor for his awesome Steam Condenser class,
|
||||
* I used it as a reference at some points.
|
||||
*
|
||||
* @author Pavel Djundik <sourcequery@xpaw.me>
|
||||
*
|
||||
* @link https://xpaw.me
|
||||
* @link https://github.com/xPaw/PHP-Source-Query
|
||||
*
|
||||
* @license GNU Lesser General Public License, version 2.1
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/Exception/SourceQueryException.php';
|
||||
require_once __DIR__ . '/Exception/AuthenticationException.php';
|
||||
require_once __DIR__ . '/Exception/InvalidArgumentException.php';
|
||||
require_once __DIR__ . '/Exception/SocketException.php';
|
||||
require_once __DIR__ . '/Exception/InvalidPacketException.php';
|
||||
require_once __DIR__ . '/Exception/TimeoutException.php';
|
||||
|
||||
require_once __DIR__ . '/Buffer.php';
|
||||
require_once __DIR__ . '/Socket.php';
|
||||
require_once __DIR__ . '/SourceRcon.php';
|
||||
require_once __DIR__ . '/GoldSourceRcon.php';
|
||||
require_once __DIR__ . '/SourceQuery.php';
|
||||
+10
-5
@@ -8,8 +8,13 @@
|
||||
[
|
||||
"rcon",
|
||||
"minecraft",
|
||||
"csgo",
|
||||
"counter-strike",
|
||||
"team fortress"
|
||||
"team fortress",
|
||||
"starbound",
|
||||
"rust",
|
||||
"ark",
|
||||
"gmod"
|
||||
],
|
||||
"require":
|
||||
{
|
||||
@@ -17,9 +22,9 @@
|
||||
},
|
||||
"autoload":
|
||||
{
|
||||
"files":
|
||||
[
|
||||
"SourceQuery/SourceQuery.class.php"
|
||||
]
|
||||
"psr-4":
|
||||
{
|
||||
"xPaw\\SourceQuery\\": "SourceQuery/"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user