add errors debug

This commit is contained in:
ghost 2024-01-12 19:10:43 +02:00
parent 9c9625cb21
commit be344abd36
2 changed files with 34 additions and 1 deletions

View file

@ -18,4 +18,8 @@ $master = new \Yggverse\Hl\Xash3D\Master('hl.ygg', 27010);
var_dump( var_dump(
$master->getServersIPv6() $master->getServersIPv6()
); );
var_dump(
$master->getErrors()
);
``` ```

View file

@ -7,6 +7,7 @@ namespace Yggverse\Hl\Xash3D;
class Master class Master
{ {
private $_socket; private $_socket;
private $_errors = [];
public function __construct( public function __construct(
string $host, string $host,
@ -16,7 +17,10 @@ class Master
{ {
$this->_socket = fsockopen( $this->_socket = fsockopen(
"udp://{$host}", "udp://{$host}",
$port $port,
$code,
$message,
$timeout
); );
if (is_resource($this->_socket)) if (is_resource($this->_socket))
@ -26,6 +30,14 @@ class Master
$timeout $timeout
); );
} }
else
{
$this->_errors[] = sprintf(
_('Connection error: %s'),
$message
);
}
} }
public function getServersIPv6( public function getServersIPv6(
@ -39,6 +51,8 @@ class Master
// Is connected // Is connected
if (!is_resource($this->_socket)) if (!is_resource($this->_socket))
{ {
$this->_errors[] = _('Socket connection error');
return null; return null;
} }
@ -49,6 +63,8 @@ class Master
$this->_socket $this->_socket
); );
$this->_errors[] = _('Could not send socket query');
return null; return null;
} }
@ -59,6 +75,8 @@ class Master
$this->_socket $this->_socket
); );
$this->_errors[] = _('Could not init packet header');
return null; return null;
} }
@ -74,6 +92,8 @@ class Master
$this->_socket $this->_socket
); );
$this->_errors[] = _('Could not read server address');
return null; return null;
} }
@ -96,6 +116,8 @@ class Master
$this->_socket $this->_socket
); );
$this->_errors[] = _('Could not read first byte of port');
return null; return null;
} }
@ -106,6 +128,8 @@ class Master
$this->_socket $this->_socket
); );
$this->_errors[] = _('Could not read second byte of port');
return null; return null;
} }
@ -136,4 +160,9 @@ class Master
return $servers; return $servers;
} }
public function getErrors(): array
{
return $this->_errors;
}
} }