Home

Awesome

Steam for Node.js

npm version npm downloads dependencies license paypal

This is a fork of node-steam's SteamClient. Essentially it's node-steam without the handler modules and with some more features. It should be compatible with all node-steam handler modules, as long as the underlying Steam protocol doesn't change without a third-party module's knowledge.

This exists because of how painfully slow it is to get new things implemented into node-steam, and also because of incompatibilities that can potentially arise between node-steam and third-party handler modules.

Protocol version bumps will always be major module releases. You're highly recommended to pin the major version in your dependencies (e.g. "steam-client": "^1.0.0").

Requires Node.js v4.1.1 or later.

Installation

$ npm install steam-client

Usage

First, require this module.

var Steam = require('steam-client');

Steam is now a namespace object containing:

Then you'll want to create an instance of CMClient and any handlers you need (externally), call SteamClient#connect and assign event listeners. Some handlers, such as node-steam-user do this automatically for you.

var steamClient = new Steam.CMClient();
steamClient.connect();
steamClient.on('connected', function() {
    steamClient.logOn({
        "account_name": "username",
        "password": "password"
    });
});

steamClient.on('logOnResponse', function(details) { /* ... */});

Constructor

The constructor takes one argument: the protocol to use to connect to Steam. This should be a value from EConnectionProtocol. Default is TCP. UDP support is experimental. There are some pros and cons to each:

Note that UDP connections use Valve-brand UDP, which is essentially TCP over UDP. Consequently, network unreliability is not a concern when using UDP.

Example:

var Steam = require('steam-client');
var client = new Steam.CMClient(Steam.EConnectionProtocol.TCP);

Servers

Steam.servers contains the list of CM servers that CMClient will attempt to connect to. The bootstrapped list is not always up-to-date and might contain dead servers. To avoid timeouts, replace it with your own list before logging in if you have one (see 'servers' event).

SteamID

Since JavaScript's Number type does not have enough precision to store 64-bit integers, SteamIDs are represented as decimal strings. (Just wrap the number in quotes)

Enums

Whenever a method accepts (or an event provides) an ESomething, it's a Number that represents some enum value. See enums.steamd and eresult.steamd for the whole list of them. For each enum, there is an equivalently named property on Steam. The property is an object; for each of the enum's members, there is an equivalently named property on the object with an equivalent value.

Note that you can't easily get the string value from the number, but you probably don't need to. You can still use them in conditions (e.g. if (type == Steam.EChatEntryType.Emote) ...) or switch statements.

Protobufs

Whenever a method accepts (or an event provides) a CMsgSomething, it's an object that represents a protobuf message. It has an equivalently named property for each set field in the specified message with the type as follows:

See the node-steam wiki for descriptions of protobuf fields.

Handlers

Most of the API is provided by handler classes that internally send and receive low-level client messages using 'message'/send.

This module has no handlers built-in. You may use handlers from node-steam, or you may alternatively use standalone handlers (such as node-steam-user).

CMClient

Properties

connected

A boolean that indicates whether you are currently connected and the encryption handshake is complete. 'connected' is emitted when it changes to true, and 'error' is emitted when it changes to false unless you called disconnect. Sending any client messages is only allowed while this is true.

loggedOn

A boolean that indicates whether you are currently logged on. Calling any handler methods except for methods to log on is only allowed while logged on.

steamID

Your own SteamID while logged on, otherwise unspecified. Must be set to a valid initial value before sending a logon message.

remoteAddress

v2.1.0 or later is required to use this property

If we've initiated a connection previously, a string containing "ipv4:port" for the server we're connecting/connected to. Also contains the address of the last host we were connected to if we're currently disconnected.

Methods

bind([localAddress][, localPort])

Override the address and/or port that will be used for the outgoing connection. Takes effect the next time you connect.

setHttpProxy(proxyUrl)

If you want to connect via an HTTP proxy, set the proxy URL using this method before connecting. HTTPS proxies are not supported at this time. Example: http://user:pass@1.2.3.4:8080

connect([server][, autoRetry])

Connects to Steam. It will keep trying to reconnect (provided autoRetry is not false) until encryption handshake is complete (see 'connected'), unless you cancel it with disconnect.

You can call this method at any time. If you are already connected, disconnects you first. If there is an ongoing connection attempt, cancels it.

disconnect()

Immediately terminates the connection and prevents any events (including 'error') from being emitted until you connect again. If you are already disconnected, does nothing. If there is an ongoing connection attempt, cancels it.

logOn(details)

Send a logon message to the CM. You must first be connected and set steamID to a valid initial value. You will receive the response in the logOnResponse event.

send(header, body, callback)

Events

error

Connection closed by the server. Only emitted if the encryption handshake is complete, otherwise it will reconnect automatically (unless you disabled autoRetry). loggedOn is now false.

connected

Encryption handshake complete. From now on, it's your responsibility to handle disconnections and reconnect (see error). You'll likely want to log on now.

logOnResponse

Logon response received. If eresult is EResult.OK, loggedOn is now true.

servers

CMClient will use this new list when reconnecting, but it will be lost when your application restarts. You might want to save it to a file or a database and assign it to Steam.servers before logging in next time.

Note that Steam.servers will be automatically updated after this event is emitted. This will be useful if you want to compare the old list with the new one for some reason - otherwise it shouldn't matter.

loggedOff

You were logged off from Steam. loggedOn is now false.

message

Emitted when you receive a message from the CM.