From 19057ed2a007915aa87abd557284fc1df40c10b6 Mon Sep 17 00:00:00 2001 From: iceiix <43691553+iceiix@users.noreply.github.com> Date: Thu, 10 Jan 2019 17:47:07 -0800 Subject: [PATCH] Add 19w02a (452) multiprotocol support (#82) Adds support for the 19w02a (451) protocol, yesterday's snapshot. Builds on https://github.com/iceiix/steven/pull/79 18w50a Closer to https://github.com/iceiix/steven/issues/72 1.14 protocol support Updates https://github.com/iceiix/steven/issues/18 Enhance protocol support * Add 19w02a (452) protocol * Add campfire recipe type * Add trade list new packet, and window open variants --- protocol/src/protocol/mod.rs | 2 +- protocol/src/protocol/packet.rs | 58 ++++++++ protocol/src/protocol/versions.rs | 4 + protocol/src/protocol/versions/v19w02a.rs | 174 ++++++++++++++++++++++ 4 files changed, 237 insertions(+), 1 deletion(-) create mode 100644 protocol/src/protocol/versions/v19w02a.rs diff --git a/protocol/src/protocol/mod.rs b/protocol/src/protocol/mod.rs index 5062d12..2b82b0a 100644 --- a/protocol/src/protocol/mod.rs +++ b/protocol/src/protocol/mod.rs @@ -37,7 +37,7 @@ use flate2::Compression; use std::time::{Instant, Duration}; use crate::shared::Position; -pub const SUPPORTED_PROTOCOLS: [i32; 11] = [404, 451, 340, 316, 315, 210, 109, 107, 74, 47, 5]; +pub const SUPPORTED_PROTOCOLS: [i32; 12] = [404, 451, 452, 340, 316, 315, 210, 109, 107, 74, 47, 5]; // TODO: switch to using thread_local storage?, see https://doc.rust-lang.org/std/macro.thread_local.html pub static mut CURRENT_PROTOCOL_VERSION: i32 = SUPPORTED_PROTOCOLS[0]; diff --git a/protocol/src/protocol/packet.rs b/protocol/src/protocol/packet.rs index 5a0cf30..2e5576b 100644 --- a/protocol/src/protocol/packet.rs +++ b/protocol/src/protocol/packet.rs @@ -809,6 +809,11 @@ state_packets!( field slot_count: u8 =, field entity_id: i32 = when(|p: &WindowOpen| p.ty == "EntityHorse"), } + packet WindowOpenHorse { + field window_id: u8 =, + field number_of_slots: VarInt =, + field entity_id: i32 =, + } packet WindowOpen_u8 { field id: u8 =, field ty: u8 =, @@ -817,6 +822,11 @@ state_packets!( field use_provided_window_title: bool =, field entity_id: i32 = when(|p: &WindowOpen_u8| p.ty == 11), } + packet WindowOpen_VarInt { + field id: VarInt =, + field ty: VarInt =, + field title: format::Component =, + } /// WindowItems sets every item in a window. packet WindowItems { field id: u8 =, @@ -1673,6 +1683,10 @@ state_packets!( field empty_sky_light_mask: VarInt =, field light_arrays: Vec =, } + packet TradeList { + field id: VarInt =, + field trades: LenPrefixed =, + } } } login Login { @@ -2357,6 +2371,13 @@ pub enum RecipeData { experience: f32, cooking_time: VarInt, }, + Campfire { + group: String, + ingredient: RecipeIngredient, + result: Option, + experience: f32, + cooking_time: VarInt, + }, } impl Default for RecipeData { @@ -2434,6 +2455,13 @@ impl Serializable for Recipe { experience: Serializable::read_from(buf)?, cooking_time: Serializable::read_from(buf)?, }, + "campfire" => RecipeData::Campfire { + group: Serializable::read_from(buf)?, + ingredient: Serializable::read_from(buf)?, + result: Serializable::read_from(buf)?, + experience: Serializable::read_from(buf)?, + cooking_time: Serializable::read_from(buf)?, + }, _ => panic!("unrecognized recipe type: {}", ty) }; @@ -2464,6 +2492,36 @@ impl Serializable for Tags { } } +#[derive(Debug, Default)] +pub struct Trade { + pub input_item_1: Option, + pub output_item: Option, + pub has_second_item: bool, + pub input_item_2: Option, + pub trades_disabled: bool, + pub tool_uses: i32, + pub max_trade_uses: i32, +} + +impl Serializable for Trade { + fn read_from(buf: &mut R) -> Result { + Ok(Trade { + input_item_1: Serializable::read_from(buf)?, + output_item: Serializable::read_from(buf)?, + has_second_item: Serializable::read_from(buf)?, + input_item_2: Serializable::read_from(buf)?, + trades_disabled: Serializable::read_from(buf)?, + tool_uses: Serializable::read_from(buf)?, + max_trade_uses: Serializable::read_from(buf)?, + }) + } + + fn write_to(&self, _: &mut W) -> Result<(), Error> { + unimplemented!() + } +} + + #[derive(Debug, Default)] pub struct CommandNode { pub flags: u8, diff --git a/protocol/src/protocol/versions.rs b/protocol/src/protocol/versions.rs index 1ba9dae..d80b2a6 100644 --- a/protocol/src/protocol/versions.rs +++ b/protocol/src/protocol/versions.rs @@ -1,5 +1,6 @@ use crate::protocol::*; +mod v19w02a; mod v18w50a; mod v1_13_2; mod v1_12_2; @@ -15,6 +16,9 @@ pub fn translate_internal_packet_id_for_version(version: i32, state: State, dir: match version { // https://wiki.vg/Protocol_History // https://wiki.vg/Protocol_version_numbers#Versions_after_the_Netty_rewrite + + // 19w02a + 452 => v19w02a::translate_internal_packet_id(state, dir, id, to_internal), // 18w50a 451 => v18w50a::translate_internal_packet_id(state, dir, id, to_internal), diff --git a/protocol/src/protocol/versions/v19w02a.rs b/protocol/src/protocol/versions/v19w02a.rs new file mode 100644 index 0000000..edbce6a --- /dev/null +++ b/protocol/src/protocol/versions/v19w02a.rs @@ -0,0 +1,174 @@ +protocol_packet_ids!( + handshake Handshaking { + serverbound Serverbound { + 0x00 => Handshake + } + clientbound Clientbound { + } + } + play Play { + serverbound Serverbound { + 0x00 => TeleportConfirm + 0x01 => QueryBlockNBT + 0x02 => ChatMessage + 0x03 => ClientStatus + 0x04 => ClientSettings + 0x05 => TabComplete + 0x06 => ConfirmTransactionServerbound + 0x07 => EnchantItem + 0x08 => ClickWindow + 0x09 => CloseWindow + 0x0a => PluginMessageServerbound + 0x0b => EditBook + 0x0c => QueryEntityNBT + 0x0d => UseEntity + 0x0e => KeepAliveServerbound_i64 + 0x0f => Player + 0x10 => PlayerPosition + 0x11 => PlayerPositionLook + 0x12 => PlayerLook + 0x13 => VehicleMove + 0x14 => SteerBoat + 0x15 => PickItem + 0x16 => CraftRecipeRequest + 0x17 => ClientAbilities + 0x18 => PlayerDigging + 0x19 => PlayerAction + 0x1a => SteerVehicle + 0x1b => CraftingBookData + 0x1c => NameItem + 0x1d => ResourcePackStatus + 0x1e => AdvancementTab + 0x1f => SelectTrade + 0x20 => SetBeaconEffect + 0x21 => HeldItemChange + 0x22 => UpdateCommandBlock + 0x23 => UpdateCommandBlockMinecart + 0x24 => CreativeInventoryAction + 0x25 => UpdateStructureBlock + 0x26 => SetSign + 0x27 => ArmSwing + 0x28 => SpectateTeleport + 0x29 => PlayerBlockPlacement_f32 + 0x2a => UseItem + } + clientbound Clientbound { + 0x00 => SpawnObject + 0x01 => SpawnExperienceOrb + 0x02 => SpawnGlobalEntity + 0x03 => SpawnMob + 0x04 => SpawnPainting + 0x05 => SpawnPlayer_f64 + 0x06 => Animation + 0x07 => Statistics + 0x08 => BlockBreakAnimation + 0x09 => UpdateBlockEntity + 0x0a => BlockAction + 0x0b => BlockChange_VarInt + 0x0c => BossBar + 0x0d => ServerDifficulty + 0x0e => ServerMessage + 0x0f => MultiBlockChange_VarInt + 0x10 => TabCompleteReply + 0x11 => DeclareCommands + 0x12 => ConfirmTransaction + 0x13 => WindowClose + 0x14 => WindowOpenHorse + 0x15 => WindowItems + 0x16 => WindowProperty + 0x17 => WindowSetSlot + 0x18 => SetCooldown + 0x19 => PluginMessageClientbound + 0x1a => NamedSoundEffect + 0x1b => Disconnect + 0x1c => EntityAction + 0x1d => NBTQueryResponse + 0x1e => Explosion + 0x1f => ChunkUnload + 0x20 => ChangeGameState + 0x21 => KeepAliveClientbound_i64 + 0x22 => ChunkData_HeightMap + 0x23 => Effect + 0x24 => Particle + 0x25 => JoinGame_i32 + 0x26 => Maps + 0x27 => Entity + 0x28 => EntityMove_i16 + 0x29 => EntityLookAndMove_i16 + 0x2a => EntityLook_VarInt + 0x2b => VehicleTeleport + 0x2c => OpenBook + 0x2d => SignEditorOpen + 0x2e => CraftRecipeResponse + 0x2f => PlayerAbilities + 0x30 => CombatEvent + 0x31 => PlayerInfo + 0x32 => FacePlayer + 0x33 => TeleportPlayer_WithConfirm + 0x34 => EntityUsedBed + 0x35 => UnlockRecipes_WithSmelting + 0x36 => EntityDestroy + 0x37 => EntityRemoveEffect + 0x38 => ResourcePackSend + 0x39 => Respawn + 0x3a => EntityHeadLook + 0x3b => SelectAdvancementTab + 0x3c => WorldBorder + 0x3d => Camera + 0x3e => SetCurrentHotbarSlot + 0x3f => ScoreboardDisplay + 0x40 => EntityMetadata + 0x41 => EntityAttach + 0x42 => EntityVelocity + 0x43 => EntityEquipment + 0x44 => SetExperience + 0x45 => UpdateHealth + 0x46 => ScoreboardObjective + 0x47 => SetPassengers + 0x48 => Teams + 0x49 => UpdateScore + 0x4a => SpawnPosition + 0x4b => TimeUpdate + 0x4d => StopSound + 0x4e => SoundEffect + 0x4f => EntitySoundEffect + 0x50 => PlayerListHeaderFooter + 0x51 => CollectItem + 0x52 => EntityTeleport_f64 + 0x53 => Advancements + 0x54 => EntityProperties + 0x55 => EntityEffect + 0x56 => DeclareRecipes + 0x57 => TagsWithEntities + 0x58 => UpdateLight + 0x59 => WindowOpen_VarInt + 0x5a => TradeList + } + } + login Login { + serverbound Serverbound { + 0x00 => LoginStart + 0x01 => EncryptionResponse + 0x02 => LoginPluginResponse + } + clientbound Clientbound { + 0x00 => LoginDisconnect + 0x01 => EncryptionRequest + 0x02 => LoginSuccess + 0x03 => SetInitialCompression + 0x04 => LoginPluginRequest + } + } + status Status { + serverbound Serverbound { + 0x00 => StatusRequest + 0x01 => StatusPing + } + clientbound Clientbound { + 0x00 => StatusResponse + 0x01 => StatusPong + } + } +); + +