csgo_gsi2/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    /// in a console or in-game chat
42    TextInput
43
44}
45
46/// a player's match statistics
47#[derive(Clone, Debug, Deserialize, Serialize)]
48#[serde(deny_unknown_fields)]
49pub struct MatchStats {
50    /// kills
51    pub kills: i64,
52    /// assists
53    pub assists: u64,
54    /// deaths
55    pub deaths: u64,
56    /// MVPs
57    pub mvps: u64,
58    /// score
59    pub score: u64,
60}
61
62/// player state
63#[derive(Clone, Debug, Deserialize, Serialize)]
64#[serde(deny_unknown_fields)]
65pub struct State {
66    /// health
67    pub health: u64,
68    /// armor
69    pub armor: u64,
70    /// has a helmet?
71    pub helmet: bool,
72    /// flashbang duration(?)
73    pub flashed: u64,
74    /// smoke duration(?)
75    pub smoked: u64,
76    /// on-fire duration(?)
77    pub burning: u64,
78    /// money
79    pub money: u64,
80    /// kills this round
81    pub round_kills: i64,
82    /// headshot(?) kills this round
83    pub round_killhs: u64,
84    /// current equipment value
85    pub equip_value: u64,
86    /// total damage dealt(?) this round
87    pub round_totaldmg: Option<u64>,
88    /// has a defuse kit?
89    #[serde(rename = "defusekit")]
90    pub defuse_kit: Option<bool>
91}
92
93/// weapon info
94#[derive(Clone, Debug, Deserialize, Serialize)]
95#[serde(deny_unknown_fields)]
96pub struct Weapon {
97    /// name
98    pub name: String,
99    /// skin
100    pub paintkit: String,
101    /// type (pistol, rifle, etc)
102    pub r#type: Option<WeaponType>, // TODO is this ever missing for anything other than the taser
103    /// state (holstered, active, etc)
104    pub state: WeaponState,
105    /// bullets in current clip
106    pub ammo_clip: Option<u64>,
107    /// bullets per clip
108    pub ammo_clip_max: Option<u64>,
109    /// bullets in reserve
110    pub ammo_reserve: Option<u64>,
111}
112
113/// a type of weapon
114#[derive(Clone, Debug, Deserialize, Serialize)]
115pub enum WeaponType {
116    /// knife
117    Knife,
118    /// fists
119    Fists,
120    /// "melee weapon" (hammer or ???)
121    Melee,
122    /// pistol
123    Pistol,
124    /// submachine gun
125    #[serde(rename = "Submachine Gun")]
126    SMG,
127    /// machine gun
128    #[serde(rename = "Machine Gun")]
129    MachineGun,
130    /// regular rifle
131    Rifle,
132    /// sniper rifle
133    SniperRifle,
134    /// shotgun
135    Shotgun,
136    /// "stackable item" (health shot in deathmatch, other examples unknown)
137    StackableItem,
138    /// tablet
139    Tablet,
140    /// grenade
141    Grenade,
142    /// bomb
143    C4,
144    /// bump mine
145    #[serde(rename = "Bump Mine")]
146    BumpMine,
147    /// breach charge
148    #[serde(rename = "Breach Charge")]
149    BreachCharge,
150
151}
152
153/// status of weapon
154#[derive(Clone, Debug, Deserialize, Serialize)]
155#[serde(rename_all = "lowercase")]
156pub enum WeaponState {
157    /// not selected
158    Holstered,
159    /// selected
160    Active,
161    /// reloading
162    Reloading,
163}