Как получить по SteamID64 получить остальные?

.samuello

Участник
Сообщения
69
Реакции
53
Всем привет, каким образом получить SteamID, SteamID3, SteamID32 и т.д с помощью SteamAPI имея только SteamID64?
 

Kruzya

Участник
Сообщения
12,970
Реакции
10,914
  • Команда форума
  • #2
Через Steam API - никак. Там банальная математика.
includes/classes/CSteamId.php:
<?php
class CSteamId {
  private static $_cache = [];

  public $IsEmulated = false;

  public $CommunityID;
  public $AccountID;
  public $v2;
  public $v3;

  public static function factory($sid, $GameID = 0) {
    $AccountID = self::ResolveToAccountID($sid);
    if ($AccountID == -1)
      throw new InvalidArgumentException("Invalid SteamID passed.");

    if (!isset(self::$_cache[$AccountID])) {
      $CacheEntry = new self();
      $CacheEntry->CommunityID  = bcadd('76561197960265728', $AccountID, 0);
      $CacheEntry->AccountID    = $AccountID;
      $CacheEntry->v3           = sprintf('[U:1:%d]', $AccountID);
      $CacheEntry->v2           = sprintf('STEAM_%d:%d:%d', $GameID, ($AccountID % 2), $AccountID / 2);

      if ($AccountID > 2147483647) {
        $CacheEntry->IsEmulated = true;
      }

      self::$_cache[$AccountID] = $CacheEntry;
    }

    return self::$_cache[$AccountID];
  }

  public static function validate($sid) {
    return (self::ResolveToAccountID($sid) != -1);
  }

  private static function ResolveToAccountID($sid) {
    if (strncmp('STEAM_', $sid, 6) == 0) {
      $parts = explode(':', $sid);
      if (count($parts) != 3)
        return -1;

      return intval($parts[2] * 2) + intval($parts[1]);
    }

    if (strncmp('[U:1', $sid, 4) == 0) {
      $parts = explode(':', $sid);
      if (count($parts) != 3)
        return -1;

      return intval(substr($parts[2], 0, -1));
    }

    if (strncmp('7656', $sid, 4) == 0 && strlen($sid) == 17) {
      return intval(bcsub($sid, '76561197960265728', 0));
    }

    // we don't know, what is this.
    return -1;
  }
}
index.php:
<?php
include('includes/classes/CSteamId.php');

var_dump(CSteamId::factory('STEAM_0:0:55665612'));
 

.samuello

Участник
Сообщения
69
Реакции
53
Через Steam API - никак. Там банальная математика.
includes/classes/CSteamId.php:
<?php
class CSteamId {
  private static $_cache = [];

  public $IsEmulated = false;

  public $CommunityID;
  public $AccountID;
  public $v2;
  public $v3;

  public static function factory($sid, $GameID = 0) {
    $AccountID = self::ResolveToAccountID($sid);
    if ($AccountID == -1)
      throw new InvalidArgumentException("Invalid SteamID passed.");

    if (!isset(self::$_cache[$AccountID])) {
      $CacheEntry = new self();
      $CacheEntry->CommunityID  = bcadd('76561197960265728', $AccountID, 0);
      $CacheEntry->AccountID    = $AccountID;
      $CacheEntry->v3           = sprintf('[U:1:%d]', $AccountID);
      $CacheEntry->v2           = sprintf('STEAM_%d:%d:%d', $GameID, ($AccountID % 2), $AccountID / 2);

      if ($AccountID > 2147483647) {
        $CacheEntry->IsEmulated = true;
      }

      self::$_cache[$AccountID] = $CacheEntry;
    }

    return self::$_cache[$AccountID];
  }

  public static function validate($sid) {
    return (self::ResolveToAccountID($sid) != -1);
  }

  private static function ResolveToAccountID($sid) {
    if (strncmp('STEAM_', $sid, 6) == 0) {
      $parts = explode(':', $sid);
      if (count($parts) != 3)
        return -1;

      return intval($parts[2] * 2) + intval($parts[1]);
    }

    if (strncmp('[U:1', $sid, 4) == 0) {
      $parts = explode(':', $sid);
      if (count($parts) != 3)
        return -1;

      return intval(substr($parts[2], 0, -1));
    }

    if (strncmp('7656', $sid, 4) == 0 && strlen($sid) == 17) {
      return intval(bcsub($sid, '76561197960265728', 0));
    }

    // we don't know, what is this.
    return -1;
  }
}
index.php:
<?php
include('includes/classes/CSteamId.php');

var_dump(CSteamId::factory('STEAM_0:0:55665612'));

Я всё перекопал, а на самом деле вот оно что
 
Сверху Снизу