feat: add connection filters; and config struct;
also move sanitize_addr to mc_server module
This commit is contained in:
parent
3dcf2f03a8
commit
822330ef87
7 changed files with 94 additions and 41 deletions
|
|
@ -11,7 +11,7 @@ use tokio::task::JoinHandle;
|
|||
use tracing::Instrument;
|
||||
|
||||
use crate::{
|
||||
mc_server::{MinecraftAPI, MinecraftServerHandle, ServerDeploymentStatus},
|
||||
mc_server::{sanitize_addr, MinecraftAPI, MinecraftServerHandle, ServerDeploymentStatus},
|
||||
packets::{
|
||||
clientbound::status::StatusTrait,
|
||||
serverbound::handshake::{self},
|
||||
|
|
@ -430,34 +430,3 @@ impl From<kube::Error> for OpaqueError {
|
|||
OpaqueError::create(value.to_string().as_str())
|
||||
}
|
||||
}
|
||||
|
||||
fn terminate_at_null(str: &str) -> &str {
|
||||
match str.split('\0').next() {
|
||||
Some(x) => x,
|
||||
None => str,
|
||||
}
|
||||
}
|
||||
|
||||
fn sanitize_addr(addr: &str) -> &str {
|
||||
// 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 addr = addr.trim_end_matches(".");
|
||||
|
||||
// Modded minecraft clients send null terminated strings,
|
||||
// after which they have extra data. This just removes them
|
||||
// from the addr lookup
|
||||
let addr = terminate_at_null(addr);
|
||||
addr
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue