SteamGameServer is a handler module for node-steam version 1.0.0 or greater. It also works with node-steam-client.
It connects to Steam as a gameserver, either anonymously or with a game server login token (GSLT).
So as to comply with Valve's rules, this doesn't register with the master server, so no server will show up on the server browser.
Subscribe to release announcements
Enums ^
There are a lot of enums used in Steam. They're all available directly from SteamGameServer
. For example, access EResult
using SteamGameServer.EResult
.
All enums can be viewed on GitHub.
Additionally, for convenience, the name of an enum value is available from any enum at the key identified by the enum
value. For example, given an EResult of 88
you can translate it using SteamGameServer.EResult[88]
which gives you
the string TwoFactorCodeMismatch
.
Static Properties ^
Static properties, or properties attached directly to SteamGameServer
, are accessed on the root module and not on instantiated handler instances.
The node-steam-client
module installation used by SteamGameServer
. You can use this in place of require('steam-client')
if you'd like to avoid duplicate installations.
Options ^
There are a number of options which can control the behavior of the SteamGameServer
object. They are:
Controls where the Steam server list is written. If null
, no data will be automatically stored.
Defaults to a platform-specific user data directory.
- On OpenShift, this is
$OPENSHIFT_DATA_DIR/node-steamuser
- On Windows, this is
%localappdata%\doctormckay\node-steamuser
- On Mac, this is
~/Library/Application Support/node-steamuser
- On Linux, this is
$XDG_DATA_HOME/node-steamuser
, or~/.local/share/node-steamuser
if$XDG_DATA_HOME
isn't defined or is empty
This reuses node-steam-user
's data directory so as to avoid duplicate files.
If you don't want to (or can't) save data to the disk, you can implement your own storage engine. To do this, simply add the following code:
client.storage.on('save', function(filename, contents, callback) {
// filename is the name of the file, as a string
// contents is a Buffer containing the file's contents
// callback is a function which you MUST call on completion or error, with a single error argument
// For example:
someStorageSystem.saveFile(filename, contents, function(err) {
callback(err);
});
});
client.storage.on('read', function(filename, callback) {
// filename is the name of the file, as a string
// callback is a function which you MUST call on completion or error, with an error argument and a Buffer argument
// For example:
someStorageSystem.readFile(filename, function(err, file) {
if(err) {
callback(err);
return;
}
callback(null, file);
});
});
In this manner, you can save data to a database, a cloud service, or anything else you choose.
A boolean which controls whether or not SteamGameServer
will automatically reconnect to Steam if disconnected due to Steam going down.
Defaults to true
.
What kind of machine ID will SteamGameServer send to Steam when logging on? Should be a value from
EMachineIDType
.
Only meaningful when logging into a persistent account with a token. Defaults to AccountTokenGenerated
.
If you're using machineIdType
AccountTokenGenerated
, this is the format it uses. This is an array of three strings,
each of which will be hashed with SHA1 before being sent to Steam. {token}
will be replaced with the current account
login token.
Defaults to ["SteamGameServer Hash BB3 {account_name}", "SteamGameServer Hash FF2 {account_name}", "SteamGameServer Hash 3B3 {account_name}"]
.
Properties ^
The SteamClient
or CMClient
which is being used to communicate with Steam.
null
if not connected, a SteamID
containing your SteamID otherwise.
An object containing options for this SteamGameServer
. Read-only, use setOption
or setOptions
to change an option.
Only defined if you're currently logged on. This is your public IP as reported by Steam, in "x.x.x.x" format.
Only defined if you're currently logged on. This is your cell (region ID) on the Steam network.
Read-only. The Steam AppID for the game this server is "running".
Read-only. The game directory reported to Steam for the game this server is "running".
Read-only. The game version reported to Steam for the game this server is "running".
Read-only. The port reported to Steam on which this "server" is "listening" for game connections.
Read-only. The port reported to Steam on which this "server" is "listening" for UDP server browser queries.
Read-only. The server flags reported to Steam when we connected.
true
if Steam reports this server as being VAC-secured. false
if not.
Methods ^
client
- An optionalSteamClient
orCMClient
to use to connect to Steam. If not provided, one will be created automatically.options
- An optional object containing zero or more options to set for thisSteamGameServer
.
Constructs a new SteamGameServer
. If you allow SteamGameServer
to create its own SteamClient
, then SteamGameServer
will
automatically save and reload the CM server list.
option
- The name of the option to setvalue
- The value to set for this option
Changes the value of an option.
options
- An object containing zero or more options.
details
- An object containing details for this logonappID
- Required. The AppID for the game this "server" will be "running".gameVersion
- Required. The version for the game this "server" will be "running" to report to Steam.gameDirectory
- Required if not available in gamedirs.json. The game directory for the game this "server" will be "running".gamePort
- Optional. The port on which this "server" will be "listening" for game connections. Defaults to 27015.queryPort
- Optional. The port on which this "server" will be "listening" for UDP queries. Defaults to 27015.secure
- Optional.true
if this "server" wants to be VAC-secured.false
if not.token
- Optional. A game server login token (GSLT) (see here) if you want to login to a persistent gameserver account. Omit to login to an anonymous gameserver account.
Logs onto Steam. The CMClient
/SteamClient
should not be already logged on, although it can be
connected.
Logs you off of Steam and closes the connection.
appid
- The AppID of the app for which you'd like the current player/user count (use0
to get current logged-in Steam user count)callback
- Called when the requested data is availableerr
- AnError
object on failure, ornull
on successplayers
- If not errored, how many Steam users are currently playing/using the app
Requests a count of how many Steam users are currently playing/using an app.
conditions
- A filter string or an object containing one or more of the following properties:app_id
- The AppID of the game for which you want serversgeo_location_ip
- The IP address of the querying client, used for geolocation (inx.x.x.x
format)region_code
- The region code where you want serversfilter_text
- A filter stringmax_servers
- Maximum number of servers to return in this response (default and hard limit 5000)
callback
- Called when the response is availableerr
- If an error occurred, this is anError
object. Otherwise, it'snull
.servers
- An array of objects containing server dataip
- The server's IP inx.x.x.x
formatport
- The server's game portplayers
- How many authenticated players are on this server (the Steam server browser will use this value if the gameserver itself reports more players and doesn't report itself as full, to prevent inflated player counts)
Requests a list of game servers from the master server.
filter
- A master server filter stringlimit
- How many servers should be returned, at maximum. Hard limit is 5000.callback
- Called when the requested data is availableservers
- An array of objects containing server dataaddr
- The server's IP address inx.x.x.x:p
formatgameport
- The port the server is running on for game clientsspecport
- The port the server is running on for spectator clients (null
for none)steamid
- ASteamID
object containing the server's SteamIDname
- The server's hostnameappid
- The AppID of the game which the server is servinggamedir
- The directory of the game which the server is servingversion
- The version of the game which the server is servingproduct
- The product name of the game which the server is servingregion
- The region code for where the server is locatedplayers
- How many people are currently on this servermax_players
- How many people can be on the server at oncebots
- How many CPU players are currently on this servermap
- The name of the map which the server is currently runningsecure
-true
if the server is VAC-secure,false
if notdedicated
-true
if the server is dedicated,false
if listenos
-w
if the server is running on Windows,l
for Linuxgametype
- The server's tags, separated by commas
Requests a list gameservers from Steam matching a given filter, along with information about the server as Steam knows it.
ips
- An array of IP addresses, inx.x.x.x:p
formatcallback
- Called when requested data is availableservers
- An object whose keys are IP addresses inx.x.x.x:p
format and values areSteamID
objects
Gets current SteamIDs for servers running on given addresses.
steamids
- An array ofSteamID
objects, or something which can parse into one (64-bit SteamID as string, Steam3 rendered format)callback
- Called when requested data is availableservers
- An object whose keys are 64-bit numeric SteamIDs and values are IP addresses inx.x.x.x:p
format
Gets current IP addresses for servers with given SteamIDs.
sinceChangenumber
- The changenumber of the last known changelist. You will get changes which have occurred since then and now. You won't get any info except the current changenumber if you request more than around 5,000 changenumbers in the past.callback
- Called when data is availablecurrentChangenumber
- The changenumber of the newest changelistapps
- An array of objects for apps which have changed. Each object has these properties:appid
- The AppID of the appchange_number
- The changenumber of the latest changelist in which the app has changedneeds_token
-true
if you need an access token to get most details about this app,null
if not
packages
- An array of objects for packages which have changed. Each object has the same properties as theapps
array, exceptappid
ispackageid
.
Requests a list of all apps/packages which have changed since a given changenumber.
apps
- Either an array of AppIDs, or an array of objects containingappid
andaccess_token
propertiespackages
- Either an array of PackageIDs, or an array of objects containingpackageid
andaccess_token
propertiescallback
- Called when requested data is availableapps
- An object whose keys are AppIDs and whose values are objectschangenumber
- The changenumber of the latest changelist in which this app changedmissingToken
-true
if you need to provide an access token to get more details about this appappinfo
- An object whose structure is identical to the output ofapp_info_print
in the Steam console
packages
- An object whose keys are PackageIDs and whose values are objects. Each object has the same properties as theapps
array, exceptappinfo
ispackageinfo
.unknownApps
- An array of input AppIDs which don't existunknownPackages
- An array of input PackageIDs which don't exist
Requests details about one or more apps or packages.
ids
- Either an integer, or an array of integers containing the IDs of the published file(s) you want details forcallback
- A function to be called when the request has completederr
- AnError
object on failure, ornull
on successresults
- An object whose keys are published file IDs, and values are object containing a ton of information
Gets details for one or more published files. Published files are anything with a URL like
https://steamcommunity.com/sharedfiles/filedetails/?id=662626851
(where id
is the published file ID).
The amount of data available in results
is huge, so I can only suggest that you console.log
it to see what's
available.
steamids
- An array ofSteamID
objects or strings which can parse intoSteamID
objectscallback
- Optional. Called when the requested data is available.personas
- An object whose keys are 64-bit SteamIDs and whose values are objects identical to those received in theuser
event
Requests persona data for one or more users from Steam. The response will arrive in the user
event, or in the callback if provided.
steamids
- An array ofSteamID
objects or strings that can parse intoSteamID
objectscallback
- Called when the requested data is available.results
- An object whose keys are 64-bit SteamIDs (as strings) and whose values are Steam levels
Gets the Steam Level for one or more Steam users.
Events ^
Events marked as ID events are special. They all have a SteamID
object as their first parameter. In addition to the event itself firing, a second event comprised of eventName + "#" + steamID.getSteamID64()
is fired.
For example:
// This will fire when we receive a chat message from ANY friend
server.on('friendMessage', function(steamID, message) {
console.log("Friend message from " + steamID.getSteam3RenderedID() + ": " + message);
});
// This will fire when we receive a chat message from [U:1:46143802] / 76561198006409530 ONLY
server.on('friendMessage#76561198006409530', function(steamID, message) {
console.log("Friend message from " + steamID.getSteam3RenderedID() + ": " + message);
});
details
- An object containing various details about your account (seeCMsgClientLogonResponse
)
Emitted when you're successfully logged into Steam.
err
- AnError
object
Emitted when an error occurs during logon. Also emitted if we're disconnected and autoRelogin
is either disabled, or it's a fatal disconnect.
If this event isn't handled, the program will crash.
The SteamGameServer
object's steamID
property will still be defined when this is emitted. The Error
object will have an eresult
parameter which is a value from the EResult
enum.
eresult
- A value from theSteamGameServer.EResult
enummsg
- A string describing the reason for the disconnect, if available (might be undefined)
Emitted when we're disconnected from Steam for a non-fatal reason and autoRelogin
is enabled. SteamGameServer
will
continually retry connection and will either emit loggedOn
when logged back on, or error
if a fatal logon error is
experienced.
Also emitted in response to a logOff() call.
The SteamGameServer
object's steamID
property will still be defined when this is emitted.
The eresult
value might be 0 (Invalid), which indicates that the disconnection was due to the connection being closed
directly, without Steam sending a LoggedOff message.
secure
-true
if Steam reports that this server is VAC-secured,false
if not secured
Emitted when Steam notifies us that we're either VAC-secured or not.
sid
- ASteamID
object for the user whose data we just receiveduser
- An object containing the user's persona data
This is an ID event.
Emitted when Steam sends us persona information about a user. The users
property isn't yet updated when this is emitted, so you can compare to see what changed.