Skip to content

Game Coordinator

Alex Corn edited this page Feb 5, 2019 · 3 revisions

v4.1.0 or later is required to interact with a GC.

Interacting with a GC typically goes like this:

  1. Listen for the appLaunched event. It will be emitted with a single appId property.
  2. Talk to the GC using sendToGC
  3. Receive messages from the GC using receivedFromGC
  4. Listen for the appQuit event. It will be emitted with a single appId property if gamesPlayed is called and the given app ID is not included (but it was in the previous gamesPlayed call).
    • appQuit will not be emitted if the client disconnects from Steam. Also listen for disconnected and error events.

These methods and events are available on a SteamUser object. For example:

const SteamUser = require('steam-user');
let user = new SteamUser();
user.logOn(...);

user.on('loggedOn', () => {
    user.gamesPlayed([440]);
});

user.on('appLaunched', (appid) => {
    // 4006 = ClientHello in TF2
    user.sendToGC(appid, 4006, {}, Buffer.alloc(0));
});

user.on('receivedFromGC', (appid, msgType, payload) => {
    console.log(`Received message ${msgType} from GC ${appid} with ${payload.length} bytes`);
});

Methods

sendToGC(appid, msgType, protoBufHeader, payload[, callback])

  • appid - The AppID of the game to which you want to send this GC message
  • msgType - The GC-specific msg ID for this message (without any protobuf masking)
  • protoBufHeader - If this is a protobuf-based message, this needs to be the protobuf header for this message. If you don't need any custom header fields (you almost definitely don't), pass an empty object here ({}). Otherwise, if this is not a protobuf-based message, pass null.
  • payload - The payload for this message, either a serialized protobuf message or a stream of bytes. Either way, it should be a Buffer (or a ByteBuffer).
  • callback - Optional. If this is a job-based message, pass a callback here and it will be invoked when a response is available.
    • appid - The AppID of the GC this response came from
    • msgType - The GC-specific msg ID for this response (without any protobuf masking)
    • payload - The payload of this response, as a Buffer

Send a message to a GC.

Events

appLaunched

  • appid

Emitted when gamesPlayed is called with a Steam AppID, indicating that you are now "playing" this game.

appQuit

  • appid

Emitted when gamesPlayed is called without a Steam AppID that was present in the previous invocation of appQuit.

Note: This will not be emitted if the client disconnects from Steam. If you want to know if an app is no longer being "played", you should also listen for disconnected and error events.

receivedFromGC

  • appid - The AppID of the GC this message came from
  • msgType - The GC-specific msg ID for this message (without any protobuf masking)
  • payload - The payload for this message, as a Buffer

Emitted when a message is received from a GC but not as a job response (i.e. a callback to sendToGC).