@@ -56,6 +56,8 @@ pub struct Server {
5656 resources : Arc < RwLock < resources:: Manager > > ,
5757 version : usize ,
5858
59+ plugin_message_handler : plugin_messages:: PluginMessageHandler ,
60+
5961 // Entity accessors
6062 game_info : ecs:: Key < entity:: GameInfo > ,
6163 player_movement : ecs:: Key < entity:: player:: PlayerMovement > ,
@@ -292,6 +294,8 @@ impl Server {
292294 version,
293295 resources,
294296
297+ plugin_message_handler : plugin_messages:: PluginMessageHandler { } ,
298+
295299 // Entity accessors
296300 game_info,
297301 player_movement : entities. get_key ( ) ,
@@ -670,46 +674,11 @@ impl Server {
670674 }
671675
672676 fn on_plugin_message_clientbound_i16 ( & mut self , msg : packet:: play:: clientbound:: PluginMessageClientbound_i16 ) {
673- self . on_plugin_message_clientbound ( & msg. channel , msg. data . data . as_slice ( ) )
677+ self . plugin_message_handler . on_plugin_message_clientbound ( & msg. channel , msg. data . data . as_slice ( ) )
674678 }
675679
676680 fn on_plugin_message_clientbound_1 ( & mut self , msg : packet:: play:: clientbound:: PluginMessageClientbound ) {
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- }
681+ self . plugin_message_handler . on_plugin_message_clientbound ( & msg. channel , & msg. data )
713682 }
714683
715684 fn on_game_join_i32_viewdistance ( & mut self , join : packet:: play:: clientbound:: JoinGame_i32_ViewDistance ) {
0 commit comments