Handle player packet id 0x23

This commit is contained in:
Stefano committed 2024-10-20 20:59:35 +02:00
1 parent b7ac8ade39
commit 74e58caab1
5 files changed
+34 -15

No files matched your search

+1 -3
View File
@@ -77,9 +77,7 @@ Cargo.lock
# === PROJECT SPECIFIC === # === PROJECT SPECIFIC ===
# mc decompiled source # mc decompiled source
mc-source-code/DecompilerMC/ mc-source-code/
mc-source-code/src/
mc-source-code/target/
plugins/* plugins/*
world/* world/*
+2
View File
@@ -7,6 +7,7 @@ mod s_confirm_teleport;
mod s_interact; mod s_interact;
mod s_keep_alive; mod s_keep_alive;
mod s_ping_request; mod s_ping_request;
mod s_player_abilities;
mod s_player_action; mod s_player_action;
mod s_player_command; mod s_player_command;
mod s_player_ground; mod s_player_ground;
@@ -28,6 +29,7 @@ pub use s_confirm_teleport::*;
pub use s_interact::*; pub use s_interact::*;
pub use s_keep_alive::*; pub use s_keep_alive::*;
pub use s_ping_request::*; pub use s_ping_request::*;
pub use s_player_abilities::*;
pub use s_player_action::*; pub use s_player_action::*;
pub use s_player_command::*; pub use s_player_command::*;
pub use s_player_ground::*; pub use s_player_ground::*;
@@ -0,0 +1,10 @@
use pumpkin_macros::packet;
use serde::Deserialize;
//The vanilla client sends this packet when the player starts/stops flying. Bitmask 0x02 is set when the player is flying.
#[derive(Deserialize)]
#[packet(0x23)]
pub struct SPlayerAbilities {
pub flags: i8,
}
+12 -5
View File
@@ -15,7 +15,6 @@ use pumpkin_core::{
}; };
use pumpkin_entity::EntityId; use pumpkin_entity::EntityId;
use pumpkin_inventory::{InventoryError, WindowType}; use pumpkin_inventory::{InventoryError, WindowType};
use pumpkin_protocol::server::play::{SCloseContainer, SSetPlayerGround, SUseItem};
use pumpkin_protocol::{ use pumpkin_protocol::{
client::play::{ client::play::{
Animation, CAcknowledgeBlockChange, CBlockUpdate, CEntityAnimation, CEntityVelocity, Animation, CAcknowledgeBlockChange, CBlockUpdate, CEntityAnimation, CEntityVelocity,
@@ -23,10 +22,10 @@ use pumpkin_protocol::{
CUpdateEntityPosRot, CUpdateEntityRot, CWorldEvent, FilterType, CUpdateEntityPosRot, CUpdateEntityRot, CWorldEvent, FilterType,
}, },
server::play::{ server::play::{
Action, ActionType, SChatCommand, SChatMessage, SClientInformationPlay, SConfirmTeleport, Action, ActionType, SChatCommand, SChatMessage, SClientInformationPlay, SCloseContainer,
SInteract, SPlayPingRequest, SPlayerAction, SPlayerCommand, SPlayerPosition, SConfirmTeleport, SInteract, SPlayPingRequest, SPlayerAbilities, SPlayerAction,
SPlayerPositionRotation, SPlayerRotation, SSetCreativeSlot, SSetHeldItem, SSwingArm, SPlayerCommand, SPlayerPosition, SPlayerPositionRotation, SPlayerRotation,
SUseItemOn, Status, SSetCreativeSlot, SSetHeldItem, SSetPlayerGround, SSwingArm, SUseItem, SUseItemOn, Status,
}, },
}; };
use pumpkin_world::block::{BlockFace, BlockState}; use pumpkin_world::block::{BlockFace, BlockState};
@@ -468,6 +467,7 @@ impl Player {
None => self.kick(TextComponent::text("Invalid action type")).await, None => self.kick(TextComponent::text("Invalid action type")).await,
} }
} }
pub async fn handle_player_action(&self, player_action: SPlayerAction) { pub async fn handle_player_action(&self, player_action: SPlayerAction) {
match Status::from_i32(player_action.status.0) { match Status::from_i32(player_action.status.0) {
Some(status) => match status { Some(status) => match status {
@@ -541,6 +541,13 @@ impl Player {
} }
} }
pub async fn handle_player_abilities(&self, player_abilities: SPlayerAbilities) {
let mut abilities = self.abilities.lock().await;
// Set the flying ability
abilities.flying = player_abilities.flags & 0x02 != 0 && abilities.allow_flying;
}
pub async fn handle_play_ping_request(&self, request: SPlayPingRequest) { pub async fn handle_play_ping_request(&self, request: SPlayPingRequest) {
self.client self.client
.send_packet(&CPingResponse::new(request.payload)) .send_packet(&CPingResponse::new(request.payload))
+9 -7
View File
@@ -20,10 +20,7 @@ use pumpkin_protocol::{
CSyncPlayerPosition, CSystemChatMessage, GameEvent, PlayerAction, CSyncPlayerPosition, CSystemChatMessage, GameEvent, PlayerAction,
}, },
server::play::{ server::play::{
SChatCommand, SChatMessage, SClickContainer, SClientInformationPlay, SConfirmTeleport, SChatCommand, SChatMessage, SClickContainer, SClientInformationPlay, SConfirmTeleport, SInteract, SPlayPingRequest, SPlayerAbilities, SPlayerAction, SPlayerCommand, SPlayerPosition, SPlayerPositionRotation, SPlayerRotation, SSetCreativeSlot, SSetHeldItem, SSetPlayerGround, SSwingArm, SUseItem, SUseItemOn
SInteract, SPlayPingRequest, SPlayerAction, SPlayerCommand, SPlayerPosition,
SPlayerPositionRotation, SPlayerRotation, SSetCreativeSlot, SSetHeldItem, SSetPlayerGround,
SSwingArm, SUseItem, SUseItemOn,
}, },
RawPacket, ServerPacket, VarInt, RawPacket, ServerPacket, VarInt,
}; };
@@ -73,7 +70,7 @@ pub struct Player {
/// This field represents the various abilities that the player possesses, such as flight, invulnerability, and other special effects. /// This field represents the various abilities that the player possesses, such as flight, invulnerability, and other special effects.
/// ///
/// **Note:** When the `abilities` field is updated, the server should send a `send_abilities_update` packet to the client to notify them of the changes. /// **Note:** When the `abilities` field is updated, the server should send a `send_abilities_update` packet to the client to notify them of the changes.
pub abilities: PlayerAbilities, pub abilities: Mutex<PlayerAbilities>,
/// The player's last known position. /// The player's last known position.
/// ///
/// This field is used to calculate the player's movement delta for network synchronization and other purposes. /// This field is used to calculate the player's movement delta for network synchronization and other purposes.
@@ -129,7 +126,7 @@ impl Player {
open_container: AtomicCell::new(None), open_container: AtomicCell::new(None),
carried_item: AtomicCell::new(None), carried_item: AtomicCell::new(None),
teleport_id_count: AtomicI32::new(0), teleport_id_count: AtomicI32::new(0),
abilities: PlayerAbilities::default(), abilities: Mutex::new(PlayerAbilities::default()),
gamemode: AtomicCell::new(gamemode), gamemode: AtomicCell::new(gamemode),
watched_section: AtomicCell::new(Vector3::new(0, 0, 0)), watched_section: AtomicCell::new(Vector3::new(0, 0, 0)),
last_position: AtomicCell::new(Vector3::new(0.0, 0.0, 0.0)), last_position: AtomicCell::new(Vector3::new(0.0, 0.0, 0.0)),
@@ -157,7 +154,7 @@ impl Player {
/// Updates the current abilities the Player has /// Updates the current abilities the Player has
pub async fn send_abilties_update(&mut self) { pub async fn send_abilties_update(&mut self) {
let mut b = 0i8; let mut b = 0i8;
let abilities = &self.abilities; let abilities = &self.abilities.lock().await;
if abilities.invulnerable { if abilities.invulnerable {
b |= 1; b |= 1;
@@ -379,6 +376,11 @@ impl Player {
.await; .await;
Ok(()) Ok(())
} }
SPlayerAbilities::PACKET_ID => {
self.handle_player_abilities(SPlayerAbilities::read(bytebuf)?)
.await;
Ok(())
}
SUseItemOn::PACKET_ID => { SUseItemOn::PACKET_ID => {
self.handle_use_item_on(SUseItemOn::read(bytebuf)?).await; self.handle_use_item_on(SUseItemOn::read(bytebuf)?).await;
Ok(()) Ok(())