From 1228807eafa16b7ce8ba1ef276160bbc03a9ed70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9?= Date: Sat, 10 Oct 2026 06:29:32 +0500 Subject: [PATCH] feat(races): integrate client patch installation and controls --- crates/coa-core/src/custom_races.rs | 468 ++++++++++++++++++++++++++++ crates/coa-core/src/lib.rs | 1 + crates/coa-core/src/modules.rs | 15 +- src-tauri/src/lib.rs | 47 ++- src/lib/api.ts | 19 ++ src/screens/ModulesPage.tsx | 114 ++++++- 6 files changed, 658 insertions(+), 6 deletions(-) create mode 100644 crates/coa-core/src/custom_races.rs diff --git a/crates/coa-core/src/custom_races.rs b/crates/coa-core/src/custom_races.rs new file mode 100644 index 0000000..a0f3a96 --- /dev/null +++ b/crates/coa-core/src/custom_races.rs @@ -0,0 +1,468 @@ +//! Management of client-side patches and assets for Custom Races. +//! +//! Handles detecting, enabling/disabling (via `.disabled` extension renaming), +//! and downloading/extracting client patches (Esteria and additional races) +//! into the player's WoW client directory. + +use std::fs::{self, File}; +use std::io::{self, Read, Write}; +use std::path::{Path, PathBuf}; + +use serde::{Deserialize, Serialize}; + +use crate::download::Cancel; +use crate::error::{Error, Result}; +use crate::fsx; + +pub const MANIFEST_FILENAME: &str = "custom_races_patch_manifest.txt"; +pub const GITHUB_RELEASE_BASE: &str = + "https://github.com/ilusixn/azerothcore-wotlk-coa/releases/download/coa-custom-1.4"; + +pub const ARCHIVES: &[(&str, &str)] = &[ + ( + "CoA-Custom-1.4-main-20261007-b46a130e.zip", + "https://github.com/ilusixn/azerothcore-wotlk-coa/releases/download/coa-custom-1.4/CoA-Custom-1.4-main-20261007-b46a130e.zip", + ), + ( + "CoA-Custom-1.4-client-part1.zip", + "https://github.com/ilusixn/azerothcore-wotlk-coa/releases/download/coa-custom-1.4/CoA-Custom-1.4-client-part1.zip", + ), + ( + "CoA-Custom-1.4-client-part2.zip", + "https://github.com/ilusixn/azerothcore-wotlk-coa/releases/download/coa-custom-1.4/CoA-Custom-1.4-client-part2.zip", + ), +]; + +pub const RACE_MPQS: &[&str] = &[ + "patch-T.MPQ", + "patch-ZE1.MPQ", + "patch-ZE2.MPQ", + "patch-ZE3.MPQ", + "patch-ZE5.MPQ", + "patch-ZE6.MPQ", + "patch-ZE7.MPQ", + "patch-ZE8.MPQ", + "patch-ZE9.MPQ", + "patch-ZEA.MPQ", + "patch-ZG.MPQ", + "patch-ZH.MPQ", + "patch-ZHA.MPQ", + "patch-ZHM.MPQ", + "patch-ZM.MPQ", + "patch-ZVU.MPQ", +]; + +#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] +#[serde(rename_all = "kebab-case")] +pub enum ClientPatchState { + NotInstalled, + Enabled, + Disabled, + PartiallyInstalled, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct ClientPatchStatus { + pub state: ClientPatchState, + pub installed_mpqs: usize, + pub total_mpqs: usize, + pub has_root_files: bool, + pub client_path: Option, +} + +/// Inspect the client folder and determine the state of custom races patches. +pub fn client_patch_status(client_path: &Path) -> ClientPatchStatus { + let data_dir = client_path.join("Data"); + let mut enabled_count = 0; + let mut disabled_count = 0; + + for mpq in RACE_MPQS { + if data_dir.join(mpq).is_file() { + enabled_count += 1; + } else if data_dir.join(format!("{mpq}.disabled")).is_file() { + disabled_count += 1; + } + } + + let has_root = client_path.join("EsteriaAppearance.dll").is_file() + || client_path.join("dinput8.dll").is_file() + || client_path.join("dinput8.dll.disabled").is_file(); + + let total = RACE_MPQS.len(); + let state = if enabled_count >= total - 2 { + ClientPatchState::Enabled + } else if disabled_count >= total - 2 { + ClientPatchState::Disabled + } else if (enabled_count + disabled_count) > 0 { + ClientPatchState::PartiallyInstalled + } else { + ClientPatchState::NotInstalled + }; + + ClientPatchStatus { + state, + installed_mpqs: enabled_count + disabled_count, + total_mpqs: total, + has_root_files: has_root, + client_path: Some(client_path.to_string_lossy().into_owned()), + } +} + +/// Enable or disable client patches by renaming MPQs and `dinput8.dll` with `.disabled`. +pub fn set_client_patch_enabled(client_path: &Path, enabled: bool) -> Result<()> { + if !client_path.is_dir() { + return Err(Error::Invalid("Game client directory not found.".into())); + } + + let data_dir = client_path.join("Data"); + let manifest_path = client_path.join(MANIFEST_FILENAME); + + // 1. Process files from manifest if it exists + if manifest_path.is_file() { + if let Ok(manifest_content) = fs::read_to_string(&manifest_path) { + for line in manifest_content.lines() { + let line = line.trim(); + if let Some(mpq) = line.strip_prefix("MPQ:") { + let mpq = mpq.trim(); + let active = data_dir.join(mpq); + let disabled = data_dir.join(format!("{mpq}.disabled")); + if enabled { + if disabled.is_file() { + let _ = fs::rename(&disabled, &active); + } + } else if active.is_file() { + let _ = fs::rename(&active, &disabled); + } + } else if line == "ROOT:dinput8.dll" { + let active = client_path.join("dinput8.dll"); + let disabled = client_path.join("dinput8.dll.disabled"); + if enabled { + if disabled.is_file() { + let _ = fs::rename(&disabled, &active); + } + } else if active.is_file() { + let _ = fs::rename(&active, &disabled); + } + } + } + } + } + + // 2. Also ensure all known RACE_MPQS and dinput8.dll are toggled even if manifest is missing + for mpq in RACE_MPQS { + let active = data_dir.join(mpq); + let disabled = data_dir.join(format!("{mpq}.disabled")); + if enabled { + if disabled.is_file() && !active.is_file() { + let _ = fs::rename(&disabled, &active); + } + } else if active.is_file() { + let _ = fs::rename(&active, &disabled); + } + } + + let dll_active = client_path.join("dinput8.dll"); + let dll_disabled = client_path.join("dinput8.dll.disabled"); + if enabled { + if dll_disabled.is_file() && !dll_active.is_file() { + let _ = fs::rename(&dll_disabled, &dll_active); + } + } else if dll_active.is_file() { + let _ = fs::rename(&dll_active, &dll_disabled); + } + + tracing::info!(enabled, "custom races client patches toggled"); + Ok(()) +} + +/// Locate an archive locally in Downloads or cache, or download it from GitHub. +fn resolve_or_download_archive( + filename: &str, + url: &str, + client: &reqwest::blocking::Client, + cancel: &Cancel, + report: &dyn Fn(&str, f32), + base_percent: f32, + percent_slice: f32, +) -> Result { + // 1. Check user Downloads folder + if let Some(userprofile) = std::env::var_os("USERPROFILE") { + let downloads = PathBuf::from(userprofile).join("Downloads"); + let candidate = downloads.join(filename); + if candidate.is_file() { + if let Ok(meta) = candidate.metadata() { + if meta.len() > 1000 { + tracing::info!(path = %candidate.display(), "using existing archive in Downloads"); + return Ok(candidate); + } + } + } + } + + // 2. Check temp / cache directory + let cache_dir = std::env::temp_dir().join("coa-client-races"); + fs::create_dir_all(&cache_dir)?; + let target = cache_dir.join(filename); + if target.is_file() { + if let Ok(meta) = target.metadata() { + if meta.len() > 1000 { + return Ok(target); + } + } + } + + // 3. Download from GitHub Releases + report(&format!("Downloading {filename}..."), base_percent); + let part_path = cache_dir.join(format!("{filename}.part")); + + let resp = client + .get(url) + .send() + .map_err(|e| Error::NetworkUnreachable(format!("Could not reach download server: {e}")))?; + + if !resp.status().is_success() { + return Err(Error::NetworkUnreachable(format!( + "Download failed with status {} for {url}", + resp.status() + ))); + } + + let total_bytes = resp.content_length().unwrap_or(0); + let mut downloaded = 0u64; + let mut src = resp; + let mut dst = File::create(&part_path)?; + + let mut buf = [0u8; 64 * 1024]; + let mut last_report = std::time::Instant::now(); + + loop { + if cancel.is_set() { + let _ = fs::remove_file(&part_path); + return Err(Error::Invalid("Operation cancelled.".into())); + } + + let n = src + .read(&mut buf) + .map_err(|e| Error::NetworkUnreachable(format!("Download interrupted: {e}")))?; + if n == 0 { + break; + } + + dst.write_all(&buf[..n])?; + downloaded += n as u64; + + if last_report.elapsed() > std::time::Duration::from_millis(200) { + let ratio = if total_bytes > 0 { + (downloaded as f32 / total_bytes as f32).clamp(0.0, 1.0) + } else { + 0.5 + }; + report( + &format!( + "Downloading {filename} ({:.1} MB)...", + downloaded as f64 / 1_048_576.0 + ), + base_percent + ratio * percent_slice, + ); + last_report = std::time::Instant::now(); + } + } + + dst.flush()?; + drop(dst); + + fs::rename(&part_path, &target)?; + Ok(target) +} + +/// Download (if needed) and extract custom races client assets into the target WoW client. +pub fn install_client_patches( + client_path: &Path, + cancel: &Cancel, + report: &dyn Fn(&str, f32), +) -> Result<()> { + if !client_path.is_dir() { + return Err(Error::Invalid("Game client directory does not exist.".into())); + } + + let data_dir = client_path.join("Data"); + fs::create_dir_all(&data_dir)?; + + // 1. Back up original Ascension.exe and patch-T.MPQ if they exist and haven't been backed up yet + let exe = client_path.join("Ascension.exe"); + let exe_bak = client_path.join("Ascension.exe.original"); + if exe.is_file() && !exe_bak.is_file() { + report("Backing up original Ascension.exe...", 0.02); + fs::copy(&exe, &exe_bak)?; + } + + let t_mpq = data_dir.join("patch-T.MPQ"); + let t_mpq_bak = data_dir.join("patch-T.MPQ.original"); + if t_mpq.is_file() && !t_mpq_bak.is_file() { + report("Backing up original patch-T.MPQ...", 0.04); + fs::copy(&t_mpq, &t_mpq_bak)?; + } + + // 2. Resolve/download archives (0.05 .. 0.50) + let http = reqwest::blocking::Client::builder() + .user_agent(concat!("CoA-Server-Manager/", env!("CARGO_PKG_VERSION"))) + .timeout(std::time::Duration::from_secs(600)) + .build() + .map_err(|e| Error::Invalid(format!("Cannot prepare downloader: {e}")))?; + + let mut resolved_archives = Vec::new(); + let n_archives = ARCHIVES.len() as f32; + for (i, (fname, url)) in ARCHIVES.iter().enumerate() { + let base_pct = 0.05 + (i as f32 / n_archives) * 0.45; + let slice = 0.45 / n_archives; + let archive_path = + resolve_or_download_archive(fname, url, &http, cancel, report, base_pct, slice)?; + resolved_archives.push(archive_path); + } + + // 3. Extract archives (0.50 .. 0.95) + let mut installed_mpqs = Vec::new(); + let mut installed_roots = Vec::new(); + + for (i, arch_path) in resolved_archives.iter().enumerate() { + if cancel.is_set() { + return Err(Error::Invalid("Operation cancelled.".into())); + } + + let arch_name = arch_path + .file_name() + .map(|n| n.to_string_lossy().into_owned()) + .unwrap_or_default(); + report( + &format!("Unpacking {arch_name}..."), + 0.50 + (i as f32 / n_archives) * 0.45, + ); + + let file = File::open(arch_path)?; + let mut zip = zip::ZipArchive::new(file) + .map_err(|e| Error::Invalid(format!("Failed to open zip {arch_name}: {e}")))?; + + let num_files = zip.len(); + for file_idx in 0..num_files { + if cancel.is_set() { + return Err(Error::Invalid("Operation cancelled.".into())); + } + + let mut zfile = zip + .by_index(file_idx) + .map_err(|e| Error::Invalid(format!("Zip entry error in {arch_name}: {e}")))?; + + if zfile.is_dir() { + continue; + } + + let zname = zfile.name().to_string(); + let zname_norm = zname.replace('\\', "/"); + + if zname_norm.contains("files/client/") { + let base = Path::new(&zname_norm) + .file_name() + .map(|n| n.to_string_lossy().into_owned()) + .unwrap_or_default(); + + if base.to_ascii_lowercase().ends_with(".mpq") { + let dest = data_dir.join(&base); + let mut out = File::create(&dest)?; + io::copy(&mut zfile, &mut out)?; + installed_mpqs.push(base); + } else if base.eq_ignore_ascii_case("dinput8.dll") { + let dest = client_path.join(&base); + let mut out = File::create(&dest)?; + io::copy(&mut zfile, &mut out)?; + installed_roots.push(base); + } + } else if zname_norm.contains("files/client_root/") { + let base = Path::new(&zname_norm) + .file_name() + .map(|n| n.to_string_lossy().into_owned()) + .unwrap_or_default(); + + if !base.is_empty() { + let dest = client_path.join(&base); + let mut out = File::create(&dest)?; + io::copy(&mut zfile, &mut out)?; + installed_roots.push(base); + } + } + } + } + + // 4. Record manifest + report("Finalizing manifest...", 0.98); + let manifest_path = client_path.join(MANIFEST_FILENAME); + installed_mpqs.sort(); + installed_mpqs.dedup(); + installed_roots.sort(); + installed_roots.dedup(); + + let mut manifest_body = String::from("# Custom Race MPQ files\n"); + for m in &installed_mpqs { + manifest_body.push_str(&format!("MPQ:{m}\n")); + } + manifest_body.push_str("# Custom Race root files\n"); + for r in &installed_roots { + manifest_body.push_str(&format!("ROOT:{r}\n")); + } + + fsx::atomic_write(&manifest_path, manifest_body.as_bytes())?; + report("Custom races client patches installed successfully!", 1.0); + tracing::info!( + mpqs = installed_mpqs.len(), + roots = installed_roots.len(), + "custom races client patch installation complete" + ); + + Ok(()) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_patch_status_and_toggle() { + let temp = tempfile::tempdir().unwrap(); + let client_path = temp.path(); + let data_dir = client_path.join("Data"); + fs::create_dir_all(&data_dir).unwrap(); + + // 1. Initial state: Not installed + let st = client_patch_status(client_path); + assert_eq!(st.state, ClientPatchState::NotInstalled); + + // 2. Create MPQs and root files + for mpq in RACE_MPQS { + fs::write(data_dir.join(mpq), b"test mpq content").unwrap(); + } + fs::write(client_path.join("dinput8.dll"), b"test dll").unwrap(); + fs::write(client_path.join("EsteriaAppearance.dll"), b"test dll").unwrap(); + + let st = client_patch_status(client_path); + assert_eq!(st.state, ClientPatchState::Enabled); + assert_eq!(st.installed_mpqs, RACE_MPQS.len()); + + // 3. Disable patches + set_client_patch_enabled(client_path, false).unwrap(); + let st = client_patch_status(client_path); + assert_eq!(st.state, ClientPatchState::Disabled); + assert!(data_dir.join("patch-T.MPQ.disabled").is_file()); + assert!(!data_dir.join("patch-T.MPQ").is_file()); + assert!(client_path.join("dinput8.dll.disabled").is_file()); + assert!(!client_path.join("dinput8.dll").is_file()); + + // 4. Re-enable patches + set_client_patch_enabled(client_path, true).unwrap(); + let st = client_patch_status(client_path); + assert_eq!(st.state, ClientPatchState::Enabled); + assert!(data_dir.join("patch-T.MPQ").is_file()); + assert!(!data_dir.join("patch-T.MPQ.disabled").is_file()); + assert!(client_path.join("dinput8.dll").is_file()); + assert!(!client_path.join("dinput8.dll.disabled").is_file()); + } +} diff --git a/crates/coa-core/src/lib.rs b/crates/coa-core/src/lib.rs index b105692..6a2d345 100644 --- a/crates/coa-core/src/lib.rs +++ b/crates/coa-core/src/lib.rs @@ -2,6 +2,7 @@ pub mod accounts; pub mod backup; pub mod cleanbase; pub mod companions; +pub mod custom_races; pub mod client; pub mod remote_client; pub mod clientdl; diff --git a/crates/coa-core/src/modules.rs b/crates/coa-core/src/modules.rs index 9564696..250a311 100644 --- a/crates/coa-core/src/modules.rs +++ b/crates/coa-core/src/modules.rs @@ -203,7 +203,20 @@ pub fn set_enabled(root: &Path, meta: &Path, id: &str, on: bool) -> Result<()> { Some(lock) } else { None }; if on { crate::realms::guard_module(root, id)?; } - set_enabled_in(&catalog(), root, meta, id, on) + set_enabled_in(&catalog(), root, meta, id, on)?; + if id == "custom-races" { + if let Ok(meta_content) = fs::read_to_string(meta.join("install.json")) { + if let Ok(install_meta) = serde_json::from_str::(&meta_content) { + if let Some(cp) = install_meta.client_path { + let client_path = PathBuf::from(cp); + if client_path.is_dir() { + let _ = crate::custom_races::set_client_patch_enabled(&client_path, on); + } + } + } + } + } + Ok(()) } fn bot_enabled(root: &Path, e: &Entry) -> Result { diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index fa60d83..1563bda 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -639,6 +639,48 @@ async fn module_set_enabled(state: State<'_, AppState>, id: String, module: Stri }) .await } + +#[tauri::command] +async fn custom_races_status(state: State<'_, AppState>, id: String) -> std::result::Result, UiError> { + let root = path_of(&state, &id)?; + blocking(move || { + let client = linked_client(&root)?; + Ok(client.as_deref().map(coa_core::custom_races::client_patch_status)) + }) + .await +} + +#[tauri::command] +async fn custom_races_install(app: AppHandle, state: State<'_, AppState>, id: String) -> std::result::Result<(), UiError> { + let root = path_of(&state, &id)?; + let _guard = BusyGuard::acquire(&state, &id)?; + let cancel = begin_client_job(&state)?; + let sid = id.clone(); + let result = blocking(move || { + let client = linked_client(&root)?.ok_or_else(|| Error::Invalid("No game client is linked to this server.".into()))?; + coa_core::custom_races::install_client_patches(&client, &cancel, &|step, percent| { + let _ = app.emit("custom-races-progress", serde_json::json!({ + "id": sid, + "step": step, + "percent": percent, + })); + }) + }) + .await; + end_client_job(&state); + result +} + +#[tauri::command] +async fn custom_races_toggle_client(state: State<'_, AppState>, id: String, enabled: bool) -> std::result::Result<(), UiError> { + let root = path_of(&state, &id)?; + let _guard = BusyGuard::acquire(&state, &id)?; + blocking(move || { + let client = linked_client(&root)?.ok_or_else(|| Error::Invalid("No game client is linked to this server.".into()))?; + coa_core::custom_races::set_client_patch_enabled(&client, enabled) + }) + .await +} #[tauri::command] async fn module_settings(state: State<'_, AppState>, id: String, module: String) -> std::result::Result, UiError> { @@ -1679,7 +1721,10 @@ pub fn run() { export_diagnostics, console_tail, console_risk, - console_command + console_command, + custom_races_status, + custom_races_install, + custom_races_toggle_client ]) .run(tauri::generate_context!()) .expect("error while running CoA Server Manager"); diff --git a/src/lib/api.ts b/src/lib/api.ts index b580709..8b2294c 100644 --- a/src/lib/api.ts +++ b/src/lib/api.ts @@ -379,6 +379,22 @@ export interface ClientDownloadCheck { dest: string; } +export type ClientPatchState = "not-installed" | "enabled" | "disabled" | "partially-installed"; + +export interface CustomRacesClientStatus { + state: ClientPatchState; + installedMpqs: number; + totalMpqs: number; + hasRootFiles: boolean; + clientPath: string | null; +} + +export interface CustomRacesProgress { + id: string; + step: string; + percent: number; +} + export type FriendsMode = "local" | "lan" | "direct" | "private"; export interface LanAddress { @@ -503,6 +519,9 @@ export const api = { clientSync: (id: string, keepModified: boolean) => invoke("client_sync", { id, keepModified }), clientDownload: (id: string, parent: string) => invoke("client_download", { id, parent }), clientCancel: () => invoke("client_cancel"), + customRacesStatus: (id: string) => invoke("custom_races_status", { id }), + customRacesInstall: (id: string) => invoke("custom_races_install", { id }), + customRacesToggleClient: (id: string, enabled: boolean) => invoke("custom_races_toggle_client", { id, enabled }), play: (id: string) => invoke("play", { id }), friendsStatus: (id: string) => invoke("friends_status", { id }), friendsCheckInternet: () => invoke("friends_check_internet"), diff --git a/src/screens/ModulesPage.tsx b/src/screens/ModulesPage.tsx index d18e919..d90a993 100644 --- a/src/screens/ModulesPage.tsx +++ b/src/screens/ModulesPage.tsx @@ -1,6 +1,7 @@ import { Fragment, useCallback, useEffect, useRef, useState, type ComponentType, type ReactNode } from "react"; +import { listen } from "@tauri-apps/api/event"; import { Bot, Flame, Gavel, Loader2, Plug, Puzzle, Scaling, Settings2, Snowflake, Sparkles, Swords, Users, type LucideProps } from "lucide-react"; -import { api, asUiError, type ModuleSetting, type ModuleView, type UiError } from "@/lib/api"; +import { api, asUiError, type CustomRacesClientStatus, type CustomRacesProgress, type ModuleSetting, type ModuleView, type UiError } from "@/lib/api"; import { cn } from "@/lib/utils"; import { Button } from "@/components/ui/button"; import { Card } from "@/components/ui/card"; @@ -86,18 +87,55 @@ export function ModulesPage({ serverId, onChanged }: { serverId: string; onChang const [open, setOpen] = useState(null); const [error, setError] = useState(null); const [changed, setChanged] = useState(false); + const [racesPatchStatus, setRacesPatchStatus] = useState(null); + const [racesInstalling, setRacesInstalling] = useState(false); + const [racesProgress, setRacesProgress] = useState(null); + + const loadRacesStatus = useCallback(async () => { + try { + const st = await api.customRacesStatus(serverId); + setRacesPatchStatus(st); + } catch { + // ignore + } + }, [serverId]); const load = useCallback(async () => { try { setModules((await api.modulesList(serverId)).filter((m) => !m.hidden)); + await loadRacesStatus(); } catch (e) { setError(asUiError(e)); } - }, [serverId]); + }, [serverId, loadRacesStatus]); useEffect(() => { void load(); - }, [load]); + const un = listen("custom-races-progress", (e) => { + if (e.payload.id === serverId) { + setRacesProgress(e.payload); + } + }); + return () => { + void un.then((f) => f()); + }; + }, [load, serverId]); + + async function installClientPatch() { + setRacesInstalling(true); + setError(null); + try { + await api.customRacesInstall(serverId); + await loadRacesStatus(); + await load(); + onChanged?.(); + } catch (e) { + setError(asUiError(e)); + } finally { + setRacesInstalling(false); + setRacesProgress(null); + } + } async function toggle(m: ModuleView) { setError(null); @@ -105,6 +143,9 @@ export function ModulesPage({ serverId, onChanged }: { serverId: string; onChang await api.moduleSetEnabled(serverId, m.id, !m.enabled); setChanged(true); await load(); + if (m.id === "custom-races") { + await loadRacesStatus(); + } onChanged?.(); } catch (e) { setError(asUiError(e)); @@ -146,8 +187,9 @@ export function ModulesPage({ serverId, onChanged }: { serverId: string; onChang role="switch" aria-checked={m.enabled} aria-label={t("mod.switch", { name: m.name })} + disabled={m.id === "custom-races" && racesInstalling} onClick={() => void toggle(m)} - className={cn("relative mt-1 h-6 w-11 shrink-0 cursor-pointer rounded-full transition-colors", m.enabled ? "bg-gold" : "bg-white/15")} + className={cn("relative mt-1 h-6 w-11 shrink-0 cursor-pointer rounded-full transition-colors", m.enabled ? "bg-gold" : "bg-white/15", (m.id === "custom-races" && racesInstalling) && "opacity-50 cursor-not-allowed")} > @@ -155,6 +197,70 @@ export function ModulesPage({ serverId, onChanged }: { serverId: string; onChang {m.installed && !m.switchable && m.status !== "soon" && m.compatibility !== "unsupported" && {t("mod.alwaysOn")}} {!m.installed && m.status !== "soon" && {t("mod.notHere")}} + {m.id === "custom-races" && ( +
+ {racesInstalling && racesProgress ? ( +
+
+ + + {racesProgress.step} + + + {Math.round(racesProgress.percent * 100)}% + +
+
+
+
+
+ ) : ( +
+
+ {racesPatchStatus?.state === "enabled" && ( + + + {locale === "ru" ? "Патч клиента: Включен" : "Client Patch: Active"} + + )} + {racesPatchStatus?.state === "disabled" && ( + + + {locale === "ru" ? "Патч клиента: Отключен (.disabled)" : "Client Patch: Disabled (.disabled)"} + + )} + {racesPatchStatus?.state === "not-installed" && ( + + + {locale === "ru" ? "Патч клиента: Не установлен" : "Client Patch: Not Installed"} + + )} + {racesPatchStatus?.state === "partially-installed" && ( + + + {locale === "ru" ? `Патч клиента: ${racesPatchStatus.installedMpqs}/${racesPatchStatus.totalMpqs} MPQ` : `Client Patch: ${racesPatchStatus.installedMpqs}/${racesPatchStatus.totalMpqs} MPQ`} + + )} +
+ {(!racesPatchStatus || racesPatchStatus.state === "not-installed" || racesPatchStatus.state === "partially-installed") && ( + + )} +
+ )} +
+ )}