Convert Figma logo to code with AI

seishun logonode-steam

Interface directly with Steam servers from Node.js

1,005
180
1,005
1

Top Related Projects

SteamKit2 is a .NET library designed to interoperate with Valve's Steam network. It aims to provide a simple, yet extensible, interface to perform various actions on the network.

Automated bot software for interacting with Steam Trade

1,114

☁️ Python package for interacting with Steam

Quick Overview

Node-steam is a Node.js library for interacting with the Steam network. It provides a comprehensive set of tools for developers to create Steam-related applications, bots, and services, allowing them to interface with various Steam features programmatically.

Pros

  • Extensive API coverage for Steam functionality
  • Active community and regular updates
  • Well-documented with examples and API references
  • Supports both user and bot account interactions

Cons

  • Steep learning curve for beginners
  • Requires careful handling of Steam credentials
  • Some features may break due to Steam updates
  • Limited official support, mainly community-driven

Code Examples

  1. Logging in to Steam:
const Steam = require('steam');

const client = new Steam.SteamClient();
const user = new Steam.SteamUser(client);

client.connect();
client.on('connected', () => {
  user.logOn({
    account_name: 'username',
    password: 'password'
  });
});

user.on('loggedOn', () => {
  console.log('Logged in!');
});
  1. Sending a chat message:
const Steam = require('steam');

const client = new Steam.SteamClient();
const user = new Steam.SteamUser(client);
const friends = new Steam.SteamFriends(client);

// Assume login code here...

friends.on('friendMsg', (steamID, message, type) => {
  if (type === Steam.EChatEntryType.ChatMsg) {
    friends.sendMessage(steamID, 'Hello! I received your message: ' + message);
  }
});
  1. Retrieving game details:
const Steam = require('steam');

const client = new Steam.SteamClient();
const apps = new Steam.SteamApps(client);

// Assume login code here...

apps.getProductInfo([440], [], (apps, packages, unknownApps, unknownPackages) => {
  console.log('Team Fortress 2 details:', apps[440]);
});

Getting Started

  1. Install the library:

    npm install steam
    
  2. Create a new JavaScript file (e.g., steam-bot.js) and add the following code:

    const Steam = require('steam');
    
    const client = new Steam.SteamClient();
    const user = new Steam.SteamUser(client);
    
    client.connect();
    client.on('connected', () => {
      user.logOn({
        account_name: 'your_username',
        password: 'your_password'
      });
    });
    
    user.on('loggedOn', () => {
      console.log('Successfully logged into Steam!');
    });
    
  3. Replace 'your_username' and 'your_password' with your Steam credentials.

  4. Run the script:

    node steam-bot.js
    

Remember to handle Steam Guard and other authentication methods as needed. Refer to the library's documentation for more advanced usage and features.

Competitor Comparisons

SteamKit2 is a .NET library designed to interoperate with Valve's Steam network. It aims to provide a simple, yet extensible, interface to perform various actions on the network.

Pros of SteamKit

  • More comprehensive and feature-rich, covering a wider range of Steam functionalities
  • Better documentation and community support
  • Actively maintained with regular updates and bug fixes

Cons of SteamKit

  • Steeper learning curve due to its extensive feature set
  • Requires more setup and configuration compared to node-steam
  • May be overkill for simple Steam-related tasks

Code Comparison

node-steam:

var Steam = require('steam');
var steamClient = new Steam.SteamClient();
steamClient.logOn({
  accountName: 'username',
  password: 'password'
});

SteamKit:

var steamClient = new SteamClient();
var manager = new CallbackManager(steamClient);
var steamUser = steamClient.GetHandler<SteamUser>();
steamClient.Connect();
steamUser.LogOn(new SteamUser.LogOnDetails {
    Username = "username",
    Password = "password"
});

Both libraries provide similar basic functionality for connecting to Steam, but SteamKit offers more advanced features and control over the connection process. node-steam is more straightforward for simple tasks, while SteamKit provides a more robust foundation for complex Steam-related applications.

Automated bot software for interacting with Steam Trade

Pros of SteamBot

  • Written in C#, which may be more familiar to some developers
  • Includes a user interface for easier management and interaction
  • Offers more built-in features specific to Steam trading and bot functionality

Cons of SteamBot

  • Less actively maintained, with fewer recent updates
  • More complex setup process due to additional dependencies
  • Limited to Windows environments, reducing cross-platform compatibility

Code Comparison

node-steam (JavaScript):

var Steam = require('steam');
var steamClient = new Steam.SteamClient();
steamClient.logOn({
  accountName: 'username',
  password: 'password'
});

SteamBot (C#):

SteamBot bot = new SteamBot(
    "username",
    "password",
    "steamGuard",
    "botName"
);
bot.Connect();

Summary

node-steam is a lightweight, cross-platform Node.js library for interacting with the Steam network, while SteamBot is a more feature-rich C# implementation specifically designed for creating Steam trading bots. node-steam offers greater flexibility and broader platform support, making it suitable for various Steam-related projects. SteamBot, on the other hand, provides a more comprehensive solution for trading bots but is limited to Windows environments and has a steeper learning curve.

1,114

☁️ Python package for interacting with Steam

Pros of steam

  • Written in Python, offering better integration with data science and machine learning libraries
  • More active development and maintenance, with recent updates and contributions
  • Comprehensive documentation and examples available in the repository

Cons of steam

  • Potentially slower performance compared to Node.js-based solutions
  • May require additional setup for developers more familiar with JavaScript ecosystems

Code Comparison

steam (Python):

from steam.client import SteamClient

client = SteamClient()
client.login(username, password)
client.games_played([440])  # Team Fortress 2

node-steam (JavaScript):

const Steam = require('steam');

const client = new Steam.SteamClient();
client.logOn({accountName: username, password: password});
client.gamesPlayed([440]);  // Team Fortress 2

Both libraries provide similar functionality for interacting with the Steam platform, but with syntax and usage patterns typical of their respective languages. The Python version (steam) offers a more object-oriented approach, while the Node.js version (node-steam) follows a more event-driven pattern common in JavaScript applications.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Steam for Node.js

NPM version Dependency Status PayPal donate button

This is a Node.js port of SteamKit2. It lets you interface with Steam without running an actual Steam client. Could be used to run an autonomous chat/trade bot.

Installation

npm install steam

Note: installing from git requires svn to fetch Steam resources (Protobufs and SteamLanguage) and curl to fetch the server list.

Note: only Node.js v4.1.1 and above is supported.

Usage

First, require this module.

var Steam = require('steam');

Steam is now a namespace object containing:

Then you'll want to create an instance of SteamClient and any handlers you need, call SteamClient#connect and assign event listeners.

var steamClient = new Steam.SteamClient();
var steamUser = new Steam.SteamUser(steamClient);
steamClient.connect();
steamClient.on('connected', function() {
  steamUser.logOn({
    account_name: 'username',
    password: 'password'
  });
});
steamClient.on('logOnResponse', function() { /* ... */});

See example.js for the usage of some of the available API.

Servers

Steam.servers contains the list of CM servers node-steam will attempt to connect to. The bootstrapped list (fetched in prepare) can get out of date and thus 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:

  • (u)int32 and fixed32 fields: Number
  • uint64, fixed64 and string fields: String
  • bytes fields: Buffer objects
  • bool fields: Boolean

See the 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:

If you think some unimplemented functionality belongs in one of the existing handlers, feel free to submit an issue to discuss it.

SteamClient

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 other than SteamUser#logOn is only allowed while logged on.

sessionID

Your session ID while logged on, otherwise unspecified. (Note: this has nothing to do with the "sessionid" cookie)

steamID

Your own SteamID while logged on, otherwise unspecified. Must be set to a valid initial value before sending a logon message (SteamUser#logOn does that for you).

Methods

connect()

Connects to Steam. It will keep trying to reconnect 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.

Events

'error'

Connection closed by the server. Only emitted if the encryption handshake is complete, otherwise it will reconnect automatically. 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 (see SteamUser#logOn).

'logOnResponse'

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

'servers'

  • an Array containing the up-to-date server list

node-steam 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'

  • EResult

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

'message'/send

Sending and receiving client messages is designed to be symmetrical, so the event and the method are documented together. Both have the following arguments:

  • header - an object representing the message header. It has the following properties:
    • msg - EMsg (no protomask).
    • proto - a CMsgProtoBufHeader object if this message is protobuf-backed, otherwise header.proto is falsy. The following fields are reserved for internal use and shall be ignored: steamid, client_sessionid, jobid_source, jobid_target. (Note: pass an empty object if you don't need to set any fields)
  • body - a Buffer containing the rest of the message. (Note: in SteamKit2's terms, this is "Body" plus "Payload")
  • callback (optional) - if not falsy, then this message is a request, and callback shall be called with any response to it instead of 'message'/send. callback has the same arguments as 'message'/send.

NPM DownloadsLast 30 Days