mirror of
https://github.com/xPaw/PHP-Source-Query.git
synced 2026-06-11 00:23:15 +02:00
Bring in stricter CS Fixer rules.
This commit is contained in:
@@ -5,8 +5,8 @@ declare(strict_types=1);
|
||||
/**
|
||||
* @author Pavel Djundik
|
||||
*
|
||||
* @link https://xpaw.me
|
||||
* @link https://github.com/xPaw/PHP-Source-Query
|
||||
* @see https://xpaw.me
|
||||
* @see https://github.com/xPaw/PHP-Source-Query
|
||||
*
|
||||
* @license GNU Lesser General Public License, version 2.1
|
||||
*
|
||||
@@ -24,16 +24,8 @@ abstract class AbstractRcon implements RconInterface
|
||||
/**
|
||||
* @throws AuthenticationException
|
||||
* @throws InvalidPacketException
|
||||
*
|
||||
* @return Buffer
|
||||
*/
|
||||
abstract protected function read(): Buffer;
|
||||
|
||||
/**
|
||||
* @param int|null $header
|
||||
* @param string $string
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
abstract protected function write(?int $header, string $string = ''): bool;
|
||||
}
|
||||
|
||||
@@ -5,8 +5,8 @@ declare(strict_types=1);
|
||||
/**
|
||||
* @author Pavel Djundik
|
||||
*
|
||||
* @link https://xpaw.me
|
||||
* @link https://github.com/xPaw/PHP-Source-Query
|
||||
* @see https://xpaw.me
|
||||
* @see https://github.com/xPaw/PHP-Source-Query
|
||||
*
|
||||
* @license GNU Lesser General Public License, version 2.1
|
||||
*
|
||||
@@ -24,49 +24,36 @@ use xPaw\SourceQuery\SourceQuery;
|
||||
final class GoldSourceRcon extends AbstractRcon
|
||||
{
|
||||
/**
|
||||
* Points to socket class
|
||||
*
|
||||
* @var SocketInterface
|
||||
* Points to socket class.
|
||||
*/
|
||||
private SocketInterface $socket;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private string $rconPassword = '';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private string $rconChallenge = '';
|
||||
|
||||
/**
|
||||
* @param SocketInterface $socket
|
||||
*/
|
||||
public function __construct(SocketInterface $socket)
|
||||
{
|
||||
$this->socket = $socket;
|
||||
}
|
||||
|
||||
/**
|
||||
* Open
|
||||
* Open.
|
||||
*/
|
||||
public function open(): void
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Close
|
||||
* Close.
|
||||
*/
|
||||
public function close(): void
|
||||
{
|
||||
$this->rconChallenge = '';
|
||||
$this->rconPassword = '';
|
||||
$this->rconPassword = '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $password
|
||||
*
|
||||
* @throws AuthenticationException
|
||||
*/
|
||||
public function authorize(string $password): void
|
||||
@@ -76,7 +63,7 @@ final class GoldSourceRcon extends AbstractRcon
|
||||
$this->write(null, 'challenge rcon');
|
||||
$buffer = $this->socket->read();
|
||||
|
||||
if ($buffer->get(14) !== 'challenge rcon') {
|
||||
if ('challenge rcon' !== $buffer->get(14)) {
|
||||
throw new AuthenticationException('Failed to get RCON challenge.', AuthenticationException::BAD_PASSWORD);
|
||||
}
|
||||
|
||||
@@ -84,10 +71,6 @@ final class GoldSourceRcon extends AbstractRcon
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $command
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws AuthenticationException
|
||||
* @throws InvalidPacketException
|
||||
*/
|
||||
@@ -106,8 +89,6 @@ final class GoldSourceRcon extends AbstractRcon
|
||||
/**
|
||||
* @throws AuthenticationException
|
||||
* @throws InvalidPacketException
|
||||
*
|
||||
* @return Buffer
|
||||
*/
|
||||
protected function read(): Buffer
|
||||
{
|
||||
@@ -121,7 +102,7 @@ final class GoldSourceRcon extends AbstractRcon
|
||||
$readMore = !$buffer->isEmpty();
|
||||
|
||||
if ($readMore) {
|
||||
if ($buffer->getByte() !== SourceQuery::S2A_RCON) {
|
||||
if (SourceQuery::S2A_RCON !== $buffer->getByte()) {
|
||||
throw new InvalidPacketException('Invalid rcon response.', InvalidPacketException::PACKET_HEADER_MISMATCH);
|
||||
}
|
||||
|
||||
@@ -140,9 +121,10 @@ final class GoldSourceRcon extends AbstractRcon
|
||||
|
||||
$trimmed = trim($stringBuffer);
|
||||
|
||||
if ($trimmed === 'Bad rcon_password.') {
|
||||
if ('Bad rcon_password.' === $trimmed) {
|
||||
throw new AuthenticationException($trimmed, AuthenticationException::BAD_PASSWORD);
|
||||
} elseif ($trimmed === 'You have been banned from this server.') {
|
||||
}
|
||||
if ('You have been banned from this server.' === $trimmed) {
|
||||
throw new AuthenticationException($trimmed, AuthenticationException::BANNED);
|
||||
}
|
||||
|
||||
@@ -151,12 +133,6 @@ final class GoldSourceRcon extends AbstractRcon
|
||||
return $buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int|null $header
|
||||
* @param string $string
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function write(?int $header, string $string = ''): bool
|
||||
{
|
||||
$command = pack('cccca*', 0xFF, 0xFF, 0xFF, 0xFF, $string);
|
||||
|
||||
@@ -5,8 +5,8 @@ declare(strict_types=1);
|
||||
/**
|
||||
* @author Pavel Djundik
|
||||
*
|
||||
* @link https://xpaw.me
|
||||
* @link https://github.com/xPaw/PHP-Source-Query
|
||||
* @see https://xpaw.me
|
||||
* @see https://github.com/xPaw/PHP-Source-Query
|
||||
*
|
||||
* @license GNU Lesser General Public License, version 2.1
|
||||
*
|
||||
@@ -21,33 +21,24 @@ use xPaw\SourceQuery\Socket\SocketInterface;
|
||||
|
||||
interface RconInterface
|
||||
{
|
||||
/**
|
||||
* @param SocketInterface $socket
|
||||
*/
|
||||
public function __construct(SocketInterface $socket);
|
||||
|
||||
/**
|
||||
* Open
|
||||
* Open.
|
||||
*/
|
||||
public function open(): void;
|
||||
|
||||
/**
|
||||
* Close
|
||||
* Close.
|
||||
*/
|
||||
public function close(): void;
|
||||
|
||||
/**
|
||||
* @param string $password
|
||||
*
|
||||
* @throws AuthenticationException
|
||||
*/
|
||||
public function authorize(string $password): void;
|
||||
|
||||
/**
|
||||
* @param string $command
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws AuthenticationException
|
||||
* @throws InvalidPacketException
|
||||
*/
|
||||
|
||||
@@ -5,8 +5,8 @@ declare(strict_types=1);
|
||||
/**
|
||||
* @author Pavel Djundik
|
||||
*
|
||||
* @link https://xpaw.me
|
||||
* @link https://github.com/xPaw/PHP-Source-Query
|
||||
* @see https://xpaw.me
|
||||
* @see https://github.com/xPaw/PHP-Source-Query
|
||||
*
|
||||
* @license GNU Lesser General Public License, version 2.1
|
||||
*
|
||||
@@ -25,7 +25,7 @@ use xPaw\SourceQuery\SourceQuery;
|
||||
final class SourceRcon extends AbstractRcon
|
||||
{
|
||||
/**
|
||||
* Points to socket class
|
||||
* Points to socket class.
|
||||
*/
|
||||
private SocketInterface $socket;
|
||||
|
||||
@@ -36,14 +36,8 @@ final class SourceRcon extends AbstractRcon
|
||||
*/
|
||||
private $rconSocket;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private int $rconRequestId = 0;
|
||||
|
||||
/**
|
||||
* @param SocketInterface $socket
|
||||
*/
|
||||
public function __construct(SocketInterface $socket)
|
||||
{
|
||||
$this->socket = $socket;
|
||||
@@ -74,7 +68,7 @@ final class SourceRcon extends AbstractRcon
|
||||
}
|
||||
|
||||
/**
|
||||
* Close
|
||||
* Close.
|
||||
*/
|
||||
public function close(): void
|
||||
{
|
||||
@@ -88,8 +82,6 @@ final class SourceRcon extends AbstractRcon
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $password
|
||||
*
|
||||
* @throws AuthenticationException
|
||||
* @throws InvalidPacketException
|
||||
*/
|
||||
@@ -104,23 +96,19 @@ final class SourceRcon extends AbstractRcon
|
||||
// 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 (SourceQuery::SERVERDATA_RESPONSE_VALUE === $type) {
|
||||
$buffer = $this->read();
|
||||
|
||||
$requestId = $buffer->getLong();
|
||||
$type = $buffer->getLong();
|
||||
}
|
||||
|
||||
if ($requestId === -1 || $type !== SourceQuery::SERVERDATA_AUTH_RESPONSE) {
|
||||
if (-1 === $requestId || SourceQuery::SERVERDATA_AUTH_RESPONSE !== $type) {
|
||||
throw new AuthenticationException('RCON authorization failed.', AuthenticationException::BAD_PASSWORD);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $command
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws AuthenticationException
|
||||
* @throws InvalidPacketException
|
||||
*/
|
||||
@@ -133,9 +121,10 @@ final class SourceRcon extends AbstractRcon
|
||||
|
||||
$type = $buffer->getLong();
|
||||
|
||||
if ($type === SourceQuery::SERVERDATA_AUTH_RESPONSE) {
|
||||
if (SourceQuery::SERVERDATA_AUTH_RESPONSE === $type) {
|
||||
throw new AuthenticationException('Bad rcon_password.', AuthenticationException::BAD_PASSWORD);
|
||||
} elseif ($type !== SourceQuery::SERVERDATA_RESPONSE_VALUE) {
|
||||
}
|
||||
if (SourceQuery::SERVERDATA_RESPONSE_VALUE !== $type) {
|
||||
throw new InvalidPacketException('Invalid rcon response.', InvalidPacketException::PACKET_HEADER_MISMATCH);
|
||||
}
|
||||
|
||||
@@ -151,13 +140,13 @@ final class SourceRcon extends AbstractRcon
|
||||
|
||||
$buffer->getLong(); // RequestID.
|
||||
|
||||
if ($buffer->getLong() !== SourceQuery::SERVERDATA_RESPONSE_VALUE) {
|
||||
if (SourceQuery::SERVERDATA_RESPONSE_VALUE !== $buffer->getLong()) {
|
||||
break;
|
||||
}
|
||||
|
||||
$data2 = $buffer->get();
|
||||
|
||||
if ($data2 === "\x00\x01\x00\x00\x00\x00") {
|
||||
if ("\x00\x01\x00\x00\x00\x00" === $data2) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -169,8 +158,6 @@ final class SourceRcon extends AbstractRcon
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Buffer
|
||||
*
|
||||
* @throws InvalidPacketException
|
||||
*/
|
||||
protected function read(): Buffer
|
||||
@@ -229,11 +216,6 @@ final class SourceRcon extends AbstractRcon
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int|null $header
|
||||
* @param string $string
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @throws InvalidPacketException
|
||||
*/
|
||||
protected function write(?int $header, string $string = ''): bool
|
||||
@@ -247,7 +229,7 @@ final class SourceRcon extends AbstractRcon
|
||||
|
||||
// Prepend packet length.
|
||||
$command = pack('V', strlen($command)) . $command;
|
||||
$length = strlen($command);
|
||||
$length = strlen($command);
|
||||
|
||||
return $length === fwrite($this->rconSocket, $command, $length);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user