mirror of
https://github.com/Corfirean/coa-server-manager.git
synced 2026-11-25 11:25:56 +00:00
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.
This commit is contained in:
1 parent
25098b5a63
commit
5c3a9def0c
3 files changed
+79
-6
No files matched your search
@@ -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<crate::realms::Mode> {
|
||||
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<String> {
|
||||
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");
|
||||
|
||||
Reference in new issue
Block a user