Raised This Month: $40 Target: $400
 10% 

Convert STEAMID to Steam Community ID


Post New Thread Reply   
 
Thread Tools Display Modes
pokemonmaster
princess milk
Join Date: Nov 2010
Location: Somewhere in this world
Old 07-15-2016 , 18:10   Re: Convert STEAMID to Steam Community ID
Reply With Quote #351

This is a snippet I wrote for sourcepawn, but I won't use anymore.
Will convert Steam64 string to steam32 int

Don't even know if this will be of use for anyone.
This was built based on this
PHP Code:
// 64 bit max is 19 numbers + 1 (for teminator)
#define MAX_STEAM64_LENGTH 20

// 11 numbers is the total numbers that the 32 bit can hold, lets make sure its less than that by 1.
// 10 + terminator
#define MAX_INTEGERS 11

stock bool GetSteam32FromSteam64(const char szSteam64Original[MAX_STEAM64_LENGTH], int &iSteam32)
{
    
char szSteam32[MAX_STEAM64_LENGTH];
    
char szSteam64[MAX_STEAM64_LENGTH];
    
    
// We don't want to actually edit the original string.
    // We make a new string for the editing.
    
strcopy(szSteam64sizeof szSteam64szSteam64Original);
    
    
// Remove the first three numbers
    
ReplaceStringEx(szSteam64sizeof(szSteam64), "765""");
    
    
// Because pawn does not support numbers bigger than 2147483647, we will need to subtract using a combination of numbers.
    // The combination can be
    // 1 number to MAX_INTEGERS
    
char szSubtractionString[] = "61197960265728";
    
    
// First integer is the integer from szSteam64
    // Second is from the subtraction string szSubtractionString
    
char szFirstInteger[MAX_INTEGERS], szSecondInteger[MAX_INTEGERS];
    
int iFirstIntegeriSecondInteger;
    
    
char szResultInt[MAX_INTEGERS];
    
    
// Ugly hack
    // Make the strings 00000000000 so when we use StringToInt the zeroes won't affect the result
    // sizeof - 1 because we need the last End of string (0) byte;
    
SetStringZeros(szFirstIntegersizeof(szFirstInteger), sizeof(szFirstInteger) - 1);
    
SetStringZeros(szSecondIntegersizeof(szSecondInteger), sizeof(szSecondInteger) - 1);

    
// Start from the end of the string, because subtraction should always start from the first number in the right.
    
int iResultInt;
    
    
int iSteam64Position strlen(szSteam64);
    
int iIntegerPosition strlen(szFirstInteger);
    
    
int iNumCount;
    
int iResultLen;
    
char szStringZeroes[MAX_INTEGERS];
    
    while(--
iSteam64Position > -1)
    {
        
iIntegerPosition -= 1;
        
        ++
iNumCount;
        
szFirstInteger[iIntegerPosition] = szSteam64[iSteam64Position];
        
szSecondInteger[iIntegerPosition] = szSubtractionString[iSteam64Position];
        
        
iFirstInteger StringToInt(szFirstInteger);
        
iSecondInteger StringToInt(szSecondInteger);
            
        
// Can we subtract without getting a negative number?
        
if(iFirstInteger >= iSecondInteger)
        {
            
iResultInt iFirstInteger iSecondInteger;
            
// 69056897
            
PrintToServer("Subtract %s from %s = %d"szFirstIntegerszSecondIntegeriResultInt);
            if(
iResultInt)
            {
                
IntToString(iResultIntszResultIntsizeof szResultInt);
                
                if( 
iNumCount != (iResultLen  strlen(szResultInt) ) )
                {
                    
SetStringZeros(szStringZeroessizeof szStringZeroesiNumCount iResultLen);
                }
                
                else
                {
                    
szStringZeroes "";
                }
            }
            
            else
            {
                
szResultInt "";
                
                
SetStringZeros(szStringZeroessizeof szStringZeroesiNumCount);
                
PrintToServer("String Zeroes: %s"szResultInt);
            }
            
            
Format(szSteam32sizeof szSteam32"%s%s%s"szStringZeroesszResultIntszSteam32);
            
PrintToServer("Current Progress: %s"szSteam32);
            
            
// Reset our stuff.
            
SetStringZeros(szFirstIntegersizeof(szFirstInteger), sizeof(szFirstInteger) - 1);
            
SetStringZeros(szSecondIntegersizeof(szSecondInteger), sizeof(szSecondInteger) - 1);
            
            
iIntegerPosition strlen(szFirstInteger);
            
iNumCount 0;
        }
        
        if(
iIntegerPosition 0)
        {
            
// We failed, and this calculation can not be done in pawn.
            
return false;
        }
        
        
// if not, lets add more numbers.
    
}
    
    
iSteam32 StringToInt(szSteam32);
    return 
true;
}

void SetStringZeros(char[] szStringint iSizeint iNumZeros)
{
    
int i;
    for(
0iNumZeros && iSizei++)
    {
        
szString[i] = '0';
    }
    
    
szString[i] = 0;

__________________
اَشْهَدُ اَنْ لَّآ اِلٰهَ اِلَّا اللہُ وَحْدَه لَا شَرِيْكَ لَه وَ اَشْهَدُ اَنَّ مُحَمَّدًا عَبْدُه وَرَسُوْلُه
No longer active in AMXX. Sorry.

Last edited by pokemonmaster; 07-15-2016 at 18:15.
pokemonmaster is offline
Byte
Senior Member
Join Date: Jun 2010
Location: 📦 CCSPlayer
Old 04-15-2017 , 00:31   Re: Convert STEAMID to Steam Community ID
Reply With Quote #352

Don't mean to bump an oldish thread but this might save someone a tiny bit of time later....

Here is the Sourcemod adaption of YamiKaitou's code here with asherkin's tip:
https://forums.alliedmods.net/showpo...&postcount=341
https://forums.alliedmods.net/showpo...&postcount=342

So far its passed all my tests but let me know if you find any issues.

PHP Code:
stock void GetSteamId2(const char[] szSteam64char[] szSteam2int iLen)
{
  
char szBase[18] = "76561197960265728";
  
int iBorrow 0;
  
char szSteam[18];
  
char szAccount[18];
  
int iY 0;
  
int iZ 0;
  
int iTemp 0;
  
  
//Copy steamid64 Over
  
Format(szSteamsizeof(szSteam), szSteam64);
  
  
//Determine iY
  
if (intval(szSteam[16]) % == 1) {
    
iY 1;
    
szSteam[16] = strval(intval(szSteam[16]) - 1);
  }
  
  
//Determine szAccount
  
for (int k 16>= 0; --k) {
    if (
iBorrow 0) {
      
iTemp intval(szSteam[k]) - 1;
      
      if (
iTemp >= intval(szBase[k])) {
        
iBorrow 0;
        
szAccount[k] = strval(iTemp intval(szBase[k]));
      }
      else {
        
iBorrow 1;
        
szAccount[k] = strval((iTemp 10) - intval(szBase[k]));
      }
    }
    else {
      if (
intval(szSteam[k]) >= intval(szBase[k])) {
        
iBorrow 0;
        
szAccount[k] = strval(intval(szSteam[k]) - intval(szBase[k]));
      }
      else {
        
iBorrow 1;
        
szAccount[k] = strval((intval(szSteam[k]) + 10) - intval(szBase[k]));
      }
    }
  }
  
  
//Divide szAccount answer by 2
  
iZ StringToInt(szAccount) / 2;
  
  
//Construct final steam2 id
  
Format(szSteam2iLen"STEAM_1:%d:%d"iYiZ);
}

int strval(const int iNum)
{
  return 
'0' + ((iNum >= && iNum <= 9) ? iNum 0);
}

int intval(int cNum)
{
  return (
cNum >= '0' && cNum <= '9') ? (cNum '0') : 0;

__________________
STEAM: /id/invexbyte | Github: InvexByte | My Community: Invex Gaming
My Plugins: Click Me!

Byte is offline
waylander3
Senior Member
Join Date: Sep 2015
Location: Russia, Norilsk
Old 08-05-2017 , 15:36   Re: Convert STEAMID to Steam Community ID
Reply With Quote #353

Hey guys, how can i convert U:1:0 to STEAM:1:0?
From steamID3 to steamID

Last edited by waylander3; 08-05-2017 at 15:48.
waylander3 is offline
arne1288
Veteran Member
Join Date: Apr 2012
Old 08-06-2017 , 18:07   Re: Convert STEAMID to Steam Community ID
Reply With Quote #354

Quote:
Originally Posted by waylander3 View Post
Hey guys, how can i convert U:1:0 to STEAM:1:0?
From steamID3 to steamID
From "[U:1:1532443]":

1532443 / 2 = 766221,5

Since the number is odd, it is then "STEAM_1:1:766221".

If the number was didn't give an odd number, e.g. "766221", it would have been "STEAM_1:0:766221"
__________________
Mostly known as "DarkDeviL".

Dropbox FastDL: Public folder will no longer work after March 15, 2017!
For more info, see the [SRCDS Thread], or the [HLDS Thread]
arne1288 is offline
waylander3
Senior Member
Join Date: Sep 2015
Location: Russia, Norilsk
Old 08-06-2017 , 21:14   Re: Convert STEAMID to Steam Community ID
Reply With Quote #355

Quote:
Originally Posted by arne1288 View Post
From "[U:1:1532443]":

1532443 / 2 = 766221,5

Since the number is odd, it is then "STEAM_1:1:766221".

If the number was didn't give an odd number, e.g. "766221", it would have been "STEAM_1:0:766221"
No, i mean on server. On my server (dota 2) i have U: format (in "status"), and i need STEAM: format.
waylander3 is offline
arne1288
Veteran Member
Join Date: Apr 2012
Old 08-07-2017 , 09:09   Re: Convert STEAMID to Steam Community ID
Reply With Quote #356

Quote:
Originally Posted by waylander3 View Post
No, i mean on server. On my server (dota 2) i have U: format (in "status"), and i need STEAM: format.
It sounded like you wanted the formula for converting it..

If you want the "status" command to show different output, you need to create a plugin that does it exactly as you want.

If you have any other plugins showing the one where you want the other, you need to adjust those plugins yourself, or hire someone to do it for you.
__________________
Mostly known as "DarkDeviL".

Dropbox FastDL: Public folder will no longer work after March 15, 2017!
For more info, see the [SRCDS Thread], or the [HLDS Thread]
arne1288 is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 09-27-2017 , 03:05   Re: Convert STEAMID to Steam Community ID
Reply With Quote #357

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)
__________________
Am I back? Well, we'll see.

Last edited by Powerlord; 09-27-2017 at 03:09.
Powerlord is offline
rautamiekka
Veteran Member
Join Date: Jan 2009
Location: Finland
Old 09-27-2017 , 03: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
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 04:35.


Powered by vBulletin®
Copyright ©2000 - 2018, vBulletin Solutions, Inc.
Theme made by Freecode