diff --git a/crates/coa-core/src/modules.rs b/crates/coa-core/src/modules.rs index 7a68d00..ebc71b8 100644 --- a/crates/coa-core/src/modules.rs +++ b/crates/coa-core/src/modules.rs @@ -259,7 +259,25 @@ fn list_in(cat: &[Entry], root: &Path) -> Vec { }) }); - let dll_candidates = [ + let alias_dlls: Vec = match e.id.as_str() { + "content-scaling" => vec![ + root.join("plugins").join("coa-content-scaling").join("coa-content-scaling.dll"), + root.join("plugins").join("coa-content-scaling.dll"), + ], + "companions" => vec![ + root.join("plugins").join("coa-playerbots").join("coa-playerbots.dll"), + root.join("plugins").join("coa-playerbots.dll"), + root.join("plugins").join("mod-coa-playerbots.dll"), + ], + "playerbots" => vec![ + root.join("plugins").join("mod-playerbots").join("mod-playerbots.dll"), + root.join("plugins").join("squid-playerbots").join("squid-playerbots.dll"), + root.join("plugins").join("mod-playerbots.dll"), + ], + _ => Vec::new(), + }; + + let mut dll_candidates = vec![ root.join("plugins").join(format!("{}.dll", e.id)), root.join("plugins").join(format!("{}.dll", e.id.replace('-', "_"))), root.join("plugins").join(format!("coa-{}.dll", e.id)), @@ -273,14 +291,12 @@ fn list_in(cat: &[Entry], root: &Path) -> Vec { root.join("plugins").join(format!("coa-{}", e.id)).join(format!("coa-{}.dll", e.id)), root.join("plugins").join(format!("mod-{}", e.id)).join(format!("mod-{}.dll", e.id)), root.join("plugins").join(format!("mod-coa-{}", e.id)).join(format!("mod-coa-{}.dll", e.id)), - // Special alias subdirectories - root.join("plugins").join("coa-content-scaling").join("coa-content-scaling.dll"), - root.join("plugins").join("coa-playerbots").join("coa-playerbots.dll"), // .manager/plugins checks root.join(".manager/plugins").join(format!("{}.dll", e.id)), root.join(".manager/plugins").join(format!("coa-{}.dll", e.id)), root.join(".manager/plugins").join(format!("mod-coa-{}.dll", e.id)), ]; + dll_candidates.extend(alias_dlls); let dll_present = dll_candidates.iter().any(|p| p.is_file()); let is_dynamic = plugin_entry.is_some() || dll_present; @@ -427,7 +443,16 @@ fn list_in(cat: &[Entry], root: &Path) -> Vec { // Also include installed dynamic plugins from plugin_reg that aren't already in views if let Some(ref reg) = plugin_reg { for (plugin_id, plugin_entry) in ®.plugins { - if !views.iter().any(|v| v.id == *plugin_id) { + let is_already_represented = views.iter().any(|v| { + v.id == *plugin_id + || format!("coa-{}", v.id) == *plugin_id + || format!("mod-coa-{}", v.id) == *plugin_id + || format!("mod-{}", v.id) == *plugin_id + || (v.id == "content-scaling" && matches!(plugin_id.as_str(), "coa-content-scaling" | "mod-coa-content-scaling")) + || (v.id == "companions" && matches!(plugin_id.as_str(), "coa-playerbots" | "mod-coa-playerbots")) + || (v.id == "playerbots" && matches!(plugin_id.as_str(), "squid-playerbots" | "mod-playerbots")) + }); + if !is_already_represented { let mut display_name = if let Ok(meta) = crate::plugins::load_store_metadata(root, plugin_id, &plugin_entry.sha256) { meta.name } else { diff --git a/crates/coa-core/src/plugins.rs b/crates/coa-core/src/plugins.rs index bbf90cf..f1b76e1 100644 --- a/crates/coa-core/src/plugins.rs +++ b/crates/coa-core/src/plugins.rs @@ -949,9 +949,21 @@ pub fn update( pub fn remove(server: &Path, id: &str) -> Result<()> { require_server_stopped(server)?; - let mut tx = TxGuard::begin_op(server, PluginOpType::Remove, id)?; let mut reg = load_registry_direct(server)?; - if reg.plugins.remove(id).is_none() { + let actual_id = if reg.plugins.contains_key(id) { + id.to_string() + } else if reg.plugins.contains_key(&format!("coa-{}", id)) { + format!("coa-{}", id) + } else if reg.plugins.contains_key(&format!("mod-{}", id)) { + format!("mod-{}", id) + } else if reg.plugins.contains_key(&format!("mod-coa-{}", id)) { + format!("mod-coa-{}", id) + } else { + id.to_string() + }; + + let mut tx = TxGuard::begin_op(server, PluginOpType::Remove, &actual_id)?; + if reg.plugins.remove(&actual_id).is_none() { return Ok(()); } @@ -962,10 +974,14 @@ pub fn remove(server: &Path, id: &str) -> Result<()> { regenerate_lockfile(server, ®)?; check_crash_injection("after_lock_update"); - let target_dir = plugins_install_dir(server).join(id); + let target_dir = plugins_install_dir(server).join(&actual_id); if target_dir.is_dir() { let _ = fs::remove_dir_all(target_dir); } + let flat_dll = plugins_install_dir(server).join(format!("{}.dll", actual_id)); + if flat_dll.is_file() { + let _ = fs::remove_file(flat_dll); + } tx.set_phase(TransactionPhase::Validating)?; check_crash_injection("before_commit"); diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 13df03a..1af9223 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -718,9 +718,20 @@ fn meta_dir(root: &std::path::Path) -> Result { if dir.join("install.json").is_file() { Ok(dir) } else { - Err(Error::Invalid( - "This server has not been added to the Manager yet.".into(), - )) + let internal_meta = root.join(".manager"); + if internal_meta.join("install.json").is_file() { + Ok(internal_meta) + } else if internal_meta.is_dir() || root.join("worldserver.exe").is_file() { + // Auto-heal minimal install.json for imported or standalone spike realms + let meta = coa_core::registry::InstallMeta::new(coa_core::registry::InstallKind::Imported, root); + let _ = std::fs::create_dir_all(&internal_meta); + let _ = coa_core::fsx::atomic_write_json(&internal_meta.join("install.json"), &meta); + Ok(internal_meta) + } else { + Err(Error::Invalid( + "This server has not been added to the Manager yet.".into(), + )) + } } } @@ -1300,7 +1311,34 @@ async fn module_set_enabled( let root = path_of(&state, &id)?; let _guard = BusyGuard::acquire(&state, &id)?; blocking(move || { - let (dir, _) = install_meta(&root)?; + // 1. If registered as dynamic plugin in .manager/plugins.json, synchronize plugin state + if let Ok(ref r) = coa_core::plugins::load_registry(&root) { + let plug_key = if r.plugins.contains_key(&module) { + Some(module.clone()) + } else if r.plugins.contains_key(&format!("coa-{}", module)) { + Some(format!("coa-{}", module)) + } else if r.plugins.contains_key(&format!("mod-{}", module)) { + Some(format!("mod-{}", module)) + } else if r.plugins.contains_key(&format!("mod-coa-{}", module)) { + Some(format!("mod-coa-{}", module)) + } else { + None + }; + + if let Some(key) = plug_key { + let _ = coa_core::plugins::set_enabled(&root, &key, enabled); + } + } + + // 2. Synchronize module .conf file / core setting + let dir = match install_meta(&root) { + Ok((dir, _)) => dir, + Err(_) => { + let fallback = root.join(".manager"); + let _ = std::fs::create_dir_all(&fallback); + fallback + } + }; coa_core::modules::set_enabled(&root, &dir, &module, enabled) }) .await diff --git a/src/screens/ModulesPage.tsx b/src/screens/ModulesPage.tsx index 4fd4459..f0727ee 100644 --- a/src/screens/ModulesPage.tsx +++ b/src/screens/ModulesPage.tsx @@ -761,15 +761,15 @@ export function ModulesPage({ setToggling(m.id); setError(null); try { - // Mutual exclusion check between companions and squid + // Mutual exclusion check between companions and playerbots (squid) if (m.id === "companions" && !m.enabled) { - const squidMod = modules?.find((x) => x.id === "squid"); - if (squidMod?.enabled) { - await api.moduleSetEnabled(serverId, "squid", false); + const otherBot = modules?.find((x) => (x.id === "playerbots" || x.id === "squid") && x.enabled); + if (otherBot) { + await api.moduleSetEnabled(serverId, otherBot.id, false); } - } else if (m.id === "squid" && !m.enabled) { - const compMod = modules?.find((x) => x.id === "companions"); - if (compMod?.enabled) { + } else if ((m.id === "playerbots" || m.id === "squid") && !m.enabled) { + const compMod = modules?.find((x) => x.id === "companions" && x.enabled); + if (compMod) { await api.moduleSetEnabled(serverId, "companions", false); } } @@ -965,6 +965,7 @@ export function ModulesPage({ const msg = await api.previewRemoveModule(serverId, moduleId); setNotification(msg); await loadInstalledPlugins(); + await load(); onChanged?.(); } catch (e) { setError(asUiError(e));