Handle invalid player commands

This commit is contained in:
Snowiiii 2024-08-15 16:09:49 +02:00
parent eeefd1d51a
commit 740a98a068
2 changed files with 19 additions and 15 deletions

View File

@ -7,7 +7,7 @@ use crate::{bytebuf::DeserializerError, ServerPacket, VarInt};
#[packet(0x25)] #[packet(0x25)]
pub struct SPlayerCommand { pub struct SPlayerCommand {
pub entitiy_id: VarInt, pub entitiy_id: VarInt,
pub action: Action, pub action: VarInt,
pub jump_boost: VarInt, pub jump_boost: VarInt,
} }
#[derive(FromPrimitive)] #[derive(FromPrimitive)]
@ -27,7 +27,7 @@ impl ServerPacket for SPlayerCommand {
fn read(bytebuf: &mut crate::bytebuf::ByteBuffer) -> Result<Self, DeserializerError> { fn read(bytebuf: &mut crate::bytebuf::ByteBuffer) -> Result<Self, DeserializerError> {
Ok(Self { Ok(Self {
entitiy_id: bytebuf.get_var_int(), 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(), jump_boost: bytebuf.get_var_int(),
}) })
} }

View File

@ -4,10 +4,10 @@ use pumpkin_inventory::WindowType;
use pumpkin_protocol::{ use pumpkin_protocol::{
client::play::{ client::play::{
Animation, CEntityAnimation, CEntityVelocity, CHeadRot, CHurtAnimation, COpenScreen, Animation, CEntityAnimation, CEntityVelocity, CHeadRot, CHurtAnimation, COpenScreen,
CUpdateEntityPos, CUpdateEntityPosRot, CUpdateEntityRot, CSetEntityMetadata, CUpdateEntityPos, CUpdateEntityPosRot, CUpdateEntityRot, Metadata,
}, },
server::play::{ server::play::{
SChatCommand, SChatMessage, SClientInformationPlay, SConfirmTeleport, SInteract, Action, SChatCommand, SChatMessage, SClientInformationPlay, SConfirmTeleport, SInteract,
SPlayerAction, SPlayerCommand, SPlayerPosition, SPlayerPositionRotation, SPlayerRotation, SPlayerAction, SPlayerCommand, SPlayerPosition, SPlayerPositionRotation, SPlayerRotation,
SSwingArm, SSwingArm,
}, },
@ -17,7 +17,7 @@ use pumpkin_text::TextComponent;
use crate::{ use crate::{
commands::{handle_command, CommandSender}, commands::{handle_command, CommandSender},
entity::player::{ChatMode, GameMode, Hand}, entity::player::{ChatMode, GameMode, Hand, Player},
server::Server, server::Server,
util::math::wrap_degrees, util::math::wrap_degrees,
}; };
@ -176,7 +176,8 @@ impl Client {
return; return;
} }
match command.action { 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::StartSneaking => player.sneaking = true,
pumpkin_protocol::server::play::Action::StopSneaking => player.sneaking = false, pumpkin_protocol::server::play::Action::StopSneaking => player.sneaking = false,
pumpkin_protocol::server::play::Action::LeaveBed => todo!(), pumpkin_protocol::server::play::Action::LeaveBed => todo!(),
@ -185,7 +186,10 @@ impl Client {
pumpkin_protocol::server::play::Action::StartHourseJump => todo!(), pumpkin_protocol::server::play::Action::StartHourseJump => todo!(),
pumpkin_protocol::server::play::Action::StopHourseJump => todo!(), pumpkin_protocol::server::play::Action::StopHourseJump => todo!(),
pumpkin_protocol::server::play::Action::OpenVehicleInventory => todo!(), pumpkin_protocol::server::play::Action::OpenVehicleInventory => todo!(),
pumpkin_protocol::server::play::Action::StartFlyingElytra => {}, // TODO pumpkin_protocol::server::play::Action::StartFlyingElytra => {} // TODO
}
} else {
self.kick("Invalid player command")
} }
} }