Skip to main content

cs2_gsi/model/
auth.rs

1//! Authentication node.
2//!
3//! CS2 itself does not push an auth token by default — the `auth` block is
4//! still present (often empty) and exposed here so consumers can inspect any
5//! custom tokens they themselves added to the gamestate integration cfg file.
6
7use serde::{Deserialize, Serialize};
8use std::collections::HashMap;
9
10/// The `auth` root node of a GSI payload. Holds any token / key/value pairs
11/// the cfg file declares under `"auth" {}`.
12#[derive(Clone, Debug, Default, Deserialize, Serialize, PartialEq, Eq)]
13#[serde(transparent)]
14pub struct Auth(pub HashMap<String, String>);
15
16impl Auth {
17    /// Lookup a token by name (e.g. `"token"`).
18    pub fn get(&self, key: &str) -> Option<&str> {
19        self.0.get(key).map(String::as_str)
20    }
21
22    /// Returns `true` if the auth block is empty.
23    pub fn is_empty(&self) -> bool {
24        self.0.is_empty()
25    }
26}