From 2eb9adc61a20bde56e5544ba52778c69030055fe Mon Sep 17 00:00:00 2001 From: Tamipes Date: Thu, 11 Dec 2025 02:26:08 +0100 Subject: [PATCH] feat: add some botched old address support --- src/kube_cache.rs | 4 ++-- src/main.rs | 20 ++++++++++++++++++-- src/mc_server.rs | 2 +- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/kube_cache.rs b/src/kube_cache.rs index 1c6555d..7a6b6ae 100644 --- a/src/kube_cache.rs +++ b/src/kube_cache.rs @@ -84,7 +84,7 @@ pub struct McApi { impl MinecraftAPI for McApi { #[tracing::instrument(name = "MinecraftAPI::query_server", level = "info", skip(self))] - async fn query_server(&self, addr: String) -> Result { + async fn query_server(&self, addr: &str) -> Result { let dep_name = match self.cache.query_dep_addr(&addr).await { Some(x) => x, None => { @@ -137,7 +137,7 @@ impl MinecraftAPI for McApi { async move { tracing::info!("starting watch"); tokio::time::sleep(frequency).await; - let server = self.query_server(addr.clone()).await.unwrap(); + let server = self.query_server(&addr).await.unwrap(); let status_json = match server.query_description().await { Ok(x) => x, Err(e) => { diff --git a/src/main.rs b/src/main.rs index 2a10663..a1f4522 100644 --- a/src/main.rs +++ b/src/main.rs @@ -129,7 +129,7 @@ async fn handle_status( status_struct.version.protocol = handshake.protocol_version.get_int(); let bye_message = format!(" - §dTami§r with §d<3§r §8(rev: {commit_hash})§r"); - let server = match api.query_server(handshake.get_server_address()).await { + let server = match api.query_server(&handshake.get_server_address()).await { Ok(x) => x, Err(e) => { tracing::warn!(err = e.context); @@ -186,7 +186,23 @@ async fn handle_login( handshake: &Handshake, api: impl MinecraftAPI, ) -> Result<(), OpaqueError> { - let server = api.query_server(handshake.get_server_address()).await?; + let addr = handshake.get_server_address(); + // Thanks to a buggy minecraft, when the client sends a join + // from a SRV DNS record, it will not use the address typed + // in the game, but use the address redicted *to* by the + // DNS record as the address for joining, plus a trailing "." + // + // For example: + // server.example.com (_minecraft._tcp.server.example.com) + // (the typed address) I (the DNS SRV record which gets read) + // V + // 5 25565 server.example.com + // I (the response for the DNS SRV query) + // V + // server.example.com. + // (the address used in the protocol) + let server = api.query_server(addr.trim_end_matches(".")).await?; + let status = server.query_status().await?; tracing::debug!(msg = "server status", status = ?status); match status { diff --git a/src/mc_server.rs b/src/mc_server.rs index 3d028fc..e74a044 100644 --- a/src/mc_server.rs +++ b/src/mc_server.rs @@ -124,7 +124,7 @@ pub trait MinecraftServerHandle: Clone { } pub trait MinecraftAPI { - async fn query_server(&self, addr: String) -> Result; + async fn query_server(&self, addr: &str) -> Result; async fn start_watch( self, server: impl MinecraftServerHandle,