diff --git a/pumpkin-protocol/src/client/play/player_chat_message.rs b/pumpkin-protocol/src/client/play/player_chat_message.rs index f39422ca9..0215ae4b0 100644 --- a/pumpkin-protocol/src/client/play/player_chat_message.rs +++ b/pumpkin-protocol/src/client/play/player_chat_message.rs @@ -9,6 +9,7 @@ use crate::{VarInt, codec::bit_set::BitSet}; #[derive(Serialize)] #[packet(PLAY_PLAYER_CHAT)] pub struct CPlayerChatMessage { + global_index: VarInt, #[serde(with = "uuid::serde::compact")] sender: uuid::Uuid, index: VarInt, @@ -29,6 +30,7 @@ pub struct CPlayerChatMessage { impl CPlayerChatMessage { #[expect(clippy::too_many_arguments)] pub fn new( + global_index: VarInt, sender: uuid::Uuid, index: VarInt, message_signature: Option>, @@ -43,13 +45,14 @@ impl CPlayerChatMessage { target_name: Option, ) -> Self { Self { + global_index, sender, index, message_signature, message, timestamp, salt, - previous_messages_count: previous_messages.len().into(), + previous_messages_count: VarInt(previous_messages.len() as i32), previous_messages, unsigned_content, filter_type, diff --git a/pumpkin/src/entity/player.rs b/pumpkin/src/entity/player.rs index 3cb9a894d..f7ab8e534 100644 --- a/pumpkin/src/entity/player.rs +++ b/pumpkin/src/entity/player.rs @@ -233,6 +233,7 @@ pub struct Player { pub experience_pick_up_delay: Mutex, pub chunk_manager: Mutex, pub has_played_before: AtomicBool, + pub global_chat_message_index: AtomicU32, } impl Player { @@ -316,6 +317,7 @@ impl Player { last_sent_food: AtomicU32::new(0), last_food_saturation: AtomicBool::new(true), has_played_before: AtomicBool::new(false), + global_chat_message_index: AtomicU32::new(0), } } diff --git a/pumpkin/src/net/packet/play.rs b/pumpkin/src/net/packet/play.rs index 46fd97747..f89e24a35 100644 --- a/pumpkin/src/net/packet/play.rs +++ b/pumpkin/src/net/packet/play.rs @@ -680,6 +680,9 @@ impl Player { } let gameprofile = &self.gameprofile; + let global_index = self + .global_chat_message_index + .fetch_add(1, std::sync::atomic::Ordering::Relaxed); send_cancellable! {{ PlayerChatEvent::new(self.clone(), message.clone(), vec![]); @@ -691,6 +694,7 @@ impl Player { let world = &entity.world.read().await; world .broadcast_packet_all(&CPlayerChatMessage::new( + VarInt(global_index as i32), gameprofile.id, 1.into(), chat_message.signature, @@ -709,6 +713,7 @@ impl Player { } else { let packet = CPlayerChatMessage::new( + VarInt(global_index as i32), gameprofile.id, 1.into(), chat_message.signature,