diff options
| author | Matthew Collins <[email protected]> | 2019-09-04 19:50:43 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2019-09-04 19:50:43 +0100 |
| commit | 49c9e90723ae8db3436ea1226341a7ed4b50f39a (patch) | |
| tree | 2c8739e0208be551e962e93c17623224468b6430 | |
| parent | Replaced tabs with spaces (diff) | |
| parent | Binding for SetLobbyJoinable, FriendState derivations, small documentation ad... (diff) | |
| download | steamworks-rs-49c9e90723ae8db3436ea1226341a7ed4b50f39a.tar.xz steamworks-rs-49c9e90723ae8db3436ea1226341a7ed4b50f39a.zip | |
Merge pull request #17 from Flaise/matchmaking
binding for SetLobbyJoinable
| -rw-r--r-- | src/error.rs | 4 | ||||
| -rw-r--r-- | src/friends.rs | 7 | ||||
| -rw-r--r-- | src/matchmaking.rs | 19 | ||||
| -rw-r--r-- | src/server.rs | 2 | ||||
| -rw-r--r-- | src/ugc.rs | 4 | ||||
| -rw-r--r-- | src/user_stats.rs | 8 | ||||
| -rw-r--r-- | src/utils.rs | 2 | ||||
| -rw-r--r-- | steamworks-sys/src/lib.rs | 1 |
8 files changed, 32 insertions, 15 deletions
diff --git a/src/error.rs b/src/error.rs index cea2ed9..0f5fc39 100644 --- a/src/error.rs +++ b/src/error.rs @@ -7,7 +7,7 @@ use crate::sys; /// /// Documentation is based on official documentation which doesn't /// always explain when an error could be returned or its meaning. -#[derive(Debug, Fail, PartialEq, Eq)] +#[derive(Copy, Clone, Debug, Fail, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub enum SteamError { /// Returned if the steamworks API fails to initialize. @@ -56,7 +56,7 @@ pub enum SteamError { #[fail(display = "access denied")] AccessDenied, /// Returned when the operation timed out - #[fail(display = "operation timed")] + #[fail(display = "operation timed out")] Timeout, /// Returned when the user is VAC2 banned #[fail(display = "VAC2 banned")] diff --git a/src/friends.rs b/src/friends.rs index b7a12f0..1958258 100644 --- a/src/friends.rs +++ b/src/friends.rs @@ -1,4 +1,3 @@ - use super::*; use std::net::Ipv4Addr; @@ -230,7 +229,7 @@ impl <Manager> Friend<Manager> { } } - /// Returns a small (32x32) avatar for the user + /// Returns a small (32x32) avatar for the user in RGBA format pub fn small_avatar(&self) -> Option<Vec<u8>> { unsafe { let utils = sys::steam_rust_get_utils(); @@ -253,7 +252,7 @@ impl <Manager> Friend<Manager> { } } - /// Returns a small (64x64) avatar for the user + /// Returns a medium (64x64) avatar for the user in RGBA format pub fn medium_avatar(&self) -> Option<Vec<u8>> { unsafe { let utils = sys::steam_rust_get_utils(); @@ -277,7 +276,7 @@ impl <Manager> Friend<Manager> { } } -#[derive(Clone, Copy, Debug)] +#[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum FriendState { Offline, Online, diff --git a/src/matchmaking.rs b/src/matchmaking.rs index f3e3b94..f10eff1 100644 --- a/src/matchmaking.rs +++ b/src/matchmaking.rs @@ -84,7 +84,7 @@ impl <Manager> Matchmaking<Manager> { /// * `LobbyEnter` /// * `LobbyCreated` pub fn create_lobby<F>(&self, ty: LobbyType, max_members: u32, mut cb: F) - where F: FnMut(Result<LobbyId, SteamError>) + 'static + Send + where F: FnMut(SResult<LobbyId>) + 'static + Send { assert!(max_members <= 250); // Steam API limits unsafe { @@ -168,6 +168,23 @@ impl <Manager> Matchmaking<Manager> { members } } + + /// Sets whether or not a lobby is joinable by other players. This always defaults to enabled + /// for a new lobby. + /// + /// If joining is disabled, then no players can join, even if they are a friend or have been + /// invited. + /// + /// Lobbies with joining disabled will not be returned from a lobby search. + /// + /// Returns true on success, false if the current user doesn't own the lobby. + pub fn set_lobby_joinable(&self, lobby: LobbyId, joinable: bool) -> bool { + unsafe { + sys::SteamAPI_ISteamMatchmaking_SetLobbyJoinable( + self.mm, sys::CSteamID(lobby.0), joinable + ) != 0 + } + } } #[test] diff --git a/src/server.rs b/src/server.rs index 47916d3..f178d28 100644 --- a/src/server.rs +++ b/src/server.rs @@ -100,7 +100,7 @@ impl Server { /// is called when the event arrives. pub fn register_callback<C, F>(&self, f: F) -> CallbackHandle<ServerManager> where C: Callback, - F: FnMut(C) + 'static + Send + Sync + F: FnMut(C) + 'static + Send { unsafe { register_callback(&self.inner, f, true) @@ -167,7 +167,7 @@ impl <Manager> UGC<Manager> { /// Subscribes to a workshop item pub fn subscribe_item<F>(&self, published_file_id: PublishedFileId, mut cb: F) - where F: FnMut(Result<(), SteamError>) + 'static + Send + Sync + where F: FnMut(Result<(), SteamError>) + 'static + Send { unsafe { let api_call = sys::SteamAPI_ISteamUGC_SubscribeItem(self.ugc, published_file_id.0); @@ -186,7 +186,7 @@ impl <Manager> UGC<Manager> { } pub fn unsubscribe_item<F>(&self, published_file_id: PublishedFileId, mut cb: F) - where F: FnMut(Result<(), SteamError>) + 'static + Send + Sync + where F: FnMut(Result<(), SteamError>) + 'static + Send { unsafe { let api_call = sys::SteamAPI_ISteamUGC_UnsubscribeItem(self.ugc, published_file_id.0); diff --git a/src/user_stats.rs b/src/user_stats.rs index 941deff..8a2fe16 100644 --- a/src/user_stats.rs +++ b/src/user_stats.rs @@ -17,7 +17,7 @@ const CALLBACK_BASE_ID: i32 = 1100; impl <Manager> UserStats<Manager> { pub fn find_leaderboard<F>(&self, name: &str, mut cb: F) - where F: FnMut(Result<Option<Leaderboard>, SteamError>) + 'static + Send + Sync + where F: FnMut(Result<Option<Leaderboard>, SteamError>) + 'static + Send { unsafe { let name = CString::new(name).unwrap(); @@ -39,7 +39,7 @@ impl <Manager> UserStats<Manager> { } pub fn find_or_create_leaderboard<F>(&self, name: &str, sort_method: LeaderboardSortMethod, display_type: LeaderboardDisplayType, mut cb: F) - where F: FnMut(Result<Option<Leaderboard>, SteamError>) + 'static + Send + Sync + where F: FnMut(Result<Option<Leaderboard>, SteamError>) + 'static + Send { unsafe { let name = CString::new(name).unwrap(); @@ -74,7 +74,7 @@ impl <Manager> UserStats<Manager> { } pub fn upload_leaderboard_score<F>(&self, leaderboard: &Leaderboard, method: UploadScoreMethod, score: i32, details: &[i32], mut cb: F) - where F: FnMut(Result<Option<LeaderboardScoreUploaded>, SteamError>) + 'static + Send + Sync + where F: FnMut(Result<Option<LeaderboardScoreUploaded>, SteamError>) + 'static + Send { unsafe { let method = match method { @@ -110,7 +110,7 @@ impl <Manager> UserStats<Manager> { max_details_len: usize, mut cb: F ) - where F: FnMut(Result<Vec<LeaderboardEntry>, SteamError>) + 'static + Send + Sync + where F: FnMut(Result<Vec<LeaderboardEntry>, SteamError>) + 'static + Send { unsafe { let request = match request { diff --git a/src/utils.rs b/src/utils.rs index d10dbb4..da868c4 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -22,7 +22,7 @@ pub enum NotificationPosition { lazy_static! { /// Global rust warning callback - static ref WARNING_CALLBACK: RwLock<Option<Box<Fn(i32, &CStr) + Send + Sync>>> = RwLock::new(None); + static ref WARNING_CALLBACK: RwLock<Option<Box<dyn Fn(i32, &CStr) + Send + Sync>>> = RwLock::new(None); } /// C function to pass as the real callback, which forwards to the `WARNING_CALLBACK` if any diff --git a/steamworks-sys/src/lib.rs b/steamworks-sys/src/lib.rs index 18d8ecf..c15b77b 100644 --- a/steamworks-sys/src/lib.rs +++ b/steamworks-sys/src/lib.rs @@ -141,6 +141,7 @@ extern "C" { pub fn SteamAPI_ISteamMatchmaking_GetLobbyOwner(instance: *mut ISteamMatchmaking, lobby: CSteamID) -> CSteamID; pub fn SteamAPI_ISteamMatchmaking_GetNumLobbyMembers(instance: *mut ISteamMatchmaking, lobby: CSteamID) -> c_int; pub fn SteamAPI_ISteamMatchmaking_GetLobbyMemberByIndex(instance: *mut ISteamMatchmaking, lobby: CSteamID, member: c_int) -> CSteamID; + pub fn SteamAPI_ISteamMatchmaking_SetLobbyJoinable(instance: *mut ISteamMatchmaking, lobby: CSteamID, lobbyJoinable: bool) -> u8; pub fn SteamAPI_ISteamNetworking_AcceptP2PSessionWithUser(instance: *mut ISteamNetworking, remote: CSteamID) -> u8; pub fn SteamAPI_ISteamNetworking_CloseP2PSessionWithUser(instance: *mut ISteamNetworking, remote: CSteamID) -> u8; |