steamid

package
v4.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 26, 2024 License: MIT Imports: 17 Imported by: 7

Documentation

Overview

Package steamid provides conversion to and from all steam ID formats.

If you wish to resolve vanity names like https://steamcommunity.com/id/SQUIRRELLY into steam id you must first obtain an API key at https://steamcommunity.com/dev/apikey.

You can then set it for the package to use:

	steamid.SetKey(apiKey)

With a steam api key set you can now use the following functions:

	steamid.ResolveVanity()

Index

Constants

View Source
const (
	BaseGID      = uint64(103582791429521408)
	BaseSID      = uint64(76561197960265728)
	InstanceMask = 0x000FFFFF
	ClanMask     = (InstanceMask + 1) >> 1
	Lobby        = (InstanceMask + 1) >> 2
	MMSLobby     = (InstanceMask + 1) >> 3
)

Variables

View Source
var (

	// BuildVersion is replaced at compile time with the current tag or revision.
	BuildVersion = "dev"    //nolint:gochecknoglobals
	BuildCommit  = "master" //nolint:gochecknoglobals
	BuildDate    = ""       //nolint:gochecknoglobals

)
View Source
var (
	// ErrNoAPIKey is returned for functions that require an API key to use when one has not been set.
	ErrNoAPIKey = errors.New("no steam web api key, to obtain one see: " +
		"https://steamcommunity.com/dev/apikey and call steamid.SetKey()")
	ErrInvalidKey         = errors.New("invalid steam api key length, must be 32 chars or 0 to remove it")
	ErrInvalidSID         = errors.New("invalid steam id")
	ErrEmptyString        = errors.New("invalid id, string empty")
	ErrSIDConvertInt64    = errors.New("failed to convert id to int64")
	ErrInvalidGID         = errors.New("invalid gid")
	ErrDecodeSID          = errors.New("could not decode steamid value")
	ErrUnmarshalStringSID = errors.New("failed to unmarshal string to SteamID")
	ErrRequestCreate      = errors.New("failed to create request")
	ErrInvalidStatusCode  = errors.New("invalid status code")
	ErrResponsePerform    = errors.New("failed to perform request")
	ErrResponseBody       = errors.New("failed to read response body")
	ErrResolveVanityGID   = errors.New("failed to resolve group vanity name")
	ErrInvalidQueryValue  = errors.New("invalid query value")
	ErrInvalidQueryLen    = errors.New("invalid value length")
)

Functions

func KeyConfigured

func KeyConfigured() bool

func SetKey

func SetKey(key string) error

SetKey will set the package global steam webapi key used for some requests Basic id conversion usage does not require this to be set.

You can alternatively set the key with the environment variable `STEAM_TOKEN={YOUR_API_KEY` To get a key see: https://steamcommunity.com/dev/apikey

Types

type AccountType

type AccountType int

AccountType is split into 10 types for a Steam account, of which 4 can be created today. Users of an "Individual" account are temporarily referred to as having a "Pending" account, which has a textual representation of "STEAM_ID_PENDING" until their account credentials are verified with Steam's authentication servers, a process usually complete by the time a server is fully connected to. Accounts of the type "Invalid" have a textual representation of "UNKNOWN" and are used for bots and accounts which do not belong to another class.

Multi-user chats use the "T" character. Steam group (clan) chats use the "c" character. Steam lobbies use Chat IDs and use the "L" character.

const (
	AccountTypeInvalid AccountType = iota
	AccountTypeIndividual
	AccountTypeMultiSeat
	AccountTypeGameServer
	AccountTypeAnonGameServer
	AccountTypePending
	AccountTypeContentServer
	AccountTypeClan
	AccountTypeChat
	AccountTypeP2PSuperSeeder
	AccountTypeAnonUser
)

func (AccountType) Letter

func (ac AccountType) Letter() string

func (AccountType) String

func (ac AccountType) String() string

type AppID

type AppID uint32

AppID is the id associated with games/apps.

type Collection

type Collection []SteamID

func (Collection) Contains

func (c Collection) Contains(sid64 SteamID) bool

func (Collection) ToInt64Slice added in v4.0.2

func (c Collection) ToInt64Slice() []int64

func (Collection) ToStringSlice

func (c Collection) ToStringSlice() []string

type Instance

type Instance int
const (
	InstanceAll Instance = iota
	InstanceDesktop
	InstanceConsole
	InstanceWeb
)

func (Instance) String

func (i Instance) String() string

type SID

type SID string

SID represents a SteamID STEAM_0:0:86173181.

type SID3

type SID3 string

SID3 represents a Steam3 [U:1:172346362].

type SID32

type SID32 uint32

SID32 represents a Steam32 172346362.

type SteamID

type SteamID struct {
	AccountID   SID32
	Instance    Instance
	AccountType AccountType
	Universe    Universe
}

SteamID represents a Steam64

((Universe << 56) | (Account Type << 52) | (Instance << 32) | Account ID)

This is using a string as the base type mainly to make interop with javascript/json simpler. There is no JSON bigint type, so when used with js the Number type gets represented as a float and will result in an invalid/truncated id value when decoded back to a native int64 form. 76561198132612090.

func New

func New(input any) SteamID

New accepts the following forms of steamid:

Steam64: - "76561198045011302" - int64(76561198045011302) - uint64(76561198045011302) Steam3: - "[U:1:84745574]" Steam: - "STEAM_0:0:42372787" AccountID: - int(84745574) - int32(84745574) - int64(84745574)

Returned SteamID should be verified with the SteamID.Valid method.

func RandSID64

func RandSID64() SteamID

RandSID64 generates a unique random (numerically) valid steamid for testing.

func Resolve added in v4.0.2

func Resolve(ctx context.Context, query string) (SteamID, error)

Resolve tries to retrieve a SteamID from a profile URL.

If an error occurs or the SteamID was unable to be resolved from the query then am error is returned. TODO try and resolve len(17) && len(9) failed conversions as vanity.

func ResolveGID

func ResolveGID(ctx context.Context, groupVanityURL string) (SteamID, error)

ResolveGID tries to resolve the GroupID from a group custom URL. NOTE This may be prone to error due to not being a real api endpoint.

func ResolveVanity

func ResolveVanity(ctx context.Context, query string) (SteamID, error)

ResolveVanity attempts to resolve the underlying SID64 of a users vanity url name This only accepts the name or last portion of the /id/ profile link For https://steamcommunity.com/id/SQUIRRELLY the value is SQUIRRELLY.

func SID64FromString

func SID64FromString(steamID string) (SteamID, error)

SID64FromString will attempt to convert a Steam64 formatted string into a SID64.

func (*SteamID) Equal

func (t *SteamID) Equal(id SteamID) bool

func (*SteamID) Int64

func (t *SteamID) Int64() int64

func (SteamID) MarshalJSON

func (t SteamID) MarshalJSON() ([]byte, error)

func (SteamID) MarshalText added in v4.0.1

func (t SteamID) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler which is used by the yaml package for marshalling.

func (*SteamID) Scan added in v4.0.3

func (t *SteamID) Scan(value interface{}) error

func (*SteamID) Steam

func (t *SteamID) Steam(format bool) SID

Steam converts a given SID64 to a SteamID2 format. e.g. 76561198132612090 -> STEAM_0:0:86173181

An empty SteamID (string) is returned if the process was unsuccessful.

func (*SteamID) Steam3

func (t *SteamID) Steam3() SID3

Steam3 converts a given id to a SID3 format. e.g. 76561198132612090 -> [U:1:172346362].

func (*SteamID) String

func (t *SteamID) String() string

func (*SteamID) UnmarshalJSON

func (t *SteamID) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the Unmarshaler interface for steam ids. It will attempt to do all steam id types by calling StringToSID64.

func (*SteamID) UnmarshalYAML added in v4.0.1

func (t *SteamID) UnmarshalYAML(node *yaml.Node) error

UnmarshalYAML implements the yaml.Unmarshaler interface for steam ids.

func (*SteamID) Valid

func (t *SteamID) Valid() bool

Valid ensures the value is at least large enough to be valid No further validation is done.

func (SteamID) Value added in v4.0.3

func (t SteamID) Value() (driver.Value, error)

type Universe

type Universe int

Universe describes the 6 known steam universe Universes 0 to 3 are common, 4 Dev not exist in all games, 5 RC is removed out from some source files "// no such universe anymore".

const (
	UniverseInvalid Universe = iota
	UniversePublic
	UniverseBeta
	UniverseInternal
	UniverseDev
	UniverseRC
)

func (Universe) String

func (u Universe) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL