Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add lobby member data functions #221

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/matchmaking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,41 @@ impl<Manager> Matchmaking<Manager> {
unsafe { sys::SteamAPI_ISteamMatchmaking_DeleteLobbyData(self.mm, lobby.0, key.as_ptr()) }
}

/// Sets per-user metadata for the local user.
///
/// Triggers a LobbyDataUpdate callback.
pub fn set_lobby_member_data(&self, lobby: LobbyId, key: &str, value: &str) {
let key = CString::new(key).unwrap();
let value = CString::new(value).unwrap();
unsafe {
sys::SteamAPI_ISteamMatchmaking_SetLobbyMemberData(
self.mm,
lobby.0,
key.as_ptr(),
value.as_ptr(),
)
}
}

/// Gets per-user metadata from another player in the specified lobby.
///
/// This can only be queried from members in lobbies that you are currently in.
/// Returns None if lobby is invalid, user is not in the lobby, or key is not set.
pub fn get_lobby_member_data(&self, lobby: LobbyId, user: SteamId, key: &str) -> Option<&str> {
let key = CString::new(key).unwrap();
unsafe {
let data = sys::SteamAPI_ISteamMatchmaking_GetLobbyMemberData(
self.mm,
lobby.0,
user.0,
key.as_ptr(),
);
CStr::from_ptr(data)
}
.to_str()
.ok()
}

/// Exits the passed lobby
pub fn leave_lobby(&self, lobby: LobbyId) {
unsafe {
Expand Down