Skip to content

Commit

Permalink
Handle invalid player commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Snowiiii committed Aug 15, 2024
1 parent eeefd1d commit 740a98a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
4 changes: 2 additions & 2 deletions pumpkin-protocol/src/server/play/s_player_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -27,7 +27,7 @@ impl ServerPacket for SPlayerCommand {
fn read(bytebuf: &mut crate::bytebuf::ByteBuffer) -> Result<Self, DeserializerError> {
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(),
})
}
Expand Down
30 changes: 17 additions & 13 deletions pumpkin/src/client/player_packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand All @@ -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,
};
Expand Down Expand Up @@ -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")
}
}

Expand Down

0 comments on commit 740a98a

Please sign in to comment.