cs2_gsi/lib.rs
1//! # cs2-gsi
2//!
3//! Counter-Strike 2 **Game State Integration** listener for Rust.
4//!
5//! - **Async, single dependency surface** — built on `tokio` + `hyper` 1.x.
6//! - **Strongly typed** model and events (no `serde_json::Value` in your code).
7//! - **Drop-in cfg writer** — generate the right `gamestate_integration_*.cfg`
8//! into the right place via Steam path discovery.
9//! - **Event diffing** done for you: subscribe to `PlayerDied`,
10//! `BombPlanted`, `RoundPhaseUpdated`, `KillFeed`, … instead of comparing
11//! payloads by hand.
12//!
13//! ## Quick start
14//!
15//! ```no_run
16//! use cs2_gsi::{events::PlayerDied, cfg::GsiCfg, GameStateListener};
17//!
18//! # async fn run() -> Result<(), Box<dyn std::error::Error>> {
19//! // 1. Drop a gamestate_integration_*.cfg into the CS2 cfg dir.
20//! #[cfg(feature = "steam-discover")]
21//! GsiCfg::for_localhost("ImLag", 4000).write_to_cs2()?;
22//!
23//! // 2. Stand up the listener.
24//! let listener = GameStateListener::new(4000);
25//! listener.on(|e: &PlayerDied| {
26//! println!("☠ {} died", e.player.name);
27//! });
28//! listener.start().await?;
29//!
30//! // ... run the rest of your app ...
31//!
32//! listener.stop().await?;
33//! # Ok(()) }
34//! ```
35//!
36//! ## How it works
37//!
38//! ```text
39//! CS2 client Your app
40//! ┌──────────┐ ┌───────────────┐
41//! │ cfg file │── HTTP POST JSON ──────────▶│ GameStateList │
42//! └──────────┘ │ (this lib) │
43//! ▲ │ diff │
44//! │ generate cfg │ ▼ │
45//! └─────────────────────────────────│ typed events │
46//! └───────────────┘
47//! ```
48//!
49//! Every payload arrives as JSON, is parsed into a [`model::GameState`],
50//! diffed against the previous one and turned into a stream of typed
51//! events. Handlers run synchronously on the listener task — keep them
52//! light or `tokio::spawn` from inside.
53
54#![cfg_attr(docsrs, feature(doc_cfg))]
55#![warn(missing_docs)]
56#![warn(rust_2018_idioms)]
57
58pub mod cfg;
59mod dispatcher;
60pub mod error;
61pub mod events;
62mod handlers;
63mod listener;
64pub mod model;
65pub mod steam;
66
67pub use crate::error::{Error, Result};
68pub use crate::events::GameEvent;
69pub use crate::listener::GameStateListener;
70pub use crate::model::GameState;