npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dota2-gsi-sockets

v1.1.0

Published

Dota 2 Game State Integration server

Downloads

9

Readme

Node.js Dota 2 GSI module (using websockets)

dota2-gsi-sockets provides an event driven interface for Dota 2's live GameState Integration data. When configured, the Dota client will send regular messages to the dota2-gsi-sockets server, which emits an event for each attribute whenever it changes.

This package is a fork of dota2-gsi, which performs the same function using EventEmitter instead of sockets.

Installation

npm install dota2-gsi-sockets

Usage

var d2gsi = require('dota2-gsi-sockets');
var server = new d2gsi([options]);

The server can be configured by passing an optional object to the constructor:

{
    port: The port that the server should listen on (default: 3000),
    ip: The IP address that the server should listen on (default: "0.0.0.0"),
    tokens: A single string or array of strings that are valid auth tokens (default: no auth required)
}

Once started, the server will accept socket requests to the supplied IP address and port, and begin emitting game data when it's available.

Examples

Using events

var d2gsi = require('dota2-gsi-sockets');
var io = require('socket.io-client');
var server = new d2gsi();

// Connect to the socket
var socket = io('http://localhost:3000');

socket.on('newclient', (client) => {
    console.log("New client connection, IP address: " + client.ip);
    if (client.auth && client.auth.token) {
        console.log("Auth token: " + client.auth.token);
    } else {
        console.log("No Auth token");
    }
});

socket.on('draft:activeteam', (msg) => {
    console.log("The active team drafting has changed to " + msg);
});

socket.on('hero:team2:player0:alive', (isAlive) => {
    if (isAlive) {
        console.log("Player 0 has respawned");
    } else {
        console.log("Player 0 has been killed!");
    }
});

Events

The server will emit the following events to all connected sockets any time they change. This list may not be complete, as Valve can silently change the key names or add news ones at any time. If you discover some new outputs, please send a pull request!

All team# references may either be team2 for Radiant, or team3 for Dire. All player# references range from player0 to player9, where 0-4 are the Radiant team and 5-9 are the Dire.

newdata - The entire raw json object sent from the Dota client
provider:name
provider:appid
provider:version
provider:timestamp
map:clock_time
map:daytime
map:dire_ward_purchase_cooldown
map:game_state
map:game_time
map:name
map:matchid
map:radiant_ward_purchase_cooldown
map:nightstalker_night
map:roshan_state
map:roshan_state_end_seconds
map:win_team
map:customgamename
player:team#:player#:assists
player:team#:player#:camps_stacked
player:team#:player#:deaths
player:team#:player#:denies
player:team#:player#:gold
player:team#:player#:gold_reliable
player:team#:player#:gold_unreliable
player:team#:player#:gpm
player:team#:player#:hero_damage
player:team#:player#:kill_list:victimid_#
player:team#:player#:kill_streak
player:team#:player#:kills
player:team#:player#:last_hits
player:team#:player#:net_worth
player:team#:player#:pro_name
player:team#:player#:runes_activated
player:team#:player#:support_gold_spent
player:team#:player#:wards_destroyed
player:team#:player#:wards_placed
player:team#:player#:wards_purchased
player:team#:player#:xpm
hero:team#:player#:alive
hero:team#:player#:break
hero:team#:player#:buyback_cost
hero:team#:player#:buyback_cooldown
hero:team#:player#:disarmed
hero:team#:player#:has_debuff
hero:team#:player#:health
hero:team#:player#:health_percent
hero:team#:player#:hexed
hero:team#:player#:id
hero:team#:player#:level
hero:team#:player#:magicimmune
hero:team#:player#:mana
hero:team#:player#:mana_percent
hero:team#:player#:max_health
hero:team#:player#:max_mana
hero:team#:player#:muted
hero:team#:player#:name
hero:team#:player#:respawn_seconds
hero:team#:player#:selected_unit
hero:team#:player#:silenced
hero:team#:player#:stunned
hero:team#:player#:talent_# (1-8)
hero:team#:player#:xpos
hero:team#:player#:ypos
items:team#:player#:slot#:can_cast
items:team#:player#:slot#:charges
items:team#:player#:slot#:contains_rune
items:team#:player#:slot#:cooldown
items:team#:player#:slot#:name
items:team#:player#:slot#:passive
items:team#:player#:slot#:purchaser

items:team#:player#:stash#:can_cast
items:team#:player#:stash#:charges
items:team#:player#:stash#:contains_rune
items:team#:player#:stash#:cooldown
items:team#:player#:stash#:name
items:team#:player#:stash#:passive
items:team#:player#:stash#:purchaser
abilities:team#:player#:ability#:ability_active
abilities:team#:player#:ability#:can_cast
abilities:team#:player#:ability#:cooldown
abilities:team#:player#:ability#:level
abilities:team#:player#:ability#:name
abilities:team#:player#:ability#:passive
abilities:team#:player#:ability#:ultimate
buildings:radiant:dota_goodguys_tower#_top.health (1-4)
buildings:radiant:dota_goodguys_tower#_top.max_health
buildings:radiant:dota_goodguys_tower#_mid.health (1-3)
buildings:radiant:dota_goodguys_tower#_mid.max_health
buildings:radiant:dota_goodguys_tower#_bot.health (1-4)
buildings:radiant:dota_goodguys_tower#_bot.max_health
buildings:radiant:good_rax_range_top.health
buildings:radiant:good_rax_range_top.max_health
buildings:radiant:good_rax_melee_top.health
buildings:radiant:good_rax_melee_top.max_health
buildings:radiant:good_rax_range_mid.health
buildings:radiant:good_rax_range_mid.max_health
buildings:radiant:good_rax_melee_mid.health
buildings:radiant:good_rax_melee_mid.max_health
buildings:radiant:good_rax_range_bot.health
buildings:radiant:good_rax_range_bot.max_health
buildings:radiant:good_rax_melee_bot.health
buildings:radiant:good_rax_melee_bot.max_health
buildings:radiant:dota_goodguys_fort:health
buildings:radiant:dota_goodguys_fort:max_health

buildings:dire:dota_badguys_tower#_top.health (1-4)
buildings:dire:dota_badguys_tower#_top.max_health
buildings:dire:dota_badguys_tower#_mid.health (1-3)
buildings:dire:dota_badguys_tower#_mid.max_health
buildings:dire:dota_badguys_tower#_bot.health (1-4)
buildings:dire:dota_badguys_tower#_bot.max_health
buildings:dire:bad_rax_range_top.health
buildings:dire:bad_rax_range_top.max_health
buildings:dire:bad_rax_melee_top.health
buildings:dire:bad_rax_melee_top.max_health
buildings:dire:bad_rax_range_mid.health
buildings:dire:bad_rax_range_mid.max_health
buildings:dire:bad_rax_melee_mid.health
buildings:dire:bad_rax_melee_mid.max_health
buildings:dire:bad_rax_range_bot.health
buildings:dire:bad_rax_range_bot.max_health
buildings:dire:bad_rax_melee_bot.health
buildings:dire:bad_rax_melee_bot.max_health
buildings:dire:dota_badguys_fort:health
buildings:dire:dota_badguys_fort:max_health
draft:activeteam
draft:activeteam_time_remaining
draft:dire_bonus_time
draft:pick
draft:radiant_bonus_time
draft:team#:home_team
draft:team#:ban#_class (0-5)
draft:team#:ban#_id (0-5)
draft:team#:pick#_class (0-4)
draft:team#:pick#_id (0-4)
wearables:team#:player#:wearable#
wearables:team#:player#:style#

Quirks

  • The Dota client does not announce all keys in an 'added' event, so there's no initial emit for some child attributes. This includes all of provider, map, and some of player. If you're trying to initialise values such as map:daytime, the easiest way to achieve it is to wait on the first map:gametime event then manually query the values from the gamestate.
  • Item and hero names are returned as strings using the console format. Dota 2 Wiki has a list of translations for items and heroes.

Configuring the Dota 2 Client

To configure the Dota client to report gamestate, you need to add a config file in steamapps\common\dota 2 beta\game\dota\cfg\gamestate_integration\. The file must use the name pattern called gamestate_integration_*.cfg, for example gamestate_integration_dota2-gsi.cfg.

The following example is included in this repository, you can copy it straight into your Dota directory to get started.

"dota2-gsi Configuration"
{
    "uri"               "http://localhost:3000/"
    "timeout"           "5.0"
    "buffer"            "0.1"
    "throttle"          "0.1"
    "heartbeat"         "30.0"
    "data"
    {
        "buildings"     "1"
        "provider"      "1"
        "map"           "1"
        "player"        "1"
        "hero"          "1"
        "abilities"     "1"
        "items"         "1"
        "draft"         "1"
        "wearables"     "1"
    }
    "auth"
    {
        "token"         "hello1234"
    }
}

For more information, see the CS:GO GameState Integration page

Caveats

Full player data is now available, but only to spectators and observers (as one would expect). The existing single player GSI data is still available, however the names of events are different to what is listed above. Please refer to previous versions of this readme or uncomment the console logging in index.js to see which keys are available

Credits

Shoutout to /u/antonpup for his C# Gamestate Integration server and inadvertently letting me know this existed.