Add Play Ping/Pong
Used for Debug, F3+3
This commit is contained in:
parent
5122097d0d
commit
938a415f77
14
pumpkin-protocol/src/client/play/c_ping_response.rs
Normal file
14
pumpkin-protocol/src/client/play/c_ping_response.rs
Normal file
@ -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 }
|
||||
}
|
||||
}
|
||||
@ -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::*;
|
||||
|
||||
@ -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::*;
|
||||
|
||||
8
pumpkin-protocol/src/server/play/s_ping_request.rs
Normal file
8
pumpkin-protocol/src/server/play/s_ping_request.rs
Normal file
@ -0,0 +1,8 @@
|
||||
use pumpkin_macros::packet;
|
||||
use serde::Deserialize;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[packet(0x21)]
|
||||
pub struct SPlayPingRequest {
|
||||
pub payload: i64,
|
||||
}
|
||||
@ -2,6 +2,6 @@ use pumpkin_macros::packet;
|
||||
|
||||
#[derive(serde::Deserialize)]
|
||||
#[packet(0x01)]
|
||||
pub struct SPingRequest {
|
||||
pub struct SStatusPingRequest {
|
||||
pub payload: i64,
|
||||
}
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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),
|
||||
}
|
||||
}
|
||||
|
||||
@ -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));
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user