NomisCZ / hlstatsx-community-edition

HLstatsX Community Edition - PHP 7 and GeoIP2 supported
GNU General Public License v2.0
83 stars 48 forks source link

Latency shows as 0 - possible fix included #77

Closed nikooo777 closed 1 year ago

nikooo777 commented 1 year ago

Describe the bug Because of how TRcon.pm expects the output of status the steamID used to index player data is in the new format. The scripts use the old format to look up the latency during update_playesr_pings and therefore it always fails. the result is a latency of 0 on the server summary.

Fix Applying this fix works for me. It 1) converts the steam id from the new version to the old version 2) removes extra spaces picked up by the old regex

diff --git a/scripts/TRcon.pm b/scripts/TRcon.pm
index 735b554..ed8d6a9 100644
--- a/scripts/TRcon.pm
+++ b/scripts/TRcon.pm
@@ -318,7 +318,7 @@ sub getPlayers
                 (\d+)\s+               # userid
                                (?:\d+\s+|)     # extra number in L4D, not sure what this is??
                 "(.+)"\s+              # name
-                (.+)\s+                    # uniqueid
+                (\S+)\s+                   # uniqueid
                 ([\d:]+)\s+            # time
                 (\d+)\s+               # ping
                 (\d+)\s+               # loss
@@ -337,8 +337,8 @@ sub getPlayers
       my $state    = $7;
       my $address  = $8;
       my $port     = $9;
-
-         $uniqueid =~ s/^STEAM_[0-9]+?\://i;
+      $uniqueid =~ s!\[U:1:(\d+)\]!($1 % 2).':'.int($1 / 2)!eg;
+      $uniqueid =~ s/^STEAM_[0-9]+?\://i;

       # &::printEvent("DEBUG", "USERID: '$userid', NAME: '$name', UNIQUEID: '$uniqueid', TIME: '$time', PING: '$ping', LOSS: '$loss', STATE: '$state', ADDRESS:'$address', CLI_PORT: '$port'", 1);

you may see the working result here: https://stats.elite-hunterz.info/hlstats.php?game=css