Skip to content

Commit 99821ec

Browse files
committed
Send reply to ServerHello: REGISTER and FML|HS ClientHello
1 parent 2585f40 commit 99821ec

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/server/mod.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,11 +686,34 @@ impl Server {
686686
"FML|HS" => {
687687
let msg = plugin_messages::FmlHs::from_message(&data);
688688
println!("FML|HS msg={:?}", msg);
689+
match msg {
690+
plugin_messages::FmlHs::ServerHello { fml_protocol_version, override_dimension } => {
691+
println!("Received FML|HS ServerHello {} {:?}", fml_protocol_version, override_dimension);
692+
693+
self.write_plugin_message("REGISTER", "FML|HS\0FML\0FML|MP\0FML\0FORGE".as_bytes());
694+
self.write_plugin_message("FML|HS", &plugin_messages::FmlHs::ClientHello { fml_protocol_version }.as_message());
695+
},
696+
_ => (),
697+
}
689698
}
690699
_ => ()
691700
}
692701
}
693702

703+
fn write_plugin_message(&mut self, channel: &str, data: &[u8]) {
704+
if self.protocol_version >= 47 {
705+
self.write_packet(packet::play::serverbound::PluginMessageServerbound {
706+
channel: channel.to_string(),
707+
data: data.to_vec(),
708+
});
709+
} else {
710+
self.write_packet(packet::play::serverbound::PluginMessageServerbound_i16 {
711+
channel: channel.to_string(),
712+
data: crate::protocol::LenPrefixedBytes::<i16>::new(data.to_vec()),
713+
});
714+
}
715+
}
716+
694717
fn on_game_join_i32_viewdistance(&mut self, join: packet::play::clientbound::JoinGame_i32_ViewDistance) {
695718
self.on_game_join(join.gamemode, join.entity_id)
696719
}
@@ -726,6 +749,7 @@ impl Server {
726749
let brand = plugin_messages::Brand {
727750
brand: "Steven".into(),
728751
};
752+
// TODO: refactor with write_plugin_message
729753
if self.protocol_version >= 47 {
730754
self.write_packet(brand.as_message());
731755
} else {

src/server/plugin_messages.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ pub enum FmlHs<'a> {
3131
}
3232

3333
impl<'a> FmlHs<'a> {
34+
pub fn as_message(&'a self) -> Vec<u8> {
35+
match self {
36+
FmlHs::ClientHello { fml_protocol_version } => {
37+
vec![*fml_protocol_version as u8]
38+
},
39+
_ => unimplemented!()
40+
}
41+
}
42+
3443
pub fn from_message(data: &[u8]) -> FmlHs<'a> {
3544
// https://wiki.vg/Minecraft_Forge_Handshake
3645
let discriminator = data[0];

0 commit comments

Comments
 (0)