From 500860daf3318ceb58128daa122d063e37c253c4 Mon Sep 17 00:00:00 2001 From: TimZ99 Date: Mon, 18 May 2020 20:27:11 +0200 Subject: [PATCH] Added regex to determine if packet loss is 0% Accepts: 0 0.0 0.00 0.000 0,0 0,00 0,000 --- src/psm/Util/Server/Updater/StatusUpdater.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/psm/Util/Server/Updater/StatusUpdater.php b/src/psm/Util/Server/Updater/StatusUpdater.php index eeba1d17..a6c1ab51 100644 --- a/src/psm/Util/Server/Updater/StatusUpdater.php +++ b/src/psm/Util/Server/Updater/StatusUpdater.php @@ -190,7 +190,9 @@ class StatusUpdater $txt = exec($pingCommand . " -c" . $max_runs . " " . $serverIp . " 2>&1", $output); // Check if output is PING and if 0,0% of packages are lost, otherwise fail. - if (substr($output[0], 0, 4) == 'PING' && strpos($output[count($output) - 2], '0.0% packet loss')) { + preg_match('/([0][,.]?0{0,3})(% packet loss)$/', $output[count($output) - 2], $output_package_loss); + + if (substr($output[0], 0, 4) == 'PING' && count($output_package_loss) !== 0) { // Gets avg from 'round-trip min/avg/max/stddev = 7.109/7.109/7.109/0.000 ms' preg_match_all("/(\d+\.\d+)/", $output[count($output) - 1], $result); $result = floatval($result[0][1]);