mirror of
https://github.com/Corfirean/coa-server-manager.git
synced 2026-11-21 03:25:56 +00:00
Phase 5: clean install (signed packages, split tar.zst, resumable verified downloads, staging + atomic commit, DB credential rotation), RA account creation, Install and Players UI
Verified: fixture packaged 2.2 GB -> 327 MB, installed in 18 s with rotated DB credentials via the native UI; hostile archives, bad signatures and interrupted downloads are rejected/resumed in tests. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0bc6059019
commit
e17c757d11
14 files changed
+1518
-14
No files matched your search
@@ -0,0 +1,168 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { listen } from "@tauri-apps/api/event";
|
||||
import { open } from "@tauri-apps/plugin-dialog";
|
||||
import { Check, ChevronDown, ChevronRight, Loader2 } from "lucide-react";
|
||||
import { api, asUiError, type InstallStep, type Preflight, type ServerSummary, type UiError } from "@/lib/api";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Card } from "@/components/ui/card";
|
||||
|
||||
type Phase = "choose" | "installing" | "done";
|
||||
|
||||
export function InstallServer(props: { canCancel: boolean; onCancel: () => void; onDone: (s: ServerSummary) => void | Promise<void> }) {
|
||||
const [dest, setDest] = useState("C:\\Games\\CoA Server");
|
||||
const [pre, setPre] = useState<Preflight | null>(null);
|
||||
const [phase, setPhase] = useState<Phase>("choose");
|
||||
const [step, setStep] = useState<InstallStep>({ step: "Preparing your server", percent: 0, detail: null });
|
||||
const [error, setError] = useState<UiError | null>(null);
|
||||
const [showAdvanced, setShowAdvanced] = useState(false);
|
||||
const [pkg, setPkg] = useState("");
|
||||
const [installed, setInstalled] = useState<ServerSummary | null>(null);
|
||||
const [showDetails, setShowDetails] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
const t = setTimeout(() => void api.installPreflight(dest).then(setPre).catch(() => setPre(null)), 250);
|
||||
return () => clearTimeout(t);
|
||||
}, [dest]);
|
||||
|
||||
useEffect(() => {
|
||||
const un = listen<InstallStep>("install-progress", (e) => setStep(e.payload));
|
||||
return () => {
|
||||
void un.then((f) => f());
|
||||
};
|
||||
}, []);
|
||||
|
||||
async function browse() {
|
||||
const picked = await open({ directory: true, multiple: false, title: "Choose where to install your server" });
|
||||
if (typeof picked === "string") setDest(picked.replace(/[\\/]+$/, "") + (picked.toLowerCase().includes("coa") ? "" : "\\CoA Server"));
|
||||
}
|
||||
|
||||
async function browsePackage() {
|
||||
const picked = await open({ directory: true, multiple: false, title: "Choose a server package folder" });
|
||||
if (typeof picked === "string") setPkg(picked);
|
||||
}
|
||||
|
||||
async function install() {
|
||||
setError(null);
|
||||
setPhase("installing");
|
||||
setStep({ step: "Preparing your server", percent: 0, detail: null });
|
||||
try {
|
||||
const s = await api.installNew(dest, pkg.trim() || undefined);
|
||||
setInstalled(s);
|
||||
setPhase("done");
|
||||
} catch (e) {
|
||||
setError(asUiError(e));
|
||||
setPhase("choose");
|
||||
}
|
||||
}
|
||||
|
||||
if (phase === "installing") {
|
||||
return (
|
||||
<main className="mx-auto flex h-full max-w-xl flex-col justify-center px-8">
|
||||
<h1 className="text-2xl font-semibold">Preparing your server</h1>
|
||||
<p className="mt-1 text-muted">This can take a few minutes. You can leave this window open.</p>
|
||||
<Card className="mt-8 p-6">
|
||||
<div className="flex items-center justify-between">
|
||||
<span className="flex items-center gap-2 font-medium">
|
||||
<Loader2 className="h-4 w-4 animate-spin text-gold" aria-hidden /> {step.step}
|
||||
</span>
|
||||
<span className="text-sm text-muted" role="status">{step.percent}%</span>
|
||||
</div>
|
||||
<div className="mt-3 h-2 overflow-hidden rounded-full bg-white/10" role="progressbar" aria-valuenow={step.percent} aria-valuemin={0} aria-valuemax={100}>
|
||||
<div className="h-full rounded-full bg-gold transition-[width] duration-300" style={{ width: `${step.percent}%` }} />
|
||||
</div>
|
||||
{step.detail && <p className="mt-2 text-xs text-muted">{step.detail}</p>}
|
||||
</Card>
|
||||
{step.step === "Downloading server" && (
|
||||
<Button className="mt-4 self-start" variant="ghost" size="sm" onClick={() => void api.cancelInstall()}>
|
||||
Cancel
|
||||
</Button>
|
||||
)}
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
if (phase === "done" && installed) {
|
||||
return (
|
||||
<main className="mx-auto flex h-full max-w-xl flex-col items-center justify-center px-8 text-center">
|
||||
<div className="flex h-14 w-14 items-center justify-center rounded-full bg-ok/15">
|
||||
<Check className="h-7 w-7 text-ok" aria-hidden />
|
||||
</div>
|
||||
<h1 className="mt-5 text-2xl font-semibold">Your server is ready</h1>
|
||||
<p className="mt-1 text-muted">Everything is installed. Start it from the next screen.</p>
|
||||
<Button className="mt-8" variant="primary" size="xl" onClick={() => void props.onDone(installed)}>
|
||||
OPEN MY SERVER
|
||||
</Button>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<main className="mx-auto flex h-full max-w-2xl flex-col justify-center gap-5 px-8 py-10">
|
||||
<div>
|
||||
<h1 className="text-2xl font-semibold">Install a new server</h1>
|
||||
<p className="mt-1 text-muted">Choose a folder, or keep the suggested one. Everything else is set up for you.</p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label htmlFor="dest" className="text-sm text-muted">Install to</label>
|
||||
<div className="mt-1 flex gap-2">
|
||||
<input
|
||||
id="dest"
|
||||
value={dest}
|
||||
onChange={(e) => setDest(e.target.value)}
|
||||
className="selectable flex-1 rounded-md border border-line bg-card px-3 py-2.5 text-[15px] outline-none focus:border-gold"
|
||||
/>
|
||||
<Button onClick={browse}>Browse…</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{pre && pre.problems.length > 0 && (
|
||||
<Card className="border-warn/40 p-4" role="alert">
|
||||
{pre.problems.map((p) => (
|
||||
<p key={p.code} className="text-sm text-warn">{p.message}</p>
|
||||
))}
|
||||
</Card>
|
||||
)}
|
||||
{pre?.ok && <p className="text-sm text-ok">This folder is ready. {Math.round(pre.free_bytes / (1 << 30))} GB free.</p>}
|
||||
|
||||
{error && (
|
||||
<Card className="border-bad/40 p-4" role="alert">
|
||||
<p className="font-medium text-bad">{error.human.code === "unknown" ? "The installation could not finish" : error.human.title}</p>
|
||||
<p className="mt-1 text-sm text-muted">{error.human.code === "unknown" ? error.technical : error.human.message}</p>
|
||||
<p className="mt-1 text-sm text-muted">Nothing was installed. You can try again; downloaded files are kept.</p>
|
||||
<button className="mt-2 cursor-pointer text-xs text-muted underline" onClick={() => setShowDetails((v) => !v)}>
|
||||
{showDetails ? "Hide" : "Show"} technical details
|
||||
</button>
|
||||
{showDetails && <pre className="mt-2 max-h-40 overflow-auto whitespace-pre-wrap rounded bg-black/40 p-2 text-xs">{error.technical}</pre>}
|
||||
</Card>
|
||||
)}
|
||||
|
||||
<div>
|
||||
<button onClick={() => setShowAdvanced((v) => !v)} aria-expanded={showAdvanced} className="flex cursor-pointer items-center gap-1 text-sm text-muted hover:text-ink">
|
||||
{showAdvanced ? <ChevronDown className="h-4 w-4" aria-hidden /> : <ChevronRight className="h-4 w-4" aria-hidden />}
|
||||
Advanced
|
||||
</button>
|
||||
{showAdvanced && (
|
||||
<div className="mt-2">
|
||||
<label htmlFor="pkg" className="text-sm text-muted">Install from a local package folder instead of downloading</label>
|
||||
<div className="mt-1 flex gap-2">
|
||||
<input id="pkg" value={pkg} onChange={(e) => setPkg(e.target.value)} placeholder="(leave empty to download)" className="selectable flex-1 rounded-md border border-line bg-card px-3 py-2 text-sm outline-none focus:border-gold" />
|
||||
<Button size="sm" onClick={browsePackage}>Browse…</Button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-3">
|
||||
<Button variant="primary" size="md" disabled={!pre?.ok} onClick={() => void install()}>
|
||||
Install
|
||||
</Button>
|
||||
{props.canCancel && (
|
||||
<Button variant="ghost" onClick={props.onCancel}>
|
||||
Cancel
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { api, asUiError, type UiError } from "@/lib/api";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Card } from "@/components/ui/card";
|
||||
|
||||
export function PlayersPage({ serverId }: { serverId: string }) {
|
||||
const [online, setOnline] = useState<boolean | null>(null);
|
||||
const [username, setUsername] = useState("");
|
||||
const [password, setPassword] = useState("");
|
||||
const [admin, setAdmin] = useState(false);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState<UiError | null>(null);
|
||||
const [done, setDone] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
let alive = true;
|
||||
const poll = () => api.status(serverId).then((s) => alive && setOnline(s.observed.world.state === "running")).catch(() => {});
|
||||
void poll();
|
||||
const t = setInterval(poll, 3000);
|
||||
return () => {
|
||||
alive = false;
|
||||
clearInterval(t);
|
||||
};
|
||||
}, [serverId]);
|
||||
|
||||
async function create() {
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
setDone(null);
|
||||
try {
|
||||
await api.createAccount(serverId, username, password, admin);
|
||||
setDone(username);
|
||||
setUsername("");
|
||||
setPassword("");
|
||||
} catch (e) {
|
||||
setError(asUiError(e));
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
const input = "w-72 rounded-md border border-line bg-bg px-3 py-2.5 text-[15px] outline-none focus:border-gold";
|
||||
return (
|
||||
<div className="max-w-xl">
|
||||
<h1 className="text-2xl font-semibold">Players</h1>
|
||||
<p className="mt-1 text-muted">Who is playing right now?</p>
|
||||
|
||||
<Card className="mt-6 p-6">
|
||||
<h2 className="font-semibold">Create your account</h2>
|
||||
<p className="mt-1 text-sm text-muted">This is the name and password you use to log in to the game.</p>
|
||||
{online === false && <p className="mt-3 text-sm text-warn">Start the server first — accounts are created while it is running.</p>}
|
||||
<div className="mt-4 flex flex-col gap-3">
|
||||
<div>
|
||||
<label htmlFor="acc-user" className="text-sm text-muted">Username</label>
|
||||
<input id="acc-user" className={input + " mt-1 block"} value={username} onChange={(e) => setUsername(e.target.value)} autoComplete="off" />
|
||||
</div>
|
||||
<div>
|
||||
<label htmlFor="acc-pass" className="text-sm text-muted">Password</label>
|
||||
<input id="acc-pass" type="password" className={input + " mt-1 block"} value={password} onChange={(e) => setPassword(e.target.value)} autoComplete="new-password" />
|
||||
</div>
|
||||
<label className="flex cursor-pointer items-start gap-2 text-sm">
|
||||
<input type="checkbox" checked={admin} onChange={(e) => setAdmin(e.target.checked)} className="mt-1" />
|
||||
<span>
|
||||
Make this account an administrator
|
||||
<span className="block text-xs text-muted">Administrators can use game-master commands in the game. Only do this for accounts you trust.</span>
|
||||
</span>
|
||||
</label>
|
||||
</div>
|
||||
<Button className="mt-5" variant="primary" disabled={busy || !online || !username || !password} onClick={() => void create()}>
|
||||
Create account
|
||||
</Button>
|
||||
{done && <p className="mt-3 text-sm text-ok" role="status">Account “{done}” created. You can log in to the game with it now.</p>}
|
||||
{error && (
|
||||
<p className="mt-3 text-sm text-bad" role="alert">
|
||||
{error.human.code === "unknown" ? error.technical : error.human.message}
|
||||
</p>
|
||||
)}
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import { Overview } from "@/screens/Overview";
|
||||
import { Placeholder } from "@/screens/Placeholder";
|
||||
import { SettingsPage } from "@/screens/SettingsPage";
|
||||
import { BackupsPage } from "@/screens/BackupsPage";
|
||||
import { PlayersPage } from "@/screens/PlayersPage";
|
||||
import { Button } from "@/components/ui/button";
|
||||
|
||||
type Page = "overview" | "bots" | "server" | "players" | "friends" | "backups" | "console" | "settings";
|
||||
@@ -80,6 +81,8 @@ export function Shell(props: {
|
||||
<Overview key={server.id} server={server} onForget={() => props.onForget(server.id)} />
|
||||
) : page === "bots" || page === "server" ? (
|
||||
<SettingsPage key={`${server.id}-${page}`} serverId={server.id} scope={page} title={current.label} question={current.question} />
|
||||
) : page === "players" ? (
|
||||
<PlayersPage key={server.id} serverId={server.id} />
|
||||
) : page === "backups" ? (
|
||||
<BackupsPage key={server.id} serverId={server.id} />
|
||||
) : (
|
||||
|
||||
+11
-5
@@ -1,7 +1,6 @@
|
||||
import { FolderSearch, Download } from "lucide-react";
|
||||
import { Card } from "@/components/ui/card";
|
||||
|
||||
export function Welcome({ onImport }: { onImport: () => void }) {
|
||||
export function Welcome({ onImport, onInstall, onBack }: { onImport: () => void; onInstall: () => void; onBack?: () => void }) {
|
||||
return (
|
||||
<main className="flex h-full flex-col items-center justify-center px-8">
|
||||
<div className="mb-10 text-center">
|
||||
@@ -11,12 +10,14 @@ export function Welcome({ onImport }: { onImport: () => void }) {
|
||||
</div>
|
||||
|
||||
<div className="grid w-full max-w-3xl grid-cols-2 gap-5">
|
||||
<Card className="p-7 opacity-60" aria-disabled="true">
|
||||
<button
|
||||
onClick={onInstall}
|
||||
className="cursor-pointer rounded-card border border-line bg-card/90 p-7 text-left shadow-[0_8px_30px_rgb(0_0_0/0.28)] transition-colors hover:border-gold/60"
|
||||
>
|
||||
<Download className="mb-4 h-7 w-7 text-gold" aria-hidden />
|
||||
<h2 className="text-lg font-semibold">Install new server</h2>
|
||||
<p className="mt-1 text-sm text-muted">One-click setup with everything included.</p>
|
||||
<p className="mt-4 inline-block rounded bg-white/5 px-2 py-1 text-xs text-muted">Coming in a later release</p>
|
||||
</Card>
|
||||
</button>
|
||||
|
||||
<button
|
||||
onClick={onImport}
|
||||
@@ -29,6 +30,11 @@ export function Welcome({ onImport }: { onImport: () => void }) {
|
||||
</p>
|
||||
</button>
|
||||
</div>
|
||||
{onBack && (
|
||||
<button onClick={onBack} className="mt-8 cursor-pointer text-sm text-muted hover:text-ink">
|
||||
Back to my servers
|
||||
</button>
|
||||
)}
|
||||
</main>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user