-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
85 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use ferrumc_core::identity::player_identity::PlayerIdentity; | ||
use ferrumc_macros::event_handler; | ||
use ferrumc_net::{ | ||
packets::{ | ||
incoming::chat_message::ChatMessageEvent, outgoing::system_message::SystemMessagePacket, | ||
}, | ||
utils::broadcast::{BroadcastOptions, BroadcastToAll}, | ||
NetResult, | ||
}; | ||
use ferrumc_state::GlobalState; | ||
use ferrumc_text::TextComponentBuilder; | ||
|
||
#[event_handler] | ||
async fn chat_message(event: ChatMessageEvent, state: GlobalState) -> NetResult<ChatMessageEvent> { | ||
let identity = state.universe.get::<PlayerIdentity>(event.player_conn_id)?; | ||
let message = | ||
TextComponentBuilder::new(format!("<{}> {}", identity.username, event.message)).build(); | ||
let packet = SystemMessagePacket::new(message, false); | ||
state | ||
.broadcast(&packet, BroadcastOptions::default().all()) | ||
.await?; | ||
|
||
Ok(event) | ||
} |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
mod chat_message; | ||
mod commands; | ||
mod handshake; | ||
mod login_process; | ||
|
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,41 @@ | ||
use std::sync::Arc; | ||
|
||
use ferrumc_events::infrastructure::Event; | ||
use ferrumc_macros::{packet, Event, NetDecode}; | ||
use ferrumc_net_codec::net_types::var_int::VarInt; | ||
use ferrumc_state::ServerState; | ||
|
||
use crate::packets::IncomingPacket; | ||
|
||
#[derive(NetDecode, Debug, Clone)] | ||
#[packet(packet_id = 0x06, state = "play")] | ||
pub struct ChatMessagePacket { | ||
pub message: String, | ||
pub timestamp: u64, | ||
pub salt: u64, | ||
pub has_signature: bool, | ||
pub signature: Option<Vec<u64>>, | ||
pub message_count: VarInt, | ||
pub acknowledged: Vec<u8>, | ||
} | ||
|
||
impl IncomingPacket for ChatMessagePacket { | ||
async fn handle(self, conn_id: usize, state: Arc<ServerState>) -> crate::NetResult<()> { | ||
ChatMessageEvent::trigger(ChatMessageEvent::new(conn_id, self.message), state).await | ||
} | ||
} | ||
|
||
#[derive(Debug, Event, Clone)] | ||
pub struct ChatMessageEvent { | ||
pub player_conn_id: usize, | ||
pub message: String, | ||
} | ||
|
||
impl ChatMessageEvent { | ||
pub fn new(player_conn_id: usize, message: String) -> Self { | ||
Self { | ||
player_conn_id, | ||
message, | ||
} | ||
} | ||
} |
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