Guest User

Untitled

a guest
Oct 22nd, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.11 KB | None | 0 0
  1.     public static function convertCommunityIdToSteamId($communityId) {
  2.         $steamId1 = substr($communityId, -1) % 2;
  3.         $steamId2a = intval(substr($communityId, 0, 4)) - 7656;
  4.         $steamId2b = substr($communityId, 4) - 1197960265728;
  5.         $steamId2b = $steamId2b - $steamId1;
  6.  
  7.         if($steamId2a <= 0 && $steamId2b <= 0) {
  8.             throw new SteamCondenserException("SteamID $communityId is too small.");
  9.         }
  10.  
  11.         return "STEAM_0:$steamId1:" . (($steamId2a + $steamId2b) / 2);
  12.     }
  13.  
  14.     public static function convertSteamIdToCommunityId($steamId) {
  15.         if($steamId == 'STEAM_ID_LAN' || $steamId == 'BOT') {
  16.             throw new SteamCondenserException("Cannot convert SteamID \"$steamId\" to a community ID.");
  17.         }
  18.         if(preg_match('/^STEAM_[0-1]:[0-1]:[0-9]+$/', $steamId) == 0) {
  19.             throw new SteamCondenserException("SteamID \"$steamId\" doesn't have the correct format.");
  20.         }
  21.  
  22.         $steamId = explode(':', substr($steamId, 6));
  23.         $steamId = $steamId[1] + $steamId[2] * 2 + 1197960265728;
  24.  
  25.         return '7656' . $steamId;
  26.     }
Add Comment
Please, Sign In to add comment