-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #195 from DavidHospital/feat/add-lobby-chat-messag…
…e-callback Adds LobbyChatMsg callback and get_lobby_chat_entry function
- Loading branch information
Showing
4 changed files
with
165 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[package] | ||
name = "lobby" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
steamworks = { path = "../../" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
use std::sync::mpsc; | ||
|
||
use steamworks::*; | ||
|
||
fn main() { | ||
let (client, single) = Client::init().unwrap(); | ||
|
||
let matchmaking = client.matchmaking(); | ||
|
||
let (sender_create_lobby, receiver_create_lobby) = mpsc::channel(); | ||
let (sender_lobby_chat_msg, receiver_lobby_chat_msg) = mpsc::channel(); | ||
|
||
matchmaking.create_lobby(LobbyType::Private, 4, move |result| match result { | ||
Ok(lobby_id) => { | ||
sender_create_lobby.send(lobby_id).unwrap(); | ||
println!("Created lobby: [{}]", lobby_id.raw()) | ||
} | ||
Err(err) => panic!("Error: {}", err), | ||
}); | ||
|
||
client.register_callback(move |message: LobbyChatMsg| { | ||
println!("Lobby chat message received: {:?}", message); | ||
sender_lobby_chat_msg.send(message).unwrap(); | ||
}); | ||
|
||
loop { | ||
single.run_callbacks(); | ||
|
||
if let Ok(lobby_id) = receiver_create_lobby.try_recv() { | ||
println!("Sending message to lobby chat..."); | ||
matchmaking | ||
.send_lobby_chat_message(lobby_id, &[0, 1, 2, 3, 4, 5]) | ||
.expect("Failed to send chat message to lobby"); | ||
} | ||
|
||
if let Ok(message) = receiver_lobby_chat_msg.try_recv() { | ||
let mut buffer = vec![0; 256]; | ||
let buffer = matchmaking.get_lobby_chat_entry( | ||
message.lobby, | ||
message.chat_id, | ||
buffer.as_mut_slice(), | ||
); | ||
println!("Message buffer: [{:?}]", buffer); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters