Skip to content

Commit

Permalink
PHP 8
Browse files Browse the repository at this point in the history
  • Loading branch information
jacklul committed Jun 4, 2023
1 parent d0ac735 commit 5b708bc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
}
],
"require": {
"php": "^5.5|^7.0",
"php": "^5.5|^7.0|^8.0",
"ext-sockets": "*"
},
"require-dev": {
Expand Down
9 changes: 5 additions & 4 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use InvalidArgumentException;
use RuntimeException;
use Socket;

/**
* This class represent single connection
Expand All @@ -35,7 +36,7 @@ class Connection
/**
* Socket handle
*
* @var resource
* @var Socket|resource
*/
protected $socket;

Expand Down Expand Up @@ -106,7 +107,7 @@ public function setTimeout($seconds)
*/
private function setTimeoutOption($seconds = 1, $microseconds = 0)
{
if (!is_resource($this->socket)) {
if (!is_resource($this->socket) && !$this->socket instanceof Socket) {
throw new RuntimeException('Socket handle is not valid');
}

Expand All @@ -132,7 +133,7 @@ public function connect()

$this->socket = @socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);

if (!is_resource($this->socket)) {
if (!is_resource($this->socket) && !$this->socket instanceof Socket) {
throw new RuntimeException('Unable to create socket: ' . socket_strerror(socket_last_error()));
}

Expand Down Expand Up @@ -252,7 +253,7 @@ public function __destruct()
*/
public function close()
{
if (is_resource($this->socket)) {
if (is_resource($this->socket) || $this->socket instanceof Socket) {
return @socket_close($this->socket);
}

Expand Down
4 changes: 4 additions & 0 deletions src/MasterServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ private function parseData($data)
{
$servers = [];

if (empty($data)) {
return $servers;
}

for ($i = 0; $i < (strlen($data) - 10); $i++) {
if ($data[$i] === "\\" && $data[$i + 7] === "\\") {
$ip = ord($data[$i + 1]) . '.' . ord($data[$i + 2]) . '.' . ord($data[$i + 3]) . '.' . ord($data[$i + 4]);
Expand Down

0 comments on commit 5b708bc

Please sign in to comment.