diff --git a/README.md b/README.md index 60d2ee5..dbba9d4 100644 --- a/README.md +++ b/README.md @@ -18,4 +18,8 @@ $master = new \Yggverse\Hl\Xash3D\Master('hl.ygg', 27010); var_dump( $master->getServersIPv6() ); + +var_dump( + $master->getErrors() +); ``` \ No newline at end of file diff --git a/src/Xash3D/Master.php b/src/Xash3D/Master.php index 69c5787..5c7c58e 100644 --- a/src/Xash3D/Master.php +++ b/src/Xash3D/Master.php @@ -7,6 +7,7 @@ namespace Yggverse\Hl\Xash3D; class Master { private $_socket; + private $_errors = []; public function __construct( string $host, @@ -16,7 +17,10 @@ class Master { $this->_socket = fsockopen( "udp://{$host}", - $port + $port, + $code, + $message, + $timeout ); if (is_resource($this->_socket)) @@ -26,6 +30,14 @@ class Master $timeout ); } + + else + { + $this->_errors[] = sprintf( + _('Connection error: %s'), + $message + ); + } } public function getServersIPv6( @@ -39,6 +51,8 @@ class Master // Is connected if (!is_resource($this->_socket)) { + $this->_errors[] = _('Socket connection error'); + return null; } @@ -49,6 +63,8 @@ class Master $this->_socket ); + $this->_errors[] = _('Could not send socket query'); + return null; } @@ -59,6 +75,8 @@ class Master $this->_socket ); + $this->_errors[] = _('Could not init packet header'); + return null; } @@ -74,6 +92,8 @@ class Master $this->_socket ); + $this->_errors[] = _('Could not read server address'); + return null; } @@ -96,6 +116,8 @@ class Master $this->_socket ); + $this->_errors[] = _('Could not read first byte of port'); + return null; } @@ -106,6 +128,8 @@ class Master $this->_socket ); + $this->_errors[] = _('Could not read second byte of port'); + return null; } @@ -136,4 +160,9 @@ class Master return $servers; } + + public function getErrors(): array + { + return $this->_errors; + } } \ No newline at end of file