From 9a15a90af845f1a3853d7bf2ad1fc3283f005ac1 Mon Sep 17 00:00:00 2001 From: ice_iix Date: Mon, 3 Dec 2018 16:06:20 -0800 Subject: [PATCH] Add 1.9 (107) multiprotocol support Closes https://github.com/iceiix/steven/pull/16 Enhances https://github.com/iceiix/steven/issues/18 --- protocol/src/protocol/mod.rs | 2 +- protocol/src/protocol/packet.rs | 19 ++- protocol/src/protocol/versions.rs | 4 + protocol/src/protocol/versions/v1_10_2.rs | 2 +- protocol/src/protocol/versions/v1_11_2.rs | 2 +- protocol/src/protocol/versions/v1_12_2.rs | 2 +- protocol/src/protocol/versions/v1_9.rs | 146 ++++++++++++++++++++++ protocol/src/protocol/versions/v1_9_2.rs | 2 +- 8 files changed, 173 insertions(+), 6 deletions(-) create mode 100644 protocol/src/protocol/versions/v1_9.rs diff --git a/protocol/src/protocol/mod.rs b/protocol/src/protocol/mod.rs index 9e77afc..48f12db 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; 5] = [340, 316, 315, 210, 109]; +pub const SUPPORTED_PROTOCOLS: [i32; 6] = [340, 316, 315, 210, 109, 107]; /// Helper macro for defining packets diff --git a/protocol/src/protocol/packet.rs b/protocol/src/protocol/packet.rs index 8cdac1a..23c234b 100644 --- a/protocol/src/protocol/packet.rs +++ b/protocol/src/protocol/packet.rs @@ -594,7 +594,7 @@ state_packets!( } /// JoinGame is sent after completing the login process. This /// sets the initial state for the client. - packet JoinGame { + packet JoinGame_i32 { /// The entity id the client will be referenced by field entity_id: i32 =, /// The starting gamemode of the client @@ -611,6 +611,23 @@ state_packets!( /// information it displays in F3 mode field reduced_debug_info: bool =, } + packet JoinGame_i8 { + /// The entity id the client will be referenced by + field entity_id: i32 =, + /// The starting gamemode of the client + field gamemode: u8 =, + /// The dimension the client is starting in + field dimension: i8 =, + /// The difficuilty setting for the server + field difficulty: u8 =, + /// The max number of players on the server + field max_players: u8 =, + /// The level type of the server + field level_type: String =, + /// Whether the client should reduce the amount of debug + /// information it displays in F3 mode + field reduced_debug_info: bool =, + } /// Maps updates a single map's contents packet Maps { field item_damage: VarInt =, diff --git a/protocol/src/protocol/versions.rs b/protocol/src/protocol/versions.rs index c2f276a..ea8d955 100644 --- a/protocol/src/protocol/versions.rs +++ b/protocol/src/protocol/versions.rs @@ -4,6 +4,7 @@ mod v1_12_2; mod v1_11_2; mod v1_10_2; mod v1_9_2; +mod v1_9; pub fn translate_internal_packet_id_for_version(version: i32, state: State, dir: Direction, id: i32, to_internal: bool) -> i32 { match version { @@ -24,6 +25,9 @@ pub fn translate_internal_packet_id_for_version(version: i32, state: State, dir: // 1.9.2 109 => v1_9_2::translate_internal_packet_id(state, dir, id, to_internal), + // 1.9 + 107 => v1_9::translate_internal_packet_id(state, dir, id, to_internal), + _ => panic!("unsupported protocol version"), } } diff --git a/protocol/src/protocol/versions/v1_10_2.rs b/protocol/src/protocol/versions/v1_10_2.rs index add7478..7cbfed5 100644 --- a/protocol/src/protocol/versions/v1_10_2.rs +++ b/protocol/src/protocol/versions/v1_10_2.rs @@ -75,7 +75,7 @@ protocol_packet_ids!( 0x20 => ChunkData 0x21 => Effect 0x22 => Particle - 0x23 => JoinGame + 0x23 => JoinGame_i32 0x24 => Maps 0x25 => EntityMove 0x26 => EntityLookAndMove diff --git a/protocol/src/protocol/versions/v1_11_2.rs b/protocol/src/protocol/versions/v1_11_2.rs index 2bd0271..5f6cc60 100644 --- a/protocol/src/protocol/versions/v1_11_2.rs +++ b/protocol/src/protocol/versions/v1_11_2.rs @@ -75,7 +75,7 @@ protocol_packet_ids!( 0x20 => ChunkData 0x21 => Effect 0x22 => Particle - 0x23 => JoinGame + 0x23 => JoinGame_i32 0x24 => Maps 0x25 => EntityMove 0x26 => EntityLookAndMove diff --git a/protocol/src/protocol/versions/v1_12_2.rs b/protocol/src/protocol/versions/v1_12_2.rs index 39a7539..897447d 100644 --- a/protocol/src/protocol/versions/v1_12_2.rs +++ b/protocol/src/protocol/versions/v1_12_2.rs @@ -78,7 +78,7 @@ protocol_packet_ids!( 0x20 => ChunkData 0x21 => Effect 0x22 => Particle - 0x23 => JoinGame + 0x23 => JoinGame_i32 0x24 => Maps 0x25 => Entity 0x26 => EntityMove diff --git a/protocol/src/protocol/versions/v1_9.rs b/protocol/src/protocol/versions/v1_9.rs new file mode 100644 index 0000000..74b8982 --- /dev/null +++ b/protocol/src/protocol/versions/v1_9.rs @@ -0,0 +1,146 @@ +protocol_packet_ids!( + handshake Handshaking { + serverbound Serverbound { + 0x00 => Handshake + } + clientbound Clientbound { + } + } + play Play { + serverbound Serverbound { + 0x00 => TeleportConfirm + 0x01 => TabComplete + 0x02 => ChatMessage + 0x03 => ClientStatus + 0x04 => ClientSettings + 0x05 => ConfirmTransactionServerbound + 0x06 => EnchantItem + 0x07 => ClickWindow + 0x08 => CloseWindow + 0x09 => PluginMessageServerbound + 0x0a => UseEntity + 0x0b => KeepAliveServerbound_VarInt + 0x0c => PlayerPosition + 0x0d => PlayerPositionLook + 0x0e => PlayerLook + 0x0f => Player + 0x10 => VehicleMove + 0x11 => SteerBoat + 0x12 => ClientAbilities + 0x13 => PlayerDigging + 0x14 => PlayerAction + 0x15 => SteerVehicle + 0x16 => ResourcePackStatus_hash + 0x17 => HeldItemChange + 0x18 => CreativeInventoryAction + 0x19 => SetSign + 0x1a => ArmSwing + 0x1b => SpectateTeleport + 0x1c => PlayerBlockPlacement_u8 + 0x1d => UseItem + } + clientbound Clientbound { + 0x00 => SpawnObject + 0x01 => SpawnExperienceOrb + 0x02 => SpawnGlobalEntity + 0x03 => SpawnMob_u8 + 0x04 => SpawnPainting + 0x05 => SpawnPlayer + 0x06 => Animation + 0x07 => Statistics + 0x08 => BlockBreakAnimation + 0x09 => UpdateBlockEntity + 0x0a => BlockAction + 0x0b => BlockChange + 0x0c => BossBar + 0x0d => ServerDifficulty + 0x0e => TabCompleteReply + 0x0f => ServerMessage + 0x10 => MultiBlockChange + 0x11 => ConfirmTransaction + 0x12 => WindowClose + 0x13 => WindowOpen + 0x14 => WindowItems + 0x15 => WindowProperty + 0x16 => WindowSetSlot + 0x17 => SetCooldown + 0x18 => PluginMessageClientbound + 0x19 => NamedSoundEffect_u8 + 0x1a => Disconnect + 0x1b => EntityAction + 0x1c => Explosion + 0x1d => ChunkUnload + 0x1e => ChangeGameState + 0x1f => KeepAliveClientbound_VarInt + 0x20 => ChunkData_NoEntities + 0x21 => Effect + 0x22 => Particle + 0x23 => JoinGame_i8 + 0x24 => Maps + 0x25 => EntityMove + 0x26 => EntityLookAndMove + 0x27 => EntityLook + 0x28 => Entity + 0x29 => VehicleTeleport + 0x2a => SignEditorOpen + 0x2b => PlayerAbilities + 0x2c => CombatEvent + 0x2d => PlayerInfo + 0x2e => TeleportPlayer + 0x2f => EntityUsedBed + 0x30 => EntityDestroy + 0x31 => EntityRemoveEffect + 0x32 => ResourcePackSend + 0x33 => Respawn + 0x34 => EntityHeadLook + 0x35 => WorldBorder + 0x36 => Camera + 0x37 => SetCurrentHotbarSlot + 0x38 => ScoreboardDisplay + 0x39 => EntityMetadata + 0x3a => EntityAttach + 0x3b => EntityVelocity + 0x3c => EntityEquipment + 0x3d => SetExperience + 0x3e => UpdateHealth + 0x3f => ScoreboardObjective + 0x40 => SetPassengers + 0x41 => Teams + 0x42 => UpdateScore + 0x43 => SpawnPosition + 0x44 => TimeUpdate + 0x45 => Title_notext + 0x46 => UpdateSign + 0x47 => SoundEffect_u8 + 0x48 => PlayerListHeaderFooter + 0x49 => CollectItem_nocount + 0x4a => EntityTeleport + 0x4b => EntityProperties + 0x4c => EntityEffect + } + } + login Login { + serverbound Serverbound { + 0x00 => LoginStart + 0x01 => EncryptionResponse + } + clientbound Clientbound { + 0x00 => LoginDisconnect + 0x01 => EncryptionRequest + 0x02 => LoginSuccess + 0x03 => SetInitialCompression + } + } + status Status { + serverbound Serverbound { + 0x00 => StatusRequest + 0x01 => StatusPing + } + clientbound Clientbound { + 0x00 => StatusResponse + 0x01 => StatusPong + } + } +); + + diff --git a/protocol/src/protocol/versions/v1_9_2.rs b/protocol/src/protocol/versions/v1_9_2.rs index faaaca9..2b9f603 100644 --- a/protocol/src/protocol/versions/v1_9_2.rs +++ b/protocol/src/protocol/versions/v1_9_2.rs @@ -75,7 +75,7 @@ protocol_packet_ids!( 0x20 => ChunkData_NoEntities 0x21 => Effect 0x22 => Particle - 0x23 => JoinGame + 0x23 => JoinGame_i32 0x24 => Maps 0x25 => EntityMove 0x26 => EntityLookAndMove