Skip to content

Commit

Permalink
Merge pull request #226 from djsell/lobby-member-data
Browse files Browse the repository at this point in the history
add lobby member data functions
  • Loading branch information
Noxime authored Feb 26, 2025
2 parents f227284 + 7bde82b commit a0b0f97
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/matchmaking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,47 @@ 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<String> {
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()
.map(str::to_owned)
.ok()
}

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

0 comments on commit a0b0f97

Please sign in to comment.