csgo_gsi/update/
player.rs

1//! player-related info
2
3use std::collections::HashMap;
4
5use serde::{Serialize, Deserialize};
6
7/// player info
8#[derive(Clone, Debug, Deserialize, Serialize)]
9#[serde(deny_unknown_fields)]
10pub struct Player {
11    /// steam ID
12    #[serde(rename = "steamid")]
13    pub steam_id: String,
14    /// display name
15    pub name: String,
16    /// observer slot number
17    pub observer_slot: Option<u64>,
18    /// current activity (in menu, playing game, etc)
19    pub activity: Activity,
20    /// match statistics
21    pub match_stats: Option<MatchStats>,
22    /// state (health, armor, etc)
23    pub state: Option<State>,
24    /// team
25    pub team: Option<super::Team>,
26    /// weapon inventory
27    #[serde(default)]
28    pub weapons: HashMap<String, Weapon>, // TODO are the keys ever not weapon_0, weapon_1, ...
29    /// clan
30    pub clan: Option<String>,
31}
32
33/// an activity a player can be doing
34#[derive(Clone, Debug, Deserialize, Serialize)]
35#[serde(rename_all = "lowercase")]
36pub enum Activity {
37    /// in a menu
38    Menu,
39    /// playing the game
40    Playing,
41}
42
43/// a player's match statistics
44#[derive(Clone, Debug, Deserialize, Serialize)]
45#[serde(deny_unknown_fields)]
46pub struct MatchStats {
47    /// kills
48    pub kills: i64,
49    /// assists
50    pub assists: u64,
51    /// deaths
52    pub deaths: u64,
53    /// MVPs
54    pub mvps: u64,
55    /// score
56    pub score: u64,
57}
58
59/// player state
60#[derive(Clone, Debug, Deserialize, Serialize)]
61#[serde(deny_unknown_fields)]
62pub struct State {
63    /// health
64    pub health: u64,
65    /// armor
66    pub armor: u64,
67    /// has a helmet?
68    pub helmet: bool,
69    /// flashbang duration(?)
70    pub flashed: u64,
71    /// smoke duration(?)
72    pub smoked: u64,
73    /// on-fire duration(?)
74    pub burning: u64,
75    /// money
76    pub money: u64,
77    /// kills this round
78    pub round_kills: i64,
79    /// headshot(?) kills this round
80    pub round_killhs: u64,
81    /// current equipment value
82    pub equip_value: u64,
83    /// total damage dealt(?) this round
84    pub round_totaldmg: Option<u64>,
85    /// has a defuse kit?
86    #[serde(rename = "defusekit")]
87    pub defuse_kit: Option<bool>
88}
89
90/// weapon info
91#[derive(Clone, Debug, Deserialize, Serialize)]
92#[serde(deny_unknown_fields)]
93pub struct Weapon {
94    /// name
95    pub name: String,
96    /// skin
97    pub paintkit: String,
98    /// type (pistol, rifle, etc)
99    pub r#type: Option<WeaponType>, // TODO is this ever missing for anything other than the taser
100    /// state (holstered, active, etc)
101    pub state: WeaponState,
102    /// bullets in current clip
103    pub ammo_clip: Option<u64>,
104    /// bullets per clip
105    pub ammo_clip_max: Option<u64>,
106    /// bullets in reserve
107    pub ammo_reserve: Option<u64>,
108}
109
110/// a type of weapon
111#[derive(Clone, Debug, Deserialize, Serialize)]
112pub enum WeaponType {
113    /// knife
114    Knife,
115    /// pistol
116    Pistol,
117    /// submachine gun
118    #[serde(rename = "Submachine Gun")]
119    SMG,
120    /// machine gun
121    #[serde(rename = "Machine Gun")]
122    MachineGun,
123    /// regular rifle
124    Rifle,
125    /// sniper rifle
126    SniperRifle,
127    /// shotgun
128    Shotgun,
129    /// "stackable item" (health shot in deathmatch, other examples unknown)
130    StackableItem,
131    /// grenade
132    Grenade,
133    /// bomb
134    C4,
135}
136
137/// status of weapon
138#[derive(Clone, Debug, Deserialize, Serialize)]
139#[serde(rename_all = "lowercase")]
140pub enum WeaponState {
141    /// not selected
142    Holstered,
143    /// selected
144    Active,
145    /// reloading
146    Reloading,
147}