mirror of
https://github.com/Corfirean/coa-server-manager.git
synced 2026-11-19 19:25:56 +00:00
Merge remote-tracking branch 'origin/feat/realms-start-together' into prepare/manager-20261028
This commit is contained in:
commit
eeb102e260
27 files changed
+809
-190
No files matched your search
@@ -176,6 +176,7 @@ export function FriendsPage({ serverId }: { serverId: string }) {
|
||||
</Line>
|
||||
</ul>
|
||||
{st.secondary_world_port && <p className="mt-3 text-sm text-muted">{t("realm.secondPort", { port: st.secondary_world_port })}</p>}
|
||||
{st.reborn_world_port && <p className="mt-3 text-sm text-muted">{t("realm.rebornPort", { port: st.reborn_world_port })}</p>}
|
||||
</Card>
|
||||
|
||||
<div className="mt-6 grid gap-3">
|
||||
|
||||
@@ -72,15 +72,15 @@ export function Overview({ server, companions = true, onForget, onOpenUpdates, o
|
||||
const human = useHuman();
|
||||
const [status, setStatus] = useState<StatusView | null>(null);
|
||||
// With both worlds started together, each realm gets its own card; the first realm owns the database and auth.
|
||||
const [realms, setRealms] = useState<{ first: string; second: string } | null>(null);
|
||||
const bothWorlds = !!status?.observed.secondary_world;
|
||||
const [realms, setRealms] = useState<{ first: string; second: string; reborn: string } | null>(null);
|
||||
const bothWorlds = !!status?.observed.secondary_world || !!status?.observed.reborn_world;
|
||||
useEffect(() => {
|
||||
if (!bothWorlds) { setRealms(null); return; }
|
||||
let alive = true;
|
||||
void api.realmProfiles(server.id).then((r) => {
|
||||
if (!alive) return;
|
||||
const name = (m: "coa" | "wildcard" | "reborn") => (m === "coa" ? "Conquest of Azeroth" : m === "reborn" ? "Warcraft Reborn" : "Wildcard");
|
||||
setRealms({ first: name(r.active), second: name(r.active === "coa" ? "wildcard" : "coa") });
|
||||
setRealms({ first: name(r.active), second: name(r.active === "coa" ? "wildcard" : "coa"), reborn: name("reborn") });
|
||||
}).catch(() => { if (alive) setRealms(null); });
|
||||
return () => { alive = false; };
|
||||
}, [bothWorlds, server.id]);
|
||||
@@ -292,8 +292,8 @@ export function Overview({ server, companions = true, onForget, onOpenUpdates, o
|
||||
);
|
||||
}
|
||||
|
||||
const { mysql, auth, world, secondary_world } = status.observed;
|
||||
const all = [mysql, auth, world, ...(secondary_world ? [secondary_world] : [])];
|
||||
const { mysql, auth, world, secondary_world, reborn_world } = status.observed;
|
||||
const all = [mysql, auth, world, ...(secondary_world ? [secondary_world] : []), ...(reborn_world ? [reborn_world] : [])];
|
||||
const running = all.every((s) => s.state === "running");
|
||||
const anyUp = all.some((s) => s.state !== "stopped");
|
||||
const transitioning = action !== null || status.busy || realmBusy;
|
||||
@@ -585,6 +585,28 @@ export function Overview({ server, companions = true, onForget, onOpenUpdates, o
|
||||
</Card>
|
||||
)}
|
||||
|
||||
{reborn_world && (
|
||||
<Card className="mt-4 p-7">
|
||||
<div className="mb-1 text-xs font-medium uppercase tracking-[0.14em] text-muted">{realms ? `${realms.reborn} · ${t("overview.server")}` : t("realm.rebornWorld")}</div>
|
||||
<div
|
||||
className={cn("flex items-center gap-3 text-3xl font-semibold", reborn_world.state === "running" ? "text-ok" : reborn_world.state === "starting" || transitioning ? "text-warn" : "text-muted")}
|
||||
role="status"
|
||||
aria-live="polite"
|
||||
>
|
||||
<span aria-hidden className={cn("h-3 w-3 rounded-full", reborn_world.state === "running" ? "bg-ok" : reborn_world.state === "starting" || transitioning ? "bg-warn" : "bg-muted/50")} />
|
||||
{reborn_world.state === "running" ? t("status.online") : reborn_world.state === "starting" ? t("status.starting") : t("status.offline")}
|
||||
</div>
|
||||
<div className="mt-5 divide-y divide-line border-y border-line">
|
||||
<Row label={t("overview.world")} s={reborn_world} />
|
||||
</div>
|
||||
<dl className="mt-4 text-sm">
|
||||
<dt className="text-muted">{t("overview.uptime")}</dt>
|
||||
<dd className="mt-0.5 text-lg">{reborn_world.state === "running" ? formatUptime(reborn_world.uptime_secs) : "—"}</dd>
|
||||
</dl>
|
||||
<p className="mt-3 text-xs text-muted">{t("realm.bothRunning")}</p>
|
||||
</Card>
|
||||
)}
|
||||
|
||||
{conflict && !anyUp && (
|
||||
<Card className="mt-4 border-warn/40 p-4" role="alert">
|
||||
<p className="font-medium text-warn">{t("overview.portTitle")}</p>
|
||||
|
||||
+36
-14
@@ -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<RealmMode, string> = { 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) => (
|
||||
<RealmPublish key={r.localId} localId={r.localId} serverName={several && r.mode !== realms[0].mode ? `${serverName} · ${REALM_LABEL[r.mode]}` : serverName} realmLabel={several ? REALM_LABEL[r.mode] : null} />
|
||||
))}</>;
|
||||
}
|
||||
|
||||
/** 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 (
|
||||
<Card className="mt-6 p-6">
|
||||
<h2 className="font-semibold">{t("registry.title")}</h2>
|
||||
<h2 className="font-semibold">{t("registry.title")}{realmLabel ? ` · ${realmLabel}` : ""}</h2>
|
||||
<p className="mt-1 text-sm text-muted">{t("registry.text")}</p>
|
||||
|
||||
|
||||
{!published && <>
|
||||
<label htmlFor="registry-name" className="mt-4 block text-sm font-medium">{t("registry.name")}</label>
|
||||
<input id="registry-name" value={name} maxLength={80} onChange={(e) => setName(e.target.value)} className="mt-1 w-full rounded-md border border-line bg-card px-3 py-2" />
|
||||
<label htmlFor="registry-description" className="mt-3 block text-sm font-medium">{t("registry.description")}</label>
|
||||
<textarea id="registry-description" value={description} rows={3} onChange={(e) => setDescription(e.target.value)} className="mt-1 w-full rounded-md border border-line bg-card px-3 py-2" />
|
||||
<label htmlFor={`registry-name-${localId}`} className="mt-4 block text-sm font-medium">{t("registry.name")}</label>
|
||||
<input id={`registry-name-${localId}`} value={name} maxLength={80} onChange={(e) => setName(e.target.value)} className="mt-1 w-full rounded-md border border-line bg-card px-3 py-2" />
|
||||
<label htmlFor={`registry-description-${localId}`} className="mt-3 block text-sm font-medium">{t("registry.description")}</label>
|
||||
<textarea id={`registry-description-${localId}`} value={description} rows={3} onChange={(e) => setDescription(e.target.value)} className="mt-1 w-full rounded-md border border-line bg-card px-3 py-2" />
|
||||
<p className="mt-1 text-xs text-muted">{t("registry.descriptionHint")}</p>
|
||||
<label htmlFor="registry-language" className="mt-3 block text-sm font-medium">{t("registry.language")}</label>
|
||||
<select id="registry-language" value={language} onChange={(e) => setLanguage(e.target.value)} className="mt-1 rounded-md border border-line bg-card px-3 py-2">
|
||||
<label htmlFor={`registry-language-${localId}`} className="mt-3 block text-sm font-medium">{t("registry.language")}</label>
|
||||
<select id={`registry-language-${localId}`} value={language} onChange={(e) => setLanguage(e.target.value)} className="mt-1 rounded-md border border-line bg-card px-3 py-2">
|
||||
{LANGUAGES.map((l) => <option key={l} value={l}>{l}</option>)}
|
||||
</select>
|
||||
<label htmlFor="registry-region" className="mt-3 block text-sm font-medium">{t("registry.region")}</label>
|
||||
<input id="registry-region" value={region} maxLength={16} placeholder="EU" onChange={(e) => setRegion(e.target.value)} className="mt-1 w-32 rounded-md border border-line bg-card px-3 py-2" />
|
||||
<label htmlFor={`registry-region-${localId}`} className="mt-3 block text-sm font-medium">{t("registry.region")}</label>
|
||||
<input id={`registry-region-${localId}`} value={region} maxLength={16} placeholder="EU" onChange={(e) => setRegion(e.target.value)} className="mt-1 w-32 rounded-md border border-line bg-card px-3 py-2" />
|
||||
<div className="mt-4">
|
||||
<Button variant="primary" disabled={busy || !status?.url || name.trim() === ""} onClick={() => void run(() => realmRegistry.publish(localId, name, description, language, region.trim() === "" ? null : region.trim()))}>
|
||||
{busy && <Loader2 className="h-4 w-4 animate-spin" aria-hidden />}{t("registry.publish")}
|
||||
@@ -97,8 +119,8 @@ export function PublishCard({ serverId, serverName }: { serverId: string; server
|
||||
<p className="mt-1 text-xs text-muted">{t("access.text")}</p>
|
||||
<label className="mt-3 flex items-start gap-2"><input type="checkbox" checked={existingOnly} onChange={(e) => setExistingOnly(e.target.checked)} className="mt-1" data-testid="existing-only" /><span>{t("access.existingOnly")}<span className="block text-xs text-muted">{t("access.existingOnlyHint")}</span></span></label>
|
||||
<label className="mt-3 flex items-start gap-2"><input type="checkbox" checked={allowPortable} onChange={(e) => setAllowPortable(e.target.checked)} className="mt-1" data-testid="allow-portable" /><span>{t("access.allowPortable")}<span className="block text-xs text-muted">{t("access.allowPortableHint")}</span></span></label>
|
||||
<label htmlFor="access-route" className="mt-3 block font-medium">{t("access.route")}</label>
|
||||
<input id="access-route" value={route} placeholder="play.example.org:3724" onChange={(e) => setRoute(e.target.value)} className="mt-1 w-full rounded-md border border-line bg-card px-3 py-2" data-testid="access-route" />
|
||||
<label htmlFor={`access-route-${localId}`} className="mt-3 block font-medium">{t("access.route")}</label>
|
||||
<input id={`access-route-${localId}`} value={route} placeholder="play.example.org:3724" onChange={(e) => setRoute(e.target.value)} className="mt-1 w-full rounded-md border border-line bg-card px-3 py-2" data-testid={`access-route-${localId}`} />
|
||||
<p className="mt-1 text-xs text-muted">{t("access.routeHint")}</p>
|
||||
<div className="mt-3 flex items-center gap-3">
|
||||
<Button size="sm" disabled={busy} onClick={() => void saveAccess()}>{t("access.save")}</Button>
|
||||
|
||||
@@ -13,6 +13,8 @@ export function RealmPicker({ serverId, running, disabled, onChanged, onBusy }:
|
||||
const [selected, setSelected] = useState<RealmMode>("coa");
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
// More than one world starts together: the main realm cannot be switched then.
|
||||
const together = !!view && (view.simultaneous || view.with_reborn);
|
||||
useEffect(() => {
|
||||
let alive = true;
|
||||
void api.realmProfiles(serverId).then(v => { if (alive) { setView(v); setSelected(v.active); } }).catch(e => { if (alive) setError(asUiError(e).technical); });
|
||||
@@ -34,18 +36,18 @@ export function RealmPicker({ serverId, running, disabled, onChanged, onBusy }:
|
||||
<div className="flex flex-wrap items-center gap-3">
|
||||
<Layers className="h-5 w-5 text-gold" aria-hidden />
|
||||
<label htmlFor="realm-profile" className="font-medium">{t("realm.profileLabel")}</label>
|
||||
{view?.simultaneous ? <span className="text-sm text-muted">Conquest of Azeroth + Wildcard</span> : <select id="realm-profile" value={selected} disabled={!view || disabled || busy} onChange={e => setSelected(e.target.value as RealmMode)} className="min-w-52 rounded-md border border-line bg-card-2 px-3 py-2 text-ink">
|
||||
{together ? <span className="text-sm text-muted">{[view.active, ...(view.simultaneous ? [view.active === "coa" ? "wildcard" : "coa"] : []), ...(view.with_reborn ? ["reborn"] : [])].map(m => m === "coa" ? "Conquest of Azeroth" : m === "reborn" ? "Warcraft Reborn" : "Wildcard").join(" + ")}</span> : <select id="realm-profile" value={selected} disabled={!view || disabled || busy} onChange={e => setSelected(e.target.value as RealmMode)} className="min-w-52 rounded-md border border-line bg-card-2 px-3 py-2 text-ink">
|
||||
<option value="coa">Conquest of Azeroth</option>
|
||||
<option value="wildcard" disabled={!view?.supported && !view?.wildcard_created}>Wildcard · Darkmoon</option>
|
||||
<option value="reborn" disabled={!view?.reborn_supported && !view?.reborn_created}>Warcraft Reborn</option>
|
||||
</select>}
|
||||
{view && !view.simultaneous && (selected !== view.active || view.recovery_pending) && <Button size="sm" disabled={disabled || busy} onClick={() => void select()}>
|
||||
{view && !together && (selected !== view.active || view.recovery_pending) && <Button size="sm" disabled={disabled || busy} onClick={() => void select()}>
|
||||
{busy && <Loader2 className="h-4 w-4 animate-spin" aria-hidden />}
|
||||
{busy ? t("realm.switching") : selected === "wildcard" && !view.wildcard_created ? t("realm.create") : selected === "reborn" && !view.reborn_created ? t("realm.rebornCreate") : running ? t("realm.restart") : t("realm.select")}
|
||||
</Button>}
|
||||
{view && !view.simultaneous && <span className="ml-auto text-xs text-muted">{t("realm.active", { name: view.active === "coa" ? "CoA" : view.active === "reborn" ? "Warcraft Reborn" : "Wildcard" })}</span>}
|
||||
{view && !together && <span className="ml-auto text-xs text-muted">{t("realm.active", { name: view.active === "coa" ? "CoA" : view.active === "reborn" ? "Warcraft Reborn" : "Wildcard" })}</span>}
|
||||
</div>
|
||||
<p className="mt-3 text-sm text-muted">{t(view?.simultaneous ? "realm.bothRunning" : "realm.separate")}</p>
|
||||
<p className="mt-3 text-sm text-muted">{t(together ? "realm.bothRunning" : "realm.separate")}</p>
|
||||
{selected === "reborn" && <p className="mt-2 text-sm text-warn">{t("realm.rebornModules")}</p>}
|
||||
{view && selected === "reborn" && !view.reborn_supported && <p className="mt-2 text-sm text-warn">{t("realm.rebornUpdate")}</p>}
|
||||
{selected === "wildcard" && <p className="mt-2 text-sm text-warn">{t("realm.modules")}</p>}
|
||||
|
||||
@@ -13,20 +13,27 @@ export function RealmStartupSettings({ serverId }: { serverId: string }) {
|
||||
void api.realmProfiles(serverId).then(v => { if (alive) setView(v); }).catch(e => { if (alive) setError(asUiError(e).technical); });
|
||||
return () => { alive = false; };
|
||||
}, [serverId]);
|
||||
async function change(enabled: boolean) {
|
||||
async function change(realm: "wildcard" | "reborn", enabled: boolean) {
|
||||
setBusy(true); setError(null);
|
||||
try { setView(await api.realmSimultaneous(serverId, enabled)); }
|
||||
try { setView(await (realm === "wildcard" ? api.realmSimultaneous : api.realmWithReborn)(serverId, enabled)); }
|
||||
catch (e) { setError(asUiError(e).technical); }
|
||||
finally { setBusy(false); }
|
||||
}
|
||||
return <Card className="mt-6 p-6" aria-busy={busy}>
|
||||
<h2 className="font-semibold">{t("realm.startupTitle")}</h2>
|
||||
<label className="mt-3 flex items-center gap-3">
|
||||
<input type="checkbox" checked={view?.simultaneous ?? false} disabled={!view || busy || !view.supported || view.active === "reborn"} onChange={e => void change(e.target.checked)} />
|
||||
<input type="checkbox" checked={view?.simultaneous ?? false} disabled={!view || busy || !view.supported || view.active === "reborn"} onChange={e => void change("wildcard", e.target.checked)} />
|
||||
<span>{t("realm.simultaneous")}</span>
|
||||
</label>
|
||||
<p className="mt-2 text-sm text-muted">{t("realm.simultaneousHint")}</p>
|
||||
{view?.simultaneous && <p className="mt-2 text-sm text-muted">{t("realm.secondPort", { port: view.secondary_world_port ?? "—" })}</p>}
|
||||
{view?.simultaneous && <p className="mt-1 text-sm text-muted">{t("realm.secondPort", { port: view.secondary_world_port ?? "—" })}</p>}
|
||||
<label className="mt-3 flex items-center gap-3">
|
||||
<input type="checkbox" checked={view?.with_reborn ?? false} disabled={!view || busy || !view.reborn_supported || view.active !== "coa"} onChange={e => void change("reborn", e.target.checked)} />
|
||||
<span>{t("realm.withReborn")}</span>
|
||||
</label>
|
||||
{view?.with_reborn && <p className="mt-1 text-sm text-muted">{t("realm.rebornPort", { port: view.reborn_world_port ?? "—" })}</p>}
|
||||
{view && view.active !== "coa" && !view.with_reborn && <p className="mt-1 text-sm text-warn">{t("realm.rebornNeedsCoa")}</p>}
|
||||
{view?.simultaneous && view.with_reborn && <p className="mt-3 text-sm">{t("realm.allThree")}</p>}
|
||||
<p className="mt-3 text-sm text-muted">{t("realm.simultaneousHint")}</p>
|
||||
{busy && <p className="mt-2 text-sm" role="status">{t("realm.preparing")}</p>}
|
||||
{error && <p className="mt-3 text-sm text-bad" role="alert">{error}</p>}
|
||||
</Card>;
|
||||
|
||||
@@ -15,7 +15,7 @@ export function RemoveServerCard({ serverId, path, onForget }: { serverId: strin
|
||||
let active = true;
|
||||
void api.status(serverId).then((s) => {
|
||||
if (!active) return;
|
||||
const all = [s.observed.mysql, s.observed.auth, s.observed.world, ...(s.observed.secondary_world ? [s.observed.secondary_world] : [])];
|
||||
const all = [s.observed.mysql, s.observed.auth, s.observed.world, ...(s.observed.secondary_world ? [s.observed.secondary_world] : []), ...(s.observed.reborn_world ? [s.observed.reborn_world] : [])];
|
||||
setRunning(all.some((x) => x.state === "running" || x.state === "starting" || x.state === "stopping"));
|
||||
}).catch(() => { /* an unreadable status must not hide the button */ });
|
||||
return () => { active = false; };
|
||||
|
||||
Reference in new issue
Block a user