From 13a7c607e11dd7e1c11be59af05738fd72b58ae3 Mon Sep 17 00:00:00 2001 From: yggverse Date: Wed, 4 Mar 2026 23:19:46 +0200 Subject: [PATCH] update parsing conditions, remove hardcoded ipv6 impl --- src/Xash3D/Master.php | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/Xash3D/Master.php b/src/Xash3D/Master.php index 5ef7d01..fcf951c 100644 --- a/src/Xash3D/Master.php +++ b/src/Xash3D/Master.php @@ -107,13 +107,13 @@ class Master // Get host if (false === $host = fread($socket, 16)) { - continue; + break; } // Is end of packet if (true === str_ends_with(bin2hex($host), bin2hex("\0\0\0\0\0\0"))) { - continue; + break; } // Skip invalid host value @@ -126,22 +126,27 @@ class Master } // Calculate port value - $port = unpack('nport', fread($socket, 2)); - - // Validate IPv6 result - if ( - false !== strpos($host, '.') || // filter_var not always works with mixed IPv6 - false === filter_var($host, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) || - false === filter_var($port, FILTER_VALIDATE_INT) // @TODO - ) + if (false === $port = fread($socket, 2)) { continue; } - $servers["[{$host}]:{$port}"] = // keep unique + if (false === $port = unpack('nport', $port)) + { + continue; + } + + // Validate IPv6 result + if ((false === filter_var($host, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) && + false === filter_var($host, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) || empty($port['port'])) + { + continue; + } + + $servers["[{$host}]:{$port['port']}"] = // keep unique [ 'host' => $host, - 'port' => $port + 'port' => $port['port'] ]; }