Add deploy + destroy server flow; migrate to t5_<mode>_<slug>_<n> naming
Full server lifecycle management from Electric Cherry: pick game/mode/map/pluto key in the Fleet page, EC provisions the deployment via Komodo, allocates a port in 28960-28980, creates the 0o777 host dir, and starts the container. Destroy button tears everything down (Komodo Destroy+Delete, rm -rf host dir, transactional DB cleanup) and surfaces any partial-failure warnings inline. Same phase cuts over to the new naming scheme (t5_zombie_cosmodrome_1 etc.). Komodo entity names now match EC server names 1:1 (no more _/- transform), and the map catalog carries friendly/slug/canonical for each of the 11 t5 zombie maps. Server rows gain game_mode, map_slug, host_dir, config_file, game_id, image, created_by, and destroyed_at columns for provisioning + audit. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,282 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from 'svelte';
|
||||
import { goto } from '$app/navigation';
|
||||
|
||||
interface T5MapEntry {
|
||||
friendly: string;
|
||||
slug: string;
|
||||
canonical: string;
|
||||
}
|
||||
|
||||
let { open = $bindable(false) }: { open?: boolean } = $props();
|
||||
|
||||
let dialog: HTMLDialogElement | undefined = $state();
|
||||
let maps = $state<T5MapEntry[]>([]);
|
||||
let mapsError = $state<string | null>(null);
|
||||
let mapsLoaded = $state(false);
|
||||
|
||||
let gameMode = $state<'zombie'>('zombie');
|
||||
let mapSlug = $state<string>('');
|
||||
let plutoKey = $state('');
|
||||
let deploying = $state(false);
|
||||
let flash = $state<string | null>(null);
|
||||
|
||||
onMount(async () => {
|
||||
try {
|
||||
const res = await fetch('/api/maps');
|
||||
const body = (await res.json()) as { t5Zombie: T5MapEntry[] };
|
||||
maps = body.t5Zombie;
|
||||
if (maps.length > 0) mapSlug = maps[0].slug;
|
||||
} catch (err) {
|
||||
mapsError = (err as Error).message;
|
||||
} finally {
|
||||
mapsLoaded = true;
|
||||
}
|
||||
});
|
||||
|
||||
// Track prior open value manually — using $effect with `open` triggers on
|
||||
// every render and repeatedly re-shows the modal.
|
||||
let wasOpen = $state(false);
|
||||
$effect(() => {
|
||||
if (!dialog) return;
|
||||
if (open && !wasOpen) {
|
||||
reset();
|
||||
dialog.showModal();
|
||||
} else if (!open && wasOpen) {
|
||||
if (dialog.open) dialog.close();
|
||||
}
|
||||
wasOpen = open;
|
||||
});
|
||||
|
||||
function reset(): void {
|
||||
plutoKey = '';
|
||||
flash = null;
|
||||
deploying = false;
|
||||
if (maps.length > 0 && !maps.some((m) => m.slug === mapSlug)) mapSlug = maps[0].slug;
|
||||
}
|
||||
|
||||
function close(): void {
|
||||
open = false;
|
||||
}
|
||||
|
||||
// Click-outside-to-close (native <dialog> only supports Esc).
|
||||
function onDialogClick(e: MouseEvent): void {
|
||||
if (!dialog) return;
|
||||
const rect = dialog.getBoundingClientRect();
|
||||
const inDialog =
|
||||
e.clientX >= rect.left && e.clientX <= rect.right &&
|
||||
e.clientY >= rect.top && e.clientY <= rect.bottom;
|
||||
if (!inDialog) close();
|
||||
}
|
||||
|
||||
let selectedMap = $derived(maps.find((m) => m.slug === mapSlug));
|
||||
let previewName = $derived(
|
||||
selectedMap ? `t5_${gameMode}_${selectedMap.slug}_?` : ''
|
||||
);
|
||||
|
||||
async function submit(e: SubmitEvent): Promise<void> {
|
||||
e.preventDefault();
|
||||
if (deploying) return;
|
||||
if (!selectedMap) {
|
||||
flash = 'pick a map';
|
||||
return;
|
||||
}
|
||||
if (plutoKey.trim().length === 0) {
|
||||
flash = 'pluto server key is required';
|
||||
return;
|
||||
}
|
||||
deploying = true;
|
||||
flash = null;
|
||||
try {
|
||||
const res = await fetch('/api/servers', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ gameMode, mapSlug: selectedMap.slug, plutoKey })
|
||||
});
|
||||
const body = (await res.json()) as {
|
||||
ok: boolean;
|
||||
name?: string;
|
||||
port?: number;
|
||||
error?: string;
|
||||
kind?: string;
|
||||
};
|
||||
if (!body.ok || !body.name) {
|
||||
flash = body.error ?? 'deploy failed';
|
||||
deploying = false;
|
||||
return;
|
||||
}
|
||||
close();
|
||||
await goto(`/servers/${encodeURIComponent(body.name)}`);
|
||||
} catch (err) {
|
||||
flash = (err as Error).message;
|
||||
deploying = false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<dialog bind:this={dialog} onclick={onDialogClick} onclose={() => (open = false)}>
|
||||
<form class="dlg" onsubmit={submit}>
|
||||
<h3>Deploy new server</h3>
|
||||
|
||||
{#if mapsError}
|
||||
<p class="flash">failed to load map catalog: {mapsError}</p>
|
||||
{:else if !mapsLoaded}
|
||||
<p class="hint">loading map catalog…</p>
|
||||
{:else}
|
||||
<div class="row">
|
||||
<span class="row-label">Game</span>
|
||||
<div class="readonly mono">Black Ops 1 (t5)</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<label for="mode">Mode</label>
|
||||
<select id="mode" bind:value={gameMode} disabled={deploying}>
|
||||
<option value="zombie">Zombies</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<label for="map">Map</label>
|
||||
<select id="map" bind:value={mapSlug} disabled={deploying}>
|
||||
{#each maps as m (m.slug)}
|
||||
<option value={m.slug}>{m.friendly}</option>
|
||||
{/each}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<label for="key">Pluto server key</label>
|
||||
<input
|
||||
id="key"
|
||||
type="password"
|
||||
bind:value={plutoKey}
|
||||
placeholder="paste each deploy — not stored"
|
||||
autocomplete="off"
|
||||
disabled={deploying}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="preview">
|
||||
<span class="k">will create</span>
|
||||
<span class="v mono">{previewName || '—'}</span>
|
||||
<span class="sub">(lobby number + port auto-assigned)</span>
|
||||
</div>
|
||||
|
||||
<div class="dlg-actions">
|
||||
<button type="button" class="secondary" onclick={close} disabled={deploying}>cancel</button>
|
||||
<button type="submit" class="primary" disabled={deploying || !selectedMap}>
|
||||
{deploying ? 'deploying…' : 'deploy server'}
|
||||
</button>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if flash}<p class="flash">{flash}</p>{/if}
|
||||
</form>
|
||||
</dialog>
|
||||
|
||||
<style>
|
||||
dialog {
|
||||
background: var(--bg-nav);
|
||||
color: var(--ink-100);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--r-md);
|
||||
padding: 0;
|
||||
max-width: 520px;
|
||||
width: calc(100vw - 40px);
|
||||
}
|
||||
dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
|
||||
.dlg { display: flex; flex-direction: column; gap: 14px; padding: var(--pad-panel); }
|
||||
h3 {
|
||||
margin: 0;
|
||||
font-family: var(--font-body);
|
||||
font-size: var(--text-xs);
|
||||
font-weight: 700;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 1.5px;
|
||||
color: var(--ink-300);
|
||||
}
|
||||
.row {
|
||||
display: grid;
|
||||
grid-template-columns: 130px 1fr;
|
||||
gap: 12px;
|
||||
align-items: center;
|
||||
}
|
||||
.row label, .row-label {
|
||||
color: var(--ink-500);
|
||||
font-family: var(--font-body);
|
||||
font-size: var(--text-xs);
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 1px;
|
||||
}
|
||||
.row select, .row input {
|
||||
background: var(--bg-page);
|
||||
color: var(--ink-100);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--r-sm);
|
||||
padding: 10px 12px;
|
||||
font-family: var(--font-mono);
|
||||
font-size: var(--text-mono);
|
||||
width: 100%;
|
||||
}
|
||||
.row input:focus, .row select:focus {
|
||||
outline: none;
|
||||
border-color: var(--accent);
|
||||
box-shadow: var(--accent-glow);
|
||||
}
|
||||
.readonly {
|
||||
color: var(--ink-300);
|
||||
padding: 10px 0;
|
||||
}
|
||||
.preview {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: baseline;
|
||||
gap: 10px;
|
||||
padding: 12px 14px;
|
||||
background: var(--bg-card);
|
||||
border: 1px solid var(--border);
|
||||
border-left: 3px solid var(--accent);
|
||||
border-radius: var(--r-sm);
|
||||
font-size: var(--text-mono);
|
||||
}
|
||||
.preview .k {
|
||||
color: var(--ink-500);
|
||||
font-family: var(--font-body);
|
||||
font-size: var(--text-xs);
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 1px;
|
||||
}
|
||||
.preview .v { color: var(--cream); }
|
||||
.preview .sub {
|
||||
color: var(--ink-500);
|
||||
font-family: var(--font-body);
|
||||
font-size: var(--text-xs);
|
||||
}
|
||||
.mono { font-family: var(--font-mono); }
|
||||
.dlg-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 6px; }
|
||||
button.primary {
|
||||
background: linear-gradient(180deg, var(--blue-500), var(--blue-600));
|
||||
border: 1px solid var(--blue-400);
|
||||
color: var(--cream);
|
||||
border-radius: var(--r-sm);
|
||||
padding: 10px 16px;
|
||||
font-family: var(--font-body);
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
}
|
||||
button.primary:disabled { opacity: 0.4; cursor: default; }
|
||||
button.secondary {
|
||||
background: var(--bg-card);
|
||||
color: var(--ink-100);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--r-sm);
|
||||
padding: 10px 16px;
|
||||
font-family: var(--font-body);
|
||||
font-size: var(--text-sm);
|
||||
cursor: pointer;
|
||||
}
|
||||
button.secondary:hover:not(:disabled) { border-color: var(--accent); box-shadow: var(--accent-glow); }
|
||||
button.secondary:disabled { opacity: 0.4; cursor: default; }
|
||||
.flash { color: var(--danger-500); font-family: var(--font-mono); font-size: var(--text-mono); margin: 0; }
|
||||
.hint { color: var(--ink-500); font-family: var(--font-mono); font-size: var(--text-mono); margin: 0; }
|
||||
</style>
|
||||
Reference in New Issue
Block a user