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

namespace Steamworks
{
    public enum EUniverse
    {
        k_EUniverseInvalid = 0,
        k_EUniversePublic = 1,
        k_EUniverseBeta = 2,
        k_EUniverseInternal = 3,
        k_EUniverseDev = 4,
        k_EUniverseMax = 5
    }
}

Type

namespace Steamworks
{
    public enum EAccountType
    {
        k_EAccountTypeInvalid = 0,
        k_EAccountTypeIndividual = 1,
        k_EAccountTypeMultiseat = 2,
        k_EAccountTypeGameServer = 3,
        k_EAccountTypeAnonGameServer = 4,
        k_EAccountTypePending = 5,
        k_EAccountTypeContentServer = 6,
        k_EAccountTypeClan = 7,
        k_EAccountTypeChat = 8,
        k_EAccountTypeConsoleUser = 9,
        k_EAccountTypeAnonUser = 10,
        k_EAccountTypeMax = 11
    }
}

Account Id

AccountId_t accountId;

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

uint unAccountInstance;

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

unAccountInstance = 0u;

For all other types, Steam sets the value to

unAccountInstance = 1u;

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

unAccountInstance = 393216u;

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.

textField.text = UserData.Me.FriendId.ToString();

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.

//Parse the input string to a uint value
uint FriendID = System.Convert.ToUint32(inputfield.text);
//Get the UserData for this friend ID
UserData newGuy = UserData.Get(FriendID);
//Invite this user to be our friend on Steam
API.Overlay.Client.Activate(FriendDialog.friendadd, newGuy);

We even have a shortcut you can use to do this all in 1 line


if(UserData.AddFriend(inputField.text))
{
    //text was parsed to a uint value and sent to Steam
}
else
{
    //text is not a unit value, and no action was taken
}

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.

lobbyIdField.text = myLobby.AccountId;

As with the Add Friend example, you can then join a lobby via the ID

//Parse the input string to a uint value
uint LobbyAccountID = System.Convert.ToUint32(inputfield.text);
//Get the UserData for this friend ID
Lobby newLobby = Lobby.Get(LobbyAccountID );
//Invite this user to be our friend on Steam
mewLobby.Join(CallbackHandler);

This can even be done in 1 line

if(Lobby.Join(inputfield.text, CallbackHandler))
{
    //input text was parsed and sent to Steam
}
else
{
    //Invalid input text, no action taken
}

Last updated