Add Clientbound Client Informations (Play)
This commit is contained in:
parent
1ab05e0c00
commit
cfa20776f6
@ -5,6 +5,6 @@ use crate::VarInt;
|
|||||||
#[derive(serde::Serialize)]
|
#[derive(serde::Serialize)]
|
||||||
#[packet(0x54)]
|
#[packet(0x54)]
|
||||||
pub struct CCenterChunk {
|
pub struct CCenterChunk {
|
||||||
pub chunk_x: VarInt,
|
pub chunk_x: VarInt,
|
||||||
pub chunk_z: VarInt
|
pub chunk_z: VarInt,
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
mod c_center_chunk;
|
|
||||||
mod c_actionbar;
|
mod c_actionbar;
|
||||||
|
mod c_center_chunk;
|
||||||
mod c_change_difficulty;
|
mod c_change_difficulty;
|
||||||
mod c_chunk_data;
|
mod c_chunk_data;
|
||||||
mod c_chunk_data_update_light;
|
mod c_chunk_data_update_light;
|
||||||
@ -27,8 +27,8 @@ mod c_update_entity_pos;
|
|||||||
mod c_update_entity_rot;
|
mod c_update_entity_rot;
|
||||||
mod player_action;
|
mod player_action;
|
||||||
|
|
||||||
pub use c_center_chunk::*;
|
|
||||||
pub use c_actionbar::*;
|
pub use c_actionbar::*;
|
||||||
|
pub use c_center_chunk::*;
|
||||||
pub use c_change_difficulty::*;
|
pub use c_change_difficulty::*;
|
||||||
pub use c_chunk_data::*;
|
pub use c_chunk_data::*;
|
||||||
pub use c_chunk_data_update_light::*;
|
pub use c_chunk_data_update_light::*;
|
||||||
|
|||||||
@ -32,7 +32,7 @@ impl PacketEncoder {
|
|||||||
.encode(&mut writer)
|
.encode(&mut writer)
|
||||||
.map_err(|_| PacketError::EncodeID)?;
|
.map_err(|_| PacketError::EncodeID)?;
|
||||||
packet.write(&mut packet_buf);
|
packet.write(&mut packet_buf);
|
||||||
|
|
||||||
writer
|
writer
|
||||||
.write(packet_buf.buf())
|
.write(packet_buf.buf())
|
||||||
.map_err(|_| PacketError::EncodeFailedWrite)?;
|
.map_err(|_| PacketError::EncodeFailedWrite)?;
|
||||||
|
|||||||
@ -4,7 +4,7 @@ use crate::VarInt;
|
|||||||
|
|
||||||
#[derive(serde::Deserialize)]
|
#[derive(serde::Deserialize)]
|
||||||
#[packet(0x00)]
|
#[packet(0x00)]
|
||||||
pub struct SClientInformation {
|
pub struct SClientInformationConfig {
|
||||||
pub locale: String, // 16
|
pub locale: String, // 16
|
||||||
pub view_distance: i8,
|
pub view_distance: i8,
|
||||||
pub chat_mode: VarInt, // Varint
|
pub chat_mode: VarInt, // Varint
|
||||||
|
|||||||
16
pumpkin-protocol/src/server/play/c_client_information.rs
Normal file
16
pumpkin-protocol/src/server/play/c_client_information.rs
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
use pumpkin_macros::packet;
|
||||||
|
|
||||||
|
use crate::VarInt;
|
||||||
|
|
||||||
|
#[derive(serde::Deserialize)]
|
||||||
|
#[packet(0x0A)]
|
||||||
|
pub struct SClientInformationPlay {
|
||||||
|
pub locale: String, // 16
|
||||||
|
pub view_distance: i8,
|
||||||
|
pub chat_mode: VarInt, // Varint
|
||||||
|
pub chat_colors: bool,
|
||||||
|
pub skin_parts: u8,
|
||||||
|
pub main_hand: VarInt,
|
||||||
|
pub text_filtering: bool,
|
||||||
|
pub server_listing: bool,
|
||||||
|
}
|
||||||
@ -1,3 +1,4 @@
|
|||||||
|
mod c_client_information;
|
||||||
mod s_chat_command;
|
mod s_chat_command;
|
||||||
mod s_chat_message;
|
mod s_chat_message;
|
||||||
mod s_confirm_teleport;
|
mod s_confirm_teleport;
|
||||||
@ -7,6 +8,7 @@ mod s_player_position_rotation;
|
|||||||
mod s_player_rotation;
|
mod s_player_rotation;
|
||||||
mod s_swing_arm;
|
mod s_swing_arm;
|
||||||
|
|
||||||
|
pub use c_client_information::*;
|
||||||
pub use s_chat_command::*;
|
pub use s_chat_command::*;
|
||||||
pub use s_chat_message::*;
|
pub use s_chat_message::*;
|
||||||
pub use s_confirm_teleport::*;
|
pub use s_confirm_teleport::*;
|
||||||
|
|||||||
@ -3,5 +3,5 @@ pub mod dimension;
|
|||||||
pub const WORLD_HEIGHT: usize = 384;
|
pub const WORLD_HEIGHT: usize = 384;
|
||||||
pub const WORLD_Y_START_AT: i32 = -64;
|
pub const WORLD_Y_START_AT: i32 = -64;
|
||||||
pub const DIRECT_PALETTE_BITS: u32 = 15;
|
pub const DIRECT_PALETTE_BITS: u32 = 15;
|
||||||
mod world;
|
|
||||||
mod block_registry;
|
mod block_registry;
|
||||||
|
mod world;
|
||||||
|
|||||||
@ -8,7 +8,7 @@ use pumpkin_protocol::{
|
|||||||
status::{CPingResponse, CStatusResponse},
|
status::{CPingResponse, CStatusResponse},
|
||||||
},
|
},
|
||||||
server::{
|
server::{
|
||||||
config::{SAcknowledgeFinishConfig, SClientInformation, SKnownPacks, SPluginMessage},
|
config::{SAcknowledgeFinishConfig, SClientInformationConfig, SKnownPacks, SPluginMessage},
|
||||||
handshake::SHandShake,
|
handshake::SHandShake,
|
||||||
login::{SEncryptionResponse, SLoginAcknowledged, SLoginPluginResponse, SLoginStart},
|
login::{SEncryptionResponse, SLoginAcknowledged, SLoginPluginResponse, SLoginStart},
|
||||||
status::{SPingRequest, SStatusRequest},
|
status::{SPingRequest, SStatusRequest},
|
||||||
@ -195,10 +195,10 @@ impl Client {
|
|||||||
}]));
|
}]));
|
||||||
dbg!("login achnowlaged");
|
dbg!("login achnowlaged");
|
||||||
}
|
}
|
||||||
pub fn handle_client_information(
|
pub fn handle_client_information_config(
|
||||||
&mut self,
|
&mut self,
|
||||||
_server: &mut Server,
|
_server: &mut Server,
|
||||||
client_information: SClientInformation,
|
client_information: SClientInformationConfig,
|
||||||
) {
|
) {
|
||||||
dbg!("got client settings");
|
dbg!("got client settings");
|
||||||
self.config = Some(PlayerConfig {
|
self.config = Some(PlayerConfig {
|
||||||
|
|||||||
@ -23,12 +23,12 @@ use pumpkin_protocol::{
|
|||||||
packet_decoder::PacketDecoder,
|
packet_decoder::PacketDecoder,
|
||||||
packet_encoder::PacketEncoder,
|
packet_encoder::PacketEncoder,
|
||||||
server::{
|
server::{
|
||||||
config::{SAcknowledgeFinishConfig, SClientInformation, SKnownPacks, SPluginMessage},
|
config::{SAcknowledgeFinishConfig, SClientInformationConfig, SKnownPacks, SPluginMessage},
|
||||||
handshake::SHandShake,
|
handshake::SHandShake,
|
||||||
login::{SEncryptionResponse, SLoginAcknowledged, SLoginPluginResponse, SLoginStart},
|
login::{SEncryptionResponse, SLoginAcknowledged, SLoginPluginResponse, SLoginStart},
|
||||||
play::{
|
play::{
|
||||||
SChatCommand, SChatMessage, SConfirmTeleport, SPlayerCommand, SPlayerPosition,
|
SChatCommand, SChatMessage, SClientInformationPlay, SConfirmTeleport, SPlayerCommand,
|
||||||
SPlayerPositionRotation, SPlayerRotation, SSwingArm,
|
SPlayerPosition, SPlayerPositionRotation, SPlayerRotation, SSwingArm,
|
||||||
},
|
},
|
||||||
status::{SPingRequest, SStatusRequest},
|
status::{SPingRequest, SStatusRequest},
|
||||||
},
|
},
|
||||||
@ -218,15 +218,20 @@ impl Client {
|
|||||||
),
|
),
|
||||||
},
|
},
|
||||||
pumpkin_protocol::ConnectionState::Config => match packet.id.0 {
|
pumpkin_protocol::ConnectionState::Config => match packet.id.0 {
|
||||||
SClientInformation::PACKET_ID => self
|
SClientInformationConfig::PACKET_ID => self.handle_client_information_config(
|
||||||
.handle_client_information(server, SClientInformation::read(bytebuf).unwrap()),
|
server,
|
||||||
|
SClientInformationConfig::read(bytebuf).unwrap(),
|
||||||
|
),
|
||||||
SPluginMessage::PACKET_ID => {
|
SPluginMessage::PACKET_ID => {
|
||||||
self.handle_plugin_message(server, SPluginMessage::read(bytebuf).unwrap())
|
self.handle_plugin_message(server, SPluginMessage::read(bytebuf).unwrap())
|
||||||
}
|
}
|
||||||
SAcknowledgeFinishConfig::PACKET_ID => self.handle_config_acknowledged(
|
SAcknowledgeFinishConfig::PACKET_ID => {
|
||||||
server,
|
self.handle_config_acknowledged(
|
||||||
SAcknowledgeFinishConfig::read(bytebuf).unwrap(),
|
server,
|
||||||
).await,
|
SAcknowledgeFinishConfig::read(bytebuf).unwrap(),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
}
|
||||||
SKnownPacks::PACKET_ID => {
|
SKnownPacks::PACKET_ID => {
|
||||||
self.handle_known_packs(server, SKnownPacks::read(bytebuf).unwrap())
|
self.handle_known_packs(server, SKnownPacks::read(bytebuf).unwrap())
|
||||||
}
|
}
|
||||||
@ -273,6 +278,10 @@ impl Client {
|
|||||||
SChatMessage::PACKET_ID => {
|
SChatMessage::PACKET_ID => {
|
||||||
self.handle_chat_message(server, SChatMessage::read(bytebuf).unwrap())
|
self.handle_chat_message(server, SChatMessage::read(bytebuf).unwrap())
|
||||||
}
|
}
|
||||||
|
SClientInformationPlay::PACKET_ID => self.handle_client_information_play(
|
||||||
|
server,
|
||||||
|
SClientInformationPlay::read(bytebuf).unwrap(),
|
||||||
|
),
|
||||||
_ => log::error!("Failed to handle player packet id {}", packet.id.0),
|
_ => log::error!("Failed to handle player packet id {}", packet.id.0),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,8 +6,8 @@ use pumpkin_protocol::{
|
|||||||
CUpdateEntityRot,
|
CUpdateEntityRot,
|
||||||
},
|
},
|
||||||
server::play::{
|
server::play::{
|
||||||
SChatCommand, SChatMessage, SConfirmTeleport, SPlayerCommand, SPlayerPosition,
|
SChatCommand, SChatMessage, SClientInformationPlay, SConfirmTeleport, SPlayerCommand,
|
||||||
SPlayerPositionRotation, SPlayerRotation, SSwingArm,
|
SPlayerPosition, SPlayerPositionRotation, SPlayerRotation, SSwingArm,
|
||||||
},
|
},
|
||||||
VarInt,
|
VarInt,
|
||||||
};
|
};
|
||||||
@ -15,12 +15,12 @@ use pumpkin_text::TextComponent;
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
commands::{handle_command, CommandSender},
|
commands::{handle_command, CommandSender},
|
||||||
entity::player::Hand,
|
entity::player::{ChatMode, Hand},
|
||||||
server::Server,
|
server::Server,
|
||||||
util::math::wrap_degrees,
|
util::math::wrap_degrees,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::Client;
|
use super::{Client, PlayerConfig};
|
||||||
|
|
||||||
/// Handles all Play Packets send by a real Player
|
/// Handles all Play Packets send by a real Player
|
||||||
impl Client {
|
impl Client {
|
||||||
@ -239,4 +239,21 @@ impl Client {
|
|||||||
),
|
),
|
||||||
) */
|
) */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn handle_client_information_play(
|
||||||
|
&mut self,
|
||||||
|
_server: &mut Server,
|
||||||
|
client_information: SClientInformationPlay,
|
||||||
|
) {
|
||||||
|
self.config = Some(PlayerConfig {
|
||||||
|
locale: client_information.locale,
|
||||||
|
view_distance: client_information.view_distance,
|
||||||
|
chat_mode: ChatMode::from_i32(client_information.chat_mode.into()).unwrap(),
|
||||||
|
chat_colors: client_information.chat_colors,
|
||||||
|
skin_parts: client_information.skin_parts,
|
||||||
|
main_hand: Hand::from_i32(client_information.main_hand.into()).unwrap(),
|
||||||
|
text_filtering: client_information.text_filtering,
|
||||||
|
server_listing: client_information.server_listing,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,12 +13,17 @@ use mio::{event::Event, Poll, Token};
|
|||||||
use num_traits::ToPrimitive;
|
use num_traits::ToPrimitive;
|
||||||
use pumpkin_entity::{entity_type::EntityType, EntityId};
|
use pumpkin_entity::{entity_type::EntityType, EntityId};
|
||||||
use pumpkin_protocol::{
|
use pumpkin_protocol::{
|
||||||
bytebuf::ByteBuffer, client::{
|
bytebuf::ByteBuffer,
|
||||||
|
client::{
|
||||||
config::CPluginMessage,
|
config::CPluginMessage,
|
||||||
play::{
|
play::{
|
||||||
CCenterChunk, CChunkData, CChunkDataUpdateLight, CGameEvent, CLogin, CPlayerAbilities, CPlayerInfoUpdate, CRemoveEntities, CRemovePlayerInfo, CSetEntityMetadata, CSpawnEntity, Metadata, PlayerAction
|
CCenterChunk, CChunkData, CChunkDataUpdateLight, CGameEvent, CLogin, CPlayerAbilities,
|
||||||
|
CPlayerInfoUpdate, CRemoveEntities, CRemovePlayerInfo, CSetEntityMetadata,
|
||||||
|
CSpawnEntity, Metadata, PlayerAction,
|
||||||
},
|
},
|
||||||
}, uuid::UUID, BitSet, ClientPacket, Players, Sample, StatusResponse, VarInt, Version, CURRENT_MC_PROTOCOL
|
},
|
||||||
|
uuid::UUID,
|
||||||
|
BitSet, ClientPacket, Players, Sample, StatusResponse, VarInt, Version, CURRENT_MC_PROTOCOL,
|
||||||
};
|
};
|
||||||
use pumpkin_world::dimension::Dimension;
|
use pumpkin_world::dimension::Dimension;
|
||||||
|
|
||||||
@ -329,9 +334,7 @@ impl Server {
|
|||||||
let chunks = Dimension::OverWorld
|
let chunks = Dimension::OverWorld
|
||||||
.into_level(
|
.into_level(
|
||||||
// TODO: load form config
|
// TODO: load form config
|
||||||
"./world"
|
"./world".parse().unwrap(),
|
||||||
.parse()
|
|
||||||
.unwrap(),
|
|
||||||
)
|
)
|
||||||
.read_chunks(wanted_chunks)
|
.read_chunks(wanted_chunks)
|
||||||
.await;
|
.await;
|
||||||
@ -342,22 +345,25 @@ impl Server {
|
|||||||
});
|
});
|
||||||
|
|
||||||
chunks.iter().for_each(|chunk| {
|
chunks.iter().for_each(|chunk| {
|
||||||
if chunk.0 == (0,0) {
|
if chunk.0 == (0, 0) {
|
||||||
let mut test = ByteBuffer::empty();
|
let mut test = ByteBuffer::empty();
|
||||||
CChunkData(chunk.1.as_ref().unwrap()).write(&mut test);
|
CChunkData(chunk.1.as_ref().unwrap()).write(&mut test);
|
||||||
let len = test.buf().len();
|
let len = test.buf().len();
|
||||||
dbg!("Chunk packet size: {}B {}KB {}MB", len, len/1024, len/(1024*1024));
|
dbg!(
|
||||||
}
|
"Chunk packet size: {}B {}KB {}MB",
|
||||||
|
len,
|
||||||
|
len / 1024,
|
||||||
|
len / (1024 * 1024)
|
||||||
|
);
|
||||||
|
}
|
||||||
match &chunk.1 {
|
match &chunk.1 {
|
||||||
Err(err) => println!(
|
Err(err) => println!(
|
||||||
"Chunk loading failed for chunk ({},{}): {}",
|
"Chunk loading failed for chunk ({},{}): {}",
|
||||||
chunk.0 .0, chunk.0 .1, err
|
chunk.0 .0, chunk.0 .1, err
|
||||||
),
|
),
|
||||||
Ok(data) => client.send_packet(&CChunkData(data)),
|
Ok(data) => client.send_packet(&CChunkData(data)),
|
||||||
}});
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// let test_chunk = TestChunk::new();
|
// let test_chunk = TestChunk::new();
|
||||||
// client.send_packet(CChunkDataUpdateLight::new(
|
// client.send_packet(CChunkDataUpdateLight::new(
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user