csgo_gsi_builder/config.rs
1use crate::components::Components;
2
3use serde::Serialize;
4
5/// Components to subscribe to.
6///
7/// The structure shouldn't be used directly, you should prefer creating a slice
8/// of [`Components`] and cast it using `into()` or `Data::from()`.
9#[derive(Serialize, Debug)]
10pub struct Data {
11 provider: bool,
12 player_id: bool,
13 player_state: bool,
14 map: bool,
15 map_round_wins: bool,
16 player_match_stats: bool,
17 player_weapons: bool,
18 round: bool,
19 allgrenades: bool,
20 allplayers_id: bool,
21 allplayers_match_state: bool,
22 allplayers_position: bool,
23 allplayers_states: bool,
24 allplayers_weapons: bool,
25 bomb: bool,
26 phase_countdowns: bool,
27 player_position: bool,
28}
29
30impl From<&[Components]> for Data {
31 fn from(components: &[Components]) -> Self {
32 Self {
33 provider: components.contains(&Components::Provider),
34 player_id: components.contains(&Components::PlayerId),
35 player_state: components.contains(&Components::PlayerState),
36 player_match_stats: components.contains(&Components::PlayerMatchStats),
37 player_weapons: components.contains(&Components::PlayerWeapons),
38 player_position: components.contains(&Components::PlayerPosition),
39 map: components.contains(&Components::Map),
40 map_round_wins: components.contains(&Components::MapRoundWins),
41 round: components.contains(&Components::Round),
42 bomb: components.contains(&Components::Bomb),
43 phase_countdowns: components.contains(&Components::PhaseCountdowns),
44 allgrenades: components.contains(&Components::AllGrenages),
45 allplayers_id: components.contains(&Components::AllPlayersId),
46 allplayers_states: components.contains(&Components::AllPlayersStates),
47 allplayers_match_state: components.contains(&Components::AllPlayersMatchStats),
48 allplayers_weapons: components.contains(&Components::AllPlayersWeapons),
49 allplayers_position: components.contains(&Components::AllPlayersPosition),
50 }
51 }
52}
53
54/// Configuration for Game State Integration.
55///
56/// You can find more informations on [VALVE's wiki].
57///
58/// [VALVE's wiki]: https://developer.valvesoftware.com/wiki/Counter-Strike:_Global_Offensive_Game_State_Integration
59#[derive(Serialize, Debug)]
60#[serde(rename = "Created with csgo-gsi-builder")]
61pub struct Config {
62 /// Service name.
63 ///
64 /// It will be used to create the cfg filename, so it shouldn't contain any
65 /// spaces or special chars except `_`.
66 #[serde(skip_serializing)]
67 pub name: String,
68
69 /// The uri that will receive the payload.
70 ///
71 /// The game will be making POST requests to this uri.
72 pub uri: String,
73
74 /// Game expects an HTTP 2XX response code from its HTTP POST request, and
75 /// game will not attempt submitting the next HTTP POST request while a
76 /// previous request is still in flight. The game will consider the request
77 /// as timed out if a response is not received within so many seconds, and
78 /// will re-heartbeat next time with full state omitting any
79 /// delta-computation.
80 pub timeout: f64,
81
82 /// Because multiple game events tend to occur one after another very
83 /// quickly, it is recommended to specify a non-zero buffer. When buffering
84 /// is enabled, the game will collect events for so many seconds to report a
85 /// bigger delta. For localhost service integration this is less of an issue
86 /// and can be tuned to match the needs of the service or set to 0.0 to
87 /// disable buffering completely.
88 pub buffer: f64,
89
90 /// For high-traffic endpoints this setting will make the game client not
91 /// send another request for at least this many seconds after receiving
92 /// previous HTTP 2XX response to avoid notifying the service when game
93 /// state changes too frequently.
94 pub throttle: f64,
95
96 /// Even if no game state change occurs, this setting instructs the game to
97 /// send a request so many seconds after receiving previous HTTP 2XX
98 /// response. The service can be configured to consider game as offline or
99 /// disconnected if it didn't get a notification for a significant period of
100 /// time exceeding the heartbeat interval.
101 pub heartbeat: f64,
102
103 /// Subscribed [`Components`].
104 pub data: Data,
105}
106
107impl Default for Config {
108 fn default() -> Self {
109 let components: &[Components] = &[];
110 Self {
111 name: String::from("unnamed"),
112 uri: String::from("127.0.0.1:3000"),
113 timeout: 1.1,
114 buffer: 0.1,
115 throttle: 1.0,
116 heartbeat: 30.0,
117 data: Data::from(components),
118 }
119 }
120}