mirror of
https://github.com/Corfirean/coa-server-manager.git
synced 2026-11-23 03:25:56 +00:00
Settings, Startup lists every realm of the server with its name. The choice is kept in Settings/realm-names.json of the main folder; the launcher, the realm-list setup and the client's Config.wtf use it, and a running database gets it at once. Names are 1-32 characters without quotation marks or control characters, written as escaped SQL. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
20d4c3351e
commit
d1534ebc92
18 files changed
+396
-26
No files matched your search
@@ -0,0 +1,60 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { api, asUiError, type RealmName } from "@/lib/api";
|
||||
import { Card } from "@/components/ui/card";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { useT } from "@/i18n";
|
||||
|
||||
const MAX_CHARS = 32;
|
||||
|
||||
export function RealmNameSettings({ serverId }: { serverId: string }) {
|
||||
const t = useT();
|
||||
const [realms, setRealms] = useState<RealmName[] | null>(null);
|
||||
const [drafts, setDrafts] = useState<Record<number, string>>({});
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [saved, setSaved] = useState<number | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
function show(list: RealmName[]) {
|
||||
setRealms(list);
|
||||
setDrafts(Object.fromEntries(list.map(r => [r.id, r.name])));
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
let alive = true;
|
||||
void api.realmNames(serverId).then(list => { if (alive) show(list); }).catch(e => { if (alive) setError(asUiError(e).technical); });
|
||||
return () => { alive = false; };
|
||||
}, [serverId]);
|
||||
|
||||
async function rename(id: number, name: string | null) {
|
||||
setBusy(true); setError(null); setSaved(null);
|
||||
try { show(await api.realmRename(serverId, id, name)); setSaved(id); }
|
||||
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.namesTitle")}</h2>
|
||||
<p className="mt-1 text-sm text-muted">{t("realm.namesHint")}</p>
|
||||
{realms?.map(r => {
|
||||
const draft = drafts[r.id] ?? r.name;
|
||||
const invalid = draft.trim().length === 0 || draft.trim().length > MAX_CHARS || draft.includes('"');
|
||||
return <div key={r.id} className="mt-4">
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<input
|
||||
className="min-w-0 flex-1 rounded border border-line bg-bg px-3 py-1.5 text-sm text-ink outline-none focus:border-gold"
|
||||
value={draft}
|
||||
maxLength={MAX_CHARS}
|
||||
aria-label={t("realm.nameDefault", { name: r.defaultName })}
|
||||
disabled={busy}
|
||||
onChange={e => setDrafts(d => ({ ...d, [r.id]: e.target.value }))}
|
||||
/>
|
||||
<Button size="sm" disabled={busy || invalid || draft.trim() === r.name} onClick={() => void rename(r.id, draft)}>{t("realm.nameSave")}</Button>
|
||||
{r.custom && <Button size="sm" variant="ghost" disabled={busy} onClick={() => void rename(r.id, null)}>{t("realm.nameReset")}</Button>}
|
||||
</div>
|
||||
<p className="mt-1 text-xs text-muted">{t("realm.nameDefault", { name: r.defaultName })}{saved === r.id ? ` · ${t("realm.nameSaved")}` : ""}</p>
|
||||
{draft.includes('"') && <p className="mt-1 text-xs text-warn">{t("realm.nameQuotes")}</p>}
|
||||
</div>;
|
||||
})}
|
||||
{error && <p className="mt-3 text-sm text-bad" role="alert">{error}</p>}
|
||||
</Card>;
|
||||
}
|
||||
@@ -12,6 +12,7 @@ import { ReleaseHistory, type HistorySelection } from "./ReleaseHistory";
|
||||
import { ClientCard } from "./ClientCard";
|
||||
import { GameDataCard } from "./GameDataCard";
|
||||
import { RealmStartupSettings } from "./RealmStartupSettings";
|
||||
import { RealmNameSettings } from "./RealmNameSettings";
|
||||
import { AutoRestartSettings } from "./AutoRestartSettings";
|
||||
import { DiagnosticsCard } from "./DiagnosticsCard";
|
||||
import { RepairCard } from "./RepairCard";
|
||||
@@ -50,7 +51,7 @@ export function SettingsHome({ serverId, path, onForget }: { serverId: string; s
|
||||
<button onClick={() => setSection("client")} className="mt-5 flex w-full cursor-pointer items-center justify-between gap-3 rounded-lg border border-line px-5 py-4 text-left text-sm hover:bg-white/5"><span>{t("settings.clientLink")}</span><span aria-hidden>→</span></button>
|
||||
<ReleaseHistory selection={history} onSelect={setHistory} />
|
||||
</div>
|
||||
<div hidden={section !== "startup"} className="max-w-3xl"><RealmStartupSettings serverId={serverId} /><AutoRestartSettings serverId={serverId} /></div>
|
||||
<div hidden={section !== "startup"} className="max-w-3xl"><RealmNameSettings serverId={serverId} /><RealmStartupSettings serverId={serverId} /><AutoRestartSettings serverId={serverId} /></div>
|
||||
<div hidden={section !== "client"} className="max-w-3xl"><ClientCard serverId={serverId} /><GameDataCard serverId={serverId} /></div>
|
||||
<div hidden={section !== "service"} className="max-w-3xl"><ServerLoggingSettings serverId={serverId} /><DiagnosticsCard serverId={serverId} /><RepairCard serverId={serverId} /><RemoveServerCard serverId={serverId} path={path} onForget={onForget} /></div>
|
||||
<div hidden={section !== "interface"} className="max-w-3xl"><Card className="mt-6 p-6"><h2 className="font-semibold">{t("settings.language")}</h2><p className="mt-1 text-sm text-muted">{t("settings.languageHint")}</p><LanguagePicker className="mt-4" /></Card><WindowSettings /><PublicServerSettings /></div>
|
||||
|
||||
Reference in new issue
Block a user