CSteamID
Here we will explain in detail the nature and structure of Valve's CSteamID and how to use it. Its worth noting that our Toolkit for Steamworks provides you with tools and features that should mean you rarely need to work with raw Steam IDs; however, it is useful to understand them.
Valve's CSteamID, also known simply as "Steam ID" is a ulong value (64 bits) and is used by Steam API to uniquely identify ... well, most things.
The native CSteamID ulong value is composed of 4 main parts
Universe
Type
Account Id
The data type AccountId_t is a wrapper around the uint primitive type ... that is it is a uint value with a few extra features.
Account Instance
This value is readable on the CSteamID but not documented in Steam.
We know from reviewing the CSteamID struct and its various methods that for Type Clan and GameServer, the account instance is set to
For all other types, Steam sets the value to
We know from experience that attempting to set a lobby in this way will fail, resulting in an invalid lobby. We have deduced that lobbies (seem) to have a constant account instance value of
Examples
Heathen has created wrap-around structures like UserData and Lobby that are interchangeable with CSteamID and ulong and provide helpful features unique to each use case of the ID. In most cases, you should be using UserData, Lobby, Clan, etc. and not need to bother with the raw CSteamID or its ulong value.
Steam IDs are used for a lot of different things and each has its own set of features and functions. For example, a CSteamID can represent a user and users have additional features like name, nickname, rich presence, etc. Alternatively, a CSteamID could represent a lobby which has features like metadata, members, etc.
Heathen has created a set of wrappers that let you treat each ID as a unique type and simplify working with the features of each unique type. Note each of these is implicitly convertible ... that is, you can use them as if they are CSteamID_t or ulong and you can assign them from CSteamID_t or ulong. These also have additional handlers to help you work with them as AccountID_t
ClanData
This is for IDs that represent a "clan" or "group"
LobbyData
This is for IDs that represent lobbies, aka chats
UserData
This is for IDs that represent users
Creating Steam IDs
While the full CSteamID is a 64-bit long, its a not very human-friendly number the actual "unique" part is just 32-bits long and much more manageable by a human. If you know the "type" of the ID then you can reconstruct it providing only the 32-bit "Account ID" part also known as a "Friend ID".
Adding Friends
Let's say you want your users to be able to "invite" each other to become friends through some method outside of Steam, such as chat, stream, etc. You could simply show the user their "Friend ID", aka the Account ID of their CSteamID. They can provide this fairly short number to prospective friends.
To display the local user's Friend ID, we can simply read it from the local user's User Data.
This will populate a simple number in the provided text field.
You can then also provide an input field where users can type in the IDs they get from others. The friend ID typed in can then be used to construct a UserData object which you can use for anything you like, including adding to Friends.
We even have a shortcut you can use to do this all in 1 line
Sharing Lobbies
Let's say you want to share a simple string so that players can join lobbies automatically. You could do this in a few ways but one option is to share the lobbies, and one is to expose the lobby's account ID.
As with the Add Friend example, you can then join a lobby via the ID
This can even be done in 1 line
Last updated