View Single Post
rautamiekka
Veteran Member
Join Date: Jan 2009
Location: Finland
Old 09-27-2017 , 02:25   Re: Convert STEAMID to Steam Community ID
Reply With Quote #358

Quote:
Originally Posted by Powerlord View Post
Note that the number 76561197960265728 looks like a constant, but it really isn't.

This doesn't really matter if you're converting SteamId2 to SteamId64 because SteamId2 only supports individual user accounts. However, SteamId3 also contains the account type and (optionally) instance ID.

The correct calculation for Community IDs:

Code:
((universe << 56) | (accountType << 52) | (instance << 32) | accountId)
The first 3 default to 1 for individual user accounts, which means the "magic number" for individual accounts is

Code:
((1L << 56) | (1L << 52) | (1L << 32))
which is 76561197960265728.

(L is there because 64-bit literals need it in the language I was using to double check this.)

If you try this to get group profile IDs or game server profile IDs, it fails spectacularly because they use different account types and instances.

Side note: The second section of a SteamId2 is the lowest bit of the account ID and the third section is the remaining 31 bits of the account ID. Hence, to get the account ID, it's

((third section << 1) | second section)
Very good to know, thank you a lot.
__________________
Links to posts I received Karma from:
Big thanks to all who gave Karma
rautamiekka is offline
Send a message via ICQ to rautamiekka Send a message via AIM to rautamiekka Send a message via MSN to rautamiekka Send a message via Yahoo to rautamiekka Send a message via Skype™ to rautamiekka