mirror of
https://github.com/timvisee/lazymc.git
synced 2025-05-19 04:40:22 -07:00
Play sound effect in lobby when server is ready
This commit is contained in:
parent
8b88cb16c5
commit
f7d89a28aa
4
Cargo.lock
generated
4
Cargo.lock
generated
@ -684,7 +684,7 @@ checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a"
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "minecraft-protocol"
|
name = "minecraft-protocol"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/timvisee/rust-minecraft-protocol?branch=lazymc-v1_17_1#bef4fa8c009857e3753d85d8e2df1f71c3ae08f6"
|
source = "git+https://github.com/timvisee/rust-minecraft-protocol?branch=lazymc-v1_17_1#d26a525c7b29b61d2db64805181fb5471ea4317a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"byteorder",
|
"byteorder",
|
||||||
"minecraft-protocol-derive",
|
"minecraft-protocol-derive",
|
||||||
@ -697,7 +697,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "minecraft-protocol-derive"
|
name = "minecraft-protocol-derive"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
source = "git+https://github.com/timvisee/rust-minecraft-protocol?branch=lazymc-v1_17_1#bef4fa8c009857e3753d85d8e2df1f71c3ae08f6"
|
source = "git+https://github.com/timvisee/rust-minecraft-protocol?branch=lazymc-v1_17_1#d26a525c7b29b61d2db64805181fb5471ea4317a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
|
37
src/lobby.rs
37
src/lobby.rs
@ -11,8 +11,8 @@ use minecraft_protocol::encoder::Encoder;
|
|||||||
use minecraft_protocol::version::v1_14_4::handshake::Handshake;
|
use minecraft_protocol::version::v1_14_4::handshake::Handshake;
|
||||||
use minecraft_protocol::version::v1_14_4::login::{LoginStart, LoginSuccess};
|
use minecraft_protocol::version::v1_14_4::login::{LoginStart, LoginSuccess};
|
||||||
use minecraft_protocol::version::v1_17_1::game::{
|
use minecraft_protocol::version::v1_17_1::game::{
|
||||||
ClientBoundKeepAlive, JoinGame, PlayerPositionAndLook, PluginMessage, Respawn,
|
ClientBoundKeepAlive, JoinGame, NamedSoundEffect, PlayerPositionAndLook, PluginMessage,
|
||||||
SetTitleSubtitle, SetTitleText, SetTitleTimes, TimeUpdate,
|
Respawn, SetTitleSubtitle, SetTitleText, SetTitleTimes, TimeUpdate,
|
||||||
};
|
};
|
||||||
use nbt::CompoundTag;
|
use nbt::CompoundTag;
|
||||||
use tokio::io::{self, AsyncWriteExt};
|
use tokio::io::{self, AsyncWriteExt};
|
||||||
@ -32,6 +32,8 @@ use crate::server::{Server, State};
|
|||||||
pub const USE_LOBBY: bool = true;
|
pub const USE_LOBBY: bool = true;
|
||||||
pub const DONT_START_SERVER: bool = false;
|
pub const DONT_START_SERVER: bool = false;
|
||||||
const STARTING_BANNER: &str = "§2Server is starting\n§7⌛ Please wait...";
|
const STARTING_BANNER: &str = "§2Server is starting\n§7⌛ Please wait...";
|
||||||
|
const JOIN_SOUND: bool = true;
|
||||||
|
const JOIN_SOUND_NAME: &str = "block.note_block.chime";
|
||||||
|
|
||||||
/// Interval for server state polling when waiting on server to come online.
|
/// Interval for server state polling when waiting on server to come online.
|
||||||
const SERVER_POLL_INTERVAL: Duration = Duration::from_millis(500);
|
const SERVER_POLL_INTERVAL: Duration = Duration::from_millis(500);
|
||||||
@ -123,13 +125,18 @@ pub async fn serve(
|
|||||||
// Grab join game packet from server
|
// Grab join game packet from server
|
||||||
let join_game = wait_for_server_join_game(&mut outbound, &mut server_buf).await?;
|
let join_game = wait_for_server_join_game(&mut outbound, &mut server_buf).await?;
|
||||||
|
|
||||||
|
// Reset lobby title, play sound effect
|
||||||
|
send_lobby_title(&mut writer, "").await?;
|
||||||
|
if JOIN_SOUND {
|
||||||
|
send_lobby_sound_effect(&mut writer).await?;
|
||||||
|
}
|
||||||
|
|
||||||
// Wait a second because Notchian servers are slow
|
// Wait a second because Notchian servers are slow
|
||||||
// See: https://wiki.vg/Protocol#Login_Success
|
// See: https://wiki.vg/Protocol#Login_Success
|
||||||
trace!(target: "lazymc::lobby", "Waiting a second before relaying client connection...");
|
trace!(target: "lazymc::lobby", "Waiting a second before relaying client connection...");
|
||||||
time::sleep(SERVER_WARMUP).await;
|
time::sleep(SERVER_WARMUP).await;
|
||||||
|
|
||||||
// Reset our lobby title, send respawn packet to teleport to real server world
|
// Send respawn packet, initiates teleport to real server world
|
||||||
send_lobby_title(&mut writer, "").await?;
|
|
||||||
send_respawn_from_join(&mut writer, join_game).await?;
|
send_respawn_from_join(&mut writer, join_game).await?;
|
||||||
|
|
||||||
// Drain inbound connection so we don't confuse the server
|
// Drain inbound connection so we don't confuse the server
|
||||||
@ -387,6 +394,28 @@ async fn send_lobby_title(writer: &mut WriteHalf<'_>, text: &str) -> Result<(),
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Send lobby ready sound effect to client.
|
||||||
|
async fn send_lobby_sound_effect(writer: &mut WriteHalf<'_>) -> Result<(), ()> {
|
||||||
|
let packet = NamedSoundEffect {
|
||||||
|
sound_name: JOIN_SOUND_NAME.into(),
|
||||||
|
sound_category: 0,
|
||||||
|
effect_pos_x: 0,
|
||||||
|
effect_pos_y: 0,
|
||||||
|
effect_pos_z: 0,
|
||||||
|
volume: 1.0,
|
||||||
|
pitch: 1.0,
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut data = Vec::new();
|
||||||
|
packet.encode(&mut data).map_err(|_| ())?;
|
||||||
|
|
||||||
|
let response =
|
||||||
|
RawPacket::new(proto::packets::play::CLIENT_NAMED_SOUND_EFFECT, data).encode()?;
|
||||||
|
writer.write_all(&response).await.map_err(|_| ())?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
/// Send respawn packet to client to jump from lobby into now loaded server.
|
/// Send respawn packet to client to jump from lobby into now loaded server.
|
||||||
///
|
///
|
||||||
/// The required details will be fetched from the `join_game` packet as provided by the server.
|
/// The required details will be fetched from the `join_game` packet as provided by the server.
|
||||||
|
@ -46,6 +46,7 @@ pub mod packets {
|
|||||||
pub mod play {
|
pub mod play {
|
||||||
pub const CLIENT_CHAT_MSG: i32 = 0x0F;
|
pub const CLIENT_CHAT_MSG: i32 = 0x0F;
|
||||||
pub const CLIENT_PLUGIN_MESSAGE: i32 = 0x18;
|
pub const CLIENT_PLUGIN_MESSAGE: i32 = 0x18;
|
||||||
|
pub const CLIENT_NAMED_SOUND_EFFECT: i32 = 0x19;
|
||||||
pub const CLIENT_DISCONNECT: i32 = 0x1A;
|
pub const CLIENT_DISCONNECT: i32 = 0x1A;
|
||||||
pub const CLIENT_KEEP_ALIVE: i32 = 0x21;
|
pub const CLIENT_KEEP_ALIVE: i32 = 0x21;
|
||||||
pub const CLIENT_JOIN_GAME: i32 = 0x26;
|
pub const CLIENT_JOIN_GAME: i32 = 0x26;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user