Skip to content

Commit

Permalink
Merge pull request #138 from wyvernbw/master
Browse files Browse the repository at this point in the history
Implement wrapper for SendLobbyChatMsg
  • Loading branch information
Noxime committed Jul 22, 2023
2 parents 2ac57a0 + c1460d6 commit e9cdf88
Showing 1 changed file with 41 additions and 3 deletions.
44 changes: 41 additions & 3 deletions src/matchmaking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,7 @@ impl<Manager> Matchmaking<Manager> {
api_call,
CALLBACK_BASE_ID + 4,
move |v, io_error| {
cb(if io_error {
Err(())
} else if v.m_EChatRoomEnterResponse != 1 {
cb(if io_error || v.m_EChatRoomEnterResponse != 1 {
Err(())
} else {
Ok(LobbyId(v.m_ulSteamIDLobby))
Expand Down Expand Up @@ -271,6 +269,46 @@ impl<Manager> Matchmaking<Manager> {
pub fn set_lobby_joinable(&self, lobby: LobbyId, joinable: bool) -> bool {
unsafe { sys::SteamAPI_ISteamMatchmaking_SetLobbyJoinable(self.mm, lobby.0, joinable) }
}

/// Broadcasts a chat message (text or binary data) to all users in the lobby.
///
/// # Parameters
/// - `lobby`: The Steam ID of the lobby to send the chat message to.
/// - `msg`: This can be text or binary data, up to 4 Kilobytes in size.
///
/// # Description
/// All users in the lobby (including the local user) will receive a `LobbyChatMsg_t` callback
/// with the message.
///
/// If you're sending binary data, you should prefix a header to the message so that you know
/// to treat it as your custom data rather than a plain old text message.
///
/// For communication that needs to be arbitrated (e.g., having a user pick from a set of characters),
/// you can use the lobby owner as the decision maker. `GetLobbyOwner` returns the current lobby owner.
/// There is guaranteed to always be one and only one lobby member who is the owner.
/// So for the choose-a-character scenario, the user who is picking a character would send the binary
/// message 'I want to be Zoe', the lobby owner would see that message, see if it was OK, and broadcast
/// the appropriate result (user X is Zoe).
///
/// These messages are sent via the Steam back-end, and so the bandwidth available is limited.
/// For higher-volume traffic like voice or game data, you'll want to use the Steam Networking API.
///
/// # Returns
/// Returns `Ok(())` if the message was successfully sent. Returns an error of type `SteamError` if the
/// message is too small or too large, or if no connection to Steam could be made.
pub fn send_lobby_chat_message(&self, lobby: LobbyId, msg: &[u8]) -> Result<(), SteamError> {
match unsafe {
steamworks_sys::SteamAPI_ISteamMatchmaking_SendLobbyChatMsg(
self.mm,
lobby.0,
msg.as_ptr() as *const c_void,
msg.len() as i32,
)
} {
true => Ok(()),
false => Err(SteamError::IOFailure),
}
}
}

/// Flags describing how a users lobby state has changed. This is provided from `LobbyChatUpdate`.
Expand Down

0 comments on commit e9cdf88

Please sign in to comment.