View Single Post
DJ Tsunami
DJ Post Spammer
Join Date: Feb 2008
Location: The Netherlands
Old 08-22-2014 , 04:55   Re: Convert STEAMID to Steam Community ID
Reply With Quote #336

Here are some snippets that support the new Steam3 format.

PHP (with GMP, but should be easy to convert to BCMath):

PHP Code:
function getCommunityId($steamId)
{
    
$accountId 0;

    if (
preg_match('/^STEAM_[0-9]:([0-9]):([0-9]+)$/i'$steamId$matches)) {
        
$accountId $matches[1] + ($matches[2] * 2);
    }
    if (
preg_match('/^\[U:[0-9]:([0-9]+)\]$/i'$steamId$matches)) {
        
$accountId $matches[1];
    }

    return 
gmp_strval(gmp_add('76561197960265728'$accountId));

MySQL (it's a bit of a monster):

PHP Code:
SELECT
    
(CASE
        
WHEN steam_id LIKE "STEAM_%" THEN 76561197960265728 CAST(SUBSTRING(steam_id91) AS UNSIGNED) + CAST(SUBSTRING(steam_id11) * AS UNSIGNED)
        
WHEN steam_id LIKE "[U:%]" THEN 76561197960265728 CAST(SUBSTRING(steam_id6CHAR_LENGTH(steam_id) - 6) AS UNSIGNED)
    
END) AS community_id 
__________________
Advertisements | REST in Pawn - HTTP client for JSON REST APIs
Please do not PM me with questions. Post in the plugin thread.

Last edited by DJ Tsunami; 08-22-2014 at 05:20.
DJ Tsunami is offline