steam-user 0.1.0

Steam User web client for Rust - HTTP-based Steam Community interactions
Documentation
//! User-related types.

use serde::{Deserialize, Serialize};
use steamid::SteamID;

/// Response from enabling two-factor authentication.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TwoFactorResponse {
    /// Status code (1 = success).
    pub status: i32,
    /// Shared secret (base64).
    pub shared_secret: Option<String>,
    /// Identity secret (base64).
    pub identity_secret: Option<String>,
    /// Secret 1 (base64).
    pub secret_1: Option<String>,
    /// Revocation code.
    pub revocation_code: Option<String>,
    /// Serial number.
    pub serial_number: Option<u64>,
    /// URI for authenticator apps.
    pub uri: Option<String>,
    /// Server time when enabled.
    pub server_time: Option<u64>,
    /// Account name.
    pub account_name: Option<String>,
    /// Token GID.
    pub token_gid: Option<String>,
    /// Confirmation type.
    pub confirm_type: Option<i32>,
    /// Phone number hint.
    pub phone_number_hint: Option<String>,
}

impl TwoFactorResponse {
    /// Returns a human-readable string with instructions and secrets for
    /// setting up the authenticator.
    pub fn setup_instructions(&self) -> String {
        let mut s = String::new();
        s.push_str("=== Steam Authenticator Setup ===\n");
        if let Some(ref secret) = self.shared_secret {
            s.push_str(&format!("Shared Secret:   {}\n", secret));
        }
        if let Some(ref secret) = self.identity_secret {
            s.push_str(&format!("Identity Secret: {}\n", secret));
        }
        if let Some(ref code) = self.revocation_code {
            s.push_str(&format!("Revocation Code: {}\n", code));
        }
        if let Some(ref serial) = self.serial_number {
            s.push_str(&format!("Serial Number:   {}\n", serial));
        }
        if let Some(ref uri) = self.uri {
            s.push_str(&format!("OTP URI:         {}\n", uri));
        }
        s.push_str("==================================\n");
        s.push_str("IMPORTANT: Save your Revocation Code! You will need it if you lose access to your authenticator.\n");
        s.push_str("To finalize, call `finalize_authenticator(sms_code)` with the code you received via SMS.\n");
        s
    }
}

/// A comment on a user's profile.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct UserComment {
    /// Comment ID.
    pub id: String,
    /// Author information.
    pub author: CommentAuthor,
    /// When posted (UNIX timestamp).
    pub timestamp: u64,
    /// Comment text (plain).
    pub content: String,
}

/// Author of a comment.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CommentAuthor {
    /// Author's SteamID.
    pub steam_id: Option<SteamID>,
    /// Author's display name.
    pub name: String,
    /// Avatar URL.
    pub avatar: String,
    /// Avatar hash.
    pub avatar_hash: String,
    /// Profile URL.
    pub profile_url: Option<String>,
    /// Custom URL part.
    pub custom_url: Option<String>,
    /// Mini-profile ID.
    pub miniprofile: Option<u64>,
}

/// A user's alias history entry.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AliasEntry {
    /// Previous name.
    pub newname: String,
    /// When changed.
    pub timechanged: String,
}

/// Steam Guard status.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
pub enum SteamGuardStatus {
    /// Mobile authenticator is enabled.
    Mobile,
    /// Email authenticator is enabled.
    Email,
    /// No two-factor authentication.
    None,
}

/// Metadata parsed from a Steam friend/following page.
///
/// Contains profile info and social counts extracted from the JavaScript
/// variables `g_rgProfileData` and `g_rgCounts` embedded in the HTML.
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct FriendPageInfo {
    /// The persona (display) name of the profile owner.
    #[serde(default)]
    pub persona_name: String,
    /// The profile URL.
    #[serde(default)]
    pub profile_url: String,
    /// The SteamID64 of the profile owner.
    #[serde(default)]
    pub steam_id: SteamID,
    /// Total number of friends.
    #[serde(default)]
    pub friends_count: u32,
    /// Number of pending incoming friend requests.
    #[serde(default)]
    pub friends_pending_count: u32,
    /// Number of blocked users.
    #[serde(default)]
    pub blocked_count: u32,
    /// Number of users being followed.
    #[serde(default)]
    pub following_count: u32,
    /// Number of groups the user belongs to.
    #[serde(default)]
    pub groups_count: u32,
    /// Number of pending group invites.
    #[serde(default)]
    pub groups_pending_count: u32,
    /// Maximum number of friends this account can have.
    #[serde(default)]
    pub friends_limit: u32,
    /// Steam Wallet balance (main, pending, currency), if visible.
    #[serde(default)]
    pub wallet_balance: Option<super::account::WalletBalance>,
}

/// Result of fetching a friend/following list page.
///
/// Wraps the list of friends/following along with page-level metadata
/// parsed from the same HTML response.
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct FriendListPage {
    /// The list of friends or followed users.
    pub friends: Vec<FriendDetails>,
    /// Page-level metadata (profile info, social counts, wallet).
    pub page_info: Option<FriendPageInfo>,
}

/// Details of a Steam friend.
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct FriendDetails {
    /// Friend's username.
    #[serde(alias = "name")]
    pub username: String,
    /// Friend's SteamID.
    #[serde(default)]
    pub steam_id: SteamID,
    /// Game currently being played.
    #[serde(default)]
    pub game: String,
    /// Online status: "offline", "online", or "ingame".
    #[serde(default)]
    pub online_status: String,
    /// Last online time string.
    #[serde(default)]
    pub last_online: String,
    /// Friend's mini-profile ID.
    #[serde(default)]
    pub miniprofile: u64,
    /// Whether the user has a nickname set for this friend.
    #[serde(default)]
    pub is_nickname: bool,
    /// Avatar URL.
    #[serde(default)]
    pub avatar: String,
    /// Avatar hash.
    #[serde(default)]
    pub avatar_hash: String,
    /// Profile URL.
    #[serde(default)]
    pub profile_url: String,
    /// Custom URL part.
    #[serde(default)]
    pub custom_url: Option<String>,
}

/// A player found in community search.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CommunitySearchPlayer {
    /// Mini-profile ID.
    pub miniprofile: u64,
    /// SteamID.
    pub steam_id: SteamID,
    /// Avatar hash.
    pub avatar_hash: String,
    /// Display name.
    pub name: String,
    /// Profile URL.
    pub profile_url: String,
    /// Custom URL part.
    pub custom_url: Option<String>,
}

/// Result of a community search.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CommunitySearchResult {
    /// List of players found.
    pub players: Vec<CommunitySearchPlayer>,
    /// Previous page number, if any.
    pub prev_page: Option<u32>,
    /// Next page number, if any.
    pub next_page: Option<u32>,
    /// Search filter used ("users").
    pub search_filter: String,
    /// Current search page.
    pub search_page: u32,
    /// Total result count.
    pub search_result_count: u32,
    /// The search query.
    pub search_text: String,
}

/// Data for a quick invite link.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct QuickInviteData {
    /// Whether the request was successful.
    pub success: bool,
    /// The unique invite token.
    pub invite_token: Option<String>,
    /// Maximum number of uses for this invite.
    pub invite_limit: Option<i32>,
    /// Duration of the invite in seconds.
    pub invite_duration: Option<i32>,
    /// When the invite was created (UNIX timestamp).
    pub time_created: Option<u64>,
    /// The SteamID of the user who created the invite.
    pub steam_id: Option<SteamID>,
}

/// Response containing all of a user's quick invite tokens.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct QuickInviteTokensResponse {
    /// Whether the request was successful.
    pub success: bool,
    /// List of active invite tokens.
    pub tokens: Vec<QuickInviteToken>,
}

/// A single quick invite token.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct QuickInviteToken {
    /// The unique invite token.
    pub invite_token: String,
    /// Maximum number of uses.
    pub invite_limit: i32,
    /// Duration of the invite in seconds.
    pub invite_duration: i32,
    /// When the invite was created (UNIX timestamp).
    pub time_created: u64,
    /// The SteamID of the user who created the invite.
    pub steam_id: Option<SteamID>,
}

/// A pending friend request (incoming or outgoing).
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PendingFriend {
    /// Friend's display name.
    pub name: String,
    /// Profile URL.
    pub link: String,
    /// Avatar URL.
    pub avatar: String,
    /// SteamID.
    pub steam_id: SteamID,
    /// Account ID.
    pub account_id: u32,
    /// Steam level.
    pub level: u32,
}

/// Result of get_pending_friend_list.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PendingFriendList {
    /// Outgoing friend requests (sent by you).
    pub sent_invites: Vec<PendingFriend>,
    /// Incoming friend requests (received from others).
    pub received_invites: Vec<PendingFriend>,
}