globaloffensive

repository·master·Indexed 18 days ago

https://github.com/doctormckay/node-globaloffensive

A Node.js interface for interacting with the Counter-Strike 2 (CS2) and Counter-Strike: Global Offensive Game Coordinator. Built on top of node-steam-user, it provides a simple API to access account data, manage inventories, inspect items, request game statistics, and handle storage units (caskets). Features include methods for crafting items, renaming items, and retrieving player profiles.

Tokens
5.2K
Snippets
12
Records
29
Agent score
13%

What's inside globaloffensive

  1. Access accountData and inventory

    master

    The module provides two main data properties that are populated once the connection is established:

    • accountData: A large object containing account statistics and information about players currently in-game. This is undefined until the accountData event is emitted.
    • inventory: An array containing the items in your inventory. This is undefined until the connectedToGC event is emitted.

    Note on Inventory and Storage Units: If you are using the inventory array to track items, be aware that the GC may load items from storage units (caskets) into your inventory without a specific call. To avoid counting items that are actually inside a storage unit, you should filter your inventory check by the casket_id property.

  2. How the Game Coordinator connection lifecycle works

    master

    The globaloffensive module interacts with the CS2 Game Coordinator (GC). Because the connection is not instantaneous, you must follow this lifecycle:

    1. Initialization: Create a GlobalOffensive instance with a SteamUser instance.
    2. Triggering Connection: Call user.gamesPlayed([730]) on your SteamUser instance.
    3. Waiting for Readiness: The module will emit a connectedToGC event once the connection is successful.

    Warning: Do not attempt to call methods or access properties like inventory or accountData before the connectedToGC event has fired, as they may be undefined or the request may fail.

  3. Install and Setup globaloffensive

    master

    To use globaloffensive, you must first install it via npm. The module is designed to work with a node-steam-user instance.

    Requirements:

    • steam-user v4.2.0 or later
    • Node.js v14 or later (for globaloffensive v3)

    Setup Steps:

    1. Install the package:
      npm install globaloffensive
    2. Initialize the module by passing your SteamUser instance to the GlobalOffensive constructor.
    3. Launch the game via SteamUser using client.gamesPlayed([730]) to establish a connection to the Game Coordinator (GC).
    4. Important: Wait for the connectedToGC event before attempting to call any methods or access properties, as the connection must be established first.
    const SteamUser = require('steam-user');
    const GlobalOffensive = require('globaloffensive');
    
    let user = new SteamUser();
    let csgo = new GlobalOffensive(user);
    
    // To initialize the GC connection:
    user.gamesPlayed([730]);
    
    // Listen for the connection event before using the API
    csgo.on('connectedToGC', () => {
        console.log('Connected to the Game Coordinator!');
    });
  4. How the GlobalOffensive client handles GC messages

    master

    The GlobalOffensive client acts as an EventEmitter. It listens to the underlying steam-user instance for receivedFromGC events.

    When a message arrives from the CS:GO Game Coordinator:

    1. It checks if the appid matches 730 (CS:GO/CS2).
    2. It identifies the message type (using the Language mapping).
    3. It looks for a registered handler in this._handlers (defined in handlers.js).
    4. If a handler exists, it executes it, passing either the raw Buffer or a ByteBuffer depending on whether the payload is a Protobuf.
    5. It emits a debug event for every message received (handled or unhandled).
  5. Initialize the GlobalOffensive client

    master

    To use node-globaloffensive, you must provide an instance of steam-user. The client requires steam-user version 4.2.0 or later. The GlobalOffensive instance will automatically attempt to connect to the CS:GO Game Coordinator (GC) once it detects the game has launched via the appLaunched event.

    const GlobalOffensive = require('node-globaloffensive');
    const SteamUser = require('steam-user');
    
    const steam = new SteamUser();
    // ... login logic ...
    
    const client = new GlobalOffensive(steam);
  6. Handle item inspection and customization events

    master

    The library provides events for inspecting specific items and receiving notifications about item changes.

    • inspectItem: Emitted in response to an inspectItem() call (requires v1.1.0+). It returns an item object containing detailed metadata like itemid, defindex, paintwear (float 0-1), stickers, and killeatervalue for StatTrak items.
    • inspectItemTimedOut: Emitted if an inspectItem() call fails to receive a timely response (requires v2.1.0+). Returns the assetid of the attempted item.
    • itemCustomizationNotification: Emitted when the GC informs the client that an item has been customized (requires v2.1.0+). Returns itemIds (array of strings) and a notificationType from the ItemCustomizationNotification enum.
    const GlobalOffensive = require('globaloffensive');
    let csgo = new GlobalOffensive(steamUser);
    
    csgo.on('itemCustomizationNotification', (itemIds, notificationType) => {
        if (notificationType == GlobalOffensive.ItemCustomizationNotification.CasketInvFull) {
            console.log('Storage unit ' + itemIds[0] + ' is full');
        }
    });
  7. Request historical game stats with requestGame()

    master

    Requests stats for a historical game. Requires v2.2.0 or later.

    Parameters:

    • shareCodeOrDetails: Either a share code as a string, or an object containing properties matchId, outcomeId, and token.

    Response: Listen for the matchList event to receive the response.

  8. Manage storage units (Caskets) with addToCasket() and removeFromCasket()

    master

    Manage items within storage units (caskets). Requires v2.1.0 or later for both methods.

    Add to Casket: addToCasket(casketId, itemId)

    • Moves an item into a storage unit.
    • Emits itemRemoved and itemCustomizationNotification (type CasketAdded).

    Remove from Casket: removeFromCasket(casketId, itemId)

    • Moves an item from a storage unit back to your inventory.
    • Emits itemAcquired and itemCustomizationNotification (type CasketRemoved).
  9. Retrieve player profile data via playersProfile event

    master

    The playersProfile event is emitted in response to a requestPlayersProfile() call. It provides a comprehensive profile object containing:

    • account_id: Steam account ID.
    • ranking: Current rank (0-18), wins, and rank_type_id (6: Matchmaking, 7: Wingman, 10: Danger Zone).
    • commendation: Counts for cmd_friendly, cmd_teaching, and cmd_leader.
    • medals: Achievement medals and associated coins.
    • player_level: Private rank level.
    • player_cur_xp: Current XP. To calculate level percentage: (player_cur_xp - 327680000) / 5000.
    • vac_banned: Boolean status.
    • penalty_seconds and penalty_reason: Current penalties.