mirror of
https://github.com/Corfirean/coa-server-manager.git
synced 2026-11-22 11:25:56 +00:00
Release Manager 0.6.0 with Chinese localization, realm sync and Linux preview
This commit is contained in:
1 parent
85963b0bf0
commit
162bfd1e04
20 files changed
+1627
-17
No files matched your search
@@ -1,6 +1,7 @@
|
||||
//! The game client is a separate object: detected read-only, and touched only in two narrow ways -
|
||||
//! The game client is a separate object: detected read-only, with targeted updates to
|
||||
//! `realmlist.wtf` (backed up first) and the `Interface/AddOns/CoABotUI` folder (backed up when it differs).
|
||||
//! WTF, Cache, other addons and the executable are never modified.
|
||||
//! The selected realm in WTF/Config.wtf is synchronized while the client is closed.
|
||||
//! Cache, other addons and the executable are never modified.
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
use std::fs;
|
||||
@@ -15,6 +16,67 @@ use crate::fsx;
|
||||
pub const ADDON_NAME: &str = "CoABotUI";
|
||||
const EXECUTABLES: [&str; 3] = ["Ascension.exe", "Wow.exe", "WoW.exe"];
|
||||
|
||||
pub fn is_running(client: &Path) -> bool {
|
||||
EXECUTABLES.iter().any(|exe| {
|
||||
let path = client.join(exe);
|
||||
let path = dunce::canonicalize(&path).unwrap_or(path);
|
||||
!crate::process::find_by_exe(&path).is_empty()
|
||||
})
|
||||
}
|
||||
|
||||
fn realm_config(old: &[u8], realm: &str) -> Vec<u8> {
|
||||
let eol: &[u8] = if old.windows(2).any(|w| w == b"\r\n") { b"\r\n" } else { b"\n" };
|
||||
let mut out = Vec::new();
|
||||
let mut replaced = false;
|
||||
for line in old.split_inclusive(|b| *b == b'\n') {
|
||||
let body = line.strip_prefix(b"\xef\xbb\xbf").unwrap_or(line);
|
||||
let mut words = body.split(|b| b.is_ascii_whitespace()).filter(|w| !w.is_empty());
|
||||
let matches = words.next().is_some_and(|w| w.eq_ignore_ascii_case(b"SET"))
|
||||
&& words.next().is_some_and(|w| w.eq_ignore_ascii_case(b"realmName"));
|
||||
if matches {
|
||||
if line.starts_with(b"\xef\xbb\xbf") { out.extend_from_slice(b"\xef\xbb\xbf"); }
|
||||
out.extend_from_slice(format!("SET realmName \"{realm}\"").as_bytes());
|
||||
if line.ends_with(b"\r\n") { out.extend_from_slice(b"\r\n"); }
|
||||
else if line.ends_with(b"\n") { out.push(b'\n'); }
|
||||
replaced = true;
|
||||
} else {
|
||||
out.extend_from_slice(line);
|
||||
}
|
||||
}
|
||||
if !replaced {
|
||||
if !out.is_empty() && !out.ends_with(b"\n") { out.extend_from_slice(eol); }
|
||||
out.extend_from_slice(format!("SET realmName \"{realm}\"").as_bytes());
|
||||
out.extend_from_slice(eol);
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
pub fn sync_realm(client: &Path, meta: &Path, mode: crate::realms::Mode) -> Result<bool> {
|
||||
sync_realm_when_closed(client, meta, mode, is_running(client))
|
||||
}
|
||||
|
||||
fn sync_realm_when_closed(client: &Path, meta: &Path, mode: crate::realms::Mode, running: bool) -> Result<bool> {
|
||||
if running { return Ok(false); }
|
||||
let file = client.join("WTF/Config.wtf");
|
||||
let old = match fs::read(&file) {
|
||||
Ok(bytes) => bytes,
|
||||
Err(e) if e.kind() == std::io::ErrorKind::NotFound => Vec::new(),
|
||||
Err(e) => return Err(e.into()),
|
||||
};
|
||||
let realm = match mode {
|
||||
crate::realms::Mode::Coa => "Conquest of Azeroth",
|
||||
crate::realms::Mode::Wildcard => "Wildcard",
|
||||
};
|
||||
let new = realm_config(&old, realm);
|
||||
if new == old { return Ok(true); }
|
||||
if file.exists() {
|
||||
let saved = backup_dir(meta).join(format!("config-realm-{}.wtf", uuid::Uuid::new_v4()));
|
||||
fsx::atomic_write(&saved, &old)?;
|
||||
}
|
||||
fsx::atomic_write(&file, &new)?;
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct Realmlist {
|
||||
pub path: String,
|
||||
@@ -253,6 +315,45 @@ pub fn launch(client: &Path) -> Result<u32> {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn realm_selection_preserves_other_settings_bytes_and_line_endings() {
|
||||
let old = b"\xef\xbb\xbfSET realmName \"Wildcard\"\r\nSET accountName \"\xff\"\r\nset REALMNAME \"old\"\r\nSET realmList \"127.0.0.1\"";
|
||||
let expected = b"\xef\xbb\xbfSET realmName \"Conquest of Azeroth\"\r\nSET accountName \"\xff\"\r\nSET realmName \"Conquest of Azeroth\"\r\nSET realmList \"127.0.0.1\"";
|
||||
assert_eq!(realm_config(old, "Conquest of Azeroth"), expected);
|
||||
assert_eq!(realm_config(b"SET sound 1", "Wildcard"), b"SET sound 1\nSET realmName \"Wildcard\"\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn realm_sync_backs_up_config_and_is_idempotent() {
|
||||
let d = tempfile::tempdir().unwrap();
|
||||
let c = fake_client(d.path());
|
||||
let meta = d.path().join("meta");
|
||||
let original = b"SET sound 1\r\nSET realmName \"Wildcard\"\r\n";
|
||||
fs::write(c.join("WTF/Config.wtf"), original).unwrap();
|
||||
assert!(sync_realm(&c, &meta, crate::realms::Mode::Coa).unwrap());
|
||||
let backups: Vec<_> = fs::read_dir(backup_dir(&meta)).unwrap().flatten().collect();
|
||||
assert_eq!(backups.len(), 1);
|
||||
assert_eq!(fs::read(backups[0].path()).unwrap(), original);
|
||||
assert!(sync_realm(&c, &meta, crate::realms::Mode::Coa).unwrap());
|
||||
assert_eq!(fs::read_dir(backup_dir(&meta)).unwrap().count(), 1);
|
||||
assert!(sync_realm(&c, &meta, crate::realms::Mode::Wildcard).unwrap());
|
||||
assert_eq!(fs::read(c.join("WTF/Config.wtf")).unwrap(), original);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn running_client_defers_realm_update_until_closed() {
|
||||
let d = tempfile::tempdir().unwrap();
|
||||
let c = fake_client(d.path());
|
||||
let meta = d.path().join("meta");
|
||||
let original = b"SET realmName \"Wildcard\"\n";
|
||||
fs::write(c.join("WTF/Config.wtf"), original).unwrap();
|
||||
assert!(!sync_realm_when_closed(&c, &meta, crate::realms::Mode::Coa, true).unwrap());
|
||||
assert_eq!(fs::read(c.join("WTF/Config.wtf")).unwrap(), original);
|
||||
assert!(!backup_dir(&meta).exists());
|
||||
assert!(sync_realm_when_closed(&c, &meta, crate::realms::Mode::Coa, false).unwrap());
|
||||
assert_eq!(fs::read(c.join("WTF/Config.wtf")).unwrap(), b"SET realmName \"Conquest of Azeroth\"\n");
|
||||
}
|
||||
|
||||
fn fake_client(d: &Path) -> PathBuf {
|
||||
let c = d.join("wow");
|
||||
fs::create_dir_all(c.join("Data/enUS")).unwrap();
|
||||
|
||||
@@ -363,6 +363,7 @@ fn game_args(cfg: &Config, n: &Names, kind: GameKind, host: &Path, port: u16, ra
|
||||
// on every interface of the container (the published address decides who can connect).
|
||||
let env = |k: &str, v: &str| ["--env".to_string(), format!("{k}={v}")];
|
||||
a.extend(env("AC_BIND_IP", "0.0.0.0"));
|
||||
a.extend(env(if kind == GameKind::World { "AC_WORLD_SERVER_PORT" } else { "AC_REALM_SERVER_PORT" }, &inner_port.to_string()));
|
||||
a.extend(env("AC_LOGS_DIR", &format!("{CORE}/Logs")));
|
||||
// The Manager applies database updates itself. The server's own updater would need a `mysql` client program inside
|
||||
// the container and stops the server when it cannot find one.
|
||||
@@ -374,6 +375,7 @@ fn game_args(cfg: &Config, n: &Names, kind: GameKind, host: &Path, port: u16, ra
|
||||
a.extend(["--publish".into(), format!("127.0.0.1:{ra_port}:{RA_PORT}")]);
|
||||
a.extend(env("AC_RA_ENABLE", "1"));
|
||||
a.extend(env("AC_RA_IP", "0.0.0.0"));
|
||||
a.extend(env("AC_RA_PORT", &RA_PORT.to_string()));
|
||||
// Saving every character can take a while.
|
||||
a.extend(["--stop-timeout".into(), "180".into()]);
|
||||
a.extend(["--env".into(), "AC_WORLD_DATABASE_INFO".into(), "--env".into(), "AC_CHARACTER_DATABASE_INFO".into()]);
|
||||
@@ -705,6 +707,21 @@ mod tests {
|
||||
assert!(runs[2].args.iter().any(|a| a == "0.0.0.0:3724:3724"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn custom_host_ports_keep_the_container_listeners_on_the_mapped_ports() {
|
||||
let (_d, root) = server("ports");
|
||||
let cfg = Config::load(&root).unwrap();
|
||||
let n = cfg.names();
|
||||
let world = game_args(&cfg, &n, GameKind::World, &root, 18085, 13443, None);
|
||||
let auth = game_args(&cfg, &n, GameKind::Auth, &root, 13724, 0, None);
|
||||
assert!(world.iter().any(|a| a == "127.0.0.1:18085:8085"));
|
||||
assert!(world.iter().any(|a| a == "127.0.0.1:13443:3443"));
|
||||
assert!(world.iter().any(|a| a == "AC_WORLD_SERVER_PORT=8085"));
|
||||
assert!(world.iter().any(|a| a == "AC_RA_PORT=3443"));
|
||||
assert!(auth.iter().any(|a| a == "127.0.0.1:13724:3724"));
|
||||
assert!(auth.iter().any(|a| a == "AC_REALM_SERVER_PORT=3724"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_second_start_leaves_running_containers_alone() {
|
||||
let (_d, root) = server("t1");
|
||||
|
||||
Reference in new issue
Block a user