SteamID (SteamID v0.1.1)

View Source

Valve's SteamID.

Summary

Types

The various Steam account types.

t()

A SteamID.

The various Steam universes.

Functions

A struct carrying all components of a SteamID.

Converts an integer to a %SteamID{}.

Creates a new %SteamID{}.

Normalizes the given %SteamID{} by setting universe, account_type, and account_instance to their default values.

Converts a string to a %SteamID{}.

Converts a %SteamID{} to an integer.

Converts a %SteamID{} to a string.

Types

account_instance()

@type account_instance() :: non_neg_integer()

account_number()

@type account_number() :: non_neg_integer()

account_type()

@type account_type() ::
  :invalid
  | :individual
  | :multiseat
  | :game_server
  | :anon_game_server
  | :pending
  | :content_server
  | :clan
  | :chat
  | :p2p_super_seeder
  | :anon_user

The various Steam account types.

authentication_server()

@type authentication_server() :: 0 | 1

format()

@type format() :: :id2 | :id3 | :id32 | :id64

size()

@type size() :: 32 | 64

t()

@type t() :: %SteamID{
  account_instance: account_instance(),
  account_number: account_number(),
  account_type: account_type(),
  authentication_server: authentication_server(),
  universe: universe()
}

A SteamID.

universe()

@type universe() ::
  (:unspecified | :individual) | :public | :beta | :internal | :dev | :rc

The various Steam universes.

Functions

%SteamID{}

(struct)

A struct carrying all components of a SteamID.

You may read all fields, but only change them by calling functions in the SteamID module.

from_integer(value)

@spec from_integer(integer()) :: {:ok, t()} | :error

Converts an integer to a %SteamID{}.

Example

iex> SteamID.from_integer(0)
{:ok,
 %SteamID{
   universe: :public,
   account_type: :individual,
   account_instance: 1,
   account_number: 0,
   authentication_server: 0
 }}
iex> SteamID.from_integer(76561198282622073)
{:ok,
 %SteamID{
   universe: :public,
   account_type: :individual,
   account_instance: 1,
   account_number: 161178172,
   authentication_server: 1
 }}
iex> SteamID.from_integer(322356345)
{:ok,
 %SteamID{
   universe: :public,
   account_type: :individual,
   account_instance: 1,
   account_number: 161178172,
   authentication_server: 1
 }}
iex> SteamID.from_integer(-42)
:error

new(fields \\ [])

@spec new([field]) :: t()
when field:
       {:universe, universe()}
       | {:account_type, account_type()}
       | {:account_instance, account_instance()}
       | {:account_number, account_number()}
       | {:authentication_server, authentication_server()}

Creates a new %SteamID{}.

Example

iex> SteamID.new()
%SteamID{
  universe: :public,
  account_type: :individual,
  account_instance: 1,
  account_number: 0,
  authentication_server: 0
}
iex> SteamID.new(account_number: 161178172, authentication_server: 1)
%SteamID{
  universe: :public,
  account_type: :individual,
  account_instance: 1,
  account_number: 161178172,
  authentication_server: 1
}

Fields

normalize(steam_id)

@spec normalize(t()) :: t()

Normalizes the given %SteamID{} by setting universe, account_type, and account_instance to their default values.

parse(value)

@spec parse(binary()) :: {:ok, t()} | :error

Converts a string to a %SteamID{}.

Example

iex> SteamID.parse("0")
{:ok,
 %SteamID{
   universe: :public,
   account_type: :individual,
   account_instance: 1,
   account_number: 0,
   authentication_server: 0
 }}
iex> SteamID.parse("U:1:322356345")
{:ok,
 %SteamID{
   universe: :public,
   account_type: :individual,
   account_instance: 1,
   account_number: 161178172,
   authentication_server: 1
 }}
iex> SteamID.parse("STEAM_1:1:161178172")
{:ok,
 %SteamID{
   universe: :public,
   account_type: :individual,
   account_instance: 1,
   account_number: 161178172,
   authentication_server: 1
 }}
iex> SteamID.parse("STEAM_0:1:161178172")
{:ok,
 %SteamID{
   universe: :unspecified,
   account_type: :individual,
   account_instance: 1,
   account_number: 161178172,
   authentication_server: 1
 }}
iex> SteamID.parse("bingus")
:error

to_integer(steam_id, opts \\ [])

@spec to_integer(t(), [option]) :: String.t() when option: {:size, size()}

Converts a %SteamID{} to an integer.

Example

iex> steam_id = SteamID.new(account_number: 161178172, authentication_server: 1)
iex> SteamID.to_integer(steam_id, size: 32)
322356345
iex> SteamID.to_integer(steam_id, size: 64)
76561198282622073

Options

  • :size (size/0) - The default value is 64.

to_string(steam_id, opts \\ [])

@spec to_string(t(), [option]) :: String.t() when option: {:format, format()}

Converts a %SteamID{} to a string.

Example

iex> steam_id = SteamID.new(account_number: 161178172, authentication_server: 1)
iex> SteamID.to_string(steam_id, format: :id2)
"STEAM_1:1:161178172"
iex> SteamID.to_string(steam_id, format: :id3)
"U:1:322356345"
iex> SteamID.to_string(steam_id, format: :id32)
"322356345"
iex> SteamID.to_string(steam_id, format: :id64)
"76561198282622073"

Options

  • :format (format/0) - The default value is :id64.

When called with the default options, this function is equivalent to Kernel.to_string/1.