mirror of
https://github.com/LordMZTE/mcstat.git
synced 2024-04-27 02:45:30 +02:00
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:
parent
d97383f31f
commit
05de59253b
32
Cargo.toml
32
Cargo.toml
|
@ -2,38 +2,34 @@
|
||||||
name = "mcstat"
|
name = "mcstat"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["LordMZTE <lord@mzte.de>"]
|
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
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
base64 = "0.13.0"
|
base64 = "0.13.0"
|
||||||
crossterm = "0.21.0"
|
crossterm = "0.23.1"
|
||||||
env_logger = "0.9.0"
|
image = "0.24.1"
|
||||||
image = "0.23.14"
|
itertools = "0.10.3"
|
||||||
itertools = "0.10.1"
|
miette = { version = "4.3.0", features = ["fancy"] }
|
||||||
log = "0.4.14"
|
serde_json = "1.0.79"
|
||||||
miette = { version = "3.2.0", features = ["fancy"] }
|
|
||||||
serde_json = "1.0.68"
|
|
||||||
smart-default = "0.6.0"
|
smart-default = "0.6.0"
|
||||||
structopt = "0.3.23"
|
structopt = "0.3.26"
|
||||||
term_size = "0.3.2"
|
term_size = "0.3.2"
|
||||||
termcolor = "1.1.2"
|
termcolor = "1.1.3"
|
||||||
trust-dns-resolver = { version = "0.20.3", features = ["tokio-runtime"] }
|
trust-dns-resolver = { version = "0.21.2", features = ["tokio-runtime"] }
|
||||||
unicode-width = "0.1.9"
|
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]
|
[dependencies.async-minecraft-ping]
|
||||||
git = "https://github.com/LordMZTE/async-minecraft-ping.git"
|
git = "https://github.com/LordMZTE/async-minecraft-ping.git"
|
||||||
tag = "v0.3.0"
|
tag = "v0.3.0"
|
||||||
|
|
||||||
[dependencies.tokio]
|
[dependencies.tokio]
|
||||||
version = "1.12.0"
|
version = "1.17.0"
|
||||||
features = ["rt-multi-thread", "macros", "time"]
|
features = ["rt-multi-thread", "macros", "time"]
|
||||||
|
|
||||||
[build-dependencies]
|
|
||||||
clap = "2.33.3"
|
|
||||||
lazy_static = "1.4.0"
|
|
||||||
yaml-rust = "0.4.5"
|
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# mcstat
|
# mcstat
|
||||||
### This tool pings a minecraft server and displays information about it.
|
### This tool pings a minecraft server and displays information about it.
|
||||||
## Currently this includes
|
## This includes
|
||||||
- protocol version
|
- protocol version
|
||||||
- server version
|
- server version
|
||||||
- player count
|
- player count
|
||||||
|
@ -18,4 +18,4 @@
|
||||||
|
|
||||||
## TODO
|
## 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))
|
||||||
|
|
14
src/lib.rs
14
src/lib.rs
|
@ -1,20 +1,19 @@
|
||||||
#[macro_use]
|
|
||||||
extern crate smart_default;
|
|
||||||
|
|
||||||
use crate::output::Table;
|
use crate::output::Table;
|
||||||
|
use async_minecraft_ping::StatusResponse;
|
||||||
use crossterm::{
|
use crossterm::{
|
||||||
style::{Attribute, Color, Print, ResetColor, SetAttribute, SetForegroundColor},
|
style::{Attribute, Color, Print, ResetColor, SetAttribute, SetForegroundColor},
|
||||||
ExecutableCommand,
|
ExecutableCommand,
|
||||||
};
|
};
|
||||||
use image::{DynamicImage, ImageFormat};
|
use image::{DynamicImage, ImageFormat};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use log::info;
|
|
||||||
use miette::{bail, miette, IntoDiagnostic, WrapErr};
|
use miette::{bail, miette, IntoDiagnostic, WrapErr};
|
||||||
|
use tracing::info;
|
||||||
use std::{
|
use std::{
|
||||||
io::{self, Cursor, Write},
|
io::{self, Cursor, Write},
|
||||||
net::IpAddr,
|
net::IpAddr,
|
||||||
};
|
};
|
||||||
use trust_dns_resolver::TokioAsyncResolver;
|
use trust_dns_resolver::TokioAsyncResolver;
|
||||||
|
use serde::Deserialize;
|
||||||
|
|
||||||
pub mod output;
|
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)> {
|
pub async fn resolve_address(addr_and_port: &str) -> miette::Result<(String, u16)> {
|
||||||
info!("Resolving address");
|
info!("Resolving address");
|
||||||
let addr;
|
let addr;
|
||||||
|
|
25
src/main.rs
25
src/main.rs
|
@ -1,20 +1,16 @@
|
||||||
use async_minecraft_ping::{ConnectionConfig, ServerDescription, StatusResponse};
|
use async_minecraft_ping::{ConnectionConfig, ServerDescription, StatusResponse};
|
||||||
|
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use log::info;
|
|
||||||
use miette::{IntoDiagnostic, WrapErr};
|
use miette::{IntoDiagnostic, WrapErr};
|
||||||
use structopt::StructOpt;
|
use structopt::StructOpt;
|
||||||
use time::{Duration, Instant};
|
use time::{Duration, Instant};
|
||||||
use tokio::time;
|
use tokio::time;
|
||||||
|
|
||||||
use mcstat::{
|
use mcstat::{
|
||||||
get_table,
|
get_table, mc_formatted_to_ansi, none_if_empty, output::Table, parse_base64_image,
|
||||||
mc_formatted_to_ansi,
|
resolve_address, EitherStatusResponse,
|
||||||
none_if_empty,
|
|
||||||
output::Table,
|
|
||||||
parse_base64_image,
|
|
||||||
resolve_address,
|
|
||||||
};
|
};
|
||||||
|
use tracing::info;
|
||||||
|
|
||||||
#[derive(Debug, StructOpt)]
|
#[derive(Debug, StructOpt)]
|
||||||
#[structopt(
|
#[structopt(
|
||||||
|
@ -83,9 +79,7 @@ impl Opt {
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> miette::Result<()> {
|
async fn main() -> miette::Result<()> {
|
||||||
env_logger::try_init()
|
tracing_subscriber::fmt().pretty().init();
|
||||||
.into_diagnostic()
|
|
||||||
.wrap_err("Failed to init logger")?;
|
|
||||||
|
|
||||||
let opt = Opt::from_args();
|
let opt = Opt::from_args();
|
||||||
|
|
||||||
|
@ -125,7 +119,16 @@ async fn main() -> miette::Result<()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
info!("Parsing status");
|
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
|
// if the server has mods, and the user hasn't used the -m argument, notify
|
||||||
// that.
|
// that.
|
||||||
|
|
|
@ -2,6 +2,7 @@ use std::{
|
||||||
cmp::{max, min},
|
cmp::{max, min},
|
||||||
io::{self, Write},
|
io::{self, Write},
|
||||||
};
|
};
|
||||||
|
use smart_default::SmartDefault;
|
||||||
use unicode_width::UnicodeWidthStr;
|
use unicode_width::UnicodeWidthStr;
|
||||||
|
|
||||||
#[derive(SmartDefault)]
|
#[derive(SmartDefault)]
|
||||||
|
|
Loading…
Reference in a new issue