hlsdk

steamid

Jul 24th, 2010
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.94 KB | None | 0 0
  1.     /*
  2.     -- Function:    get_steamid64
  3.     -- Purpose: Check whether we have a regular steam ID, or a 64 bit steam ID and return a 64 bit steam ID either way
  4.     -- Arguments:   $steam_arg - Either a regular, or a 64 bit steam ID
  5.     -- Returns: The 64 bit steam ID, or false if an invalid argument is provided
  6.     */
  7.     private function get_steamid64($steam_arg)
  8.     {
  9.         if (preg_match('/^STEAM_[0-9]:[0-9]:[0-9]{1,}/i', $steam_arg))
  10.         {
  11.             return $this->calculate_steamid64($steam_arg);
  12.         }
  13.         else if (preg_match('/^76561197960[0-9]{6}$/i', $steam_arg))
  14.         {
  15.             return $steam_arg;
  16.         }
  17.         else
  18.         {
  19.             return false;
  20.         }
  21.     }
  22.  
  23.     /*
  24.     -- Function:    calculate_steamid64
  25.     -- Purpose: Translate a steam ID to a 64 bit steam id as used by Valve
  26.     -- Arguments:   $steam_id - The steam ID to translate
  27.     -- Returns: The 64 bit steam ID, or false if an invalid steam ID is provided
  28.     */
  29.     public function calculate_steamid64($steam_id)
  30.     {
  31.         if (preg_match('/^STEAM_[0-9]:[0-9]:[0-9]{1,}/i', $steam_id))
  32.         {
  33.             $steam_id = str_replace("_", ":", $steam_id);
  34.             list($part_one, $part_two, $part_three, $part_four) = explode(':', $steam_id);
  35.             $result = bcadd('76561197960265728', $part_four * 2);
  36.             $result = bcadd($result, $part_two);
  37.             return bcadd($result, $part_three);
  38.         }
  39.         else
  40.         {
  41.             return false;
  42.         }
  43.     }
  44.  
  45.     /*
  46.     -- Function:    calculate_steamid
  47.     -- Purpose: Translate a 64 bit steam ID to a steam id as used by Valve
  48.     -- Arguments:   $steam_id64 - The 64 bit steam ID to translate
  49.     -- Returns: The steam ID, or false if an invalid 64 bit steam ID is provided
  50.     */
  51.     public function calculate_steamid($steam_id64)
  52.     {
  53.         if (preg_match('/^76561197960[0-9]{6}$/i', $steam_id64))
  54.         {
  55.             $part_one = substr( $steam_id64, -1) % 2 == 0 ? 0 : 1;
  56.             $part_two = bcsub( $steam_id64, '76561197960265728' );
  57.             $part_two = bcsub( $part_two, $part_one );
  58.             $part_two = bcdiv( $part_two, 2 );
  59.             return "STEAM_0:" . $part_one . ':' . $part_two;
  60.         }
  61.         else
  62.         {
  63.             return false;
  64.         }
  65.     }
Add Comment
Please, Sign In to add comment