From 5c3a9def0c387b178c140c52fd752c339945b7c5 Mon Sep 17 00:00:00 2001 From: "Fabien F." <8136686+lostmind84@users.noreply.github.com> Date: Sun, 4 Oct 2026 09:53:48 +0200 Subject: [PATCH] feat: realm profiles (CoA / Wildcard) work on a Docker server The Realm card showed "io: No such file or directory (os error 2)" on a Docker server: the Wildcard check read Core/worldserver.exe. The card lets the owner switch realm, so it is made to work rather than hidden. What the repack's patched launcher did at each start is done by the Docker backend: finish an interrupted switch (realms::before_start), name the realms in the realm list, and give the containers the databases of the selected realm (acore_world_wildcard, acore_characters_wildcard). The switch itself is the shared code. prepare_launcher has nothing to patch on a Docker server, and Wildcard support is read from Core/worldserver as it is from Core/worldserver.exe (the .exe wins when both exist, so a repack is read as before). Tests: the support check on both binary names, no launcher to adapt, and the databases passed to the containers for each realm. Creating the Wildcard realm itself needs a build and a database with the Wildcard migrations and was not run. --- crates/coa-core/src/docker/lifecycle.rs | 45 ++++++++++++++++++++++--- crates/coa-core/src/realms.rs | 35 ++++++++++++++++++- docs/ARCHITECTURE.md | 5 +++ 3 files changed, 79 insertions(+), 6 deletions(-) diff --git a/crates/coa-core/src/docker/lifecycle.rs b/crates/coa-core/src/docker/lifecycle.rs index a4d6025..b727664 100644 --- a/crates/coa-core/src/docker/lifecycle.rs +++ b/crates/coa-core/src/docker/lifecycle.rs @@ -223,6 +223,9 @@ fn start(d: &dyn Docker, root: &Path, cfg: &Config, with_game: bool, log: &mut L return Ok(()); } + // Realm profiles (CoA / Wildcard): finish an interrupted switch, then make the realm list say what is selected. The repack's + // launcher did this when it started; here nothing else would. + let realm = prepare_realm(root, log)?; ensure_image(d, log)?; super::ensure_main_configs(root).map_err(|e| Failure { code: ErrorCode::ServerFilesIncomplete, output: e.to_string() })?; std::fs::create_dir_all(root.join("Core/Logs")).map_err(|e| Failure { code: ErrorCode::ServerFilesIncomplete, output: e.to_string() })?; @@ -234,7 +237,7 @@ fn start(d: &dyn Docker, root: &Path, cfg: &Config, with_game: bool, log: &mut L remove(d, &n.world); let mut call = Call::new(&[], Duration::from_secs(60)); call.args = game_args(cfg, &n, GameKind::World, &host, &cfg.data_path(&host), ports.world, ports.ra, owner.as_deref()); - call.env = database_env(&secrets, true); + call.env = database_env(&secrets, true, realm); run_container(d, &call, &n.world, log)?; } wait_listening(d, cfg, &n.world, ports.world, WORLD_WAIT, log)?; @@ -243,7 +246,7 @@ fn start(d: &dyn Docker, root: &Path, cfg: &Config, with_game: bool, log: &mut L remove(d, &n.auth); let mut call = Call::new(&[], Duration::from_secs(60)); call.args = game_args(cfg, &n, GameKind::Auth, &host, &cfg.data_path(&host), ports.auth, 0, owner.as_deref()); - call.env = database_env(&secrets, false); + call.env = database_env(&secrets, false, realm); run_container(d, &call, &n.auth, log)?; } wait_listening(d, cfg, &n.auth, ports.auth, AUTH_WAIT, log)?; @@ -372,16 +375,32 @@ enum GameKind { } /// Connection strings: host;port;user;password;database. They hold the password, so they travel by environment. -fn database_env(s: &Secrets, world: bool) -> Vec<(String, String)> { +fn database_env(s: &Secrets, world: bool, realm: crate::realms::Mode) -> Vec<(String, String)> { let info = |db: &str| format!("db;3306;acore;{};{db}", s.app); let mut env = vec![("AC_LOGIN_DATABASE_INFO".to_string(), info("acore_auth"))]; if world { - env.push(("AC_WORLD_DATABASE_INFO".into(), info("acore_world"))); - env.push(("AC_CHARACTER_DATABASE_INFO".into(), info("acore_characters"))); + // The databases of the selected realm (the Wildcard realm has its own world and characters databases). + let schema = |kind: &str| realm.schema(kind).unwrap_or("acore_world"); + env.push(("AC_WORLD_DATABASE_INFO".into(), info(schema("world")))); + env.push(("AC_CHARACTER_DATABASE_INFO".into(), info(schema("characters")))); } env } +/// Realm profiles are only in play once a profile has been chosen on this server (`Settings/realm-profile.json`). +fn prepare_realm(root: &Path, log: &mut Log) -> Step { + let fail_with = |e: crate::error::Error| Failure { code: ErrorCode::StartupFailed, output: e.to_string() }; + crate::realms::before_start(root).map_err(fail_with)?; + let active = crate::realms::state(root).map_err(fail_with)?.active; + if root.join("Settings/realm-profile.json").exists() { + crate::realms::setup_realmlist(root).map_err(fail_with)?; + let db = crate::db::Db::from_repack(root, crate::db::Account::Admin).map_err(fail_with)?; + db.query("UPDATE acore_auth.realmlist SET name='Conquest of Azeroth' WHERE id=1; UPDATE acore_auth.realmlist SET name='Wildcard' WHERE id=2;").map_err(fail_with)?; + log.say(format!("realm {}", active.name())); + } + Ok(active) +} + fn game_args(cfg: &Config, n: &Names, kind: GameKind, host: &Path, data: &Path, port: u16, ra_port: u16, owner: Option<&str>) -> Vec { let (name, alias, binary, conf, inner_port) = match kind { GameKind::World => (&n.world, "world", "./worldserver", "configs/worldserver.conf", WORLD_PORT), @@ -733,6 +752,22 @@ mod tests { assert!(!plain.iter().any(|a| a == "--lower-case-table-names=1" || a == "--user")); } + #[test] + fn the_containers_use_the_databases_of_the_selected_realm() { + let s = Secrets { root: "r".into(), app: "apppw".into() }; + let get = |env: &[(String, String)], k: &str| env.iter().find(|(n, _)| n == k).map(|(_, v)| v.clone()); + let coa = database_env(&s, true, crate::realms::Mode::Coa); + assert_eq!(get(&coa, "AC_WORLD_DATABASE_INFO").unwrap(), "db;3306;acore;apppw;acore_world"); + assert_eq!(get(&coa, "AC_CHARACTER_DATABASE_INFO").unwrap(), "db;3306;acore;apppw;acore_characters"); + let wild = database_env(&s, true, crate::realms::Mode::Wildcard); + assert_eq!(get(&wild, "AC_WORLD_DATABASE_INFO").unwrap(), "db;3306;acore;apppw;acore_world_wildcard"); + assert_eq!(get(&wild, "AC_CHARACTER_DATABASE_INFO").unwrap(), "db;3306;acore;apppw;acore_characters_wildcard"); + // Accounts are shared by both realms; the auth server never sees the others. + assert_eq!(get(&wild, "AC_LOGIN_DATABASE_INFO").unwrap(), "db;3306;acore;apppw;acore_auth"); + let auth = database_env(&s, false, crate::realms::Mode::Wildcard); + assert_eq!(auth.len(), 1); + } + #[test] fn the_database_is_only_healthy_once_it_takes_tcp_connections() { let (_d, root) = server("t1"); diff --git a/crates/coa-core/src/realms.rs b/crates/coa-core/src/realms.rs index f99fb84..2885433 100644 --- a/crates/coa-core/src/realms.rs +++ b/crates/coa-core/src/realms.rs @@ -65,10 +65,16 @@ pub fn state(root: &Path) -> Result { fsx::read_json(&root.join(STATE)) } +/// The world server executable of this folder: `worldserver.exe` in a repack, `worldserver` in a Docker server. +fn world_binary(root: &Path) -> std::path::PathBuf { + let exe = root.join("Core/worldserver.exe"); + if exe.exists() { exe } else { root.join("Core/worldserver") } +} + pub fn view(root: &Path) -> Result { let s = state(root)?; // Inspect the binary itself; templates or an old log cannot prove installed support. - let supported = fs::read(root.join("Core/worldserver.exe"))? + let supported = fs::read(world_binary(root))? .windows(b"Wildcard synergy settings".len()).any(|w| w == b"Wildcard synergy settings"); Ok(View { active: s.active, wildcard_created: s.wildcard_created, supported, recovery_pending: root.join(JOURNAL).exists(), simultaneous: s.simultaneous, secondary_world_port: s.secondary_world_port, secondary_running: crate::multiworld::is_running(root) }) } @@ -269,6 +275,8 @@ pub fn select(root: &Path, mode: Mode) -> Result { /// Adapt the bundled launcher's canonical schema and realm choices without changing its supervision logic. pub fn prepare_launcher(root: &Path) -> Result<()> { + // A Docker server has no launcher to adapt: the Docker backend reads the active realm itself. + if crate::docker::is_docker(root) { return Ok(()); } let path = root.join("Scripts/manage.py"); let source = fs::read_to_string(&path)?; let patched = patch_launcher(&source)?; @@ -353,6 +361,31 @@ pub fn setup_realmlist(root: &Path) -> Result<()> { mod tests { use super::*; + #[test] + fn a_docker_server_is_checked_for_wildcard_support_in_its_own_binary() { + let d = tempfile::tempdir().unwrap(); + fs::create_dir_all(d.path().join("Core")).unwrap(); + fs::create_dir_all(d.path().join("Settings")).unwrap(); + fs::write(d.path().join("Settings/docker.json"), br#"{"project":"t1"}"#).unwrap(); + fs::write(d.path().join("Core/worldserver"), b"ELF...Wildcard synergy settings...").unwrap(); + assert!(view(d.path()).unwrap().supported, "worldserver without .exe is read too"); + fs::write(d.path().join("Core/worldserver"), b"ELF...an older build").unwrap(); + assert!(!view(d.path()).unwrap().supported); + // The repack's executable still wins when both exist, so a repack is read as before. + fs::write(d.path().join("Core/worldserver.exe"), b"MZ...Wildcard synergy settings").unwrap(); + assert!(view(d.path()).unwrap().supported); + } + + #[test] + fn a_docker_server_has_no_launcher_to_adapt() { + let d = tempfile::tempdir().unwrap(); + fs::create_dir_all(d.path().join("Settings")).unwrap(); + // No Scripts/manage.py anywhere: on a repack this fails, on a Docker server there is nothing to do. + assert!(prepare_launcher(d.path()).is_err()); + fs::write(d.path().join("Settings/docker.json"), br#"{"project":"t1"}"#).unwrap(); + prepare_launcher(d.path()).unwrap(); + } + #[test] fn fresh_wildcard_disables_bots_and_preserves_scaling() { let mut f = Files::new(); diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index 885a89c..319e51a 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -411,6 +411,11 @@ hand over to `coa_core::docker`; nothing else needed to change for start, stop, * **Updates are refused for a Docker server, never half done.** `update::preview`, `apply` and `rollback` refuse it: the update packages are the repack's (executables, a bundled MySQL, a launcher) and applying one would put Windows files in a Linux folder. Found by installing a server with the screen: the update check had read the Windows channel and offered one. +* **Realm profiles (CoA / Wildcard) work on a Docker server.** What the repack's patched launcher did at each start is done + by the Docker backend: finish an interrupted switch (`realms::before_start`), name the realms in the realm list, and give + the containers the databases of the selected realm (`acore_world_wildcard` ...). The switch itself (configuration swap, + database copy, journal) is the shared code; `prepare_launcher` has nothing to patch, and Wildcard support is read from + `Core/worldserver` as it is from `Core/worldserver.exe`. * **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.