diff --git a/docs/config/basic.md b/docs/config/basic.md index ac8b118f..8d224a02 100644 --- a/docs/config/basic.md +++ b/docs/config/basic.md @@ -115,3 +115,11 @@ Creative Adventure Spectator ``` + +### IP Scrubbing + +Whether to scrub player IPs from logs + +```toml +scrub_ips=true +``` diff --git a/pumpkin-config/src/lib.rs b/pumpkin-config/src/lib.rs index 6062bb25..49821864 100644 --- a/pumpkin-config/src/lib.rs +++ b/pumpkin-config/src/lib.rs @@ -94,6 +94,9 @@ pub struct BasicConfiguration { /// The default game mode for players. #[serde_inline_default(GameMode::Survival)] pub default_gamemode: GameMode, + /// Whether to remove IPs from logs or not + #[serde_inline_default(true)] + pub scrub_ips: bool, } fn default_server_address() -> SocketAddr { @@ -115,6 +118,7 @@ impl Default for BasicConfiguration { encryption: true, motd: "A Blazing fast Pumpkin Server!".to_string(), default_gamemode: GameMode::Survival, + scrub_ips: true, } } } diff --git a/pumpkin/src/main.rs b/pumpkin/src/main.rs index 093efc09..e4e10f63 100644 --- a/pumpkin/src/main.rs +++ b/pumpkin/src/main.rs @@ -39,6 +39,17 @@ pub mod rcon; pub mod server; pub mod world; +fn scrub_address(ip: &str) -> String { + use pumpkin_config::BASIC_CONFIG; + if BASIC_CONFIG.scrub_ips { + ip.chars() + .map(|ch| if ch == '.' || ch == ':' { ch } else { 'x' }) + .collect() + } else { + ip.to_string() + } +} + fn init_logger() { use pumpkin_config::ADVANCED_CONFIG; if ADVANCED_CONFIG.logging.enabled { @@ -196,7 +207,10 @@ fn main() -> io::Result<()> { log::warn!("failed to set TCP_NODELAY {e}"); } - log::info!("Accepted connection from: {}", address); + log::info!( + "Accepted connection from: {}", + scrub_address(&format!("{}", address)) + ); let token = next(&mut unique_token); poll.registry().register(