pub struct GameStateListener { /* private fields */ }Expand description
HTTP listener for CS2 GSI payloads.
Cheap to clone — every clone shares the same dispatcher and last-state cache. Handlers registered through any clone fire on every payload.
Implementations§
Source§impl GameStateListener
impl GameStateListener
Sourcepub fn new(port: u16) -> Self
pub fn new(port: u16) -> Self
Create a listener that will bind to 127.0.0.1:<port> when started.
Sourcepub fn with_addr(addr: SocketAddr) -> Self
pub fn with_addr(addr: SocketAddr) -> Self
Create a listener with a fully specified bind address.
Sourcepub fn addr(&self) -> SocketAddr
pub fn addr(&self) -> SocketAddr
The configured bind address. After start succeeds,
this is also returned by actual_addr.
Sourcepub fn actual_addr(&self) -> Option<SocketAddr>
pub fn actual_addr(&self) -> Option<SocketAddr>
The actual bound socket address — useful when you bind to port 0
and want to discover the OS-assigned port.
Sourcepub fn on<E, F>(&self, handler: F) -> &Self
pub fn on<E, F>(&self, handler: F) -> &Self
Subscribe to a strongly typed event.
let gsl = GameStateListener::new(4000);
gsl.on(|e: &PlayerGotKill| {
println!("{} now has {} round kills", e.player.name, e.new_round_kills);
});Sourcepub fn current_state(&self) -> Option<GameState>
pub fn current_state(&self) -> Option<GameState>
The most recently received game state, if any.
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
Sourcepub async fn start(&self) -> Result<()>
pub async fn start(&self) -> Result<()>
Bind the listener and start accepting GSI payloads. Returns once the
socket is bound — the actual serve loop runs as a background tokio
task. Call stop to shut it down.
Sourcepub async fn start_with_fallbacks<I>(&self, fallbacks: I) -> Result<()>where
I: IntoIterator<Item = SocketAddr>,
pub async fn start_with_fallbacks<I>(&self, fallbacks: I) -> Result<()>where
I: IntoIterator<Item = SocketAddr>,
Bind, falling back to alternative addresses if the primary is busy.
Tries self.addr first. If that address is reported as in use
(after the per-address retry budget is exhausted), each fallback
is tried in turn. The first address that binds wins; the actual
chosen address is then available via
actual_addr.
Pass port = 0 as a final fallback to ask the OS to pick any
free ephemeral port — that bind effectively cannot fail.
All non-AddrInUse errors short-circuit immediately (no point
trying fallbacks if e.g. the loopback interface is gone).
Trait Implementations§
Source§impl Clone for GameStateListener
impl Clone for GameStateListener
Source§fn clone(&self) -> GameStateListener
fn clone(&self) -> GameStateListener
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more