mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 06:16:04 +00:00
make the packets in events be Arc
so they're cheap to clone
This commit is contained in:
parent
8fd88aeae8
commit
661c3622be
2 changed files with 15 additions and 10 deletions
|
@ -9,13 +9,16 @@ use azalea_protocol::packets::game::{
|
|||
serverbound_chat_command_packet::ServerboundChatCommandPacket,
|
||||
serverbound_chat_packet::ServerboundChatPacket,
|
||||
};
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
use std::{
|
||||
sync::Arc,
|
||||
time::{SystemTime, UNIX_EPOCH},
|
||||
};
|
||||
|
||||
/// A chat packet, either a system message or a chat message.
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum ChatPacket {
|
||||
System(ClientboundSystemChatPacket),
|
||||
Player(Box<ClientboundPlayerChatPacket>),
|
||||
System(Arc<ClientboundSystemChatPacket>),
|
||||
Player(Arc<ClientboundPlayerChatPacket>),
|
||||
}
|
||||
|
||||
macro_rules! regex {
|
||||
|
|
|
@ -65,11 +65,11 @@ pub enum Event {
|
|||
Chat(ChatPacket),
|
||||
/// Happens 20 times per second, but only when the world is loaded.
|
||||
Tick,
|
||||
Packet(Box<ClientboundGamePacket>),
|
||||
Packet(Arc<ClientboundGamePacket>),
|
||||
/// Happens when a player is added, removed, or updated in the tab list.
|
||||
UpdatePlayers(UpdatePlayersEvent),
|
||||
/// Emits when the player dies.
|
||||
Death(Option<Box<ClientboundPlayerCombatKillPacket>>),
|
||||
Death(Option<Arc<ClientboundPlayerCombatKillPacket>>),
|
||||
}
|
||||
|
||||
/// Happens when a player is added, removed, or updated in the tab list.
|
||||
|
@ -421,8 +421,9 @@ impl Client {
|
|||
client: &Client,
|
||||
tx: &Sender<Event>,
|
||||
) -> Result<(), HandleError> {
|
||||
tx.send(Event::Packet(Box::new(packet.clone()))).await?;
|
||||
match packet {
|
||||
let packet = Arc::new(packet.clone());
|
||||
tx.send(Event::Packet(packet.clone())).await?;
|
||||
match &*packet {
|
||||
ClientboundGamePacket::Login(p) => {
|
||||
debug!("Got login packet");
|
||||
|
||||
|
@ -896,12 +897,13 @@ impl Client {
|
|||
}
|
||||
ClientboundGamePacket::PlayerChat(p) => {
|
||||
debug!("Got player chat packet {:?}", p);
|
||||
tx.send(Event::Chat(ChatPacket::Player(Box::new(p.clone()))))
|
||||
tx.send(Event::Chat(ChatPacket::Player(Arc::new(p.clone()))))
|
||||
.await?;
|
||||
}
|
||||
ClientboundGamePacket::SystemChat(p) => {
|
||||
debug!("Got system chat packet {:?}", p);
|
||||
tx.send(Event::Chat(ChatPacket::System(p.clone()))).await?;
|
||||
tx.send(Event::Chat(ChatPacket::System(Arc::new(p.clone()))))
|
||||
.await?;
|
||||
}
|
||||
ClientboundGamePacket::Sound(_p) => {
|
||||
// debug!("Got sound packet {:?}", p);
|
||||
|
@ -975,7 +977,7 @@ impl Client {
|
|||
// because of https://github.com/rust-lang/rust/issues/57478
|
||||
if !*client.dead.lock() {
|
||||
*client.dead.lock() = true;
|
||||
tx.send(Event::Death(Some(Box::new(p.clone())))).await?;
|
||||
tx.send(Event::Death(Some(Arc::new(p.clone())))).await?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue