aboutsummaryrefslogtreecommitdiff
path: root/src/matchmaking.rs
diff options
context:
space:
mode:
authorMatthew Collins <[email protected]>2018-05-07 01:02:44 +0100
committerMatthew Collins <[email protected]>2018-05-07 01:02:44 +0100
commit63f96e3eb579cd53b4a7bee84ef173add5f888e8 (patch)
tree8badd7acdc85a70f141f3750bbf047c586cffd44 /src/matchmaking.rs
parentFix building with older steam sdks (diff)
downloadsteamworks-rs-63f96e3eb579cd53b4a7bee84ef173add5f888e8.tar.xz
steamworks-rs-63f96e3eb579cd53b4a7bee84ef173add5f888e8.zip
Steam networking support + other improvements
Diffstat (limited to 'src/matchmaking.rs')
-rw-r--r--src/matchmaking.rs60
1 files changed, 58 insertions, 2 deletions
diff --git a/src/matchmaking.rs b/src/matchmaking.rs
index f219381..0f3c17b 100644
--- a/src/matchmaking.rs
+++ b/src/matchmaking.rs
@@ -17,8 +17,33 @@ pub enum LobbyType {
Invisible,
}
-#[derive(Debug)]
-pub struct LobbyId(pub u64);
+#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
+pub struct LobbyId(pub(crate) u64);
+
+impl LobbyId {
+ /// Creates a `LobbyId` from a raw 64 bit value.
+ ///
+ /// May be useful for deserializing lobby ids from
+ /// a network or save format.
+ pub fn from_raw(id: u64) -> LobbyId {
+ LobbyId(id)
+ }
+
+ /// Returns the raw 64 bit value of the lobby id
+ ///
+ /// May be useful for serializing lobby ids over a
+ /// network or to a save format.
+ pub fn raw(&self) -> u64 {
+ self.0
+ }
+
+ /// Returns whether this id is valid or not
+ pub fn is_valid(&self) -> bool {
+ unsafe {
+ sys::steam_rust_is_steam_id_valid(self.0) != 0
+ }
+ }
+}
impl <Manager> Matchmaking<Manager> {
@@ -105,6 +130,37 @@ impl <Manager> Matchmaking<Manager> {
sys::SteamAPI_ISteamMatchmaking_LeaveLobby(self.mm, lobby.0);
}
}
+
+ /// Returns the steam id of the current owner of the passed lobby
+ pub fn lobby_owner(&self, lobby: LobbyId) -> SteamId {
+ unsafe {
+ SteamId(sys::SteamAPI_ISteamMatchmaking_GetLobbyOwner(self.mm, lobby.0))
+ }
+ }
+
+ /// Returns the number of players in a lobby.
+ ///
+ /// Useful if you are not currently in the lobby
+ pub fn lobby_member_count(&self, lobby: LobbyId) -> usize {
+ unsafe {
+ let count = sys::SteamAPI_ISteamMatchmaking_GetNumLobbyMembers(self.mm, lobby.0);
+ count as usize
+ }
+ }
+
+ /// Returns a list of members currently in the lobby
+ pub fn lobby_members(&self, lobby: LobbyId) -> Vec<SteamId> {
+ unsafe {
+ let count = sys::SteamAPI_ISteamMatchmaking_GetNumLobbyMembers(self.mm, lobby.0);
+ let mut members = Vec::with_capacity(count as usize);
+ for idx in 0 .. count {
+ members.push(SteamId(
+ sys::SteamAPI_ISteamMatchmaking_GetLobbyMemberByIndex(self.mm, lobby.0, idx)
+ ))
+ }
+ members
+ }
+ }
}
#[test]