diff --git a/crates/coa-core/src/config/mod.rs b/crates/coa-core/src/config/mod.rs index 2ee7744..52dcb96 100644 --- a/crates/coa-core/src/config/mod.rs +++ b/crates/coa-core/src/config/mod.rs @@ -67,7 +67,12 @@ pub fn targets(root: &Path, scope: Scope) -> Result { Scope::Bots => { let conf = root.join("Core/configs/modules/mod_coa_playerbots.conf"); if !conf.is_file() { - return Err(Error::Invalid("CoA Companions (bots) are not installed on this server.".into())); + // The server ships the documented defaults as `.dist` and uses them until an active file exists: make it. + let dist = root.join("Core/configs/modules/mod_coa_playerbots.conf.dist"); + if !dist.is_file() { + return Err(Error::Invalid("CoA Companions (bots) are not installed on this server.".into())); + } + fsx::atomic_write(&conf, &fs::read(&dist)?)?; } Ok(Targets { read: conf.clone(), writes: vec![conf], generated: None }) } @@ -753,9 +758,15 @@ Logger.x=6,Console Server } #[test] - fn bots_scope_requires_the_module_config() { + fn bots_scope_requires_the_module_config_or_its_default_file() { let (_d, root, _m) = fixture(); - fs::remove_file(root.join("Core/configs/modules/mod_coa_playerbots.conf")).unwrap(); - assert!(load(&root, Scope::Bots).is_err()); + let modules = root.join("Core/configs/modules"); + let conf = modules.join("mod_coa_playerbots.conf"); + let text = fs::read(&conf).unwrap(); + fs::remove_file(&conf).unwrap(); + assert!(load(&root, Scope::Bots).is_err(), "neither file: not installed"); + fs::write(modules.join("mod_coa_playerbots.conf.dist"), &text).unwrap(); + assert!(load(&root, Scope::Bots).is_ok(), "only the default file: it is made"); + assert!(conf.is_file()); } } diff --git a/crates/coa-core/src/layout.rs b/crates/coa-core/src/layout.rs index 1db1d33..b262a15 100644 --- a/crates/coa-core/src/layout.rs +++ b/crates/coa-core/src/layout.rs @@ -229,7 +229,10 @@ pub fn scan(root: &Path) -> Result { .collect(); database_schemas.sort(); - let bot_conf = modules_dir.join("mod_coa_playerbots.conf"); + // A fresh repack ships `mod_coa_playerbots.conf.dist` and only writes the active file when someone changes it. + let bot_active = modules_dir.join("mod_coa_playerbots.conf"); + let bot_dist = modules_dir.join("mod_coa_playerbots.conf.dist"); + let bot_conf = if bot_active.is_file() { bot_active } else { bot_dist }; let bot_config_keys = count_bot_keys(&bot_conf); let banner_revision = banner_revision_in_log(&root.join("Core/Logs/Server.log")); @@ -475,6 +478,18 @@ mod tests { assert_eq!(r.hint, Some("not-repack")); } + #[test] + fn the_companions_are_found_by_their_documented_default_file_when_no_active_one_exists() { + let dir = tempfile::tempdir().unwrap(); + let root = dir.path().join("repack"); + testkit::fake_repack(&root); + let modules = root.join("Core/configs/modules"); + fs::rename(modules.join("mod_coa_playerbots.conf"), modules.join("mod_coa_playerbots.conf.dist")).unwrap(); + let r = scan(&root).unwrap(); + assert!(r.items.iter().any(|i| i.key == "companions" && i.status == Status::Found), "found through the .dist"); + assert_eq!(r.bot_config_keys, 2); + } + #[test] fn missing_folder_is_an_error_not_a_verdict() { assert!(scan(Path::new("C:/definitely/not/here")).is_err());