@@ -5,7 +5,27 @@ use byteorder::WriteBytesExt;
55
66use crate :: protocol:: packet:: play:: serverbound:: PluginMessageServerbound ;
77use crate :: protocol:: packet:: play:: serverbound:: PluginMessageServerbound_i16 ;
8- use crate :: protocol:: { Serializable , Error } ;
8+ use crate :: protocol:: { Serializable , Error , LenPrefixed , VarInt } ;
9+
10+ #[ derive( Debug , Default ) ]
11+ pub struct Mod {
12+ name : String ,
13+ version : String ,
14+ }
15+
16+ impl Serializable for Mod {
17+ fn read_from < R : io:: Read > ( buf : & mut R ) -> Result < Self , Error > {
18+ Ok ( Mod {
19+ name : Serializable :: read_from ( buf) ?,
20+ version : Serializable :: read_from ( buf) ?,
21+ } )
22+ }
23+
24+ fn write_to < W : io:: Write > ( & self , buf : & mut W ) -> Result < ( ) , Error > {
25+ self . name . write_to ( buf) ?;
26+ self . version . write_to ( buf)
27+ }
28+ }
929
1030#[ derive( Debug ) ]
1131pub enum FmlHs < ' a > {
@@ -17,7 +37,7 @@ pub enum FmlHs<'a> {
1737 fml_protocol_version : i8 ,
1838 } ,
1939 ModList {
20- mods : HashMap < & ' a str , & ' a str > ,
40+ mods : LenPrefixed < VarInt , Mod > ,
2141 } ,
2242 RegistryData {
2343 has_more : bool ,
@@ -57,9 +77,7 @@ impl<'a> Serializable for FmlHs<'a> {
5777 } ,
5878 1 => panic ! ( "Received unexpected FML|HS ClientHello from server" ) ,
5979 2 => {
60- //TODO let number_of_mods = VarInt::read_from(&mut data[1..].to_vec());
61- let mods: HashMap < & ' a str , & ' a str > = HashMap :: new ( ) ;
62- // TODO: read mods
80+ let mods: LenPrefixed < VarInt , Mod > = Serializable :: read_from ( buf) ?;
6381
6482 Ok ( FmlHs :: ModList {
6583 mods,
@@ -78,11 +96,7 @@ impl<'a> Serializable for FmlHs<'a> {
7896 } ,
7997 FmlHs :: ModList { mods } => {
8098 buf. write_u8 ( 2 ) ?;
81- Ok ( ( ) )
82-
83- //let number_of_mods = VarInt(mods.len() as i32);
84- //number_of_mods.write_to(&mut buf).unwrap();
85- // TODO: write mods
99+ mods. write_to ( buf)
86100 } ,
87101 _ => unimplemented ! ( )
88102 }
0 commit comments