Skip to main content

steam_client/
lib.rs

1// `SteamError` is intentionally a wide enum carrying typed payloads
2// (Reqwest, WebSocket, prost::Decode, etc.). Wrapping every `Result<_, _>`
3// in `Box<>` to satisfy clippy's `result_large_err` would obscure the public
4// API for an internal stack-size concern. Allowed crate-wide; revisit if/when
5// SteamError is restructured.
6#![allow(clippy::result_large_err)]
7
8//! Steam client for Rust.
9//!
10//! This crate provides a Steam client for individual and anonymous user account
11//! types. Three authentication paths are supported:
12//!
13//! - **Refresh token** — load a previously saved token with [`TokenStore`] (recommended
14//!   for long-running bots).
15//! - **Password** — call [`SteamClient::log_on_with_password`]; handle the
16//!   [`crate::SteamError::SteamGuardRequired`] error to supply a Steam Guard code.
17//! - **Cookie** — call [`SteamClient::log_on_with_cookies`] with existing
18//!   `steamcommunity.com` session cookies; the library exchanges them for a
19//!   short-lived web logon token internally.
20//!
21//! # Example: refresh token (persistent session)
22//!
23//! ```rust,no_run
24//! use steam_client::{AuthEvent, LogOnDetails, SteamClient, SteamEvent, TokenStore};
25//!
26//! #[tokio::main]
27//! async fn main() {
28//!     let mut client = SteamClient::new(Default::default());
29//!     let token_store = TokenStore::new("steam_tokens.json");
30//!
31//!     // Load previous session if available, fall back to empty details on first run.
32//!     let logon_details = token_store.load(None).unwrap_or_default();
33//!     client.log_on(logon_details).await.unwrap();
34//!
35//!     // In your event loop, persist the token whenever it is refreshed.
36//!     // while let Some(event) = client.poll_event_timeout(Duration::from_secs(30)).await.unwrap() {
37//!     //     if let SteamEvent::Auth(AuthEvent::RefreshToken { token, account_name }) = event {
38//!     //         token_store.save(account_name, token, 0).unwrap();
39//!     //     }
40//!     // }
41//! }
42//! ```
43//!
44//! # Example: cookie login
45//!
46//! ```rust,no_run
47//! use steam_client::SteamClient;
48//!
49//! #[tokio::main]
50//! async fn main() {
51//!     let mut client = SteamClient::new(Default::default());
52//!
53//!     // Cookies must include at least `steamLoginSecure` for the target account.
54//!     let cookies = "sessionid=abc123; steamLoginSecure=76561198000000000%7C%7Ctoken";
55//!     let response = client.log_on_with_cookies(cookies).await.unwrap();
56//!     println!("Logged in as {}", response.steam_id.steam3());
57//! }
58//! ```
59
60// Core modules (at root level)
61mod connection;
62mod error;
63mod options;
64mod protocol;
65mod types;
66
67// Organized submodules
68pub mod cache;
69pub mod client;
70pub mod internal;
71pub mod persistence;
72pub mod services;
73pub mod utils;
74
75// ============================================================================
76// Public Re-exports
77// ============================================================================
78
79// Core types
80// Client
81pub use client::{AccountEvent, AppChange, AppInfoData, AppsEvent, AuthEvent, CSGOEvent, ChatEvent, ConnectionEvent, ContentEvent, CsgoClientHello, CsgoCommendation, CsgoPartyEntry, CsgoRanking, CsgoWelcome, FriendEntry, FriendsEvent, LicenseEntry, MessageHandler, MockHandles, NotificationsEvent, PackageChange, PackageInfoData, SteamClient, SteamClientBuilder, SteamEvent, SteamEventStream, SystemEvent, UserPersona};
82pub use error::SteamError;
83// Internal (exposed for testing)
84pub use internal::{HeartbeatManager, JobManager, JobResponse, MessageSender, MockMessageSender, ReconnectManager, ReconnectState, SentMessage, SessionInfo};
85pub use options::{HeartbeatOptions, ReconnectConfig, SteamOptions};
86pub use persistence::TokenStore;
87// Services
88pub use services::{
89    // Account
90    AccountInfo,
91    AccountLimitations,
92    // Friends
93    AddFriendResult,
94    // Apps
95    AppInfo,
96    AppInfoRequest,
97    // Economy
98    AssetClass,
99    AssetClassInfo,
100    // App auth
101    AuthSessionResult,
102    AuthSessionTicket,
103    // Family sharing
104    AuthorizedBorrower,
105    AuthorizedDevice,
106    // CDN
107    CdnAuthToken,
108    // Chat
109    ChatMessage,
110    // Chat room
111    ChatRole,
112    ChatRoom,
113    ChatRoomGroup,
114    ChatRoomMember,
115    ChatRoomMessage,
116    ContentServer,
117    DepotManifest,
118    EmailInfo,
119    Emoticon,
120    EquippedProfileItems,
121    FileChunk,
122    Friend,
123    FriendMessageSession,
124    FriendsGroup,
125    // GC
126    GCMessage,
127    GCProtoHeader,
128    GCSendOptions,
129    // Game servers
130    GameServer,
131    HistoryMessage,
132    // Idler
133    IdlerHandle,
134    InviteLinkInfo,
135    ManifestFile,
136    // Notifications
137    Notification,
138    NotificationType,
139    OwnedApp,
140    OwnedProfileItems,
141    PackageInfo,
142    PackageInfoRequest,
143    PrivacySettings,
144    ProfileItem,
145    // Published files
146    PublishedFileDetails,
147    // Rich presence
148    RichPresenceData,
149    RolePermissions,
150    SendMessageResult,
151    SteamGuardDetails,
152    // Trading
153    TradeRestrictions,
154    TradeUrl,
155    // Two-factor
156    TwoFactorSecrets,
157    VacBans,
158    VoteData,
159    WalletInfo,
160};
161// Re-export commonly used types from other crates
162pub use steam_enums::{EAccountType, EAppType, EChatEntryType, EClanRelationship, ECurrencyCode, EFriendRelationship, ELicenseType, EPaymentMethod, EPersonaState, EPlatformType, EResult, EServerType, EUniverse};
163pub use steamid::SteamID;
164pub use types::{LogOnDetails, LogOnResponse};
165// Utils (exposed for advanced usage)
166pub use utils::{Clock, HttpClient, HttpResponse, MockClock, MockHttpClient, MockRequest, MockRng, ReqwestHttpClient, Rng, SystemClock, ThreadRng};