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

Convert STEAMID to Steam Community ID


Post New Thread Reply   
 
Thread Tools Display Modes
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 11-15-2014 , 10:10   Re: Convert STEAMID to Steam Community ID
Reply With Quote #341

Quote:
Originally Posted by nomy View Post
Hey guys, anyone has a block that converts Community ID (Steam64) to Steam ID? I need it for sourcemod scripting.
I have one for AMXModX, you should be able to easily convert it to Sourcemod. I can't remember if it works 100% since it I haven't published my plugin update yet.

Code:
new const szBase[] = "76561197960265728";

stock getSteam2(const szSteam64[], szSteam2[], iLen)
{
	new iBorrow = 0;
	new szSteam[18];
	new szAccount[18];
	new iY = 0;
	new iZ = 0;
	new iTemp = 0;
	
	arrayset(szAccount, '0', charsmax(szAccount));
	copy(szSteam, charsmax(szSteam), szSteam64);
	
	
	if (intval(szSteam[16]) % 2 == 1)
	{
		iY = 1;
		szSteam[16] = strval(intval(szSteam[16]) - 1);
	}
	
	for (new k = 16; k >= 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]));
			}
		}
	}
	
	iZ = str_to_num(szAccount);
	iZ /= 2;
	
	formatex(szSteam2, iLen, "STEAM_0:%d:%d", iY, iZ);
}

stock getSteam64(const szSteam2[], szSteam64[18])
{
	new iCarry = 0;
	new szAccount[18];
	new iTemp = 0;
	
	copy(szSteam64, charsmax(szSteam64), szBase);
	formatex(szAccount, charsmax(szAccount), "%s", szSteam2[10]);
	formatex(szAccount, charsmax(szAccount), "%017d", str_to_num(szAccount));
	
	szSteam64[16] = strval(intval(szSteam64[16]) + intval(szSteam2[8]));
	
	for (new j = 0; j < 2; j++)
	{
		for (new k = 16; k >= 0; k--)
		{
			if (iCarry > 0)
			{
				iTemp = intval(szSteam64[k-iCarry+1]) + 1;
				
				if (iTemp > 9)
				{
					iTemp -= 10;
					szSteam64[k-iCarry+1] = strval(iTemp);
					iCarry += 1;
				}
				else
				{
					szSteam64[k-iCarry+1] = strval(iTemp);
					iCarry = 0;
				}
				
				k++;
			}
			else
			{
				iTemp = intval(szSteam64[k]) + intval(szAccount[k]);
				
				if (iTemp > 9)
				{
					iCarry = 1;
					iTemp -= 10;
				}
				
				szSteam64[k] = strval(iTemp);
			}
		}
	}
}

strval(const iNum)
{
	switch (iNum)
	{
		case 0:		return '0';
		case 1:		return '1';
		case 2:		return '2';
		case 3:		return '3';
		case 4:		return '4';
		case 5:		return '5';
		case 6:		return '6';
		case 7:		return '7';
		case 8:		return '8';
		case 9:		return '9';
	}
	
	return '0';
}

intval(cNum)
{
	switch (cNum)
	{
		case '0':		return 0;
		case '1':		return 1;
		case '2':		return 2;
		case '3':		return 3;
		case '4':		return 4;
		case '5':		return 5;
		case '6':		return 6;
		case '7':		return 7;
		case '8':		return 8;
		case '9':		return 9;
	}
	
	return 0;
}
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 11-15-2014 , 11:13   Re: Convert STEAMID to Steam Community ID
Reply With Quote #342

Quote:
Originally Posted by YamiKaitou View Post
Code:
strval(const iNum)
{
	switch (iNum)
	{
		case 0:		return '0';
		case 1:		return '1';
		case 2:		return '2';
		case 3:		return '3';
		case 4:		return '4';
		case 5:		return '5';
		case 6:		return '6';
		case 7:		return '7';
		case 8:		return '8';
		case 9:		return '9';
	}
	
	return '0';
}

intval(cNum)
{
	switch (cNum)
	{
		case '0':		return 0;
		case '1':		return 1;
		case '2':		return 2;
		case '3':		return 3;
		case '4':		return 4;
		case '5':		return 5;
		case '6':		return 6;
		case '7':		return 7;
		case '8':		return 8;
		case '9':		return 9;
	}
	
	return 0;
}
Code:
strval(const iNum)
{
    return '0' + ((iNum >= 0 && iNum <= 9) ? iNum : 0);
}

intval(cNum)
{
    return (cNum >= '0' && cNum <= '9') ? (cNum - '0') : 0;
}
__________________
asherkin is offline
JayBird2025
New Member
Join Date: Mar 2016
Old 03-04-2016 , 07:37   Re: Convert STEAMID to Steam Community ID
Reply With Quote #343

how could you add/implement this into a website like https://steamid.io/
JayBird2025 is offline
DarthNinja
SourceMod Plugin Approver
Join Date: Mar 2009
Location: PreThinkHook()
Old 03-11-2016 , 09:23   Re: Convert STEAMID to Steam Community ID
Reply With Quote #344

Quote:
Originally Posted by JayBird2025 View Post
how could you add/implement this into a website like https://steamid.io/
Find / write a PHP version of the function, and implement it on your site
__________________
DarthNinja is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 03-15-2016 , 08:37   Re: Convert STEAMID to Steam Community ID
Reply With Quote #345

Quote:
Originally Posted by DarthNinja View Post
Find / write a PHP version of the function, and implement it on your site
This is what I use...

PHP Code:
    function CommunityID2SteamID($communityid)
    {
        
$steamid 'STEAM_1:';
        
$z = ($communityid 76561197960265728) / 2;

        if (
$z floor($z) == 0.5)
            
$steamid.='1:';
        else
            
$steamid.='0:';

        
$steamid.=floor($z);
        return 
$steamid;
    }

    function 
SteamID2CommunityID($steamid
    { 
        
$parts explode(':'str_replace('STEAM_''' ,$steamid)); 
        return 
bcadd(bcadd('76561197960265728'$parts['1']), bcmul($parts['2'], '2')); 
    } 
__________________
Neuro Toxin is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 03-15-2016 , 10:09   Re: Convert STEAMID to Steam Community ID
Reply With Quote #346

Quote:
Originally Posted by Neuro Toxin View Post
This is what I use...

PHP Code:
    function CommunityID2SteamID($communityid)
    {
        
$steamid 'STEAM_1:';
        
$z = ($communityid 76561197960265728) / 2;

        if (
$z floor($z) == 0.5)
            
$steamid.='1:';
        else
            
$steamid.='0:';

        
$steamid.=floor($z);
        return 
$steamid;
    }

    function 
SteamID2CommunityID($steamid
    { 
        
$parts explode(':'str_replace('STEAM_''' ,$steamid)); 
        return 
bcadd(bcadd('76561197960265728'$parts['1']), bcmul($parts['2'], '2')); 
    } 
Just be aware that this will fail on 32-bit systems as PHP uses 32-bit integers for integer math on them. Unless PHP changed this in the later 5.x versions or in 7.0.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 03-15-2016 , 10:13   Re: Convert STEAMID to Steam Community ID
Reply With Quote #347

Didn't realise that.

Apon checking my web server, it does run 64-bit.

Edit: Found this
__________________

Last edited by Neuro Toxin; 03-15-2016 at 10:20.
Neuro Toxin is offline
Vergil333
Member
Join Date: Apr 2016
Old 04-15-2016 , 12:59   Re: Convert STEAMID to Steam Community ID
Reply With Quote #348

Hello everyone! I'm new here

I've got question for you.

STEAM_X:Y:Z

Thanks to you guys, I know how to transfer SteamID64 to community ID.

But what about X? Should it be 0 or 1?

I am converting steam's ids from web site to CS:GO server's whitelist.txt.
https://forums.alliedmods.net/showthread.php?p=715068

Can X be set 1 for every ID to let users join?

Last edited by Vergil333; 04-15-2016 at 13:14.
Vergil333 is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 04-15-2016 , 19:18   Re: Convert STEAMID to Steam Community ID
Reply With Quote #349

Csgo uses 1
__________________
Neuro Toxin is offline
Vergil333
Member
Join Date: Apr 2016
Old 04-16-2016 , 01:23   Re: Convert STEAMID to Steam Community ID
Reply With Quote #350

Quote:
Originally Posted by Neuro Toxin View Post
Csgo uses 1
That's all I need. Thank you
Vergil333 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 15:24.


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