@@ -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\0 FML\0 FML|MP\0 FML\0 FORGE" . 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 {
0 commit comments