Add Clientbound Player Chat Message
This commit is contained in:
parent
0e831dbe00
commit
d0a8790d7b
70
pumpkin-protocol/src/client/play/c_player_chat_message.rs
Normal file
70
pumpkin-protocol/src/client/play/c_player_chat_message.rs
Normal file
@ -0,0 +1,70 @@
|
||||
use num_derive::FromPrimitive;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::{text::TextComponent, VarInt};
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct PlayerChatMessage<'a> {
|
||||
sender: uuid::Uuid,
|
||||
index: VarInt,
|
||||
message_signature: Option<&'a [u8]>,
|
||||
message: String,
|
||||
timestamp: i64,
|
||||
salt: i64,
|
||||
previous_messages: &'a [PreviousMessage<'a>], // max 20
|
||||
unsigned_content: Option<TextComponent>,
|
||||
/// See `FilterType`
|
||||
filter_type: VarInt,
|
||||
chat_type: VarInt,
|
||||
sender_name: TextComponent,
|
||||
target_name: Option<TextComponent>,
|
||||
}
|
||||
|
||||
impl<'a> PlayerChatMessage<'a> {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn new(
|
||||
sender: uuid::Uuid,
|
||||
index: VarInt,
|
||||
message_signature: Option<&'a [u8]>,
|
||||
message: String,
|
||||
timestamp: i64,
|
||||
salt: i64,
|
||||
previous_messages: &'a [PreviousMessage<'a>],
|
||||
unsigned_content: Option<TextComponent>,
|
||||
filter_type: VarInt,
|
||||
chat_type: VarInt,
|
||||
sender_name: TextComponent,
|
||||
target_name: Option<TextComponent>,
|
||||
) -> Self {
|
||||
Self {
|
||||
sender,
|
||||
index,
|
||||
message_signature,
|
||||
message,
|
||||
timestamp,
|
||||
salt,
|
||||
previous_messages,
|
||||
unsigned_content,
|
||||
filter_type,
|
||||
chat_type,
|
||||
sender_name,
|
||||
target_name,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct PreviousMessage<'a> {
|
||||
message_id: VarInt,
|
||||
signature: Option<&'a [u8]>,
|
||||
}
|
||||
|
||||
#[derive(FromPrimitive)]
|
||||
pub enum FilterType {
|
||||
/// Message is not filtered at all
|
||||
PassThrough,
|
||||
/// Message is fully filtered
|
||||
FullyFiltered,
|
||||
/// Only some characters in the message are filtered
|
||||
PartiallyFiltered,
|
||||
}
|
||||
@ -5,6 +5,7 @@ mod c_head_rot;
|
||||
mod c_login;
|
||||
mod c_play_disconnect;
|
||||
mod c_player_abilities;
|
||||
mod c_player_chat_message;
|
||||
mod c_player_info_update;
|
||||
mod c_set_held_item;
|
||||
mod c_spawn_player;
|
||||
@ -22,6 +23,7 @@ pub use c_head_rot::*;
|
||||
pub use c_login::*;
|
||||
pub use c_play_disconnect::*;
|
||||
pub use c_player_abilities::*;
|
||||
pub use c_player_chat_message::*;
|
||||
pub use c_player_info_update::*;
|
||||
pub use c_set_held_item::*;
|
||||
pub use c_spawn_player::*;
|
||||
|
||||
@ -6,11 +6,7 @@ use client::Client;
|
||||
use commands::handle_command;
|
||||
use configuration::AdvancedConfiguration;
|
||||
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
rc::Rc,
|
||||
thread,
|
||||
};
|
||||
use std::{collections::HashMap, rc::Rc, thread};
|
||||
|
||||
use client::interrupted;
|
||||
use configuration::BasicConfiguration;
|
||||
@ -64,10 +60,7 @@ fn main() -> io::Result<()> {
|
||||
|
||||
let mut connections: HashMap<Token, Rc<RefCell<Client>>> = HashMap::new();
|
||||
|
||||
let mut server = Server::new((
|
||||
basic_config,
|
||||
advanced_configuration,
|
||||
));
|
||||
let mut server = Server::new((basic_config, advanced_configuration));
|
||||
log::info!("Started Server took {}ms", time.elapsed().as_millis());
|
||||
log::info!("You now can connect to the server");
|
||||
|
||||
@ -112,8 +105,8 @@ fn main() -> io::Result<()> {
|
||||
}
|
||||
};
|
||||
if let Err(e) = connection.set_nodelay(true) {
|
||||
log::warn!("failed to set TCP_NODELAY {e}");
|
||||
}
|
||||
log::warn!("failed to set TCP_NODELAY {e}");
|
||||
}
|
||||
|
||||
log::info!("Accepted connection from: {}", address);
|
||||
|
||||
@ -129,8 +122,7 @@ fn main() -> io::Result<()> {
|
||||
connection,
|
||||
addr,
|
||||
)));
|
||||
server
|
||||
.add_client(rc_token, Rc::clone(&client));
|
||||
server.add_client(rc_token, Rc::clone(&client));
|
||||
connections.insert(token, client);
|
||||
},
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user