@@ -56,8 +56,6 @@ pub struct Server {
5656 resources : Arc < RwLock < resources:: Manager > > ,
5757 version : usize ,
5858
59- plugin_message_handler : plugin_messages:: PluginMessageHandler ,
60-
6159 // Entity accessors
6260 game_info : ecs:: Key < entity:: GameInfo > ,
6361 player_movement : ecs:: Key < entity:: player:: PlayerMovement > ,
@@ -294,8 +292,6 @@ impl Server {
294292 version,
295293 resources,
296294
297- plugin_message_handler : plugin_messages:: PluginMessageHandler { } ,
298-
299295 // Entity accessors
300296 game_info,
301297 player_movement : entities. get_key ( ) ,
@@ -674,11 +670,46 @@ impl Server {
674670 }
675671
676672 fn on_plugin_message_clientbound_i16 ( & mut self , msg : packet:: play:: clientbound:: PluginMessageClientbound_i16 ) {
677- self . plugin_message_handler . on_plugin_message_clientbound ( & msg. channel , msg. data . data . as_slice ( ) )
673+ self . on_plugin_message_clientbound ( & msg. channel , msg. data . data . as_slice ( ) )
678674 }
679675
680676 fn on_plugin_message_clientbound_1 ( & mut self , msg : packet:: play:: clientbound:: PluginMessageClientbound ) {
681- self . plugin_message_handler . on_plugin_message_clientbound ( & msg. channel , & msg. data )
677+ self . on_plugin_message_clientbound ( & msg. channel , & msg. data )
678+ }
679+
680+ fn on_plugin_message_clientbound ( & mut self , channel : & str , data : & [ u8 ] ) {
681+ println ! ( "Received plugin message: channel={}, data={:?}" , channel, data) ;
682+
683+ match channel {
684+ // TODO: "REGISTER" =>
685+ // TODO: "UNREGISTER" =>
686+ "FML|HS" => {
687+ // https://wiki.vg/Minecraft_Forge_Handshake
688+ let discriminator = data[ 0 ] ;
689+
690+ match discriminator {
691+ 0 => {
692+ // ServerHello
693+ let fml_protocol_version = data[ 1 ] ;
694+ let dimension = if fml_protocol_version > 1 {
695+ use byteorder:: { BigEndian , ReadBytesExt } ;
696+ let dimension = ( & data[ 2 ..2 + 4 ] ) . read_u32 :: < BigEndian > ( ) . unwrap ( ) ;
697+ Some ( dimension)
698+ } else {
699+ None
700+ } ;
701+
702+ println ! ( "FML|HS ServerHello: fml_protocol_version={}, dimension={:?}" , fml_protocol_version, dimension) ;
703+
704+ // TODO: send reply
705+ } ,
706+ _ => {
707+ println ! ( "Unhandled FML|HS packet: discriminator={}" , discriminator) ;
708+ }
709+ }
710+ }
711+ _ => ( )
712+ }
682713 }
683714
684715 fn on_game_join_i32_viewdistance ( & mut self , join : packet:: play:: clientbound:: JoinGame_i32_ViewDistance ) {
0 commit comments