From 726463e94e88f5aa7bd1052aa7242b5650359760 Mon Sep 17 00:00:00 2001 From: ghost Date: Fri, 12 Jan 2024 20:06:45 +0200 Subject: [PATCH] fix packet reader --- src/Xash3D/Master.php | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/src/Xash3D/Master.php b/src/Xash3D/Master.php index 7feadbb..8442007 100644 --- a/src/Xash3D/Master.php +++ b/src/Xash3D/Master.php @@ -88,13 +88,7 @@ class Master // Get host if (false === $host = fread($this->_socket, 16)) { - fclose( - $this->_socket - ); - - $this->_errors[] = _('Could not read server address'); - - return null; + break; } // Is end of packet @@ -103,34 +97,28 @@ class Master break; } - // Skip invalid host + // Skip invalid host value if (false === $host = inet_ntop($host)) { + // Shift port bytes + fread($this->_socket, 2); + continue; } // Decode first byte for port if (false === $byte1 = fread($this->_socket, 1)) { - fclose( - $this->_socket - ); - - $this->_errors[] = _('Could not read first byte of port'); + // Shift port byte + fread($this->_socket, 1); - return null; + continue; } // Decode second byte for port if (false === $byte2 = fread($this->_socket, 1)) { - fclose( - $this->_socket - ); - - $this->_errors[] = _('Could not read second byte of port'); - - return null; + continue; } // Calculate port value