Add support for reponse sent when the server is starting

Other changes:
- bump dependencies
- upgrade rust edition
- switch to tracing
This commit is contained in:
LordMZTE 2022-04-02 00:39:04 +02:00
parent d97383f31f
commit 05de59253b
Signed by: LordMZTE
GPG Key ID: B64802DC33A64FF6
5 changed files with 41 additions and 35 deletions

View File

@ -2,38 +2,34 @@
name = "mcstat"
version = "0.1.0"
authors = ["LordMZTE <lord@mzte.de>"]
edition = "2018"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
base64 = "0.13.0"
crossterm = "0.21.0"
env_logger = "0.9.0"
image = "0.23.14"
itertools = "0.10.1"
log = "0.4.14"
miette = { version = "3.2.0", features = ["fancy"] }
serde_json = "1.0.68"
crossterm = "0.23.1"
image = "0.24.1"
itertools = "0.10.3"
miette = { version = "4.3.0", features = ["fancy"] }
serde_json = "1.0.79"
smart-default = "0.6.0"
structopt = "0.3.23"
structopt = "0.3.26"
term_size = "0.3.2"
termcolor = "1.1.2"
trust-dns-resolver = { version = "0.20.3", features = ["tokio-runtime"] }
termcolor = "1.1.3"
trust-dns-resolver = { version = "0.21.2", features = ["tokio-runtime"] }
unicode-width = "0.1.9"
viuer = "0.5.2"
viuer = "0.6.0"
serde = { version = "1.0.136", features = ["derive"] }
tracing-subscriber = "0.3.10"
tracing = "0.1.32"
[dependencies.async-minecraft-ping]
git = "https://github.com/LordMZTE/async-minecraft-ping.git"
tag = "v0.3.0"
[dependencies.tokio]
version = "1.12.0"
version = "1.17.0"
features = ["rt-multi-thread", "macros", "time"]
[build-dependencies]
clap = "2.33.3"
lazy_static = "1.4.0"
yaml-rust = "0.4.5"
[features]

View File

@ -1,6 +1,6 @@
# mcstat
### This tool pings a minecraft server and displays information about it.
## Currently this includes
## This includes
- protocol version
- server version
- player count
@ -18,4 +18,4 @@
## TODO
---
- [x] fork async-minecraft-ping in order to fix some bugs and implement mod list response (dev is not responding to [issue](https://github.com/jsvana/async-minecraft-ping/issues/3))
- [x] fork async-minecraft-ping to fix some bugs and implement mod list response (dev is not responding to [issue](https://github.com/jsvana/async-minecraft-ping/issues/3))

View File

@ -1,20 +1,19 @@
#[macro_use]
extern crate smart_default;
use crate::output::Table;
use async_minecraft_ping::StatusResponse;
use crossterm::{
style::{Attribute, Color, Print, ResetColor, SetAttribute, SetForegroundColor},
ExecutableCommand,
};
use image::{DynamicImage, ImageFormat};
use itertools::Itertools;
use log::info;
use miette::{bail, miette, IntoDiagnostic, WrapErr};
use tracing::info;
use std::{
io::{self, Cursor, Write},
net::IpAddr,
};
use trust_dns_resolver::TokioAsyncResolver;
use serde::Deserialize;
pub mod output;
@ -35,6 +34,13 @@ macro_rules! none_if_empty {
}};
}
#[derive(Deserialize)]
#[serde(untagged)]
pub enum EitherStatusResponse {
Text { text: String },
Normal(StatusResponse),
}
pub async fn resolve_address(addr_and_port: &str) -> miette::Result<(String, u16)> {
info!("Resolving address");
let addr;

View File

@ -1,20 +1,16 @@
use async_minecraft_ping::{ConnectionConfig, ServerDescription, StatusResponse};
use itertools::Itertools;
use log::info;
use miette::{IntoDiagnostic, WrapErr};
use structopt::StructOpt;
use time::{Duration, Instant};
use tokio::time;
use mcstat::{
get_table,
mc_formatted_to_ansi,
none_if_empty,
output::Table,
parse_base64_image,
resolve_address,
get_table, mc_formatted_to_ansi, none_if_empty, output::Table, parse_base64_image,
resolve_address, EitherStatusResponse,
};
use tracing::info;
#[derive(Debug, StructOpt)]
#[structopt(
@ -83,9 +79,7 @@ impl Opt {
#[tokio::main]
async fn main() -> miette::Result<()> {
env_logger::try_init()
.into_diagnostic()
.wrap_err("Failed to init logger")?;
tracing_subscriber::fmt().pretty().init();
let opt = Opt::from_args();
@ -125,7 +119,16 @@ async fn main() -> miette::Result<()> {
}
info!("Parsing status");
let response = serde_json::from_str::<StatusResponse>(&raw_response).into_diagnostic()?;
let response = serde_json::from_str::<EitherStatusResponse>(&raw_response).into_diagnostic()?;
let response = match response {
EitherStatusResponse::Text { text } => {
println!("The server says:\n{}", text);
return Ok(());
},
EitherStatusResponse::Normal(r) => r,
};
// if the server has mods, and the user hasn't used the -m argument, notify
// that.

View File

@ -2,6 +2,7 @@ use std::{
cmp::{max, min},
io::{self, Write},
};
use smart_default::SmartDefault;
use unicode_width::UnicodeWidthStr;
#[derive(SmartDefault)]