Skip to main content

FakeSteamBackend

Struct FakeSteamBackend 

Source
pub struct FakeSteamBackend { /* private fields */ }
Expand description

An in-memory Steam. Cheap to clone: every clone shares the same state, so a test keeps one clone to inspect while the kit owns another inside crate::SteamBackendRes.

Defaults: local id 76561197960265729, app id 480; with feature lobby, create_lobby completes on the next pump with ids 1000, 1001, ... and join_lobby succeeds on the next pump; with feature stats, stats are ready, no stat or achievement is defined, and a store succeeds on the next pump; with auth, a ticket arrives on the next pump; with friends, no friends; with overlay, the overlay is enabled. Each feature’s knobs are listed with its methods.

Implementations§

Source§

impl FakeSteamBackend

Auth controls (feature auth).

Source

pub fn fake_web_api_ticket(op: u64) -> Vec<u8> ⓘ

Available on crate feature auth only.

The bytes of the fake ticket for backend operation op: b"FAKE-TICKET-<op>". The kit numbers its ticket requests 1, 2, 3, … in the order it sends them.

Source

pub fn fail_next_auth_ticket(&self, failure: FakeAuthFailure)

Available on crate feature auth only.

Make the next ticket request fail in the given way.

Source

pub fn live_auth_tickets(&self) -> Vec<String>

Available on crate feature auth only.

The identities of every ticket requested and not cancelled (pending or delivered), in request order.

Source§

impl FakeSteamBackend

Source

pub fn new() -> Self

A fresh fake Steam with the defaults described on the type.

Source

pub fn calls(&self) -> Vec<FakeCall>

Every call recorded so far, in order.

Source

pub fn pump_count(&self) -> u64

How many times SteamBackend::pump has been called (the kit pumps exactly once per frame while this backend is installed).

Source

pub fn set_local_id(&self, id: u64)

Set the local user’s SteamID64.

Source

pub fn push_event(&self, event: BackendEvent)

Queue any raw backend event (e.g. a join request) for the next pump.

Source

pub fn set_friend_name(&self, id: u64, name: &str)

Give a user a persona name. With feature friends this also queues the PersonaChanged (name) event Steam sends.

Source

pub fn set_launch_command_line(&self, text: &str)

Set what launch_command_line returns.

Source

pub fn simulate_steam_exit(&self)

Queue what the real backend reports when the Steam client exits while the game runs (BackendEvent::SteamLost with crate::SteamLostReason::SteamExited) for the next pump: the kit then makes the backend inert (never pumped again) and writes crate::SteamLost.

Source

pub fn simulate_steam_shutdown(&self)

What the real backend does when Steam sends its shutdown callback: from this call on the backend supports no feature (every feature accessor is None, so the kit cannot reach any feature call), the next pump drops what was queued and returns BackendEvent::SteamLost once, later pumps return nothing. calls shows that nothing reaches the backend afterwards.

Source

pub fn simulate_steam_process_ended(&self)

What the real backend does when the operating system reports the Steam client process gone (killed or crashed, no shutdown callback): the same as simulate_steam_shutdown, with crate::SteamLostReason::SteamProcessEnded.

Source

pub fn panic_in_next_pump(&self)

The next pump PANICS (like a panic inside steamworks), to test that the kit catches it (in a build that unwinds): that frame’s queued events are dropped and Steam is treated as lost. Rust’s panic hook prints the panic message as usual.

Source

pub fn set_app_id(&self, app_id: u32)

Set the running app’s id (default 480), as the friends feature sees it.

Source

pub fn push_rich_presence_join(&self, from: u64, connect: &str)

Available on crate features friends or lobby only.

Queue what real Steam produces for a rich-presence “Join Game” or an accepted invite while the game runs (GameRichPresenceJoinRequested): one event per compiled feature that reads it (RichPresenceJoinRequested for lobby, ConnectRequested for friends), as the real backend does.

Source§

impl FakeSteamBackend

Friends controls (feature friends). Each change queues the PersonaChanged event real Steam would send (delivered on the next pump).

Source

pub fn add_friend(&self, id: u64, state: PersonaState)

Available on crate feature friends only.

Add a friend with this state (name: set_friend_name).

Source

pub fn remove_friend(&self, id: u64)

Available on crate feature friends only.

Remove a friend.

Source

pub fn set_friend_state(&self, id: u64, state: PersonaState)

Available on crate feature friends only.

Change a friend’s online status.

Source

pub fn set_friend_game(&self, id: u64, game: Option<(u32, u64)>)

Available on crate feature friends only.

Set (Some((app_id, lobby))) or clear the game a friend plays.

Source

pub fn set_friend_rich_presence(&self, id: u64, key: &str, value: Option<&str>)

Available on crate feature friends only.

Set (Some) or remove (None) one rich-presence key of a friend. Like real Steam, this sends NO event: the kit sees it on its next refresh.

Source

pub fn set_friend_nickname(&self, id: u64, nickname: Option<&str>)

Available on crate feature friends only.

Set (Some) or clear the nickname the local user gave a friend.

Source

pub fn set_local_persona(&self, name: &str, state: PersonaState)

Available on crate feature friends only.

Set the local user’s own persona name and state.

Source

pub fn set_friend_avatar(&self, id: u64, width: u32, height: u32, rgba: Vec<u8>)

Available on crate feature friends only.

Give a user an avatar (returned for every size; rgba should be width * height * 4 bytes).

Source

pub fn set_friend_avatar_loading(&self, id: u64, loading: bool)

Available on crate feature friends only.

true: the user’s avatar is “loading” (None for every size, as Steam answers while it loads a large one); false: available again, with a PersonaChanged like Steam.

Source

pub fn set_user_info_loaded(&self, id: u64)

Available on crate feature friends only.

Mark a user’s info as already loaded: request_user_information then returns false (as it does for friends; otherwise it returns true and queues a PersonaChanged for the user).

Source

pub fn silence_next_user_info(&self)

Available on crate feature friends only.

The next request_user_information is accepted, but Steam never delivers the persona.

Source

pub fn refuse_next_game_invite(&self)

Available on crate feature friends only.

The next game invite is refused by Steam (GameInviteSent { ok: false }).

Source§

impl FakeSteamBackend

Leaderboard controls (feature leaderboards).

Source

pub fn add_leaderboard( &self, name: &str, sort: LeaderboardSort, display: LeaderboardDisplay, )

Available on crate feature leaderboards only.

Create a board, as the partner site would.

Source

pub fn add_leaderboard_entry( &self, board: &str, steam_id: u64, score: i32, details: &[i32], )

Available on crate feature leaderboards only.

Put a player’s entry on a board (replacing theirs). Details beyond 64 are dropped.

Source

pub fn set_friends(&self, friends: &[u64])

Available on crate feature leaderboards only.

The local player’s Steam friends (for ScoreRange::Friends).

Source

pub fn fail_next_leaderboard_call(&self, failure: FakeLeaderboardFailure)

Available on crate feature leaderboards only.

Make the next leaderboard call fail in the given way.

Source

pub fn leaderboard_entries(&self, board: &str) -> Vec<LeaderboardEntry>

Available on crate feature leaderboards only.

A board’s entries, best first (empty for an unknown board).

Source§

impl FakeSteamBackend

Lobby controls (feature lobby).

Source

pub fn set_auto_complete_create(&self, auto: bool)

Available on crate feature lobby only.

false: create_lobby stays pending until complete_create / fail_create.

Source

pub fn set_join_succeeds(&self, ok: bool)

Available on crate feature lobby only.

Make the following join_lobby calls fail (false) or succeed (true).

Source

pub fn complete_create(&self, lobby: u64)

Available on crate feature lobby only.

Complete a pending create with lobby (delivered on the next pump).

Source

pub fn fail_create(&self, message: &str)

Available on crate feature lobby only.

Fail a pending create (delivered on the next pump).

Source

pub fn set_member_count(&self, lobby: u64, count: usize)

Available on crate feature lobby only.

Set a lobby’s member count as seen by lobby_member_count.

Source

pub fn put_lobby_data(&self, lobby: u64, key: &str, value: &str)

Available on crate feature lobby only.

Pre-set lobby metadata (as if another host had set it).

Source

pub fn rich_presence(&self, key: &str) -> Option<String>

Available on crate feature lobby only.

Current rich presence value for key.

Source§

impl FakeSteamBackend

Overlay controls (feature overlay). Every request the kit passes on is recorded as FakeCall::ActivateOverlay.

Source

pub fn set_overlay_enabled(&self, enabled: bool)

Available on crate feature overlay only.

Whether Steam reports the overlay as available (default true).

Source

pub fn toggle_overlay(&self, active: bool)

Available on crate feature overlay only.

Queue an “overlay opened” (true) or “closed” (false) event, as Steam sends when the player presses Shift+Tab.

Source

pub fn refuse_next_overlay(&self)

Available on crate feature overlay only.

The backend refuses the next overlay call (OverlayErrorKind::Refused).

Source§

impl FakeSteamBackend

Stats controls (feature stats).

Source

pub fn define_stat(&self, name: &str, value: StatValue)

Available on crate feature stats only.

Define a stat with its type (the variant) and starting value, as the partner site would.

Source

pub fn define_achievement(&self, name: &str, unlocked: bool)

Available on crate feature stats only.

Define an achievement, locked or already unlocked.

Source

pub fn set_stats_ready(&self, ready: bool)

Available on crate feature stats only.

false: every stats call fails as if Steam had not loaded the stats (default true).

Source

pub fn fail_next_store(&self, failure: FakeStoreFailure)

Available on crate feature stats only.

Make the next store_stats fail in the given way.

Source

pub fn stat(&self, name: &str) -> Option<StatValue>

Available on crate feature stats only.

A stat’s current in-memory value.

Source

pub fn achieved(&self, name: &str) -> Option<bool>

Available on crate feature stats only.

Whether an achievement is unlocked (in memory).

Trait Implementations§

Source§

impl AuthBackend for FakeSteamBackend

Available on crate feature auth only.
Source§

fn request_web_api_ticket(&self, op: u64, identity: &str) -> bool

Ask Steam for a Web API ticket for identity (the name of the service that checks it). false = refused (for example an identity with a NUL byte).
Source§

fn cancel_auth_ticket(&self, op: u64)

Cancel the ticket of op (pending or delivered). Unknown ops are ignored.
Source§

impl Clone for FakeSteamBackend

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FakeSteamBackend

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for FakeSteamBackend

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl FriendsBackend for FakeSteamBackend

Available on crate feature friends only.
Source§

fn current_app_id(&self) -> u32

The running app’s id.
Source§

fn friend_ids(&self) -> Vec<u64>

The SteamID64s of the local user’s friends (Steam’s “immediate” friends).
Source§

fn persona_name(&self, id: u64) -> String

A user’s persona name.
Source§

fn persona_nickname(&self, id: u64) -> Option<String>

The nickname the local user gave this user, if any.
Source§

fn persona_state(&self, id: u64) -> PersonaState

A friend’s online status.
Source§

fn game_played(&self, id: u64) -> Option<FriendGame>

The game a friend is playing, if any.
Source§

fn friend_rich_presence(&self, id: u64, key: &str) -> Option<String>

One rich-presence value of a friend (None when unset or empty). Steam shares the rich presence of friends playing the same game; others’ is generally not available.
Source§

fn local_persona(&self) -> (String, PersonaState)

The local user’s own persona name and state, the state as friends see it (Away, Invisible, …). The real backend reads it like a friend’s state, with the local user’s own id.
Source§

fn invite_user_to_game(&self, id: u64, connect: &str) -> bool

Send a Steam game invite carrying connect (at most MAX_CONNECT_BYTES, no NUL). true = the call was made (Steam gives no delivery receipt).
Source§

fn request_user_information(&self, id: u64, name_only: bool) -> bool

Ask Steam to load a user’s persona (name, and the avatar unless name_only). true = it is being loaded (a PersonaChanged event follows); false = it is already available.
Source§

fn friend_avatar( &self, id: u64, _size: AvatarSize, ) -> Option<(u32, u32, Vec<u8>)>

A user’s avatar as (width, height, RGBA bytes), or None when Steam has none (or has not loaded it).
Source§

impl LeaderboardBackend for FakeSteamBackend

Available on crate feature leaderboards only.
Source§

fn find_leaderboard( &self, op: u64, name: &str, create: Option<(LeaderboardSort, LeaderboardDisplay)>, ) -> bool

Find a leaderboard by name, creating it with create when given and missing. Outcome: LeaderboardFound, LeaderboardNotFound or LeaderboardIoFailure with this op.
Source§

fn upload_score( &self, op: u64, board: u64, method: UploadMethod, score: i32, details: &[i32], ) -> bool

Upload a score (at most MAX_LEADERBOARD_DETAILS details) to a found board. Outcome: LeaderboardScoreUploaded, LeaderboardUploadRejected or LeaderboardIoFailure.
Source§

fn download_scores(&self, op: u64, board: u64, range: ScoreRange) -> bool

Download entries of a found board (always with room for MAX_LEADERBOARD_DETAILS details per entry). Outcome: LeaderboardScoresDownloaded or LeaderboardIoFailure.
Source§

fn leaderboard_sort(&self, board: u64) -> Option<LeaderboardSort>

A found board’s sort method (None when unknown).
Source§

fn leaderboard_display(&self, board: u64) -> Option<LeaderboardDisplay>

A found board’s display type (None when unknown).
Source§

fn leaderboard_entry_count(&self, board: u64) -> i32

A found board’s entry count as of the last find / upload / download (0 when unknown).
Source§

impl LobbyBackend for FakeSteamBackend

Available on crate feature lobby only.
Source§

fn create_lobby(&self, kind: LobbyKind, max_members: u32)

Start creating a lobby. Outcome: BackendEvent::LobbyCreated or BackendEvent::LobbyCreateFailed from a following pump.
Source§

fn join_lobby(&self, lobby: u64)

Start joining a lobby. Outcome: BackendEvent::LobbyEntered or BackendEvent::LobbyJoinFailed from a following pump.
Source§

fn leave_lobby(&self, lobby: u64)

Leave a lobby (no-op if not a member).
Source§

fn set_lobby_data(&self, lobby: u64, key: &str, value: &str) -> bool

Set a lobby metadata key (owner only). false on failure.
Source§

fn lobby_data(&self, lobby: u64, key: &str) -> Option<String>

Read a lobby metadata key. None when missing.
Source§

fn lobby_member_count(&self, lobby: u64) -> usize

Number of members currently in the lobby.
Source§

fn set_lobby_joinable(&self, lobby: u64, joinable: bool) -> bool

Allow or forbid joining the lobby. false on failure.
Source§

fn set_rich_presence(&self, key: &str, value: Option<&str>) -> bool

Set (Some) or remove (None) one rich-presence key. false on failure.
Source§

fn clear_rich_presence(&self)

Remove every rich-presence key this process set.
Source§

fn invite_to_game(&self, friend: u64, connect: &str) -> bool

Send a Steam game invite carrying connect to friend. false if it could not be sent.
Source§

impl OverlayBackend for FakeSteamBackend

Available on crate feature overlay only.
Source§

fn overlay_enabled(&self) -> bool

Steam reports the overlay as available to this process.
Source§

fn open_overlay(&self, request: &OpenOverlay) -> bool

Open the overlay as requested. true = the call was made (Steam gives no answer).
Source§

impl StatsBackend for FakeSteamBackend

Available on crate feature stats only.
Source§

fn is_ready(&self, probe: Option<&str>) -> bool

Are the local user’s stats loaded? probe is a stat or achievement name to test with (None: the backend picks its own test). Must be cheap: called about once a second until it returns true.
Source§

fn get_stat(&self, name: &str, kind: StatKind) -> Option<StatValue>

Read a stat of the given kind. None: unknown name, wrong kind, or not loaded.
Source§

fn set_stat(&self, name: &str, value: StatValue) -> bool

Write a stat (in memory). false: unknown name, wrong kind, not loaded, or not finite.
Source§

fn achievement(&self, name: &str) -> Option<bool>

Is the achievement unlocked? None: unknown name or not loaded.
Source§

fn unlock_achievement(&self, name: &str) -> bool

Unlock an achievement (in memory; the popup shows on the next store). false on failure.
Source§

fn clear_achievement(&self, name: &str) -> bool

Lock an achievement again (in memory; meant for development). false on failure.
Source§

fn indicate_achievement_progress( &self, name: &str, current: u32, max: u32, ) -> bool

Show the “current / max” progress popup of an achievement. Sets and unlocks nothing. false on failure.
Source§

fn store_stats(&self) -> bool

Send the in-memory changes to Steam. true = the store was started; its outcome arrives later. false = refused locally (nothing to store for this app, stats not loaded).
Source§

fn reset_all_stats(&self, achievements_too: bool) -> bool

Reset every stat (and, optionally, every achievement) of the local user and store it. Meant for development. false on failure.
Source§

impl SteamBackend for FakeSteamBackend

Source§

fn local_id(&self) -> u64

The local user’s SteamID64.
Source§

fn friend_name(&self, id: u64) -> String

A user’s persona name. What an unknown user gives is the backend’s: real Steam returns "[unknown]" for a user it knows nothing about (Valve’s GetFriendPersonaName), the fake backend returns "".
Source§

fn launch_command_line(&self) -> String

The command line Steam launched the game with (“” when none).
Source§

fn pump(&self) -> Vec<BackendEvent>

Pump Steam callbacks once and return everything that arrived since the last pump (callbacks + completed call results). Called by the kit exactly once per frame, in crate::SteamKitSystems::Pump; never call it yourself. A backend that learns Steam is gone returns BackendEvent::SteamLost; a panic in here is caught by the kit (in a build that unwinds) and treated the same way (SteamLostReason::PumpPanicked).
Source§

fn lobby(&self) -> Option<&dyn LobbyBackend>

Available on crate feature lobby only.
The lobby / rich presence / invite half of this backend (feature lobby). The default is None: the lobby feature then treats Steam as unavailable and answers requests with crate::LobbyErrorKind::NoBackend.
Source§

fn stats(&self) -> Option<&dyn StatsBackend>

Available on crate feature stats only.
The stats / achievements half of this backend (feature stats). The default is None: the stats feature then treats Steam as unavailable and answers requests with crate::StatsErrorKind::NoBackend.
Source§

fn leaderboards(&self) -> Option<&dyn LeaderboardBackend>

Available on crate feature leaderboards only.
The leaderboard half of this backend (feature leaderboards). The default is None: the leaderboards feature then treats Steam as unavailable and answers requests with crate::LeaderboardErrorKind::NoBackend.
Source§

fn auth(&self) -> Option<&dyn AuthBackend>

Available on crate feature auth only.
The Web API ticket half of this backend (feature auth). The default is None: the auth feature then answers requests with crate::AuthErrorKind::NoBackend.
Source§

fn friends(&self) -> Option<&dyn FriendsBackend>

Available on crate feature friends only.
The friends half of this backend (feature friends). The default is None: the friends feature then treats Steam as unavailable (crate::FriendsErrorKind::NoBackend).
Source§

fn overlay(&self) -> Option<&dyn OverlayBackend>

Available on crate feature overlay only.
The overlay half of this backend (feature overlay). The default is None: the overlay feature then answers requests with crate::OverlayErrorKind::NoBackend.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> ConditionalSend for T
where T: Send,

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSend for T
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromTemplate for T
where T: Clone + Default + Unpin,

Source§

type Template = T

The Template for this type.
Source§

impl<T> FromWorld for T
where T: Default,

Source§

fn from_world(_world: &mut World) -> T

Creates Self using default().

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoResult<T> for T

Source§

fn into_result(self) -> Result<T, RunSystemError>

Converts this type into the system output type.
Source§

impl<T> Template for T
where T: Clone + Unpin,

Source§

type Output = T

The type of value produced by this Template.
Source§

fn build_template( &self, _context: &mut TemplateContext<'_, '_>, ) -> Result<<T as Template>::Output, BevyError>

Uses this template and the given entity context to produce a Template::Output.
Source§

fn clone_template(&self) -> T

Clones this template. See Clone.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more