From 34390a0713fe00214df17d07e3c3f7691a006225 Mon Sep 17 00:00:00 2001 From: yggverse Date: Wed, 4 Mar 2026 22:56:37 +0200 Subject: [PATCH] simplify port decoding --- src/Xash3D/Master.php | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/src/Xash3D/Master.php b/src/Xash3D/Master.php index 2714627..5ef7d01 100644 --- a/src/Xash3D/Master.php +++ b/src/Xash3D/Master.php @@ -125,29 +125,14 @@ class Master continue; } - // Decode first byte of port - if (false === $byte1 = fread($socket, 1)) - { - // Shift port byte - fread($socket, 1); - - continue; - } - - // Decode second byte of port - if (false === $byte2 = fread($socket, 1)) - { - continue; - } - // Calculate port value - $port = ord($byte1) * 256 + ord($byte2); + $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) + false === filter_var($port, FILTER_VALIDATE_INT) // @TODO ) { continue;