View Single Post
devicenull
Veteran Member
Join Date: Mar 2004
Location: CT
Old 02-22-2009 , 21:42   Re: Convert STEAMID to Steam Community ID
Reply With Quote #135

Some MySQL stored procedures to do this for you (Note: Assumes you are entering these using the command line client, otherwise you may need to fiddle with the delimiters)

Code:
DELIMITER | 
drop function SteamToInt|

create function SteamToInt(steamid varchar(64))
RETURNS bigint(64)
BEGIN
	declare authserver int;
	declare authid int;

	set authserver = cast(substr(steamid,9,1) as unsigned integer);
	set authid = cast(substr(steamid,11) as unsigned integer);
	return 76561197960265728+(authid*2)+authserver;
END |

drop function IntToSteam|

create function IntToSteam(communityid bigint(64))
RETURNS varchar(64)
BEGIN
	declare ret varchar(64);
	declare authserver int;
	declare authid bigint;

	set communityid = communityid-76561197960265728;
	set authserver = mod(communityid,2);
	set communityid = communityid-authserver;
	set authid = communityid/2;
	set ret = concat("STEAM_0:",authserver,":",authid);
	return ret;
END |
DELIMITER ;
Usage:
Code:
select SteamToInt("STEAM_0:1:1199"), IntToSteam(76561197960268127);
__________________
Various bits of semi-useful code in a bunch of languages: http://code.devicenull.org/
devicenull is offline