将 SteamID 转换为 32/64 位 SteamID Swift

Convert SteamID to 32/64 bit SteamID Swift

我的 SteamID 格式为 STEAM_0:1:21643603

如何将其翻译成:

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