Skip to content

Commit 797dd91

Browse files
committed
revert packet name to Disguised and make it more like ChatPacket::Player
1 parent 888c276 commit 797dd91

File tree

5 files changed

+64
-37
lines changed

5 files changed

+64
-37
lines changed

azalea-client/src/chat.rs

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use azalea_chat::FormattedText;
44
use azalea_protocol::packets::game::{
5-
clientbound_disguised_chat_packet::ClientboundMaskedChatPacket,
5+
clientbound_disguised_chat_packet::ClientboundDisguisedChatPacket,
66
clientbound_player_chat_packet::ClientboundPlayerChatPacket,
77
clientbound_system_chat_packet::ClientboundSystemChatPacket,
88
serverbound_chat_command_packet::ServerboundChatCommandPacket,
@@ -31,7 +31,7 @@ use crate::{
3131
pub enum ChatPacket {
3232
System(Arc<ClientboundSystemChatPacket>),
3333
Player(Arc<ClientboundPlayerChatPacket>),
34-
Masked(Arc<ClientboundMaskedChatPacket>),
34+
Disguised(Arc<ClientboundDisguisedChatPacket>),
3535
}
3636

3737
macro_rules! regex {
@@ -47,7 +47,7 @@ impl ChatPacket {
4747
match self {
4848
ChatPacket::System(p) => p.content.clone(),
4949
ChatPacket::Player(p) => p.message(),
50-
ChatPacket::Masked(p) => p.message.clone(),
50+
ChatPacket::Disguised(p) => p.message(),
5151
}
5252
}
5353

@@ -57,12 +57,6 @@ impl ChatPacket {
5757
/// None.
5858
pub fn split_sender_and_content(&self) -> (Option<String>, String) {
5959
match self {
60-
ChatPacket::Player(p) => (
61-
// If it's a player chat packet, then the sender and content
62-
// are already split for us.
63-
Some(p.chat_type.name.to_string()),
64-
p.body.content.clone(),
65-
),
6660
ChatPacket::System(p) => {
6761
let message = p.content.to_string();
6862
// Overlay messages aren't in chat
@@ -77,16 +71,18 @@ impl ChatPacket {
7771

7872
(None, message)
7973
}
80-
ChatPacket::Masked(p) => {
81-
let message = p.message.to_string();
82-
// It's a system message, so we'll have to match the content
83-
// with regex
84-
if let Some(m) = regex!("^<([a-zA-Z_0-9]{1,16})> (.+)$").captures(&message) {
85-
return (Some(m[1].to_string()), m[2].to_string());
86-
}
87-
88-
(None, message)
89-
}
74+
ChatPacket::Player(p) => (
75+
// If it's a player chat packet, then the sender and content
76+
// are already split for us.
77+
Some(p.chat_type.name.to_string()),
78+
p.body.content.clone(),
79+
),
80+
ChatPacket::Disguised(p) => (
81+
// disguised chat packets are basically the same as player chat packets but without
82+
// the chat signing things
83+
Some(p.chat_type.name.to_string()),
84+
p.message.to_string(),
85+
),
9086
}
9187
}
9288

@@ -104,7 +100,7 @@ impl ChatPacket {
104100
match self {
105101
ChatPacket::System(_) => None,
106102
ChatPacket::Player(m) => Some(m.sender),
107-
ChatPacket::Masked(_) => None,
103+
ChatPacket::Disguised(_) => None,
108104
}
109105
}
110106

azalea-client/src/packet_handling/game.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -997,6 +997,18 @@ pub fn process_packet_events(ecs: &mut World) {
997997
packet: ChatPacket::System(Arc::new(p.clone())),
998998
});
999999
}
1000+
ClientboundGamePacket::DisguisedChat(p) => {
1001+
debug!("Got disguised chat packet {p:?}");
1002+
1003+
let mut system_state: SystemState<EventWriter<ChatReceivedEvent>> =
1004+
SystemState::new(ecs);
1005+
let mut chat_events = system_state.get_mut(ecs);
1006+
1007+
chat_events.send(ChatReceivedEvent {
1008+
entity: player_entity,
1009+
packet: ChatPacket::Disguised(Arc::new(p.clone())),
1010+
});
1011+
}
10001012
ClientboundGamePacket::Sound(_p) => {
10011013
// debug!("Got sound packet {p:?}");
10021014
}
@@ -1382,18 +1394,6 @@ pub fn process_packet_events(ecs: &mut World) {
13821394
ClientboundGamePacket::TabList(_) => {}
13831395
ClientboundGamePacket::TagQuery(_) => {}
13841396
ClientboundGamePacket::TakeItemEntity(_) => {}
1385-
ClientboundGamePacket::MaskedChat(p) => {
1386-
debug!("Got masked chat packet {p:?}");
1387-
1388-
let mut system_state: SystemState<EventWriter<ChatReceivedEvent>> =
1389-
SystemState::new(ecs);
1390-
let mut chat_events = system_state.get_mut(ecs);
1391-
1392-
chat_events.send(ChatReceivedEvent {
1393-
entity: player_entity,
1394-
packet: ChatPacket::Masked(Arc::new(p.clone())),
1395-
});
1396-
}
13971397
ClientboundGamePacket::Bundle(_) => {}
13981398
ClientboundGamePacket::DamageEvent(_) => {}
13991399
ClientboundGamePacket::HurtAnimation(_) => {}
Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,41 @@
11
use super::clientbound_player_chat_packet::ChatTypeBound;
22
use azalea_buf::McBuf;
3-
use azalea_chat::FormattedText;
3+
use azalea_chat::{
4+
translatable_component::{StringOrComponent, TranslatableComponent},
5+
FormattedText,
6+
};
47
use azalea_protocol_macros::ClientboundGamePacket;
58

9+
// A disguised chat packet is basically the same as a normal
10+
// [`ClientboundPlayerChatPacket`], except that it doesn't have any of the chat
11+
// signing things. Vanilla servers use this when messages are sent from the
12+
// console.
613
#[derive(Clone, Debug, McBuf, ClientboundGamePacket, PartialEq)]
7-
pub struct ClientboundMaskedChatPacket {
14+
pub struct ClientboundDisguisedChatPacket {
815
pub message: FormattedText,
916
pub chat_type: ChatTypeBound,
1017
}
18+
19+
impl ClientboundDisguisedChatPacket {
20+
/// Get the full message, including the sender part.
21+
#[must_use]
22+
pub fn message(&self) -> FormattedText {
23+
let sender = self.chat_type.name.clone();
24+
let content = self.message.clone();
25+
let target = self.chat_type.target_name.clone();
26+
27+
let translation_key = self.chat_type.chat_type.chat_translation_key();
28+
29+
let mut args = vec![
30+
StringOrComponent::FormattedText(sender),
31+
StringOrComponent::FormattedText(content),
32+
];
33+
if let Some(target) = target {
34+
args.push(StringOrComponent::FormattedText(target));
35+
}
36+
37+
let component = TranslatableComponent::new(translation_key.to_string(), args);
38+
39+
FormattedText::Translatable(component)
40+
}
41+
}

azalea-protocol/src/packets/game/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ declare_state_packets!(
255255
0x19: clientbound_damage_event_packet::ClientboundDamageEventPacket,
256256
0x1a: clientbound_delete_chat_packet::ClientboundDeleteChatPacket,
257257
0x1b: clientbound_disconnect_packet::ClientboundDisconnectPacket,
258-
0x1c: clientbound_disguised_chat_packet::ClientboundMaskedChatPacket,
258+
0x1c: clientbound_disguised_chat_packet::ClientboundDisguisedChatPacket,
259259
0x1d: clientbound_entity_event_packet::ClientboundEntityEventPacket,
260260
0x1e: clientbound_explode_packet::ClientboundExplodePacket,
261261
0x1f: clientbound_forget_level_chunk_packet::ClientboundForgetLevelChunkPacket,

azalea-world/src/chunk_storage.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,8 @@ impl PartialChunkStorage {
211211
}
212212

213213
/// Set a chunk in the shared storage and reference it from the limited
214-
/// storage. Use [`Self::set_with_shared_reference`] if you already have
215-
/// an `Arc<RwLock<Chunk>>`.
214+
/// storage. Use [`Self::limited_set`] if you already have an
215+
/// `Arc<RwLock<Chunk>>`.
216216
///
217217
/// # Panics
218218
/// If the chunk is not in the render distance.

0 commit comments

Comments
 (0)