Home

Awesome

SteamGameServer

A handler module for node-steam v1.0.0 and greater

npm version npm downloads dependencies license paypal

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

Contents

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.

Steam

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:

dataDirectory

Controls where the Steam server list is written. If null, no data will be automatically stored.

Defaults to a platform-specific user data directory.

This reuses node-steam-user's data directory so as to avoid duplicate files.

Custom Storage Engine

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.

autoRelogin

A boolean which controls whether or not SteamGameServer will automatically reconnect to Steam if disconnected due to Steam going down.

Defaults to true.

machineIdType

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.

machineIdFormat

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 ^

client

The SteamClient or CMClient which is being used to communicate with Steam.

steamID

null if not connected, a SteamID containing your SteamID otherwise.

options

An object containing options for this SteamGameServer. Read-only, use setOption or setOptions to change an option.

publicIP

Only defined if you're currently logged on. This is your public IP as reported by Steam, in "x.x.x.x" format.

cellID

Only defined if you're currently logged on. This is your cell (region ID) on the Steam network.

appID

Read-only. The Steam AppID for the game this server is "running".

gameDir

Read-only. The game directory reported to Steam for the game this server is "running".

gameVersion

Read-only. The game version reported to Steam for the game this server is "running".

port

Read-only. The port reported to Steam on which this "server" is "listening" for game connections.

queryPort

Read-only. The port reported to Steam on which this "server" is "listening" for UDP server browser queries.

flags

Read-only. The server flags reported to Steam when we connected.

secure

true if Steam reports this server as being VAC-secured. false if not.

Methods ^

Constructor([client][, options])

Constructs a new SteamGameServer. If you allow SteamGameServer to create its own SteamClient, then SteamGameServer will automatically save and reload the CM server list.

setOption(option, value)

Changes the value of an option.

setOptions(options)

logOn(details)

Logs onto Steam. The CMClient/SteamClient should not be already logged on, although it can be connected.

logOff()

Logs you off of Steam and closes the connection.

getPlayerCount(appid, callback)

Requests a count of how many Steam users are currently playing/using an app.

serverQuery(conditions, callback)

Requests a list of game servers from the master server.

getServerList(filter, limit, callback)

Requests a list gameservers from Steam matching a given filter, along with information about the server as Steam knows it.

getServerSteamIDsByIP(ips, callback)

Gets current SteamIDs for servers running on given addresses.

getServerIPsBySteamID(steamids, callback)

Gets current IP addresses for servers with given SteamIDs.

getProductChanges(sinceChangenumber, callback)

Requests a list of all apps/packages which have changed since a given changenumber.

getProductInfo(apps, packages, callback)

Requests details about one or more apps or packages.

getPublishedFileDetails(ids, callback)

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.

getPersonas(steamids[, callback])

Requests persona data for one or more users from Steam. The response will arrive in the user event, or in the callback if provided.

getSteamLevels(steamids, callback)

Gets the Steam Level for one or more Steam users.

Events ^

ID 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);
});

loggedOn

Emitted when you're successfully logged into Steam.

error

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.

disconnected

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.

vac

Emitted when Steam notifies us that we're either VAC-secured or not.

user

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.