Web Marketing
Live Chat | Request a Quote

Blog

Musings on design, development, and digital marketing

CSGO Gambling Skins Jackpot: How to Log into Steam’s Servers and Web Interface with a Node.js Bot?

THURSDAY, SEPTEMBER 28, 2017

Gaming has always been a fascinating segment of the world entertainment media. Valve Corporation developed Steam to cater to this same segment. Currently, its gaming platform hosts thousands of games and caters to gamers from not only the US, but Europe, Japan, and the rest of the world.

Counter-Strike Global Offensive (CSGO) a popular Steam game. Being popular, it has encouraged the game's programmers to develop and sell cosmetic “skins”, also known as Counter Strike skins. Skins are short snippets of software that integrate with players and make them more powerful. While some skins add only a minuscule power to a player's punch, others can decide the fate of an entire game. Naturally, those in the latter category command the highest prices in skins' marketplace. (Only game developers can develop skins.)

A lot of the players cannot or don't want to spend real dollars on purchasing skins. So they resort to skin gambling or CSGO betting. Several CSGO gambling sites exist where gamers hedge their skins in a winner-takes-all play. In fact, you can create your own jackpot website. All you need is a Steam account and familiarity with Node.js.

In this tutorial you will learn to implement a crucial part of developing a full-fledged Steam jackpot website: Creating a bot that can log into a Steam server, be an active resident there, listen to Steam events, and make API requests to other Steam servers with the goal to communicate and exchange trade offers between gamers. Such bots are at the root of many Steam-independent gambling websites. If the task seems ovewhelming, you can consult an expert from a Node.js development company, such as Cogniter.

Prerequisites

Developing a CSGO betting bot at the root of a Steam gambling website is neither as easy as publishing hello, world nor as challenging as designing the C language. You will need a deeper-than-superficial familiarity with programming and the following tools:

  1. Node.js: a JavaScript framework, will be used to develop a bot for a Steam jackpot website. Familiarity required: Above beginner. So we are going to create a Node.js application.
  2. node-steam: A Node.js library for interfacing with Steam servers. Connects directly to the servers and provides well-thought abstractions without taking away the power to manipulate low-level procedures. Downloadable from GitHub.
  3. node-steam-totp: A Node.js library that generates a two-factor authentication code. This piece of code is essential for a secure login into a Steam server.
  4. node-steam-weblogon: A node-steam implementation, used to log into Steam's web servers.
  5. node-steam-web-api-key: A Node.js library, used to interact with Steamworks' API key.
  6. A Steam account. The APIs should be enabled.

Procedure

Once the libraries have been downloaded and tested to be working, you can start off with implementation.

Create a Node.js Module

Keep node-steam, node-steam-totp, node-steam-weblogon, node-steam-web-api-key, and core Node.js library inside the module's scope.

var
  EventEmitter			= require('events').EventEmitter,
  Steam				= require('steam'),
  SteamWebLogOn			= require('steam-weblogon'),
  GetSteamAPIKey		= require('steam-web-api-key'),
  SteamTotp			= require('steam-totp'),
  Util				= require('util'),
  Fs				= require('fs'),
  Crypto			= require('crypto'),
  Path				= require('path'),
  Config			= require('./../../config/config.json');

Create a Bot Function

The bot function will be the Steam bot's constructor. The name associated with the Steam account will be passed as a parameter to the constructor.

function Bot(accountName) {
  if (!accountName) {
    throw new Error("Bot account name is required.");
    return;
  }

Add EventEmitter to the Bot Function

Through EventEmitter, the Steam bot can communicate with other services through its listener and emitter events.

 EventEmitter.call(this);
  this._client = new Steam.SteamClient();
  this._user = new Steam.SteamUser(this._client);
  this._web = new SteamWebLogOn(this._client, this._user);
  this._account = accountName.trim().toLowerCase();
}
Util.inherits(Bot, EventEmitter);
module.exports = Bot;

Create a SteamClient Object

Store the object inside the bot's this._client.

Create SteamUser and SteamWebLogOn

SteamUser requires a Steam client to function. SteamWebLogOn requires a Steam client and several SteamUser objects to work flawlessly. The last two lines of the code in Image 3 show that each Bot instance inherits the all of EventEmitter.

Let the World See Your Bot

The statement module.exports = Bot; statement reveals the Bot object to the outside world.

Log into Steam with getBotDetails()

getBotDetails() extends the bot constructor and fetches the details needed to log into a Steam account through a bot. Details like a shared secret (used for two-factor authentication) and identity secret are utilized for trade confirmations. Account name and password are also fetched to log into a Steam server. The data needed for configuration is taken from config.json (Image 1).

var options {…} creates a structure to store login data. The structure is then passed to a SteamUser instance's logOn().

Bot.prototype.getBotDetails = function () {
  var profile = Path.resolve('../config/profiles/' + Config.bot[this._account].account_name + '.json');
  if (Fs.existsSync(profile)) {
    var _2fa = JSON.parse(Fs.readFileSync(profile, 'utf8'));
    this.shared_secret = _2fa.shared_secret;
    this.identity_secret = _2fa.identity_secret;
  } else {
    throw new Error('Bot profile file not found.');
    return;
  }
  
  var options = {
    account_name: Config.bot[this._account].account_name,
    password: Config.bot[this._account].password,
    two_factor_code: SteamTotp.generateAuthCode(_2fa.shared_secret)
  }
  
  return options;
};

Log into a Steam Server

Bot.logIn() function is doing the actual bot account logon to the Steam server and Steam web community (or Node.js server). A connection to the server is initiated by executing connect() of a SteamClient object.

A "connected" event is emitted as soon as the connection is established. SteamClient can listen to the emission through the "on" method.

Bot.prototype.logIn = function () {
  this._client.connect();
  this._client.on('connected', () => {
    this._user.logOn(this.getBotDetails());
  });
  
  this._client.on('logOnResponse', (logonResp) => {
    if (logonResp.eresult === Steam.EResult.OK) {
      this.emit('loggedIn', logonResp);
      this._web.webLogOn((sessionID, newCookie) => {
        this._sessID = sessionID;
        this._wcookie = newCookie;
        GetSteamAPIKey({
          sessionID: sessionID,
          webCookie: newCookie
        }, (err, APIKey) => {
          this._APIKey = APIKey;
        });
      });
    } else {
      this.emit('LoginFailed', logonResp);
    }
  });
};

Inside the "connected" event listener, a SteamUser object's logOn() is executed. The details are passed to logOn() through getBotDetails().

SteamClient remits logOnResponse() when an attempt to log in is made. After being listened to, the event passes a logOnResp parameter. If eresult == Steam.EResult.OK, the login was successful.

Log into Steam's Web Interface

steam-tradeoffer-manager is used to log into Steam's web interface. Call weblogon() from the SteamWebLogOn library. weblogon() accepts a callback function with two parameters: session ID generated for the web logon and cookies that identify the bot. Once the session ID and cookies are fetched, you can get an API key for your account by calling GetSteamAPIKey() of node-steam-web-api-key. The API key is used by libraries to utilize Steam community features.

Voila – The Bot is Ready

Your steam trade bot is ready to run in the background with minimal functionality. The functionality can be enhanced to create jackpot websites and trade skins.

Takeaway

This short guide contains information for any intermediate level Node.js developer to code a bot. If you find the task overwhelming, or if your business needs a bot developed reliably and quickly, consider hiring our Node.js developers. We have several years' experience in working in Node.js, and have developed multiple Steam bots for our clients during this period.

Posted By Chetan Anand at
Label(s):  

comments powered by Disqus
 
Share on Facebook. Share on Google+ Pin It

Blogs by Categories

Blogs by Years


2023

2022

2021

2020

2019

2018

2017

2016

2015

2014

2013

2012

Recent Posts

News and Events

News and information of our company, projects, partnerships, staff and community.

Show All