Fix: Serverbound Chat Message
This commit is contained in:
parent
5445975238
commit
a6fbc3d13a
@ -55,26 +55,16 @@ impl VarInt {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn encode(&self, mut w: impl Write) -> Result<(), io::Error> {
|
pub fn encode(&self, mut w: impl Write) -> Result<(), io::Error> {
|
||||||
let x = self.0 as u64;
|
let mut x = self.0 as u64;
|
||||||
let stage1 = (x & 0x000000000000007f)
|
loop {
|
||||||
| ((x & 0x0000000000003f80) << 1)
|
let byte = (x & 0x7F) as u8;
|
||||||
| ((x & 0x00000000001fc000) << 2)
|
x >>= 7;
|
||||||
| ((x & 0x000000000fe00000) << 3)
|
if x == 0 {
|
||||||
| ((x & 0x00000000f0000000) << 4);
|
w.write_all(&[byte])?;
|
||||||
|
break;
|
||||||
let leading = stage1.leading_zeros();
|
}
|
||||||
|
w.write_all(&[byte | 0x80])?;
|
||||||
let unused_bytes = (leading - 1) >> 3;
|
}
|
||||||
let bytes_needed = 8 - unused_bytes;
|
|
||||||
|
|
||||||
// set all but the last MSBs
|
|
||||||
let msbs = 0x8080808080808080;
|
|
||||||
let msbmask = 0xffffffffffffffff >> (((8 - bytes_needed + 1) << 3) - 1);
|
|
||||||
|
|
||||||
let merged = stage1 | (msbs & msbmask);
|
|
||||||
let bytes = merged.to_le_bytes();
|
|
||||||
|
|
||||||
w.write_all(unsafe { bytes.get_unchecked(..bytes_needed as usize) })?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -22,6 +22,8 @@ pub struct PacketEncoder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl PacketEncoder {
|
impl PacketEncoder {
|
||||||
|
// i think clippy is broken
|
||||||
|
#[allow(clippy::needless_borrows_for_generic_args)]
|
||||||
pub fn append_packet<P: ClientPacket>(&mut self, packet: &P) -> Result<(), PacketError> {
|
pub fn append_packet<P: ClientPacket>(&mut self, packet: &P) -> Result<(), PacketError> {
|
||||||
let start_len = self.buf.len();
|
let start_len = self.buf.len();
|
||||||
|
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
use bytes::Bytes;
|
||||||
use pumpkin_macros::packet;
|
use pumpkin_macros::packet;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@ -11,7 +12,7 @@ pub struct SChatMessage {
|
|||||||
pub message: String,
|
pub message: String,
|
||||||
pub timestamp: i64,
|
pub timestamp: i64,
|
||||||
pub salt: i64,
|
pub salt: i64,
|
||||||
pub signature: Option<Vec<u8>>,
|
pub signature: Option<Bytes>,
|
||||||
pub messagee_count: VarInt,
|
pub messagee_count: VarInt,
|
||||||
// acknowledged: BitSet,
|
// acknowledged: BitSet,
|
||||||
}
|
}
|
||||||
@ -23,7 +24,7 @@ impl ServerPacket for SChatMessage {
|
|||||||
message: bytebuf.get_string().unwrap(),
|
message: bytebuf.get_string().unwrap(),
|
||||||
timestamp: bytebuf.get_i64(),
|
timestamp: bytebuf.get_i64(),
|
||||||
salt: bytebuf.get_i64(),
|
salt: bytebuf.get_i64(),
|
||||||
signature: bytebuf.get_option(|v| v.get_slice().to_vec()),
|
signature: bytebuf.get_option(|v| v.copy_to_bytes(255)),
|
||||||
messagee_count: bytebuf.get_var_int(),
|
messagee_count: bytebuf.get_var_int(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@ -218,7 +218,7 @@ impl Client {
|
|||||||
self,
|
self,
|
||||||
&CPlayerChatMessage::new(
|
&CPlayerChatMessage::new(
|
||||||
pumpkin_protocol::uuid::UUID(gameprofile.id),
|
pumpkin_protocol::uuid::UUID(gameprofile.id),
|
||||||
chat_message.messagee_count,
|
1.into(),
|
||||||
chat_message.signature.as_deref(),
|
chat_message.signature.as_deref(),
|
||||||
&message,
|
&message,
|
||||||
chat_message.timestamp,
|
chat_message.timestamp,
|
||||||
|
|||||||
@ -44,8 +44,6 @@ use crate::{
|
|||||||
pub const CURRENT_MC_VERSION: &str = "1.21.1";
|
pub const CURRENT_MC_VERSION: &str = "1.21.1";
|
||||||
|
|
||||||
pub struct Server {
|
pub struct Server {
|
||||||
pub compression_threshold: Option<u8>,
|
|
||||||
|
|
||||||
pub public_key: RsaPublicKey,
|
pub public_key: RsaPublicKey,
|
||||||
pub private_key: RsaPrivateKey,
|
pub private_key: RsaPrivateKey,
|
||||||
pub public_key_der: Box<[u8]>,
|
pub public_key_der: Box<[u8]>,
|
||||||
@ -81,7 +79,7 @@ impl Server {
|
|||||||
let cached_server_brand = Self::build_brand();
|
let cached_server_brand = Self::build_brand();
|
||||||
|
|
||||||
// TODO: only create when needed
|
// TODO: only create when needed
|
||||||
dbg!("creating keys");
|
log::debug!("Creating encryption keys...");
|
||||||
let (public_key, private_key) = Self::generate_keys();
|
let (public_key, private_key) = Self::generate_keys();
|
||||||
|
|
||||||
let public_key_der = rsa_der::public_key_to_der(
|
let public_key_der = rsa_der::public_key_to_der(
|
||||||
@ -100,7 +98,7 @@ impl Server {
|
|||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
log::debug!("Pumpkin does currently not have World or Chunk generation, Using ../world folder with vanilla pregenerated chunks");
|
log::warn!("Pumpkin does currently not have World or Chunk generation, Using ../world folder with vanilla pregenerated chunks");
|
||||||
let world = World::load(Dimension::OverWorld.into_level(
|
let world = World::load(Dimension::OverWorld.into_level(
|
||||||
// TODO: load form config
|
// TODO: load form config
|
||||||
"./world".parse().unwrap(),
|
"./world".parse().unwrap(),
|
||||||
@ -111,7 +109,6 @@ impl Server {
|
|||||||
// 0 is invalid
|
// 0 is invalid
|
||||||
entity_id: 2.into(),
|
entity_id: 2.into(),
|
||||||
world: Arc::new(Mutex::new(world)),
|
world: Arc::new(Mutex::new(world)),
|
||||||
compression_threshold: None, // 256
|
|
||||||
public_key,
|
public_key,
|
||||||
cached_server_brand,
|
cached_server_brand,
|
||||||
private_key,
|
private_key,
|
||||||
@ -249,7 +246,7 @@ impl Server {
|
|||||||
&CSpawnEntity::new(
|
&CSpawnEntity::new(
|
||||||
entity_id.into(),
|
entity_id.into(),
|
||||||
UUID(gameprofile.id),
|
UUID(gameprofile.id),
|
||||||
EntityType::Player.to_i32().unwrap().into(),
|
(EntityType::Player as i32).into(),
|
||||||
x,
|
x,
|
||||||
y,
|
y,
|
||||||
z,
|
z,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user