Skip to content

Commit c3d2212

Browse files
committed
Add ModList serialization using Mod serializable, LenPrefixed<VarInt, Mod>
1 parent 0c79130 commit c3d2212

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

src/server/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ impl Server {
693693

694694
self.write_plugin_message("REGISTER", "FML|HS\0FML\0FML|MP\0FML\0FORGE".as_bytes());
695695
self.write_plugin_message("FML|HS", &plugin_messages::FmlHs::ClientHello { fml_protocol_version }.as_message());
696-
let mods: HashMap<&str, &str> = HashMap::new();
696+
let mods: crate::protocol::LenPrefixed<crate::protocol::VarInt, plugin_messages::Mod> = Default::default();
697697
self.write_plugin_message("FML|HS", &plugin_messages::FmlHs::ModList { mods }.as_message());
698698
},
699699
_ => (),

src/server/plugin_messages.rs

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,27 @@ use byteorder::WriteBytesExt;
55

66
use crate::protocol::packet::play::serverbound::PluginMessageServerbound;
77
use 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)]
1131
pub 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

Comments
 (0)