将SteamID转换为32/64位SteamID Swift

时间:2016-01-11 17:56:06

标签: ios swift steam

我的SteamID格式为STEAM_0:1:21643603

如何将其翻译为:

  • Steam32ID(帐户ID),格式为43287207;
  • Steam64ID,格式为76561198003552935;

1 个答案:

答案 0 :(得分:1)

Valve SteamID wiki

// STEAM_X:Y:Z
func convertToSteam32ID(steamString: String) -> UInt64 {
    let array = steamString.componentsSeparatedByString(":")
    let Y = UInt64(array[1])!
    let Z = UInt64(array[2])!
    return (Z << 1) | Y
}

func convertToSteam64ID(accountID accountID: UInt64) -> UInt64 {
    let Universe: UInt64 = 1
    let AccountType: UInt64 = 1
    let Instance: UInt64 = 1
    return ((Universe << 56) | (AccountType << 52) | (Instance << 32) | accountID)
}

let steam32ID = convertToSteam32ID("STEAM_0:1:21643603")

let steam64ID = convertToSteam64ID(accountID: steam32ID)

Source Gist