Merge pull request #230 from Corfirean/feat/startup-fleet-top-up

Companions: the startup limit creates the missing ones
This commit is contained in:
Corfirean authored and GitHub committed 2026-11-20 21:43:30 +05:00
commit 802bde220c
12 files changed
+221 -34

No files matched your search

+1
View File
@@ -69,6 +69,7 @@ export {};
if(cmd==="list_presets"){const pr=args?.scope==="server"?serverPresets:botsPresets;return (pr.presets as any[]).map(p=>({id:p.id,title:p.title,description:p.description}));}
if(cmd==="preview_preset"){const a=args;const sc=a.scope==="server"?serverSchema:botsSchema;const pr=(a.scope==="server"?serverPresets:botsPresets).presets as any[];const p=pr.find(x=>x.id===a.preset)??{id:a.preset??"defaults",title:"Recommended defaults",description:"Every setting returns to its default value."};const st=(sc.settings as any[]).filter(x=>x.type==="int"||x.type==="float"||x.type==="enum").slice(0,3);return {id:p.id,title:p.title,description:p.description,changes:st.map(x=>({key:x.key,title:x.title,from:x.default,to:x.type==="enum"?(x.options?.[1]?.value??x.default):(Number(x.default)||1)*2,dangerous:false}))};}
if(cmd==="companion_sizes") return {hardware:{cores:16,ram_gb:31,free_ram_gb:12},sizes:[{id:"small",title:"Small",bots:50,warning:null},{id:"medium",title:"Medium",bots:250,warning:null},{id:"large",title:"Large",bots:500,warning:"500 companions may need more CPU and memory than this computer has (8 cores, 16 GB)."}]};
if(cmd==="top_up_startup_fleet") return 0;
if(cmd==="add_companions"){const base=(window as any).__bots??85;(window as any).__target=base+args.count;return {spawned:"queued",created:null,baseline:base};}
if(cmd==="check_update") return {from_version:(window as any).__updated?"0.261028.83":"0.261026.81",to_version:"0.261028.83",items:[],conflicts:[],migrations:5,pending_migrations:(window as any).__updated?0:5,download_bytes:6000000};
if(cmd==="apply_update"){const w=window as any;for(let i=1;i<=8;i++){await new Promise((r: any)=>setTimeout(r,700));(w.__handlers?.["update-progress"]??[]).forEach((h: any)=>h({event:"update-progress",id:1,payload:{step:i<4?"Downloading the update":i<7?"Applying the update":"Finishing",percent:i*12}}));}(window as any).__updated=true;return {txn:{state:"committed",to_version:"0.261028.83"},migrations:null};}
+2
View File
@@ -597,6 +597,8 @@ const de: Partial<Record<keyof typeof en, string>> = {
"comp.startCount": "Wie viele sich anmelden",
"comp.startSave": "Speichern",
"comp.startSaved": "Gespeichert. Gilt ab dem nächsten Serverstart.",
"comp.startTopUp": "Gespeichert. {n} weitere Begleiter werden erstellt, damit {max} existieren; die übrigen gibt es schon.",
"comp.startTopUpConfirm": "{n} weitere Begleiter erstellen, damit {max} existieren? Vorhandene werden nicht erneut erstellt.",
"comp.startHint": "Bots, die sich nicht anmelden, bleiben gespeichert und können später online gebracht werden.",
"comp.startInvalid": "Gib eine ganze Zahl von 0 bis 5000 ein.",
+2
View File
@@ -696,6 +696,8 @@ const en = {
"comp.startCount": "How many log in",
"comp.startSave": "Save",
"comp.startSaved": "Saved. It applies the next time the server starts.",
"comp.startTopUp": "Saved. Creating {n} more companions so that {max} exist; the others already exist.",
"comp.startTopUpConfirm": "Create {n} more companions so that {max} exist? Companions that already exist are not created again.",
"comp.startHint": "Bots that do not log in stay saved and can be brought online later.",
"comp.startInvalid": "Enter a whole number from 0 to 5000.",
+2
View File
@@ -597,6 +597,8 @@ const es: Partial<Record<keyof typeof en, string>> = {
"comp.startCount": "Cuántos inician sesión",
"comp.startSave": "Guardar",
"comp.startSaved": "Guardado. Se aplica la próxima vez que se inicie el servidor.",
"comp.startTopUp": "Guardado. Se crean {n} compañeros más para que existan {max}; los demás ya existen.",
"comp.startTopUpConfirm": "¿Crear {n} compañeros más para que existan {max}? Los que ya existen no se crean de nuevo.",
"comp.startHint": "Los bots que no inician sesión quedan guardados y se pueden conectar más tarde.",
"comp.startInvalid": "Introduce un número entero de 0 a 5000.",
+2
View File
@@ -597,6 +597,8 @@ const fr: Partial<Record<keyof typeof en, string>> = {
"comp.startCount": "Combien se connectent",
"comp.startSave": "Enregistrer",
"comp.startSaved": "Enregistré. S’applique au prochain démarrage du serveur.",
"comp.startTopUp": "Enregistré. {n} compagnons de plus sont créés pour qu’il y en ait {max} ; les autres existent déjà.",
"comp.startTopUpConfirm": "Créer {n} compagnons de plus pour qu’il y en ait {max} ? Ceux qui existent déjà ne sont pas recréés.",
"comp.startHint": "Les bots qui ne se connectent pas restent enregistrés et peuvent être mis en ligne plus tard.",
"comp.startInvalid": "Saisissez un nombre entier de 0 à 5000.",
+2
View File
@@ -679,6 +679,8 @@ const ru: Partial<Record<keyof typeof en, string>> = {
"comp.startCount": "Сколько входит",
"comp.startSave": "Сохранить",
"comp.startSaved": "Сохранено. Вступит в силу при следующем запуске сервера.",
"comp.startTopUp": "Сохранено. Создаётся ещё {n} компаньонов, чтобы их стало {max}; остальные уже есть.",
"comp.startTopUpConfirm": "Создать ещё {n} компаньонов, чтобы их стало {max}? Уже существующие заново не создаются.",
"comp.startHint": "Боты, которые не входят, остаются сохранёнными, их можно вывести в сеть позже.",
"comp.startInvalid": "Введите целое число от 0 до 5000.",
+2
View File
@@ -650,6 +650,8 @@ const zh = {
"comp.startCount": "自动登录随从数量",
"comp.startSave": "保存",
"comp.startSaved": "已保存。将在下次服务器启动时生效。",
"comp.startTopUp": "已保存。正在再创建 {n} 个同伴,使总数达到 {max};其余已存在。",
"comp.startTopUpConfirm": "再创建 {n} 个同伴,使总数达到 {max}?已存在的不会重复创建。",
"comp.startHint": "未登录的随从仍保留在数据库中,随时可在需要时手动调出上线。",
"comp.startInvalid": "请输入 0 到 5000 之间的整数。",
+2
View File
@@ -556,6 +556,8 @@ export const api = {
invoke<{ txn: UpdateTxn; preexisting_character_count?: number }>("apply_update", { id, source: source ?? null, resolutions }),
rollbackUpdate: (id: string, txn: string) => invoke<UpdateTxn>("rollback_update", { id, txn }),
retryUpdateValidation: (id: string, txn: string) => invoke<UpdateTxn>("retry_update_validation", { id, txn }),
/** Creates the companions the startup fleet is missing (the limit is a fleet size). Returns how many were queued. */
topUpStartupFleet: (id: string, realm?: RealmMode) => invoke<number>("top_up_startup_fleet", { id, realm: realm ?? null }),
population: (id: string, realm?: RealmMode) => invoke<Population | null>("get_population", { id, realm: realm ?? null }),
stopSpawning: (id: string, realm?: RealmMode) => invoke<{ count: number }>("companions_stop_spawning", { id, realm: realm ?? null }),
takeOffline: (id: string, realm?: RealmMode) => invoke<{ count: number }>("companions_take_offline", { id, realm: realm ?? null }),
+9 -2
View File
@@ -305,11 +305,18 @@ export function CompanionsCard({ serverId }: { serverId: string }) {
setError(null);
setStartNote(null);
try {
// The limit is a fleet size: companions that exist count, only the missing ones are created.
const missing = autoOn && running && isViewingActiveRealm && pop ? Math.max(0, maxNum - pop.bots_total) : 0;
if (missing > 200 && !window.confirm(t("comp.startTopUpConfirm", { n: Math.min(missing, 2000), max: maxNum }))) {
setStartBusy(false);
return;
}
await api.save(serverId, "bots", {
"CoaBots.AutoLoginOnStartup": autoOn,
"CoaBots.AutoLogin.MaxCount": maxNum,
});
setStartNote(t("comp.startSaved"));
const queued = autoOn && running ? await api.topUpStartupFleet(serverId, activeServerRealm) : 0;
setStartNote(queued > 0 ? t("comp.startTopUp", { n: queued, max: maxNum }) : t("comp.startSaved"));
} catch (e) {
setError(asUiError(e));
} finally {
@@ -781,7 +788,7 @@ export function CompanionsCard({ serverId }: { serverId: string }) {
Persistent Startup Fleet
</h3>
<p className="text-xs text-muted">
Configure how many bots automatically log into the world whenever the server launches.
The server keeps this many companions. At every start the ones that exist log in, and only the missing ones are created.
</p>
<div className="flex flex-wrap items-center gap-4 text-sm">