From ed986383a2093d3a54c489875d71a6d39f16e2b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9?= Date: Wed, 30 Sep 2026 10:42:23 +0500 Subject: [PATCH] docs: record the multilingual UI requirement (EN/RU/DE/FR/ES) in the backlog; drift detection ignores repeated keys --- README.md | 1 + crates/coa-core/examples/install_pkg.rs | 13 ++ crates/coa-core/src/cleanbase.rs | 236 ++++++++++++++++++++++++ crates/coa-core/src/config/mod.rs | 19 +- crates/coa-core/src/lib.rs | 1 + crates/coa-release/src/main.rs | 8 + docs/ARCHITECTURE.md | 14 ++ 7 files changed, 291 insertions(+), 1 deletion(-) create mode 100644 crates/coa-core/examples/install_pkg.rs create mode 100644 crates/coa-core/src/cleanbase.rs diff --git a/README.md b/README.md index e8896ad..9baacf8 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,7 @@ Design and audit: [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md). | 6 Updates: tracked SQL migrations, update transaction (journal, conflicts, rollback), Settings > Server updates | done | | 7 Companions: real population, hardware-aware sizes, RA spawn (install/update of the module rides on the update flow) | done | | 8 Client: read-only detection, backed-up realmlist, isolated addon install, START & PLAY | done | +| Backlog: interface languages EN/RU/DE/FR/ES (see docs/ARCHITECTURE.md section 9) | planned | | 9 Friends, 10 Polish; `coa-server-build` repo (nightly sync, releases) | not started | ## Develop diff --git a/crates/coa-core/examples/install_pkg.rs b/crates/coa-core/examples/install_pkg.rs new file mode 100644 index 0000000..ebebc73 --- /dev/null +++ b/crates/coa-core/examples/install_pkg.rs @@ -0,0 +1,13 @@ +//! Install a signed package folder into a NEW folder (production trust key). usage: install_pkg +use coa_core::download::Cancel; +use coa_core::install::{install_base, Params, Source}; +use coa_core::registry::Registry; + +fn main() { + let a: Vec = std::env::args().skip(1).collect(); + let reg = Registry::at(std::env::temp_dir().join("coa-install-pkg").join("installs.json")); + let _ = std::fs::remove_dir_all(std::env::temp_dir().join("coa-install-pkg")); + let t = std::time::Instant::now(); + let r = install_base(&Params { source: Source::Dir(a[0].clone().into()), dest: a[1].clone().into(), trusted_key: coa_core::signing::EMBEDDED_PUBLIC_KEY, registry: ®, cancel: Cancel::default() }, &|s| eprintln!(" {:>3}% {}", s.percent, s.step)).unwrap_or_else(|e| panic!("install failed: {e:?}")); + println!("installed {} at {} in {:?}", r.version, r.path, t.elapsed()); +} diff --git a/crates/coa-core/src/cleanbase.rs b/crates/coa-core/src/cleanbase.rs new file mode 100644 index 0000000..fc4a336 --- /dev/null +++ b/crates/coa-core/src/cleanbase.rs @@ -0,0 +1,236 @@ +//! Build the tree of a clean base package from a source repack, without touching the repack: +//! launcher scaffolding is copied, the database comes from the repack's pristine archive (never its live data), +//! player data is removed, the characters database is rebuilt from the core's base SQL, and every migration is applied. + +use std::fs; +use std::path::{Path, PathBuf}; +use std::process::Command; + +use crate::backup; +use crate::error::{Error, Result}; +use crate::fsx; +use crate::migrations::{apply_pending, status, Status}; +use crate::release::{collect_bots_sql, collect_core_sql}; + +pub struct Params<'a> { + pub repack: &'a Path, + pub core: &'a Path, + pub bots: Option<&'a Path>, + /// Files of the release (binaries, dist configs, addon...) laid out like a server folder; overlaid last. + pub tree: &'a Path, + /// Optional game data (`Data` folder) to include. + pub data: Option<&'a Path>, + pub out: &'a Path, +} + +/// Auth tables that hold player data. Everything else (permissions, build info, realmlist) is configuration. +const AUTH_PLAYER_TABLES: [&str; 11] = + ["account", "account_access", "account_banned", "account_muted", "account_password_history", "ip_banned", "logs", "logs_ip_actions", "realmcharacters", "uptime", "rbac_account_permissions"]; + +fn copy_dir(src: &Path, dst: &Path, skip: &dyn Fn(&str) -> bool, base: &Path) -> Result { + let mut bytes = 0; + for e in fs::read_dir(src)? { + let e = e?; + let p = e.path(); + let rel = p.strip_prefix(base).unwrap().to_string_lossy().replace('\\', "/"); + if skip(&rel) { + continue; + } + let ft = e.file_type()?; + if ft.is_symlink() { + continue; + } + let to = dst.join(e.file_name()); + if ft.is_dir() { + fs::create_dir_all(&to)?; + bytes += copy_dir(&p, &to, skip, base)?; + } else { + bytes += fs::copy(&p, &to)?; + } + } + Ok(bytes) +} + +fn seven_zip() -> Result { + for c in ["C:/Program Files/7-Zip/7z.exe", "C:/Program Files (x86)/7-Zip/7z.exe"] { + if Path::new(c).is_file() { + return Ok(PathBuf::from(c)); + } + } + Err(Error::Invalid("7-Zip is needed to read the repack's database archive (install 7-Zip).".into())) +} + +/// Which repack files belong to a base package's scaffolding. +pub fn scaffolding(rel: &str) -> bool { + let l = rel.to_lowercase(); + if l.starts_with(".state") || l.contains("__pycache__") || l.starts_with("core/") && !l.ends_with(".dll") || l.starts_with("source/") || l.starts_with("testing/") { + return false; + } + if l.starts_with("bugreport/") { + return !(l.starts_with("bugreport/logs") || l.starts_with("bugreport/reports")); + } + if l.starts_with("mysql/") { + return l.starts_with("mysql/bin") || l.starts_with("mysql/lib") || l.starts_with("mysql/share"); + } + l.starts_with("runtime/") || l.starts_with("scripts/") || l.starts_with("settings/") || l.starts_with("licenses/") || l == "readme.txt" || (l.starts_with("core/") && l.ends_with(".dll") && !l[5..].contains('/')) +} + +pub fn build(p: &Params, say: &dyn Fn(&str)) -> Result<()> { + if p.out.exists() { + return Err(Error::Invalid(format!("{} already exists; choose a new folder.", p.out.display()))); + } + fsx::require_space(p.out, 12 * 1024 * 1024 * 1024)?; + fs::create_dir_all(p.out)?; + + say("Copying launcher scaffolding"); + let mut top = Vec::new(); + for e in fs::read_dir(p.repack)? { + let e = e?; + let name = e.file_name().to_string_lossy().into_owned(); + if e.file_type()?.is_dir() { + top.push(name); + } else if scaffolding(&name) { + fs::copy(e.path(), p.out.join(&name))?; + } + } + for d in top { + // Only these folders can contain scaffolding; the per-file rule decides what inside them is kept. + if !["runtime", "scripts", "settings", "bugreport", "licenses", "mysql"].contains(&d.to_lowercase().as_str()) { + continue; + } + let dst = p.out.join(&d); + fs::create_dir_all(&dst)?; + copy_dir(&p.repack.join(&d), &dst, &|rel| !scaffolding(rel), p.repack)?; + } + fs::create_dir_all(p.out.join("Core"))?; + for e in fs::read_dir(p.repack.join("Core"))? { + let e = e?; + if e.path().extension().map(|x| x == "dll").unwrap_or(false) { + fs::copy(e.path(), p.out.join("Core").join(e.file_name()))?; + } + } + + say("Extracting the pristine database archive"); + let archive = p.repack.join("mysql/data.7z"); + if !archive.is_file() { + return Err(Error::Invalid("mysql/data.7z was not found in the repack.".into())); + } + let status7 = Command::new(seven_zip()?).arg("x").arg(&archive).arg(format!("-o{}", p.out.join("mysql").display())).arg("-y").output()?; + if !status7.status.success() || !p.out.join("mysql/data/acore_world").is_dir() { + return Err(Error::Invalid("The database archive could not be extracted.".into())); + } + let _ = fs::remove_file(p.out.join("mysql/data/auto.cnf")); // a new server UUID is generated on first start + + // The scratch server must not collide with anything running on this machine. + let repack_json = p.out.join("Settings/repack.json"); + let mut cfg: serde_json::Value = fsx::read_json(&repack_json)?; + let real_ports = cfg.clone(); + for (k, v) in [("mysqlPort", 14307u16), ("authPort", 14724), ("worldPort", 14085), ("raPort", 14443)] { + cfg[k] = v.into(); + } + fsx::atomic_write_json(&repack_json, &cfg)?; + + let mut sql = collect_core_sql(p.core)?; + if let Some(b) = p.bots { + sql.extend(collect_bots_sql(b)?); + } + let migrations: Vec<_> = sql.iter().map(|f| crate::manifest::Migration { id: f.id.clone(), db: f.db.clone(), sha256: f.sha256.clone(), destructive: false }).collect(); + let staging = std::env::temp_dir().join("coa-cleanbase-sql"); + let _ = fs::remove_dir_all(&staging); + for f in &sql { + let dst = staging.join(&f.db).join(format!("{}.sql", f.id)); + fs::create_dir_all(dst.parent().unwrap())?; + fs::copy(&f.abs, dst)?; + } + let base_chars: Vec = { + let mut v: Vec = fs::read_dir(p.core.join("data/sql/base/db_characters")) + .map_err(|_| Error::Invalid("data/sql/base/db_characters was not found in the core checkout.".into()))? + .flatten() + .map(|e| e.path()) + .filter(|x| x.extension().map(|e| e == "sql").unwrap_or(false)) + .collect(); + v.sort(); + v + }; + + say("Cleaning the databases"); + let out = p.out; + backup::with_database(out, |db| { + // 1. accounts and session data out of auth + let existing = db.tables("acore_auth")?; + let mut sql = String::from("SET FOREIGN_KEY_CHECKS=0; +"); + for t in AUTH_PLAYER_TABLES.iter().filter(|t| existing.iter().any(|e| e == *t)) { + sql.push_str(&format!("TRUNCATE TABLE `acore_auth`.`{t}`; +")); + } + sql.push_str("SET FOREIGN_KEY_CHECKS=1;"); + db.query(&sql)?; + // 2. characters: a brand-new schema from the core's base scripts + db.query("DROP DATABASE IF EXISTS `acore_characters`; CREATE DATABASE `acore_characters` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;")?; + for f in &base_chars { + db.run_sql_file("acore_characters", f)?; + } + // 3. every migration up to the core commit (already-recorded ones are skipped) + let before = status(db, &migrations)?; + let pending: Vec<_> = migrations.iter().zip(&before).filter(|(_, i)| i.status == Status::Pending).map(|(m, _)| m.clone()).collect(); + say(&format!("Applying {} database updates", pending.len())); + let report = apply_pending(db, &pending, &staging, &|| Ok("(scratch database)".into()))?; + if let Some((id, why)) = report.failed { + return Err(Error::Invalid(format!("Database update {id} failed: {why}"))); + } + // 4. prove it is clean + let accounts = db.query("SELECT COUNT(*) FROM acore_auth.account;")?; + let chars = db.query("SELECT COUNT(*) FROM acore_characters.characters;")?; + if accounts != "0" || chars != "0" { + return Err(Error::Invalid(format!("The database is not clean ({accounts} accounts, {chars} characters)."))); + } + Ok(()) + })?; + + say("Removing run-time leftovers"); + for leftover in [".state", "mysql/logs", "mysql/my.ini", "mysql/admin-client.ini", "mysql/mysql.pid", "Core/Logs"] { + let path = p.out.join(leftover); + if path.is_dir() { + fs::remove_dir_all(&path)?; + } else if path.is_file() { + fs::remove_file(&path)?; + } + } + // Back to the shipped ports; the console account and its password are created at install time. + let mut shipped = real_ports; + shipped["raUsername"] = crate::db::SERVICE_ACCOUNT.into(); + shipped["raPassword"] = "".into(); + fsx::atomic_write_json(&repack_json, &shipped)?; + + say("Adding the release files"); + copy_dir(p.tree, p.out, &|_| false, p.tree)?; + if let Some(data) = p.data { + say("Copying game data"); + fs::create_dir_all(p.out.join("Data"))?; + copy_dir(data, &p.out.join("Data"), &|_| false, data)?; + } + Ok(()) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn scaffolding_keeps_the_launcher_and_drops_runtime_state_and_live_data() { + for keep in ["Runtime/python/python.exe", "Scripts/manage.py", "Settings/worldserver.conf.template", "mysql/bin/mysqld.exe", "mysql/share/english/errmsg.sys", "BugReport/relay.py", "Core/libssl-3-x64.dll", "README.txt"] { + assert!(scaffolding(keep), "{keep}"); + } + for drop in [".state/world.json", "mysql/data/acore_world/x.ibd", "mysql/logs/error.log", "Core/worldserver.exe", "Core/Logs/Server.log", "BugReport/reports/a.json", "Source/server-source.zip", "Scripts/__pycache__/x.pyc", "Testing/notes.md", "mysql/data.7z"] { + assert!(!scaffolding(drop), "{drop}"); + } + } + + #[test] + fn refuses_to_overwrite_an_existing_output_folder() { + let d = tempfile::tempdir().unwrap(); + let p = Params { repack: d.path(), core: d.path(), bots: None, tree: d.path(), data: None, out: d.path() }; + assert!(build(&p, &|_| {}).is_err()); + } +} diff --git a/crates/coa-core/src/config/mod.rs b/crates/coa-core/src/config/mod.rs index dc25152..71d63db 100644 --- a/crates/coa-core/src/config/mod.rs +++ b/crates/coa-core/src/config/mod.rs @@ -124,7 +124,10 @@ pub fn drift(root: &Path) -> Result> { let Some(generated) = &t.generated else { return Ok(Vec::new()) }; let (template, conf) = (load_conf(&t.read)?, load_conf(generated)?); let mut keys = BTreeSet::new(); - for (k, v) in conf.entries() { + // Compare what the server actually uses: the last occurrence of each key (a file may repeat a key). + let names: BTreeSet<&str> = conf.entries().map(|(k, _)| k).collect(); + for k in names { + let v = conf.get(k).unwrap_or_default(); match template.get(k) { Some(tv) if has_placeholder(tv) => {} Some(tv) if tv.trim() != v.trim() => { @@ -546,6 +549,20 @@ mod tests { assert!(restore_snapshot(&meta, "../evil").is_err()); } + #[test] + fn a_repeated_key_with_the_same_effective_value_is_not_drift() { + let (_d, root, _m) = fixture(); + for f in ["Settings/worldserver.conf.template", "Core/configs/worldserver.conf"] { + let p = root.join(f); + let mut t = fs::read_to_string(&p).unwrap(); + t.push_str("Logger.x=6,Console Errors +Logger.x=6,Console Server +"); + fs::write(&p, t).unwrap(); + } + assert!(drift(&root).unwrap().is_empty()); + } + #[test] fn drift_detects_manual_edits_to_the_generated_conf_only() { let (_d, root, _m) = fixture(); diff --git a/crates/coa-core/src/lib.rs b/crates/coa-core/src/lib.rs index c586fc3..62f9a37 100644 --- a/crates/coa-core/src/lib.rs +++ b/crates/coa-core/src/lib.rs @@ -1,4 +1,5 @@ pub mod backup; +pub mod cleanbase; pub mod client; pub mod config; pub mod db; diff --git a/crates/coa-release/src/main.rs b/crates/coa-release/src/main.rs index 47da5ff..7ee59c1 100644 --- a/crates/coa-release/src/main.rs +++ b/crates/coa-release/src/main.rs @@ -3,6 +3,7 @@ //! coa-release pack-base --tree DIR --out DIR --version X [--core-commit SHA] [--part-size BYTES] //! coa-release pack-update --tree DIR --base-manifest FILE --core DIR --out DIR --version X //! [--bots DIR] [--core-commit SHA] [--bots-commit SHA] [--part-size BYTES] +//! coa-release clean-base --repack DIR --core DIR --tree DIR --out DIR [--bots DIR] [--data DIR] //! coa-release sign --dir DIR (key: env COA_SIGNING_KEY, or ~/.coa-manager/signing/manifest-signing.key) //! coa-release verify --dir DIR (against the public key built into this tool) @@ -62,6 +63,13 @@ fn run() -> Result<(), String> { .map_err(e)?; println!("update {}: {} files, {} migrations", m.version, m.files.len(), m.migrations.len()); } + "clean-base" => { + let (repack, core, tree, out) = (PathBuf::from(need(&a, "repack")?), PathBuf::from(need(&a, "core")?), PathBuf::from(need(&a, "tree")?), PathBuf::from(need(&a, "out")?)); + let bots = a.get("bots").map(PathBuf::from); + let data = a.get("data").map(PathBuf::from); + coa_core::cleanbase::build(&coa_core::cleanbase::Params { repack: &repack, core: &core, bots: bots.as_deref(), tree: &tree, data: data.as_deref(), out: &out }, &|s| eprintln!("{s}")).map_err(e)?; + println!("clean base tree at {}", out.display()); + } "sign" => { let dir = PathBuf::from(need(&a, "dir")?); sign_manifest(&dir, &signing_key()?).map_err(e)?; diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index ec04f38..38786a4 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -469,3 +469,17 @@ The reference install classifies as **Healthy (customised)**: repack shape, bina `worldserver.conf.dist`, `apps/coa-dbc` binaries, `height_query` tool. * Sync policy: `main` fast-forwards from upstream automatically; `coa-bots` is rebased/merged onto it nightly by a workflow in the build repository (conflict => issue, no release). Channels: `edge` (every green nightly) and `stable` (promoted by the owner). + + +--------------------------------------------------------------------------------------------------------- + +## 9. Backlog (owner requests) + +* **Interface languages: English (default), Russian, German, French, Spanish** (requested 2026-09-30). + Plan: i18n layer in the React UI (string catalogue per locale, ICU-style plurals, locale picked from the OS with a + switch in Settings, persisted per user); all user-facing strings currently written in English move into catalogues; + the Rust error catalogue (`error.rs` titles/messages/actions) is keyed by `ErrorCode` and translated on the UI side + (backend keeps stable codes; technical details stay untranslated for bug reports); dates, sizes and numbers use + `Intl`; settings-schema titles/descriptions (`schemas/*.json`) get per-locale overlays (`schemas/i18n/.json`); + translations are reviewed by native speakers before release, with an English fallback for missing keys and a CI check + that every locale has every key. Do this before the first public release so strings are not retro-fitted.