Raised This Month: $32 Target: $400
 8% 

Convert STEAMID to Steam Community ID


Post New Thread Reply   
 
Thread Tools Display Modes
8088
Veteran Member
Join Date: Jan 2008
Old 02-04-2008 , 01:31   Re: Convert STEAMID to Steam Community ID
Reply With Quote #41

Just wanted to thank you and show you what you made possible on my vBulletin forums (that still need a lot of work) :





This was created with your snippet converted to php by KoST, and some other nice code which he kindly provided.
8088 is offline
voogru
Inspector Javert
Join Date: Oct 2004
Old 02-04-2008 , 04:55   Re: Convert STEAMID to Steam Community ID
Reply With Quote #42

Quote:
Originally Posted by 8088 View Post
Just wanted to thank you and show you what you made possible on my vBulletin forums (that still need a lot of work) :





This was created with your snippet converted to php by KoST, and some other nice code which he kindly provided.
Ooh that looks spiffy.

Care to share it? I'd like to stick it on my forum
voogru is offline
Scuzzy
Senior Member
Join Date: Oct 2007
Old 02-04-2008 , 18:14   Re: Convert STEAMID to Steam Community ID
Reply With Quote #43

Quote:
Originally Posted by 8088 View Post
Just wanted to thank you and show you what you made possible on my vBulletin forums (that still need a lot of work) :



This was created with your snippet converted to php by KoST, and some other nice code which he kindly provided.
We have something similar, but are the icons actually from the steam friends? If so, how'd you translate the steam_friends id into an avatar gif?

Thanks!
Scuzzy
Scuzzy is offline
Josiah
New Member
Join Date: Feb 2008
Old 02-04-2008 , 21:25   Re: Convert STEAMID to Steam Community ID
Reply With Quote #44

I had a quick question about this. I see that it is possible to track from a friend id to a steam_id. Well there was a hacker on my server that I banned and, the genius he was, he added me to friends so I would know his name. I forgot to grab his steam_id and need it in order to post it to our forums.

So my question is. How do I get someones friend id and what format is it in? Lets say for example I wanted to find a friend id from this:

http://steamcommunity.com/id/royalbouchdag

That is my friend the TF2 hacker. Any help would rock

Last edited by Josiah; 02-04-2008 at 21:28.
Josiah is offline
Nican
Veteran Member
Join Date: Jan 2006
Location: NY
Old 02-04-2008 , 22:23   Re: Convert STEAMID to Steam Community ID
Reply With Quote #45

76561197985873864

If you go over the "Add to your friends list", and check the link, you will see his friends id
__________________
http://www.nican132.com
I require reputation!
Nican is offline
Send a message via ICQ to Nican Send a message via MSN to Nican
8088
Veteran Member
Join Date: Jan 2008
Old 02-05-2008 , 10:32   Re: Convert STEAMID to Steam Community ID
Reply With Quote #46

Quote:
Originally Posted by voogru View Post
Ooh that looks spiffy.

Care to share it? I'd like to stick it on my forum :D
Sure, I'd be glad to share it :)

First you need to get the SteamID, you can do this by letting your users fill this in in their user profiles. Then you calculate the connected friendid for it with some php :
PHP Code:
$friendid steam2friend($profilefield['value']);

function 
steam2friend($steam_id){
    
$steam_id=strtolower($steam_id);
    if (
substr($steam_id,0,7)=='steam_0') {
        
$tmp=explode(':',$steam_id);
        if ((
count($tmp)==3) && is_numeric($tmp[1]) && is_numeric($tmp[2])){
            return 
bcadd((($tmp[2]*2)+$tmp[1]),'76561197960265728');
        }else return 
false;
        }else{
            return 
false;
        }
    } 
The result allows you to create links to various Steamcommunity links, for example :
PHP Code:
<a href="http://steamcommunity.com/profiles/'.$friendid.'">View SteamID Page</a
And with the Steam browser protocol you can create more handy links :
PHP Code:
<a href="steam://friends/add/'.$friendid.'">Add to your Steam friends</a
To retrieve the actual status of the user, you need to read out the actual SteamID page at the Steam community and look for unique html tags or parts. And to not 'hammer' the Steam pages every time a user profile is viewed, it is wise to cache the results, for which memcached is a great tool.
PHP Code:
$ret=get_steam_stats($friendid);

function 
get_steam_stats($id){
    
    
$mc=new Memcache;
    if (!@
$mc->connect('localhost', <the port number to which memcached is listening to>)) {
        echo 
'memcached unavailable';
     return 
false;
    }
    
    
$ret=@$mc->get('xd'.$id);
    if (!
$ret){
        
$data=file_get_contents("http://steamcommunity.com/profiles/".$id);    
        
$ret=array(); 
This part reads out the SteamID page for the calculated $friendid. To put usefull information like the online status into an array, you can do the following :
PHP Code:
        $ret['uid']=intval($_GET['u']);
        if (
strpos($data,'<h2>Private Profile</h2>')!==false) {
            
$ret['private']=1;
        }else{
            if (
strpos($data,'status_online.gif')!==false){
                
$ret['online']=1;
            }else if ((
$p1=strpos($data,'<p id="statusInGameText">'))!==false){
                
                
$p2=strpos($data,'<',$p1+25);
                
$tmp=substr($data,$p1+25,$p2-$p1-25);
                
$ret['ingame']=$tmp;
                
$ret['join']='steam://friends/joingame/'.$id;            
            } 
Now that you have the current status of the user, you can show it in the userprofile by doing the following :
PHP Code:
    if (isset($ret['private'])){
        echo 
'Online status unavailable';
    }
    else{
        if (isset(
$ret['ingame'])) 
        echo 
'User is In-Game playing '.$ret['ingame'].' - <a href="'.$ret['join'].'">Join</a>;
        if (isset($ret['
online'])) 
        echo '
User is online';
        if (isset($ret['
offline']))
        echo '
User is offline '.$ret['offline'];

On my vBulletin forums I give users the choice to hide the the Steam Community links. In case you're using vB as well and need help on implementing this, let me know. The code above is quite generic and can be used on any page or forumsoftware.

Quote:
Originally Posted by Scuzzy View Post
We have something similar, but are the icons actually from the steam friends? If so, how'd you translate the steam_friends id into an avatar gif?
The Steam avatars are first downloaded to a local folder on the webserver.

This code takes care of that :
PHP Code:
            if (($p1=strpos($data,'<div class="avatarFull">'))!==false){
                
$p1=strpos($data,'<',$p1+24);
                
$p2=strpos($data,'>',$p1+1);
                
$tmp=substr($data,$p1,$p2-$p1+1);
                
$link_full=get_link_src($tmp);
                
download($link_full,'/folder/where/avatars/should/be/stored/prefix_full'.$ret['uid'].'.jpg');
                
$ret['img_full']=$tmp;
                
                
$tmp=str_replace('_full','',$tmp);
                
$link_small=get_link_src($tmp);
                
download($link_small,'/folder/where/avatars/should/be/stored/prefix_small'.$ret['uid'].'.jpg');
                
$ret['img_small']=$tmp;
            }

function 
get_link_src($data){
    
$p1=strpos($data,chr(34));
    
$p2=strpos($data,chr(34),$p1+1);
    return 
substr($data,$p1+1,$p2-$p1-1);
}
 
function 
download ($url,$target){    
    
$data=file_get_contents($url);
    if (
$data) {
        
file_put_contents($target,$data);    
    }

And then they are shown in the userprofile with this code :
PHP Code:
<img src="/folder/where/avatars/should/be/stored/prefix_small'.$userinfo[userid].'.jpg" alt="Steam avatar"/> 

The result as I have it now can be seen here.
Let me know if things are still unclear :)

Last edited by 8088; 02-05-2008 at 10:36.
8088 is offline
bl4nk
SourceMod Developer
Join Date: Jul 2007
Old 02-05-2008 , 10:46   Re: Convert STEAMID to Steam Community ID
Reply With Quote #47

Very nicely done! Thanks for sharing too. +karma
bl4nk is offline
Jheshka
Senior Member
Join Date: Dec 2005
Old 02-08-2008 , 19:12   Re: Convert STEAMID to Steam Community ID
Reply With Quote #48

Wow... Very nice.
__________________
James
Jheshka is offline
mindstormmaster
New Member
Join Date: Feb 2008
Old 02-13-2008 , 14:02   Re: Convert STEAMID to Steam Community ID
Reply With Quote #49

It looks like there's some code missing. What you have there doesn't store anything back to Memcached, making it irrelevant in this example. Your comments are great, but could you post the complete script?
mindstormmaster is offline
KoST
Senior Member
Join Date: Jul 2005
Old 02-13-2008 , 19:58   Re: Convert STEAMID to Steam Community ID
Reply With Quote #50

Quote:
Originally Posted by mindstormmaster View Post
It looks like there's some code missing. What you have there doesn't store anything back to Memcached, making it irrelevant in this example. Your comments are great, but could you post the complete script?
here is my original code:
PHP Code:
<?php
 
function get_steam_stats($id){
    
    
$mc=new Memcache;
    if (!
$mc->connect('localhost'11211)) return false;
    
    
$ret=$mc->get('xd'.$id);
    if (!
$ret){
        
$data=file_get_contents("http://steamcommunity.com/profiles/".$id);    
        
$ret=array();
        
        
        
        if (
strpos($data,'<h2>Private Profile</h2>')!==false) {
            
$ret['private']=1;
        }else{
            if (
strpos($data,'status_online.gif')!==false){
                
$ret['online']=1;
            }else if ((
$p1=strpos($data,'<p id="statusInGameText">'))!==false){
                
                
$p2=strpos($data,'<',$p1+25);
                
$tmp=substr($data,$p1+25,$p2-$p1-25);
                
$ret['ingame']=$tmp;
                
$ret['join']='steam://friends/joingame/'.$id;
 
                
            }else{ 
                if ((
$p1=strpos($data,'<p id="statusOfflineText">'))!==false){
                    
$p2=strpos($data,'<',$p1+26);
                    
$tmp=substr($data,$p1+26,$p2-$p1-26);
                    
$ret['offline']=$tmp;
                }
            }
            
            if ((
$p1=strpos($data,'<div class="avatarFull">'))!==false){
                
$p1=strpos($data,'<',$p1+24);
                
$p2=strpos($data,'>',$p1+1);
                
$tmp=substr($data,$p1,$p2-$p1+1);
                
$link_full=get_link_src($tmp);
                
gaben_downloadz0r($link_full,'/home/lol/public_html/avatars/lol_full'.$id.'.jpg');
                
$ret['img_full']=$tmp;
                
                
$tmp=str_replace('_full','',$tmp);
                
$link_small=get_link_src($tmp);
                
gaben_downloadz0r($link_small,'/home/lol/public_html/avatars/lol_small'.$id.'.jpg');
                
$ret['img_small']=$tmp;
            }
                
            if ((
$p1=strpos($data,'Steam Rating:</div>'))!==false){
                
$p2=strpos($data,'<',$p1+19);
                
$tmp=substr($data,$p1+19,$p2-$p1-19);
                
$ret['rating']=trim($tmp);
            }    
            
            if ((
$p1=strpos($data,'Member since:</div>'))!==false){
                
$p2=strpos($data,'<',$p1+19);
                
$tmp=substr($data,$p1+19,$p2-$p1-19);
                
$ret['member']=trim($tmp);
            }
            
            if ((
$p1=strpos($data,'Playing time:</div>'))!==false){
                
$p2=strpos($data,'<',$p1+19);
                
$tmp=substr($data,$p1+19,$p2-$p1-19);
                
$ret['time']=trim($tmp);
            }
            
        }
        
$mc->set('xd'.$id,$ret,MEMCACHE_COMPRESSED,1800);        
        
        
        
    }
    
    
 
    return 
$ret;
        
}
 
 
function 
get_link_src($data){
    
$p1=strpos($data,chr(34));
    
$p2=strpos($data,chr(34),$p1+1);
    return 
substr($data,$p1+1,$p2-$p1-1);
}
 
function 
gaben_downloadz0r ($url,$target){    
    
$data=file_get_contents($url);
    if (
$data) {
        
file_put_contents($target,$data);    
    }
}
?>
__________________

Last edited by KoST; 02-13-2008 at 20:01.
KoST is offline
Reply



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 03:45.


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