Fix: Serverbound Chat Message

This commit is contained in:
Snowiiii
2024-08-20 13:19:50 +02:00
parent 5445975238
commit a6fbc3d13a
5 changed files with 19 additions and 29 deletions

View File

@@ -55,26 +55,16 @@ impl VarInt {
}
pub fn encode(&self, mut w: impl Write) -> Result<(), io::Error> {
let x = self.0 as u64;
let stage1 = (x & 0x000000000000007f)
| ((x & 0x0000000000003f80) << 1)
| ((x & 0x00000000001fc000) << 2)
| ((x & 0x000000000fe00000) << 3)
| ((x & 0x00000000f0000000) << 4);
let leading = stage1.leading_zeros();
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) })?;
let mut x = self.0 as u64;
loop {
let byte = (x & 0x7F) as u8;
x >>= 7;
if x == 0 {
w.write_all(&[byte])?;
break;
}
w.write_all(&[byte | 0x80])?;
}
Ok(())
}

View File

@@ -22,6 +22,8 @@ pub struct 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> {
let start_len = self.buf.len();

View File

@@ -1,3 +1,4 @@
use bytes::Bytes;
use pumpkin_macros::packet;
use crate::{
@@ -11,7 +12,7 @@ pub struct SChatMessage {
pub message: String,
pub timestamp: i64,
pub salt: i64,
pub signature: Option<Vec<u8>>,
pub signature: Option<Bytes>,
pub messagee_count: VarInt,
// acknowledged: BitSet,
}
@@ -23,7 +24,7 @@ impl ServerPacket for SChatMessage {
message: bytebuf.get_string().unwrap(),
timestamp: 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(),
})
}

View File

@@ -218,7 +218,7 @@ impl Client {
self,
&CPlayerChatMessage::new(
pumpkin_protocol::uuid::UUID(gameprofile.id),
chat_message.messagee_count,
1.into(),
chat_message.signature.as_deref(),
&message,
chat_message.timestamp,

View File

@@ -44,8 +44,6 @@ use crate::{
pub const CURRENT_MC_VERSION: &str = "1.21.1";
pub struct Server {
pub compression_threshold: Option<u8>,
pub public_key: RsaPublicKey,
pub private_key: RsaPrivateKey,
pub public_key_der: Box<[u8]>,
@@ -81,7 +79,7 @@ impl Server {
let cached_server_brand = Self::build_brand();
// TODO: only create when needed
dbg!("creating keys");
log::debug!("Creating encryption keys...");
let (public_key, private_key) = Self::generate_keys();
let public_key_der = rsa_der::public_key_to_der(
@@ -100,7 +98,7 @@ impl Server {
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(
// TODO: load form config
"./world".parse().unwrap(),
@@ -111,7 +109,6 @@ impl Server {
// 0 is invalid
entity_id: 2.into(),
world: Arc::new(Mutex::new(world)),
compression_threshold: None, // 256
public_key,
cached_server_brand,
private_key,
@@ -249,7 +246,7 @@ impl Server {
&CSpawnEntity::new(
entity_id.into(),
UUID(gameprofile.id),
EntityType::Player.to_i32().unwrap().into(),
(EntityType::Player as i32).into(),
x,
y,
z,