diff options
| author | Matthew Collins <[email protected]> | 2018-02-27 12:18:56 +0000 |
|---|---|---|
| committer | Matthew Collins <[email protected]> | 2018-02-27 12:18:56 +0000 |
| commit | db7c3f7bcd5f1e804345bf90591f3e360ef456fb (patch) | |
| tree | 621b19bddf5078ef8c5d763575eeb6745888cb64 | |
| parent | Derive `Ord`/`Eq` for SteamId (diff) | |
| download | steamworks-rs-db7c3f7bcd5f1e804345bf90591f3e360ef456fb.tar.xz steamworks-rs-db7c3f7bcd5f1e804345bf90591f3e360ef456fb.zip | |
Add basic steam user accessor
| -rw-r--r-- | src/lib.rs | 15 | ||||
| -rw-r--r-- | src/user.rs | 17 | ||||
| -rw-r--r-- | steamworks-sys/src/lib.cpp | 3 | ||||
| -rw-r--r-- | steamworks-sys/src/lib.rs | 5 |
4 files changed, 39 insertions, 1 deletions
@@ -18,6 +18,8 @@ mod friends; pub use friends::*; mod matchmaking; pub use matchmaking::*; +mod user; +pub use user::*; use std::sync::{Arc, Mutex, Weak}; use std::ffi::{CString, CStr}; @@ -242,6 +244,19 @@ impl Client { } } + + /// Returns an accessor to the steam user interface + pub fn user(&self) -> User { + unsafe { + let user = sys::steam_rust_get_user(); + debug_assert!(!user.is_null()); + User { + user, + _client: self.inner.clone(), + } + } + + } } impl Drop for ClientInner { diff --git a/src/user.rs b/src/user.rs new file mode 100644 index 0000000..fcd3e40 --- /dev/null +++ b/src/user.rs @@ -0,0 +1,17 @@ + +use super::*; + +/// Access to the steam user interface +pub struct User { + pub(crate) user: *mut sys::ISteamUser, + pub(crate) _client: Arc<ClientInner>, +} + +impl User { + /// Returns the steam id of the current user + pub fn steam_id(&self) -> SteamId { + unsafe { + SteamId(sys::SteamAPI_ISteamUser_GetSteamID(self.user)) + } + } +}
\ No newline at end of file diff --git a/steamworks-sys/src/lib.cpp b/steamworks-sys/src/lib.cpp index 9994909..75c399a 100644 --- a/steamworks-sys/src/lib.cpp +++ b/steamworks-sys/src/lib.cpp @@ -99,4 +99,5 @@ extern "C" ISteamMatchmaking *steam_rust_get_matchmaking() { } extern "C" ISteamUtils *steam_rust_get_utils() { return SteamUtils(); } extern "C" ISteamApps *steam_rust_get_apps() { return SteamApps(); } -extern "C" ISteamFriends *steam_rust_get_friends() { return SteamFriends(); }
\ No newline at end of file +extern "C" ISteamFriends *steam_rust_get_friends() { return SteamFriends(); } +extern "C" ISteamUser *steam_rust_get_user() { return SteamUser(); }
\ No newline at end of file diff --git a/steamworks-sys/src/lib.rs b/steamworks-sys/src/lib.rs index 604d12e..db642ac 100644 --- a/steamworks-sys/src/lib.rs +++ b/steamworks-sys/src/lib.rs @@ -17,6 +17,8 @@ pub struct ISteamApps(c_void); pub struct ISteamFriends(c_void); #[repr(C)] pub struct ISteamMatchmaking(c_void); +#[repr(C)] +pub struct ISteamUser(c_void); pub type HSteamPipe = i32; pub type HSteamUser = i32; @@ -215,6 +217,7 @@ extern "C" { pub fn steam_rust_get_utils() -> *mut ISteamUtils; pub fn steam_rust_get_apps() -> *mut ISteamApps; pub fn steam_rust_get_friends() -> *mut ISteamFriends; + pub fn steam_rust_get_user() -> *mut ISteamUser; // pub fn SteamAPI_Init() -> u8; @@ -255,4 +258,6 @@ extern "C" { pub fn SteamAPI_ISteamMatchmaking_CreateLobby(instance: *mut ISteamMatchmaking, lobby_ty: LobbyType, max_members: c_int) -> SteamAPICall; pub fn SteamAPI_ISteamMatchmaking_RequestLobbyList(instance: *mut ISteamMatchmaking) -> SteamAPICall; pub fn SteamAPI_ISteamMatchmaking_GetLobbyByIndex(instance: *mut ISteamMatchmaking, lobby: c_int) -> u64; + + pub fn SteamAPI_ISteamUser_GetSteamID(instance: *mut ISteamUser) -> u64; } |