library(steamr)

The Steam API uses a variety of IDs. From user IDs, clan IDs and game group IDs to more special cases like curator IDs or recommendation IDs, identifying things in Steam works using strings of numerical mumbo-jumbo. This can become quite inconvenient if there are multiple types of the same ID. This is the case for Steam IDs which can identify users, groups, and game groups. Steam IDs can take four forms:

  • Vanity IDs: Human-readable account name given by the user
  • Steam64 IDs: 64-bit representations of account information
  • Steam2 IDs: Text representations of account information
  • Steam3 IDs: Slightly more useful text representations of account information

It is important to be able to convert between these IDs. Usually, vanity IDs are used wherever accounts are handled and shared by users. Steam64 is machine-readable and often used in API methods. Steam2 and Steam3 contain the most important information in relatively easy to access ways. Each ID type (except vanity) consists of five components: Authentication server (or simply Y), account number (or Z), instance, type, and universe (or X).

The authentication server can be 0 or 1. If the account number is even, it is 0, otherwise it is 1. The account number is a unique number of a user account. The instance is a number between 0 and 4 that tells us if the account is a desktop instance (1), console instance (2), web distance (4), or all at once (0). The account type identifies whether we are dealing with a user or individual (1), group (7), or something else (e.g., a cypercafe account or game server). Finally, the universe can be a number between 0 and 5 but is mostly set to 1 (public). 0 (unspecified), 2 (beta), and 3 (internal) are also possible. 4 and 5 are legacy universes and do not really exist.

steamr supports conversions and parsing of Steam IDs. It is built on the popular SteamID php library and powered by the gmp and bigBits packages for high-precision arithmetics and logical operations. More information on Steam IDs can be found on the official wiki.

Conversions

To convert between different types of IDs, we can use the convert_steamid function. To convert from or to vanity IDs, an API key is required to be set.

vanities <- c("BeFoRE-CS", "vgenkin")
steam64 <- convert_steamid(vanities, to = "steam64")
steam64
#>           BeFoRE-CS             vgenkin 
#> "76561198092541763" "76561197984981409"
steam2 <- convert_steamid(steam64, to = "steam2")
steam2
#>    76561198092541763    76561197984981409 
#> "STEAM_1:1:66138017" "STEAM_1:1:12357840"
steam3 <- convert_steamid(steam2, to = "steam3")
steam3
#> STEAM_1:1:66138017 STEAM_1:1:12357840 
#>  "[U:1:132276035]"   "[U:1:24715681]"
convert_steamid(steam3, to = "vanity")
#> [U:1:132276035]  [U:1:24715681] 
#>     "BeFoRE-CS"       "vgenkin"

While conversions between Steam64, Steam2 and Steam3 can be done by applying some high-precision logical operations, resolving vanity IDs requires communicating with the Steam Web API. Vanity conversions are powered by the ResolveVanityURL endpoint in the resolve_vanity function. Here, we can also specify the type of profile, i.e. profile, group, or game group. For example, we can look up the name of the official Valve group:

resolve_vanity("Valve", type = "group")
#> [1] "103582791429521412"
lookup_steamid("Valve", vanity_type = "group")
#> # A tibble: 1 × 4
#>   steam64            steam2 steam3  vanity
#>   <chr>              <chr>  <chr>   <chr> 
#> 1 103582791429521412 NA     [g:1:4] Valve

One way to get these converted IDs in a tidy dataframe is to use the lookup_steamid function.

lookup_steamid(vanities)
#> # A tibble: 2 × 4
#>   steam64           steam2             steam3          vanity   
#>   <chr>             <chr>              <chr>           <chr>    
#> 1 76561198092541763 STEAM_1:1:66138017 [U:1:132276035] BeFoRE-CS
#> 2 76561197984981409 STEAM_1:1:12357840 [U:1:24715681]  vgenkin

Parsing

If we are interested in the internals of the Steam IDs, steamr provides parsing functions for Steam64, Steam3, and Steam2 IDs. All parsing functions return dataframes and work on vectors.

steam64 <- c(steam64, "103582791429521412")
parse_steam64(steam64)
#> # A tibble: 3 × 5
#>    auth   number instance  type universe
#>   <int>    <int>    <int> <int>    <int>
#> 1     1 66138017        1     1        1
#> 2     1 12357840        1     1        1
#> 3     0        2        0     7        1
parse_steam2(steam2)
#> # A tibble: 2 × 5
#>    auth   number instance  type universe
#>   <int>    <int>    <dbl> <dbl>    <int>
#> 1     1 66138017        1     1        1
#> 2     1 12357840        1     1        1
steam3 <- c(steam3, "[g:1:4]")
parse_steam3(steam3)
#> # A tibble: 3 × 5
#>    auth   number instance  type universe
#>   <int>    <int>    <dbl> <int>    <int>
#> 1     1 66138017        1     1        1
#> 2     0 12357840        1     1        1
#> 3     0        2        0     7        1