diff --git a/pumpkin-protocol/src/client/play/c_ping_response.rs b/pumpkin-protocol/src/client/play/c_ping_response.rs new file mode 100644 index 000000000..f8f58e9a9 --- /dev/null +++ b/pumpkin-protocol/src/client/play/c_ping_response.rs @@ -0,0 +1,14 @@ +use pumpkin_macros::packet; +use serde::Serialize; + +#[derive(Serialize)] +#[packet(0x36)] +pub struct CPingResponse { + payload: i64, +} + +impl CPingResponse { + pub fn new(payload: i64) -> Self { + Self { payload } + } +} diff --git a/pumpkin-protocol/src/client/play/mod.rs b/pumpkin-protocol/src/client/play/mod.rs index 1a07061f6..2ff20e4c0 100644 --- a/pumpkin-protocol/src/client/play/mod.rs +++ b/pumpkin-protocol/src/client/play/mod.rs @@ -15,6 +15,7 @@ mod c_hurt_animation; mod c_login; mod c_open_screen; mod c_particle; +mod c_ping_response; mod c_play_disconnect; mod c_player_abilities; mod c_player_chat_message; @@ -50,6 +51,7 @@ pub use c_hurt_animation::*; pub use c_login::*; pub use c_open_screen::*; pub use c_particle::*; +pub use c_ping_response::*; pub use c_play_disconnect::*; pub use c_player_abilities::*; pub use c_player_chat_message::*; diff --git a/pumpkin-protocol/src/server/play/mod.rs b/pumpkin-protocol/src/server/play/mod.rs index b218e1e10..c29a11775 100644 --- a/pumpkin-protocol/src/server/play/mod.rs +++ b/pumpkin-protocol/src/server/play/mod.rs @@ -3,6 +3,7 @@ mod s_chat_message; mod s_client_information; mod s_confirm_teleport; mod s_interact; +mod s_ping_request; mod s_player_action; mod s_player_command; mod s_player_position; @@ -18,6 +19,7 @@ pub use s_chat_message::*; pub use s_client_information::*; pub use s_confirm_teleport::*; pub use s_interact::*; +pub use s_ping_request::*; pub use s_player_action::*; pub use s_player_command::*; pub use s_player_position::*; diff --git a/pumpkin-protocol/src/server/play/s_ping_request.rs b/pumpkin-protocol/src/server/play/s_ping_request.rs new file mode 100644 index 000000000..1da4e4b45 --- /dev/null +++ b/pumpkin-protocol/src/server/play/s_ping_request.rs @@ -0,0 +1,8 @@ +use pumpkin_macros::packet; +use serde::Deserialize; + +#[derive(Deserialize)] +#[packet(0x21)] +pub struct SPlayPingRequest { + pub payload: i64, +} diff --git a/pumpkin-protocol/src/server/status/s_ping_request.rs b/pumpkin-protocol/src/server/status/s_ping_request.rs index c73f8536a..172814d68 100644 --- a/pumpkin-protocol/src/server/status/s_ping_request.rs +++ b/pumpkin-protocol/src/server/status/s_ping_request.rs @@ -2,6 +2,6 @@ use pumpkin_macros::packet; #[derive(serde::Deserialize)] #[packet(0x01)] -pub struct SPingRequest { +pub struct SStatusPingRequest { pub payload: i64, } diff --git a/pumpkin/src/client/client_packet.rs b/pumpkin/src/client/client_packet.rs index a80e17a41..7be9a4d1d 100644 --- a/pumpkin/src/client/client_packet.rs +++ b/pumpkin/src/client/client_packet.rs @@ -9,7 +9,7 @@ use pumpkin_protocol::{ config::{SAcknowledgeFinishConfig, SClientInformationConfig, SKnownPacks, SPluginMessage}, handshake::SHandShake, login::{SEncryptionResponse, SLoginAcknowledged, SLoginPluginResponse, SLoginStart}, - status::{SPingRequest, SStatusRequest}, + status::{SStatusPingRequest, SStatusRequest}, }, ConnectionState, KnownPack, CURRENT_MC_PROTOCOL, }; @@ -54,7 +54,7 @@ impl Client { self.send_packet(&CStatusResponse::new(&server.status_response_json)); } - pub fn handle_ping_request(&mut self, _server: &mut Server, ping_request: SPingRequest) { + pub fn handle_ping_request(&mut self, _server: &mut Server, ping_request: SStatusPingRequest) { dbg!("ping"); self.send_packet(&CPingResponse::new(ping_request.payload)); self.close(); diff --git a/pumpkin/src/client/mod.rs b/pumpkin/src/client/mod.rs index d92cc25c2..837976873 100644 --- a/pumpkin/src/client/mod.rs +++ b/pumpkin/src/client/mod.rs @@ -28,10 +28,11 @@ use pumpkin_protocol::{ login::{SEncryptionResponse, SLoginAcknowledged, SLoginPluginResponse, SLoginStart}, play::{ SChatCommand, SChatMessage, SClientInformationPlay, SConfirmTeleport, SInteract, - SPlayerAction, SPlayerCommand, SPlayerPosition, SPlayerPositionRotation, - SPlayerRotation, SSetCreativeSlot, SSetHeldItem, SSwingArm, SUseItemOn, + SPlayPingRequest, SPlayerAction, SPlayerCommand, SPlayerPosition, + SPlayerPositionRotation, SPlayerRotation, SSetCreativeSlot, SSetHeldItem, SSwingArm, + SUseItemOn, }, - status::{SPingRequest, SStatusRequest}, + status::{SStatusPingRequest, SStatusRequest}, }, ClientPacket, ConnectionState, PacketError, RawPacket, ServerPacket, }; @@ -201,8 +202,8 @@ impl Client { SStatusRequest::PACKET_ID => { self.handle_status_request(server, SStatusRequest::read(bytebuf).unwrap()) } - SPingRequest::PACKET_ID => { - self.handle_ping_request(server, SPingRequest::read(bytebuf).unwrap()) + SStatusPingRequest::PACKET_ID => { + self.handle_ping_request(server, SStatusPingRequest::read(bytebuf).unwrap()) } _ => log::error!( "Failed to handle packet id {} while in Status state", @@ -307,6 +308,9 @@ impl Client { SSetCreativeSlot::PACKET_ID => { self.handle_set_creative_slot(server, SSetCreativeSlot::read(bytebuf).unwrap()) } + SPlayPingRequest::PACKET_ID => { + self.handle_play_ping_request(server, SPlayPingRequest::read(bytebuf).unwrap()) + } _ => log::error!("Failed to handle player packet id {}", packet.id.0), } } diff --git a/pumpkin/src/client/player_packet.rs b/pumpkin/src/client/player_packet.rs index c6fefe0d3..bd040469d 100644 --- a/pumpkin/src/client/player_packet.rs +++ b/pumpkin/src/client/player_packet.rs @@ -11,14 +11,15 @@ use pumpkin_entity::EntityId; use pumpkin_protocol::{ client::play::{ Animation, CAcknowledgeBlockChange, CBlockUpdate, CEntityAnimation, CEntityVelocity, - CHeadRot, CHurtAnimation, CPlayerChatMessage, CUpdateEntityPos, CUpdateEntityPosRot, - CUpdateEntityRot, CWorldEvent, FilterType, + CHeadRot, CHurtAnimation, CPingResponse, CPlayerChatMessage, CUpdateEntityPos, + CUpdateEntityPosRot, CUpdateEntityRot, CWorldEvent, FilterType, }, position::WorldPosition, server::play::{ Action, ActionType, SChatCommand, SChatMessage, SClientInformationPlay, SConfirmTeleport, - SInteract, SPlayerAction, SPlayerCommand, SPlayerPosition, SPlayerPositionRotation, - SPlayerRotation, SSetCreativeSlot, SSetHeldItem, SSwingArm, SUseItemOn, Status, + SInteract, SPlayPingRequest, SPlayerAction, SPlayerCommand, SPlayerPosition, + SPlayerPositionRotation, SPlayerRotation, SSetCreativeSlot, SSetHeldItem, SSwingArm, + SUseItemOn, Status, }, }; use pumpkin_text::TextComponent; @@ -361,6 +362,10 @@ impl Client { } } + pub fn handle_play_ping_request(&mut self, _server: &mut Server, request: SPlayPingRequest) { + self.send_packet(&CPingResponse::new(request.payload)); + } + pub fn handle_use_item_on(&mut self, server: &mut Server, use_item_on: SUseItemOn) { self.send_packet(&CAcknowledgeBlockChange::new(use_item_on.sequence));