diff --git a/SourceQuery/BaseSocket.php b/SourceQuery/BaseSocket.php new file mode 100644 index 0000000..ce35bc2 --- /dev/null +++ b/SourceQuery/BaseSocket.php @@ -0,0 +1,38 @@ + + * + * @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; + + /** + * Base socket interface + * + * @package xPaw\SourceQuery + */ + abstract class BaseSocket + { + public $Socket; + public $Engine; + + public $Ip; + public $Port; + public $Timeout; + + public function __destruct( ) + { + $this->Close( ); + } + + abstract public function Close( ); + abstract public function Open( $Ip, $Port, $Timeout, $Engine ); + abstract public function Write( $Header, $String = '' ); + abstract public function Read( $Length = 1400 ); + } diff --git a/SourceQuery/Socket.php b/SourceQuery/Socket.php index 554584d..df31def 100644 --- a/SourceQuery/Socket.php +++ b/SourceQuery/Socket.php @@ -23,15 +23,8 @@ * @uses xPaw\SourceQuery\Exception\InvalidPacketException * @uses xPaw\SourceQuery\Exception\SocketException */ - class Socket + class Socket extends BaseSocket { - public $Socket; - public $Engine; - - public $Ip; - public $Port; - public $Timeout; - public function Close( ) { if( $this->Socket ) diff --git a/SourceQuery/SourceQuery.php b/SourceQuery/SourceQuery.php index e3571b0..5ce30f0 100644 --- a/SourceQuery/SourceQuery.php +++ b/SourceQuery/SourceQuery.php @@ -109,9 +109,9 @@ */ private $UseOldGetChallengeMethod; - public function __construct( ) + public function __construct( BaseSocket $Socket = null ) { - $this->Socket = new Socket( ); + $this->Socket = $Socket ?: new Socket( ); } public function __destruct( ) diff --git a/SourceQuery/bootstrap.php b/SourceQuery/bootstrap.php index 1958607..585ddf2 100644 --- a/SourceQuery/bootstrap.php +++ b/SourceQuery/bootstrap.php @@ -20,6 +20,7 @@ require_once __DIR__ . '/Exception/InvalidPacketException.php'; require_once __DIR__ . '/Buffer.php'; + require_once __DIR__ . '/BaseSocket.php'; require_once __DIR__ . '/Socket.php'; require_once __DIR__ . '/SourceRcon.php'; require_once __DIR__ . '/GoldSourceRcon.php';