aboutsummaryrefslogtreecommitdiff
path: root/src/friends.rs
diff options
context:
space:
mode:
authorMatthew Collins <[email protected]>2020-02-22 20:50:46 +0000
committerMatthew Collins <[email protected]>2020-02-22 20:50:46 +0000
commit0b4f68b1f4fac5c7e608861274eadeb5186688b3 (patch)
tree9d69e5fd94e4d6cd8c7a535f4a0236e2d55c7d35 /src/friends.rs
parentBump version to 0.6.1 (diff)
downloadsteamworks-rs-0b4f68b1f4fac5c7e608861274eadeb5186688b3.tar.xz
steamworks-rs-0b4f68b1f4fac5c7e608861274eadeb5186688b3.zip
Rework to use the new flat steam api
Diffstat (limited to 'src/friends.rs')
-rw-r--r--src/friends.rs56
1 files changed, 30 insertions, 26 deletions
diff --git a/src/friends.rs b/src/friends.rs
index 82e4633..5159732 100644
--- a/src/friends.rs
+++ b/src/friends.rs
@@ -71,7 +71,7 @@ impl <Manager> Friends<Manager> {
}
let mut friends = Vec::with_capacity(count as usize);
for idx in 0 .. count {
- let friend = SteamId(sys::SteamAPI_ISteamFriends_GetFriendByIndex(self.friends, idx, flags.bits() as _).0);
+ let friend = SteamId(sys::SteamAPI_ISteamFriends_GetFriendByIndex(self.friends, idx, flags.bits() as _));
friends.push(Friend {
id: friend,
friends: self.friends,
@@ -93,7 +93,7 @@ impl <Manager> Friends<Manager> {
pub fn request_user_information(&self, user: SteamId, name_only: bool) {
unsafe {
- sys::SteamAPI_ISteamFriends_RequestUserInformation(self.friends, sys::CSteamID(user.0), name_only as u8);
+ sys::SteamAPI_ISteamFriends_RequestUserInformation(self.friends, user.0, name_only);
}
}
@@ -101,14 +101,18 @@ impl <Manager> Friends<Manager> {
pub fn activate_game_overlay_to_web_page(&self, url: &str) {
unsafe {
let url = CString::new(url).unwrap();
- sys::SteamAPI_ISteamFriends_ActivateGameOverlayToWebPage(self.friends, url.as_ptr() as *const _);
+ sys::SteamAPI_ISteamFriends_ActivateGameOverlayToWebPage(
+ self.friends,
+ url.as_ptr() as *const _,
+ sys::EActivateGameOverlayToWebPageMode::k_EActivateGameOverlayToWebPageMode_Default
+ );
}
}
/// Opens up an invite dialog for the given lobby
pub fn activate_invite_dialog(&self, lobby: LobbyId) {
unsafe {
- sys::SteamAPI_ISteamFriends_ActivateGameOverlayInviteDialog(self.friends, sys::CSteamID(lobby.0));
+ sys::SteamAPI_ISteamFriends_ActivateGameOverlayInviteDialog(self.friends, lobby.0);
}
}
}
@@ -164,8 +168,8 @@ unsafe impl Callback for GameLobbyJoinRequested {
unsafe fn from_raw(raw: *mut libc::c_void) -> Self {
let val = &mut *(raw as *mut sys::GameLobbyJoinRequested_t);
GameLobbyJoinRequested {
- lobby_steam_id: LobbyId(val.m_steamIDLobby.0),
- friend_steam_id: SteamId(val.m_steamIDFriend.0),
+ lobby_steam_id: LobbyId(val.m_steamIDLobby.m_steamid.m_unAll64Bits),
+ friend_steam_id: SteamId(val.m_steamIDFriend.m_steamid.m_unAll64Bits),
}
}
}
@@ -189,7 +193,7 @@ impl <Manager> Friend<Manager> {
pub fn name(&self) -> String {
unsafe {
- let name = sys::SteamAPI_ISteamFriends_GetFriendPersonaName(self.friends, sys::CSteamID(self.id.0));
+ let name = sys::SteamAPI_ISteamFriends_GetFriendPersonaName(self.friends, self.id.0);
let name = CStr::from_ptr(name);
name.to_string_lossy().into_owned()
}
@@ -197,15 +201,15 @@ impl <Manager> Friend<Manager> {
pub fn state(&self) -> FriendState {
unsafe {
- let state = sys::SteamAPI_ISteamFriends_GetFriendPersonaState(self.friends, sys::CSteamID(self.id.0));
+ let state = sys::SteamAPI_ISteamFriends_GetFriendPersonaState(self.friends, self.id.0);
match state {
- sys::EPersonaState::EPersonaStateOffline => FriendState::Offline,
- sys::EPersonaState::EPersonaStateOnline => FriendState::Online,
- sys::EPersonaState::EPersonaStateBusy => FriendState::Busy,
- sys::EPersonaState::EPersonaStateAway => FriendState::Away,
- sys::EPersonaState::EPersonaStateSnooze => FriendState::Snooze,
- sys::EPersonaState::EPersonaStateLookingToPlay => FriendState::LookingToPlay,
- sys::EPersonaState::EPersonaStateLookingToTrade => FriendState::LookingToTrade,
+ sys::EPersonaState::k_EPersonaStateOffline => FriendState::Offline,
+ sys::EPersonaState::k_EPersonaStateOnline => FriendState::Online,
+ sys::EPersonaState::k_EPersonaStateBusy => FriendState::Busy,
+ sys::EPersonaState::k_EPersonaStateAway => FriendState::Away,
+ sys::EPersonaState::k_EPersonaStateSnooze => FriendState::Snooze,
+ sys::EPersonaState::k_EPersonaStateLookingToPlay => FriendState::LookingToPlay,
+ sys::EPersonaState::k_EPersonaStateLookingToTrade => FriendState::LookingToTrade,
_ => unreachable!(),
}
}
@@ -215,13 +219,13 @@ impl <Manager> Friend<Manager> {
pub fn game_played(&self) -> Option<FriendGame> {
unsafe {
let mut info: sys::FriendGameInfo_t = std::mem::zeroed();
- if sys::SteamAPI_ISteamFriends_GetFriendGamePlayed(self.friends, sys::CSteamID(self.id.0), &mut info) != 0 {
+ if sys::SteamAPI_ISteamFriends_GetFriendGamePlayed(self.friends, self.id.0, &mut info) {
Some(FriendGame {
- game: GameId(info.m_gameID.0),
+ game: GameId(std::mem::transmute(info.m_gameID)),
game_address: info.m_unGameIP.into(),
game_port: info.m_usGamePort,
query_port: info.m_usQueryPort,
- lobby: LobbyId(info.m_steamIDLobby.0),
+ lobby: LobbyId(info.m_steamIDLobby.m_steamid.m_unAll64Bits),
})
} else {
None
@@ -232,20 +236,20 @@ impl <Manager> Friend<Manager> {
/// 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();
- let img = sys::SteamAPI_ISteamFriends_GetSmallFriendAvatar(self.friends, sys::CSteamID(self.id.0));
+ let utils = sys::SteamAPI_SteamUtils_v009();
+ let img = sys::SteamAPI_ISteamFriends_GetSmallFriendAvatar(self.friends, self.id.0);
if img == 0 {
return None;
}
let mut width = 0;
let mut height = 0;
- if sys::SteamAPI_ISteamUtils_GetImageSize(utils, img, &mut width, &mut height) == 0 {
+ if !sys::SteamAPI_ISteamUtils_GetImageSize(utils, img, &mut width, &mut height) {
return None;
}
assert_eq!(width, 32);
assert_eq!(height, 32);
let mut dest = vec![0; 32 * 32 * 4];
- if sys::SteamAPI_ISteamUtils_GetImageRGBA(utils, img, dest.as_mut_ptr(), 32 * 32 * 4) == 0 {
+ if !sys::SteamAPI_ISteamUtils_GetImageRGBA(utils, img, dest.as_mut_ptr(), 32 * 32 * 4) {
return None;
}
Some(dest)
@@ -255,20 +259,20 @@ impl <Manager> Friend<Manager> {
/// 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();
- let img = sys::SteamAPI_ISteamFriends_GetMediumFriendAvatar(self.friends, sys::CSteamID(self.id.0));
+ let utils = sys::SteamAPI_SteamUtils_v009();
+ let img = sys::SteamAPI_ISteamFriends_GetMediumFriendAvatar(self.friends, self.id.0);
if img == 0 {
return None;
}
let mut width = 0;
let mut height = 0;
- if sys::SteamAPI_ISteamUtils_GetImageSize(utils, img, &mut width, &mut height) == 0 {
+ if !sys::SteamAPI_ISteamUtils_GetImageSize(utils, img, &mut width, &mut height) {
return None;
}
assert_eq!(width, 64);
assert_eq!(height, 64);
let mut dest = vec![0; 64 * 64 * 4];
- if sys::SteamAPI_ISteamUtils_GetImageRGBA(utils, img, dest.as_mut_ptr(), 64 * 64 * 4) == 0 {
+ if !sys::SteamAPI_ISteamUtils_GetImageRGBA(utils, img, dest.as_mut_ptr(), 64 * 64 * 4) {
return None;
}
Some(dest)