mirror of
https://github.com/Corfirean/coa-server-manager.git
synced 2026-11-21 03:25:56 +00:00
feat: open firewall ports for every running world and list every realm publicly
- Starting a server that is open to friends adds the firewall rules for the world ports of all realms that start together (only missing ones; a refused Windows prompt does not undo the start). - Settings shows one public-listing block per realm that starts together. The main realm keeps its plain local id, so an existing listing is untouched. - A realm that runs as an extra world is reached through that world's own console port, so its listing reports its own state and capabilities. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
321ac597ce
commit
af82963f35
6 files changed
+119
-24
No files matched your search
+36
-14
@@ -4,16 +4,38 @@ 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 { api, asUiError, type RealmMode } 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"];
|
||||
|
||||
/** Publishing this server's realm to the central Registry: a name, a description, a language. Nothing else leaves this machine. */
|
||||
const REALM_LABEL: Record<RealmMode, string> = { coa: "Conquest of Azeroth", wildcard: "Wildcard", reborn: "Warcraft Reborn" };
|
||||
|
||||
/** The realms this server runs: the main one keeps the plain id it was published under, each realm that starts next to it has its own. */
|
||||
export function PublishCard({ serverId, serverName }: { serverId: string; serverName: string }) {
|
||||
const [realms, setRealms] = useState<{ localId: string; mode: RealmMode }[] | null>(null);
|
||||
useEffect(() => {
|
||||
let alive = true;
|
||||
void api.realmProfiles(serverId).then((r) => {
|
||||
if (!alive) return;
|
||||
const extra: RealmMode[] = [];
|
||||
if (r.simultaneous) extra.push(r.active === "coa" ? "wildcard" : "coa");
|
||||
if (r.with_reborn) extra.push("reborn");
|
||||
setRealms([{ localId: `srv-${serverId}`, mode: r.active }, ...extra.map((mode) => ({ localId: `srv-${serverId}:${mode}`, mode }))]);
|
||||
}).catch(() => { if (alive) setRealms([{ localId: `srv-${serverId}`, mode: "coa" }]); });
|
||||
return () => { alive = false; };
|
||||
}, [serverId]);
|
||||
if (!realms) return null;
|
||||
const several = realms.length > 1;
|
||||
return <>{realms.map((r) => (
|
||||
<RealmPublish key={r.localId} localId={r.localId} serverName={several && r.mode !== realms[0].mode ? `${serverName} · ${REALM_LABEL[r.mode]}` : serverName} realmLabel={several ? REALM_LABEL[r.mode] : null} />
|
||||
))}</>;
|
||||
}
|
||||
|
||||
/** Publishing one realm to the central Registry: a name, a description, a language. Nothing else leaves this machine. */
|
||||
function RealmPublish({ localId, serverName, realmLabel }: { localId: string; serverName: string; realmLabel: string | null }) {
|
||||
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;
|
||||
@@ -58,22 +80,22 @@ export function PublishCard({ serverId, serverName }: { serverId: string; server
|
||||
|
||||
return (
|
||||
<Card className="mt-6 p-6">
|
||||
<h2 className="font-semibold">{t("registry.title")}</h2>
|
||||
<h2 className="font-semibold">{t("registry.title")}{realmLabel ? ` · ${realmLabel}` : ""}</h2>
|
||||
<p className="mt-1 text-sm text-muted">{t("registry.text")}</p>
|
||||
|
||||
|
||||
{!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" />
|
||||
<label htmlFor={`registry-name-${localId}`} className="mt-4 block text-sm font-medium">{t("registry.name")}</label>
|
||||
<input id={`registry-name-${localId}`} 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-${localId}`} className="mt-3 block text-sm font-medium">{t("registry.description")}</label>
|
||||
<textarea id={`registry-description-${localId}`} 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">
|
||||
<label htmlFor={`registry-language-${localId}`} className="mt-3 block text-sm font-medium">{t("registry.language")}</label>
|
||||
<select id={`registry-language-${localId}`} 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>
|
||||
<label htmlFor="registry-region" className="mt-3 block text-sm font-medium">{t("registry.region")}</label>
|
||||
<input id="registry-region" value={region} maxLength={16} placeholder="EU" onChange={(e) => setRegion(e.target.value)} className="mt-1 w-32 rounded-md border border-line bg-card px-3 py-2" />
|
||||
<label htmlFor={`registry-region-${localId}`} className="mt-3 block text-sm font-medium">{t("registry.region")}</label>
|
||||
<input id={`registry-region-${localId}`} value={region} maxLength={16} placeholder="EU" onChange={(e) => setRegion(e.target.value)} className="mt-1 w-32 rounded-md border border-line bg-card px-3 py-2" />
|
||||
<div className="mt-4">
|
||||
<Button variant="primary" disabled={busy || !status?.url || name.trim() === ""} onClick={() => void run(() => realmRegistry.publish(localId, name, description, language, region.trim() === "" ? null : region.trim()))}>
|
||||
{busy && <Loader2 className="h-4 w-4 animate-spin" aria-hidden />}{t("registry.publish")}
|
||||
@@ -97,8 +119,8 @@ export function PublishCard({ serverId, serverName }: { serverId: string; server
|
||||
<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 className="block text-xs text-muted">{t("access.allowPortableHint")}</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" />
|
||||
<label htmlFor={`access-route-${localId}`} className="mt-3 block font-medium">{t("access.route")}</label>
|
||||
<input id={`access-route-${localId}`} 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-${localId}`} />
|
||||
<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>
|
||||
|
||||
Reference in new issue
Block a user