From af82963f35370f5e51033d08cdbc41da3d12b83c 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: Tue, 27 Oct 2026 15:29:09 +0500 Subject: [PATCH] feat: open firewall ports for every running world and list every realm publicly - Starting a server that is open to friends adds the firewall rules for the world ports of all realms that start together (only missing ones; a refused Windows prompt does not undo the start). - Settings shows one public-listing block per realm that starts together. The main realm keeps its plain local id, so an existing listing is untouched. - A realm that runs as an extra world is reached through that world's own console port, so its listing reports its own state and capabilities. Co-Authored-By: Claude Sonnet 5.5 --- ...7-public-list-shows-every-running-realm.md | 7 +++ crates/coa-core/src/multiworld.rs | 37 ++++++++++++++ .../coa-core/src/portable/service/access.rs | 10 +++- crates/coa-core/src/realms.rs | 17 +++++++ src-tauri/src/lib.rs | 22 +++++--- src/screens/PublishCard.tsx | 50 +++++++++++++------ 6 files changed, 119 insertions(+), 24 deletions(-) create mode 100644 changelog.d/20261027-public-list-shows-every-running-realm.md diff --git a/changelog.d/20261027-public-list-shows-every-running-realm.md b/changelog.d/20261027-public-list-shows-every-running-realm.md new file mode 100644 index 0000000..d098b19 --- /dev/null +++ b/changelog.d/20261027-public-list-shows-every-running-realm.md @@ -0,0 +1,7 @@ +--- +area: manager +type: fixed +audience: admins +title: Public listing offers every realm that starts together, not just the main one +--- +With Wildcard or Warcraft Reborn started next to Conquest of Azeroth, Settings now has one listing block per realm, each with its own name, description and access options. diff --git a/crates/coa-core/src/multiworld.rs b/crates/coa-core/src/multiworld.rs index d5327e4..3c96fa2 100644 --- a/crates/coa-core/src/multiworld.rs +++ b/crates/coa-core/src/multiworld.rs @@ -82,6 +82,21 @@ pub fn tree_running(main: &Path, tree: Tree) -> bool { .any(|n| process::read_state_record(&second, n).is_some_and(|p| process::is_alive(&p))) } +/// The folder whose world server runs `mode`: the main folder, or the folder of the extra world that runs that realm. +/// Its settings hold the console port that belongs to that world. +pub fn world_root(main: &Path, mode: Mode) -> PathBuf { + let Ok(s) = realms::state(main) else { + return main.to_path_buf(); + }; + if mode == s.active { + return main.to_path_buf(); + } + Tree::ALL + .into_iter() + .find(|t| t.enabled(&s) && t.mode(s.active) == mode) + .map_or_else(|| main.to_path_buf(), |t| tree_root(main, t)) +} + /// Any of the extra worlds is running or still stopping. pub fn is_running(main: &Path) -> bool { Tree::ALL.into_iter().any(|t| tree_running(main, t)) @@ -446,6 +461,28 @@ mod tests { assert!(!Tree::Second.enabled(&s) && Tree::Reborn.enabled(&s)); } + #[test] + fn a_realm_is_reached_through_the_folder_of_its_own_world() { + let t = tempfile::tempdir().unwrap(); + let main = t.path(); + fsx::atomic_write( + &main.join("Settings/realm-profile.json"), + br#"{"active":"coa","wildcard_created":true,"reborn_created":true,"simultaneous":true,"with_reborn":true}"#, + ) + .unwrap(); + assert_eq!(world_root(main, Mode::Coa), main); + assert_eq!(world_root(main, Mode::Wildcard), main.join(".realms/secondary")); + assert_eq!(world_root(main, Mode::Reborn), main.join(".realms/reborn")); + // A realm that is not switched on has no world of its own: the main folder answers. + fsx::atomic_write( + &main.join("Settings/realm-profile.json"), + br#"{"active":"coa","wildcard_created":true,"reborn_created":true,"with_reborn":true}"#, + ) + .unwrap(); + assert_eq!(world_root(main, Mode::Wildcard), main); + assert_eq!(world_root(main, Mode::Reborn), main.join(".realms/reborn")); + } + #[test] fn reborn_starts_together_with_conquest_of_azeroth_only() { let t = tempfile::tempdir().unwrap(); diff --git a/crates/coa-core/src/portable/service/access.rs b/crates/coa-core/src/portable/service/access.rs index 9c220ac..bded8aa 100644 --- a/crates/coa-core/src/portable/service/access.rs +++ b/crates/coa-core/src/portable/service/access.rs @@ -248,9 +248,15 @@ impl RealmAccess { } } + /// The folder of the world server this realm runs in: an extra world next to the main one has its own console port. + fn world_folder(&self, root: &Path) -> PathBuf { + self.mode + .map_or_else(|| root.to_path_buf(), |m| crate::multiworld::world_root(root, m)) + } + pub fn ra(&self) -> Result { match &self.source { - Source::Install { root } => Ra::connect(root), + Source::Install { root } => Ra::connect(&self.world_folder(root)), Source::Descriptor(d) => Ra::connect_to(d.ra_port, &d.ra_user, d.ra_password.expose()), } } @@ -261,7 +267,7 @@ impl RealmAccess { pub fn ports(&self) -> (Option, u16) { match &self.source { - Source::Install { root } => (None, read_ports(root).ra), + Source::Install { root } => (None, read_ports(&self.world_folder(root)).ra), Source::Descriptor(d) => (Some(d.db_port), d.ra_port), } } diff --git a/crates/coa-core/src/realms.rs b/crates/coa-core/src/realms.rs index d0bed69..32b4fb8 100644 --- a/crates/coa-core/src/realms.rs +++ b/crates/coa-core/src/realms.rs @@ -80,6 +80,17 @@ pub struct RealmState { } impl RealmState { + /// World ports of the realms that run next to the primary one (the ones that are switched on). + pub fn extra_world_ports(&self) -> Vec { + [ + self.secondary_world_port.filter(|_| self.simultaneous), + self.reborn_world_port.filter(|_| self.with_reborn), + ] + .into_iter() + .flatten() + .collect() + } + /// Realms that run as a world of their own next to the primary one. pub fn extra_modes(&self) -> Vec { let mut modes = Vec::new(); @@ -1047,6 +1058,12 @@ CoA.GameModeMask = 0 assert_eq!(s.extra_modes(), [Mode::Reborn]); s.simultaneous = true; assert_eq!(s.extra_modes(), [Mode::Wildcard, Mode::Reborn]); + s.secondary_world_port = Some(8086); + s.reborn_world_port = Some(8087); + assert_eq!(s.extra_world_ports(), [8086, 8087]); + s.with_reborn = false; + assert_eq!(s.extra_world_ports(), [8086]); + s.with_reborn = true; // Wildcard as the main realm still pairs with Conquest of Azeroth. s.active = Mode::Wildcard; s.with_reborn = false; diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 1057d5f..04c825b 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -604,7 +604,19 @@ async fn start_server( }) .await; let _ = tauri::async_runtime::spawn_blocking(move || { - meta_dir(&root).and_then(|m| coa_core::friends::reapply(&root, &m)) + let meta = meta_dir(&root)?; + coa_core::friends::reapply(&root, &meta)?; + // A world switched on after the server was opened to friends has no firewall rule yet. Rules are only + // added when missing (one Windows confirmation); a refusal must not undo a start that worked. + if platform::flavor() == Flavor::Repack + && coa_core::friends::load(&meta).mode != coa_core::friends::Mode::Local + { + let extra = coa_core::realms::state(&root)?.extra_world_ports(); + if let Err(e) = coa_core::firewall::ensure_rules_with_extra(&layout::read_ports(&root), &extra) { + tracing::warn!("firewall rules for the running worlds were not added: {e}"); + } + } + Ok::<(), Error>(()) }) .await; } @@ -2557,13 +2569,7 @@ async fn friends_enable( let ports = layout::read_ports(&root); let mut note = None; let realms = coa_core::realms::state(&root)?; - let extra: Vec = [ - realms.secondary_world_port.filter(|_| realms.simultaneous), - realms.reborn_world_port.filter(|_| realms.with_reborn), - ] - .into_iter() - .flatten() - .collect(); + let extra = realms.extra_world_ports(); let host = match mode { Mode::Local => "127.0.0.1".to_string(), Mode::Lan => coa_core::net::resolve_lan_host(lan_address_override.as_deref(), coa_core::net::lan_ip())?, diff --git a/src/screens/PublishCard.tsx b/src/screens/PublishCard.tsx index b606113..5ce6516 100644 --- a/src/screens/PublishCard.tsx +++ b/src/screens/PublishCard.tsx @@ -4,16 +4,38 @@ import { Button } from "@/components/ui/button"; import { Card } from "@/components/ui/card"; import { cn } from "@/lib/utils"; import { useT, type Key } from "@/i18n"; -import { asUiError } from "@/lib/api"; +import { api, asUiError, type RealmMode } from "@/lib/api"; import { realmRegistry, useRegistryStatus } from "@/lib/registry"; import { asControlError, control, type ControlStatus } from "@/lib/control"; const LANGUAGES = ["en", "ru", "de", "fr", "es", "zh", "pt", "pl", "uk"]; -/** Publishing this server's realm to the central Registry: a name, a description, a language. Nothing else leaves this machine. */ +const REALM_LABEL: Record = { coa: "Conquest of Azeroth", wildcard: "Wildcard", reborn: "Warcraft Reborn" }; + +/** The realms this server runs: the main one keeps the plain id it was published under, each realm that starts next to it has its own. */ export function PublishCard({ serverId, serverName }: { serverId: string; serverName: string }) { + const [realms, setRealms] = useState<{ localId: string; mode: RealmMode }[] | null>(null); + useEffect(() => { + let alive = true; + void api.realmProfiles(serverId).then((r) => { + if (!alive) return; + const extra: RealmMode[] = []; + if (r.simultaneous) extra.push(r.active === "coa" ? "wildcard" : "coa"); + if (r.with_reborn) extra.push("reborn"); + setRealms([{ localId: `srv-${serverId}`, mode: r.active }, ...extra.map((mode) => ({ localId: `srv-${serverId}:${mode}`, mode }))]); + }).catch(() => { if (alive) setRealms([{ localId: `srv-${serverId}`, mode: "coa" }]); }); + return () => { alive = false; }; + }, [serverId]); + if (!realms) return null; + const several = realms.length > 1; + return <>{realms.map((r) => ( + + ))}; +} + +/** Publishing one realm to the central Registry: a name, a description, a language. Nothing else leaves this machine. */ +function RealmPublish({ localId, serverName, realmLabel }: { localId: string; serverName: string; realmLabel: string | null }) { const t = useT(); - const localId = `srv-${serverId}`; const { status, refresh } = useRegistryStatus(); const mine = status?.realms.find((r) => r.local_id === localId); const published = !!mine?.enabled; @@ -58,22 +80,22 @@ export function PublishCard({ serverId, serverName }: { serverId: string; server return ( -

{t("registry.title")}

+

{t("registry.title")}{realmLabel ? ` · ${realmLabel}` : ""}

{t("registry.text")}

{!published && <> - - setName(e.target.value)} className="mt-1 w-full rounded-md border border-line bg-card px-3 py-2" /> - -