diff --git a/Cargo.lock b/Cargo.lock index 3eaa521..a95b41e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -347,7 +347,7 @@ dependencies = [ [[package]] name = "coa-core" -version = "0.1.4" +version = "0.1.5" dependencies = [ "base64 0.22.1", "chrono", @@ -375,7 +375,7 @@ dependencies = [ [[package]] name = "coa-release" -version = "0.1.4" +version = "0.1.5" dependencies = [ "chrono", "coa-core", @@ -384,7 +384,7 @@ dependencies = [ [[package]] name = "coa-server-manager" -version = "0.1.4" +version = "0.1.5" dependencies = [ "coa-core", "serde", diff --git a/Cargo.toml b/Cargo.toml index f917913..01ca054 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ resolver = "2" members = ["crates/coa-core", "crates/coa-release", "src-tauri"] [workspace.package] -version = "0.1.4" +version = "0.1.5" edition = "2021" license = "AGPL-3.0-only" diff --git a/crates/coa-core/src/config/mod.rs b/crates/coa-core/src/config/mod.rs index 1698841..a3eb738 100644 --- a/crates/coa-core/src/config/mod.rs +++ b/crates/coa-core/src/config/mod.rs @@ -138,6 +138,17 @@ pub fn materialize_module_configs(root: &Path) -> Result> { let active = dir.join(format!("{stem}.conf")); if !active.exists() { fs::copy(e.path(), &active)?; + if stem == "coa" { + // This product serves the CoA client only, and the servers listen on this computer unless the owner + // shares them; without this key the server drops CoA clients that connect from another address + // (friends over a private network) right after login. + if let Ok(bytes) = fs::read(&active) { + if let Ok(mut conf) = parser::ConfFile::parse_bytes(&bytes) { + conf.set("CoA.AllowRemoteClients", "1", &["Set by CoA Server Manager: this server is built for CoA clients"]); + fsx::atomic_write(&active, conf.to_text().as_bytes())?; + } + } + } created.push(format!("{stem}.conf")); } else if let (Ok(have), Ok(dist)) = (fs::read(&active), fs::read(e.path())) { if let (Ok(mut conf), Ok(dist)) = (parser::ConfFile::parse_bytes(&have), parser::ConfFile::parse_bytes(&dist)) { @@ -512,8 +523,8 @@ Spellbook.New = 5 fs::write(m.join("coa_bugreport.conf.dist"), "x = 1 ").unwrap(); assert_eq!(materialize_module_configs(&root).unwrap(), vec!["coa.conf".to_string(), "spellbook.conf (+1 keys)".to_string()]); - assert_eq!(fs::read_to_string(m.join("coa.conf")).unwrap(), "CoA.Enable = 1 -"); + let coa = fs::read_to_string(m.join("coa.conf")).unwrap(); + assert!(coa.contains("CoA.Enable = 1") && coa.contains("CoA.AllowRemoteClients = 1"), "{coa}"); let sb = fs::read_to_string(m.join("spellbook.conf")).unwrap(); assert!(sb.contains("Spellbook.Enable = 0"), "existing values are never changed: {sb}"); assert!(sb.contains("Spellbook.New = 5"), "new documented key was added: {sb}"); diff --git a/crates/coa-core/src/friends.rs b/crates/coa-core/src/friends.rs index 10b77fa..ba4ee6c 100644 --- a/crates/coa-core/src/friends.rs +++ b/crates/coa-core/src/friends.rs @@ -94,9 +94,9 @@ pub fn set_open(root: &Path, meta: &Path, open: bool) -> Result { let coa_conf = root.join("Core/configs/modules/coa.conf"); if let Ok(bytes) = fs::read(&coa_conf) { let mut conf = ConfFile::parse_bytes(&bytes)?; - let want_remote = if open { "1" } else { "0" }; - if conf.get("CoA.AllowRemoteClients").map(str::trim) != Some(want_remote) { - conf.set("CoA.AllowRemoteClients", want_remote, &["Set by CoA Server Manager together with the friends mode"]); + // Opening turns it on; closing leaves it alone (it only matters while the servers listen beyond this computer). + if open && conf.get("CoA.AllowRemoteClients").map(str::trim) != Some("1") { + conf.set("CoA.AllowRemoteClients", "1", &["Set by CoA Server Manager together with the friends mode"]); originals.push((coa_conf.clone(), bytes)); edits.push((coa_conf, conf.to_text())); } @@ -213,7 +213,7 @@ mod tests { } #[test] - fn sharing_also_allows_remote_coa_clients_and_closing_takes_it_back() { + fn sharing_also_allows_remote_coa_clients_and_closing_leaves_it() { let (_d, root, meta) = setup(); let coa = root.join("Core/configs/modules/coa.conf"); fs::create_dir_all(coa.parent().unwrap()).unwrap(); @@ -224,7 +224,7 @@ CoA.AllowRemoteClients = 0 assert!(fs::read_to_string(&coa).unwrap().contains("CoA.AllowRemoteClients = 1")); assert!(fs::read_to_string(&coa).unwrap().contains("CoA.Enable = 1")); assert!(set_open(&root, &meta, false).unwrap()); - assert!(fs::read_to_string(&coa).unwrap().contains("CoA.AllowRemoteClients = 0")); + assert!(fs::read_to_string(&coa).unwrap().contains("CoA.AllowRemoteClients = 1"), "closing only changes BindIP"); } #[test] diff --git a/package.json b/package.json index e085248..a5662b2 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "coa-server-manager", "private": true, - "version": "0.1.4", + "version": "0.1.5", "license": "AGPL-3.0-only", "type": "module", "scripts": { diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 367237b..fd3fee9 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -1,7 +1,7 @@ { "$schema": "https://schema.tauri.app/config/2", "productName": "CoA Server Manager", - "version": "0.1.4", + "version": "0.1.5", "identifier": "com.coa.servermanager", "build": { "beforeDevCommand": "npm run dev",