*/
abstract class Protocol
@@ -33,142 +31,97 @@ abstract class Protocol
/**
* Constants for class states
*/
- const STATE_TESTING = 1;
-
- const STATE_BETA = 2;
-
- const STATE_STABLE = 3;
-
- const STATE_DEPRECATED = 4;
+ public const STATE_TESTING = 1;
+ public const STATE_BETA = 2;
+ public const STATE_STABLE = 3;
+ public const STATE_DEPRECATED = 4;
/**
* Constants for packet keys
*/
- const PACKET_ALL = 'all'; // Some protocols allow all data to be sent back in one call.
-
- const PACKET_BASIC = 'basic';
-
- const PACKET_CHALLENGE = 'challenge';
-
- const PACKET_CHANNELS = 'channels'; // Voice servers
-
- const PACKET_DETAILS = 'details';
-
- const PACKET_INFO = 'info';
-
- const PACKET_PLAYERS = 'players';
+ public const PACKET_ALL = 'all'; // Some protocols allow all data to be sent back in one call.
+ public const PACKET_BASIC = 'basic';
- const PACKET_STATUS = 'status';
-
- const PACKET_RULES = 'rules';
-
- const PACKET_VERSION = 'version';
+ public const PACKET_CHALLENGE = 'challenge';
+ public const PACKET_CHANNELS = 'channels'; // Voice servers
+ public const PACKET_DETAILS = 'details';
+ public const PACKET_INFO = 'info';
+ public const PACKET_PLAYERS = 'players';
+ public const PACKET_STATUS = 'status';
+ public const PACKET_RULES = 'rules';
+ public const PACKET_VERSION = 'version';
/**
* Transport constants
*/
- const TRANSPORT_UDP = 'udp';
-
- const TRANSPORT_TCP = 'tcp';
-
- const TRANSPORT_SSL = 'ssl';
-
- const TRANSPORT_TLS = 'tls';
+ public const TRANSPORT_UDP = 'udp';
+ public const TRANSPORT_TCP = 'tcp';
+ public const TRANSPORT_SSL = 'ssl';
+ public const TRANSPORT_TLS = 'tls';
/**
* Short name of the protocol
- *
- * @type string
*/
- protected $name = 'unknown';
+ protected string $name = 'unknown';
/**
* The longer, fancier name for the protocol
- *
- * @type string
*/
- protected $name_long = 'unknown';
+ protected string $name_long = 'unknown';
/**
* The difference between the client port and query port
- *
- * @type int
*/
- protected $port_diff = 0;
+ protected int $port_diff = 0;
/**
* The transport method to use to actually send the data
* Default is UDP
- *
- * @type string
*/
- protected $transport = self::TRANSPORT_UDP;
+ protected string $transport = self::TRANSPORT_UDP;
/**
* The protocol type used when querying the server
- *
- * @type string
*/
- protected $protocol = 'unknown';
+ protected string $protocol = 'unknown';
/**
* Holds the valid packet types this protocol has available.
- *
- * @type array
*/
- protected $packets = [];
+ protected array $packets = [];
/**
* Holds the response headers and the method to use to process them.
- *
- * @type array
*/
- protected $responses = [];
+ protected array $responses = [];
/**
* Holds the list of methods to run when parsing the packet response(s) data. These
* methods should provide all the return information.
- *
- * @type array
*/
- protected $process_methods = [];
+ protected array $process_methods = [];
/**
* The packet responses received
- *
- * @type array
*/
- protected $packets_response = [];
-
- /**
- * Holds the instance of the result class
- *
- * @type null
- */
- protected $result = null;
+ protected array $packets_response = [];
/**
* Options for this protocol
- *
- * @type array
*/
- protected $options = [];
+ protected array $options = [];
/**
* Define the state of this class
- *
- * @type int
*/
- protected $state = self::STATE_STABLE;
+ protected int $state = self::STATE_STABLE;
/**
* Holds specific normalize settings
*
* @todo: Remove this ugly bulk by moving specific ones to their specific game(s)
- *
- * @type array
*/
- protected $normalize = [
+ protected array $normalize = [
// General
'general' => [
// target => source
@@ -205,14 +158,9 @@ abstract class Protocol
/**
* Quick join link
- *
- * @type string
*/
- protected $join_link = '';
+ protected ?string $join_link = null;
- /**
- * @param array $options
- */
public function __construct(array $options = [])
{
@@ -222,10 +170,8 @@ public function __construct(array $options = [])
/**
* String name of this class
- *
- * @return string
*/
- public function __toString()
+ public function __toString(): string
{
return $this->name;
@@ -233,10 +179,8 @@ public function __toString()
/**
* Get the port difference between the server's client (game) and query ports
- *
- * @return int
*/
- public function portDiff()
+ public function portDiff(): int
{
return $this->port_diff;
@@ -246,12 +190,8 @@ public function portDiff()
* "Find" the query port based off of the client port and port_diff
*
* This method is meant to be overloaded for more complex maths or lookup tables
- *
- * @param int $clientPort
- *
- * @return int
*/
- public function findQueryPort($clientPort)
+ public function findQueryPort(int $clientPort): int
{
return $clientPort + $this->port_diff;
@@ -259,10 +199,8 @@ public function findQueryPort($clientPort)
/**
* Return the join_link as defined by the protocol class
- *
- * @return string
*/
- public function joinLink()
+ public function joinLink(): ?string
{
return $this->join_link;
@@ -270,10 +208,8 @@ public function joinLink()
/**
* Short (callable) name of this class
- *
- * @return string
*/
- public function name()
+ public function name(): string
{
return $this->name;
@@ -281,10 +217,8 @@ public function name()
/**
* Long name of this class
- *
- * @return string
*/
- public function nameLong()
+ public function nameLong(): string
{
return $this->name_long;
@@ -292,10 +226,8 @@ public function nameLong()
/**
* Return the status of this Protocol Class
- *
- * @return int
*/
- public function state()
+ public function state(): int
{
return $this->state;
@@ -303,10 +235,8 @@ public function state()
/**
* Return the protocol property
- *
- * @return string
*/
- public function getProtocol()
+ public function getProtocol(): string
{
return $this->protocol;
@@ -314,16 +244,10 @@ public function getProtocol()
/**
* Get/set the transport type for this protocol
- *
- * @param string|null $type
- *
- * @return string
*/
- public function transport($type = null)
+ public function transport(?string $type = null): ?string
{
-
- // Act as setter
- if (!is_null($type)) {
+ if ($type !== null) {
$this->transport = $type;
}
@@ -332,15 +256,10 @@ public function transport($type = null)
/**
* Set the options for the protocol call
- *
- * @param array $options
- *
- * @return array
*/
- public function options($options = [])
+ public function options(array $options = []): array
{
- // Act as setter
if (!empty($options)) {
$this->options = $options;
}
@@ -355,31 +274,25 @@ public function options($options = [])
/**
* Return specific packet(s)
- *
- * @param array $type
- *
- * @return array
*/
- public function getPacket($type = [])
+ public function getPacket(array|string $type = []): array|string
{
-
$packets = [];
-
// We want an array of packets back
if (is_array($type) && !empty($type)) {
// Loop the packets
foreach ($this->packets as $packet_type => $packet_data) {
// We want this packet
- if (in_array($packet_type, $type)) {
+ if (in_array($packet_type, $type, true)) {
$packets[$packet_type] = $packet_data;
}
}
- } elseif ($type == '!challenge') {
+ } elseif ($type === '!challenge') {
// Loop the packets
foreach ($this->packets as $packet_type => $packet_data) {
// Dont want challenge packets
- if ($packet_type != self::PACKET_CHALLENGE) {
+ if ($packet_type !== self::PACKET_CHALLENGE) {
$packets[$packet_type] = $packet_data;
}
}
@@ -397,15 +310,9 @@ public function getPacket($type = [])
/**
* Get/set the packet response
- *
- * @param array|null $response
- *
- * @return array
*/
- public function packetResponse(array $response = null)
+ public function packetResponse(?array $response = null): array
{
-
- // Act as setter
if (!empty($response)) {
$this->packets_response = $response;
}
@@ -420,27 +327,17 @@ public function packetResponse(array $response = null)
/**
* Determine whether or not this protocol has a challenge needed before querying
- *
- * @return bool
*/
- public function hasChallenge()
+ public function hasChallenge(): bool
{
-
return (isset($this->packets[self::PACKET_CHALLENGE]) && !empty($this->packets[self::PACKET_CHALLENGE]));
}
/**
* Parse the challenge response and add it to the buffer items that need it.
* This should be overloaded by extending class
- *
- * @codeCoverageIgnore
- * @SuppressWarnings(PHPMD.UnusedFormalParameter)
- *
- * @param \GameQ\Buffer $challenge_buffer
- *
- * @return bool
*/
- public function challengeParseAndApply(Buffer $challenge_buffer)
+ public function challengeParseAndApply(Buffer $challenge_buffer): bool
{
return true;
@@ -448,12 +345,8 @@ public function challengeParseAndApply(Buffer $challenge_buffer)
/**
* Apply the challenge string to all the packets that need it.
- *
- * @param string $challenge_string
- *
- * @return bool
*/
- protected function challengeApply($challenge_string)
+ protected function challengeApply(string $challenge_string): bool
{
// Let's loop through all the packets and append the challenge where it is needed
@@ -465,11 +358,43 @@ protected function challengeApply($challenge_string)
}
/**
- * Get the normalize settings for the protocol
+ * Converts a string from ISO-8859-1 to UTF-8.
+ * This is a replacement for PHP's utf8_encode function that was deprecated with PHP 8.2.
+ *
+ * Source: symfony/polyfill-php72
+ * See https://github.com/symfony/polyfill-php72/blob/bf44a9fd41feaac72b074de600314a93e2ae78e2/Php72.php#L24-L38
*
- * @return array
+ * @author Nicolas Grekas
+ * @author Dariusz Rumiński > 1, $j = 0; $i < $len; ++$i, ++$j) {
+ switch (true) {
+ case $s[$i] < "\x80":
+ $s[$j] = $s[$i];
+ break;
+ case $s[$i] < "\xC0":
+ $s[$j] = "\xC2";
+ $s[++$j] = $s[$i];
+ break;
+ default:
+ $s[$j] = "\xC3";
+ $s[++$j] = \chr(\ord($s[$i]) - 64);
+ break;
+ }
+ }
+
+ return substr($s, 0, $j);
+ }
+
+ /**
+ * Get the normalize settings for the protocol
+ */
+ public function getNormalize(): array
{
return $this->normalize;
@@ -481,20 +406,13 @@ public function getNormalize()
/**
* Generic method to allow protocol classes to do work right before the query is sent
- *
- * @codeCoverageIgnore
- * @SuppressWarnings(PHPMD.UnusedFormalParameter)
- *
- * @param \GameQ\Server $server
*/
- public function beforeSend(Server $server)
+ public function beforeSend(Server $server): void
{
}
/**
* Method called to process query response data. Each extending class has to have one of these functions.
- *
- * @return mixed
*/
- abstract public function processResponse();
+ abstract public function processResponse(): mixed;
}
diff --git a/src/GameQ/Protocols/Aa3.php b/src/GameQ/Protocols/Aa3.php
index 6ffd412a..2ad70c16 100644
--- a/src/GameQ/Protocols/Aa3.php
+++ b/src/GameQ/Protocols/Aa3.php
@@ -29,25 +29,19 @@ class Aa3 extends Source
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'aa3';
+ protected string $name = 'aa3';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "America's Army 3";
+ protected string $name_long = "America's Army 3";
/**
* Query port = client_port + 18243
*
* client_port default 8777
* query_port default 27020
- *
- * @type int
*/
- protected $port_diff = 18243;
+ protected int $port_diff = 18243;
}
diff --git a/src/GameQ/Protocols/Aapg.php b/src/GameQ/Protocols/Aapg.php
index a207d4fe..784907e9 100644
--- a/src/GameQ/Protocols/Aapg.php
+++ b/src/GameQ/Protocols/Aapg.php
@@ -28,15 +28,11 @@ class Aapg extends Aa3
{
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'aapg';
+ protected string $name = 'aapg';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "America's Army: Proving Grounds";
+ protected string $name_long = "America's Army: Proving Grounds";
}
diff --git a/src/GameQ/Protocols/Arkse.php b/src/GameQ/Protocols/Arkse.php
index 3193c5a6..75c82288 100644
--- a/src/GameQ/Protocols/Arkse.php
+++ b/src/GameQ/Protocols/Arkse.php
@@ -29,23 +29,17 @@ class Arkse extends Source
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'arkse';
+ protected string $name = 'arkse';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "ARK: Survival Evolved";
+ protected string $name_long = "ARK: Survival Evolved";
/**
* query_port = client_port + 19238
* 27015 = 7777 + 19238
- *
- * @type int
*/
- protected $port_diff = 19238;
+ protected int $port_diff = 19238;
}
diff --git a/src/GameQ/Protocols/Arma.php b/src/GameQ/Protocols/Arma.php
index 2653872f..87e7c8c0 100644
--- a/src/GameQ/Protocols/Arma.php
+++ b/src/GameQ/Protocols/Arma.php
@@ -29,15 +29,11 @@ class Arma extends Gamespy2
{
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'arma';
+ protected string $name = 'arma';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "ArmA Armed Assault";
+ protected string $name_long = "ArmA Armed Assault";
}
diff --git a/src/GameQ/Protocols/Arma3.php b/src/GameQ/Protocols/Arma3.php
index fdc2cba4..f8a4e921 100644
--- a/src/GameQ/Protocols/Arma3.php
+++ b/src/GameQ/Protocols/Arma3.php
@@ -33,36 +33,36 @@
class Arma3 extends Source
{
// Base DLC names
- const BASE_DLC_KART = 'Karts';
- const BASE_DLC_MARKSMEN = 'Marksmen';
- const BASE_DLC_HELI = 'Helicopters';
- const BASE_DLC_CURATOR = 'Curator';
- const BASE_DLC_EXPANSION = 'Expansion';
- const BASE_DLC_JETS = 'Jets';
- const BASE_DLC_ORANGE = 'Laws of War';
- const BASE_DLC_ARGO = 'Malden';
- const BASE_DLC_TACOPS = 'Tac-Ops';
- const BASE_DLC_TANKS = 'Tanks';
- const BASE_DLC_CONTACT = 'Contact';
- const BASE_DLC_ENOCH = 'Contact (Platform)';
+ private const BASE_DLC_KART = 'Karts';
+ private const BASE_DLC_MARKSMEN = 'Marksmen';
+ private const BASE_DLC_HELI = 'Helicopters';
+ private const BASE_DLC_CURATOR = 'Curator';
+ private const BASE_DLC_EXPANSION = 'Expansion';
+ private const BASE_DLC_JETS = 'Jets';
+ private const BASE_DLC_ORANGE = 'Laws of War';
+ private const BASE_DLC_ARGO = 'Malden';
+ private const BASE_DLC_TACOPS = 'Tac-Ops';
+ private const BASE_DLC_TANKS = 'Tanks';
+ private const BASE_DLC_CONTACT = 'Contact';
+ private const BASE_DLC_ENOCH = 'Contact (Platform)';
// Special
- const BASE_DLC_AOW = 'Art of War';
+ private const BASE_DLC_AOW = 'Art of War';
// Creator DLC names
- const CREATOR_DLC_GM = 'Global Mobilization';
- const CREATOR_DLC_VN = 'S.O.G. Prairie Fire';
- const CREATOR_DLC_CSLA = 'ČSLA - Iron Curtain';
- const CREATOR_DLC_WS = 'Western Sahara';
+ /*
+ private const CREATOR_DLC_GM = 'Global Mobilization';
+ private const CREATOR_DLC_VN = 'S.O.G. Prairie Fire';
+ private const CREATOR_DLC_CSLA = 'ČSLA - Iron Curtain';
+ private const CREATOR_DLC_WS = 'Western Sahara';
+ */
/**
* DLC Flags/Bits as defined in the documentation.
*
* @see https://community.bistudio.com/wiki/Arma_3:_ServerBrowserProtocol3
- *
- * @var array
*/
- protected $dlcFlags = [
+ protected array $dlcFlags = [
0b0000000000000001 => self::BASE_DLC_KART,
0b0000000000000010 => self::BASE_DLC_MARKSMEN,
0b0000000000000100 => self::BASE_DLC_HELI,
@@ -83,30 +83,22 @@ class Arma3 extends Source
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'arma3';
+ protected string $name = 'arma3';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Arma3";
+ protected string $name_long = "Arma3";
/**
* Query port = client_port + 1
- *
- * @type int
*/
- protected $port_diff = 1;
+ protected int $port_diff = 1;
/**
* Process the rules since Arma3 changed their response for rules
*
- * @param Buffer $buffer
- *
* @return array
* @throws \GameQ\Exception\Protocol
*/
@@ -133,8 +125,7 @@ protected function processRules(Buffer $buffer)
// Make a new buffer with the reassembled data
$responseBuffer = new Buffer($data);
- // Kill the old buffer, should be empty
- unset($buffer, $data);
+ unset($data);
// Set the result to a new result instance
$result = new Result();
diff --git a/src/GameQ/Protocols/Armedassault2oa.php b/src/GameQ/Protocols/Armedassault2oa.php
index e527a38d..7b08c28a 100644
--- a/src/GameQ/Protocols/Armedassault2oa.php
+++ b/src/GameQ/Protocols/Armedassault2oa.php
@@ -29,22 +29,16 @@ class Armedassault2oa extends Source
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = "armedassault2oa";
+ protected string $name = "armedassault2oa";
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Armed Assault 2: Operation Arrowhead";
+ protected string $name_long = "Armed Assault 2: Operation Arrowhead";
/**
* Query port = client_port + 1
- *
- * @type int
*/
- protected $port_diff = 1;
+ protected int $port_diff = 1;
}
diff --git a/src/GameQ/Protocols/Ase.php b/src/GameQ/Protocols/Ase.php
index abc47818..61ccc26e 100644
--- a/src/GameQ/Protocols/Ase.php
+++ b/src/GameQ/Protocols/Ase.php
@@ -34,47 +34,35 @@ class Ase extends Protocol
/**
* Array of packets we want to look up.
* Each key should correspond to a defined method in this or a parent class
- *
- * @type array
*/
- protected $packets = [
+ protected array $packets = [
self::PACKET_ALL => "s",
];
/**
* The query protocol used to make the call
- *
- * @type string
*/
- protected $protocol = 'ase';
+ protected string $protocol = 'ase';
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'ase';
+ protected string $name = 'ase';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "All-Seeing Eye";
+ protected string $name_long = "All-Seeing Eye";
/**
* The client join link
- *
- * @type string
*/
- protected $join_link = null;
+ protected ?string $join_link = null;
/**
* Normalize settings for this protocol
- *
- * @type array
*/
- protected $normalize = [
+ protected array $normalize = [
// General
'general' => [
// target => source
@@ -100,10 +88,10 @@ class Ase extends Protocol
/**
* Process the response
*
- * @return array
+ * @return mixed
* @throws \GameQ\Exception\Protocol
*/
- public function processResponse()
+ public function processResponse(): mixed
{
// Create a new buffer
$buffer = new Buffer(implode('', $this->packets_response));
@@ -153,13 +141,9 @@ public function processResponse()
/**
* Handles processing the extra key/value pairs for server settings
- *
- * @param \GameQ\Buffer $buffer
- * @param \GameQ\Result $result
*/
- protected function processKeyValuePairs(Buffer &$buffer, Result &$result)
+ protected function processKeyValuePairs(Buffer $buffer, Result $result)
{
-
// Key / value pairs
while ($buffer->getLength()) {
$key = $buffer->readPascalString(1, true);
@@ -181,13 +165,9 @@ protected function processKeyValuePairs(Buffer &$buffer, Result &$result)
/**
* Handles processing the player and team data into a usable format
- *
- * @param \GameQ\Buffer $buffer
- * @param \GameQ\Result $result
*/
- protected function processPlayersAndTeams(Buffer &$buffer, Result &$result)
+ protected function processPlayersAndTeams(Buffer $buffer, Result $result)
{
-
// Players and team info
while ($buffer->getLength()) {
// Get the flags
diff --git a/src/GameQ/Protocols/Atlas.php b/src/GameQ/Protocols/Atlas.php
index 83406bae..64c6d4a0 100644
--- a/src/GameQ/Protocols/Atlas.php
+++ b/src/GameQ/Protocols/Atlas.php
@@ -29,17 +29,13 @@ class Atlas extends Source
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'atlas';
+ protected string $name = 'atlas';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Atlas";
+ protected string $name_long = "Atlas";
/**
* query_port = client_port + 51800
@@ -48,8 +44,6 @@ class Atlas extends Source
* this is the default value for the stock game server, both ports
* can be independently changed from the stock ones,
* making the port_diff logic useless.
- *
- * @type int
*/
- protected $port_diff = 51800;
+ protected int $port_diff = 51800;
}
diff --git a/src/GameQ/Protocols/Avorion.php b/src/GameQ/Protocols/Avorion.php
index b4aa2d7a..95ce25d8 100644
--- a/src/GameQ/Protocols/Avorion.php
+++ b/src/GameQ/Protocols/Avorion.php
@@ -27,22 +27,11 @@ class Avorion extends Source
{
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'avorion';
+ protected string $name = 'avorion';
/**
* Longer string name of this protocol class
- *
- * @type string
- */
- protected $name_long = "Avorion";
-
- /**
- * query_port = client_port + 1
- *
- * @type int
- * protected $port_diff = 1;
*/
+ protected string $name_long = "Avorion";
}
diff --git a/src/GameQ/Protocols/Barotrauma.php b/src/GameQ/Protocols/Barotrauma.php
index 643428a2..dd0d2c76 100644
--- a/src/GameQ/Protocols/Barotrauma.php
+++ b/src/GameQ/Protocols/Barotrauma.php
@@ -28,22 +28,16 @@ class Barotrauma extends Source
{
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'barotrauma';
+ protected string $name = 'barotrauma';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Barotrauma";
+ protected string $name_long = "Barotrauma";
/**
* query_port = client_port + 1
- *
- * @type int
*/
- protected $port_diff = 1;
+ protected int $port_diff = 1;
}
diff --git a/src/GameQ/Protocols/Batt1944.php b/src/GameQ/Protocols/Batt1944.php
index f0ff38e6..539e0a99 100644
--- a/src/GameQ/Protocols/Batt1944.php
+++ b/src/GameQ/Protocols/Batt1944.php
@@ -29,31 +29,23 @@ class Batt1944 extends Source
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'batt1944';
+ protected string $name = 'batt1944';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Battalion 1944";
+ protected string $name_long = "Battalion 1944";
/**
* query_port = client_port + 3
- *
- * @type int
*/
- protected $port_diff = 3;
+ protected int $port_diff = 3;
/**
* Normalize main fields
- *
- * @var array
*/
- protected $normalize = [
+ protected array $normalize = [
// General
'general' => [
// target => source
diff --git a/src/GameQ/Protocols/Bf1942.php b/src/GameQ/Protocols/Bf1942.php
index 4cf06c5e..f48f5b64 100644
--- a/src/GameQ/Protocols/Bf1942.php
+++ b/src/GameQ/Protocols/Bf1942.php
@@ -29,39 +29,29 @@ class Bf1942 extends Gamespy
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'bf1942';
+ protected string $name = 'bf1942';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Battlefield 1942";
+ protected string $name_long = "Battlefield 1942";
/**
* query_port = client_port + 8433
* 23000 = 14567 + 8433
- *
- * @type int
*/
- protected $port_diff = 8433;
+ protected int $port_diff = 8433;
/**
* The client join link
- *
- * @type string
*/
- protected $join_link = "bf1942://%s:%d";
+ protected ?string $join_link = "bf1942://%s:%d";
/**
* Normalize settings for this protocol
- *
- * @type array
*/
- protected $normalize = [
+ protected array $normalize = [
// General
'general' => [
// target => source
diff --git a/src/GameQ/Protocols/Bf2.php b/src/GameQ/Protocols/Bf2.php
index 0610f9d0..ca107d2c 100644
--- a/src/GameQ/Protocols/Bf2.php
+++ b/src/GameQ/Protocols/Bf2.php
@@ -29,48 +29,38 @@ class Bf2 extends Gamespy3
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'bf2';
+ protected string $name = 'bf2';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Battlefield 2";
+ protected string $name_long = "Battlefield 2";
/**
* query_port = client_port + 8433
* 29900 = 16567 + 13333
- *
- * @type int
*/
- protected $port_diff = 13333;
+ protected int $port_diff = 13333;
/**
* The client join link
- *
- * @type string
*/
- protected $join_link = "bf2://%s:%d";
+ protected ?string $join_link = "bf2://%s:%d";
/**
* BF2 has a different query packet to send than "normal" Gamespy 3
*
* @var array
*/
- protected $packets = [
+ protected array $packets = [
self::PACKET_ALL => "\xFE\xFD\x00\x10\x20\x30\x40\xFF\xFF\xFF\x01",
];
/**
* Normalize settings for this protocol
- *
- * @type array
*/
- protected $normalize = [
+ protected array $normalize = [
// General
'general' => [
// target => source
diff --git a/src/GameQ/Protocols/Bf3.php b/src/GameQ/Protocols/Bf3.php
index 90845159..8de1b567 100644
--- a/src/GameQ/Protocols/Bf3.php
+++ b/src/GameQ/Protocols/Bf3.php
@@ -36,10 +36,8 @@ class Bf3 extends Protocol
/**
* Array of packets we want to query.
- *
- * @type array
*/
- protected $packets = [
+ protected array $packets = [
self::PACKET_STATUS => "\x00\x00\x00\x21\x1b\x00\x00\x00\x01\x00\x00\x00\x0a\x00\x00\x00serverInfo\x00",
self::PACKET_VERSION => "\x00\x00\x00\x22\x18\x00\x00\x00\x01\x00\x00\x00\x07\x00\x00\x00version\x00",
self::PACKET_PLAYERS =>
@@ -49,9 +47,8 @@ class Bf3 extends Protocol
/**
* Use the response flag to figure out what method to run
*
- * @type array
*/
- protected $responses = [
+ protected array $responses = [
1627389952 => "processDetails", // a
1644167168 => "processVersion", // b
1660944384 => "processPlayers", // c
@@ -59,53 +56,39 @@ class Bf3 extends Protocol
/**
* The transport mode for this protocol is TCP
- *
- * @type string
- */
- protected $transport = self::TRANSPORT_TCP;
+ */
+ protected string $transport = self::TRANSPORT_TCP;
/**
* The query protocol used to make the call
- *
- * @type string
*/
- protected $protocol = 'bf3';
+ protected string $protocol = 'bf3';
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'bf3';
+ protected string $name = 'bf3';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Battlefield 3";
+ protected string $name_long = "Battlefield 3";
/**
* The client join link
- *
- * @type string
*/
- protected $join_link = null;
+ protected ?string $join_link = null;
/**
* query_port = client_port + 22000
* 47200 = 25200 + 22000
- *
- * @type int
*/
- protected $port_diff = 22000;
+ protected int $port_diff = 22000;
/**
* Normalize settings for this protocol
- *
- * @type array
*/
- protected $normalize = [
+ protected array $normalize = [
// General
'general' => [
// target => source
@@ -129,10 +112,10 @@ class Bf3 extends Protocol
/**
* Process the response for the StarMade server
*
- * @return array
+ * @return mixed
* @throws \GameQ\Exception\Protocol
*/
- public function processResponse()
+ public function processResponse(): mixed
{
// Holds the results sent back
@@ -176,7 +159,7 @@ public function processResponse()
// Check to make sure the expected length matches the real length
// Subtract 4 for the sequence_id pulled out earlier
- if ($packetLength != ($buffer->readInt32() - 4)) {
+ if ($packetLength !== ($buffer->readInt32() - 4)) {
throw new Exception(__METHOD__ . " packet length does not match expected length!");
}
@@ -196,8 +179,7 @@ public function processResponse()
/**
* Decode the buffer into a usable format
- *
- * @param \GameQ\Buffer $buffer
+
*
* @return array
*/
@@ -223,8 +205,7 @@ protected function decode(Buffer $buffer)
/**
* Process the server details
- *
- * @param \GameQ\Buffer $buffer
+
*
* @return array
*/
@@ -282,15 +263,14 @@ protected function processDetails(Buffer $buffer)
// Added in R29, No docs as of yet
$result->add('quickmatch', (int)$items[$index_current + 13]); // Guessed from research
- unset($items, $index_current, $teamCount, $buffer);
+ unset($items, $index_current, $teamCount);
return $result->fetch();
}
/**
* Process the server version
- *
- * @param \GameQ\Buffer $buffer
+
*
* @return array
*/
@@ -305,15 +285,14 @@ protected function processVersion(Buffer $buffer)
$result->add('version', $items[2]);
- unset($buffer, $items);
+ unset($items);
return $result->fetch();
}
/**
* Process the players
- *
- * @param \GameQ\Buffer $buffer
+
*
* @return array
*/
diff --git a/src/GameQ/Protocols/Bf4.php b/src/GameQ/Protocols/Bf4.php
index 69517529..ce13a33a 100644
--- a/src/GameQ/Protocols/Bf4.php
+++ b/src/GameQ/Protocols/Bf4.php
@@ -34,22 +34,17 @@ class Bf4 extends Bf3
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'bf4';
+ protected string $name = 'bf4';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Battlefield 4";
+ protected string $name_long = "Battlefield 4";
/**
* Handle processing details since they are different than BF3
- *
- * @param \GameQ\Buffer $buffer
+
*
* @return array
*/
@@ -107,7 +102,7 @@ protected function processDetails(Buffer $buffer)
$result->add('blaze_player_count', (int) $items[$index_current + 13]);
$result->add('blaze_game_state', (int) $items[$index_current + 14]);
- unset($items, $index_current, $teamCount, $buffer);
+ unset($items, $index_current, $teamCount);
return $result->fetch();
}
diff --git a/src/GameQ/Protocols/Bfbc2.php b/src/GameQ/Protocols/Bfbc2.php
index b7167a02..f32a1cff 100644
--- a/src/GameQ/Protocols/Bfbc2.php
+++ b/src/GameQ/Protocols/Bfbc2.php
@@ -39,10 +39,8 @@ class Bfbc2 extends Protocol
/**
* Array of packets we want to query.
- *
- * @type array
*/
- protected $packets = [
+ protected array $packets = [
self::PACKET_VERSION => "\x00\x00\x00\x00\x18\x00\x00\x00\x01\x00\x00\x00\x07\x00\x00\x00version\x00",
self::PACKET_STATUS => "\x00\x00\x00\x00\x1b\x00\x00\x00\x01\x00\x00\x00\x0a\x00\x00\x00serverInfo\x00",
self::PACKET_PLAYERS => "\x00\x00\x00\x00\x24\x00\x00\x00\x02\x00\x00\x00\x0b\x00\x00\x00listPlayers\x00\x03\x00\x00\x00\x61ll\x00",
@@ -51,9 +49,8 @@ class Bfbc2 extends Protocol
/**
* Use the response flag to figure out what method to run
*
- * @type array
*/
- protected $responses = [
+ protected array $responses = [
"processVersion",
"processDetails",
"processPlayers",
@@ -61,53 +58,39 @@ class Bfbc2 extends Protocol
/**
* The transport mode for this protocol is TCP
- *
- * @type string
- */
- protected $transport = self::TRANSPORT_TCP;
+ */
+ protected string $transport = self::TRANSPORT_TCP;
/**
* The query protocol used to make the call
- *
- * @type string
*/
- protected $protocol = 'bfbc2';
+ protected string $protocol = 'bfbc2';
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'bfbc2';
+ protected string $name = 'bfbc2';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Battlefield Bad Company 2";
+ protected string $name_long = "Battlefield Bad Company 2";
/**
* The client join link
- *
- * @type string
*/
- protected $join_link = null;
+ protected ?string $join_link = null;
/**
* query_port = client_port + 29321
* 48888 = 19567 + 29321
- *
- * @type int
*/
- protected $port_diff = 29321;
+ protected int $port_diff = 29321;
/**
* Normalize settings for this protocol
- *
- * @type array
*/
- protected $normalize = [
+ protected array $normalize = [
// General
'general' => [
// target => source
@@ -131,10 +114,10 @@ class Bfbc2 extends Protocol
/**
* Process the response for the StarMade server
*
- * @return array
+ * @return mixed
* @throws \GameQ\Exception\Protocol
*/
- public function processResponse()
+ public function processResponse(): mixed
{
//print_r($this->packets_response);
@@ -156,7 +139,7 @@ public function processResponse()
// Check to make sure the expected length matches the real length
// Subtract 4 for the header burn
- if ($packetLength != ($buffer->readInt32() - 4)) {
+ if ($packetLength !== ($buffer->readInt32() - 4)) {
throw new Exception(__METHOD__ . " packet length does not match expected length!");
}
@@ -178,8 +161,7 @@ public function processResponse()
/**
* Decode the buffer into a usable format
- *
- * @param \GameQ\Buffer $buffer
+
*
* @return array
*/
@@ -205,8 +187,7 @@ protected function decode(Buffer $buffer)
/**
* Process the server details
- *
- * @param \GameQ\Buffer $buffer
+
*
* @return array
*/
@@ -261,15 +242,14 @@ protected function processDetails(Buffer $buffer)
$result->add('join_queue', (($items[$index_current + 11] == 'true') ? 1 : 0));
$result->add('region', $items[$index_current + 12]);
- unset($items, $index_current, $teamCount, $buffer);
+ unset($items, $index_current, $teamCount);
return $result->fetch();
}
/**
* Process the server version
- *
- * @param \GameQ\Buffer $buffer
+
*
* @return array
*/
@@ -283,15 +263,14 @@ protected function processVersion(Buffer $buffer)
$result->add('version', $items[2]);
- unset($buffer, $items);
+ unset($items);
return $result->fetch();
}
/**
* Process the players
- *
- * @param \GameQ\Buffer $buffer
+
*
* @return array
*/
diff --git a/src/GameQ/Protocols/Bfh.php b/src/GameQ/Protocols/Bfh.php
index 067d77f9..5e8d47ff 100644
--- a/src/GameQ/Protocols/Bfh.php
+++ b/src/GameQ/Protocols/Bfh.php
@@ -29,15 +29,11 @@ class Bfh extends Bf4
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'bfh';
+ protected string $name = 'bfh';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Battlefield Hardline";
+ protected string $name_long = "Battlefield Hardline";
}
diff --git a/src/GameQ/Protocols/Blackmesa.php b/src/GameQ/Protocols/Blackmesa.php
index efaafdfb..903c8d13 100644
--- a/src/GameQ/Protocols/Blackmesa.php
+++ b/src/GameQ/Protocols/Blackmesa.php
@@ -28,15 +28,11 @@ class Blackmesa extends Source
{
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'blackmesa';
+ protected string $name = 'blackmesa';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Black Mesa";
+ protected string $name_long = "Black Mesa";
}
diff --git a/src/GameQ/Protocols/Brink.php b/src/GameQ/Protocols/Brink.php
index 20226525..d1696bba 100644
--- a/src/GameQ/Protocols/Brink.php
+++ b/src/GameQ/Protocols/Brink.php
@@ -29,22 +29,16 @@ class Brink extends Source
{
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'brink';
+ protected string $name = 'brink';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Brink";
+ protected string $name_long = "Brink";
/**
* query_port = client_port + 1
- *
- * @type int
*/
- protected $port_diff = 1;
+ protected int $port_diff = 1;
}
diff --git a/src/GameQ/Protocols/Cfx.php b/src/GameQ/Protocols/Cfx.php
index 0aa92659..0faacde9 100644
--- a/src/GameQ/Protocols/Cfx.php
+++ b/src/GameQ/Protocols/Cfx.php
@@ -23,7 +23,6 @@
use GameQ\Protocol;
use GameQ\Result;
use GameQ\Server;
-use GameQ\Protocols\Http;
/**
* GTA Five M Protocol Class
@@ -43,56 +42,43 @@ class Cfx extends Protocol
/**
* Array of packets we want to look up.
* Each key should correspond to a defined method in this or a parent class
- *
- * @type array
*/
- protected $packets = [
+ protected array $packets = [
self::PACKET_STATUS => "\xFF\xFF\xFF\xFFgetinfo xxx",
];
/**
* Use the response flag to figure out what method to run
*
- * @type array
*/
- protected $responses = [
+ protected array $responses = [
"\xFF\xFF\xFF\xFFinfoResponse" => "processStatus",
];
/**
* The query protocol used to make the call
- *
- * @type string
*/
- protected $protocol = 'cfx';
+ protected string $protocol = 'cfx';
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'cfx';
+ protected string $name = 'cfx';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "CitizenFX";
+ protected string $name_long = "CitizenFX";
/**
- * Holds the Player list so we can overwrite it back
- *
- * @var string
+ * Holds the player list so we can overwrite it back
*/
- protected $PlayerList = [];
+ protected array $playerList = [];
/**
* Normalize settings for this protocol
- *
- * @type array
*/
- protected $normalize = [
+ protected array $normalize = [
// General
'general' => [
// target => source
@@ -109,7 +95,7 @@ class Cfx extends Protocol
/**
* Get FiveM players list using a sub query
*/
- public function beforeSend(Server $server)
+ public function beforeSend(Server $server): void
{
$GameQ = new \GameQ\GameQ();
$GameQ->addServer([
@@ -117,16 +103,16 @@ public function beforeSend(Server $server)
'host' => "$server->ip:$server->port_query",
]);
$results = $GameQ->process();
- $this->PlayerList = isset($results[0]) && isset($results[0][0]) ? $results[0][0] : [];
+ $this->playerList = $results[0][0] ?? [];
}
/**
* Process the response
*
- * @return array
+ * @return mixed
* @throws \GameQ\Exception\Protocol
*/
- public function processResponse()
+ public function processResponse(): mixed
{
// In case it comes back as multiple packets (it shouldn't)
$buffer = new Buffer(implode('', $this->packets_response));
@@ -136,13 +122,11 @@ public function processResponse()
// Figure out which packet response this is
if (empty($response_type) || !array_key_exists($response_type, $this->responses)) {
- throw new Exception(__METHOD__ . " response type '{$response_type}' is not valid");
+ throw new Exception(__METHOD__ . " response type '$response_type' is not valid");
}
// Offload the call
- $results = call_user_func_array([$this, $this->responses[$response_type]], [$buffer]);
-
- return $results;
+ return $this->{$this->responses[$response_type]}($buffer);
}
/*
@@ -152,8 +136,6 @@ public function processResponse()
/**
* Handle processing the status response
*
- * @param Buffer $buffer
- *
* @return array
*/
protected function processStatus(Buffer $buffer)
@@ -162,17 +144,14 @@ protected function processStatus(Buffer $buffer)
$result = new Result();
// Lets peek and see if the data starts with a \
- if ($buffer->lookAhead(1) == '\\') {
+ if ($buffer->lookAhead() === '\\') {
// Burn the first one
- $buffer->skip(1);
+ $buffer->skip();
}
// Explode the data
$data = explode('\\', $buffer->getBuffer());
- // No longer needed
- unset($buffer);
-
$itemCount = count($data);
// Now lets loop the array
@@ -181,7 +160,7 @@ protected function processStatus(Buffer $buffer)
$key = $data[$x];
$val = $data[$x + 1];
- if (in_array($key, ['challenge'])) {
+ if ($key === 'challenge') {
continue; // skip
}
@@ -190,8 +169,8 @@ protected function processStatus(Buffer $buffer)
}
// Add result of sub http-protocol if available
- if ($this->PlayerList) {
- $result->add('players', $this->PlayerList);
+ if ($this->playerList) {
+ $result->add('players', $this->playerList);
}
return $result->fetch();
diff --git a/src/GameQ/Protocols/Cfxplayers.php b/src/GameQ/Protocols/Cfxplayers.php
index 02897c38..393e8441 100644
--- a/src/GameQ/Protocols/Cfxplayers.php
+++ b/src/GameQ/Protocols/Cfxplayers.php
@@ -20,7 +20,6 @@
namespace GameQ\Protocols;
use GameQ\Exception\Protocol as Exception;
-use GameQ\Protocols\Http;
/**
* GTA Five M Protocol Class
@@ -35,59 +34,36 @@
* @author Jesse Lukas
*/
-class CFXPlayers extends Http
+class Cfxplayers extends Http
{
- /**
- * Holds the real ip so we can overwrite it back
- *
- * @var string
- */
- protected $realIp = null;
-
- /**
- * Holds the real port so we can overwrite it back
- *
- * @var int
- */
- protected $realPortQuery = null;
-
/**
* Packets to send
- *
- * @var array
*/
- protected $packets = [
+ protected array $packets = [
self::PACKET_STATUS => "GET /players.json HTTP/1.0\r\nAccept: */*\r\n\r\n", // Player List
];
/**
* The protocol being used
- *
- * @var string
*/
- protected $protocol = 'cfxplayers';
+ protected string $protocol = 'cfxplayers';
/**
* String name of this protocol class
- *
- * @var string
*/
- protected $name = 'cfxplayers';
+ protected string $name = 'cfxplayers';
/**
* Longer string name of this protocol class
- *
- * @var string
*/
- protected $name_long = "cfxplayers";
+ protected string $name_long = "cfxplayers";
/**
* Process the response
*
- * @return array
* @throws Exception
*/
- public function processResponse()
+ public function processResponse(): mixed
{
// Make sure we have any players
if (empty($this->packets_response)) {
diff --git a/src/GameQ/Protocols/Citadel.php b/src/GameQ/Protocols/Citadel.php
index 3d1074b1..86147720 100644
--- a/src/GameQ/Protocols/Citadel.php
+++ b/src/GameQ/Protocols/Citadel.php
@@ -28,15 +28,11 @@ class Citadel extends Source
{
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'citadel';
+ protected string $name = 'citadel';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Citadel";
+ protected string $name_long = "Citadel";
}
diff --git a/src/GameQ/Protocols/Cod.php b/src/GameQ/Protocols/Cod.php
index 2425ea67..354f5dca 100644
--- a/src/GameQ/Protocols/Cod.php
+++ b/src/GameQ/Protocols/Cod.php
@@ -29,15 +29,11 @@ class Cod extends Quake3
{
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'cod';
+ protected string $name = 'cod';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Call of Duty";
+ protected string $name_long = "Call of Duty";
}
diff --git a/src/GameQ/Protocols/Cod2.php b/src/GameQ/Protocols/Cod2.php
index 79be7ca2..31d573f3 100644
--- a/src/GameQ/Protocols/Cod2.php
+++ b/src/GameQ/Protocols/Cod2.php
@@ -28,15 +28,11 @@ class Cod2 extends Quake3
{
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'cod2';
+ protected string $name = 'cod2';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Call of Duty 2";
+ protected string $name_long = "Call of Duty 2";
}
diff --git a/src/GameQ/Protocols/Cod4.php b/src/GameQ/Protocols/Cod4.php
index 9838d9cb..95cc47e9 100644
--- a/src/GameQ/Protocols/Cod4.php
+++ b/src/GameQ/Protocols/Cod4.php
@@ -28,15 +28,11 @@ class Cod4 extends Quake3
{
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'cod4';
+ protected string $name = 'cod4';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Call of Duty 4";
+ protected string $name_long = "Call of Duty 4";
}
diff --git a/src/GameQ/Protocols/Codmw2.php b/src/GameQ/Protocols/Codmw2.php
index 290e43c9..abf1c89b 100644
--- a/src/GameQ/Protocols/Codmw2.php
+++ b/src/GameQ/Protocols/Codmw2.php
@@ -31,17 +31,13 @@ class Codmw2 extends Quake3
{
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'codmw2';
+ protected string $name = 'codmw2';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Call of Duty: Modern Warfare 2";
+ protected string $name_long = "Call of Duty: Modern Warfare 2";
protected function processPlayers(Buffer $buffer)
{
@@ -60,10 +56,10 @@ protected function processPlayers(Buffer $buffer)
];
// Skip first "
- $playerInfo->skip(1);
+ $playerInfo->skip();
// Add player name, encoded
- $player['name'] = utf8_encode(trim(($playerInfo->readString('"'))));
+ $player['name'] = $this->convertToUtf8(trim(($playerInfo->readString('"'))));
// Add player
$players[] = $player;
@@ -80,9 +76,8 @@ protected function processPlayers(Buffer $buffer)
// Add Playercount
$result->add('clients', count($players));
-
- // Clear
- unset($buffer, $players);
+
+ unset($players);
return $result->fetch();
}
diff --git a/src/GameQ/Protocols/Codmw3.php b/src/GameQ/Protocols/Codmw3.php
index 1049b602..603cac1c 100644
--- a/src/GameQ/Protocols/Codmw3.php
+++ b/src/GameQ/Protocols/Codmw3.php
@@ -29,22 +29,16 @@ class Codmw3 extends Source
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'codmw3';
+ protected string $name = 'codmw3';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Call of Duty: Modern Warfare 3";
+ protected string $name_long = "Call of Duty: Modern Warfare 3";
/**
* query_port = client_port + 2
- *
- * @type int
*/
- protected $port_diff = 2;
+ protected int $port_diff = 2;
}
diff --git a/src/GameQ/Protocols/Coduo.php b/src/GameQ/Protocols/Coduo.php
index 2dd9a182..41368a40 100644
--- a/src/GameQ/Protocols/Coduo.php
+++ b/src/GameQ/Protocols/Coduo.php
@@ -29,15 +29,11 @@ class Coduo extends Quake3
{
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'coduo';
+ protected string $name = 'coduo';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Call of Duty: United Offensive";
+ protected string $name_long = "Call of Duty: United Offensive";
}
diff --git a/src/GameQ/Protocols/Codwaw.php b/src/GameQ/Protocols/Codwaw.php
index f730678e..05f1c899 100644
--- a/src/GameQ/Protocols/Codwaw.php
+++ b/src/GameQ/Protocols/Codwaw.php
@@ -29,15 +29,11 @@ class Codwaw extends Quake3
{
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'codwaw';
+ protected string $name = 'codwaw';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Call of Duty: World at War";
+ protected string $name_long = "Call of Duty: World at War";
}
diff --git a/src/GameQ/Protocols/Conanexiles.php b/src/GameQ/Protocols/Conanexiles.php
index a097e1d8..a5f8a274 100644
--- a/src/GameQ/Protocols/Conanexiles.php
+++ b/src/GameQ/Protocols/Conanexiles.php
@@ -28,15 +28,11 @@ class Conanexiles extends Source
{
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'conanexiles';
+ protected string $name = 'conanexiles';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Conan Exiles";
+ protected string $name_long = "Conan Exiles";
}
diff --git a/src/GameQ/Protocols/Contagion.php b/src/GameQ/Protocols/Contagion.php
index 64d0b76e..d8873956 100644
--- a/src/GameQ/Protocols/Contagion.php
+++ b/src/GameQ/Protocols/Contagion.php
@@ -29,14 +29,10 @@ class Contagion extends Source
{
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'contagion';
+ protected string $name = 'contagion';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Contagion";
+ protected string $name_long = "Contagion";
}
diff --git a/src/GameQ/Protocols/Crysis.php b/src/GameQ/Protocols/Crysis.php
index e09a673d..b380c61e 100644
--- a/src/GameQ/Protocols/Crysis.php
+++ b/src/GameQ/Protocols/Crysis.php
@@ -29,15 +29,11 @@ class Crysis extends Gamespy3
{
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'crysis';
+ protected string $name = 'crysis';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Crysis";
+ protected string $name_long = "Crysis";
}
diff --git a/src/GameQ/Protocols/Crysis2.php b/src/GameQ/Protocols/Crysis2.php
index 75c6614a..03c383f3 100644
--- a/src/GameQ/Protocols/Crysis2.php
+++ b/src/GameQ/Protocols/Crysis2.php
@@ -29,15 +29,11 @@ class Crysis2 extends Gamespy3
{
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'crysis2';
+ protected string $name = 'crysis2';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Crysis 2";
+ protected string $name_long = "Crysis 2";
}
diff --git a/src/GameQ/Protocols/Crysiswars.php b/src/GameQ/Protocols/Crysiswars.php
index 44dcdcf1..756efacd 100644
--- a/src/GameQ/Protocols/Crysiswars.php
+++ b/src/GameQ/Protocols/Crysiswars.php
@@ -29,15 +29,11 @@ class Crysiswars extends Gamespy3
{
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'crysiswars';
+ protected string $name = 'crysiswars';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Crysis Wars";
+ protected string $name_long = "Crysis Wars";
}
diff --git a/src/GameQ/Protocols/Cs15.php b/src/GameQ/Protocols/Cs15.php
index ba375240..8769b456 100644
--- a/src/GameQ/Protocols/Cs15.php
+++ b/src/GameQ/Protocols/Cs15.php
@@ -31,15 +31,11 @@ class Cs15 extends Won
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'cs15';
+ protected string $name = 'cs15';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Counter-Strike 1.5";
+ protected string $name_long = "Counter-Strike 1.5";
}
diff --git a/src/GameQ/Protocols/Cs16.php b/src/GameQ/Protocols/Cs16.php
index 25a66029..806b348a 100644
--- a/src/GameQ/Protocols/Cs16.php
+++ b/src/GameQ/Protocols/Cs16.php
@@ -29,17 +29,13 @@ class Cs16 extends Source
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'cs16';
+ protected string $name = 'cs16';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Counter-Strike 1.6";
+ protected string $name_long = "Counter-Strike 1.6";
/**
* In the case of cs 1.6 we offload split packets here because the split packet response for rules is in
diff --git a/src/GameQ/Protocols/Cs2d.php b/src/GameQ/Protocols/Cs2d.php
index 0f238fdd..3fa9f147 100644
--- a/src/GameQ/Protocols/Cs2d.php
+++ b/src/GameQ/Protocols/Cs2d.php
@@ -36,10 +36,8 @@ class Cs2d extends Protocol
/**
* Array of packets we want to query.
- *
- * @type array
*/
- protected $packets = [
+ protected array $packets = [
self::PACKET_STATUS => "\x01\x00\xFB\x01",
//self::PACKET_STATUS => "\x01\x00\x03\x10\x21\xFB\x01\x75\x00",
self::PACKET_PLAYERS => "\x01\x00\xFB\x05",
@@ -48,47 +46,36 @@ class Cs2d extends Protocol
/**
* Use the response flag to figure out what method to run
*
- * @type array
*/
- protected $responses = [
+ protected array $responses = [
"\x01\x00\xFB\x01" => "processDetails",
"\x01\x00\xFB\x05" => "processPlayers",
];
/**
* The query protocol used to make the call
- *
- * @type string
*/
- protected $protocol = 'cs2d';
+ protected string $protocol = 'cs2d';
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'cs2d';
+ protected string $name = 'cs2d';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Counter-Strike 2d";
+ protected string $name_long = "Counter-Strike 2d";
/**
* The client join link
- *
- * @type string
*/
- protected $join_link = "cs2d://%s:%d/";
+ protected ?string $join_link = "cs2d://%s:%d/";
/**
* Normalize settings for this protocol
- *
- * @type array
*/
- protected $normalize = [
+ protected array $normalize = [
// General
'general' => [
// target => source
@@ -112,10 +99,10 @@ class Cs2d extends Protocol
/**
* Process the response for the Tibia server
*
- * @return array
+ * @return mixed
* @throws \GameQ\Exception\Protocol
*/
- public function processResponse()
+ public function processResponse(): mixed
{
// We have a merged packet, try to split it back up
@@ -178,8 +165,6 @@ public function processResponse()
/**
* Handles processing the details data into a usable format
*
- * @param Buffer $buffer
- *
* @return array
* @throws Exception
*/
@@ -200,24 +185,20 @@ protected function processDetails(Buffer $buffer)
$result->add('lua_scripts', (int)$this->readFlag($serverFlags, 6));
// Read the rest of the buffer data
- $result->add('servername', utf8_encode($buffer->readPascalString(0)));
- $result->add('mapname', utf8_encode($buffer->readPascalString(0)));
+ $result->add('servername', $this->convertToUtf8($buffer->readPascalString()));
+ $result->add('mapname', $this->convertToUtf8($buffer->readPascalString()));
$result->add('num_players', $buffer->readInt8());
$result->add('max_players', $buffer->readInt8());
$result->add('game_mode', $buffer->readInt8());
$result->add('num_bots', (($this->readFlag($serverFlags, 5)) ? $buffer->readInt8() : 0));
$result->add('dedicated', 1);
- unset($buffer);
-
return $result->fetch();
}
/**
* Handles processing the player data into a usable format
*
- * @param Buffer $buffer
- *
* @return array
* @throws Exception
*/
@@ -236,14 +217,14 @@ protected function processPlayers(Buffer $buffer)
if (($id = $buffer->readInt8()) !== 0) {
// Add the results
$result->addPlayer('id', $id);
- $result->addPlayer('name', utf8_encode($buffer->readPascalString(0)));
+ $result->addPlayer('name', $this->convertToUtf8($buffer->readPascalString()));
$result->addPlayer('team', $buffer->readInt8());
$result->addPlayer('score', $buffer->readInt32());
$result->addPlayer('deaths', $buffer->readInt32());
}
}
- unset($buffer, $id);
+ unset($id);
return $result->fetch();
}
@@ -258,6 +239,6 @@ protected function processPlayers(Buffer $buffer)
*/
protected function readFlag($flags, $offset)
{
- return !!($flags & (1 << $offset));
+ return (bool)($flags & (1 << $offset));
}
}
diff --git a/src/GameQ/Protocols/Cscz.php b/src/GameQ/Protocols/Cscz.php
index b539128f..e3de7037 100644
--- a/src/GameQ/Protocols/Cscz.php
+++ b/src/GameQ/Protocols/Cscz.php
@@ -31,15 +31,11 @@ class Cscz extends Cs16
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'cscz';
+ protected string $name = 'cscz';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Counter-Strike: Condition Zero";
+ protected string $name_long = "Counter-Strike: Condition Zero";
}
diff --git a/src/GameQ/Protocols/Csgo.php b/src/GameQ/Protocols/Csgo.php
index 41af7352..ea37ddae 100644
--- a/src/GameQ/Protocols/Csgo.php
+++ b/src/GameQ/Protocols/Csgo.php
@@ -29,15 +29,11 @@ class Csgo extends Source
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'csgo';
+ protected string $name = 'csgo';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Counter-Strike: Global Offensive";
+ protected string $name_long = "Counter-Strike: Global Offensive";
}
diff --git a/src/GameQ/Protocols/Css.php b/src/GameQ/Protocols/Css.php
index be75da3d..1e82cc9e 100644
--- a/src/GameQ/Protocols/Css.php
+++ b/src/GameQ/Protocols/Css.php
@@ -28,15 +28,11 @@ class Css extends Source
{
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'css';
+ protected string $name = 'css';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Counter-Strike: Source";
+ protected string $name_long = "Counter-Strike: Source";
}
diff --git a/src/GameQ/Protocols/Dal.php b/src/GameQ/Protocols/Dal.php
index 6b05037d..4e518b65 100644
--- a/src/GameQ/Protocols/Dal.php
+++ b/src/GameQ/Protocols/Dal.php
@@ -29,15 +29,11 @@ class Dal extends Arkse
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'dal';
+ protected string $name = 'dal';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Dark and Light";
+ protected string $name_long = "Dark and Light";
}
diff --git a/src/GameQ/Protocols/Dayz.php b/src/GameQ/Protocols/Dayz.php
index 01c7c28d..3cff46bd 100644
--- a/src/GameQ/Protocols/Dayz.php
+++ b/src/GameQ/Protocols/Dayz.php
@@ -29,26 +29,18 @@ class Dayz extends Source
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'dayz';
+ protected string $name = 'dayz';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "DayZ Standalone";
+ protected string $name_long = "DayZ Standalone";
/**
* Overload the math used to guess at the Query Port
- *
- * @param int $clientPort
- *
- * @return int
*/
- public function findQueryPort($clientPort)
+ public function findQueryPort(int $clientPort): int
{
/*
diff --git a/src/GameQ/Protocols/Dayzmod.php b/src/GameQ/Protocols/Dayzmod.php
index 2ce1076d..07be900e 100644
--- a/src/GameQ/Protocols/Dayzmod.php
+++ b/src/GameQ/Protocols/Dayzmod.php
@@ -30,15 +30,11 @@ class Dayzmod extends Armedassault2oa
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'dayzmod';
+ protected string $name = 'dayzmod';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "DayZ Mod";
+ protected string $name_long = "DayZ Mod";
}
diff --git a/src/GameQ/Protocols/Dod.php b/src/GameQ/Protocols/Dod.php
index 0c7baf69..d99287e2 100644
--- a/src/GameQ/Protocols/Dod.php
+++ b/src/GameQ/Protocols/Dod.php
@@ -31,15 +31,11 @@ class Dod extends Cs16
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'dod';
+ protected string $name = 'dod';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Day of Defeat";
+ protected string $name_long = "Day of Defeat";
}
diff --git a/src/GameQ/Protocols/Dods.php b/src/GameQ/Protocols/Dods.php
index 898d75b9..dcc3380a 100644
--- a/src/GameQ/Protocols/Dods.php
+++ b/src/GameQ/Protocols/Dods.php
@@ -28,15 +28,11 @@ class Dods extends Source
{
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'dods';
+ protected string $name = 'dods';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Day of Defeat: Source";
+ protected string $name_long = "Day of Defeat: Source";
}
diff --git a/src/GameQ/Protocols/Doom3.php b/src/GameQ/Protocols/Doom3.php
index 2e00f5f1..cbf8c489 100644
--- a/src/GameQ/Protocols/Doom3.php
+++ b/src/GameQ/Protocols/Doom3.php
@@ -36,56 +36,43 @@ class Doom3 extends Protocol
/**
* Array of packets we want to look up.
* Each key should correspond to a defined method in this or a parent class
- *
- * @type array
*/
- protected $packets = [
+ protected array $packets = [
self::PACKET_ALL => "\xFF\xFFgetInfo\x00PiNGPoNG\x00",
];
/**
* Use the response flag to figure out what method to run
*
- * @type array
*/
- protected $responses = [
+ protected array $responses = [
"\xFF\xFFinfoResponse" => 'processStatus',
];
/**
* The query protocol used to make the call
- *
- * @type string
*/
- protected $protocol = 'doom3';
+ protected string $protocol = 'doom3';
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'doom3';
+ protected string $name = 'doom3';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Doom 3";
+ protected string $name_long = "Doom 3";
/**
* The client join link
- *
- * @type string
*/
- protected $join_link = null;
+ protected ?string $join_link = null;
/**
* Normalize settings for this protocol
- *
- * @type array
*/
- protected $normalize = [
+ protected array $normalize = [
// General
'general' => [
// target => source
@@ -109,7 +96,7 @@ class Doom3 extends Protocol
* @return mixed
* @throws Exception
*/
- public function processResponse()
+ public function processResponse(): mixed
{
// Make a buffer
$buffer = new Buffer(implode('', $this->packets_response));
@@ -123,14 +110,12 @@ public function processResponse()
throw new Exception(__METHOD__ . " response type '" . bin2hex($header) . "' is not valid");
}
- return call_user_func_array([$this, $this->responses[$header]], [$buffer]);
+ return $this->{$this->responses[$header]}($buffer);
}
/**
* Process the status response
*
- * @param Buffer $buffer
- *
* @return array
*/
protected function processStatus(Buffer $buffer)
@@ -138,22 +123,15 @@ protected function processStatus(Buffer $buffer)
// We need to split the data and offload
$results = $this->processServerInfo($buffer);
- $results = array_merge_recursive(
+ return array_merge_recursive(
$results,
$this->processPlayers($buffer)
);
-
- unset($buffer);
-
- // Return results
- return $results;
}
/**
* Handle processing the server information
*
- * @param Buffer $buffer
- *
* @return array
*/
protected function processServerInfo(Buffer $buffer)
@@ -166,7 +144,7 @@ protected function processServerInfo(Buffer $buffer)
// Key / value pairs, delimited by an empty pair
while ($buffer->getLength()) {
$key = trim($buffer->readString());
- $val = utf8_encode(trim($buffer->readString()));
+ $val = $this->convertToUtf8(trim($buffer->readString()));
// Something is empty so we are done
if (empty($key) && empty($val)) {
@@ -176,16 +154,12 @@ protected function processServerInfo(Buffer $buffer)
$result->add($key, $val);
}
- unset($buffer);
-
return $result->fetch();
}
/**
* Handle processing of player data
*
- * @param Buffer $buffer
- *
* @return array
*/
protected function processPlayers(Buffer $buffer)
@@ -204,7 +178,7 @@ protected function processPlayers(Buffer $buffer)
$result->addPlayer('ping', $buffer->readInt16());
$result->addPlayer('rate', $buffer->readInt32());
// Add player name, encoded
- $result->addPlayer('name', utf8_encode(trim($buffer->readString())));
+ $result->addPlayer('name', $this->convertToUtf8(trim($buffer->readString())));
// Increment
$playerCount++;
@@ -214,7 +188,7 @@ protected function processPlayers(Buffer $buffer)
$result->add('clients', $playerCount);
// Clear
- unset($buffer, $playerCount);
+ unset($playerCount);
return $result->fetch();
}
diff --git a/src/GameQ/Protocols/Dow.php b/src/GameQ/Protocols/Dow.php
index b66512a7..6c28b6c0 100644
--- a/src/GameQ/Protocols/Dow.php
+++ b/src/GameQ/Protocols/Dow.php
@@ -18,8 +18,6 @@
namespace GameQ\Protocols;
-use GameQ\Buffer;
-
/**
* Class Dow
*
@@ -32,24 +30,18 @@ class Dow extends Source
{
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'dow';
+ protected string $name = 'dow';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Days of War";
+ protected string $name_long = "Days of War";
/**
* Normalize main fields
- *
- * @var array
*/
- protected $normalize = [
+ protected array $normalize = [
// General
'general' => [
// target => source
diff --git a/src/GameQ/Protocols/Eco.php b/src/GameQ/Protocols/Eco.php
index a2292e90..0ccf4eb3 100644
--- a/src/GameQ/Protocols/Eco.php
+++ b/src/GameQ/Protocols/Eco.php
@@ -33,51 +33,43 @@ class Eco extends Http
*
* @var array
*/
- protected $packets = [
+ protected array $packets = [
self::PACKET_STATUS => "GET /frontpage HTTP/1.0\r\nAccept: */*\r\n\r\n",
];
/**
* Http protocol is SSL
*
- * @var string
*/
- protected $transport = self::TRANSPORT_TCP;
+ protected string $transport = self::TRANSPORT_TCP;
/**
* The protocol being used
*
- * @var string
*/
- protected $protocol = 'eco';
+ protected string $protocol = 'eco';
/**
* String name of this protocol class
*
- * @var string
*/
- protected $name = 'eco';
+ protected string $name = 'eco';
/**
* Longer string name of this protocol class
*
- * @var string
*/
- protected $name_long = "ECO Global Survival";
+ protected string $name_long = "ECO Global Survival";
/**
* query_port = client_port + 1
- *
- * @type int
*/
- protected $port_diff = 1;
+ protected int $port_diff = 1;
/**
* Normalize some items
- *
- * @var array
*/
- protected $normalize = [
+ protected array $normalize = [
// General
'general' => [
// target => source
@@ -92,10 +84,10 @@ class Eco extends Http
/**
* Process the response
*
- * @return array
+ * @return mixed
* @throws Exception
*/
- public function processResponse()
+ public function processResponse(): mixed
{
if (empty($this->packets_response)) {
return [];
diff --git a/src/GameQ/Protocols/Egs.php b/src/GameQ/Protocols/Egs.php
index aab79aea..d7b6c60d 100644
--- a/src/GameQ/Protocols/Egs.php
+++ b/src/GameQ/Protocols/Egs.php
@@ -30,22 +30,16 @@ class Egs extends Source
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'egs';
+ protected string $name = 'egs';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Empyrion - Galactic Survival";
+ protected string $name_long = "Empyrion - Galactic Survival";
/**
* query_port = client_port + 1
- *
- * @type int
*/
- protected $port_diff = 1;
+ protected int $port_diff = 1;
}
diff --git a/src/GameQ/Protocols/Et.php b/src/GameQ/Protocols/Et.php
index 63b5beb7..7a3c208d 100644
--- a/src/GameQ/Protocols/Et.php
+++ b/src/GameQ/Protocols/Et.php
@@ -29,15 +29,11 @@ class Et extends Quake3
{
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'et';
+ protected string $name = 'et';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Wolfenstein Enemy Territory";
+ protected string $name_long = "Wolfenstein Enemy Territory";
}
diff --git a/src/GameQ/Protocols/Etqw.php b/src/GameQ/Protocols/Etqw.php
index 1f3a446c..bdd2e151 100644
--- a/src/GameQ/Protocols/Etqw.php
+++ b/src/GameQ/Protocols/Etqw.php
@@ -34,10 +34,8 @@ class Etqw extends Protocol
/**
* Array of packets we want to look up.
* Each key should correspond to a defined method in this or a parent class
- *
- * @type array
*/
- protected $packets = [
+ protected array $packets = [
self::PACKET_STATUS => "\xFF\xFFgetInfoEx\x00\x00\x00\x00",
//self::PACKET_STATUS => "\xFF\xFFgetInfo\x00\x00\x00\x00\x00",
];
@@ -45,39 +43,30 @@ class Etqw extends Protocol
/**
* Use the response flag to figure out what method to run
*
- * @type array
*/
- protected $responses = [
+ protected array $responses = [
"\xFF\xFFinfoExResponse" => "processStatus",
];
/**
* The query protocol used to make the call
- *
- * @type string
*/
- protected $protocol = 'etqw';
+ protected string $protocol = 'etqw';
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'etqw';
+ protected string $name = 'etqw';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Enemy Territory Quake Wars";
+ protected string $name_long = "Enemy Territory Quake Wars";
/**
* Normalize settings for this protocol
- *
- * @type array
*/
- protected $normalize = [
+ protected array $normalize = [
// General
'general' => [
// target => source
@@ -100,10 +89,10 @@ class Etqw extends Protocol
/**
* Process the response
*
- * @return array
+ * @return mixed
* @throws \GameQ\Exception\Protocol
*/
- public function processResponse()
+ public function processResponse(): mixed
{
// In case it comes back as multiple packets (it shouldn't)
$buffer = new Buffer(implode('', $this->packets_response));
@@ -113,13 +102,11 @@ public function processResponse()
// Figure out which packet response this is
if (!array_key_exists($response_type, $this->responses)) {
- throw new Exception(__METHOD__ . " response type '{$response_type}' is not valid");
+ throw new Exception(__METHOD__ . " response type '$response_type' is not valid");
}
// Offload the call
- $results = call_user_func_array([$this, $this->responses[$response_type]], [$buffer]);
-
- return $results;
+ return $this->{$this->responses[$response_type]}($buffer);
}
/*
@@ -129,8 +116,6 @@ public function processResponse()
/**
* Handle processing the status response
*
- * @param Buffer $buffer
- *
* @return array
*/
protected function processStatus(Buffer $buffer)
@@ -176,24 +161,19 @@ protected function processStatus(Buffer $buffer)
// Now let's parse the extended player info
$this->parsePlayersExtra($buffer, $result);
- unset($buffer);
-
return $result->fetch();
}
/**
* Parse players out of the status ex response
- *
- * @param Buffer $buffer
- * @param Result $result
*/
- protected function parsePlayers(Buffer &$buffer, Result &$result)
+ protected function parsePlayers(Buffer $buffer, Result $result)
{
// By default there are 0 players
$players = 0;
// Iterate over the players until we run out
- while (($id = $buffer->readInt8()) != 32) {
+ while (($id = $buffer->readInt8()) !== 32) {
$result->addPlayer('id', $id);
$result->addPlayer('ping', $buffer->readInt16());
$result->addPlayer('name', $buffer->readString());
@@ -212,11 +192,8 @@ protected function parsePlayers(Buffer &$buffer, Result &$result)
/**
* Handle parsing extra player data
- *
- * @param Buffer $buffer
- * @param Result $result
*/
- protected function parsePlayersExtra(Buffer &$buffer, Result &$result)
+ protected function parsePlayersExtra(Buffer $buffer, Result $result)
{
// Iterate over the extra player info
while (($id = $buffer->readInt8()) != 32) {
diff --git a/src/GameQ/Protocols/Ffe.php b/src/GameQ/Protocols/Ffe.php
index c0947bdc..f91d3dd7 100644
--- a/src/GameQ/Protocols/Ffe.php
+++ b/src/GameQ/Protocols/Ffe.php
@@ -29,15 +29,11 @@ class Ffe extends Source
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'ffe';
+ protected string $name = 'ffe';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Fortress Forever";
+ protected string $name_long = "Fortress Forever";
}
diff --git a/src/GameQ/Protocols/Ffow.php b/src/GameQ/Protocols/Ffow.php
index 00c33d47..9dee3299 100644
--- a/src/GameQ/Protocols/Ffow.php
+++ b/src/GameQ/Protocols/Ffow.php
@@ -23,10 +23,8 @@ class Ffow extends Protocol
/**
* Array of packets we want to look up.
* Each key should correspond to a defined method in this or a parent class
- *
- * @type array
*/
- protected $packets = [
+ protected array $packets = [
self::PACKET_CHALLENGE => "\xFF\xFF\xFF\xFF\x57",
self::PACKET_RULES => "\xFF\xFF\xFF\xFF\x56%s",
self::PACKET_PLAYERS => "\xFF\xFF\xFF\xFF\x55%s",
@@ -36,9 +34,8 @@ class Ffow extends Protocol
/**
* Use the response flag to figure out what method to run
*
- * @type array
*/
- protected $responses = [
+ protected array $responses = [
"\xFF\xFF\xFF\xFF\x49\x02" => 'processInfo', // I
"\xFF\xFF\xFF\xFF\x45\x00" => 'processRules', // E
"\xFF\xFF\xFF\xFF\x44\x00" => 'processPlayers', // D
@@ -46,45 +43,33 @@ class Ffow extends Protocol
/**
* The query protocol used to make the call
- *
- * @type string
*/
- protected $protocol = 'ffow';
+ protected string $protocol = 'ffow';
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'ffow';
+ protected string $name = 'ffow';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Frontlines Fuel of War";
+ protected string $name_long = "Frontlines Fuel of War";
/**
* The client join link
- *
- * @type string
*/
- protected $join_link = null;
+ protected ?string $join_link = null;
/**
* query_port = client_port + 2
- *
- * @type int
*/
- protected $port_diff = 2;
+ protected int $port_diff = 2;
/**
* Normalize settings for this protocol
- *
- * @type array
*/
- protected $normalize = [
+ protected array $normalize = [
// General
'general' => [
// target => source
@@ -107,12 +92,9 @@ class Ffow extends Protocol
/**
* Parse the challenge response and apply it to all the packet types
*
- * @param \GameQ\Buffer $challenge_buffer
- *
- * @return bool
* @throws \GameQ\Exception\Protocol
*/
- public function challengeParseAndApply(Buffer $challenge_buffer)
+ public function challengeParseAndApply(Buffer $challenge_buffer): bool
{
// Burn padding
$challenge_buffer->skip(5);
@@ -127,7 +109,7 @@ public function challengeParseAndApply(Buffer $challenge_buffer)
* @return mixed
* @throws Exception
*/
- public function processResponse()
+ public function processResponse(): mixed
{
// Init results
$results = [];
@@ -158,8 +140,6 @@ public function processResponse()
/**
* Handle processing the server information
*
- * @param Buffer $buffer
- *
* @return array
*/
protected function processInfo(Buffer $buffer)
@@ -185,16 +165,12 @@ protected function processInfo(Buffer $buffer)
$result->add('max_rounds', $buffer->readInt8());
$result->add('time_left', $buffer->readInt16());
- unset($buffer);
-
return $result->fetch();
}
/**
* Handle processing the server rules
*
- * @param Buffer $buffer
- *
* @return array
*/
protected function processRules(Buffer $buffer)
@@ -203,13 +179,13 @@ protected function processRules(Buffer $buffer)
$result = new Result();
// Burn extra header
- $buffer->skip(1);
+ $buffer->skip();
// Read rules until we run out of buffer
while ($buffer->getLength()) {
$key = $buffer->readString();
// Check for map
- if (strstr($key, "Map:")) {
+ if (str_contains($key, "Map:")) {
$result->addSub("maplist", "name", $buffer->readString());
} else // Regular rule
{
@@ -217,8 +193,6 @@ protected function processRules(Buffer $buffer)
}
}
- unset($buffer);
-
return $result->fetch();
}
@@ -227,17 +201,10 @@ protected function processRules(Buffer $buffer)
*
* @todo: Build this out when there is a server with players to test against
*
- * @param Buffer $buffer
- *
* @return array
*/
protected function processPlayers(Buffer $buffer)
{
- // Set the result to a new result instance
- $result = new Result();
-
- unset($buffer);
-
- return $result->fetch();
+ return (new Result())->fetch();
}
}
diff --git a/src/GameQ/Protocols/Fof.php b/src/GameQ/Protocols/Fof.php
index a35c4c0a..ca844146 100644
--- a/src/GameQ/Protocols/Fof.php
+++ b/src/GameQ/Protocols/Fof.php
@@ -29,15 +29,11 @@ class Fof extends Source
{
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'fof';
+ protected string $name = 'fof';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Fistful of Frags";
+ protected string $name_long = "Fistful of Frags";
}
diff --git a/src/GameQ/Protocols/Gamespy.php b/src/GameQ/Protocols/Gamespy.php
index b1a1e4fa..9c224f42 100644
--- a/src/GameQ/Protocols/Gamespy.php
+++ b/src/GameQ/Protocols/Gamespy.php
@@ -21,7 +21,7 @@
use GameQ\Protocol;
use GameQ\Buffer;
use GameQ\Result;
-use \GameQ\Exception\Protocol as Exception;
+use GameQ\Exception\Protocol as Exception;
/**
* GameSpy Protocol class
@@ -34,48 +34,37 @@ class Gamespy extends Protocol
/**
* Array of packets we want to look up.
* Each key should correspond to a defined method in this or a parent class
- *
- * @type array
*/
- protected $packets = [
+ protected array $packets = [
self::PACKET_STATUS => "\x5C\x73\x74\x61\x74\x75\x73\x5C",
];
/**
* The query protocol used to make the call
- *
- * @type string
*/
- protected $protocol = 'gamespy';
+ protected string $protocol = 'gamespy';
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'gamespy';
+ protected string $name = 'gamespy';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "GameSpy Server";
+ protected string $name_long = "GameSpy Server";
/**
* The client join link
- *
- * @type string
*/
- protected $join_link = null;
+ protected ?string $join_link = null;
/**
* Process the response for this protocol
*
- * @return array
* @throws Exception
*/
- public function processResponse()
+ public function processResponse(): mixed
{
// Holds the processed packets so we can sort them in case they come in an unordered
$processed = [];
@@ -84,13 +73,13 @@ public function processResponse()
foreach ($this->packets_response as $response) {
// Check to see if we had a preg_match error
if (($match = preg_match("#^(.*)\\\\queryid\\\\([^\\\\]+)(\\\\|$)#", $response, $matches)) === false
- || $match != 1
+ || $match !== 1
) {
throw new Exception(__METHOD__ . " An error occurred while parsing the packets for 'queryid'");
}
// Multiply so we move the decimal point out of the way, if there is one
- $key = (int)(floatval($matches[2]) * 1000);
+ $key = (int)((float)$matches[2] * 1000);
// Add this packet to the processed
$processed[$key] = $matches[1];
@@ -110,8 +99,6 @@ public function processResponse()
/**
* Handle processing the status buffer
*
- * @param Buffer $buffer
- *
* @return array
*/
protected function processStatus(Buffer $buffer)
@@ -123,17 +110,14 @@ protected function processStatus(Buffer $buffer)
$result->add('dedicated', 1);
// Lets peek and see if the data starts with a \
- if ($buffer->lookAhead(1) == '\\') {
+ if ($buffer->lookAhead() === '\\') {
// Burn the first one
- $buffer->skip(1);
+ $buffer->skip();
}
// Explode the data
$data = explode('\\', $buffer->getBuffer());
- // No longer needed
- unset($buffer);
-
// Init some vars
$numPlayers = 0;
$numTeams = 0;
@@ -151,15 +135,15 @@ protected function processStatus(Buffer $buffer)
// Check for _ variable (i.e players)
if (($suffix = strrpos($key, '_')) !== false && is_numeric(substr($key, $suffix + 1))) {
// See if this is a team designation
- if (substr($key, 0, $suffix) == 'teamname') {
+ if (str_starts_with($key, 'teamname')) {
$result->addTeam('teamname', $val);
$numTeams++;
} else {
// Its a player
- if (substr($key, 0, $suffix) == 'playername') {
+ if (str_starts_with($key, 'playername')) {
$numPlayers++;
}
- $result->addPlayer(substr($key, 0, $suffix), utf8_encode($val));
+ $result->addPlayer(substr($key, 0, $suffix), $this->convertToUtf8($val));
}
} else {
// Regular variable so just add the value.
diff --git a/src/GameQ/Protocols/Gamespy2.php b/src/GameQ/Protocols/Gamespy2.php
index c7788d9e..ab4f3c4b 100644
--- a/src/GameQ/Protocols/Gamespy2.php
+++ b/src/GameQ/Protocols/Gamespy2.php
@@ -37,18 +37,14 @@ class Gamespy2 extends Protocol
/**
* Define the state of this class
- *
- * @type int
*/
- protected $state = self::STATE_BETA;
+ protected int $state = self::STATE_BETA;
/**
* Array of packets we want to look up.
* Each key should correspond to a defined method in this or a parent class
- *
- * @type array
*/
- protected $packets = [
+ protected array $packets = [
self::PACKET_DETAILS => "\xFE\xFD\x00\x43\x4F\x52\x59\xFF\x00\x00",
self::PACKET_PLAYERS => "\xFE\xFD\x00\x43\x4F\x52\x58\x00\xFF\xFF",
];
@@ -56,47 +52,36 @@ class Gamespy2 extends Protocol
/**
* Use the response flag to figure out what method to run
*
- * @type array
*/
- protected $responses = [
+ protected array $responses = [
"\x00\x43\x4F\x52\x59" => "processDetails",
"\x00\x43\x4F\x52\x58" => "processPlayers",
];
/**
* The query protocol used to make the call
- *
- * @type string
*/
- protected $protocol = 'gamespy2';
+ protected string $protocol = 'gamespy2';
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'gamespy2';
+ protected string $name = 'gamespy2';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "GameSpy2 Server";
+ protected string $name_long = "GameSpy2 Server";
/**
* The client join link
- *
- * @type string
*/
- protected $join_link = null;
+ protected ?string $join_link = null;
/**
* Normalize settings for this protocol
- *
- * @type array
*/
- protected $normalize = [
+ protected array $normalize = [
// General
'general' => [
// target => source
@@ -115,10 +100,10 @@ class Gamespy2 extends Protocol
/**
* Process the response
*
- * @return array
+ * @return mixed
* @throws Exception
*/
- public function processResponse()
+ public function processResponse(): mixed
{
// Will hold the packets after sorting
@@ -164,8 +149,7 @@ public function processResponse()
/**
* Handles processing the details data into a usable format
- *
- * @param \GameQ\Buffer $buffer
+
*
* @return array
* @throws Exception
@@ -179,21 +163,18 @@ protected function processDetails(Buffer $buffer)
// We go until we hit an empty key
while ($buffer->getLength()) {
$key = $buffer->readString();
- if (strlen($key) == 0) {
+ if ($key === '') {
break;
}
- $result->add($key, utf8_encode($buffer->readString()));
+ $result->add($key, $this->convertToUtf8($buffer->readString()));
}
- unset($buffer);
-
return $result->fetch();
}
/**
* Handles processing the players data into a usable format
- *
- * @param \GameQ\Buffer $buffer
+
*
* @return array
* @throws Exception
@@ -205,7 +186,7 @@ protected function processPlayers(Buffer $buffer)
$result = new Result();
// Skip the header
- $buffer->skip(1);
+ $buffer->skip();
// Players are first
$this->parsePlayerTeam('players', $buffer, $result);
@@ -213,21 +194,15 @@ protected function processPlayers(Buffer $buffer)
// Teams are next
$this->parsePlayerTeam('teams', $buffer, $result);
- unset($buffer);
-
return $result->fetch();
}
/**
* Parse the player/team info returned from the player call
*
- * @param string $dataType
- * @param \GameQ\Buffer $buffer
- * @param \GameQ\Result $result
- *
* @throws Exception
*/
- protected function parsePlayerTeam($dataType, Buffer &$buffer, Result &$result)
+ protected function parsePlayerTeam(string $dataType, Buffer $buffer, Result $result)
{
// Do count
@@ -247,7 +222,7 @@ protected function parsePlayerTeam($dataType, Buffer &$buffer, Result &$result)
}
// Check if there are any value entries
- if ($buffer->lookAhead() == "\x00") {
+ if ($buffer->lookAhead() === "\x00") {
$buffer->skip();
return;
@@ -256,14 +231,12 @@ protected function parsePlayerTeam($dataType, Buffer &$buffer, Result &$result)
// Get the values
while ($buffer->getLength() > 4) {
foreach ($varNames as $varName) {
- $result->addSub($dataType, utf8_encode($varName), utf8_encode($buffer->readString()));
+ $result->addSub($dataType, $this->convertToUtf8($varName), $this->convertToUtf8($buffer->readString()));
}
if ($buffer->lookAhead() === "\x00") {
$buffer->skip();
break;
}
}
-
- return;
}
}
diff --git a/src/GameQ/Protocols/Gamespy3.php b/src/GameQ/Protocols/Gamespy3.php
index 2df0a4bd..64243d6a 100644
--- a/src/GameQ/Protocols/Gamespy3.php
+++ b/src/GameQ/Protocols/Gamespy3.php
@@ -37,68 +37,52 @@ class Gamespy3 extends Protocol
/**
* Array of packets we want to look up.
* Each key should correspond to a defined method in this or a parent class
- *
- * @type array
*/
- protected $packets = [
+ protected array $packets = [
self::PACKET_CHALLENGE => "\xFE\xFD\x09\x10\x20\x30\x40",
self::PACKET_ALL => "\xFE\xFD\x00\x10\x20\x30\x40%s\xFF\xFF\xFF\x01",
];
/**
* The query protocol used to make the call
- *
- * @type string
*/
- protected $protocol = 'gamespy3';
+ protected string $protocol = 'gamespy3';
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'gamespy3';
+ protected string $name = 'gamespy3';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "GameSpy3 Server";
+ protected string $name_long = "GameSpy3 Server";
/**
* The client join link
- *
- * @type string
*/
- protected $join_link = null;
+ protected ?string $join_link = null;
/**
* This defines the split between the server info and player/team info.
* This value can vary by game. This value is the default split.
- *
- * @var string
*/
- protected $packetSplit = "/\\x00\\x00\\x01/m";
+ protected string $packetsplit = "/\\x00\\x00\\x01/m";
/**
* Parse the challenge response and apply it to all the packet types
- *
- * @param \GameQ\Buffer $challenge_buffer
- *
- * @return bool
- * @throws \GameQ\Exception\Protocol
*/
- public function challengeParseAndApply(Buffer $challenge_buffer)
+ public function challengeParseAndApply(Buffer $challenge_buffer): bool
{
// Pull out the challenge
- $challenge = substr(preg_replace("/[^0-9\-]/si", "", $challenge_buffer->getBuffer()), 1);
+ $challenge = substr(preg_replace("/[^0-9\-]/i", "", $challenge_buffer->getBuffer()), 1);
// By default, no challenge result (see #197)
$challenge_result = '';
// Check for valid challenge (see #197)
if ($challenge) {
+ $challenge = (int) $challenge;
// Encode chellenge result
$challenge_result = sprintf(
"%c%c%c%c",
@@ -115,10 +99,8 @@ public function challengeParseAndApply(Buffer $challenge_buffer)
/**
* Process the response
- *
- * @return array
*/
- public function processResponse()
+ public function processResponse(): mixed
{
// Holds the processed packets
@@ -142,7 +124,7 @@ public function processResponse()
$id = $buffer->readInt8();
// Burn next byte not sure what it is used for
- $buffer->skip(1);
+ $buffer->skip();
// Add this packet to the processed
$processed[$id] = $buffer->getBuffer();
@@ -157,7 +139,7 @@ public function processResponse()
$packets = $this->cleanPackets(array_values($processed));
// Split the packets by type general and the rest (i.e. players & teams)
- $split = preg_split($this->packetSplit, implode('', $packets));
+ $split = preg_split($this->packetsplit, implode('', $packets));
// Create a new result
$result = new Result();
@@ -185,12 +167,8 @@ public function processResponse()
/**
* Handles cleaning up packets since the responses can be a bit "dirty"
- *
- * @param array $packets
- *
- * @return array
*/
- protected function cleanPackets(array $packets = [])
+ protected function cleanPackets(array $packets = []): array
{
// Get the number of packets
@@ -211,7 +189,7 @@ protected function cleanPackets(array $packets = [])
$sndvar = substr($snd, 0, strpos($snd, "\x00"));
// Check if fstvar is a substring of sndvar
// If so, remove it from the first string
- if (!empty($fstvar) && strpos($sndvar, $fstvar) !== false) {
+ if (!empty($fstvar) && str_contains($sndvar, $fstvar)) {
$packets[$i] = preg_replace("#(\\x00[^\\x00]+\\x00)$#", "\x00", $packets[$i]);
}
}
@@ -223,7 +201,8 @@ protected function cleanPackets(array $packets = [])
$prefix = $buffer->readString();
// Check to see if the return before has the same prefix present
- if ($prefix != null && strstr($packets[($x - 1)], $prefix)) {
+ if (str_contains($packets[($x - 1)], $prefix)
+ ) {
// Update the return by removing the prefix plus 2 chars
$packets[$x] = substr(str_replace($prefix, '', $packets[$x]), 2);
}
@@ -239,32 +218,24 @@ protected function cleanPackets(array $packets = [])
/**
* Handles processing the details data into a usable format
- *
- * @param \GameQ\Buffer $buffer
- * @param \GameQ\Result $result
*/
- protected function processDetails(Buffer &$buffer, Result &$result)
+ protected function processDetails(Buffer $buffer, Result $result): void
{
-
// We go until we hit an empty key
while ($buffer->getLength()) {
$key = $buffer->readString();
- if (strlen($key) == 0) {
+ if ($key === '') {
break;
}
- $result->add($key, utf8_encode($buffer->readString()));
+ $result->add($key, $this->convertToUtf8($buffer->readString()));
}
}
/**
* Handles processing the player and team data into a usable format
- *
- * @param \GameQ\Buffer $buffer
- * @param \GameQ\Result $result
*/
- protected function processPlayersAndTeams(Buffer &$buffer, Result &$result)
+ protected function processPlayersAndTeams(Buffer $buffer, Result $result): void
{
-
/*
* Explode the data into groups. First is player, next is team (item_t)
* Each group should be as follows:
@@ -289,7 +260,7 @@ protected function processPlayersAndTeams(Buffer &$buffer, Result &$result)
// Pull out the item
$item = $data[$x];
// If this is an empty item, move on
- if ($item == '' || $item == "\x00") {
+ if ($item === '' || $item === "\x00") {
continue;
}
/*
@@ -305,12 +276,12 @@ protected function processPlayersAndTeams(Buffer &$buffer, Result &$result)
* For now we just strip out these characters
*/
// Check to see if $item has a _ at the end, this is player info
- if (substr($item, -1) == '_') {
+ if (str_ends_with($item, '_')) {
// Set the item group
$item_group = 'players';
// Set the item type, rip off any trailing stuff and bad chars
$item_type = rtrim(str_replace("\x01", '', $item), '_');
- } elseif (substr($item, -2) == '_t') {
+ } elseif (str_ends_with($item, '_t')) {
// Check to see if $item has a _t at the end, this is team info
// Set the item group
$item_group = 'teams';
@@ -328,7 +299,7 @@ protected function processPlayersAndTeams(Buffer &$buffer, Result &$result)
break;
}
// Add the value to the proper item in the correct group
- $result->addSub($item_group, $item_type, utf8_encode(trim($val)));
+ $result->addSub($item_group, $item_type, $this->convertToUtf8(trim($val)));
}
// Unset our buffer
unset($buf_temp);
diff --git a/src/GameQ/Protocols/Gmod.php b/src/GameQ/Protocols/Gmod.php
index 65967247..f110dfdb 100644
--- a/src/GameQ/Protocols/Gmod.php
+++ b/src/GameQ/Protocols/Gmod.php
@@ -28,15 +28,11 @@ class Gmod extends Source
{
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'gmod';
+ protected string $name = 'gmod';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Garry's Mod";
+ protected string $name_long = "Garry's Mod";
}
diff --git a/src/GameQ/Protocols/Grav.php b/src/GameQ/Protocols/Grav.php
index e025075a..07e7589d 100644
--- a/src/GameQ/Protocols/Grav.php
+++ b/src/GameQ/Protocols/Grav.php
@@ -28,15 +28,11 @@ class Grav extends Source
{
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'grav';
+ protected string $name = 'grav';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "GRAV Online";
+ protected string $name_long = "GRAV Online";
}
diff --git a/src/GameQ/Protocols/Gta5m.php b/src/GameQ/Protocols/Gta5m.php
index 59843f66..d1ea57cb 100644
--- a/src/GameQ/Protocols/Gta5m.php
+++ b/src/GameQ/Protocols/Gta5m.php
@@ -36,22 +36,16 @@ class Gta5m extends Cfx
{
/**
* The query protocol used to make the call
- *
- * @type string
*/
- protected $protocol = 'gta5m';
+ protected string $protocol = 'gta5m';
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'gta5m';
+ protected string $name = 'gta5m';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "GTA Five M";
+ protected string $name_long = "GTA Five M";
}
diff --git a/src/GameQ/Protocols/Gtan.php b/src/GameQ/Protocols/Gtan.php
index f7b531ee..31bf7fc2 100644
--- a/src/GameQ/Protocols/Gtan.php
+++ b/src/GameQ/Protocols/Gtan.php
@@ -39,7 +39,7 @@ class Gtan extends Http
*
* @var array
*/
- protected $packets = [
+ protected array $packets = [
//self::PACKET_STATUS => "GET /apiservers HTTP/1.0\r\nHost: master.gtanet.work\r\nAccept: */*\r\n\r\n",
self::PACKET_STATUS => "GET /gtan/api.php?ip=%s&raw HTTP/1.0\r\nHost: multiplayerhosting.info\r\nAccept: */*\r\n\r\n",
];
@@ -47,46 +47,41 @@ class Gtan extends Http
/**
* Http protocol is SSL
*
- * @var string
*/
- protected $transport = self::TRANSPORT_SSL;
+ protected string $transport = self::TRANSPORT_SSL;
/**
* The protocol being used
*
- * @var string
*/
- protected $protocol = 'gtan';
+ protected string $protocol = 'gtan';
/**
* String name of this protocol class
*
- * @var string
*/
- protected $name = 'gtan';
+ protected string $name = 'gtan';
/**
* Longer string name of this protocol class
*
- * @var string
*/
- protected $name_long = "Grand Theft Auto Network";
+ protected string $name_long = "Grand Theft Auto Network";
/**
* Holds the real ip so we can overwrite it back
- *
- * @var string
*/
- protected $realIp = null;
+ protected ?string $realIp = null;
- protected $realPortQuery = null;
+ /**
+ * Holds the real query port so we can overwrite it back
+ */
+ protected ?int $realPortQuery = null;
/**
* Normalize some items
- *
- * @var array
*/
- protected $normalize = [
+ protected array $normalize = [
// General
'general' => [
// target => source
@@ -100,7 +95,7 @@ class Gtan extends Http
],
];
- public function beforeSend(Server $server)
+ public function beforeSend(Server $server): void
{
// Loop over the packets and update them
foreach ($this->packets as $packetType => $packet) {
@@ -120,10 +115,10 @@ public function beforeSend(Server $server)
/**
* Process the response
*
- * @return array
+ * @return mixed
* @throws Exception
*/
- public function processResponse()
+ public function processResponse(): mixed
{
// No response, assume offline
if (empty($this->packets_response)) {
diff --git a/src/GameQ/Protocols/Gtar.php b/src/GameQ/Protocols/Gtar.php
index 2121e07c..17e0fc5e 100644
--- a/src/GameQ/Protocols/Gtar.php
+++ b/src/GameQ/Protocols/Gtar.php
@@ -37,53 +37,48 @@ class Gtar extends Http
*
* @var array
*/
- protected $packets = [
+ protected array $packets = [
self::PACKET_STATUS => "GET /master/ HTTP/1.0\r\nHost: cdn.rage.mp\r\nAccept: */*\r\n\r\n",
];
/**
* Http protocol is SSL
*
- * @var string
*/
- protected $transport = self::TRANSPORT_SSL;
+ protected string $transport = self::TRANSPORT_SSL;
/**
* The protocol being used
*
- * @var string
*/
- protected $protocol = 'gtar';
+ protected string $protocol = 'gtar';
/**
* String name of this protocol class
*
- * @var string
*/
- protected $name = 'gtar';
+ protected string $name = 'gtar';
/**
* Longer string name of this protocol class
*
- * @var string
*/
- protected $name_long = "Grand Theft Auto Rage";
+ protected string $name_long = "Grand Theft Auto Rage";
/**
* Holds the real ip so we can overwrite it back
- *
- * @var string
*/
- protected $realIp = null;
+ protected ?string $realIp = null;
- protected $realPortQuery = null;
+ /**
+ * Holds the real query port so we can overwrite it back
+ */
+ protected ?int $realPortQuery = null;
/**
* Normalize some items
- *
- * @var array
*/
- protected $normalize = [
+ protected array $normalize = [
// General
'general' => [
// target => source
@@ -95,7 +90,7 @@ class Gtar extends Http
],
];
- public function beforeSend(Server $server)
+ public function beforeSend(Server $server): void
{
// Loop over the packets and update them
foreach ($this->packets as $packetType => $packet) {
@@ -114,10 +109,10 @@ public function beforeSend(Server $server)
/**
* Process the response
*
- * @return array
+ * @return mixed
* @throws Exception
*/
- public function processResponse()
+ public function processResponse(): mixed
{
// No response, assume offline
if (empty($this->packets_response)) {
diff --git a/src/GameQ/Protocols/Had2.php b/src/GameQ/Protocols/Had2.php
index 92134351..e65bcd4e 100644
--- a/src/GameQ/Protocols/Had2.php
+++ b/src/GameQ/Protocols/Had2.php
@@ -28,31 +28,23 @@ class Had2 extends Gamespy2
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'had2';
+ protected string $name = 'had2';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Hidden & Dangerous 2";
+ protected string $name_long = "Hidden & Dangerous 2";
/**
* The difference between the client port and query port
- *
- * @type int
*/
- protected $port_diff = 3;
+ protected int $port_diff = 3;
/**
* Normalize settings for this protocol
- *
- * @type array
*/
- protected $normalize = [
+ protected array $normalize = [
// General
'general' => [
// target => source
diff --git a/src/GameQ/Protocols/Halo.php b/src/GameQ/Protocols/Halo.php
index f402f94d..d1baf0be 100644
--- a/src/GameQ/Protocols/Halo.php
+++ b/src/GameQ/Protocols/Halo.php
@@ -28,15 +28,11 @@ class Halo extends Gamespy2
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'halo';
+ protected string $name = 'halo';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Halo: Combat Evolved";
+ protected string $name_long = "Halo: Combat Evolved";
}
diff --git a/src/GameQ/Protocols/Hl1.php b/src/GameQ/Protocols/Hl1.php
index e17667b6..b065868c 100644
--- a/src/GameQ/Protocols/Hl1.php
+++ b/src/GameQ/Protocols/Hl1.php
@@ -29,15 +29,11 @@ class Hl1 extends Source
{
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'hl1';
+ protected string $name = 'hl1';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Half Life";
+ protected string $name_long = "Half Life";
}
diff --git a/src/GameQ/Protocols/Hl2dm.php b/src/GameQ/Protocols/Hl2dm.php
index 15f881aa..977a8e0f 100644
--- a/src/GameQ/Protocols/Hl2dm.php
+++ b/src/GameQ/Protocols/Hl2dm.php
@@ -28,15 +28,11 @@ class Hl2dm extends Source
{
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'hl2dm';
+ protected string $name = 'hl2dm';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Half Life 2: Deathmatch";
+ protected string $name_long = "Half Life 2: Deathmatch";
}
diff --git a/src/GameQ/Protocols/Hll.php b/src/GameQ/Protocols/Hll.php
index bf0b00c1..0ad0a862 100644
--- a/src/GameQ/Protocols/Hll.php
+++ b/src/GameQ/Protocols/Hll.php
@@ -28,41 +28,17 @@ class Hll extends Source
{
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'hll';
+ protected string $name = 'hll';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Hell Let Loose";
+ protected string $name_long = "Hell Let Loose";
/**
* query_port = client_port + 15
* 64015 = 64000 + 15
- *
- * @type int
*/
- protected $port_diff = 15;
-
- /**
- * Normalize settings for this protocol
- *
- * @type array
- */
- /*protected $normalize = [
- 'general' => [
- // target => source
- 'dedicated' => 'dedicated',
- 'gametype' => 'gametype',
- 'servername' => 'hostname',
- 'mapname' => 'mapname',
- 'maxplayers' => 'maxplayers',
- 'numplayers' => 'numplayers',
- 'password' => 'password',
- ],
- ];*/
+ protected int $port_diff = 15;
}
diff --git a/src/GameQ/Protocols/Http.php b/src/GameQ/Protocols/Http.php
index 2a86d8d1..b965b3b3 100644
--- a/src/GameQ/Protocols/Http.php
+++ b/src/GameQ/Protocols/Http.php
@@ -32,36 +32,26 @@ abstract class Http extends Protocol
{
/**
* The query protocol used to make the call
- *
- * @type string
*/
- protected $protocol = 'http';
+ protected string $protocol = 'http';
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'http';
+ protected string $name = 'http';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Generic HTTP protocol";
+ protected string $name_long = "Generic HTTP protocol";
/**
* Http protocol is TCP
- *
- * @var string
*/
- protected $transport = self::TRANSPORT_TCP;
+ protected string $transport = self::TRANSPORT_TCP;
/**
* The client join link
- *
- * @type string
*/
- protected $join_link = null;
+ protected ?string $join_link = null;
}
diff --git a/src/GameQ/Protocols/Hurtworld.php b/src/GameQ/Protocols/Hurtworld.php
index fa54654a..e0020e21 100644
--- a/src/GameQ/Protocols/Hurtworld.php
+++ b/src/GameQ/Protocols/Hurtworld.php
@@ -29,14 +29,10 @@ class Hurtworld extends Source
{
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'hurtworld';
+ protected string $name = 'hurtworld';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Hurtworld";
+ protected string $name_long = "Hurtworld";
}
diff --git a/src/GameQ/Protocols/Insurgency.php b/src/GameQ/Protocols/Insurgency.php
index 77b8329e..e9c7635b 100644
--- a/src/GameQ/Protocols/Insurgency.php
+++ b/src/GameQ/Protocols/Insurgency.php
@@ -28,15 +28,11 @@ class Insurgency extends Source
{
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'insurgency';
+ protected string $name = 'insurgency';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Insurgency";
+ protected string $name_long = "Insurgency";
}
diff --git a/src/GameQ/Protocols/Insurgencysand.php b/src/GameQ/Protocols/Insurgencysand.php
index 407d6e26..d628020b 100644
--- a/src/GameQ/Protocols/Insurgencysand.php
+++ b/src/GameQ/Protocols/Insurgencysand.php
@@ -28,22 +28,16 @@ class Insurgencysand extends Source
{
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'insurgencysand';
+ protected string $name = 'insurgencysand';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Insurgency: Sandstorm";
+ protected string $name_long = "Insurgency: Sandstorm";
/**
* query_port = client_port + 29
- *
- * @type int
*/
- protected $port_diff = 29;
+ protected int $port_diff = 29;
}
diff --git a/src/GameQ/Protocols/Jediacademy.php b/src/GameQ/Protocols/Jediacademy.php
index a051a3a9..3ca6b07b 100644
--- a/src/GameQ/Protocols/Jediacademy.php
+++ b/src/GameQ/Protocols/Jediacademy.php
@@ -28,15 +28,11 @@ class Jediacademy extends Quake3
{
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'jediacademy';
+ protected string $name = 'jediacademy';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Star Wars Jedi Knight: Jedi Academy";
+ protected string $name_long = "Star Wars Jedi Knight: Jedi Academy";
}
diff --git a/src/GameQ/Protocols/Jedioutcast.php b/src/GameQ/Protocols/Jedioutcast.php
index 1afd9afe..aa07f253 100644
--- a/src/GameQ/Protocols/Jedioutcast.php
+++ b/src/GameQ/Protocols/Jedioutcast.php
@@ -28,15 +28,11 @@ class Jedioutcast extends Quake3
{
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'jedioutcast';
+ protected string $name = 'jedioutcast';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Star Wars Jedi Knight II: Jedi Outcast";
+ protected string $name_long = "Star Wars Jedi Knight II: Jedi Outcast";
}
diff --git a/src/GameQ/Protocols/Justcause2.php b/src/GameQ/Protocols/Justcause2.php
index 648cb6d5..e1996103 100644
--- a/src/GameQ/Protocols/Justcause2.php
+++ b/src/GameQ/Protocols/Justcause2.php
@@ -33,48 +33,38 @@ class Justcause2 extends Gamespy4
{
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'justcause2';
+ protected string $name = 'justcause2';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Just Cause 2 Multiplayer";
+ protected string $name_long = "Just Cause 2 Multiplayer";
/**
* The client join link
- *
- * @type string
*/
- protected $join_link = "steam://connect/%s:%d/";
+ protected ?string $join_link = "steam://connect/%s:%d/";
/**
* Change the packets used
*
* @var array
*/
- protected $packets = [
+ protected array $packets = [
self::PACKET_CHALLENGE => "\xFE\xFD\x09\x10\x20\x30\x40",
self::PACKET_ALL => "\xFE\xFD\x00\x10\x20\x30\x40%s\xFF\xFF\xFF\x02",
];
/**
* Override the packet split
- *
- * @var string
*/
- protected $packetSplit = "/\\x00\\x00\\x00/m";
+ protected string $packetsplit = "/\\x00\\x00\\x00/m";
/**
* Normalize settings for this protocol
- *
- * @type array
*/
- protected $normalize = [
+ protected array $normalize = [
'general' => [
// target => source
'dedicated' => 'dedicated',
@@ -94,11 +84,8 @@ class Justcause2 extends Gamespy4
/**
* Overload so we can add in some static data points
- *
- * @param Buffer $buffer
- * @param Result $result
*/
- protected function processDetails(Buffer &$buffer, Result &$result)
+ protected function processDetails(Buffer $buffer, Result $result): void
{
parent::processDetails($buffer, $result);
@@ -110,12 +97,9 @@ protected function processDetails(Buffer &$buffer, Result &$result)
/**
* Override the parent, this protocol is returned differently
*
- * @param Buffer $buffer
- * @param Result $result
- *
* @see Gamespy3::processPlayersAndTeams()
*/
- protected function processPlayersAndTeams(Buffer &$buffer, Result &$result)
+ protected function processPlayersAndTeams(Buffer $buffer, Result $result): void
{
// Loop until we run out of data
while ($buffer->getLength()) {
diff --git a/src/GameQ/Protocols/Justcause3.php b/src/GameQ/Protocols/Justcause3.php
index c4e901d9..cdc48409 100644
--- a/src/GameQ/Protocols/Justcause3.php
+++ b/src/GameQ/Protocols/Justcause3.php
@@ -29,22 +29,16 @@ class Justcause3 extends Source
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'justcause3';
+ protected string $name = 'justcause3';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Just Cause 3";
+ protected string $name_long = "Just Cause 3";
/**
* Query port = client_port + 1
- *
- * @type int
*/
- protected $port_diff = 1;
+ protected int $port_diff = 1;
}
diff --git a/src/GameQ/Protocols/Killingfloor.php b/src/GameQ/Protocols/Killingfloor.php
index 9cc19643..c2685715 100644
--- a/src/GameQ/Protocols/Killingfloor.php
+++ b/src/GameQ/Protocols/Killingfloor.php
@@ -32,36 +32,27 @@ class Killingfloor extends Unreal2
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'killing floor';
+ protected string $name = 'killing floor';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Killing Floor";
+ protected string $name_long = "Killing Floor";
/**
* query_port = client_port + 1
- *
- * @type int
*/
- protected $port_diff = 1;
+ protected int $port_diff = 1;
/**
* The client join link
- *
- * @type string
*/
- protected $join_link = "steam://connect/%s:%d/";
+ protected ?string $join_link = "steam://connect/%s:%d/";
/**
* Overload the default detail process since this version is different
- *
- * @param \GameQ\Buffer $buffer
+
*
* @return array
*/
@@ -77,20 +68,18 @@ protected function processDetails(Buffer $buffer)
$result->add('queryport', $buffer->readInt32()); // 0
// We burn the first char since it is not always correct with the hostname
- $buffer->skip(1);
+ $buffer->skip();
// Read as a regular string since the length is incorrect (what we skipped earlier)
- $result->add('servername', utf8_encode($buffer->readString()));
+ $result->add('servername', $this->convertToUtf8($buffer->readString()));
// The rest is read as normal
- $result->add('mapname', utf8_encode($buffer->readPascalString(1)));
+ $result->add('mapname', $this->convertToUtf8($buffer->readPascalString(1)));
$result->add('gametype', $buffer->readPascalString(1));
$result->add('numplayers', $buffer->readInt32());
$result->add('maxplayers', $buffer->readInt32());
$result->add('currentwave', $buffer->readInt32());
- unset($buffer);
-
return $result->fetch();
}
}
diff --git a/src/GameQ/Protocols/Killingfloor2.php b/src/GameQ/Protocols/Killingfloor2.php
index a134f258..c3203841 100644
--- a/src/GameQ/Protocols/Killingfloor2.php
+++ b/src/GameQ/Protocols/Killingfloor2.php
@@ -29,23 +29,17 @@ class Killingfloor2 extends Source
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'killing floor 2';
+ protected string $name = 'killing floor 2';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Killing Floor 2";
+ protected string $name_long = "Killing Floor 2";
/**
* query_port = client_port + 19238
* 27015 = 7777 + 19238
- *
- * @type int
*/
- protected $port_diff = 19238;
+ protected int $port_diff = 19238;
}
diff --git a/src/GameQ/Protocols/Kingpin.php b/src/GameQ/Protocols/Kingpin.php
index 87007d91..fd0a1bf0 100644
--- a/src/GameQ/Protocols/Kingpin.php
+++ b/src/GameQ/Protocols/Kingpin.php
@@ -29,15 +29,11 @@ class Kingpin extends Quake2
{
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'kingpin';
+ protected string $name = 'kingpin';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Kingpin: Life of Crime";
+ protected string $name_long = "Kingpin: Life of Crime";
}
diff --git a/src/GameQ/Protocols/L4d.php b/src/GameQ/Protocols/L4d.php
index 596452a7..c5b569ef 100644
--- a/src/GameQ/Protocols/L4d.php
+++ b/src/GameQ/Protocols/L4d.php
@@ -28,15 +28,11 @@ class L4d extends Source
{
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'l4d';
+ protected string $name = 'l4d';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Left 4 Dead";
+ protected string $name_long = "Left 4 Dead";
}
diff --git a/src/GameQ/Protocols/L4d2.php b/src/GameQ/Protocols/L4d2.php
index 475514c9..085638ce 100644
--- a/src/GameQ/Protocols/L4d2.php
+++ b/src/GameQ/Protocols/L4d2.php
@@ -28,15 +28,11 @@ class L4d2 extends Source
{
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'l4d2';
+ protected string $name = 'l4d2';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Left 4 Dead 2";
+ protected string $name_long = "Left 4 Dead 2";
}
diff --git a/src/GameQ/Protocols/Lhmp.php b/src/GameQ/Protocols/Lhmp.php
index 3d5e81f3..4195fe88 100644
--- a/src/GameQ/Protocols/Lhmp.php
+++ b/src/GameQ/Protocols/Lhmp.php
@@ -36,10 +36,8 @@ class Lhmp extends Protocol
/**
* Array of packets we want to look up.
* Each key should correspond to a defined method in this or a parent class
- *
- * @type array
*/
- protected $packets = [
+ protected array $packets = [
self::PACKET_DETAILS => "LHMPo",
self::PACKET_PLAYERS => "LHMPp",
];
@@ -47,47 +45,36 @@ class Lhmp extends Protocol
/**
* Use the response flag to figure out what method to run
*
- * @type array
*/
- protected $responses = [
+ protected array $responses = [
"LHMPo" => "processDetails",
"LHMPp" => "processPlayers",
];
/**
* The query protocol used to make the call
- *
- * @type string
*/
- protected $protocol = 'lhmp';
+ protected string $protocol = 'lhmp';
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'lhmp';
+ protected string $name = 'lhmp';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Lost Heaven";
+ protected string $name_long = "Lost Heaven";
/**
* query_port = client_port + 1
- *
- * @type int
*/
- protected $port_diff = 1;
+ protected int $port_diff = 1;
/**
* Normalize settings for this protocol
- *
- * @type array
*/
- protected $normalize = [
+ protected array $normalize = [
// General
'general' => [
// target => source
@@ -107,10 +94,10 @@ class Lhmp extends Protocol
/**
* Process the response
*
- * @return array
+ * @return mixed
* @throws \GameQ\Exception\Protocol
*/
- public function processResponse()
+ public function processResponse(): mixed
{
// Will hold the packets after sorting
$packets = [];
@@ -134,7 +121,7 @@ public function processResponse()
foreach ($packets as $header => $packetGroup) {
// Figure out which packet response this is
if (!array_key_exists($header, $this->responses)) {
- throw new Exception(__METHOD__ . " response type '{$header}' is not valid");
+ throw new Exception(__METHOD__ . " response type '$header' is not valid");
}
// Now we need to call the proper method
@@ -156,8 +143,6 @@ public function processResponse()
/**
* Handles processing the details data into a usable format
*
- * @param Buffer $buffer
- *
* @return array
* @throws Exception
*/
@@ -171,12 +156,10 @@ protected function processDetails(Buffer $buffer)
$result->add('password', $buffer->readString());
$result->add('numplayers', $buffer->readInt16());
$result->add('maxplayers', $buffer->readInt16());
- $result->add('servername', utf8_encode($buffer->readPascalString()));
+ $result->add('servername', $this->convertToUtf8($buffer->readPascalString()));
$result->add('gamemode', $buffer->readPascalString());
- $result->add('website', utf8_encode($buffer->readPascalString()));
- $result->add('mapname', utf8_encode($buffer->readPascalString()));
-
- unset($buffer);
+ $result->add('website', $this->convertToUtf8($buffer->readPascalString()));
+ $result->add('mapname', $this->convertToUtf8($buffer->readPascalString()));
return $result->fetch();
}
@@ -184,8 +167,6 @@ protected function processDetails(Buffer $buffer)
/**
* Handles processing the player data into a usable format
*
- * @param Buffer $buffer
- *
* @return array
*/
protected function processPlayers(Buffer $buffer)
@@ -203,11 +184,11 @@ protected function processPlayers(Buffer $buffer)
if (($id = $buffer->readInt16()) !== 0) {
// Add the results
$result->addPlayer('id', $id);
- $result->addPlayer('name', utf8_encode($buffer->readPascalString()));
+ $result->addPlayer('name', $this->convertToUtf8($buffer->readPascalString()));
}
}
- unset($buffer, $id);
+ unset($id);
return $result->fetch();
}
diff --git a/src/GameQ/Protocols/Lifeisfeudal.php b/src/GameQ/Protocols/Lifeisfeudal.php
index 0db79805..d9123331 100644
--- a/src/GameQ/Protocols/Lifeisfeudal.php
+++ b/src/GameQ/Protocols/Lifeisfeudal.php
@@ -28,22 +28,16 @@ class Lifeisfeudal extends Source
{
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'lifeisfeudal';
+ protected string $name = 'lifeisfeudal';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Life is Feudal";
+ protected string $name_long = "Life is Feudal";
/**
* query_port = client_port + 2
- *
- * @type int
*/
- protected $port_diff = 2;
+ protected int $port_diff = 2;
}
diff --git a/src/GameQ/Protocols/M2mp.php b/src/GameQ/Protocols/M2mp.php
index a6076e3a..54fdd4c1 100644
--- a/src/GameQ/Protocols/M2mp.php
+++ b/src/GameQ/Protocols/M2mp.php
@@ -40,63 +40,48 @@ class M2mp extends Protocol
/**
* Array of packets we want to look up.
* Each key should correspond to a defined method in this or a parent class
- *
- * @type array
*/
- protected $packets = [
+ protected array $packets = [
self::PACKET_ALL => "M2MP",
];
/**
* Use the response flag to figure out what method to run
*
- * @type array
*/
- protected $responses = [
+ protected array $responses = [
"M2MP" => 'processStatus',
];
/**
* The query protocol used to make the call
- *
- * @type string
*/
- protected $protocol = 'm2mp';
+ protected string $protocol = 'm2mp';
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'm2mp';
+ protected string $name = 'm2mp';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Mafia 2 Multiplayer";
+ protected string $name_long = "Mafia 2 Multiplayer";
/**
* The client join link
- *
- * @type string
*/
- protected $join_link = null;
+ protected ?string $join_link = null;
/**
* The difference between the client port and query port
- *
- * @type int
*/
- protected $port_diff = 1;
+ protected int $port_diff = 1;
/**
* Normalize settings for this protocol
- *
- * @type array
*/
- protected $normalize = [
+ protected array $normalize = [
// General
'general' => [
// target => source
@@ -118,7 +103,7 @@ class M2mp extends Protocol
* @return mixed
* @throws Exception
*/
- public function processResponse()
+ public function processResponse(): mixed
{
// Make a buffer
$buffer = new Buffer(implode('', $this->packets_response));
@@ -128,18 +113,16 @@ public function processResponse()
// Header
// Figure out which packet response this is
- if ($header != "M2MP") {
+ if ($header !== "M2MP") {
throw new Exception(__METHOD__ . " response type '" . bin2hex($header) . "' is not valid");
}
- return call_user_func_array([$this, $this->responses[$header]], [$buffer]);
+ return $this->{$this->responses[$header]}($buffer);
}
/**
* Process the status response
*
- * @param Buffer $buffer
- *
* @return array
*/
protected function processStatus(Buffer $buffer)
@@ -147,22 +130,15 @@ protected function processStatus(Buffer $buffer)
// We need to split the data and offload
$results = $this->processServerInfo($buffer);
- $results = array_merge_recursive(
+ return array_merge_recursive(
$results,
$this->processPlayers($buffer)
);
-
- unset($buffer);
-
- // Return results
- return $results;
}
/**
* Handle processing the server information
*
- * @param Buffer $buffer
- *
* @return array
*/
protected function processServerInfo(Buffer $buffer)
@@ -181,16 +157,12 @@ protected function processServerInfo(Buffer $buffer)
$result->add('gamemode', $buffer->readPascalString(1, true));
$result->add('password', (bool) $buffer->readInt8());
- unset($buffer);
-
return $result->fetch();
}
/**
* Handle processing of player data
*
- * @param Buffer $buffer
- *
* @return array
*/
protected function processPlayers(Buffer $buffer)
@@ -208,12 +180,9 @@ protected function processPlayers(Buffer $buffer)
// Only player name information is available
// Add player name, encoded
- $result->addPlayer('name', utf8_encode(trim($buffer->readPascalString(1, true))));
+ $result->addPlayer('name', $this->convertToUtf8(trim($buffer->readPascalString(1, true))));
}
- // Clear
- unset($buffer);
-
return $result->fetch();
}
}
diff --git a/src/GameQ/Protocols/Minecraft.php b/src/GameQ/Protocols/Minecraft.php
index a895cb87..d1fa4fa5 100644
--- a/src/GameQ/Protocols/Minecraft.php
+++ b/src/GameQ/Protocols/Minecraft.php
@@ -43,31 +43,23 @@ class Minecraft extends Gamespy3
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'minecraft';
+ protected string $name = 'minecraft';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Minecraft";
+ protected string $name_long = "Minecraft";
/**
* The client join link
- *
- * @type string
*/
- protected $join_link = "minecraft://%s:%d/";
+ protected ?string $join_link = "minecraft://%s:%d/";
/**
* Normalize settings for this protocol
- *
- * @type array
*/
- protected $normalize = [
+ protected array $normalize = [
// General
'general' => [
// target => source
diff --git a/src/GameQ/Protocols/Minecraftbe.php b/src/GameQ/Protocols/Minecraftbe.php
index 60209679..298238a9 100644
--- a/src/GameQ/Protocols/Minecraftbe.php
+++ b/src/GameQ/Protocols/Minecraftbe.php
@@ -30,24 +30,18 @@ class Minecraftbe extends Raknet
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'minecraftbe';
+ protected string $name = 'minecraftbe';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Minecraft Bedrock Edition";
+ protected string $name_long = "Minecraft Bedrock Edition";
/**
* Normalize settings for this protocol
- *
- * @type array
*/
- protected $normalize = [
+ protected array $normalize = [
// General
'general' => [
// target => source
diff --git a/src/GameQ/Protocols/Minecraftpe.php b/src/GameQ/Protocols/Minecraftpe.php
index 21d11868..dc0496df 100644
--- a/src/GameQ/Protocols/Minecraftpe.php
+++ b/src/GameQ/Protocols/Minecraftpe.php
@@ -30,15 +30,11 @@ class Minecraftpe extends Minecraft
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'minecraftpe';
+ protected string $name = 'minecraftpe';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "MinecraftPE";
+ protected string $name_long = "MinecraftPE";
}
diff --git a/src/GameQ/Protocols/Miscreated.php b/src/GameQ/Protocols/Miscreated.php
index d59fed12..ffb5a5ae 100644
--- a/src/GameQ/Protocols/Miscreated.php
+++ b/src/GameQ/Protocols/Miscreated.php
@@ -28,32 +28,24 @@ class Miscreated extends Source
{
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'miscreated';
+ protected string $name = 'miscreated';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Miscreated";
+ protected string $name_long = "Miscreated";
/**
* query_port = client_port + 2
* 64092 = 64090 + 2
- *
- * @type int
*/
- protected $port_diff = 2;
+ protected int $port_diff = 2;
/**
* Normalize settings for this protocol
- *
- * @type array
*/
- protected $normalize = [
+ protected array $normalize = [
'general' => [
// target => source
'dedicated' => 'dedicated',
diff --git a/src/GameQ/Protocols/Modiverse.php b/src/GameQ/Protocols/Modiverse.php
index 64b41ed5..be35fbec 100644
--- a/src/GameQ/Protocols/Modiverse.php
+++ b/src/GameQ/Protocols/Modiverse.php
@@ -29,15 +29,11 @@ class Modiverse extends Source
{
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'modiverse';
+ protected string $name = 'modiverse';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Modiverse";
+ protected string $name_long = "Modiverse";
}
diff --git a/src/GameQ/Protocols/Mohaa.php b/src/GameQ/Protocols/Mohaa.php
index 66ddd7e7..dac15a3c 100644
--- a/src/GameQ/Protocols/Mohaa.php
+++ b/src/GameQ/Protocols/Mohaa.php
@@ -29,24 +29,18 @@ class Mohaa extends Gamespy
{
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'mohaa';
+ protected string $name = 'mohaa';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Medal of honor: Allied Assault";
+ protected string $name_long = "Medal of honor: Allied Assault";
/**
* Normalize settings for this protocol
- *
- * @type array
*/
- protected $normalize = [
+ protected array $normalize = [
'general' => [
// target => source
'dedicated' => 'dedicated',
@@ -67,12 +61,8 @@ class Mohaa extends Gamespy
/**
* Query port is always the client port + 97 in MOHAA
- *
- * @param int $clientPort
- *
- * @return int
*/
- public function findQueryPort($clientPort)
+ public function findQueryPort(int $clientPort): int
{
return $clientPort + 97;
}
diff --git a/src/GameQ/Protocols/Mordhau.php b/src/GameQ/Protocols/Mordhau.php
index fa305ce1..dec895ba 100644
--- a/src/GameQ/Protocols/Mordhau.php
+++ b/src/GameQ/Protocols/Mordhau.php
@@ -29,25 +29,11 @@ class Mordhau extends Source
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'mordhau';
+ protected string $name = 'mordhau';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "MORDHAU";
-
- #protected $port = 7777;
-
- /**
- * query_port = client_port + 19238
- * 27015 = 7777 + 19238
- *
- * @type int
- */
- #protected $port_diff = 19238;
+ protected string $name_long = "MORDHAU";
}
diff --git a/src/GameQ/Protocols/Mta.php b/src/GameQ/Protocols/Mta.php
index b95dc4c8..da8d5282 100644
--- a/src/GameQ/Protocols/Mta.php
+++ b/src/GameQ/Protocols/Mta.php
@@ -31,29 +31,21 @@ class Mta extends Ase
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'mta';
+ protected string $name = 'mta';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Multi Theft Auto";
+ protected string $name_long = "Multi Theft Auto";
/**
* query_port = client_port + 123
- *
- * @type int
*/
- protected $port_diff = 123;
+ protected int $port_diff = 123;
/**
* The client join link
- *
- * @type string
*/
- protected $join_link = "mtasa://%s:%d/";
+ protected ?string $join_link = "mtasa://%s:%d/";
}
diff --git a/src/GameQ/Protocols/Mumble.php b/src/GameQ/Protocols/Mumble.php
index 299389cf..b51f7510 100644
--- a/src/GameQ/Protocols/Mumble.php
+++ b/src/GameQ/Protocols/Mumble.php
@@ -36,61 +36,45 @@ class Mumble extends Protocol
/**
* Array of packets we want to look up.
* Each key should correspond to a defined method in this or a parent class
- *
- * @type array
*/
- protected $packets = [
+ protected array $packets = [
self::PACKET_ALL => "\x6A\x73\x6F\x6E", // JSON packet
];
/**
* The transport mode for this protocol is TCP
- *
- * @type string
- */
- protected $transport = self::TRANSPORT_TCP;
+ */
+ protected string $transport = self::TRANSPORT_TCP;
/**
* The query protocol used to make the call
- *
- * @type string
*/
- protected $protocol = 'mumble';
+ protected string $protocol = 'mumble';
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'mumble';
+ protected string $name = 'mumble';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Mumble Server";
+ protected string $name_long = "Mumble Server";
/**
* The client join link
- *
- * @type string
*/
- protected $join_link = "mumble://%s:%d/";
+ protected ?string $join_link = "mumble://%s:%d/";
/**
* 27800 = 64738 - 36938
- *
- * @type int
*/
- protected $port_diff = -36938;
+ protected int $port_diff = -36938;
/**
* Normalize settings for this protocol
- *
- * @type array
*/
- protected $normalize = [
+ protected array $normalize = [
// General
'general' => [
'dedicated' => 'dedicated',
@@ -115,15 +99,20 @@ class Mumble extends Protocol
/**
* Process the response
*
- * @return array
+ * @return mixed
* @throws \GameQ\Exception\Protocol
*/
- public function processResponse()
+ public function processResponse(): mixed
{
-
- // Try to json_decode, make it into an array
- if (($data = json_decode(implode('', $this->packets_response), true)) === null) {
- throw new Exception(__METHOD__ . " Unable to decode JSON data.");
+ $data = json_decode(
+ implode('', $this->packets_response),
+ true,
+ 512,
+ JSON_THROW_ON_ERROR
+ );
+
+ if (!is_array($data)) {
+ throw new Exception('Failed to decode JSON response to array');
}
// Set the result to a new result instance
@@ -135,7 +124,7 @@ public function processResponse()
// Let's iterate over the response items, there are a lot
foreach ($data as $key => $value) {
// Ignore root for now, that is where all of the channel/player info is housed
- if (in_array($key, ['root'])) {
+ if ($key === 'root') {
continue;
}
@@ -160,13 +149,9 @@ public function processResponse()
/**
* Handles processing the the channels and user info
- *
- * @param array $data
- * @param \GameQ\Result $result
*/
- protected function processChannelsAndUsers(array $data, Result &$result)
+ protected function processChannelsAndUsers(array $data, Result $result): void
{
-
// Let's add all of the channel information
foreach ($data as $key => $value) {
// We will handle these later
diff --git a/src/GameQ/Protocols/Nmrih.php b/src/GameQ/Protocols/Nmrih.php
index acae3b6e..3002894d 100644
--- a/src/GameQ/Protocols/Nmrih.php
+++ b/src/GameQ/Protocols/Nmrih.php
@@ -29,15 +29,11 @@ class Nmrih extends Source
{
/**
* No More Room in Hell protocol class
- *
- * @type string
*/
- protected $name = 'nmrih';
+ protected string $name = 'nmrih';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "No More Room in Hell";
+ protected string $name_long = "No More Room in Hell";
}
diff --git a/src/GameQ/Protocols/Ns2.php b/src/GameQ/Protocols/Ns2.php
index 4c323929..1f3ef06e 100644
--- a/src/GameQ/Protocols/Ns2.php
+++ b/src/GameQ/Protocols/Ns2.php
@@ -28,22 +28,16 @@ class Ns2 extends Source
{
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'ns2';
+ protected string $name = 'ns2';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Natural Selection 2";
+ protected string $name_long = "Natural Selection 2";
/**
* query_port = client_port + 1
- *
- * @type int
*/
- protected $port_diff = 1;
+ protected int $port_diff = 1;
}
diff --git a/src/GameQ/Protocols/Of.php b/src/GameQ/Protocols/Of.php
index bce7612d..7c69f3b2 100644
--- a/src/GameQ/Protocols/Of.php
+++ b/src/GameQ/Protocols/Of.php
@@ -29,15 +29,11 @@ class Of extends Source
{
/**
* Open Fortress protocol class
- *
- * @type string
*/
- protected $name = 'of';
+ protected string $name = 'of';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Open Fortress";
+ protected string $name_long = "Open Fortress";
}
diff --git a/src/GameQ/Protocols/Openttd.php b/src/GameQ/Protocols/Openttd.php
index 75c44fe1..620b2999 100644
--- a/src/GameQ/Protocols/Openttd.php
+++ b/src/GameQ/Protocols/Openttd.php
@@ -36,47 +36,35 @@ class Openttd extends Protocol
/**
* Array of packets we want to look up.
* Each key should correspond to a defined method in this or a parent class
- *
- * @type array
*/
- protected $packets = [
+ protected array $packets = [
self::PACKET_ALL => "\x03\x00\x00",
];
/**
* The query protocol used to make the call
- *
- * @type string
*/
- protected $protocol = 'openttd';
+ protected string $protocol = 'openttd';
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'openttd';
+ protected string $name = 'openttd';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Open Transport Tycoon Deluxe";
+ protected string $name_long = "Open Transport Tycoon Deluxe";
/**
* The client join link
- *
- * @type string
*/
- protected $join_link = null;
+ protected ?string $join_link = null;
/**
* Normalize settings for this protocol
- *
- * @type array
*/
- protected $normalize = [
+ protected array $normalize = [
// General
'general' => [
// target => source
@@ -95,7 +83,7 @@ class Openttd extends Protocol
* @return mixed
* @throws Exception
*/
- public function processResponse()
+ public function processResponse(): mixed
{
// Make a buffer
$buffer = new Buffer(implode('', $this->packets_response));
@@ -106,22 +94,20 @@ public function processResponse()
// Grab the header
$length = $buffer->readInt16();
//$type = $buffer->readInt8();
- $buffer->skip(1); // Skip the "$type" as its not used in the code, and to comply with phpmd it cant be assigned and not used.
+ $buffer->skip(); // Skip the "$type" as its not used in the code.
// Header
// Figure out which packet response this is
- if ($packetLength != $length) {
- throw new Exception(__METHOD__ . " response type '" . bin2hex($length) . "' is not valid");
+ if ($packetLength !== $length) {
+ throw new Exception(__METHOD__ . " header length '" .$length . "' does not match packet length '" . $packetLength . "'.");
}
- return call_user_func_array([$this, 'processServerInfo'], [$buffer]);
+ return $this->processServerInfo($buffer);
}
/**
* Handle processing the server information
*
- * @param Buffer $buffer
- *
* @return array
*/
protected function processServerInfo(Buffer $buffer)
@@ -176,7 +162,6 @@ protected function processServerInfo(Buffer $buffer)
$result->add('dedicated', $buffer->readInt8());
// Cascades all the way down even if case is meet
}
- unset($buffer);
return $result->fetch();
}
diff --git a/src/GameQ/Protocols/Pixark.php b/src/GameQ/Protocols/Pixark.php
index 445f6541..69d47d7d 100644
--- a/src/GameQ/Protocols/Pixark.php
+++ b/src/GameQ/Protocols/Pixark.php
@@ -29,22 +29,16 @@ class Pixark extends Arkse
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'pixark';
+ protected string $name = 'pixark';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "PixARK";
+ protected string $name_long = "PixARK";
/**
* Query port = client_port + 1
- *
- * @type int
*/
- protected $port_diff = 1;
+ protected int $port_diff = 1;
}
diff --git a/src/GameQ/Protocols/Postscriptum.php b/src/GameQ/Protocols/Postscriptum.php
index 555ba7d1..2174ae4b 100644
--- a/src/GameQ/Protocols/Postscriptum.php
+++ b/src/GameQ/Protocols/Postscriptum.php
@@ -28,23 +28,17 @@ class Postscriptum extends Source
{
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'postscriptum';
+ protected string $name = 'postscriptum';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Post Scriptum";
+ protected string $name_long = "Post Scriptum";
/**
* query_port = client_port + 10
* 64092 = 64090 + 10
- *
- * @type int
*/
- protected $port_diff = 10;
+ protected int $port_diff = 10;
}
diff --git a/src/GameQ/Protocols/Projectrealitybf2.php b/src/GameQ/Protocols/Projectrealitybf2.php
index 6f4b5ce0..271fc43a 100644
--- a/src/GameQ/Protocols/Projectrealitybf2.php
+++ b/src/GameQ/Protocols/Projectrealitybf2.php
@@ -31,15 +31,11 @@ class Projectrealitybf2 extends Bf2
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'projectrealitybf2';
+ protected string $name = 'projectrealitybf2';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Project Reality: Battlefield 2";
+ protected string $name_long = "Project Reality: Battlefield 2";
}
diff --git a/src/GameQ/Protocols/Quake2.php b/src/GameQ/Protocols/Quake2.php
index f0366c2c..e0a55fab 100644
--- a/src/GameQ/Protocols/Quake2.php
+++ b/src/GameQ/Protocols/Quake2.php
@@ -20,56 +20,43 @@ class Quake2 extends Protocol
/**
* Array of packets we want to look up.
* Each key should correspond to a defined method in this or a parent class
- *
- * @type array
*/
- protected $packets = [
+ protected array $packets = [
self::PACKET_STATUS => "\xFF\xFF\xFF\xFFstatus\x00",
];
/**
* Use the response flag to figure out what method to run
*
- * @type array
*/
- protected $responses = [
+ protected array $responses = [
"\xFF\xFF\xFF\xFF\x70\x72\x69\x6e\x74" => 'processStatus',
];
/**
* The query protocol used to make the call
- *
- * @type string
*/
- protected $protocol = 'quake2';
+ protected string $protocol = 'quake2';
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'quake2';
+ protected string $name = 'quake2';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Quake 2 Server";
+ protected string $name_long = "Quake 2 Server";
/**
* The client join link
- *
- * @type string
*/
- protected $join_link = null;
+ protected ?string $join_link = null;
/**
* Normalize settings for this protocol
- *
- * @type array
*/
- protected $normalize = [
+ protected array $normalize = [
// General
'general' => [
// target => source
@@ -95,7 +82,7 @@ class Quake2 extends Protocol
* @return mixed
* @throws Exception
*/
- public function processResponse()
+ public function processResponse(): mixed
{
// Make a buffer
$buffer = new Buffer(implode('', $this->packets_response));
@@ -108,14 +95,12 @@ public function processResponse()
throw new Exception(__METHOD__ . " response type '" . bin2hex($header) . "' is not valid");
}
- return call_user_func_array([$this, $this->responses[$header]], [$buffer]);
+ return $this->{$this->responses[$header]}($buffer);
}
/**
* Process the status response
*
- * @param Buffer $buffer
- *
* @return array
*/
protected function processStatus(Buffer $buffer)
@@ -123,22 +108,15 @@ protected function processStatus(Buffer $buffer)
// We need to split the data and offload
$results = $this->processServerInfo(new Buffer($buffer->readString("\x0A")));
- $results = array_merge_recursive(
+ return array_merge_recursive(
$results,
$this->processPlayers(new Buffer($buffer->getBuffer()))
);
-
- unset($buffer);
-
- // Return results
- return $results;
}
/**
* Handle processing the server information
*
- * @param Buffer $buffer
- *
* @return array
*/
protected function processServerInfo(Buffer $buffer)
@@ -154,23 +132,19 @@ protected function processServerInfo(Buffer $buffer)
// Add result
$result->add(
trim($buffer->readString('\\')),
- utf8_encode(trim($buffer->readStringMulti(['\\', "\x0a"])))
+ $this->convertToUtf8(trim($buffer->readStringMulti(['\\', "\x0a"])))
);
}
$result->add('password', 0);
$result->add('mod', 0);
- unset($buffer);
-
return $result->fetch();
}
/**
* Handle processing of player data
*
- * @param Buffer $buffer
- *
* @return array
*/
protected function processPlayers(Buffer $buffer)
@@ -191,10 +165,10 @@ protected function processPlayers(Buffer $buffer)
$result->addPlayer('ping', $playerInfo->readString("\x20"));
// Skip first "
- $playerInfo->skip(1);
+ $playerInfo->skip();
// Add player name, encoded
- $result->addPlayer('name', utf8_encode(trim(($playerInfo->readString('"')))));
+ $result->addPlayer('name', $this->convertToUtf8(trim(($playerInfo->readString('"')))));
// Skip first "
$playerInfo->skip(2);
@@ -211,8 +185,7 @@ protected function processPlayers(Buffer $buffer)
$result->add('clients', $playerCount);
- // Clear
- unset($buffer, $playerCount);
+ unset($playerCount);
return $result->fetch();
}
diff --git a/src/GameQ/Protocols/Quake3.php b/src/GameQ/Protocols/Quake3.php
index 6269b927..c8afe031 100644
--- a/src/GameQ/Protocols/Quake3.php
+++ b/src/GameQ/Protocols/Quake3.php
@@ -20,56 +20,43 @@ class Quake3 extends Protocol
/**
* Array of packets we want to look up.
* Each key should correspond to a defined method in this or a parent class
- *
- * @type array
*/
- protected $packets = [
+ protected array $packets = [
self::PACKET_STATUS => "\xFF\xFF\xFF\xFF\x67\x65\x74\x73\x74\x61\x74\x75\x73\x0A",
];
/**
* Use the response flag to figure out what method to run
*
- * @type array
*/
- protected $responses = [
+ protected array $responses = [
"\xFF\xFF\xFF\xFFstatusResponse" => 'processStatus',
];
/**
* The query protocol used to make the call
- *
- * @type string
*/
- protected $protocol = 'quake3';
+ protected string $protocol = 'quake3';
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'quake3';
+ protected string $name = 'quake3';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Quake 3 Server";
+ protected string $name_long = "Quake 3 Server";
/**
* The client join link
- *
- * @type string
*/
- protected $join_link = null;
+ protected ?string $join_link = null;
/**
* Normalize settings for this protocol
- *
- * @type array
*/
- protected $normalize = [
+ protected array $normalize = [
// General
'general' => [
// target => source
@@ -95,7 +82,7 @@ class Quake3 extends Protocol
* @return mixed
* @throws Exception
*/
- public function processResponse()
+ public function processResponse(): mixed
{
// Make a buffer
$buffer = new Buffer(implode('', $this->packets_response));
@@ -108,30 +95,22 @@ public function processResponse()
throw new Exception(__METHOD__ . " response type '" . bin2hex($header) . "' is not valid");
}
- return call_user_func_array([$this, $this->responses[$header]], [$buffer]);
+ return $this->{$this->responses[$header]}($buffer);
}
protected function processStatus(Buffer $buffer)
{
// We need to split the data and offload
$results = $this->processServerInfo(new Buffer($buffer->readString("\x0A")));
-
- $results = array_merge_recursive(
+ return array_merge_recursive(
$results,
$this->processPlayers(new Buffer($buffer->getBuffer()))
);
-
- unset($buffer);
-
- // Return results
- return $results;
}
/**
* Handle processing the server information
*
- * @param Buffer $buffer
- *
* @return array
*/
protected function processServerInfo(Buffer $buffer)
@@ -147,20 +126,16 @@ protected function processServerInfo(Buffer $buffer)
// Add result
$result->add(
trim($buffer->readString('\\')),
- utf8_encode(trim($buffer->readStringMulti(['\\', "\x0a"])))
+ $this->convertToUtf8(trim($buffer->readStringMulti(['\\', "\x0a"])))
);
}
- unset($buffer);
-
return $result->fetch();
}
/**
* Handle processing of player data
*
- * @param Buffer $buffer
- *
* @return array
* @throws Exception
*/
@@ -179,10 +154,10 @@ protected function processPlayers(Buffer $buffer)
$result->addPlayer('ping', $buffer->readString("\x20"));
// Look ahead to see if we have a name or team
- $checkTeam = $buffer->lookAhead(1);
+ $checkTeam = $buffer->lookAhead();
// We have team info
- if ($checkTeam != '' and $checkTeam != '"') {
+ if ($checkTeam !== '' && $checkTeam !== '"') {
$result->addPlayer('team', $buffer->readString("\x20"));
}
@@ -195,7 +170,7 @@ protected function processPlayers(Buffer $buffer)
}
// Add player name, encoded
- $result->addPlayer('name', utf8_encode(trim($buffer->readString('"'))));
+ $result->addPlayer('name', $this->convertToUtf8(trim($buffer->readString('"'))));
// Burn ending delimiter
$buffer->read();
@@ -206,8 +181,7 @@ protected function processPlayers(Buffer $buffer)
$result->add('clients', $playerCount);
- // Clear
- unset($buffer, $playerCount);
+ unset($playerCount);
return $result->fetch();
}
diff --git a/src/GameQ/Protocols/Quake4.php b/src/GameQ/Protocols/Quake4.php
index 6a5f5c7e..9c1a1753 100644
--- a/src/GameQ/Protocols/Quake4.php
+++ b/src/GameQ/Protocols/Quake4.php
@@ -32,22 +32,17 @@ class Quake4 extends Doom3
{
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'quake4';
+ protected string $name = 'quake4';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Quake 4";
+ protected string $name_long = "Quake 4";
/**
* Handle processing of player data
- *
- * @param \GameQ\Buffer $buffer
+
*
* @return array
*/
@@ -67,7 +62,7 @@ protected function processPlayers(Buffer $buffer)
$result->addPlayer('ping', $buffer->readInt16());
$result->addPlayer('rate', $buffer->readInt32());
// Add player name, encoded
- $result->addPlayer('name', utf8_encode(trim($buffer->readString())));
+ $result->addPlayer('name', $this->convertToUtf8(trim($buffer->readString())));
$result->addPlayer('clantag', $buffer->readString());
// Increment
$playerCount++;
@@ -76,8 +71,7 @@ protected function processPlayers(Buffer $buffer)
// Add the number of players to the result
$result->add('numplayers', $playerCount);
- // Clear
- unset($buffer, $playerCount);
+ unset($playerCount);
return $result->fetch();
}
diff --git a/src/GameQ/Protocols/Quakelive.php b/src/GameQ/Protocols/Quakelive.php
index d5df3501..62877d53 100644
--- a/src/GameQ/Protocols/Quakelive.php
+++ b/src/GameQ/Protocols/Quakelive.php
@@ -28,15 +28,11 @@ class Quakelive extends Source
{
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'quakelive';
+ protected string $name = 'quakelive';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Quake Live";
+ protected string $name_long = "Quake Live";
}
diff --git a/src/GameQ/Protocols/Raknet.php b/src/GameQ/Protocols/Raknet.php
index 539cc688..3a033861 100644
--- a/src/GameQ/Protocols/Raknet.php
+++ b/src/GameQ/Protocols/Raknet.php
@@ -36,52 +36,40 @@ class Raknet extends Protocol
/**
* The magic string that is sent to get access to the server information
*/
- const OFFLINE_MESSAGE_DATA_ID = "\x00\xFF\xFF\x00\xFE\xFE\xFE\xFE\xFD\xFD\xFD\xFD\x12\x34\x56\x78";
+ public const OFFLINE_MESSAGE_DATA_ID = "\x00\xFF\xFF\x00\xFE\xFE\xFE\xFE\xFD\xFD\xFD\xFD\x12\x34\x56\x78";
/**
* Expected first part of the response from the server after query
*/
- const ID_UNCONNECTED_PONG = "\x1C";
+ public const ID_UNCONNECTED_PONG = "\x1C";
/**
* Array of packets we want to look up.
* Each key should correspond to a defined method in this or a parent class
- *
- * @type array
*/
- protected $packets = [
+ protected array $packets = [
self::PACKET_STATUS => "\x01%s%s\x02\x00\x00\x00\x00\x00\x00\x00", // Format time, magic,
];
/**
* The query protocol used to make the call
- *
- * @type string
*/
- protected $protocol = 'raknet';
+ protected string $protocol = 'raknet';
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'raknet';
+ protected string $name = 'raknet';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Raknet Server";
+ protected string $name_long = "Raknet Server";
/**
* Do some work to build the packet we need to send out to query
- *
- * @param Server $server
- *
- * @return void
*/
- public function beforeSend(Server $server)
+ public function beforeSend(Server $server): void
{
// Update the server status packet before it is sent
$this->packets[self::PACKET_STATUS] = sprintf(
@@ -94,16 +82,16 @@ public function beforeSend(Server $server)
/**
* Process the response
*
- * @return array
+ * @return mixed
* @throws \GameQ\Exception\Protocol
*/
- public function processResponse()
+ public function processResponse(): mixed
{
// Merge the response array into a buffer. Unknown if this protocol does split packets or not
$buffer = new Buffer(implode($this->packets_response));
// Read first character from response. It should match below
- $header = $buffer->read(1);
+ $header = $buffer->read();
// Check first character to make sure the header matches
if ($header !== self::ID_UNCONNECTED_PONG) {
diff --git a/src/GameQ/Protocols/Redorchestra2.php b/src/GameQ/Protocols/Redorchestra2.php
index 67330167..fd49ce19 100644
--- a/src/GameQ/Protocols/Redorchestra2.php
+++ b/src/GameQ/Protocols/Redorchestra2.php
@@ -28,23 +28,17 @@ class Redorchestra2 extends Source
{
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'redorchestra2';
+ protected string $name = 'redorchestra2';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Red Orchestra 2";
+ protected string $name_long = "Red Orchestra 2";
/**
* query_port = client_port + 19238
* 27015 = 7777 + 19238
- *
- * @type int
*/
- protected $port_diff = 19238;
+ protected int $port_diff = 19238;
}
diff --git a/src/GameQ/Protocols/Redorchestraostfront.php b/src/GameQ/Protocols/Redorchestraostfront.php
index 4c83b7eb..7ade3f67 100644
--- a/src/GameQ/Protocols/Redorchestraostfront.php
+++ b/src/GameQ/Protocols/Redorchestraostfront.php
@@ -29,15 +29,11 @@ class Redorchestraostfront extends Source
{
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'redorchestraostfront';
+ protected string $name = 'redorchestraostfront';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Red Orchestra: Ostfront 41-45";
+ protected string $name_long = "Red Orchestra: Ostfront 41-45";
}
diff --git a/src/GameQ/Protocols/Rf2.php b/src/GameQ/Protocols/Rf2.php
index 9901c425..8b358fc4 100644
--- a/src/GameQ/Protocols/Rf2.php
+++ b/src/GameQ/Protocols/Rf2.php
@@ -28,23 +28,17 @@ class Rf2 extends Source
{
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'rf2';
+ protected string $name = 'rf2';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "rFactor 2";
+ protected string $name_long = "rFactor 2";
/**
* query_port = client_port + 2
* 64092 = 64090 + 2
- *
- * @type int
*/
- protected $port_diff = 2;
+ protected int $port_diff = 2;
}
diff --git a/src/GameQ/Protocols/Rfactor.php b/src/GameQ/Protocols/Rfactor.php
index 296f4c16..78d1e2c2 100644
--- a/src/GameQ/Protocols/Rfactor.php
+++ b/src/GameQ/Protocols/Rfactor.php
@@ -29,15 +29,11 @@ class Rfactor extends Source
{
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'rfactor';
+ protected string $name = 'rfactor';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "rFactor";
+ protected string $name_long = "rFactor";
}
diff --git a/src/GameQ/Protocols/Rfactor2.php b/src/GameQ/Protocols/Rfactor2.php
index 22a0c085..bee9f996 100644
--- a/src/GameQ/Protocols/Rfactor2.php
+++ b/src/GameQ/Protocols/Rfactor2.php
@@ -29,15 +29,11 @@ class Rfactor2 extends Source
{
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'rfactor2';
+ protected string $name = 'rfactor2';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "rFactor2";
+ protected string $name_long = "rFactor2";
}
diff --git a/src/GameQ/Protocols/Risingstorm2.php b/src/GameQ/Protocols/Risingstorm2.php
index ddb82a53..feb4a4e0 100644
--- a/src/GameQ/Protocols/Risingstorm2.php
+++ b/src/GameQ/Protocols/Risingstorm2.php
@@ -29,26 +29,18 @@ class Risingstorm2 extends Source
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'rising storm 2';
+ protected string $name = 'rising storm 2';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Rising Storm 2";
+ protected string $name_long = "Rising Storm 2";
/**
* Query port is always 27015
- *
- * @param int $clientPort
- *
- * @return int
*/
- public function findQueryPort($clientPort)
+ public function findQueryPort(int $clientPort): int
{
return 27015;
}
diff --git a/src/GameQ/Protocols/Rust.php b/src/GameQ/Protocols/Rust.php
index 356cc19f..fc0bcbac 100644
--- a/src/GameQ/Protocols/Rust.php
+++ b/src/GameQ/Protocols/Rust.php
@@ -31,22 +31,16 @@ class Rust extends Source
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'rust';
+ protected string $name = 'rust';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Rust";
+ protected string $name_long = "Rust";
/**
* Overload so we can get max players from mp of keywords and num players from cp keyword
- *
- * @param Buffer $buffer
*/
protected function processDetails(Buffer $buffer)
{
diff --git a/src/GameQ/Protocols/Samp.php b/src/GameQ/Protocols/Samp.php
index cf01f834..7c39ca3c 100644
--- a/src/GameQ/Protocols/Samp.php
+++ b/src/GameQ/Protocols/Samp.php
@@ -38,10 +38,8 @@ class Samp extends Protocol
/**
* Array of packets we want to look up.
* Each key should correspond to a defined method in this or a parent class
- *
- * @type array
*/
- protected $packets = [
+ protected array $packets = [
self::PACKET_STATUS => "SAMP%si",
self::PACKET_PLAYERS => "SAMP%sd",
self::PACKET_RULES => "SAMP%sr",
@@ -50,9 +48,8 @@ class Samp extends Protocol
/**
* Use the response flag to figure out what method to run
*
- * @type array
*/
- protected $responses = [
+ protected array $responses = [
"\x69" => "processStatus", // i
"\x64" => "processPlayers", // d
"\x72" => "processRules", // r
@@ -60,45 +57,33 @@ class Samp extends Protocol
/**
* The query protocol used to make the call
- *
- * @type string
*/
- protected $protocol = 'samp';
+ protected string $protocol = 'samp';
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'samp';
+ protected string $name = 'samp';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "San Andreas Multiplayer";
+ protected string $name_long = "San Andreas Multiplayer";
/**
* Holds the calculated server code that is passed when querying for information
- *
- * @type string
*/
- protected $server_code = null;
+ protected ?string $server_code = null;
/**
* The client join link
- *
- * @type string
*/
- protected $join_link = "samp://%s:%d/";
+ protected ?string $join_link = "samp://%s:%d/";
/**
* Normalize settings for this protocol
- *
- * @type array
*/
- protected $normalize = [
+ protected array $normalize = [
// General
'general' => [
// target => source
@@ -119,14 +104,12 @@ class Samp extends Protocol
/**
* Handle some work before sending the packets out to the server
- *
- * @param \GameQ\Server $server
*/
- public function beforeSend(Server $server)
+ public function beforeSend(Server $server): void
{
-
// Build the server code
- $this->server_code = implode('', array_map('chr', explode('.', $server->ip()))) .
+ $ipNumbers = array_map('intval', explode('.', $server->ip()));
+ $this->server_code = implode('', array_map('chr', $ipNumbers)) .
pack("S", $server->portClient());
// Loop over the packets and update them
@@ -139,10 +122,10 @@ public function beforeSend(Server $server)
/**
* Process the response
*
- * @return array
+ * @return mixed
* @throws \GameQ\Exception\Protocol
*/
- public function processResponse()
+ public function processResponse(): mixed
{
// Results that will be returned
@@ -158,7 +141,7 @@ public function processResponse()
// Check the header, should be SAMP
if (($header = $buffer->read(4)) !== 'SAMP') {
- throw new Exception(__METHOD__ . " header response '{$header}' is not valid");
+ throw new Exception(__METHOD__ . " header response '$header' is not valid");
}
// Check to make sure the server response code matches what we sent
@@ -167,11 +150,11 @@ public function processResponse()
}
// Figure out what packet response this is for
- $response_type = $buffer->read(1);
+ $response_type = $buffer->read();
// Figure out which packet response this is
if (!array_key_exists($response_type, $this->responses)) {
- throw new Exception(__METHOD__ . " response type '{$response_type}' is not valid");
+ throw new Exception(__METHOD__ . " response type '$response_type' is not valid");
}
// Now we need to call the proper method
@@ -193,8 +176,6 @@ public function processResponse()
/**
* Handles processing the server status data
*
- * @param \GameQ\Buffer $buffer
- *
* @return array
* @throws \GameQ\Exception\Protocol
*/
@@ -213,20 +194,16 @@ protected function processStatus(Buffer $buffer)
$result->add('max_players', $buffer->readInt16());
// These are read differently for these last 3
- $result->add('servername', utf8_encode($buffer->read($buffer->readInt32())));
+ $result->add('servername', $this->convertToUtf8($buffer->read($buffer->readInt32())));
$result->add('gametype', $buffer->read($buffer->readInt32()));
$result->add('language', $buffer->read($buffer->readInt32()));
- unset($buffer);
-
return $result->fetch();
}
/**
* Handles processing the player data into a usable format
*
- * @param \GameQ\Buffer $buffer
- *
* @return array
*/
protected function processPlayers(Buffer $buffer)
@@ -241,21 +218,17 @@ protected function processPlayers(Buffer $buffer)
// Run until we run out of buffer
while ($buffer->getLength()) {
$result->addPlayer('id', $buffer->readInt8());
- $result->addPlayer('name', utf8_encode($buffer->readPascalString()));
+ $result->addPlayer('name', $this->convertToUtf8($buffer->readPascalString()));
$result->addPlayer('score', $buffer->readInt32());
$result->addPlayer('ping', $buffer->readInt32());
}
- unset($buffer);
-
return $result->fetch();
}
/**
* Handles processing the rules data into a usable format
*
- * @param \GameQ\Buffer $buffer
- *
* @return array
*/
protected function processRules(Buffer $buffer)
@@ -272,8 +245,6 @@ protected function processRules(Buffer $buffer)
$result->add($buffer->readPascalString(), $buffer->readPascalString());
}
- unset($buffer);
-
return $result->fetch();
}
}
diff --git a/src/GameQ/Protocols/Sco.php b/src/GameQ/Protocols/Sco.php
index a920fbd8..564a960f 100644
--- a/src/GameQ/Protocols/Sco.php
+++ b/src/GameQ/Protocols/Sco.php
@@ -29,22 +29,16 @@ class Sco extends Source
{
/**
* Sven Co-op protocol class
- *
- * @type string
*/
- protected $name = 'sco';
+ protected string $name = 'sco';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Sven Co-op";
+ protected string $name_long = "Sven Co-op";
/**
* query_port = client_port + 1
- *
- * @type int
*/
- protected $port_diff = 1;
+ protected int $port_diff = 1;
}
diff --git a/src/GameQ/Protocols/Serioussam.php b/src/GameQ/Protocols/Serioussam.php
index 64a03cf7..5a192866 100644
--- a/src/GameQ/Protocols/Serioussam.php
+++ b/src/GameQ/Protocols/Serioussam.php
@@ -28,31 +28,23 @@ class Serioussam extends Gamespy
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'serioussam';
+ protected string $name = 'serioussam';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Serious Sam";
+ protected string $name_long = "Serious Sam";
/**
* query_port = client_port + 1
- *
- * @type int
*/
- protected $port_diff = 1;
+ protected int $port_diff = 1;
/**
* Normalize settings for this protocol
- *
- * @type array
*/
- protected $normalize = [
+ protected array $normalize = [
// General
'general' => [
// target => source
diff --git a/src/GameQ/Protocols/Sevendaystodie.php b/src/GameQ/Protocols/Sevendaystodie.php
index 8919b97f..d6ecf9f2 100644
--- a/src/GameQ/Protocols/Sevendaystodie.php
+++ b/src/GameQ/Protocols/Sevendaystodie.php
@@ -28,22 +28,16 @@ class Sevendaystodie extends Source
{
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'sevendaystodie';
+ protected string $name = 'sevendaystodie';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "7 Days to Die";
+ protected string $name_long = "7 Days to Die";
/**
* query_port = client_port + 0
- *
- * @type int
*/
- protected $port_diff = 0;
+ protected int $port_diff = 0;
}
diff --git a/src/GameQ/Protocols/Ship.php b/src/GameQ/Protocols/Ship.php
index 9c3bee9e..a9507ff3 100644
--- a/src/GameQ/Protocols/Ship.php
+++ b/src/GameQ/Protocols/Ship.php
@@ -34,24 +34,19 @@ class Ship extends Source
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'ship';
+ protected string $name = 'ship';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "The Ship";
+ protected string $name_long = "The Ship";
/**
* Specific player parse for The Ship
*
* Player response has unknown data after the last real player
- *
- * @param \GameQ\Buffer $buffer
+
*
* @return array
*/
@@ -88,8 +83,6 @@ protected function processPlayers(Buffer $buffer)
}
}
- unset($buffer);
-
return $result->fetch();
}
}
diff --git a/src/GameQ/Protocols/Sof2.php b/src/GameQ/Protocols/Sof2.php
index 96a4db25..34821fac 100644
--- a/src/GameQ/Protocols/Sof2.php
+++ b/src/GameQ/Protocols/Sof2.php
@@ -28,22 +28,16 @@ class Sof2 extends Quake3
{
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'sof2';
+ protected string $name = 'sof2';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Solder of Fortune II";
+ protected string $name_long = "Solder of Fortune II";
/**
* The client join link
- *
- * @type string
*/
- protected $join_link = "sof2mp://%s:%d/";
+ protected ?string $join_link = "sof2mp://%s:%d/";
}
diff --git a/src/GameQ/Protocols/Soldat.php b/src/GameQ/Protocols/Soldat.php
index a9dbbc4e..68fc9086 100644
--- a/src/GameQ/Protocols/Soldat.php
+++ b/src/GameQ/Protocols/Soldat.php
@@ -31,29 +31,21 @@ class Soldat extends Ase
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'soldat';
+ protected string $name = 'soldat';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Soldat";
+ protected string $name_long = "Soldat";
/**
* query_port = client_port + 123
- *
- * @type int
*/
- protected $port_diff = 123;
+ protected int $port_diff = 123;
/**
* The client join link
- *
- * @type string
*/
- protected $join_link = "soldat://%s:%d/";
+ protected ?string $join_link = "soldat://%s:%d/";
}
diff --git a/src/GameQ/Protocols/Source.php b/src/GameQ/Protocols/Source.php
index dbf9212a..e0ebe71c 100644
--- a/src/GameQ/Protocols/Source.php
+++ b/src/GameQ/Protocols/Source.php
@@ -29,8 +29,6 @@
* This class is used as the basis for all other source based servers
* that rely on the source protocol for game querying.
*
- * @SuppressWarnings(PHPMD.NumberOfChildren)
- *
* @author Austin Bischoff
*/
class Source extends Protocol
@@ -39,16 +37,14 @@ class Source extends Protocol
/*
* Source engine type constants
*/
- const SOURCE_ENGINE = 0,
- GOLDSOURCE_ENGINE = 1;
+ public const SOURCE_ENGINE = 0;
+ public const GOLDSOURCE_ENGINE = 1;
/**
* Array of packets we want to look up.
* Each key should correspond to a defined method in this or a parent class
- *
- * @type array
*/
- protected $packets = [
+ protected array $packets = [
self::PACKET_CHALLENGE => "\xFF\xFF\xFF\xFF\x56\x00\x00\x00\x00",
self::PACKET_DETAILS => "\xFF\xFF\xFF\xFFTSource Engine Query\x00%s",
self::PACKET_PLAYERS => "\xFF\xFF\xFF\xFF\x55%s",
@@ -58,9 +54,8 @@ class Source extends Protocol
/**
* Use the response flag to figure out what method to run
*
- * @type array
*/
- protected $responses = [
+ protected array $responses = [
"\x49" => "processDetails", // I
"\x6d" => "processDetailsGoldSource", // m, goldsource
"\x44" => "processPlayers", // D
@@ -69,45 +64,33 @@ class Source extends Protocol
/**
* The query protocol used to make the call
- *
- * @type string
*/
- protected $protocol = 'source';
+ protected string $protocol = 'source';
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'source';
+ protected string $name = 'source';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Source Server";
+ protected string $name_long = "Source Server";
/**
* Define the Source engine type. By default it is assumed to be Source
- *
- * @type int
*/
- protected $source_engine = self::SOURCE_ENGINE;
+ protected int $source_engine = self::SOURCE_ENGINE;
/**
* The client join link
- *
- * @type string
*/
- protected $join_link = "steam://connect/%s:%d/";
+ protected ?string $join_link = "steam://connect/%s:%d/";
/**
* Normalize settings for this protocol
- *
- * @type array
*/
- protected $normalize = [
+ protected array $normalize = [
// General
'general' => [
// target => source
@@ -131,12 +114,9 @@ class Source extends Protocol
/**
* Parse the challenge response and apply it to all the packet types
*
- * @param \GameQ\Buffer $challenge_buffer
- *
- * @return bool
* @throws \GameQ\Exception\Protocol
*/
- public function challengeParseAndApply(Buffer $challenge_buffer)
+ public function challengeParseAndApply(Buffer $challenge_buffer): bool
{
// Skip the header
@@ -149,10 +129,10 @@ public function challengeParseAndApply(Buffer $challenge_buffer)
/**
* Process the response
*
- * @return array
+ * @return mixed
* @throws \GameQ\Exception\Protocol
*/
- public function processResponse()
+ public function processResponse(): mixed
{
// Will hold the results when complete
$results = [];
@@ -168,14 +148,13 @@ public function processResponse()
$header = $buffer->readInt32Signed();
// Single packet
- if ($header == -1) {
+ if ($header === -1) {
// We need to peek and see what kind of engine this is for later processing
- if ($buffer->lookAhead(1) == "\x6d") {
+ if ($buffer->lookAhead() === "\x6d") {
$this->source_engine = self::GOLDSOURCE_ENGINE;
}
$packets[] = $buffer->getBuffer();
- continue;
} else {
// Split packet
@@ -200,11 +179,11 @@ public function processResponse()
}
// Figure out what packet response this is for
- $response_type = $buffer->read(1);
+ $response_type = $buffer->read();
// Figure out which packet response this is
if (!array_key_exists($response_type, $this->responses)) {
- throw new Exception(__METHOD__ . " response type '{$response_type}' is not valid");
+ throw new Exception(__METHOD__ . " response type '$response_type' is not valid");
}
// Now we need to call the proper method
@@ -217,7 +196,7 @@ public function processResponse()
}
// Free up memory
- unset($packets, $packet, $packet_id, $response_type);
+ unset($packets, $packet_id, $response_type);
return $results;
}
@@ -229,8 +208,6 @@ public function processResponse()
/**
* Process the split packets and decompress if necessary
*
- * @SuppressWarnings(PHPMD.UnusedLocalVariable)
- *
* @param $packet_id
* @param array $packets
*
@@ -249,12 +226,12 @@ protected function processPackets($packet_id, array $packets = [])
$buffer = new Buffer($packet);
// Gold source
- if ($this->source_engine == self::GOLDSOURCE_ENGINE) {
+ if ($this->source_engine === self::GOLDSOURCE_ENGINE) {
// Grab the packet number (byte)
$packet_number = $buffer->readInt8();
// We need to burn the extra header (\xFF\xFF\xFF\xFF) on first loop
- if ($i == 0) {
+ if ($i === 0) {
$buffer->read(4);
}
@@ -272,12 +249,10 @@ protected function processPackets($packet_id, array $packets = [])
if ($packet_id & 0x80000000) {
// Check to see if we have Bzip2 installed
if (!function_exists('bzdecompress')) {
- // @codeCoverageIgnoreStart
throw new Exception(
'Bzip2 is not installed. See http://www.php.net/manual/en/book.bzip2.php for more info.',
0
);
- // @codeCoverageIgnoreEnd
}
// Get the length of the packet (long)
@@ -290,17 +265,15 @@ protected function processPackets($packet_id, array $packets = [])
$result = bzdecompress($buffer->getBuffer());
// Now verify the length
- if (strlen($result) != $packet_length) {
- // @codeCoverageIgnoreStart
+ if (strlen($result) !== $packet_length) {
throw new Exception(
- "Checksum for compressed packet failed! Length expected: {$packet_length}, length
+ "Checksum for compressed packet failed! Length expected: $packet_length, length
returned: " . strlen($result)
);
- // @codeCoverageIgnoreEnd
}
// We need to burn the extra header (\xFF\xFF\xFF\xFF) on first loop
- if ($i == 0) {
+ if ($i === 0) {
$result = substr($result, 4);
}
} else {
@@ -308,7 +281,7 @@ protected function processPackets($packet_id, array $packets = [])
$buffer->readInt16Signed();
// We need to burn the extra header (\xFF\xFF\xFF\xFF) on first loop
- if ($i == 0) {
+ if ($i === 0) {
$buffer->read(4);
}
@@ -323,9 +296,6 @@ protected function processPackets($packet_id, array $packets = [])
unset($buffer);
}
- // Free some memory
- unset($packets, $packet);
-
// Sort the packets by packet number
ksort($packs);
@@ -336,8 +306,6 @@ protected function processPackets($packet_id, array $packets = [])
/**
* Handles processing the details data into a usable format
*
- * @param \GameQ\Buffer $buffer
- *
* @return mixed
* @throws \GameQ\Exception\Protocol
*/
@@ -362,7 +330,7 @@ protected function processDetails(Buffer $buffer)
$result->add('secure', $buffer->readInt8());
// Special result for The Ship only (appid=2400)
- if ($result->get('steamappid') == 2400) {
+ if ($result->get('steamappid') === 2400) {
$result->add('game_mode', $buffer->readInt8());
$result->add('witness_count', $buffer->readInt8());
$result->add('witness_time', $buffer->readInt8());
@@ -371,7 +339,7 @@ protected function processDetails(Buffer $buffer)
$result->add('version', $buffer->readString());
// Because of php 5.4...
- $edfCheck = $buffer->lookAhead(1);
+ $edfCheck = $buffer->lookAhead();
// Extra data flag
if (!empty($edfCheck)) {
@@ -401,15 +369,12 @@ protected function processDetails(Buffer $buffer)
unset($edf);
}
- unset($buffer);
-
return $result->fetch();
}
/**
* Handles processing the server details from goldsource response
- *
- * @param \GameQ\Buffer $buffer
+
*
* @return array
* @throws \GameQ\Exception\Protocol
@@ -436,7 +401,7 @@ protected function processDetailsGoldSource(Buffer $buffer)
$result->add('ismod', $buffer->readInt8());
// We only run these if ismod is 1 (true)
- if ($result->get('ismod') == 1) {
+ if ($result->get('ismod') === 1) {
$result->add('mod_urlinfo', $buffer->readString());
$result->add('mod_urldl', $buffer->readString());
$buffer->skip();
@@ -449,17 +414,13 @@ protected function processDetailsGoldSource(Buffer $buffer)
$result->add('secure', $buffer->readInt8());
$result->add('num_bots', $buffer->readInt8());
- unset($buffer);
-
return $result->fetch();
}
/**
* Handles processing the player data into a usable format
*
- * @param \GameQ\Buffer $buffer
- *
- * @return mixed
+ * @return array
*/
protected function processPlayers(Buffer $buffer)
{
@@ -474,7 +435,7 @@ protected function processPlayers(Buffer $buffer)
$result->add('num_players', $num_players);
// No players so no need to look any further
- if ($num_players == 0) {
+ if ($num_players === 0) {
return $result->fetch();
}
@@ -486,17 +447,13 @@ protected function processPlayers(Buffer $buffer)
$result->addPlayer('time', $buffer->readFloat32());
}
- unset($buffer);
-
return $result->fetch();
}
/**
* Handles processing the rules data into a usable format
*
- * @param \GameQ\Buffer $buffer
- *
- * @return mixed
+ * @return array
*/
protected function processRules(Buffer $buffer)
{
@@ -515,8 +472,6 @@ protected function processRules(Buffer $buffer)
$result->add($buffer->readString(), $buffer->readString());
}
- unset($buffer);
-
return $result->fetch();
}
}
diff --git a/src/GameQ/Protocols/Spaceengineers.php b/src/GameQ/Protocols/Spaceengineers.php
index ddf8567d..2c2e04ab 100644
--- a/src/GameQ/Protocols/Spaceengineers.php
+++ b/src/GameQ/Protocols/Spaceengineers.php
@@ -28,15 +28,11 @@ class Spaceengineers extends Source
{
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'spaceengineers';
+ protected string $name = 'spaceengineers';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Space Engineers";
+ protected string $name_long = "Space Engineers";
}
diff --git a/src/GameQ/Protocols/Squad.php b/src/GameQ/Protocols/Squad.php
index 3c021885..d35396eb 100644
--- a/src/GameQ/Protocols/Squad.php
+++ b/src/GameQ/Protocols/Squad.php
@@ -31,23 +31,17 @@ class Squad extends Source
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'squad';
+ protected string $name = 'squad';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Squad";
+ protected string $name_long = "Squad";
/**
* query_port = client_port + 19378
* 27165 = 7787 + 19378
- *
- * @type int
*/
- protected $port_diff = 19378;
+ protected int $port_diff = 19378;
}
diff --git a/src/GameQ/Protocols/Starmade.php b/src/GameQ/Protocols/Starmade.php
index 09a033fb..7497fc09 100644
--- a/src/GameQ/Protocols/Starmade.php
+++ b/src/GameQ/Protocols/Starmade.php
@@ -37,54 +37,40 @@ class Starmade extends Protocol
/**
* Array of packets we want to query.
- *
- * @type array
*/
- protected $packets = [
+ protected array $packets = [
self::PACKET_STATUS => "\x00\x00\x00\x09\x2a\xff\xff\x01\x6f\x00\x00\x00\x00",
];
/**
* The transport mode for this protocol is TCP
- *
- * @type string
- */
- protected $transport = self::TRANSPORT_TCP;
+ */
+ protected string $transport = self::TRANSPORT_TCP;
/**
* The query protocol used to make the call
- *
- * @type string
*/
- protected $protocol = 'starmade';
+ protected string $protocol = 'starmade';
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'starmade';
+ protected string $name = 'starmade';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "StarMade";
+ protected string $name_long = "StarMade";
/**
* The client join link
- *
- * @type string
*/
- protected $join_link = null;
+ protected ?string $join_link = null;
/**
* Normalize settings for this protocol
- *
- * @type array
*/
- protected $normalize = [
+ protected array $normalize = [
// General
'general' => [
// target => source
@@ -99,10 +85,10 @@ class Starmade extends Protocol
/**
* Process the response for the StarMade server
*
- * @return array
+ * @return mixed
* @throws \GameQ\Exception\Protocol
*/
- public function processResponse()
+ public function processResponse(): mixed
{
// Implode the packets, not sure if there is any split logic for multiple packets
@@ -150,15 +136,12 @@ public function processResponse()
/**
* Parse the server response parameters
- *
- * @SuppressWarnings(PHPMD.CyclomaticComplexity)
- *
- * @param \GameQ\Buffer $buffer
+
*
* @return array
* @throws \GameQ\Exception\Protocol
*/
- protected function parseServerParameters(Buffer &$buffer)
+ protected function parseServerParameters(Buffer $buffer)
{
// Init the parsed data array
diff --git a/src/GameQ/Protocols/Stormworks.php b/src/GameQ/Protocols/Stormworks.php
index 735b5776..9885665e 100644
--- a/src/GameQ/Protocols/Stormworks.php
+++ b/src/GameQ/Protocols/Stormworks.php
@@ -29,22 +29,16 @@ class Stormworks extends Source
{
/**
* Stormworks protocol class
- *
- * @type string
*/
- protected $name = 'stormworks';
+ protected string $name = 'stormworks';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Stormworks";
+ protected string $name_long = "Stormworks";
/**
* query_port = client_port + 1
- *
- * @type int
*/
- protected $port_diff = 1;
+ protected int $port_diff = 1;
}
diff --git a/src/GameQ/Protocols/Swat4.php b/src/GameQ/Protocols/Swat4.php
index 7b8e1200..2de57e4f 100644
--- a/src/GameQ/Protocols/Swat4.php
+++ b/src/GameQ/Protocols/Swat4.php
@@ -29,22 +29,16 @@ class Swat4 extends Gamespy2
{
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'swat4';
+ protected string $name = 'swat4';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "SWAT 4";
+ protected string $name_long = "SWAT 4";
/**
* query_port = client_port + 1
- *
- * @type int
*/
- protected $port_diff = 1;
+ protected int $port_diff = 1;
}
diff --git a/src/GameQ/Protocols/Teamspeak2.php b/src/GameQ/Protocols/Teamspeak2.php
index df0d59aa..1787e521 100644
--- a/src/GameQ/Protocols/Teamspeak2.php
+++ b/src/GameQ/Protocols/Teamspeak2.php
@@ -40,10 +40,8 @@ class Teamspeak2 extends Protocol
/**
* Array of packets we want to look up.
* Each key should correspond to a defined method in this or a parent class
- *
- * @type array
*/
- protected $packets = [
+ protected array $packets = [
self::PACKET_DETAILS => "sel %d\x0asi\x0a",
self::PACKET_CHANNELS => "sel %d\x0acl\x0a",
self::PACKET_PLAYERS => "sel %d\x0apl\x0a",
@@ -51,45 +49,33 @@ class Teamspeak2 extends Protocol
/**
* The transport mode for this protocol is TCP
- *
- * @type string
- */
- protected $transport = self::TRANSPORT_TCP;
+ */
+ protected string $transport = self::TRANSPORT_TCP;
/**
* The query protocol used to make the call
- *
- * @type string
*/
- protected $protocol = 'teamspeak2';
+ protected string $protocol = 'teamspeak2';
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'teamspeak2';
+ protected string $name = 'teamspeak2';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Teamspeak 2";
+ protected string $name_long = "Teamspeak 2";
/**
* The client join link
- *
- * @type string
*/
- protected $join_link = "teamspeak://%s:%d/";
+ protected ?string $join_link = "teamspeak://%s:%d/";
/**
* Normalize settings for this protocol
- *
- * @type array
*/
- protected $normalize = [
+ protected array $normalize = [
// General
'general' => [
'dedicated' => 'dedicated',
@@ -114,11 +100,9 @@ class Teamspeak2 extends Protocol
/**
* Before we send off the queries we need to update the packets
*
- * @param \GameQ\Server $server
- *
* @throws \GameQ\Exception\Protocol
*/
- public function beforeSend(Server $server)
+ public function beforeSend(Server $server): void
{
// Check to make sure we have a query_port because it is required
@@ -138,10 +122,10 @@ public function beforeSend(Server $server)
/**
* Process the response
*
- * @return array
+ * @return mixed
* @throws \GameQ\Exception\Protocol
*/
- public function processResponse()
+ public function processResponse(): mixed
{
// Make a new buffer out of all of the packets
@@ -149,11 +133,11 @@ public function processResponse()
// Check the header [TS]
if (($header = trim($buffer->readString("\n"))) !== '[TS]') {
- throw new Exception(__METHOD__ . " Expected header '{$header}' does not match expected '[TS]'.");
+ throw new Exception(__METHOD__ . " Expected header '$header' does not match expected '[TS]'.");
}
// Split this buffer as the data blocks are bound by "OK" and drop any empty values
- $sections = array_filter(explode("OK", $buffer->getBuffer()), function ($value) {
+ $sections = array_filter(explode("OK", $buffer->getBuffer()), static function ($value) {
$value = trim($value);
@@ -172,19 +156,19 @@ public function processResponse()
$check = substr($section, 0, 7);
// Offload to the proper method
- if ($check == 'server_') {
+ if ($check === 'server_') {
// Server settings and info
$this->processDetails($section, $result);
- } elseif ($check == "id\tcode") {
+ } elseif ($check === "id\tcode") {
// Channel info
$this->processChannels($section, $result);
- } elseif ($check == "p_id\tc_") {
+ } elseif ($check === "p_id\tc_") {
// Player info
$this->processPlayers($section, $result);
}
}
- unset($buffer, $sections, $section, $check);
+ unset($buffer, $sections, $check);
return $result->fetch();
}
@@ -196,13 +180,9 @@ public function processResponse()
/**
* Handles processing the details data into a usable format
- *
- * @param string $data
- * @param \GameQ\Result $result
*/
- protected function processDetails($data, Result &$result)
+ protected function processDetails(string $data, Result $result)
{
-
// Create a buffer
$buffer = new Buffer($data);
@@ -218,19 +198,16 @@ protected function processDetails($data, Result &$result)
list($key, $value) = explode('=', $row, 2);
// Add this to the result
- $result->add($key, utf8_encode($value));
+ $result->add($key, $this->convertToUtf8($value));
}
- unset($data, $buffer, $row, $key, $value);
+ unset($buffer, $row, $key, $value);
}
/**
* Process the channel listing
- *
- * @param string $data
- * @param \GameQ\Result $result
*/
- protected function processChannels($data, Result &$result)
+ protected function processChannels(string $data, Result $result)
{
// Create a buffer
@@ -249,20 +226,17 @@ protected function processChannels($data, Result &$result)
foreach ($data as $key => $value) {
// Now add the data to the result
- $result->addTeam($key, utf8_encode($value));
+ $result->addTeam($key, $this->convertToUtf8($value));
}
}
- unset($data, $buffer, $row, $columns, $key, $value);
+ unset($buffer, $row, $columns, $key, $value);
}
/**
* Process the user listing
- *
- * @param string $data
- * @param \GameQ\Result $result
*/
- protected function processPlayers($data, Result &$result)
+ protected function processPlayers(string $data, Result $result)
{
// Create a buffer
@@ -281,10 +255,10 @@ protected function processPlayers($data, Result &$result)
foreach ($data as $key => $value) {
// Now add the data to the result
- $result->addPlayer($key, utf8_encode($value));
+ $result->addPlayer($key, $this->convertToUtf8($value));
}
}
- unset($data, $buffer, $row, $columns, $key, $value);
+ unset($buffer, $row, $columns, $key, $value);
}
}
diff --git a/src/GameQ/Protocols/Teamspeak3.php b/src/GameQ/Protocols/Teamspeak3.php
index c66f6a44..e26ace52 100644
--- a/src/GameQ/Protocols/Teamspeak3.php
+++ b/src/GameQ/Protocols/Teamspeak3.php
@@ -40,10 +40,8 @@ class Teamspeak3 extends Protocol
/**
* Array of packets we want to look up.
* Each key should correspond to a defined method in this or a parent class
- *
- * @type array
*/
- protected $packets = [
+ protected array $packets = [
self::PACKET_DETAILS => "use port=%d\x0Aserverinfo\x0A",
self::PACKET_PLAYERS => "use port=%d\x0Aclientlist\x0A",
self::PACKET_CHANNELS => "use port=%d\x0Achannellist -topic\x0A",
@@ -51,45 +49,33 @@ class Teamspeak3 extends Protocol
/**
* The transport mode for this protocol is TCP
- *
- * @type string
- */
- protected $transport = self::TRANSPORT_TCP;
+ */
+ protected string $transport = self::TRANSPORT_TCP;
/**
* The query protocol used to make the call
- *
- * @type string
*/
- protected $protocol = 'teamspeak3';
+ protected string $protocol = 'teamspeak3';
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'teamspeak3';
+ protected string $name = 'teamspeak3';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Teamspeak 3";
+ protected string $name_long = "Teamspeak 3";
/**
* The client join link
- *
- * @type string
*/
- protected $join_link = "ts3server://%s?port=%d";
+ protected ?string $join_link = "ts3server://%s?port=%d";
/**
* Normalize settings for this protocol
- *
- * @type array
*/
- protected $normalize = [
+ protected array $normalize = [
// General
'general' => [
'dedicated' => 'dedicated',
@@ -114,11 +100,9 @@ class Teamspeak3 extends Protocol
/**
* Before we send off the queries we need to update the packets
*
- * @param \GameQ\Server $server
- *
* @throws \GameQ\Exception\Protocol
*/
- public function beforeSend(Server $server)
+ public function beforeSend(Server $server): void
{
// Check to make sure we have a query_port because it is required
@@ -138,10 +122,10 @@ public function beforeSend(Server $server)
/**
* Process the response
*
- * @return array
+ * @return mixed
* @throws \GameQ\Exception\Protocol
*/
- public function processResponse()
+ public function processResponse(): mixed
{
// Make a new buffer out of all of the packets
@@ -149,7 +133,7 @@ public function processResponse()
// Check the header TS3
if (($header = trim($buffer->readString("\n"))) !== 'TS3') {
- throw new Exception(__METHOD__ . " Expected header '{$header}' does not match expected 'TS3'.");
+ throw new Exception(__METHOD__ . " Expected header '$header' does not match expected 'TS3'.");
}
// Convert all the escaped characters
@@ -166,12 +150,12 @@ public function processResponse()
);
// Explode the sections and filter to remove empty, junk ones
- $sections = array_filter(explode("\n", $raw), function ($value) {
+ $sections = array_filter(explode("\n", $raw), static function ($value) {
$value = trim($value);
// Not empty string or a message response for "error id=\d"
- return !empty($value) && substr($value, 0, 5) !== 'error';
+ return !empty($value) && !str_starts_with($value, 'error');
});
// Trim up the values to remove extra whitespace
@@ -186,19 +170,19 @@ public function processResponse()
$check = substr(trim($section), 0, 4);
// Use the first part of the response to figure out where we need to go
- if ($check == 'virt') {
+ if ($check === 'virt') {
// Server info
$this->processDetails($section, $result);
- } elseif ($check == 'cid=') {
+ } elseif ($check === 'cid=') {
// Channels
$this->processChannels($section, $result);
- } elseif ($check == 'clid') {
+ } elseif ($check === 'clid') {
// Clients (players)
$this->processPlayers($section, $result);
}
}
- unset($buffer, $sections, $section, $check);
+ unset($buffer, $sections, $check);
return $result->fetch();
}
@@ -231,7 +215,7 @@ protected function processProperties($data)
list($key, $value) = array_pad(explode('=', $item, 2), 2, '');
// Convert spaces and other character changes
- $properties[$key] = utf8_encode(str_replace(
+ $properties[$key] = $this->convertToUtf8(str_replace(
[
'\\s', // Translate spaces
],
@@ -247,11 +231,8 @@ protected function processProperties($data)
/**
* Handles processing the details data into a usable format
- *
- * @param string $data
- * @param \GameQ\Result $result
*/
- protected function processDetails($data, Result &$result)
+ protected function processDetails(string $data, Result $result)
{
// Offload the parsing for these values
@@ -271,16 +252,13 @@ protected function processDetails($data, Result &$result)
($properties['virtualserver_clientsonline'] - $properties['virtualserver_queryclientsonline'])
);
- unset($data, $properties, $key, $value);
+ unset($properties, $key, $value);
}
/**
* Process the channel listing
- *
- * @param string $data
- * @param \GameQ\Result $result
*/
- protected function processChannels($data, Result &$result)
+ protected function processChannels(string $data, Result $result)
{
// We need to split the data at the pipe
@@ -297,16 +275,13 @@ protected function processChannels($data, Result &$result)
}
}
- unset($data, $channel, $channels, $properties, $key, $value);
+ unset($channels, $properties, $key);
}
/**
* Process the user listing
- *
- * @param string $data
- * @param \GameQ\Result $result
*/
- protected function processPlayers($data, Result &$result)
+ protected function processPlayers(string $data, Result $result)
{
// We need to split the data at the pipe
@@ -323,6 +298,6 @@ protected function processPlayers($data, Result &$result)
}
}
- unset($data, $player, $players, $properties, $key, $value);
+ unset($players, $properties, $key);
}
}
diff --git a/src/GameQ/Protocols/Teeworlds.php b/src/GameQ/Protocols/Teeworlds.php
index 1bdaa472..c512ca08 100644
--- a/src/GameQ/Protocols/Teeworlds.php
+++ b/src/GameQ/Protocols/Teeworlds.php
@@ -37,10 +37,8 @@ class Teeworlds extends Protocol
/**
* Array of packets we want to look up.
* Each key should correspond to a defined method in this or a parent class
- *
- * @type array
*/
- protected $packets = [
+ protected array $packets = [
self::PACKET_ALL => "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x67\x69\x65\x33\x05",
// 0.5 Packet (not compatible, maybe some wants to implement "Teeworldsold")
//self::PACKET_STATUS => "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFFgief",
@@ -49,46 +47,35 @@ class Teeworlds extends Protocol
/**
* Use the response flag to figure out what method to run
*
- * @type array
*/
- protected $responses = [
+ protected array $responses = [
"\xff\xff\xff\xff\xff\xff\xff\xff\xff\xffinf35" => "processAll",
];
/**
* The query protocol used to make the call
- *
- * @type string
*/
- protected $protocol = 'teeworlds';
+ protected string $protocol = 'teeworlds';
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'teeworlds';
+ protected string $name = 'teeworlds';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Teeworlds Server";
+ protected string $name_long = "Teeworlds Server";
/**
* The client join link
- *
- * @type string
*/
- protected $join_link = "steam://connect/%s:%d/";
+ protected ?string $join_link = "steam://connect/%s:%d/";
/**
* Normalize settings for this protocol
- *
- * @type array
*/
- protected $normalize = [
+ protected array $normalize = [
// General
'general' => [
// target => source
@@ -107,10 +94,10 @@ class Teeworlds extends Protocol
/**
* Process the response
*
- * @return array
+ * @return mixed
* @throws Exception
*/
- public function processResponse()
+ public function processResponse(): mixed
{
// Holds the results
$results = [];
@@ -143,8 +130,6 @@ public function processResponse()
/**
* Handle processing all of the data returned
*
- * @param Buffer $buffer
- *
* @return array
*/
protected function processAll(Buffer $buffer)
@@ -174,8 +159,6 @@ protected function processAll(Buffer $buffer)
$result->addPlayer('team', $buffer->readString());
}
- unset($buffer);
-
return $result->fetch();
}
}
diff --git a/src/GameQ/Protocols/Terraria.php b/src/GameQ/Protocols/Terraria.php
index d9455ef5..717de08d 100644
--- a/src/GameQ/Protocols/Terraria.php
+++ b/src/GameQ/Protocols/Terraria.php
@@ -30,30 +30,22 @@ class Terraria extends Tshock
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'terraria';
+ protected string $name = 'terraria';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Terraria";
+ protected string $name_long = "Terraria";
/**
* query_port = client_port + 101
* 7878 = 7777 + 101
- *
- * @type int
*/
- protected $port_diff = 101;
+ protected int $port_diff = 101;
/**
* The client join link
- *
- * @type string
*/
- protected $join_link = "steam://connect/%s:%d/";
+ protected ?string $join_link = "steam://connect/%s:%d/";
}
diff --git a/src/GameQ/Protocols/Tf2.php b/src/GameQ/Protocols/Tf2.php
index e08411b7..15fd864b 100644
--- a/src/GameQ/Protocols/Tf2.php
+++ b/src/GameQ/Protocols/Tf2.php
@@ -28,15 +28,11 @@ class Tf2 extends Source
{
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'tf2';
+ protected string $name = 'tf2';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Team Fortress 2";
+ protected string $name_long = "Team Fortress 2";
}
diff --git a/src/GameQ/Protocols/Theforrest.php b/src/GameQ/Protocols/Theforrest.php
index 975c3f6f..6b591020 100644
--- a/src/GameQ/Protocols/Theforrest.php
+++ b/src/GameQ/Protocols/Theforrest.php
@@ -29,22 +29,16 @@ class Theforrest extends Source
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'theforrest';
+ protected string $name = 'theforrest';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "The Forrest";
+ protected string $name_long = "The Forrest";
/**
* query_port = client_port + 1
- *
- * @type int
*/
- protected $port_diff = 1;
+ protected int $port_diff = 1;
}
diff --git a/src/GameQ/Protocols/Tibia.php b/src/GameQ/Protocols/Tibia.php
index 8702bfa3..462a4440 100644
--- a/src/GameQ/Protocols/Tibia.php
+++ b/src/GameQ/Protocols/Tibia.php
@@ -19,7 +19,6 @@
namespace GameQ\Protocols;
use GameQ\Protocol;
-use GameQ\Buffer;
use GameQ\Result;
use GameQ\Exception\Protocol as Exception;
@@ -38,54 +37,40 @@ class Tibia extends Protocol
/**
* Array of packets we want to query.
- *
- * @type array
*/
- protected $packets = [
+ protected array $packets = [
self::PACKET_STATUS => "\x06\x00\xFF\xFF\x69\x6E\x66\x6F",
];
/**
* The transport mode for this protocol is TCP
- *
- * @type string
- */
- protected $transport = self::TRANSPORT_TCP;
+ */
+ protected string $transport = self::TRANSPORT_TCP;
/**
* The query protocol used to make the call
- *
- * @type string
*/
- protected $protocol = 'tibia';
+ protected string $protocol = 'tibia';
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'tibia';
+ protected string $name = 'tibia';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Tibia";
+ protected string $name_long = "Tibia";
/**
* The client join link
- *
- * @type string
*/
- protected $join_link = "otserv://%s/%d/";
+ protected ?string $join_link = "otserv://%s/%d/";
/**
* Normalize settings for this protocol
- *
- * @type array
*/
- protected $normalize = [
+ protected array $normalize = [
// General
'general' => [
// target => source
@@ -102,10 +87,10 @@ class Tibia extends Protocol
/**
* Process the response for the Tibia server
*
- * @return array
+ * @return mixed
* @throws \GameQ\Exception\Protocol
*/
- public function processResponse()
+ public function processResponse(): mixed
{
// Merge the response packets
$xmlString = implode('', $this->packets_response);
@@ -124,7 +109,7 @@ public function processResponse()
// Iterate over the info
foreach (['serverinfo', 'owner', 'map', 'npcs', 'monsters', 'players'] as $property) {
foreach ($xmlDoc->{$property}->attributes() as $key => $value) {
- if (!in_array($property, ['serverinfo'])) {
+ if ($property !== 'serverinfo') {
$key = $property . '_' . $key;
}
@@ -135,7 +120,7 @@ public function processResponse()
$result->add("motd", (string)$xmlDoc->motd);
- unset($xmlDoc, $xmlDoc);
+ unset($xmlDoc);
return $result->fetch();
}
diff --git a/src/GameQ/Protocols/Tshock.php b/src/GameQ/Protocols/Tshock.php
index 551a09e4..684fcdcc 100644
--- a/src/GameQ/Protocols/Tshock.php
+++ b/src/GameQ/Protocols/Tshock.php
@@ -40,37 +40,32 @@ class Tshock extends Http
*
* @var array
*/
- protected $packets = [
+ protected array $packets = [
self::PACKET_STATUS => "GET /v2/server/status?players=true&rules=true HTTP/1.0\r\nAccept: */*\r\n\r\n",
];
/**
* The protocol being used
*
- * @var string
*/
- protected $protocol = 'tshock';
+ protected string $protocol = 'tshock';
/**
* String name of this protocol class
*
- * @var string
*/
- protected $name = 'tshock';
+ protected string $name = 'tshock';
/**
* Longer string name of this protocol class
*
- * @var string
*/
- protected $name_long = "Tshock";
+ protected string $name_long = "Tshock";
/**
* Normalize some items
- *
- * @var array
*/
- protected $normalize = [
+ protected array $normalize = [
// General
'general' => [
// target => source
@@ -91,10 +86,10 @@ class Tshock extends Http
/**
* Process the response
*
- * @return array
+ * @return mixed
* @throws Exception
*/
- public function processResponse()
+ public function processResponse(): mixed
{
if (empty($this->packets_response)) {
return [];
@@ -104,13 +99,18 @@ public function processResponse()
preg_match('/\{(.*)\}/ms', implode('', $this->packets_response), $matches);
// Return should be JSON, let's validate
- if (!isset($matches[0]) || ($json = json_decode($matches[0])) === null) {
+ if (!isset($matches[0]) || ($json = json_decode(
+ $matches[0],
+ false,
+ 512,
+ JSON_THROW_ON_ERROR
+ )) === null) {
throw new Exception("JSON response from Tshock protocol is invalid.");
}
// Check the status response
- if ($json->status != 200) {
- throw new Exception("JSON status from Tshock protocol response was '{$json->status}', expected '200'.");
+ if ($json->status !== '200') {
+ throw new Exception("JSON status from Tshock protocol response was '$json->status', expected '200'.");
}
$result = new Result();
diff --git a/src/GameQ/Protocols/Unreal2.php b/src/GameQ/Protocols/Unreal2.php
index 0ef06757..4642ac3a 100644
--- a/src/GameQ/Protocols/Unreal2.php
+++ b/src/GameQ/Protocols/Unreal2.php
@@ -34,10 +34,8 @@ class Unreal2 extends Protocol
/**
* Array of packets we want to look up.
* Each key should correspond to a defined method in this or a parent class
- *
- * @type array
*/
- protected $packets = [
+ protected array $packets = [
self::PACKET_DETAILS => "\x79\x00\x00\x00\x00",
self::PACKET_RULES => "\x79\x00\x00\x00\x01",
self::PACKET_PLAYERS => "\x79\x00\x00\x00\x02",
@@ -46,9 +44,8 @@ class Unreal2 extends Protocol
/**
* Use the response flag to figure out what method to run
*
- * @type array
*/
- protected $responses = [
+ protected array $responses = [
"\x80\x00\x00\x00\x00" => "processDetails", // 0
"\x80\x00\x00\x00\x01" => "processRules", // 1
"\x80\x00\x00\x00\x02" => "processPlayers", // 2
@@ -56,31 +53,23 @@ class Unreal2 extends Protocol
/**
* The query protocol used to make the call
- *
- * @type string
*/
- protected $protocol = 'unreal2';
+ protected string $protocol = 'unreal2';
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'unreal2';
+ protected string $name = 'unreal2';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Unreal 2";
+ protected string $name_long = "Unreal 2";
/**
* Normalize settings for this protocol
- *
- * @type array
*/
- protected $normalize = [
+ protected array $normalize = [
// General
'general' => [
// target => source
@@ -102,10 +91,10 @@ class Unreal2 extends Protocol
/**
* Process the response
*
- * @return array
+ * @return mixed
* @throws \GameQ\Exception\Protocol
*/
- public function processResponse()
+ public function processResponse(): mixed
{
// Will hold the packets after sorting
@@ -151,10 +140,9 @@ public function processResponse()
/**
* Handles processing the details data into a usable format
+
*
- * @param \GameQ\Buffer $buffer
- *
- * @return mixed
+ * @return array
* @throws \GameQ\Exception\Protocol
*/
protected function processDetails(Buffer $buffer)
@@ -167,24 +155,21 @@ protected function processDetails(Buffer $buffer)
$result->add('serverip', $buffer->readPascalString(1)); // empty
$result->add('gameport', $buffer->readInt32());
$result->add('queryport', $buffer->readInt32()); // 0
- $result->add('servername', utf8_encode($buffer->readPascalString(1)));
- $result->add('mapname', utf8_encode($buffer->readPascalString(1)));
+ $result->add('servername', $this->convertToUtf8($buffer->readPascalString(1)));
+ $result->add('mapname', $this->convertToUtf8($buffer->readPascalString(1)));
$result->add('gametype', $buffer->readPascalString(1));
$result->add('numplayers', $buffer->readInt32());
$result->add('maxplayers', $buffer->readInt32());
$result->add('ping', $buffer->readInt32()); // 0
- unset($buffer);
-
return $result->fetch();
}
/**
* Handles processing the player data into a usable format
+
*
- * @param \GameQ\Buffer $buffer
- *
- * @return mixed
+ * @return array
*/
protected function processPlayers(Buffer $buffer)
{
@@ -198,7 +183,7 @@ protected function processPlayers(Buffer $buffer)
if (($id = $buffer->readInt32()) !== 0) {
// Add the results
$result->addPlayer('id', $id);
- $result->addPlayer('name', utf8_encode($buffer->readPascalString(1)));
+ $result->addPlayer('name', $this->convertToUtf8($buffer->readPascalString(1)));
$result->addPlayer('ping', $buffer->readInt32());
$result->addPlayer('score', $buffer->readInt32());
@@ -207,7 +192,7 @@ protected function processPlayers(Buffer $buffer)
}
}
- unset($buffer, $id);
+ unset($id);
return $result->fetch();
}
@@ -215,9 +200,7 @@ protected function processPlayers(Buffer $buffer)
/**
* Handles processing the rules data into a usable format
*
- * @param \GameQ\Buffer $buffer
- *
- * @return mixed
+ * @return array
*/
protected function processRules(Buffer $buffer)
{
@@ -236,11 +219,9 @@ protected function processRules(Buffer $buffer)
$key .= ++$inc;
}
- $result->add(strtolower($key), utf8_encode($buffer->readPascalString(1)));
+ $result->add(strtolower($key), $this->convertToUtf8($buffer->readPascalString(1)));
}
- unset($buffer);
-
return $result->fetch();
}
}
diff --git a/src/GameQ/Protocols/Unturned.php b/src/GameQ/Protocols/Unturned.php
index 4829b37a..d7de41a2 100644
--- a/src/GameQ/Protocols/Unturned.php
+++ b/src/GameQ/Protocols/Unturned.php
@@ -28,22 +28,16 @@ class Unturned extends Source
{
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'unturned';
+ protected string $name = 'unturned';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Unturned";
+ protected string $name_long = "Unturned";
/**
* query_port = client_port + 1
- *
- * @type int
*/
- protected $port_diff = 1;
+ protected int $port_diff = 1;
}
diff --git a/src/GameQ/Protocols/Urbanterror.php b/src/GameQ/Protocols/Urbanterror.php
index 682f91e6..1400fc3a 100644
--- a/src/GameQ/Protocols/Urbanterror.php
+++ b/src/GameQ/Protocols/Urbanterror.php
@@ -28,22 +28,16 @@ class Urbanterror extends Quake3
{
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'urbanterror';
+ protected string $name = 'urbanterror';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Urban Terror";
+ protected string $name_long = "Urban Terror";
/**
* The client join link
- *
- * @type string
*/
- protected $join_link = "urt://%s:%d/";
+ protected ?string $join_link = "urt://%s:%d/";
}
diff --git a/src/GameQ/Protocols/Ut.php b/src/GameQ/Protocols/Ut.php
index 75722ce1..0f385e79 100644
--- a/src/GameQ/Protocols/Ut.php
+++ b/src/GameQ/Protocols/Ut.php
@@ -28,31 +28,23 @@ class Ut extends Gamespy
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'ut';
+ protected string $name = 'ut';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Unreal Tournament";
+ protected string $name_long = "Unreal Tournament";
/**
* query_port = client_port + 1
- *
- * @type int
*/
- protected $port_diff = 1;
+ protected int $port_diff = 1;
/**
* Normalize settings for this protocol
- *
- * @type array
*/
- protected $normalize = [
+ protected array $normalize = [
// General
'general' => [
// target => source
diff --git a/src/GameQ/Protocols/Ut2004.php b/src/GameQ/Protocols/Ut2004.php
index 953089f9..b87bec36 100644
--- a/src/GameQ/Protocols/Ut2004.php
+++ b/src/GameQ/Protocols/Ut2004.php
@@ -28,15 +28,11 @@ class Ut2004 extends Unreal2
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'ut2004';
+ protected string $name = 'ut2004';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Unreal Tournament 2004";
+ protected string $name_long = "Unreal Tournament 2004";
}
diff --git a/src/GameQ/Protocols/Ut3.php b/src/GameQ/Protocols/Ut3.php
index b55cc340..0e174fb6 100644
--- a/src/GameQ/Protocols/Ut3.php
+++ b/src/GameQ/Protocols/Ut3.php
@@ -32,24 +32,18 @@ class Ut3 extends Gamespy3
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'ut3';
+ protected string $name = 'ut3';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Unreal Tournament 3";
+ protected string $name_long = "Unreal Tournament 3";
/**
* Normalize settings for this protocol
- *
- * @type array
*/
- protected $normalize = [
+ protected array $normalize = [
// General
'general' => [
'dedicated' => 'bIsDedicated',
@@ -61,13 +55,12 @@ class Ut3 extends Gamespy3
/**
* Overload the response process so we can make some changes
*
- * @return array
+ * @return mixed
*/
- public function processResponse()
+ public function processResponse(): mixed
{
// Grab the result from the parent
- /** @type array $result */
$result = parent::processResponse();
// Move some stuff around
@@ -102,12 +95,8 @@ public function processResponse()
/**
* Dirty hack to rename result entries into something more useful
- *
- * @param array $result
- * @param string $old
- * @param string $new
*/
- protected function renameResult(array &$result, $old, $new)
+ protected function renameResult(array &$result, string $old, string $new): void
{
// Check to see if the old item is there
@@ -119,11 +108,8 @@ protected function renameResult(array &$result, $old, $new)
/**
* Dirty hack to delete result items
- *
- * @param array $result
- * @param array $array
*/
- protected function deleteResult(array &$result, array $array)
+ protected function deleteResult(array &$result, array $array): void
{
foreach ($array as $key) {
diff --git a/src/GameQ/Protocols/Valheim.php b/src/GameQ/Protocols/Valheim.php
index 18469229..2679ea6a 100644
--- a/src/GameQ/Protocols/Valheim.php
+++ b/src/GameQ/Protocols/Valheim.php
@@ -27,22 +27,16 @@ class Valheim extends Source
{
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'valheim';
+ protected string $name = 'valheim';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Valheim";
+ protected string $name_long = "Valheim";
/**
* query_port = client_port + 1
- *
- * @type int
*/
- protected $port_diff = 1;
+ protected int $port_diff = 1;
}
diff --git a/src/GameQ/Protocols/Ventrilo.php b/src/GameQ/Protocols/Ventrilo.php
index 6986bedc..7f112a68 100644
--- a/src/GameQ/Protocols/Ventrilo.php
+++ b/src/GameQ/Protocols/Ventrilo.php
@@ -40,48 +40,36 @@ class Ventrilo extends Protocol
/**
* Array of packets we want to look up.
* Each key should correspond to a defined method in this or a parent class
- *
- * @type array
*/
- protected $packets = [
+ protected array $packets = [
self::PACKET_ALL =>
"V\xc8\xf4\xf9`\xa2\x1e\xa5M\xfb\x03\xccQN\xa1\x10\x95\xaf\xb2g\x17g\x812\xfbW\xfd\x8e\xd2\x22r\x034z\xbb\x98",
];
/**
* The query protocol used to make the call
- *
- * @type string
*/
- protected $protocol = 'ventrilo';
+ protected string $protocol = 'ventrilo';
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'ventrilo';
+ protected string $name = 'ventrilo';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Ventrilo";
+ protected string $name_long = "Ventrilo";
/**
* The client join link
- *
- * @type string
*/
- protected $join_link = "ventrilo://%s:%d/";
+ protected ?string $join_link = "ventrilo://%s:%d/";
/**
* Normalize settings for this protocol
- *
- * @type array
*/
- protected $normalize = [
+ protected array $normalize = [
// General
'general' => [
'dedicated' => 'dedicated',
@@ -633,10 +621,10 @@ class Ventrilo extends Protocol
/**
* Process the response
*
- * @return array
+ * @return mixed
* @throws \GameQ\Exception\Protocol
*/
- public function processResponse()
+ public function processResponse(): mixed
{
// We need to decrypt the packets
@@ -645,7 +633,7 @@ public function processResponse()
// Now let us convert special characters from hex to ascii all at once
$decrypted = preg_replace_callback(
'|%([0-9A-F]{2})|',
- function ($matches) {
+ static function ($matches) {
// Pack this into ascii
return pack('H*', $matches[1]);
@@ -672,7 +660,7 @@ function ($matches) {
$line = trim($line);
// We dont have anything in this line
- if (strlen($line) == 0) {
+ if ($line === '') {
continue;
}
@@ -723,7 +711,7 @@ function ($matches) {
// By default we just add they key as an item
default:
- $result->add($key, utf8_encode($value));
+ $result->add($key, $this->convertToUtf8($value));
break;
}
}
@@ -741,10 +729,6 @@ function ($matches) {
/**
* Decrypt the incoming packets
*
- * @codeCoverageIgnore
- *
- * @param array $packets
- *
* @return string
* @throws \GameQ\Exception\Protocol
*/
@@ -810,21 +794,23 @@ protected function decryptPackets(array $packets = [])
$a1 = $header_items['datakey'] & 0xFF;
$a2 = $header_items['datakey'] >> 8;
- if ($a1 == 0) {
+ if ($a1 === 0) {
throw new Exception(__METHOD__ . ": Data key is invalid");
}
$chars = unpack("C*", substr($packet, 20));
- $data = "";
- $characterCount = count($chars);
-
- for ($index = 1; $index <= $characterCount; $index++) {
- $chars[$index] -= ($table[$a2] + (($index - 1) % 72)) & 0xFF;
- $a2 = ($a2 + $a1) & 0xFF;
- $data .= chr($chars[$index]);
+ if ($chars !== false) {
+ $data = "";
+ $characterCount = count($chars);
+
+ for ($index = 1; $index <= $characterCount; $index++) {
+ $chars[$index] -= ($table[$a2] + (($index - 1) % 72)) & 0xFF;
+ $a2 = ($a2 + $a1) & 0xFF;
+ $data .= chr($chars[$index]);
+ }
+ //@todo: Check CRC ???
+ $decrypted[$header_items['pck']] = $data;
}
- //@todo: Check CRC ???
- $decrypted[$header_items['pck']] = $data;
}
// Return the decrypted packets as one string
@@ -833,12 +819,8 @@ protected function decryptPackets(array $packets = [])
/**
* Process the channel listing
- *
- * @param string $data
- * @param int $fieldCount
- * @param \GameQ\Result $result
*/
- protected function processChannel($data, $fieldCount, Result &$result)
+ protected function processChannel(string $data, int $fieldCount, Result $result)
{
// Split the items on the comma
@@ -849,18 +831,14 @@ protected function processChannel($data, $fieldCount, Result &$result)
// Split the key=value pair
list($key, $value) = explode("=", $item, 2);
- $result->addTeam(strtolower($key), utf8_encode($value));
+ $result->addTeam(strtolower($key), $this->convertToUtf8($value));
}
}
/**
* Process the user listing
- *
- * @param string $data
- * @param int $fieldCount
- * @param \GameQ\Result $result
*/
- protected function processPlayer($data, $fieldCount, Result &$result)
+ protected function processPlayer(string $data, int $fieldCount, Result $result)
{
// Split the items on the comma
@@ -871,7 +849,7 @@ protected function processPlayer($data, $fieldCount, Result &$result)
// Split the key=value pair
list($key, $value) = explode("=", $item, 2);
- $result->addPlayer(strtolower($key), utf8_encode($value));
+ $result->addPlayer(strtolower($key), $this->convertToUtf8($value));
}
}
}
diff --git a/src/GameQ/Protocols/Vrising.php b/src/GameQ/Protocols/Vrising.php
index 08549469..8c06de27 100644
--- a/src/GameQ/Protocols/Vrising.php
+++ b/src/GameQ/Protocols/Vrising.php
@@ -27,22 +27,16 @@ class Vrising extends Source
{
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'vrising';
+ protected string $name = 'vrising';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "V Rising";
+ protected string $name_long = "V Rising";
/**
* query_port = client_port + 1
- *
- * @type int
*/
- protected $port_diff = 1;
+ protected int $port_diff = 1;
}
diff --git a/src/GameQ/Protocols/Warsow.php b/src/GameQ/Protocols/Warsow.php
index f1d629a9..7ed1ad0a 100644
--- a/src/GameQ/Protocols/Warsow.php
+++ b/src/GameQ/Protocols/Warsow.php
@@ -31,30 +31,22 @@ class Warsow extends Quake3
{
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'warsow';
+ protected string $name = 'warsow';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Warsow";
+ protected string $name_long = "Warsow";
/**
* The client join link
- *
- * @type string
*/
- protected $join_link = "warsow://%s:%d/";
+ protected ?string $join_link = "warsow://%s:%d/";
/**
* Handle player info, different than quake3 base
*
- * @param Buffer $buffer
- *
* @return array
* @throws \GameQ\Exception\Protocol
*/
@@ -73,13 +65,13 @@ protected function processPlayers(Buffer $buffer)
$result->addPlayer('ping', $playerInfo->readString("\x20"));
// Skip first "
- $playerInfo->skip(1);
+ $playerInfo->skip();
// Add player name, encoded
- $result->addPlayer('name', utf8_encode(trim(($playerInfo->readString('"')))));
+ $result->addPlayer('name', $this->convertToUtf8(trim(($playerInfo->readString('"')))));
// Skip space
- $playerInfo->skip(1);
+ $playerInfo->skip();
// Add team
$result->addPlayer('team', $playerInfo->read());
@@ -88,9 +80,6 @@ protected function processPlayers(Buffer $buffer)
unset($playerInfo);
}
- // Clear
- unset($buffer);
-
return $result->fetch();
}
}
diff --git a/src/GameQ/Protocols/Won.php b/src/GameQ/Protocols/Won.php
index bef09841..a047648b 100644
--- a/src/GameQ/Protocols/Won.php
+++ b/src/GameQ/Protocols/Won.php
@@ -34,10 +34,8 @@ class Won extends Source
/**
* Array of packets we want to look up.
* Each key should correspond to a defined method in this or a parent class
- *
- * @type array
*/
- protected $packets = [
+ protected array $packets = [
self::PACKET_DETAILS => "\xFF\xFF\xFF\xFFdetails\x00",
self::PACKET_PLAYERS => "\xFF\xFF\xFF\xFFplayers",
self::PACKET_RULES => "\xFF\xFF\xFF\xFFrules",
@@ -45,22 +43,16 @@ class Won extends Source
/**
* The query protocol used to make the call
- *
- * @type string
*/
- protected $protocol = 'won';
+ protected string $protocol = 'won';
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'won';
+ protected string $name = 'won';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "World Opponent Network";
+ protected string $name_long = "World Opponent Network";
}
diff --git a/src/GameQ/Protocols/Wurm.php b/src/GameQ/Protocols/Wurm.php
index c5936522..424f400f 100644
--- a/src/GameQ/Protocols/Wurm.php
+++ b/src/GameQ/Protocols/Wurm.php
@@ -28,15 +28,11 @@ class Wurm extends Source
{
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'wurm';
+ protected string $name = 'wurm';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Wurm Unlimited";
+ protected string $name_long = "Wurm Unlimited";
}
diff --git a/src/GameQ/Protocols/Zomboid.php b/src/GameQ/Protocols/Zomboid.php
index 4733d97a..32a14ac0 100644
--- a/src/GameQ/Protocols/Zomboid.php
+++ b/src/GameQ/Protocols/Zomboid.php
@@ -28,15 +28,11 @@ class Zomboid extends Source
{
/**
* String name of this protocol class
- *
- * @type string
*/
- protected $name = 'zomboid';
+ protected string $name = 'zomboid';
/**
* Longer string name of this protocol class
- *
- * @type string
*/
- protected $name_long = "Project Zomboid";
+ protected string $name_long = "Project Zomboid";
}
diff --git a/src/GameQ/Query/Core.php b/src/GameQ/Query/Core.php
index fd1949da..9aac781f 100644
--- a/src/GameQ/Query/Core.php
+++ b/src/GameQ/Query/Core.php
@@ -31,159 +31,116 @@ abstract class Core
*
* @type null|resource
*/
- public $socket = null;
+ public $socket;
/**
* The transport type (udp, tcp, etc...)
* See http://php.net/manual/en/transports.php for the supported list
- *
- * @type string
- */
- protected $transport = null;
+ */
+ protected ?string $transport;
/**
* Connection IP address
- *
- * @type string
*/
- protected $ip = null;
+ protected ?string $ip = null;
/**
* Connection port
- *
- * @type int
*/
- protected $port = null;
+ protected ?int $port = null;
/**
* The time in seconds to wait before timing out while connecting to the socket
- *
- * @type int
*/
- protected $timeout = 3; // Seconds
+ protected int $timeout = 3; // Seconds
/**
* Socket is blocking?
- *
- * @type bool
*/
- protected $blocking = false;
+ protected bool $blocking = false;
/**
* Called when the class is cloned
*/
public function __clone()
{
-
// Reset the properties for this class when cloned
$this->reset();
}
/**
* Set the connection information for the socket
- *
- * @param string $transport
- * @param string $ip
- * @param int $port
- * @param int $timeout seconds
- * @param bool $blocking
*/
- public function set($transport, $ip, $port, $timeout = 3, $blocking = false)
+ public function set(?string $transport, string $ip, int $port, int $timeout = 3, bool $blocking = false): void
{
-
$this->transport = $transport;
-
$this->ip = $ip;
-
$this->port = $port;
-
$this->timeout = $timeout;
-
$this->blocking = $blocking;
}
/**
* Reset this instance's properties
*/
- public function reset()
+ public function reset(): void
{
-
$this->transport = null;
-
$this->ip = null;
-
$this->port = null;
-
$this->timeout = 3;
-
$this->blocking = false;
}
- public function getTransport()
+ public function getTransport(): ?string
{
return $this->transport;
}
- public function getIp()
+ public function getIp(): ?string
{
return $this->ip;
}
- public function getPort()
+ public function getPort(): ?int
{
return $this->port;
}
- public function getTimeout()
+ public function getTimeout(): int
{
return $this->timeout;
}
- public function getBlocking()
+ public function getBlocking(): bool
{
return $this->blocking;
}
/**
* Create a new socket
- *
- * @return void
*/
- abstract protected function create();
+ abstract protected function create(): void;
/**
* Get the socket
- *
- * @return mixed
*/
- abstract public function get();
+ abstract public function get(): mixed;
/**
* Write data to the socket
*
- * @param string $data
- *
* @return int The number of bytes written
*/
- abstract public function write($data);
+ abstract public function write(string|array $data): int;
/**
* Close the socket
- *
- * @return void
*/
- abstract public function close();
+ abstract public function close(): void;
/**
* Read the responses from the socket(s)
- *
- * @SuppressWarnings(PHPMD.UnusedFormalParameter)
- *
- * @param array $sockets
- * @param int $timeout
- * @param int $stream_timeout
- *
- * @return array
*/
- abstract public function getResponses(array $sockets, $timeout, $stream_timeout);
+ abstract public function getResponses(array $sockets, int $timeout, int $stream_timeout): array;
}
diff --git a/src/GameQ/Query/Native.php b/src/GameQ/Query/Native.php
index 24200b0c..e2c97893 100644
--- a/src/GameQ/Query/Native.php
+++ b/src/GameQ/Query/Native.php
@@ -30,10 +30,10 @@ class Native extends Core
/**
* Get the current socket or create one and return
*
- * @return resource|null
+ * @return mixed
* @throws \GameQ\Exception\Query
*/
- public function get()
+ public function get(): mixed
{
// No socket for this server, make one
@@ -47,12 +47,12 @@ public function get()
/**
* Write data to the socket
*
- * @param string $data
+ * @param string|array $data
*
* @return int The number of bytes written
* @throws \GameQ\Exception\Query
*/
- public function write($data)
+ public function write(string|array $data): int
{
try {
@@ -71,7 +71,7 @@ public function write($data)
/**
* Close the current socket
*/
- public function close()
+ public function close(): void
{
if ($this->socket) {
@@ -85,7 +85,7 @@ public function close()
*
* @throws \GameQ\Exception\Query
*/
- protected function create()
+ protected function create(): void
{
// Create the remote address
@@ -124,7 +124,7 @@ protected function create()
// Something bad happened, throw query exception
throw new Exception(
- __METHOD__ . " - Error creating socket to server {$this->ip}:{$this->port}. Error: " . $errstr,
+ __METHOD__ . " - Error creating socket to server $this->ip:$this->port. Error: " . $errstr,
$errno
);
}
@@ -132,22 +132,9 @@ protected function create()
/**
* Pull the responses out of the stream
- *
- * @SuppressWarnings(PHPMD.CyclomaticComplexity)
- * @SuppressWarnings(PHPMD.NPathComplexity)
- *
- * @param array $sockets
- * @param int $timeout
- * @param int $stream_timeout
- *
- * @return array Raw responses
*/
- public function getResponses(array $sockets, $timeout, $stream_timeout)
+ public function getResponses(array $sockets, int $timeout, int $stream_timeout): array
{
-
- // Set the loop to active
- $loop_active = true;
-
// Will hold the responses read from the sockets
$responses = [];
@@ -180,7 +167,7 @@ public function getResponses(array $sockets, $timeout, $stream_timeout)
$time_stop = microtime(true) + $timeout;
// Let's loop until we break something.
- while ($loop_active && microtime(true) < $time_stop) {
+ while (microtime(true) < $time_stop) {
// Check to make sure $read is not empty, if so we are done
if (empty($read)) {
break;
@@ -204,7 +191,7 @@ public function getResponses(array $sockets, $timeout, $stream_timeout)
}
// Check to see if the response is empty, if so we are done with this server
- if (strlen($response) == 0) {
+ if ($response === '') {
// Remove this server from any future read loops
unset($sockets_tmp[(int)$socket]);
continue;
diff --git a/src/GameQ/Result.php b/src/GameQ/Result.php
index 7023f17a..e5d82f38 100644
--- a/src/GameQ/Result.php
+++ b/src/GameQ/Result.php
@@ -26,70 +26,50 @@
*/
class Result
{
-
/**
* Formatted server response
- *
- * @var array
*/
- protected $result = [];
+ protected array $result = [];
/**
* Adds variable to results
- *
- * @param string $name Variable name
- * @param string|array $value Variable value
*/
- public function add($name, $value)
+ public function add(string $name, mixed $value): void
{
-
$this->result[$name] = $value;
}
/**
* Adds player variable to output
- *
- * @param string $name Variable name
- * @param string $value Variable value
*/
- public function addPlayer($name, $value)
+ public function addPlayer(string $name, mixed $value): void
{
-
$this->addSub('players', $name, $value);
}
/**
* Adds player variable to output
- *
- * @param string $name Variable name
- * @param string $value Variable value
*/
- public function addTeam($name, $value)
+ public function addTeam(string $name, mixed $value): void
{
-
$this->addSub('teams', $name, $value);
}
/**
* Add a variable to a category
- *
- * @param $sub string The category
- * @param $key string The variable name
- * @param $value string The variable value
*/
- public function addSub($sub, $key, $value)
+ public function addSub(string $sub, string $key, mixed $value): void
{
-
// Nothing of this type yet, set an empty array
- if (!isset($this->result[$sub]) or !is_array($this->result[$sub])) {
+ if (!isset($this->result[$sub]) || !is_array($this->result[$sub])) {
$this->result[$sub] = [];
}
// Find the first entry that doesn't have this variable
$found = false;
$count = count($this->result[$sub]);
- for ($i = 0; $i != $count; $i++) {
- if (!isset($this->result[$sub][$i][$key])) {
+ foreach ($this->result[$sub] as $i => $iValue) {
+ if (!isset($iValue[$key])) {
$this->result[$sub][$i][$key] = $value;
$found = true;
break;
@@ -106,10 +86,8 @@ public function addSub($sub, $key, $value)
/**
* Return all stored results
- *
- * @return array All results
*/
- public function fetch()
+ public function fetch(): array
{
return $this->result;
@@ -117,14 +95,10 @@ public function fetch()
/**
* Return a single variable
- *
- * @param string $var The variable name
- *
- * @return mixed The variable value
*/
- public function get($var)
+ public function get(string $var): mixed
{
- return isset($this->result[$var]) ? $this->result[$var] : null;
+ return $this->result[$var] ?? null;
}
}
diff --git a/src/GameQ/Server.php b/src/GameQ/Server.php
index 1725d461..dbc30d8a 100644
--- a/src/GameQ/Server.php
+++ b/src/GameQ/Server.php
@@ -19,6 +19,7 @@
namespace GameQ;
use GameQ\Exception\Server as Exception;
+use GameQ\Query\Core;
/**
* Server class to represent each server entity
@@ -30,13 +31,10 @@ class Server
/*
* Server array keys
*/
- const SERVER_TYPE = 'type';
-
- const SERVER_HOST = 'host';
-
- const SERVER_ID = 'id';
-
- const SERVER_OPTIONS = 'options';
+ public const SERVER_TYPE = 'type';
+ public const SERVER_HOST = 'host';
+ public const SERVER_ID = 'id';
+ public const SERVER_OPTIONS = 'options';
/*
* Server options keys
@@ -45,62 +43,46 @@ class Server
/*
* Use this option when the query_port and client connect ports are different
*/
- const SERVER_OPTIONS_QUERY_PORT = 'query_port';
+ public const SERVER_OPTIONS_QUERY_PORT = 'query_port';
/**
* The protocol class for this server
- *
- * @type \GameQ\Protocol
*/
- protected $protocol = null;
+ protected ?Protocol $protocol = null;
/**
* Id of this server
- *
- * @type string
*/
- public $id = null;
+ public ?string $id = null;
/**
* IP Address of this server
- *
- * @type string
*/
- public $ip = null;
+ public ?string $ip = null;
/**
* The server's client port (connect port)
- *
- * @type int
*/
- public $port_client = null;
+ public ?int $port_client = null;
/**
* The server's query port
- *
- * @type int
*/
- public $port_query = null;
+ public ?int $port_query = null;
/**
* Holds other server specific options
- *
- * @type array
*/
- protected $options = [];
+ protected array $options = [];
/**
* Holds the sockets already open for this server
- *
- * @type array
*/
- protected $sockets = [];
+ protected array $sockets = [];
/**
* Construct the class with the passed options
*
- * @param array $server_info
- *
* @throws \GameQ\Exception\Server
*/
public function __construct(array $server_info = [])
@@ -141,30 +123,28 @@ public function __construct(array $server_info = [])
);
$this->protocol = $class->newInstanceArgs([$this->options]);
- } catch (\ReflectionException $e) {
+ } catch (\ReflectionException) {
throw new Exception("Unable to locate Protocols class for '{$server_info[self::SERVER_TYPE]}'!");
}
// Check and set any server options
$this->checkAndSetServerOptions();
- unset($server_info, $class);
+ unset($class);
}
/**
* Check and set the ip address for this server
*
- * @param $ip_address
- *
* @throws \GameQ\Exception\Server
*/
- protected function checkAndSetIpPort($ip_address)
+ protected function checkAndSetIpPort(string $ip_address): void
{
// Test for IPv6
if (substr_count($ip_address, ':') > 1) {
// See if we have a port, input should be in the format [::1]:27015 or similar
- if (strstr($ip_address, ']:')) {
+ if (str_contains($ip_address, ']:')) {
// Explode to get port
$server_addr = explode(':', $ip_address);
@@ -178,42 +158,41 @@ protected function checkAndSetIpPort($ip_address)
} else {
// Just the IPv6 address, no port defined, fail
throw new Exception(
- "The host address '{$ip_address}' is missing the port. All "
+ "The host address '$ip_address' is missing the port. All "
. "servers must have a port defined!"
);
}
// Now let's validate the IPv6 value sent, remove the square brackets ([]) first
if (!filter_var(trim($this->ip, '[]'), FILTER_VALIDATE_IP, ['flags' => FILTER_FLAG_IPV6,])) {
- throw new Exception("The IPv6 address '{$this->ip}' is invalid.");
+ throw new Exception("The IPv6 address '$this->ip' is invalid.");
}
} else {
// We have IPv4 with a port defined
- if (strstr($ip_address, ':')) {
- list($this->ip, $this->port_client) = explode(':', $ip_address);
-
- // Type case the port
- $this->port_client = (int)$this->port_client;
+ if (str_contains($ip_address, ':')) {
+ $addressParts = explode(':', $ip_address);
+ $this->ip = $addressParts[0];
+ $this->port_client = (int)$addressParts[1];
} else {
// No port, fail
throw new Exception(
- "The host address '{$ip_address}' is missing the port. All "
+ "The host address '$ip_address' is missing the port. All "
. "servers must have a port defined!"
);
}
// Validate the IPv4 value, if FALSE is not a valid IP, maybe a hostname.
- if (! filter_var($this->ip, FILTER_VALIDATE_IP, ['flags' => FILTER_FLAG_IPV4,])) {
+ if (!filter_var($this->ip, FILTER_VALIDATE_IP, ['flags' => FILTER_FLAG_IPV4,])) {
// Try to resolve the hostname to IPv4
$resolved = gethostbyname($this->ip);
// When gethostbyname() fails it returns the original string
if ($this->ip === $resolved) {
// so if ip and the result from gethostbyname() are equal this failed.
- throw new Exception("Unable to resolve the host '{$this->ip}' to an IP address.");
- } else {
- $this->ip = $resolved;
+ throw new Exception("Unable to resolve the host '$this->ip' to an IP address.");
}
+
+ $this->ip = $resolved;
}
}
}
@@ -221,7 +200,7 @@ protected function checkAndSetIpPort($ip_address)
/**
* Check and set any server specific options
*/
- protected function checkAndSetServerOptions()
+ protected function checkAndSetServerOptions(): void
{
// Specific query port defined
@@ -236,30 +215,22 @@ protected function checkAndSetServerOptions()
/**
* Set an option for this server
*
- * @param $key
- * @param $value
- *
* @return $this
*/
- public function setOption($key, $value)
+ public function setOption(string $key, mixed $value): self
{
-
$this->options[$key] = $value;
- return $this; // Make chainable
+ return $this;
}
/**
* Return set option value
- *
- * @param mixed $key
- *
- * @return mixed
*/
- public function getOption($key)
+ public function getOption(string $key): mixed
{
- return (array_key_exists($key, $this->options)) ? $this->options[$key] : null;
+ return $this->options[$key] ?? null;
}
public function getOptions()
@@ -269,10 +240,8 @@ public function getOptions()
/**
* Get the ID for this server
- *
- * @return string
*/
- public function id()
+ public function id(): string
{
return $this->id;
@@ -280,10 +249,8 @@ public function id()
/**
* Get the IP address for this server
- *
- * @return string
*/
- public function ip()
+ public function ip(): string
{
return $this->ip;
@@ -291,10 +258,8 @@ public function ip()
/**
* Get the client port for this server
- *
- * @return int
*/
- public function portClient()
+ public function portClient(): int
{
return $this->port_client;
@@ -302,10 +267,8 @@ public function portClient()
/**
* Get the query port for this server
- *
- * @return int
*/
- public function portQuery()
+ public function portQuery(): int
{
return $this->port_query;
@@ -313,10 +276,8 @@ public function portQuery()
/**
* Return the protocol class for this server
- *
- * @return \GameQ\Protocol
*/
- public function protocol()
+ public function protocol(): ?Protocol
{
return $this->protocol;
@@ -324,13 +285,16 @@ public function protocol()
/**
* Get the join link for this server
- *
- * @return string
*/
- public function getJoinLink()
+ public function getJoinLink(): ?string
{
+ $joinLink = $this->protocol?->joinLink();
- return sprintf($this->protocol->joinLink(), $this->ip, $this->portClient());
+ if ($joinLink === null) {
+ return null;
+ }
+
+ return sprintf($joinLink, $this->ip, $this->portClient());
}
/*
@@ -339,12 +303,8 @@ public function getJoinLink()
/**
* Add a socket for this server to be reused
- *
- * @codeCoverageIgnore
- *
- * @param \GameQ\Query\Core $socket
*/
- public function socketAdd(Query\Core $socket)
+ public function socketAdd(Core $socket): void
{
$this->sockets[] = $socket;
@@ -352,12 +312,8 @@ public function socketAdd(Query\Core $socket)
/**
* Get a socket from the list to reuse, if any are available
- *
- * @codeCoverageIgnore
- *
- * @return \GameQ\Query\Core|null
*/
- public function socketGet()
+ public function socketGet(): ?Core
{
$socket = null;
@@ -371,10 +327,8 @@ public function socketGet()
/**
* Clear any sockets still listed and attempt to close them
- *
- * @codeCoverageIgnore
*/
- public function socketCleanse()
+ public function socketCleanse(): void
{
// Close all of the sockets available
diff --git a/tests/MockDNS.php b/tests/MockDNS.php
index 1821b719..a0e1777e 100644
--- a/tests/MockDNS.php
+++ b/tests/MockDNS.php
@@ -6,8 +6,6 @@
* MockDNS class using monkey patching. Inspired by symfony/phpunit-bridge
*
* @see https://github.com/symfony/phpunit-bridge/blob/5.3/DnsMock.php
- *
- * @SuppressWarnings(PHPMD)
*/
class MockDNS
{
diff --git a/tests/Protocols/Base.php b/tests/Protocols/Base.php
index 27820e9e..55d36291 100644
--- a/tests/Protocols/Base.php
+++ b/tests/Protocols/Base.php
@@ -23,8 +23,6 @@
/**
* Class Base for protocol tests
*
- * @SuppressWarnings(PHPMD.NumberOfChildren)
- *
* @package GameQ\Tests\Protocols
*/
abstract class Base extends TestBase
diff --git a/tests/Protocols/Mumble.php b/tests/Protocols/Mumble.php
index b90703d3..65a58ea5 100644
--- a/tests/Protocols/Mumble.php
+++ b/tests/Protocols/Mumble.php
@@ -66,8 +66,7 @@ public function testPackets()
*/
public function testBadResponseFormat()
{
- $this->expectException(\Exception::class);
- $this->expectExceptionMessage("GameQ\Protocols\Mumble::processResponse Unable to decode JSON data.");
+ $this->expectException(\JsonException::class);
// Should fail out
$this->queryTest('127.0.0.1:27015', 'mumble', [ '{"key1": "val", "key2" :}' ], true);
}