Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
lukas0008 committed Aug 7, 2024
2 parents 298389a + 0cec9bf commit 2e31fda
Show file tree
Hide file tree
Showing 23 changed files with 446 additions and 114 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ Pumpkin is currently under heavy development.

## What Pumpkin aims to be:
- A fast, efficient, and scalable Minecraft server
- Use Multi-Threading
- Compatible with the latest Minecraft server version
- Adherent to Vanilla game mechanics
- Be Secure and prevent all Exploits found
- Highly configurable with the ability to disable unnecessary features
- A platform for plugin development

Expand Down Expand Up @@ -51,7 +53,7 @@ Pumpkin is currently under heavy development.
- [x] Player Client brand
- [x] Player Teleport
- [x] Player Movement
- [ ] Player Animation
- [x] Player Animation
- [ ] Player Inventory
- [ ] Player Attack
- Server
Expand Down
11 changes: 11 additions & 0 deletions pumpkin-protocol/src/bytebuf/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,17 @@ impl ByteBuffer {
self.buffer.put_slice(src)
}

pub fn put<T: Buf>(&mut self, src: T)
where
Self: Sized,
{
self.buffer.put(src)
}

pub fn reserve(&mut self, additional: usize) {
self.buffer.reserve(additional)
}

pub fn get_slice(&mut self) -> BytesMut {
self.buffer.split()
}
Expand Down
24 changes: 16 additions & 8 deletions pumpkin-protocol/src/bytebuf/serializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use std::fmt::Display;
use serde::{ser, Serialize};
use thiserror::Error;

use crate::VarInt;

use super::ByteBuffer;

pub struct Serializer {
Expand Down Expand Up @@ -121,16 +123,22 @@ impl<'a> ser::Serializer for &'a mut Serializer {
unimplemented!()
}
fn serialize_none(self) -> Result<Self::Ok, Self::Error> {
unimplemented!()
self.output.put_bool(false);
Ok(())
}
fn serialize_seq(self, _len: Option<usize>) -> Result<Self::SerializeSeq, Self::Error> {
unimplemented!()
fn serialize_seq(self, len: Option<usize>) -> Result<Self::SerializeSeq, Self::Error> {
if let Some(len) = len {
self.output.put_var_int(&VarInt(len as i32));
}
Ok(self)
}
fn serialize_some<T>(self, _value: &T) -> Result<Self::Ok, Self::Error>
fn serialize_some<T>(self, value: &T) -> Result<Self::Ok, Self::Error>
where
T: ?Sized + Serialize,
{
unimplemented!()
self.output.put_bool(true);
dbg!("aa");
value.serialize(self)
}
fn serialize_str(self, v: &str) -> Result<Self::Ok, Self::Error> {
self.output.put_string(v);
Expand Down Expand Up @@ -213,16 +221,16 @@ impl<'a> ser::SerializeSeq for &'a mut Serializer {
type Error = SerializerError;

// Serialize a single element of the sequence.
fn serialize_element<T>(&mut self, _value: &T) -> Result<(), Self::Error>
fn serialize_element<T>(&mut self, value: &T) -> Result<(), Self::Error>
where
T: ?Sized + Serialize,
{
todo!()
value.serialize(&mut **self)
}

// Close the sequence.
fn end(self) -> Result<(), Self::Error> {
todo!()
Ok(())
}
}

Expand Down
10 changes: 7 additions & 3 deletions pumpkin-protocol/src/client/login/c_encryption_request.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use pumpkin_macros::packet;

use crate::{bytebuf::ByteBuffer, ClientPacket, VarIntType};
use crate::{bytebuf::ByteBuffer, ClientPacket, VarInt};

#[packet(0x01)]
pub struct CEncryptionRequest<'a> {
server_id: &'a str, // 20
public_key_length: VarInt,
public_key: &'a [u8],
verify_token_length: VarInt,
verify_token: &'a [u8],
should_authenticate: bool,
}
Expand All @@ -19,7 +21,9 @@ impl<'a> CEncryptionRequest<'a> {
) -> Self {
Self {
server_id,
public_key_length: public_key.len().into(),
public_key,
verify_token_length: verify_token.len().into(),
verify_token,
should_authenticate,
}
Expand All @@ -29,9 +33,9 @@ impl<'a> CEncryptionRequest<'a> {
impl<'a> ClientPacket for CEncryptionRequest<'a> {
fn write(&self, bytebuf: &mut ByteBuffer) {
bytebuf.put_string(self.server_id);
bytebuf.put_var_int(&(self.public_key.len() as VarIntType).into());
bytebuf.put_var_int(&self.public_key_length);
bytebuf.put_slice(self.public_key);
bytebuf.put_var_int(&(self.verify_token.len() as VarIntType).into());
bytebuf.put_var_int(&self.verify_token_length);
bytebuf.put_slice(self.verify_token);
bytebuf.put_bool(self.should_authenticate);
}
Expand Down
5 changes: 1 addition & 4 deletions pumpkin-protocol/src/client/login/c_login_success.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ impl<'a> ClientPacket for CLoginSuccess<'a> {
bytebuf.put_list::<Property>(self.properties, |p, v| {
p.put_string(&v.name);
p.put_string(&v.value);
// has signature ?
// todo: for some reason we get "got too many bytes error when using a signature"
p.put_bool(false);
// p.put_option(&v.signature, |p,v| p.put_string(v));
p.put_option(&v.signature, |p, v| p.put_string(v));
});
bytebuf.put_bool(self.strict_error_handling);
}
Expand Down
31 changes: 31 additions & 0 deletions pumpkin-protocol/src/client/play/c_entity_animation.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use num_derive::ToPrimitive;
use pumpkin_macros::packet;
use serde::Serialize;

use crate::VarInt;

#[derive(Serialize, Clone)]
#[packet(0x03)]
pub struct CEntityAnimation {
entity_id: VarInt,
/// See `Animation`
animation: u8,
}

impl CEntityAnimation {
pub fn new(entity_id: VarInt, animation: u8) -> Self {
Self {
entity_id,
animation,
}
}
}

#[derive(ToPrimitive)]
pub enum Animation {
SwingMainArm,
LeaveBed,
SwingOffhand,
CriticalEffect,
MagicCriticaleffect,
}
33 changes: 33 additions & 0 deletions pumpkin-protocol/src/client/play/c_entity_metadata.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use pumpkin_macros::packet;
use serde::Serialize;

use crate::VarInt;

#[derive(Serialize, Clone)]
#[packet(0x58)]
pub struct CSetEntityMetadata {
entity_id: VarInt,
metadata: Vec<Metadata>,
}

impl CSetEntityMetadata {
pub fn new(entity_id: VarInt, metadata: Vec<Metadata>) -> Self {
Self {
entity_id,
metadata,
}
}
}

#[derive(Serialize, Clone)]
pub struct Metadata {
index: u8,
typ: VarInt,
value: u8,
}

impl Metadata {
pub fn new(index: u8, typ: VarInt, value: u8) -> Self {
Self { index, typ, value }
}
}
42 changes: 5 additions & 37 deletions pumpkin-protocol/src/client/play/c_login.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use pumpkin_macros::packet;
use serde::Serialize;

use crate::{bytebuf::ByteBuffer, ClientPacket, VarInt};
use crate::VarInt;

#[derive(Serialize)]
#[packet(0x2B)]
pub struct CLogin {
entity_id: i32,
Expand All @@ -20,9 +22,7 @@ pub struct CLogin {
previous_gamemode: i8,
debug: bool,
is_flat: bool,
has_death_loc: bool,
death_dimension_name: Option<String>,
death_loc: Option<i64>, // POSITION NOT STRING
death_dimension_name: Option<(String, i64)>, // POSITION NOT STRING
portal_cooldown: VarInt,
enforce_secure_chat: bool,
}
Expand All @@ -46,9 +46,7 @@ impl CLogin {
previous_gamemode: i8,
debug: bool,
is_flat: bool,
has_death_loc: bool,
death_dimension_name: Option<String>,
death_loc: Option<i64>, // todo add block pos
death_dimension_name: Option<(String, i64)>,
portal_cooldown: VarInt,
enforce_secure_chat: bool,
) -> Self {
Expand All @@ -69,39 +67,9 @@ impl CLogin {
previous_gamemode,
debug,
is_flat,
has_death_loc,
death_dimension_name,
death_loc,
portal_cooldown,
enforce_secure_chat,
}
}
}

impl ClientPacket for CLogin {
fn write(&self, bytebuf: &mut ByteBuffer) {
bytebuf.put_i32(self.entity_id);
bytebuf.put_bool(self.is_hardcore);
bytebuf.put_list(&self.dimension_names, |buf, v| buf.put_string(v));
bytebuf.put_var_int(&self.max_players);
bytebuf.put_var_int(&self.view_distance);
bytebuf.put_var_int(&self.simulated_distance);
bytebuf.put_bool(self.reduced_debug_info);
bytebuf.put_bool(self.enabled_respawn_screen);
bytebuf.put_bool(self.limited_crafting);
bytebuf.put_var_int(&self.dimension_type);
bytebuf.put_string(&self.dimension_name);
bytebuf.put_i64(self.hashed_seed);
bytebuf.put_u8(self.game_mode);
bytebuf.put_i8(self.previous_gamemode);
bytebuf.put_bool(self.debug);
bytebuf.put_bool(self.is_flat);
bytebuf.put_bool(self.has_death_loc);
if self.has_death_loc {
bytebuf.put_string(self.death_dimension_name.as_ref().unwrap());
bytebuf.put_i64(self.death_loc.unwrap());
}
bytebuf.put_var_int(&self.portal_cooldown);
bytebuf.put_bool(self.enforce_secure_chat);
}
}
12 changes: 2 additions & 10 deletions pumpkin-protocol/src/client/play/c_player_abilities.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use pumpkin_macros::packet;
use serde::Serialize;

use crate::{bytebuf::ByteBuffer, ClientPacket};

#[derive(Serialize)]
#[packet(0x38)]
pub struct CPlayerAbilities {
flags: i8,
Expand All @@ -18,11 +18,3 @@ impl CPlayerAbilities {
}
}
}

impl ClientPacket for CPlayerAbilities {
fn write(&self, bytebuf: &mut ByteBuffer) {
bytebuf.put_i8(self.flags);
bytebuf.put_f32(self.flying_speed);
bytebuf.put_f32(self.field_of_view);
}
}
70 changes: 70 additions & 0 deletions pumpkin-protocol/src/client/play/c_player_chat_message.rs
Original file line number Diff line number Diff line change
@@ -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 changes: 1 addition & 4 deletions pumpkin-protocol/src/client/play/c_player_info_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ impl<'a> ClientPacket for CPlayerInfoUpdate<'a> {
p.put_list::<Property>(properties, |p, v| {
p.put_string(&v.name);
p.put_string(&v.value);
// has signature ?
// todo: for some reason we get "got too many bytes error when using a signature"
p.put_bool(false);
// todo signature
p.put_option(&v.signature, |p, v| p.put_string(v));
});
}
PlayerAction::InitializeChat(_) => todo!(),
Expand Down
Loading

0 comments on commit 2e31fda

Please sign in to comment.