Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- -- Function: get_steamid64
- -- Purpose: Check whether we have a regular steam ID, or a 64 bit steam ID and return a 64 bit steam ID either way
- -- Arguments: $steam_arg - Either a regular, or a 64 bit steam ID
- -- Returns: The 64 bit steam ID, or false if an invalid argument is provided
- */
- private function get_steamid64($steam_arg)
- {
- if (preg_match('/^STEAM_[0-9]:[0-9]:[0-9]{1,}/i', $steam_arg))
- {
- return $this->calculate_steamid64($steam_arg);
- }
- else if (preg_match('/^76561197960[0-9]{6}$/i', $steam_arg))
- {
- return $steam_arg;
- }
- else
- {
- return false;
- }
- }
- /*
- -- Function: calculate_steamid64
- -- Purpose: Translate a steam ID to a 64 bit steam id as used by Valve
- -- Arguments: $steam_id - The steam ID to translate
- -- Returns: The 64 bit steam ID, or false if an invalid steam ID is provided
- */
- public function calculate_steamid64($steam_id)
- {
- if (preg_match('/^STEAM_[0-9]:[0-9]:[0-9]{1,}/i', $steam_id))
- {
- $steam_id = str_replace("_", ":", $steam_id);
- list($part_one, $part_two, $part_three, $part_four) = explode(':', $steam_id);
- $result = bcadd('76561197960265728', $part_four * 2);
- $result = bcadd($result, $part_two);
- return bcadd($result, $part_three);
- }
- else
- {
- return false;
- }
- }
- /*
- -- Function: calculate_steamid
- -- Purpose: Translate a 64 bit steam ID to a steam id as used by Valve
- -- Arguments: $steam_id64 - The 64 bit steam ID to translate
- -- Returns: The steam ID, or false if an invalid 64 bit steam ID is provided
- */
- public function calculate_steamid($steam_id64)
- {
- if (preg_match('/^76561197960[0-9]{6}$/i', $steam_id64))
- {
- $part_one = substr( $steam_id64, -1) % 2 == 0 ? 0 : 1;
- $part_two = bcsub( $steam_id64, '76561197960265728' );
- $part_two = bcsub( $part_two, $part_one );
- $part_two = bcdiv( $part_two, 2 );
- return "STEAM_0:" . $part_one . ':' . $part_two;
- }
- else
- {
- return false;
- }
- }
Add Comment
Please, Sign In to add comment