Files
horizon-airdef/crates/horizon-client/src/server/eula.rs
T
Ludovic Marie 01db93a987 Port server.properties, eula.txt and the server user lists
DedicatedServerProperties with every key, default, parser and serializer,
java.util.Properties load/store, Eula and the four StoredUserList files,
checked against the pinned server JAR by test_server_files_parity.py.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-12 17:34:57 +02:00

39 lines
1.3 KiB
Rust

//! eula.txt (net.minecraft.server.Eula): the server runs only once the file
//! says `eula=true`; a file that is missing or unreadable is replaced with
//! the default one and counts as not agreed.
use super::java_properties::{Properties, date_string, now_millis};
use std::path::Path;
/// CommonLinks.EULA.
pub const EULA_LINK: &str = "https://aka.ms/MinecraftEULA";
/// The default file, as Properties.store(OutputStream) writes it.
pub fn default_file(millis: i64) -> String {
let mut p = Properties::default();
p.put("eula", "false".into());
p.store(
Some(&format!(
"By changing the setting below to TRUE you are indicating your agreement to our EULA ({EULA_LINK})."
)),
&date_string(millis),
true,
)
}
/// Eula.readFile; `Err` carries the warning vanilla logs.
pub fn agreed(path: &Path) -> Result<bool, String> {
let read = std::fs::read(path)
.map_err(|e| e.to_string())
.and_then(|b| Properties::load_latin1(&b).map_err(|e| e.to_string()));
match read {
Ok(p) => Ok(p
.get("eula")
.unwrap_or("false")
.eq_ignore_ascii_case("true")),
Err(_) => {
let _ = std::fs::write(path, default_file(now_millis()));
Err(format!("Failed to load {}", path.display()))
}
}
}