Пример #1
0
 /**
  * Returns a SteamID instance constructed from a steamcommunity.com
  * URL form, or simply from a vanity url.
  *
  * Please note that you must implement vanity lookup function using
  * ISteamUser/ResolveVanityURL api interface yourself.
  *
  * Callback function must return resolved SteamID as a string,
  * or null if API returns success=42 (meaning no match).
  * 
  * It's up to you to throw any exceptions if you wish to do so.
  *
  * This function can act as a pass-through for rendered Steam2/Steam3 ids.
  *
  * Example implementation is provided in `VanityURLs.php` file.
  *
  * @param string $Value Input URL
  * @param string $VanityCallback Callback which is called when a vanity lookup is required
  * 
  * @return SteamID Fluent interface
  * 
  * @throws InvalidArgumentException
  */
 public static function SetFromURL($Value, callable $VanityCallback)
 {
     if (preg_match('/^https?:\\/\\/steamcommunity.com\\/profiles\\/(.+?)(?:\\/|$)/', $Value, $Matches) === 1) {
         $Value = $Matches[1];
     } else {
         if (preg_match('/^https?:\\/\\/steamcommunity.com\\/(id|groups|games)\\/([\\w-]+)(?:\\/|$)/', $Value, $Matches) === 1 || preg_match('/^()([\\w-]+)$/', $Value, $Matches) === 1) {
             $Length = strlen($Matches[2]);
             if ($Length < 2 || $Length > 32) {
                 throw new InvalidArgumentException('Provided vanity url has bad length.');
             }
             // Steam doesn't allow vanity urls to be valid steamids
             if (self::IsNumeric($Matches[2])) {
                 $SteamID = new SteamID($Matches[2]);
                 if ($SteamID->IsValid()) {
                     return $SteamID;
                 }
             }
             switch ($Matches[1]) {
                 case 'groups':
                     $VanityType = self::VanityGroup;
                     break;
                 case 'games':
                     $VanityType = self::VanityGameGroup;
                     break;
                 default:
                     $VanityType = self::VanityIndividual;
             }
             $Value = call_user_func($VanityCallback, $Matches[2], $VanityType);
             if ($Value === null) {
                 throw new InvalidArgumentException('Provided vanity url does not resolve to any SteamID.');
             }
         }
     }
     return new SteamID($Value);
 }
Пример #2
0
 public function testSteam3CorrectParse()
 {
     $s = new SteamID('[U:1:123]');
     $this->assertTrue($s->IsValid());
     $this->assertEquals(123, $s->GetAccountID());
     $this->assertEquals(SteamID::DesktopInstance, $s->GetAccountInstance());
     $this->assertEquals(SteamID::UniversePublic, $s->GetAccountUniverse());
     $this->assertEquals(SteamID::TypeIndividual, $s->GetAccountType());
     $s->SetAccountInstance(1337);
     $this->assertEquals(1337, $s->GetAccountInstance());
     $this->assertFalse($s->IsValid());
     $s = new SteamID('[A:1:123:456]');
     $this->assertTrue($s->IsValid());
     $this->assertEquals(123, $s->GetAccountID());
     $this->assertEquals(456, $s->GetAccountInstance());
     $this->assertEquals(SteamID::UniversePublic, $s->GetAccountUniverse());
     $this->assertEquals(SteamID::TypeAnonGameServer, $s->GetAccountType());
     $s = new SteamID('[L:2:123]');
     $this->assertTrue($s->IsValid());
     $this->assertEquals(123, $s->GetAccountID());
     $this->assertTrue(!!($s->GetAccountInstance() & SteamID::InstanceFlagLobby));
     $this->assertEquals(SteamID::UniverseBeta, $s->GetAccountUniverse());
     $this->assertEquals(SteamID::TypeChat, $s->GetAccountType());
     $s = new SteamID('[c:3:123]');
     $this->assertTrue($s->IsValid());
     $this->assertEquals(123, $s->GetAccountID());
     $this->assertTrue(!!($s->GetAccountInstance() & SteamID::InstanceFlagClan));
     $this->assertEquals(SteamID::UniverseInternal, $s->GetAccountUniverse());
     $this->assertEquals(SteamID::TypeChat, $s->GetAccountType());
     $s = new SteamID('[g:1:456]');
     $s->SetAccountInstance(1337);
     $s->SetAccountID(0);
     $this->assertFalse($s->IsValid());
     $this->assertEquals(0, $s->GetAccountID());
     $this->assertEquals(SteamID::UniversePublic, $s->GetAccountUniverse());
     $this->assertEquals(SteamID::TypeClan, $s->GetAccountType());
     $s = new SteamID('[G:4:1]');
     $this->assertTrue($s->IsValid());
     $s->SetAccountID(0);
     $this->assertFalse($s->IsValid());
     $this->assertEquals(0, $s->GetAccountID());
     $this->assertEquals(SteamID::UniverseDev, $s->GetAccountUniverse());
     $this->assertEquals(SteamID::TypeGameServer, $s->GetAccountType());
     $this->assertNotEquals(15, $s->GetAccountType());
     $s->SetAccountType(15);
     $s->SetAccountUniverse(200);
     $this->assertFalse($s->IsValid());
     $this->assertEquals(15, $s->GetAccountType());
     $this->assertEquals(200, $s->GetAccountUniverse());
     $this->assertEquals('[i:200:0]', $s->RenderSteam3());
 }