From 740a98a068e883f2bfa5205977e1c6ab238a955d Mon Sep 17 00:00:00 2001 From: Snowiiii Date: Thu, 15 Aug 2024 16:09:49 +0200 Subject: [PATCH] Handle invalid player commands --- .../src/server/play/s_player_command.rs | 4 +-- pumpkin/src/client/player_packet.rs | 30 +++++++++++-------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/pumpkin-protocol/src/server/play/s_player_command.rs b/pumpkin-protocol/src/server/play/s_player_command.rs index cc364e9fd..e62f9cd05 100644 --- a/pumpkin-protocol/src/server/play/s_player_command.rs +++ b/pumpkin-protocol/src/server/play/s_player_command.rs @@ -7,7 +7,7 @@ use crate::{bytebuf::DeserializerError, ServerPacket, VarInt}; #[packet(0x25)] pub struct SPlayerCommand { pub entitiy_id: VarInt, - pub action: Action, + pub action: VarInt, pub jump_boost: VarInt, } #[derive(FromPrimitive)] @@ -27,7 +27,7 @@ impl ServerPacket for SPlayerCommand { fn read(bytebuf: &mut crate::bytebuf::ByteBuffer) -> Result { Ok(Self { entitiy_id: bytebuf.get_var_int(), - action: Action::from_i32(bytebuf.get_var_int().into()).unwrap(), + action: bytebuf.get_var_int(), jump_boost: bytebuf.get_var_int(), }) } diff --git a/pumpkin/src/client/player_packet.rs b/pumpkin/src/client/player_packet.rs index 4ed9c8df2..579ed460a 100644 --- a/pumpkin/src/client/player_packet.rs +++ b/pumpkin/src/client/player_packet.rs @@ -4,10 +4,10 @@ use pumpkin_inventory::WindowType; use pumpkin_protocol::{ client::play::{ Animation, CEntityAnimation, CEntityVelocity, CHeadRot, CHurtAnimation, COpenScreen, - CUpdateEntityPos, CUpdateEntityPosRot, CUpdateEntityRot, + CSetEntityMetadata, CUpdateEntityPos, CUpdateEntityPosRot, CUpdateEntityRot, Metadata, }, server::play::{ - SChatCommand, SChatMessage, SClientInformationPlay, SConfirmTeleport, SInteract, + Action, SChatCommand, SChatMessage, SClientInformationPlay, SConfirmTeleport, SInteract, SPlayerAction, SPlayerCommand, SPlayerPosition, SPlayerPositionRotation, SPlayerRotation, SSwingArm, }, @@ -17,7 +17,7 @@ use pumpkin_text::TextComponent; use crate::{ commands::{handle_command, CommandSender}, - entity::player::{ChatMode, GameMode, Hand}, + entity::player::{ChatMode, GameMode, Hand, Player}, server::Server, util::math::wrap_degrees, }; @@ -176,16 +176,20 @@ impl Client { return; } - match command.action { - pumpkin_protocol::server::play::Action::StartSneaking => player.sneaking = true, - pumpkin_protocol::server::play::Action::StopSneaking => player.sneaking = false, - pumpkin_protocol::server::play::Action::LeaveBed => todo!(), - pumpkin_protocol::server::play::Action::StartSprinting => player.sprinting = true, - pumpkin_protocol::server::play::Action::StopSprinting => player.sprinting = false, - pumpkin_protocol::server::play::Action::StartHourseJump => todo!(), - pumpkin_protocol::server::play::Action::StopHourseJump => todo!(), - pumpkin_protocol::server::play::Action::OpenVehicleInventory => todo!(), - pumpkin_protocol::server::play::Action::StartFlyingElytra => {}, // TODO + if let Some(action) = Action::from_i32(command.action.0 as i32) { + match action { + pumpkin_protocol::server::play::Action::StartSneaking => player.sneaking = true, + pumpkin_protocol::server::play::Action::StopSneaking => player.sneaking = false, + pumpkin_protocol::server::play::Action::LeaveBed => todo!(), + pumpkin_protocol::server::play::Action::StartSprinting => player.sprinting = true, + pumpkin_protocol::server::play::Action::StopSprinting => player.sprinting = false, + pumpkin_protocol::server::play::Action::StartHourseJump => todo!(), + pumpkin_protocol::server::play::Action::StopHourseJump => todo!(), + pumpkin_protocol::server::play::Action::OpenVehicleInventory => todo!(), + pumpkin_protocol::server::play::Action::StartFlyingElytra => {} // TODO + } + } else { + self.kick("Invalid player command") } }