From 76363400926e807af164080c9ed2fd7ff00e5956 Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Mon, 19 Oct 2015 22:04:34 +0300 Subject: [PATCH] Use gmp module to correctly read server's steamid on 32-bit systems --- SourceQuery/SourceQuery.php | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/SourceQuery/SourceQuery.php b/SourceQuery/SourceQuery.php index 1e4770d..2cba855 100644 --- a/SourceQuery/SourceQuery.php +++ b/SourceQuery/SourceQuery.php @@ -304,10 +304,37 @@ $Server[ 'GamePort' ] = $Buffer->GetShort( ); } - // The server's SteamID - does this serve any purpose? + // The server's steamid + // Want to play around with this? + // You can use https://github.com/xPaw/SteamID.php if( $Flags & 0x10 ) { - $Server[ 'ServerID' ] = $Buffer->GetUnsignedLong( ) | ( $Buffer->GetUnsignedLong( ) << 32 ); // TODO: verify this + $a = $Buffer->GetUnsignedLong( ); + $b = $Buffer->GetUnsignedLong( ); + $SteamID = 0; + + if( PHP_INT_SIZE === 4 ) + { + if( extension_loaded( 'gmp2' ) ) + { + $a = gmp_abs( $a ); + $b = gmp_abs( $b ); + + $SteamID = gmp_strval( gmp_or( $a, gmp_mul( $b, gmp_pow( 2, 32 ) ) ) ); + } + else + { + throw new \RuntimeException( 'Either 64-bit PHP installation or "gmp" module is required to correctly parse server\'s steamid.' ); + } + } + else + { + $SteamID = $a | ( $b << 32 ); + } + + $Server[ 'SteamID' ] = $SteamID; + + unset( $a, $b, $SteamID ); } // The spectator port and then the spectator server name