Skip to main content

steam_user/types/
friends.rs

1//! User-related types.
2
3use serde::{Deserialize, Serialize};
4use steamid::SteamID;
5
6/// Response from enabling two-factor authentication.
7#[derive(Debug, Clone, Serialize, Deserialize)]
8pub struct TwoFactorResponse {
9    /// Status code (1 = success).
10    pub status: i32,
11    /// Shared secret (base64).
12    pub shared_secret: Option<String>,
13    /// Identity secret (base64).
14    pub identity_secret: Option<String>,
15    /// Secret 1 (base64).
16    pub secret_1: Option<String>,
17    /// Revocation code.
18    pub revocation_code: Option<String>,
19    /// Serial number.
20    pub serial_number: Option<u64>,
21    /// URI for authenticator apps.
22    pub uri: Option<String>,
23    /// Server time when enabled.
24    pub server_time: Option<u64>,
25    /// Account name.
26    pub account_name: Option<String>,
27    /// Token GID.
28    pub token_gid: Option<String>,
29    /// Confirmation type.
30    pub confirm_type: Option<i32>,
31    /// Phone number hint.
32    pub phone_number_hint: Option<String>,
33}
34
35impl TwoFactorResponse {
36    /// Returns a human-readable string with instructions and secrets for
37    /// setting up the authenticator.
38    pub fn setup_instructions(&self) -> String {
39        let mut s = String::new();
40        s.push_str("=== Steam Authenticator Setup ===\n");
41        if let Some(ref secret) = self.shared_secret {
42            s.push_str(&format!("Shared Secret:   {}\n", secret));
43        }
44        if let Some(ref secret) = self.identity_secret {
45            s.push_str(&format!("Identity Secret: {}\n", secret));
46        }
47        if let Some(ref code) = self.revocation_code {
48            s.push_str(&format!("Revocation Code: {}\n", code));
49        }
50        if let Some(ref serial) = self.serial_number {
51            s.push_str(&format!("Serial Number:   {}\n", serial));
52        }
53        if let Some(ref uri) = self.uri {
54            s.push_str(&format!("OTP URI:         {}\n", uri));
55        }
56        s.push_str("==================================\n");
57        s.push_str("IMPORTANT: Save your Revocation Code! You will need it if you lose access to your authenticator.\n");
58        s.push_str("To finalize, call `finalize_authenticator(sms_code)` with the code you received via SMS.\n");
59        s
60    }
61}
62
63/// A comment on a user's profile.
64#[derive(Debug, Clone, Serialize, Deserialize)]
65pub struct UserComment {
66    /// Comment ID.
67    pub id: String,
68    /// Author information.
69    pub author: CommentAuthor,
70    /// When posted (UNIX timestamp).
71    pub timestamp: u64,
72    /// Comment text (plain).
73    pub content: String,
74}
75
76/// Author of a comment.
77#[derive(Debug, Clone, Serialize, Deserialize)]
78pub struct CommentAuthor {
79    /// Author's SteamID.
80    pub steam_id: Option<SteamID>,
81    /// Author's display name.
82    pub name: String,
83    /// Avatar URL.
84    pub avatar: String,
85    /// Avatar hash.
86    pub avatar_hash: String,
87    /// Profile URL.
88    pub profile_url: Option<String>,
89    /// Custom URL part.
90    pub custom_url: Option<String>,
91    /// Mini-profile ID.
92    pub miniprofile: Option<u64>,
93}
94
95/// A user's alias history entry.
96#[derive(Debug, Clone, Serialize, Deserialize)]
97pub struct AliasEntry {
98    /// Previous name.
99    pub newname: String,
100    /// When changed.
101    pub timechanged: String,
102}
103
104/// Steam Guard status.
105#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
106#[non_exhaustive]
107pub enum SteamGuardStatus {
108    /// Mobile authenticator is enabled.
109    Mobile,
110    /// Email authenticator is enabled.
111    Email,
112    /// No two-factor authentication.
113    None,
114}
115
116/// Metadata parsed from a Steam friend/following page.
117///
118/// Contains profile info and social counts extracted from the JavaScript
119/// variables `g_rgProfileData` and `g_rgCounts` embedded in the HTML.
120#[derive(Debug, Clone, Serialize, Deserialize, Default)]
121pub struct FriendPageInfo {
122    /// The persona (display) name of the profile owner.
123    #[serde(default)]
124    pub persona_name: String,
125    /// The profile URL.
126    #[serde(default)]
127    pub profile_url: String,
128    /// The SteamID64 of the profile owner.
129    #[serde(default)]
130    pub steam_id: SteamID,
131    /// Total number of friends.
132    #[serde(default)]
133    pub friends_count: u32,
134    /// Number of pending incoming friend requests.
135    #[serde(default)]
136    pub friends_pending_count: u32,
137    /// Number of blocked users.
138    #[serde(default)]
139    pub blocked_count: u32,
140    /// Number of users being followed.
141    #[serde(default)]
142    pub following_count: u32,
143    /// Number of groups the user belongs to.
144    #[serde(default)]
145    pub groups_count: u32,
146    /// Number of pending group invites.
147    #[serde(default)]
148    pub groups_pending_count: u32,
149    /// Maximum number of friends this account can have.
150    #[serde(default)]
151    pub friends_limit: u32,
152    /// Steam Wallet balance (main, pending, currency), if visible.
153    #[serde(default)]
154    pub wallet_balance: Option<super::account::WalletBalance>,
155}
156
157/// Result of fetching a friend/following list page.
158///
159/// Wraps the list of friends/following along with page-level metadata
160/// parsed from the same HTML response.
161#[derive(Debug, Clone, Serialize, Deserialize, Default)]
162pub struct FriendListPage {
163    /// The list of friends or followed users.
164    pub friends: Vec<FriendDetails>,
165    /// Page-level metadata (profile info, social counts, wallet).
166    pub page_info: Option<FriendPageInfo>,
167}
168
169/// Details of a Steam friend.
170#[derive(Debug, Clone, Serialize, Deserialize, Default)]
171pub struct FriendDetails {
172    /// Friend's username.
173    #[serde(alias = "name")]
174    pub username: String,
175    /// Friend's SteamID.
176    #[serde(default)]
177    pub steam_id: SteamID,
178    /// Game currently being played.
179    #[serde(default)]
180    pub game: String,
181    /// Online status: "offline", "online", or "ingame".
182    #[serde(default)]
183    pub online_status: String,
184    /// Last online time string.
185    #[serde(default)]
186    pub last_online: String,
187    /// Friend's mini-profile ID.
188    #[serde(default)]
189    pub miniprofile: u64,
190    /// Whether the user has a nickname set for this friend.
191    #[serde(default)]
192    pub is_nickname: bool,
193    /// Avatar URL.
194    #[serde(default)]
195    pub avatar: String,
196    /// Avatar hash.
197    #[serde(default)]
198    pub avatar_hash: String,
199    /// Profile URL.
200    #[serde(default)]
201    pub profile_url: String,
202    /// Custom URL part.
203    #[serde(default)]
204    pub custom_url: Option<String>,
205}
206
207/// A player found in community search.
208#[derive(Debug, Clone, Serialize, Deserialize)]
209pub struct CommunitySearchPlayer {
210    /// Mini-profile ID.
211    pub miniprofile: u64,
212    /// SteamID.
213    pub steam_id: SteamID,
214    /// Avatar hash.
215    pub avatar_hash: String,
216    /// Display name.
217    pub name: String,
218    /// Profile URL.
219    pub profile_url: String,
220    /// Custom URL part.
221    pub custom_url: Option<String>,
222}
223
224/// Result of a community search.
225#[derive(Debug, Clone, Serialize, Deserialize)]
226pub struct CommunitySearchResult {
227    /// List of players found.
228    pub players: Vec<CommunitySearchPlayer>,
229    /// Previous page number, if any.
230    pub prev_page: Option<u32>,
231    /// Next page number, if any.
232    pub next_page: Option<u32>,
233    /// Search filter used ("users").
234    pub search_filter: String,
235    /// Current search page.
236    pub search_page: u32,
237    /// Total result count.
238    pub search_result_count: u32,
239    /// The search query.
240    pub search_text: String,
241}
242
243/// Data for a quick invite link.
244#[derive(Debug, Clone, Serialize, Deserialize)]
245pub struct QuickInviteData {
246    /// Whether the request was successful.
247    pub success: bool,
248    /// The unique invite token.
249    pub invite_token: Option<String>,
250    /// Maximum number of uses for this invite.
251    pub invite_limit: Option<i32>,
252    /// Duration of the invite in seconds.
253    pub invite_duration: Option<i32>,
254    /// When the invite was created (UNIX timestamp).
255    pub time_created: Option<u64>,
256    /// The SteamID of the user who created the invite.
257    pub steam_id: Option<SteamID>,
258}
259
260/// Response containing all of a user's quick invite tokens.
261#[derive(Debug, Clone, Serialize, Deserialize)]
262pub struct QuickInviteTokensResponse {
263    /// Whether the request was successful.
264    pub success: bool,
265    /// List of active invite tokens.
266    pub tokens: Vec<QuickInviteToken>,
267}
268
269/// A single quick invite token.
270#[derive(Debug, Clone, Serialize, Deserialize)]
271pub struct QuickInviteToken {
272    /// The unique invite token.
273    pub invite_token: String,
274    /// Maximum number of uses.
275    pub invite_limit: i32,
276    /// Duration of the invite in seconds.
277    pub invite_duration: i32,
278    /// When the invite was created (UNIX timestamp).
279    pub time_created: u64,
280    /// The SteamID of the user who created the invite.
281    pub steam_id: Option<SteamID>,
282}
283
284/// A pending friend request (incoming or outgoing).
285#[derive(Debug, Clone, Serialize, Deserialize)]
286pub struct PendingFriend {
287    /// Friend's display name.
288    pub name: String,
289    /// Profile URL.
290    pub link: String,
291    /// Avatar URL.
292    pub avatar: String,
293    /// SteamID.
294    pub steam_id: SteamID,
295    /// Account ID.
296    pub account_id: u32,
297    /// Steam level.
298    pub level: u32,
299}
300
301/// Result of get_pending_friend_list.
302#[derive(Debug, Clone, Serialize, Deserialize)]
303pub struct PendingFriendList {
304    /// Outgoing friend requests (sent by you).
305    pub sent_invites: Vec<PendingFriend>,
306    /// Incoming friend requests (received from others).
307    pub received_invites: Vec<PendingFriend>,
308}