Raised This Month: $12 Target: $400
 3% 

stock FormatSteamID | Format steamid type to another | update 18.10.2022


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 10-17-2022 , 11:34   stock FormatSteamID | Format steamid type to another | update 18.10.2022
Reply With Quote #1

Snippet for format one type of Steamid to another type.
- Code is working with strings. Output type follow by these AuthIdType: AuthId_Steam2, AuthId_Steam3 and AuthId_SteamID64
- Callback return true when code actually formatted something into output string.


PHP Code:


/**
 * Script to format SteamID type to another type.
 *
 * @param input            Input string where began read SteamID.
 * @param output        Destination string buffer.
 * @param maxlength     Maximum length of output string buffer.
 * @param type            SteamID type to format. AuthId_Steam2,  AuthId_Steam3 and AuthId_SteamID64
 *
 * @return              True when script format another SteamID. False when nothing happened.
 */

stock bool FormatSteamID(const char[] inputchar[] outputint maxlengthAuthIdType type)
{
    
AuthIdType input_type AuthId_Engine// This indicate input value as ERROR

    
if(StrContains(input"STEAM_"false) != -1)
    {
        if(
strlen(input) <= 10 || input[7] != ':' || input[9] != ':')
        {
            return 
false;
        }

        
int a StringToInt(input[8]);
        
int b StringToInt(input[10]);

        if((
<= && <= 0) || || 0)
            return 
false;

        
input_type AuthId_Steam2;
    }
    else if(
StrContains(input"[U:1:"false) != -1)
    {
        if(
strlen(input) <= || input[2] != ':' || input[4] != ':' || StringToInt(input[5]) <= 0)
        {
            return 
false;
        }
        
        
input_type AuthId_Steam3;
    }


    
int higherbit = (1<<0)|(1<<20)|(1<<24); // 64-bit 76561197960265728 = STEAM_0:0:0
    
int result[2];


    if(
input_type == AuthId_Engine)
    {
        
int len strlen(input);

        if(
len 17)
            return 
false;
        
        for(
int c 0lenc++)
        {
            if(!
IsCharNumeric(input[c]))
                return 
false;
        }

        
StringToInt64(inputresult);

        if(
result[0] <= ||
            
result[1] < higherbit)
        {
            return 
false;
        }
        
        
input_type AuthId_SteamID64;
    }


    switch(
type)
    {
        case 
AuthId_Steam2:
        {
            if(
input_type == AuthId_Steam2)
                return 
false;

            if(
input_type == AuthId_Steam3)
            {
                
int W StringToInt(input[5]);
                
int Y W%2;
                
int Z = (W-Y) / 2;

                
Format(outputmaxlength"STEAM_0:%i:%i"YZ);

                return 
true;
            }
            else
            {
                
int W result[0];
                
int Y W%2;
                
int Z = (W-Y) / 2;

                
Format(outputmaxlength"STEAM_%i:%i:%i",
                                                    
result[1] >>> 24// "Universes" ?
                                                    
Y,
                                                    
Z);
                return 
true;
            }
        }
        case 
AuthId_Steam3:
        {
            if(
input_type == AuthId_Steam3)
                return 
false;

            if(
input_type == AuthId_Steam2)
            {
                
int Z StringToInt(input[10]);
                
int Y StringToInt(input[8]);
                
int W Z*2+Y;

                
Format(outputmaxlength"[U:1:%i]"W);

                return 
true;
            }
            else
            {
                
int W result[0];

                
Format(outputmaxlength"[U:1:%i]"W);
                
                return 
true;
            }
        }
        case 
AuthId_SteamID64:
        {
            if(
input_type == AuthId_SteamID64)
                return 
false;

            if(
input_type == AuthId_Steam2)
            {
                
int Z StringToInt(input[10]);
                
int Y StringToInt(input[8]);

                
//W=Z*2+V+Y
                
int V higherbit;
                
int W Z*2+Y;

                
result[0] = W;
                
result[1] = V;

                
Int64ToString(resultoutputmaxlength);

                return 
true;
            }
            else
            {
                
int V higherbit;
                
int W StringToInt(input[5]);

                
result[0] = W;
                
result[1] = V;

                
Int64ToString(resultoutputmaxlength);

                return 
true;
            }
        }
    }

    return 
false;

- This code not have all kinds steam id validation checks.
- This code may not work 100%
Please, mention if you found bug or mistake of this.

- I made this half-sleep, so there maybe mistakes.
- I did not look ahead, is there already this kind snippet some where here.

*edit
18.10.2022 UPDATE
- I added some number checks and string length checks to avoid errors.

Last edited by Bacardi; 10-18-2022 at 09:23. Reason: lot of changes. Updated
Bacardi is offline
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 18:45.


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