Prepare ChatType registry
This commit is contained in:
parent
41442c5b5d
commit
5b636111e4
@ -5,7 +5,7 @@ use crate::{bytebuf::ByteBuffer, ClientPacket, Property};
|
|||||||
#[packet(0x02)]
|
#[packet(0x02)]
|
||||||
pub struct CLoginSuccess<'a> {
|
pub struct CLoginSuccess<'a> {
|
||||||
pub uuid: uuid::Uuid,
|
pub uuid: uuid::Uuid,
|
||||||
pub username: String, // 16
|
pub username: &'a str, // 16
|
||||||
pub properties: &'a [Property],
|
pub properties: &'a [Property],
|
||||||
pub strict_error_handling: bool,
|
pub strict_error_handling: bool,
|
||||||
}
|
}
|
||||||
@ -13,7 +13,7 @@ pub struct CLoginSuccess<'a> {
|
|||||||
impl<'a> CLoginSuccess<'a> {
|
impl<'a> CLoginSuccess<'a> {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
uuid: uuid::Uuid,
|
uuid: uuid::Uuid,
|
||||||
username: String,
|
username: &'a str,
|
||||||
properties: &'a [Property],
|
properties: &'a [Property],
|
||||||
strict_error_handling: bool,
|
strict_error_handling: bool,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
|
|||||||
@ -5,11 +5,11 @@ use crate::VarInt;
|
|||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
#[packet(0x2B)]
|
#[packet(0x2B)]
|
||||||
pub struct CLogin {
|
pub struct CLogin<'a> {
|
||||||
entity_id: i32,
|
entity_id: i32,
|
||||||
is_hardcore: bool,
|
is_hardcore: bool,
|
||||||
dimension_count: VarInt,
|
dimension_count: VarInt,
|
||||||
dimension_names: Vec<String>,
|
dimension_names: &'a [&'a str],
|
||||||
max_players: VarInt,
|
max_players: VarInt,
|
||||||
view_distance: VarInt,
|
view_distance: VarInt,
|
||||||
simulated_distance: VarInt,
|
simulated_distance: VarInt,
|
||||||
@ -17,7 +17,7 @@ pub struct CLogin {
|
|||||||
enabled_respawn_screen: bool,
|
enabled_respawn_screen: bool,
|
||||||
limited_crafting: bool,
|
limited_crafting: bool,
|
||||||
dimension_type: VarInt,
|
dimension_type: VarInt,
|
||||||
dimension_name: String,
|
dimension_name: &'a str,
|
||||||
hashed_seed: i64,
|
hashed_seed: i64,
|
||||||
game_mode: u8,
|
game_mode: u8,
|
||||||
previous_gamemode: i8,
|
previous_gamemode: i8,
|
||||||
@ -28,12 +28,12 @@ pub struct CLogin {
|
|||||||
enforce_secure_chat: bool,
|
enforce_secure_chat: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CLogin {
|
impl<'a> CLogin<'a> {
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub fn new(
|
pub fn new(
|
||||||
entity_id: i32,
|
entity_id: i32,
|
||||||
is_hardcore: bool,
|
is_hardcore: bool,
|
||||||
dimension_names: Vec<String>,
|
dimension_names: &'a [&'a str],
|
||||||
max_players: VarInt,
|
max_players: VarInt,
|
||||||
view_distance: VarInt,
|
view_distance: VarInt,
|
||||||
simulated_distance: VarInt,
|
simulated_distance: VarInt,
|
||||||
@ -41,7 +41,7 @@ impl CLogin {
|
|||||||
enabled_respawn_screen: bool,
|
enabled_respawn_screen: bool,
|
||||||
limited_crafting: bool,
|
limited_crafting: bool,
|
||||||
dimension_type: VarInt,
|
dimension_type: VarInt,
|
||||||
dimension_name: String,
|
dimension_name: &'a str,
|
||||||
hashed_seed: i64,
|
hashed_seed: i64,
|
||||||
game_mode: u8,
|
game_mode: u8,
|
||||||
previous_gamemode: i8,
|
previous_gamemode: i8,
|
||||||
|
|||||||
@ -3,7 +3,7 @@ use pumpkin_macros::packet;
|
|||||||
use pumpkin_text::TextComponent;
|
use pumpkin_text::TextComponent;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
use crate::VarInt;
|
use crate::{BitSet, VarInt};
|
||||||
|
|
||||||
#[derive(Serialize, Clone)]
|
#[derive(Serialize, Clone)]
|
||||||
#[packet(0x39)]
|
#[packet(0x39)]
|
||||||
@ -14,10 +14,13 @@ pub struct CPlayerChatMessage<'a> {
|
|||||||
message: String,
|
message: String,
|
||||||
timestamp: i64,
|
timestamp: i64,
|
||||||
salt: i64,
|
salt: i64,
|
||||||
|
previous_messages_count: VarInt,
|
||||||
previous_messages: &'a [PreviousMessage<'a>], // max 20
|
previous_messages: &'a [PreviousMessage<'a>], // max 20
|
||||||
unsigned_content: Option<TextComponent>,
|
unsigned_content: Option<TextComponent>,
|
||||||
/// See `FilterType`
|
/// See `FilterType`
|
||||||
filter_type: VarInt,
|
filter_type: VarInt,
|
||||||
|
// TODO: THIS IS A HACK, We currently don't support writing or reading bitsets
|
||||||
|
filter_type_bits: bool,
|
||||||
chat_type: VarInt,
|
chat_type: VarInt,
|
||||||
sender_name: TextComponent,
|
sender_name: TextComponent,
|
||||||
target_name: Option<TextComponent>,
|
target_name: Option<TextComponent>,
|
||||||
@ -46,9 +49,11 @@ impl<'a> CPlayerChatMessage<'a> {
|
|||||||
message,
|
message,
|
||||||
timestamp,
|
timestamp,
|
||||||
salt,
|
salt,
|
||||||
|
previous_messages_count: previous_messages.len().into(),
|
||||||
previous_messages,
|
previous_messages,
|
||||||
unsigned_content,
|
unsigned_content,
|
||||||
filter_type,
|
filter_type,
|
||||||
|
filter_type_bits: false,
|
||||||
chat_type,
|
chat_type,
|
||||||
sender_name,
|
sender_name,
|
||||||
target_name,
|
target_name,
|
||||||
|
|||||||
@ -5,13 +5,13 @@ use crate::VarInt;
|
|||||||
|
|
||||||
#[derive(Serialize, Clone)]
|
#[derive(Serialize, Clone)]
|
||||||
#[packet(0x42)]
|
#[packet(0x42)]
|
||||||
pub struct CRemoveEntities {
|
pub struct CRemoveEntities<'a> {
|
||||||
count: VarInt,
|
count: VarInt,
|
||||||
entitiy_ids: Vec<VarInt>,
|
entitiy_ids: &'a [VarInt],
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CRemoveEntities {
|
impl<'a> CRemoveEntities<'a> {
|
||||||
pub fn new(entitiy_ids: Vec<VarInt>) -> Self {
|
pub fn new(entitiy_ids: &'a [VarInt]) -> Self {
|
||||||
Self {
|
Self {
|
||||||
count: VarInt(entitiy_ids.len() as i32),
|
count: VarInt(entitiy_ids.len() as i32),
|
||||||
entitiy_ids,
|
entitiy_ids,
|
||||||
|
|||||||
@ -2,7 +2,7 @@ use std::io::{self, Write};
|
|||||||
|
|
||||||
use bytebuf::{packet_id::Packet, ByteBuffer, DeserializerError};
|
use bytebuf::{packet_id::Packet, ByteBuffer, DeserializerError};
|
||||||
use bytes::Buf;
|
use bytes::Buf;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize, Serializer};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
pub mod bytebuf;
|
pub mod bytebuf;
|
||||||
|
|||||||
@ -1,7 +1,33 @@
|
|||||||
pub struct ChatType {}
|
use serde::Serialize;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize)]
|
||||||
|
pub struct ChatType {
|
||||||
|
chat: Decoration,
|
||||||
|
narration: Decoration,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize)]
|
||||||
pub struct Decoration {
|
pub struct Decoration {
|
||||||
translation_key: String,
|
translation_key: String,
|
||||||
// style: Option,
|
style: u8,
|
||||||
|
// TODO
|
||||||
|
// style: Option<Styles>,
|
||||||
parameters: Vec<String>,
|
parameters: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for ChatType {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
chat: Decoration {
|
||||||
|
style: 0,
|
||||||
|
parameters: vec!["sender".into(), "content".into()],
|
||||||
|
translation_key: "chat.type.text".into(),
|
||||||
|
},
|
||||||
|
narration: Decoration {
|
||||||
|
style: 0,
|
||||||
|
parameters: vec!["sender".into(), "content".into()],
|
||||||
|
translation_key: "chat.type.text.narrate".into(),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
use biomes::Biome;
|
use biomes::Biome;
|
||||||
|
use chat_type::ChatType;
|
||||||
use dimensions::Dimension;
|
use dimensions::Dimension;
|
||||||
use fastnbt::SerOpts;
|
use fastnbt::SerOpts;
|
||||||
use paint::Painting;
|
use paint::Painting;
|
||||||
@ -50,6 +51,16 @@ impl Registry {
|
|||||||
.unwrap(),
|
.unwrap(),
|
||||||
}],
|
}],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let _chat_types = Registry {
|
||||||
|
registry_id: "minecraft:chat_type".to_string(),
|
||||||
|
registry_entries: vec![RegistryEntry {
|
||||||
|
entry_id: "minecraft:chat",
|
||||||
|
data: fastnbt::to_bytes_with_opts(&ChatType::default(), SerOpts::network_nbt())
|
||||||
|
.unwrap(),
|
||||||
|
}],
|
||||||
|
};
|
||||||
|
|
||||||
let damage_types = Registry {
|
let damage_types = Registry {
|
||||||
registry_id: "minecraft:damage_type".to_string(),
|
registry_id: "minecraft:damage_type".to_string(),
|
||||||
registry_entries: damage_type::entires(),
|
registry_entries: damage_type::entires(),
|
||||||
@ -62,6 +73,13 @@ impl Registry {
|
|||||||
.unwrap(),
|
.unwrap(),
|
||||||
}],
|
}],
|
||||||
};
|
};
|
||||||
vec![dimensions, damage_types, biomes, wolf_variants, paintings]
|
vec![
|
||||||
|
dimensions,
|
||||||
|
damage_types,
|
||||||
|
biomes,
|
||||||
|
wolf_variants,
|
||||||
|
paintings,
|
||||||
|
// chat_types,
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,7 +15,6 @@ use pumpkin_protocol::{
|
|||||||
},
|
},
|
||||||
ConnectionState, KnownPack, RawBytes,
|
ConnectionState, KnownPack, RawBytes,
|
||||||
};
|
};
|
||||||
use pumpkin_registry::Registry;
|
|
||||||
use pumpkin_text::TextComponent;
|
use pumpkin_text::TextComponent;
|
||||||
use rsa::Pkcs1v15Encrypt;
|
use rsa::Pkcs1v15Encrypt;
|
||||||
use sha1::{Digest, Sha1};
|
use sha1::{Digest, Sha1};
|
||||||
@ -150,7 +149,7 @@ impl Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if let Some(profile) = self.gameprofile.as_ref().cloned() {
|
if let Some(profile) = self.gameprofile.as_ref().cloned() {
|
||||||
let packet = CLoginSuccess::new(profile.id, profile.name, &profile.properties, false);
|
let packet = CLoginSuccess::new(profile.id, &profile.name, &profile.properties, false);
|
||||||
self.send_packet(packet);
|
self.send_packet(packet);
|
||||||
} else {
|
} else {
|
||||||
self.kick("game profile is none");
|
self.kick("game profile is none");
|
||||||
@ -225,8 +224,8 @@ impl Client {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle_known_packs(&mut self, _server: &mut Server, _config_acknowledged: SKnownPacks) {
|
pub fn handle_known_packs(&mut self, server: &mut Server, _config_acknowledged: SKnownPacks) {
|
||||||
for registry in Registry::get_static() {
|
for registry in &server.cached_registry {
|
||||||
self.send_packet(CRegistryData::new(
|
self.send_packet(CRegistryData::new(
|
||||||
®istry.registry_id,
|
®istry.registry_id,
|
||||||
®istry.registry_entries,
|
®istry.registry_entries,
|
||||||
|
|||||||
@ -2,8 +2,8 @@ use num_traits::FromPrimitive;
|
|||||||
use pumpkin_inventory::WindowType;
|
use pumpkin_inventory::WindowType;
|
||||||
use pumpkin_protocol::{
|
use pumpkin_protocol::{
|
||||||
client::play::{
|
client::play::{
|
||||||
Animation, CEntityAnimation, CHeadRot, COpenScreen, CSystemChatMessge, CUpdateEntityPos,
|
Animation, CEntityAnimation, CHeadRot, COpenScreen, CPlayerChatMessage, CUpdateEntityPos,
|
||||||
CUpdateEntityPosRot, CUpdateEntityRot,
|
CUpdateEntityPosRot, CUpdateEntityRot, FilterType,
|
||||||
},
|
},
|
||||||
server::play::{
|
server::play::{
|
||||||
SChatCommand, SChatMessage, SConfirmTeleport, SPlayerCommand, SPlayerPosition,
|
SChatCommand, SChatMessage, SConfirmTeleport, SPlayerCommand, SPlayerPosition,
|
||||||
@ -203,30 +203,30 @@ impl Client {
|
|||||||
let gameprofile = self.gameprofile.as_ref().unwrap();
|
let gameprofile = self.gameprofile.as_ref().unwrap();
|
||||||
dbg!("got message");
|
dbg!("got message");
|
||||||
// yeah a "raw system message", the ugly way to do that, but it works
|
// yeah a "raw system message", the ugly way to do that, but it works
|
||||||
|
// server.broadcast_packet(
|
||||||
|
// self,
|
||||||
|
// CSystemChatMessge::new(
|
||||||
|
// TextComponent::from(format!("{}: {}", gameprofile.name, message)),
|
||||||
|
// false,
|
||||||
|
// ),
|
||||||
|
// );
|
||||||
server.broadcast_packet(
|
server.broadcast_packet(
|
||||||
self,
|
self,
|
||||||
CSystemChatMessge::new(
|
CPlayerChatMessage::new(
|
||||||
TextComponent::from(format!("{}: {}", gameprofile.name, message)),
|
gameprofile.id,
|
||||||
false,
|
0.into(),
|
||||||
|
None,
|
||||||
|
message.clone(),
|
||||||
|
chat_message.timestamp,
|
||||||
|
chat_message.salt,
|
||||||
|
&[],
|
||||||
|
Some(TextComponent::from(message.clone())),
|
||||||
|
pumpkin_protocol::VarInt(FilterType::PassThrough as i32),
|
||||||
|
0.into(),
|
||||||
|
TextComponent::from(gameprofile.name.clone()),
|
||||||
|
None,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
/*server.broadcast_packet(
|
|
||||||
self,
|
|
||||||
CPlayerChatMessage::new(
|
|
||||||
gameprofile.id,
|
|
||||||
0.into(),
|
|
||||||
None,
|
|
||||||
message.clone(),
|
|
||||||
chat_message.timestamp,
|
|
||||||
chat_message.salt,
|
|
||||||
&[],
|
|
||||||
Some(TextComponent::from(message.clone())),
|
|
||||||
pumpkin_protocol::VarInt(FilterType::PassThrough as i32),
|
|
||||||
0.into(),
|
|
||||||
TextComponent::from(gameprofile.name.clone()),
|
|
||||||
None,
|
|
||||||
),
|
|
||||||
) */
|
|
||||||
/* server.broadcast_packet(
|
/* server.broadcast_packet(
|
||||||
self,
|
self,
|
||||||
CDisguisedChatMessage::new(
|
CDisguisedChatMessage::new(
|
||||||
|
|||||||
@ -22,6 +22,7 @@ use pumpkin_protocol::{
|
|||||||
},
|
},
|
||||||
BitSet, ClientPacket, Players, Sample, StatusResponse, VarInt, Version, CURRENT_MC_PROTOCOL,
|
BitSet, ClientPacket, Players, Sample, StatusResponse, VarInt, Version, CURRENT_MC_PROTOCOL,
|
||||||
};
|
};
|
||||||
|
use pumpkin_registry::Registry;
|
||||||
use pumpkin_world::chunk::TestChunk;
|
use pumpkin_world::chunk::TestChunk;
|
||||||
use rsa::{traits::PublicKeyParts, RsaPrivateKey, RsaPublicKey};
|
use rsa::{traits::PublicKeyParts, RsaPrivateKey, RsaPublicKey};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
@ -50,6 +51,9 @@ pub struct Server {
|
|||||||
/// Cache the Server brand buffer so we don't have to rebuild them every time a player joins
|
/// Cache the Server brand buffer so we don't have to rebuild them every time a player joins
|
||||||
pub cached_server_brand: Vec<u8>,
|
pub cached_server_brand: Vec<u8>,
|
||||||
|
|
||||||
|
/// Cache the registry so we don't have to parse it every time a player joins
|
||||||
|
pub cached_registry: Vec<Registry>,
|
||||||
|
|
||||||
pub current_clients: HashMap<Rc<Token>, Rc<RefCell<Client>>>,
|
pub current_clients: HashMap<Rc<Token>, Rc<RefCell<Client>>>,
|
||||||
|
|
||||||
// TODO: replace with HashMap <World, Player>
|
// TODO: replace with HashMap <World, Player>
|
||||||
@ -89,6 +93,7 @@ impl Server {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
|
cached_registry: Registry::get_static(),
|
||||||
// 0 is invalid
|
// 0 is invalid
|
||||||
entity_id: 2.into(),
|
entity_id: 2.into(),
|
||||||
// world: World::load(""),
|
// world: World::load(""),
|
||||||
@ -123,7 +128,7 @@ impl Server {
|
|||||||
// todo: put this into the entitiy struct
|
// todo: put this into the entitiy struct
|
||||||
if client.is_player() {
|
if client.is_player() {
|
||||||
let id = client.player.as_ref().unwrap().entity_id();
|
let id = client.player.as_ref().unwrap().entity_id();
|
||||||
self.broadcast_packet(&mut client, CRemoveEntities::new(vec![id.into()]))
|
self.broadcast_packet(&mut client, CRemoveEntities::new(&[id.into()]))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -140,7 +145,7 @@ impl Server {
|
|||||||
client.send_packet(CLogin::new(
|
client.send_packet(CLogin::new(
|
||||||
entity_id,
|
entity_id,
|
||||||
self.base_config.hardcore,
|
self.base_config.hardcore,
|
||||||
vec!["minecraft:overworld".into()],
|
&["minecraft:overworld"],
|
||||||
self.base_config.max_players.into(),
|
self.base_config.max_players.into(),
|
||||||
self.base_config.view_distance.into(), // TODO: view distance
|
self.base_config.view_distance.into(), // TODO: view distance
|
||||||
self.base_config.simulation_distance.into(), // TODO: sim view dinstance
|
self.base_config.simulation_distance.into(), // TODO: sim view dinstance
|
||||||
@ -148,7 +153,7 @@ impl Server {
|
|||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
0.into(),
|
0.into(),
|
||||||
"minecraft:overworld".into(),
|
"minecraft:overworld",
|
||||||
0, // seed
|
0, // seed
|
||||||
match self.base_config.default_gamemode {
|
match self.base_config.default_gamemode {
|
||||||
GameMode::Undefined => GameMode::Survival,
|
GameMode::Undefined => GameMode::Survival,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user