dota2-gsi-sockets
v1.1.0
Published
Dota 2 Game State Integration server
Downloads
9
Maintainers
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 ofplayer
. If you're trying to initialise values such asmap:daytime
, the easiest way to achieve it is to wait on the firstmap: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.