Git Product home page Git Product logo

steamid.php's Introduction

SteamID.php Packagist Codecov

This 64bit structure is used for identifying various objects on the Steam network. This library provides an easy way to work with SteamIDs and makes conversions easy.

This library does not use subtraction hacks like described on Valve Developer Wiki, or used in many other functions.

SteamID.php requires modern PHP version, and GMP module to be installed to perform operations 64-bit math.

Brief overview

A SteamID is made up of four parts: its universe, its type, its instance, and its account ID.

  • Universe: Currently there are 5 universes. A universe is a unique instance of Steam. You'll probably only be interacting with the public universe, which is the regular Steam. Only Valve employees can access non-public universes.
  • Type: A SteamID's type determines what it identifies. The most common type is individual, for user accounts. There are also other types such as clans (Steam groups), gameservers, and more.
  • Instance: Steam allows three simultaneous user account instances right now (1 = desktop, 2 = console, 4 = web, 0 = all)
  • Account ID: This represents a unique account of a type.

Using this library

It's really easy to use it, as constructor automatically figures out given input and works its magic from there. If provided SteamID is not in a valid format, an InvalidArgumentException is thrown. You can call IsValid on given SteamID instance to perform various checks which make sure that given account type / universe / instance are correct. You can view test file for multiple examples on how to manipulate SteamIDs.

Example

try
{
	// Constructor also accepts Steam3 and Steam2 representations
	$s = new SteamID( '76561197984981409' );
}
catch( InvalidArgumentException $e )
{
	echo 'Given SteamID could not be parsed.';
}

// Renders SteamID in it's Steam3 representation (e.g. [U:1:24715681])
echo $s->RenderSteam3() . PHP_EOL;

// Renders SteamID in it's Steam2 representation (e.g. STEAM_0:1:12357840)
echo $s->RenderSteam2() . PHP_EOL;

// Converts this SteamID into it's 64bit integer form (e.g. 76561197984981409)
echo $s->ConvertToUInt64() . PHP_EOL;

Also see VanityURLs.php for parsing any user input including URLs. If you're going to process user input, SteamID::SetFromURL() is all you need to use.

SteamID normalization

If you run some website where users can enter their own SteamIDs, sometimes you might encounter SteamIDs which have wrong universe or instanceid set, which will result in a completely different, yet valid, SteamID. To avoid this, you can manipulate given SteamID and set universe to public and instance to desktop.

try
{
	$s = new SteamID( $ID );
	
	if( $s->GetAccountType() !== SteamID::TypeIndividual )
	{
		throw new InvalidArgumentException( 'We only support individual SteamIDs.' );
	}
	else if( !$s->IsValid() )
	{
		throw new InvalidArgumentException( 'Invalid SteamID.' );
	}
	
	$s->SetAccountInstance( SteamID::DesktopInstance );
	$s->SetAccountUniverse( SteamID::UniversePublic );

	var_dump( $s->RenderSteam3() ); // [U:1:24715681]
	var_dump( $s->ConvertToUInt64() ); // 76561197984981409
}
catch( InvalidArgumentException $e )
{
	echo $e->getMessage();
}

After doing these steps, you can call RenderSteam3, RenderSteam2 or ConvertToUInt64 to get normalized SteamID.

See Example.php for a fully fledged example.

Functions

Name Parameters Description
IsValid - Gets a value indicating whether this instance is valid.
RenderSteam2 - Renders this instance into it's Steam2 "STEAM_" representation.
RenderSteam3 - Renders this instance into it's Steam3 representation.
RenderSteamInvite - Encodes accountid as HEX which can be used in `http://s.team/p/` URL.
RenderCsgoFriendCode - Encodes accountid as CS:GO friend code.
ConvertToUInt64 - Converts this SteamID into it's 64bit integer form.
SetFromURL string, callback Parse any user input including URLs and just steam ids.
SetFromUInt64 string or int (e.g 765...) Sets the various components of this SteamID from a 64bit integer form.
SetFromCsgoFriendCode string Sets the accountid of this SteamID from a CS:GO friend code. Resets other components to default values.
GetAccountID - Gets the account id.
GetAccountInstance - Gets the account instance.
GetAccountType - Gets the account type.
GetAccountUniverse - Gets the account universe.
SetAccountID New account id Sets the account id.
SetAccountInstance New account instance Sets the account instance. (e.g. SteamID::DesktopInstance)
SetAccountType New account type Sets the account type. (e.g. SteamID::TypeAnonGameServer)
SetAccountUniverse New account universe Sets the account universe. (e.g. SteamID::UniversePublic)

New Steam invite URLs

Valve introduce a new way of sharing profile URLs (https://s.team/p/hjqp or https://steamcommunity.com/user/hjqp). The encoding is simply hex encoded account id and each letter being replaced with a custom alphabet. While HEX originally is 0-9a-f, in the converted version numbers and letters a or e are not included, but they still work in the URL because Valve does a single pass replacement.

This library natively supports parsing s.team/p/ or steamcommunity.com/user/ URLs in SetFromURL function.

Here's the mapping of replacements:

Hex Letter
0 b
1 c
2 d
3 f
4 g
5 h
6 j
7 k
8 m
9 n
a p
b q
c r
d t
e v
f w

License

MIT

steamid.php's People

Contributors

dependabot[bot] avatar galexrt avatar inilo avatar jenky avatar timmw avatar xpaw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

steamid.php's Issues

Wrong SteamID with RenderSteam2() function

Hello. I have been seeing this problem for a long time, I just rarely use the conversion from Steam64 to Steam2, so I did not report it before.
Problem: Wrong universe.

Code example:

<?php
require __DIR__ . '/inc/SteamID.php';

$sid64 = 76561198210303223; // really sid: STEAM_0:1:125018747
$s = new SteamID($sid64);
echo $s->RenderSteam2(); // STEAM_1:1:125018747

$sid64 = 76561197990364979; // correct sid: STEAM_0:1:15049625
$s = new SteamID($sid64);
echo $s->RenderSteam2(); // STEAM_1:1:15049625

$sid64 = 76561198166638169; // correct sid: STEAM_0:1:103186220
$s = new SteamID($sid64);
echo $s->RenderSteam2(); // STEAM_1:1:103186220

This problem is observed on the release version 2.0.0, also on the current github version.
I checked version 2.0.0 on php 7.4.3 and the current version on php 8.1 - in both cases the problem is present.

Parsing of account ID goes weird

    $steam = new SteamID();
    $steam->SetAccountID(48251305);
    var_dump($steam->ConvertToUInt64());
        //reparse
    $steam = new SteamID($steamshit->RenderSteam2());
    var_dump($steam->ConvertToUInt64());

string(8) "48251305"
string(17) "76561198008517033"

GMP errors despite installing the module

I'm running PHP version 7.1.32-1+ubuntu18.04.1

I've tried numerous times to install the GMP module for this PHP version. I edit the php.ini to ensure the gmp extension is included, but no matter what I'm always receiving the following error:

An exception occurred: Call to undefined function gmp_init() in /var/www/example.org/public_html/library/PageBansCP/SteamID.php on line 126

Any suggestions to get this module working?

Cannot convert 32-bit IDs to 64-bit

Although SteamID can be constructed with a 64-bit ID, it does not have a function to consistently emit 64-bit IDs, despite what ConvertToUInt64() might imply. That is, ConvertToUInt64() is just a round-trip function and doesn't actually convert anything:

(new SteamID('1'))->ConvertToUInt64() // "1"

Contrast this with GetAccountID(), which actually does consistently output the 32-bit form of the account ID. There should be a 64-bit analogue of this method.

Error in steamid Processing STEAM_#

I am using your script for a donation script im building, the problem is simple, when retreiving a normal steamid " STEAM_1:0:7828#####" for example it should be "STEAM_0:0:7828#####"

it keeps saying its steam_1 not steam_0.

This is a example:
https://steamid.io/lookup/76561198116838208

if you notice its STEAM_0, but if you enter STEAM_1 itll show it as STEAM_0.

Catching an invalid Steam ID exception.

Hi!

try { // Attempt initializing a SteamID instance with the input.
    $providedID = new SteamID($id);
} catch(InvalidArgumentException $e) { // Invalid ID, can be a custom URL thing. Or a URL.
    echo 'Invalid ID....';
}

Using this code, On PHP 7.0.4, it doesn't actually catch the exception and just throws out a fatal error and exits the page. Am I doing something wrong?

Cheers.

Steam Vanity Lookup Failing to perform API request

Hello. I'm having a bit of an odd issue where the Vanity URL lookup just stopped working. I'm not quite sure what's causing it because it's been working for the past few months and just stopped working now. I have a feeling Steam may have changed something in their API because it stopped working across multiple projects of mine. I also know that I haven't reached my API limit for the day because I can still access the API manually through my browser.

I am using the same code you provided in the VanityURL's php file. I happend to notice that SteamID's, SteamID64's, and SteamID3's still work, however when looking up Vanity URL's (https://steamcommunity.com/id/driedsponge, driedsponge) the API request failed.

Any help would be appreciated. Thank you!

Add namespace

Autoloading the SteamID.php trough composer without namespace throws the following error in a laravel setup.

image

STEAM_0-prefixed IDs emitted as STEAM_1-prefixed

STEAM_0:1:124 (and a bunch of other STEAM_0-prefixed IDs) are showing up as STEAM_1 when output by RenderSteam2 method. Other sites also corroborate that this should be STEAM_0-prefixed.

echo (new \SteamID('STEAM_0:1:124'))->RenderSteam2(); // STEAM_1:1:124

PHP7 support

Strings that contain hexadecimal numbers are no longer considered to be
numeric and don't receive special treatment anymore.

  • Line 439: return gmp_intval( $this->Get( 0, '0xFFFFFFFF' ) );
  • Line 449: return gmp_intval( $this->Get( 32, '0xFFFFF' ) );
  • Line 459: return gmp_intval( $this->Get( 52, '0xF' ) );
  • Line 469: return gmp_intval( $this->Get( 56, '0xFF' ) );
  • Line 481: $this->Set( 0, '0xFFFFFFFF', $Value );
  • Line 495: $this->Set( 32, '0xFFFFF', $Value );
  • Line 509: $this->Set( 52, '0xF', $Value );
  • Line 523: $this->Set( 56, '0xFF', $Value );

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.