Skip to content

Commit 0cd02fd

Browse files
authored
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
1 parent ba4a7a9 commit 0cd02fd

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

src/protocol/forge.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,13 @@ pub enum FmlHs {
9797
ModList {
9898
mods: LenPrefixed<VarInt, ForgeMod>,
9999
},
100-
/* TODO: 1.8+ https://wiki.vg/Minecraft_Forge_Handshake#Differences_from_Forge_1.7.10
101100
RegistryData {
102101
has_more: bool,
103102
name: String,
104103
ids: LenPrefixed<VarInt, ModIdMapping>,
105104
substitutions: LenPrefixed<VarInt, String>,
106105
dummies: LenPrefixed<VarInt, String>,
107106
},
108-
*/
109107
ModIdData {
110108
mappings: LenPrefixed<VarInt, ModIdMapping>,
111109
block_substitutions: LenPrefixed<VarInt, String>,
@@ -145,11 +143,23 @@ impl Serializable for FmlHs {
145143
})
146144
},
147145
3 => {
148-
Ok(FmlHs::ModIdData {
149-
mappings: Serializable::read_from(buf)?,
150-
block_substitutions: Serializable::read_from(buf)?,
151-
item_substitutions: Serializable::read_from(buf)?,
152-
})
146+
let protocol_version = unsafe { crate::protocol::CURRENT_PROTOCOL_VERSION };
147+
148+
if protocol_version >= 47 {
149+
Ok(FmlHs::RegistryData {
150+
has_more: Serializable::read_from(buf)?,
151+
name: Serializable::read_from(buf)?,
152+
ids: Serializable::read_from(buf)?,
153+
substitutions: Serializable::read_from(buf)?,
154+
dummies: Serializable::read_from(buf)?,
155+
})
156+
} else {
157+
Ok(FmlHs::ModIdData {
158+
mappings: Serializable::read_from(buf)?,
159+
block_substitutions: Serializable::read_from(buf)?,
160+
item_substitutions: Serializable::read_from(buf)?,
161+
})
162+
}
153163
},
154164
255 => {
155165
Ok(FmlHs::HandshakeAck {

src/server/mod.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ impl Server {
108108
pub fn connect(resources: Arc<RwLock<resources::Manager>>, profile: mojang::Profile, address: &str, protocol_version: i32, forge_mods: Vec<forge::ForgeMod>) -> Result<Server, protocol::Error> {
109109
let mut conn = protocol::Conn::new(address, protocol_version)?;
110110

111-
let host = conn.host.clone();
111+
let tag = if forge_mods.len() != 0 { "\0FML\0" } else { "" };
112+
let host = conn.host.clone() + tag;
112113
let port = conn.port;
113114
conn.write_packet(protocol::packet::handshake::serverbound::Handshake {
114115
protocol_version: protocol::VarInt(protocol_version),
@@ -711,7 +712,16 @@ impl Server {
711712
self.write_fmlhs_plugin_message(&HandshakeAck { phase: WaitingServerData });
712713
},
713714
ModIdData { mappings: _, block_substitutions: _, item_substitutions: _ } => {
714-
self.write_fmlhs_plugin_message(&HandshakeAck { phase: WaitingServerData });
715+
println!("Received FML|HS ModIdData");
716+
self.write_fmlhs_plugin_message(&HandshakeAck { phase: WaitingServerComplete });
717+
// TODO: dynamically register mod blocks
718+
},
719+
RegistryData { has_more, name, ids: _, substitutions: _, dummies: _ } => {
720+
println!("Received FML|HS RegistryData for {}", name);
721+
if !has_more {
722+
self.write_fmlhs_plugin_message(&HandshakeAck { phase: WaitingServerComplete });
723+
}
724+
// TODO: dynamically register mod blocks
715725
},
716726
HandshakeAck { phase } => {
717727
match phase {

0 commit comments

Comments
 (0)