comment out impl (#5468)
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -10049,6 +10049,7 @@ version = "1.0.0-local"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"ariadne",
|
"ariadne",
|
||||||
"async-compression",
|
"async-compression",
|
||||||
|
"async-minecraft-ping",
|
||||||
"async-recursion",
|
"async-recursion",
|
||||||
"async-tungstenite",
|
"async-tungstenite",
|
||||||
"async-walkdir",
|
"async-walkdir",
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ edition.workspace = true
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
ariadne = { workspace = true }
|
ariadne = { workspace = true }
|
||||||
async-compression = { workspace = true, features = ["gzip", "tokio"] }
|
async-compression = { workspace = true, features = ["gzip", "tokio"] }
|
||||||
|
async-minecraft-ping = { workspace = true, features = ["srv"] }
|
||||||
async-recursion = { workspace = true }
|
async-recursion = { workspace = true }
|
||||||
async-tungstenite = { workspace = true, features = [
|
async-tungstenite = { workspace = true, features = [
|
||||||
"tokio-runtime",
|
"tokio-runtime",
|
||||||
|
|||||||
@@ -12,7 +12,8 @@ pub use crate::util::server_ping::{
|
|||||||
ServerGameProfile, ServerPlayers, ServerStatus, ServerVersion,
|
ServerGameProfile, ServerPlayers, ServerStatus, ServerVersion,
|
||||||
};
|
};
|
||||||
use crate::util::{io, server_ping};
|
use crate::util::{io, server_ping};
|
||||||
use crate::{ErrorKind, Result, State, launcher};
|
use crate::{Error, ErrorKind, Result, State, launcher};
|
||||||
|
use async_minecraft_ping::ServerDescription;
|
||||||
use async_walkdir::WalkDir;
|
use async_walkdir::WalkDir;
|
||||||
use async_zip::{Compression, ZipEntryBuilder};
|
use async_zip::{Compression, ZipEntryBuilder};
|
||||||
use chrono::{DateTime, Local, TimeZone, Utc};
|
use chrono::{DateTime, Local, TimeZone, Utc};
|
||||||
@@ -23,10 +24,12 @@ use futures::StreamExt;
|
|||||||
use quartz_nbt::{NbtCompound, NbtTag};
|
use quartz_nbt::{NbtCompound, NbtTag};
|
||||||
use regex::{Regex, RegexBuilder};
|
use regex::{Regex, RegexBuilder};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
use serde_json::value::RawValue;
|
||||||
use std::cmp::Reverse;
|
use std::cmp::Reverse;
|
||||||
use std::io::Cursor;
|
use std::io::Cursor;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::sync::LazyLock;
|
use std::sync::LazyLock;
|
||||||
|
use std::time::Instant;
|
||||||
use tokio::io::AsyncWriteExt;
|
use tokio::io::AsyncWriteExt;
|
||||||
use tokio::task::JoinSet;
|
use tokio::task::JoinSet;
|
||||||
use tokio_util::compat::FuturesAsyncWriteCompatExt;
|
use tokio_util::compat::FuturesAsyncWriteCompatExt;
|
||||||
@@ -913,6 +916,18 @@ pub async fn get_profile_protocol_version(
|
|||||||
pub async fn get_server_status(
|
pub async fn get_server_status(
|
||||||
address: &str,
|
address: &str,
|
||||||
protocol_version: Option<ProtocolVersion>,
|
protocol_version: Option<ProtocolVersion>,
|
||||||
|
) -> Result<ServerStatus> {
|
||||||
|
tracing::debug!(
|
||||||
|
"Pinging {address} with protocol version {protocol_version:?}"
|
||||||
|
);
|
||||||
|
|
||||||
|
get_server_status_old(address, protocol_version).await
|
||||||
|
// get_server_status_new(address, protocol_version).await
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn get_server_status_old(
|
||||||
|
address: &str,
|
||||||
|
protocol_version: Option<ProtocolVersion>,
|
||||||
) -> Result<ServerStatus> {
|
) -> Result<ServerStatus> {
|
||||||
let (original_host, original_port) = parse_server_address(address)?;
|
let (original_host, original_port) = parse_server_address(address)?;
|
||||||
let (host, port) =
|
let (host, port) =
|
||||||
@@ -927,3 +942,87 @@ pub async fn get_server_status(
|
|||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn _get_server_status_new(
|
||||||
|
address: &str,
|
||||||
|
protocol_version: Option<ProtocolVersion>,
|
||||||
|
) -> Result<ServerStatus> {
|
||||||
|
let (address, port) = match address.rsplit_once(':') {
|
||||||
|
Some((addr, port)) => {
|
||||||
|
let port = port.parse::<u16>().map_err(|_err| {
|
||||||
|
Error::from(ErrorKind::InputError("invalid port number".into()))
|
||||||
|
})?;
|
||||||
|
(addr, port)
|
||||||
|
}
|
||||||
|
None => (address, 25565),
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut builder = async_minecraft_ping::ConnectionConfig::build(address)
|
||||||
|
.with_port(port)
|
||||||
|
.with_srv_lookup();
|
||||||
|
|
||||||
|
if let Some(version) = protocol_version {
|
||||||
|
builder = builder.with_protocol_version(version.version as usize)
|
||||||
|
}
|
||||||
|
|
||||||
|
let conn = builder.connect().await.map_err(|_err| {
|
||||||
|
Error::from(ErrorKind::InputError("failed to connect to server".into()))
|
||||||
|
})?;
|
||||||
|
|
||||||
|
let ping_conn = conn.status().await.map_err(|_err| {
|
||||||
|
Error::from(ErrorKind::InputError("failed to get server status".into()))
|
||||||
|
})?;
|
||||||
|
let status = &ping_conn.status;
|
||||||
|
let description = match &status.description {
|
||||||
|
ServerDescription::Plain(text) => {
|
||||||
|
serde_json::value::to_raw_value(&text).ok()
|
||||||
|
}
|
||||||
|
ServerDescription::Object { text } => {
|
||||||
|
// TODO: `text` always seems to be empty?
|
||||||
|
RawValue::from_string(text.clone()).ok()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let players = ServerPlayers {
|
||||||
|
max: status.players.max.cast_signed(),
|
||||||
|
online: status.players.online.cast_signed(),
|
||||||
|
sample: status
|
||||||
|
.players
|
||||||
|
.sample
|
||||||
|
.as_ref()
|
||||||
|
.map(|sample| {
|
||||||
|
sample
|
||||||
|
.iter()
|
||||||
|
.map(|player| ServerGameProfile {
|
||||||
|
id: player.id.clone(),
|
||||||
|
name: player.name.clone(),
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
})
|
||||||
|
.unwrap_or_default(),
|
||||||
|
};
|
||||||
|
let version = ServerVersion {
|
||||||
|
name: status.version.name.clone(),
|
||||||
|
protocol: status.version.protocol,
|
||||||
|
legacy: false,
|
||||||
|
};
|
||||||
|
let favicon = status.favicon.as_ref().and_then(|url| url.parse().ok());
|
||||||
|
|
||||||
|
let latency = {
|
||||||
|
let start = Instant::now();
|
||||||
|
let ping_magic = Utc::now().timestamp_millis().cast_unsigned();
|
||||||
|
ping_conn.ping(ping_magic).await.map_err(|_err| {
|
||||||
|
Error::from(ErrorKind::InputError("failed to do ping".into()))
|
||||||
|
})?;
|
||||||
|
start.elapsed().as_millis() as i64
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(ServerStatus {
|
||||||
|
description,
|
||||||
|
players: Some(players),
|
||||||
|
version: Some(version),
|
||||||
|
favicon,
|
||||||
|
enforces_secure_chat: false,
|
||||||
|
ping: Some(latency),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user