我有一个蒸汽IDS列表,如下所示:
STEAM_1:0:61759597
STEAM_1:1:20263946
STEAM_1:0:105065707
对于所有对steam API的调用,你需要给它一个steamID64,看起来像这样:
76561198083784922
76561198000793621
76561198170397142
Steam页面显示了如何从SteamID转换为SteamID64的示例 https://developer.valvesoftware.com/wiki/SteamID
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)
Worked Example:
Universe: Public (1)
Account Type: Clan (7)
Instance: 0
Account ID: 4
64-bit integer value: 103582791429521412
我的问题是如何在python中实现它。我不明白这里发生的任何事情。
为了让我的问题变得非常明确,我想从STEAM_1:0:61759597
开始解析SteamID64 76561198083784922
我知道这是可能的,因为有很多网站都是这样做的: https://steamid.io/,http://steamidfinder.com/,https://steamid.co/
这么多问题是:这个算法做了什么以及如何在python中实现它?
更新
这是我现在的代码,没有按预期工作:
steamID = "STEAM_1:0:61759597"
X = int(steamID[6:7])
Y = int(steamID[8:9])
Z = int(steamID[10:])
#x is 1
#y is 0
#z is 61759597
print(X,Y,Z)
print((X << 56) | (Y << 52) | (Z << 32) | 4)
#current output: 265255449329139716
#desired output: 76561198083784922
答案 0 :(得分:1)
实现实际上与Steam wiki上显示的完全相同:
>>> (1 << 56) | (7 << 52) | (0 << 32) | 4
103582791429521412
<<
和|
为bitwise operators,分别执行左移和按位OR。您可以在维基百科上了解更多有关bitwise operations的内容。
就将任意Steam ID转换为64位系统而言,我发现了gist:
def steamid_to_64bit(steamid):
steam64id = 76561197960265728 # I honestly don't know where
# this came from, but it works...
id_split = steamid.split(":")
steam64id += int(id_split[2]) * 2 # again, not sure why multiplying by 2...
if id_split[1] == "1":
steam64id += 1
return steam64id
In [14]: steamid_to_64bit("STEAM_1:0:61759597")
Out[14]: 76561198083784922
In [15]: steamid_to_64bit("STEAM_1:1:20263946")
Out[15]: 76561198000793621
In [16]: steamid_to_64bit("STEAM_1:0:105065707")
Out[16]: 76561198170397142
答案 1 :(得分:1)
steam forum post如何转换,我们只关心最后两个数字:
ID3因此是ID64基数(76561197960265728)的偏移量,是帐号。 有史以来第一个帐号:(其76561197960265728 + 1,76561197960265728不存在)
ID64 = 76561197960265728 + (B * 2) + A
ID3 = (B * 2) + A
ID32 = STEAM_0:A:B
所以你需要的只是:
def to_steam64(s):
return ((b * 2) + a) + 76561197960265728
走反向路线,来自steam64:
def from_steam64(sid):
y = int(sid) - 76561197960265728
x = y % 2
return "STEAM_0:{}:{}".format(x, (y - x) // 2)
这是转换表here
答案 2 :(得分:-1)
究竟发生的事情是,SteamID到SteamID64转换正在获取存储在SteamID中的基本10整数信息,并将它们转换为64位二进制数。
如果您采用Valve组示例,则可以使用SteamID64
(103582791429521412)_10 = (101110000000000000000000000000000000000000000000000000100)_2.
这里的每个角色都代表一点。查看数字n = {56,52,32,0},您可以看到从64位数字的第n位开始,您将获得与某个存储细节相对应的二进制值。
1|0111|00000000000000000000|00000000000000000000000000000100
Universe(来自第56位):1 2 (公开)
帐户类型(从第52位开始):0111 2 = 7(Clan)
实例(从第32位开始):00000000000000000000 2 = 0
帐户ID(从第0位开始): 00000000000000000000000000000100 2 = 4