steamkit/steam/steam_client/configuration/
steam_configuration_state.rs1use std::fmt;
4use std::ops::BitOr;
5use std::sync::Arc;
6use std::time::Duration;
7
8use crate::base::generated::steam_language::{EClientPersonaStateFlag, EUniverse};
9use crate::networking::steam3::protocol_type::ProtocolTypes;
10use crate::steam::discovery::i_server_list_provider::IServerListProvider;
11
12use super::i_machine_info_provider::IMachineInfoProvider;
13use super::steam_configuration::HttpClientFactory;
14
15#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
18pub struct PersonaStateFlags(i32);
19
20impl PersonaStateFlags {
21 pub const DEFAULT: PersonaStateFlags = PersonaStateFlags(
24 EClientPersonaStateFlag::PlayerName.value()
25 | EClientPersonaStateFlag::Presence.value()
26 | EClientPersonaStateFlag::SourceID.value()
27 | EClientPersonaStateFlag::GameExtraInfo.value()
28 | EClientPersonaStateFlag::LastSeen.value(),
29 );
30
31 pub const fn new(bits: i32) -> Self {
33 Self(bits)
34 }
35
36 pub const fn bits(self) -> i32 {
38 self.0
39 }
40
41 pub const fn contains(self, flag: EClientPersonaStateFlag) -> bool {
43 self.0 & flag.value() != 0
44 }
45
46 pub fn insert(&mut self, flag: EClientPersonaStateFlag) {
48 self.0 |= flag.value();
49 }
50
51 pub fn representative(&self) -> Option<EClientPersonaStateFlag> {
53 EClientPersonaStateFlag::ALL
54 .iter()
55 .copied()
56 .find(|flag| self.contains(*flag))
57 }
58
59 pub const fn union(self, other: Self) -> Self {
61 Self(self.0 | other.0)
62 }
63}
64
65impl BitOr for PersonaStateFlags {
66 type Output = PersonaStateFlags;
67
68 fn bitor(self, rhs: Self) -> Self::Output {
69 self.union(rhs)
70 }
71}
72
73impl From<EClientPersonaStateFlag> for PersonaStateFlags {
74 fn from(flag: EClientPersonaStateFlag) -> Self {
75 Self(flag.value())
76 }
77}
78
79#[derive(Clone)]
81pub struct SteamConfigurationState {
82 pub allow_directory_fetch: bool,
84 pub cell_id: u32,
86 pub connection_timeout: Duration,
88 pub default_persona_state_flags: PersonaStateFlags,
90 pub http_client_factory: HttpClientFactory,
92 pub machine_info_provider: Arc<dyn IMachineInfoProvider>,
94 pub protocol_types: ProtocolTypes,
96 pub server_list_provider: Arc<dyn IServerListProvider>,
98 pub universe: EUniverse,
100 pub web_api_base_address: reqwest::Url,
102 pub web_api_key: String,
104}
105
106impl fmt::Debug for SteamConfigurationState {
107 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
108 f.debug_struct("SteamConfigurationState")
109 .field("allow_directory_fetch", &self.allow_directory_fetch)
110 .field("cell_id", &self.cell_id)
111 .field("connection_timeout", &self.connection_timeout)
112 .field("default_persona_state_flags", &self.default_persona_state_flags)
113 .field("machine_info_provider", &"Arc<dyn IMachineInfoProvider>")
114 .field("protocol_types", &self.protocol_types)
115 .field("server_list_provider", &"Arc<dyn IServerListProvider>")
116 .field("universe", &self.universe)
117 .field("web_api_base_address", &self.web_api_base_address)
118 .field("web_api_key", &self.web_api_key)
119 .finish()
120 }
121}
122
123impl Default for SteamConfigurationState {
124 fn default() -> Self {
125 Self {
126 allow_directory_fetch: true,
127 cell_id: 0,
128 connection_timeout: Duration::from_secs(5),
129 default_persona_state_flags: PersonaStateFlags::DEFAULT,
130 http_client_factory: super::steam_configuration::default_http_client_factory(),
131 machine_info_provider: crate::util::hardware_utils::MachineInfoProvider::get_default_provider(),
132 protocol_types: ProtocolTypes::TCP | ProtocolTypes::WEB_SOCKET,
133 server_list_provider: Arc::new(crate::steam::discovery::memory_server_list_provider::MemoryServerListProvider::new()),
134 universe: EUniverse::Public,
135 web_api_base_address: super::steam_configuration::default_web_api_base_address(),
136 web_api_key: String::new(),
137 }
138 }
139}