dota-gsi

Crates.iodota-gsi
lib.rsdota-gsi
version0.1.4
sourcesrc
created_at2022-11-14 23:05:05.106335
updated_at2024-06-30 12:13:22.269888
descriptionGame State Integration with Dota 2 in rust. Provides a server that listens for JSON events sent by Dota 2.
homepage
repositoryhttps://github.com/tomasfarias/dota-gsi
max_upload_size
id715251
size115,732
Tomás Farías Santana (tomasfarias)

documentation

README

dota-gsi

Game State Integration with Dota 2 in rust. Provides a server that listens for JSON events sent by Dota 2.

Requirements

Integration requires:

  1. Creating a .cfg configuration file in the Dota 2 game configuration directory.
  2. Running Dota 2 with the -gamestateintegration launch option.

The configuration file can have any name name, but must be prefixed by gamestate_integration_. For example, gamestate_integration_test.cfg would be located:

  • In Linux: ~/.steam/steam/steamapps/common/dota 2 beta/game/dota/cfg/gamestate_integration_test.cfg
  • In Windows: D:\Steam\steamapps\common\dota 2 beta\csgo\cfg\gamestate_integration_test.cfg

Here's a sample configuration file:

"dota2-gsi Configuration"
{
   "uri"               "http://127.0.0.1:53000/"
   "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"         "abcdefghijklmopqrstuvxyz123456789"
   }
}

Take note of the URI used in the configuration file as it must be the same URI used when creating a new GSIServer.

Examples

Examples showcase how to implement handlers that parse the game state data and do whatever we want with it.

Echoslam: echo back data received by the server

This program uses the provided component models to attempt to parse the JSON received by the server. See the full program at src/bin/echoslam.rs

We simply define two echo handlers as:

use dota::{components::GameState, GSIServer};

/// Echo back Dota GameState integration state.
async fn echo_gamestate_handler(gs: GameState) {
    println!("{}", gs);
}

/// Echo back raw JSON events.
async fn echo_json_handler(value: serde_json::Value) {
    println!("{}", value);
}

Initialize the GSIServer using command line arguments with:

let server = GSIServer::new(&args.uri);

And we pass the handlers to the server when running:

if args.raw {
    server.run(echo_json_handler).await?;
} else {
    server.run(echo_gamestate_handler).await?;
}

We have defined a command line flag that determines whether we are attempting to parse the JSON data before echoing it or passing the raw JSON.

This program is provided with dota-gsi and can be compiled with:

cargo build --release --bin echoslam
Commit count: 34

cargo fmt