-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathechoslam.rs
45 lines (35 loc) · 1.05 KB
/
echoslam.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use clap::Parser;
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);
}
/// Listen for Dota 2 events and echo (slam) them.
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
struct Args {
/// URI for the server to listen for events.
/// This must be the same URI used in the Game State configuration file.
#[arg(short, long)]
uri: String,
/// Don't attempt to parse JSON data.
/// Echo raw JSON events as received from Dota 2.
#[arg(short, long)]
raw: bool,
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
env_logger::init();
let args = Args::parse();
let server = GSIServer::new(&args.uri);
if args.raw {
server.run(echo_json_handler).await?;
} else {
server.run(echo_gamestate_handler).await?;
}
Ok(())
}