fix(modules-preview): isolate dll detection, deduplicate plugins, fix toggle exclusivity and metadata resolution

This commit is contained in:
Дмитрий committed 2026-11-03 16:26:37 +05:00
1 parent 221f4a93d3
commit c2bf8ecbb6
4 files changed
+99 -19

No files matched your search

+30 -5
View File
@@ -259,7 +259,25 @@ fn list_in(cat: &[Entry], root: &Path) -> Vec<ModuleView> {
}) })
}); });
let dll_candidates = [ let alias_dlls: Vec<PathBuf> = 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)),
root.join("plugins").join(format!("{}.dll", e.id.replace('-', "_"))), root.join("plugins").join(format!("{}.dll", e.id.replace('-', "_"))),
root.join("plugins").join(format!("coa-{}.dll", e.id)), root.join("plugins").join(format!("coa-{}.dll", e.id)),
@@ -273,14 +291,12 @@ fn list_in(cat: &[Entry], root: &Path) -> Vec<ModuleView> {
root.join("plugins").join(format!("coa-{}", e.id)).join(format!("coa-{}.dll", e.id)), 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-{}", e.id)).join(format!("mod-{}.dll", e.id)),
root.join("plugins").join(format!("mod-coa-{}", e.id)).join(format!("mod-coa-{}.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 // .manager/plugins checks
root.join(".manager/plugins").join(format!("{}.dll", e.id)), 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!("coa-{}.dll", e.id)),
root.join(".manager/plugins").join(format!("mod-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 dll_present = dll_candidates.iter().any(|p| p.is_file());
let is_dynamic = plugin_entry.is_some() || dll_present; let is_dynamic = plugin_entry.is_some() || dll_present;
@@ -427,7 +443,16 @@ fn list_in(cat: &[Entry], root: &Path) -> Vec<ModuleView> {
// Also include installed dynamic plugins from plugin_reg that aren't already in views // Also include installed dynamic plugins from plugin_reg that aren't already in views
if let Some(ref reg) = plugin_reg { if let Some(ref reg) = plugin_reg {
for (plugin_id, plugin_entry) in &reg.plugins { for (plugin_id, plugin_entry) in &reg.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) { let mut display_name = if let Ok(meta) = crate::plugins::load_store_metadata(root, plugin_id, &plugin_entry.sha256) {
meta.name meta.name
} else { } else {
+19 -3
View File
@@ -949,9 +949,21 @@ pub fn update(
pub fn remove(server: &Path, id: &str) -> Result<()> { pub fn remove(server: &Path, id: &str) -> Result<()> {
require_server_stopped(server)?; require_server_stopped(server)?;
let mut tx = TxGuard::begin_op(server, PluginOpType::Remove, id)?;
let mut reg = load_registry_direct(server)?; 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(()); return Ok(());
} }
@@ -962,10 +974,14 @@ pub fn remove(server: &Path, id: &str) -> Result<()> {
regenerate_lockfile(server, &reg)?; regenerate_lockfile(server, &reg)?;
check_crash_injection("after_lock_update"); 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() { if target_dir.is_dir() {
let _ = fs::remove_dir_all(target_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)?; tx.set_phase(TransactionPhase::Validating)?;
check_crash_injection("before_commit"); check_crash_injection("before_commit");
+42 -4
View File
@@ -718,9 +718,20 @@ fn meta_dir(root: &std::path::Path) -> Result<PathBuf> {
if dir.join("install.json").is_file() { if dir.join("install.json").is_file() {
Ok(dir) Ok(dir)
} else { } else {
Err(Error::Invalid( let internal_meta = root.join(".manager");
"This server has not been added to the Manager yet.".into(), 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 root = path_of(&state, &id)?;
let _guard = BusyGuard::acquire(&state, &id)?; let _guard = BusyGuard::acquire(&state, &id)?;
blocking(move || { 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) coa_core::modules::set_enabled(&root, &dir, &module, enabled)
}) })
.await .await
+8 -7
View File
@@ -761,15 +761,15 @@ export function ModulesPage({
setToggling(m.id); setToggling(m.id);
setError(null); setError(null);
try { try {
// Mutual exclusion check between companions and squid // Mutual exclusion check between companions and playerbots (squid)
if (m.id === "companions" && !m.enabled) { if (m.id === "companions" && !m.enabled) {
const squidMod = modules?.find((x) => x.id === "squid"); const otherBot = modules?.find((x) => (x.id === "playerbots" || x.id === "squid") && x.enabled);
if (squidMod?.enabled) { if (otherBot) {
await api.moduleSetEnabled(serverId, "squid", false); await api.moduleSetEnabled(serverId, otherBot.id, false);
} }
} else if (m.id === "squid" && !m.enabled) { } else if ((m.id === "playerbots" || m.id === "squid") && !m.enabled) {
const compMod = modules?.find((x) => x.id === "companions"); const compMod = modules?.find((x) => x.id === "companions" && x.enabled);
if (compMod?.enabled) { if (compMod) {
await api.moduleSetEnabled(serverId, "companions", false); await api.moduleSetEnabled(serverId, "companions", false);
} }
} }
@@ -965,6 +965,7 @@ export function ModulesPage({
const msg = await api.previewRemoveModule(serverId, moduleId); const msg = await api.previewRemoveModule(serverId, moduleId);
setNotification(msg); setNotification(msg);
await loadInstalledPlugins(); await loadInstalledPlugins();
await load();
onChanged?.(); onChanged?.();
} catch (e) { } catch (e) {
setError(asUiError(e)); setError(asUiError(e));