Skip to content

Commit 492a1a0

Browse files
committed
Parse modinfo.modList from server ping packet
1 parent 3f9dc31 commit 492a1a0

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/protocol/mod.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,29 @@ impl Conn {
996996
let version = val.get("version").ok_or(invalid_status())?;
997997
let players = val.get("players").ok_or(invalid_status())?;
998998

999+
// TODO: Option<> to distinguish non-modded, vs no mods?
1000+
let mut forge_mods: std::vec::Vec<crate::server::plugin_messages::ForgeMod> = vec![];
1001+
if let Some(modinfo) = val.get("modinfo") {
1002+
if let Some(modinfo_type) = modinfo.get("type") {
1003+
if modinfo_type == "FML" {
1004+
if let Some(modlist) = modinfo.get("modList") {
1005+
if let Value::Array(items) = modlist {
1006+
for item in items {
1007+
if let Value::Object(obj) = item {
1008+
let modid = obj.get("modid").unwrap().as_str().unwrap().to_string();
1009+
let version = obj.get("version").unwrap().as_str().unwrap().to_string();
1010+
1011+
forge_mods.push(crate::server::plugin_messages::ForgeMod { modid, version });
1012+
}
1013+
}
1014+
}
1015+
}
1016+
} else {
1017+
panic!("Unrecognized modinfo type in server ping response: {} in {}", modinfo_type, modinfo);
1018+
}
1019+
}
1020+
}
1021+
9991022
Ok((Status {
10001023
version: StatusVersion {
10011024
name: version.get("name").and_then(Value::as_str).ok_or(invalid_status())?
@@ -1016,6 +1039,7 @@ impl Conn {
10161039
description: format::Component::from_value(val.get("description")
10171040
.ok_or(invalid_status())?),
10181041
favicon: val.get("favicon").and_then(Value::as_str).map(|v| v.to_owned()),
1042+
forge_mods,
10191043
},
10201044
ping))
10211045
}
@@ -1027,6 +1051,7 @@ pub struct Status {
10271051
pub players: StatusPlayers,
10281052
pub description: format::Component,
10291053
pub favicon: Option<String>,
1054+
pub forge_mods: Vec<crate::server::plugin_messages::ForgeMod>,
10301055
}
10311056

10321057
#[derive(Debug)]

src/screen/server_list.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ struct PingInfo {
7878
max: i32,
7979
protocol_version: i32,
8080
protocol_name: String,
81+
forge_mods: Vec<crate::server::plugin_messages::ForgeMod>,
8182
favicon: Option<image::DynamicImage>,
8283
}
8384

@@ -283,6 +284,7 @@ impl ServerList {
283284
max: res.0.players.max,
284285
protocol_version: res.0.version.protocol,
285286
protocol_name: res.0.version.name,
287+
forge_mods: res.0.forge_mods,
286288
favicon,
287289
}));
288290
}
@@ -299,6 +301,7 @@ impl ServerList {
299301
max: 0,
300302
protocol_version: 0,
301303
protocol_name: "".to_owned(),
304+
forge_mods: vec![],
302305
favicon: None,
303306
});
304307
}
@@ -497,6 +500,9 @@ impl super::Screen for ServerList {
497500

498501
// TODO: store in memory instead of disk? but where?
499502
self.server_protocol_versions.insert(res.address, res.protocol_version);
503+
if res.forge_mods.len() > 0 {
504+
println!("Forge mods installed on server: {:?}", res.forge_mods);
505+
}
500506
let mut out = fs::File::create("server_versions.json").unwrap();
501507
serde_json::to_writer_pretty(&mut out, &self.server_protocol_versions).unwrap();
502508
}

0 commit comments

Comments
 (0)