use std::sync::Arc;
use steamkit_protos::steam::EAuthTokenPlatformType;
use crate::base::generated::steam_language::EOSType;
use crate::util::utils::Utils;
use super::i_authenticator::IAuthenticator;
#[derive(Clone)]
pub struct AuthSessionDetails {
pub username: Option<String>,
pub password: Option<String>,
pub device_friendly_name: Option<String>,
pub platform_type: EAuthTokenPlatformType,
pub client_os_type: EOSType,
pub is_persistent_session: bool,
pub website_id: Option<String>,
pub guard_data: Option<String>,
pub authenticator: Option<Arc<dyn IAuthenticator>>,
}
impl Default for AuthSessionDetails {
fn default() -> Self {
AuthSessionDetails {
username: None,
password: None,
device_friendly_name: Some(format!("{} (SteamKit2)", machine_name())),
platform_type: EAuthTokenPlatformType::KEAuthTokenPlatformTypeSteamClient,
client_os_type: Utils::get_os_type(),
is_persistent_session: false,
website_id: Some("Client".to_string()),
guard_data: None,
authenticator: None,
}
}
}
impl AuthSessionDetails {
pub fn new() -> Self {
AuthSessionDetails::default()
}
}
impl std::fmt::Debug for AuthSessionDetails {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("AuthSessionDetails")
.field("username", &self.username)
.field("password", &self.password.as_ref().map(|_| "<redacted>"))
.field("device_friendly_name", &self.device_friendly_name)
.field("platform_type", &self.platform_type)
.field("client_os_type", &self.client_os_type)
.field("is_persistent_session", &self.is_persistent_session)
.field("website_id", &self.website_id)
.field("guard_data", &self.guard_data)
.field(
"authenticator",
&self.authenticator.as_ref().map(|_| "Arc<dyn IAuthenticator>"),
)
.finish()
}
}
fn machine_name() -> String {
std::env::var("COMPUTERNAME")
.or_else(|_| std::env::var("HOSTNAME"))
.ok()
.filter(|name| !name.is_empty())
.unwrap_or_else(|| "unknown".to_string())
}