Browse Source

Add compatibility with newer versions of forge

master
Kilobyte22 6 months ago
parent
commit
e7ffafe193
4 changed files with 60 additions and 8 deletions
  1. +1
    -1
      Cargo.lock
  2. +1
    -1
      Cargo.toml
  3. +28
    -3
      src/data.rs
  4. +30
    -3
      src/main.rs

+ 1
- 1
Cargo.lock View File

@ -72,7 +72,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "mc-server-ping"
version = "0.1.0"
version = "0.1.1"
dependencies = [
"ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",


+ 1
- 1
Cargo.toml View File

@ -1,6 +1,6 @@
[package]
name = "mc-server-ping"
version = "0.1.0"
version = "0.1.1"
authors = ["Kilobyte22 <stiepen22@gmx.de>"]
edition = "2018"


+ 28
- 3
src/data.rs View File

@ -293,7 +293,7 @@ impl DescriptionInfo {
formatting_code = false;
match c {
'r' => format = Default::default(),
'0' ... '9' | 'a' ... 'f' => format.color = ColorSpec::from_legacy(c),
'0' ..= '9' | 'a' ..= 'f' => format.color = ColorSpec::from_legacy(c),
'k' => format.obfuscated ^= true,
'l' => format.bold ^= true,
'm' => format.strikethrough ^= true,
@ -333,6 +333,28 @@ impl DescriptionInfo {
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct NewMod {
#[serde(rename = "modId")]
pub id: String,
#[serde(rename = "modmarker")]
pub marker: String
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ForgeData {
pub mods: Vec<NewMod>,
pub channels: Vec<Channel>
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Channel {
#[serde(rename = "res")]
pub resource_name: String,
pub version: String,
pub required: bool
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ServerInfo {
pub version: VersionInfo,
@ -341,7 +363,10 @@ pub struct ServerInfo {
#[serde(skip_serializing_if = "Option::is_none")]
pub favicon: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub modinfo: Option<ModInfo>
pub modinfo: Option<ModInfo>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "forgeData")]
pub forge_data: Option<ForgeData>
}
fn is_false(value: &bool) -> bool { !value }
fn is_false(value: &bool) -> bool { !value }

+ 30
- 3
src/main.rs View File

@ -77,6 +77,7 @@ fn get_args<'a, 'b>() -> clap::App<'a, 'b> {
(@arg json: -j --json "Output as JSON")
(@arg desc_format: +takes_value --descformat "Convert the Format of the description to either of (chat_component|legacy)")
(@arg hidemods: --hidemods "Hide the list of mods, as it can get quite lengthy")
(@arg hidechannels: --hidechannels "Hide the list of forge channels, as it can get quite lengthy")
(@arg SERVER: +required "The server to ping")
)
}
@ -132,8 +133,8 @@ fn main() {
println!(" - {} [{}]", Colour::Green.paint(player.name), player.id);
}
print!("Modded: ");
match info.modinfo {
Some(modinfo) => {
match (info.modinfo, info.forge_data) {
(Some(modinfo), _) => {
print!("{}, {} mods", Colour::Green.paint(modinfo.ty), modinfo.mod_list.len());
if !matches.is_present("hidemods") {
println!();
@ -144,7 +145,33 @@ fn main() {
println!(" (hidden)");
}
}
None => {
(None, Some(modinfo)) => {
print!("{}, {} mods", Colour::Green.paint("Minecraft Forge"), modinfo.mods.len());
if !matches.is_present("hidemods") {
println!();
for m in modinfo.mods {
println!(" - {} {}", m.id, m.marker);
}
} else {
println!("{}", Colour::RGB(0x99, 0x99, 0x99).paint(" (hidden)"));
}
print!("Channels ({}): ", modinfo.channels.len());
if !matches.is_present("hidechannels") {
println!();
for m in modinfo.channels {
print!(" - {} {}", m.resource_name, m.version);
if m.required {
println!(" {}", Colour::Blue.paint("[required]"));
} else {
println!()
}
}
} else {
println!("{}", Colour::RGB(0x99, 0x99, 0x99).paint(" (hidden)"));
}
}
(None, None) => {
println!("{}", Colour::Red.paint("No"));
}
}


Loading…
Cancel
Save