将 SteamID64 转换为 SteamID

Convert SteamID64 to SteamID

我正在寻找一种方法,可以将 SteamID64 (76561198032122624) 转换为 PHP 中的 SteamID (STEAM_0:0:35928448)。我已经对此进行了很多搜索,但找不到如何执行此操作。我几乎可以肯定这是可能的,因为像 steamid.io 这样的网站能够找到它,但我不知道如何找到它。

您需要的所有信息都在 Valve's SteamID wiki page:

Legacy Format

Steam IDs follow a fairly simple format when represented textually: "STEAM_X:Y:Z", where X, Y and Z are integers.

  • X represents the "Universe" the steam account belongs to. If 'X' is 0, then this is Universe 1 (Public).
  • Y is the lowest bit of the Account ID. Thus, Y is either 0 or 1.
  • Z is the highest 31 bits of the Account ID.

As a 64-bit integer

Given the components of a Steam ID, a Steam ID can be converted to it's 64-bit integer form as follows:

((Universe << 56) | (Account Type << 52) | (Instance << 32) | Account ID)

我的 PHP 非常 生疏,但这里有一些(未经测试的)伪代码应该可以大致满足要求:

var steamId64 = 76561198032122624;

var universe = (steamId64 >> 56) & 0xFF;
if (universe == 1) universe = 0;

var accountIdLowBit = steamId64 & 1;

var accountIdHighBits = (steamId64 >> 1) & 0x7FFFFFF;

// should hopefully produce "STEAM_0:0:35928448"
var legacySteamId = "STEAM_" + universe + ":" + accountIdLowBit + ":" + accountIdHighBits;
<?php 

$steamid64="76561198237914532"; //YOUR STEAM ID 64

echo "<-- By BigBossPT to VynexGaming.com -->";
echo "<br><br>Steamid32: ".getSteamId32($steamid64);
echo "<br><br>Steamid64: ".getSteamID64(getSteamId32($steamid64)); // 76561197985756607 
echo "<br><br>Thanks for Gio! Website that i found: https://facepunch.com/showthread.php?t=1238157";
//OBTER STEAM ID 64 

function getSteamID64($id) {
    if (preg_match('/^STEAM_/', $id)) {
        $parts = explode(':', $id);
        return bcadd(bcadd(bcmul($parts[2], '2'), '76561197960265728'), $parts[1]);
    } elseif (is_numeric($id) && strlen($id) < 16) {
        return bcadd($id, '76561197960265728');
    } else {
        return $id; // We have no idea what this is, so just return it.
    }
}


function parseInt($string) {
    //    return intval($string);
        if(preg_match('/(\d+)/', $string, $array)) {
            return $array[1];
        } else {
            return 0;
        }
    }
function getSteamId32($id){
    // Convert SteamID64 into SteamID

    $subid = substr($id, 4); 
    $steamY = parseInt($subid);
    $steamY = $steamY - 1197960265728; //76561197960265728

    if ($steamY%2 == 1){
    $steamX = 1;
    } else {
    $steamX = 0;
    }

    $steamY = (($steamY - $steamX) / 2);
    $steamID = "STEAM_0:" . (string)$steamX . ":" . (string)$steamY;
    return $steamID;

}
?>
function steamid64_to_steamid2($steamid64) {
    $accountID = bcsub($steamid64, '76561197960265728');
    return 'STEAM_0:'.bcmod($accountID, '2').':'.bcdiv($accountID, 2);
}

这是一个实际工作的版本,不需要 BC Math PHP Extension

<?php
    $id = "{STEAMID64 HERE}";

function parseInt($string) {
//    return intval($string);
    if(preg_match('/(\d+)/', $string, $array)) {
        return $array[1];
    } else {
        return 0;
    }}

// Convert SteamID64 into SteamID
$subid = substr($id, 4); // because calculators suck
$steamY = parseInt($subid);
$steamY = $steamY - 1197960265728; //76561197960265728
$steamX = 0;
if ($steamY%2 == 1){
$steamX = 1;
} else {
$steamX = 0;
}

$steamY = (($steamY - $steamX) / 2);
$steamID = "STEAM_0:" . (string)$steamX . ":" . (string)$steamY;
echo $steamID;

?>