mirror of
https://github.com/Corfirean/coa-server-manager.git
synced 2026-11-19 19:25:56 +00:00
Phase 12: Coordinator deployment files, join/claim commands and UI, access options for published realms
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
71e1488336
commit
2caa687490
18 files changed
+856
-8
No files matched your search
@@ -7,6 +7,8 @@ import { asUiError } from "@/lib/api";
|
||||
import { realmRegistry, useRegistryStatus } from "@/lib/registry";
|
||||
import { asPortableError, portable, usePortable, type PreflightView } from "@/lib/portable";
|
||||
import { Notes, Projection } from "@/screens/PortablePage";
|
||||
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";
|
||||
|
||||
const VISIBLE_MODULES = 3;
|
||||
@@ -65,7 +67,7 @@ function SortHeader({ id, sort, order, onSort, children, className }: { id: Sort
|
||||
|
||||
function Drawer({ summary, catalog, onClose }: { summary: RealmSummary; catalog: Catalog; onClose: () => void }) {
|
||||
const { t } = useI18n();
|
||||
const { state } = usePortable();
|
||||
const { state, refresh: refreshPortable } = usePortable();
|
||||
const [detail, setDetail] = useState<RealmDetail | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [character, setCharacter] = useState("");
|
||||
@@ -140,10 +142,9 @@ function Drawer({ summary, catalog, onClose }: { summary: RealmSummary; catalog:
|
||||
</div>}
|
||||
</>}
|
||||
</section>
|
||||
</div>
|
||||
<div className="border-t border-line p-5">
|
||||
<Button variant="primary" className="w-full" disabled>{t("browse.play")}</Button>
|
||||
<p className="mt-2 text-xs text-muted">{t("browse.playSoon")}</p>
|
||||
<section>
|
||||
<JoinPanel realm={summary.realm_id} character={character} automatic={summary.account_provisioning.automatic} onClaimed={() => void refreshPortable()} />
|
||||
</section>
|
||||
</div>
|
||||
</aside>;
|
||||
}
|
||||
@@ -166,8 +167,12 @@ export function BrowsePage() {
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [selected, setSelected] = useState<RealmSummary | null>(null);
|
||||
const [catalog, setCatalog] = useState<Catalog>({});
|
||||
const [preferred, setPreferred] = useState("");
|
||||
const [preferredSaved, setPreferredSaved] = useState("");
|
||||
const [preferredNote, setPreferredNote] = useState<string | null>(null);
|
||||
const ticket = useRef(0);
|
||||
|
||||
useEffect(() => { void control.status().then((c) => { setPreferred(c.preferred_username); setPreferredSaved(c.preferred_username); }).catch(() => {}); }, []);
|
||||
useEffect(() => { void browse.modules().then((m) => setCatalog(Object.fromEntries(m.map((x) => [x.id, x])))).catch(() => {}); }, []);
|
||||
useEffect(() => { if (status?.url && url === "") setUrl(status.url); }, [status?.url]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||
|
||||
@@ -225,6 +230,13 @@ export function BrowsePage() {
|
||||
<Button size="sm" disabled={url.trim() === (status?.url ?? "")} onClick={() => void realmRegistry.setUrl(url.trim() || null).then(refresh).catch((e) => setError(asUiError(e).technical))}>{t("registry.urlSave")}</Button>
|
||||
</div>
|
||||
{noUrl && <p className="mt-2 text-sm text-muted">{t("browse.noUrl")}</p>}
|
||||
<div className="mt-2 flex items-center gap-2 text-sm">
|
||||
<label htmlFor="preferred-name" className="shrink-0 text-muted">{t("join.preferred")}</label>
|
||||
<input id="preferred-name" value={preferred} maxLength={16} placeholder="PLAYER" onChange={(e) => { setPreferred(e.target.value); setPreferredNote(null); }} className="w-44 rounded-md border border-line bg-card px-3 py-1.5" data-testid="preferred-name" />
|
||||
<Button size="sm" disabled={preferred.trim() === preferredSaved} onClick={() => void control.setPreferredUsername(preferred).then((n) => { setPreferred(n); setPreferredSaved(n); setPreferredNote(t("join.preferredSaved")); }).catch((e) => setError(asControlError(e).message))}>{t("registry.urlSave")}</Button>
|
||||
{preferredNote && <span className="text-xs text-ok" role="status">{preferredNote}</span>}
|
||||
</div>
|
||||
<p className="mt-1 text-xs text-muted">{t("join.preferredHint")}</p>
|
||||
|
||||
<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" />
|
||||
|
||||
@@ -0,0 +1,156 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { Check, Copy, Eye, EyeOff, Loader2 } from "lucide-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { useI18n, type Key } from "@/i18n";
|
||||
import { asControlError, control, type AccountView, type Credentials, type JoinOutcome, type RemoteCharacter } from "@/lib/control";
|
||||
import { Notes } from "@/screens/PortablePage";
|
||||
|
||||
const STATUS_TEXT: Record<string, Key> = {
|
||||
launched: "join.status.launched",
|
||||
ready: "join.status.ready",
|
||||
needs_relay: "join.status.needsRelay",
|
||||
needs_client: "join.status.needsClient",
|
||||
needs_transfer: "join.status.needsTransfer",
|
||||
incompatible: "join.status.incompatible",
|
||||
needs_link: "join.status.needsLink",
|
||||
};
|
||||
|
||||
function ErrorLine({ code, message }: { code: string; message: string }) {
|
||||
const { t } = useI18n();
|
||||
const key = `join.err.${code}` as Key;
|
||||
const known = t(key) !== key;
|
||||
return <p className="mt-2 text-sm text-bad" role="alert" data-code={code}>{known ? t(key) : message}</p>;
|
||||
}
|
||||
|
||||
/** The player's account on one server: shown as a name; the password appears only when asked for and goes to the clipboard, never to the screen by default. */
|
||||
function AccountBox({ realm, account, onForget }: { realm: string; account: AccountView; onForget: () => void }) {
|
||||
const { t } = useI18n();
|
||||
const [creds, setCreds] = useState<Credentials | null>(null);
|
||||
const [shown, setShown] = useState(false);
|
||||
const [copied, setCopied] = useState<"name" | "password" | null>(null);
|
||||
useEffect(() => { setCreds(null); setShown(false); }, [realm, account.username]);
|
||||
async function load(): Promise<Credentials | null> {
|
||||
if (creds) return creds;
|
||||
const c = await control.credentials(realm);
|
||||
setCreds(c);
|
||||
return c;
|
||||
}
|
||||
async function copy(what: "name" | "password") {
|
||||
const c = await load();
|
||||
if (!c) return;
|
||||
try { await navigator.clipboard.writeText(what === "name" ? c.username : c.password); setCopied(what); setTimeout(() => setCopied(null), 4000); } catch { /* the clipboard is not available */ }
|
||||
}
|
||||
return <div className="rounded-md border border-line p-3" data-testid="account-box">
|
||||
<p className="text-xs uppercase tracking-wide text-muted">{t("join.account")}</p>
|
||||
<p className="mt-1 flex items-center gap-2 font-mono text-base" data-testid="account-name">{account.username}
|
||||
<button aria-label={t("join.copyName")} onClick={() => void copy("name")} className="cursor-pointer text-muted hover:text-ink">{copied === "name" ? <Check className="h-4 w-4 text-ok" /> : <Copy className="h-4 w-4" />}</button>
|
||||
</p>
|
||||
<div className="mt-2 flex flex-wrap items-center gap-2">
|
||||
<Button size="sm" onClick={() => void copy("password")}>{copied === "password" ? <Check className="h-4 w-4 text-ok" aria-hidden /> : <Copy className="h-4 w-4" aria-hidden />}{copied === "password" ? t("join.copied") : t("join.copyPassword")}</Button>
|
||||
<Button size="sm" variant="ghost" onClick={() => void load().then(() => setShown((s) => !s))}>{shown ? <EyeOff className="h-4 w-4" aria-hidden /> : <Eye className="h-4 w-4" aria-hidden />}{shown ? t("join.hide") : t("join.show")}</Button>
|
||||
<Button size="sm" variant="ghost" onClick={onForget}>{t("join.forget")}</Button>
|
||||
</div>
|
||||
{shown && creds && <p className="mt-2 break-all font-mono text-sm" data-testid="account-password">{creds.password}</p>}
|
||||
<p className="mt-2 text-xs text-muted">{t("join.accountHint")}</p>
|
||||
</div>;
|
||||
}
|
||||
|
||||
function LinkForm({ realm, onLinked }: { realm: string; onLinked: () => void }) {
|
||||
const { t } = useI18n();
|
||||
const [login, setLogin] = useState("");
|
||||
const [password, setPassword] = useState("");
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [err, setErr] = useState<{ code: string; message: string } | null>(null);
|
||||
async function submit() {
|
||||
setBusy(true); setErr(null);
|
||||
try { await control.link(realm, login.trim(), password); setPassword(""); onLinked(); } catch (e) { setErr(asControlError(e)); } finally { setBusy(false); }
|
||||
}
|
||||
return <form className="rounded-md border border-line p-3" onSubmit={(e) => { e.preventDefault(); void submit(); }}>
|
||||
<p className="text-sm font-medium">{t("join.link.title")}</p>
|
||||
<p className="mt-1 text-xs text-muted">{t("join.link.text")}</p>
|
||||
<label htmlFor="link-login" className="mt-3 block text-sm">{t("join.link.login")}</label>
|
||||
<input id="link-login" value={login} autoComplete="off" onChange={(e) => setLogin(e.target.value)} className="mt-1 w-full rounded-md border border-line bg-card px-3 py-2" />
|
||||
<label htmlFor="link-password" className="mt-3 block text-sm">{t("join.link.password")}</label>
|
||||
<input id="link-password" type="password" value={password} autoComplete="off" onChange={(e) => setPassword(e.target.value)} className="mt-1 w-full rounded-md border border-line bg-card px-3 py-2" />
|
||||
<Button type="submit" className="mt-3" disabled={busy || login.trim() === "" || password === ""}>{busy && <Loader2 className="h-4 w-4 animate-spin" aria-hidden />}{t("join.link.submit")}</Button>
|
||||
{err && <ErrorLine code={err.code} message={err.message} />}
|
||||
</form>;
|
||||
}
|
||||
|
||||
const CLASS_NAMES: Record<number, string> = { 1: "Warrior", 2: "Paladin", 3: "Hunter", 4: "Rogue", 5: "Priest", 6: "Death Knight", 7: "Shaman", 8: "Mage", 9: "Warlock", 11: "Druid" };
|
||||
|
||||
function ServerCharacters({ realm, onClaimed }: { realm: string; onClaimed: () => void }) {
|
||||
const { t } = useI18n();
|
||||
const [list, setList] = useState<RemoteCharacter[] | null>(null);
|
||||
const [busy, setBusy] = useState<string | null>(null);
|
||||
const [err, setErr] = useState<{ code: string; message: string } | null>(null);
|
||||
const [done, setDone] = useState<string | null>(null);
|
||||
async function load() {
|
||||
setBusy("*"); setErr(null);
|
||||
try { setList(await control.characters(realm)); } catch (e) { setErr(asControlError(e)); setList(null); } finally { setBusy(null); }
|
||||
}
|
||||
async function claim(name: string) {
|
||||
setBusy(name); setErr(null); setDone(null);
|
||||
try { const c = await control.claim(realm, name); setDone(t("join.chars.done", { name: c.name, revision: c.revision })); onClaimed(); await load(); } catch (e) { setErr(asControlError(e)); } finally { setBusy(null); }
|
||||
}
|
||||
return <section data-testid="server-characters">
|
||||
<h3 className="mb-1 font-medium">{t("join.chars.title")}</h3>
|
||||
<p className="text-xs text-muted">{t("join.chars.text")}</p>
|
||||
<Button size="sm" className="mt-2" onClick={() => void load()} disabled={busy !== null}>{busy === "*" && <Loader2 className="h-4 w-4 animate-spin" aria-hidden />}{t("join.chars.show")}</Button>
|
||||
{list && list.length === 0 && <p className="mt-2 text-sm text-muted">{t("join.chars.none")}</p>}
|
||||
{list && list.length > 0 && <ul className="mt-2 space-y-2">
|
||||
{list.map((c) => <li key={c.name} className="flex items-center justify-between gap-3 rounded-md border border-line p-2">
|
||||
<span><span className="font-medium">{c.name}</span><span className="text-muted"> — {CLASS_NAMES[c.class] ?? `#${c.class}`}, {t("portable.level", { level: c.level })}</span>
|
||||
{!c.eligible && <span className="block text-xs text-warn">{t("join.chars.notEligible")} ({c.reasons.join(", ")})</span>}</span>
|
||||
{c.yours ? <span className="text-xs text-ok">{t("join.chars.portable")}</span>
|
||||
: <Button size="sm" disabled={!c.eligible || busy !== null} onClick={() => void claim(c.name)}>{busy === c.name && <Loader2 className="h-4 w-4 animate-spin" aria-hidden />}{t("join.chars.make")}</Button>}
|
||||
</li>)}
|
||||
</ul>}
|
||||
{done && <p className="mt-2 text-sm text-ok" role="status">{done}</p>}
|
||||
{err && <ErrorLine code={err.code} message={err.message} />}
|
||||
</section>;
|
||||
}
|
||||
|
||||
/** Joining one server: the account, the game, the character-claim and the honest "not yet" cases. */
|
||||
export function JoinPanel({ realm, character, automatic, onClaimed }: { realm: string; character: string; automatic: boolean; onClaimed: () => void }) {
|
||||
const { t } = useI18n();
|
||||
const [account, setAccount] = useState<AccountView | null>(null);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [outcome, setOutcome] = useState<JoinOutcome | null>(null);
|
||||
const [err, setErr] = useState<{ code: string; message: string } | null>(null);
|
||||
const [linking, setLinking] = useState(false);
|
||||
const [bring, setBring] = useState(false);
|
||||
const refresh = () => control.account(realm).then(setAccount).catch(() => setAccount(null));
|
||||
useEffect(() => { setOutcome(null); setErr(null); setLinking(false); void refresh(); }, [realm]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||
|
||||
async function join() {
|
||||
setBusy(true); setErr(null); setOutcome(null);
|
||||
try {
|
||||
const o = await control.join(realm, bring && character ? character : null, true);
|
||||
setOutcome(o);
|
||||
if (o.status === "needs_link") setLinking(true);
|
||||
await refresh();
|
||||
} catch (e) { setErr(asControlError(e)); } finally { setBusy(false); }
|
||||
}
|
||||
|
||||
const text = outcome ? STATUS_TEXT[outcome.status] : undefined;
|
||||
const bad = outcome && ["incompatible", "needs_relay", "needs_client", "needs_transfer", "needs_link"].includes(outcome.status);
|
||||
return <div className="space-y-4">
|
||||
{account && <AccountBox realm={realm} account={account} onForget={() => void control.forget(realm).then(() => { setAccount(null); setOutcome(null); })} />}
|
||||
{(linking || (!account && !automatic)) && <LinkForm realm={realm} onLinked={() => { setLinking(false); void refresh(); setOutcome(null); }} />}
|
||||
<div>
|
||||
{character && <label className="mb-2 flex items-start gap-2 text-sm"><input type="checkbox" checked={bring} onChange={(e) => setBring(e.target.checked)} className="mt-1" data-testid="bring-character" /><span>{t("join.bring")}<span className="block text-xs text-muted">{t("join.bringHint")}</span></span></label>}
|
||||
<Button variant="primary" className="w-full" disabled={busy} onClick={() => void join()} data-testid="join-button">{busy && <Loader2 className="h-4 w-4 animate-spin" aria-hidden />}{t("join.button")}</Button>
|
||||
{!account && automatic && !linking && <button className="mt-2 cursor-pointer text-xs text-muted underline hover:text-ink" onClick={() => setLinking(true)}>{t("join.haveAccount")}</button>}
|
||||
{outcome && text && <div className={cn("mt-3 rounded-md border p-3 text-sm", bad ? "border-warn/50 bg-warn/10" : "border-ok/40 bg-ok/10")} role="status" data-status={outcome.status}>
|
||||
<p>{t(text)}</p>
|
||||
{outcome.account_created && <p className="mt-1 text-xs text-muted">{t("join.created", { name: outcome.username ?? "" })}</p>}
|
||||
{outcome.password_reset && <p className="mt-1 text-xs text-muted">{t("join.reset")}</p>}
|
||||
{outcome.notes.length > 0 && <Notes notes={outcome.notes} />}
|
||||
</div>}
|
||||
{err && <ErrorLine code={err.code} message={err.message} />}
|
||||
</div>
|
||||
<ServerCharacters realm={realm} onClaimed={onClaimed} />
|
||||
</div>;
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import { cn } from "@/lib/utils";
|
||||
import { useT, type Key } from "@/i18n";
|
||||
import { asUiError } 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"];
|
||||
|
||||
@@ -23,6 +24,24 @@ 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 [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;
|
||||
|
||||
useEffect(() => {
|
||||
const load = () => void control.status().then(setCtl).catch(() => {});
|
||||
load();
|
||||
const timer = setInterval(load, 3000);
|
||||
return () => clearInterval(timer);
|
||||
}, []);
|
||||
useEffect(() => { if (mine) { setExistingOnly(mine.existing_only); setRoute(mine.route ?? ""); } }, [mine?.existing_only, 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); }
|
||||
}
|
||||
|
||||
useEffect(() => { if (status && status.url !== null) setUrl((u) => (u === "" ? status.url ?? "" : u)); }, [status?.url]);
|
||||
useEffect(() => {
|
||||
@@ -78,6 +97,22 @@ export function PublishCard({ serverId, serverName }: { serverId: string; server
|
||||
<Button size="sm" disabled={busy} onClick={() => void run(() => realmRegistry.unpublish(localId))}>{t("registry.stop")}</Button>
|
||||
</div>
|
||||
</div>}
|
||||
{mine && (published || mine.state === "unpublishing") && <div className="mt-4 rounded-md border border-line p-3 text-sm" data-testid="access-options">
|
||||
<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 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>
|
||||
<div className="mt-3 flex items-center gap-3">
|
||||
<Button size="sm" disabled={busy} onClick={() => void saveAccess()}>{t("access.save")}</Button>
|
||||
{accessSaved && <span className="text-xs text-ok" role="status">{t("access.saved")}</span>}
|
||||
</div>
|
||||
<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>
|
||||
{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>}
|
||||
</Card>
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user