Unify server pinging implementations between app and backend (#5510)

* Improve ping impl to bring parity to app lib impl

* Fix issue with new impl

* fix labrinth compile

* wip: why do servers not provide server info..

* Fix ping impl overriding port

* fix theseus_gui

* remove unneeded recursion lmit
This commit is contained in:
aecsocket
2026-03-13 16:21:09 +00:00
committed by GitHub
parent 991b4d8c13
commit d14360aba5
13 changed files with 246 additions and 225 deletions
+1 -1
View File
@@ -318,7 +318,7 @@ macro_rules! get_resource_file {
Ok(dir) => dir,
Err(e) => {
break 'get_resource_file $crate::Result::Err(
$crate::util::io::IOError::from(e).into(),
$crate::Error::from($crate::util::io::IOError::from(e)),
);
}
};
@@ -1,53 +1,3 @@
use crate::ErrorKind;
use crate::error::Result;
use crate::util::protocol_version::ProtocolVersion;
use serde::{Deserialize, Serialize};
use serde_json::value::RawValue;
use std::time::Duration;
use tokio::net::ToSocketAddrs;
use tokio::select;
use url::Url;
#[derive(Deserialize, Serialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct ServerStatus {
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<Box<RawValue>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub players: Option<ServerPlayers>,
#[serde(skip_serializing_if = "Option::is_none")]
pub version: Option<ServerVersion>,
#[serde(skip_serializing_if = "Option::is_none")]
pub favicon: Option<Url>,
#[serde(default)]
pub enforces_secure_chat: bool,
#[serde(skip_serializing_if = "Option::is_none")]
pub ping: Option<i64>,
}
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct ServerPlayers {
pub max: i32,
pub online: i32,
#[serde(default)]
pub sample: Vec<ServerGameProfile>,
}
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct ServerGameProfile {
pub id: String,
pub name: String,
}
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct ServerVersion {
pub name: String,
pub protocol: i32,
#[serde(skip_deserializing)]
pub legacy: bool,
}
pub async fn get_server_status(
address: &impl ToSocketAddrs,
original_address: (&str, u16),
@@ -305,8 +255,8 @@ mod legacy {
}),
description: parts.next().and_then(|x| to_raw_value(x).ok()),
players: Some(ServerPlayers {
online: parts.next().and_then(|x| x.parse().ok()).unwrap_or(-1),
max: parts.next().and_then(|x| x.parse().ok()).unwrap_or(-1),
online: parts.next().and_then(|x| x.parse().ok()),
max: parts.next().and_then(|x| x.parse().ok()),
sample: vec![],
}),
favicon: None,
@@ -0,0 +1,43 @@
use serde::{Deserialize, Serialize};
use serde_json::value::RawValue;
use url::Url;
#[derive(Deserialize, Serialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct ServerStatus {
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<Box<RawValue>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub players: Option<ServerPlayers>,
#[serde(skip_serializing_if = "Option::is_none")]
pub version: Option<ServerVersion>,
#[serde(skip_serializing_if = "Option::is_none")]
pub favicon: Option<Url>,
#[serde(default)]
pub enforces_secure_chat: bool,
#[serde(skip_serializing_if = "Option::is_none")]
pub ping: Option<i64>,
}
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct ServerPlayers {
pub max: Option<i32>,
pub online: Option<i32>,
#[serde(default)]
pub sample: Vec<ServerGameProfile>,
}
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct ServerGameProfile {
pub id: String,
pub name: String,
}
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct ServerVersion {
pub name: String,
pub protocol: i32,
#[serde(skip_deserializing)]
pub legacy: bool,
}