Integrate isolated rulesets, portable admission, and compatible relay authentication

This commit is contained in:
Дмитрий committed 2026-10-24 06:04:26 +05:00
commit d5f1e9cc83
112 files changed
+5892 -965

No files matched your search

+39 -11
View File
@@ -7,6 +7,7 @@ import { asUiError } from "@/lib/api";
import { useRegistryStatus } from "@/lib/registry";
import { asPortableError, portable, usePortable, type PreflightView } from "@/lib/portable";
import { Notes, Projection } from "@/screens/PortablePage";
import { RulesetBadge, formatRulesetLabel } from "@/components/RulesetBadge";
import { JoinPanel } from "@/screens/JoinPanel";
import { asControlError, control } from "@/lib/control";
import { browse, rate, type BrowseParams, type ModuleEntry, type ModuleInfo, type RealmDetail, type RealmSummary, type SortKey } from "@/lib/browse";
@@ -50,7 +51,7 @@ function Online({ p }: { p: RealmSummary["population"] }) {
}
function Mode({ ruleset }: { ruleset: string }) {
return <span>{ruleset === "wildcard" ? "Wildcard" : "CoA"}</span>;
return <RulesetBadge ruleset={ruleset} size="sm" />;
}
function compactRates(r: RealmSummary["rates"], t: (k: Key, v?: Record<string, string | number>) => string): string {
@@ -67,7 +68,7 @@ function SortHeader({ id, sort, order, onSort, children, className }: { id: Sort
}
function Drawer({ summary, catalog, onClose }: { summary: RealmSummary; catalog: Catalog; onClose: () => void }) {
const { t, locale } = useI18n();
const { t, tn, locale } = useI18n();
const { state, refresh: refreshPortable } = usePortable();
const [detail, setDetail] = useState<RealmDetail | null>(null);
const [error, setError] = useState<string | null>(null);
@@ -75,6 +76,11 @@ function Drawer({ summary, catalog, onClose }: { summary: RealmSummary; catalog:
const [pre, setPre] = useState<PreflightView | null>(null);
const [preError, setPreError] = useState<string | null>(null);
const characters = state?.characters ?? [];
const matchingCharacters = useMemo(
() => characters.filter((c) => c.ruleset === summary.ruleset),
[characters, summary.ruleset]
);
const hiddenCount = characters.length - matchingCharacters.length;
useEffect(() => {
let alive = true;
@@ -82,7 +88,13 @@ function Drawer({ summary, catalog, onClose }: { summary: RealmSummary; catalog:
void browse.detail(summary.realm_id).then((d) => { if (alive) setDetail(d); }).catch((e) => { if (alive) setError(asUiError(e).technical); });
return () => { alive = false; };
}, [summary.realm_id]);
useEffect(() => { if (!character && characters.length > 0) setCharacter(characters[0].id); }, [characters.length]); // eslint-disable-line react-hooks/exhaustive-deps
useEffect(() => {
if ((!character || !matchingCharacters.some((c) => c.id === character)) && matchingCharacters.length > 0) {
setCharacter(matchingCharacters[0].id);
} else if (matchingCharacters.length === 0) {
setCharacter("");
}
}, [matchingCharacters, character]);
useEffect(() => {
if (!character || !detail) { setPre(null); return; }
let alive = true;
@@ -142,11 +154,27 @@ function Drawer({ summary, catalog, onClose }: { summary: RealmSummary; catalog:
<h3 className="mb-1 font-medium">{t("browse.compat")}</h3>
{error && <p className="text-bad" role="alert">{error}</p>}
{!error && !d && <p className="flex items-center gap-2 text-muted"><Loader2 className="h-4 w-4 animate-spin" aria-hidden />{t("portable.make.loading")}</p>}
{characters.length === 0 && <p className="text-muted">{t("browse.noCharacter")}</p>}
{characters.length > 0 && <>
<select aria-label={t("browse.character")} value={character} onChange={(e) => setCharacter(e.target.value)} className="w-full rounded-md border border-line bg-card px-3 py-2">
{characters.map((c) => <option key={c.id} value={c.id}>{c.name} — {c.class_name}, {t("portable.level", { level: c.level })}</option>)}
</select>
{matchingCharacters.length === 0 && (
<div className="space-y-1">
<p className="text-muted">{t("browse.noCharacter")}</p>
{hiddenCount > 0 && (
<p className="text-xs text-muted">
{tn("browse.hidden_characters", hiddenCount)}
</p>
)}
</div>
)}
{matchingCharacters.length > 0 && <>
<div className="space-y-1">
<select aria-label={t("browse.character")} value={character} onChange={(e) => setCharacter(e.target.value)} className="w-full rounded-md border border-line bg-card px-3 py-2">
{matchingCharacters.map((c) => <option key={c.id} value={c.id}>[{formatRulesetLabel(c.ruleset)}] {c.name} — {c.class_name}, {t("portable.level", { level: c.level })}</option>)}
</select>
{hiddenCount > 0 && (
<p className="text-xs text-muted">
{tn("browse.hidden_characters", hiddenCount)}
</p>
)}
</div>
{preError && <p className="mt-2 text-warn">{preError}</p>}
{pre && chosen && <div className={cn("mt-2 rounded-md border p-3", blocked ? "border-bad/50 bg-bad/10" : pre.verdict === "degraded" ? "border-warn/50 bg-warn/10" : "border-ok/40 bg-ok/10")} data-verdict={pre.verdict}>
<p className="font-medium">{blocked ? t("browse.cannotPlay") : t("browse.canPlay")}</p>
@@ -166,7 +194,7 @@ export function BrowsePage() {
const { t } = useI18n();
const { status } = useRegistryStatus(5000);
const [q, setQ] = useState("");
const [ruleset, setRuleset] = useState<"" | "coa" | "wildcard">("");
const [ruleset, setRuleset] = useState<"" | "coa" | "wildcard" | "reborn">("");
const [capMin, setCapMin] = useState("");
const [capMax, setCapMax] = useState("");
const [module, setModule] = useState("");
@@ -247,8 +275,8 @@ export function BrowsePage() {
<div className="mt-4 grid grid-cols-2 gap-3 md:grid-cols-6">
<input aria-label={t("browse.search")} value={q} onChange={(e) => setQ(e.target.value)} placeholder={t("browse.search")} className="col-span-2 rounded-md border border-line bg-card px-3 py-2 text-sm" />
<select aria-label={t("browse.mode")} value={ruleset} onChange={(e) => setRuleset(e.target.value as "" | "coa" | "wildcard")} className="rounded-md border border-line bg-card px-3 py-2 text-sm">
<option value="">{t("browse.mode")}: {t("browse.any")}</option><option value="coa">CoA</option><option value="wildcard">Wildcard</option>
<select aria-label={t("browse.mode")} value={ruleset} onChange={(e) => setRuleset(e.target.value as "" | "coa" | "wildcard" | "reborn")} className="rounded-md border border-line bg-card px-3 py-2 text-sm">
<option value="">{t("browse.mode")}: {t("browse.any")}</option><option value="coa">CoA</option><option value="wildcard">Wildcard</option><option value="reborn">Warcraft Reborn</option>
</select>
<div className="flex items-center gap-1 text-sm"><input aria-label={t("browse.capMin")} inputMode="numeric" value={capMin} onChange={(e) => setCapMin(e.target.value.replace(/\D/g, ""))} placeholder={t("browse.capMin")} className="w-full rounded-md border border-line bg-card px-2 py-2" /><span className="text-muted">–</span><input aria-label={t("browse.capMax")} inputMode="numeric" value={capMax} onChange={(e) => setCapMax(e.target.value.replace(/\D/g, ""))} placeholder={t("browse.capMax")} className="w-full rounded-md border border-line bg-card px-2 py-2" /></div>
<select aria-label={t("browse.module")} value={module} onChange={(e) => setModule(e.target.value)} className="rounded-md border border-line bg-card px-3 py-2 text-sm">
+70 -5
View File
@@ -4,6 +4,8 @@ import { AlertTriangle, CheckCircle2, History, Loader2, Plus, ShieldAlert, Sword
import { useT, type Key } from "@/i18n";
import { Button } from "@/components/ui/button";
import { Card } from "@/components/ui/card";
import { RulesetBadge } from "@/components/RulesetBadge";
import type { Ruleset } from "@/lib/browse";
import { cn } from "@/lib/utils";
import {
asPortableError, portable, usePortable,
@@ -110,7 +112,10 @@ function PlayDialog({ character, realms, initial, onClose, onChanged }: { charac
return <div className="fixed inset-0 z-40 flex items-center justify-center bg-black/60 p-6" role="dialog" aria-modal="true" aria-labelledby="play-title">
<Card className="max-h-full w-full max-w-xl overflow-y-auto p-6">
<div className="flex items-start justify-between">
<h2 id="play-title" className="text-lg font-semibold">{t("portable.play.title", { name: character.name })}</h2>
<div className="flex items-center gap-3">
<h2 id="play-title" className="text-lg font-semibold">{t("portable.play.title", { name: character.name })}</h2>
<RulesetBadge ruleset={character.ruleset} size="sm" />
</div>
<button onClick={onClose} aria-label={t("portable.cancel")} className="cursor-pointer text-muted hover:text-ink"><X className="h-5 w-5" /></button>
</div>
<label className="mt-4 block text-sm font-medium" htmlFor="play-realm">{t("portable.play.realm")}</label>
@@ -218,7 +223,10 @@ function HistoryDialog({ character, onClose }: { character: CharacterView; onClo
return <div className="fixed inset-0 z-40 flex items-center justify-center bg-black/60 p-6" role="dialog" aria-modal="true" aria-labelledby="hist-title">
<Card className="max-h-full w-full max-w-xl overflow-y-auto p-6">
<div className="flex items-start justify-between">
<h2 id="hist-title" className="text-lg font-semibold">{t("portable.history.title", { name: character.name })}</h2>
<div className="flex items-center gap-3">
<h2 id="hist-title" className="text-lg font-semibold">{t("portable.history.title", { name: character.name })}</h2>
<RulesetBadge ruleset={character.ruleset} size="sm" />
</div>
<button onClick={onClose} aria-label={t("portable.close")} className="cursor-pointer text-muted hover:text-ink"><X className="h-5 w-5" /></button>
</div>
{!list && !error && <Loader2 className="mt-4 h-4 w-4 animate-spin" aria-hidden />}
@@ -240,8 +248,13 @@ export function PortablePage({ onOpenSettings }: { onOpenSettings?: () => void }
const [making, setMaking] = useState(false);
const [error, setError] = useState<PortableError | null>(null);
const [copied, setCopied] = useState(false);
const [rulesetFilter, setRulesetFilter] = useState<"" | Ruleset>("");
const realms = state?.realms ?? [];
const characters = state?.characters ?? [];
const filteredCharacters = useMemo(() => {
if (!rulesetFilter) return characters;
return characters.filter((c) => c.ruleset === rulesetFilter);
}, [characters, rulesetFilter]);
const usable = useMemo(() => realms, [realms]);
async function addRealm() {
@@ -294,14 +307,66 @@ export function PortablePage({ onOpenSettings }: { onOpenSettings?: () => void }
<div className="px-5 py-3"><Button size="sm" variant="ghost" onClick={() => void addRealm()}><Plus className="h-4 w-4" aria-hidden />{t("portable.realm.add")}</Button></div>
</Card>
<h2 className="mt-8 text-lg font-semibold">{t("portable.characters.title")}</h2>
<div className="mt-8 flex flex-wrap items-center justify-between gap-3">
<h2 className="text-lg font-semibold">{t("portable.characters.title")}</h2>
<div className="flex rounded-md border border-line bg-card p-0.5 text-xs">
<button
type="button"
onClick={() => setRulesetFilter("")}
className={cn(
"cursor-pointer rounded px-2.5 py-1 font-medium transition-colors",
rulesetFilter === "" ? "bg-white/10 text-ink shadow-sm" : "text-muted hover:text-ink"
)}
>
{t("portable.filter.all")}
</button>
<button
type="button"
onClick={() => setRulesetFilter("coa")}
className={cn(
"cursor-pointer rounded px-2.5 py-1 font-medium transition-colors",
rulesetFilter === "coa" ? "bg-sky-500/20 text-sky-300 shadow-sm" : "text-muted hover:text-ink"
)}
>
Conquest of Azeroth
</button>
<button
type="button"
onClick={() => setRulesetFilter("wildcard")}
className={cn(
"cursor-pointer rounded px-2.5 py-1 font-medium transition-colors",
rulesetFilter === "wildcard" ? "bg-amber-500/20 text-amber-300 shadow-sm" : "text-muted hover:text-ink"
)}
>
Wildcard
</button>
<button
type="button"
onClick={() => setRulesetFilter("reborn")}
className={cn(
"cursor-pointer rounded px-2.5 py-1 font-medium transition-colors",
rulesetFilter === "reborn" ? "bg-emerald-500/20 text-emerald-300 shadow-sm" : "text-muted hover:text-ink"
)}
>
Warcraft Reborn
</button>
</div>
</div>
{characters.length === 0 && <Card className="mt-3 p-5 text-sm text-muted">{t("portable.characters.none")}</Card>}
{characters.length > 0 && filteredCharacters.length === 0 && (
<Card className="mt-3 p-5 text-sm text-muted">
{t("portable.filter.none")}
</Card>
)}
<div className="mt-3 space-y-4">
{characters.map((c) => <Card key={c.id} className="p-5" data-character={c.name}>
{filteredCharacters.map((c) => <Card key={c.id} className="p-5" data-character={c.name}>
<div className="flex flex-wrap items-center gap-3">
<Swords className="h-5 w-5 text-gold" aria-hidden />
<div className="min-w-0 flex-1">
<p className="text-lg font-semibold">{c.name}</p>
<div className="flex items-center gap-2">
<p className="text-lg font-semibold">{c.name}</p>
<RulesetBadge ruleset={c.ruleset} size="sm" />
</div>
<p className="text-sm text-muted">{c.class_name} · {t("portable.level", { level: c.level })} · {t("portable.revision", { n: c.revision })}</p>
<p className="text-xs text-muted">{t("portable.lastSync", { when: when(c.updated_at) })}{c.active_realm ? ` · ${t("portable.activeOn", { realm: c.active_realm })}` : ""}</p>
</div>
+7 -3
View File
@@ -23,11 +23,13 @@ export function PublishCard({ serverId, serverName }: { serverId: string; server
const [region, setRegion] = useState("");
const [busy, setBusy] = useState(false);
const [error, setError] = useState<string | null>(null);
const [allowPortable, setAllowPortable] = useState(false);
const [existingOnly, setExistingOnly] = useState(false);
const [route, setRoute] = useState("");
const [accessSaved, setAccessSaved] = useState(false);
const [ctl, setCtl] = useState<ControlStatus | null>(null);
const link = ctl?.hosting.find((h) => h.local_id === localId)?.link;
const host = ctl?.hosting.find((h) => h.local_id === localId);
const link = host?.link;
useEffect(() => {
const load = () => void control.status().then(setCtl).catch(() => {});
@@ -35,11 +37,11 @@ export function PublishCard({ serverId, serverName }: { serverId: string; server
const timer = setInterval(load, 3000);
return () => clearInterval(timer);
}, []);
useEffect(() => { if (mine) { setExistingOnly(mine.existing_only); setRoute(mine.route ?? ""); } }, [mine?.existing_only, mine?.route]);
useEffect(() => { if (mine) { setExistingOnly(mine.existing_only); setAllowPortable(mine.allow_portable); setRoute(mine.route ?? ""); } }, [mine?.existing_only, mine?.allow_portable, mine?.route]);
async function saveAccess() {
setBusy(true); setError(null); setAccessSaved(false);
try { await control.setAccess(localId, existingOnly, route.trim() === "" ? null : route.trim()); await refresh(); setAccessSaved(true); } catch (e) { setError(asControlError(e).message); } finally { setBusy(false); }
try { await control.setAccess(localId, existingOnly, allowPortable, route.trim() === "" ? null : route.trim()); await refresh(); setAccessSaved(true); } catch (e) { setError(asControlError(e).message); } finally { setBusy(false); }
}
useEffect(() => {
@@ -94,6 +96,7 @@ export function PublishCard({ serverId, serverName }: { serverId: string; server
<p className="font-medium">{t("access.title")}</p>
<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></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" />
<p className="mt-1 text-xs text-muted">{t("access.routeHint")}</p>
@@ -104,6 +107,7 @@ export function PublishCard({ serverId, serverName }: { serverId: string; server
<p className={cn("mt-3 text-xs", link?.connected ? "text-ok" : "text-muted")} data-testid="control-link" data-connected={link?.connected ? "yes" : "no"}>
{link?.connected ? t("access.linkUp") : t("access.linkDown")}{link?.last_error && !link.connected ? ` — ${link.last_error}` : ""}
</p>
<p className={cn("mt-2 text-xs", host?.relay?.connected ? "text-ok" : "text-warn")} data-testid="relay-link">{host?.relay?.connected ? t("access.relayUp") : t("access.relayDown")}{host?.relay?.last_error ? ` — ${host.relay.last_error}` : ""}</p>
{ctl && ctl.secret_store === "file" && <p className="mt-1 text-xs text-warn">{t("access.fileStore")}</p>}
</div>}
{error && <p className="mt-3 text-sm text-bad" role="alert">{error}</p>}