mirror of
https://github.com/Corfirean/coa-server-manager.git
synced 2026-11-18 19:25:56 +00:00
Phase 10: central realm Registry, Host publishing lifecycle, deployment
crates/coa-registry-proto (protocol 1: types, limits, signed-request canonicalisation, test vectors), services/coa-registry (axum + PostgreSQL, migrations, rate limits, Dockerfile, deploy files), services/coa-registry-e2e (Host lifecycle against the real service, live VPS gate), coa-core realm_registry (identity keys, client, publishing loop on its own thread), Settings -> Public listing card, docs REGISTRY_PROTOCOL.md and REGISTRY_DEPLOYMENT.md. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ec40f146aa
commit
1267bcc41e
56 files changed
+10198
-13
No files matched your search
@@ -984,6 +984,28 @@ const en = {
|
||||
"fr.lan.unavailable": "Selected address unavailable",
|
||||
"fr.lan.unavailableText": "The selected address is not currently assigned to a detected local interface. Choose another address or switch to Automatic, or keep this address intentionally.",
|
||||
"fr.lan.invalid": "Invalid IPv4 address",
|
||||
"registry.title": "Public listing",
|
||||
"registry.text": "Publish this realm in the central list so that players can find it. Only its name, description, language, version and capabilities are shared: no passwords, no characters, no accounts. The realm keeps running if the list is unreachable.",
|
||||
"registry.url": "Registry address",
|
||||
"registry.urlSave": "Save address",
|
||||
"registry.name": "Realm name",
|
||||
"registry.description": "Description",
|
||||
"registry.descriptionHint": "Plain text, up to 1000 characters.",
|
||||
"registry.language": "Language",
|
||||
"registry.publish": "Publish this realm",
|
||||
"registry.stop": "Stop publishing",
|
||||
"registry.retry": "Try again",
|
||||
"registry.noUrl": "Enter the Registry address first.",
|
||||
"registry.revision": "listing version {n}",
|
||||
"registry.retryIn": "Next attempt in {s} s.",
|
||||
"registry.state.starting": "Starting to publish…",
|
||||
"registry.state.waiting_for_realm": "Waiting for the realm to be ready…",
|
||||
"registry.state.realm_stopped": "The realm is not running; it is listed as offline.",
|
||||
"registry.state.online": "Published and online.",
|
||||
"registry.state.retrying": "The Registry could not be reached; trying again. Your realm is not affected.",
|
||||
"registry.state.rejected": "The Registry refused this realm. Publishing is stopped.",
|
||||
"registry.state.unpublishing": "Removing the listing…",
|
||||
"registry.state.disabled": "Not published.",
|
||||
} as const;
|
||||
|
||||
export default en;
|
||||
@@ -982,6 +982,28 @@ const ru: Partial<Record<keyof typeof en, string>> = {
|
||||
"fr.lan.unavailable": "Выбранный адрес недоступен",
|
||||
"fr.lan.unavailableText": "Выбранный адрес сейчас не назначен обнаруженному сетевому интерфейсу. Выберите другой адрес, переключитесь на автоматический выбор или намеренно сохраните этот адрес.",
|
||||
"fr.lan.invalid": "Некорректный IPv4-адрес",
|
||||
"registry.title": "Публичный список",
|
||||
"registry.text": "Опубликуйте этот реалм в общем списке, чтобы игроки могли его найти. Передаются только название, описание, язык, версия и возможности реалма: никаких паролей, персонажей и аккаунтов. Если список недоступен, реалм продолжает работать.",
|
||||
"registry.url": "Адрес реестра",
|
||||
"registry.urlSave": "Сохранить адрес",
|
||||
"registry.name": "Название реалма",
|
||||
"registry.description": "Описание",
|
||||
"registry.descriptionHint": "Простой текст, до 1000 символов.",
|
||||
"registry.language": "Язык",
|
||||
"registry.publish": "Опубликовать реалм",
|
||||
"registry.stop": "Снять с публикации",
|
||||
"registry.retry": "Повторить",
|
||||
"registry.noUrl": "Сначала укажите адрес реестра.",
|
||||
"registry.revision": "версия записи {n}",
|
||||
"registry.retryIn": "Следующая попытка через {s} с.",
|
||||
"registry.state.starting": "Начинаю публикацию…",
|
||||
"registry.state.waiting_for_realm": "Жду, пока реалм будет готов…",
|
||||
"registry.state.realm_stopped": "Реалм не запущен; в списке он отмечен как недоступный.",
|
||||
"registry.state.online": "Опубликован и доступен.",
|
||||
"registry.state.retrying": "Реестр недоступен, пробую снова. На ваш реалм это не влияет.",
|
||||
"registry.state.rejected": "Реестр отклонил этот реалм. Публикация остановлена.",
|
||||
"registry.state.unpublishing": "Убираю запись из списка…",
|
||||
"registry.state.disabled": "Не опубликован.",
|
||||
};
|
||||
|
||||
export default ru;
|
||||
@@ -0,0 +1,49 @@
|
||||
import { useCallback, useEffect, useRef, useState } from "react";
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
|
||||
export type PublishState = "starting" | "waiting_for_realm" | "realm_stopped" | "online" | "retrying" | "rejected" | "unpublishing" | "disabled";
|
||||
|
||||
export interface RealmPublishStatus {
|
||||
local_id: string;
|
||||
realm_id: string | null;
|
||||
enabled: boolean;
|
||||
state: PublishState;
|
||||
display_name: string;
|
||||
description: string;
|
||||
language: string;
|
||||
metadata_revision: number | null;
|
||||
last_ok_unix: number | null;
|
||||
last_error: string | null;
|
||||
retry_in_secs: number | null;
|
||||
}
|
||||
|
||||
export interface RegistryStatus {
|
||||
url: string | null;
|
||||
realms: RealmPublishStatus[];
|
||||
}
|
||||
|
||||
export const realmRegistry = {
|
||||
status: () => invoke<RegistryStatus>("registry_status"),
|
||||
setUrl: (url: string | null) => invoke<void>("registry_set_url", { url }),
|
||||
publish: (localId: string, displayName: string, description: string, language: string) =>
|
||||
invoke<void>("registry_publish", { localId, displayName, description, language }),
|
||||
unpublish: (localId: string) => invoke<void>("registry_unpublish", { localId }),
|
||||
retry: (localId: string) => invoke<void>("registry_retry", { localId }),
|
||||
};
|
||||
|
||||
/** The publishing state of this Manager's realms, refreshed while a screen shows it. The loop itself runs without the screen. */
|
||||
export function useRegistryStatus(everyMs = 2000): { status: RegistryStatus | null; refresh: () => Promise<void> } {
|
||||
const [status, setStatus] = useState<RegistryStatus | null>(null);
|
||||
const busy = useRef(false);
|
||||
const refresh = useCallback(async () => {
|
||||
if (busy.current) return;
|
||||
busy.current = true;
|
||||
try { setStatus(await realmRegistry.status()); } catch { /* the service is not available */ } finally { busy.current = false; }
|
||||
}, []);
|
||||
useEffect(() => {
|
||||
void refresh();
|
||||
const timer = setInterval(() => void refresh(), everyMs);
|
||||
return () => clearInterval(timer);
|
||||
}, [refresh, everyMs]);
|
||||
return { status, refresh };
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { Loader2 } from "lucide-react";
|
||||
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 { realmRegistry, useRegistryStatus } from "@/lib/registry";
|
||||
|
||||
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. */
|
||||
export function PublishCard({ serverId, serverName }: { serverId: string; serverName: string }) {
|
||||
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;
|
||||
const [url, setUrl] = useState("");
|
||||
const [name, setName] = useState(serverName);
|
||||
const [description, setDescription] = useState("");
|
||||
const [language, setLanguage] = useState("en");
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => { if (status && status.url !== null) setUrl((u) => (u === "" ? status.url ?? "" : u)); }, [status?.url]);
|
||||
useEffect(() => {
|
||||
if (mine && mine.display_name) { setName(mine.display_name); setDescription(mine.description); setLanguage(mine.language || "en"); }
|
||||
}, [mine?.display_name, mine?.description, mine?.language]);
|
||||
|
||||
async function run(action: () => Promise<void>) {
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
try { await action(); await refresh(); } catch (e) { setError(asUiError(e).technical); } finally { setBusy(false); }
|
||||
}
|
||||
|
||||
const tone = mine?.state === "online" ? "text-ok" : mine?.state === "rejected" ? "text-bad" : mine?.state === "retrying" || mine?.state === "realm_stopped" || mine?.state === "waiting_for_realm" ? "text-warn" : "text-muted";
|
||||
|
||||
return (
|
||||
<Card className="mt-6 p-6">
|
||||
<h2 className="font-semibold">{t("registry.title")}</h2>
|
||||
<p className="mt-1 text-sm text-muted">{t("registry.text")}</p>
|
||||
|
||||
<label htmlFor="registry-url" className="mt-4 block text-sm font-medium">{t("registry.url")}</label>
|
||||
<div className="mt-1 flex gap-2">
|
||||
<input id="registry-url" value={url} onChange={(e) => setUrl(e.target.value)} placeholder="https://registry.example" className="min-w-0 flex-1 rounded-md border border-line bg-card px-3 py-2" />
|
||||
<Button size="sm" disabled={busy || url.trim() === (status?.url ?? "")} onClick={() => void run(() => realmRegistry.setUrl(url.trim() || null))}>{t("registry.urlSave")}</Button>
|
||||
</div>
|
||||
|
||||
{!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" />
|
||||
<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">
|
||||
{LANGUAGES.map((l) => <option key={l} value={l}>{l}</option>)}
|
||||
</select>
|
||||
<div className="mt-4">
|
||||
<Button variant="primary" disabled={busy || !status?.url || name.trim() === ""} onClick={() => void run(() => realmRegistry.publish(localId, name, description, language))}>
|
||||
{busy && <Loader2 className="h-4 w-4 animate-spin" aria-hidden />}{t("registry.publish")}
|
||||
</Button>
|
||||
{!status?.url && <p className="mt-2 text-xs text-muted">{t("registry.noUrl")}</p>}
|
||||
</div>
|
||||
</>}
|
||||
|
||||
{mine && (published || mine.state === "unpublishing") && <div className="mt-4 rounded-md border border-line p-3 text-sm" role="status">
|
||||
<p className={cn("font-medium", tone)} data-state={mine.state}>{t(`registry.state.${mine.state}` as Key)}</p>
|
||||
<p className="mt-1 text-xs text-muted">{mine.display_name}{mine.metadata_revision ? ` · ${t("registry.revision", { n: mine.metadata_revision })}` : ""}</p>
|
||||
{mine.last_error && <p className="mt-1 text-xs text-warn">{mine.last_error}</p>}
|
||||
{mine.state === "retrying" && mine.retry_in_secs !== null && <p className="mt-1 text-xs text-muted">{t("registry.retryIn", { s: mine.retry_in_secs })}</p>}
|
||||
<div className="mt-3 flex gap-2">
|
||||
{mine.state === "rejected" && <Button size="sm" onClick={() => void run(async () => { await realmRegistry.retry(localId); })}>{t("registry.retry")}</Button>}
|
||||
<Button size="sm" disabled={busy} onClick={() => void run(() => realmRegistry.unpublish(localId))}>{t("registry.stop")}</Button>
|
||||
</div>
|
||||
</div>}
|
||||
{error && <p className="mt-3 text-sm text-bad" role="alert">{error}</p>}
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
@@ -13,12 +13,13 @@ import { hasKey, useHuman, useI18n, type Key } from "@/i18n";
|
||||
import { LanguagePicker } from "@/components/LanguagePicker";
|
||||
import { RealmStartupSettings } from "@/screens/RealmStartupSettings";
|
||||
import { RepairCard } from "@/screens/RepairCard";
|
||||
import { PublishCard } from "@/screens/PublishCard";
|
||||
|
||||
function mb(bytes: number) {
|
||||
return bytes >= 1 << 20 ? `${(bytes / (1 << 20)).toFixed(1)} MB` : `${Math.max(1, Math.round(bytes / 1024))} KB`;
|
||||
}
|
||||
|
||||
export function SettingsHome({ serverId }: { serverId: string }) {
|
||||
export function SettingsHome({ serverId, serverName }: { serverId: string; serverName: string }) {
|
||||
const { t } = useI18n();
|
||||
const upd = useServerUpdate(serverId);
|
||||
const human = useHuman();
|
||||
@@ -171,6 +172,7 @@ export function SettingsHome({ serverId }: { serverId: string }) {
|
||||
|
||||
<DiagnosticsCard serverId={serverId} />
|
||||
<RepairCard key={serverId} serverId={serverId} />
|
||||
<PublishCard key={`publish-${serverId}`} serverId={serverId} serverName={serverName} />
|
||||
|
||||
<AboutCard />
|
||||
|
||||
|
||||
@@ -141,7 +141,7 @@ export function Shell(props: {
|
||||
) : page === "friends" ? (
|
||||
<FriendsPage key={server.id} serverId={server.id} />
|
||||
) : page === "settings" ? (
|
||||
<SettingsHome key={server.id} serverId={server.id} />
|
||||
<SettingsHome key={server.id} serverId={server.id} serverName={server.name} />
|
||||
) : page === "characters" ? (
|
||||
<PortablePage key="characters" />
|
||||
) : page === "players" ? (
|
||||
|
||||
Reference in new issue
Block a user