diff --git a/changelog.d/20261013-installed-module-versions.md b/changelog.d/20261013-installed-module-versions.md new file mode 100644 index 0000000..7916c12 --- /dev/null +++ b/changelog.d/20261013-installed-module-versions.md @@ -0,0 +1,7 @@ +--- +area: manager +type: added +audience: admins +title: Module cards show installed server revisions and the client race patch version +--- +Module revisions come from the currently installed release metadata. The race card shows the client patch version separately; missing version metadata is reported honestly instead of showing a download version as installed. diff --git a/crates/coa-core/src/custom_races.rs b/crates/coa-core/src/custom_races.rs index 63db5d6..4acda94 100644 --- a/crates/coa-core/src/custom_races.rs +++ b/crates/coa-core/src/custom_races.rs @@ -146,6 +146,7 @@ pub enum ClientPatchState { #[serde(rename_all = "camelCase")] pub struct ClientPatchStatus { pub state: ClientPatchState, + pub version: Option, pub installed_mpqs: usize, pub total_mpqs: usize, pub has_root_files: bool, @@ -210,7 +211,8 @@ pub fn client_patch_status(client_path: &Path) -> ClientPatchStatus { } else if !manifest.is_empty() || patch_files(client_path).is_ok_and(|files| files.iter().filter(|file| file.path.starts_with("Data/") && file.path != "Data/patch-T.MPQ").any(|file| matches_patch(&client_path.join(&file.path), file) || matches_patch(&suffix(&client_path.join(&file.path), "disabled"), file))) { ClientPatchState::PartiallyInstalled } else { ClientPatchState::NotInstalled }; - ClientPatchStatus { state, installed_mpqs, total_mpqs: RACE_MPQS.len(), has_root_files, + let version = manifest.lines().find_map(|line| line.strip_prefix("# CoA Custom ").map(str::to_string)); + ClientPatchStatus { state, version, installed_mpqs, total_mpqs: RACE_MPQS.len(), has_root_files, client_path: Some(client_path.to_string_lossy().into_owned()) } } diff --git a/crates/coa-core/src/modules.rs b/crates/coa-core/src/modules.rs index b6d0bdd..f5b8606 100644 --- a/crates/coa-core/src/modules.rs +++ b/crates/coa-core/src/modules.rs @@ -119,7 +119,26 @@ fn conf_name(root: &Path, e: &Entry) -> String { } } +fn installed_module_commits(root: &Path) -> BTreeMap { + let Ok(directory) = crate::registry::metadata_dir_for(root) else { return Default::default() }; + let Ok((_, meta)) = crate::registry::MetaDir::open(&directory) else { return Default::default() }; + let Some(version) = meta.core.version else { return Default::default() }; + let candidates = [directory.join("manifests").join(format!("update-{version}.json")), directory.join("manifests/base.json")]; + for path in candidates { + let Ok(manifest) = crate::fsx::read_json::(&path) else { continue }; + if manifest.get("version").and_then(|value| value.as_str()) != Some(&version) { continue; } + if let Some(commits) = manifest.get("compatibility").and_then(|value| value.get("moduleCommits")).and_then(|value| value.as_object()) { + return commits.iter().filter_map(|(name, commit)| { + let commit = commit.as_str()?; + (commit.len() == 40 && commit.bytes().all(|byte| byte.is_ascii_hexdigit())).then(|| (name.clone(), commit.chars().take(8).collect())) + }).collect(); + } + } + Default::default() +} + fn list_in(cat: &[Entry], root: &Path) -> Vec { + let installed_commits = installed_module_commits(root); let wildcard = crate::realms::state(root).map(|s| s.active == crate::realms::Mode::Wildcard).unwrap_or(true); cat.iter() .cloned() @@ -141,6 +160,8 @@ fn list_in(cat: &[Entry], root: &Path) -> Vec { let version = if e.id == "playerbots" { crate::squid::release(root).map(|release| { [release.tag, release.commit.map(|commit| commit.chars().take(8).collect())].into_iter().flatten().collect::>().join(" · ") }) } else { None }; + let key = match e.id.as_str() { "companions" => "bots", "playerbots" => "squid", "content-scaling" => "scaling", "custom-races" => "races", id => id }; + let version = if installed { version.or_else(|| installed_commits.get(key).cloned()) } else { None }; ModuleView { version, compatibility: if blocked { "unsupported" } else if wildcard && e.id != "client-compat" { "experimental" } else { "compatible" }.into(), @@ -425,6 +446,22 @@ mod tests { (root, meta) } + #[test] + fn module_revisions_come_from_the_installed_release_only() { + let temp = tempfile::tempdir().unwrap(); + let root = temp.path().join("server"); + fs::create_dir_all(&root).unwrap(); + let mut meta = crate::registry::InstallMeta::new(crate::registry::InstallKind::Imported, &root); + meta.core.version = Some("2.0.0".into()); + let directory = crate::registry::MetaDir::create(&root, &meta).unwrap(); + let value = serde_json::json!({"version": "2.0.0", "compatibility": {"moduleCommits": {"races": "a".repeat(40), "bots": "b".repeat(40)}}}); + fsx::atomic_write_json(&directory.root.join("manifests/update-2.0.0.json"), &value).unwrap(); + assert_eq!(installed_module_commits(&root).get("races").map(String::as_str), Some("aaaaaaaa")); + let stale = serde_json::json!({"version": "1.0.0", "compatibility": {"moduleCommits": {"races": "c".repeat(40)}}}); + fsx::atomic_write_json(&directory.root.join("manifests/update-2.0.0.json"), &stale).unwrap(); + assert!(installed_module_commits(&root).is_empty()); + } + #[test] fn squid_missing_keys_use_code_defaults_and_saves_enforce_json_ranges() { let d = tempfile::tempdir().unwrap(); diff --git a/src/lib/api.ts b/src/lib/api.ts index aafe0df..b0fb34a 100644 --- a/src/lib/api.ts +++ b/src/lib/api.ts @@ -393,6 +393,7 @@ export interface ClientDownloadCheck { export type ClientPatchState = "not-installed" | "enabled" | "disabled" | "partially-installed"; export interface CustomRacesClientStatus { + version: string | null; state: ClientPatchState; installedMpqs: number; totalMpqs: number; diff --git a/src/screens/ModulesPage.tsx b/src/screens/ModulesPage.tsx index 9894687..5cba9dd 100644 --- a/src/screens/ModulesPage.tsx +++ b/src/screens/ModulesPage.tsx @@ -216,7 +216,9 @@ export function ModulesPage({ serverId, onChanged, onRegisterGuard }: { serverId {!m.installed && m.status !== "soon" && {t("mod.notHere")}} {m.id === "custom-races" && ( +
+

{locale === "ru" ? "Установленная версия патча клиента: " : "Installed client patch version: "}{racesPatchStatus?.version ?? (locale === "ru" ? "не записана" : "not recorded")}

{racesInstalling && racesProgress ? (