如何从python中的steamid获取steamid 64

2024-05-15 10:22:05 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个steam ID列表,如下所示:

STEAM_1:0:61759597
STEAM_1:1:20263946
STEAM_1:0:105065707

对于所有对steam API的调用,需要给它一个steamID64,如下所示:

^{pr2}$

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开始,从中解析出76561198083784922的SteamID64

我知道这是可能的,因为有很多网站都这样做: 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

Tags: httpscomidisbitaccountintegersteam
3条回答

实际实现与Steam wiki上显示的完全相同:

>>> (1 << 56) | (7 << 52) | (0 << 32) | 4
103582791429521412

<<和{}是{a1},分别执行左移位和按位“或”。你可以在维基百科上了解更多关于bitwise operations的信息。在

至于将任意Steam id转换为64位系统,我发现了这个gist

^{pr2}$

实际上,SteamID到SteamID64的转换是将存储在SteamID中的以10为基数的整数信息转换为64位二进制数。在

如果以阀组为例,可以使用SteamID64

(103582791429521412)_10 = (101110000000000000000000000000000000000000000000000000100)_2.

这里的每个字符代表一个位。看看数字n={56,52,32,0},可以看到从64位数字的第n位开始,得到与特定存储细节相对应的二进制值。在

1|0111|00000000000000000000|00000000000000000000000000000100

  • 宇宙(第56位起):12(公共)

  • 账户类型(第52位起):01112=7(集团)

  • 实例(从第32位开始):000000000000000000002=0

  • 帐户ID(从第0位开始): 00000000000000000000000001002=4

steam forum post中有一个关于如何转换的解释,我们只关心最后两个数字:

因此,ID3是ID64基数(76561197960265728)的偏移量,是帐号。 首次开户:(其76561197960265728+176561197960265728不存在)

    ID64 = 76561197960265728 + (B * 2) + A
    ID3 = (B * 2) + A
    ID32 = STEAM_0:A:B

所以你只需要:

^{pr2}$

从64号蒸汽机开始反向行驶:

def from_steam64(sid):
    y = int(sid) - 76561197960265728
    x = y % 2 
    return "STEAM_0:{}:{}".format(x, (y - x) // 2)

是一个转换表here

相关问题 更多 >