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
This commit is contained in:
iceiix 2019-05-11 18:37:33 -07:00 committed by GitHub
parent ba4a7a9d85
commit 0cd02fd2da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 9 deletions

View File

@ -97,7 +97,6 @@ pub enum FmlHs {
ModList {
mods: LenPrefixed<VarInt, ForgeMod>,
},
/* 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<VarInt, String>,
dummies: LenPrefixed<VarInt, String>,
},
*/
ModIdData {
mappings: LenPrefixed<VarInt, ModIdMapping>,
block_substitutions: LenPrefixed<VarInt, String>,
@ -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 {

View File

@ -108,7 +108,8 @@ impl Server {
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> {
let mut conn = protocol::Conn::new(address, protocol_version)?;
let host = conn.host.clone();
let tag = if forge_mods.len() != 0 { "\0FML\0" } else { "" };
let host = conn.host.clone() + tag;
let port = conn.port;
conn.write_packet(protocol::packet::handshake::serverbound::Handshake {
protocol_version: protocol::VarInt(protocol_version),
@ -711,7 +712,16 @@ impl Server {
self.write_fmlhs_plugin_message(&HandshakeAck { phase: WaitingServerData });
},
ModIdData { mappings: _, block_substitutions: _, item_substitutions: _ } => {
self.write_fmlhs_plugin_message(&HandshakeAck { phase: WaitingServerData });
println!("Received FML|HS ModIdData");
self.write_fmlhs_plugin_message(&HandshakeAck { phase: WaitingServerComplete });
// TODO: dynamically register mod blocks
},
RegistryData { has_more, name, ids: _, substitutions: _, dummies: _ } => {
println!("Received FML|HS RegistryData for {}", name);
if !has_more {
self.write_fmlhs_plugin_message(&HandshakeAck { phase: WaitingServerComplete });
}
// TODO: dynamically register mod blocks
},
HandshakeAck { phase } => {
match phase {