From 0250b61c621d0fd13f969ef0e71a6e404c39019b Mon Sep 17 00:00:00 2001 From: "Fabien F." <8136686+lostmind84@users.noreply.github.com> Date: Sun, 4 Oct 2026 10:40:03 +0200 Subject: [PATCH] feat: a wrong game data folder is diagnosed, and it can be changed from Settings The world refusing to start with the standard Data set (no CoA DBC) is now reported as GameDataMismatch. A Settings card shows the folder in use and changes it while the server is stopped, using the install checks. --- crates/coa-core/src/docker/install.rs | 2 +- crates/coa-core/src/docker/mod.rs | 45 +++++++++++++++++++++++++++ crates/coa-core/src/error.rs | 6 ++++ crates/coa-core/src/health.rs | 9 ++++++ docs/ARCHITECTURE.md | 4 +++ src-tauri/src/lib.rs | 27 ++++++++++++++++ src/dev/mock.ts | 2 ++ src/i18n/locales/en.ts | 7 +++++ src/lib/api.ts | 3 ++ src/screens/GameDataCard.tsx | 44 ++++++++++++++++++++++++++ src/screens/SettingsHome.tsx | 3 ++ 11 files changed, 151 insertions(+), 1 deletion(-) create mode 100644 src/screens/GameDataCard.tsx diff --git a/crates/coa-core/src/docker/install.rs b/crates/coa-core/src/docker/install.rs index e427c18..48ef998 100644 --- a/crates/coa-core/src/docker/install.rs +++ b/crates/coa-core/src/docker/install.rs @@ -112,7 +112,7 @@ pub fn preflight(dest: &Path, data_dir: &Path, needed_bytes: u64, registry: &Reg Preflight { ok: problems.is_empty(), problems, free_bytes } } -fn data_problems(data_dir: &Path) -> Vec { +pub(crate) fn data_problems(data_dir: &Path) -> Vec { let s = data_dir.to_string_lossy(); if !data_dir.is_absolute() || s.contains(':') { return vec![problem("data_path", "Choose the game data folder with its full path, without a colon in it.")]; diff --git a/crates/coa-core/src/docker/mod.rs b/crates/coa-core/src/docker/mod.rs index 4edf3d4..0ad30e2 100644 --- a/crates/coa-core/src/docker/mod.rs +++ b/crates/coa-core/src/docker/mod.rs @@ -189,6 +189,29 @@ pub(crate) fn env_name(key: &str) -> String { out } +/// The folder mounted as the game data of this Docker server. +pub fn game_data_dir(root: &Path) -> Result { + Ok(Config::load(root)?.data_path(root)) +} + +/// Point a Docker server at another game data folder (used in place, read-only). The containers are recreated at the next +/// start, so the servers must be stopped: a running one keeps the folder it has. +pub fn set_game_data(root: &Path, path: &Path) -> Result<()> { + let problems = install::data_problems(path); + if !problems.is_empty() { + return Err(Error::Invalid(problems.iter().map(|p| p.message.clone()).collect::>().join(" "))); + } + let observed = crate::process::observe(root, &crate::layout::read_ports(root)); + let busy = |s: &crate::process::ServiceStatus| matches!(s.state, crate::process::ServiceState::Running | crate::process::ServiceState::Starting | crate::process::ServiceState::Stopping); + if busy(&observed.world) || busy(&observed.auth) { + return Err(Error::Invalid("Stop the server before changing the game data folder.".into())); + } + let mut cfg = Config::load(root)?; + cfg.data_dir = Some(path.to_string_lossy().into_owned()); + cfg.validate()?; + fsx::atomic_write_json(&root.join(MARKER), &cfg) +} + /// A reason a value cannot work on a Docker server, for settings that name a path: the server runs in a container that sees only /// its own `Core` folder (as `/srv/core`, its working directory), so a path elsewhere on this computer does not exist for it. pub fn setting_problem(key: &str, raw: &str) -> Option<&'static str> { @@ -264,6 +287,28 @@ mod tests { use super::*; use std::fs; + #[cfg(unix)] + #[test] + fn the_game_data_folder_can_be_changed_when_the_servers_are_stopped() { + let d = tempfile::tempdir().unwrap(); + let root = d.path().join("srv"); + std::fs::create_dir_all(root.join("Settings")).unwrap(); + std::fs::write(root.join(MARKER), r#"{"project":"t1","dataDir":"/old/data"}"#).unwrap(); + let good = d.path().join("data"); + std::fs::create_dir_all(good.join("dbc")).unwrap(); + std::fs::create_dir_all(good.join("maps")).unwrap(); + assert_eq!(game_data_dir(&root).unwrap(), std::path::PathBuf::from("/old/data")); + set_game_data(&root, &good).unwrap(); + assert_eq!(game_data_dir(&root).unwrap(), good); + assert_eq!(Config::load(&root).unwrap().project, "t1", "the other settings are kept"); + // A folder that does not look like game data is refused and nothing changes. + let empty = d.path().join("empty"); + std::fs::create_dir_all(&empty).unwrap(); + assert!(set_game_data(&root, &empty).is_err()); + assert_eq!(game_data_dir(&root).unwrap(), good); + assert!(set_game_data(&root, std::path::Path::new("relative/dir")).is_err()); + } + #[cfg(unix)] #[test] fn a_path_outside_the_core_folder_is_refused_for_a_docker_server() { diff --git a/crates/coa-core/src/error.rs b/crates/coa-core/src/error.rs index f2b236c..9ccabff 100644 --- a/crates/coa-core/src/error.rs +++ b/crates/coa-core/src/error.rs @@ -55,6 +55,7 @@ pub enum ErrorCode { OperationInProgress, StartupFailed, DockerUnavailable, + GameDataMismatch, HashMismatch, PathRejected, PackageNotPublished, @@ -138,6 +139,11 @@ impl ErrorCode { "This server runs in Docker. Install Docker, start it, and make sure your user account may use it, then try again.", &[Retry, ShowDetails], ), + ErrorCode::GameDataMismatch => ( + "The game data folder is not the CoA set", + "The server stopped because the DBC files in the game data folder are not the ones of the Conquest of Azeroth client. Choose the folder that holds the CoA data (Settings > Game data folder), then start again.", + &[ShowDetails], + ), ErrorCode::HashMismatch => ( "A downloaded file is damaged", "The file did not match its checksum and was not used.", diff --git a/crates/coa-core/src/health.rs b/crates/coa-core/src/health.rs index 65f608c..312e666 100644 --- a/crates/coa-core/src/health.rs +++ b/crates/coa-core/src/health.rs @@ -25,6 +25,8 @@ pub fn diagnose(text: &str) -> Option { Some(ErrorCode::DatabaseNotRunning) } else if l.contains("address already in use") || l.contains("could not bind") || l.contains("only one usage of each socket") { Some(ErrorCode::PortInUse) + } else if l.contains("does not hold the coa client dbc set") || l.contains("_outdated_ dbc data") { + Some(ErrorCode::GameDataMismatch) } else if l.contains("config::loadfile") && l.contains("failed open file") && l.contains("worldserver.conf") { Some(ErrorCode::ServerFilesIncomplete) } else { @@ -57,6 +59,13 @@ pub fn diagnose_installation(root: &Path) -> Option { mod tests { use super::*; + #[test] + fn a_game_data_folder_without_the_coa_dbc_set_is_named_as_such() { + let log = "Using DataDir /srv/data/\nSpellAffect.dbc not found in /srv/data/dbc/\nDataDir does not hold the CoA client DBC set. Install it with apps/coa-dbc/client_dbc.py."; + assert_eq!(diagnose(log), Some(ErrorCode::GameDataMismatch)); + assert_eq!(diagnose("You have _outdated_ DBC data. Please extract correct versions from current using client."), Some(ErrorCode::GameDataMismatch)); + } + #[test] fn recognises_missing_migrations() { let log = "ERROR [sql.sql] [1146] Table 'acore_world.coa_boss' doesn't exist\nFATAL [sql.sql] Your database structure is not up to date."; diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index a056b2d..476fd30 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -430,6 +430,10 @@ hand over to `coa_core::docker`; nothing else needed to change for start, stop, equal to the variables the containers get. A world that restarts itself (exit code 2) is restarted by Docker once it has come up. The database console shows `docker logs`, and the file-based screens read Linux locations (the desktop folder from the user directories file, memory from `/proc/meminfo`, the distribution name for the problem report). +* **Game data folder** (`docker::game_data_dir` / `set_game_data`, Settings card): `dataDir` in `docker.json` can be changed + after the install, only while the world and auth are stopped, and only to a folder that passes the install checks. A world + that stops with "does not hold the CoA client dbc set" is reported as `GameDataMismatch` (wrong data set: the standard one, + not Conquest of Azeroth's) instead of a bare failure. * **Not done yet**: downloading the game data, updates, port conflict detection, the firewall and exposure checks, the Wildcard realm profiles, and the client under Wine/Proton. diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 8138327..134d6e6 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -110,6 +110,31 @@ fn summary(id: String, path: PathBuf) -> ServerSummary { ServerSummary { id, name, path: path.to_string_lossy().into_owned() } } +/// The game data folder of a Docker server; none for a repack, whose data is inside its own folder. +#[tauri::command] +fn game_data_folder(state: State<'_, AppState>, id: String) -> std::result::Result, UiError> { + let root = path_of(&state, &id)?; + if !coa_core::docker::is_docker(&root) { + return Ok(None); + } + Ok(Some(coa_core::docker::game_data_dir(&root)?.to_string_lossy().into_owned())) +} + +/// Point a Docker server at another game data folder. The servers must be stopped. +#[tauri::command] +async fn set_game_data_folder(state: State<'_, AppState>, id: String, path: String) -> std::result::Result { + let root = path_of(&state, &id)?; + let _guard = BusyGuard::acquire(&state, &id)?; + blocking(move || { + if !coa_core::docker::is_docker(&root) { + return Err(Error::Invalid("The game data of this server is inside its folder.".into())); + } + coa_core::docker::set_game_data(&root, std::path::Path::new(&path))?; + Ok(path) + }) + .await +} + #[tauri::command] fn default_install_dir() -> String { if platform::flavor() == Flavor::Docker { @@ -1688,6 +1713,8 @@ pub fn run() { .manage(AppState { registry: Registry::at(dir.join("installs.json")), busy: Mutex::new(HashSet::new()), install_cancel: Mutex::new(None), client_cancel: Mutex::new(None) }) .invoke_handler(tauri::generate_handler![ default_install_dir, + game_data_folder, + set_game_data_folder, install_environment, scan_server, add_server, diff --git a/src/dev/mock.ts b/src/dev/mock.ts index 122ad26..89b6b31 100644 --- a/src/dev/mock.ts +++ b/src/dev/mock.ts @@ -92,6 +92,8 @@ export {}; if(cmd==="open_link"){(window as any).__lastLink=args.url;return null;} if(cmd==="export_diagnostics") return "C:\\Users\\you\\Desktop\\CoA-Diagnostics-20261001-140000.zip"; if(cmd==="list_crashes") return []; + if(cmd==="game_data_folder") return new URLSearchParams(location.search).get("flavor")==="docker"?"/srv/coa/server-data":null; + if(cmd==="set_game_data_folder") return args.path; if(cmd==="install_environment"){const docker=new URLSearchParams(location.search).get("flavor")==="docker";return docker?{flavor:"docker",default_dir:"/home/you/CoaServer",docker_problem:new URLSearchParams(location.search).has("nodocker")?"permission denied while trying to connect to the Docker daemon socket":null}:{flavor:"repack",default_dir:"C:\\Games\\CoA Server",docker_problem:null};} if(cmd==="install_preflight") return {ok:true,problems:[],free_bytes:210*2**30}; if(cmd==="install_requirements") return {download_bytes:Math.round(5.9*2**30),unpacked_bytes:Math.round(11.4*2**30),version:"0.2.0"}; diff --git a/src/i18n/locales/en.ts b/src/i18n/locales/en.ts index 21910e5..90c80fa 100644 --- a/src/i18n/locales/en.ts +++ b/src/i18n/locales/en.ts @@ -144,6 +144,8 @@ const en = { "err.operation_in_progress.message": "The server is busy starting or stopping. Wait a moment and try again.", "err.startup_failed.title": "Server could not start", "err.startup_failed.message": "A service stopped while starting. Check the details for the cause.", + "err.game_data_mismatch.title": "The game data folder is not the CoA set", + "err.game_data_mismatch.message": "The server stopped because the DBC files in the game data folder are not the ones of the Conquest of Azeroth client. Choose the folder that holds the CoA data (Settings > Game data folder), then start again.", "err.docker_unavailable.title": "Docker is not available", "err.docker_unavailable.message": "This server runs in Docker. Install Docker, start it, and make sure your user account may use it, then try again.", "err.hash_mismatch.title": "A downloaded file is damaged", @@ -191,6 +193,11 @@ const en = { "install.localPkg": "Install from a local package folder instead of downloading", "install.localPkgHint": "(leave empty to download)", "install.button": "Install", + "gamedata.title": "Game data folder", + "gamedata.text": "The folder with the game's dbc, maps, vmaps and mmaps that this server reads. It is used where it is and never changed. It must be the Conquest of Azeroth set, not the standard one. Stop the server before changing it.", + "gamedata.change": "Change…", + "gamedata.dialog": "Choose the game data folder", + "gamedata.saved": "Saved. It is used the next time the server starts.", "install.docker.title": "Docker is needed", "install.docker.text": "On Linux the server runs in Docker. Install Docker and start it, or allow your user to use it, then check again.", "install.docker.retry": "Check again", diff --git a/src/lib/api.ts b/src/lib/api.ts index dc0c173..3c3c153 100644 --- a/src/lib/api.ts +++ b/src/lib/api.ts @@ -498,6 +498,9 @@ export const api = { restoreConfigs: (id: string, backupId: string) => invoke("restore_backup_configs", { id, backupId }), restoreDatabase: (id: string, backupId: string, database: string) => invoke("restore_backup_database", { id, backupId, database }), installEnvironment: () => invoke("install_environment"), + /** The game data folder of a Docker server; null for a repack. */ + gameDataFolder: (id: string) => invoke("game_data_folder", { id }), + setGameDataFolder: (id: string, path: string) => invoke("set_game_data_folder", { id, path }), installPreflight: (dest: string, needed?: number, gameData?: string) => invoke("install_preflight", { dest, needed: needed ?? null, gameData: gameData ?? null }), installRequirements: (pkg?: string) => invoke("install_requirements", { package: pkg ?? null }), realmlistProfiles: (id: string) => invoke<{ profiles: RealmProfile[]; active: string | null }>("realmlist_profiles", { id }), diff --git a/src/screens/GameDataCard.tsx b/src/screens/GameDataCard.tsx new file mode 100644 index 0000000..1f3d22d --- /dev/null +++ b/src/screens/GameDataCard.tsx @@ -0,0 +1,44 @@ +import { useEffect, useState } from "react"; +import { open } from "@tauri-apps/plugin-dialog"; +import { api, asUiError } from "@/lib/api"; +import { Button } from "@/components/ui/button"; +import { Card } from "@/components/ui/card"; +import { useT } from "@/i18n"; + +/** Where a Docker server reads the game data from. Not shown for a repack, which keeps its data in its own folder. */ +export function GameDataCard({ serverId }: { serverId: string }) { + const t = useT(); + const [folder, setFolder] = useState(null); + const [message, setMessage] = useState<{ ok: boolean; text: string } | null>(null); + + useEffect(() => { + let alive = true; + void api.gameDataFolder(serverId).then((f) => alive && setFolder(f)).catch(() => alive && setFolder(null)); + return () => { alive = false; }; + }, [serverId]); + + if (folder === null) return null; + + async function change() { + const picked = await open({ directory: true, multiple: false, title: t("gamedata.dialog"), defaultPath: folder ?? undefined }); + if (typeof picked !== "string") return; + try { + setFolder(await api.setGameDataFolder(serverId, picked)); + setMessage({ ok: true, text: t("gamedata.saved") }); + } catch (e) { + setMessage({ ok: false, text: asUiError(e).technical }); + } + } + + return ( + +

{t("gamedata.title")}

+

{t("gamedata.text")}

+
+ {folder} + +
+ {message &&

{message.text}

} +
+ ); +} diff --git a/src/screens/SettingsHome.tsx b/src/screens/SettingsHome.tsx index e3e999e..525cdd9 100644 --- a/src/screens/SettingsHome.tsx +++ b/src/screens/SettingsHome.tsx @@ -7,6 +7,7 @@ import { api, asUiError, type UiError, type UpdatePreview, type UpdateTxn } from import { Button } from "@/components/ui/button"; import { Card } from "@/components/ui/card"; import { ClientCard } from "@/screens/ClientCard"; +import { GameDataCard } from "@/screens/GameDataCard"; import { DiagnosticsCard } from "@/screens/DiagnosticsCard"; import { AboutCard } from "@/screens/AboutCard"; import { RemoveServerCard } from "@/screens/RemoveServerCard"; @@ -174,6 +175,8 @@ export function SettingsHome({ serverId, path, onForget }: { serverId: string; p + +