View Single Post
pokemonmaster
princess milk
Join Date: Nov 2010
Location: Somewhere in this world :)
Old 07-15-2016 , 17: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 17:15.
pokemonmaster is offline