Crates.io | dota-gsi |
lib.rs | dota-gsi |
version | 0.1.4 |
source | src |
created_at | 2022-11-14 23:05:05.106335 |
updated_at | 2024-06-30 12:13:22.269888 |
description | Game State Integration with Dota 2 in rust. Provides a server that listens for JSON events sent by Dota 2. |
homepage | |
repository | https://github.com/tomasfarias/dota-gsi |
max_upload_size | |
id | 715251 |
size | 115,732 |
Game State Integration with Dota 2 in rust. Provides a server that listens for JSON events sent by Dota 2.
Integration requires:
.cfg
configuration file in the Dota 2 game configuration directory.The configuration file can have any name name, but must be prefixed by gamestate_integration_
.
For example, gamestate_integration_test.cfg
would be located:
~/.steam/steam/steamapps/common/dota 2 beta/game/dota/cfg/gamestate_integration_test.cfg
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 showcase how to implement handlers that parse the game state data and do whatever we want with it.
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