From 2451e780bd69f4c5eee1eac3750fbb72b8dbdb4d Mon Sep 17 00:00:00 2001 From: iceiix <43691553+iceiix@users.noreply.github.com> Date: Sat, 11 May 2019 18:37:33 -0700 Subject: [PATCH] Forge 1.8.9-1.12.2 handshake protocol support (#144) Adds support for connecting to Forge servers from 1.8.9 up to 1.12.2. (1.7.10 was already supported with #134 #88) Tested on: - 1.8.9 + forge 11.15.1.2318 + ironchest - 1.10.2 + forge 12.18.3.2511 + ironchest - 1.11.2 + forge 13.20.1.2588 + ironchest - 1.12.2 + forge 14.23.5.2837 + ironchest Changes: * Parse and handle FmlHs::RegistryData packet for 1.8+ * Fix RegistryData acknowledgement phase WaitingServerComplete * Fix acknowledgement phase for 1.7.10 ModIdData too, somehow it worked accidentally * Append \0FML\0 to end of server hostname if Forge mods detected https://wiki.vg/Minecraft_Forge_Handshake#Connection_to_a_forge_server --- protocol/src/protocol/forge.rs | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/protocol/src/protocol/forge.rs b/protocol/src/protocol/forge.rs index 21d47b3..841df92 100644 --- a/protocol/src/protocol/forge.rs +++ b/protocol/src/protocol/forge.rs @@ -97,7 +97,6 @@ pub enum FmlHs { ModList { mods: LenPrefixed, }, - /* TODO: 1.8+ https://wiki.vg/Minecraft_Forge_Handshake#Differences_from_Forge_1.7.10 RegistryData { has_more: bool, name: String, @@ -105,7 +104,6 @@ pub enum FmlHs { substitutions: LenPrefixed, dummies: LenPrefixed, }, - */ ModIdData { mappings: LenPrefixed, block_substitutions: LenPrefixed, @@ -145,11 +143,23 @@ impl Serializable for FmlHs { }) }, 3 => { - Ok(FmlHs::ModIdData { - mappings: Serializable::read_from(buf)?, - block_substitutions: Serializable::read_from(buf)?, - item_substitutions: Serializable::read_from(buf)?, - }) + let protocol_version = unsafe { crate::protocol::CURRENT_PROTOCOL_VERSION }; + + if protocol_version >= 47 { + Ok(FmlHs::RegistryData { + has_more: Serializable::read_from(buf)?, + name: Serializable::read_from(buf)?, + ids: Serializable::read_from(buf)?, + substitutions: Serializable::read_from(buf)?, + dummies: Serializable::read_from(buf)?, + }) + } else { + Ok(FmlHs::ModIdData { + mappings: Serializable::read_from(buf)?, + block_substitutions: Serializable::read_from(buf)?, + item_substitutions: Serializable::read_from(buf)?, + }) + } }, 255 => { Ok(FmlHs::HandshakeAck {