Rename packets

Use yarn packet names (with some exceptions) for better consistency. We should also avoid using Mojang names for things in the future.
This commit is contained in:
Ryan 2022-07-29 04:49:08 -07:00
parent c8fe351dd3
commit 959e2b2deb
7 changed files with 303 additions and 295 deletions

View file

@ -18,8 +18,8 @@ use valence::protocol::packets::login::c2s::{EncryptionResponse, LoginStart};
use valence::protocol::packets::login::s2c::{LoginSuccess, S2cLoginPacket};
use valence::protocol::packets::play::c2s::C2sPlayPacket;
use valence::protocol::packets::play::s2c::S2cPlayPacket;
use valence::protocol::packets::status::c2s::{PingRequest, StatusRequest};
use valence::protocol::packets::status::s2c::{PongResponse, StatusResponse};
use valence::protocol::packets::status::c2s::{QueryPing, QueryRequest};
use valence::protocol::packets::status::s2c::{QueryPong, QueryResponse};
use valence::protocol::packets::{DecodePacket, EncodePacket};
use valence::protocol::{Encode, VarInt};
@ -121,14 +121,14 @@ async fn handle_connection(client: TcpStream, cli: Cli) -> anyhow::Result<()> {
match handshake.next_state {
HandshakeNextState::Status => {
cli.rw_packet::<StatusRequest>(&mut client_read, &mut server_write)
cli.rw_packet::<QueryRequest>(&mut client_read, &mut server_write)
.await?;
cli.rw_packet::<StatusResponse>(&mut server_read, &mut client_write)
cli.rw_packet::<QueryResponse>(&mut server_read, &mut client_write)
.await?;
cli.rw_packet::<PingRequest>(&mut client_read, &mut server_write)
cli.rw_packet::<QueryPing>(&mut client_read, &mut server_write)
.await?;
cli.rw_packet::<PongResponse>(&mut server_read, &mut client_write)
cli.rw_packet::<QueryPong>(&mut server_read, &mut client_write)
.await?;
}
HandshakeNextState::Login => {
@ -150,7 +150,7 @@ async fn handle_connection(client: TcpStream, cli: Cli) -> anyhow::Result<()> {
s2c = passthrough(server_read.into_inner(), client_write) => s2c,
};
}
S2cLoginPacket::SetCompression(pkt) => {
S2cLoginPacket::LoginCompression(pkt) => {
let threshold = pkt.threshold.0 as u32;
client_read.enable_compression(threshold);
server_read.enable_compression(threshold);
@ -159,7 +159,7 @@ async fn handle_connection(client: TcpStream, cli: Cli) -> anyhow::Result<()> {
.await?;
}
S2cLoginPacket::LoginSuccess(_) => {}
S2cLoginPacket::Disconnect(_) => return Ok(()),
S2cLoginPacket::LoginDisconnect(_) => return Ok(()),
S2cLoginPacket::LoginPluginRequest(_) => {
bail!("got login plugin request. Don't know how to proceed.")
}

View file

@ -18,7 +18,7 @@ pub use crate::chunk_pos::ChunkPos;
use crate::config::Config;
use crate::dimension::DimensionId;
use crate::protocol_inner::packets::play::s2c::{
BlockUpdate, LevelChunkHeightmaps, LevelChunkWithLight, S2cPlayPacket, SectionBlocksUpdate,
BlockUpdate, ChunkDataHeightmaps, ChunkData, S2cPlayPacket, ChunkSectionUpdate,
};
use crate::protocol_inner::{Encode, Nbt, VarInt, VarLong};
use crate::server::SharedServer;
@ -272,17 +272,17 @@ impl<C: Config> Chunk<C> {
/// Gets the chunk data packet for this chunk with the given position. This
/// does not include unapplied changes.
pub(crate) fn chunk_data_packet(&self, pos: ChunkPos) -> LevelChunkWithLight {
pub(crate) fn chunk_data_packet(&self, pos: ChunkPos) -> ChunkData {
let mut blocks_and_biomes = Vec::new();
for sect in self.sections.iter() {
blocks_and_biomes.extend_from_slice(&sect.compact_data);
}
LevelChunkWithLight {
ChunkData {
chunk_x: pos.x,
chunk_z: pos.z,
heightmaps: Nbt(LevelChunkHeightmaps {
heightmaps: Nbt(ChunkDataHeightmaps {
motion_blocking: self.heightmap.clone(),
}),
blocks_and_biomes,
@ -346,7 +346,7 @@ impl<C: Config> Chunk<C> {
| (pos.z as i64 & 0x3fffff) << 20
| (sect_y as i64 + min_y.div_euclid(16) as i64) & 0xfffff;
packet(BlockChangePacket::Multi(SectionBlocksUpdate {
packet(BlockChangePacket::Multi(ChunkSectionUpdate {
chunk_section_position,
invert_trust_edges: false,
blocks,
@ -407,7 +407,7 @@ impl<C: Config> Chunk<C> {
#[derive(Clone, Debug)]
pub(crate) enum BlockChangePacket {
Single(BlockUpdate),
Multi(SectionBlocksUpdate),
Multi(ChunkSectionUpdate),
}
impl From<BlockChangePacket> for S2cPlayPacket {

View file

@ -25,16 +25,16 @@ use crate::player_textures::SignedPlayerTextures;
use crate::protocol_inner::packets::play::c2s::{
C2sPlayPacket, DiggingStatus, InteractKind, PlayerCommandId,
};
pub use crate::protocol_inner::packets::play::s2c::SetTitleAnimationTimes as TitleAnimationTimes;
pub use crate::protocol_inner::packets::play::s2c::TitleAnimationTimes as TitleAnimationTimes;
use crate::protocol_inner::packets::play::s2c::{
Animate, BiomeRegistry, BlockChangeAck, ChatType, ChatTypeChat, ChatTypeNarration,
EntityAnimation, BiomeRegistry, PlayerActionResponse, ChatType, ChatTypeChat, ChatTypeNarration,
ChatTypeRegistry, ChatTypeRegistryEntry, ClearTitles, DimensionTypeRegistry,
DimensionTypeRegistryEntry, Disconnect, EntityStatus, ForgetLevelChunk, GameEvent,
GameEventReason, KeepAlive, Login, MoveEntityPosition, MoveEntityPositionAndRotation,
MoveEntityRotation, PlayerPosition, PlayerPositionFlags, RegistryCodec, RemoveEntities,
Respawn, RotateHead, S2cPlayPacket, SetChunkCacheCenter, SetChunkCacheRadius,
SetEntityMetadata, SetEntityMotion, SetSubtitleText, SetTitleText, SpawnPosition, SystemChat,
TeleportEntity, UpdateAttributes, UpdateAttributesProperty,
DimensionTypeRegistryEntry, Disconnect, EntityStatus, UnloadChunk, GameStateChange,
GameStateChangeReason, KeepAlive, GameJoin, MoveRelative, RotateAndMoveRelative,
Rotate, PlayerPositionLook, PlayerPositionLookFlags, RegistryCodec, EntitiesDestroy,
PlayerRespawn, EntitySetHeadYaw, S2cPlayPacket, ChunkRenderDistanceCenter, ChunkLoadDistance,
EntityTrackerUpdate, EntityVelocityUpdate, UpdateSubtitle, UpdateTitle, PlayerSpawnPosition, GameMessage,
EntityPosition, EntityAttributes, EntityAttributesProperty,
};
use crate::protocol_inner::{BoundedInt, ByteAngle, Nbt, RawBytes, VarInt};
use crate::server::{C2sPacketChannels, NewClientData, SharedServer};
@ -460,10 +460,10 @@ impl<C: Config> Client<C> {
let title = title.into();
let subtitle = subtitle.into();
self.send_packet(SetTitleText { text: title });
self.send_packet(UpdateTitle { text: title });
if !subtitle.is_empty() {
self.send_packet(SetSubtitleText {
self.send_packet(UpdateSubtitle {
subtitle_text: subtitle,
});
}
@ -565,7 +565,7 @@ impl<C: Config> Client<C> {
}
/// Gets if hardcore mode is enabled.
pub fn is_hardcore(&mut self) -> bool {
pub fn is_hardcore(&self) -> bool {
self.flags.hardcore()
}
@ -669,7 +669,7 @@ impl<C: Config> Client<C> {
}
match pkt {
C2sPlayPacket::AcceptTeleportation(p) => {
C2sPlayPacket::TeleportConfirm(p) => {
if self.pending_teleports == 0 {
log::warn!("unexpected teleport confirmation from {}", self.username());
self.disconnect_no_reason();
@ -691,16 +691,16 @@ impl<C: Config> Client<C> {
self.disconnect_no_reason();
}
}
C2sPlayPacket::BlockEntityTagQuery(_) => {}
C2sPlayPacket::ChangeDifficulty(_) => {}
C2sPlayPacket::ChatCommand(_) => {}
C2sPlayPacket::Chat(p) => self.events.push_back(Event::ChatMessage {
C2sPlayPacket::QueryBlockNbt(_) => {}
C2sPlayPacket::UpdateDifficulty(_) => {}
C2sPlayPacket::CommandExecution(_) => {}
C2sPlayPacket::ChatMessage(p) => self.events.push_back(Event::ChatMessage {
message: p.message.0,
timestamp: Duration::from_millis(p.timestamp),
}),
C2sPlayPacket::ChatPreview(_) => {}
C2sPlayPacket::ClientCommand(_) => {}
C2sPlayPacket::ClientInformation(p) => {
C2sPlayPacket::RequestChatPreview(_) => {}
C2sPlayPacket::ClientStatus(_) => {}
C2sPlayPacket::ClientSettings(p) => {
let old = self.settings.replace(Settings {
locale: p.locale.0,
view_distance: p.view_distance.0,
@ -713,13 +713,14 @@ impl<C: Config> Client<C> {
self.events.push_back(Event::SettingsChanged(old));
}
C2sPlayPacket::CommandSuggestion(_) => {}
C2sPlayPacket::ContainerButtonClick(_) => {}
C2sPlayPacket::ContainerClose(_) => {}
C2sPlayPacket::RequestCommandCompletion(_) => {}
C2sPlayPacket::ButtonClick(_) => {}
C2sPlayPacket::ClickSlot(_) => {}
C2sPlayPacket::CloseHandledScreen(_) => {}
C2sPlayPacket::CustomPayload(_) => {}
C2sPlayPacket::EditBook(_) => {}
C2sPlayPacket::EntityTagQuery(_) => {}
C2sPlayPacket::Interact(p) => {
C2sPlayPacket::BookUpdate(_) => {}
C2sPlayPacket::QueryEntityNbt(_) => {}
C2sPlayPacket::PlayerInteractEntity(p) => {
if let Some(id) = entities.get_with_network_id(p.entity_id.0) {
// TODO: verify that the client has line of sight to the targeted entity and
// that the distance is <=4 blocks.
@ -755,7 +756,7 @@ impl<C: Config> Client<C> {
self.flags.set_got_keepalive(true);
}
}
C2sPlayPacket::LockDifficulty(_) => {}
C2sPlayPacket::UpdateDifficultyLock(_) => {}
C2sPlayPacket::MovePlayerPosition(p) => {
handle_movement_packet(self, false, p.position, self.yaw, self.pitch, p.on_ground)
}
@ -765,7 +766,7 @@ impl<C: Config> Client<C> {
C2sPlayPacket::MovePlayerRotation(p) => {
handle_movement_packet(self, false, self.new_position, p.yaw, p.pitch, p.on_ground)
}
C2sPlayPacket::MovePlayerStatusOnly(p) => handle_movement_packet(
C2sPlayPacket::MovePlayerOnGround(p) => handle_movement_packet(
self,
false,
self.new_position,
@ -783,15 +784,15 @@ impl<C: Config> Client<C> {
self.flags.on_ground(),
);
}
C2sPlayPacket::PaddleBoat(p) => {
C2sPlayPacket::BoatPaddleState(p) => {
self.events.push_back(Event::SteerBoat {
left_paddle_turning: p.left_paddle_turning,
right_paddle_turning: p.right_paddle_turning,
});
}
C2sPlayPacket::PickItem(_) => {}
C2sPlayPacket::PlaceRecipe(_) => {}
C2sPlayPacket::PlayerAbilities(_) => {}
C2sPlayPacket::PickFromInventory(_) => {}
C2sPlayPacket::CraftRequest(_) => {}
C2sPlayPacket::UpdatePlayerAbilities(_) => {}
C2sPlayPacket::PlayerAction(p) => {
// TODO: verify dug block is within the correct distance from the client.
// TODO: verify that the broken block is allowed to be broken?
@ -875,25 +876,25 @@ impl<C: Config> Client<C> {
});
}
C2sPlayPacket::PlayerInput(_) => {}
C2sPlayPacket::Pong(_) => {}
C2sPlayPacket::PlayPong(_) => {}
C2sPlayPacket::RecipeBookChangeSettings(_) => {}
C2sPlayPacket::RecipeBookSeenRecipe(_) => {}
C2sPlayPacket::RenameItem(_) => {}
C2sPlayPacket::ResourcePack(_) => {}
C2sPlayPacket::SeenAdvancements(_) => {}
C2sPlayPacket::SelectTrade(_) => {}
C2sPlayPacket::SetBeacon(_) => {}
C2sPlayPacket::SetCarriedItem(_) => {}
C2sPlayPacket::SetCommandBlock(_) => {}
C2sPlayPacket::SetCommandBlockMinecart(_) => {}
C2sPlayPacket::SetCreativeModeSlot(_) => {}
C2sPlayPacket::SetJigsawBlock(_) => {}
C2sPlayPacket::SetStructureBlock(_) => {}
C2sPlayPacket::SignUpdate(_) => {}
C2sPlayPacket::Swing(p) => self.events.push_back(Event::ArmSwing(p.hand)),
C2sPlayPacket::TeleportToEntity(_) => {}
C2sPlayPacket::UseItemOn(_) => {}
C2sPlayPacket::UseItem(_) => {}
C2sPlayPacket::ResourcePackStatus(_) => {}
C2sPlayPacket::AdvancementTab(_) => {}
C2sPlayPacket::SelectMerchantTrade(_) => {}
C2sPlayPacket::UpdateBeacon(_) => {}
C2sPlayPacket::UpdateSelectedSlot(_) => {}
C2sPlayPacket::UpdateCommandBlock(_) => {}
C2sPlayPacket::UpdateCommandBlockMinecart(_) => {}
C2sPlayPacket::UpdateCreativeModeSlot(_) => {}
C2sPlayPacket::UpdateJigsaw(_) => {}
C2sPlayPacket::UpdateStructureBlock(_) => {}
C2sPlayPacket::UpdateSign(_) => {}
C2sPlayPacket::HandSwing(p) => self.events.push_back(Event::ArmSwing(p.hand)),
C2sPlayPacket::SpectatorTeleport(_) => {}
C2sPlayPacket::PlayerInteractBlock(_) => {}
C2sPlayPacket::PlayerInteractItem(_) => {}
}
}
@ -938,7 +939,7 @@ impl<C: Config> Client<C> {
dimension_names.push(ident!("{LIBRARY_NAMESPACE}:dummy_dimension"));
self.send_packet(Login {
self.send_packet(GameJoin {
entity_id: 0, // EntityId 0 is reserved for clients.
is_hardcore: self.flags.hardcore(),
gamemode: self.new_game_mode,
@ -976,7 +977,7 @@ impl<C: Config> Client<C> {
// TODO: clear player list.
// Client bug workaround: send the client to a dummy dimension first.
self.send_packet(Respawn {
self.send_packet(PlayerRespawn {
dimension_type_name: ident!("{LIBRARY_NAMESPACE}:dimension_type_0"),
dimension_name: ident!("{LIBRARY_NAMESPACE}:dummy_dimension"),
hashed_seed: 0,
@ -988,7 +989,7 @@ impl<C: Config> Client<C> {
last_death_location: None,
});
self.send_packet(Respawn {
self.send_packet(PlayerRespawn {
dimension_type_name: ident!(
"{LIBRARY_NAMESPACE}:dimension_type_{}",
world.meta.dimension().0
@ -1013,8 +1014,8 @@ impl<C: Config> Client<C> {
if self.old_game_mode != self.new_game_mode {
self.old_game_mode = self.new_game_mode;
self.send_packet(GameEvent {
reason: GameEventReason::ChangeGameMode,
self.send_packet(GameStateChange {
reason: GameStateChangeReason::ChangeGameMode,
value: self.new_game_mode as i32 as f32,
});
}
@ -1029,9 +1030,9 @@ impl<C: Config> Client<C> {
if self.flags.attack_speed_modified() {
self.flags.set_attack_speed_modified(false);
self.send_packet(UpdateAttributes {
self.send_packet(EntityAttributes {
entity_id: VarInt(0),
properties: vec![UpdateAttributesProperty {
properties: vec![EntityAttributesProperty {
key: ident!("generic.attack_speed"),
value: self.attack_speed,
modifiers: Vec::new(),
@ -1042,9 +1043,9 @@ impl<C: Config> Client<C> {
if self.flags.movement_speed_modified() {
self.flags.set_movement_speed_modified(false);
self.send_packet(UpdateAttributes {
self.send_packet(EntityAttributes {
entity_id: VarInt(0),
properties: vec![UpdateAttributesProperty {
properties: vec![EntityAttributesProperty {
key: ident!("generic.movement_speed"),
value: self.movement_speed,
modifiers: Vec::new(),
@ -1056,7 +1057,7 @@ impl<C: Config> Client<C> {
if self.flags.modified_spawn_position() {
self.flags.set_modified_spawn_position(false);
self.send_packet(SpawnPosition {
self.send_packet(PlayerSpawnPosition {
location: self.spawn_position,
angle: self.spawn_position_yaw,
})
@ -1066,7 +1067,7 @@ impl<C: Config> Client<C> {
if self.old_max_view_distance != self.new_max_view_distance {
self.old_max_view_distance = self.new_max_view_distance;
if self.created_tick != current_tick {
self.send_packet(SetChunkCacheRadius {
self.send_packet(ChunkLoadDistance {
view_distance: BoundedInt(VarInt(self.new_max_view_distance as i32)),
})
}
@ -1099,7 +1100,7 @@ impl<C: Config> Client<C> {
let new_section = self.new_position.map(|n| (n / 16.0).floor() as i32);
if old_section != new_section {
self.send_packet(SetChunkCacheCenter {
self.send_packet(ChunkRenderDistanceCenter {
chunk_x: VarInt(new_section.x),
chunk_z: VarInt(new_section.z),
})
@ -1128,7 +1129,7 @@ impl<C: Config> Client<C> {
send_packet(
&mut self.send,
ForgetLevelChunk {
UnloadChunk {
chunk_x: pos.x,
chunk_z: pos.z,
},
@ -1150,7 +1151,7 @@ impl<C: Config> Client<C> {
for seq in self.dug_blocks.drain(..) {
send_packet(
&mut self.send,
BlockChangeAck {
PlayerActionResponse {
sequence: VarInt(seq),
},
)
@ -1163,11 +1164,11 @@ impl<C: Config> Client<C> {
if self.flags.teleported_this_tick() {
self.flags.set_teleported_this_tick(false);
self.send_packet(PlayerPosition {
self.send_packet(PlayerPositionLook {
position: self.new_position,
yaw: self.yaw,
pitch: self.pitch,
flags: PlayerPositionFlags::new(false, false, false, false, false),
flags: PlayerPositionLookFlags::new(false, false, false, false, false),
teleport_id: VarInt((self.teleport_id_counter - 1) as i32),
dismount_vehicle: false,
});
@ -1178,7 +1179,7 @@ impl<C: Config> Client<C> {
if self.flags.velocity_modified() {
self.flags.set_velocity_modified(false);
self.send_packet(SetEntityMotion {
self.send_packet(EntityVelocityUpdate {
entity_id: VarInt(0),
velocity: velocity_to_packet_units(self.velocity),
});
@ -1188,7 +1189,7 @@ impl<C: Config> Client<C> {
for msg in self.msgs_to_send.drain(..) {
send_packet(
&mut self.send,
SystemChat {
GameMessage {
chat: msg,
kind: VarInt(0),
},
@ -1217,7 +1218,7 @@ impl<C: Config> Client<C> {
{
send_packet(
&mut self.send,
MoveEntityPositionAndRotation {
RotateAndMoveRelative {
entity_id: VarInt(id.to_network_id()),
delta: (position_delta * 4096.0).as_(),
yaw: ByteAngle::from_degrees(entity.yaw()),
@ -1229,7 +1230,7 @@ impl<C: Config> Client<C> {
if entity.position() != entity.old_position() && !needs_teleport {
send_packet(
&mut self.send,
MoveEntityPosition {
MoveRelative {
entity_id: VarInt(id.to_network_id()),
delta: (position_delta * 4096.0).as_(),
on_ground: entity.on_ground(),
@ -1240,7 +1241,7 @@ impl<C: Config> Client<C> {
if flags.yaw_or_pitch_modified() {
send_packet(
&mut self.send,
MoveEntityRotation {
Rotate {
entity_id: VarInt(id.to_network_id()),
yaw: ByteAngle::from_degrees(entity.yaw()),
pitch: ByteAngle::from_degrees(entity.pitch()),
@ -1253,7 +1254,7 @@ impl<C: Config> Client<C> {
if needs_teleport {
send_packet(
&mut self.send,
TeleportEntity {
EntityPosition {
entity_id: VarInt(id.to_network_id()),
position: entity.position(),
yaw: ByteAngle::from_degrees(entity.yaw()),
@ -1266,7 +1267,7 @@ impl<C: Config> Client<C> {
if flags.velocity_modified() {
send_packet(
&mut self.send,
SetEntityMotion {
EntityVelocityUpdate {
entity_id: VarInt(id.to_network_id()),
velocity: velocity_to_packet_units(entity.velocity()),
},
@ -1276,7 +1277,7 @@ impl<C: Config> Client<C> {
if flags.head_yaw_modified() {
send_packet(
&mut self.send,
RotateHead {
EntitySetHeadYaw {
entity_id: VarInt(id.to_network_id()),
head_yaw: ByteAngle::from_degrees(entity.head_yaw()),
},
@ -1294,7 +1295,7 @@ impl<C: Config> Client<C> {
});
if !entities_to_unload.is_empty() {
self.send_packet(RemoveEntities {
self.send_packet(EntitiesDestroy {
entities: entities_to_unload,
});
}
@ -1306,7 +1307,7 @@ impl<C: Config> Client<C> {
if !data.is_empty() {
data.push(0xff);
self.send_packet(SetEntityMetadata {
self.send_packet(EntityTrackerUpdate {
entity_id: VarInt(0),
metadata: RawBytes(data),
});
@ -1377,7 +1378,7 @@ fn send_entity_events(send_opt: &mut SendOpt, entity_id: i32, events: &[EntityEv
),
StatusOrAnimation::Animation(code) => send_packet(
send_opt,
Animate {
EntityAnimation {
entity_id: VarInt(entity_id),
animation: code,
},

View file

@ -13,7 +13,7 @@ use vek::{Aabb, Vec3};
use crate::config::Config;
use crate::protocol_inner::packets::play::s2c::{
AddEntity, AddExperienceOrb, AddPlayer, S2cPlayPacket, SetEntityMetadata,
EntitySpawn, ExperienceOrbSpawn, PlayerSpawn, S2cPlayPacket, EntityTrackerUpdate,
};
use crate::protocol_inner::{ByteAngle, RawBytes, VarInt};
use crate::slotmap::{Key, SlotMap};
@ -556,10 +556,10 @@ impl<C: Config> Entity<C> {
pub(crate) fn initial_tracked_data_packet(
&self,
this_id: EntityId,
) -> Option<SetEntityMetadata> {
) -> Option<EntityTrackerUpdate> {
self.variants
.initial_tracked_data()
.map(|meta| SetEntityMetadata {
.map(|meta| EntityTrackerUpdate {
entity_id: VarInt(this_id.to_network_id()),
metadata: RawBytes(meta),
})
@ -572,10 +572,10 @@ impl<C: Config> Entity<C> {
pub(crate) fn updated_tracked_data_packet(
&self,
this_id: EntityId,
) -> Option<SetEntityMetadata> {
) -> Option<EntityTrackerUpdate> {
self.variants
.updated_tracked_data()
.map(|meta| SetEntityMetadata {
.map(|meta| EntityTrackerUpdate {
entity_id: VarInt(this_id.to_network_id()),
metadata: RawBytes(meta),
})
@ -585,20 +585,20 @@ impl<C: Config> Entity<C> {
match &self.variants {
EntityEnum::Marker(_) => None,
EntityEnum::ExperienceOrb(_) => {
Some(EntitySpawnPacket::ExperienceOrb(AddExperienceOrb {
Some(EntitySpawnPacket::ExperienceOrb(ExperienceOrbSpawn {
entity_id: VarInt(this_id.to_network_id()),
position: self.new_position,
count: 0, // TODO
}))
}
EntityEnum::Player(_) => Some(EntitySpawnPacket::Player(AddPlayer {
EntityEnum::Player(_) => Some(EntitySpawnPacket::Player(PlayerSpawn {
entity_id: VarInt(this_id.to_network_id()),
player_uuid: self.uuid,
position: self.new_position,
yaw: ByteAngle::from_degrees(self.yaw),
pitch: ByteAngle::from_degrees(self.pitch),
})),
_ => Some(EntitySpawnPacket::Entity(AddEntity {
_ => Some(EntitySpawnPacket::Entity(EntitySpawn {
entity_id: VarInt(this_id.to_network_id()),
object_uuid: self.uuid,
kind: VarInt(self.kind() as i32),
@ -619,9 +619,9 @@ pub(crate) fn velocity_to_packet_units(vel: Vec3<f32>) -> Vec3<i16> {
}
pub(crate) enum EntitySpawnPacket {
Entity(AddEntity),
ExperienceOrb(AddExperienceOrb),
Player(AddPlayer),
Entity(EntitySpawn),
ExperienceOrb(ExperienceOrbSpawn),
Player(PlayerSpawn),
}
impl From<EntitySpawnPacket> for S2cPlayPacket {

View file

@ -9,7 +9,7 @@ use uuid::Uuid;
use crate::client::GameMode;
use crate::player_textures::SignedPlayerTextures;
use crate::protocol_inner::packets::play::s2c::{
PlayerInfo, PlayerInfoAddPlayer, S2cPlayPacket, TabList,
PlayerListAddPlayer, PlayerListHeaderFooter, S2cPlayPacket, UpdatePlayerList,
};
use crate::protocol_inner::packets::Property;
use crate::protocol_inner::VarInt;
@ -164,7 +164,7 @@ impl PlayerList {
let add_player: Vec<_> = self
.entries
.iter()
.map(|(&uuid, e)| PlayerInfoAddPlayer {
.map(|(&uuid, e)| PlayerListAddPlayer {
uuid,
username: e.username.clone().into(),
properties: {
@ -186,12 +186,12 @@ impl PlayerList {
.collect();
if !add_player.is_empty() {
packet(PlayerInfo::AddPlayer(add_player).into());
packet(UpdatePlayerList::AddPlayer(add_player).into());
}
if self.header != Text::default() || self.footer != Text::default() {
packet(
TabList {
PlayerListHeaderFooter {
header: self.header.clone(),
footer: self.footer.clone(),
}
@ -202,7 +202,7 @@ impl PlayerList {
pub(crate) fn diff_packets(&self, mut packet: impl FnMut(S2cPlayPacket)) {
if !self.removed.is_empty() {
packet(PlayerInfo::RemovePlayer(self.removed.iter().cloned().collect()).into());
packet(UpdatePlayerList::RemovePlayer(self.removed.iter().cloned().collect()).into());
}
let mut add_player = Vec::new();
@ -221,7 +221,7 @@ impl PlayerList {
});
}
add_player.push(PlayerInfoAddPlayer {
add_player.push(PlayerListAddPlayer {
uuid,
username: e.username.clone().into(),
properties,
@ -248,24 +248,24 @@ impl PlayerList {
}
if !add_player.is_empty() {
packet(PlayerInfo::AddPlayer(add_player).into());
packet(UpdatePlayerList::AddPlayer(add_player).into());
}
if !game_mode.is_empty() {
packet(PlayerInfo::UpdateGameMode(game_mode).into());
packet(UpdatePlayerList::UpdateGameMode(game_mode).into());
}
if !ping.is_empty() {
packet(PlayerInfo::UpdateLatency(ping).into());
packet(UpdatePlayerList::UpdateLatency(ping).into());
}
if !display_name.is_empty() {
packet(PlayerInfo::UpdateDisplayName(display_name).into());
packet(UpdatePlayerList::UpdateDisplayName(display_name).into());
}
if self.modified_header_or_footer {
packet(
TabList {
PlayerListHeaderFooter {
header: self.header.clone(),
footer: self.footer.clone(),
}

View file

@ -448,13 +448,13 @@ pub mod status {
use super::super::*;
def_struct! {
StatusResponse 0x00 {
QueryResponse 0x00 {
json_response: String
}
}
def_struct! {
PongResponse 0x01 {
QueryPong 0x01 {
/// Should be the same as the payload from ping.
payload: u64
}
@ -465,11 +465,11 @@ pub mod status {
use super::super::*;
def_struct! {
StatusRequest 0x00 {}
QueryRequest 0x00 {}
}
def_struct! {
PingRequest 0x01 {
QueryPing 0x01 {
payload: u64
}
}
@ -482,7 +482,7 @@ pub mod login {
use super::super::*;
def_struct! {
Disconnect 0x00 {
LoginDisconnect 0x00 {
reason: Text,
}
}
@ -506,7 +506,7 @@ pub mod login {
}
def_struct! {
SetCompression 0x03 {
LoginCompression 0x03 {
threshold: VarInt
}
}
@ -521,10 +521,10 @@ pub mod login {
def_packet_group! {
S2cLoginPacket {
Disconnect,
LoginDisconnect,
EncryptionRequest,
LoginSuccess,
SetCompression,
LoginCompression,
LoginPluginRequest,
}
}
@ -584,7 +584,7 @@ pub mod play {
use super::super::*;
def_struct! {
AddEntity 0x00 {
EntitySpawn 0x00 {
entity_id: VarInt,
object_uuid: Uuid,
kind: VarInt,
@ -598,7 +598,7 @@ pub mod play {
}
def_struct! {
AddExperienceOrb 0x01 {
ExperienceOrbSpawn 0x01 {
entity_id: VarInt,
position: Vec3<f64>,
count: i16,
@ -606,7 +606,7 @@ pub mod play {
}
def_struct! {
AddPlayer 0x02 {
PlayerSpawn 0x02 {
entity_id: VarInt,
player_uuid: Uuid,
position: Vec3<f64>,
@ -616,20 +616,20 @@ pub mod play {
}
def_struct! {
Animate 0x03 {
EntityAnimation 0x03 {
entity_id: VarInt,
animation: u8,
}
}
def_struct! {
BlockChangeAck 0x05 {
PlayerActionResponse 0x05 {
sequence: VarInt,
}
}
def_struct! {
BlockDestruction 0x06 {
BlockBreakingProgress 0x06 {
entity_id: VarInt,
location: BlockPos,
destroy_stage: BoundedInt<u8, 0, 10>,
@ -637,7 +637,7 @@ pub mod play {
}
def_struct! {
BlockEntityData 0x07 {
BlockEntityUpdate 0x07 {
location: BlockPos,
kind: VarInt, // TODO: use enum here
data: nbt::Blob,
@ -661,32 +661,32 @@ pub mod play {
}
def_struct! {
BossEvent 0x0a {
BossBar 0x0a {
uuid: Uuid,
action: BossEventAction,
action: BossBarAction,
}
}
def_enum! {
BossEventAction: VarInt {
Add: BossEventActionAdd = 0,
BossBarAction: VarInt {
Add: BossBarActionAdd = 0,
// TODO
}
}
def_struct! {
BossEventActionAdd {
BossBarActionAdd {
title: Text,
health: f32,
color: BossEventColor,
division: BossEventDivision,
color: BossBarColor,
division: BossBarDivision,
/// TODO: bitmask
flags: u8,
}
}
def_enum! {
BossEventColor: VarInt {
BossBarColor: VarInt {
Pink = 0,
Blue = 1,
Red = 2,
@ -698,7 +698,7 @@ pub mod play {
}
def_enum! {
BossEventDivision: VarInt {
BossBarDivision: VarInt {
NoDivision = 0,
SixNotches = 1,
TenNotches = 2,
@ -708,7 +708,7 @@ pub mod play {
}
def_struct! {
ChangeDifficulty 0x0b {
SetDifficulty 0x0b {
difficulty: Difficulty,
locked: bool,
}
@ -743,21 +743,21 @@ pub mod play {
}
def_struct! {
ForgetLevelChunk 0x1a {
UnloadChunk 0x1a {
chunk_x: i32,
chunk_z: i32
}
}
def_struct! {
GameEvent 0x1b {
reason: GameEventReason,
GameStateChange 0x1b {
reason: GameStateChangeReason,
value: f32,
}
}
def_enum! {
GameEventReason: u8 {
GameStateChangeReason: u8 {
NoRespawnBlockAvailable = 0,
EndRaining = 1,
BeginRaining = 2,
@ -774,7 +774,7 @@ pub mod play {
}
def_struct! {
InitializeWorldBorder 0x1d {
WorldBorderInitialize 0x1d {
x: f64,
z: f64,
old_diameter: f64,
@ -793,12 +793,12 @@ pub mod play {
}
def_struct! {
LevelChunkWithLight 0x1f {
ChunkData 0x1f {
chunk_x: i32,
chunk_z: i32,
heightmaps: Nbt<LevelChunkHeightmaps>,
heightmaps: Nbt<ChunkDataHeightmaps>,
blocks_and_biomes: Vec<u8>,
block_entities: Vec<LevelChunkBlockEntity>,
block_entities: Vec<ChunkDataBlockEntity>,
trust_edges: bool,
sky_light_mask: BitVec<u64>,
block_light_mask: BitVec<u64>,
@ -810,13 +810,13 @@ pub mod play {
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct LevelChunkHeightmaps {
pub struct ChunkDataHeightmaps {
#[serde(rename = "MOTION_BLOCKING", serialize_with = "nbt::i64_array")]
pub motion_blocking: Vec<i64>,
}
def_struct! {
LevelChunkBlockEntity {
ChunkDataBlockEntity {
packed_xz: i8,
y: i16,
kind: VarInt,
@ -825,7 +825,7 @@ pub mod play {
}
def_struct! {
Login 0x23 {
GameJoin 0x23 {
/// Entity ID of the joining player
entity_id: i32,
is_hardcore: bool,
@ -1017,7 +1017,7 @@ pub mod play {
}
def_struct! {
MoveEntityPosition 0x26 {
MoveRelative 0x26 {
entity_id: VarInt,
delta: Vec3<i16>,
on_ground: bool,
@ -1025,7 +1025,7 @@ pub mod play {
}
def_struct! {
MoveEntityPositionAndRotation 0x27 {
RotateAndMoveRelative 0x27 {
entity_id: VarInt,
delta: Vec3<i16>,
yaw: ByteAngle,
@ -1035,7 +1035,7 @@ pub mod play {
}
def_struct! {
MoveEntityRotation 0x28 {
Rotate 0x28 {
entity_id: VarInt,
yaw: ByteAngle,
pitch: ByteAngle,
@ -1044,7 +1044,7 @@ pub mod play {
}
def_struct! {
PlayerChat 0x30 {
ChatMessage 0x30 {
message: Text,
/// Index into the chat type registry
kind: VarInt,
@ -1054,8 +1054,8 @@ pub mod play {
}
def_enum! {
PlayerInfo 0x34: VarInt {
AddPlayer: Vec<PlayerInfoAddPlayer> = 0,
UpdatePlayerList 0x34: VarInt {
AddPlayer: Vec<PlayerListAddPlayer> = 0,
UpdateGameMode: Vec<(Uuid, GameMode)> = 1,
UpdateLatency: Vec<(Uuid, VarInt)> = 2,
UpdateDisplayName: Vec<(Uuid, Option<Text>)> = 3,
@ -1064,7 +1064,7 @@ pub mod play {
}
def_struct! {
PlayerInfoAddPlayer {
PlayerListAddPlayer {
uuid: Uuid,
username: BoundedString<3, 16>,
properties: Vec<Property>,
@ -1076,18 +1076,18 @@ pub mod play {
}
def_struct! {
PlayerPosition 0x36 {
PlayerPositionLook 0x36 {
position: Vec3<f64>,
yaw: f32,
pitch: f32,
flags: PlayerPositionFlags,
flags: PlayerPositionLookFlags,
teleport_id: VarInt,
dismount_vehicle: bool,
}
}
def_bitfield! {
PlayerPositionFlags: u8 {
PlayerPositionLookFlags: u8 {
x = 0,
y = 1,
z = 2,
@ -1097,13 +1097,13 @@ pub mod play {
}
def_struct! {
RemoveEntities 0x38 {
EntitiesDestroy 0x38 {
entities: Vec<VarInt>,
}
}
def_struct! {
Respawn 0x3b {
PlayerRespawn 0x3b {
dimension_type_name: Ident,
dimension_name: Ident,
hashed_seed: u64,
@ -1117,14 +1117,14 @@ pub mod play {
}
def_struct! {
RotateHead 0x3c {
EntitySetHeadYaw 0x3c {
entity_id: VarInt,
head_yaw: ByteAngle,
}
}
def_struct! {
SectionBlocksUpdate 0x3d {
ChunkSectionUpdate 0x3d {
chunk_section_position: i64,
invert_trust_edges: bool,
blocks: Vec<VarLong>,
@ -1132,53 +1132,53 @@ pub mod play {
}
def_struct! {
SetCarriedItem 0x47 {
UpdateSelectedSlot 0x47 {
slot: BoundedInt<u8, 0, 9>,
}
}
def_struct! {
SetChunkCacheCenter 0x48 {
ChunkRenderDistanceCenter 0x48 {
chunk_x: VarInt,
chunk_z: VarInt,
}
}
def_struct! {
SetChunkCacheRadius 0x49 {
ChunkLoadDistance 0x49 {
view_distance: BoundedInt<VarInt, 2, 32>,
}
}
def_struct! {
SpawnPosition 0x4a {
PlayerSpawnPosition 0x4a {
location: BlockPos,
angle: f32,
}
}
def_struct! {
SetEntityMetadata 0x4d {
EntityTrackerUpdate 0x4d {
entity_id: VarInt,
metadata: RawBytes,
}
}
def_struct! {
SetEntityMotion 0x4f {
EntityVelocityUpdate 0x4f {
entity_id: VarInt,
velocity: Vec3<i16>,
}
}
def_struct! {
SetSubtitleText 0x58 {
UpdateSubtitle 0x58 {
subtitle_text: Text,
}
}
def_struct! {
SetTime 0x59 {
WorldTimeUpdate 0x59 {
/// The age of the world in 1/20ths of a second.
world_age: i64,
/// The current time of day in 1/20ths of a second.
@ -1189,14 +1189,14 @@ pub mod play {
}
def_struct! {
SetTitleText 0x5a {
UpdateTitle 0x5a {
text: Text,
}
}
def_struct! {
#[derive(Copy, PartialEq, Eq)]
SetTitleAnimationTimes 0x5b {
TitleAnimationTimes 0x5b {
/// Ticks to spend fading in.
fade_in: u32,
/// Ticks to keep the title displayed.
@ -1207,7 +1207,7 @@ pub mod play {
}
def_struct! {
SystemChat 0x5f {
GameMessage 0x5f {
chat: Text,
/// Index into the chat type registry.
kind: VarInt,
@ -1215,14 +1215,14 @@ pub mod play {
}
def_struct! {
TabList 0x60 {
PlayerListHeaderFooter 0x60 {
header: Text,
footer: Text,
}
}
def_struct! {
TeleportEntity 0x63 {
EntityPosition 0x63 {
entity_id: VarInt,
position: Vec3<f64>,
yaw: ByteAngle,
@ -1232,22 +1232,22 @@ pub mod play {
}
def_struct! {
UpdateAttributes 0x65 {
EntityAttributes 0x65 {
entity_id: VarInt,
properties: Vec<UpdateAttributesProperty>,
properties: Vec<EntityAttributesProperty>,
}
}
def_struct! {
UpdateAttributesProperty {
EntityAttributesProperty {
key: Ident,
value: f64,
modifiers: Vec<UpdateAttributesModifiers>
modifiers: Vec<EntityAttributesModifiers>
}
}
def_struct! {
UpdateAttributesModifiers {
EntityAttributesModifiers {
uuid: Uuid,
amount: f64,
operation: u8,
@ -1256,48 +1256,48 @@ pub mod play {
def_packet_group! {
S2cPlayPacket {
AddEntity,
AddExperienceOrb,
AddPlayer,
Animate,
BlockChangeAck,
BlockDestruction,
BlockEntityData,
EntitySpawn,
ExperienceOrbSpawn,
PlayerSpawn,
EntityAnimation,
PlayerActionResponse,
BlockBreakingProgress,
BlockEntityUpdate,
BlockEvent,
BlockUpdate,
BossEvent,
BossBar,
ClearTitles,
Disconnect,
EntityStatus,
ForgetLevelChunk,
GameEvent,
UnloadChunk,
GameStateChange,
KeepAlive,
LevelChunkWithLight,
Login,
MoveEntityPosition,
MoveEntityPositionAndRotation,
MoveEntityRotation,
PlayerChat,
PlayerInfo,
PlayerPosition,
RemoveEntities,
Respawn,
RotateHead,
SectionBlocksUpdate,
SetCarriedItem,
SetChunkCacheCenter,
SetChunkCacheRadius,
SpawnPosition,
SetEntityMetadata,
SetEntityMotion,
SetSubtitleText,
SetTime,
SetTitleText,
SetTitleAnimationTimes,
SystemChat,
TabList,
TeleportEntity,
UpdateAttributes,
ChunkData,
GameJoin,
MoveRelative,
RotateAndMoveRelative,
Rotate,
ChatMessage,
UpdatePlayerList,
PlayerPositionLook,
EntitiesDestroy,
PlayerRespawn,
EntitySetHeadYaw,
ChunkSectionUpdate,
UpdateSelectedSlot,
ChunkRenderDistanceCenter,
ChunkLoadDistance,
PlayerSpawnPosition,
EntityTrackerUpdate,
EntityVelocityUpdate,
UpdateSubtitle,
WorldTimeUpdate,
UpdateTitle,
TitleAnimationTimes,
GameMessage,
PlayerListHeaderFooter,
EntityPosition,
EntityAttributes,
}
}
}
@ -1306,20 +1306,20 @@ pub mod play {
use super::super::*;
def_struct! {
AcceptTeleportation 0x00 {
TeleportConfirm 0x00 {
teleport_id: VarInt
}
}
def_struct! {
BlockEntityTagQuery 0x01 {
QueryBlockNbt 0x01 {
transaction_id: VarInt,
location: BlockPos,
}
}
def_enum! {
ChangeDifficulty 0x02: i8 {
UpdateDifficulty 0x02: i8 {
Peaceful = 0,
Easy = 1,
Normal = 2,
@ -1328,7 +1328,7 @@ pub mod play {
}
def_struct! {
ChatCommand 0x03 {
CommandExecution 0x03 {
command: String, // TODO: bounded?
// TODO: timestamp, arg signatures
signed_preview: bool,
@ -1336,7 +1336,7 @@ pub mod play {
}
def_struct! {
Chat 0x04 {
ChatMessage 0x04 {
message: BoundedString<0, 256>,
timestamp: u64,
salt: u64,
@ -1346,14 +1346,14 @@ pub mod play {
}
def_struct! {
ChatPreview 0x05 {
RequestChatPreview 0x05 {
query: i32, // TODO: is this an i32 or a varint?
message: BoundedString<0, 256>,
}
}
def_enum! {
ClientCommand 0x06: VarInt {
ClientStatus 0x06: VarInt {
/// Sent when ready to complete login and ready to respawn after death.
PerformRespawn = 0,
/// Sent when the statistics menu is opened.
@ -1362,7 +1362,7 @@ pub mod play {
}
def_struct! {
ClientInformation 0x07 {
ClientSettings 0x07 {
/// e.g. en_US
locale: BoundedString<0, 16>,
/// Client-side render distance in chunks.
@ -1408,7 +1408,7 @@ pub mod play {
}
def_struct! {
CommandSuggestion 0x08 {
RequestCommandCompletion 0x08 {
transaction_id: VarInt,
/// Text behind the cursor without the '/'.
text: BoundedString<0, 32500>
@ -1416,14 +1416,20 @@ pub mod play {
}
def_struct! {
ContainerButtonClick 0x09 {
ButtonClick 0x09 {
window_id: i8,
button_id: i8,
}
}
def_struct! {
ContainerClose 0x0b {
ClickSlot 0x0a {
// TODO
}
}
def_struct! {
CloseHandledScreen 0x0b {
window_id: u8,
}
}
@ -1436,7 +1442,7 @@ pub mod play {
}
def_struct! {
EditBook 0x0d {
BookUpdate 0x0d {
slot: VarInt,
entries: Vec<String>,
title: Option<String>,
@ -1444,14 +1450,14 @@ pub mod play {
}
def_struct! {
EntityTagQuery 0x0e {
QueryEntityNbt 0x0e {
transaction_id: VarInt,
entity_id: VarInt,
}
}
def_struct! {
Interact 0x0f {
PlayerInteractEntity 0x0f {
entity_id: VarInt,
kind: InteractKind,
sneaking: bool,
@ -1489,7 +1495,7 @@ pub mod play {
}
def_struct! {
LockDifficulty 0x12 {
UpdateDifficultyLock 0x12 {
locked: bool
}
}
@ -1524,7 +1530,7 @@ pub mod play {
}
def_struct! {
MovePlayerStatusOnly 0x16 {
MovePlayerOnGround 0x16 {
on_ground: bool
}
}
@ -1541,20 +1547,20 @@ pub mod play {
}
def_struct! {
PaddleBoat 0x18 {
BoatPaddleState 0x18 {
left_paddle_turning: bool,
right_paddle_turning: bool,
}
}
def_struct! {
PickItem 0x19 {
PickFromInventory 0x19 {
slot_to_use: VarInt,
}
}
def_struct! {
PlaceRecipe 0x1a {
CraftRequest 0x1a {
window_id: i8,
recipe: Ident,
make_all: bool,
@ -1562,7 +1568,7 @@ pub mod play {
}
def_enum! {
PlayerAbilities 0x1b: i8 {
UpdatePlayerAbilities 0x1b: i8 {
NotFlying = 0,
Flying = 0b10,
}
@ -1645,7 +1651,7 @@ pub mod play {
}
def_struct! {
Pong 0x1f {
PlayPong 0x1f {
id: i32,
}
}
@ -1680,7 +1686,7 @@ pub mod play {
}
def_enum! {
ResourcePack 0x23: VarInt {
ResourcePackStatus 0x23: VarInt {
SuccessfullyLoaded = 0,
Declined = 1,
FailedDownload = 2,
@ -1689,20 +1695,20 @@ pub mod play {
}
def_enum! {
SeenAdvancements 0x24: VarInt {
AdvancementTab 0x24: VarInt {
OpenedTab: Ident = 0,
ClosedScreen = 1,
}
}
def_struct! {
SelectTrade 0x25 {
SelectMerchantTrade 0x25 {
selected_slot: VarInt,
}
}
def_struct! {
SetBeacon 0x26 {
UpdateBeacon 0x26 {
// TODO: potion ids
primary_effect: Option<VarInt>,
secondary_effect: Option<VarInt>,
@ -1710,13 +1716,13 @@ pub mod play {
}
def_struct! {
SetCarriedItem 0x27 {
UpdateSelectedSlot 0x27 {
slot: BoundedInt<i16, 0, 8>,
}
}
def_struct! {
SetCommandBlock 0x28 {
UpdateCommandBlock 0x28 {
location: BlockPos,
command: String,
mode: CommandBlockMode,
@ -1741,7 +1747,7 @@ pub mod play {
}
def_struct! {
SetCommandBlockMinecart 0x29 {
UpdateCommandBlockMinecart 0x29 {
entity_id: VarInt,
command: String,
track_output: bool,
@ -1749,14 +1755,14 @@ pub mod play {
}
def_struct! {
SetCreativeModeSlot 0x2a {
UpdateCreativeModeSlot 0x2a {
slot: i16,
// TODO: clicked_item: Slot,
}
}
def_struct! {
SetJigsawBlock 0x2b {
UpdateJigsaw 0x2b {
location: BlockPos,
name: Ident,
target: Ident,
@ -1767,7 +1773,7 @@ pub mod play {
}
def_struct! {
SetStructureBlock 0x2c {
UpdateStructureBlock 0x2c {
location: BlockPos,
action: StructureBlockAction,
mode: StructureBlockMode,
@ -1827,26 +1833,26 @@ pub mod play {
}
def_struct! {
SignUpdate 0x2d {
UpdateSign 0x2d {
location: BlockPos,
lines: [BoundedString<0, 384>; 4],
}
}
def_struct! {
Swing 0x2e {
HandSwing 0x2e {
hand: Hand,
}
}
def_struct! {
TeleportToEntity 0x2f {
SpectatorTeleport 0x2f {
target: Uuid,
}
}
def_struct! {
UseItemOn 0x30 {
PlayerInteractBlock 0x30 {
hand: Hand,
location: BlockPos,
face: BlockFace,
@ -1857,7 +1863,7 @@ pub mod play {
}
def_struct! {
UseItem 0x31 {
PlayerInteractItem 0x31 {
hand: Hand,
sequence: VarInt,
}
@ -1865,55 +1871,56 @@ pub mod play {
def_packet_group! {
C2sPlayPacket {
AcceptTeleportation,
BlockEntityTagQuery,
ChangeDifficulty,
ChatCommand,
Chat,
ChatPreview,
ClientCommand,
ClientInformation,
CommandSuggestion,
ContainerButtonClick,
ContainerClose,
TeleportConfirm,
QueryBlockNbt,
UpdateDifficulty,
CommandExecution,
ChatMessage,
RequestChatPreview,
ClientStatus,
ClientSettings,
RequestCommandCompletion,
ButtonClick,
ClickSlot,
CloseHandledScreen,
CustomPayload,
EditBook,
EntityTagQuery,
Interact,
BookUpdate,
QueryEntityNbt,
PlayerInteractEntity,
JigsawGenerate,
KeepAlive,
LockDifficulty,
UpdateDifficultyLock,
MovePlayerPosition,
MovePlayerPositionAndRotation,
MovePlayerRotation,
MovePlayerStatusOnly,
MovePlayerOnGround,
MoveVehicle,
PaddleBoat,
PickItem,
PlaceRecipe,
PlayerAbilities,
BoatPaddleState,
PickFromInventory,
CraftRequest,
UpdatePlayerAbilities,
PlayerAction,
PlayerCommand,
PlayerInput,
Pong,
PlayPong,
RecipeBookChangeSettings,
RecipeBookSeenRecipe,
RenameItem,
ResourcePack,
SeenAdvancements,
SelectTrade,
SetBeacon,
SetCarriedItem,
SetCommandBlock,
SetCommandBlockMinecart,
SetCreativeModeSlot,
SetJigsawBlock,
SetStructureBlock,
SignUpdate,
Swing,
TeleportToEntity,
UseItemOn,
UseItem,
ResourcePackStatus,
AdvancementTab,
SelectMerchantTrade,
UpdateBeacon,
UpdateSelectedSlot,
UpdateCommandBlock,
UpdateCommandBlockMinecart,
UpdateCreativeModeSlot,
UpdateJigsaw,
UpdateStructureBlock,
UpdateSign,
HandSwing,
SpectatorTeleport,
PlayerInteractBlock,
PlayerInteractItem,
}
}
}

View file

@ -38,11 +38,11 @@ use crate::protocol_inner::packets::handshake::{Handshake, HandshakeNextState};
use crate::protocol_inner::packets::login::c2s::{
EncryptionResponse, LoginStart, VerifyTokenOrMsgSig,
};
use crate::protocol_inner::packets::login::s2c::{EncryptionRequest, LoginSuccess, SetCompression};
use crate::protocol_inner::packets::login::s2c::{EncryptionRequest, LoginSuccess, LoginCompression};
use crate::protocol_inner::packets::play::c2s::C2sPlayPacket;
use crate::protocol_inner::packets::play::s2c::S2cPlayPacket;
use crate::protocol_inner::packets::status::c2s::{PingRequest, StatusRequest};
use crate::protocol_inner::packets::status::s2c::{PongResponse, StatusResponse};
use crate::protocol_inner::packets::status::c2s::{QueryPing, QueryRequest};
use crate::protocol_inner::packets::status::s2c::{QueryPong, QueryResponse};
use crate::protocol_inner::packets::{login, Property};
use crate::protocol_inner::{BoundedArray, BoundedString, VarInt};
use crate::util::valid_username;
@ -552,7 +552,7 @@ async fn handle_status<C: Config>(
c: &mut Codec,
remote_addr: SocketAddr,
) -> anyhow::Result<()> {
c.dec.read_packet::<StatusRequest>().await?;
c.dec.read_packet::<QueryRequest>().await?;
match server.0.cfg.server_list_ping(&server, remote_addr).await {
ServerListPing::Respond {
@ -583,7 +583,7 @@ async fn handle_status<C: Config>(
}
c.enc
.write_packet(&StatusResponse {
.write_packet(&QueryResponse {
json_response: json.to_string(),
})
.await?;
@ -591,9 +591,9 @@ async fn handle_status<C: Config>(
ServerListPing::Ignore => return Ok(()),
}
let PingRequest { payload } = c.dec.read_packet().await?;
let QueryPing { payload } = c.dec.read_packet().await?;
c.enc.write_packet(&PongResponse { payload }).await?;
c.enc.write_packet(&QueryPong { payload }).await?;
Ok(())
}
@ -705,7 +705,7 @@ async fn handle_login<C: Config>(
let compression_threshold = 256;
c.enc
.write_packet(&SetCompression {
.write_packet(&LoginCompression {
threshold: VarInt(compression_threshold as i32),
})
.await?;
@ -723,7 +723,7 @@ async fn handle_login<C: Config>(
if let Err(reason) = server.0.cfg.login(server, &npd).await {
log::info!("Disconnect at login: \"{reason}\"");
c.enc
.write_packet(&login::s2c::Disconnect { reason })
.write_packet(&login::s2c::LoginDisconnect { reason })
.await?;
return Ok(None);
}