Skip to main content

steam_client/
options.rs

1//! Steam client options.
2
3use std::time::Duration;
4/// Connection protocol to use.
5#[derive(Debug, Clone, Copy, PartialEq, Eq)]
6pub enum EConnectionProtocol {
7    Auto,
8    Tcp,
9    WebSocket,
10}
11
12/// Options for the Steam client.
13#[derive(Debug, Clone)]
14pub struct SteamOptions {
15    /// Connection protocol to use.
16    pub protocol: EConnectionProtocol,
17
18    /// Whether to automatically reconnect on disconnect.
19    pub auto_relogin: bool,
20
21    /// Whether to enable web compatibility mode (WebSocket only, port 443).
22    pub web_compatibility_mode: bool,
23
24    /// HTTP proxy URL.
25    pub http_proxy: Option<String>,
26
27    /// SOCKS proxy URL.
28    pub socks_proxy: Option<String>,
29
30    /// Whether to renew refresh tokens automatically.
31    pub renew_refresh_tokens: bool,
32
33    /// Machine name to report to Steam.
34    pub machine_name: Option<String>,
35
36    /// Language to use for Steam messages.
37    pub language: String,
38
39    /// Local address to bind to.
40    pub local_address: Option<String>,
41
42    /// Local port to bind to.
43    pub local_port: Option<u16>,
44
45    /// Additional headers to send with WebSocket handshake.
46    pub additional_headers: std::collections::HashMap<String, String>,
47
48    /// Whether to enable PICS cache.
49    pub enable_pics_cache: bool,
50
51    /// Whether to cache all PICS data.
52    pub pics_cache_all: bool,
53
54    /// Interval between changelist updates (in milliseconds).
55    pub changelist_update_interval: u64,
56
57    /// Whether to save app tickets.
58    pub save_app_tickets: bool,
59
60    /// Reconnection configuration.
61    pub reconnect: ReconnectConfig,
62
63    /// Heartbeat configuration.
64    pub heartbeat: HeartbeatOptions,
65}
66
67/// Reconnection configuration.
68#[derive(Debug, Clone)]
69pub struct ReconnectConfig {
70    /// Whether auto reconnection is enabled.
71    pub enabled: bool,
72    /// Maximum number of reconnection attempts.
73    pub max_attempts: u32,
74    /// Initial delay before first reconnection attempt.
75    pub initial_delay: Duration,
76    /// Maximum delay between reconnection attempts.
77    pub max_delay: Duration,
78    /// Delay multiplier for exponential backoff.
79    pub backoff_multiplier: f64,
80}
81
82impl Default for ReconnectConfig {
83    fn default() -> Self {
84        Self {
85            enabled: true,
86            max_attempts: 10,
87            initial_delay: Duration::from_secs(2),
88            max_delay: Duration::from_secs(60),
89            backoff_multiplier: 2.0,
90        }
91    }
92}
93
94/// Heartbeat configuration options.
95#[derive(Debug, Clone)]
96pub struct HeartbeatOptions {
97    /// Whether heartbeat is enabled.
98    pub enabled: bool,
99    /// Interval between heartbeats.
100    pub interval: Duration,
101}
102
103impl Default for HeartbeatOptions {
104    fn default() -> Self {
105        Self { enabled: true, interval: Duration::from_secs(30) }
106    }
107}
108
109impl Default for SteamOptions {
110    fn default() -> Self {
111        Self {
112            protocol: EConnectionProtocol::Auto,
113            auto_relogin: true,
114            web_compatibility_mode: false,
115            http_proxy: None,
116            socks_proxy: None,
117            renew_refresh_tokens: false,
118            machine_name: None,
119            language: "english".to_string(),
120            local_address: None,
121            local_port: None,
122            additional_headers: std::collections::HashMap::new(),
123            enable_pics_cache: false,
124            pics_cache_all: false,
125            changelist_update_interval: 60000,
126            save_app_tickets: true,
127            reconnect: ReconnectConfig::default(),
128            heartbeat: HeartbeatOptions::default(),
129        }
130    }
131}